blob: 0677dad07894fa0d6220c8898f30b30015c01f37 [file] [log] [blame]
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "code_generator_mips.h"
18
19#include "arch/mips/entrypoints_direct_mips.h"
20#include "arch/mips/instruction_set_features_mips.h"
21#include "art_method.h"
Chris Larsen701566a2015-10-27 15:29:13 -070022#include "code_generator_utils.h"
Vladimir Marko3a21e382016-09-02 12:38:38 +010023#include "compiled_method.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020024#include "entrypoints/quick/quick_entrypoints.h"
25#include "entrypoints/quick/quick_entrypoints_enum.h"
26#include "gc/accounting/card_table.h"
27#include "intrinsics.h"
Chris Larsen701566a2015-10-27 15:29:13 -070028#include "intrinsics_mips.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020029#include "mirror/array-inl.h"
30#include "mirror/class-inl.h"
31#include "offsets.h"
32#include "thread.h"
33#include "utils/assembler.h"
34#include "utils/mips/assembler_mips.h"
35#include "utils/stack_checks.h"
36
37namespace art {
38namespace mips {
39
40static constexpr int kCurrentMethodStackOffset = 0;
41static constexpr Register kMethodRegisterArgument = A0;
42
Alexey Frunzee3fb2452016-05-10 16:08:05 -070043// We'll maximize the range of a single load instruction for dex cache array accesses
44// by aligning offset -32768 with the offset of the first used element.
45static constexpr uint32_t kDexCacheArrayLwOffset = 0x8000;
46
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020047Location MipsReturnLocation(Primitive::Type return_type) {
48 switch (return_type) {
49 case Primitive::kPrimBoolean:
50 case Primitive::kPrimByte:
51 case Primitive::kPrimChar:
52 case Primitive::kPrimShort:
53 case Primitive::kPrimInt:
54 case Primitive::kPrimNot:
55 return Location::RegisterLocation(V0);
56
57 case Primitive::kPrimLong:
58 return Location::RegisterPairLocation(V0, V1);
59
60 case Primitive::kPrimFloat:
61 case Primitive::kPrimDouble:
62 return Location::FpuRegisterLocation(F0);
63
64 case Primitive::kPrimVoid:
65 return Location();
66 }
67 UNREACHABLE();
68}
69
70Location InvokeDexCallingConventionVisitorMIPS::GetReturnLocation(Primitive::Type type) const {
71 return MipsReturnLocation(type);
72}
73
74Location InvokeDexCallingConventionVisitorMIPS::GetMethodLocation() const {
75 return Location::RegisterLocation(kMethodRegisterArgument);
76}
77
78Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(Primitive::Type type) {
79 Location next_location;
80
81 switch (type) {
82 case Primitive::kPrimBoolean:
83 case Primitive::kPrimByte:
84 case Primitive::kPrimChar:
85 case Primitive::kPrimShort:
86 case Primitive::kPrimInt:
87 case Primitive::kPrimNot: {
88 uint32_t gp_index = gp_index_++;
89 if (gp_index < calling_convention.GetNumberOfRegisters()) {
90 next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index));
91 } else {
92 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
93 next_location = Location::StackSlot(stack_offset);
94 }
95 break;
96 }
97
98 case Primitive::kPrimLong: {
99 uint32_t gp_index = gp_index_;
100 gp_index_ += 2;
101 if (gp_index + 1 < calling_convention.GetNumberOfRegisters()) {
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800102 Register reg = calling_convention.GetRegisterAt(gp_index);
103 if (reg == A1 || reg == A3) {
104 gp_index_++; // Skip A1(A3), and use A2_A3(T0_T1) instead.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200105 gp_index++;
106 }
107 Register low_even = calling_convention.GetRegisterAt(gp_index);
108 Register high_odd = calling_convention.GetRegisterAt(gp_index + 1);
109 DCHECK_EQ(low_even + 1, high_odd);
110 next_location = Location::RegisterPairLocation(low_even, high_odd);
111 } else {
112 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
113 next_location = Location::DoubleStackSlot(stack_offset);
114 }
115 break;
116 }
117
118 // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double
119 // will take up the even/odd pair, while floats are stored in even regs only.
120 // On 64 bit FPU, both double and float are stored in even registers only.
121 case Primitive::kPrimFloat:
122 case Primitive::kPrimDouble: {
123 uint32_t float_index = float_index_++;
124 if (float_index < calling_convention.GetNumberOfFpuRegisters()) {
125 next_location = Location::FpuRegisterLocation(
126 calling_convention.GetFpuRegisterAt(float_index));
127 } else {
128 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
129 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
130 : Location::StackSlot(stack_offset);
131 }
132 break;
133 }
134
135 case Primitive::kPrimVoid:
136 LOG(FATAL) << "Unexpected parameter type " << type;
137 break;
138 }
139
140 // Space on the stack is reserved for all arguments.
141 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
142
143 return next_location;
144}
145
146Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type type) {
147 return MipsReturnLocation(type);
148}
149
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100150// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
151#define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700152#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200153
154class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS {
155 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000156 explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200157
158 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
159 LocationSummary* locations = instruction_->GetLocations();
160 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
161 __ Bind(GetEntryLabel());
162 if (instruction_->CanThrowIntoCatchBlock()) {
163 // Live registers will be restored in the catch block if caught.
164 SaveLiveRegisters(codegen, instruction_->GetLocations());
165 }
166 // We're moving two locations to locations that could overlap, so we need a parallel
167 // move resolver.
168 InvokeRuntimeCallingConvention calling_convention;
169 codegen->EmitParallelMoves(locations->InAt(0),
170 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
171 Primitive::kPrimInt,
172 locations->InAt(1),
173 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
174 Primitive::kPrimInt);
Serban Constantinescufca16662016-07-14 09:21:59 +0100175 QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt()
176 ? kQuickThrowStringBounds
177 : kQuickThrowArrayBounds;
178 mips_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100179 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200180 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
181 }
182
183 bool IsFatal() const OVERRIDE { return true; }
184
185 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; }
186
187 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200188 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS);
189};
190
191class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS {
192 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000193 explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200194
195 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
196 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
197 __ Bind(GetEntryLabel());
Serban Constantinescufca16662016-07-14 09:21:59 +0100198 mips_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200199 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
200 }
201
202 bool IsFatal() const OVERRIDE { return true; }
203
204 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; }
205
206 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200207 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS);
208};
209
210class LoadClassSlowPathMIPS : public SlowPathCodeMIPS {
211 public:
212 LoadClassSlowPathMIPS(HLoadClass* cls,
213 HInstruction* at,
214 uint32_t dex_pc,
215 bool do_clinit)
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000216 : SlowPathCodeMIPS(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200217 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
218 }
219
220 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000221 LocationSummary* locations = instruction_->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200222 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
223
224 __ Bind(GetEntryLabel());
225 SaveLiveRegisters(codegen, locations);
226
227 InvokeRuntimeCallingConvention calling_convention;
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000228 dex::TypeIndex type_index = cls_->GetTypeIndex();
229 __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200230
Serban Constantinescufca16662016-07-14 09:21:59 +0100231 QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage
232 : kQuickInitializeType;
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000233 mips_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200234 if (do_clinit_) {
235 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
236 } else {
237 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
238 }
239
240 // Move the class to the desired location.
241 Location out = locations->Out();
242 if (out.IsValid()) {
243 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000244 Primitive::Type type = instruction_->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200245 mips_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
246 }
247
248 RestoreLiveRegisters(codegen, locations);
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000249 // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry.
250 DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_);
251 if (cls_ == instruction_ && cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) {
252 DCHECK(out.IsValid());
253 // TODO: Change art_quick_initialize_type/art_quick_initialize_static_storage to
254 // kSaveEverything and use a temporary for the .bss entry address in the fast path,
255 // so that we can avoid another calculation here.
256 bool isR6 = mips_codegen->GetInstructionSetFeatures().IsR6();
257 Register base = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>();
258 DCHECK_NE(out.AsRegister<Register>(), AT);
259 CodeGeneratorMIPS::PcRelativePatchInfo* info =
Vladimir Marko1998cd02017-01-13 13:02:58 +0000260 mips_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index);
Alexey Frunze6b892cd2017-01-03 17:11:38 -0800261 bool reordering = __ SetReorder(false);
262 mips_codegen->EmitPcRelativeAddressPlaceholderHigh(info, TMP, base);
263 __ StoreToOffset(kStoreWord, out.AsRegister<Register>(), TMP, /* placeholder */ 0x5678);
264 __ SetReorder(reordering);
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000265 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200266 __ B(GetExitLabel());
267 }
268
269 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; }
270
271 private:
272 // The class this slow path will load.
273 HLoadClass* const cls_;
274
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200275 // The dex PC of `at_`.
276 const uint32_t dex_pc_;
277
278 // Whether to initialize the class.
279 const bool do_clinit_;
280
281 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS);
282};
283
284class LoadStringSlowPathMIPS : public SlowPathCodeMIPS {
285 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000286 explicit LoadStringSlowPathMIPS(HLoadString* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200287
288 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
289 LocationSummary* locations = instruction_->GetLocations();
290 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
291 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
292
293 __ Bind(GetEntryLabel());
294 SaveLiveRegisters(codegen, locations);
295
296 InvokeRuntimeCallingConvention calling_convention;
Vladimir Markoaad75c62016-10-03 08:46:48 +0000297 HLoadString* load = instruction_->AsLoadString();
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000298 const dex::StringIndex string_index = load->GetStringIndex();
299 __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_);
Serban Constantinescufca16662016-07-14 09:21:59 +0100300 mips_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200301 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
302 Primitive::Type type = instruction_->GetType();
303 mips_codegen->MoveLocation(locations->Out(),
304 calling_convention.GetReturnLocation(type),
305 type);
306
307 RestoreLiveRegisters(codegen, locations);
Vladimir Markoaad75c62016-10-03 08:46:48 +0000308
309 // Store the resolved String to the BSS entry.
310 // TODO: Change art_quick_resolve_string to kSaveEverything and use a temporary for the
311 // .bss entry address in the fast path, so that we can avoid another calculation here.
312 bool isR6 = mips_codegen->GetInstructionSetFeatures().IsR6();
313 Register base = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>();
314 Register out = locations->Out().AsRegister<Register>();
315 DCHECK_NE(out, AT);
316 CodeGeneratorMIPS::PcRelativePatchInfo* info =
317 mips_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index);
Alexey Frunze6b892cd2017-01-03 17:11:38 -0800318 bool reordering = __ SetReorder(false);
319 mips_codegen->EmitPcRelativeAddressPlaceholderHigh(info, TMP, base);
320 __ StoreToOffset(kStoreWord, out, TMP, /* placeholder */ 0x5678);
321 __ SetReorder(reordering);
Vladimir Markoaad75c62016-10-03 08:46:48 +0000322
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200323 __ B(GetExitLabel());
324 }
325
326 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; }
327
328 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200329 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS);
330};
331
332class NullCheckSlowPathMIPS : public SlowPathCodeMIPS {
333 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000334 explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200335
336 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
337 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
338 __ Bind(GetEntryLabel());
339 if (instruction_->CanThrowIntoCatchBlock()) {
340 // Live registers will be restored in the catch block if caught.
341 SaveLiveRegisters(codegen, instruction_->GetLocations());
342 }
Serban Constantinescufca16662016-07-14 09:21:59 +0100343 mips_codegen->InvokeRuntime(kQuickThrowNullPointer,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200344 instruction_,
345 instruction_->GetDexPc(),
Serban Constantinescufca16662016-07-14 09:21:59 +0100346 this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200347 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
348 }
349
350 bool IsFatal() const OVERRIDE { return true; }
351
352 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; }
353
354 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200355 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS);
356};
357
358class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS {
359 public:
360 SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000361 : SlowPathCodeMIPS(instruction), successor_(successor) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200362
363 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
364 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
365 __ Bind(GetEntryLabel());
Serban Constantinescufca16662016-07-14 09:21:59 +0100366 mips_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200367 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200368 if (successor_ == nullptr) {
369 __ B(GetReturnLabel());
370 } else {
371 __ B(mips_codegen->GetLabelOf(successor_));
372 }
373 }
374
375 MipsLabel* GetReturnLabel() {
376 DCHECK(successor_ == nullptr);
377 return &return_label_;
378 }
379
380 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; }
381
382 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200383 // If not null, the block to branch to after the suspend check.
384 HBasicBlock* const successor_;
385
386 // If `successor_` is null, the label to branch to after the suspend check.
387 MipsLabel return_label_;
388
389 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS);
390};
391
392class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS {
393 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000394 explicit TypeCheckSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200395
396 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
397 LocationSummary* locations = instruction_->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200398 uint32_t dex_pc = instruction_->GetDexPc();
399 DCHECK(instruction_->IsCheckCast()
400 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
401 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
402
403 __ Bind(GetEntryLabel());
404 SaveLiveRegisters(codegen, locations);
405
406 // We're moving two locations to locations that could overlap, so we need a parallel
407 // move resolver.
408 InvokeRuntimeCallingConvention calling_convention;
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800409 codegen->EmitParallelMoves(locations->InAt(0),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200410 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
411 Primitive::kPrimNot,
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800412 locations->InAt(1),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200413 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
414 Primitive::kPrimNot);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200415 if (instruction_->IsInstanceOf()) {
Serban Constantinescufca16662016-07-14 09:21:59 +0100416 mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this);
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800417 CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200418 Primitive::Type ret_type = instruction_->GetType();
419 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
420 mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200421 } else {
422 DCHECK(instruction_->IsCheckCast());
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800423 mips_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this);
424 CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200425 }
426
427 RestoreLiveRegisters(codegen, locations);
428 __ B(GetExitLabel());
429 }
430
431 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; }
432
433 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200434 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS);
435};
436
437class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS {
438 public:
Aart Bik42249c32016-01-07 15:33:50 -0800439 explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000440 : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200441
442 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800443 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200444 __ Bind(GetEntryLabel());
Serban Constantinescufca16662016-07-14 09:21:59 +0100445 mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000446 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200447 }
448
449 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; }
450
451 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200452 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS);
453};
454
455CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph,
456 const MipsInstructionSetFeatures& isa_features,
457 const CompilerOptions& compiler_options,
458 OptimizingCompilerStats* stats)
459 : CodeGenerator(graph,
460 kNumberOfCoreRegisters,
461 kNumberOfFRegisters,
462 kNumberOfRegisterPairs,
463 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
464 arraysize(kCoreCalleeSaves)),
465 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
466 arraysize(kFpuCalleeSaves)),
467 compiler_options,
468 stats),
469 block_labels_(nullptr),
470 location_builder_(graph, this),
471 instruction_visitor_(graph, this),
472 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +0100473 assembler_(graph->GetArena(), &isa_features),
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700474 isa_features_(isa_features),
Alexey Frunze06a46c42016-07-19 15:00:40 -0700475 uint32_literals_(std::less<uint32_t>(),
476 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze06a46c42016-07-19 15:00:40 -0700477 pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
478 boot_image_string_patches_(StringReferenceValueComparator(),
479 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
480 pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
481 boot_image_type_patches_(TypeReferenceValueComparator(),
482 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
483 pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko1998cd02017-01-13 13:02:58 +0000484 type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze06a46c42016-07-19 15:00:40 -0700485 boot_image_address_patches_(std::less<uint32_t>(),
486 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze627c1a02017-01-30 19:28:14 -0800487 jit_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
488 jit_class_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze06a46c42016-07-19 15:00:40 -0700489 clobbered_ra_(false) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200490 // Save RA (containing the return address) to mimic Quick.
491 AddAllocatedRegister(Location::RegisterLocation(RA));
492}
493
494#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100495// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
496#define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700497#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200498
499void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) {
500 // Ensure that we fix up branches.
501 __ FinalizeCode();
502
503 // Adjust native pc offsets in stack maps.
504 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800505 uint32_t old_position =
506 stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kMips);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200507 uint32_t new_position = __ GetAdjustedPosition(old_position);
508 DCHECK_GE(new_position, old_position);
509 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
510 }
511
512 // Adjust pc offsets for the disassembly information.
513 if (disasm_info_ != nullptr) {
514 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
515 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
516 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
517 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
518 it.second.start = __ GetAdjustedPosition(it.second.start);
519 it.second.end = __ GetAdjustedPosition(it.second.end);
520 }
521 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
522 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
523 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
524 }
525 }
526
527 CodeGenerator::Finalize(allocator);
528}
529
530MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const {
531 return codegen_->GetAssembler();
532}
533
534void ParallelMoveResolverMIPS::EmitMove(size_t index) {
535 DCHECK_LT(index, moves_.size());
536 MoveOperands* move = moves_[index];
537 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
538}
539
540void ParallelMoveResolverMIPS::EmitSwap(size_t index) {
541 DCHECK_LT(index, moves_.size());
542 MoveOperands* move = moves_[index];
543 Primitive::Type type = move->GetType();
544 Location loc1 = move->GetDestination();
545 Location loc2 = move->GetSource();
546
547 DCHECK(!loc1.IsConstant());
548 DCHECK(!loc2.IsConstant());
549
550 if (loc1.Equals(loc2)) {
551 return;
552 }
553
554 if (loc1.IsRegister() && loc2.IsRegister()) {
555 // Swap 2 GPRs.
556 Register r1 = loc1.AsRegister<Register>();
557 Register r2 = loc2.AsRegister<Register>();
558 __ Move(TMP, r2);
559 __ Move(r2, r1);
560 __ Move(r1, TMP);
561 } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) {
562 FRegister f1 = loc1.AsFpuRegister<FRegister>();
563 FRegister f2 = loc2.AsFpuRegister<FRegister>();
564 if (type == Primitive::kPrimFloat) {
565 __ MovS(FTMP, f2);
566 __ MovS(f2, f1);
567 __ MovS(f1, FTMP);
568 } else {
569 DCHECK_EQ(type, Primitive::kPrimDouble);
570 __ MovD(FTMP, f2);
571 __ MovD(f2, f1);
572 __ MovD(f1, FTMP);
573 }
574 } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) ||
575 (loc1.IsFpuRegister() && loc2.IsRegister())) {
576 // Swap FPR and GPR.
577 DCHECK_EQ(type, Primitive::kPrimFloat); // Can only swap a float.
578 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
579 : loc2.AsFpuRegister<FRegister>();
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +0200580 Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200581 __ Move(TMP, r2);
582 __ Mfc1(r2, f1);
583 __ Mtc1(TMP, f1);
584 } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) {
585 // Swap 2 GPR register pairs.
586 Register r1 = loc1.AsRegisterPairLow<Register>();
587 Register r2 = loc2.AsRegisterPairLow<Register>();
588 __ Move(TMP, r2);
589 __ Move(r2, r1);
590 __ Move(r1, TMP);
591 r1 = loc1.AsRegisterPairHigh<Register>();
592 r2 = loc2.AsRegisterPairHigh<Register>();
593 __ Move(TMP, r2);
594 __ Move(r2, r1);
595 __ Move(r1, TMP);
596 } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) ||
597 (loc1.IsFpuRegister() && loc2.IsRegisterPair())) {
598 // Swap FPR and GPR register pair.
599 DCHECK_EQ(type, Primitive::kPrimDouble);
600 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
601 : loc2.AsFpuRegister<FRegister>();
602 Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
603 : loc2.AsRegisterPairLow<Register>();
604 Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
605 : loc2.AsRegisterPairHigh<Register>();
606 // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and
607 // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR
608 // unpredictable and the following mfch1 will fail.
609 __ Mfc1(TMP, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800610 __ MoveFromFpuHigh(AT, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200611 __ Mtc1(r2_l, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800612 __ MoveToFpuHigh(r2_h, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200613 __ Move(r2_l, TMP);
614 __ Move(r2_h, AT);
615 } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) {
616 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false);
617 } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) {
618 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true);
David Brazdilcc0f3112016-01-28 17:14:52 +0000619 } else if ((loc1.IsRegister() && loc2.IsStackSlot()) ||
620 (loc1.IsStackSlot() && loc2.IsRegister())) {
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +0200621 Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>();
622 intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex();
David Brazdilcc0f3112016-01-28 17:14:52 +0000623 __ Move(TMP, reg);
624 __ LoadFromOffset(kLoadWord, reg, SP, offset);
625 __ StoreToOffset(kStoreWord, TMP, SP, offset);
626 } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) ||
627 (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) {
628 Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
629 : loc2.AsRegisterPairLow<Register>();
630 Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
631 : loc2.AsRegisterPairHigh<Register>();
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +0200632 intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex();
David Brazdilcc0f3112016-01-28 17:14:52 +0000633 intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize)
634 : loc2.GetHighStackIndex(kMipsWordSize);
635 __ Move(TMP, reg_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000636 __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000637 __ StoreToOffset(kStoreWord, TMP, SP, offset_l);
David Brazdil04d3e872016-01-29 09:50:09 +0000638 __ Move(TMP, reg_h);
639 __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h);
640 __ StoreToOffset(kStoreWord, TMP, SP, offset_h);
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +0200641 } else if (loc1.IsFpuRegister() || loc2.IsFpuRegister()) {
642 FRegister reg = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
643 : loc2.AsFpuRegister<FRegister>();
644 intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex();
645 if (type == Primitive::kPrimFloat) {
646 __ MovS(FTMP, reg);
647 __ LoadSFromOffset(reg, SP, offset);
648 __ StoreSToOffset(FTMP, SP, offset);
649 } else {
650 DCHECK_EQ(type, Primitive::kPrimDouble);
651 __ MovD(FTMP, reg);
652 __ LoadDFromOffset(reg, SP, offset);
653 __ StoreDToOffset(FTMP, SP, offset);
654 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200655 } else {
656 LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported";
657 }
658}
659
660void ParallelMoveResolverMIPS::RestoreScratch(int reg) {
661 __ Pop(static_cast<Register>(reg));
662}
663
664void ParallelMoveResolverMIPS::SpillScratch(int reg) {
665 __ Push(static_cast<Register>(reg));
666}
667
668void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) {
669 // Allocate a scratch register other than TMP, if available.
670 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
671 // automatically unspilled when the scratch scope object is destroyed).
672 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
673 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
674 int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0;
675 for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) {
676 __ LoadFromOffset(kLoadWord,
677 Register(ensure_scratch.GetRegister()),
678 SP,
679 index1 + stack_offset);
680 __ LoadFromOffset(kLoadWord,
681 TMP,
682 SP,
683 index2 + stack_offset);
684 __ StoreToOffset(kStoreWord,
685 Register(ensure_scratch.GetRegister()),
686 SP,
687 index2 + stack_offset);
688 __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset);
689 }
690}
691
Alexey Frunze73296a72016-06-03 22:51:46 -0700692void CodeGeneratorMIPS::ComputeSpillMask() {
693 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
694 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
695 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
696 // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved
697 // registers, include the ZERO register to force alignment of FPU callee-saved registers
698 // within the stack frame.
699 if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) {
700 core_spill_mask_ |= (1 << ZERO);
701 }
Alexey Frunze58320ce2016-08-30 21:40:46 -0700702}
703
704bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const {
Alexey Frunze06a46c42016-07-19 15:00:40 -0700705 // If RA is clobbered by PC-relative operations on R2 and it's the only spilled register
Alexey Frunze58320ce2016-08-30 21:40:46 -0700706 // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration()
707 // into the path that creates a stack frame so that RA can be explicitly saved and restored.
708 // RA can't otherwise be saved/restored when it's the only spilled register.
Alexey Frunze58320ce2016-08-30 21:40:46 -0700709 return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_;
Alexey Frunze73296a72016-06-03 22:51:46 -0700710}
711
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200712static dwarf::Reg DWARFReg(Register reg) {
713 return dwarf::Reg::MipsCore(static_cast<int>(reg));
714}
715
716// TODO: mapping of floating-point registers to DWARF.
717
718void CodeGeneratorMIPS::GenerateFrameEntry() {
719 __ Bind(&frame_entry_label_);
720
721 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod();
722
723 if (do_overflow_check) {
724 __ LoadFromOffset(kLoadWord,
725 ZERO,
726 SP,
727 -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips)));
728 RecordPcInfo(nullptr, 0);
729 }
730
731 if (HasEmptyFrame()) {
Alexey Frunze58320ce2016-08-30 21:40:46 -0700732 CHECK_EQ(fpu_spill_mask_, 0u);
733 CHECK_EQ(core_spill_mask_, 1u << RA);
734 CHECK(!clobbered_ra_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200735 return;
736 }
737
738 // Make sure the frame size isn't unreasonably large.
739 if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) {
740 LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes";
741 }
742
743 // Spill callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200744
Alexey Frunze73296a72016-06-03 22:51:46 -0700745 uint32_t ofs = GetFrameSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200746 __ IncreaseFrameSize(ofs);
747
Alexey Frunze73296a72016-06-03 22:51:46 -0700748 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
749 Register reg = static_cast<Register>(MostSignificantBit(mask));
750 mask ^= 1u << reg;
751 ofs -= kMipsWordSize;
752 // The ZERO register is only included for alignment.
753 if (reg != ZERO) {
754 __ StoreToOffset(kStoreWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200755 __ cfi().RelOffset(DWARFReg(reg), ofs);
756 }
757 }
758
Alexey Frunze73296a72016-06-03 22:51:46 -0700759 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
760 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
761 mask ^= 1u << reg;
762 ofs -= kMipsDoublewordSize;
763 __ StoreDToOffset(reg, SP, ofs);
764 // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200765 }
766
Nicolas Geoffray96eeb4e2016-10-12 22:03:31 +0100767 // Save the current method if we need it. Note that we do not
768 // do this in HCurrentMethod, as the instruction might have been removed
769 // in the SSA graph.
770 if (RequiresCurrentMethod()) {
771 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
772 }
Goran Jakovljevicc6418422016-12-05 16:31:55 +0100773
774 if (GetGraph()->HasShouldDeoptimizeFlag()) {
775 // Initialize should deoptimize flag to 0.
776 __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag());
777 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200778}
779
780void CodeGeneratorMIPS::GenerateFrameExit() {
781 __ cfi().RememberState();
782
783 if (!HasEmptyFrame()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200784 // Restore callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200785
Alexey Frunze73296a72016-06-03 22:51:46 -0700786 // For better instruction scheduling restore RA before other registers.
787 uint32_t ofs = GetFrameSize();
788 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
789 Register reg = static_cast<Register>(MostSignificantBit(mask));
790 mask ^= 1u << reg;
791 ofs -= kMipsWordSize;
792 // The ZERO register is only included for alignment.
793 if (reg != ZERO) {
794 __ LoadFromOffset(kLoadWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200795 __ cfi().Restore(DWARFReg(reg));
796 }
797 }
798
Alexey Frunze73296a72016-06-03 22:51:46 -0700799 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
800 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
801 mask ^= 1u << reg;
802 ofs -= kMipsDoublewordSize;
803 __ LoadDFromOffset(reg, SP, ofs);
804 // TODO: __ cfi().Restore(DWARFReg(reg));
805 }
806
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700807 size_t frame_size = GetFrameSize();
808 // Adjust the stack pointer in the delay slot if doing so doesn't break CFI.
809 bool exchange = IsInt<16>(static_cast<int32_t>(frame_size));
810 bool reordering = __ SetReorder(false);
811 if (exchange) {
812 __ Jr(RA);
813 __ DecreaseFrameSize(frame_size); // Single instruction in delay slot.
814 } else {
815 __ DecreaseFrameSize(frame_size);
816 __ Jr(RA);
817 __ Nop(); // In delay slot.
818 }
819 __ SetReorder(reordering);
820 } else {
821 __ Jr(RA);
822 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200823 }
824
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200825 __ cfi().RestoreState();
826 __ cfi().DefCFAOffset(GetFrameSize());
827}
828
829void CodeGeneratorMIPS::Bind(HBasicBlock* block) {
830 __ Bind(GetLabelOf(block));
831}
832
833void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
834 if (src.Equals(dst)) {
835 return;
836 }
837
838 if (src.IsConstant()) {
839 MoveConstant(dst, src.GetConstant());
840 } else {
841 if (Primitive::Is64BitType(dst_type)) {
842 Move64(dst, src);
843 } else {
844 Move32(dst, src);
845 }
846 }
847}
848
849void CodeGeneratorMIPS::Move32(Location destination, Location source) {
850 if (source.Equals(destination)) {
851 return;
852 }
853
854 if (destination.IsRegister()) {
855 if (source.IsRegister()) {
856 __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>());
857 } else if (source.IsFpuRegister()) {
858 __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>());
859 } else {
860 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
861 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
862 }
863 } else if (destination.IsFpuRegister()) {
864 if (source.IsRegister()) {
865 __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>());
866 } else if (source.IsFpuRegister()) {
867 __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
868 } else {
869 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
870 __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
871 }
872 } else {
873 DCHECK(destination.IsStackSlot()) << destination;
874 if (source.IsRegister()) {
875 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
876 } else if (source.IsFpuRegister()) {
877 __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex());
878 } else {
879 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
880 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
881 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
882 }
883 }
884}
885
886void CodeGeneratorMIPS::Move64(Location destination, Location source) {
887 if (source.Equals(destination)) {
888 return;
889 }
890
891 if (destination.IsRegisterPair()) {
892 if (source.IsRegisterPair()) {
893 __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
894 __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
895 } else if (source.IsFpuRegister()) {
896 Register dst_high = destination.AsRegisterPairHigh<Register>();
897 Register dst_low = destination.AsRegisterPairLow<Register>();
898 FRegister src = source.AsFpuRegister<FRegister>();
899 __ Mfc1(dst_low, src);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800900 __ MoveFromFpuHigh(dst_high, src);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200901 } else {
902 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
903 int32_t off = source.GetStackIndex();
904 Register r = destination.AsRegisterPairLow<Register>();
905 __ LoadFromOffset(kLoadDoubleword, r, SP, off);
906 }
907 } else if (destination.IsFpuRegister()) {
908 if (source.IsRegisterPair()) {
909 FRegister dst = destination.AsFpuRegister<FRegister>();
910 Register src_high = source.AsRegisterPairHigh<Register>();
911 Register src_low = source.AsRegisterPairLow<Register>();
912 __ Mtc1(src_low, dst);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800913 __ MoveToFpuHigh(src_high, dst);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200914 } else if (source.IsFpuRegister()) {
915 __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
916 } else {
917 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
918 __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
919 }
920 } else {
921 DCHECK(destination.IsDoubleStackSlot()) << destination;
922 int32_t off = destination.GetStackIndex();
923 if (source.IsRegisterPair()) {
924 __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off);
925 } else if (source.IsFpuRegister()) {
926 __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off);
927 } else {
928 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
929 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
930 __ StoreToOffset(kStoreWord, TMP, SP, off);
931 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4);
932 __ StoreToOffset(kStoreWord, TMP, SP, off + 4);
933 }
934 }
935}
936
937void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) {
938 if (c->IsIntConstant() || c->IsNullConstant()) {
939 // Move 32 bit constant.
940 int32_t value = GetInt32ValueOf(c);
941 if (destination.IsRegister()) {
942 Register dst = destination.AsRegister<Register>();
943 __ LoadConst32(dst, value);
944 } else {
945 DCHECK(destination.IsStackSlot())
946 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -0700947 __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200948 }
949 } else if (c->IsLongConstant()) {
950 // Move 64 bit constant.
951 int64_t value = GetInt64ValueOf(c);
952 if (destination.IsRegisterPair()) {
953 Register r_h = destination.AsRegisterPairHigh<Register>();
954 Register r_l = destination.AsRegisterPairLow<Register>();
955 __ LoadConst64(r_h, r_l, value);
956 } else {
957 DCHECK(destination.IsDoubleStackSlot())
958 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -0700959 __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200960 }
961 } else if (c->IsFloatConstant()) {
962 // Move 32 bit float constant.
963 int32_t value = GetInt32ValueOf(c);
964 if (destination.IsFpuRegister()) {
965 __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP);
966 } else {
967 DCHECK(destination.IsStackSlot())
968 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -0700969 __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200970 }
971 } else {
972 // Move 64 bit double constant.
973 DCHECK(c->IsDoubleConstant()) << c->DebugName();
974 int64_t value = GetInt64ValueOf(c);
975 if (destination.IsFpuRegister()) {
976 FRegister fd = destination.AsFpuRegister<FRegister>();
977 __ LoadDConst64(fd, value, TMP);
978 } else {
979 DCHECK(destination.IsDoubleStackSlot())
980 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -0700981 __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200982 }
983 }
984}
985
986void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) {
987 DCHECK(destination.IsRegister());
988 Register dst = destination.AsRegister<Register>();
989 __ LoadConst32(dst, value);
990}
991
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200992void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) {
993 if (location.IsRegister()) {
994 locations->AddTemp(location);
Alexey Frunzec9e94f32015-10-26 16:11:39 -0700995 } else if (location.IsRegisterPair()) {
996 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
997 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200998 } else {
999 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
1000 }
1001}
1002
Vladimir Markoaad75c62016-10-03 08:46:48 +00001003template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
1004inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches(
1005 const ArenaDeque<PcRelativePatchInfo>& infos,
1006 ArenaVector<LinkerPatch>* linker_patches) {
1007 for (const PcRelativePatchInfo& info : infos) {
1008 const DexFile& dex_file = info.target_dex_file;
1009 size_t offset_or_index = info.offset_or_index;
1010 DCHECK(info.high_label.IsBound());
1011 uint32_t high_offset = __ GetLabelLocation(&info.high_label);
1012 // On R2 we use HMipsComputeBaseMethodAddress and patch relative to
1013 // the assembler's base label used for PC-relative addressing.
1014 uint32_t pc_rel_offset = info.pc_rel_label.IsBound()
1015 ? __ GetLabelLocation(&info.pc_rel_label)
1016 : __ GetPcRelBaseLabelLocation();
1017 linker_patches->push_back(Factory(high_offset, &dex_file, pc_rel_offset, offset_or_index));
1018 }
1019}
1020
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001021void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
1022 DCHECK(linker_patches->empty());
1023 size_t size =
Alexey Frunze06a46c42016-07-19 15:00:40 -07001024 pc_relative_dex_cache_patches_.size() +
1025 pc_relative_string_patches_.size() +
1026 pc_relative_type_patches_.size() +
Vladimir Marko1998cd02017-01-13 13:02:58 +00001027 type_bss_entry_patches_.size() +
Alexey Frunze06a46c42016-07-19 15:00:40 -07001028 boot_image_string_patches_.size() +
1029 boot_image_type_patches_.size() +
1030 boot_image_address_patches_.size();
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001031 linker_patches->reserve(size);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001032 EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_,
1033 linker_patches);
1034 if (!GetCompilerOptions().IsBootImage()) {
Vladimir Marko1998cd02017-01-13 13:02:58 +00001035 DCHECK(pc_relative_type_patches_.empty());
Vladimir Markoaad75c62016-10-03 08:46:48 +00001036 EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_,
1037 linker_patches);
1038 } else {
Vladimir Marko6bec91c2017-01-09 15:03:12 +00001039 EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_,
1040 linker_patches);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001041 EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_,
1042 linker_patches);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001043 }
Vladimir Marko1998cd02017-01-13 13:02:58 +00001044 EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_,
1045 linker_patches);
Alexey Frunze06a46c42016-07-19 15:00:40 -07001046 for (const auto& entry : boot_image_string_patches_) {
1047 const StringReference& target_string = entry.first;
1048 Literal* literal = entry.second;
1049 DCHECK(literal->GetLabel()->IsBound());
1050 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1051 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
1052 target_string.dex_file,
Andreas Gampe8a0128a2016-11-28 07:38:35 -08001053 target_string.string_index.index_));
Alexey Frunze06a46c42016-07-19 15:00:40 -07001054 }
1055 for (const auto& entry : boot_image_type_patches_) {
1056 const TypeReference& target_type = entry.first;
1057 Literal* literal = entry.second;
1058 DCHECK(literal->GetLabel()->IsBound());
1059 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1060 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
1061 target_type.dex_file,
Andreas Gampea5b09a62016-11-17 15:21:22 -08001062 target_type.type_index.index_));
Alexey Frunze06a46c42016-07-19 15:00:40 -07001063 }
1064 for (const auto& entry : boot_image_address_patches_) {
1065 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
1066 Literal* literal = entry.second;
1067 DCHECK(literal->GetLabel()->IsBound());
1068 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1069 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
1070 }
Vladimir Marko1998cd02017-01-13 13:02:58 +00001071 DCHECK_EQ(size, linker_patches->size());
Alexey Frunze06a46c42016-07-19 15:00:40 -07001072}
1073
1074CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch(
Vladimir Marko6bec91c2017-01-09 15:03:12 +00001075 const DexFile& dex_file, dex::StringIndex string_index) {
1076 return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_);
Alexey Frunze06a46c42016-07-19 15:00:40 -07001077}
1078
1079CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch(
Andreas Gampea5b09a62016-11-17 15:21:22 -08001080 const DexFile& dex_file, dex::TypeIndex type_index) {
1081 return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001082}
1083
Vladimir Marko1998cd02017-01-13 13:02:58 +00001084CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewTypeBssEntryPatch(
1085 const DexFile& dex_file, dex::TypeIndex type_index) {
1086 return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_);
1087}
1088
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001089CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeDexCacheArrayPatch(
1090 const DexFile& dex_file, uint32_t element_offset) {
1091 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
1092}
1093
1094CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch(
1095 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
1096 patches->emplace_back(dex_file, offset_or_index);
1097 return &patches->back();
1098}
1099
Alexey Frunze06a46c42016-07-19 15:00:40 -07001100Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
1101 return map->GetOrCreate(
1102 value,
1103 [this, value]() { return __ NewLiteral<uint32_t>(value); });
1104}
1105
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001106Literal* CodeGeneratorMIPS::DeduplicateMethodLiteral(MethodReference target_method,
1107 MethodToLiteralMap* map) {
1108 return map->GetOrCreate(
1109 target_method,
1110 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1111}
1112
Alexey Frunze06a46c42016-07-19 15:00:40 -07001113Literal* CodeGeneratorMIPS::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
Andreas Gampe8a0128a2016-11-28 07:38:35 -08001114 dex::StringIndex string_index) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07001115 return boot_image_string_patches_.GetOrCreate(
1116 StringReference(&dex_file, string_index),
1117 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1118}
1119
1120Literal* CodeGeneratorMIPS::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
Andreas Gampea5b09a62016-11-17 15:21:22 -08001121 dex::TypeIndex type_index) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07001122 return boot_image_type_patches_.GetOrCreate(
1123 TypeReference(&dex_file, type_index),
1124 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1125}
1126
1127Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) {
1128 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
1129 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
1130 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
1131}
1132
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001133void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info,
1134 Register out,
1135 Register base) {
Vladimir Markoaad75c62016-10-03 08:46:48 +00001136 if (GetInstructionSetFeatures().IsR6()) {
1137 DCHECK_EQ(base, ZERO);
1138 __ Bind(&info->high_label);
1139 __ Bind(&info->pc_rel_label);
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001140 // Add the high half of a 32-bit offset to PC.
Vladimir Markoaad75c62016-10-03 08:46:48 +00001141 __ Auipc(out, /* placeholder */ 0x1234);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001142 } else {
1143 // If base is ZERO, emit NAL to obtain the actual base.
1144 if (base == ZERO) {
1145 // Generate a dummy PC-relative call to obtain PC.
1146 __ Nal();
1147 }
1148 __ Bind(&info->high_label);
1149 __ Lui(out, /* placeholder */ 0x1234);
1150 // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding
1151 // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler.
1152 if (base == ZERO) {
1153 __ Bind(&info->pc_rel_label);
1154 }
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001155 // Add the high half of a 32-bit offset to PC.
Vladimir Markoaad75c62016-10-03 08:46:48 +00001156 __ Addu(out, out, (base == ZERO) ? RA : base);
1157 }
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001158 // The immediately following instruction will add the sign-extended low half of the 32-bit
1159 // offset to `out` (e.g. lw, jialc, addiu).
Vladimir Markoaad75c62016-10-03 08:46:48 +00001160}
1161
Alexey Frunze627c1a02017-01-30 19:28:14 -08001162CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootStringPatch(
1163 const DexFile& dex_file,
1164 dex::StringIndex dex_index,
1165 Handle<mirror::String> handle) {
1166 jit_string_roots_.Overwrite(StringReference(&dex_file, dex_index),
1167 reinterpret_cast64<uint64_t>(handle.GetReference()));
1168 jit_string_patches_.emplace_back(dex_file, dex_index.index_);
1169 return &jit_string_patches_.back();
1170}
1171
1172CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootClassPatch(
1173 const DexFile& dex_file,
1174 dex::TypeIndex dex_index,
1175 Handle<mirror::Class> handle) {
1176 jit_class_roots_.Overwrite(TypeReference(&dex_file, dex_index),
1177 reinterpret_cast64<uint64_t>(handle.GetReference()));
1178 jit_class_patches_.emplace_back(dex_file, dex_index.index_);
1179 return &jit_class_patches_.back();
1180}
1181
1182void CodeGeneratorMIPS::PatchJitRootUse(uint8_t* code,
1183 const uint8_t* roots_data,
1184 const CodeGeneratorMIPS::JitPatchInfo& info,
1185 uint64_t index_in_table) const {
1186 uint32_t literal_offset = GetAssembler().GetLabelLocation(&info.high_label);
1187 uintptr_t address =
1188 reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>);
1189 uint32_t addr32 = dchecked_integral_cast<uint32_t>(address);
1190 // lui reg, addr32_high
1191 DCHECK_EQ(code[literal_offset + 0], 0x34);
1192 DCHECK_EQ(code[literal_offset + 1], 0x12);
1193 DCHECK_EQ((code[literal_offset + 2] & 0xE0), 0x00);
1194 DCHECK_EQ(code[literal_offset + 3], 0x3C);
1195 // lw reg, reg, addr32_low
1196 DCHECK_EQ(code[literal_offset + 4], 0x78);
1197 DCHECK_EQ(code[literal_offset + 5], 0x56);
1198 DCHECK_EQ((code[literal_offset + 7] & 0xFC), 0x8C);
1199 addr32 += (addr32 & 0x8000) << 1; // Account for sign extension in "lw reg, reg, addr32_low".
1200 // lui reg, addr32_high
1201 code[literal_offset + 0] = static_cast<uint8_t>(addr32 >> 16);
1202 code[literal_offset + 1] = static_cast<uint8_t>(addr32 >> 24);
1203 // lw reg, reg, addr32_low
1204 code[literal_offset + 4] = static_cast<uint8_t>(addr32 >> 0);
1205 code[literal_offset + 5] = static_cast<uint8_t>(addr32 >> 8);
1206}
1207
1208void CodeGeneratorMIPS::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) {
1209 for (const JitPatchInfo& info : jit_string_patches_) {
1210 const auto& it = jit_string_roots_.find(StringReference(&info.target_dex_file,
1211 dex::StringIndex(info.index)));
1212 DCHECK(it != jit_string_roots_.end());
1213 PatchJitRootUse(code, roots_data, info, it->second);
1214 }
1215 for (const JitPatchInfo& info : jit_class_patches_) {
1216 const auto& it = jit_class_roots_.find(TypeReference(&info.target_dex_file,
1217 dex::TypeIndex(info.index)));
1218 DCHECK(it != jit_class_roots_.end());
1219 PatchJitRootUse(code, roots_data, info, it->second);
1220 }
1221}
1222
Goran Jakovljevice114da22016-12-26 14:21:43 +01001223void CodeGeneratorMIPS::MarkGCCard(Register object,
1224 Register value,
1225 bool value_can_be_null) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001226 MipsLabel done;
1227 Register card = AT;
1228 Register temp = TMP;
Goran Jakovljevice114da22016-12-26 14:21:43 +01001229 if (value_can_be_null) {
1230 __ Beqz(value, &done);
1231 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001232 __ LoadFromOffset(kLoadWord,
1233 card,
1234 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001235 Thread::CardTableOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001236 __ Srl(temp, object, gc::accounting::CardTable::kCardShift);
1237 __ Addu(temp, card, temp);
1238 __ Sb(card, temp, 0);
Goran Jakovljevice114da22016-12-26 14:21:43 +01001239 if (value_can_be_null) {
1240 __ Bind(&done);
1241 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001242}
1243
David Brazdil58282f42016-01-14 12:45:10 +00001244void CodeGeneratorMIPS::SetupBlockedRegisters() const {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001245 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
1246 blocked_core_registers_[ZERO] = true;
1247 blocked_core_registers_[K0] = true;
1248 blocked_core_registers_[K1] = true;
1249 blocked_core_registers_[GP] = true;
1250 blocked_core_registers_[SP] = true;
1251 blocked_core_registers_[RA] = true;
1252
1253 // AT and TMP(T8) are used as temporary/scratch registers
1254 // (similar to how AT is used by MIPS assemblers).
1255 blocked_core_registers_[AT] = true;
1256 blocked_core_registers_[TMP] = true;
1257 blocked_fpu_registers_[FTMP] = true;
1258
1259 // Reserve suspend and thread registers.
1260 blocked_core_registers_[S0] = true;
1261 blocked_core_registers_[TR] = true;
1262
1263 // Reserve T9 for function calls
1264 blocked_core_registers_[T9] = true;
1265
1266 // Reserve odd-numbered FPU registers.
1267 for (size_t i = 1; i < kNumberOfFRegisters; i += 2) {
1268 blocked_fpu_registers_[i] = true;
1269 }
1270
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02001271 if (GetGraph()->IsDebuggable()) {
1272 // Stubs do not save callee-save floating point registers. If the graph
1273 // is debuggable, we need to deal with these registers differently. For
1274 // now, just block them.
1275 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1276 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1277 }
1278 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001279}
1280
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001281size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1282 __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index);
1283 return kMipsWordSize;
1284}
1285
1286size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1287 __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index);
1288 return kMipsWordSize;
1289}
1290
1291size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1292 __ StoreDToOffset(FRegister(reg_id), SP, stack_index);
1293 return kMipsDoublewordSize;
1294}
1295
1296size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1297 __ LoadDFromOffset(FRegister(reg_id), SP, stack_index);
1298 return kMipsDoublewordSize;
1299}
1300
1301void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001302 stream << Register(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001303}
1304
1305void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001306 stream << FRegister(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001307}
1308
Serban Constantinescufca16662016-07-14 09:21:59 +01001309constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16;
1310
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001311void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint,
1312 HInstruction* instruction,
1313 uint32_t dex_pc,
1314 SlowPathCode* slow_path) {
Alexandre Rames91a65162016-09-19 13:54:30 +01001315 ValidateInvokeRuntime(entrypoint, instruction, slow_path);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001316 bool reordering = __ SetReorder(false);
Serban Constantinescufca16662016-07-14 09:21:59 +01001317 __ LoadFromOffset(kLoadWord, T9, TR, GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value());
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001318 __ Jalr(T9);
Serban Constantinescufca16662016-07-14 09:21:59 +01001319 if (IsDirectEntrypoint(entrypoint)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001320 // Reserve argument space on stack (for $a0-$a3) for
1321 // entrypoints that directly reference native implementations.
1322 // Called function may use this space to store $a0-$a3 regs.
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001323 __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001324 __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001325 } else {
1326 __ Nop(); // In delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001327 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001328 __ SetReorder(reordering);
Serban Constantinescufca16662016-07-14 09:21:59 +01001329 if (EntrypointRequiresStackMap(entrypoint)) {
1330 RecordPcInfo(instruction, dex_pc, slow_path);
1331 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001332}
1333
1334void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path,
1335 Register class_reg) {
1336 __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
1337 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
1338 __ Blt(TMP, AT, slow_path->GetEntryLabel());
1339 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
1340 __ Sync(0);
1341 __ Bind(slow_path->GetExitLabel());
1342}
1343
1344void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1345 __ Sync(0); // Only stype 0 is supported.
1346}
1347
1348void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction,
1349 HBasicBlock* successor) {
1350 SuspendCheckSlowPathMIPS* slow_path =
1351 new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor);
1352 codegen_->AddSlowPath(slow_path);
1353
1354 __ LoadFromOffset(kLoadUnsignedHalfword,
1355 TMP,
1356 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001357 Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001358 if (successor == nullptr) {
1359 __ Bnez(TMP, slow_path->GetEntryLabel());
1360 __ Bind(slow_path->GetReturnLabel());
1361 } else {
1362 __ Beqz(TMP, codegen_->GetLabelOf(successor));
1363 __ B(slow_path->GetEntryLabel());
1364 // slow_path will return to GetLabelOf(successor).
1365 }
1366}
1367
1368InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph,
1369 CodeGeneratorMIPS* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001370 : InstructionCodeGenerator(graph, codegen),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001371 assembler_(codegen->GetAssembler()),
1372 codegen_(codegen) {}
1373
1374void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1375 DCHECK_EQ(instruction->InputCount(), 2U);
1376 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1377 Primitive::Type type = instruction->GetResultType();
1378 switch (type) {
1379 case Primitive::kPrimInt: {
1380 locations->SetInAt(0, Location::RequiresRegister());
1381 HInstruction* right = instruction->InputAt(1);
1382 bool can_use_imm = false;
1383 if (right->IsConstant()) {
1384 int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant());
1385 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1386 can_use_imm = IsUint<16>(imm);
1387 } else if (instruction->IsAdd()) {
1388 can_use_imm = IsInt<16>(imm);
1389 } else {
1390 DCHECK(instruction->IsSub());
1391 can_use_imm = IsInt<16>(-imm);
1392 }
1393 }
1394 if (can_use_imm)
1395 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1396 else
1397 locations->SetInAt(1, Location::RequiresRegister());
1398 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1399 break;
1400 }
1401
1402 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001403 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001404 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1405 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001406 break;
1407 }
1408
1409 case Primitive::kPrimFloat:
1410 case Primitive::kPrimDouble:
1411 DCHECK(instruction->IsAdd() || instruction->IsSub());
1412 locations->SetInAt(0, Location::RequiresFpuRegister());
1413 locations->SetInAt(1, Location::RequiresFpuRegister());
1414 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1415 break;
1416
1417 default:
1418 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1419 }
1420}
1421
1422void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1423 Primitive::Type type = instruction->GetType();
1424 LocationSummary* locations = instruction->GetLocations();
1425
1426 switch (type) {
1427 case Primitive::kPrimInt: {
1428 Register dst = locations->Out().AsRegister<Register>();
1429 Register lhs = locations->InAt(0).AsRegister<Register>();
1430 Location rhs_location = locations->InAt(1);
1431
1432 Register rhs_reg = ZERO;
1433 int32_t rhs_imm = 0;
1434 bool use_imm = rhs_location.IsConstant();
1435 if (use_imm) {
1436 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
1437 } else {
1438 rhs_reg = rhs_location.AsRegister<Register>();
1439 }
1440
1441 if (instruction->IsAnd()) {
1442 if (use_imm)
1443 __ Andi(dst, lhs, rhs_imm);
1444 else
1445 __ And(dst, lhs, rhs_reg);
1446 } else if (instruction->IsOr()) {
1447 if (use_imm)
1448 __ Ori(dst, lhs, rhs_imm);
1449 else
1450 __ Or(dst, lhs, rhs_reg);
1451 } else if (instruction->IsXor()) {
1452 if (use_imm)
1453 __ Xori(dst, lhs, rhs_imm);
1454 else
1455 __ Xor(dst, lhs, rhs_reg);
1456 } else if (instruction->IsAdd()) {
1457 if (use_imm)
1458 __ Addiu(dst, lhs, rhs_imm);
1459 else
1460 __ Addu(dst, lhs, rhs_reg);
1461 } else {
1462 DCHECK(instruction->IsSub());
1463 if (use_imm)
1464 __ Addiu(dst, lhs, -rhs_imm);
1465 else
1466 __ Subu(dst, lhs, rhs_reg);
1467 }
1468 break;
1469 }
1470
1471 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001472 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1473 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1474 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1475 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001476 Location rhs_location = locations->InAt(1);
1477 bool use_imm = rhs_location.IsConstant();
1478 if (!use_imm) {
1479 Register rhs_high = rhs_location.AsRegisterPairHigh<Register>();
1480 Register rhs_low = rhs_location.AsRegisterPairLow<Register>();
1481 if (instruction->IsAnd()) {
1482 __ And(dst_low, lhs_low, rhs_low);
1483 __ And(dst_high, lhs_high, rhs_high);
1484 } else if (instruction->IsOr()) {
1485 __ Or(dst_low, lhs_low, rhs_low);
1486 __ Or(dst_high, lhs_high, rhs_high);
1487 } else if (instruction->IsXor()) {
1488 __ Xor(dst_low, lhs_low, rhs_low);
1489 __ Xor(dst_high, lhs_high, rhs_high);
1490 } else if (instruction->IsAdd()) {
1491 if (lhs_low == rhs_low) {
1492 // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs.
1493 __ Slt(TMP, lhs_low, ZERO);
1494 __ Addu(dst_low, lhs_low, rhs_low);
1495 } else {
1496 __ Addu(dst_low, lhs_low, rhs_low);
1497 // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged.
1498 __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low);
1499 }
1500 __ Addu(dst_high, lhs_high, rhs_high);
1501 __ Addu(dst_high, dst_high, TMP);
1502 } else {
1503 DCHECK(instruction->IsSub());
1504 __ Sltu(TMP, lhs_low, rhs_low);
1505 __ Subu(dst_low, lhs_low, rhs_low);
1506 __ Subu(dst_high, lhs_high, rhs_high);
1507 __ Subu(dst_high, dst_high, TMP);
1508 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001509 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001510 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
1511 if (instruction->IsOr()) {
1512 uint32_t low = Low32Bits(value);
1513 uint32_t high = High32Bits(value);
1514 if (IsUint<16>(low)) {
1515 if (dst_low != lhs_low || low != 0) {
1516 __ Ori(dst_low, lhs_low, low);
1517 }
1518 } else {
1519 __ LoadConst32(TMP, low);
1520 __ Or(dst_low, lhs_low, TMP);
1521 }
1522 if (IsUint<16>(high)) {
1523 if (dst_high != lhs_high || high != 0) {
1524 __ Ori(dst_high, lhs_high, high);
1525 }
1526 } else {
1527 if (high != low) {
1528 __ LoadConst32(TMP, high);
1529 }
1530 __ Or(dst_high, lhs_high, TMP);
1531 }
1532 } else if (instruction->IsXor()) {
1533 uint32_t low = Low32Bits(value);
1534 uint32_t high = High32Bits(value);
1535 if (IsUint<16>(low)) {
1536 if (dst_low != lhs_low || low != 0) {
1537 __ Xori(dst_low, lhs_low, low);
1538 }
1539 } else {
1540 __ LoadConst32(TMP, low);
1541 __ Xor(dst_low, lhs_low, TMP);
1542 }
1543 if (IsUint<16>(high)) {
1544 if (dst_high != lhs_high || high != 0) {
1545 __ Xori(dst_high, lhs_high, high);
1546 }
1547 } else {
1548 if (high != low) {
1549 __ LoadConst32(TMP, high);
1550 }
1551 __ Xor(dst_high, lhs_high, TMP);
1552 }
1553 } else if (instruction->IsAnd()) {
1554 uint32_t low = Low32Bits(value);
1555 uint32_t high = High32Bits(value);
1556 if (IsUint<16>(low)) {
1557 __ Andi(dst_low, lhs_low, low);
1558 } else if (low != 0xFFFFFFFF) {
1559 __ LoadConst32(TMP, low);
1560 __ And(dst_low, lhs_low, TMP);
1561 } else if (dst_low != lhs_low) {
1562 __ Move(dst_low, lhs_low);
1563 }
1564 if (IsUint<16>(high)) {
1565 __ Andi(dst_high, lhs_high, high);
1566 } else if (high != 0xFFFFFFFF) {
1567 if (high != low) {
1568 __ LoadConst32(TMP, high);
1569 }
1570 __ And(dst_high, lhs_high, TMP);
1571 } else if (dst_high != lhs_high) {
1572 __ Move(dst_high, lhs_high);
1573 }
1574 } else {
1575 if (instruction->IsSub()) {
1576 value = -value;
1577 } else {
1578 DCHECK(instruction->IsAdd());
1579 }
1580 int32_t low = Low32Bits(value);
1581 int32_t high = High32Bits(value);
1582 if (IsInt<16>(low)) {
1583 if (dst_low != lhs_low || low != 0) {
1584 __ Addiu(dst_low, lhs_low, low);
1585 }
1586 if (low != 0) {
1587 __ Sltiu(AT, dst_low, low);
1588 }
1589 } else {
1590 __ LoadConst32(TMP, low);
1591 __ Addu(dst_low, lhs_low, TMP);
1592 __ Sltu(AT, dst_low, TMP);
1593 }
1594 if (IsInt<16>(high)) {
1595 if (dst_high != lhs_high || high != 0) {
1596 __ Addiu(dst_high, lhs_high, high);
1597 }
1598 } else {
1599 if (high != low) {
1600 __ LoadConst32(TMP, high);
1601 }
1602 __ Addu(dst_high, lhs_high, TMP);
1603 }
1604 if (low != 0) {
1605 __ Addu(dst_high, dst_high, AT);
1606 }
1607 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001608 }
1609 break;
1610 }
1611
1612 case Primitive::kPrimFloat:
1613 case Primitive::kPrimDouble: {
1614 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
1615 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
1616 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
1617 if (instruction->IsAdd()) {
1618 if (type == Primitive::kPrimFloat) {
1619 __ AddS(dst, lhs, rhs);
1620 } else {
1621 __ AddD(dst, lhs, rhs);
1622 }
1623 } else {
1624 DCHECK(instruction->IsSub());
1625 if (type == Primitive::kPrimFloat) {
1626 __ SubS(dst, lhs, rhs);
1627 } else {
1628 __ SubD(dst, lhs, rhs);
1629 }
1630 }
1631 break;
1632 }
1633
1634 default:
1635 LOG(FATAL) << "Unexpected binary operation type " << type;
1636 }
1637}
1638
1639void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001640 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001641
1642 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1643 Primitive::Type type = instr->GetResultType();
1644 switch (type) {
1645 case Primitive::kPrimInt:
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001646 locations->SetInAt(0, Location::RequiresRegister());
1647 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1648 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1649 break;
1650 case Primitive::kPrimLong:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001651 locations->SetInAt(0, Location::RequiresRegister());
1652 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1653 locations->SetOut(Location::RequiresRegister());
1654 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001655 default:
1656 LOG(FATAL) << "Unexpected shift type " << type;
1657 }
1658}
1659
1660static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte;
1661
1662void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001663 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001664 LocationSummary* locations = instr->GetLocations();
1665 Primitive::Type type = instr->GetType();
1666
1667 Location rhs_location = locations->InAt(1);
1668 bool use_imm = rhs_location.IsConstant();
1669 Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>();
1670 int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0;
Roland Levillain5b5b9312016-03-22 14:57:31 +00001671 const uint32_t shift_mask =
1672 (type == Primitive::kPrimInt) ? kMaxIntShiftDistance : kMaxLongShiftDistance;
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001673 const uint32_t shift_value = rhs_imm & shift_mask;
Alexey Frunze92d90602015-12-18 18:16:36 -08001674 // Are the INS (Insert Bit Field) and ROTR instructions supported?
1675 bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001676
1677 switch (type) {
1678 case Primitive::kPrimInt: {
1679 Register dst = locations->Out().AsRegister<Register>();
1680 Register lhs = locations->InAt(0).AsRegister<Register>();
1681 if (use_imm) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001682 if (shift_value == 0) {
1683 if (dst != lhs) {
1684 __ Move(dst, lhs);
1685 }
1686 } else if (instr->IsShl()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001687 __ Sll(dst, lhs, shift_value);
1688 } else if (instr->IsShr()) {
1689 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001690 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001691 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001692 } else {
1693 if (has_ins_rotr) {
1694 __ Rotr(dst, lhs, shift_value);
1695 } else {
1696 __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask);
1697 __ Srl(dst, lhs, shift_value);
1698 __ Or(dst, dst, TMP);
1699 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001700 }
1701 } else {
1702 if (instr->IsShl()) {
1703 __ Sllv(dst, lhs, rhs_reg);
1704 } else if (instr->IsShr()) {
1705 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001706 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001707 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001708 } else {
1709 if (has_ins_rotr) {
1710 __ Rotrv(dst, lhs, rhs_reg);
1711 } else {
1712 __ Subu(TMP, ZERO, rhs_reg);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001713 // 32-bit shift instructions use the 5 least significant bits of the shift count, so
1714 // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case
1715 // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out
1716 // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`,
1717 // IOW, the OR'd values are equal.
Alexey Frunze92d90602015-12-18 18:16:36 -08001718 __ Sllv(TMP, lhs, TMP);
1719 __ Srlv(dst, lhs, rhs_reg);
1720 __ Or(dst, dst, TMP);
1721 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001722 }
1723 }
1724 break;
1725 }
1726
1727 case Primitive::kPrimLong: {
1728 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1729 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1730 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1731 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
1732 if (use_imm) {
1733 if (shift_value == 0) {
1734 codegen_->Move64(locations->Out(), locations->InAt(0));
1735 } else if (shift_value < kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001736 if (has_ins_rotr) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001737 if (instr->IsShl()) {
1738 __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1739 __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value);
1740 __ Sll(dst_low, lhs_low, shift_value);
1741 } else if (instr->IsShr()) {
1742 __ Srl(dst_low, lhs_low, shift_value);
1743 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1744 __ Sra(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001745 } else if (instr->IsUShr()) {
1746 __ Srl(dst_low, lhs_low, shift_value);
1747 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1748 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001749 } else {
1750 __ Srl(dst_low, lhs_low, shift_value);
1751 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1752 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001753 __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001754 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001755 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001756 if (instr->IsShl()) {
1757 __ Sll(dst_low, lhs_low, shift_value);
1758 __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value);
1759 __ Sll(dst_high, lhs_high, shift_value);
1760 __ Or(dst_high, dst_high, TMP);
1761 } else if (instr->IsShr()) {
1762 __ Sra(dst_high, lhs_high, shift_value);
1763 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1764 __ Srl(dst_low, lhs_low, shift_value);
1765 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001766 } else if (instr->IsUShr()) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001767 __ Srl(dst_high, lhs_high, shift_value);
1768 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1769 __ Srl(dst_low, lhs_low, shift_value);
1770 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001771 } else {
1772 __ Srl(TMP, lhs_low, shift_value);
1773 __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value);
1774 __ Or(dst_low, dst_low, TMP);
1775 __ Srl(TMP, lhs_high, shift_value);
1776 __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1777 __ Or(dst_high, dst_high, TMP);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001778 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001779 }
1780 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001781 const uint32_t shift_value_high = shift_value - kMipsBitsPerWord;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001782 if (instr->IsShl()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001783 __ Sll(dst_high, lhs_low, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001784 __ Move(dst_low, ZERO);
1785 } else if (instr->IsShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001786 __ Sra(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001787 __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1);
Alexey Frunze92d90602015-12-18 18:16:36 -08001788 } else if (instr->IsUShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001789 __ Srl(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001790 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001791 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001792 if (shift_value == kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001793 // 64-bit rotation by 32 is just a swap.
1794 __ Move(dst_low, lhs_high);
1795 __ Move(dst_high, lhs_low);
1796 } else {
1797 if (has_ins_rotr) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001798 __ Srl(dst_low, lhs_high, shift_value_high);
1799 __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high);
1800 __ Srl(dst_high, lhs_low, shift_value_high);
1801 __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001802 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001803 __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high);
1804 __ Srl(dst_low, lhs_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001805 __ Or(dst_low, dst_low, TMP);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001806 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high);
1807 __ Srl(dst_high, lhs_low, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001808 __ Or(dst_high, dst_high, TMP);
1809 }
1810 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001811 }
1812 }
1813 } else {
1814 MipsLabel done;
1815 if (instr->IsShl()) {
1816 __ Sllv(dst_low, lhs_low, rhs_reg);
1817 __ Nor(AT, ZERO, rhs_reg);
1818 __ Srl(TMP, lhs_low, 1);
1819 __ Srlv(TMP, TMP, AT);
1820 __ Sllv(dst_high, lhs_high, rhs_reg);
1821 __ Or(dst_high, dst_high, TMP);
1822 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1823 __ Beqz(TMP, &done);
1824 __ Move(dst_high, dst_low);
1825 __ Move(dst_low, ZERO);
1826 } else if (instr->IsShr()) {
1827 __ Srav(dst_high, lhs_high, rhs_reg);
1828 __ Nor(AT, ZERO, rhs_reg);
1829 __ Sll(TMP, lhs_high, 1);
1830 __ Sllv(TMP, TMP, AT);
1831 __ Srlv(dst_low, lhs_low, rhs_reg);
1832 __ Or(dst_low, dst_low, TMP);
1833 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1834 __ Beqz(TMP, &done);
1835 __ Move(dst_low, dst_high);
1836 __ Sra(dst_high, dst_high, 31);
Alexey Frunze92d90602015-12-18 18:16:36 -08001837 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001838 __ Srlv(dst_high, lhs_high, rhs_reg);
1839 __ Nor(AT, ZERO, rhs_reg);
1840 __ Sll(TMP, lhs_high, 1);
1841 __ Sllv(TMP, TMP, AT);
1842 __ Srlv(dst_low, lhs_low, rhs_reg);
1843 __ Or(dst_low, dst_low, TMP);
1844 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1845 __ Beqz(TMP, &done);
1846 __ Move(dst_low, dst_high);
1847 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001848 } else {
1849 __ Nor(AT, ZERO, rhs_reg);
1850 __ Srlv(TMP, lhs_low, rhs_reg);
1851 __ Sll(dst_low, lhs_high, 1);
1852 __ Sllv(dst_low, dst_low, AT);
1853 __ Or(dst_low, dst_low, TMP);
1854 __ Srlv(TMP, lhs_high, rhs_reg);
1855 __ Sll(dst_high, lhs_low, 1);
1856 __ Sllv(dst_high, dst_high, AT);
1857 __ Or(dst_high, dst_high, TMP);
1858 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1859 __ Beqz(TMP, &done);
1860 __ Move(TMP, dst_high);
1861 __ Move(dst_high, dst_low);
1862 __ Move(dst_low, TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001863 }
1864 __ Bind(&done);
1865 }
1866 break;
1867 }
1868
1869 default:
1870 LOG(FATAL) << "Unexpected shift operation type " << type;
1871 }
1872}
1873
1874void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) {
1875 HandleBinaryOp(instruction);
1876}
1877
1878void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) {
1879 HandleBinaryOp(instruction);
1880}
1881
1882void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) {
1883 HandleBinaryOp(instruction);
1884}
1885
1886void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) {
1887 HandleBinaryOp(instruction);
1888}
1889
1890void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) {
1891 LocationSummary* locations =
1892 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1893 locations->SetInAt(0, Location::RequiresRegister());
1894 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1895 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1896 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1897 } else {
1898 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1899 }
1900}
1901
Alexey Frunze2923db72016-08-20 01:55:47 -07001902auto InstructionCodeGeneratorMIPS::GetImplicitNullChecker(HInstruction* instruction) {
1903 auto null_checker = [this, instruction]() {
1904 this->codegen_->MaybeRecordImplicitNullCheck(instruction);
1905 };
1906 return null_checker;
1907}
1908
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001909void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) {
1910 LocationSummary* locations = instruction->GetLocations();
1911 Register obj = locations->InAt(0).AsRegister<Register>();
1912 Location index = locations->InAt(1);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001913 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Alexey Frunze2923db72016-08-20 01:55:47 -07001914 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001915
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001916 Primitive::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001917 switch (type) {
1918 case Primitive::kPrimBoolean: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001919 Register out = locations->Out().AsRegister<Register>();
1920 if (index.IsConstant()) {
1921 size_t offset =
1922 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001923 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001924 } else {
1925 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07001926 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001927 }
1928 break;
1929 }
1930
1931 case Primitive::kPrimByte: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001932 Register out = locations->Out().AsRegister<Register>();
1933 if (index.IsConstant()) {
1934 size_t offset =
1935 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001936 __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001937 } else {
1938 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07001939 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001940 }
1941 break;
1942 }
1943
1944 case Primitive::kPrimShort: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001945 Register out = locations->Out().AsRegister<Register>();
1946 if (index.IsConstant()) {
1947 size_t offset =
1948 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001949 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001950 } else {
1951 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1952 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001953 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001954 }
1955 break;
1956 }
1957
1958 case Primitive::kPrimChar: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001959 Register out = locations->Out().AsRegister<Register>();
1960 if (index.IsConstant()) {
1961 size_t offset =
1962 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001963 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001964 } else {
1965 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1966 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001967 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001968 }
1969 break;
1970 }
1971
1972 case Primitive::kPrimInt:
1973 case Primitive::kPrimNot: {
1974 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001975 Register out = locations->Out().AsRegister<Register>();
1976 if (index.IsConstant()) {
1977 size_t offset =
1978 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001979 __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001980 } else {
1981 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1982 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001983 __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001984 }
1985 break;
1986 }
1987
1988 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001989 Register out = locations->Out().AsRegisterPairLow<Register>();
1990 if (index.IsConstant()) {
1991 size_t offset =
1992 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001993 __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001994 } else {
1995 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1996 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001997 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001998 }
1999 break;
2000 }
2001
2002 case Primitive::kPrimFloat: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002003 FRegister out = locations->Out().AsFpuRegister<FRegister>();
2004 if (index.IsConstant()) {
2005 size_t offset =
2006 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002007 __ LoadSFromOffset(out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002008 } else {
2009 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
2010 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002011 __ LoadSFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002012 }
2013 break;
2014 }
2015
2016 case Primitive::kPrimDouble: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002017 FRegister out = locations->Out().AsFpuRegister<FRegister>();
2018 if (index.IsConstant()) {
2019 size_t offset =
2020 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002021 __ LoadDFromOffset(out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002022 } else {
2023 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
2024 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002025 __ LoadDFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002026 }
2027 break;
2028 }
2029
2030 case Primitive::kPrimVoid:
2031 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2032 UNREACHABLE();
2033 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002034}
2035
2036void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) {
2037 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2038 locations->SetInAt(0, Location::RequiresRegister());
2039 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2040}
2041
2042void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) {
2043 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01002044 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002045 Register obj = locations->InAt(0).AsRegister<Register>();
2046 Register out = locations->Out().AsRegister<Register>();
2047 __ LoadFromOffset(kLoadWord, out, obj, offset);
2048 codegen_->MaybeRecordImplicitNullCheck(instruction);
2049}
2050
Alexey Frunzef58b2482016-09-02 22:14:06 -07002051Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) {
2052 return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern())
2053 ? Location::ConstantLocation(instruction->AsConstant())
2054 : Location::RequiresRegister();
2055}
2056
2057Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) {
2058 // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register.
2059 // We can store a non-zero float or double constant without first loading it into the FPU,
2060 // but we should only prefer this if the constant has a single use.
2061 if (instruction->IsConstant() &&
2062 (instruction->AsConstant()->IsZeroBitPattern() ||
2063 instruction->GetUses().HasExactlyOneElement())) {
2064 return Location::ConstantLocation(instruction->AsConstant());
2065 // Otherwise fall through and require an FPU register for the constant.
2066 }
2067 return Location::RequiresFpuRegister();
2068}
2069
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002070void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) {
Pavle Batuta934808f2015-11-03 13:23:54 +01002071 bool needs_runtime_call = instruction->NeedsTypeCheck();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002072 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2073 instruction,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002074 needs_runtime_call ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Pavle Batuta934808f2015-11-03 13:23:54 +01002075 if (needs_runtime_call) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002076 InvokeRuntimeCallingConvention calling_convention;
2077 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2078 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2079 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2080 } else {
2081 locations->SetInAt(0, Location::RequiresRegister());
2082 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2083 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002084 locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002085 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002086 locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002087 }
2088 }
2089}
2090
2091void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) {
2092 LocationSummary* locations = instruction->GetLocations();
2093 Register obj = locations->InAt(0).AsRegister<Register>();
2094 Location index = locations->InAt(1);
Alexey Frunzef58b2482016-09-02 22:14:06 -07002095 Location value_location = locations->InAt(2);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002096 Primitive::Type value_type = instruction->GetComponentType();
2097 bool needs_runtime_call = locations->WillCall();
2098 bool needs_write_barrier =
2099 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Alexey Frunze2923db72016-08-20 01:55:47 -07002100 auto null_checker = GetImplicitNullChecker(instruction);
Alexey Frunzef58b2482016-09-02 22:14:06 -07002101 Register base_reg = index.IsConstant() ? obj : TMP;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002102
2103 switch (value_type) {
2104 case Primitive::kPrimBoolean:
2105 case Primitive::kPrimByte: {
2106 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002107 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002108 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002109 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002110 __ Addu(base_reg, obj, index.AsRegister<Register>());
2111 }
2112 if (value_location.IsConstant()) {
2113 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2114 __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker);
2115 } else {
2116 Register value = value_location.AsRegister<Register>();
2117 __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002118 }
2119 break;
2120 }
2121
2122 case Primitive::kPrimShort:
2123 case Primitive::kPrimChar: {
2124 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002125 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002126 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002127 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002128 __ Sll(base_reg, index.AsRegister<Register>(), TIMES_2);
2129 __ Addu(base_reg, obj, base_reg);
2130 }
2131 if (value_location.IsConstant()) {
2132 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2133 __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker);
2134 } else {
2135 Register value = value_location.AsRegister<Register>();
2136 __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002137 }
2138 break;
2139 }
2140
2141 case Primitive::kPrimInt:
2142 case Primitive::kPrimNot: {
2143 if (!needs_runtime_call) {
2144 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002145 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002146 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002147 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002148 __ Sll(base_reg, index.AsRegister<Register>(), TIMES_4);
2149 __ Addu(base_reg, obj, base_reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002150 }
Alexey Frunzef58b2482016-09-02 22:14:06 -07002151 if (value_location.IsConstant()) {
2152 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2153 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2154 DCHECK(!needs_write_barrier);
2155 } else {
2156 Register value = value_location.AsRegister<Register>();
2157 __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
2158 if (needs_write_barrier) {
2159 DCHECK_EQ(value_type, Primitive::kPrimNot);
Goran Jakovljevice114da22016-12-26 14:21:43 +01002160 codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull());
Alexey Frunzef58b2482016-09-02 22:14:06 -07002161 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002162 }
2163 } else {
2164 DCHECK_EQ(value_type, Primitive::kPrimNot);
Serban Constantinescufca16662016-07-14 09:21:59 +01002165 codegen_->InvokeRuntime(kQuickAputObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002166 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
2167 }
2168 break;
2169 }
2170
2171 case Primitive::kPrimLong: {
2172 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002173 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002174 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002175 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002176 __ Sll(base_reg, index.AsRegister<Register>(), TIMES_8);
2177 __ Addu(base_reg, obj, base_reg);
2178 }
2179 if (value_location.IsConstant()) {
2180 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
2181 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
2182 } else {
2183 Register value = value_location.AsRegisterPairLow<Register>();
2184 __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002185 }
2186 break;
2187 }
2188
2189 case Primitive::kPrimFloat: {
2190 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002191 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002192 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002193 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002194 __ Sll(base_reg, index.AsRegister<Register>(), TIMES_4);
2195 __ Addu(base_reg, obj, base_reg);
2196 }
2197 if (value_location.IsConstant()) {
2198 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2199 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2200 } else {
2201 FRegister value = value_location.AsFpuRegister<FRegister>();
2202 __ StoreSToOffset(value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002203 }
2204 break;
2205 }
2206
2207 case Primitive::kPrimDouble: {
2208 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002209 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002210 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002211 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002212 __ Sll(base_reg, index.AsRegister<Register>(), TIMES_8);
2213 __ Addu(base_reg, obj, base_reg);
2214 }
2215 if (value_location.IsConstant()) {
2216 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
2217 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
2218 } else {
2219 FRegister value = value_location.AsFpuRegister<FRegister>();
2220 __ StoreDToOffset(value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002221 }
2222 break;
2223 }
2224
2225 case Primitive::kPrimVoid:
2226 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2227 UNREACHABLE();
2228 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002229}
2230
2231void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01002232 RegisterSet caller_saves = RegisterSet::Empty();
2233 InvokeRuntimeCallingConvention calling_convention;
2234 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2235 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2236 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002237 locations->SetInAt(0, Location::RequiresRegister());
2238 locations->SetInAt(1, Location::RequiresRegister());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002239}
2240
2241void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
2242 LocationSummary* locations = instruction->GetLocations();
2243 BoundsCheckSlowPathMIPS* slow_path =
2244 new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction);
2245 codegen_->AddSlowPath(slow_path);
2246
2247 Register index = locations->InAt(0).AsRegister<Register>();
2248 Register length = locations->InAt(1).AsRegister<Register>();
2249
2250 // length is limited by the maximum positive signed 32-bit integer.
2251 // Unsigned comparison of length and index checks for index < 0
2252 // and for length <= index simultaneously.
2253 __ Bgeu(index, length, slow_path->GetEntryLabel());
2254}
2255
2256void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) {
2257 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2258 instruction,
2259 LocationSummary::kCallOnSlowPath);
2260 locations->SetInAt(0, Location::RequiresRegister());
2261 locations->SetInAt(1, Location::RequiresRegister());
2262 // Note that TypeCheckSlowPathMIPS uses this register too.
2263 locations->AddTemp(Location::RequiresRegister());
2264}
2265
2266void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) {
2267 LocationSummary* locations = instruction->GetLocations();
2268 Register obj = locations->InAt(0).AsRegister<Register>();
2269 Register cls = locations->InAt(1).AsRegister<Register>();
2270 Register obj_cls = locations->GetTemp(0).AsRegister<Register>();
2271
2272 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction);
2273 codegen_->AddSlowPath(slow_path);
2274
2275 // TODO: avoid this check if we know obj is not null.
2276 __ Beqz(obj, slow_path->GetExitLabel());
2277 // Compare the class of `obj` with `cls`.
2278 __ LoadFromOffset(kLoadWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value());
2279 __ Bne(obj_cls, cls, slow_path->GetEntryLabel());
2280 __ Bind(slow_path->GetExitLabel());
2281}
2282
2283void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) {
2284 LocationSummary* locations =
2285 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2286 locations->SetInAt(0, Location::RequiresRegister());
2287 if (check->HasUses()) {
2288 locations->SetOut(Location::SameAsFirstInput());
2289 }
2290}
2291
2292void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) {
2293 // We assume the class is not null.
2294 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS(
2295 check->GetLoadClass(),
2296 check,
2297 check->GetDexPc(),
2298 true);
2299 codegen_->AddSlowPath(slow_path);
2300 GenerateClassInitializationCheck(slow_path,
2301 check->GetLocations()->InAt(0).AsRegister<Register>());
2302}
2303
2304void LocationsBuilderMIPS::VisitCompare(HCompare* compare) {
2305 Primitive::Type in_type = compare->InputAt(0)->GetType();
2306
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002307 LocationSummary* locations =
2308 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002309
2310 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002311 case Primitive::kPrimBoolean:
2312 case Primitive::kPrimByte:
2313 case Primitive::kPrimShort:
2314 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002315 case Primitive::kPrimInt:
Alexey Frunzee7697712016-09-15 21:37:49 -07002316 locations->SetInAt(0, Location::RequiresRegister());
2317 locations->SetInAt(1, Location::RequiresRegister());
2318 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2319 break;
2320
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002321 case Primitive::kPrimLong:
2322 locations->SetInAt(0, Location::RequiresRegister());
2323 locations->SetInAt(1, Location::RequiresRegister());
2324 // Output overlaps because it is written before doing the low comparison.
2325 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2326 break;
2327
2328 case Primitive::kPrimFloat:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002329 case Primitive::kPrimDouble:
2330 locations->SetInAt(0, Location::RequiresFpuRegister());
2331 locations->SetInAt(1, Location::RequiresFpuRegister());
2332 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002333 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002334
2335 default:
2336 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
2337 }
2338}
2339
2340void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) {
2341 LocationSummary* locations = instruction->GetLocations();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002342 Register res = locations->Out().AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002343 Primitive::Type in_type = instruction->InputAt(0)->GetType();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002344 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002345
2346 // 0 if: left == right
2347 // 1 if: left > right
2348 // -1 if: left < right
2349 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002350 case Primitive::kPrimBoolean:
2351 case Primitive::kPrimByte:
2352 case Primitive::kPrimShort:
2353 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002354 case Primitive::kPrimInt: {
2355 Register lhs = locations->InAt(0).AsRegister<Register>();
2356 Register rhs = locations->InAt(1).AsRegister<Register>();
2357 __ Slt(TMP, lhs, rhs);
2358 __ Slt(res, rhs, lhs);
2359 __ Subu(res, res, TMP);
2360 break;
2361 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002362 case Primitive::kPrimLong: {
2363 MipsLabel done;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002364 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2365 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
2366 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
2367 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
2368 // TODO: more efficient (direct) comparison with a constant.
2369 __ Slt(TMP, lhs_high, rhs_high);
2370 __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt.
2371 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2372 __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal.
2373 __ Sltu(TMP, lhs_low, rhs_low);
2374 __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt.
2375 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2376 __ Bind(&done);
2377 break;
2378 }
2379
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002380 case Primitive::kPrimFloat: {
Roland Levillain32ca3752016-02-17 16:49:37 +00002381 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002382 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2383 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2384 MipsLabel done;
2385 if (isR6) {
2386 __ CmpEqS(FTMP, lhs, rhs);
2387 __ LoadConst32(res, 0);
2388 __ Bc1nez(FTMP, &done);
2389 if (gt_bias) {
2390 __ CmpLtS(FTMP, lhs, rhs);
2391 __ LoadConst32(res, -1);
2392 __ Bc1nez(FTMP, &done);
2393 __ LoadConst32(res, 1);
2394 } else {
2395 __ CmpLtS(FTMP, rhs, lhs);
2396 __ LoadConst32(res, 1);
2397 __ Bc1nez(FTMP, &done);
2398 __ LoadConst32(res, -1);
2399 }
2400 } else {
2401 if (gt_bias) {
2402 __ ColtS(0, lhs, rhs);
2403 __ LoadConst32(res, -1);
2404 __ Bc1t(0, &done);
2405 __ CeqS(0, lhs, rhs);
2406 __ LoadConst32(res, 1);
2407 __ Movt(res, ZERO, 0);
2408 } else {
2409 __ ColtS(0, rhs, lhs);
2410 __ LoadConst32(res, 1);
2411 __ Bc1t(0, &done);
2412 __ CeqS(0, lhs, rhs);
2413 __ LoadConst32(res, -1);
2414 __ Movt(res, ZERO, 0);
2415 }
2416 }
2417 __ Bind(&done);
2418 break;
2419 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002420 case Primitive::kPrimDouble: {
Roland Levillain32ca3752016-02-17 16:49:37 +00002421 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002422 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2423 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2424 MipsLabel done;
2425 if (isR6) {
2426 __ CmpEqD(FTMP, lhs, rhs);
2427 __ LoadConst32(res, 0);
2428 __ Bc1nez(FTMP, &done);
2429 if (gt_bias) {
2430 __ CmpLtD(FTMP, lhs, rhs);
2431 __ LoadConst32(res, -1);
2432 __ Bc1nez(FTMP, &done);
2433 __ LoadConst32(res, 1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002434 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002435 __ CmpLtD(FTMP, rhs, lhs);
2436 __ LoadConst32(res, 1);
2437 __ Bc1nez(FTMP, &done);
2438 __ LoadConst32(res, -1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002439 }
2440 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002441 if (gt_bias) {
2442 __ ColtD(0, lhs, rhs);
2443 __ LoadConst32(res, -1);
2444 __ Bc1t(0, &done);
2445 __ CeqD(0, lhs, rhs);
2446 __ LoadConst32(res, 1);
2447 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002448 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002449 __ ColtD(0, rhs, lhs);
2450 __ LoadConst32(res, 1);
2451 __ Bc1t(0, &done);
2452 __ CeqD(0, lhs, rhs);
2453 __ LoadConst32(res, -1);
2454 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002455 }
2456 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002457 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002458 break;
2459 }
2460
2461 default:
2462 LOG(FATAL) << "Unimplemented compare type " << in_type;
2463 }
2464}
2465
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002466void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002467 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002468 switch (instruction->InputAt(0)->GetType()) {
2469 default:
2470 case Primitive::kPrimLong:
2471 locations->SetInAt(0, Location::RequiresRegister());
2472 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2473 break;
2474
2475 case Primitive::kPrimFloat:
2476 case Primitive::kPrimDouble:
2477 locations->SetInAt(0, Location::RequiresFpuRegister());
2478 locations->SetInAt(1, Location::RequiresFpuRegister());
2479 break;
2480 }
David Brazdilb3e773e2016-01-26 11:28:37 +00002481 if (!instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002482 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2483 }
2484}
2485
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002486void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00002487 if (instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002488 return;
2489 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002490
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002491 Primitive::Type type = instruction->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002492 LocationSummary* locations = instruction->GetLocations();
2493 Register dst = locations->Out().AsRegister<Register>();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002494 MipsLabel true_label;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002495
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002496 switch (type) {
2497 default:
2498 // Integer case.
2499 GenerateIntCompare(instruction->GetCondition(), locations);
2500 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002501
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002502 case Primitive::kPrimLong:
2503 // TODO: don't use branches.
2504 GenerateLongCompareAndBranch(instruction->GetCondition(), locations, &true_label);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002505 break;
2506
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002507 case Primitive::kPrimFloat:
2508 case Primitive::kPrimDouble:
Alexey Frunze2ddb7172016-09-06 17:04:55 -07002509 GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations);
2510 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002511 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002512
2513 // Convert the branches into the result.
2514 MipsLabel done;
2515
2516 // False case: result = 0.
2517 __ LoadConst32(dst, 0);
2518 __ B(&done);
2519
2520 // True case: result = 1.
2521 __ Bind(&true_label);
2522 __ LoadConst32(dst, 1);
2523 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002524}
2525
Alexey Frunze7e99e052015-11-24 19:28:01 -08002526void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2527 DCHECK(instruction->IsDiv() || instruction->IsRem());
2528 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2529
2530 LocationSummary* locations = instruction->GetLocations();
2531 Location second = locations->InAt(1);
2532 DCHECK(second.IsConstant());
2533
2534 Register out = locations->Out().AsRegister<Register>();
2535 Register dividend = locations->InAt(0).AsRegister<Register>();
2536 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2537 DCHECK(imm == 1 || imm == -1);
2538
2539 if (instruction->IsRem()) {
2540 __ Move(out, ZERO);
2541 } else {
2542 if (imm == -1) {
2543 __ Subu(out, ZERO, dividend);
2544 } else if (out != dividend) {
2545 __ Move(out, dividend);
2546 }
2547 }
2548}
2549
2550void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2551 DCHECK(instruction->IsDiv() || instruction->IsRem());
2552 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2553
2554 LocationSummary* locations = instruction->GetLocations();
2555 Location second = locations->InAt(1);
2556 DCHECK(second.IsConstant());
2557
2558 Register out = locations->Out().AsRegister<Register>();
2559 Register dividend = locations->InAt(0).AsRegister<Register>();
2560 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002561 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Alexey Frunze7e99e052015-11-24 19:28:01 -08002562 int ctz_imm = CTZ(abs_imm);
2563
2564 if (instruction->IsDiv()) {
2565 if (ctz_imm == 1) {
2566 // Fast path for division by +/-2, which is very common.
2567 __ Srl(TMP, dividend, 31);
2568 } else {
2569 __ Sra(TMP, dividend, 31);
2570 __ Srl(TMP, TMP, 32 - ctz_imm);
2571 }
2572 __ Addu(out, dividend, TMP);
2573 __ Sra(out, out, ctz_imm);
2574 if (imm < 0) {
2575 __ Subu(out, ZERO, out);
2576 }
2577 } else {
2578 if (ctz_imm == 1) {
2579 // Fast path for modulo +/-2, which is very common.
2580 __ Sra(TMP, dividend, 31);
2581 __ Subu(out, dividend, TMP);
2582 __ Andi(out, out, 1);
2583 __ Addu(out, out, TMP);
2584 } else {
2585 __ Sra(TMP, dividend, 31);
2586 __ Srl(TMP, TMP, 32 - ctz_imm);
2587 __ Addu(out, dividend, TMP);
2588 if (IsUint<16>(abs_imm - 1)) {
2589 __ Andi(out, out, abs_imm - 1);
2590 } else {
2591 __ Sll(out, out, 32 - ctz_imm);
2592 __ Srl(out, out, 32 - ctz_imm);
2593 }
2594 __ Subu(out, out, TMP);
2595 }
2596 }
2597}
2598
2599void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2600 DCHECK(instruction->IsDiv() || instruction->IsRem());
2601 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2602
2603 LocationSummary* locations = instruction->GetLocations();
2604 Location second = locations->InAt(1);
2605 DCHECK(second.IsConstant());
2606
2607 Register out = locations->Out().AsRegister<Register>();
2608 Register dividend = locations->InAt(0).AsRegister<Register>();
2609 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2610
2611 int64_t magic;
2612 int shift;
2613 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2614
2615 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2616
2617 __ LoadConst32(TMP, magic);
2618 if (isR6) {
2619 __ MuhR6(TMP, dividend, TMP);
2620 } else {
2621 __ MultR2(dividend, TMP);
2622 __ Mfhi(TMP);
2623 }
2624 if (imm > 0 && magic < 0) {
2625 __ Addu(TMP, TMP, dividend);
2626 } else if (imm < 0 && magic > 0) {
2627 __ Subu(TMP, TMP, dividend);
2628 }
2629
2630 if (shift != 0) {
2631 __ Sra(TMP, TMP, shift);
2632 }
2633
2634 if (instruction->IsDiv()) {
2635 __ Sra(out, TMP, 31);
2636 __ Subu(out, TMP, out);
2637 } else {
2638 __ Sra(AT, TMP, 31);
2639 __ Subu(AT, TMP, AT);
2640 __ LoadConst32(TMP, imm);
2641 if (isR6) {
2642 __ MulR6(TMP, AT, TMP);
2643 } else {
2644 __ MulR2(TMP, AT, TMP);
2645 }
2646 __ Subu(out, dividend, TMP);
2647 }
2648}
2649
2650void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) {
2651 DCHECK(instruction->IsDiv() || instruction->IsRem());
2652 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2653
2654 LocationSummary* locations = instruction->GetLocations();
2655 Register out = locations->Out().AsRegister<Register>();
2656 Location second = locations->InAt(1);
2657
2658 if (second.IsConstant()) {
2659 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2660 if (imm == 0) {
2661 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2662 } else if (imm == 1 || imm == -1) {
2663 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002664 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002665 DivRemByPowerOfTwo(instruction);
2666 } else {
2667 DCHECK(imm <= -2 || imm >= 2);
2668 GenerateDivRemWithAnyConstant(instruction);
2669 }
2670 } else {
2671 Register dividend = locations->InAt(0).AsRegister<Register>();
2672 Register divisor = second.AsRegister<Register>();
2673 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2674 if (instruction->IsDiv()) {
2675 if (isR6) {
2676 __ DivR6(out, dividend, divisor);
2677 } else {
2678 __ DivR2(out, dividend, divisor);
2679 }
2680 } else {
2681 if (isR6) {
2682 __ ModR6(out, dividend, divisor);
2683 } else {
2684 __ ModR2(out, dividend, divisor);
2685 }
2686 }
2687 }
2688}
2689
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002690void LocationsBuilderMIPS::VisitDiv(HDiv* div) {
2691 Primitive::Type type = div->GetResultType();
2692 LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong)
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002693 ? LocationSummary::kCallOnMainOnly
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002694 : LocationSummary::kNoCall;
2695
2696 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2697
2698 switch (type) {
2699 case Primitive::kPrimInt:
2700 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08002701 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002702 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2703 break;
2704
2705 case Primitive::kPrimLong: {
2706 InvokeRuntimeCallingConvention calling_convention;
2707 locations->SetInAt(0, Location::RegisterPairLocation(
2708 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2709 locations->SetInAt(1, Location::RegisterPairLocation(
2710 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2711 locations->SetOut(calling_convention.GetReturnLocation(type));
2712 break;
2713 }
2714
2715 case Primitive::kPrimFloat:
2716 case Primitive::kPrimDouble:
2717 locations->SetInAt(0, Location::RequiresFpuRegister());
2718 locations->SetInAt(1, Location::RequiresFpuRegister());
2719 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2720 break;
2721
2722 default:
2723 LOG(FATAL) << "Unexpected div type " << type;
2724 }
2725}
2726
2727void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) {
2728 Primitive::Type type = instruction->GetType();
2729 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002730
2731 switch (type) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002732 case Primitive::kPrimInt:
2733 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002734 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002735 case Primitive::kPrimLong: {
Serban Constantinescufca16662016-07-14 09:21:59 +01002736 codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002737 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
2738 break;
2739 }
2740 case Primitive::kPrimFloat:
2741 case Primitive::kPrimDouble: {
2742 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
2743 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2744 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2745 if (type == Primitive::kPrimFloat) {
2746 __ DivS(dst, lhs, rhs);
2747 } else {
2748 __ DivD(dst, lhs, rhs);
2749 }
2750 break;
2751 }
2752 default:
2753 LOG(FATAL) << "Unexpected div type " << type;
2754 }
2755}
2756
2757void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01002758 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002759 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002760}
2761
2762void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2763 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction);
2764 codegen_->AddSlowPath(slow_path);
2765 Location value = instruction->GetLocations()->InAt(0);
2766 Primitive::Type type = instruction->GetType();
2767
2768 switch (type) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00002769 case Primitive::kPrimBoolean:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002770 case Primitive::kPrimByte:
2771 case Primitive::kPrimChar:
2772 case Primitive::kPrimShort:
2773 case Primitive::kPrimInt: {
2774 if (value.IsConstant()) {
2775 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2776 __ B(slow_path->GetEntryLabel());
2777 } else {
2778 // A division by a non-null constant is valid. We don't need to perform
2779 // any check, so simply fall through.
2780 }
2781 } else {
2782 DCHECK(value.IsRegister()) << value;
2783 __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel());
2784 }
2785 break;
2786 }
2787 case Primitive::kPrimLong: {
2788 if (value.IsConstant()) {
2789 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2790 __ B(slow_path->GetEntryLabel());
2791 } else {
2792 // A division by a non-null constant is valid. We don't need to perform
2793 // any check, so simply fall through.
2794 }
2795 } else {
2796 DCHECK(value.IsRegisterPair()) << value;
2797 __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>());
2798 __ Beqz(TMP, slow_path->GetEntryLabel());
2799 }
2800 break;
2801 }
2802 default:
2803 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
2804 }
2805}
2806
2807void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) {
2808 LocationSummary* locations =
2809 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2810 locations->SetOut(Location::ConstantLocation(constant));
2811}
2812
2813void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
2814 // Will be generated at use site.
2815}
2816
2817void LocationsBuilderMIPS::VisitExit(HExit* exit) {
2818 exit->SetLocations(nullptr);
2819}
2820
2821void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
2822}
2823
2824void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) {
2825 LocationSummary* locations =
2826 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2827 locations->SetOut(Location::ConstantLocation(constant));
2828}
2829
2830void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
2831 // Will be generated at use site.
2832}
2833
2834void LocationsBuilderMIPS::VisitGoto(HGoto* got) {
2835 got->SetLocations(nullptr);
2836}
2837
2838void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) {
2839 DCHECK(!successor->IsExitBlock());
2840 HBasicBlock* block = got->GetBlock();
2841 HInstruction* previous = got->GetPrevious();
2842 HLoopInformation* info = block->GetLoopInformation();
2843
2844 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
2845 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
2846 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
2847 return;
2848 }
2849 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
2850 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
2851 }
2852 if (!codegen_->GoesToNextBlock(block, successor)) {
2853 __ B(codegen_->GetLabelOf(successor));
2854 }
2855}
2856
2857void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) {
2858 HandleGoto(got, got->GetSuccessor());
2859}
2860
2861void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2862 try_boundary->SetLocations(nullptr);
2863}
2864
2865void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2866 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
2867 if (!successor->IsExitBlock()) {
2868 HandleGoto(try_boundary, successor);
2869 }
2870}
2871
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002872void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond,
2873 LocationSummary* locations) {
2874 Register dst = locations->Out().AsRegister<Register>();
2875 Register lhs = locations->InAt(0).AsRegister<Register>();
2876 Location rhs_location = locations->InAt(1);
2877 Register rhs_reg = ZERO;
2878 int64_t rhs_imm = 0;
2879 bool use_imm = rhs_location.IsConstant();
2880 if (use_imm) {
2881 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2882 } else {
2883 rhs_reg = rhs_location.AsRegister<Register>();
2884 }
2885
2886 switch (cond) {
2887 case kCondEQ:
2888 case kCondNE:
Alexey Frunzee7697712016-09-15 21:37:49 -07002889 if (use_imm && IsInt<16>(-rhs_imm)) {
2890 if (rhs_imm == 0) {
2891 if (cond == kCondEQ) {
2892 __ Sltiu(dst, lhs, 1);
2893 } else {
2894 __ Sltu(dst, ZERO, lhs);
2895 }
2896 } else {
2897 __ Addiu(dst, lhs, -rhs_imm);
2898 if (cond == kCondEQ) {
2899 __ Sltiu(dst, dst, 1);
2900 } else {
2901 __ Sltu(dst, ZERO, dst);
2902 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002903 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002904 } else {
Alexey Frunzee7697712016-09-15 21:37:49 -07002905 if (use_imm && IsUint<16>(rhs_imm)) {
2906 __ Xori(dst, lhs, rhs_imm);
2907 } else {
2908 if (use_imm) {
2909 rhs_reg = TMP;
2910 __ LoadConst32(rhs_reg, rhs_imm);
2911 }
2912 __ Xor(dst, lhs, rhs_reg);
2913 }
2914 if (cond == kCondEQ) {
2915 __ Sltiu(dst, dst, 1);
2916 } else {
2917 __ Sltu(dst, ZERO, dst);
2918 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002919 }
2920 break;
2921
2922 case kCondLT:
2923 case kCondGE:
2924 if (use_imm && IsInt<16>(rhs_imm)) {
2925 __ Slti(dst, lhs, rhs_imm);
2926 } else {
2927 if (use_imm) {
2928 rhs_reg = TMP;
2929 __ LoadConst32(rhs_reg, rhs_imm);
2930 }
2931 __ Slt(dst, lhs, rhs_reg);
2932 }
2933 if (cond == kCondGE) {
2934 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2935 // only the slt instruction but no sge.
2936 __ Xori(dst, dst, 1);
2937 }
2938 break;
2939
2940 case kCondLE:
2941 case kCondGT:
2942 if (use_imm && IsInt<16>(rhs_imm + 1)) {
2943 // Simulate lhs <= rhs via lhs < rhs + 1.
2944 __ Slti(dst, lhs, rhs_imm + 1);
2945 if (cond == kCondGT) {
2946 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2947 // only the slti instruction but no sgti.
2948 __ Xori(dst, dst, 1);
2949 }
2950 } else {
2951 if (use_imm) {
2952 rhs_reg = TMP;
2953 __ LoadConst32(rhs_reg, rhs_imm);
2954 }
2955 __ Slt(dst, rhs_reg, lhs);
2956 if (cond == kCondLE) {
2957 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2958 // only the slt instruction but no sle.
2959 __ Xori(dst, dst, 1);
2960 }
2961 }
2962 break;
2963
2964 case kCondB:
2965 case kCondAE:
2966 if (use_imm && IsInt<16>(rhs_imm)) {
2967 // Sltiu sign-extends its 16-bit immediate operand before
2968 // the comparison and thus lets us compare directly with
2969 // unsigned values in the ranges [0, 0x7fff] and
2970 // [0xffff8000, 0xffffffff].
2971 __ Sltiu(dst, lhs, rhs_imm);
2972 } else {
2973 if (use_imm) {
2974 rhs_reg = TMP;
2975 __ LoadConst32(rhs_reg, rhs_imm);
2976 }
2977 __ Sltu(dst, lhs, rhs_reg);
2978 }
2979 if (cond == kCondAE) {
2980 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2981 // only the sltu instruction but no sgeu.
2982 __ Xori(dst, dst, 1);
2983 }
2984 break;
2985
2986 case kCondBE:
2987 case kCondA:
2988 if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
2989 // Simulate lhs <= rhs via lhs < rhs + 1.
2990 // Note that this only works if rhs + 1 does not overflow
2991 // to 0, hence the check above.
2992 // Sltiu sign-extends its 16-bit immediate operand before
2993 // the comparison and thus lets us compare directly with
2994 // unsigned values in the ranges [0, 0x7fff] and
2995 // [0xffff8000, 0xffffffff].
2996 __ Sltiu(dst, lhs, rhs_imm + 1);
2997 if (cond == kCondA) {
2998 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2999 // only the sltiu instruction but no sgtiu.
3000 __ Xori(dst, dst, 1);
3001 }
3002 } else {
3003 if (use_imm) {
3004 rhs_reg = TMP;
3005 __ LoadConst32(rhs_reg, rhs_imm);
3006 }
3007 __ Sltu(dst, rhs_reg, lhs);
3008 if (cond == kCondBE) {
3009 // Simulate lhs <= rhs via !(rhs < lhs) since there's
3010 // only the sltu instruction but no sleu.
3011 __ Xori(dst, dst, 1);
3012 }
3013 }
3014 break;
3015 }
3016}
3017
Alexey Frunze674b9ee2016-09-20 14:54:15 -07003018bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond,
3019 LocationSummary* input_locations,
3020 Register dst) {
3021 Register lhs = input_locations->InAt(0).AsRegister<Register>();
3022 Location rhs_location = input_locations->InAt(1);
3023 Register rhs_reg = ZERO;
3024 int64_t rhs_imm = 0;
3025 bool use_imm = rhs_location.IsConstant();
3026 if (use_imm) {
3027 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
3028 } else {
3029 rhs_reg = rhs_location.AsRegister<Register>();
3030 }
3031
3032 switch (cond) {
3033 case kCondEQ:
3034 case kCondNE:
3035 if (use_imm && IsInt<16>(-rhs_imm)) {
3036 __ Addiu(dst, lhs, -rhs_imm);
3037 } else if (use_imm && IsUint<16>(rhs_imm)) {
3038 __ Xori(dst, lhs, rhs_imm);
3039 } else {
3040 if (use_imm) {
3041 rhs_reg = TMP;
3042 __ LoadConst32(rhs_reg, rhs_imm);
3043 }
3044 __ Xor(dst, lhs, rhs_reg);
3045 }
3046 return (cond == kCondEQ);
3047
3048 case kCondLT:
3049 case kCondGE:
3050 if (use_imm && IsInt<16>(rhs_imm)) {
3051 __ Slti(dst, lhs, rhs_imm);
3052 } else {
3053 if (use_imm) {
3054 rhs_reg = TMP;
3055 __ LoadConst32(rhs_reg, rhs_imm);
3056 }
3057 __ Slt(dst, lhs, rhs_reg);
3058 }
3059 return (cond == kCondGE);
3060
3061 case kCondLE:
3062 case kCondGT:
3063 if (use_imm && IsInt<16>(rhs_imm + 1)) {
3064 // Simulate lhs <= rhs via lhs < rhs + 1.
3065 __ Slti(dst, lhs, rhs_imm + 1);
3066 return (cond == kCondGT);
3067 } else {
3068 if (use_imm) {
3069 rhs_reg = TMP;
3070 __ LoadConst32(rhs_reg, rhs_imm);
3071 }
3072 __ Slt(dst, rhs_reg, lhs);
3073 return (cond == kCondLE);
3074 }
3075
3076 case kCondB:
3077 case kCondAE:
3078 if (use_imm && IsInt<16>(rhs_imm)) {
3079 // Sltiu sign-extends its 16-bit immediate operand before
3080 // the comparison and thus lets us compare directly with
3081 // unsigned values in the ranges [0, 0x7fff] and
3082 // [0xffff8000, 0xffffffff].
3083 __ Sltiu(dst, lhs, rhs_imm);
3084 } else {
3085 if (use_imm) {
3086 rhs_reg = TMP;
3087 __ LoadConst32(rhs_reg, rhs_imm);
3088 }
3089 __ Sltu(dst, lhs, rhs_reg);
3090 }
3091 return (cond == kCondAE);
3092
3093 case kCondBE:
3094 case kCondA:
3095 if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
3096 // Simulate lhs <= rhs via lhs < rhs + 1.
3097 // Note that this only works if rhs + 1 does not overflow
3098 // to 0, hence the check above.
3099 // Sltiu sign-extends its 16-bit immediate operand before
3100 // the comparison and thus lets us compare directly with
3101 // unsigned values in the ranges [0, 0x7fff] and
3102 // [0xffff8000, 0xffffffff].
3103 __ Sltiu(dst, lhs, rhs_imm + 1);
3104 return (cond == kCondA);
3105 } else {
3106 if (use_imm) {
3107 rhs_reg = TMP;
3108 __ LoadConst32(rhs_reg, rhs_imm);
3109 }
3110 __ Sltu(dst, rhs_reg, lhs);
3111 return (cond == kCondBE);
3112 }
3113 }
3114}
3115
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003116void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond,
3117 LocationSummary* locations,
3118 MipsLabel* label) {
3119 Register lhs = locations->InAt(0).AsRegister<Register>();
3120 Location rhs_location = locations->InAt(1);
3121 Register rhs_reg = ZERO;
Alexey Frunzee7697712016-09-15 21:37:49 -07003122 int64_t rhs_imm = 0;
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003123 bool use_imm = rhs_location.IsConstant();
3124 if (use_imm) {
3125 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
3126 } else {
3127 rhs_reg = rhs_location.AsRegister<Register>();
3128 }
3129
3130 if (use_imm && rhs_imm == 0) {
3131 switch (cond) {
3132 case kCondEQ:
3133 case kCondBE: // <= 0 if zero
3134 __ Beqz(lhs, label);
3135 break;
3136 case kCondNE:
3137 case kCondA: // > 0 if non-zero
3138 __ Bnez(lhs, label);
3139 break;
3140 case kCondLT:
3141 __ Bltz(lhs, label);
3142 break;
3143 case kCondGE:
3144 __ Bgez(lhs, label);
3145 break;
3146 case kCondLE:
3147 __ Blez(lhs, label);
3148 break;
3149 case kCondGT:
3150 __ Bgtz(lhs, label);
3151 break;
3152 case kCondB: // always false
3153 break;
3154 case kCondAE: // always true
3155 __ B(label);
3156 break;
3157 }
3158 } else {
Alexey Frunzee7697712016-09-15 21:37:49 -07003159 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3160 if (isR6 || !use_imm) {
3161 if (use_imm) {
3162 rhs_reg = TMP;
3163 __ LoadConst32(rhs_reg, rhs_imm);
3164 }
3165 switch (cond) {
3166 case kCondEQ:
3167 __ Beq(lhs, rhs_reg, label);
3168 break;
3169 case kCondNE:
3170 __ Bne(lhs, rhs_reg, label);
3171 break;
3172 case kCondLT:
3173 __ Blt(lhs, rhs_reg, label);
3174 break;
3175 case kCondGE:
3176 __ Bge(lhs, rhs_reg, label);
3177 break;
3178 case kCondLE:
3179 __ Bge(rhs_reg, lhs, label);
3180 break;
3181 case kCondGT:
3182 __ Blt(rhs_reg, lhs, label);
3183 break;
3184 case kCondB:
3185 __ Bltu(lhs, rhs_reg, label);
3186 break;
3187 case kCondAE:
3188 __ Bgeu(lhs, rhs_reg, label);
3189 break;
3190 case kCondBE:
3191 __ Bgeu(rhs_reg, lhs, label);
3192 break;
3193 case kCondA:
3194 __ Bltu(rhs_reg, lhs, label);
3195 break;
3196 }
3197 } else {
3198 // Special cases for more efficient comparison with constants on R2.
3199 switch (cond) {
3200 case kCondEQ:
3201 __ LoadConst32(TMP, rhs_imm);
3202 __ Beq(lhs, TMP, label);
3203 break;
3204 case kCondNE:
3205 __ LoadConst32(TMP, rhs_imm);
3206 __ Bne(lhs, TMP, label);
3207 break;
3208 case kCondLT:
3209 if (IsInt<16>(rhs_imm)) {
3210 __ Slti(TMP, lhs, rhs_imm);
3211 __ Bnez(TMP, label);
3212 } else {
3213 __ LoadConst32(TMP, rhs_imm);
3214 __ Blt(lhs, TMP, label);
3215 }
3216 break;
3217 case kCondGE:
3218 if (IsInt<16>(rhs_imm)) {
3219 __ Slti(TMP, lhs, rhs_imm);
3220 __ Beqz(TMP, label);
3221 } else {
3222 __ LoadConst32(TMP, rhs_imm);
3223 __ Bge(lhs, TMP, label);
3224 }
3225 break;
3226 case kCondLE:
3227 if (IsInt<16>(rhs_imm + 1)) {
3228 // Simulate lhs <= rhs via lhs < rhs + 1.
3229 __ Slti(TMP, lhs, rhs_imm + 1);
3230 __ Bnez(TMP, label);
3231 } else {
3232 __ LoadConst32(TMP, rhs_imm);
3233 __ Bge(TMP, lhs, label);
3234 }
3235 break;
3236 case kCondGT:
3237 if (IsInt<16>(rhs_imm + 1)) {
3238 // Simulate lhs > rhs via !(lhs < rhs + 1).
3239 __ Slti(TMP, lhs, rhs_imm + 1);
3240 __ Beqz(TMP, label);
3241 } else {
3242 __ LoadConst32(TMP, rhs_imm);
3243 __ Blt(TMP, lhs, label);
3244 }
3245 break;
3246 case kCondB:
3247 if (IsInt<16>(rhs_imm)) {
3248 __ Sltiu(TMP, lhs, rhs_imm);
3249 __ Bnez(TMP, label);
3250 } else {
3251 __ LoadConst32(TMP, rhs_imm);
3252 __ Bltu(lhs, TMP, label);
3253 }
3254 break;
3255 case kCondAE:
3256 if (IsInt<16>(rhs_imm)) {
3257 __ Sltiu(TMP, lhs, rhs_imm);
3258 __ Beqz(TMP, label);
3259 } else {
3260 __ LoadConst32(TMP, rhs_imm);
3261 __ Bgeu(lhs, TMP, label);
3262 }
3263 break;
3264 case kCondBE:
3265 if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
3266 // Simulate lhs <= rhs via lhs < rhs + 1.
3267 // Note that this only works if rhs + 1 does not overflow
3268 // to 0, hence the check above.
3269 __ Sltiu(TMP, lhs, rhs_imm + 1);
3270 __ Bnez(TMP, label);
3271 } else {
3272 __ LoadConst32(TMP, rhs_imm);
3273 __ Bgeu(TMP, lhs, label);
3274 }
3275 break;
3276 case kCondA:
3277 if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
3278 // Simulate lhs > rhs via !(lhs < rhs + 1).
3279 // Note that this only works if rhs + 1 does not overflow
3280 // to 0, hence the check above.
3281 __ Sltiu(TMP, lhs, rhs_imm + 1);
3282 __ Beqz(TMP, label);
3283 } else {
3284 __ LoadConst32(TMP, rhs_imm);
3285 __ Bltu(TMP, lhs, label);
3286 }
3287 break;
3288 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003289 }
3290 }
3291}
3292
3293void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond,
3294 LocationSummary* locations,
3295 MipsLabel* label) {
3296 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
3297 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
3298 Location rhs_location = locations->InAt(1);
3299 Register rhs_high = ZERO;
3300 Register rhs_low = ZERO;
3301 int64_t imm = 0;
3302 uint32_t imm_high = 0;
3303 uint32_t imm_low = 0;
3304 bool use_imm = rhs_location.IsConstant();
3305 if (use_imm) {
3306 imm = rhs_location.GetConstant()->AsLongConstant()->GetValue();
3307 imm_high = High32Bits(imm);
3308 imm_low = Low32Bits(imm);
3309 } else {
3310 rhs_high = rhs_location.AsRegisterPairHigh<Register>();
3311 rhs_low = rhs_location.AsRegisterPairLow<Register>();
3312 }
3313
3314 if (use_imm && imm == 0) {
3315 switch (cond) {
3316 case kCondEQ:
3317 case kCondBE: // <= 0 if zero
3318 __ Or(TMP, lhs_high, lhs_low);
3319 __ Beqz(TMP, label);
3320 break;
3321 case kCondNE:
3322 case kCondA: // > 0 if non-zero
3323 __ Or(TMP, lhs_high, lhs_low);
3324 __ Bnez(TMP, label);
3325 break;
3326 case kCondLT:
3327 __ Bltz(lhs_high, label);
3328 break;
3329 case kCondGE:
3330 __ Bgez(lhs_high, label);
3331 break;
3332 case kCondLE:
3333 __ Or(TMP, lhs_high, lhs_low);
3334 __ Sra(AT, lhs_high, 31);
3335 __ Bgeu(AT, TMP, label);
3336 break;
3337 case kCondGT:
3338 __ Or(TMP, lhs_high, lhs_low);
3339 __ Sra(AT, lhs_high, 31);
3340 __ Bltu(AT, TMP, label);
3341 break;
3342 case kCondB: // always false
3343 break;
3344 case kCondAE: // always true
3345 __ B(label);
3346 break;
3347 }
3348 } else if (use_imm) {
3349 // TODO: more efficient comparison with constants without loading them into TMP/AT.
3350 switch (cond) {
3351 case kCondEQ:
3352 __ LoadConst32(TMP, imm_high);
3353 __ Xor(TMP, TMP, lhs_high);
3354 __ LoadConst32(AT, imm_low);
3355 __ Xor(AT, AT, lhs_low);
3356 __ Or(TMP, TMP, AT);
3357 __ Beqz(TMP, label);
3358 break;
3359 case kCondNE:
3360 __ LoadConst32(TMP, imm_high);
3361 __ Xor(TMP, TMP, lhs_high);
3362 __ LoadConst32(AT, imm_low);
3363 __ Xor(AT, AT, lhs_low);
3364 __ Or(TMP, TMP, AT);
3365 __ Bnez(TMP, label);
3366 break;
3367 case kCondLT:
3368 __ LoadConst32(TMP, imm_high);
3369 __ Blt(lhs_high, TMP, label);
3370 __ Slt(TMP, TMP, lhs_high);
3371 __ LoadConst32(AT, imm_low);
3372 __ Sltu(AT, lhs_low, AT);
3373 __ Blt(TMP, AT, label);
3374 break;
3375 case kCondGE:
3376 __ LoadConst32(TMP, imm_high);
3377 __ Blt(TMP, lhs_high, label);
3378 __ Slt(TMP, lhs_high, TMP);
3379 __ LoadConst32(AT, imm_low);
3380 __ Sltu(AT, lhs_low, AT);
3381 __ Or(TMP, TMP, AT);
3382 __ Beqz(TMP, label);
3383 break;
3384 case kCondLE:
3385 __ LoadConst32(TMP, imm_high);
3386 __ Blt(lhs_high, TMP, label);
3387 __ Slt(TMP, TMP, lhs_high);
3388 __ LoadConst32(AT, imm_low);
3389 __ Sltu(AT, AT, lhs_low);
3390 __ Or(TMP, TMP, AT);
3391 __ Beqz(TMP, label);
3392 break;
3393 case kCondGT:
3394 __ LoadConst32(TMP, imm_high);
3395 __ Blt(TMP, lhs_high, label);
3396 __ Slt(TMP, lhs_high, TMP);
3397 __ LoadConst32(AT, imm_low);
3398 __ Sltu(AT, AT, lhs_low);
3399 __ Blt(TMP, AT, label);
3400 break;
3401 case kCondB:
3402 __ LoadConst32(TMP, imm_high);
3403 __ Bltu(lhs_high, TMP, label);
3404 __ Sltu(TMP, TMP, lhs_high);
3405 __ LoadConst32(AT, imm_low);
3406 __ Sltu(AT, lhs_low, AT);
3407 __ Blt(TMP, AT, label);
3408 break;
3409 case kCondAE:
3410 __ LoadConst32(TMP, imm_high);
3411 __ Bltu(TMP, lhs_high, label);
3412 __ Sltu(TMP, lhs_high, TMP);
3413 __ LoadConst32(AT, imm_low);
3414 __ Sltu(AT, lhs_low, AT);
3415 __ Or(TMP, TMP, AT);
3416 __ Beqz(TMP, label);
3417 break;
3418 case kCondBE:
3419 __ LoadConst32(TMP, imm_high);
3420 __ Bltu(lhs_high, TMP, label);
3421 __ Sltu(TMP, TMP, lhs_high);
3422 __ LoadConst32(AT, imm_low);
3423 __ Sltu(AT, AT, lhs_low);
3424 __ Or(TMP, TMP, AT);
3425 __ Beqz(TMP, label);
3426 break;
3427 case kCondA:
3428 __ LoadConst32(TMP, imm_high);
3429 __ Bltu(TMP, lhs_high, label);
3430 __ Sltu(TMP, lhs_high, TMP);
3431 __ LoadConst32(AT, imm_low);
3432 __ Sltu(AT, AT, lhs_low);
3433 __ Blt(TMP, AT, label);
3434 break;
3435 }
3436 } else {
3437 switch (cond) {
3438 case kCondEQ:
3439 __ Xor(TMP, lhs_high, rhs_high);
3440 __ Xor(AT, lhs_low, rhs_low);
3441 __ Or(TMP, TMP, AT);
3442 __ Beqz(TMP, label);
3443 break;
3444 case kCondNE:
3445 __ Xor(TMP, lhs_high, rhs_high);
3446 __ Xor(AT, lhs_low, rhs_low);
3447 __ Or(TMP, TMP, AT);
3448 __ Bnez(TMP, label);
3449 break;
3450 case kCondLT:
3451 __ Blt(lhs_high, rhs_high, label);
3452 __ Slt(TMP, rhs_high, lhs_high);
3453 __ Sltu(AT, lhs_low, rhs_low);
3454 __ Blt(TMP, AT, label);
3455 break;
3456 case kCondGE:
3457 __ Blt(rhs_high, lhs_high, label);
3458 __ Slt(TMP, lhs_high, rhs_high);
3459 __ Sltu(AT, lhs_low, rhs_low);
3460 __ Or(TMP, TMP, AT);
3461 __ Beqz(TMP, label);
3462 break;
3463 case kCondLE:
3464 __ Blt(lhs_high, rhs_high, label);
3465 __ Slt(TMP, rhs_high, lhs_high);
3466 __ Sltu(AT, rhs_low, lhs_low);
3467 __ Or(TMP, TMP, AT);
3468 __ Beqz(TMP, label);
3469 break;
3470 case kCondGT:
3471 __ Blt(rhs_high, lhs_high, label);
3472 __ Slt(TMP, lhs_high, rhs_high);
3473 __ Sltu(AT, rhs_low, lhs_low);
3474 __ Blt(TMP, AT, label);
3475 break;
3476 case kCondB:
3477 __ Bltu(lhs_high, rhs_high, label);
3478 __ Sltu(TMP, rhs_high, lhs_high);
3479 __ Sltu(AT, lhs_low, rhs_low);
3480 __ Blt(TMP, AT, label);
3481 break;
3482 case kCondAE:
3483 __ Bltu(rhs_high, lhs_high, label);
3484 __ Sltu(TMP, lhs_high, rhs_high);
3485 __ Sltu(AT, lhs_low, rhs_low);
3486 __ Or(TMP, TMP, AT);
3487 __ Beqz(TMP, label);
3488 break;
3489 case kCondBE:
3490 __ Bltu(lhs_high, rhs_high, label);
3491 __ Sltu(TMP, rhs_high, lhs_high);
3492 __ Sltu(AT, rhs_low, lhs_low);
3493 __ Or(TMP, TMP, AT);
3494 __ Beqz(TMP, label);
3495 break;
3496 case kCondA:
3497 __ Bltu(rhs_high, lhs_high, label);
3498 __ Sltu(TMP, lhs_high, rhs_high);
3499 __ Sltu(AT, rhs_low, lhs_low);
3500 __ Blt(TMP, AT, label);
3501 break;
3502 }
3503 }
3504}
3505
Alexey Frunze2ddb7172016-09-06 17:04:55 -07003506void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond,
3507 bool gt_bias,
3508 Primitive::Type type,
3509 LocationSummary* locations) {
3510 Register dst = locations->Out().AsRegister<Register>();
3511 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3512 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3513 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3514 if (type == Primitive::kPrimFloat) {
3515 if (isR6) {
3516 switch (cond) {
3517 case kCondEQ:
3518 __ CmpEqS(FTMP, lhs, rhs);
3519 __ Mfc1(dst, FTMP);
3520 __ Andi(dst, dst, 1);
3521 break;
3522 case kCondNE:
3523 __ CmpEqS(FTMP, lhs, rhs);
3524 __ Mfc1(dst, FTMP);
3525 __ Addiu(dst, dst, 1);
3526 break;
3527 case kCondLT:
3528 if (gt_bias) {
3529 __ CmpLtS(FTMP, lhs, rhs);
3530 } else {
3531 __ CmpUltS(FTMP, lhs, rhs);
3532 }
3533 __ Mfc1(dst, FTMP);
3534 __ Andi(dst, dst, 1);
3535 break;
3536 case kCondLE:
3537 if (gt_bias) {
3538 __ CmpLeS(FTMP, lhs, rhs);
3539 } else {
3540 __ CmpUleS(FTMP, lhs, rhs);
3541 }
3542 __ Mfc1(dst, FTMP);
3543 __ Andi(dst, dst, 1);
3544 break;
3545 case kCondGT:
3546 if (gt_bias) {
3547 __ CmpUltS(FTMP, rhs, lhs);
3548 } else {
3549 __ CmpLtS(FTMP, rhs, lhs);
3550 }
3551 __ Mfc1(dst, FTMP);
3552 __ Andi(dst, dst, 1);
3553 break;
3554 case kCondGE:
3555 if (gt_bias) {
3556 __ CmpUleS(FTMP, rhs, lhs);
3557 } else {
3558 __ CmpLeS(FTMP, rhs, lhs);
3559 }
3560 __ Mfc1(dst, FTMP);
3561 __ Andi(dst, dst, 1);
3562 break;
3563 default:
3564 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
3565 UNREACHABLE();
3566 }
3567 } else {
3568 switch (cond) {
3569 case kCondEQ:
3570 __ CeqS(0, lhs, rhs);
3571 __ LoadConst32(dst, 1);
3572 __ Movf(dst, ZERO, 0);
3573 break;
3574 case kCondNE:
3575 __ CeqS(0, lhs, rhs);
3576 __ LoadConst32(dst, 1);
3577 __ Movt(dst, ZERO, 0);
3578 break;
3579 case kCondLT:
3580 if (gt_bias) {
3581 __ ColtS(0, lhs, rhs);
3582 } else {
3583 __ CultS(0, lhs, rhs);
3584 }
3585 __ LoadConst32(dst, 1);
3586 __ Movf(dst, ZERO, 0);
3587 break;
3588 case kCondLE:
3589 if (gt_bias) {
3590 __ ColeS(0, lhs, rhs);
3591 } else {
3592 __ CuleS(0, lhs, rhs);
3593 }
3594 __ LoadConst32(dst, 1);
3595 __ Movf(dst, ZERO, 0);
3596 break;
3597 case kCondGT:
3598 if (gt_bias) {
3599 __ CultS(0, rhs, lhs);
3600 } else {
3601 __ ColtS(0, rhs, lhs);
3602 }
3603 __ LoadConst32(dst, 1);
3604 __ Movf(dst, ZERO, 0);
3605 break;
3606 case kCondGE:
3607 if (gt_bias) {
3608 __ CuleS(0, rhs, lhs);
3609 } else {
3610 __ ColeS(0, rhs, lhs);
3611 }
3612 __ LoadConst32(dst, 1);
3613 __ Movf(dst, ZERO, 0);
3614 break;
3615 default:
3616 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
3617 UNREACHABLE();
3618 }
3619 }
3620 } else {
3621 DCHECK_EQ(type, Primitive::kPrimDouble);
3622 if (isR6) {
3623 switch (cond) {
3624 case kCondEQ:
3625 __ CmpEqD(FTMP, lhs, rhs);
3626 __ Mfc1(dst, FTMP);
3627 __ Andi(dst, dst, 1);
3628 break;
3629 case kCondNE:
3630 __ CmpEqD(FTMP, lhs, rhs);
3631 __ Mfc1(dst, FTMP);
3632 __ Addiu(dst, dst, 1);
3633 break;
3634 case kCondLT:
3635 if (gt_bias) {
3636 __ CmpLtD(FTMP, lhs, rhs);
3637 } else {
3638 __ CmpUltD(FTMP, lhs, rhs);
3639 }
3640 __ Mfc1(dst, FTMP);
3641 __ Andi(dst, dst, 1);
3642 break;
3643 case kCondLE:
3644 if (gt_bias) {
3645 __ CmpLeD(FTMP, lhs, rhs);
3646 } else {
3647 __ CmpUleD(FTMP, lhs, rhs);
3648 }
3649 __ Mfc1(dst, FTMP);
3650 __ Andi(dst, dst, 1);
3651 break;
3652 case kCondGT:
3653 if (gt_bias) {
3654 __ CmpUltD(FTMP, rhs, lhs);
3655 } else {
3656 __ CmpLtD(FTMP, rhs, lhs);
3657 }
3658 __ Mfc1(dst, FTMP);
3659 __ Andi(dst, dst, 1);
3660 break;
3661 case kCondGE:
3662 if (gt_bias) {
3663 __ CmpUleD(FTMP, rhs, lhs);
3664 } else {
3665 __ CmpLeD(FTMP, rhs, lhs);
3666 }
3667 __ Mfc1(dst, FTMP);
3668 __ Andi(dst, dst, 1);
3669 break;
3670 default:
3671 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
3672 UNREACHABLE();
3673 }
3674 } else {
3675 switch (cond) {
3676 case kCondEQ:
3677 __ CeqD(0, lhs, rhs);
3678 __ LoadConst32(dst, 1);
3679 __ Movf(dst, ZERO, 0);
3680 break;
3681 case kCondNE:
3682 __ CeqD(0, lhs, rhs);
3683 __ LoadConst32(dst, 1);
3684 __ Movt(dst, ZERO, 0);
3685 break;
3686 case kCondLT:
3687 if (gt_bias) {
3688 __ ColtD(0, lhs, rhs);
3689 } else {
3690 __ CultD(0, lhs, rhs);
3691 }
3692 __ LoadConst32(dst, 1);
3693 __ Movf(dst, ZERO, 0);
3694 break;
3695 case kCondLE:
3696 if (gt_bias) {
3697 __ ColeD(0, lhs, rhs);
3698 } else {
3699 __ CuleD(0, lhs, rhs);
3700 }
3701 __ LoadConst32(dst, 1);
3702 __ Movf(dst, ZERO, 0);
3703 break;
3704 case kCondGT:
3705 if (gt_bias) {
3706 __ CultD(0, rhs, lhs);
3707 } else {
3708 __ ColtD(0, rhs, lhs);
3709 }
3710 __ LoadConst32(dst, 1);
3711 __ Movf(dst, ZERO, 0);
3712 break;
3713 case kCondGE:
3714 if (gt_bias) {
3715 __ CuleD(0, rhs, lhs);
3716 } else {
3717 __ ColeD(0, rhs, lhs);
3718 }
3719 __ LoadConst32(dst, 1);
3720 __ Movf(dst, ZERO, 0);
3721 break;
3722 default:
3723 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
3724 UNREACHABLE();
3725 }
3726 }
3727 }
3728}
3729
Alexey Frunze674b9ee2016-09-20 14:54:15 -07003730bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond,
3731 bool gt_bias,
3732 Primitive::Type type,
3733 LocationSummary* input_locations,
3734 int cc) {
3735 FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>();
3736 FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>();
3737 CHECK(!codegen_->GetInstructionSetFeatures().IsR6());
3738 if (type == Primitive::kPrimFloat) {
3739 switch (cond) {
3740 case kCondEQ:
3741 __ CeqS(cc, lhs, rhs);
3742 return false;
3743 case kCondNE:
3744 __ CeqS(cc, lhs, rhs);
3745 return true;
3746 case kCondLT:
3747 if (gt_bias) {
3748 __ ColtS(cc, lhs, rhs);
3749 } else {
3750 __ CultS(cc, lhs, rhs);
3751 }
3752 return false;
3753 case kCondLE:
3754 if (gt_bias) {
3755 __ ColeS(cc, lhs, rhs);
3756 } else {
3757 __ CuleS(cc, lhs, rhs);
3758 }
3759 return false;
3760 case kCondGT:
3761 if (gt_bias) {
3762 __ CultS(cc, rhs, lhs);
3763 } else {
3764 __ ColtS(cc, rhs, lhs);
3765 }
3766 return false;
3767 case kCondGE:
3768 if (gt_bias) {
3769 __ CuleS(cc, rhs, lhs);
3770 } else {
3771 __ ColeS(cc, rhs, lhs);
3772 }
3773 return false;
3774 default:
3775 LOG(FATAL) << "Unexpected non-floating-point condition";
3776 UNREACHABLE();
3777 }
3778 } else {
3779 DCHECK_EQ(type, Primitive::kPrimDouble);
3780 switch (cond) {
3781 case kCondEQ:
3782 __ CeqD(cc, lhs, rhs);
3783 return false;
3784 case kCondNE:
3785 __ CeqD(cc, lhs, rhs);
3786 return true;
3787 case kCondLT:
3788 if (gt_bias) {
3789 __ ColtD(cc, lhs, rhs);
3790 } else {
3791 __ CultD(cc, lhs, rhs);
3792 }
3793 return false;
3794 case kCondLE:
3795 if (gt_bias) {
3796 __ ColeD(cc, lhs, rhs);
3797 } else {
3798 __ CuleD(cc, lhs, rhs);
3799 }
3800 return false;
3801 case kCondGT:
3802 if (gt_bias) {
3803 __ CultD(cc, rhs, lhs);
3804 } else {
3805 __ ColtD(cc, rhs, lhs);
3806 }
3807 return false;
3808 case kCondGE:
3809 if (gt_bias) {
3810 __ CuleD(cc, rhs, lhs);
3811 } else {
3812 __ ColeD(cc, rhs, lhs);
3813 }
3814 return false;
3815 default:
3816 LOG(FATAL) << "Unexpected non-floating-point condition";
3817 UNREACHABLE();
3818 }
3819 }
3820}
3821
3822bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond,
3823 bool gt_bias,
3824 Primitive::Type type,
3825 LocationSummary* input_locations,
3826 FRegister dst) {
3827 FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>();
3828 FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>();
3829 CHECK(codegen_->GetInstructionSetFeatures().IsR6());
3830 if (type == Primitive::kPrimFloat) {
3831 switch (cond) {
3832 case kCondEQ:
3833 __ CmpEqS(dst, lhs, rhs);
3834 return false;
3835 case kCondNE:
3836 __ CmpEqS(dst, lhs, rhs);
3837 return true;
3838 case kCondLT:
3839 if (gt_bias) {
3840 __ CmpLtS(dst, lhs, rhs);
3841 } else {
3842 __ CmpUltS(dst, lhs, rhs);
3843 }
3844 return false;
3845 case kCondLE:
3846 if (gt_bias) {
3847 __ CmpLeS(dst, lhs, rhs);
3848 } else {
3849 __ CmpUleS(dst, lhs, rhs);
3850 }
3851 return false;
3852 case kCondGT:
3853 if (gt_bias) {
3854 __ CmpUltS(dst, rhs, lhs);
3855 } else {
3856 __ CmpLtS(dst, rhs, lhs);
3857 }
3858 return false;
3859 case kCondGE:
3860 if (gt_bias) {
3861 __ CmpUleS(dst, rhs, lhs);
3862 } else {
3863 __ CmpLeS(dst, rhs, lhs);
3864 }
3865 return false;
3866 default:
3867 LOG(FATAL) << "Unexpected non-floating-point condition";
3868 UNREACHABLE();
3869 }
3870 } else {
3871 DCHECK_EQ(type, Primitive::kPrimDouble);
3872 switch (cond) {
3873 case kCondEQ:
3874 __ CmpEqD(dst, lhs, rhs);
3875 return false;
3876 case kCondNE:
3877 __ CmpEqD(dst, lhs, rhs);
3878 return true;
3879 case kCondLT:
3880 if (gt_bias) {
3881 __ CmpLtD(dst, lhs, rhs);
3882 } else {
3883 __ CmpUltD(dst, lhs, rhs);
3884 }
3885 return false;
3886 case kCondLE:
3887 if (gt_bias) {
3888 __ CmpLeD(dst, lhs, rhs);
3889 } else {
3890 __ CmpUleD(dst, lhs, rhs);
3891 }
3892 return false;
3893 case kCondGT:
3894 if (gt_bias) {
3895 __ CmpUltD(dst, rhs, lhs);
3896 } else {
3897 __ CmpLtD(dst, rhs, lhs);
3898 }
3899 return false;
3900 case kCondGE:
3901 if (gt_bias) {
3902 __ CmpUleD(dst, rhs, lhs);
3903 } else {
3904 __ CmpLeD(dst, rhs, lhs);
3905 }
3906 return false;
3907 default:
3908 LOG(FATAL) << "Unexpected non-floating-point condition";
3909 UNREACHABLE();
3910 }
3911 }
3912}
3913
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003914void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond,
3915 bool gt_bias,
3916 Primitive::Type type,
3917 LocationSummary* locations,
3918 MipsLabel* label) {
3919 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3920 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3921 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3922 if (type == Primitive::kPrimFloat) {
3923 if (isR6) {
3924 switch (cond) {
3925 case kCondEQ:
3926 __ CmpEqS(FTMP, lhs, rhs);
3927 __ Bc1nez(FTMP, label);
3928 break;
3929 case kCondNE:
3930 __ CmpEqS(FTMP, lhs, rhs);
3931 __ Bc1eqz(FTMP, label);
3932 break;
3933 case kCondLT:
3934 if (gt_bias) {
3935 __ CmpLtS(FTMP, lhs, rhs);
3936 } else {
3937 __ CmpUltS(FTMP, lhs, rhs);
3938 }
3939 __ Bc1nez(FTMP, label);
3940 break;
3941 case kCondLE:
3942 if (gt_bias) {
3943 __ CmpLeS(FTMP, lhs, rhs);
3944 } else {
3945 __ CmpUleS(FTMP, lhs, rhs);
3946 }
3947 __ Bc1nez(FTMP, label);
3948 break;
3949 case kCondGT:
3950 if (gt_bias) {
3951 __ CmpUltS(FTMP, rhs, lhs);
3952 } else {
3953 __ CmpLtS(FTMP, rhs, lhs);
3954 }
3955 __ Bc1nez(FTMP, label);
3956 break;
3957 case kCondGE:
3958 if (gt_bias) {
3959 __ CmpUleS(FTMP, rhs, lhs);
3960 } else {
3961 __ CmpLeS(FTMP, rhs, lhs);
3962 }
3963 __ Bc1nez(FTMP, label);
3964 break;
3965 default:
3966 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07003967 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003968 }
3969 } else {
3970 switch (cond) {
3971 case kCondEQ:
3972 __ CeqS(0, lhs, rhs);
3973 __ Bc1t(0, label);
3974 break;
3975 case kCondNE:
3976 __ CeqS(0, lhs, rhs);
3977 __ Bc1f(0, label);
3978 break;
3979 case kCondLT:
3980 if (gt_bias) {
3981 __ ColtS(0, lhs, rhs);
3982 } else {
3983 __ CultS(0, lhs, rhs);
3984 }
3985 __ Bc1t(0, label);
3986 break;
3987 case kCondLE:
3988 if (gt_bias) {
3989 __ ColeS(0, lhs, rhs);
3990 } else {
3991 __ CuleS(0, lhs, rhs);
3992 }
3993 __ Bc1t(0, label);
3994 break;
3995 case kCondGT:
3996 if (gt_bias) {
3997 __ CultS(0, rhs, lhs);
3998 } else {
3999 __ ColtS(0, rhs, lhs);
4000 }
4001 __ Bc1t(0, label);
4002 break;
4003 case kCondGE:
4004 if (gt_bias) {
4005 __ CuleS(0, rhs, lhs);
4006 } else {
4007 __ ColeS(0, rhs, lhs);
4008 }
4009 __ Bc1t(0, label);
4010 break;
4011 default:
4012 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07004013 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004014 }
4015 }
4016 } else {
4017 DCHECK_EQ(type, Primitive::kPrimDouble);
4018 if (isR6) {
4019 switch (cond) {
4020 case kCondEQ:
4021 __ CmpEqD(FTMP, lhs, rhs);
4022 __ Bc1nez(FTMP, label);
4023 break;
4024 case kCondNE:
4025 __ CmpEqD(FTMP, lhs, rhs);
4026 __ Bc1eqz(FTMP, label);
4027 break;
4028 case kCondLT:
4029 if (gt_bias) {
4030 __ CmpLtD(FTMP, lhs, rhs);
4031 } else {
4032 __ CmpUltD(FTMP, lhs, rhs);
4033 }
4034 __ Bc1nez(FTMP, label);
4035 break;
4036 case kCondLE:
4037 if (gt_bias) {
4038 __ CmpLeD(FTMP, lhs, rhs);
4039 } else {
4040 __ CmpUleD(FTMP, lhs, rhs);
4041 }
4042 __ Bc1nez(FTMP, label);
4043 break;
4044 case kCondGT:
4045 if (gt_bias) {
4046 __ CmpUltD(FTMP, rhs, lhs);
4047 } else {
4048 __ CmpLtD(FTMP, rhs, lhs);
4049 }
4050 __ Bc1nez(FTMP, label);
4051 break;
4052 case kCondGE:
4053 if (gt_bias) {
4054 __ CmpUleD(FTMP, rhs, lhs);
4055 } else {
4056 __ CmpLeD(FTMP, rhs, lhs);
4057 }
4058 __ Bc1nez(FTMP, label);
4059 break;
4060 default:
4061 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07004062 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004063 }
4064 } else {
4065 switch (cond) {
4066 case kCondEQ:
4067 __ CeqD(0, lhs, rhs);
4068 __ Bc1t(0, label);
4069 break;
4070 case kCondNE:
4071 __ CeqD(0, lhs, rhs);
4072 __ Bc1f(0, label);
4073 break;
4074 case kCondLT:
4075 if (gt_bias) {
4076 __ ColtD(0, lhs, rhs);
4077 } else {
4078 __ CultD(0, lhs, rhs);
4079 }
4080 __ Bc1t(0, label);
4081 break;
4082 case kCondLE:
4083 if (gt_bias) {
4084 __ ColeD(0, lhs, rhs);
4085 } else {
4086 __ CuleD(0, lhs, rhs);
4087 }
4088 __ Bc1t(0, label);
4089 break;
4090 case kCondGT:
4091 if (gt_bias) {
4092 __ CultD(0, rhs, lhs);
4093 } else {
4094 __ ColtD(0, rhs, lhs);
4095 }
4096 __ Bc1t(0, label);
4097 break;
4098 case kCondGE:
4099 if (gt_bias) {
4100 __ CuleD(0, rhs, lhs);
4101 } else {
4102 __ ColeD(0, rhs, lhs);
4103 }
4104 __ Bc1t(0, label);
4105 break;
4106 default:
4107 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07004108 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004109 }
4110 }
4111 }
4112}
4113
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004114void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00004115 size_t condition_input_index,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004116 MipsLabel* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00004117 MipsLabel* false_target) {
4118 HInstruction* cond = instruction->InputAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004119
David Brazdil0debae72015-11-12 18:37:00 +00004120 if (true_target == nullptr && false_target == nullptr) {
4121 // Nothing to do. The code always falls through.
4122 return;
4123 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00004124 // Constant condition, statically compared against "true" (integer value 1).
4125 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00004126 if (true_target != nullptr) {
4127 __ B(true_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004128 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004129 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00004130 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00004131 if (false_target != nullptr) {
4132 __ B(false_target);
4133 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004134 }
David Brazdil0debae72015-11-12 18:37:00 +00004135 return;
4136 }
4137
4138 // The following code generates these patterns:
4139 // (1) true_target == nullptr && false_target != nullptr
4140 // - opposite condition true => branch to false_target
4141 // (2) true_target != nullptr && false_target == nullptr
4142 // - condition true => branch to true_target
4143 // (3) true_target != nullptr && false_target != nullptr
4144 // - condition true => branch to true_target
4145 // - branch to false_target
4146 if (IsBooleanValueOrMaterializedCondition(cond)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004147 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00004148 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004149 DCHECK(cond_val.IsRegister());
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004150 if (true_target == nullptr) {
David Brazdil0debae72015-11-12 18:37:00 +00004151 __ Beqz(cond_val.AsRegister<Register>(), false_target);
4152 } else {
4153 __ Bnez(cond_val.AsRegister<Register>(), true_target);
4154 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004155 } else {
4156 // The condition instruction has not been materialized, use its inputs as
4157 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00004158 HCondition* condition = cond->AsCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004159 Primitive::Type type = condition->InputAt(0)->GetType();
4160 LocationSummary* locations = cond->GetLocations();
4161 IfCondition if_cond = condition->GetCondition();
4162 MipsLabel* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00004163
David Brazdil0debae72015-11-12 18:37:00 +00004164 if (true_target == nullptr) {
4165 if_cond = condition->GetOppositeCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004166 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00004167 }
4168
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004169 switch (type) {
4170 default:
4171 GenerateIntCompareAndBranch(if_cond, locations, branch_target);
4172 break;
4173 case Primitive::kPrimLong:
4174 GenerateLongCompareAndBranch(if_cond, locations, branch_target);
4175 break;
4176 case Primitive::kPrimFloat:
4177 case Primitive::kPrimDouble:
4178 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
4179 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004180 }
4181 }
David Brazdil0debae72015-11-12 18:37:00 +00004182
4183 // If neither branch falls through (case 3), the conditional branch to `true_target`
4184 // was already emitted (case 2) and we need to emit a jump to `false_target`.
4185 if (true_target != nullptr && false_target != nullptr) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004186 __ B(false_target);
4187 }
4188}
4189
4190void LocationsBuilderMIPS::VisitIf(HIf* if_instr) {
4191 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00004192 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004193 locations->SetInAt(0, Location::RequiresRegister());
4194 }
4195}
4196
4197void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00004198 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
4199 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
4200 MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
4201 nullptr : codegen_->GetLabelOf(true_successor);
4202 MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
4203 nullptr : codegen_->GetLabelOf(false_successor);
4204 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004205}
4206
4207void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
4208 LocationSummary* locations = new (GetGraph()->GetArena())
4209 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
Vladimir Marko804b03f2016-09-14 16:26:36 +01004210 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
David Brazdil0debae72015-11-12 18:37:00 +00004211 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004212 locations->SetInAt(0, Location::RequiresRegister());
4213 }
4214}
4215
4216void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08004217 SlowPathCodeMIPS* slow_path =
4218 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00004219 GenerateTestAndBranch(deoptimize,
4220 /* condition_input_index */ 0,
4221 slow_path->GetEntryLabel(),
4222 /* false_target */ nullptr);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004223}
4224
Alexey Frunze674b9ee2016-09-20 14:54:15 -07004225// This function returns true if a conditional move can be generated for HSelect.
4226// Otherwise it returns false and HSelect must be implemented in terms of conditonal
4227// branches and regular moves.
4228//
4229// If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect.
4230//
4231// While determining feasibility of a conditional move and setting inputs/outputs
4232// are two distinct tasks, this function does both because they share quite a bit
4233// of common logic.
4234static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) {
4235 bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition());
4236 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
4237 HCondition* condition = cond->AsCondition();
4238
4239 Primitive::Type cond_type = materialized ? Primitive::kPrimInt : condition->InputAt(0)->GetType();
4240 Primitive::Type dst_type = select->GetType();
4241
4242 HConstant* cst_true_value = select->GetTrueValue()->AsConstant();
4243 HConstant* cst_false_value = select->GetFalseValue()->AsConstant();
4244 bool is_true_value_zero_constant =
4245 (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern());
4246 bool is_false_value_zero_constant =
4247 (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern());
4248
4249 bool can_move_conditionally = false;
4250 bool use_const_for_false_in = false;
4251 bool use_const_for_true_in = false;
4252
4253 if (!cond->IsConstant()) {
4254 switch (cond_type) {
4255 default:
4256 switch (dst_type) {
4257 default:
4258 // Moving int on int condition.
4259 if (is_r6) {
4260 if (is_true_value_zero_constant) {
4261 // seleqz out_reg, false_reg, cond_reg
4262 can_move_conditionally = true;
4263 use_const_for_true_in = true;
4264 } else if (is_false_value_zero_constant) {
4265 // selnez out_reg, true_reg, cond_reg
4266 can_move_conditionally = true;
4267 use_const_for_false_in = true;
4268 } else if (materialized) {
4269 // Not materializing unmaterialized int conditions
4270 // to keep the instruction count low.
4271 // selnez AT, true_reg, cond_reg
4272 // seleqz TMP, false_reg, cond_reg
4273 // or out_reg, AT, TMP
4274 can_move_conditionally = true;
4275 }
4276 } else {
4277 // movn out_reg, true_reg/ZERO, cond_reg
4278 can_move_conditionally = true;
4279 use_const_for_true_in = is_true_value_zero_constant;
4280 }
4281 break;
4282 case Primitive::kPrimLong:
4283 // Moving long on int condition.
4284 if (is_r6) {
4285 if (is_true_value_zero_constant) {
4286 // seleqz out_reg_lo, false_reg_lo, cond_reg
4287 // seleqz out_reg_hi, false_reg_hi, cond_reg
4288 can_move_conditionally = true;
4289 use_const_for_true_in = true;
4290 } else if (is_false_value_zero_constant) {
4291 // selnez out_reg_lo, true_reg_lo, cond_reg
4292 // selnez out_reg_hi, true_reg_hi, cond_reg
4293 can_move_conditionally = true;
4294 use_const_for_false_in = true;
4295 }
4296 // Other long conditional moves would generate 6+ instructions,
4297 // which is too many.
4298 } else {
4299 // movn out_reg_lo, true_reg_lo/ZERO, cond_reg
4300 // movn out_reg_hi, true_reg_hi/ZERO, cond_reg
4301 can_move_conditionally = true;
4302 use_const_for_true_in = is_true_value_zero_constant;
4303 }
4304 break;
4305 case Primitive::kPrimFloat:
4306 case Primitive::kPrimDouble:
4307 // Moving float/double on int condition.
4308 if (is_r6) {
4309 if (materialized) {
4310 // Not materializing unmaterialized int conditions
4311 // to keep the instruction count low.
4312 can_move_conditionally = true;
4313 if (is_true_value_zero_constant) {
4314 // sltu TMP, ZERO, cond_reg
4315 // mtc1 TMP, temp_cond_reg
4316 // seleqz.fmt out_reg, false_reg, temp_cond_reg
4317 use_const_for_true_in = true;
4318 } else if (is_false_value_zero_constant) {
4319 // sltu TMP, ZERO, cond_reg
4320 // mtc1 TMP, temp_cond_reg
4321 // selnez.fmt out_reg, true_reg, temp_cond_reg
4322 use_const_for_false_in = true;
4323 } else {
4324 // sltu TMP, ZERO, cond_reg
4325 // mtc1 TMP, temp_cond_reg
4326 // sel.fmt temp_cond_reg, false_reg, true_reg
4327 // mov.fmt out_reg, temp_cond_reg
4328 }
4329 }
4330 } else {
4331 // movn.fmt out_reg, true_reg, cond_reg
4332 can_move_conditionally = true;
4333 }
4334 break;
4335 }
4336 break;
4337 case Primitive::kPrimLong:
4338 // We don't materialize long comparison now
4339 // and use conditional branches instead.
4340 break;
4341 case Primitive::kPrimFloat:
4342 case Primitive::kPrimDouble:
4343 switch (dst_type) {
4344 default:
4345 // Moving int on float/double condition.
4346 if (is_r6) {
4347 if (is_true_value_zero_constant) {
4348 // mfc1 TMP, temp_cond_reg
4349 // seleqz out_reg, false_reg, TMP
4350 can_move_conditionally = true;
4351 use_const_for_true_in = true;
4352 } else if (is_false_value_zero_constant) {
4353 // mfc1 TMP, temp_cond_reg
4354 // selnez out_reg, true_reg, TMP
4355 can_move_conditionally = true;
4356 use_const_for_false_in = true;
4357 } else {
4358 // mfc1 TMP, temp_cond_reg
4359 // selnez AT, true_reg, TMP
4360 // seleqz TMP, false_reg, TMP
4361 // or out_reg, AT, TMP
4362 can_move_conditionally = true;
4363 }
4364 } else {
4365 // movt out_reg, true_reg/ZERO, cc
4366 can_move_conditionally = true;
4367 use_const_for_true_in = is_true_value_zero_constant;
4368 }
4369 break;
4370 case Primitive::kPrimLong:
4371 // Moving long on float/double condition.
4372 if (is_r6) {
4373 if (is_true_value_zero_constant) {
4374 // mfc1 TMP, temp_cond_reg
4375 // seleqz out_reg_lo, false_reg_lo, TMP
4376 // seleqz out_reg_hi, false_reg_hi, TMP
4377 can_move_conditionally = true;
4378 use_const_for_true_in = true;
4379 } else if (is_false_value_zero_constant) {
4380 // mfc1 TMP, temp_cond_reg
4381 // selnez out_reg_lo, true_reg_lo, TMP
4382 // selnez out_reg_hi, true_reg_hi, TMP
4383 can_move_conditionally = true;
4384 use_const_for_false_in = true;
4385 }
4386 // Other long conditional moves would generate 6+ instructions,
4387 // which is too many.
4388 } else {
4389 // movt out_reg_lo, true_reg_lo/ZERO, cc
4390 // movt out_reg_hi, true_reg_hi/ZERO, cc
4391 can_move_conditionally = true;
4392 use_const_for_true_in = is_true_value_zero_constant;
4393 }
4394 break;
4395 case Primitive::kPrimFloat:
4396 case Primitive::kPrimDouble:
4397 // Moving float/double on float/double condition.
4398 if (is_r6) {
4399 can_move_conditionally = true;
4400 if (is_true_value_zero_constant) {
4401 // seleqz.fmt out_reg, false_reg, temp_cond_reg
4402 use_const_for_true_in = true;
4403 } else if (is_false_value_zero_constant) {
4404 // selnez.fmt out_reg, true_reg, temp_cond_reg
4405 use_const_for_false_in = true;
4406 } else {
4407 // sel.fmt temp_cond_reg, false_reg, true_reg
4408 // mov.fmt out_reg, temp_cond_reg
4409 }
4410 } else {
4411 // movt.fmt out_reg, true_reg, cc
4412 can_move_conditionally = true;
4413 }
4414 break;
4415 }
4416 break;
4417 }
4418 }
4419
4420 if (can_move_conditionally) {
4421 DCHECK(!use_const_for_false_in || !use_const_for_true_in);
4422 } else {
4423 DCHECK(!use_const_for_false_in);
4424 DCHECK(!use_const_for_true_in);
4425 }
4426
4427 if (locations_to_set != nullptr) {
4428 if (use_const_for_false_in) {
4429 locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value));
4430 } else {
4431 locations_to_set->SetInAt(0,
4432 Primitive::IsFloatingPointType(dst_type)
4433 ? Location::RequiresFpuRegister()
4434 : Location::RequiresRegister());
4435 }
4436 if (use_const_for_true_in) {
4437 locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value));
4438 } else {
4439 locations_to_set->SetInAt(1,
4440 Primitive::IsFloatingPointType(dst_type)
4441 ? Location::RequiresFpuRegister()
4442 : Location::RequiresRegister());
4443 }
4444 if (materialized) {
4445 locations_to_set->SetInAt(2, Location::RequiresRegister());
4446 }
4447 // On R6 we don't require the output to be the same as the
4448 // first input for conditional moves unlike on R2.
4449 bool is_out_same_as_first_in = !can_move_conditionally || !is_r6;
4450 if (is_out_same_as_first_in) {
4451 locations_to_set->SetOut(Location::SameAsFirstInput());
4452 } else {
4453 locations_to_set->SetOut(Primitive::IsFloatingPointType(dst_type)
4454 ? Location::RequiresFpuRegister()
4455 : Location::RequiresRegister());
4456 }
4457 }
4458
4459 return can_move_conditionally;
4460}
4461
4462void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) {
4463 LocationSummary* locations = select->GetLocations();
4464 Location dst = locations->Out();
4465 Location src = locations->InAt(1);
4466 Register src_reg = ZERO;
4467 Register src_reg_high = ZERO;
4468 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
4469 Register cond_reg = TMP;
4470 int cond_cc = 0;
4471 Primitive::Type cond_type = Primitive::kPrimInt;
4472 bool cond_inverted = false;
4473 Primitive::Type dst_type = select->GetType();
4474
4475 if (IsBooleanValueOrMaterializedCondition(cond)) {
4476 cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>();
4477 } else {
4478 HCondition* condition = cond->AsCondition();
4479 LocationSummary* cond_locations = cond->GetLocations();
4480 IfCondition if_cond = condition->GetCondition();
4481 cond_type = condition->InputAt(0)->GetType();
4482 switch (cond_type) {
4483 default:
4484 DCHECK_NE(cond_type, Primitive::kPrimLong);
4485 cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg);
4486 break;
4487 case Primitive::kPrimFloat:
4488 case Primitive::kPrimDouble:
4489 cond_inverted = MaterializeFpCompareR2(if_cond,
4490 condition->IsGtBias(),
4491 cond_type,
4492 cond_locations,
4493 cond_cc);
4494 break;
4495 }
4496 }
4497
4498 DCHECK(dst.Equals(locations->InAt(0)));
4499 if (src.IsRegister()) {
4500 src_reg = src.AsRegister<Register>();
4501 } else if (src.IsRegisterPair()) {
4502 src_reg = src.AsRegisterPairLow<Register>();
4503 src_reg_high = src.AsRegisterPairHigh<Register>();
4504 } else if (src.IsConstant()) {
4505 DCHECK(src.GetConstant()->IsZeroBitPattern());
4506 }
4507
4508 switch (cond_type) {
4509 default:
4510 switch (dst_type) {
4511 default:
4512 if (cond_inverted) {
4513 __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg);
4514 } else {
4515 __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg);
4516 }
4517 break;
4518 case Primitive::kPrimLong:
4519 if (cond_inverted) {
4520 __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg);
4521 __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg);
4522 } else {
4523 __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg);
4524 __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg);
4525 }
4526 break;
4527 case Primitive::kPrimFloat:
4528 if (cond_inverted) {
4529 __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
4530 } else {
4531 __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
4532 }
4533 break;
4534 case Primitive::kPrimDouble:
4535 if (cond_inverted) {
4536 __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
4537 } else {
4538 __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
4539 }
4540 break;
4541 }
4542 break;
4543 case Primitive::kPrimLong:
4544 LOG(FATAL) << "Unreachable";
4545 UNREACHABLE();
4546 case Primitive::kPrimFloat:
4547 case Primitive::kPrimDouble:
4548 switch (dst_type) {
4549 default:
4550 if (cond_inverted) {
4551 __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc);
4552 } else {
4553 __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc);
4554 }
4555 break;
4556 case Primitive::kPrimLong:
4557 if (cond_inverted) {
4558 __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc);
4559 __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc);
4560 } else {
4561 __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc);
4562 __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc);
4563 }
4564 break;
4565 case Primitive::kPrimFloat:
4566 if (cond_inverted) {
4567 __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
4568 } else {
4569 __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
4570 }
4571 break;
4572 case Primitive::kPrimDouble:
4573 if (cond_inverted) {
4574 __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
4575 } else {
4576 __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
4577 }
4578 break;
4579 }
4580 break;
4581 }
4582}
4583
4584void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) {
4585 LocationSummary* locations = select->GetLocations();
4586 Location dst = locations->Out();
4587 Location false_src = locations->InAt(0);
4588 Location true_src = locations->InAt(1);
4589 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
4590 Register cond_reg = TMP;
4591 FRegister fcond_reg = FTMP;
4592 Primitive::Type cond_type = Primitive::kPrimInt;
4593 bool cond_inverted = false;
4594 Primitive::Type dst_type = select->GetType();
4595
4596 if (IsBooleanValueOrMaterializedCondition(cond)) {
4597 cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>();
4598 } else {
4599 HCondition* condition = cond->AsCondition();
4600 LocationSummary* cond_locations = cond->GetLocations();
4601 IfCondition if_cond = condition->GetCondition();
4602 cond_type = condition->InputAt(0)->GetType();
4603 switch (cond_type) {
4604 default:
4605 DCHECK_NE(cond_type, Primitive::kPrimLong);
4606 cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg);
4607 break;
4608 case Primitive::kPrimFloat:
4609 case Primitive::kPrimDouble:
4610 cond_inverted = MaterializeFpCompareR6(if_cond,
4611 condition->IsGtBias(),
4612 cond_type,
4613 cond_locations,
4614 fcond_reg);
4615 break;
4616 }
4617 }
4618
4619 if (true_src.IsConstant()) {
4620 DCHECK(true_src.GetConstant()->IsZeroBitPattern());
4621 }
4622 if (false_src.IsConstant()) {
4623 DCHECK(false_src.GetConstant()->IsZeroBitPattern());
4624 }
4625
4626 switch (dst_type) {
4627 default:
4628 if (Primitive::IsFloatingPointType(cond_type)) {
4629 __ Mfc1(cond_reg, fcond_reg);
4630 }
4631 if (true_src.IsConstant()) {
4632 if (cond_inverted) {
4633 __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg);
4634 } else {
4635 __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg);
4636 }
4637 } else if (false_src.IsConstant()) {
4638 if (cond_inverted) {
4639 __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg);
4640 } else {
4641 __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg);
4642 }
4643 } else {
4644 DCHECK_NE(cond_reg, AT);
4645 if (cond_inverted) {
4646 __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg);
4647 __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg);
4648 } else {
4649 __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg);
4650 __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg);
4651 }
4652 __ Or(dst.AsRegister<Register>(), AT, TMP);
4653 }
4654 break;
4655 case Primitive::kPrimLong: {
4656 if (Primitive::IsFloatingPointType(cond_type)) {
4657 __ Mfc1(cond_reg, fcond_reg);
4658 }
4659 Register dst_lo = dst.AsRegisterPairLow<Register>();
4660 Register dst_hi = dst.AsRegisterPairHigh<Register>();
4661 if (true_src.IsConstant()) {
4662 Register src_lo = false_src.AsRegisterPairLow<Register>();
4663 Register src_hi = false_src.AsRegisterPairHigh<Register>();
4664 if (cond_inverted) {
4665 __ Selnez(dst_lo, src_lo, cond_reg);
4666 __ Selnez(dst_hi, src_hi, cond_reg);
4667 } else {
4668 __ Seleqz(dst_lo, src_lo, cond_reg);
4669 __ Seleqz(dst_hi, src_hi, cond_reg);
4670 }
4671 } else {
4672 DCHECK(false_src.IsConstant());
4673 Register src_lo = true_src.AsRegisterPairLow<Register>();
4674 Register src_hi = true_src.AsRegisterPairHigh<Register>();
4675 if (cond_inverted) {
4676 __ Seleqz(dst_lo, src_lo, cond_reg);
4677 __ Seleqz(dst_hi, src_hi, cond_reg);
4678 } else {
4679 __ Selnez(dst_lo, src_lo, cond_reg);
4680 __ Selnez(dst_hi, src_hi, cond_reg);
4681 }
4682 }
4683 break;
4684 }
4685 case Primitive::kPrimFloat: {
4686 if (!Primitive::IsFloatingPointType(cond_type)) {
4687 // sel*.fmt tests bit 0 of the condition register, account for that.
4688 __ Sltu(TMP, ZERO, cond_reg);
4689 __ Mtc1(TMP, fcond_reg);
4690 }
4691 FRegister dst_reg = dst.AsFpuRegister<FRegister>();
4692 if (true_src.IsConstant()) {
4693 FRegister src_reg = false_src.AsFpuRegister<FRegister>();
4694 if (cond_inverted) {
4695 __ SelnezS(dst_reg, src_reg, fcond_reg);
4696 } else {
4697 __ SeleqzS(dst_reg, src_reg, fcond_reg);
4698 }
4699 } else if (false_src.IsConstant()) {
4700 FRegister src_reg = true_src.AsFpuRegister<FRegister>();
4701 if (cond_inverted) {
4702 __ SeleqzS(dst_reg, src_reg, fcond_reg);
4703 } else {
4704 __ SelnezS(dst_reg, src_reg, fcond_reg);
4705 }
4706 } else {
4707 if (cond_inverted) {
4708 __ SelS(fcond_reg,
4709 true_src.AsFpuRegister<FRegister>(),
4710 false_src.AsFpuRegister<FRegister>());
4711 } else {
4712 __ SelS(fcond_reg,
4713 false_src.AsFpuRegister<FRegister>(),
4714 true_src.AsFpuRegister<FRegister>());
4715 }
4716 __ MovS(dst_reg, fcond_reg);
4717 }
4718 break;
4719 }
4720 case Primitive::kPrimDouble: {
4721 if (!Primitive::IsFloatingPointType(cond_type)) {
4722 // sel*.fmt tests bit 0 of the condition register, account for that.
4723 __ Sltu(TMP, ZERO, cond_reg);
4724 __ Mtc1(TMP, fcond_reg);
4725 }
4726 FRegister dst_reg = dst.AsFpuRegister<FRegister>();
4727 if (true_src.IsConstant()) {
4728 FRegister src_reg = false_src.AsFpuRegister<FRegister>();
4729 if (cond_inverted) {
4730 __ SelnezD(dst_reg, src_reg, fcond_reg);
4731 } else {
4732 __ SeleqzD(dst_reg, src_reg, fcond_reg);
4733 }
4734 } else if (false_src.IsConstant()) {
4735 FRegister src_reg = true_src.AsFpuRegister<FRegister>();
4736 if (cond_inverted) {
4737 __ SeleqzD(dst_reg, src_reg, fcond_reg);
4738 } else {
4739 __ SelnezD(dst_reg, src_reg, fcond_reg);
4740 }
4741 } else {
4742 if (cond_inverted) {
4743 __ SelD(fcond_reg,
4744 true_src.AsFpuRegister<FRegister>(),
4745 false_src.AsFpuRegister<FRegister>());
4746 } else {
4747 __ SelD(fcond_reg,
4748 false_src.AsFpuRegister<FRegister>(),
4749 true_src.AsFpuRegister<FRegister>());
4750 }
4751 __ MovD(dst_reg, fcond_reg);
4752 }
4753 break;
4754 }
4755 }
4756}
4757
Goran Jakovljevicc6418422016-12-05 16:31:55 +01004758void LocationsBuilderMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
4759 LocationSummary* locations = new (GetGraph()->GetArena())
4760 LocationSummary(flag, LocationSummary::kNoCall);
4761 locations->SetOut(Location::RequiresRegister());
Mingyao Yang063fc772016-08-02 11:02:54 -07004762}
4763
Goran Jakovljevicc6418422016-12-05 16:31:55 +01004764void InstructionCodeGeneratorMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
4765 __ LoadFromOffset(kLoadWord,
4766 flag->GetLocations()->Out().AsRegister<Register>(),
4767 SP,
4768 codegen_->GetStackOffsetOfShouldDeoptimizeFlag());
Mingyao Yang063fc772016-08-02 11:02:54 -07004769}
4770
David Brazdil74eb1b22015-12-14 11:44:01 +00004771void LocationsBuilderMIPS::VisitSelect(HSelect* select) {
4772 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07004773 CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations);
David Brazdil74eb1b22015-12-14 11:44:01 +00004774}
4775
4776void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07004777 bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6();
4778 if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) {
4779 if (is_r6) {
4780 GenConditionalMoveR6(select);
4781 } else {
4782 GenConditionalMoveR2(select);
4783 }
4784 } else {
4785 LocationSummary* locations = select->GetLocations();
4786 MipsLabel false_target;
4787 GenerateTestAndBranch(select,
4788 /* condition_input_index */ 2,
4789 /* true_target */ nullptr,
4790 &false_target);
4791 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
4792 __ Bind(&false_target);
4793 }
David Brazdil74eb1b22015-12-14 11:44:01 +00004794}
4795
David Srbecky0cf44932015-12-09 14:09:59 +00004796void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) {
4797 new (GetGraph()->GetArena()) LocationSummary(info);
4798}
4799
David Srbeckyd28f4a02016-03-14 17:14:24 +00004800void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) {
4801 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00004802}
4803
4804void CodeGeneratorMIPS::GenerateNop() {
4805 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00004806}
4807
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004808void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
4809 Primitive::Type field_type = field_info.GetFieldType();
4810 bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble);
4811 bool generate_volatile = field_info.IsVolatile() && is_wide;
4812 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004813 instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004814
4815 locations->SetInAt(0, Location::RequiresRegister());
4816 if (generate_volatile) {
4817 InvokeRuntimeCallingConvention calling_convention;
4818 // need A0 to hold base + offset
4819 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4820 if (field_type == Primitive::kPrimLong) {
4821 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimLong));
4822 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02004823 // Use Location::Any() to prevent situations when running out of available fp registers.
4824 locations->SetOut(Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004825 // Need some temp core regs since FP results are returned in core registers
4826 Location reg = calling_convention.GetReturnLocation(Primitive::kPrimLong);
4827 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>()));
4828 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>()));
4829 }
4830 } else {
4831 if (Primitive::IsFloatingPointType(instruction->GetType())) {
4832 locations->SetOut(Location::RequiresFpuRegister());
4833 } else {
4834 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4835 }
4836 }
4837}
4838
4839void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction,
4840 const FieldInfo& field_info,
4841 uint32_t dex_pc) {
4842 Primitive::Type type = field_info.GetFieldType();
4843 LocationSummary* locations = instruction->GetLocations();
4844 Register obj = locations->InAt(0).AsRegister<Register>();
4845 LoadOperandType load_type = kLoadUnsignedByte;
4846 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01004847 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Alexey Frunze2923db72016-08-20 01:55:47 -07004848 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004849
4850 switch (type) {
4851 case Primitive::kPrimBoolean:
4852 load_type = kLoadUnsignedByte;
4853 break;
4854 case Primitive::kPrimByte:
4855 load_type = kLoadSignedByte;
4856 break;
4857 case Primitive::kPrimShort:
4858 load_type = kLoadSignedHalfword;
4859 break;
4860 case Primitive::kPrimChar:
4861 load_type = kLoadUnsignedHalfword;
4862 break;
4863 case Primitive::kPrimInt:
4864 case Primitive::kPrimFloat:
4865 case Primitive::kPrimNot:
4866 load_type = kLoadWord;
4867 break;
4868 case Primitive::kPrimLong:
4869 case Primitive::kPrimDouble:
4870 load_type = kLoadDoubleword;
4871 break;
4872 case Primitive::kPrimVoid:
4873 LOG(FATAL) << "Unreachable type " << type;
4874 UNREACHABLE();
4875 }
4876
4877 if (is_volatile && load_type == kLoadDoubleword) {
4878 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01004879 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004880 // Do implicit Null check
4881 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
4882 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Serban Constantinescufca16662016-07-14 09:21:59 +01004883 codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004884 CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>();
4885 if (type == Primitive::kPrimDouble) {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02004886 // FP results are returned in core registers. Need to move them.
4887 Location out = locations->Out();
4888 if (out.IsFpuRegister()) {
4889 __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), out.AsFpuRegister<FRegister>());
4890 __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
4891 out.AsFpuRegister<FRegister>());
4892 } else {
4893 DCHECK(out.IsDoubleStackSlot());
4894 __ StoreToOffset(kStoreWord,
4895 locations->GetTemp(1).AsRegister<Register>(),
4896 SP,
4897 out.GetStackIndex());
4898 __ StoreToOffset(kStoreWord,
4899 locations->GetTemp(2).AsRegister<Register>(),
4900 SP,
4901 out.GetStackIndex() + 4);
4902 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004903 }
4904 } else {
4905 if (!Primitive::IsFloatingPointType(type)) {
4906 Register dst;
4907 if (type == Primitive::kPrimLong) {
4908 DCHECK(locations->Out().IsRegisterPair());
4909 dst = locations->Out().AsRegisterPairLow<Register>();
4910 } else {
4911 DCHECK(locations->Out().IsRegister());
4912 dst = locations->Out().AsRegister<Register>();
4913 }
Alexey Frunze2923db72016-08-20 01:55:47 -07004914 __ LoadFromOffset(load_type, dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004915 } else {
4916 DCHECK(locations->Out().IsFpuRegister());
4917 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4918 if (type == Primitive::kPrimFloat) {
Alexey Frunze2923db72016-08-20 01:55:47 -07004919 __ LoadSFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004920 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07004921 __ LoadDFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004922 }
4923 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004924 }
4925
4926 if (is_volatile) {
4927 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4928 }
4929}
4930
4931void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
4932 Primitive::Type field_type = field_info.GetFieldType();
4933 bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble);
4934 bool generate_volatile = field_info.IsVolatile() && is_wide;
4935 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004936 instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004937
4938 locations->SetInAt(0, Location::RequiresRegister());
4939 if (generate_volatile) {
4940 InvokeRuntimeCallingConvention calling_convention;
4941 // need A0 to hold base + offset
4942 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4943 if (field_type == Primitive::kPrimLong) {
4944 locations->SetInAt(1, Location::RegisterPairLocation(
4945 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
4946 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02004947 // Use Location::Any() to prevent situations when running out of available fp registers.
4948 locations->SetInAt(1, Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004949 // Pass FP parameters in core registers.
4950 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
4951 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
4952 }
4953 } else {
4954 if (Primitive::IsFloatingPointType(field_type)) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07004955 locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004956 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07004957 locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004958 }
4959 }
4960}
4961
4962void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction,
4963 const FieldInfo& field_info,
Goran Jakovljevice114da22016-12-26 14:21:43 +01004964 uint32_t dex_pc,
4965 bool value_can_be_null) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004966 Primitive::Type type = field_info.GetFieldType();
4967 LocationSummary* locations = instruction->GetLocations();
4968 Register obj = locations->InAt(0).AsRegister<Register>();
Alexey Frunzef58b2482016-09-02 22:14:06 -07004969 Location value_location = locations->InAt(1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004970 StoreOperandType store_type = kStoreByte;
4971 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01004972 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Alexey Frunze2923db72016-08-20 01:55:47 -07004973 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004974
4975 switch (type) {
4976 case Primitive::kPrimBoolean:
4977 case Primitive::kPrimByte:
4978 store_type = kStoreByte;
4979 break;
4980 case Primitive::kPrimShort:
4981 case Primitive::kPrimChar:
4982 store_type = kStoreHalfword;
4983 break;
4984 case Primitive::kPrimInt:
4985 case Primitive::kPrimFloat:
4986 case Primitive::kPrimNot:
4987 store_type = kStoreWord;
4988 break;
4989 case Primitive::kPrimLong:
4990 case Primitive::kPrimDouble:
4991 store_type = kStoreDoubleword;
4992 break;
4993 case Primitive::kPrimVoid:
4994 LOG(FATAL) << "Unreachable type " << type;
4995 UNREACHABLE();
4996 }
4997
4998 if (is_volatile) {
4999 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
5000 }
5001
5002 if (is_volatile && store_type == kStoreDoubleword) {
5003 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01005004 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005005 // Do implicit Null check.
5006 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
5007 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
5008 if (type == Primitive::kPrimDouble) {
5009 // Pass FP parameters in core registers.
Alexey Frunzef58b2482016-09-02 22:14:06 -07005010 if (value_location.IsFpuRegister()) {
5011 __ Mfc1(locations->GetTemp(1).AsRegister<Register>(),
5012 value_location.AsFpuRegister<FRegister>());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02005013 __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
Alexey Frunzef58b2482016-09-02 22:14:06 -07005014 value_location.AsFpuRegister<FRegister>());
5015 } else if (value_location.IsDoubleStackSlot()) {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02005016 __ LoadFromOffset(kLoadWord,
5017 locations->GetTemp(1).AsRegister<Register>(),
5018 SP,
Alexey Frunzef58b2482016-09-02 22:14:06 -07005019 value_location.GetStackIndex());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02005020 __ LoadFromOffset(kLoadWord,
5021 locations->GetTemp(2).AsRegister<Register>(),
5022 SP,
Alexey Frunzef58b2482016-09-02 22:14:06 -07005023 value_location.GetStackIndex() + 4);
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02005024 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07005025 DCHECK(value_location.IsConstant());
5026 DCHECK(value_location.GetConstant()->IsDoubleConstant());
5027 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02005028 __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(),
5029 locations->GetTemp(1).AsRegister<Register>(),
5030 value);
5031 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005032 }
Serban Constantinescufca16662016-07-14 09:21:59 +01005033 codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005034 CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>();
5035 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07005036 if (value_location.IsConstant()) {
5037 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
5038 __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker);
5039 } else if (!Primitive::IsFloatingPointType(type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005040 Register src;
5041 if (type == Primitive::kPrimLong) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07005042 src = value_location.AsRegisterPairLow<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005043 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07005044 src = value_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005045 }
Alexey Frunze2923db72016-08-20 01:55:47 -07005046 __ StoreToOffset(store_type, src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005047 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07005048 FRegister src = value_location.AsFpuRegister<FRegister>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005049 if (type == Primitive::kPrimFloat) {
Alexey Frunze2923db72016-08-20 01:55:47 -07005050 __ StoreSToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005051 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07005052 __ StoreDToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005053 }
5054 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005055 }
5056
5057 // TODO: memory barriers?
5058 if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07005059 Register src = value_location.AsRegister<Register>();
Goran Jakovljevice114da22016-12-26 14:21:43 +01005060 codegen_->MarkGCCard(obj, src, value_can_be_null);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005061 }
5062
5063 if (is_volatile) {
5064 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
5065 }
5066}
5067
5068void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
5069 HandleFieldGet(instruction, instruction->GetFieldInfo());
5070}
5071
5072void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
5073 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
5074}
5075
5076void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
5077 HandleFieldSet(instruction, instruction->GetFieldInfo());
5078}
5079
5080void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Goran Jakovljevice114da22016-12-26 14:21:43 +01005081 HandleFieldSet(instruction,
5082 instruction->GetFieldInfo(),
5083 instruction->GetDexPc(),
5084 instruction->GetValueCanBeNull());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005085}
5086
Alexey Frunze06a46c42016-07-19 15:00:40 -07005087void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(
5088 HInstruction* instruction ATTRIBUTE_UNUSED,
5089 Location root,
5090 Register obj,
5091 uint32_t offset) {
5092 Register root_reg = root.AsRegister<Register>();
5093 if (kEmitCompilerReadBarrier) {
5094 UNIMPLEMENTED(FATAL) << "for read barrier";
5095 } else {
5096 // Plain GC root load with no read barrier.
5097 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
5098 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
5099 // Note that GC roots are not affected by heap poisoning, thus we
5100 // do not have to unpoison `root_reg` here.
5101 }
5102}
5103
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005104void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) {
5105 LocationSummary::CallKind call_kind =
5106 instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
5107 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
5108 locations->SetInAt(0, Location::RequiresRegister());
5109 locations->SetInAt(1, Location::RequiresRegister());
5110 // The output does overlap inputs.
5111 // Note that TypeCheckSlowPathMIPS uses this register too.
5112 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
5113}
5114
5115void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) {
5116 LocationSummary* locations = instruction->GetLocations();
5117 Register obj = locations->InAt(0).AsRegister<Register>();
5118 Register cls = locations->InAt(1).AsRegister<Register>();
5119 Register out = locations->Out().AsRegister<Register>();
5120
5121 MipsLabel done;
5122
5123 // Return 0 if `obj` is null.
5124 // TODO: Avoid this check if we know `obj` is not null.
5125 __ Move(out, ZERO);
5126 __ Beqz(obj, &done);
5127
5128 // Compare the class of `obj` with `cls`.
5129 __ LoadFromOffset(kLoadWord, out, obj, mirror::Object::ClassOffset().Int32Value());
5130 if (instruction->IsExactCheck()) {
5131 // Classes must be equal for the instanceof to succeed.
5132 __ Xor(out, out, cls);
5133 __ Sltiu(out, out, 1);
5134 } else {
5135 // If the classes are not equal, we go into a slow path.
5136 DCHECK(locations->OnlyCallsOnSlowPath());
5137 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction);
5138 codegen_->AddSlowPath(slow_path);
5139 __ Bne(out, cls, slow_path->GetEntryLabel());
5140 __ LoadConst32(out, 1);
5141 __ Bind(slow_path->GetExitLabel());
5142 }
5143
5144 __ Bind(&done);
5145}
5146
5147void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) {
5148 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
5149 locations->SetOut(Location::ConstantLocation(constant));
5150}
5151
5152void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
5153 // Will be generated at use site.
5154}
5155
5156void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) {
5157 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
5158 locations->SetOut(Location::ConstantLocation(constant));
5159}
5160
5161void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
5162 // Will be generated at use site.
5163}
5164
5165void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) {
5166 InvokeDexCallingConventionVisitorMIPS calling_convention_visitor;
5167 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
5168}
5169
5170void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
5171 HandleInvoke(invoke);
Alexey Frunze1b8464d2016-11-12 17:22:05 -08005172 // The register T7 is required to be used for the hidden argument in
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005173 // art_quick_imt_conflict_trampoline, so add the hidden argument.
Alexey Frunze1b8464d2016-11-12 17:22:05 -08005174 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T7));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005175}
5176
5177void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
5178 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
5179 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005180 Location receiver = invoke->GetLocations()->InAt(0);
5181 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07005182 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005183
5184 // Set the hidden argument.
5185 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
5186 invoke->GetDexMethodIndex());
5187
5188 // temp = object->GetClass();
5189 if (receiver.IsStackSlot()) {
5190 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
5191 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
5192 } else {
5193 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
5194 }
5195 codegen_->MaybeRecordImplicitNullCheck(invoke);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00005196 __ LoadFromOffset(kLoadWord, temp, temp,
5197 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
5198 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00005199 invoke->GetImtIndex(), kMipsPointerSize));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005200 // temp = temp->GetImtEntryAt(method_offset);
5201 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
5202 // T9 = temp->GetEntryPoint();
5203 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
5204 // T9();
5205 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005206 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005207 DCHECK(!codegen_->IsLeafMethod());
5208 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
5209}
5210
5211void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen701566a2015-10-27 15:29:13 -07005212 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
5213 if (intrinsic.TryDispatch(invoke)) {
5214 return;
5215 }
5216
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005217 HandleInvoke(invoke);
5218}
5219
5220void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00005221 // Explicit clinit checks triggered by static invokes must have been pruned by
5222 // art::PrepareForRegisterAllocation.
5223 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005224
Alexey Frunze6b892cd2017-01-03 17:11:38 -08005225 bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6();
5226 bool has_extra_input = invoke->HasPcRelativeDexCache() && !is_r6;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005227
Chris Larsen701566a2015-10-27 15:29:13 -07005228 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
5229 if (intrinsic.TryDispatch(invoke)) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005230 if (invoke->GetLocations()->CanCall() && has_extra_input) {
5231 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
5232 }
Chris Larsen701566a2015-10-27 15:29:13 -07005233 return;
5234 }
5235
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005236 HandleInvoke(invoke);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005237
5238 // Add the extra input register if either the dex cache array base register
5239 // or the PC-relative base register for accessing literals is needed.
5240 if (has_extra_input) {
5241 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
5242 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005243}
5244
Orion Hodsonac141392017-01-13 11:53:47 +00005245void LocationsBuilderMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
5246 HandleInvoke(invoke);
5247}
5248
5249void InstructionCodeGeneratorMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
5250 codegen_->GenerateInvokePolymorphicCall(invoke);
5251}
5252
Chris Larsen701566a2015-10-27 15:29:13 -07005253static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005254 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen701566a2015-10-27 15:29:13 -07005255 IntrinsicCodeGeneratorMIPS intrinsic(codegen);
5256 intrinsic.Dispatch(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005257 return true;
5258 }
5259 return false;
5260}
5261
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005262HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind(
Alexey Frunze06a46c42016-07-19 15:00:40 -07005263 HLoadString::LoadKind desired_string_load_kind) {
5264 if (kEmitCompilerReadBarrier) {
5265 UNIMPLEMENTED(FATAL) << "for read barrier";
5266 }
Alexey Frunze6b892cd2017-01-03 17:11:38 -08005267 // We disable PC-relative load on pre-R6 when there is an irreducible loop, as the optimization
Alexey Frunze06a46c42016-07-19 15:00:40 -07005268 // is incompatible with it.
Vladimir Markoaad75c62016-10-03 08:46:48 +00005269 // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods
5270 // with irreducible loops.
Alexey Frunze06a46c42016-07-19 15:00:40 -07005271 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
Alexey Frunze6b892cd2017-01-03 17:11:38 -08005272 bool is_r6 = GetInstructionSetFeatures().IsR6();
5273 bool fallback_load = has_irreducible_loops && !is_r6;
Alexey Frunze06a46c42016-07-19 15:00:40 -07005274 switch (desired_string_load_kind) {
5275 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5276 DCHECK(!GetCompilerOptions().GetCompilePic());
5277 break;
5278 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5279 DCHECK(GetCompilerOptions().GetCompilePic());
5280 break;
5281 case HLoadString::LoadKind::kBootImageAddress:
5282 break;
Vladimir Markoaad75c62016-10-03 08:46:48 +00005283 case HLoadString::LoadKind::kBssEntry:
Alexey Frunze06a46c42016-07-19 15:00:40 -07005284 DCHECK(!Runtime::Current()->UseJitCompilation());
Alexey Frunze06a46c42016-07-19 15:00:40 -07005285 break;
Nicolas Geoffray132d8362016-11-16 09:19:42 +00005286 case HLoadString::LoadKind::kJitTableAddress:
5287 DCHECK(Runtime::Current()->UseJitCompilation());
Alexey Frunze627c1a02017-01-30 19:28:14 -08005288 fallback_load = false;
Nicolas Geoffray132d8362016-11-16 09:19:42 +00005289 break;
Vladimir Marko6bec91c2017-01-09 15:03:12 +00005290 case HLoadString::LoadKind::kDexCacheViaMethod:
5291 fallback_load = false;
5292 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07005293 }
5294 if (fallback_load) {
5295 desired_string_load_kind = HLoadString::LoadKind::kDexCacheViaMethod;
5296 }
5297 return desired_string_load_kind;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005298}
5299
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005300HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind(
5301 HLoadClass::LoadKind desired_class_load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07005302 if (kEmitCompilerReadBarrier) {
5303 UNIMPLEMENTED(FATAL) << "for read barrier";
5304 }
Alexey Frunze6b892cd2017-01-03 17:11:38 -08005305 // We disable PC-relative load on pre-R6 when there is an irreducible loop, as the optimization
Alexey Frunze06a46c42016-07-19 15:00:40 -07005306 // is incompatible with it.
5307 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
Alexey Frunze6b892cd2017-01-03 17:11:38 -08005308 bool is_r6 = GetInstructionSetFeatures().IsR6();
5309 bool fallback_load = has_irreducible_loops && !is_r6;
Alexey Frunze06a46c42016-07-19 15:00:40 -07005310 switch (desired_class_load_kind) {
Nicolas Geoffray83c8e272017-01-31 14:36:37 +00005311 case HLoadClass::LoadKind::kInvalid:
5312 LOG(FATAL) << "UNREACHABLE";
5313 UNREACHABLE();
Alexey Frunze06a46c42016-07-19 15:00:40 -07005314 case HLoadClass::LoadKind::kReferrersClass:
5315 fallback_load = false;
5316 break;
5317 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5318 DCHECK(!GetCompilerOptions().GetCompilePic());
5319 break;
5320 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5321 DCHECK(GetCompilerOptions().GetCompilePic());
5322 break;
5323 case HLoadClass::LoadKind::kBootImageAddress:
5324 break;
Vladimir Marko6bec91c2017-01-09 15:03:12 +00005325 case HLoadClass::LoadKind::kBssEntry:
5326 DCHECK(!Runtime::Current()->UseJitCompilation());
5327 break;
Nicolas Geoffray22384ae2016-12-12 22:33:36 +00005328 case HLoadClass::LoadKind::kJitTableAddress:
Alexey Frunze06a46c42016-07-19 15:00:40 -07005329 DCHECK(Runtime::Current()->UseJitCompilation());
Alexey Frunze627c1a02017-01-30 19:28:14 -08005330 fallback_load = false;
Alexey Frunze06a46c42016-07-19 15:00:40 -07005331 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07005332 case HLoadClass::LoadKind::kDexCacheViaMethod:
5333 fallback_load = false;
5334 break;
5335 }
5336 if (fallback_load) {
5337 desired_class_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod;
5338 }
5339 return desired_class_load_kind;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005340}
5341
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005342Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
5343 Register temp) {
Alexey Frunze6b892cd2017-01-03 17:11:38 -08005344 CHECK(!GetInstructionSetFeatures().IsR6());
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005345 CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
5346 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
5347 if (!invoke->GetLocations()->Intrinsified()) {
5348 return location.AsRegister<Register>();
5349 }
5350 // For intrinsics we allow any location, so it may be on the stack.
5351 if (!location.IsRegister()) {
5352 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
5353 return temp;
5354 }
5355 // For register locations, check if the register was saved. If so, get it from the stack.
5356 // Note: There is a chance that the register was saved but not overwritten, so we could
5357 // save one load. However, since this is just an intrinsic slow path we prefer this
5358 // simple and more robust approach rather that trying to determine if that's the case.
5359 SlowPathCode* slow_path = GetCurrentSlowPath();
5360 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
5361 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
5362 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
5363 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
5364 return temp;
5365 }
5366 return location.AsRegister<Register>();
5367}
5368
Vladimir Markodc151b22015-10-15 18:02:30 +01005369HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch(
5370 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +01005371 HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005372 HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info;
Alexey Frunze6b892cd2017-01-03 17:11:38 -08005373 // We disable PC-relative load on pre-R6 when there is an irreducible loop, as the optimization
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005374 // is incompatible with it.
5375 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
Alexey Frunze6b892cd2017-01-03 17:11:38 -08005376 bool is_r6 = GetInstructionSetFeatures().IsR6();
5377 bool fallback_load = has_irreducible_loops && !is_r6;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005378 switch (dispatch_info.method_load_kind) {
Vladimir Markodc151b22015-10-15 18:02:30 +01005379 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005380 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01005381 default:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005382 fallback_load = false;
Vladimir Markodc151b22015-10-15 18:02:30 +01005383 break;
5384 }
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005385 if (fallback_load) {
5386 dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
5387 dispatch_info.method_load_data = 0;
5388 }
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005389 return dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01005390}
5391
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005392void CodeGeneratorMIPS::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
5393 // All registers are assumed to be correctly set up per the calling convention.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005394 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005395 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
5396 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
Alexey Frunze6b892cd2017-01-03 17:11:38 -08005397 bool is_r6 = GetInstructionSetFeatures().IsR6();
5398 Register base_reg = (invoke->HasPcRelativeDexCache() && !is_r6)
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005399 ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>())
5400 : ZERO;
5401
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005402 switch (method_load_kind) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01005403 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005404 // temp = thread->string_init_entrypoint
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01005405 uint32_t offset =
5406 GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005407 __ LoadFromOffset(kLoadWord,
5408 temp.AsRegister<Register>(),
5409 TR,
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01005410 offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005411 break;
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01005412 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005413 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00005414 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005415 break;
5416 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
5417 __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress());
5418 break;
Alexey Frunze6b892cd2017-01-03 17:11:38 -08005419 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
5420 if (is_r6) {
5421 uint32_t offset = invoke->GetDexCacheArrayOffset();
5422 CodeGeneratorMIPS::PcRelativePatchInfo* info =
5423 NewPcRelativeDexCacheArrayPatch(invoke->GetDexFileForPcRelativeDexCache(), offset);
5424 bool reordering = __ SetReorder(false);
5425 EmitPcRelativeAddressPlaceholderHigh(info, TMP, ZERO);
5426 __ Lw(temp.AsRegister<Register>(), TMP, /* placeholder */ 0x5678);
5427 __ SetReorder(reordering);
5428 } else {
5429 HMipsDexCacheArraysBase* base =
5430 invoke->InputAt(invoke->GetSpecialInputIndex())->AsMipsDexCacheArraysBase();
5431 int32_t offset =
5432 invoke->GetDexCacheArrayOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset;
5433 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset);
5434 }
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005435 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005436 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00005437 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005438 Register reg = temp.AsRegister<Register>();
5439 Register method_reg;
5440 if (current_method.IsRegister()) {
5441 method_reg = current_method.AsRegister<Register>();
5442 } else {
5443 // TODO: use the appropriate DCHECK() here if possible.
5444 // DCHECK(invoke->GetLocations()->Intrinsified());
5445 DCHECK(!current_method.IsValid());
5446 method_reg = reg;
5447 __ Lw(reg, SP, kCurrentMethodStackOffset);
5448 }
5449
5450 // temp = temp->dex_cache_resolved_methods_;
5451 __ LoadFromOffset(kLoadWord,
5452 reg,
5453 method_reg,
5454 ArtMethod::DexCacheResolvedMethodsOffset(kMipsPointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01005455 // temp = temp[index_in_cache];
5456 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
5457 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005458 __ LoadFromOffset(kLoadWord,
5459 reg,
5460 reg,
5461 CodeGenerator::GetCachePointerOffset(index_in_cache));
5462 break;
5463 }
5464 }
5465
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005466 switch (code_ptr_location) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005467 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005468 __ Bal(&frame_entry_label_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005469 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005470 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
5471 // T9 = callee_method->entry_point_from_quick_compiled_code_;
Goran Jakovljevic1a878372015-10-26 14:28:52 +01005472 __ LoadFromOffset(kLoadWord,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005473 T9,
5474 callee_method.AsRegister<Register>(),
5475 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07005476 kMipsPointerSize).Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005477 // T9()
5478 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005479 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005480 break;
5481 }
5482 DCHECK(!IsLeafMethod());
5483}
5484
5485void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00005486 // Explicit clinit checks triggered by static invokes must have been pruned by
5487 // art::PrepareForRegisterAllocation.
5488 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005489
5490 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
5491 return;
5492 }
5493
5494 LocationSummary* locations = invoke->GetLocations();
5495 codegen_->GenerateStaticOrDirectCall(invoke,
5496 locations->HasTemps()
5497 ? locations->GetTemp(0)
5498 : Location::NoLocation());
5499 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
5500}
5501
Chris Larsen3acee732015-11-18 13:31:08 -08005502void CodeGeneratorMIPS::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
Goran Jakovljevice919b072016-10-04 10:17:34 +02005503 // Use the calling convention instead of the location of the receiver, as
5504 // intrinsics may have put the receiver in a different register. In the intrinsics
5505 // slow path, the arguments have been moved to the right place, so here we are
5506 // guaranteed that the receiver is the first register of the calling convention.
5507 InvokeDexCallingConvention calling_convention;
5508 Register receiver = calling_convention.GetRegisterAt(0);
5509
Chris Larsen3acee732015-11-18 13:31:08 -08005510 Register temp = temp_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005511 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
5512 invoke->GetVTableIndex(), kMipsPointerSize).SizeValue();
5513 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07005514 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005515
5516 // temp = object->GetClass();
Goran Jakovljevice919b072016-10-04 10:17:34 +02005517 __ LoadFromOffset(kLoadWord, temp, receiver, class_offset);
Chris Larsen3acee732015-11-18 13:31:08 -08005518 MaybeRecordImplicitNullCheck(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005519 // temp = temp->GetMethodAt(method_offset);
5520 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
5521 // T9 = temp->GetEntryPoint();
5522 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
5523 // T9();
5524 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005525 __ NopIfNoReordering();
Chris Larsen3acee732015-11-18 13:31:08 -08005526}
5527
5528void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
5529 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
5530 return;
5531 }
5532
5533 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005534 DCHECK(!codegen_->IsLeafMethod());
5535 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
5536}
5537
5538void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) {
Vladimir Marko41559982017-01-06 14:04:23 +00005539 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
5540 if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07005541 InvokeRuntimeCallingConvention calling_convention;
Vladimir Marko41559982017-01-06 14:04:23 +00005542 CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(
Alexey Frunze06a46c42016-07-19 15:00:40 -07005543 cls,
5544 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko41559982017-01-06 14:04:23 +00005545 Location::RegisterLocation(V0));
Alexey Frunze06a46c42016-07-19 15:00:40 -07005546 return;
5547 }
Vladimir Marko41559982017-01-06 14:04:23 +00005548 DCHECK(!cls->NeedsAccessCheck());
Alexey Frunze06a46c42016-07-19 15:00:40 -07005549
5550 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier)
5551 ? LocationSummary::kCallOnSlowPath
5552 : LocationSummary::kNoCall;
5553 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Alexey Frunze06a46c42016-07-19 15:00:40 -07005554 switch (load_kind) {
5555 // We need an extra register for PC-relative literals on R2.
5556 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
Alexey Frunze06a46c42016-07-19 15:00:40 -07005557 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00005558 case HLoadClass::LoadKind::kBootImageAddress:
5559 case HLoadClass::LoadKind::kBssEntry:
Alexey Frunze06a46c42016-07-19 15:00:40 -07005560 if (codegen_->GetInstructionSetFeatures().IsR6()) {
5561 break;
5562 }
5563 FALLTHROUGH_INTENDED;
Alexey Frunze06a46c42016-07-19 15:00:40 -07005564 case HLoadClass::LoadKind::kReferrersClass:
Alexey Frunze06a46c42016-07-19 15:00:40 -07005565 locations->SetInAt(0, Location::RequiresRegister());
5566 break;
5567 default:
5568 break;
5569 }
5570 locations->SetOut(Location::RequiresRegister());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005571}
5572
Nicolas Geoffray5247c082017-01-13 14:17:29 +00005573// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
5574// move.
5575void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS {
Vladimir Marko41559982017-01-06 14:04:23 +00005576 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
5577 if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) {
5578 codegen_->GenerateLoadClassRuntimeCall(cls);
Pavle Batutae87a7182015-10-28 13:10:42 +01005579 return;
5580 }
Vladimir Marko41559982017-01-06 14:04:23 +00005581 DCHECK(!cls->NeedsAccessCheck());
Pavle Batutae87a7182015-10-28 13:10:42 +01005582
Vladimir Marko41559982017-01-06 14:04:23 +00005583 LocationSummary* locations = cls->GetLocations();
Alexey Frunze06a46c42016-07-19 15:00:40 -07005584 Location out_loc = locations->Out();
5585 Register out = out_loc.AsRegister<Register>();
5586 Register base_or_current_method_reg;
5587 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
5588 switch (load_kind) {
5589 // We need an extra register for PC-relative literals on R2.
5590 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
Alexey Frunze06a46c42016-07-19 15:00:40 -07005591 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00005592 case HLoadClass::LoadKind::kBootImageAddress:
5593 case HLoadClass::LoadKind::kBssEntry:
Alexey Frunze06a46c42016-07-19 15:00:40 -07005594 base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>();
5595 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07005596 case HLoadClass::LoadKind::kReferrersClass:
5597 case HLoadClass::LoadKind::kDexCacheViaMethod:
5598 base_or_current_method_reg = locations->InAt(0).AsRegister<Register>();
5599 break;
5600 default:
5601 base_or_current_method_reg = ZERO;
5602 break;
5603 }
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00005604
Alexey Frunze06a46c42016-07-19 15:00:40 -07005605 bool generate_null_check = false;
5606 switch (load_kind) {
5607 case HLoadClass::LoadKind::kReferrersClass: {
5608 DCHECK(!cls->CanCallRuntime());
5609 DCHECK(!cls->MustGenerateClinitCheck());
5610 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
5611 GenerateGcRootFieldLoad(cls,
5612 out_loc,
5613 base_or_current_method_reg,
5614 ArtMethod::DeclaringClassOffset().Int32Value());
5615 break;
5616 }
5617 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00005618 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze06a46c42016-07-19 15:00:40 -07005619 __ LoadLiteral(out,
5620 base_or_current_method_reg,
5621 codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
5622 cls->GetTypeIndex()));
5623 break;
5624 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Marko6bec91c2017-01-09 15:03:12 +00005625 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze06a46c42016-07-19 15:00:40 -07005626 CodeGeneratorMIPS::PcRelativePatchInfo* info =
5627 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze6b892cd2017-01-03 17:11:38 -08005628 bool reordering = __ SetReorder(false);
5629 codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out, base_or_current_method_reg);
5630 __ Addiu(out, out, /* placeholder */ 0x5678);
5631 __ SetReorder(reordering);
Alexey Frunze06a46c42016-07-19 15:00:40 -07005632 break;
5633 }
5634 case HLoadClass::LoadKind::kBootImageAddress: {
5635 DCHECK(!kEmitCompilerReadBarrier);
Nicolas Geoffray5247c082017-01-13 14:17:29 +00005636 uint32_t address = dchecked_integral_cast<uint32_t>(
5637 reinterpret_cast<uintptr_t>(cls->GetClass().Get()));
5638 DCHECK_NE(address, 0u);
Alexey Frunze06a46c42016-07-19 15:00:40 -07005639 __ LoadLiteral(out,
5640 base_or_current_method_reg,
5641 codegen_->DeduplicateBootImageAddressLiteral(address));
5642 break;
5643 }
Vladimir Marko6bec91c2017-01-09 15:03:12 +00005644 case HLoadClass::LoadKind::kBssEntry: {
Vladimir Marko6bec91c2017-01-09 15:03:12 +00005645 CodeGeneratorMIPS::PcRelativePatchInfo* info =
Vladimir Marko1998cd02017-01-13 13:02:58 +00005646 codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze6b892cd2017-01-03 17:11:38 -08005647 bool reordering = __ SetReorder(false);
5648 codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out, base_or_current_method_reg);
5649 __ LoadFromOffset(kLoadWord, out, out, /* placeholder */ 0x5678);
5650 __ SetReorder(reordering);
Vladimir Marko6bec91c2017-01-09 15:03:12 +00005651 generate_null_check = true;
5652 break;
5653 }
Nicolas Geoffray22384ae2016-12-12 22:33:36 +00005654 case HLoadClass::LoadKind::kJitTableAddress: {
Alexey Frunze627c1a02017-01-30 19:28:14 -08005655 CodeGeneratorMIPS::JitPatchInfo* info = codegen_->NewJitRootClassPatch(cls->GetDexFile(),
5656 cls->GetTypeIndex(),
5657 cls->GetClass());
5658 bool reordering = __ SetReorder(false);
5659 __ Bind(&info->high_label);
5660 __ Lui(out, /* placeholder */ 0x1234);
5661 GenerateGcRootFieldLoad(cls, out_loc, out, /* placeholder */ 0x5678);
5662 __ SetReorder(reordering);
Alexey Frunze06a46c42016-07-19 15:00:40 -07005663 break;
5664 }
Vladimir Marko41559982017-01-06 14:04:23 +00005665 case HLoadClass::LoadKind::kDexCacheViaMethod:
Nicolas Geoffray83c8e272017-01-31 14:36:37 +00005666 case HLoadClass::LoadKind::kInvalid:
Vladimir Marko41559982017-01-06 14:04:23 +00005667 LOG(FATAL) << "UNREACHABLE";
5668 UNREACHABLE();
Alexey Frunze06a46c42016-07-19 15:00:40 -07005669 }
5670
5671 if (generate_null_check || cls->MustGenerateClinitCheck()) {
5672 DCHECK(cls->CanCallRuntime());
5673 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS(
5674 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
5675 codegen_->AddSlowPath(slow_path);
5676 if (generate_null_check) {
5677 __ Beqz(out, slow_path->GetEntryLabel());
5678 }
5679 if (cls->MustGenerateClinitCheck()) {
5680 GenerateClassInitializationCheck(slow_path, out);
5681 } else {
5682 __ Bind(slow_path->GetExitLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005683 }
5684 }
5685}
5686
5687static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07005688 return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005689}
5690
5691void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) {
5692 LocationSummary* locations =
5693 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
5694 locations->SetOut(Location::RequiresRegister());
5695}
5696
5697void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) {
5698 Register out = load->GetLocations()->Out().AsRegister<Register>();
5699 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
5700}
5701
5702void LocationsBuilderMIPS::VisitClearException(HClearException* clear) {
5703 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
5704}
5705
5706void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
5707 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
5708}
5709
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005710void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08005711 LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load);
Nicolas Geoffray917d0162015-11-24 18:25:35 +00005712 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Alexey Frunze06a46c42016-07-19 15:00:40 -07005713 HLoadString::LoadKind load_kind = load->GetLoadKind();
5714 switch (load_kind) {
5715 // We need an extra register for PC-relative literals on R2.
5716 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5717 case HLoadString::LoadKind::kBootImageAddress:
5718 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Markoaad75c62016-10-03 08:46:48 +00005719 case HLoadString::LoadKind::kBssEntry:
Alexey Frunze06a46c42016-07-19 15:00:40 -07005720 if (codegen_->GetInstructionSetFeatures().IsR6()) {
5721 break;
5722 }
5723 FALLTHROUGH_INTENDED;
5724 // We need an extra register for PC-relative dex cache accesses.
Alexey Frunze06a46c42016-07-19 15:00:40 -07005725 case HLoadString::LoadKind::kDexCacheViaMethod:
5726 locations->SetInAt(0, Location::RequiresRegister());
5727 break;
5728 default:
5729 break;
5730 }
Alexey Frunzebb51df82016-11-01 16:07:32 -07005731 if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) {
5732 InvokeRuntimeCallingConvention calling_convention;
5733 locations->SetOut(calling_convention.GetReturnLocation(load->GetType()));
5734 } else {
5735 locations->SetOut(Location::RequiresRegister());
5736 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005737}
5738
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00005739// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
5740// move.
5741void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS {
Alexey Frunze06a46c42016-07-19 15:00:40 -07005742 HLoadString::LoadKind load_kind = load->GetLoadKind();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005743 LocationSummary* locations = load->GetLocations();
Alexey Frunze06a46c42016-07-19 15:00:40 -07005744 Location out_loc = locations->Out();
5745 Register out = out_loc.AsRegister<Register>();
5746 Register base_or_current_method_reg;
5747 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
5748 switch (load_kind) {
5749 // We need an extra register for PC-relative literals on R2.
5750 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5751 case HLoadString::LoadKind::kBootImageAddress:
5752 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Markoaad75c62016-10-03 08:46:48 +00005753 case HLoadString::LoadKind::kBssEntry:
Alexey Frunze06a46c42016-07-19 15:00:40 -07005754 base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>();
5755 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07005756 default:
5757 base_or_current_method_reg = ZERO;
5758 break;
5759 }
5760
5761 switch (load_kind) {
5762 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00005763 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze06a46c42016-07-19 15:00:40 -07005764 __ LoadLiteral(out,
5765 base_or_current_method_reg,
5766 codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
5767 load->GetStringIndex()));
5768 return; // No dex cache slow path.
5769 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Markoaad75c62016-10-03 08:46:48 +00005770 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze06a46c42016-07-19 15:00:40 -07005771 CodeGeneratorMIPS::PcRelativePatchInfo* info =
Vladimir Marko6bec91c2017-01-09 15:03:12 +00005772 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunze6b892cd2017-01-03 17:11:38 -08005773 bool reordering = __ SetReorder(false);
5774 codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out, base_or_current_method_reg);
5775 __ Addiu(out, out, /* placeholder */ 0x5678);
5776 __ SetReorder(reordering);
Alexey Frunze06a46c42016-07-19 15:00:40 -07005777 return; // No dex cache slow path.
5778 }
5779 case HLoadString::LoadKind::kBootImageAddress: {
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00005780 uint32_t address = dchecked_integral_cast<uint32_t>(
5781 reinterpret_cast<uintptr_t>(load->GetString().Get()));
5782 DCHECK_NE(address, 0u);
Alexey Frunze06a46c42016-07-19 15:00:40 -07005783 __ LoadLiteral(out,
5784 base_or_current_method_reg,
5785 codegen_->DeduplicateBootImageAddressLiteral(address));
5786 return; // No dex cache slow path.
5787 }
Vladimir Markoaad75c62016-10-03 08:46:48 +00005788 case HLoadString::LoadKind::kBssEntry: {
5789 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
5790 CodeGeneratorMIPS::PcRelativePatchInfo* info =
Vladimir Marko6bec91c2017-01-09 15:03:12 +00005791 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunze6b892cd2017-01-03 17:11:38 -08005792 bool reordering = __ SetReorder(false);
5793 codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out, base_or_current_method_reg);
5794 __ LoadFromOffset(kLoadWord, out, out, /* placeholder */ 0x5678);
5795 __ SetReorder(reordering);
Vladimir Markoaad75c62016-10-03 08:46:48 +00005796 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS(load);
5797 codegen_->AddSlowPath(slow_path);
5798 __ Beqz(out, slow_path->GetEntryLabel());
5799 __ Bind(slow_path->GetExitLabel());
5800 return;
5801 }
Alexey Frunze627c1a02017-01-30 19:28:14 -08005802 case HLoadString::LoadKind::kJitTableAddress: {
5803 CodeGeneratorMIPS::JitPatchInfo* info =
5804 codegen_->NewJitRootStringPatch(load->GetDexFile(),
5805 load->GetStringIndex(),
5806 load->GetString());
5807 bool reordering = __ SetReorder(false);
5808 __ Bind(&info->high_label);
5809 __ Lui(out, /* placeholder */ 0x1234);
5810 GenerateGcRootFieldLoad(load, out_loc, out, /* placeholder */ 0x5678);
5811 __ SetReorder(reordering);
5812 return;
5813 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07005814 default:
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07005815 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07005816 }
Nicolas Geoffray917d0162015-11-24 18:25:35 +00005817
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07005818 // TODO: Re-add the compiler code to do string dex cache lookup again.
Vladimir Markoaad75c62016-10-03 08:46:48 +00005819 DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod);
5820 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe8a0128a2016-11-28 07:38:35 -08005821 __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_);
Vladimir Markoaad75c62016-10-03 08:46:48 +00005822 codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc());
5823 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005824}
5825
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005826void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) {
5827 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
5828 locations->SetOut(Location::ConstantLocation(constant));
5829}
5830
5831void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
5832 // Will be generated at use site.
5833}
5834
5835void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
5836 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005837 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005838 InvokeRuntimeCallingConvention calling_convention;
5839 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5840}
5841
5842void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
5843 if (instruction->IsEnter()) {
Serban Constantinescufca16662016-07-14 09:21:59 +01005844 codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005845 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
5846 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01005847 codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005848 }
5849 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
5850}
5851
5852void LocationsBuilderMIPS::VisitMul(HMul* mul) {
5853 LocationSummary* locations =
5854 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
5855 switch (mul->GetResultType()) {
5856 case Primitive::kPrimInt:
5857 case Primitive::kPrimLong:
5858 locations->SetInAt(0, Location::RequiresRegister());
5859 locations->SetInAt(1, Location::RequiresRegister());
5860 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5861 break;
5862
5863 case Primitive::kPrimFloat:
5864 case Primitive::kPrimDouble:
5865 locations->SetInAt(0, Location::RequiresFpuRegister());
5866 locations->SetInAt(1, Location::RequiresFpuRegister());
5867 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
5868 break;
5869
5870 default:
5871 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
5872 }
5873}
5874
5875void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) {
5876 Primitive::Type type = instruction->GetType();
5877 LocationSummary* locations = instruction->GetLocations();
5878 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
5879
5880 switch (type) {
5881 case Primitive::kPrimInt: {
5882 Register dst = locations->Out().AsRegister<Register>();
5883 Register lhs = locations->InAt(0).AsRegister<Register>();
5884 Register rhs = locations->InAt(1).AsRegister<Register>();
5885
5886 if (isR6) {
5887 __ MulR6(dst, lhs, rhs);
5888 } else {
5889 __ MulR2(dst, lhs, rhs);
5890 }
5891 break;
5892 }
5893 case Primitive::kPrimLong: {
5894 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
5895 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
5896 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
5897 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
5898 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
5899 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
5900
5901 // Extra checks to protect caused by the existance of A1_A2.
5902 // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo:
5903 // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2).
5904 DCHECK_NE(dst_high, lhs_low);
5905 DCHECK_NE(dst_high, rhs_low);
5906
5907 // A_B * C_D
5908 // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ]
5909 // dst_lo: [ low(B*D) ]
5910 // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result.
5911
5912 if (isR6) {
5913 __ MulR6(TMP, lhs_high, rhs_low);
5914 __ MulR6(dst_high, lhs_low, rhs_high);
5915 __ Addu(dst_high, dst_high, TMP);
5916 __ MuhuR6(TMP, lhs_low, rhs_low);
5917 __ Addu(dst_high, dst_high, TMP);
5918 __ MulR6(dst_low, lhs_low, rhs_low);
5919 } else {
5920 __ MulR2(TMP, lhs_high, rhs_low);
5921 __ MulR2(dst_high, lhs_low, rhs_high);
5922 __ Addu(dst_high, dst_high, TMP);
5923 __ MultuR2(lhs_low, rhs_low);
5924 __ Mfhi(TMP);
5925 __ Addu(dst_high, dst_high, TMP);
5926 __ Mflo(dst_low);
5927 }
5928 break;
5929 }
5930 case Primitive::kPrimFloat:
5931 case Primitive::kPrimDouble: {
5932 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5933 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
5934 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
5935 if (type == Primitive::kPrimFloat) {
5936 __ MulS(dst, lhs, rhs);
5937 } else {
5938 __ MulD(dst, lhs, rhs);
5939 }
5940 break;
5941 }
5942 default:
5943 LOG(FATAL) << "Unexpected mul type " << type;
5944 }
5945}
5946
5947void LocationsBuilderMIPS::VisitNeg(HNeg* neg) {
5948 LocationSummary* locations =
5949 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
5950 switch (neg->GetResultType()) {
5951 case Primitive::kPrimInt:
5952 case Primitive::kPrimLong:
5953 locations->SetInAt(0, Location::RequiresRegister());
5954 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5955 break;
5956
5957 case Primitive::kPrimFloat:
5958 case Primitive::kPrimDouble:
5959 locations->SetInAt(0, Location::RequiresFpuRegister());
5960 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
5961 break;
5962
5963 default:
5964 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
5965 }
5966}
5967
5968void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) {
5969 Primitive::Type type = instruction->GetType();
5970 LocationSummary* locations = instruction->GetLocations();
5971
5972 switch (type) {
5973 case Primitive::kPrimInt: {
5974 Register dst = locations->Out().AsRegister<Register>();
5975 Register src = locations->InAt(0).AsRegister<Register>();
5976 __ Subu(dst, ZERO, src);
5977 break;
5978 }
5979 case Primitive::kPrimLong: {
5980 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
5981 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
5982 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
5983 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
5984 __ Subu(dst_low, ZERO, src_low);
5985 __ Sltu(TMP, ZERO, dst_low);
5986 __ Subu(dst_high, ZERO, src_high);
5987 __ Subu(dst_high, dst_high, TMP);
5988 break;
5989 }
5990 case Primitive::kPrimFloat:
5991 case Primitive::kPrimDouble: {
5992 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5993 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
5994 if (type == Primitive::kPrimFloat) {
5995 __ NegS(dst, src);
5996 } else {
5997 __ NegD(dst, src);
5998 }
5999 break;
6000 }
6001 default:
6002 LOG(FATAL) << "Unexpected neg type " << type;
6003 }
6004}
6005
6006void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) {
6007 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006008 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006009 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006010 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00006011 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6012 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006013}
6014
6015void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) {
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00006016 codegen_->InvokeRuntime(kQuickAllocArrayResolved, instruction, instruction->GetDexPc());
6017 CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006018}
6019
6020void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) {
6021 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006022 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006023 InvokeRuntimeCallingConvention calling_convention;
David Brazdil6de19382016-01-08 17:37:10 +00006024 if (instruction->IsStringAlloc()) {
6025 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
6026 } else {
6027 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
David Brazdil6de19382016-01-08 17:37:10 +00006028 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006029 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
6030}
6031
6032void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) {
David Brazdil6de19382016-01-08 17:37:10 +00006033 if (instruction->IsStringAlloc()) {
6034 // String is allocated through StringFactory. Call NewEmptyString entry point.
6035 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07006036 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00006037 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
6038 __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value());
6039 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07006040 __ NopIfNoReordering();
David Brazdil6de19382016-01-08 17:37:10 +00006041 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
6042 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01006043 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00006044 CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>();
David Brazdil6de19382016-01-08 17:37:10 +00006045 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006046}
6047
6048void LocationsBuilderMIPS::VisitNot(HNot* instruction) {
6049 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
6050 locations->SetInAt(0, Location::RequiresRegister());
6051 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6052}
6053
6054void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) {
6055 Primitive::Type type = instruction->GetType();
6056 LocationSummary* locations = instruction->GetLocations();
6057
6058 switch (type) {
6059 case Primitive::kPrimInt: {
6060 Register dst = locations->Out().AsRegister<Register>();
6061 Register src = locations->InAt(0).AsRegister<Register>();
6062 __ Nor(dst, src, ZERO);
6063 break;
6064 }
6065
6066 case Primitive::kPrimLong: {
6067 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
6068 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
6069 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
6070 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
6071 __ Nor(dst_high, src_high, ZERO);
6072 __ Nor(dst_low, src_low, ZERO);
6073 break;
6074 }
6075
6076 default:
6077 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
6078 }
6079}
6080
6081void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) {
6082 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
6083 locations->SetInAt(0, Location::RequiresRegister());
6084 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6085}
6086
6087void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) {
6088 LocationSummary* locations = instruction->GetLocations();
6089 __ Xori(locations->Out().AsRegister<Register>(),
6090 locations->InAt(0).AsRegister<Register>(),
6091 1);
6092}
6093
6094void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01006095 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
6096 locations->SetInAt(0, Location::RequiresRegister());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006097}
6098
Calin Juravle2ae48182016-03-16 14:05:09 +00006099void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) {
6100 if (CanMoveNullCheckToUser(instruction)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006101 return;
6102 }
6103 Location obj = instruction->GetLocations()->InAt(0);
6104
6105 __ Lw(ZERO, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00006106 RecordPcInfo(instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006107}
6108
Calin Juravle2ae48182016-03-16 14:05:09 +00006109void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006110 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00006111 AddSlowPath(slow_path);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006112
6113 Location obj = instruction->GetLocations()->InAt(0);
6114
6115 __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
6116}
6117
6118void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00006119 codegen_->GenerateNullCheck(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006120}
6121
6122void LocationsBuilderMIPS::VisitOr(HOr* instruction) {
6123 HandleBinaryOp(instruction);
6124}
6125
6126void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) {
6127 HandleBinaryOp(instruction);
6128}
6129
6130void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
6131 LOG(FATAL) << "Unreachable";
6132}
6133
6134void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) {
6135 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
6136}
6137
6138void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) {
6139 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
6140 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
6141 if (location.IsStackSlot()) {
6142 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
6143 } else if (location.IsDoubleStackSlot()) {
6144 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
6145 }
6146 locations->SetOut(location);
6147}
6148
6149void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction
6150 ATTRIBUTE_UNUSED) {
6151 // Nothing to do, the parameter is already at its location.
6152}
6153
6154void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) {
6155 LocationSummary* locations =
6156 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6157 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
6158}
6159
6160void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction
6161 ATTRIBUTE_UNUSED) {
6162 // Nothing to do, the method is already at its location.
6163}
6164
6165void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) {
6166 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Vladimir Marko372f10e2016-05-17 16:30:10 +01006167 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006168 locations->SetInAt(i, Location::Any());
6169 }
6170 locations->SetOut(Location::Any());
6171}
6172
6173void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
6174 LOG(FATAL) << "Unreachable";
6175}
6176
6177void LocationsBuilderMIPS::VisitRem(HRem* rem) {
6178 Primitive::Type type = rem->GetResultType();
6179 LocationSummary::CallKind call_kind =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006180 (type == Primitive::kPrimInt) ? LocationSummary::kNoCall : LocationSummary::kCallOnMainOnly;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006181 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
6182
6183 switch (type) {
6184 case Primitive::kPrimInt:
6185 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08006186 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006187 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6188 break;
6189
6190 case Primitive::kPrimLong: {
6191 InvokeRuntimeCallingConvention calling_convention;
6192 locations->SetInAt(0, Location::RegisterPairLocation(
6193 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
6194 locations->SetInAt(1, Location::RegisterPairLocation(
6195 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
6196 locations->SetOut(calling_convention.GetReturnLocation(type));
6197 break;
6198 }
6199
6200 case Primitive::kPrimFloat:
6201 case Primitive::kPrimDouble: {
6202 InvokeRuntimeCallingConvention calling_convention;
6203 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
6204 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
6205 locations->SetOut(calling_convention.GetReturnLocation(type));
6206 break;
6207 }
6208
6209 default:
6210 LOG(FATAL) << "Unexpected rem type " << type;
6211 }
6212}
6213
6214void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) {
6215 Primitive::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006216
6217 switch (type) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08006218 case Primitive::kPrimInt:
6219 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006220 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006221 case Primitive::kPrimLong: {
Serban Constantinescufca16662016-07-14 09:21:59 +01006222 codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006223 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
6224 break;
6225 }
6226 case Primitive::kPrimFloat: {
Serban Constantinescufca16662016-07-14 09:21:59 +01006227 codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00006228 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006229 break;
6230 }
6231 case Primitive::kPrimDouble: {
Serban Constantinescufca16662016-07-14 09:21:59 +01006232 codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00006233 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006234 break;
6235 }
6236 default:
6237 LOG(FATAL) << "Unexpected rem type " << type;
6238 }
6239}
6240
6241void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
6242 memory_barrier->SetLocations(nullptr);
6243}
6244
6245void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
6246 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
6247}
6248
6249void LocationsBuilderMIPS::VisitReturn(HReturn* ret) {
6250 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret);
6251 Primitive::Type return_type = ret->InputAt(0)->GetType();
6252 locations->SetInAt(0, MipsReturnLocation(return_type));
6253}
6254
6255void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
6256 codegen_->GenerateFrameExit();
6257}
6258
6259void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) {
6260 ret->SetLocations(nullptr);
6261}
6262
6263void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
6264 codegen_->GenerateFrameExit();
6265}
6266
Alexey Frunze92d90602015-12-18 18:16:36 -08006267void LocationsBuilderMIPS::VisitRor(HRor* ror) {
6268 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00006269}
6270
Alexey Frunze92d90602015-12-18 18:16:36 -08006271void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) {
6272 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00006273}
6274
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006275void LocationsBuilderMIPS::VisitShl(HShl* shl) {
6276 HandleShift(shl);
6277}
6278
6279void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) {
6280 HandleShift(shl);
6281}
6282
6283void LocationsBuilderMIPS::VisitShr(HShr* shr) {
6284 HandleShift(shr);
6285}
6286
6287void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) {
6288 HandleShift(shr);
6289}
6290
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006291void LocationsBuilderMIPS::VisitSub(HSub* instruction) {
6292 HandleBinaryOp(instruction);
6293}
6294
6295void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) {
6296 HandleBinaryOp(instruction);
6297}
6298
6299void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
6300 HandleFieldGet(instruction, instruction->GetFieldInfo());
6301}
6302
6303void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
6304 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
6305}
6306
6307void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
6308 HandleFieldSet(instruction, instruction->GetFieldInfo());
6309}
6310
6311void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Goran Jakovljevice114da22016-12-26 14:21:43 +01006312 HandleFieldSet(instruction,
6313 instruction->GetFieldInfo(),
6314 instruction->GetDexPc(),
6315 instruction->GetValueCanBeNull());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006316}
6317
6318void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet(
6319 HUnresolvedInstanceFieldGet* instruction) {
6320 FieldAccessCallingConventionMIPS calling_convention;
6321 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
6322 instruction->GetFieldType(),
6323 calling_convention);
6324}
6325
6326void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet(
6327 HUnresolvedInstanceFieldGet* instruction) {
6328 FieldAccessCallingConventionMIPS calling_convention;
6329 codegen_->GenerateUnresolvedFieldAccess(instruction,
6330 instruction->GetFieldType(),
6331 instruction->GetFieldIndex(),
6332 instruction->GetDexPc(),
6333 calling_convention);
6334}
6335
6336void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet(
6337 HUnresolvedInstanceFieldSet* instruction) {
6338 FieldAccessCallingConventionMIPS calling_convention;
6339 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
6340 instruction->GetFieldType(),
6341 calling_convention);
6342}
6343
6344void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet(
6345 HUnresolvedInstanceFieldSet* instruction) {
6346 FieldAccessCallingConventionMIPS calling_convention;
6347 codegen_->GenerateUnresolvedFieldAccess(instruction,
6348 instruction->GetFieldType(),
6349 instruction->GetFieldIndex(),
6350 instruction->GetDexPc(),
6351 calling_convention);
6352}
6353
6354void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet(
6355 HUnresolvedStaticFieldGet* instruction) {
6356 FieldAccessCallingConventionMIPS calling_convention;
6357 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
6358 instruction->GetFieldType(),
6359 calling_convention);
6360}
6361
6362void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet(
6363 HUnresolvedStaticFieldGet* instruction) {
6364 FieldAccessCallingConventionMIPS calling_convention;
6365 codegen_->GenerateUnresolvedFieldAccess(instruction,
6366 instruction->GetFieldType(),
6367 instruction->GetFieldIndex(),
6368 instruction->GetDexPc(),
6369 calling_convention);
6370}
6371
6372void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet(
6373 HUnresolvedStaticFieldSet* instruction) {
6374 FieldAccessCallingConventionMIPS calling_convention;
6375 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
6376 instruction->GetFieldType(),
6377 calling_convention);
6378}
6379
6380void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet(
6381 HUnresolvedStaticFieldSet* instruction) {
6382 FieldAccessCallingConventionMIPS calling_convention;
6383 codegen_->GenerateUnresolvedFieldAccess(instruction,
6384 instruction->GetFieldType(),
6385 instruction->GetFieldIndex(),
6386 instruction->GetDexPc(),
6387 calling_convention);
6388}
6389
6390void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
Vladimir Marko70e97462016-08-09 11:04:26 +01006391 LocationSummary* locations =
6392 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
Vladimir Marko804b03f2016-09-14 16:26:36 +01006393 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006394}
6395
6396void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
6397 HBasicBlock* block = instruction->GetBlock();
6398 if (block->GetLoopInformation() != nullptr) {
6399 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
6400 // The back edge will generate the suspend check.
6401 return;
6402 }
6403 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
6404 // The goto will generate the suspend check.
6405 return;
6406 }
6407 GenerateSuspendCheck(instruction, nullptr);
6408}
6409
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006410void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) {
6411 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006412 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006413 InvokeRuntimeCallingConvention calling_convention;
6414 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6415}
6416
6417void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) {
Serban Constantinescufca16662016-07-14 09:21:59 +01006418 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006419 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
6420}
6421
6422void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) {
6423 Primitive::Type input_type = conversion->GetInputType();
6424 Primitive::Type result_type = conversion->GetResultType();
6425 DCHECK_NE(input_type, result_type);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006426 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006427
6428 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
6429 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
6430 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
6431 }
6432
6433 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006434 if (!isR6 &&
6435 ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) ||
6436 (result_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(input_type)))) {
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006437 call_kind = LocationSummary::kCallOnMainOnly;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006438 }
6439
6440 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
6441
6442 if (call_kind == LocationSummary::kNoCall) {
6443 if (Primitive::IsFloatingPointType(input_type)) {
6444 locations->SetInAt(0, Location::RequiresFpuRegister());
6445 } else {
6446 locations->SetInAt(0, Location::RequiresRegister());
6447 }
6448
6449 if (Primitive::IsFloatingPointType(result_type)) {
6450 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
6451 } else {
6452 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6453 }
6454 } else {
6455 InvokeRuntimeCallingConvention calling_convention;
6456
6457 if (Primitive::IsFloatingPointType(input_type)) {
6458 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
6459 } else {
6460 DCHECK_EQ(input_type, Primitive::kPrimLong);
6461 locations->SetInAt(0, Location::RegisterPairLocation(
6462 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
6463 }
6464
6465 locations->SetOut(calling_convention.GetReturnLocation(result_type));
6466 }
6467}
6468
6469void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) {
6470 LocationSummary* locations = conversion->GetLocations();
6471 Primitive::Type result_type = conversion->GetResultType();
6472 Primitive::Type input_type = conversion->GetInputType();
6473 bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006474 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006475
6476 DCHECK_NE(input_type, result_type);
6477
6478 if (result_type == Primitive::kPrimLong && Primitive::IsIntegralType(input_type)) {
6479 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
6480 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
6481 Register src = locations->InAt(0).AsRegister<Register>();
6482
Alexey Frunzea871ef12016-06-27 15:20:11 -07006483 if (dst_low != src) {
6484 __ Move(dst_low, src);
6485 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006486 __ Sra(dst_high, src, 31);
6487 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
6488 Register dst = locations->Out().AsRegister<Register>();
6489 Register src = (input_type == Primitive::kPrimLong)
6490 ? locations->InAt(0).AsRegisterPairLow<Register>()
6491 : locations->InAt(0).AsRegister<Register>();
6492
6493 switch (result_type) {
6494 case Primitive::kPrimChar:
6495 __ Andi(dst, src, 0xFFFF);
6496 break;
6497 case Primitive::kPrimByte:
6498 if (has_sign_extension) {
6499 __ Seb(dst, src);
6500 } else {
6501 __ Sll(dst, src, 24);
6502 __ Sra(dst, dst, 24);
6503 }
6504 break;
6505 case Primitive::kPrimShort:
6506 if (has_sign_extension) {
6507 __ Seh(dst, src);
6508 } else {
6509 __ Sll(dst, src, 16);
6510 __ Sra(dst, dst, 16);
6511 }
6512 break;
6513 case Primitive::kPrimInt:
Alexey Frunzea871ef12016-06-27 15:20:11 -07006514 if (dst != src) {
6515 __ Move(dst, src);
6516 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006517 break;
6518
6519 default:
6520 LOG(FATAL) << "Unexpected type conversion from " << input_type
6521 << " to " << result_type;
6522 }
6523 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006524 if (input_type == Primitive::kPrimLong) {
6525 if (isR6) {
6526 // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
6527 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
6528 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
6529 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
6530 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
6531 __ Mtc1(src_low, FTMP);
6532 __ Mthc1(src_high, FTMP);
6533 if (result_type == Primitive::kPrimFloat) {
6534 __ Cvtsl(dst, FTMP);
6535 } else {
6536 __ Cvtdl(dst, FTMP);
6537 }
6538 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01006539 QuickEntrypointEnum entrypoint = (result_type == Primitive::kPrimFloat) ? kQuickL2f
6540 : kQuickL2d;
6541 codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc());
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006542 if (result_type == Primitive::kPrimFloat) {
6543 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
6544 } else {
6545 CheckEntrypointTypes<kQuickL2d, double, int64_t>();
6546 }
6547 }
6548 } else {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006549 Register src = locations->InAt(0).AsRegister<Register>();
6550 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
6551 __ Mtc1(src, FTMP);
6552 if (result_type == Primitive::kPrimFloat) {
6553 __ Cvtsw(dst, FTMP);
6554 } else {
6555 __ Cvtdw(dst, FTMP);
6556 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006557 }
6558 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
6559 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006560 if (result_type == Primitive::kPrimLong) {
6561 if (isR6) {
6562 // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
6563 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
6564 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
6565 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
6566 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
6567 MipsLabel truncate;
6568 MipsLabel done;
6569
6570 // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive
6571 // value when the input is either a NaN or is outside of the range of the output type
6572 // after the truncation. IOW, the three special cases (NaN, too small, too big) produce
6573 // the same result.
6574 //
6575 // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum
6576 // value of the output type if the input is outside of the range after the truncation or
6577 // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct
6578 // results. This matches the desired float/double-to-int/long conversion exactly.
6579 //
6580 // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction.
6581 //
6582 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
6583 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
6584 // even though it must be NAN2008=1 on R6.
6585 //
6586 // The code takes care of the different behaviors by first comparing the input to the
6587 // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int).
6588 // If the input is greater than or equal to the minimum, it procedes to the truncate
6589 // instruction, which will handle such an input the same way irrespective of NAN2008.
6590 // Otherwise the input is compared to itself to determine whether it is a NaN or not
6591 // in order to return either zero or the minimum value.
6592 //
6593 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
6594 // truncate instruction for MIPS64R6.
6595 if (input_type == Primitive::kPrimFloat) {
6596 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min());
6597 __ LoadConst32(TMP, min_val);
6598 __ Mtc1(TMP, FTMP);
6599 __ CmpLeS(FTMP, FTMP, src);
6600 } else {
6601 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min());
6602 __ LoadConst32(TMP, High32Bits(min_val));
6603 __ Mtc1(ZERO, FTMP);
6604 __ Mthc1(TMP, FTMP);
6605 __ CmpLeD(FTMP, FTMP, src);
6606 }
6607
6608 __ Bc1nez(FTMP, &truncate);
6609
6610 if (input_type == Primitive::kPrimFloat) {
6611 __ CmpEqS(FTMP, src, src);
6612 } else {
6613 __ CmpEqD(FTMP, src, src);
6614 }
6615 __ Move(dst_low, ZERO);
6616 __ LoadConst32(dst_high, std::numeric_limits<int32_t>::min());
6617 __ Mfc1(TMP, FTMP);
6618 __ And(dst_high, dst_high, TMP);
6619
6620 __ B(&done);
6621
6622 __ Bind(&truncate);
6623
6624 if (input_type == Primitive::kPrimFloat) {
6625 __ TruncLS(FTMP, src);
6626 } else {
6627 __ TruncLD(FTMP, src);
6628 }
6629 __ Mfc1(dst_low, FTMP);
6630 __ Mfhc1(dst_high, FTMP);
6631
6632 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006633 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01006634 QuickEntrypointEnum entrypoint = (input_type == Primitive::kPrimFloat) ? kQuickF2l
6635 : kQuickD2l;
6636 codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc());
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006637 if (input_type == Primitive::kPrimFloat) {
6638 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
6639 } else {
6640 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
6641 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006642 }
6643 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006644 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
6645 Register dst = locations->Out().AsRegister<Register>();
6646 MipsLabel truncate;
6647 MipsLabel done;
6648
6649 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
6650 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
6651 // even though it must be NAN2008=1 on R6.
6652 //
6653 // For details see the large comment above for the truncation of float/double to long on R6.
6654 //
6655 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
6656 // truncate instruction for MIPS64R6.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006657 if (input_type == Primitive::kPrimFloat) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006658 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min());
6659 __ LoadConst32(TMP, min_val);
6660 __ Mtc1(TMP, FTMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006661 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006662 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min());
6663 __ LoadConst32(TMP, High32Bits(min_val));
6664 __ Mtc1(ZERO, FTMP);
Alexey Frunzea871ef12016-06-27 15:20:11 -07006665 __ MoveToFpuHigh(TMP, FTMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006666 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006667
6668 if (isR6) {
6669 if (input_type == Primitive::kPrimFloat) {
6670 __ CmpLeS(FTMP, FTMP, src);
6671 } else {
6672 __ CmpLeD(FTMP, FTMP, src);
6673 }
6674 __ Bc1nez(FTMP, &truncate);
6675
6676 if (input_type == Primitive::kPrimFloat) {
6677 __ CmpEqS(FTMP, src, src);
6678 } else {
6679 __ CmpEqD(FTMP, src, src);
6680 }
6681 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
6682 __ Mfc1(TMP, FTMP);
6683 __ And(dst, dst, TMP);
6684 } else {
6685 if (input_type == Primitive::kPrimFloat) {
6686 __ ColeS(0, FTMP, src);
6687 } else {
6688 __ ColeD(0, FTMP, src);
6689 }
6690 __ Bc1t(0, &truncate);
6691
6692 if (input_type == Primitive::kPrimFloat) {
6693 __ CeqS(0, src, src);
6694 } else {
6695 __ CeqD(0, src, src);
6696 }
6697 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
6698 __ Movf(dst, ZERO, 0);
6699 }
6700
6701 __ B(&done);
6702
6703 __ Bind(&truncate);
6704
6705 if (input_type == Primitive::kPrimFloat) {
6706 __ TruncWS(FTMP, src);
6707 } else {
6708 __ TruncWD(FTMP, src);
6709 }
6710 __ Mfc1(dst, FTMP);
6711
6712 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006713 }
6714 } else if (Primitive::IsFloatingPointType(result_type) &&
6715 Primitive::IsFloatingPointType(input_type)) {
6716 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
6717 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
6718 if (result_type == Primitive::kPrimFloat) {
6719 __ Cvtsd(dst, src);
6720 } else {
6721 __ Cvtds(dst, src);
6722 }
6723 } else {
6724 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
6725 << " to " << result_type;
6726 }
6727}
6728
6729void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) {
6730 HandleShift(ushr);
6731}
6732
6733void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) {
6734 HandleShift(ushr);
6735}
6736
6737void LocationsBuilderMIPS::VisitXor(HXor* instruction) {
6738 HandleBinaryOp(instruction);
6739}
6740
6741void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) {
6742 HandleBinaryOp(instruction);
6743}
6744
6745void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
6746 // Nothing to do, this should be removed during prepare for register allocator.
6747 LOG(FATAL) << "Unreachable";
6748}
6749
6750void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
6751 // Nothing to do, this should be removed during prepare for register allocator.
6752 LOG(FATAL) << "Unreachable";
6753}
6754
6755void LocationsBuilderMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006756 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006757}
6758
6759void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006760 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006761}
6762
6763void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006764 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006765}
6766
6767void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006768 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006769}
6770
6771void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006772 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006773}
6774
6775void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006776 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006777}
6778
6779void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006780 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006781}
6782
6783void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006784 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006785}
6786
6787void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006788 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006789}
6790
6791void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006792 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006793}
6794
6795void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006796 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006797}
6798
6799void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006800 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006801}
6802
6803void LocationsBuilderMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006804 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006805}
6806
6807void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006808 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006809}
6810
6811void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006812 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006813}
6814
6815void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006816 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006817}
6818
6819void LocationsBuilderMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006820 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006821}
6822
6823void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006824 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006825}
6826
6827void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006828 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006829}
6830
6831void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00006832 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006833}
6834
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006835void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
6836 LocationSummary* locations =
6837 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
6838 locations->SetInAt(0, Location::RequiresRegister());
6839}
6840
Alexey Frunze96b66822016-09-10 02:32:44 -07006841void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg,
6842 int32_t lower_bound,
6843 uint32_t num_entries,
6844 HBasicBlock* switch_block,
6845 HBasicBlock* default_block) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006846 // Create a set of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00006847 Register temp_reg = TMP;
6848 __ Addiu32(temp_reg, value_reg, -lower_bound);
6849 // Jump to default if index is negative
6850 // Note: We don't check the case that index is positive while value < lower_bound, because in
6851 // this case, index >= num_entries must be true. So that we can save one branch instruction.
6852 __ Bltz(temp_reg, codegen_->GetLabelOf(default_block));
6853
Alexey Frunze96b66822016-09-10 02:32:44 -07006854 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00006855 // Jump to successors[0] if value == lower_bound.
6856 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0]));
6857 int32_t last_index = 0;
6858 for (; num_entries - last_index > 2; last_index += 2) {
6859 __ Addiu(temp_reg, temp_reg, -2);
6860 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
6861 __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
6862 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
6863 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
6864 }
6865 if (num_entries - last_index == 2) {
6866 // The last missing case_value.
6867 __ Addiu(temp_reg, temp_reg, -1);
6868 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006869 }
6870
Vladimir Markof3e0ee22015-12-17 15:23:13 +00006871 // And the default for any other value.
Alexey Frunze96b66822016-09-10 02:32:44 -07006872 if (!codegen_->GoesToNextBlock(switch_block, default_block)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006873 __ B(codegen_->GetLabelOf(default_block));
6874 }
6875}
6876
Alexey Frunze96b66822016-09-10 02:32:44 -07006877void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg,
6878 Register constant_area,
6879 int32_t lower_bound,
6880 uint32_t num_entries,
6881 HBasicBlock* switch_block,
6882 HBasicBlock* default_block) {
6883 // Create a jump table.
6884 std::vector<MipsLabel*> labels(num_entries);
6885 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
6886 for (uint32_t i = 0; i < num_entries; i++) {
6887 labels[i] = codegen_->GetLabelOf(successors[i]);
6888 }
6889 JumpTable* table = __ CreateJumpTable(std::move(labels));
6890
6891 // Is the value in range?
6892 __ Addiu32(TMP, value_reg, -lower_bound);
6893 if (IsInt<16>(static_cast<int32_t>(num_entries))) {
6894 __ Sltiu(AT, TMP, num_entries);
6895 __ Beqz(AT, codegen_->GetLabelOf(default_block));
6896 } else {
6897 __ LoadConst32(AT, num_entries);
6898 __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block));
6899 }
6900
6901 // We are in the range of the table.
6902 // Load the target address from the jump table, indexing by the value.
6903 __ LoadLabelAddress(AT, constant_area, table->GetLabel());
6904 __ Sll(TMP, TMP, 2);
6905 __ Addu(TMP, TMP, AT);
6906 __ Lw(TMP, TMP, 0);
6907 // Compute the absolute target address by adding the table start address
6908 // (the table contains offsets to targets relative to its start).
6909 __ Addu(TMP, TMP, AT);
6910 // And jump.
6911 __ Jr(TMP);
6912 __ NopIfNoReordering();
6913}
6914
6915void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
6916 int32_t lower_bound = switch_instr->GetStartValue();
6917 uint32_t num_entries = switch_instr->GetNumEntries();
6918 LocationSummary* locations = switch_instr->GetLocations();
6919 Register value_reg = locations->InAt(0).AsRegister<Register>();
6920 HBasicBlock* switch_block = switch_instr->GetBlock();
6921 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
6922
6923 if (codegen_->GetInstructionSetFeatures().IsR6() &&
6924 num_entries > kPackedSwitchJumpTableThreshold) {
6925 // R6 uses PC-relative addressing to access the jump table.
6926 // R2, OTOH, requires an HMipsComputeBaseMethodAddress input to access
6927 // the jump table and it is implemented by changing HPackedSwitch to
6928 // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress.
6929 // See VisitMipsPackedSwitch() for the table-based implementation on R2.
6930 GenTableBasedPackedSwitch(value_reg,
6931 ZERO,
6932 lower_bound,
6933 num_entries,
6934 switch_block,
6935 default_block);
6936 } else {
6937 GenPackedSwitchWithCompares(value_reg,
6938 lower_bound,
6939 num_entries,
6940 switch_block,
6941 default_block);
6942 }
6943}
6944
6945void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) {
6946 LocationSummary* locations =
6947 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
6948 locations->SetInAt(0, Location::RequiresRegister());
6949 // Constant area pointer (HMipsComputeBaseMethodAddress).
6950 locations->SetInAt(1, Location::RequiresRegister());
6951}
6952
6953void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) {
6954 int32_t lower_bound = switch_instr->GetStartValue();
6955 uint32_t num_entries = switch_instr->GetNumEntries();
6956 LocationSummary* locations = switch_instr->GetLocations();
6957 Register value_reg = locations->InAt(0).AsRegister<Register>();
6958 Register constant_area = locations->InAt(1).AsRegister<Register>();
6959 HBasicBlock* switch_block = switch_instr->GetBlock();
6960 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
6961
6962 // This is an R2-only path. HPackedSwitch has been changed to
6963 // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress
6964 // required to address the jump table relative to PC.
6965 GenTableBasedPackedSwitch(value_reg,
6966 constant_area,
6967 lower_bound,
6968 num_entries,
6969 switch_block,
6970 default_block);
6971}
6972
Alexey Frunzee3fb2452016-05-10 16:08:05 -07006973void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress(
6974 HMipsComputeBaseMethodAddress* insn) {
6975 LocationSummary* locations =
6976 new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall);
6977 locations->SetOut(Location::RequiresRegister());
6978}
6979
6980void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress(
6981 HMipsComputeBaseMethodAddress* insn) {
6982 LocationSummary* locations = insn->GetLocations();
6983 Register reg = locations->Out().AsRegister<Register>();
6984
6985 CHECK(!codegen_->GetInstructionSetFeatures().IsR6());
6986
6987 // Generate a dummy PC-relative call to obtain PC.
6988 __ Nal();
6989 // Grab the return address off RA.
6990 __ Move(reg, RA);
Alexey Frunze06a46c42016-07-19 15:00:40 -07006991 // TODO: Can we share this code with that of VisitMipsDexCacheArraysBase()?
Alexey Frunzee3fb2452016-05-10 16:08:05 -07006992
6993 // Remember this offset (the obtained PC value) for later use with constant area.
6994 __ BindPcRelBaseLabel();
6995}
6996
6997void LocationsBuilderMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) {
6998 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base);
6999 locations->SetOut(Location::RequiresRegister());
7000}
7001
7002void InstructionCodeGeneratorMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) {
7003 Register reg = base->GetLocations()->Out().AsRegister<Register>();
7004 CodeGeneratorMIPS::PcRelativePatchInfo* info =
7005 codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset());
Alexey Frunze6b892cd2017-01-03 17:11:38 -08007006 CHECK(!codegen_->GetInstructionSetFeatures().IsR6());
7007 bool reordering = __ SetReorder(false);
Vladimir Markoaad75c62016-10-03 08:46:48 +00007008 // TODO: Reuse MipsComputeBaseMethodAddress on R2 instead of passing ZERO to force emitting NAL.
Alexey Frunze6b892cd2017-01-03 17:11:38 -08007009 codegen_->EmitPcRelativeAddressPlaceholderHigh(info, reg, ZERO);
7010 __ Addiu(reg, reg, /* placeholder */ 0x5678);
7011 __ SetReorder(reordering);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007012}
7013
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007014void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
7015 // The trampoline uses the same calling convention as dex calling conventions,
7016 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
7017 // the method_idx.
7018 HandleInvoke(invoke);
7019}
7020
7021void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
7022 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
7023}
7024
Roland Levillain2aba7cd2016-02-03 12:27:20 +00007025void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) {
7026 LocationSummary* locations =
7027 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
7028 locations->SetInAt(0, Location::RequiresRegister());
7029 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007030}
7031
Roland Levillain2aba7cd2016-02-03 12:27:20 +00007032void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) {
7033 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00007034 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007035 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Roland Levillain2aba7cd2016-02-03 12:27:20 +00007036 instruction->GetIndex(), kMipsPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007037 __ LoadFromOffset(kLoadWord,
7038 locations->Out().AsRegister<Register>(),
7039 locations->InAt(0).AsRegister<Register>(),
7040 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00007041 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007042 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00007043 instruction->GetIndex(), kMipsPointerSize));
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00007044 __ LoadFromOffset(kLoadWord,
7045 locations->Out().AsRegister<Register>(),
7046 locations->InAt(0).AsRegister<Register>(),
7047 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007048 __ LoadFromOffset(kLoadWord,
7049 locations->Out().AsRegister<Register>(),
7050 locations->Out().AsRegister<Register>(),
7051 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00007052 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007053}
7054
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007055#undef __
7056#undef QUICK_ENTRY_POINT
7057
7058} // namespace mips
7059} // namespace art