blob: b2cebc0dbd3130c3d75f5ea23d21ffb31e5b0422 [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
Chih-Hung Hsiehfba39972016-05-11 11:26:48 -0700144// NOLINT on __ macro to suppress wrong warning/fix from clang-tidy.
145#define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> // NOLINT
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200146#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsWordSize, x).Int32Value()
147
148class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS {
149 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000150 explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200151
152 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
153 LocationSummary* locations = instruction_->GetLocations();
154 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
155 __ Bind(GetEntryLabel());
156 if (instruction_->CanThrowIntoCatchBlock()) {
157 // Live registers will be restored in the catch block if caught.
158 SaveLiveRegisters(codegen, instruction_->GetLocations());
159 }
160 // We're moving two locations to locations that could overlap, so we need a parallel
161 // move resolver.
162 InvokeRuntimeCallingConvention calling_convention;
163 codegen->EmitParallelMoves(locations->InAt(0),
164 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
165 Primitive::kPrimInt,
166 locations->InAt(1),
167 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
168 Primitive::kPrimInt);
169 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds),
170 instruction_,
171 instruction_->GetDexPc(),
172 this,
173 IsDirectEntrypoint(kQuickThrowArrayBounds));
174 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
175 }
176
177 bool IsFatal() const OVERRIDE { return true; }
178
179 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; }
180
181 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200182 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS);
183};
184
185class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS {
186 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000187 explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200188
189 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
190 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
191 __ Bind(GetEntryLabel());
192 if (instruction_->CanThrowIntoCatchBlock()) {
193 // Live registers will be restored in the catch block if caught.
194 SaveLiveRegisters(codegen, instruction_->GetLocations());
195 }
196 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero),
197 instruction_,
198 instruction_->GetDexPc(),
199 this,
200 IsDirectEntrypoint(kQuickThrowDivZero));
201 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
202 }
203
204 bool IsFatal() const OVERRIDE { return true; }
205
206 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; }
207
208 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200209 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS);
210};
211
212class LoadClassSlowPathMIPS : public SlowPathCodeMIPS {
213 public:
214 LoadClassSlowPathMIPS(HLoadClass* cls,
215 HInstruction* at,
216 uint32_t dex_pc,
217 bool do_clinit)
David Srbecky9cd6d372016-02-09 15:24:47 +0000218 : SlowPathCodeMIPS(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200219 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
220 }
221
222 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
223 LocationSummary* locations = at_->GetLocations();
224 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
225
226 __ Bind(GetEntryLabel());
227 SaveLiveRegisters(codegen, locations);
228
229 InvokeRuntimeCallingConvention calling_convention;
230 __ LoadConst32(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
231
232 int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
233 : QUICK_ENTRY_POINT(pInitializeType);
234 bool direct = do_clinit_ ? IsDirectEntrypoint(kQuickInitializeStaticStorage)
235 : IsDirectEntrypoint(kQuickInitializeType);
236
237 mips_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this, direct);
238 if (do_clinit_) {
239 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
240 } else {
241 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
242 }
243
244 // Move the class to the desired location.
245 Location out = locations->Out();
246 if (out.IsValid()) {
247 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
248 Primitive::Type type = at_->GetType();
249 mips_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
250 }
251
252 RestoreLiveRegisters(codegen, locations);
253 __ B(GetExitLabel());
254 }
255
256 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; }
257
258 private:
259 // The class this slow path will load.
260 HLoadClass* const cls_;
261
262 // The instruction where this slow path is happening.
263 // (Might be the load class or an initialization check).
264 HInstruction* const at_;
265
266 // The dex PC of `at_`.
267 const uint32_t dex_pc_;
268
269 // Whether to initialize the class.
270 const bool do_clinit_;
271
272 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS);
273};
274
275class LoadStringSlowPathMIPS : public SlowPathCodeMIPS {
276 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000277 explicit LoadStringSlowPathMIPS(HLoadString* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200278
279 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
280 LocationSummary* locations = instruction_->GetLocations();
281 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
282 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
283
284 __ Bind(GetEntryLabel());
285 SaveLiveRegisters(codegen, locations);
286
287 InvokeRuntimeCallingConvention calling_convention;
David Srbecky9cd6d372016-02-09 15:24:47 +0000288 const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex();
289 __ LoadConst32(calling_convention.GetRegisterAt(0), string_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200290 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString),
291 instruction_,
292 instruction_->GetDexPc(),
293 this,
294 IsDirectEntrypoint(kQuickResolveString));
295 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
296 Primitive::Type type = instruction_->GetType();
297 mips_codegen->MoveLocation(locations->Out(),
298 calling_convention.GetReturnLocation(type),
299 type);
300
301 RestoreLiveRegisters(codegen, locations);
302 __ B(GetExitLabel());
303 }
304
305 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; }
306
307 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200308 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS);
309};
310
311class NullCheckSlowPathMIPS : public SlowPathCodeMIPS {
312 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000313 explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200314
315 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
316 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
317 __ Bind(GetEntryLabel());
318 if (instruction_->CanThrowIntoCatchBlock()) {
319 // Live registers will be restored in the catch block if caught.
320 SaveLiveRegisters(codegen, instruction_->GetLocations());
321 }
322 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer),
323 instruction_,
324 instruction_->GetDexPc(),
325 this,
326 IsDirectEntrypoint(kQuickThrowNullPointer));
327 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
328 }
329
330 bool IsFatal() const OVERRIDE { return true; }
331
332 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; }
333
334 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200335 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS);
336};
337
338class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS {
339 public:
340 SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000341 : SlowPathCodeMIPS(instruction), successor_(successor) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200342
343 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
344 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
345 __ Bind(GetEntryLabel());
346 SaveLiveRegisters(codegen, instruction_->GetLocations());
347 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend),
348 instruction_,
349 instruction_->GetDexPc(),
350 this,
351 IsDirectEntrypoint(kQuickTestSuspend));
352 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
353 RestoreLiveRegisters(codegen, instruction_->GetLocations());
354 if (successor_ == nullptr) {
355 __ B(GetReturnLabel());
356 } else {
357 __ B(mips_codegen->GetLabelOf(successor_));
358 }
359 }
360
361 MipsLabel* GetReturnLabel() {
362 DCHECK(successor_ == nullptr);
363 return &return_label_;
364 }
365
366 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; }
367
368 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200369 // If not null, the block to branch to after the suspend check.
370 HBasicBlock* const successor_;
371
372 // If `successor_` is null, the label to branch to after the suspend check.
373 MipsLabel return_label_;
374
375 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS);
376};
377
378class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS {
379 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000380 explicit TypeCheckSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200381
382 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
383 LocationSummary* locations = instruction_->GetLocations();
384 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) : locations->Out();
385 uint32_t dex_pc = instruction_->GetDexPc();
386 DCHECK(instruction_->IsCheckCast()
387 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
388 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
389
390 __ Bind(GetEntryLabel());
391 SaveLiveRegisters(codegen, locations);
392
393 // We're moving two locations to locations that could overlap, so we need a parallel
394 // move resolver.
395 InvokeRuntimeCallingConvention calling_convention;
396 codegen->EmitParallelMoves(locations->InAt(1),
397 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
398 Primitive::kPrimNot,
399 object_class,
400 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
401 Primitive::kPrimNot);
402
403 if (instruction_->IsInstanceOf()) {
404 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
405 instruction_,
406 dex_pc,
407 this,
408 IsDirectEntrypoint(kQuickInstanceofNonTrivial));
Roland Levillain888d0672015-11-23 18:53:50 +0000409 CheckEntrypointTypes<
410 kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200411 Primitive::Type ret_type = instruction_->GetType();
412 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
413 mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200414 } else {
415 DCHECK(instruction_->IsCheckCast());
416 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast),
417 instruction_,
418 dex_pc,
419 this,
420 IsDirectEntrypoint(kQuickCheckCast));
421 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
422 }
423
424 RestoreLiveRegisters(codegen, locations);
425 __ B(GetExitLabel());
426 }
427
428 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; }
429
430 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200431 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS);
432};
433
434class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS {
435 public:
Aart Bik42249c32016-01-07 15:33:50 -0800436 explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000437 : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200438
439 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800440 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200441 __ Bind(GetEntryLabel());
442 SaveLiveRegisters(codegen, instruction_->GetLocations());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200443 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize),
444 instruction_,
Aart Bik42249c32016-01-07 15:33:50 -0800445 instruction_->GetDexPc(),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200446 this,
447 IsDirectEntrypoint(kQuickDeoptimize));
Roland Levillain888d0672015-11-23 18:53:50 +0000448 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200449 }
450
451 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; }
452
453 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200454 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS);
455};
456
457CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph,
458 const MipsInstructionSetFeatures& isa_features,
459 const CompilerOptions& compiler_options,
460 OptimizingCompilerStats* stats)
461 : CodeGenerator(graph,
462 kNumberOfCoreRegisters,
463 kNumberOfFRegisters,
464 kNumberOfRegisterPairs,
465 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
466 arraysize(kCoreCalleeSaves)),
467 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
468 arraysize(kFpuCalleeSaves)),
469 compiler_options,
470 stats),
471 block_labels_(nullptr),
472 location_builder_(graph, this),
473 instruction_visitor_(graph, this),
474 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +0100475 assembler_(graph->GetArena(), &isa_features),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200476 isa_features_(isa_features) {
477 // Save RA (containing the return address) to mimic Quick.
478 AddAllocatedRegister(Location::RegisterLocation(RA));
479}
480
481#undef __
Chih-Hung Hsiehfba39972016-05-11 11:26:48 -0700482// NOLINT on __ macro to suppress wrong warning/fix from clang-tidy.
483#define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200484#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsWordSize, x).Int32Value()
485
486void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) {
487 // Ensure that we fix up branches.
488 __ FinalizeCode();
489
490 // Adjust native pc offsets in stack maps.
491 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
492 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
493 uint32_t new_position = __ GetAdjustedPosition(old_position);
494 DCHECK_GE(new_position, old_position);
495 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
496 }
497
498 // Adjust pc offsets for the disassembly information.
499 if (disasm_info_ != nullptr) {
500 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
501 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
502 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
503 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
504 it.second.start = __ GetAdjustedPosition(it.second.start);
505 it.second.end = __ GetAdjustedPosition(it.second.end);
506 }
507 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
508 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
509 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
510 }
511 }
512
513 CodeGenerator::Finalize(allocator);
514}
515
516MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const {
517 return codegen_->GetAssembler();
518}
519
520void ParallelMoveResolverMIPS::EmitMove(size_t index) {
521 DCHECK_LT(index, moves_.size());
522 MoveOperands* move = moves_[index];
523 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
524}
525
526void ParallelMoveResolverMIPS::EmitSwap(size_t index) {
527 DCHECK_LT(index, moves_.size());
528 MoveOperands* move = moves_[index];
529 Primitive::Type type = move->GetType();
530 Location loc1 = move->GetDestination();
531 Location loc2 = move->GetSource();
532
533 DCHECK(!loc1.IsConstant());
534 DCHECK(!loc2.IsConstant());
535
536 if (loc1.Equals(loc2)) {
537 return;
538 }
539
540 if (loc1.IsRegister() && loc2.IsRegister()) {
541 // Swap 2 GPRs.
542 Register r1 = loc1.AsRegister<Register>();
543 Register r2 = loc2.AsRegister<Register>();
544 __ Move(TMP, r2);
545 __ Move(r2, r1);
546 __ Move(r1, TMP);
547 } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) {
548 FRegister f1 = loc1.AsFpuRegister<FRegister>();
549 FRegister f2 = loc2.AsFpuRegister<FRegister>();
550 if (type == Primitive::kPrimFloat) {
551 __ MovS(FTMP, f2);
552 __ MovS(f2, f1);
553 __ MovS(f1, FTMP);
554 } else {
555 DCHECK_EQ(type, Primitive::kPrimDouble);
556 __ MovD(FTMP, f2);
557 __ MovD(f2, f1);
558 __ MovD(f1, FTMP);
559 }
560 } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) ||
561 (loc1.IsFpuRegister() && loc2.IsRegister())) {
562 // Swap FPR and GPR.
563 DCHECK_EQ(type, Primitive::kPrimFloat); // Can only swap a float.
564 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
565 : loc2.AsFpuRegister<FRegister>();
566 Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>()
567 : loc2.AsRegister<Register>();
568 __ Move(TMP, r2);
569 __ Mfc1(r2, f1);
570 __ Mtc1(TMP, f1);
571 } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) {
572 // Swap 2 GPR register pairs.
573 Register r1 = loc1.AsRegisterPairLow<Register>();
574 Register r2 = loc2.AsRegisterPairLow<Register>();
575 __ Move(TMP, r2);
576 __ Move(r2, r1);
577 __ Move(r1, TMP);
578 r1 = loc1.AsRegisterPairHigh<Register>();
579 r2 = loc2.AsRegisterPairHigh<Register>();
580 __ Move(TMP, r2);
581 __ Move(r2, r1);
582 __ Move(r1, TMP);
583 } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) ||
584 (loc1.IsFpuRegister() && loc2.IsRegisterPair())) {
585 // Swap FPR and GPR register pair.
586 DCHECK_EQ(type, Primitive::kPrimDouble);
587 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
588 : loc2.AsFpuRegister<FRegister>();
589 Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
590 : loc2.AsRegisterPairLow<Register>();
591 Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
592 : loc2.AsRegisterPairHigh<Register>();
593 // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and
594 // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR
595 // unpredictable and the following mfch1 will fail.
596 __ Mfc1(TMP, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800597 __ MoveFromFpuHigh(AT, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200598 __ Mtc1(r2_l, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800599 __ MoveToFpuHigh(r2_h, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200600 __ Move(r2_l, TMP);
601 __ Move(r2_h, AT);
602 } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) {
603 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false);
604 } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) {
605 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true);
David Brazdilcc0f3112016-01-28 17:14:52 +0000606 } else if ((loc1.IsRegister() && loc2.IsStackSlot()) ||
607 (loc1.IsStackSlot() && loc2.IsRegister())) {
608 Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>()
609 : loc2.AsRegister<Register>();
610 intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex()
611 : loc2.GetStackIndex();
612 __ Move(TMP, reg);
613 __ LoadFromOffset(kLoadWord, reg, SP, offset);
614 __ StoreToOffset(kStoreWord, TMP, SP, offset);
615 } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) ||
616 (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) {
617 Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
618 : loc2.AsRegisterPairLow<Register>();
619 Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
620 : loc2.AsRegisterPairHigh<Register>();
621 intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex()
622 : loc2.GetStackIndex();
623 intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize)
624 : loc2.GetHighStackIndex(kMipsWordSize);
625 __ Move(TMP, reg_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000626 __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000627 __ StoreToOffset(kStoreWord, TMP, SP, offset_l);
David Brazdil04d3e872016-01-29 09:50:09 +0000628 __ Move(TMP, reg_h);
629 __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h);
630 __ StoreToOffset(kStoreWord, TMP, SP, offset_h);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200631 } else {
632 LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported";
633 }
634}
635
636void ParallelMoveResolverMIPS::RestoreScratch(int reg) {
637 __ Pop(static_cast<Register>(reg));
638}
639
640void ParallelMoveResolverMIPS::SpillScratch(int reg) {
641 __ Push(static_cast<Register>(reg));
642}
643
644void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) {
645 // Allocate a scratch register other than TMP, if available.
646 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
647 // automatically unspilled when the scratch scope object is destroyed).
648 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
649 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
650 int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0;
651 for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) {
652 __ LoadFromOffset(kLoadWord,
653 Register(ensure_scratch.GetRegister()),
654 SP,
655 index1 + stack_offset);
656 __ LoadFromOffset(kLoadWord,
657 TMP,
658 SP,
659 index2 + stack_offset);
660 __ StoreToOffset(kStoreWord,
661 Register(ensure_scratch.GetRegister()),
662 SP,
663 index2 + stack_offset);
664 __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset);
665 }
666}
667
Alexey Frunze73296a72016-06-03 22:51:46 -0700668void CodeGeneratorMIPS::ComputeSpillMask() {
669 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
670 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
671 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
672 // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved
673 // registers, include the ZERO register to force alignment of FPU callee-saved registers
674 // within the stack frame.
675 if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) {
676 core_spill_mask_ |= (1 << ZERO);
677 }
678}
679
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200680static dwarf::Reg DWARFReg(Register reg) {
681 return dwarf::Reg::MipsCore(static_cast<int>(reg));
682}
683
684// TODO: mapping of floating-point registers to DWARF.
685
686void CodeGeneratorMIPS::GenerateFrameEntry() {
687 __ Bind(&frame_entry_label_);
688
689 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod();
690
691 if (do_overflow_check) {
692 __ LoadFromOffset(kLoadWord,
693 ZERO,
694 SP,
695 -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips)));
696 RecordPcInfo(nullptr, 0);
697 }
698
699 if (HasEmptyFrame()) {
700 return;
701 }
702
703 // Make sure the frame size isn't unreasonably large.
704 if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) {
705 LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes";
706 }
707
708 // Spill callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200709
Alexey Frunze73296a72016-06-03 22:51:46 -0700710 uint32_t ofs = GetFrameSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200711 __ IncreaseFrameSize(ofs);
712
Alexey Frunze73296a72016-06-03 22:51:46 -0700713 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
714 Register reg = static_cast<Register>(MostSignificantBit(mask));
715 mask ^= 1u << reg;
716 ofs -= kMipsWordSize;
717 // The ZERO register is only included for alignment.
718 if (reg != ZERO) {
719 __ StoreToOffset(kStoreWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200720 __ cfi().RelOffset(DWARFReg(reg), ofs);
721 }
722 }
723
Alexey Frunze73296a72016-06-03 22:51:46 -0700724 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
725 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
726 mask ^= 1u << reg;
727 ofs -= kMipsDoublewordSize;
728 __ StoreDToOffset(reg, SP, ofs);
729 // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200730 }
731
Alexey Frunze73296a72016-06-03 22:51:46 -0700732 // Store the current method pointer.
733 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200734}
735
736void CodeGeneratorMIPS::GenerateFrameExit() {
737 __ cfi().RememberState();
738
739 if (!HasEmptyFrame()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200740 // Restore callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200741
Alexey Frunze73296a72016-06-03 22:51:46 -0700742 // For better instruction scheduling restore RA before other registers.
743 uint32_t ofs = GetFrameSize();
744 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
745 Register reg = static_cast<Register>(MostSignificantBit(mask));
746 mask ^= 1u << reg;
747 ofs -= kMipsWordSize;
748 // The ZERO register is only included for alignment.
749 if (reg != ZERO) {
750 __ LoadFromOffset(kLoadWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200751 __ cfi().Restore(DWARFReg(reg));
752 }
753 }
754
Alexey Frunze73296a72016-06-03 22:51:46 -0700755 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
756 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
757 mask ^= 1u << reg;
758 ofs -= kMipsDoublewordSize;
759 __ LoadDFromOffset(reg, SP, ofs);
760 // TODO: __ cfi().Restore(DWARFReg(reg));
761 }
762
763 __ DecreaseFrameSize(GetFrameSize());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200764 }
765
766 __ Jr(RA);
767 __ Nop();
768
769 __ cfi().RestoreState();
770 __ cfi().DefCFAOffset(GetFrameSize());
771}
772
773void CodeGeneratorMIPS::Bind(HBasicBlock* block) {
774 __ Bind(GetLabelOf(block));
775}
776
777void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
778 if (src.Equals(dst)) {
779 return;
780 }
781
782 if (src.IsConstant()) {
783 MoveConstant(dst, src.GetConstant());
784 } else {
785 if (Primitive::Is64BitType(dst_type)) {
786 Move64(dst, src);
787 } else {
788 Move32(dst, src);
789 }
790 }
791}
792
793void CodeGeneratorMIPS::Move32(Location destination, Location source) {
794 if (source.Equals(destination)) {
795 return;
796 }
797
798 if (destination.IsRegister()) {
799 if (source.IsRegister()) {
800 __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>());
801 } else if (source.IsFpuRegister()) {
802 __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>());
803 } else {
804 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
805 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
806 }
807 } else if (destination.IsFpuRegister()) {
808 if (source.IsRegister()) {
809 __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>());
810 } else if (source.IsFpuRegister()) {
811 __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
812 } else {
813 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
814 __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
815 }
816 } else {
817 DCHECK(destination.IsStackSlot()) << destination;
818 if (source.IsRegister()) {
819 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
820 } else if (source.IsFpuRegister()) {
821 __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex());
822 } else {
823 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
824 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
825 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
826 }
827 }
828}
829
830void CodeGeneratorMIPS::Move64(Location destination, Location source) {
831 if (source.Equals(destination)) {
832 return;
833 }
834
835 if (destination.IsRegisterPair()) {
836 if (source.IsRegisterPair()) {
837 __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
838 __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
839 } else if (source.IsFpuRegister()) {
840 Register dst_high = destination.AsRegisterPairHigh<Register>();
841 Register dst_low = destination.AsRegisterPairLow<Register>();
842 FRegister src = source.AsFpuRegister<FRegister>();
843 __ Mfc1(dst_low, src);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800844 __ MoveFromFpuHigh(dst_high, src);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200845 } else {
846 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
847 int32_t off = source.GetStackIndex();
848 Register r = destination.AsRegisterPairLow<Register>();
849 __ LoadFromOffset(kLoadDoubleword, r, SP, off);
850 }
851 } else if (destination.IsFpuRegister()) {
852 if (source.IsRegisterPair()) {
853 FRegister dst = destination.AsFpuRegister<FRegister>();
854 Register src_high = source.AsRegisterPairHigh<Register>();
855 Register src_low = source.AsRegisterPairLow<Register>();
856 __ Mtc1(src_low, dst);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800857 __ MoveToFpuHigh(src_high, dst);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200858 } else if (source.IsFpuRegister()) {
859 __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
860 } else {
861 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
862 __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
863 }
864 } else {
865 DCHECK(destination.IsDoubleStackSlot()) << destination;
866 int32_t off = destination.GetStackIndex();
867 if (source.IsRegisterPair()) {
868 __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off);
869 } else if (source.IsFpuRegister()) {
870 __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off);
871 } else {
872 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
873 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
874 __ StoreToOffset(kStoreWord, TMP, SP, off);
875 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4);
876 __ StoreToOffset(kStoreWord, TMP, SP, off + 4);
877 }
878 }
879}
880
881void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) {
882 if (c->IsIntConstant() || c->IsNullConstant()) {
883 // Move 32 bit constant.
884 int32_t value = GetInt32ValueOf(c);
885 if (destination.IsRegister()) {
886 Register dst = destination.AsRegister<Register>();
887 __ LoadConst32(dst, value);
888 } else {
889 DCHECK(destination.IsStackSlot())
890 << "Cannot move " << c->DebugName() << " to " << destination;
891 __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP);
892 }
893 } else if (c->IsLongConstant()) {
894 // Move 64 bit constant.
895 int64_t value = GetInt64ValueOf(c);
896 if (destination.IsRegisterPair()) {
897 Register r_h = destination.AsRegisterPairHigh<Register>();
898 Register r_l = destination.AsRegisterPairLow<Register>();
899 __ LoadConst64(r_h, r_l, value);
900 } else {
901 DCHECK(destination.IsDoubleStackSlot())
902 << "Cannot move " << c->DebugName() << " to " << destination;
903 __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP);
904 }
905 } else if (c->IsFloatConstant()) {
906 // Move 32 bit float constant.
907 int32_t value = GetInt32ValueOf(c);
908 if (destination.IsFpuRegister()) {
909 __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP);
910 } else {
911 DCHECK(destination.IsStackSlot())
912 << "Cannot move " << c->DebugName() << " to " << destination;
913 __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP);
914 }
915 } else {
916 // Move 64 bit double constant.
917 DCHECK(c->IsDoubleConstant()) << c->DebugName();
918 int64_t value = GetInt64ValueOf(c);
919 if (destination.IsFpuRegister()) {
920 FRegister fd = destination.AsFpuRegister<FRegister>();
921 __ LoadDConst64(fd, value, TMP);
922 } else {
923 DCHECK(destination.IsDoubleStackSlot())
924 << "Cannot move " << c->DebugName() << " to " << destination;
925 __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP);
926 }
927 }
928}
929
930void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) {
931 DCHECK(destination.IsRegister());
932 Register dst = destination.AsRegister<Register>();
933 __ LoadConst32(dst, value);
934}
935
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200936void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) {
937 if (location.IsRegister()) {
938 locations->AddTemp(location);
Alexey Frunzec9e94f32015-10-26 16:11:39 -0700939 } else if (location.IsRegisterPair()) {
940 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
941 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200942 } else {
943 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
944 }
945}
946
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200947void CodeGeneratorMIPS::MarkGCCard(Register object, Register value) {
948 MipsLabel done;
949 Register card = AT;
950 Register temp = TMP;
951 __ Beqz(value, &done);
952 __ LoadFromOffset(kLoadWord,
953 card,
954 TR,
955 Thread::CardTableOffset<kMipsWordSize>().Int32Value());
956 __ Srl(temp, object, gc::accounting::CardTable::kCardShift);
957 __ Addu(temp, card, temp);
958 __ Sb(card, temp, 0);
959 __ Bind(&done);
960}
961
David Brazdil58282f42016-01-14 12:45:10 +0000962void CodeGeneratorMIPS::SetupBlockedRegisters() const {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200963 // Don't allocate the dalvik style register pair passing.
964 blocked_register_pairs_[A1_A2] = true;
965
966 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
967 blocked_core_registers_[ZERO] = true;
968 blocked_core_registers_[K0] = true;
969 blocked_core_registers_[K1] = true;
970 blocked_core_registers_[GP] = true;
971 blocked_core_registers_[SP] = true;
972 blocked_core_registers_[RA] = true;
973
974 // AT and TMP(T8) are used as temporary/scratch registers
975 // (similar to how AT is used by MIPS assemblers).
976 blocked_core_registers_[AT] = true;
977 blocked_core_registers_[TMP] = true;
978 blocked_fpu_registers_[FTMP] = true;
979
980 // Reserve suspend and thread registers.
981 blocked_core_registers_[S0] = true;
982 blocked_core_registers_[TR] = true;
983
984 // Reserve T9 for function calls
985 blocked_core_registers_[T9] = true;
986
987 // Reserve odd-numbered FPU registers.
988 for (size_t i = 1; i < kNumberOfFRegisters; i += 2) {
989 blocked_fpu_registers_[i] = true;
990 }
991
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200992 UpdateBlockedPairRegisters();
993}
994
995void CodeGeneratorMIPS::UpdateBlockedPairRegisters() const {
996 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
997 MipsManagedRegister current =
998 MipsManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
999 if (blocked_core_registers_[current.AsRegisterPairLow()]
1000 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
1001 blocked_register_pairs_[i] = true;
1002 }
1003 }
1004}
1005
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001006size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1007 __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index);
1008 return kMipsWordSize;
1009}
1010
1011size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1012 __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index);
1013 return kMipsWordSize;
1014}
1015
1016size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1017 __ StoreDToOffset(FRegister(reg_id), SP, stack_index);
1018 return kMipsDoublewordSize;
1019}
1020
1021size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1022 __ LoadDFromOffset(FRegister(reg_id), SP, stack_index);
1023 return kMipsDoublewordSize;
1024}
1025
1026void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001027 stream << Register(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001028}
1029
1030void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001031 stream << FRegister(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001032}
1033
1034void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint,
1035 HInstruction* instruction,
1036 uint32_t dex_pc,
1037 SlowPathCode* slow_path) {
1038 InvokeRuntime(GetThreadOffset<kMipsWordSize>(entrypoint).Int32Value(),
1039 instruction,
1040 dex_pc,
1041 slow_path,
1042 IsDirectEntrypoint(entrypoint));
1043}
1044
1045constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16;
1046
1047void CodeGeneratorMIPS::InvokeRuntime(int32_t entry_point_offset,
1048 HInstruction* instruction,
1049 uint32_t dex_pc,
1050 SlowPathCode* slow_path,
1051 bool is_direct_entrypoint) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001052 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
1053 __ Jalr(T9);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001054 if (is_direct_entrypoint) {
1055 // Reserve argument space on stack (for $a0-$a3) for
1056 // entrypoints that directly reference native implementations.
1057 // Called function may use this space to store $a0-$a3 regs.
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001058 __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001059 __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001060 } else {
1061 __ Nop(); // In delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001062 }
1063 RecordPcInfo(instruction, dex_pc, slow_path);
1064}
1065
1066void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path,
1067 Register class_reg) {
1068 __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
1069 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
1070 __ Blt(TMP, AT, slow_path->GetEntryLabel());
1071 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
1072 __ Sync(0);
1073 __ Bind(slow_path->GetExitLabel());
1074}
1075
1076void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1077 __ Sync(0); // Only stype 0 is supported.
1078}
1079
1080void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction,
1081 HBasicBlock* successor) {
1082 SuspendCheckSlowPathMIPS* slow_path =
1083 new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor);
1084 codegen_->AddSlowPath(slow_path);
1085
1086 __ LoadFromOffset(kLoadUnsignedHalfword,
1087 TMP,
1088 TR,
1089 Thread::ThreadFlagsOffset<kMipsWordSize>().Int32Value());
1090 if (successor == nullptr) {
1091 __ Bnez(TMP, slow_path->GetEntryLabel());
1092 __ Bind(slow_path->GetReturnLabel());
1093 } else {
1094 __ Beqz(TMP, codegen_->GetLabelOf(successor));
1095 __ B(slow_path->GetEntryLabel());
1096 // slow_path will return to GetLabelOf(successor).
1097 }
1098}
1099
1100InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph,
1101 CodeGeneratorMIPS* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001102 : InstructionCodeGenerator(graph, codegen),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001103 assembler_(codegen->GetAssembler()),
1104 codegen_(codegen) {}
1105
1106void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1107 DCHECK_EQ(instruction->InputCount(), 2U);
1108 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1109 Primitive::Type type = instruction->GetResultType();
1110 switch (type) {
1111 case Primitive::kPrimInt: {
1112 locations->SetInAt(0, Location::RequiresRegister());
1113 HInstruction* right = instruction->InputAt(1);
1114 bool can_use_imm = false;
1115 if (right->IsConstant()) {
1116 int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant());
1117 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1118 can_use_imm = IsUint<16>(imm);
1119 } else if (instruction->IsAdd()) {
1120 can_use_imm = IsInt<16>(imm);
1121 } else {
1122 DCHECK(instruction->IsSub());
1123 can_use_imm = IsInt<16>(-imm);
1124 }
1125 }
1126 if (can_use_imm)
1127 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1128 else
1129 locations->SetInAt(1, Location::RequiresRegister());
1130 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1131 break;
1132 }
1133
1134 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001135 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001136 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1137 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001138 break;
1139 }
1140
1141 case Primitive::kPrimFloat:
1142 case Primitive::kPrimDouble:
1143 DCHECK(instruction->IsAdd() || instruction->IsSub());
1144 locations->SetInAt(0, Location::RequiresFpuRegister());
1145 locations->SetInAt(1, Location::RequiresFpuRegister());
1146 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1147 break;
1148
1149 default:
1150 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1151 }
1152}
1153
1154void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1155 Primitive::Type type = instruction->GetType();
1156 LocationSummary* locations = instruction->GetLocations();
1157
1158 switch (type) {
1159 case Primitive::kPrimInt: {
1160 Register dst = locations->Out().AsRegister<Register>();
1161 Register lhs = locations->InAt(0).AsRegister<Register>();
1162 Location rhs_location = locations->InAt(1);
1163
1164 Register rhs_reg = ZERO;
1165 int32_t rhs_imm = 0;
1166 bool use_imm = rhs_location.IsConstant();
1167 if (use_imm) {
1168 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
1169 } else {
1170 rhs_reg = rhs_location.AsRegister<Register>();
1171 }
1172
1173 if (instruction->IsAnd()) {
1174 if (use_imm)
1175 __ Andi(dst, lhs, rhs_imm);
1176 else
1177 __ And(dst, lhs, rhs_reg);
1178 } else if (instruction->IsOr()) {
1179 if (use_imm)
1180 __ Ori(dst, lhs, rhs_imm);
1181 else
1182 __ Or(dst, lhs, rhs_reg);
1183 } else if (instruction->IsXor()) {
1184 if (use_imm)
1185 __ Xori(dst, lhs, rhs_imm);
1186 else
1187 __ Xor(dst, lhs, rhs_reg);
1188 } else if (instruction->IsAdd()) {
1189 if (use_imm)
1190 __ Addiu(dst, lhs, rhs_imm);
1191 else
1192 __ Addu(dst, lhs, rhs_reg);
1193 } else {
1194 DCHECK(instruction->IsSub());
1195 if (use_imm)
1196 __ Addiu(dst, lhs, -rhs_imm);
1197 else
1198 __ Subu(dst, lhs, rhs_reg);
1199 }
1200 break;
1201 }
1202
1203 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001204 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1205 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1206 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1207 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001208 Location rhs_location = locations->InAt(1);
1209 bool use_imm = rhs_location.IsConstant();
1210 if (!use_imm) {
1211 Register rhs_high = rhs_location.AsRegisterPairHigh<Register>();
1212 Register rhs_low = rhs_location.AsRegisterPairLow<Register>();
1213 if (instruction->IsAnd()) {
1214 __ And(dst_low, lhs_low, rhs_low);
1215 __ And(dst_high, lhs_high, rhs_high);
1216 } else if (instruction->IsOr()) {
1217 __ Or(dst_low, lhs_low, rhs_low);
1218 __ Or(dst_high, lhs_high, rhs_high);
1219 } else if (instruction->IsXor()) {
1220 __ Xor(dst_low, lhs_low, rhs_low);
1221 __ Xor(dst_high, lhs_high, rhs_high);
1222 } else if (instruction->IsAdd()) {
1223 if (lhs_low == rhs_low) {
1224 // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs.
1225 __ Slt(TMP, lhs_low, ZERO);
1226 __ Addu(dst_low, lhs_low, rhs_low);
1227 } else {
1228 __ Addu(dst_low, lhs_low, rhs_low);
1229 // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged.
1230 __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low);
1231 }
1232 __ Addu(dst_high, lhs_high, rhs_high);
1233 __ Addu(dst_high, dst_high, TMP);
1234 } else {
1235 DCHECK(instruction->IsSub());
1236 __ Sltu(TMP, lhs_low, rhs_low);
1237 __ Subu(dst_low, lhs_low, rhs_low);
1238 __ Subu(dst_high, lhs_high, rhs_high);
1239 __ Subu(dst_high, dst_high, TMP);
1240 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001241 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001242 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
1243 if (instruction->IsOr()) {
1244 uint32_t low = Low32Bits(value);
1245 uint32_t high = High32Bits(value);
1246 if (IsUint<16>(low)) {
1247 if (dst_low != lhs_low || low != 0) {
1248 __ Ori(dst_low, lhs_low, low);
1249 }
1250 } else {
1251 __ LoadConst32(TMP, low);
1252 __ Or(dst_low, lhs_low, TMP);
1253 }
1254 if (IsUint<16>(high)) {
1255 if (dst_high != lhs_high || high != 0) {
1256 __ Ori(dst_high, lhs_high, high);
1257 }
1258 } else {
1259 if (high != low) {
1260 __ LoadConst32(TMP, high);
1261 }
1262 __ Or(dst_high, lhs_high, TMP);
1263 }
1264 } else if (instruction->IsXor()) {
1265 uint32_t low = Low32Bits(value);
1266 uint32_t high = High32Bits(value);
1267 if (IsUint<16>(low)) {
1268 if (dst_low != lhs_low || low != 0) {
1269 __ Xori(dst_low, lhs_low, low);
1270 }
1271 } else {
1272 __ LoadConst32(TMP, low);
1273 __ Xor(dst_low, lhs_low, TMP);
1274 }
1275 if (IsUint<16>(high)) {
1276 if (dst_high != lhs_high || high != 0) {
1277 __ Xori(dst_high, lhs_high, high);
1278 }
1279 } else {
1280 if (high != low) {
1281 __ LoadConst32(TMP, high);
1282 }
1283 __ Xor(dst_high, lhs_high, TMP);
1284 }
1285 } else if (instruction->IsAnd()) {
1286 uint32_t low = Low32Bits(value);
1287 uint32_t high = High32Bits(value);
1288 if (IsUint<16>(low)) {
1289 __ Andi(dst_low, lhs_low, low);
1290 } else if (low != 0xFFFFFFFF) {
1291 __ LoadConst32(TMP, low);
1292 __ And(dst_low, lhs_low, TMP);
1293 } else if (dst_low != lhs_low) {
1294 __ Move(dst_low, lhs_low);
1295 }
1296 if (IsUint<16>(high)) {
1297 __ Andi(dst_high, lhs_high, high);
1298 } else if (high != 0xFFFFFFFF) {
1299 if (high != low) {
1300 __ LoadConst32(TMP, high);
1301 }
1302 __ And(dst_high, lhs_high, TMP);
1303 } else if (dst_high != lhs_high) {
1304 __ Move(dst_high, lhs_high);
1305 }
1306 } else {
1307 if (instruction->IsSub()) {
1308 value = -value;
1309 } else {
1310 DCHECK(instruction->IsAdd());
1311 }
1312 int32_t low = Low32Bits(value);
1313 int32_t high = High32Bits(value);
1314 if (IsInt<16>(low)) {
1315 if (dst_low != lhs_low || low != 0) {
1316 __ Addiu(dst_low, lhs_low, low);
1317 }
1318 if (low != 0) {
1319 __ Sltiu(AT, dst_low, low);
1320 }
1321 } else {
1322 __ LoadConst32(TMP, low);
1323 __ Addu(dst_low, lhs_low, TMP);
1324 __ Sltu(AT, dst_low, TMP);
1325 }
1326 if (IsInt<16>(high)) {
1327 if (dst_high != lhs_high || high != 0) {
1328 __ Addiu(dst_high, lhs_high, high);
1329 }
1330 } else {
1331 if (high != low) {
1332 __ LoadConst32(TMP, high);
1333 }
1334 __ Addu(dst_high, lhs_high, TMP);
1335 }
1336 if (low != 0) {
1337 __ Addu(dst_high, dst_high, AT);
1338 }
1339 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001340 }
1341 break;
1342 }
1343
1344 case Primitive::kPrimFloat:
1345 case Primitive::kPrimDouble: {
1346 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
1347 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
1348 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
1349 if (instruction->IsAdd()) {
1350 if (type == Primitive::kPrimFloat) {
1351 __ AddS(dst, lhs, rhs);
1352 } else {
1353 __ AddD(dst, lhs, rhs);
1354 }
1355 } else {
1356 DCHECK(instruction->IsSub());
1357 if (type == Primitive::kPrimFloat) {
1358 __ SubS(dst, lhs, rhs);
1359 } else {
1360 __ SubD(dst, lhs, rhs);
1361 }
1362 }
1363 break;
1364 }
1365
1366 default:
1367 LOG(FATAL) << "Unexpected binary operation type " << type;
1368 }
1369}
1370
1371void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001372 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001373
1374 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1375 Primitive::Type type = instr->GetResultType();
1376 switch (type) {
1377 case Primitive::kPrimInt:
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001378 locations->SetInAt(0, Location::RequiresRegister());
1379 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1380 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1381 break;
1382 case Primitive::kPrimLong:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001383 locations->SetInAt(0, Location::RequiresRegister());
1384 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1385 locations->SetOut(Location::RequiresRegister());
1386 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001387 default:
1388 LOG(FATAL) << "Unexpected shift type " << type;
1389 }
1390}
1391
1392static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte;
1393
1394void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001395 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001396 LocationSummary* locations = instr->GetLocations();
1397 Primitive::Type type = instr->GetType();
1398
1399 Location rhs_location = locations->InAt(1);
1400 bool use_imm = rhs_location.IsConstant();
1401 Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>();
1402 int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0;
Roland Levillain5b5b9312016-03-22 14:57:31 +00001403 const uint32_t shift_mask =
1404 (type == Primitive::kPrimInt) ? kMaxIntShiftDistance : kMaxLongShiftDistance;
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001405 const uint32_t shift_value = rhs_imm & shift_mask;
Alexey Frunze92d90602015-12-18 18:16:36 -08001406 // Are the INS (Insert Bit Field) and ROTR instructions supported?
1407 bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001408
1409 switch (type) {
1410 case Primitive::kPrimInt: {
1411 Register dst = locations->Out().AsRegister<Register>();
1412 Register lhs = locations->InAt(0).AsRegister<Register>();
1413 if (use_imm) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001414 if (shift_value == 0) {
1415 if (dst != lhs) {
1416 __ Move(dst, lhs);
1417 }
1418 } else if (instr->IsShl()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001419 __ Sll(dst, lhs, shift_value);
1420 } else if (instr->IsShr()) {
1421 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001422 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001423 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001424 } else {
1425 if (has_ins_rotr) {
1426 __ Rotr(dst, lhs, shift_value);
1427 } else {
1428 __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask);
1429 __ Srl(dst, lhs, shift_value);
1430 __ Or(dst, dst, TMP);
1431 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001432 }
1433 } else {
1434 if (instr->IsShl()) {
1435 __ Sllv(dst, lhs, rhs_reg);
1436 } else if (instr->IsShr()) {
1437 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001438 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001439 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001440 } else {
1441 if (has_ins_rotr) {
1442 __ Rotrv(dst, lhs, rhs_reg);
1443 } else {
1444 __ Subu(TMP, ZERO, rhs_reg);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001445 // 32-bit shift instructions use the 5 least significant bits of the shift count, so
1446 // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case
1447 // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out
1448 // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`,
1449 // IOW, the OR'd values are equal.
Alexey Frunze92d90602015-12-18 18:16:36 -08001450 __ Sllv(TMP, lhs, TMP);
1451 __ Srlv(dst, lhs, rhs_reg);
1452 __ Or(dst, dst, TMP);
1453 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001454 }
1455 }
1456 break;
1457 }
1458
1459 case Primitive::kPrimLong: {
1460 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1461 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1462 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1463 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
1464 if (use_imm) {
1465 if (shift_value == 0) {
1466 codegen_->Move64(locations->Out(), locations->InAt(0));
1467 } else if (shift_value < kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001468 if (has_ins_rotr) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001469 if (instr->IsShl()) {
1470 __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1471 __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value);
1472 __ Sll(dst_low, lhs_low, shift_value);
1473 } else if (instr->IsShr()) {
1474 __ Srl(dst_low, lhs_low, shift_value);
1475 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1476 __ Sra(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001477 } else if (instr->IsUShr()) {
1478 __ Srl(dst_low, lhs_low, shift_value);
1479 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1480 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001481 } else {
1482 __ Srl(dst_low, lhs_low, shift_value);
1483 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1484 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001485 __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001486 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001487 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001488 if (instr->IsShl()) {
1489 __ Sll(dst_low, lhs_low, shift_value);
1490 __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value);
1491 __ Sll(dst_high, lhs_high, shift_value);
1492 __ Or(dst_high, dst_high, TMP);
1493 } else if (instr->IsShr()) {
1494 __ Sra(dst_high, lhs_high, shift_value);
1495 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1496 __ Srl(dst_low, lhs_low, shift_value);
1497 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001498 } else if (instr->IsUShr()) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001499 __ Srl(dst_high, lhs_high, shift_value);
1500 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1501 __ Srl(dst_low, lhs_low, shift_value);
1502 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001503 } else {
1504 __ Srl(TMP, lhs_low, shift_value);
1505 __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value);
1506 __ Or(dst_low, dst_low, TMP);
1507 __ Srl(TMP, lhs_high, shift_value);
1508 __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1509 __ Or(dst_high, dst_high, TMP);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001510 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001511 }
1512 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001513 const uint32_t shift_value_high = shift_value - kMipsBitsPerWord;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001514 if (instr->IsShl()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001515 __ Sll(dst_high, lhs_low, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001516 __ Move(dst_low, ZERO);
1517 } else if (instr->IsShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001518 __ Sra(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001519 __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1);
Alexey Frunze92d90602015-12-18 18:16:36 -08001520 } else if (instr->IsUShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001521 __ Srl(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001522 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001523 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001524 if (shift_value == kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001525 // 64-bit rotation by 32 is just a swap.
1526 __ Move(dst_low, lhs_high);
1527 __ Move(dst_high, lhs_low);
1528 } else {
1529 if (has_ins_rotr) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001530 __ Srl(dst_low, lhs_high, shift_value_high);
1531 __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high);
1532 __ Srl(dst_high, lhs_low, shift_value_high);
1533 __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001534 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001535 __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high);
1536 __ Srl(dst_low, lhs_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001537 __ Or(dst_low, dst_low, TMP);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001538 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high);
1539 __ Srl(dst_high, lhs_low, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001540 __ Or(dst_high, dst_high, TMP);
1541 }
1542 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001543 }
1544 }
1545 } else {
1546 MipsLabel done;
1547 if (instr->IsShl()) {
1548 __ Sllv(dst_low, lhs_low, rhs_reg);
1549 __ Nor(AT, ZERO, rhs_reg);
1550 __ Srl(TMP, lhs_low, 1);
1551 __ Srlv(TMP, TMP, AT);
1552 __ Sllv(dst_high, lhs_high, rhs_reg);
1553 __ Or(dst_high, dst_high, TMP);
1554 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1555 __ Beqz(TMP, &done);
1556 __ Move(dst_high, dst_low);
1557 __ Move(dst_low, ZERO);
1558 } else if (instr->IsShr()) {
1559 __ Srav(dst_high, lhs_high, rhs_reg);
1560 __ Nor(AT, ZERO, rhs_reg);
1561 __ Sll(TMP, lhs_high, 1);
1562 __ Sllv(TMP, TMP, AT);
1563 __ Srlv(dst_low, lhs_low, rhs_reg);
1564 __ Or(dst_low, dst_low, TMP);
1565 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1566 __ Beqz(TMP, &done);
1567 __ Move(dst_low, dst_high);
1568 __ Sra(dst_high, dst_high, 31);
Alexey Frunze92d90602015-12-18 18:16:36 -08001569 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001570 __ Srlv(dst_high, lhs_high, rhs_reg);
1571 __ Nor(AT, ZERO, rhs_reg);
1572 __ Sll(TMP, lhs_high, 1);
1573 __ Sllv(TMP, TMP, AT);
1574 __ Srlv(dst_low, lhs_low, rhs_reg);
1575 __ Or(dst_low, dst_low, TMP);
1576 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1577 __ Beqz(TMP, &done);
1578 __ Move(dst_low, dst_high);
1579 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001580 } else {
1581 __ Nor(AT, ZERO, rhs_reg);
1582 __ Srlv(TMP, lhs_low, rhs_reg);
1583 __ Sll(dst_low, lhs_high, 1);
1584 __ Sllv(dst_low, dst_low, AT);
1585 __ Or(dst_low, dst_low, TMP);
1586 __ Srlv(TMP, lhs_high, rhs_reg);
1587 __ Sll(dst_high, lhs_low, 1);
1588 __ Sllv(dst_high, dst_high, AT);
1589 __ Or(dst_high, dst_high, TMP);
1590 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1591 __ Beqz(TMP, &done);
1592 __ Move(TMP, dst_high);
1593 __ Move(dst_high, dst_low);
1594 __ Move(dst_low, TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001595 }
1596 __ Bind(&done);
1597 }
1598 break;
1599 }
1600
1601 default:
1602 LOG(FATAL) << "Unexpected shift operation type " << type;
1603 }
1604}
1605
1606void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) {
1607 HandleBinaryOp(instruction);
1608}
1609
1610void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) {
1611 HandleBinaryOp(instruction);
1612}
1613
1614void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) {
1615 HandleBinaryOp(instruction);
1616}
1617
1618void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) {
1619 HandleBinaryOp(instruction);
1620}
1621
1622void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) {
1623 LocationSummary* locations =
1624 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1625 locations->SetInAt(0, Location::RequiresRegister());
1626 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1627 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1628 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1629 } else {
1630 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1631 }
1632}
1633
1634void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) {
1635 LocationSummary* locations = instruction->GetLocations();
1636 Register obj = locations->InAt(0).AsRegister<Register>();
1637 Location index = locations->InAt(1);
1638 Primitive::Type type = instruction->GetType();
1639
1640 switch (type) {
1641 case Primitive::kPrimBoolean: {
1642 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1643 Register out = locations->Out().AsRegister<Register>();
1644 if (index.IsConstant()) {
1645 size_t offset =
1646 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1647 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1648 } else {
1649 __ Addu(TMP, obj, index.AsRegister<Register>());
1650 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset);
1651 }
1652 break;
1653 }
1654
1655 case Primitive::kPrimByte: {
1656 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
1657 Register out = locations->Out().AsRegister<Register>();
1658 if (index.IsConstant()) {
1659 size_t offset =
1660 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1661 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1662 } else {
1663 __ Addu(TMP, obj, index.AsRegister<Register>());
1664 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset);
1665 }
1666 break;
1667 }
1668
1669 case Primitive::kPrimShort: {
1670 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
1671 Register out = locations->Out().AsRegister<Register>();
1672 if (index.IsConstant()) {
1673 size_t offset =
1674 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1675 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1676 } else {
1677 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1678 __ Addu(TMP, obj, TMP);
1679 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset);
1680 }
1681 break;
1682 }
1683
1684 case Primitive::kPrimChar: {
1685 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
1686 Register out = locations->Out().AsRegister<Register>();
1687 if (index.IsConstant()) {
1688 size_t offset =
1689 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1690 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1691 } else {
1692 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1693 __ Addu(TMP, obj, TMP);
1694 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset);
1695 }
1696 break;
1697 }
1698
1699 case Primitive::kPrimInt:
1700 case Primitive::kPrimNot: {
1701 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1702 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
1703 Register out = locations->Out().AsRegister<Register>();
1704 if (index.IsConstant()) {
1705 size_t offset =
1706 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1707 __ LoadFromOffset(kLoadWord, out, obj, offset);
1708 } else {
1709 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1710 __ Addu(TMP, obj, TMP);
1711 __ LoadFromOffset(kLoadWord, out, TMP, data_offset);
1712 }
1713 break;
1714 }
1715
1716 case Primitive::kPrimLong: {
1717 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
1718 Register out = locations->Out().AsRegisterPairLow<Register>();
1719 if (index.IsConstant()) {
1720 size_t offset =
1721 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1722 __ LoadFromOffset(kLoadDoubleword, out, obj, offset);
1723 } else {
1724 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1725 __ Addu(TMP, obj, TMP);
1726 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset);
1727 }
1728 break;
1729 }
1730
1731 case Primitive::kPrimFloat: {
1732 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
1733 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1734 if (index.IsConstant()) {
1735 size_t offset =
1736 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1737 __ LoadSFromOffset(out, obj, offset);
1738 } else {
1739 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1740 __ Addu(TMP, obj, TMP);
1741 __ LoadSFromOffset(out, TMP, data_offset);
1742 }
1743 break;
1744 }
1745
1746 case Primitive::kPrimDouble: {
1747 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
1748 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1749 if (index.IsConstant()) {
1750 size_t offset =
1751 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1752 __ LoadDFromOffset(out, obj, offset);
1753 } else {
1754 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1755 __ Addu(TMP, obj, TMP);
1756 __ LoadDFromOffset(out, TMP, data_offset);
1757 }
1758 break;
1759 }
1760
1761 case Primitive::kPrimVoid:
1762 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1763 UNREACHABLE();
1764 }
1765 codegen_->MaybeRecordImplicitNullCheck(instruction);
1766}
1767
1768void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) {
1769 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1770 locations->SetInAt(0, Location::RequiresRegister());
1771 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1772}
1773
1774void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) {
1775 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01001776 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001777 Register obj = locations->InAt(0).AsRegister<Register>();
1778 Register out = locations->Out().AsRegister<Register>();
1779 __ LoadFromOffset(kLoadWord, out, obj, offset);
1780 codegen_->MaybeRecordImplicitNullCheck(instruction);
1781}
1782
1783void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) {
Pavle Batuta934808f2015-11-03 13:23:54 +01001784 bool needs_runtime_call = instruction->NeedsTypeCheck();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001785 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1786 instruction,
Pavle Batuta934808f2015-11-03 13:23:54 +01001787 needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
1788 if (needs_runtime_call) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001789 InvokeRuntimeCallingConvention calling_convention;
1790 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1791 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1792 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1793 } else {
1794 locations->SetInAt(0, Location::RequiresRegister());
1795 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1796 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
1797 locations->SetInAt(2, Location::RequiresFpuRegister());
1798 } else {
1799 locations->SetInAt(2, Location::RequiresRegister());
1800 }
1801 }
1802}
1803
1804void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) {
1805 LocationSummary* locations = instruction->GetLocations();
1806 Register obj = locations->InAt(0).AsRegister<Register>();
1807 Location index = locations->InAt(1);
1808 Primitive::Type value_type = instruction->GetComponentType();
1809 bool needs_runtime_call = locations->WillCall();
1810 bool needs_write_barrier =
1811 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
1812
1813 switch (value_type) {
1814 case Primitive::kPrimBoolean:
1815 case Primitive::kPrimByte: {
1816 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1817 Register value = locations->InAt(2).AsRegister<Register>();
1818 if (index.IsConstant()) {
1819 size_t offset =
1820 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1821 __ StoreToOffset(kStoreByte, value, obj, offset);
1822 } else {
1823 __ Addu(TMP, obj, index.AsRegister<Register>());
1824 __ StoreToOffset(kStoreByte, value, TMP, data_offset);
1825 }
1826 break;
1827 }
1828
1829 case Primitive::kPrimShort:
1830 case Primitive::kPrimChar: {
1831 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
1832 Register value = locations->InAt(2).AsRegister<Register>();
1833 if (index.IsConstant()) {
1834 size_t offset =
1835 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1836 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1837 } else {
1838 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1839 __ Addu(TMP, obj, TMP);
1840 __ StoreToOffset(kStoreHalfword, value, TMP, data_offset);
1841 }
1842 break;
1843 }
1844
1845 case Primitive::kPrimInt:
1846 case Primitive::kPrimNot: {
1847 if (!needs_runtime_call) {
1848 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
1849 Register value = locations->InAt(2).AsRegister<Register>();
1850 if (index.IsConstant()) {
1851 size_t offset =
1852 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1853 __ StoreToOffset(kStoreWord, value, obj, offset);
1854 } else {
1855 DCHECK(index.IsRegister()) << index;
1856 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1857 __ Addu(TMP, obj, TMP);
1858 __ StoreToOffset(kStoreWord, value, TMP, data_offset);
1859 }
1860 codegen_->MaybeRecordImplicitNullCheck(instruction);
1861 if (needs_write_barrier) {
1862 DCHECK_EQ(value_type, Primitive::kPrimNot);
1863 codegen_->MarkGCCard(obj, value);
1864 }
1865 } else {
1866 DCHECK_EQ(value_type, Primitive::kPrimNot);
1867 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
1868 instruction,
1869 instruction->GetDexPc(),
1870 nullptr,
1871 IsDirectEntrypoint(kQuickAputObject));
1872 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
1873 }
1874 break;
1875 }
1876
1877 case Primitive::kPrimLong: {
1878 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
1879 Register value = locations->InAt(2).AsRegisterPairLow<Register>();
1880 if (index.IsConstant()) {
1881 size_t offset =
1882 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1883 __ StoreToOffset(kStoreDoubleword, value, obj, offset);
1884 } else {
1885 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1886 __ Addu(TMP, obj, TMP);
1887 __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset);
1888 }
1889 break;
1890 }
1891
1892 case Primitive::kPrimFloat: {
1893 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
1894 FRegister value = locations->InAt(2).AsFpuRegister<FRegister>();
1895 DCHECK(locations->InAt(2).IsFpuRegister());
1896 if (index.IsConstant()) {
1897 size_t offset =
1898 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1899 __ StoreSToOffset(value, obj, offset);
1900 } else {
1901 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1902 __ Addu(TMP, obj, TMP);
1903 __ StoreSToOffset(value, TMP, data_offset);
1904 }
1905 break;
1906 }
1907
1908 case Primitive::kPrimDouble: {
1909 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
1910 FRegister value = locations->InAt(2).AsFpuRegister<FRegister>();
1911 DCHECK(locations->InAt(2).IsFpuRegister());
1912 if (index.IsConstant()) {
1913 size_t offset =
1914 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1915 __ StoreDToOffset(value, obj, offset);
1916 } else {
1917 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1918 __ Addu(TMP, obj, TMP);
1919 __ StoreDToOffset(value, TMP, data_offset);
1920 }
1921 break;
1922 }
1923
1924 case Primitive::kPrimVoid:
1925 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1926 UNREACHABLE();
1927 }
1928
1929 // Ints and objects are handled in the switch.
1930 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
1931 codegen_->MaybeRecordImplicitNullCheck(instruction);
1932 }
1933}
1934
1935void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
1936 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
1937 ? LocationSummary::kCallOnSlowPath
1938 : LocationSummary::kNoCall;
1939 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
1940 locations->SetInAt(0, Location::RequiresRegister());
1941 locations->SetInAt(1, Location::RequiresRegister());
1942 if (instruction->HasUses()) {
1943 locations->SetOut(Location::SameAsFirstInput());
1944 }
1945}
1946
1947void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
1948 LocationSummary* locations = instruction->GetLocations();
1949 BoundsCheckSlowPathMIPS* slow_path =
1950 new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction);
1951 codegen_->AddSlowPath(slow_path);
1952
1953 Register index = locations->InAt(0).AsRegister<Register>();
1954 Register length = locations->InAt(1).AsRegister<Register>();
1955
1956 // length is limited by the maximum positive signed 32-bit integer.
1957 // Unsigned comparison of length and index checks for index < 0
1958 // and for length <= index simultaneously.
1959 __ Bgeu(index, length, slow_path->GetEntryLabel());
1960}
1961
1962void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) {
1963 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1964 instruction,
1965 LocationSummary::kCallOnSlowPath);
1966 locations->SetInAt(0, Location::RequiresRegister());
1967 locations->SetInAt(1, Location::RequiresRegister());
1968 // Note that TypeCheckSlowPathMIPS uses this register too.
1969 locations->AddTemp(Location::RequiresRegister());
1970}
1971
1972void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) {
1973 LocationSummary* locations = instruction->GetLocations();
1974 Register obj = locations->InAt(0).AsRegister<Register>();
1975 Register cls = locations->InAt(1).AsRegister<Register>();
1976 Register obj_cls = locations->GetTemp(0).AsRegister<Register>();
1977
1978 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction);
1979 codegen_->AddSlowPath(slow_path);
1980
1981 // TODO: avoid this check if we know obj is not null.
1982 __ Beqz(obj, slow_path->GetExitLabel());
1983 // Compare the class of `obj` with `cls`.
1984 __ LoadFromOffset(kLoadWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value());
1985 __ Bne(obj_cls, cls, slow_path->GetEntryLabel());
1986 __ Bind(slow_path->GetExitLabel());
1987}
1988
1989void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) {
1990 LocationSummary* locations =
1991 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1992 locations->SetInAt(0, Location::RequiresRegister());
1993 if (check->HasUses()) {
1994 locations->SetOut(Location::SameAsFirstInput());
1995 }
1996}
1997
1998void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) {
1999 // We assume the class is not null.
2000 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS(
2001 check->GetLoadClass(),
2002 check,
2003 check->GetDexPc(),
2004 true);
2005 codegen_->AddSlowPath(slow_path);
2006 GenerateClassInitializationCheck(slow_path,
2007 check->GetLocations()->InAt(0).AsRegister<Register>());
2008}
2009
2010void LocationsBuilderMIPS::VisitCompare(HCompare* compare) {
2011 Primitive::Type in_type = compare->InputAt(0)->GetType();
2012
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002013 LocationSummary* locations =
2014 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002015
2016 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002017 case Primitive::kPrimBoolean:
2018 case Primitive::kPrimByte:
2019 case Primitive::kPrimShort:
2020 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002021 case Primitive::kPrimInt:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002022 case Primitive::kPrimLong:
2023 locations->SetInAt(0, Location::RequiresRegister());
2024 locations->SetInAt(1, Location::RequiresRegister());
2025 // Output overlaps because it is written before doing the low comparison.
2026 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2027 break;
2028
2029 case Primitive::kPrimFloat:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002030 case Primitive::kPrimDouble:
2031 locations->SetInAt(0, Location::RequiresFpuRegister());
2032 locations->SetInAt(1, Location::RequiresFpuRegister());
2033 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002034 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002035
2036 default:
2037 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
2038 }
2039}
2040
2041void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) {
2042 LocationSummary* locations = instruction->GetLocations();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002043 Register res = locations->Out().AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002044 Primitive::Type in_type = instruction->InputAt(0)->GetType();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002045 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002046
2047 // 0 if: left == right
2048 // 1 if: left > right
2049 // -1 if: left < right
2050 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002051 case Primitive::kPrimBoolean:
2052 case Primitive::kPrimByte:
2053 case Primitive::kPrimShort:
2054 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002055 case Primitive::kPrimInt: {
2056 Register lhs = locations->InAt(0).AsRegister<Register>();
2057 Register rhs = locations->InAt(1).AsRegister<Register>();
2058 __ Slt(TMP, lhs, rhs);
2059 __ Slt(res, rhs, lhs);
2060 __ Subu(res, res, TMP);
2061 break;
2062 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002063 case Primitive::kPrimLong: {
2064 MipsLabel done;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002065 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2066 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
2067 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
2068 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
2069 // TODO: more efficient (direct) comparison with a constant.
2070 __ Slt(TMP, lhs_high, rhs_high);
2071 __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt.
2072 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2073 __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal.
2074 __ Sltu(TMP, lhs_low, rhs_low);
2075 __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt.
2076 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2077 __ Bind(&done);
2078 break;
2079 }
2080
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002081 case Primitive::kPrimFloat: {
Roland Levillain32ca3752016-02-17 16:49:37 +00002082 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002083 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2084 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2085 MipsLabel done;
2086 if (isR6) {
2087 __ CmpEqS(FTMP, lhs, rhs);
2088 __ LoadConst32(res, 0);
2089 __ Bc1nez(FTMP, &done);
2090 if (gt_bias) {
2091 __ CmpLtS(FTMP, lhs, rhs);
2092 __ LoadConst32(res, -1);
2093 __ Bc1nez(FTMP, &done);
2094 __ LoadConst32(res, 1);
2095 } else {
2096 __ CmpLtS(FTMP, rhs, lhs);
2097 __ LoadConst32(res, 1);
2098 __ Bc1nez(FTMP, &done);
2099 __ LoadConst32(res, -1);
2100 }
2101 } else {
2102 if (gt_bias) {
2103 __ ColtS(0, lhs, rhs);
2104 __ LoadConst32(res, -1);
2105 __ Bc1t(0, &done);
2106 __ CeqS(0, lhs, rhs);
2107 __ LoadConst32(res, 1);
2108 __ Movt(res, ZERO, 0);
2109 } else {
2110 __ ColtS(0, rhs, lhs);
2111 __ LoadConst32(res, 1);
2112 __ Bc1t(0, &done);
2113 __ CeqS(0, lhs, rhs);
2114 __ LoadConst32(res, -1);
2115 __ Movt(res, ZERO, 0);
2116 }
2117 }
2118 __ Bind(&done);
2119 break;
2120 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002121 case Primitive::kPrimDouble: {
Roland Levillain32ca3752016-02-17 16:49:37 +00002122 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002123 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2124 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2125 MipsLabel done;
2126 if (isR6) {
2127 __ CmpEqD(FTMP, lhs, rhs);
2128 __ LoadConst32(res, 0);
2129 __ Bc1nez(FTMP, &done);
2130 if (gt_bias) {
2131 __ CmpLtD(FTMP, lhs, rhs);
2132 __ LoadConst32(res, -1);
2133 __ Bc1nez(FTMP, &done);
2134 __ LoadConst32(res, 1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002135 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002136 __ CmpLtD(FTMP, rhs, lhs);
2137 __ LoadConst32(res, 1);
2138 __ Bc1nez(FTMP, &done);
2139 __ LoadConst32(res, -1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002140 }
2141 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002142 if (gt_bias) {
2143 __ ColtD(0, lhs, rhs);
2144 __ LoadConst32(res, -1);
2145 __ Bc1t(0, &done);
2146 __ CeqD(0, lhs, rhs);
2147 __ LoadConst32(res, 1);
2148 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002149 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002150 __ ColtD(0, rhs, lhs);
2151 __ LoadConst32(res, 1);
2152 __ Bc1t(0, &done);
2153 __ CeqD(0, lhs, rhs);
2154 __ LoadConst32(res, -1);
2155 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002156 }
2157 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002158 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002159 break;
2160 }
2161
2162 default:
2163 LOG(FATAL) << "Unimplemented compare type " << in_type;
2164 }
2165}
2166
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002167void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002168 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002169 switch (instruction->InputAt(0)->GetType()) {
2170 default:
2171 case Primitive::kPrimLong:
2172 locations->SetInAt(0, Location::RequiresRegister());
2173 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2174 break;
2175
2176 case Primitive::kPrimFloat:
2177 case Primitive::kPrimDouble:
2178 locations->SetInAt(0, Location::RequiresFpuRegister());
2179 locations->SetInAt(1, Location::RequiresFpuRegister());
2180 break;
2181 }
David Brazdilb3e773e2016-01-26 11:28:37 +00002182 if (!instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002183 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2184 }
2185}
2186
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002187void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00002188 if (instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002189 return;
2190 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002191
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002192 Primitive::Type type = instruction->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002193 LocationSummary* locations = instruction->GetLocations();
2194 Register dst = locations->Out().AsRegister<Register>();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002195 MipsLabel true_label;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002196
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002197 switch (type) {
2198 default:
2199 // Integer case.
2200 GenerateIntCompare(instruction->GetCondition(), locations);
2201 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002202
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002203 case Primitive::kPrimLong:
2204 // TODO: don't use branches.
2205 GenerateLongCompareAndBranch(instruction->GetCondition(), locations, &true_label);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002206 break;
2207
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002208 case Primitive::kPrimFloat:
2209 case Primitive::kPrimDouble:
2210 // TODO: don't use branches.
2211 GenerateFpCompareAndBranch(instruction->GetCondition(),
2212 instruction->IsGtBias(),
2213 type,
2214 locations,
2215 &true_label);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002216 break;
2217 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002218
2219 // Convert the branches into the result.
2220 MipsLabel done;
2221
2222 // False case: result = 0.
2223 __ LoadConst32(dst, 0);
2224 __ B(&done);
2225
2226 // True case: result = 1.
2227 __ Bind(&true_label);
2228 __ LoadConst32(dst, 1);
2229 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002230}
2231
Alexey Frunze7e99e052015-11-24 19:28:01 -08002232void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2233 DCHECK(instruction->IsDiv() || instruction->IsRem());
2234 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2235
2236 LocationSummary* locations = instruction->GetLocations();
2237 Location second = locations->InAt(1);
2238 DCHECK(second.IsConstant());
2239
2240 Register out = locations->Out().AsRegister<Register>();
2241 Register dividend = locations->InAt(0).AsRegister<Register>();
2242 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2243 DCHECK(imm == 1 || imm == -1);
2244
2245 if (instruction->IsRem()) {
2246 __ Move(out, ZERO);
2247 } else {
2248 if (imm == -1) {
2249 __ Subu(out, ZERO, dividend);
2250 } else if (out != dividend) {
2251 __ Move(out, dividend);
2252 }
2253 }
2254}
2255
2256void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2257 DCHECK(instruction->IsDiv() || instruction->IsRem());
2258 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2259
2260 LocationSummary* locations = instruction->GetLocations();
2261 Location second = locations->InAt(1);
2262 DCHECK(second.IsConstant());
2263
2264 Register out = locations->Out().AsRegister<Register>();
2265 Register dividend = locations->InAt(0).AsRegister<Register>();
2266 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002267 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Alexey Frunze7e99e052015-11-24 19:28:01 -08002268 int ctz_imm = CTZ(abs_imm);
2269
2270 if (instruction->IsDiv()) {
2271 if (ctz_imm == 1) {
2272 // Fast path for division by +/-2, which is very common.
2273 __ Srl(TMP, dividend, 31);
2274 } else {
2275 __ Sra(TMP, dividend, 31);
2276 __ Srl(TMP, TMP, 32 - ctz_imm);
2277 }
2278 __ Addu(out, dividend, TMP);
2279 __ Sra(out, out, ctz_imm);
2280 if (imm < 0) {
2281 __ Subu(out, ZERO, out);
2282 }
2283 } else {
2284 if (ctz_imm == 1) {
2285 // Fast path for modulo +/-2, which is very common.
2286 __ Sra(TMP, dividend, 31);
2287 __ Subu(out, dividend, TMP);
2288 __ Andi(out, out, 1);
2289 __ Addu(out, out, TMP);
2290 } else {
2291 __ Sra(TMP, dividend, 31);
2292 __ Srl(TMP, TMP, 32 - ctz_imm);
2293 __ Addu(out, dividend, TMP);
2294 if (IsUint<16>(abs_imm - 1)) {
2295 __ Andi(out, out, abs_imm - 1);
2296 } else {
2297 __ Sll(out, out, 32 - ctz_imm);
2298 __ Srl(out, out, 32 - ctz_imm);
2299 }
2300 __ Subu(out, out, TMP);
2301 }
2302 }
2303}
2304
2305void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2306 DCHECK(instruction->IsDiv() || instruction->IsRem());
2307 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2308
2309 LocationSummary* locations = instruction->GetLocations();
2310 Location second = locations->InAt(1);
2311 DCHECK(second.IsConstant());
2312
2313 Register out = locations->Out().AsRegister<Register>();
2314 Register dividend = locations->InAt(0).AsRegister<Register>();
2315 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2316
2317 int64_t magic;
2318 int shift;
2319 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2320
2321 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2322
2323 __ LoadConst32(TMP, magic);
2324 if (isR6) {
2325 __ MuhR6(TMP, dividend, TMP);
2326 } else {
2327 __ MultR2(dividend, TMP);
2328 __ Mfhi(TMP);
2329 }
2330 if (imm > 0 && magic < 0) {
2331 __ Addu(TMP, TMP, dividend);
2332 } else if (imm < 0 && magic > 0) {
2333 __ Subu(TMP, TMP, dividend);
2334 }
2335
2336 if (shift != 0) {
2337 __ Sra(TMP, TMP, shift);
2338 }
2339
2340 if (instruction->IsDiv()) {
2341 __ Sra(out, TMP, 31);
2342 __ Subu(out, TMP, out);
2343 } else {
2344 __ Sra(AT, TMP, 31);
2345 __ Subu(AT, TMP, AT);
2346 __ LoadConst32(TMP, imm);
2347 if (isR6) {
2348 __ MulR6(TMP, AT, TMP);
2349 } else {
2350 __ MulR2(TMP, AT, TMP);
2351 }
2352 __ Subu(out, dividend, TMP);
2353 }
2354}
2355
2356void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) {
2357 DCHECK(instruction->IsDiv() || instruction->IsRem());
2358 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2359
2360 LocationSummary* locations = instruction->GetLocations();
2361 Register out = locations->Out().AsRegister<Register>();
2362 Location second = locations->InAt(1);
2363
2364 if (second.IsConstant()) {
2365 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2366 if (imm == 0) {
2367 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2368 } else if (imm == 1 || imm == -1) {
2369 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002370 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002371 DivRemByPowerOfTwo(instruction);
2372 } else {
2373 DCHECK(imm <= -2 || imm >= 2);
2374 GenerateDivRemWithAnyConstant(instruction);
2375 }
2376 } else {
2377 Register dividend = locations->InAt(0).AsRegister<Register>();
2378 Register divisor = second.AsRegister<Register>();
2379 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2380 if (instruction->IsDiv()) {
2381 if (isR6) {
2382 __ DivR6(out, dividend, divisor);
2383 } else {
2384 __ DivR2(out, dividend, divisor);
2385 }
2386 } else {
2387 if (isR6) {
2388 __ ModR6(out, dividend, divisor);
2389 } else {
2390 __ ModR2(out, dividend, divisor);
2391 }
2392 }
2393 }
2394}
2395
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002396void LocationsBuilderMIPS::VisitDiv(HDiv* div) {
2397 Primitive::Type type = div->GetResultType();
2398 LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong)
2399 ? LocationSummary::kCall
2400 : LocationSummary::kNoCall;
2401
2402 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2403
2404 switch (type) {
2405 case Primitive::kPrimInt:
2406 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08002407 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002408 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2409 break;
2410
2411 case Primitive::kPrimLong: {
2412 InvokeRuntimeCallingConvention calling_convention;
2413 locations->SetInAt(0, Location::RegisterPairLocation(
2414 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2415 locations->SetInAt(1, Location::RegisterPairLocation(
2416 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2417 locations->SetOut(calling_convention.GetReturnLocation(type));
2418 break;
2419 }
2420
2421 case Primitive::kPrimFloat:
2422 case Primitive::kPrimDouble:
2423 locations->SetInAt(0, Location::RequiresFpuRegister());
2424 locations->SetInAt(1, Location::RequiresFpuRegister());
2425 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2426 break;
2427
2428 default:
2429 LOG(FATAL) << "Unexpected div type " << type;
2430 }
2431}
2432
2433void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) {
2434 Primitive::Type type = instruction->GetType();
2435 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002436
2437 switch (type) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002438 case Primitive::kPrimInt:
2439 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002440 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002441 case Primitive::kPrimLong: {
2442 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv),
2443 instruction,
2444 instruction->GetDexPc(),
2445 nullptr,
2446 IsDirectEntrypoint(kQuickLdiv));
2447 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
2448 break;
2449 }
2450 case Primitive::kPrimFloat:
2451 case Primitive::kPrimDouble: {
2452 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
2453 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2454 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2455 if (type == Primitive::kPrimFloat) {
2456 __ DivS(dst, lhs, rhs);
2457 } else {
2458 __ DivD(dst, lhs, rhs);
2459 }
2460 break;
2461 }
2462 default:
2463 LOG(FATAL) << "Unexpected div type " << type;
2464 }
2465}
2466
2467void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2468 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2469 ? LocationSummary::kCallOnSlowPath
2470 : LocationSummary::kNoCall;
2471 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2472 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
2473 if (instruction->HasUses()) {
2474 locations->SetOut(Location::SameAsFirstInput());
2475 }
2476}
2477
2478void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2479 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction);
2480 codegen_->AddSlowPath(slow_path);
2481 Location value = instruction->GetLocations()->InAt(0);
2482 Primitive::Type type = instruction->GetType();
2483
2484 switch (type) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00002485 case Primitive::kPrimBoolean:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002486 case Primitive::kPrimByte:
2487 case Primitive::kPrimChar:
2488 case Primitive::kPrimShort:
2489 case Primitive::kPrimInt: {
2490 if (value.IsConstant()) {
2491 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2492 __ B(slow_path->GetEntryLabel());
2493 } else {
2494 // A division by a non-null constant is valid. We don't need to perform
2495 // any check, so simply fall through.
2496 }
2497 } else {
2498 DCHECK(value.IsRegister()) << value;
2499 __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel());
2500 }
2501 break;
2502 }
2503 case Primitive::kPrimLong: {
2504 if (value.IsConstant()) {
2505 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2506 __ B(slow_path->GetEntryLabel());
2507 } else {
2508 // A division by a non-null constant is valid. We don't need to perform
2509 // any check, so simply fall through.
2510 }
2511 } else {
2512 DCHECK(value.IsRegisterPair()) << value;
2513 __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>());
2514 __ Beqz(TMP, slow_path->GetEntryLabel());
2515 }
2516 break;
2517 }
2518 default:
2519 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
2520 }
2521}
2522
2523void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) {
2524 LocationSummary* locations =
2525 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2526 locations->SetOut(Location::ConstantLocation(constant));
2527}
2528
2529void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
2530 // Will be generated at use site.
2531}
2532
2533void LocationsBuilderMIPS::VisitExit(HExit* exit) {
2534 exit->SetLocations(nullptr);
2535}
2536
2537void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
2538}
2539
2540void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) {
2541 LocationSummary* locations =
2542 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2543 locations->SetOut(Location::ConstantLocation(constant));
2544}
2545
2546void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
2547 // Will be generated at use site.
2548}
2549
2550void LocationsBuilderMIPS::VisitGoto(HGoto* got) {
2551 got->SetLocations(nullptr);
2552}
2553
2554void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) {
2555 DCHECK(!successor->IsExitBlock());
2556 HBasicBlock* block = got->GetBlock();
2557 HInstruction* previous = got->GetPrevious();
2558 HLoopInformation* info = block->GetLoopInformation();
2559
2560 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
2561 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
2562 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
2563 return;
2564 }
2565 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
2566 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
2567 }
2568 if (!codegen_->GoesToNextBlock(block, successor)) {
2569 __ B(codegen_->GetLabelOf(successor));
2570 }
2571}
2572
2573void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) {
2574 HandleGoto(got, got->GetSuccessor());
2575}
2576
2577void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2578 try_boundary->SetLocations(nullptr);
2579}
2580
2581void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2582 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
2583 if (!successor->IsExitBlock()) {
2584 HandleGoto(try_boundary, successor);
2585 }
2586}
2587
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002588void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond,
2589 LocationSummary* locations) {
2590 Register dst = locations->Out().AsRegister<Register>();
2591 Register lhs = locations->InAt(0).AsRegister<Register>();
2592 Location rhs_location = locations->InAt(1);
2593 Register rhs_reg = ZERO;
2594 int64_t rhs_imm = 0;
2595 bool use_imm = rhs_location.IsConstant();
2596 if (use_imm) {
2597 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2598 } else {
2599 rhs_reg = rhs_location.AsRegister<Register>();
2600 }
2601
2602 switch (cond) {
2603 case kCondEQ:
2604 case kCondNE:
2605 if (use_imm && IsUint<16>(rhs_imm)) {
2606 __ Xori(dst, lhs, rhs_imm);
2607 } else {
2608 if (use_imm) {
2609 rhs_reg = TMP;
2610 __ LoadConst32(rhs_reg, rhs_imm);
2611 }
2612 __ Xor(dst, lhs, rhs_reg);
2613 }
2614 if (cond == kCondEQ) {
2615 __ Sltiu(dst, dst, 1);
2616 } else {
2617 __ Sltu(dst, ZERO, dst);
2618 }
2619 break;
2620
2621 case kCondLT:
2622 case kCondGE:
2623 if (use_imm && IsInt<16>(rhs_imm)) {
2624 __ Slti(dst, lhs, rhs_imm);
2625 } else {
2626 if (use_imm) {
2627 rhs_reg = TMP;
2628 __ LoadConst32(rhs_reg, rhs_imm);
2629 }
2630 __ Slt(dst, lhs, rhs_reg);
2631 }
2632 if (cond == kCondGE) {
2633 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2634 // only the slt instruction but no sge.
2635 __ Xori(dst, dst, 1);
2636 }
2637 break;
2638
2639 case kCondLE:
2640 case kCondGT:
2641 if (use_imm && IsInt<16>(rhs_imm + 1)) {
2642 // Simulate lhs <= rhs via lhs < rhs + 1.
2643 __ Slti(dst, lhs, rhs_imm + 1);
2644 if (cond == kCondGT) {
2645 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2646 // only the slti instruction but no sgti.
2647 __ Xori(dst, dst, 1);
2648 }
2649 } else {
2650 if (use_imm) {
2651 rhs_reg = TMP;
2652 __ LoadConst32(rhs_reg, rhs_imm);
2653 }
2654 __ Slt(dst, rhs_reg, lhs);
2655 if (cond == kCondLE) {
2656 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2657 // only the slt instruction but no sle.
2658 __ Xori(dst, dst, 1);
2659 }
2660 }
2661 break;
2662
2663 case kCondB:
2664 case kCondAE:
2665 if (use_imm && IsInt<16>(rhs_imm)) {
2666 // Sltiu sign-extends its 16-bit immediate operand before
2667 // the comparison and thus lets us compare directly with
2668 // unsigned values in the ranges [0, 0x7fff] and
2669 // [0xffff8000, 0xffffffff].
2670 __ Sltiu(dst, lhs, rhs_imm);
2671 } else {
2672 if (use_imm) {
2673 rhs_reg = TMP;
2674 __ LoadConst32(rhs_reg, rhs_imm);
2675 }
2676 __ Sltu(dst, lhs, rhs_reg);
2677 }
2678 if (cond == kCondAE) {
2679 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2680 // only the sltu instruction but no sgeu.
2681 __ Xori(dst, dst, 1);
2682 }
2683 break;
2684
2685 case kCondBE:
2686 case kCondA:
2687 if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
2688 // Simulate lhs <= rhs via lhs < rhs + 1.
2689 // Note that this only works if rhs + 1 does not overflow
2690 // to 0, hence the check above.
2691 // Sltiu sign-extends its 16-bit immediate operand before
2692 // the comparison and thus lets us compare directly with
2693 // unsigned values in the ranges [0, 0x7fff] and
2694 // [0xffff8000, 0xffffffff].
2695 __ Sltiu(dst, lhs, rhs_imm + 1);
2696 if (cond == kCondA) {
2697 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2698 // only the sltiu instruction but no sgtiu.
2699 __ Xori(dst, dst, 1);
2700 }
2701 } else {
2702 if (use_imm) {
2703 rhs_reg = TMP;
2704 __ LoadConst32(rhs_reg, rhs_imm);
2705 }
2706 __ Sltu(dst, rhs_reg, lhs);
2707 if (cond == kCondBE) {
2708 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2709 // only the sltu instruction but no sleu.
2710 __ Xori(dst, dst, 1);
2711 }
2712 }
2713 break;
2714 }
2715}
2716
2717void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond,
2718 LocationSummary* locations,
2719 MipsLabel* label) {
2720 Register lhs = locations->InAt(0).AsRegister<Register>();
2721 Location rhs_location = locations->InAt(1);
2722 Register rhs_reg = ZERO;
2723 int32_t rhs_imm = 0;
2724 bool use_imm = rhs_location.IsConstant();
2725 if (use_imm) {
2726 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2727 } else {
2728 rhs_reg = rhs_location.AsRegister<Register>();
2729 }
2730
2731 if (use_imm && rhs_imm == 0) {
2732 switch (cond) {
2733 case kCondEQ:
2734 case kCondBE: // <= 0 if zero
2735 __ Beqz(lhs, label);
2736 break;
2737 case kCondNE:
2738 case kCondA: // > 0 if non-zero
2739 __ Bnez(lhs, label);
2740 break;
2741 case kCondLT:
2742 __ Bltz(lhs, label);
2743 break;
2744 case kCondGE:
2745 __ Bgez(lhs, label);
2746 break;
2747 case kCondLE:
2748 __ Blez(lhs, label);
2749 break;
2750 case kCondGT:
2751 __ Bgtz(lhs, label);
2752 break;
2753 case kCondB: // always false
2754 break;
2755 case kCondAE: // always true
2756 __ B(label);
2757 break;
2758 }
2759 } else {
2760 if (use_imm) {
2761 // TODO: more efficient comparison with 16-bit constants without loading them into TMP.
2762 rhs_reg = TMP;
2763 __ LoadConst32(rhs_reg, rhs_imm);
2764 }
2765 switch (cond) {
2766 case kCondEQ:
2767 __ Beq(lhs, rhs_reg, label);
2768 break;
2769 case kCondNE:
2770 __ Bne(lhs, rhs_reg, label);
2771 break;
2772 case kCondLT:
2773 __ Blt(lhs, rhs_reg, label);
2774 break;
2775 case kCondGE:
2776 __ Bge(lhs, rhs_reg, label);
2777 break;
2778 case kCondLE:
2779 __ Bge(rhs_reg, lhs, label);
2780 break;
2781 case kCondGT:
2782 __ Blt(rhs_reg, lhs, label);
2783 break;
2784 case kCondB:
2785 __ Bltu(lhs, rhs_reg, label);
2786 break;
2787 case kCondAE:
2788 __ Bgeu(lhs, rhs_reg, label);
2789 break;
2790 case kCondBE:
2791 __ Bgeu(rhs_reg, lhs, label);
2792 break;
2793 case kCondA:
2794 __ Bltu(rhs_reg, lhs, label);
2795 break;
2796 }
2797 }
2798}
2799
2800void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond,
2801 LocationSummary* locations,
2802 MipsLabel* label) {
2803 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2804 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
2805 Location rhs_location = locations->InAt(1);
2806 Register rhs_high = ZERO;
2807 Register rhs_low = ZERO;
2808 int64_t imm = 0;
2809 uint32_t imm_high = 0;
2810 uint32_t imm_low = 0;
2811 bool use_imm = rhs_location.IsConstant();
2812 if (use_imm) {
2813 imm = rhs_location.GetConstant()->AsLongConstant()->GetValue();
2814 imm_high = High32Bits(imm);
2815 imm_low = Low32Bits(imm);
2816 } else {
2817 rhs_high = rhs_location.AsRegisterPairHigh<Register>();
2818 rhs_low = rhs_location.AsRegisterPairLow<Register>();
2819 }
2820
2821 if (use_imm && imm == 0) {
2822 switch (cond) {
2823 case kCondEQ:
2824 case kCondBE: // <= 0 if zero
2825 __ Or(TMP, lhs_high, lhs_low);
2826 __ Beqz(TMP, label);
2827 break;
2828 case kCondNE:
2829 case kCondA: // > 0 if non-zero
2830 __ Or(TMP, lhs_high, lhs_low);
2831 __ Bnez(TMP, label);
2832 break;
2833 case kCondLT:
2834 __ Bltz(lhs_high, label);
2835 break;
2836 case kCondGE:
2837 __ Bgez(lhs_high, label);
2838 break;
2839 case kCondLE:
2840 __ Or(TMP, lhs_high, lhs_low);
2841 __ Sra(AT, lhs_high, 31);
2842 __ Bgeu(AT, TMP, label);
2843 break;
2844 case kCondGT:
2845 __ Or(TMP, lhs_high, lhs_low);
2846 __ Sra(AT, lhs_high, 31);
2847 __ Bltu(AT, TMP, label);
2848 break;
2849 case kCondB: // always false
2850 break;
2851 case kCondAE: // always true
2852 __ B(label);
2853 break;
2854 }
2855 } else if (use_imm) {
2856 // TODO: more efficient comparison with constants without loading them into TMP/AT.
2857 switch (cond) {
2858 case kCondEQ:
2859 __ LoadConst32(TMP, imm_high);
2860 __ Xor(TMP, TMP, lhs_high);
2861 __ LoadConst32(AT, imm_low);
2862 __ Xor(AT, AT, lhs_low);
2863 __ Or(TMP, TMP, AT);
2864 __ Beqz(TMP, label);
2865 break;
2866 case kCondNE:
2867 __ LoadConst32(TMP, imm_high);
2868 __ Xor(TMP, TMP, lhs_high);
2869 __ LoadConst32(AT, imm_low);
2870 __ Xor(AT, AT, lhs_low);
2871 __ Or(TMP, TMP, AT);
2872 __ Bnez(TMP, label);
2873 break;
2874 case kCondLT:
2875 __ LoadConst32(TMP, imm_high);
2876 __ Blt(lhs_high, TMP, label);
2877 __ Slt(TMP, TMP, lhs_high);
2878 __ LoadConst32(AT, imm_low);
2879 __ Sltu(AT, lhs_low, AT);
2880 __ Blt(TMP, AT, label);
2881 break;
2882 case kCondGE:
2883 __ LoadConst32(TMP, imm_high);
2884 __ Blt(TMP, lhs_high, label);
2885 __ Slt(TMP, lhs_high, TMP);
2886 __ LoadConst32(AT, imm_low);
2887 __ Sltu(AT, lhs_low, AT);
2888 __ Or(TMP, TMP, AT);
2889 __ Beqz(TMP, label);
2890 break;
2891 case kCondLE:
2892 __ LoadConst32(TMP, imm_high);
2893 __ Blt(lhs_high, TMP, label);
2894 __ Slt(TMP, TMP, lhs_high);
2895 __ LoadConst32(AT, imm_low);
2896 __ Sltu(AT, AT, lhs_low);
2897 __ Or(TMP, TMP, AT);
2898 __ Beqz(TMP, label);
2899 break;
2900 case kCondGT:
2901 __ LoadConst32(TMP, imm_high);
2902 __ Blt(TMP, lhs_high, label);
2903 __ Slt(TMP, lhs_high, TMP);
2904 __ LoadConst32(AT, imm_low);
2905 __ Sltu(AT, AT, lhs_low);
2906 __ Blt(TMP, AT, label);
2907 break;
2908 case kCondB:
2909 __ LoadConst32(TMP, imm_high);
2910 __ Bltu(lhs_high, TMP, label);
2911 __ Sltu(TMP, TMP, lhs_high);
2912 __ LoadConst32(AT, imm_low);
2913 __ Sltu(AT, lhs_low, AT);
2914 __ Blt(TMP, AT, label);
2915 break;
2916 case kCondAE:
2917 __ LoadConst32(TMP, imm_high);
2918 __ Bltu(TMP, lhs_high, label);
2919 __ Sltu(TMP, lhs_high, TMP);
2920 __ LoadConst32(AT, imm_low);
2921 __ Sltu(AT, lhs_low, AT);
2922 __ Or(TMP, TMP, AT);
2923 __ Beqz(TMP, label);
2924 break;
2925 case kCondBE:
2926 __ LoadConst32(TMP, imm_high);
2927 __ Bltu(lhs_high, TMP, label);
2928 __ Sltu(TMP, TMP, lhs_high);
2929 __ LoadConst32(AT, imm_low);
2930 __ Sltu(AT, AT, lhs_low);
2931 __ Or(TMP, TMP, AT);
2932 __ Beqz(TMP, label);
2933 break;
2934 case kCondA:
2935 __ LoadConst32(TMP, imm_high);
2936 __ Bltu(TMP, lhs_high, label);
2937 __ Sltu(TMP, lhs_high, TMP);
2938 __ LoadConst32(AT, imm_low);
2939 __ Sltu(AT, AT, lhs_low);
2940 __ Blt(TMP, AT, label);
2941 break;
2942 }
2943 } else {
2944 switch (cond) {
2945 case kCondEQ:
2946 __ Xor(TMP, lhs_high, rhs_high);
2947 __ Xor(AT, lhs_low, rhs_low);
2948 __ Or(TMP, TMP, AT);
2949 __ Beqz(TMP, label);
2950 break;
2951 case kCondNE:
2952 __ Xor(TMP, lhs_high, rhs_high);
2953 __ Xor(AT, lhs_low, rhs_low);
2954 __ Or(TMP, TMP, AT);
2955 __ Bnez(TMP, label);
2956 break;
2957 case kCondLT:
2958 __ Blt(lhs_high, rhs_high, label);
2959 __ Slt(TMP, rhs_high, lhs_high);
2960 __ Sltu(AT, lhs_low, rhs_low);
2961 __ Blt(TMP, AT, label);
2962 break;
2963 case kCondGE:
2964 __ Blt(rhs_high, lhs_high, label);
2965 __ Slt(TMP, lhs_high, rhs_high);
2966 __ Sltu(AT, lhs_low, rhs_low);
2967 __ Or(TMP, TMP, AT);
2968 __ Beqz(TMP, label);
2969 break;
2970 case kCondLE:
2971 __ Blt(lhs_high, rhs_high, label);
2972 __ Slt(TMP, rhs_high, lhs_high);
2973 __ Sltu(AT, rhs_low, lhs_low);
2974 __ Or(TMP, TMP, AT);
2975 __ Beqz(TMP, label);
2976 break;
2977 case kCondGT:
2978 __ Blt(rhs_high, lhs_high, label);
2979 __ Slt(TMP, lhs_high, rhs_high);
2980 __ Sltu(AT, rhs_low, lhs_low);
2981 __ Blt(TMP, AT, label);
2982 break;
2983 case kCondB:
2984 __ Bltu(lhs_high, rhs_high, label);
2985 __ Sltu(TMP, rhs_high, lhs_high);
2986 __ Sltu(AT, lhs_low, rhs_low);
2987 __ Blt(TMP, AT, label);
2988 break;
2989 case kCondAE:
2990 __ Bltu(rhs_high, lhs_high, label);
2991 __ Sltu(TMP, lhs_high, rhs_high);
2992 __ Sltu(AT, lhs_low, rhs_low);
2993 __ Or(TMP, TMP, AT);
2994 __ Beqz(TMP, label);
2995 break;
2996 case kCondBE:
2997 __ Bltu(lhs_high, rhs_high, label);
2998 __ Sltu(TMP, rhs_high, lhs_high);
2999 __ Sltu(AT, rhs_low, lhs_low);
3000 __ Or(TMP, TMP, AT);
3001 __ Beqz(TMP, label);
3002 break;
3003 case kCondA:
3004 __ Bltu(rhs_high, lhs_high, label);
3005 __ Sltu(TMP, lhs_high, rhs_high);
3006 __ Sltu(AT, rhs_low, lhs_low);
3007 __ Blt(TMP, AT, label);
3008 break;
3009 }
3010 }
3011}
3012
3013void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond,
3014 bool gt_bias,
3015 Primitive::Type type,
3016 LocationSummary* locations,
3017 MipsLabel* label) {
3018 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3019 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3020 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3021 if (type == Primitive::kPrimFloat) {
3022 if (isR6) {
3023 switch (cond) {
3024 case kCondEQ:
3025 __ CmpEqS(FTMP, lhs, rhs);
3026 __ Bc1nez(FTMP, label);
3027 break;
3028 case kCondNE:
3029 __ CmpEqS(FTMP, lhs, rhs);
3030 __ Bc1eqz(FTMP, label);
3031 break;
3032 case kCondLT:
3033 if (gt_bias) {
3034 __ CmpLtS(FTMP, lhs, rhs);
3035 } else {
3036 __ CmpUltS(FTMP, lhs, rhs);
3037 }
3038 __ Bc1nez(FTMP, label);
3039 break;
3040 case kCondLE:
3041 if (gt_bias) {
3042 __ CmpLeS(FTMP, lhs, rhs);
3043 } else {
3044 __ CmpUleS(FTMP, lhs, rhs);
3045 }
3046 __ Bc1nez(FTMP, label);
3047 break;
3048 case kCondGT:
3049 if (gt_bias) {
3050 __ CmpUltS(FTMP, rhs, lhs);
3051 } else {
3052 __ CmpLtS(FTMP, rhs, lhs);
3053 }
3054 __ Bc1nez(FTMP, label);
3055 break;
3056 case kCondGE:
3057 if (gt_bias) {
3058 __ CmpUleS(FTMP, rhs, lhs);
3059 } else {
3060 __ CmpLeS(FTMP, rhs, lhs);
3061 }
3062 __ Bc1nez(FTMP, label);
3063 break;
3064 default:
3065 LOG(FATAL) << "Unexpected non-floating-point condition";
3066 }
3067 } else {
3068 switch (cond) {
3069 case kCondEQ:
3070 __ CeqS(0, lhs, rhs);
3071 __ Bc1t(0, label);
3072 break;
3073 case kCondNE:
3074 __ CeqS(0, lhs, rhs);
3075 __ Bc1f(0, label);
3076 break;
3077 case kCondLT:
3078 if (gt_bias) {
3079 __ ColtS(0, lhs, rhs);
3080 } else {
3081 __ CultS(0, lhs, rhs);
3082 }
3083 __ Bc1t(0, label);
3084 break;
3085 case kCondLE:
3086 if (gt_bias) {
3087 __ ColeS(0, lhs, rhs);
3088 } else {
3089 __ CuleS(0, lhs, rhs);
3090 }
3091 __ Bc1t(0, label);
3092 break;
3093 case kCondGT:
3094 if (gt_bias) {
3095 __ CultS(0, rhs, lhs);
3096 } else {
3097 __ ColtS(0, rhs, lhs);
3098 }
3099 __ Bc1t(0, label);
3100 break;
3101 case kCondGE:
3102 if (gt_bias) {
3103 __ CuleS(0, rhs, lhs);
3104 } else {
3105 __ ColeS(0, rhs, lhs);
3106 }
3107 __ Bc1t(0, label);
3108 break;
3109 default:
3110 LOG(FATAL) << "Unexpected non-floating-point condition";
3111 }
3112 }
3113 } else {
3114 DCHECK_EQ(type, Primitive::kPrimDouble);
3115 if (isR6) {
3116 switch (cond) {
3117 case kCondEQ:
3118 __ CmpEqD(FTMP, lhs, rhs);
3119 __ Bc1nez(FTMP, label);
3120 break;
3121 case kCondNE:
3122 __ CmpEqD(FTMP, lhs, rhs);
3123 __ Bc1eqz(FTMP, label);
3124 break;
3125 case kCondLT:
3126 if (gt_bias) {
3127 __ CmpLtD(FTMP, lhs, rhs);
3128 } else {
3129 __ CmpUltD(FTMP, lhs, rhs);
3130 }
3131 __ Bc1nez(FTMP, label);
3132 break;
3133 case kCondLE:
3134 if (gt_bias) {
3135 __ CmpLeD(FTMP, lhs, rhs);
3136 } else {
3137 __ CmpUleD(FTMP, lhs, rhs);
3138 }
3139 __ Bc1nez(FTMP, label);
3140 break;
3141 case kCondGT:
3142 if (gt_bias) {
3143 __ CmpUltD(FTMP, rhs, lhs);
3144 } else {
3145 __ CmpLtD(FTMP, rhs, lhs);
3146 }
3147 __ Bc1nez(FTMP, label);
3148 break;
3149 case kCondGE:
3150 if (gt_bias) {
3151 __ CmpUleD(FTMP, rhs, lhs);
3152 } else {
3153 __ CmpLeD(FTMP, rhs, lhs);
3154 }
3155 __ Bc1nez(FTMP, label);
3156 break;
3157 default:
3158 LOG(FATAL) << "Unexpected non-floating-point condition";
3159 }
3160 } else {
3161 switch (cond) {
3162 case kCondEQ:
3163 __ CeqD(0, lhs, rhs);
3164 __ Bc1t(0, label);
3165 break;
3166 case kCondNE:
3167 __ CeqD(0, lhs, rhs);
3168 __ Bc1f(0, label);
3169 break;
3170 case kCondLT:
3171 if (gt_bias) {
3172 __ ColtD(0, lhs, rhs);
3173 } else {
3174 __ CultD(0, lhs, rhs);
3175 }
3176 __ Bc1t(0, label);
3177 break;
3178 case kCondLE:
3179 if (gt_bias) {
3180 __ ColeD(0, lhs, rhs);
3181 } else {
3182 __ CuleD(0, lhs, rhs);
3183 }
3184 __ Bc1t(0, label);
3185 break;
3186 case kCondGT:
3187 if (gt_bias) {
3188 __ CultD(0, rhs, lhs);
3189 } else {
3190 __ ColtD(0, rhs, lhs);
3191 }
3192 __ Bc1t(0, label);
3193 break;
3194 case kCondGE:
3195 if (gt_bias) {
3196 __ CuleD(0, rhs, lhs);
3197 } else {
3198 __ ColeD(0, rhs, lhs);
3199 }
3200 __ Bc1t(0, label);
3201 break;
3202 default:
3203 LOG(FATAL) << "Unexpected non-floating-point condition";
3204 }
3205 }
3206 }
3207}
3208
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003209void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00003210 size_t condition_input_index,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003211 MipsLabel* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00003212 MipsLabel* false_target) {
3213 HInstruction* cond = instruction->InputAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003214
David Brazdil0debae72015-11-12 18:37:00 +00003215 if (true_target == nullptr && false_target == nullptr) {
3216 // Nothing to do. The code always falls through.
3217 return;
3218 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00003219 // Constant condition, statically compared against "true" (integer value 1).
3220 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00003221 if (true_target != nullptr) {
3222 __ B(true_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003223 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003224 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00003225 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00003226 if (false_target != nullptr) {
3227 __ B(false_target);
3228 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003229 }
David Brazdil0debae72015-11-12 18:37:00 +00003230 return;
3231 }
3232
3233 // The following code generates these patterns:
3234 // (1) true_target == nullptr && false_target != nullptr
3235 // - opposite condition true => branch to false_target
3236 // (2) true_target != nullptr && false_target == nullptr
3237 // - condition true => branch to true_target
3238 // (3) true_target != nullptr && false_target != nullptr
3239 // - condition true => branch to true_target
3240 // - branch to false_target
3241 if (IsBooleanValueOrMaterializedCondition(cond)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003242 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00003243 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003244 DCHECK(cond_val.IsRegister());
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003245 if (true_target == nullptr) {
David Brazdil0debae72015-11-12 18:37:00 +00003246 __ Beqz(cond_val.AsRegister<Register>(), false_target);
3247 } else {
3248 __ Bnez(cond_val.AsRegister<Register>(), true_target);
3249 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003250 } else {
3251 // The condition instruction has not been materialized, use its inputs as
3252 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00003253 HCondition* condition = cond->AsCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003254 Primitive::Type type = condition->InputAt(0)->GetType();
3255 LocationSummary* locations = cond->GetLocations();
3256 IfCondition if_cond = condition->GetCondition();
3257 MipsLabel* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00003258
David Brazdil0debae72015-11-12 18:37:00 +00003259 if (true_target == nullptr) {
3260 if_cond = condition->GetOppositeCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003261 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00003262 }
3263
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003264 switch (type) {
3265 default:
3266 GenerateIntCompareAndBranch(if_cond, locations, branch_target);
3267 break;
3268 case Primitive::kPrimLong:
3269 GenerateLongCompareAndBranch(if_cond, locations, branch_target);
3270 break;
3271 case Primitive::kPrimFloat:
3272 case Primitive::kPrimDouble:
3273 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
3274 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003275 }
3276 }
David Brazdil0debae72015-11-12 18:37:00 +00003277
3278 // If neither branch falls through (case 3), the conditional branch to `true_target`
3279 // was already emitted (case 2) and we need to emit a jump to `false_target`.
3280 if (true_target != nullptr && false_target != nullptr) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003281 __ B(false_target);
3282 }
3283}
3284
3285void LocationsBuilderMIPS::VisitIf(HIf* if_instr) {
3286 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00003287 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003288 locations->SetInAt(0, Location::RequiresRegister());
3289 }
3290}
3291
3292void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00003293 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
3294 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
3295 MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
3296 nullptr : codegen_->GetLabelOf(true_successor);
3297 MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
3298 nullptr : codegen_->GetLabelOf(false_successor);
3299 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003300}
3301
3302void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
3303 LocationSummary* locations = new (GetGraph()->GetArena())
3304 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
David Brazdil0debae72015-11-12 18:37:00 +00003305 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003306 locations->SetInAt(0, Location::RequiresRegister());
3307 }
3308}
3309
3310void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08003311 SlowPathCodeMIPS* slow_path =
3312 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00003313 GenerateTestAndBranch(deoptimize,
3314 /* condition_input_index */ 0,
3315 slow_path->GetEntryLabel(),
3316 /* false_target */ nullptr);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003317}
3318
David Brazdil74eb1b22015-12-14 11:44:01 +00003319void LocationsBuilderMIPS::VisitSelect(HSelect* select) {
3320 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
3321 if (Primitive::IsFloatingPointType(select->GetType())) {
3322 locations->SetInAt(0, Location::RequiresFpuRegister());
3323 locations->SetInAt(1, Location::RequiresFpuRegister());
3324 } else {
3325 locations->SetInAt(0, Location::RequiresRegister());
3326 locations->SetInAt(1, Location::RequiresRegister());
3327 }
3328 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
3329 locations->SetInAt(2, Location::RequiresRegister());
3330 }
3331 locations->SetOut(Location::SameAsFirstInput());
3332}
3333
3334void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) {
3335 LocationSummary* locations = select->GetLocations();
3336 MipsLabel false_target;
3337 GenerateTestAndBranch(select,
3338 /* condition_input_index */ 2,
3339 /* true_target */ nullptr,
3340 &false_target);
3341 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
3342 __ Bind(&false_target);
3343}
3344
David Srbecky0cf44932015-12-09 14:09:59 +00003345void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) {
3346 new (GetGraph()->GetArena()) LocationSummary(info);
3347}
3348
David Srbeckyd28f4a02016-03-14 17:14:24 +00003349void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) {
3350 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00003351}
3352
3353void CodeGeneratorMIPS::GenerateNop() {
3354 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00003355}
3356
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003357void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3358 Primitive::Type field_type = field_info.GetFieldType();
3359 bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble);
3360 bool generate_volatile = field_info.IsVolatile() && is_wide;
3361 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3362 instruction, generate_volatile ? LocationSummary::kCall : LocationSummary::kNoCall);
3363
3364 locations->SetInAt(0, Location::RequiresRegister());
3365 if (generate_volatile) {
3366 InvokeRuntimeCallingConvention calling_convention;
3367 // need A0 to hold base + offset
3368 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3369 if (field_type == Primitive::kPrimLong) {
3370 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimLong));
3371 } else {
3372 locations->SetOut(Location::RequiresFpuRegister());
3373 // Need some temp core regs since FP results are returned in core registers
3374 Location reg = calling_convention.GetReturnLocation(Primitive::kPrimLong);
3375 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>()));
3376 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>()));
3377 }
3378 } else {
3379 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3380 locations->SetOut(Location::RequiresFpuRegister());
3381 } else {
3382 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3383 }
3384 }
3385}
3386
3387void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction,
3388 const FieldInfo& field_info,
3389 uint32_t dex_pc) {
3390 Primitive::Type type = field_info.GetFieldType();
3391 LocationSummary* locations = instruction->GetLocations();
3392 Register obj = locations->InAt(0).AsRegister<Register>();
3393 LoadOperandType load_type = kLoadUnsignedByte;
3394 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003395 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003396
3397 switch (type) {
3398 case Primitive::kPrimBoolean:
3399 load_type = kLoadUnsignedByte;
3400 break;
3401 case Primitive::kPrimByte:
3402 load_type = kLoadSignedByte;
3403 break;
3404 case Primitive::kPrimShort:
3405 load_type = kLoadSignedHalfword;
3406 break;
3407 case Primitive::kPrimChar:
3408 load_type = kLoadUnsignedHalfword;
3409 break;
3410 case Primitive::kPrimInt:
3411 case Primitive::kPrimFloat:
3412 case Primitive::kPrimNot:
3413 load_type = kLoadWord;
3414 break;
3415 case Primitive::kPrimLong:
3416 case Primitive::kPrimDouble:
3417 load_type = kLoadDoubleword;
3418 break;
3419 case Primitive::kPrimVoid:
3420 LOG(FATAL) << "Unreachable type " << type;
3421 UNREACHABLE();
3422 }
3423
3424 if (is_volatile && load_type == kLoadDoubleword) {
3425 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003426 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003427 // Do implicit Null check
3428 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
3429 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3430 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pA64Load),
3431 instruction,
3432 dex_pc,
3433 nullptr,
3434 IsDirectEntrypoint(kQuickA64Load));
3435 CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>();
3436 if (type == Primitive::kPrimDouble) {
3437 // Need to move to FP regs since FP results are returned in core registers.
3438 __ Mtc1(locations->GetTemp(1).AsRegister<Register>(),
3439 locations->Out().AsFpuRegister<FRegister>());
Alexey Frunzebb9863a2016-01-11 15:51:16 -08003440 __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
3441 locations->Out().AsFpuRegister<FRegister>());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003442 }
3443 } else {
3444 if (!Primitive::IsFloatingPointType(type)) {
3445 Register dst;
3446 if (type == Primitive::kPrimLong) {
3447 DCHECK(locations->Out().IsRegisterPair());
3448 dst = locations->Out().AsRegisterPairLow<Register>();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003449 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
3450 if (obj == dst) {
3451 __ LoadFromOffset(kLoadWord, dst_high, obj, offset + kMipsWordSize);
3452 codegen_->MaybeRecordImplicitNullCheck(instruction);
3453 __ LoadFromOffset(kLoadWord, dst, obj, offset);
3454 } else {
3455 __ LoadFromOffset(kLoadWord, dst, obj, offset);
3456 codegen_->MaybeRecordImplicitNullCheck(instruction);
3457 __ LoadFromOffset(kLoadWord, dst_high, obj, offset + kMipsWordSize);
3458 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003459 } else {
3460 DCHECK(locations->Out().IsRegister());
3461 dst = locations->Out().AsRegister<Register>();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003462 __ LoadFromOffset(load_type, dst, obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003463 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003464 } else {
3465 DCHECK(locations->Out().IsFpuRegister());
3466 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
3467 if (type == Primitive::kPrimFloat) {
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003468 __ LoadSFromOffset(dst, obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003469 } else {
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003470 __ LoadDFromOffset(dst, obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003471 }
3472 }
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003473 // Longs are handled earlier.
3474 if (type != Primitive::kPrimLong) {
3475 codegen_->MaybeRecordImplicitNullCheck(instruction);
3476 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003477 }
3478
3479 if (is_volatile) {
3480 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3481 }
3482}
3483
3484void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3485 Primitive::Type field_type = field_info.GetFieldType();
3486 bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble);
3487 bool generate_volatile = field_info.IsVolatile() && is_wide;
3488 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3489 instruction, generate_volatile ? LocationSummary::kCall : LocationSummary::kNoCall);
3490
3491 locations->SetInAt(0, Location::RequiresRegister());
3492 if (generate_volatile) {
3493 InvokeRuntimeCallingConvention calling_convention;
3494 // need A0 to hold base + offset
3495 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3496 if (field_type == Primitive::kPrimLong) {
3497 locations->SetInAt(1, Location::RegisterPairLocation(
3498 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
3499 } else {
3500 locations->SetInAt(1, Location::RequiresFpuRegister());
3501 // Pass FP parameters in core registers.
3502 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
3503 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
3504 }
3505 } else {
3506 if (Primitive::IsFloatingPointType(field_type)) {
3507 locations->SetInAt(1, Location::RequiresFpuRegister());
3508 } else {
3509 locations->SetInAt(1, Location::RequiresRegister());
3510 }
3511 }
3512}
3513
3514void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction,
3515 const FieldInfo& field_info,
3516 uint32_t dex_pc) {
3517 Primitive::Type type = field_info.GetFieldType();
3518 LocationSummary* locations = instruction->GetLocations();
3519 Register obj = locations->InAt(0).AsRegister<Register>();
3520 StoreOperandType store_type = kStoreByte;
3521 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003522 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003523
3524 switch (type) {
3525 case Primitive::kPrimBoolean:
3526 case Primitive::kPrimByte:
3527 store_type = kStoreByte;
3528 break;
3529 case Primitive::kPrimShort:
3530 case Primitive::kPrimChar:
3531 store_type = kStoreHalfword;
3532 break;
3533 case Primitive::kPrimInt:
3534 case Primitive::kPrimFloat:
3535 case Primitive::kPrimNot:
3536 store_type = kStoreWord;
3537 break;
3538 case Primitive::kPrimLong:
3539 case Primitive::kPrimDouble:
3540 store_type = kStoreDoubleword;
3541 break;
3542 case Primitive::kPrimVoid:
3543 LOG(FATAL) << "Unreachable type " << type;
3544 UNREACHABLE();
3545 }
3546
3547 if (is_volatile) {
3548 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3549 }
3550
3551 if (is_volatile && store_type == kStoreDoubleword) {
3552 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003553 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003554 // Do implicit Null check.
3555 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
3556 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3557 if (type == Primitive::kPrimDouble) {
3558 // Pass FP parameters in core registers.
3559 __ Mfc1(locations->GetTemp(1).AsRegister<Register>(),
3560 locations->InAt(1).AsFpuRegister<FRegister>());
Alexey Frunzebb9863a2016-01-11 15:51:16 -08003561 __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
3562 locations->InAt(1).AsFpuRegister<FRegister>());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003563 }
3564 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pA64Store),
3565 instruction,
3566 dex_pc,
3567 nullptr,
3568 IsDirectEntrypoint(kQuickA64Store));
3569 CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>();
3570 } else {
3571 if (!Primitive::IsFloatingPointType(type)) {
3572 Register src;
3573 if (type == Primitive::kPrimLong) {
3574 DCHECK(locations->InAt(1).IsRegisterPair());
3575 src = locations->InAt(1).AsRegisterPairLow<Register>();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003576 Register src_high = locations->InAt(1).AsRegisterPairHigh<Register>();
3577 __ StoreToOffset(kStoreWord, src, obj, offset);
3578 codegen_->MaybeRecordImplicitNullCheck(instruction);
3579 __ StoreToOffset(kStoreWord, src_high, obj, offset + kMipsWordSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003580 } else {
3581 DCHECK(locations->InAt(1).IsRegister());
3582 src = locations->InAt(1).AsRegister<Register>();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003583 __ StoreToOffset(store_type, src, obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003584 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003585 } else {
3586 DCHECK(locations->InAt(1).IsFpuRegister());
3587 FRegister src = locations->InAt(1).AsFpuRegister<FRegister>();
3588 if (type == Primitive::kPrimFloat) {
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003589 __ StoreSToOffset(src, obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003590 } else {
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003591 __ StoreDToOffset(src, obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003592 }
3593 }
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003594 // Longs are handled earlier.
3595 if (type != Primitive::kPrimLong) {
3596 codegen_->MaybeRecordImplicitNullCheck(instruction);
3597 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003598 }
3599
3600 // TODO: memory barriers?
3601 if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) {
3602 DCHECK(locations->InAt(1).IsRegister());
3603 Register src = locations->InAt(1).AsRegister<Register>();
3604 codegen_->MarkGCCard(obj, src);
3605 }
3606
3607 if (is_volatile) {
3608 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3609 }
3610}
3611
3612void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3613 HandleFieldGet(instruction, instruction->GetFieldInfo());
3614}
3615
3616void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3617 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
3618}
3619
3620void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3621 HandleFieldSet(instruction, instruction->GetFieldInfo());
3622}
3623
3624void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3625 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
3626}
3627
3628void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) {
3629 LocationSummary::CallKind call_kind =
3630 instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
3631 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3632 locations->SetInAt(0, Location::RequiresRegister());
3633 locations->SetInAt(1, Location::RequiresRegister());
3634 // The output does overlap inputs.
3635 // Note that TypeCheckSlowPathMIPS uses this register too.
3636 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3637}
3638
3639void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) {
3640 LocationSummary* locations = instruction->GetLocations();
3641 Register obj = locations->InAt(0).AsRegister<Register>();
3642 Register cls = locations->InAt(1).AsRegister<Register>();
3643 Register out = locations->Out().AsRegister<Register>();
3644
3645 MipsLabel done;
3646
3647 // Return 0 if `obj` is null.
3648 // TODO: Avoid this check if we know `obj` is not null.
3649 __ Move(out, ZERO);
3650 __ Beqz(obj, &done);
3651
3652 // Compare the class of `obj` with `cls`.
3653 __ LoadFromOffset(kLoadWord, out, obj, mirror::Object::ClassOffset().Int32Value());
3654 if (instruction->IsExactCheck()) {
3655 // Classes must be equal for the instanceof to succeed.
3656 __ Xor(out, out, cls);
3657 __ Sltiu(out, out, 1);
3658 } else {
3659 // If the classes are not equal, we go into a slow path.
3660 DCHECK(locations->OnlyCallsOnSlowPath());
3661 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction);
3662 codegen_->AddSlowPath(slow_path);
3663 __ Bne(out, cls, slow_path->GetEntryLabel());
3664 __ LoadConst32(out, 1);
3665 __ Bind(slow_path->GetExitLabel());
3666 }
3667
3668 __ Bind(&done);
3669}
3670
3671void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) {
3672 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3673 locations->SetOut(Location::ConstantLocation(constant));
3674}
3675
3676void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
3677 // Will be generated at use site.
3678}
3679
3680void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) {
3681 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3682 locations->SetOut(Location::ConstantLocation(constant));
3683}
3684
3685void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
3686 // Will be generated at use site.
3687}
3688
3689void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) {
3690 InvokeDexCallingConventionVisitorMIPS calling_convention_visitor;
3691 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
3692}
3693
3694void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
3695 HandleInvoke(invoke);
3696 // The register T0 is required to be used for the hidden argument in
3697 // art_quick_imt_conflict_trampoline, so add the hidden argument.
3698 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
3699}
3700
3701void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
3702 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
3703 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003704 Location receiver = invoke->GetLocations()->InAt(0);
3705 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3706 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsWordSize);
3707
3708 // Set the hidden argument.
3709 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
3710 invoke->GetDexMethodIndex());
3711
3712 // temp = object->GetClass();
3713 if (receiver.IsStackSlot()) {
3714 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
3715 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
3716 } else {
3717 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
3718 }
3719 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nelli Kimbadee982016-05-13 13:08:53 +03003720 __ LoadFromOffset(kLoadWord, temp, temp,
3721 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
3722 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity50706432016-06-14 11:31:04 -07003723 invoke->GetImtIndex(), kMipsPointerSize));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003724 // temp = temp->GetImtEntryAt(method_offset);
3725 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
3726 // T9 = temp->GetEntryPoint();
3727 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
3728 // T9();
3729 __ Jalr(T9);
3730 __ Nop();
3731 DCHECK(!codegen_->IsLeafMethod());
3732 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3733}
3734
3735void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen701566a2015-10-27 15:29:13 -07003736 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
3737 if (intrinsic.TryDispatch(invoke)) {
3738 return;
3739 }
3740
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003741 HandleInvoke(invoke);
3742}
3743
3744void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00003745 // Explicit clinit checks triggered by static invokes must have been pruned by
3746 // art::PrepareForRegisterAllocation.
3747 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003748
Chris Larsen701566a2015-10-27 15:29:13 -07003749 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
3750 if (intrinsic.TryDispatch(invoke)) {
3751 return;
3752 }
3753
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003754 HandleInvoke(invoke);
3755}
3756
Chris Larsen701566a2015-10-27 15:29:13 -07003757static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003758 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen701566a2015-10-27 15:29:13 -07003759 IntrinsicCodeGeneratorMIPS intrinsic(codegen);
3760 intrinsic.Dispatch(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003761 return true;
3762 }
3763 return false;
3764}
3765
Vladimir Markocac5a7e2016-02-22 10:39:50 +00003766HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind(
3767 HLoadString::LoadKind desired_string_load_kind ATTRIBUTE_UNUSED) {
3768 // TODO: Implement other kinds.
3769 return HLoadString::LoadKind::kDexCacheViaMethod;
3770}
3771
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01003772HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind(
3773 HLoadClass::LoadKind desired_class_load_kind) {
3774 DCHECK_NE(desired_class_load_kind, HLoadClass::LoadKind::kReferrersClass);
3775 // TODO: Implement other kinds.
3776 return HLoadClass::LoadKind::kDexCacheViaMethod;
3777}
3778
Vladimir Markodc151b22015-10-15 18:02:30 +01003779HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch(
3780 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
3781 MethodReference target_method ATTRIBUTE_UNUSED) {
3782 switch (desired_dispatch_info.method_load_kind) {
3783 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
3784 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
3785 // TODO: Implement these types. For the moment, we fall back to kDexCacheViaMethod.
3786 return HInvokeStaticOrDirect::DispatchInfo {
3787 HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod,
3788 HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod,
3789 0u,
3790 0u
3791 };
3792 default:
3793 break;
3794 }
3795 switch (desired_dispatch_info.code_ptr_location) {
3796 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
3797 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
3798 // TODO: Implement these types. For the moment, we fall back to kCallArtMethod.
3799 return HInvokeStaticOrDirect::DispatchInfo {
3800 desired_dispatch_info.method_load_kind,
3801 HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod,
3802 desired_dispatch_info.method_load_data,
3803 0u
3804 };
3805 default:
3806 return desired_dispatch_info;
3807 }
3808}
3809
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003810void CodeGeneratorMIPS::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
3811 // All registers are assumed to be correctly set up per the calling convention.
3812
3813 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
3814 switch (invoke->GetMethodLoadKind()) {
3815 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
3816 // temp = thread->string_init_entrypoint
3817 __ LoadFromOffset(kLoadWord,
3818 temp.AsRegister<Register>(),
3819 TR,
3820 invoke->GetStringInitOffset());
3821 break;
3822 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00003823 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003824 break;
3825 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
3826 __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress());
3827 break;
3828 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003829 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
Vladimir Markodc151b22015-10-15 18:02:30 +01003830 // TODO: Implement these types.
3831 // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch().
3832 LOG(FATAL) << "Unsupported";
3833 UNREACHABLE();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003834 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00003835 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003836 Register reg = temp.AsRegister<Register>();
3837 Register method_reg;
3838 if (current_method.IsRegister()) {
3839 method_reg = current_method.AsRegister<Register>();
3840 } else {
3841 // TODO: use the appropriate DCHECK() here if possible.
3842 // DCHECK(invoke->GetLocations()->Intrinsified());
3843 DCHECK(!current_method.IsValid());
3844 method_reg = reg;
3845 __ Lw(reg, SP, kCurrentMethodStackOffset);
3846 }
3847
3848 // temp = temp->dex_cache_resolved_methods_;
3849 __ LoadFromOffset(kLoadWord,
3850 reg,
3851 method_reg,
3852 ArtMethod::DexCacheResolvedMethodsOffset(kMipsPointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01003853 // temp = temp[index_in_cache];
3854 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
3855 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003856 __ LoadFromOffset(kLoadWord,
3857 reg,
3858 reg,
3859 CodeGenerator::GetCachePointerOffset(index_in_cache));
3860 break;
3861 }
3862 }
3863
3864 switch (invoke->GetCodePtrLocation()) {
3865 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
3866 __ Jalr(&frame_entry_label_, T9);
3867 break;
3868 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
3869 // LR = invoke->GetDirectCodePtr();
3870 __ LoadConst32(T9, invoke->GetDirectCodePtr());
3871 // LR()
3872 __ Jalr(T9);
3873 __ Nop();
3874 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003875 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
Vladimir Markodc151b22015-10-15 18:02:30 +01003876 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
3877 // TODO: Implement these types.
3878 // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch().
3879 LOG(FATAL) << "Unsupported";
3880 UNREACHABLE();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003881 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
3882 // T9 = callee_method->entry_point_from_quick_compiled_code_;
Goran Jakovljevic1a878372015-10-26 14:28:52 +01003883 __ LoadFromOffset(kLoadWord,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003884 T9,
3885 callee_method.AsRegister<Register>(),
3886 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
3887 kMipsWordSize).Int32Value());
3888 // T9()
3889 __ Jalr(T9);
3890 __ Nop();
3891 break;
3892 }
3893 DCHECK(!IsLeafMethod());
3894}
3895
3896void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00003897 // Explicit clinit checks triggered by static invokes must have been pruned by
3898 // art::PrepareForRegisterAllocation.
3899 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003900
3901 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
3902 return;
3903 }
3904
3905 LocationSummary* locations = invoke->GetLocations();
3906 codegen_->GenerateStaticOrDirectCall(invoke,
3907 locations->HasTemps()
3908 ? locations->GetTemp(0)
3909 : Location::NoLocation());
3910 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3911}
3912
Chris Larsen3acee732015-11-18 13:31:08 -08003913void CodeGeneratorMIPS::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003914 LocationSummary* locations = invoke->GetLocations();
3915 Location receiver = locations->InAt(0);
Chris Larsen3acee732015-11-18 13:31:08 -08003916 Register temp = temp_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003917 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
3918 invoke->GetVTableIndex(), kMipsPointerSize).SizeValue();
3919 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3920 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsWordSize);
3921
3922 // temp = object->GetClass();
Chris Larsen3acee732015-11-18 13:31:08 -08003923 DCHECK(receiver.IsRegister());
3924 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
3925 MaybeRecordImplicitNullCheck(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003926 // temp = temp->GetMethodAt(method_offset);
3927 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
3928 // T9 = temp->GetEntryPoint();
3929 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
3930 // T9();
3931 __ Jalr(T9);
3932 __ Nop();
Chris Larsen3acee732015-11-18 13:31:08 -08003933}
3934
3935void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
3936 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
3937 return;
3938 }
3939
3940 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003941 DCHECK(!codegen_->IsLeafMethod());
3942 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3943}
3944
3945void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) {
Pavle Batutae87a7182015-10-28 13:10:42 +01003946 InvokeRuntimeCallingConvention calling_convention;
3947 CodeGenerator::CreateLoadClassLocationSummary(
3948 cls,
3949 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
3950 Location::RegisterLocation(V0));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003951}
3952
3953void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) {
3954 LocationSummary* locations = cls->GetLocations();
Pavle Batutae87a7182015-10-28 13:10:42 +01003955 if (cls->NeedsAccessCheck()) {
3956 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
3957 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess),
3958 cls,
3959 cls->GetDexPc(),
3960 nullptr,
3961 IsDirectEntrypoint(kQuickInitializeTypeAndVerifyAccess));
Roland Levillain888d0672015-11-23 18:53:50 +00003962 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Pavle Batutae87a7182015-10-28 13:10:42 +01003963 return;
3964 }
3965
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003966 Register out = locations->Out().AsRegister<Register>();
3967 Register current_method = locations->InAt(0).AsRegister<Register>();
3968 if (cls->IsReferrersClass()) {
3969 DCHECK(!cls->CanCallRuntime());
3970 DCHECK(!cls->MustGenerateClinitCheck());
3971 __ LoadFromOffset(kLoadWord, out, current_method,
3972 ArtMethod::DeclaringClassOffset().Int32Value());
3973 } else {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003974 __ LoadFromOffset(kLoadWord, out, current_method,
3975 ArtMethod::DexCacheResolvedTypesOffset(kMipsPointerSize).Int32Value());
3976 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00003977
3978 if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) {
3979 DCHECK(cls->CanCallRuntime());
3980 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS(
3981 cls,
3982 cls,
3983 cls->GetDexPc(),
3984 cls->MustGenerateClinitCheck());
3985 codegen_->AddSlowPath(slow_path);
3986 if (!cls->IsInDexCache()) {
3987 __ Beqz(out, slow_path->GetEntryLabel());
3988 }
3989 if (cls->MustGenerateClinitCheck()) {
3990 GenerateClassInitializationCheck(slow_path, out);
3991 } else {
3992 __ Bind(slow_path->GetExitLabel());
3993 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003994 }
3995 }
3996}
3997
3998static int32_t GetExceptionTlsOffset() {
3999 return Thread::ExceptionOffset<kMipsWordSize>().Int32Value();
4000}
4001
4002void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) {
4003 LocationSummary* locations =
4004 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4005 locations->SetOut(Location::RequiresRegister());
4006}
4007
4008void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) {
4009 Register out = load->GetLocations()->Out().AsRegister<Register>();
4010 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
4011}
4012
4013void LocationsBuilderMIPS::VisitClearException(HClearException* clear) {
4014 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
4015}
4016
4017void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
4018 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
4019}
4020
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004021void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004022 LocationSummary::CallKind call_kind = load->NeedsEnvironment()
4023 ? LocationSummary::kCallOnSlowPath
4024 : LocationSummary::kNoCall;
Nicolas Geoffray917d0162015-11-24 18:25:35 +00004025 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004026 locations->SetInAt(0, Location::RequiresRegister());
4027 locations->SetOut(Location::RequiresRegister());
4028}
4029
4030void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004031 LocationSummary* locations = load->GetLocations();
4032 Register out = locations->Out().AsRegister<Register>();
4033 Register current_method = locations->InAt(0).AsRegister<Register>();
4034 __ LoadFromOffset(kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
4035 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
4036 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
Nicolas Geoffray917d0162015-11-24 18:25:35 +00004037
4038 if (!load->IsInDexCache()) {
4039 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS(load);
4040 codegen_->AddSlowPath(slow_path);
4041 __ Beqz(out, slow_path->GetEntryLabel());
4042 __ Bind(slow_path->GetExitLabel());
4043 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004044}
4045
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004046void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) {
4047 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
4048 locations->SetOut(Location::ConstantLocation(constant));
4049}
4050
4051void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
4052 // Will be generated at use site.
4053}
4054
4055void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
4056 LocationSummary* locations =
4057 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4058 InvokeRuntimeCallingConvention calling_convention;
4059 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4060}
4061
4062void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
4063 if (instruction->IsEnter()) {
4064 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLockObject),
4065 instruction,
4066 instruction->GetDexPc(),
4067 nullptr,
4068 IsDirectEntrypoint(kQuickLockObject));
4069 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
4070 } else {
4071 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pUnlockObject),
4072 instruction,
4073 instruction->GetDexPc(),
4074 nullptr,
4075 IsDirectEntrypoint(kQuickUnlockObject));
4076 }
4077 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
4078}
4079
4080void LocationsBuilderMIPS::VisitMul(HMul* mul) {
4081 LocationSummary* locations =
4082 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
4083 switch (mul->GetResultType()) {
4084 case Primitive::kPrimInt:
4085 case Primitive::kPrimLong:
4086 locations->SetInAt(0, Location::RequiresRegister());
4087 locations->SetInAt(1, Location::RequiresRegister());
4088 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4089 break;
4090
4091 case Primitive::kPrimFloat:
4092 case Primitive::kPrimDouble:
4093 locations->SetInAt(0, Location::RequiresFpuRegister());
4094 locations->SetInAt(1, Location::RequiresFpuRegister());
4095 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4096 break;
4097
4098 default:
4099 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
4100 }
4101}
4102
4103void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) {
4104 Primitive::Type type = instruction->GetType();
4105 LocationSummary* locations = instruction->GetLocations();
4106 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4107
4108 switch (type) {
4109 case Primitive::kPrimInt: {
4110 Register dst = locations->Out().AsRegister<Register>();
4111 Register lhs = locations->InAt(0).AsRegister<Register>();
4112 Register rhs = locations->InAt(1).AsRegister<Register>();
4113
4114 if (isR6) {
4115 __ MulR6(dst, lhs, rhs);
4116 } else {
4117 __ MulR2(dst, lhs, rhs);
4118 }
4119 break;
4120 }
4121 case Primitive::kPrimLong: {
4122 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4123 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4124 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4125 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
4126 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
4127 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
4128
4129 // Extra checks to protect caused by the existance of A1_A2.
4130 // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo:
4131 // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2).
4132 DCHECK_NE(dst_high, lhs_low);
4133 DCHECK_NE(dst_high, rhs_low);
4134
4135 // A_B * C_D
4136 // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ]
4137 // dst_lo: [ low(B*D) ]
4138 // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result.
4139
4140 if (isR6) {
4141 __ MulR6(TMP, lhs_high, rhs_low);
4142 __ MulR6(dst_high, lhs_low, rhs_high);
4143 __ Addu(dst_high, dst_high, TMP);
4144 __ MuhuR6(TMP, lhs_low, rhs_low);
4145 __ Addu(dst_high, dst_high, TMP);
4146 __ MulR6(dst_low, lhs_low, rhs_low);
4147 } else {
4148 __ MulR2(TMP, lhs_high, rhs_low);
4149 __ MulR2(dst_high, lhs_low, rhs_high);
4150 __ Addu(dst_high, dst_high, TMP);
4151 __ MultuR2(lhs_low, rhs_low);
4152 __ Mfhi(TMP);
4153 __ Addu(dst_high, dst_high, TMP);
4154 __ Mflo(dst_low);
4155 }
4156 break;
4157 }
4158 case Primitive::kPrimFloat:
4159 case Primitive::kPrimDouble: {
4160 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4161 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
4162 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
4163 if (type == Primitive::kPrimFloat) {
4164 __ MulS(dst, lhs, rhs);
4165 } else {
4166 __ MulD(dst, lhs, rhs);
4167 }
4168 break;
4169 }
4170 default:
4171 LOG(FATAL) << "Unexpected mul type " << type;
4172 }
4173}
4174
4175void LocationsBuilderMIPS::VisitNeg(HNeg* neg) {
4176 LocationSummary* locations =
4177 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
4178 switch (neg->GetResultType()) {
4179 case Primitive::kPrimInt:
4180 case Primitive::kPrimLong:
4181 locations->SetInAt(0, Location::RequiresRegister());
4182 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4183 break;
4184
4185 case Primitive::kPrimFloat:
4186 case Primitive::kPrimDouble:
4187 locations->SetInAt(0, Location::RequiresFpuRegister());
4188 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4189 break;
4190
4191 default:
4192 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
4193 }
4194}
4195
4196void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) {
4197 Primitive::Type type = instruction->GetType();
4198 LocationSummary* locations = instruction->GetLocations();
4199
4200 switch (type) {
4201 case Primitive::kPrimInt: {
4202 Register dst = locations->Out().AsRegister<Register>();
4203 Register src = locations->InAt(0).AsRegister<Register>();
4204 __ Subu(dst, ZERO, src);
4205 break;
4206 }
4207 case Primitive::kPrimLong: {
4208 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4209 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4210 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4211 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
4212 __ Subu(dst_low, ZERO, src_low);
4213 __ Sltu(TMP, ZERO, dst_low);
4214 __ Subu(dst_high, ZERO, src_high);
4215 __ Subu(dst_high, dst_high, TMP);
4216 break;
4217 }
4218 case Primitive::kPrimFloat:
4219 case Primitive::kPrimDouble: {
4220 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4221 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
4222 if (type == Primitive::kPrimFloat) {
4223 __ NegS(dst, src);
4224 } else {
4225 __ NegD(dst, src);
4226 }
4227 break;
4228 }
4229 default:
4230 LOG(FATAL) << "Unexpected neg type " << type;
4231 }
4232}
4233
4234void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) {
4235 LocationSummary* locations =
4236 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4237 InvokeRuntimeCallingConvention calling_convention;
4238 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4239 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
4240 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
4241 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4242}
4243
4244void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) {
4245 InvokeRuntimeCallingConvention calling_convention;
4246 Register current_method_register = calling_convention.GetRegisterAt(2);
4247 __ Lw(current_method_register, SP, kCurrentMethodStackOffset);
4248 // Move an uint16_t value to a register.
4249 __ LoadConst32(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
4250 codegen_->InvokeRuntime(
4251 GetThreadOffset<kMipsWordSize>(instruction->GetEntrypoint()).Int32Value(),
4252 instruction,
4253 instruction->GetDexPc(),
4254 nullptr,
4255 IsDirectEntrypoint(kQuickAllocArrayWithAccessCheck));
4256 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
4257 void*, uint32_t, int32_t, ArtMethod*>();
4258}
4259
4260void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) {
4261 LocationSummary* locations =
4262 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4263 InvokeRuntimeCallingConvention calling_convention;
David Brazdil6de19382016-01-08 17:37:10 +00004264 if (instruction->IsStringAlloc()) {
4265 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
4266 } else {
4267 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4268 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4269 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004270 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
4271}
4272
4273void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) {
David Brazdil6de19382016-01-08 17:37:10 +00004274 if (instruction->IsStringAlloc()) {
4275 // String is allocated through StringFactory. Call NewEmptyString entry point.
4276 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
4277 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsWordSize);
4278 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
4279 __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value());
4280 __ Jalr(T9);
4281 __ Nop();
4282 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
4283 } else {
4284 codegen_->InvokeRuntime(
4285 GetThreadOffset<kMipsWordSize>(instruction->GetEntrypoint()).Int32Value(),
4286 instruction,
4287 instruction->GetDexPc(),
4288 nullptr,
4289 IsDirectEntrypoint(kQuickAllocObjectWithAccessCheck));
4290 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
4291 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004292}
4293
4294void LocationsBuilderMIPS::VisitNot(HNot* instruction) {
4295 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4296 locations->SetInAt(0, Location::RequiresRegister());
4297 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4298}
4299
4300void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) {
4301 Primitive::Type type = instruction->GetType();
4302 LocationSummary* locations = instruction->GetLocations();
4303
4304 switch (type) {
4305 case Primitive::kPrimInt: {
4306 Register dst = locations->Out().AsRegister<Register>();
4307 Register src = locations->InAt(0).AsRegister<Register>();
4308 __ Nor(dst, src, ZERO);
4309 break;
4310 }
4311
4312 case Primitive::kPrimLong: {
4313 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4314 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4315 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4316 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
4317 __ Nor(dst_high, src_high, ZERO);
4318 __ Nor(dst_low, src_low, ZERO);
4319 break;
4320 }
4321
4322 default:
4323 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
4324 }
4325}
4326
4327void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) {
4328 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4329 locations->SetInAt(0, Location::RequiresRegister());
4330 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4331}
4332
4333void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) {
4334 LocationSummary* locations = instruction->GetLocations();
4335 __ Xori(locations->Out().AsRegister<Register>(),
4336 locations->InAt(0).AsRegister<Register>(),
4337 1);
4338}
4339
4340void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) {
4341 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4342 ? LocationSummary::kCallOnSlowPath
4343 : LocationSummary::kNoCall;
4344 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4345 locations->SetInAt(0, Location::RequiresRegister());
4346 if (instruction->HasUses()) {
4347 locations->SetOut(Location::SameAsFirstInput());
4348 }
4349}
4350
Calin Juravle2ae48182016-03-16 14:05:09 +00004351void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) {
4352 if (CanMoveNullCheckToUser(instruction)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004353 return;
4354 }
4355 Location obj = instruction->GetLocations()->InAt(0);
4356
4357 __ Lw(ZERO, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00004358 RecordPcInfo(instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004359}
4360
Calin Juravle2ae48182016-03-16 14:05:09 +00004361void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004362 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00004363 AddSlowPath(slow_path);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004364
4365 Location obj = instruction->GetLocations()->InAt(0);
4366
4367 __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
4368}
4369
4370void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00004371 codegen_->GenerateNullCheck(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004372}
4373
4374void LocationsBuilderMIPS::VisitOr(HOr* instruction) {
4375 HandleBinaryOp(instruction);
4376}
4377
4378void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) {
4379 HandleBinaryOp(instruction);
4380}
4381
4382void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
4383 LOG(FATAL) << "Unreachable";
4384}
4385
4386void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) {
4387 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
4388}
4389
4390void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) {
4391 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4392 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
4393 if (location.IsStackSlot()) {
4394 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
4395 } else if (location.IsDoubleStackSlot()) {
4396 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
4397 }
4398 locations->SetOut(location);
4399}
4400
4401void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction
4402 ATTRIBUTE_UNUSED) {
4403 // Nothing to do, the parameter is already at its location.
4404}
4405
4406void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) {
4407 LocationSummary* locations =
4408 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4409 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
4410}
4411
4412void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction
4413 ATTRIBUTE_UNUSED) {
4414 // Nothing to do, the method is already at its location.
4415}
4416
4417void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) {
4418 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Vladimir Marko372f10e2016-05-17 16:30:10 +01004419 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004420 locations->SetInAt(i, Location::Any());
4421 }
4422 locations->SetOut(Location::Any());
4423}
4424
4425void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
4426 LOG(FATAL) << "Unreachable";
4427}
4428
4429void LocationsBuilderMIPS::VisitRem(HRem* rem) {
4430 Primitive::Type type = rem->GetResultType();
4431 LocationSummary::CallKind call_kind =
4432 (type == Primitive::kPrimInt) ? LocationSummary::kNoCall : LocationSummary::kCall;
4433 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
4434
4435 switch (type) {
4436 case Primitive::kPrimInt:
4437 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08004438 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004439 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4440 break;
4441
4442 case Primitive::kPrimLong: {
4443 InvokeRuntimeCallingConvention calling_convention;
4444 locations->SetInAt(0, Location::RegisterPairLocation(
4445 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
4446 locations->SetInAt(1, Location::RegisterPairLocation(
4447 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
4448 locations->SetOut(calling_convention.GetReturnLocation(type));
4449 break;
4450 }
4451
4452 case Primitive::kPrimFloat:
4453 case Primitive::kPrimDouble: {
4454 InvokeRuntimeCallingConvention calling_convention;
4455 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
4456 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
4457 locations->SetOut(calling_convention.GetReturnLocation(type));
4458 break;
4459 }
4460
4461 default:
4462 LOG(FATAL) << "Unexpected rem type " << type;
4463 }
4464}
4465
4466void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) {
4467 Primitive::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004468
4469 switch (type) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08004470 case Primitive::kPrimInt:
4471 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004472 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004473 case Primitive::kPrimLong: {
4474 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod),
4475 instruction,
4476 instruction->GetDexPc(),
4477 nullptr,
4478 IsDirectEntrypoint(kQuickLmod));
4479 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
4480 break;
4481 }
4482 case Primitive::kPrimFloat: {
4483 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf),
4484 instruction, instruction->GetDexPc(),
4485 nullptr,
4486 IsDirectEntrypoint(kQuickFmodf));
Roland Levillain888d0672015-11-23 18:53:50 +00004487 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004488 break;
4489 }
4490 case Primitive::kPrimDouble: {
4491 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod),
4492 instruction, instruction->GetDexPc(),
4493 nullptr,
4494 IsDirectEntrypoint(kQuickFmod));
Roland Levillain888d0672015-11-23 18:53:50 +00004495 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004496 break;
4497 }
4498 default:
4499 LOG(FATAL) << "Unexpected rem type " << type;
4500 }
4501}
4502
4503void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
4504 memory_barrier->SetLocations(nullptr);
4505}
4506
4507void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
4508 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
4509}
4510
4511void LocationsBuilderMIPS::VisitReturn(HReturn* ret) {
4512 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret);
4513 Primitive::Type return_type = ret->InputAt(0)->GetType();
4514 locations->SetInAt(0, MipsReturnLocation(return_type));
4515}
4516
4517void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
4518 codegen_->GenerateFrameExit();
4519}
4520
4521void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) {
4522 ret->SetLocations(nullptr);
4523}
4524
4525void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
4526 codegen_->GenerateFrameExit();
4527}
4528
Alexey Frunze92d90602015-12-18 18:16:36 -08004529void LocationsBuilderMIPS::VisitRor(HRor* ror) {
4530 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00004531}
4532
Alexey Frunze92d90602015-12-18 18:16:36 -08004533void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) {
4534 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00004535}
4536
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004537void LocationsBuilderMIPS::VisitShl(HShl* shl) {
4538 HandleShift(shl);
4539}
4540
4541void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) {
4542 HandleShift(shl);
4543}
4544
4545void LocationsBuilderMIPS::VisitShr(HShr* shr) {
4546 HandleShift(shr);
4547}
4548
4549void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) {
4550 HandleShift(shr);
4551}
4552
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004553void LocationsBuilderMIPS::VisitSub(HSub* instruction) {
4554 HandleBinaryOp(instruction);
4555}
4556
4557void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) {
4558 HandleBinaryOp(instruction);
4559}
4560
4561void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4562 HandleFieldGet(instruction, instruction->GetFieldInfo());
4563}
4564
4565void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4566 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
4567}
4568
4569void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
4570 HandleFieldSet(instruction, instruction->GetFieldInfo());
4571}
4572
4573void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
4574 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
4575}
4576
4577void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet(
4578 HUnresolvedInstanceFieldGet* instruction) {
4579 FieldAccessCallingConventionMIPS calling_convention;
4580 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
4581 instruction->GetFieldType(),
4582 calling_convention);
4583}
4584
4585void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet(
4586 HUnresolvedInstanceFieldGet* instruction) {
4587 FieldAccessCallingConventionMIPS calling_convention;
4588 codegen_->GenerateUnresolvedFieldAccess(instruction,
4589 instruction->GetFieldType(),
4590 instruction->GetFieldIndex(),
4591 instruction->GetDexPc(),
4592 calling_convention);
4593}
4594
4595void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet(
4596 HUnresolvedInstanceFieldSet* instruction) {
4597 FieldAccessCallingConventionMIPS calling_convention;
4598 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
4599 instruction->GetFieldType(),
4600 calling_convention);
4601}
4602
4603void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet(
4604 HUnresolvedInstanceFieldSet* instruction) {
4605 FieldAccessCallingConventionMIPS calling_convention;
4606 codegen_->GenerateUnresolvedFieldAccess(instruction,
4607 instruction->GetFieldType(),
4608 instruction->GetFieldIndex(),
4609 instruction->GetDexPc(),
4610 calling_convention);
4611}
4612
4613void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet(
4614 HUnresolvedStaticFieldGet* instruction) {
4615 FieldAccessCallingConventionMIPS calling_convention;
4616 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
4617 instruction->GetFieldType(),
4618 calling_convention);
4619}
4620
4621void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet(
4622 HUnresolvedStaticFieldGet* instruction) {
4623 FieldAccessCallingConventionMIPS calling_convention;
4624 codegen_->GenerateUnresolvedFieldAccess(instruction,
4625 instruction->GetFieldType(),
4626 instruction->GetFieldIndex(),
4627 instruction->GetDexPc(),
4628 calling_convention);
4629}
4630
4631void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet(
4632 HUnresolvedStaticFieldSet* instruction) {
4633 FieldAccessCallingConventionMIPS calling_convention;
4634 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
4635 instruction->GetFieldType(),
4636 calling_convention);
4637}
4638
4639void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet(
4640 HUnresolvedStaticFieldSet* instruction) {
4641 FieldAccessCallingConventionMIPS calling_convention;
4642 codegen_->GenerateUnresolvedFieldAccess(instruction,
4643 instruction->GetFieldType(),
4644 instruction->GetFieldIndex(),
4645 instruction->GetDexPc(),
4646 calling_convention);
4647}
4648
4649void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
4650 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
4651}
4652
4653void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
4654 HBasicBlock* block = instruction->GetBlock();
4655 if (block->GetLoopInformation() != nullptr) {
4656 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
4657 // The back edge will generate the suspend check.
4658 return;
4659 }
4660 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
4661 // The goto will generate the suspend check.
4662 return;
4663 }
4664 GenerateSuspendCheck(instruction, nullptr);
4665}
4666
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004667void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) {
4668 LocationSummary* locations =
4669 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4670 InvokeRuntimeCallingConvention calling_convention;
4671 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4672}
4673
4674void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) {
4675 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException),
4676 instruction,
4677 instruction->GetDexPc(),
4678 nullptr,
4679 IsDirectEntrypoint(kQuickDeliverException));
4680 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
4681}
4682
4683void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) {
4684 Primitive::Type input_type = conversion->GetInputType();
4685 Primitive::Type result_type = conversion->GetResultType();
4686 DCHECK_NE(input_type, result_type);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004687 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004688
4689 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
4690 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
4691 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
4692 }
4693
4694 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004695 if (!isR6 &&
4696 ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) ||
4697 (result_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(input_type)))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004698 call_kind = LocationSummary::kCall;
4699 }
4700
4701 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
4702
4703 if (call_kind == LocationSummary::kNoCall) {
4704 if (Primitive::IsFloatingPointType(input_type)) {
4705 locations->SetInAt(0, Location::RequiresFpuRegister());
4706 } else {
4707 locations->SetInAt(0, Location::RequiresRegister());
4708 }
4709
4710 if (Primitive::IsFloatingPointType(result_type)) {
4711 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4712 } else {
4713 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4714 }
4715 } else {
4716 InvokeRuntimeCallingConvention calling_convention;
4717
4718 if (Primitive::IsFloatingPointType(input_type)) {
4719 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
4720 } else {
4721 DCHECK_EQ(input_type, Primitive::kPrimLong);
4722 locations->SetInAt(0, Location::RegisterPairLocation(
4723 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
4724 }
4725
4726 locations->SetOut(calling_convention.GetReturnLocation(result_type));
4727 }
4728}
4729
4730void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) {
4731 LocationSummary* locations = conversion->GetLocations();
4732 Primitive::Type result_type = conversion->GetResultType();
4733 Primitive::Type input_type = conversion->GetInputType();
4734 bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004735 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4736 bool fpu_32bit = codegen_->GetInstructionSetFeatures().Is32BitFloatingPoint();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004737
4738 DCHECK_NE(input_type, result_type);
4739
4740 if (result_type == Primitive::kPrimLong && Primitive::IsIntegralType(input_type)) {
4741 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4742 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4743 Register src = locations->InAt(0).AsRegister<Register>();
4744
4745 __ Move(dst_low, src);
4746 __ Sra(dst_high, src, 31);
4747 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
4748 Register dst = locations->Out().AsRegister<Register>();
4749 Register src = (input_type == Primitive::kPrimLong)
4750 ? locations->InAt(0).AsRegisterPairLow<Register>()
4751 : locations->InAt(0).AsRegister<Register>();
4752
4753 switch (result_type) {
4754 case Primitive::kPrimChar:
4755 __ Andi(dst, src, 0xFFFF);
4756 break;
4757 case Primitive::kPrimByte:
4758 if (has_sign_extension) {
4759 __ Seb(dst, src);
4760 } else {
4761 __ Sll(dst, src, 24);
4762 __ Sra(dst, dst, 24);
4763 }
4764 break;
4765 case Primitive::kPrimShort:
4766 if (has_sign_extension) {
4767 __ Seh(dst, src);
4768 } else {
4769 __ Sll(dst, src, 16);
4770 __ Sra(dst, dst, 16);
4771 }
4772 break;
4773 case Primitive::kPrimInt:
4774 __ Move(dst, src);
4775 break;
4776
4777 default:
4778 LOG(FATAL) << "Unexpected type conversion from " << input_type
4779 << " to " << result_type;
4780 }
4781 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004782 if (input_type == Primitive::kPrimLong) {
4783 if (isR6) {
4784 // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
4785 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
4786 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4787 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
4788 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4789 __ Mtc1(src_low, FTMP);
4790 __ Mthc1(src_high, FTMP);
4791 if (result_type == Primitive::kPrimFloat) {
4792 __ Cvtsl(dst, FTMP);
4793 } else {
4794 __ Cvtdl(dst, FTMP);
4795 }
4796 } else {
4797 int32_t entry_offset = (result_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pL2f)
4798 : QUICK_ENTRY_POINT(pL2d);
4799 bool direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickL2f)
4800 : IsDirectEntrypoint(kQuickL2d);
4801 codegen_->InvokeRuntime(entry_offset,
4802 conversion,
4803 conversion->GetDexPc(),
4804 nullptr,
4805 direct);
4806 if (result_type == Primitive::kPrimFloat) {
4807 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
4808 } else {
4809 CheckEntrypointTypes<kQuickL2d, double, int64_t>();
4810 }
4811 }
4812 } else {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004813 Register src = locations->InAt(0).AsRegister<Register>();
4814 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4815 __ Mtc1(src, FTMP);
4816 if (result_type == Primitive::kPrimFloat) {
4817 __ Cvtsw(dst, FTMP);
4818 } else {
4819 __ Cvtdw(dst, FTMP);
4820 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004821 }
4822 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
4823 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004824 if (result_type == Primitive::kPrimLong) {
4825 if (isR6) {
4826 // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
4827 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
4828 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
4829 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4830 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4831 MipsLabel truncate;
4832 MipsLabel done;
4833
4834 // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive
4835 // value when the input is either a NaN or is outside of the range of the output type
4836 // after the truncation. IOW, the three special cases (NaN, too small, too big) produce
4837 // the same result.
4838 //
4839 // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum
4840 // value of the output type if the input is outside of the range after the truncation or
4841 // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct
4842 // results. This matches the desired float/double-to-int/long conversion exactly.
4843 //
4844 // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction.
4845 //
4846 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
4847 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
4848 // even though it must be NAN2008=1 on R6.
4849 //
4850 // The code takes care of the different behaviors by first comparing the input to the
4851 // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int).
4852 // If the input is greater than or equal to the minimum, it procedes to the truncate
4853 // instruction, which will handle such an input the same way irrespective of NAN2008.
4854 // Otherwise the input is compared to itself to determine whether it is a NaN or not
4855 // in order to return either zero or the minimum value.
4856 //
4857 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
4858 // truncate instruction for MIPS64R6.
4859 if (input_type == Primitive::kPrimFloat) {
4860 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min());
4861 __ LoadConst32(TMP, min_val);
4862 __ Mtc1(TMP, FTMP);
4863 __ CmpLeS(FTMP, FTMP, src);
4864 } else {
4865 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min());
4866 __ LoadConst32(TMP, High32Bits(min_val));
4867 __ Mtc1(ZERO, FTMP);
4868 __ Mthc1(TMP, FTMP);
4869 __ CmpLeD(FTMP, FTMP, src);
4870 }
4871
4872 __ Bc1nez(FTMP, &truncate);
4873
4874 if (input_type == Primitive::kPrimFloat) {
4875 __ CmpEqS(FTMP, src, src);
4876 } else {
4877 __ CmpEqD(FTMP, src, src);
4878 }
4879 __ Move(dst_low, ZERO);
4880 __ LoadConst32(dst_high, std::numeric_limits<int32_t>::min());
4881 __ Mfc1(TMP, FTMP);
4882 __ And(dst_high, dst_high, TMP);
4883
4884 __ B(&done);
4885
4886 __ Bind(&truncate);
4887
4888 if (input_type == Primitive::kPrimFloat) {
4889 __ TruncLS(FTMP, src);
4890 } else {
4891 __ TruncLD(FTMP, src);
4892 }
4893 __ Mfc1(dst_low, FTMP);
4894 __ Mfhc1(dst_high, FTMP);
4895
4896 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004897 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004898 int32_t entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2l)
4899 : QUICK_ENTRY_POINT(pD2l);
4900 bool direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickF2l)
4901 : IsDirectEntrypoint(kQuickD2l);
4902 codegen_->InvokeRuntime(entry_offset, conversion, conversion->GetDexPc(), nullptr, direct);
4903 if (input_type == Primitive::kPrimFloat) {
4904 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
4905 } else {
4906 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
4907 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004908 }
4909 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004910 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
4911 Register dst = locations->Out().AsRegister<Register>();
4912 MipsLabel truncate;
4913 MipsLabel done;
4914
4915 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
4916 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
4917 // even though it must be NAN2008=1 on R6.
4918 //
4919 // For details see the large comment above for the truncation of float/double to long on R6.
4920 //
4921 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
4922 // truncate instruction for MIPS64R6.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004923 if (input_type == Primitive::kPrimFloat) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004924 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min());
4925 __ LoadConst32(TMP, min_val);
4926 __ Mtc1(TMP, FTMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004927 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004928 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min());
4929 __ LoadConst32(TMP, High32Bits(min_val));
4930 __ Mtc1(ZERO, FTMP);
4931 if (fpu_32bit) {
4932 __ Mtc1(TMP, static_cast<FRegister>(FTMP + 1));
4933 } else {
4934 __ Mthc1(TMP, FTMP);
4935 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004936 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004937
4938 if (isR6) {
4939 if (input_type == Primitive::kPrimFloat) {
4940 __ CmpLeS(FTMP, FTMP, src);
4941 } else {
4942 __ CmpLeD(FTMP, FTMP, src);
4943 }
4944 __ Bc1nez(FTMP, &truncate);
4945
4946 if (input_type == Primitive::kPrimFloat) {
4947 __ CmpEqS(FTMP, src, src);
4948 } else {
4949 __ CmpEqD(FTMP, src, src);
4950 }
4951 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
4952 __ Mfc1(TMP, FTMP);
4953 __ And(dst, dst, TMP);
4954 } else {
4955 if (input_type == Primitive::kPrimFloat) {
4956 __ ColeS(0, FTMP, src);
4957 } else {
4958 __ ColeD(0, FTMP, src);
4959 }
4960 __ Bc1t(0, &truncate);
4961
4962 if (input_type == Primitive::kPrimFloat) {
4963 __ CeqS(0, src, src);
4964 } else {
4965 __ CeqD(0, src, src);
4966 }
4967 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
4968 __ Movf(dst, ZERO, 0);
4969 }
4970
4971 __ B(&done);
4972
4973 __ Bind(&truncate);
4974
4975 if (input_type == Primitive::kPrimFloat) {
4976 __ TruncWS(FTMP, src);
4977 } else {
4978 __ TruncWD(FTMP, src);
4979 }
4980 __ Mfc1(dst, FTMP);
4981
4982 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004983 }
4984 } else if (Primitive::IsFloatingPointType(result_type) &&
4985 Primitive::IsFloatingPointType(input_type)) {
4986 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4987 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
4988 if (result_type == Primitive::kPrimFloat) {
4989 __ Cvtsd(dst, src);
4990 } else {
4991 __ Cvtds(dst, src);
4992 }
4993 } else {
4994 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
4995 << " to " << result_type;
4996 }
4997}
4998
4999void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) {
5000 HandleShift(ushr);
5001}
5002
5003void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) {
5004 HandleShift(ushr);
5005}
5006
5007void LocationsBuilderMIPS::VisitXor(HXor* instruction) {
5008 HandleBinaryOp(instruction);
5009}
5010
5011void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) {
5012 HandleBinaryOp(instruction);
5013}
5014
5015void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
5016 // Nothing to do, this should be removed during prepare for register allocator.
5017 LOG(FATAL) << "Unreachable";
5018}
5019
5020void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
5021 // Nothing to do, this should be removed during prepare for register allocator.
5022 LOG(FATAL) << "Unreachable";
5023}
5024
5025void LocationsBuilderMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005026 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005027}
5028
5029void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005030 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005031}
5032
5033void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005034 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005035}
5036
5037void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005038 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005039}
5040
5041void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005042 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005043}
5044
5045void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005046 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005047}
5048
5049void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005050 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005051}
5052
5053void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005054 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005055}
5056
5057void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005058 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005059}
5060
5061void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005062 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005063}
5064
5065void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005066 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005067}
5068
5069void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005070 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005071}
5072
5073void LocationsBuilderMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005074 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005075}
5076
5077void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005078 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005079}
5080
5081void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005082 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005083}
5084
5085void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005086 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005087}
5088
5089void LocationsBuilderMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005090 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005091}
5092
5093void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005094 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005095}
5096
5097void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005098 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005099}
5100
5101void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005102 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005103}
5104
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005105void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5106 LocationSummary* locations =
5107 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
5108 locations->SetInAt(0, Location::RequiresRegister());
5109}
5110
5111void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5112 int32_t lower_bound = switch_instr->GetStartValue();
5113 int32_t num_entries = switch_instr->GetNumEntries();
5114 LocationSummary* locations = switch_instr->GetLocations();
5115 Register value_reg = locations->InAt(0).AsRegister<Register>();
5116 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
5117
5118 // Create a set of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005119 Register temp_reg = TMP;
5120 __ Addiu32(temp_reg, value_reg, -lower_bound);
5121 // Jump to default if index is negative
5122 // Note: We don't check the case that index is positive while value < lower_bound, because in
5123 // this case, index >= num_entries must be true. So that we can save one branch instruction.
5124 __ Bltz(temp_reg, codegen_->GetLabelOf(default_block));
5125
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005126 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005127 // Jump to successors[0] if value == lower_bound.
5128 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0]));
5129 int32_t last_index = 0;
5130 for (; num_entries - last_index > 2; last_index += 2) {
5131 __ Addiu(temp_reg, temp_reg, -2);
5132 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
5133 __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
5134 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
5135 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
5136 }
5137 if (num_entries - last_index == 2) {
5138 // The last missing case_value.
5139 __ Addiu(temp_reg, temp_reg, -1);
5140 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005141 }
5142
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005143 // And the default for any other value.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005144 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
5145 __ B(codegen_->GetLabelOf(default_block));
5146 }
5147}
5148
5149void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5150 // The trampoline uses the same calling convention as dex calling conventions,
5151 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
5152 // the method_idx.
5153 HandleInvoke(invoke);
5154}
5155
5156void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5157 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
5158}
5159
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005160void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) {
5161 LocationSummary* locations =
5162 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
5163 locations->SetInAt(0, Location::RequiresRegister());
5164 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005165}
5166
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005167void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) {
5168 LocationSummary* locations = instruction->GetLocations();
5169 uint32_t method_offset = 0;
Vladimir Markoa1de9182016-02-25 11:37:38 +00005170 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005171 method_offset = mirror::Class::EmbeddedVTableEntryOffset(
5172 instruction->GetIndex(), kMipsPointerSize).SizeValue();
5173 } else {
Nelli Kimbadee982016-05-13 13:08:53 +03005174 __ LoadFromOffset(kLoadWord,
5175 locations->Out().AsRegister<Register>(),
5176 locations->InAt(0).AsRegister<Register>(),
5177 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
5178 method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity50706432016-06-14 11:31:04 -07005179 instruction->GetIndex(), kMipsPointerSize));
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005180 }
5181 __ LoadFromOffset(kLoadWord,
5182 locations->Out().AsRegister<Register>(),
5183 locations->InAt(0).AsRegister<Register>(),
5184 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005185}
5186
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005187#undef __
5188#undef QUICK_ENTRY_POINT
5189
5190} // namespace mips
5191} // namespace art