blob: 6376f03b26abb8f8449cb3daae2a136a35219136 [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
Alexey Frunze4147fcc2017-06-17 19:57:27 -070019#include "arch/mips/asm_support_mips.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020020#include "arch/mips/entrypoints_direct_mips.h"
21#include "arch/mips/instruction_set_features_mips.h"
22#include "art_method.h"
Vladimir Marko94ec2db2017-09-06 17:21:03 +010023#include "class_table.h"
Chris Larsen701566a2015-10-27 15:29:13 -070024#include "code_generator_utils.h"
Vladimir Marko3a21e382016-09-02 12:38:38 +010025#include "compiled_method.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020026#include "entrypoints/quick/quick_entrypoints.h"
27#include "entrypoints/quick/quick_entrypoints_enum.h"
28#include "gc/accounting/card_table.h"
Andreas Gampe09659c22017-09-18 18:23:32 -070029#include "heap_poisoning.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020030#include "intrinsics.h"
Chris Larsen701566a2015-10-27 15:29:13 -070031#include "intrinsics_mips.h"
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010032#include "linker/linker_patch.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020033#include "mirror/array-inl.h"
34#include "mirror/class-inl.h"
35#include "offsets.h"
Vladimir Marko174b2e22017-10-12 13:34:49 +010036#include "stack_map_stream.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020037#include "thread.h"
38#include "utils/assembler.h"
39#include "utils/mips/assembler_mips.h"
40#include "utils/stack_checks.h"
41
42namespace art {
43namespace mips {
44
45static constexpr int kCurrentMethodStackOffset = 0;
46static constexpr Register kMethodRegisterArgument = A0;
47
Alexey Frunze4147fcc2017-06-17 19:57:27 -070048// Flags controlling the use of thunks for Baker read barriers.
49constexpr bool kBakerReadBarrierThunksEnableForFields = true;
50constexpr bool kBakerReadBarrierThunksEnableForArrays = true;
51constexpr bool kBakerReadBarrierThunksEnableForGcRoots = true;
52
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010053Location MipsReturnLocation(DataType::Type return_type) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020054 switch (return_type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010055 case DataType::Type::kReference:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010056 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010057 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010058 case DataType::Type::kInt8:
59 case DataType::Type::kUint16:
60 case DataType::Type::kInt16:
61 case DataType::Type::kInt32:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020062 return Location::RegisterLocation(V0);
63
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010064 case DataType::Type::kInt64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020065 return Location::RegisterPairLocation(V0, V1);
66
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010067 case DataType::Type::kFloat32:
68 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020069 return Location::FpuRegisterLocation(F0);
70
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010071 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020072 return Location();
73 }
74 UNREACHABLE();
75}
76
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010077Location InvokeDexCallingConventionVisitorMIPS::GetReturnLocation(DataType::Type type) const {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020078 return MipsReturnLocation(type);
79}
80
81Location InvokeDexCallingConventionVisitorMIPS::GetMethodLocation() const {
82 return Location::RegisterLocation(kMethodRegisterArgument);
83}
84
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010085Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(DataType::Type type) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020086 Location next_location;
87
88 switch (type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010089 case DataType::Type::kReference:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010090 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010091 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010092 case DataType::Type::kInt8:
93 case DataType::Type::kUint16:
94 case DataType::Type::kInt16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010095 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020096 uint32_t gp_index = gp_index_++;
97 if (gp_index < calling_convention.GetNumberOfRegisters()) {
98 next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index));
99 } else {
100 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
101 next_location = Location::StackSlot(stack_offset);
102 }
103 break;
104 }
105
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100106 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200107 uint32_t gp_index = gp_index_;
108 gp_index_ += 2;
109 if (gp_index + 1 < calling_convention.GetNumberOfRegisters()) {
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800110 Register reg = calling_convention.GetRegisterAt(gp_index);
111 if (reg == A1 || reg == A3) {
112 gp_index_++; // Skip A1(A3), and use A2_A3(T0_T1) instead.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200113 gp_index++;
114 }
115 Register low_even = calling_convention.GetRegisterAt(gp_index);
116 Register high_odd = calling_convention.GetRegisterAt(gp_index + 1);
117 DCHECK_EQ(low_even + 1, high_odd);
118 next_location = Location::RegisterPairLocation(low_even, high_odd);
119 } else {
120 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
121 next_location = Location::DoubleStackSlot(stack_offset);
122 }
123 break;
124 }
125
126 // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double
127 // will take up the even/odd pair, while floats are stored in even regs only.
128 // On 64 bit FPU, both double and float are stored in even registers only.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100129 case DataType::Type::kFloat32:
130 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200131 uint32_t float_index = float_index_++;
132 if (float_index < calling_convention.GetNumberOfFpuRegisters()) {
133 next_location = Location::FpuRegisterLocation(
134 calling_convention.GetFpuRegisterAt(float_index));
135 } else {
136 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100137 next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
138 : Location::StackSlot(stack_offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200139 }
140 break;
141 }
142
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100143 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200144 LOG(FATAL) << "Unexpected parameter type " << type;
145 break;
146 }
147
148 // Space on the stack is reserved for all arguments.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100149 stack_index_ += DataType::Is64BitType(type) ? 2 : 1;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200150
151 return next_location;
152}
153
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100154Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type type) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200155 return MipsReturnLocation(type);
156}
157
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100158// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
159#define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700160#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200161
162class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS {
163 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000164 explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200165
166 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
167 LocationSummary* locations = instruction_->GetLocations();
168 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
169 __ Bind(GetEntryLabel());
170 if (instruction_->CanThrowIntoCatchBlock()) {
171 // Live registers will be restored in the catch block if caught.
172 SaveLiveRegisters(codegen, instruction_->GetLocations());
173 }
174 // We're moving two locations to locations that could overlap, so we need a parallel
175 // move resolver.
176 InvokeRuntimeCallingConvention calling_convention;
177 codegen->EmitParallelMoves(locations->InAt(0),
178 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100179 DataType::Type::kInt32,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200180 locations->InAt(1),
181 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100182 DataType::Type::kInt32);
Serban Constantinescufca16662016-07-14 09:21:59 +0100183 QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt()
184 ? kQuickThrowStringBounds
185 : kQuickThrowArrayBounds;
186 mips_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100187 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200188 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
189 }
190
191 bool IsFatal() const OVERRIDE { return true; }
192
193 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; }
194
195 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200196 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS);
197};
198
199class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS {
200 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000201 explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200202
203 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
204 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
205 __ Bind(GetEntryLabel());
Serban Constantinescufca16662016-07-14 09:21:59 +0100206 mips_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200207 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
208 }
209
210 bool IsFatal() const OVERRIDE { return true; }
211
212 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; }
213
214 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200215 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS);
216};
217
218class LoadClassSlowPathMIPS : public SlowPathCodeMIPS {
219 public:
220 LoadClassSlowPathMIPS(HLoadClass* cls,
221 HInstruction* at,
222 uint32_t dex_pc,
Vladimir Markof3c52b42017-11-17 17:32:12 +0000223 bool do_clinit)
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700224 : SlowPathCodeMIPS(at),
225 cls_(cls),
226 dex_pc_(dex_pc),
Vladimir Markof3c52b42017-11-17 17:32:12 +0000227 do_clinit_(do_clinit) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200228 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
229 }
230
231 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000232 LocationSummary* locations = instruction_->GetLocations();
Alexey Frunzec61c0762017-04-10 13:54:23 -0700233 Location out = locations->Out();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200234 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Alexey Frunzec61c0762017-04-10 13:54:23 -0700235 InvokeRuntimeCallingConvention calling_convention;
236 DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200237 __ Bind(GetEntryLabel());
238 SaveLiveRegisters(codegen, locations);
239
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000240 dex::TypeIndex type_index = cls_->GetTypeIndex();
241 __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_);
Serban Constantinescufca16662016-07-14 09:21:59 +0100242 QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage
243 : kQuickInitializeType;
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000244 mips_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200245 if (do_clinit_) {
246 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
247 } else {
248 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
249 }
250
251 // Move the class to the desired location.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200252 if (out.IsValid()) {
253 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100254 DataType::Type type = instruction_->GetType();
Alexey Frunzec61c0762017-04-10 13:54:23 -0700255 mips_codegen->MoveLocation(out,
256 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
257 type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200258 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200259 RestoreLiveRegisters(codegen, locations);
Alexey Frunzec61c0762017-04-10 13:54:23 -0700260
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200261 __ B(GetExitLabel());
262 }
263
264 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; }
265
266 private:
267 // The class this slow path will load.
268 HLoadClass* const cls_;
269
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200270 // The dex PC of `at_`.
271 const uint32_t dex_pc_;
272
273 // Whether to initialize the class.
274 const bool do_clinit_;
275
276 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS);
277};
278
279class LoadStringSlowPathMIPS : public SlowPathCodeMIPS {
280 public:
Vladimir Markof3c52b42017-11-17 17:32:12 +0000281 explicit LoadStringSlowPathMIPS(HLoadString* instruction)
282 : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200283
284 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexey Frunzec61c0762017-04-10 13:54:23 -0700285 DCHECK(instruction_->IsLoadString());
286 DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200287 LocationSummary* locations = instruction_->GetLocations();
288 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Vladimir Markof3c52b42017-11-17 17:32:12 +0000289 const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200290 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Alexey Frunzec61c0762017-04-10 13:54:23 -0700291 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200292 __ Bind(GetEntryLabel());
293 SaveLiveRegisters(codegen, locations);
294
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000295 __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_);
Serban Constantinescufca16662016-07-14 09:21:59 +0100296 mips_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200297 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Alexey Frunzec61c0762017-04-10 13:54:23 -0700298
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100299 DataType::Type type = instruction_->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200300 mips_codegen->MoveLocation(locations->Out(),
Alexey Frunzec61c0762017-04-10 13:54:23 -0700301 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200302 type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200303 RestoreLiveRegisters(codegen, locations);
Vladimir Markoaad75c62016-10-03 08:46:48 +0000304
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200305 __ B(GetExitLabel());
306 }
307
308 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; }
309
310 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200311 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS);
312};
313
314class NullCheckSlowPathMIPS : public SlowPathCodeMIPS {
315 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000316 explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200317
318 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
319 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
320 __ Bind(GetEntryLabel());
321 if (instruction_->CanThrowIntoCatchBlock()) {
322 // Live registers will be restored in the catch block if caught.
323 SaveLiveRegisters(codegen, instruction_->GetLocations());
324 }
Serban Constantinescufca16662016-07-14 09:21:59 +0100325 mips_codegen->InvokeRuntime(kQuickThrowNullPointer,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200326 instruction_,
327 instruction_->GetDexPc(),
Serban Constantinescufca16662016-07-14 09:21:59 +0100328 this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200329 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
330 }
331
332 bool IsFatal() const OVERRIDE { return true; }
333
334 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; }
335
336 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200337 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS);
338};
339
340class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS {
341 public:
342 SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000343 : SlowPathCodeMIPS(instruction), successor_(successor) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200344
345 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Lena Djokicca8c2952017-05-29 11:31:46 +0200346 LocationSummary* locations = instruction_->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200347 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
348 __ Bind(GetEntryLabel());
Lena Djokicca8c2952017-05-29 11:31:46 +0200349 SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD.
Serban Constantinescufca16662016-07-14 09:21:59 +0100350 mips_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200351 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Lena Djokicca8c2952017-05-29 11:31:46 +0200352 RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200353 if (successor_ == nullptr) {
354 __ B(GetReturnLabel());
355 } else {
356 __ B(mips_codegen->GetLabelOf(successor_));
357 }
358 }
359
360 MipsLabel* GetReturnLabel() {
361 DCHECK(successor_ == nullptr);
362 return &return_label_;
363 }
364
365 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; }
366
Chris Larsena2045912017-11-02 12:39:54 -0700367 HBasicBlock* GetSuccessor() const {
368 return successor_;
369 }
370
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200371 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200372 // If not null, the block to branch to after the suspend check.
373 HBasicBlock* const successor_;
374
375 // If `successor_` is null, the label to branch to after the suspend check.
376 MipsLabel return_label_;
377
378 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS);
379};
380
381class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS {
382 public:
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800383 explicit TypeCheckSlowPathMIPS(HInstruction* instruction, bool is_fatal)
384 : SlowPathCodeMIPS(instruction), is_fatal_(is_fatal) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200385
386 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
387 LocationSummary* locations = instruction_->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200388 uint32_t dex_pc = instruction_->GetDexPc();
389 DCHECK(instruction_->IsCheckCast()
390 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
391 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
392
393 __ Bind(GetEntryLabel());
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800394 if (!is_fatal_) {
395 SaveLiveRegisters(codegen, locations);
396 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200397
398 // We're moving two locations to locations that could overlap, so we need a parallel
399 // move resolver.
400 InvokeRuntimeCallingConvention calling_convention;
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800401 codegen->EmitParallelMoves(locations->InAt(0),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200402 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100403 DataType::Type::kReference,
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800404 locations->InAt(1),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200405 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100406 DataType::Type::kReference);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200407 if (instruction_->IsInstanceOf()) {
Serban Constantinescufca16662016-07-14 09:21:59 +0100408 mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this);
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800409 CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100410 DataType::Type ret_type = instruction_->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200411 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
412 mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200413 } else {
414 DCHECK(instruction_->IsCheckCast());
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800415 mips_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this);
416 CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200417 }
418
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800419 if (!is_fatal_) {
420 RestoreLiveRegisters(codegen, locations);
421 __ B(GetExitLabel());
422 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200423 }
424
425 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; }
426
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800427 bool IsFatal() const OVERRIDE { return is_fatal_; }
428
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200429 private:
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800430 const bool is_fatal_;
431
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200432 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS);
433};
434
435class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS {
436 public:
Aart Bik42249c32016-01-07 15:33:50 -0800437 explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000438 : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200439
440 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800441 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200442 __ Bind(GetEntryLabel());
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +0100443 LocationSummary* locations = instruction_->GetLocations();
444 SaveLiveRegisters(codegen, locations);
445 InvokeRuntimeCallingConvention calling_convention;
446 __ LoadConst32(calling_convention.GetRegisterAt(0),
447 static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind()));
Serban Constantinescufca16662016-07-14 09:21:59 +0100448 mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +0100449 CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200450 }
451
452 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; }
453
454 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200455 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS);
456};
457
Alexey Frunze15958152017-02-09 19:08:30 -0800458class ArraySetSlowPathMIPS : public SlowPathCodeMIPS {
459 public:
460 explicit ArraySetSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {}
461
462 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
463 LocationSummary* locations = instruction_->GetLocations();
464 __ Bind(GetEntryLabel());
465 SaveLiveRegisters(codegen, locations);
466
467 InvokeRuntimeCallingConvention calling_convention;
Vladimir Markoca6fff82017-10-03 14:49:14 +0100468 HParallelMove parallel_move(codegen->GetGraph()->GetAllocator());
Alexey Frunze15958152017-02-09 19:08:30 -0800469 parallel_move.AddMove(
470 locations->InAt(0),
471 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100472 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800473 nullptr);
474 parallel_move.AddMove(
475 locations->InAt(1),
476 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100477 DataType::Type::kInt32,
Alexey Frunze15958152017-02-09 19:08:30 -0800478 nullptr);
479 parallel_move.AddMove(
480 locations->InAt(2),
481 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100482 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800483 nullptr);
484 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
485
486 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
487 mips_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this);
488 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
489 RestoreLiveRegisters(codegen, locations);
490 __ B(GetExitLabel());
491 }
492
493 const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS"; }
494
495 private:
496 DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS);
497};
498
499// Slow path marking an object reference `ref` during a read
500// barrier. The field `obj.field` in the object `obj` holding this
501// reference does not get updated by this slow path after marking (see
502// ReadBarrierMarkAndUpdateFieldSlowPathMIPS below for that).
503//
504// This means that after the execution of this slow path, `ref` will
505// always be up-to-date, but `obj.field` may not; i.e., after the
506// flip, `ref` will be a to-space reference, but `obj.field` will
507// probably still be a from-space reference (unless it gets updated by
508// another thread, or if another thread installed another object
509// reference (different from `ref`) in `obj.field`).
510//
511// If `entrypoint` is a valid location it is assumed to already be
512// holding the entrypoint. The case where the entrypoint is passed in
513// is for the GcRoot read barrier.
514class ReadBarrierMarkSlowPathMIPS : public SlowPathCodeMIPS {
515 public:
516 ReadBarrierMarkSlowPathMIPS(HInstruction* instruction,
517 Location ref,
518 Location entrypoint = Location::NoLocation())
519 : SlowPathCodeMIPS(instruction), ref_(ref), entrypoint_(entrypoint) {
520 DCHECK(kEmitCompilerReadBarrier);
521 }
522
523 const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; }
524
525 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
526 LocationSummary* locations = instruction_->GetLocations();
527 Register ref_reg = ref_.AsRegister<Register>();
528 DCHECK(locations->CanCall());
529 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg;
530 DCHECK(instruction_->IsInstanceFieldGet() ||
531 instruction_->IsStaticFieldGet() ||
532 instruction_->IsArrayGet() ||
533 instruction_->IsArraySet() ||
534 instruction_->IsLoadClass() ||
535 instruction_->IsLoadString() ||
536 instruction_->IsInstanceOf() ||
537 instruction_->IsCheckCast() ||
538 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) ||
539 (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified()))
540 << "Unexpected instruction in read barrier marking slow path: "
541 << instruction_->DebugName();
542
543 __ Bind(GetEntryLabel());
544 // No need to save live registers; it's taken care of by the
545 // entrypoint. Also, there is no need to update the stack mask,
546 // as this runtime call will not trigger a garbage collection.
547 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
548 DCHECK((V0 <= ref_reg && ref_reg <= T7) ||
549 (S2 <= ref_reg && ref_reg <= S7) ||
550 (ref_reg == FP)) << ref_reg;
551 // "Compact" slow path, saving two moves.
552 //
553 // Instead of using the standard runtime calling convention (input
554 // and output in A0 and V0 respectively):
555 //
556 // A0 <- ref
557 // V0 <- ReadBarrierMark(A0)
558 // ref <- V0
559 //
560 // we just use rX (the register containing `ref`) as input and output
561 // of a dedicated entrypoint:
562 //
563 // rX <- ReadBarrierMarkRegX(rX)
564 //
565 if (entrypoint_.IsValid()) {
566 mips_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this);
567 DCHECK_EQ(entrypoint_.AsRegister<Register>(), T9);
568 __ Jalr(entrypoint_.AsRegister<Register>());
569 __ NopIfNoReordering();
570 } else {
571 int32_t entry_point_offset =
Roland Levillain97c46462017-05-11 14:04:03 +0100572 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1);
Alexey Frunze15958152017-02-09 19:08:30 -0800573 // This runtime call does not require a stack map.
574 mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset,
575 instruction_,
576 this,
577 /* direct */ false);
578 }
579 __ B(GetExitLabel());
580 }
581
582 private:
583 // The location (register) of the marked object reference.
584 const Location ref_;
585
586 // The location of the entrypoint if already loaded.
587 const Location entrypoint_;
588
589 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS);
590};
591
592// Slow path marking an object reference `ref` during a read barrier,
593// and if needed, atomically updating the field `obj.field` in the
594// object `obj` holding this reference after marking (contrary to
595// ReadBarrierMarkSlowPathMIPS above, which never tries to update
596// `obj.field`).
597//
598// This means that after the execution of this slow path, both `ref`
599// and `obj.field` will be up-to-date; i.e., after the flip, both will
600// hold the same to-space reference (unless another thread installed
601// another object reference (different from `ref`) in `obj.field`).
602class ReadBarrierMarkAndUpdateFieldSlowPathMIPS : public SlowPathCodeMIPS {
603 public:
604 ReadBarrierMarkAndUpdateFieldSlowPathMIPS(HInstruction* instruction,
605 Location ref,
606 Register obj,
607 Location field_offset,
608 Register temp1)
609 : SlowPathCodeMIPS(instruction),
610 ref_(ref),
611 obj_(obj),
612 field_offset_(field_offset),
613 temp1_(temp1) {
614 DCHECK(kEmitCompilerReadBarrier);
615 }
616
617 const char* GetDescription() const OVERRIDE {
618 return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS";
619 }
620
621 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
622 LocationSummary* locations = instruction_->GetLocations();
623 Register ref_reg = ref_.AsRegister<Register>();
624 DCHECK(locations->CanCall());
625 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg;
626 // This slow path is only used by the UnsafeCASObject intrinsic.
627 DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()))
628 << "Unexpected instruction in read barrier marking and field updating slow path: "
629 << instruction_->DebugName();
630 DCHECK(instruction_->GetLocations()->Intrinsified());
631 DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject);
632 DCHECK(field_offset_.IsRegisterPair()) << field_offset_;
633
634 __ Bind(GetEntryLabel());
635
636 // Save the old reference.
637 // Note that we cannot use AT or TMP to save the old reference, as those
638 // are used by the code that follows, but we need the old reference after
639 // the call to the ReadBarrierMarkRegX entry point.
640 DCHECK_NE(temp1_, AT);
641 DCHECK_NE(temp1_, TMP);
642 __ Move(temp1_, ref_reg);
643
644 // No need to save live registers; it's taken care of by the
645 // entrypoint. Also, there is no need to update the stack mask,
646 // as this runtime call will not trigger a garbage collection.
647 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
648 DCHECK((V0 <= ref_reg && ref_reg <= T7) ||
649 (S2 <= ref_reg && ref_reg <= S7) ||
650 (ref_reg == FP)) << ref_reg;
651 // "Compact" slow path, saving two moves.
652 //
653 // Instead of using the standard runtime calling convention (input
654 // and output in A0 and V0 respectively):
655 //
656 // A0 <- ref
657 // V0 <- ReadBarrierMark(A0)
658 // ref <- V0
659 //
660 // we just use rX (the register containing `ref`) as input and output
661 // of a dedicated entrypoint:
662 //
663 // rX <- ReadBarrierMarkRegX(rX)
664 //
665 int32_t entry_point_offset =
Roland Levillain97c46462017-05-11 14:04:03 +0100666 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1);
Alexey Frunze15958152017-02-09 19:08:30 -0800667 // This runtime call does not require a stack map.
668 mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset,
669 instruction_,
670 this,
671 /* direct */ false);
672
673 // If the new reference is different from the old reference,
674 // update the field in the holder (`*(obj_ + field_offset_)`).
675 //
676 // Note that this field could also hold a different object, if
677 // another thread had concurrently changed it. In that case, the
678 // the compare-and-set (CAS) loop below would abort, leaving the
679 // field as-is.
680 MipsLabel done;
681 __ Beq(temp1_, ref_reg, &done);
682
683 // Update the the holder's field atomically. This may fail if
684 // mutator updates before us, but it's OK. This is achieved
685 // using a strong compare-and-set (CAS) operation with relaxed
686 // memory synchronization ordering, where the expected value is
687 // the old reference and the desired value is the new reference.
688
689 // Convenience aliases.
690 Register base = obj_;
691 // The UnsafeCASObject intrinsic uses a register pair as field
692 // offset ("long offset"), of which only the low part contains
693 // data.
694 Register offset = field_offset_.AsRegisterPairLow<Register>();
695 Register expected = temp1_;
696 Register value = ref_reg;
697 Register tmp_ptr = TMP; // Pointer to actual memory.
698 Register tmp = AT; // Value in memory.
699
700 __ Addu(tmp_ptr, base, offset);
701
702 if (kPoisonHeapReferences) {
703 __ PoisonHeapReference(expected);
704 // Do not poison `value` if it is the same register as
705 // `expected`, which has just been poisoned.
706 if (value != expected) {
707 __ PoisonHeapReference(value);
708 }
709 }
710
711 // do {
712 // tmp = [r_ptr] - expected;
713 // } while (tmp == 0 && failure([r_ptr] <- r_new_value));
714
715 bool is_r6 = mips_codegen->GetInstructionSetFeatures().IsR6();
716 MipsLabel loop_head, exit_loop;
717 __ Bind(&loop_head);
718 if (is_r6) {
719 __ LlR6(tmp, tmp_ptr);
720 } else {
721 __ LlR2(tmp, tmp_ptr);
722 }
723 __ Bne(tmp, expected, &exit_loop);
724 __ Move(tmp, value);
725 if (is_r6) {
726 __ ScR6(tmp, tmp_ptr);
727 } else {
728 __ ScR2(tmp, tmp_ptr);
729 }
730 __ Beqz(tmp, &loop_head);
731 __ Bind(&exit_loop);
732
733 if (kPoisonHeapReferences) {
734 __ UnpoisonHeapReference(expected);
735 // Do not unpoison `value` if it is the same register as
736 // `expected`, which has just been unpoisoned.
737 if (value != expected) {
738 __ UnpoisonHeapReference(value);
739 }
740 }
741
742 __ Bind(&done);
743 __ B(GetExitLabel());
744 }
745
746 private:
747 // The location (register) of the marked object reference.
748 const Location ref_;
749 // The register containing the object holding the marked object reference field.
750 const Register obj_;
751 // The location of the offset of the marked reference field within `obj_`.
752 Location field_offset_;
753
754 const Register temp1_;
755
756 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS);
757};
758
759// Slow path generating a read barrier for a heap reference.
760class ReadBarrierForHeapReferenceSlowPathMIPS : public SlowPathCodeMIPS {
761 public:
762 ReadBarrierForHeapReferenceSlowPathMIPS(HInstruction* instruction,
763 Location out,
764 Location ref,
765 Location obj,
766 uint32_t offset,
767 Location index)
768 : SlowPathCodeMIPS(instruction),
769 out_(out),
770 ref_(ref),
771 obj_(obj),
772 offset_(offset),
773 index_(index) {
774 DCHECK(kEmitCompilerReadBarrier);
775 // If `obj` is equal to `out` or `ref`, it means the initial object
776 // has been overwritten by (or after) the heap object reference load
777 // to be instrumented, e.g.:
778 //
779 // __ LoadFromOffset(kLoadWord, out, out, offset);
780 // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset);
781 //
782 // In that case, we have lost the information about the original
783 // object, and the emitted read barrier cannot work properly.
784 DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out;
785 DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref;
786 }
787
788 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
789 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
790 LocationSummary* locations = instruction_->GetLocations();
791 Register reg_out = out_.AsRegister<Register>();
792 DCHECK(locations->CanCall());
793 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
794 DCHECK(instruction_->IsInstanceFieldGet() ||
795 instruction_->IsStaticFieldGet() ||
796 instruction_->IsArrayGet() ||
797 instruction_->IsInstanceOf() ||
798 instruction_->IsCheckCast() ||
799 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()))
800 << "Unexpected instruction in read barrier for heap reference slow path: "
801 << instruction_->DebugName();
802
803 __ Bind(GetEntryLabel());
804 SaveLiveRegisters(codegen, locations);
805
806 // We may have to change the index's value, but as `index_` is a
807 // constant member (like other "inputs" of this slow path),
808 // introduce a copy of it, `index`.
809 Location index = index_;
810 if (index_.IsValid()) {
811 // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
812 if (instruction_->IsArrayGet()) {
813 // Compute the actual memory offset and store it in `index`.
814 Register index_reg = index_.AsRegister<Register>();
815 DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg));
816 if (codegen->IsCoreCalleeSaveRegister(index_reg)) {
817 // We are about to change the value of `index_reg` (see the
818 // calls to art::mips::MipsAssembler::Sll and
819 // art::mips::MipsAssembler::Addiu32 below), but it has
820 // not been saved by the previous call to
821 // art::SlowPathCode::SaveLiveRegisters, as it is a
822 // callee-save register --
823 // art::SlowPathCode::SaveLiveRegisters does not consider
824 // callee-save registers, as it has been designed with the
825 // assumption that callee-save registers are supposed to be
826 // handled by the called function. So, as a callee-save
827 // register, `index_reg` _would_ eventually be saved onto
828 // the stack, but it would be too late: we would have
829 // changed its value earlier. Therefore, we manually save
830 // it here into another freely available register,
831 // `free_reg`, chosen of course among the caller-save
832 // registers (as a callee-save `free_reg` register would
833 // exhibit the same problem).
834 //
835 // Note we could have requested a temporary register from
836 // the register allocator instead; but we prefer not to, as
837 // this is a slow path, and we know we can find a
838 // caller-save register that is available.
839 Register free_reg = FindAvailableCallerSaveRegister(codegen);
840 __ Move(free_reg, index_reg);
841 index_reg = free_reg;
842 index = Location::RegisterLocation(index_reg);
843 } else {
844 // The initial register stored in `index_` has already been
845 // saved in the call to art::SlowPathCode::SaveLiveRegisters
846 // (as it is not a callee-save register), so we can freely
847 // use it.
848 }
849 // Shifting the index value contained in `index_reg` by the scale
850 // factor (2) cannot overflow in practice, as the runtime is
851 // unable to allocate object arrays with a size larger than
852 // 2^26 - 1 (that is, 2^28 - 4 bytes).
853 __ Sll(index_reg, index_reg, TIMES_4);
854 static_assert(
855 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
856 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
857 __ Addiu32(index_reg, index_reg, offset_);
858 } else {
859 // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile
860 // intrinsics, `index_` is not shifted by a scale factor of 2
861 // (as in the case of ArrayGet), as it is actually an offset
862 // to an object field within an object.
863 DCHECK(instruction_->IsInvoke()) << instruction_->DebugName();
864 DCHECK(instruction_->GetLocations()->Intrinsified());
865 DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) ||
866 (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile))
867 << instruction_->AsInvoke()->GetIntrinsic();
868 DCHECK_EQ(offset_, 0U);
869 DCHECK(index_.IsRegisterPair());
870 // UnsafeGet's offset location is a register pair, the low
871 // part contains the correct offset.
872 index = index_.ToLow();
873 }
874 }
875
876 // We're moving two or three locations to locations that could
877 // overlap, so we need a parallel move resolver.
878 InvokeRuntimeCallingConvention calling_convention;
Vladimir Markoca6fff82017-10-03 14:49:14 +0100879 HParallelMove parallel_move(codegen->GetGraph()->GetAllocator());
Alexey Frunze15958152017-02-09 19:08:30 -0800880 parallel_move.AddMove(ref_,
881 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100882 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800883 nullptr);
884 parallel_move.AddMove(obj_,
885 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100886 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800887 nullptr);
888 if (index.IsValid()) {
889 parallel_move.AddMove(index,
890 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100891 DataType::Type::kInt32,
Alexey Frunze15958152017-02-09 19:08:30 -0800892 nullptr);
893 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
894 } else {
895 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
896 __ LoadConst32(calling_convention.GetRegisterAt(2), offset_);
897 }
898 mips_codegen->InvokeRuntime(kQuickReadBarrierSlow,
899 instruction_,
900 instruction_->GetDexPc(),
901 this);
902 CheckEntrypointTypes<
903 kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>();
Lena Djokic8098da92017-06-28 12:07:50 +0200904 mips_codegen->MoveLocation(out_,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100905 calling_convention.GetReturnLocation(DataType::Type::kReference),
906 DataType::Type::kReference);
Alexey Frunze15958152017-02-09 19:08:30 -0800907
908 RestoreLiveRegisters(codegen, locations);
909 __ B(GetExitLabel());
910 }
911
912 const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathMIPS"; }
913
914 private:
915 Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) {
916 size_t ref = static_cast<int>(ref_.AsRegister<Register>());
917 size_t obj = static_cast<int>(obj_.AsRegister<Register>());
918 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
919 if (i != ref &&
920 i != obj &&
921 !codegen->IsCoreCalleeSaveRegister(i) &&
922 !codegen->IsBlockedCoreRegister(i)) {
923 return static_cast<Register>(i);
924 }
925 }
926 // We shall never fail to find a free caller-save register, as
927 // there are more than two core caller-save registers on MIPS
928 // (meaning it is possible to find one which is different from
929 // `ref` and `obj`).
930 DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u);
931 LOG(FATAL) << "Could not find a free caller-save register";
932 UNREACHABLE();
933 }
934
935 const Location out_;
936 const Location ref_;
937 const Location obj_;
938 const uint32_t offset_;
939 // An additional location containing an index to an array.
940 // Only used for HArrayGet and the UnsafeGetObject &
941 // UnsafeGetObjectVolatile intrinsics.
942 const Location index_;
943
944 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS);
945};
946
947// Slow path generating a read barrier for a GC root.
948class ReadBarrierForRootSlowPathMIPS : public SlowPathCodeMIPS {
949 public:
950 ReadBarrierForRootSlowPathMIPS(HInstruction* instruction, Location out, Location root)
951 : SlowPathCodeMIPS(instruction), out_(out), root_(root) {
952 DCHECK(kEmitCompilerReadBarrier);
953 }
954
955 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
956 LocationSummary* locations = instruction_->GetLocations();
957 Register reg_out = out_.AsRegister<Register>();
958 DCHECK(locations->CanCall());
959 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
960 DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString())
961 << "Unexpected instruction in read barrier for GC root slow path: "
962 << instruction_->DebugName();
963
964 __ Bind(GetEntryLabel());
965 SaveLiveRegisters(codegen, locations);
966
967 InvokeRuntimeCallingConvention calling_convention;
968 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Lena Djokic8098da92017-06-28 12:07:50 +0200969 mips_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
970 root_,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100971 DataType::Type::kReference);
Alexey Frunze15958152017-02-09 19:08:30 -0800972 mips_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow,
973 instruction_,
974 instruction_->GetDexPc(),
975 this);
976 CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>();
Lena Djokic8098da92017-06-28 12:07:50 +0200977 mips_codegen->MoveLocation(out_,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100978 calling_convention.GetReturnLocation(DataType::Type::kReference),
979 DataType::Type::kReference);
Alexey Frunze15958152017-02-09 19:08:30 -0800980
981 RestoreLiveRegisters(codegen, locations);
982 __ B(GetExitLabel());
983 }
984
985 const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS"; }
986
987 private:
988 const Location out_;
989 const Location root_;
990
991 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS);
992};
993
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200994CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph,
995 const MipsInstructionSetFeatures& isa_features,
996 const CompilerOptions& compiler_options,
997 OptimizingCompilerStats* stats)
998 : CodeGenerator(graph,
999 kNumberOfCoreRegisters,
1000 kNumberOfFRegisters,
1001 kNumberOfRegisterPairs,
1002 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
1003 arraysize(kCoreCalleeSaves)),
1004 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
1005 arraysize(kFpuCalleeSaves)),
1006 compiler_options,
1007 stats),
1008 block_labels_(nullptr),
1009 location_builder_(graph, this),
1010 instruction_visitor_(graph, this),
Vladimir Markoca6fff82017-10-03 14:49:14 +01001011 move_resolver_(graph->GetAllocator(), this),
1012 assembler_(graph->GetAllocator(), &isa_features),
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001013 isa_features_(isa_features),
Alexey Frunze06a46c42016-07-19 15:00:40 -07001014 uint32_literals_(std::less<uint32_t>(),
Vladimir Markoca6fff82017-10-03 14:49:14 +01001015 graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1016 pc_relative_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1017 method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1018 pc_relative_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1019 type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1020 pc_relative_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1021 string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1022 jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1023 jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze06a46c42016-07-19 15:00:40 -07001024 clobbered_ra_(false) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001025 // Save RA (containing the return address) to mimic Quick.
1026 AddAllocatedRegister(Location::RegisterLocation(RA));
1027}
1028
1029#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +01001030// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
1031#define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -07001032#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001033
1034void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) {
1035 // Ensure that we fix up branches.
1036 __ FinalizeCode();
1037
1038 // Adjust native pc offsets in stack maps.
Vladimir Marko174b2e22017-10-12 13:34:49 +01001039 StackMapStream* stack_map_stream = GetStackMapStream();
1040 for (size_t i = 0, num = stack_map_stream->GetNumberOfStackMaps(); i != num; ++i) {
Mathieu Chartiera2f526f2017-01-19 14:48:48 -08001041 uint32_t old_position =
Vladimir Marko33bff252017-11-01 14:35:42 +00001042 stack_map_stream->GetStackMap(i).native_pc_code_offset.Uint32Value(InstructionSet::kMips);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001043 uint32_t new_position = __ GetAdjustedPosition(old_position);
1044 DCHECK_GE(new_position, old_position);
Vladimir Marko174b2e22017-10-12 13:34:49 +01001045 stack_map_stream->SetStackMapNativePcOffset(i, new_position);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001046 }
1047
1048 // Adjust pc offsets for the disassembly information.
1049 if (disasm_info_ != nullptr) {
1050 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
1051 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
1052 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
1053 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
1054 it.second.start = __ GetAdjustedPosition(it.second.start);
1055 it.second.end = __ GetAdjustedPosition(it.second.end);
1056 }
1057 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
1058 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
1059 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
1060 }
1061 }
1062
1063 CodeGenerator::Finalize(allocator);
1064}
1065
1066MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const {
1067 return codegen_->GetAssembler();
1068}
1069
1070void ParallelMoveResolverMIPS::EmitMove(size_t index) {
1071 DCHECK_LT(index, moves_.size());
1072 MoveOperands* move = moves_[index];
1073 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
1074}
1075
1076void ParallelMoveResolverMIPS::EmitSwap(size_t index) {
1077 DCHECK_LT(index, moves_.size());
1078 MoveOperands* move = moves_[index];
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001079 DataType::Type type = move->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001080 Location loc1 = move->GetDestination();
1081 Location loc2 = move->GetSource();
1082
1083 DCHECK(!loc1.IsConstant());
1084 DCHECK(!loc2.IsConstant());
1085
1086 if (loc1.Equals(loc2)) {
1087 return;
1088 }
1089
1090 if (loc1.IsRegister() && loc2.IsRegister()) {
1091 // Swap 2 GPRs.
1092 Register r1 = loc1.AsRegister<Register>();
1093 Register r2 = loc2.AsRegister<Register>();
1094 __ Move(TMP, r2);
1095 __ Move(r2, r1);
1096 __ Move(r1, TMP);
1097 } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) {
1098 FRegister f1 = loc1.AsFpuRegister<FRegister>();
1099 FRegister f2 = loc2.AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001100 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001101 __ MovS(FTMP, f2);
1102 __ MovS(f2, f1);
1103 __ MovS(f1, FTMP);
1104 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001105 DCHECK_EQ(type, DataType::Type::kFloat64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001106 __ MovD(FTMP, f2);
1107 __ MovD(f2, f1);
1108 __ MovD(f1, FTMP);
1109 }
1110 } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) ||
1111 (loc1.IsFpuRegister() && loc2.IsRegister())) {
1112 // Swap FPR and GPR.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001113 DCHECK_EQ(type, DataType::Type::kFloat32); // Can only swap a float.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001114 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
1115 : loc2.AsFpuRegister<FRegister>();
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001116 Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001117 __ Move(TMP, r2);
1118 __ Mfc1(r2, f1);
1119 __ Mtc1(TMP, f1);
1120 } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) {
1121 // Swap 2 GPR register pairs.
1122 Register r1 = loc1.AsRegisterPairLow<Register>();
1123 Register r2 = loc2.AsRegisterPairLow<Register>();
1124 __ Move(TMP, r2);
1125 __ Move(r2, r1);
1126 __ Move(r1, TMP);
1127 r1 = loc1.AsRegisterPairHigh<Register>();
1128 r2 = loc2.AsRegisterPairHigh<Register>();
1129 __ Move(TMP, r2);
1130 __ Move(r2, r1);
1131 __ Move(r1, TMP);
1132 } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) ||
1133 (loc1.IsFpuRegister() && loc2.IsRegisterPair())) {
1134 // Swap FPR and GPR register pair.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001135 DCHECK_EQ(type, DataType::Type::kFloat64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001136 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
1137 : loc2.AsFpuRegister<FRegister>();
1138 Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
1139 : loc2.AsRegisterPairLow<Register>();
1140 Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
1141 : loc2.AsRegisterPairHigh<Register>();
1142 // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and
1143 // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR
1144 // unpredictable and the following mfch1 will fail.
1145 __ Mfc1(TMP, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -08001146 __ MoveFromFpuHigh(AT, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001147 __ Mtc1(r2_l, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -08001148 __ MoveToFpuHigh(r2_h, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001149 __ Move(r2_l, TMP);
1150 __ Move(r2_h, AT);
1151 } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) {
1152 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false);
1153 } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) {
1154 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true);
David Brazdilcc0f3112016-01-28 17:14:52 +00001155 } else if ((loc1.IsRegister() && loc2.IsStackSlot()) ||
1156 (loc1.IsStackSlot() && loc2.IsRegister())) {
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001157 Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>();
1158 intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex();
David Brazdilcc0f3112016-01-28 17:14:52 +00001159 __ Move(TMP, reg);
1160 __ LoadFromOffset(kLoadWord, reg, SP, offset);
1161 __ StoreToOffset(kStoreWord, TMP, SP, offset);
1162 } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) ||
1163 (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) {
1164 Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
1165 : loc2.AsRegisterPairLow<Register>();
1166 Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
1167 : loc2.AsRegisterPairHigh<Register>();
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001168 intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex();
David Brazdilcc0f3112016-01-28 17:14:52 +00001169 intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize)
1170 : loc2.GetHighStackIndex(kMipsWordSize);
1171 __ Move(TMP, reg_l);
David Brazdilcc0f3112016-01-28 17:14:52 +00001172 __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l);
David Brazdilcc0f3112016-01-28 17:14:52 +00001173 __ StoreToOffset(kStoreWord, TMP, SP, offset_l);
David Brazdil04d3e872016-01-29 09:50:09 +00001174 __ Move(TMP, reg_h);
1175 __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h);
1176 __ StoreToOffset(kStoreWord, TMP, SP, offset_h);
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001177 } else if (loc1.IsFpuRegister() || loc2.IsFpuRegister()) {
1178 FRegister reg = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
1179 : loc2.AsFpuRegister<FRegister>();
1180 intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001181 if (type == DataType::Type::kFloat32) {
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001182 __ MovS(FTMP, reg);
1183 __ LoadSFromOffset(reg, SP, offset);
1184 __ StoreSToOffset(FTMP, SP, offset);
1185 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001186 DCHECK_EQ(type, DataType::Type::kFloat64);
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001187 __ MovD(FTMP, reg);
1188 __ LoadDFromOffset(reg, SP, offset);
1189 __ StoreDToOffset(FTMP, SP, offset);
1190 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001191 } else {
1192 LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported";
1193 }
1194}
1195
1196void ParallelMoveResolverMIPS::RestoreScratch(int reg) {
1197 __ Pop(static_cast<Register>(reg));
1198}
1199
1200void ParallelMoveResolverMIPS::SpillScratch(int reg) {
1201 __ Push(static_cast<Register>(reg));
1202}
1203
1204void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) {
1205 // Allocate a scratch register other than TMP, if available.
1206 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
1207 // automatically unspilled when the scratch scope object is destroyed).
1208 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
1209 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
Chris Larsen715f43e2017-10-23 11:00:32 -07001210 int stack_offset = ensure_scratch.IsSpilled() ? kStackAlignment : 0;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001211 for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) {
1212 __ LoadFromOffset(kLoadWord,
1213 Register(ensure_scratch.GetRegister()),
1214 SP,
1215 index1 + stack_offset);
1216 __ LoadFromOffset(kLoadWord,
1217 TMP,
1218 SP,
1219 index2 + stack_offset);
1220 __ StoreToOffset(kStoreWord,
1221 Register(ensure_scratch.GetRegister()),
1222 SP,
1223 index2 + stack_offset);
1224 __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset);
1225 }
1226}
1227
Alexey Frunze73296a72016-06-03 22:51:46 -07001228void CodeGeneratorMIPS::ComputeSpillMask() {
1229 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
1230 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
1231 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
1232 // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved
1233 // registers, include the ZERO register to force alignment of FPU callee-saved registers
1234 // within the stack frame.
1235 if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) {
1236 core_spill_mask_ |= (1 << ZERO);
1237 }
Alexey Frunze58320ce2016-08-30 21:40:46 -07001238}
1239
1240bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const {
Alexey Frunze06a46c42016-07-19 15:00:40 -07001241 // If RA is clobbered by PC-relative operations on R2 and it's the only spilled register
Alexey Frunze58320ce2016-08-30 21:40:46 -07001242 // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration()
1243 // into the path that creates a stack frame so that RA can be explicitly saved and restored.
1244 // RA can't otherwise be saved/restored when it's the only spilled register.
Alexey Frunze58320ce2016-08-30 21:40:46 -07001245 return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_;
Alexey Frunze73296a72016-06-03 22:51:46 -07001246}
1247
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001248static dwarf::Reg DWARFReg(Register reg) {
1249 return dwarf::Reg::MipsCore(static_cast<int>(reg));
1250}
1251
1252// TODO: mapping of floating-point registers to DWARF.
1253
1254void CodeGeneratorMIPS::GenerateFrameEntry() {
1255 __ Bind(&frame_entry_label_);
1256
Vladimir Marko33bff252017-11-01 14:35:42 +00001257 bool do_overflow_check =
1258 FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips) || !IsLeafMethod();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001259
1260 if (do_overflow_check) {
1261 __ LoadFromOffset(kLoadWord,
1262 ZERO,
1263 SP,
Vladimir Marko33bff252017-11-01 14:35:42 +00001264 -static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kMips)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001265 RecordPcInfo(nullptr, 0);
1266 }
1267
1268 if (HasEmptyFrame()) {
Alexey Frunze58320ce2016-08-30 21:40:46 -07001269 CHECK_EQ(fpu_spill_mask_, 0u);
1270 CHECK_EQ(core_spill_mask_, 1u << RA);
1271 CHECK(!clobbered_ra_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001272 return;
1273 }
1274
1275 // Make sure the frame size isn't unreasonably large.
Vladimir Marko33bff252017-11-01 14:35:42 +00001276 if (GetFrameSize() > GetStackOverflowReservedBytes(InstructionSet::kMips)) {
1277 LOG(FATAL) << "Stack frame larger than "
1278 << GetStackOverflowReservedBytes(InstructionSet::kMips) << " bytes";
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001279 }
1280
1281 // Spill callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001282
Alexey Frunze73296a72016-06-03 22:51:46 -07001283 uint32_t ofs = GetFrameSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001284 __ IncreaseFrameSize(ofs);
1285
Alexey Frunze73296a72016-06-03 22:51:46 -07001286 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
1287 Register reg = static_cast<Register>(MostSignificantBit(mask));
1288 mask ^= 1u << reg;
1289 ofs -= kMipsWordSize;
1290 // The ZERO register is only included for alignment.
1291 if (reg != ZERO) {
1292 __ StoreToOffset(kStoreWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001293 __ cfi().RelOffset(DWARFReg(reg), ofs);
1294 }
1295 }
1296
Alexey Frunze73296a72016-06-03 22:51:46 -07001297 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
1298 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
1299 mask ^= 1u << reg;
1300 ofs -= kMipsDoublewordSize;
1301 __ StoreDToOffset(reg, SP, ofs);
1302 // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001303 }
1304
Nicolas Geoffray96eeb4e2016-10-12 22:03:31 +01001305 // Save the current method if we need it. Note that we do not
1306 // do this in HCurrentMethod, as the instruction might have been removed
1307 // in the SSA graph.
1308 if (RequiresCurrentMethod()) {
1309 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
1310 }
Goran Jakovljevicc6418422016-12-05 16:31:55 +01001311
1312 if (GetGraph()->HasShouldDeoptimizeFlag()) {
1313 // Initialize should deoptimize flag to 0.
1314 __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag());
1315 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001316}
1317
1318void CodeGeneratorMIPS::GenerateFrameExit() {
1319 __ cfi().RememberState();
1320
1321 if (!HasEmptyFrame()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001322 // Restore callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001323
Alexey Frunze73296a72016-06-03 22:51:46 -07001324 // For better instruction scheduling restore RA before other registers.
1325 uint32_t ofs = GetFrameSize();
1326 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
1327 Register reg = static_cast<Register>(MostSignificantBit(mask));
1328 mask ^= 1u << reg;
1329 ofs -= kMipsWordSize;
1330 // The ZERO register is only included for alignment.
1331 if (reg != ZERO) {
1332 __ LoadFromOffset(kLoadWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001333 __ cfi().Restore(DWARFReg(reg));
1334 }
1335 }
1336
Alexey Frunze73296a72016-06-03 22:51:46 -07001337 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
1338 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
1339 mask ^= 1u << reg;
1340 ofs -= kMipsDoublewordSize;
1341 __ LoadDFromOffset(reg, SP, ofs);
1342 // TODO: __ cfi().Restore(DWARFReg(reg));
1343 }
1344
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001345 size_t frame_size = GetFrameSize();
1346 // Adjust the stack pointer in the delay slot if doing so doesn't break CFI.
1347 bool exchange = IsInt<16>(static_cast<int32_t>(frame_size));
1348 bool reordering = __ SetReorder(false);
1349 if (exchange) {
1350 __ Jr(RA);
1351 __ DecreaseFrameSize(frame_size); // Single instruction in delay slot.
1352 } else {
1353 __ DecreaseFrameSize(frame_size);
1354 __ Jr(RA);
1355 __ Nop(); // In delay slot.
1356 }
1357 __ SetReorder(reordering);
1358 } else {
1359 __ Jr(RA);
1360 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001361 }
1362
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001363 __ cfi().RestoreState();
1364 __ cfi().DefCFAOffset(GetFrameSize());
1365}
1366
1367void CodeGeneratorMIPS::Bind(HBasicBlock* block) {
1368 __ Bind(GetLabelOf(block));
1369}
1370
Lena Djokicca8c2952017-05-29 11:31:46 +02001371VectorRegister VectorRegisterFrom(Location location) {
1372 DCHECK(location.IsFpuRegister());
1373 return static_cast<VectorRegister>(location.AsFpuRegister<FRegister>());
1374}
1375
Lena Djokic8098da92017-06-28 12:07:50 +02001376void CodeGeneratorMIPS::MoveLocation(Location destination,
1377 Location source,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001378 DataType::Type dst_type) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001379 if (source.Equals(destination)) {
1380 return;
1381 }
1382
Lena Djokic8098da92017-06-28 12:07:50 +02001383 if (source.IsConstant()) {
1384 MoveConstant(destination, source.GetConstant());
1385 } else {
1386 if (destination.IsRegister()) {
1387 if (source.IsRegister()) {
1388 __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>());
1389 } else if (source.IsFpuRegister()) {
1390 __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>());
1391 } else {
1392 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001393 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Lena Djokic8098da92017-06-28 12:07:50 +02001394 }
1395 } else if (destination.IsRegisterPair()) {
1396 if (source.IsRegisterPair()) {
1397 __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
1398 __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
1399 } else if (source.IsFpuRegister()) {
1400 Register dst_high = destination.AsRegisterPairHigh<Register>();
1401 Register dst_low = destination.AsRegisterPairLow<Register>();
1402 FRegister src = source.AsFpuRegister<FRegister>();
1403 __ Mfc1(dst_low, src);
1404 __ MoveFromFpuHigh(dst_high, src);
1405 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001406 DCHECK(source.IsDoubleStackSlot())
1407 << "Cannot move from " << source << " to " << destination;
Lena Djokic8098da92017-06-28 12:07:50 +02001408 int32_t off = source.GetStackIndex();
1409 Register r = destination.AsRegisterPairLow<Register>();
1410 __ LoadFromOffset(kLoadDoubleword, r, SP, off);
1411 }
1412 } else if (destination.IsFpuRegister()) {
1413 if (source.IsRegister()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001414 DCHECK(!DataType::Is64BitType(dst_type));
Lena Djokic8098da92017-06-28 12:07:50 +02001415 __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>());
1416 } else if (source.IsRegisterPair()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001417 DCHECK(DataType::Is64BitType(dst_type));
Lena Djokic8098da92017-06-28 12:07:50 +02001418 FRegister dst = destination.AsFpuRegister<FRegister>();
1419 Register src_high = source.AsRegisterPairHigh<Register>();
1420 Register src_low = source.AsRegisterPairLow<Register>();
1421 __ Mtc1(src_low, dst);
1422 __ MoveToFpuHigh(src_high, dst);
1423 } else if (source.IsFpuRegister()) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001424 if (GetGraph()->HasSIMD()) {
1425 __ MoveV(VectorRegisterFrom(destination),
1426 VectorRegisterFrom(source));
Lena Djokic8098da92017-06-28 12:07:50 +02001427 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001428 if (DataType::Is64BitType(dst_type)) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001429 __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
1430 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001431 DCHECK_EQ(dst_type, DataType::Type::kFloat32);
Lena Djokicca8c2952017-05-29 11:31:46 +02001432 __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
1433 }
Lena Djokic8098da92017-06-28 12:07:50 +02001434 }
Lena Djokicca8c2952017-05-29 11:31:46 +02001435 } else if (source.IsSIMDStackSlot()) {
1436 __ LoadQFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
Lena Djokic8098da92017-06-28 12:07:50 +02001437 } else if (source.IsDoubleStackSlot()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001438 DCHECK(DataType::Is64BitType(dst_type));
Lena Djokic8098da92017-06-28 12:07:50 +02001439 __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
1440 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001441 DCHECK(!DataType::Is64BitType(dst_type));
Lena Djokic8098da92017-06-28 12:07:50 +02001442 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
1443 __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
1444 }
Lena Djokicca8c2952017-05-29 11:31:46 +02001445 } else if (destination.IsSIMDStackSlot()) {
1446 if (source.IsFpuRegister()) {
1447 __ StoreQToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex());
1448 } else {
1449 DCHECK(source.IsSIMDStackSlot());
1450 __ LoadQFromOffset(FTMP, SP, source.GetStackIndex());
1451 __ StoreQToOffset(FTMP, SP, destination.GetStackIndex());
1452 }
Lena Djokic8098da92017-06-28 12:07:50 +02001453 } else if (destination.IsDoubleStackSlot()) {
1454 int32_t dst_offset = destination.GetStackIndex();
1455 if (source.IsRegisterPair()) {
1456 __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, dst_offset);
1457 } else if (source.IsFpuRegister()) {
1458 __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset);
1459 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001460 DCHECK(source.IsDoubleStackSlot())
1461 << "Cannot move from " << source << " to " << destination;
Lena Djokic8098da92017-06-28 12:07:50 +02001462 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
1463 __ StoreToOffset(kStoreWord, TMP, SP, dst_offset);
1464 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4);
1465 __ StoreToOffset(kStoreWord, TMP, SP, dst_offset + 4);
1466 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001467 } else {
Lena Djokic8098da92017-06-28 12:07:50 +02001468 DCHECK(destination.IsStackSlot()) << destination;
1469 int32_t dst_offset = destination.GetStackIndex();
1470 if (source.IsRegister()) {
1471 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, dst_offset);
1472 } else if (source.IsFpuRegister()) {
1473 __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset);
1474 } else {
1475 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
1476 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
1477 __ StoreToOffset(kStoreWord, TMP, SP, dst_offset);
1478 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001479 }
1480 }
1481}
1482
1483void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) {
1484 if (c->IsIntConstant() || c->IsNullConstant()) {
1485 // Move 32 bit constant.
1486 int32_t value = GetInt32ValueOf(c);
1487 if (destination.IsRegister()) {
1488 Register dst = destination.AsRegister<Register>();
1489 __ LoadConst32(dst, value);
1490 } else {
1491 DCHECK(destination.IsStackSlot())
1492 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -07001493 __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001494 }
1495 } else if (c->IsLongConstant()) {
1496 // Move 64 bit constant.
1497 int64_t value = GetInt64ValueOf(c);
1498 if (destination.IsRegisterPair()) {
1499 Register r_h = destination.AsRegisterPairHigh<Register>();
1500 Register r_l = destination.AsRegisterPairLow<Register>();
1501 __ LoadConst64(r_h, r_l, value);
1502 } else {
1503 DCHECK(destination.IsDoubleStackSlot())
1504 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -07001505 __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001506 }
1507 } else if (c->IsFloatConstant()) {
1508 // Move 32 bit float constant.
1509 int32_t value = GetInt32ValueOf(c);
1510 if (destination.IsFpuRegister()) {
1511 __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP);
1512 } else {
1513 DCHECK(destination.IsStackSlot())
1514 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -07001515 __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001516 }
1517 } else {
1518 // Move 64 bit double constant.
1519 DCHECK(c->IsDoubleConstant()) << c->DebugName();
1520 int64_t value = GetInt64ValueOf(c);
1521 if (destination.IsFpuRegister()) {
1522 FRegister fd = destination.AsFpuRegister<FRegister>();
1523 __ LoadDConst64(fd, value, TMP);
1524 } else {
1525 DCHECK(destination.IsDoubleStackSlot())
1526 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -07001527 __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001528 }
1529 }
1530}
1531
1532void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) {
1533 DCHECK(destination.IsRegister());
1534 Register dst = destination.AsRegister<Register>();
1535 __ LoadConst32(dst, value);
1536}
1537
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001538void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) {
1539 if (location.IsRegister()) {
1540 locations->AddTemp(location);
Alexey Frunzec9e94f32015-10-26 16:11:39 -07001541 } else if (location.IsRegisterPair()) {
1542 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
1543 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001544 } else {
1545 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
1546 }
1547}
1548
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001549template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
Vladimir Markoaad75c62016-10-03 08:46:48 +00001550inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches(
1551 const ArenaDeque<PcRelativePatchInfo>& infos,
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001552 ArenaVector<linker::LinkerPatch>* linker_patches) {
Vladimir Markoaad75c62016-10-03 08:46:48 +00001553 for (const PcRelativePatchInfo& info : infos) {
1554 const DexFile& dex_file = info.target_dex_file;
1555 size_t offset_or_index = info.offset_or_index;
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001556 DCHECK(info.label.IsBound());
1557 uint32_t literal_offset = __ GetLabelLocation(&info.label);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001558 // On R2 we use HMipsComputeBaseMethodAddress and patch relative to
1559 // the assembler's base label used for PC-relative addressing.
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001560 const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info;
1561 uint32_t pc_rel_offset = info_high.pc_rel_label.IsBound()
1562 ? __ GetLabelLocation(&info_high.pc_rel_label)
Vladimir Markoaad75c62016-10-03 08:46:48 +00001563 : __ GetPcRelBaseLabelLocation();
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001564 linker_patches->push_back(Factory(literal_offset, &dex_file, pc_rel_offset, offset_or_index));
Vladimir Markoaad75c62016-10-03 08:46:48 +00001565 }
1566}
1567
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001568void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001569 DCHECK(linker_patches->empty());
1570 size_t size =
Vladimir Marko65979462017-05-19 17:25:12 +01001571 pc_relative_method_patches_.size() +
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001572 method_bss_entry_patches_.size() +
Alexey Frunze06a46c42016-07-19 15:00:40 -07001573 pc_relative_type_patches_.size() +
Vladimir Marko65979462017-05-19 17:25:12 +01001574 type_bss_entry_patches_.size() +
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01001575 pc_relative_string_patches_.size() +
1576 string_bss_entry_patches_.size();
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001577 linker_patches->reserve(size);
Vladimir Marko65979462017-05-19 17:25:12 +01001578 if (GetCompilerOptions().IsBootImage()) {
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001579 EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>(
1580 pc_relative_method_patches_, linker_patches);
1581 EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>(
1582 pc_relative_type_patches_, linker_patches);
1583 EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>(
1584 pc_relative_string_patches_, linker_patches);
Vladimir Marko65979462017-05-19 17:25:12 +01001585 } else {
1586 DCHECK(pc_relative_method_patches_.empty());
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001587 EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>(
1588 pc_relative_type_patches_, linker_patches);
1589 EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>(
1590 pc_relative_string_patches_, linker_patches);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001591 }
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001592 EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>(
1593 method_bss_entry_patches_, linker_patches);
1594 EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>(
1595 type_bss_entry_patches_, linker_patches);
1596 EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>(
1597 string_bss_entry_patches_, linker_patches);
Vladimir Marko1998cd02017-01-13 13:02:58 +00001598 DCHECK_EQ(size, linker_patches->size());
Alexey Frunze06a46c42016-07-19 15:00:40 -07001599}
1600
Vladimir Marko65979462017-05-19 17:25:12 +01001601CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeMethodPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001602 MethodReference target_method,
1603 const PcRelativePatchInfo* info_high) {
Vladimir Marko65979462017-05-19 17:25:12 +01001604 return NewPcRelativePatch(*target_method.dex_file,
Mathieu Chartierfc8b4222017-09-17 13:44:24 -07001605 target_method.index,
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001606 info_high,
Vladimir Marko65979462017-05-19 17:25:12 +01001607 &pc_relative_method_patches_);
Alexey Frunze06a46c42016-07-19 15:00:40 -07001608}
1609
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001610CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewMethodBssEntryPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001611 MethodReference target_method,
1612 const PcRelativePatchInfo* info_high) {
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001613 return NewPcRelativePatch(*target_method.dex_file,
Mathieu Chartierfc8b4222017-09-17 13:44:24 -07001614 target_method.index,
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001615 info_high,
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001616 &method_bss_entry_patches_);
1617}
1618
Alexey Frunze06a46c42016-07-19 15:00:40 -07001619CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001620 const DexFile& dex_file,
1621 dex::TypeIndex type_index,
1622 const PcRelativePatchInfo* info_high) {
1623 return NewPcRelativePatch(dex_file, type_index.index_, info_high, &pc_relative_type_patches_);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001624}
1625
Vladimir Marko1998cd02017-01-13 13:02:58 +00001626CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewTypeBssEntryPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001627 const DexFile& dex_file,
1628 dex::TypeIndex type_index,
1629 const PcRelativePatchInfo* info_high) {
1630 return NewPcRelativePatch(dex_file, type_index.index_, info_high, &type_bss_entry_patches_);
Vladimir Marko1998cd02017-01-13 13:02:58 +00001631}
1632
Vladimir Marko65979462017-05-19 17:25:12 +01001633CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001634 const DexFile& dex_file,
1635 dex::StringIndex string_index,
1636 const PcRelativePatchInfo* info_high) {
1637 return NewPcRelativePatch(dex_file, string_index.index_, info_high, &pc_relative_string_patches_);
Vladimir Marko65979462017-05-19 17:25:12 +01001638}
1639
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01001640CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewStringBssEntryPatch(
1641 const DexFile& dex_file,
1642 dex::StringIndex string_index,
1643 const PcRelativePatchInfo* info_high) {
1644 return NewPcRelativePatch(dex_file, string_index.index_, info_high, &string_bss_entry_patches_);
1645}
1646
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001647CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001648 const DexFile& dex_file,
1649 uint32_t offset_or_index,
1650 const PcRelativePatchInfo* info_high,
1651 ArenaDeque<PcRelativePatchInfo>* patches) {
1652 patches->emplace_back(dex_file, offset_or_index, info_high);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001653 return &patches->back();
1654}
1655
Alexey Frunze06a46c42016-07-19 15:00:40 -07001656Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
1657 return map->GetOrCreate(
1658 value,
1659 [this, value]() { return __ NewLiteral<uint32_t>(value); });
1660}
1661
Alexey Frunze06a46c42016-07-19 15:00:40 -07001662Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) {
Richard Uhlerc52f3032017-03-02 13:45:45 +00001663 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_);
Alexey Frunze06a46c42016-07-19 15:00:40 -07001664}
1665
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001666void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high,
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001667 Register out,
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001668 Register base) {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001669 DCHECK(!info_high->patch_info_high);
Alexey Frunze6079dca2017-05-28 19:10:28 -07001670 DCHECK_NE(out, base);
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001671 bool reordering = __ SetReorder(false);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001672 if (GetInstructionSetFeatures().IsR6()) {
1673 DCHECK_EQ(base, ZERO);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001674 __ Bind(&info_high->label);
1675 __ Bind(&info_high->pc_rel_label);
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001676 // Add the high half of a 32-bit offset to PC.
Vladimir Markoaad75c62016-10-03 08:46:48 +00001677 __ Auipc(out, /* placeholder */ 0x1234);
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001678 __ SetReorder(reordering);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001679 } else {
1680 // If base is ZERO, emit NAL to obtain the actual base.
1681 if (base == ZERO) {
1682 // Generate a dummy PC-relative call to obtain PC.
1683 __ Nal();
1684 }
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001685 __ Bind(&info_high->label);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001686 __ Lui(out, /* placeholder */ 0x1234);
1687 // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding
1688 // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler.
1689 if (base == ZERO) {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001690 __ Bind(&info_high->pc_rel_label);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001691 }
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001692 __ SetReorder(reordering);
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001693 // Add the high half of a 32-bit offset to PC.
Vladimir Markoaad75c62016-10-03 08:46:48 +00001694 __ Addu(out, out, (base == ZERO) ? RA : base);
1695 }
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001696 // A following instruction will add the sign-extended low half of the 32-bit
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001697 // offset to `out` (e.g. lw, jialc, addiu).
Vladimir Markoaad75c62016-10-03 08:46:48 +00001698}
1699
Alexey Frunze627c1a02017-01-30 19:28:14 -08001700CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootStringPatch(
1701 const DexFile& dex_file,
Vladimir Marko174b2e22017-10-12 13:34:49 +01001702 dex::StringIndex string_index,
Alexey Frunze627c1a02017-01-30 19:28:14 -08001703 Handle<mirror::String> handle) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01001704 ReserveJitStringRoot(StringReference(&dex_file, string_index), handle);
1705 jit_string_patches_.emplace_back(dex_file, string_index.index_);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001706 return &jit_string_patches_.back();
1707}
1708
1709CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootClassPatch(
1710 const DexFile& dex_file,
Vladimir Marko174b2e22017-10-12 13:34:49 +01001711 dex::TypeIndex type_index,
Alexey Frunze627c1a02017-01-30 19:28:14 -08001712 Handle<mirror::Class> handle) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01001713 ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle);
1714 jit_class_patches_.emplace_back(dex_file, type_index.index_);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001715 return &jit_class_patches_.back();
1716}
1717
1718void CodeGeneratorMIPS::PatchJitRootUse(uint8_t* code,
1719 const uint8_t* roots_data,
1720 const CodeGeneratorMIPS::JitPatchInfo& info,
1721 uint64_t index_in_table) const {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001722 uint32_t high_literal_offset = GetAssembler().GetLabelLocation(&info.high_label);
1723 uint32_t low_literal_offset = GetAssembler().GetLabelLocation(&info.low_label);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001724 uintptr_t address =
1725 reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>);
1726 uint32_t addr32 = dchecked_integral_cast<uint32_t>(address);
1727 // lui reg, addr32_high
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001728 DCHECK_EQ(code[high_literal_offset + 0], 0x34);
1729 DCHECK_EQ(code[high_literal_offset + 1], 0x12);
1730 DCHECK_EQ((code[high_literal_offset + 2] & 0xE0), 0x00);
1731 DCHECK_EQ(code[high_literal_offset + 3], 0x3C);
Alexey Frunzec61c0762017-04-10 13:54:23 -07001732 // instr reg, reg, addr32_low
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001733 DCHECK_EQ(code[low_literal_offset + 0], 0x78);
1734 DCHECK_EQ(code[low_literal_offset + 1], 0x56);
Alexey Frunzec61c0762017-04-10 13:54:23 -07001735 addr32 += (addr32 & 0x8000) << 1; // Account for sign extension in "instr reg, reg, addr32_low".
Alexey Frunze627c1a02017-01-30 19:28:14 -08001736 // lui reg, addr32_high
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001737 code[high_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 16);
1738 code[high_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 24);
Alexey Frunzec61c0762017-04-10 13:54:23 -07001739 // instr reg, reg, addr32_low
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001740 code[low_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 0);
1741 code[low_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 8);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001742}
1743
1744void CodeGeneratorMIPS::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) {
1745 for (const JitPatchInfo& info : jit_string_patches_) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01001746 StringReference string_reference(&info.target_dex_file, dex::StringIndex(info.index));
1747 uint64_t index_in_table = GetJitStringRootIndex(string_reference);
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001748 PatchJitRootUse(code, roots_data, info, index_in_table);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001749 }
1750 for (const JitPatchInfo& info : jit_class_patches_) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01001751 TypeReference type_reference(&info.target_dex_file, dex::TypeIndex(info.index));
1752 uint64_t index_in_table = GetJitClassRootIndex(type_reference);
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001753 PatchJitRootUse(code, roots_data, info, index_in_table);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001754 }
1755}
1756
Goran Jakovljevice114da22016-12-26 14:21:43 +01001757void CodeGeneratorMIPS::MarkGCCard(Register object,
1758 Register value,
1759 bool value_can_be_null) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001760 MipsLabel done;
1761 Register card = AT;
1762 Register temp = TMP;
Goran Jakovljevice114da22016-12-26 14:21:43 +01001763 if (value_can_be_null) {
1764 __ Beqz(value, &done);
1765 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001766 __ LoadFromOffset(kLoadWord,
1767 card,
1768 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001769 Thread::CardTableOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001770 __ Srl(temp, object, gc::accounting::CardTable::kCardShift);
1771 __ Addu(temp, card, temp);
1772 __ Sb(card, temp, 0);
Goran Jakovljevice114da22016-12-26 14:21:43 +01001773 if (value_can_be_null) {
1774 __ Bind(&done);
1775 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001776}
1777
David Brazdil58282f42016-01-14 12:45:10 +00001778void CodeGeneratorMIPS::SetupBlockedRegisters() const {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001779 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
1780 blocked_core_registers_[ZERO] = true;
1781 blocked_core_registers_[K0] = true;
1782 blocked_core_registers_[K1] = true;
1783 blocked_core_registers_[GP] = true;
1784 blocked_core_registers_[SP] = true;
1785 blocked_core_registers_[RA] = true;
1786
1787 // AT and TMP(T8) are used as temporary/scratch registers
1788 // (similar to how AT is used by MIPS assemblers).
1789 blocked_core_registers_[AT] = true;
1790 blocked_core_registers_[TMP] = true;
1791 blocked_fpu_registers_[FTMP] = true;
1792
1793 // Reserve suspend and thread registers.
1794 blocked_core_registers_[S0] = true;
1795 blocked_core_registers_[TR] = true;
1796
1797 // Reserve T9 for function calls
1798 blocked_core_registers_[T9] = true;
1799
1800 // Reserve odd-numbered FPU registers.
1801 for (size_t i = 1; i < kNumberOfFRegisters; i += 2) {
1802 blocked_fpu_registers_[i] = true;
1803 }
1804
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02001805 if (GetGraph()->IsDebuggable()) {
1806 // Stubs do not save callee-save floating point registers. If the graph
1807 // is debuggable, we need to deal with these registers differently. For
1808 // now, just block them.
1809 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1810 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1811 }
1812 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001813}
1814
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001815size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1816 __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index);
1817 return kMipsWordSize;
1818}
1819
1820size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1821 __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index);
1822 return kMipsWordSize;
1823}
1824
1825size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001826 if (GetGraph()->HasSIMD()) {
1827 __ StoreQToOffset(FRegister(reg_id), SP, stack_index);
1828 } else {
1829 __ StoreDToOffset(FRegister(reg_id), SP, stack_index);
1830 }
1831 return GetFloatingPointSpillSlotSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001832}
1833
1834size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001835 if (GetGraph()->HasSIMD()) {
1836 __ LoadQFromOffset(FRegister(reg_id), SP, stack_index);
1837 } else {
1838 __ LoadDFromOffset(FRegister(reg_id), SP, stack_index);
1839 }
1840 return GetFloatingPointSpillSlotSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001841}
1842
1843void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001844 stream << Register(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001845}
1846
1847void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001848 stream << FRegister(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001849}
1850
Serban Constantinescufca16662016-07-14 09:21:59 +01001851constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16;
1852
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001853void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint,
1854 HInstruction* instruction,
1855 uint32_t dex_pc,
1856 SlowPathCode* slow_path) {
Alexandre Rames91a65162016-09-19 13:54:30 +01001857 ValidateInvokeRuntime(entrypoint, instruction, slow_path);
Alexey Frunze15958152017-02-09 19:08:30 -08001858 GenerateInvokeRuntime(GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value(),
1859 IsDirectEntrypoint(entrypoint));
1860 if (EntrypointRequiresStackMap(entrypoint)) {
1861 RecordPcInfo(instruction, dex_pc, slow_path);
1862 }
1863}
1864
1865void CodeGeneratorMIPS::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
1866 HInstruction* instruction,
1867 SlowPathCode* slow_path,
1868 bool direct) {
1869 ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path);
1870 GenerateInvokeRuntime(entry_point_offset, direct);
1871}
1872
1873void CodeGeneratorMIPS::GenerateInvokeRuntime(int32_t entry_point_offset, bool direct) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001874 bool reordering = __ SetReorder(false);
Alexey Frunze15958152017-02-09 19:08:30 -08001875 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001876 __ Jalr(T9);
Alexey Frunze15958152017-02-09 19:08:30 -08001877 if (direct) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001878 // Reserve argument space on stack (for $a0-$a3) for
1879 // entrypoints that directly reference native implementations.
1880 // Called function may use this space to store $a0-$a3 regs.
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001881 __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001882 __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001883 } else {
1884 __ Nop(); // In delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001885 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001886 __ SetReorder(reordering);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001887}
1888
1889void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path,
1890 Register class_reg) {
Igor Murashkin86083f72017-10-27 10:59:04 -07001891 __ LoadFromOffset(kLoadSignedByte, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001892 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
1893 __ Blt(TMP, AT, slow_path->GetEntryLabel());
1894 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
1895 __ Sync(0);
1896 __ Bind(slow_path->GetExitLabel());
1897}
1898
1899void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1900 __ Sync(0); // Only stype 0 is supported.
1901}
1902
1903void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction,
1904 HBasicBlock* successor) {
1905 SuspendCheckSlowPathMIPS* slow_path =
Chris Larsena2045912017-11-02 12:39:54 -07001906 down_cast<SuspendCheckSlowPathMIPS*>(instruction->GetSlowPath());
1907
1908 if (slow_path == nullptr) {
1909 slow_path =
1910 new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS(instruction, successor);
1911 instruction->SetSlowPath(slow_path);
1912 codegen_->AddSlowPath(slow_path);
1913 if (successor != nullptr) {
1914 DCHECK(successor->IsLoopHeader());
1915 }
1916 } else {
1917 DCHECK_EQ(slow_path->GetSuccessor(), successor);
1918 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001919
1920 __ LoadFromOffset(kLoadUnsignedHalfword,
1921 TMP,
1922 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001923 Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001924 if (successor == nullptr) {
1925 __ Bnez(TMP, slow_path->GetEntryLabel());
1926 __ Bind(slow_path->GetReturnLabel());
1927 } else {
1928 __ Beqz(TMP, codegen_->GetLabelOf(successor));
1929 __ B(slow_path->GetEntryLabel());
1930 // slow_path will return to GetLabelOf(successor).
1931 }
1932}
1933
1934InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph,
1935 CodeGeneratorMIPS* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001936 : InstructionCodeGenerator(graph, codegen),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001937 assembler_(codegen->GetAssembler()),
1938 codegen_(codegen) {}
1939
1940void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1941 DCHECK_EQ(instruction->InputCount(), 2U);
Vladimir Markoca6fff82017-10-03 14:49:14 +01001942 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001943 DataType::Type type = instruction->GetResultType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001944 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001945 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001946 locations->SetInAt(0, Location::RequiresRegister());
1947 HInstruction* right = instruction->InputAt(1);
1948 bool can_use_imm = false;
1949 if (right->IsConstant()) {
1950 int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant());
1951 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1952 can_use_imm = IsUint<16>(imm);
1953 } else if (instruction->IsAdd()) {
1954 can_use_imm = IsInt<16>(imm);
1955 } else {
1956 DCHECK(instruction->IsSub());
1957 can_use_imm = IsInt<16>(-imm);
1958 }
1959 }
1960 if (can_use_imm)
1961 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1962 else
1963 locations->SetInAt(1, Location::RequiresRegister());
1964 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1965 break;
1966 }
1967
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001968 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001969 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001970 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1971 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001972 break;
1973 }
1974
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001975 case DataType::Type::kFloat32:
1976 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001977 DCHECK(instruction->IsAdd() || instruction->IsSub());
1978 locations->SetInAt(0, Location::RequiresFpuRegister());
1979 locations->SetInAt(1, Location::RequiresFpuRegister());
1980 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1981 break;
1982
1983 default:
1984 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1985 }
1986}
1987
1988void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001989 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001990 LocationSummary* locations = instruction->GetLocations();
1991
1992 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001993 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001994 Register dst = locations->Out().AsRegister<Register>();
1995 Register lhs = locations->InAt(0).AsRegister<Register>();
1996 Location rhs_location = locations->InAt(1);
1997
1998 Register rhs_reg = ZERO;
1999 int32_t rhs_imm = 0;
2000 bool use_imm = rhs_location.IsConstant();
2001 if (use_imm) {
2002 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2003 } else {
2004 rhs_reg = rhs_location.AsRegister<Register>();
2005 }
2006
2007 if (instruction->IsAnd()) {
2008 if (use_imm)
2009 __ Andi(dst, lhs, rhs_imm);
2010 else
2011 __ And(dst, lhs, rhs_reg);
2012 } else if (instruction->IsOr()) {
2013 if (use_imm)
2014 __ Ori(dst, lhs, rhs_imm);
2015 else
2016 __ Or(dst, lhs, rhs_reg);
2017 } else if (instruction->IsXor()) {
2018 if (use_imm)
2019 __ Xori(dst, lhs, rhs_imm);
2020 else
2021 __ Xor(dst, lhs, rhs_reg);
2022 } else if (instruction->IsAdd()) {
2023 if (use_imm)
2024 __ Addiu(dst, lhs, rhs_imm);
2025 else
2026 __ Addu(dst, lhs, rhs_reg);
2027 } else {
2028 DCHECK(instruction->IsSub());
2029 if (use_imm)
2030 __ Addiu(dst, lhs, -rhs_imm);
2031 else
2032 __ Subu(dst, lhs, rhs_reg);
2033 }
2034 break;
2035 }
2036
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002037 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002038 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
2039 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
2040 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2041 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002042 Location rhs_location = locations->InAt(1);
2043 bool use_imm = rhs_location.IsConstant();
2044 if (!use_imm) {
2045 Register rhs_high = rhs_location.AsRegisterPairHigh<Register>();
2046 Register rhs_low = rhs_location.AsRegisterPairLow<Register>();
2047 if (instruction->IsAnd()) {
2048 __ And(dst_low, lhs_low, rhs_low);
2049 __ And(dst_high, lhs_high, rhs_high);
2050 } else if (instruction->IsOr()) {
2051 __ Or(dst_low, lhs_low, rhs_low);
2052 __ Or(dst_high, lhs_high, rhs_high);
2053 } else if (instruction->IsXor()) {
2054 __ Xor(dst_low, lhs_low, rhs_low);
2055 __ Xor(dst_high, lhs_high, rhs_high);
2056 } else if (instruction->IsAdd()) {
2057 if (lhs_low == rhs_low) {
2058 // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs.
2059 __ Slt(TMP, lhs_low, ZERO);
2060 __ Addu(dst_low, lhs_low, rhs_low);
2061 } else {
2062 __ Addu(dst_low, lhs_low, rhs_low);
2063 // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged.
2064 __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low);
2065 }
2066 __ Addu(dst_high, lhs_high, rhs_high);
2067 __ Addu(dst_high, dst_high, TMP);
2068 } else {
2069 DCHECK(instruction->IsSub());
2070 __ Sltu(TMP, lhs_low, rhs_low);
2071 __ Subu(dst_low, lhs_low, rhs_low);
2072 __ Subu(dst_high, lhs_high, rhs_high);
2073 __ Subu(dst_high, dst_high, TMP);
2074 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002075 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002076 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
2077 if (instruction->IsOr()) {
2078 uint32_t low = Low32Bits(value);
2079 uint32_t high = High32Bits(value);
2080 if (IsUint<16>(low)) {
2081 if (dst_low != lhs_low || low != 0) {
2082 __ Ori(dst_low, lhs_low, low);
2083 }
2084 } else {
2085 __ LoadConst32(TMP, low);
2086 __ Or(dst_low, lhs_low, TMP);
2087 }
2088 if (IsUint<16>(high)) {
2089 if (dst_high != lhs_high || high != 0) {
2090 __ Ori(dst_high, lhs_high, high);
2091 }
2092 } else {
2093 if (high != low) {
2094 __ LoadConst32(TMP, high);
2095 }
2096 __ Or(dst_high, lhs_high, TMP);
2097 }
2098 } else if (instruction->IsXor()) {
2099 uint32_t low = Low32Bits(value);
2100 uint32_t high = High32Bits(value);
2101 if (IsUint<16>(low)) {
2102 if (dst_low != lhs_low || low != 0) {
2103 __ Xori(dst_low, lhs_low, low);
2104 }
2105 } else {
2106 __ LoadConst32(TMP, low);
2107 __ Xor(dst_low, lhs_low, TMP);
2108 }
2109 if (IsUint<16>(high)) {
2110 if (dst_high != lhs_high || high != 0) {
2111 __ Xori(dst_high, lhs_high, high);
2112 }
2113 } else {
2114 if (high != low) {
2115 __ LoadConst32(TMP, high);
2116 }
2117 __ Xor(dst_high, lhs_high, TMP);
2118 }
2119 } else if (instruction->IsAnd()) {
2120 uint32_t low = Low32Bits(value);
2121 uint32_t high = High32Bits(value);
2122 if (IsUint<16>(low)) {
2123 __ Andi(dst_low, lhs_low, low);
2124 } else if (low != 0xFFFFFFFF) {
2125 __ LoadConst32(TMP, low);
2126 __ And(dst_low, lhs_low, TMP);
2127 } else if (dst_low != lhs_low) {
2128 __ Move(dst_low, lhs_low);
2129 }
2130 if (IsUint<16>(high)) {
2131 __ Andi(dst_high, lhs_high, high);
2132 } else if (high != 0xFFFFFFFF) {
2133 if (high != low) {
2134 __ LoadConst32(TMP, high);
2135 }
2136 __ And(dst_high, lhs_high, TMP);
2137 } else if (dst_high != lhs_high) {
2138 __ Move(dst_high, lhs_high);
2139 }
2140 } else {
2141 if (instruction->IsSub()) {
2142 value = -value;
2143 } else {
2144 DCHECK(instruction->IsAdd());
2145 }
2146 int32_t low = Low32Bits(value);
2147 int32_t high = High32Bits(value);
2148 if (IsInt<16>(low)) {
2149 if (dst_low != lhs_low || low != 0) {
2150 __ Addiu(dst_low, lhs_low, low);
2151 }
2152 if (low != 0) {
2153 __ Sltiu(AT, dst_low, low);
2154 }
2155 } else {
2156 __ LoadConst32(TMP, low);
2157 __ Addu(dst_low, lhs_low, TMP);
2158 __ Sltu(AT, dst_low, TMP);
2159 }
2160 if (IsInt<16>(high)) {
2161 if (dst_high != lhs_high || high != 0) {
2162 __ Addiu(dst_high, lhs_high, high);
2163 }
2164 } else {
2165 if (high != low) {
2166 __ LoadConst32(TMP, high);
2167 }
2168 __ Addu(dst_high, lhs_high, TMP);
2169 }
2170 if (low != 0) {
2171 __ Addu(dst_high, dst_high, AT);
2172 }
2173 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002174 }
2175 break;
2176 }
2177
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002178 case DataType::Type::kFloat32:
2179 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002180 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
2181 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2182 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2183 if (instruction->IsAdd()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002184 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002185 __ AddS(dst, lhs, rhs);
2186 } else {
2187 __ AddD(dst, lhs, rhs);
2188 }
2189 } else {
2190 DCHECK(instruction->IsSub());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002191 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002192 __ SubS(dst, lhs, rhs);
2193 } else {
2194 __ SubD(dst, lhs, rhs);
2195 }
2196 }
2197 break;
2198 }
2199
2200 default:
2201 LOG(FATAL) << "Unexpected binary operation type " << type;
2202 }
2203}
2204
2205void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002206 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002207
Vladimir Markoca6fff82017-10-03 14:49:14 +01002208 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002209 DataType::Type type = instr->GetResultType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002210 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002211 case DataType::Type::kInt32:
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002212 locations->SetInAt(0, Location::RequiresRegister());
2213 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
2214 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2215 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002216 case DataType::Type::kInt64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002217 locations->SetInAt(0, Location::RequiresRegister());
2218 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
2219 locations->SetOut(Location::RequiresRegister());
2220 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002221 default:
2222 LOG(FATAL) << "Unexpected shift type " << type;
2223 }
2224}
2225
2226static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte;
2227
2228void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002229 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002230 LocationSummary* locations = instr->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002231 DataType::Type type = instr->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002232
2233 Location rhs_location = locations->InAt(1);
2234 bool use_imm = rhs_location.IsConstant();
2235 Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>();
2236 int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0;
Roland Levillain5b5b9312016-03-22 14:57:31 +00002237 const uint32_t shift_mask =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002238 (type == DataType::Type::kInt32) ? kMaxIntShiftDistance : kMaxLongShiftDistance;
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002239 const uint32_t shift_value = rhs_imm & shift_mask;
Alexey Frunze92d90602015-12-18 18:16:36 -08002240 // Are the INS (Insert Bit Field) and ROTR instructions supported?
2241 bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002242
2243 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002244 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002245 Register dst = locations->Out().AsRegister<Register>();
2246 Register lhs = locations->InAt(0).AsRegister<Register>();
2247 if (use_imm) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002248 if (shift_value == 0) {
2249 if (dst != lhs) {
2250 __ Move(dst, lhs);
2251 }
2252 } else if (instr->IsShl()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002253 __ Sll(dst, lhs, shift_value);
2254 } else if (instr->IsShr()) {
2255 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002256 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002257 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002258 } else {
2259 if (has_ins_rotr) {
2260 __ Rotr(dst, lhs, shift_value);
2261 } else {
2262 __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask);
2263 __ Srl(dst, lhs, shift_value);
2264 __ Or(dst, dst, TMP);
2265 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002266 }
2267 } else {
2268 if (instr->IsShl()) {
2269 __ Sllv(dst, lhs, rhs_reg);
2270 } else if (instr->IsShr()) {
2271 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002272 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002273 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002274 } else {
2275 if (has_ins_rotr) {
2276 __ Rotrv(dst, lhs, rhs_reg);
2277 } else {
2278 __ Subu(TMP, ZERO, rhs_reg);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002279 // 32-bit shift instructions use the 5 least significant bits of the shift count, so
2280 // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case
2281 // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out
2282 // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`,
2283 // IOW, the OR'd values are equal.
Alexey Frunze92d90602015-12-18 18:16:36 -08002284 __ Sllv(TMP, lhs, TMP);
2285 __ Srlv(dst, lhs, rhs_reg);
2286 __ Or(dst, dst, TMP);
2287 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002288 }
2289 }
2290 break;
2291 }
2292
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002293 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002294 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
2295 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
2296 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2297 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
2298 if (use_imm) {
2299 if (shift_value == 0) {
Lena Djokic8098da92017-06-28 12:07:50 +02002300 codegen_->MoveLocation(locations->Out(), locations->InAt(0), type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002301 } else if (shift_value < kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002302 if (has_ins_rotr) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002303 if (instr->IsShl()) {
2304 __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
2305 __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value);
2306 __ Sll(dst_low, lhs_low, shift_value);
2307 } else if (instr->IsShr()) {
2308 __ Srl(dst_low, lhs_low, shift_value);
2309 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
2310 __ Sra(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002311 } else if (instr->IsUShr()) {
2312 __ Srl(dst_low, lhs_low, shift_value);
2313 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
2314 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002315 } else {
2316 __ Srl(dst_low, lhs_low, shift_value);
2317 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
2318 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002319 __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002320 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002321 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002322 if (instr->IsShl()) {
2323 __ Sll(dst_low, lhs_low, shift_value);
2324 __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value);
2325 __ Sll(dst_high, lhs_high, shift_value);
2326 __ Or(dst_high, dst_high, TMP);
2327 } else if (instr->IsShr()) {
2328 __ Sra(dst_high, lhs_high, shift_value);
2329 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
2330 __ Srl(dst_low, lhs_low, shift_value);
2331 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08002332 } else if (instr->IsUShr()) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002333 __ Srl(dst_high, lhs_high, shift_value);
2334 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
2335 __ Srl(dst_low, lhs_low, shift_value);
2336 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08002337 } else {
2338 __ Srl(TMP, lhs_low, shift_value);
2339 __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value);
2340 __ Or(dst_low, dst_low, TMP);
2341 __ Srl(TMP, lhs_high, shift_value);
2342 __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
2343 __ Or(dst_high, dst_high, TMP);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002344 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002345 }
2346 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002347 const uint32_t shift_value_high = shift_value - kMipsBitsPerWord;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002348 if (instr->IsShl()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002349 __ Sll(dst_high, lhs_low, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002350 __ Move(dst_low, ZERO);
2351 } else if (instr->IsShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002352 __ Sra(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002353 __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1);
Alexey Frunze92d90602015-12-18 18:16:36 -08002354 } else if (instr->IsUShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002355 __ Srl(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002356 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08002357 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002358 if (shift_value == kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002359 // 64-bit rotation by 32 is just a swap.
2360 __ Move(dst_low, lhs_high);
2361 __ Move(dst_high, lhs_low);
2362 } else {
2363 if (has_ins_rotr) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002364 __ Srl(dst_low, lhs_high, shift_value_high);
2365 __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high);
2366 __ Srl(dst_high, lhs_low, shift_value_high);
2367 __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08002368 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002369 __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high);
2370 __ Srl(dst_low, lhs_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08002371 __ Or(dst_low, dst_low, TMP);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002372 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high);
2373 __ Srl(dst_high, lhs_low, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08002374 __ Or(dst_high, dst_high, TMP);
2375 }
2376 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002377 }
2378 }
2379 } else {
Chris Larsen3e5fecd2017-11-09 14:21:28 -08002380 const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002381 MipsLabel done;
2382 if (instr->IsShl()) {
2383 __ Sllv(dst_low, lhs_low, rhs_reg);
2384 __ Nor(AT, ZERO, rhs_reg);
2385 __ Srl(TMP, lhs_low, 1);
2386 __ Srlv(TMP, TMP, AT);
2387 __ Sllv(dst_high, lhs_high, rhs_reg);
2388 __ Or(dst_high, dst_high, TMP);
2389 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
Chris Larsen3e5fecd2017-11-09 14:21:28 -08002390 if (isR6) {
2391 __ Beqzc(TMP, &done, /* is_bare */ true);
2392 __ Move(dst_high, dst_low);
2393 __ Move(dst_low, ZERO);
2394 } else {
2395 __ Movn(dst_high, dst_low, TMP);
2396 __ Movn(dst_low, ZERO, TMP);
2397 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002398 } else if (instr->IsShr()) {
2399 __ Srav(dst_high, lhs_high, rhs_reg);
2400 __ Nor(AT, ZERO, rhs_reg);
2401 __ Sll(TMP, lhs_high, 1);
2402 __ Sllv(TMP, TMP, AT);
2403 __ Srlv(dst_low, lhs_low, rhs_reg);
2404 __ Or(dst_low, dst_low, TMP);
2405 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
Chris Larsen3e5fecd2017-11-09 14:21:28 -08002406 if (isR6) {
2407 __ Beqzc(TMP, &done, /* is_bare */ true);
2408 __ Move(dst_low, dst_high);
2409 __ Sra(dst_high, dst_high, 31);
2410 } else {
2411 __ Sra(AT, dst_high, 31);
2412 __ Movn(dst_low, dst_high, TMP);
2413 __ Movn(dst_high, AT, TMP);
2414 }
Alexey Frunze92d90602015-12-18 18:16:36 -08002415 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002416 __ Srlv(dst_high, lhs_high, rhs_reg);
2417 __ Nor(AT, ZERO, rhs_reg);
2418 __ Sll(TMP, lhs_high, 1);
2419 __ Sllv(TMP, TMP, AT);
2420 __ Srlv(dst_low, lhs_low, rhs_reg);
2421 __ Or(dst_low, dst_low, TMP);
2422 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
Chris Larsen3e5fecd2017-11-09 14:21:28 -08002423 if (isR6) {
2424 __ Beqzc(TMP, &done, /* is_bare */ true);
2425 __ Move(dst_low, dst_high);
2426 __ Move(dst_high, ZERO);
2427 } else {
2428 __ Movn(dst_low, dst_high, TMP);
2429 __ Movn(dst_high, ZERO, TMP);
2430 }
2431 } else { // Rotate.
Alexey Frunze92d90602015-12-18 18:16:36 -08002432 __ Nor(AT, ZERO, rhs_reg);
2433 __ Srlv(TMP, lhs_low, rhs_reg);
2434 __ Sll(dst_low, lhs_high, 1);
2435 __ Sllv(dst_low, dst_low, AT);
2436 __ Or(dst_low, dst_low, TMP);
2437 __ Srlv(TMP, lhs_high, rhs_reg);
2438 __ Sll(dst_high, lhs_low, 1);
2439 __ Sllv(dst_high, dst_high, AT);
2440 __ Or(dst_high, dst_high, TMP);
2441 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
Chris Larsen3e5fecd2017-11-09 14:21:28 -08002442 if (isR6) {
2443 __ Beqzc(TMP, &done, /* is_bare */ true);
2444 __ Move(TMP, dst_high);
2445 __ Move(dst_high, dst_low);
2446 __ Move(dst_low, TMP);
2447 } else {
2448 __ Movn(AT, dst_high, TMP);
2449 __ Movn(dst_high, dst_low, TMP);
2450 __ Movn(dst_low, AT, TMP);
2451 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002452 }
2453 __ Bind(&done);
2454 }
2455 break;
2456 }
2457
2458 default:
2459 LOG(FATAL) << "Unexpected shift operation type " << type;
2460 }
2461}
2462
2463void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) {
2464 HandleBinaryOp(instruction);
2465}
2466
2467void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) {
2468 HandleBinaryOp(instruction);
2469}
2470
2471void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) {
2472 HandleBinaryOp(instruction);
2473}
2474
2475void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) {
2476 HandleBinaryOp(instruction);
2477}
2478
2479void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002480 DataType::Type type = instruction->GetType();
Alexey Frunze15958152017-02-09 19:08:30 -08002481 bool object_array_get_with_read_barrier =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002482 kEmitCompilerReadBarrier && (type == DataType::Type::kReference);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002483 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01002484 new (GetGraph()->GetAllocator()) LocationSummary(instruction,
2485 object_array_get_with_read_barrier
2486 ? LocationSummary::kCallOnSlowPath
2487 : LocationSummary::kNoCall);
Alexey Frunzec61c0762017-04-10 13:54:23 -07002488 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
2489 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
2490 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002491 locations->SetInAt(0, Location::RequiresRegister());
2492 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002493 if (DataType::IsFloatingPointType(type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002494 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2495 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08002496 // The output overlaps in the case of an object array get with
2497 // read barriers enabled: we do not want the move to overwrite the
2498 // array's location, as we need it to emit the read barrier.
2499 locations->SetOut(Location::RequiresRegister(),
2500 object_array_get_with_read_barrier
2501 ? Location::kOutputOverlap
2502 : Location::kNoOutputOverlap);
2503 }
2504 // We need a temporary register for the read barrier marking slow
2505 // path in CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier.
2506 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002507 bool temp_needed = instruction->GetIndex()->IsConstant()
2508 ? !kBakerReadBarrierThunksEnableForFields
2509 : !kBakerReadBarrierThunksEnableForArrays;
2510 if (temp_needed) {
2511 locations->AddTemp(Location::RequiresRegister());
2512 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002513 }
2514}
2515
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002516static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS* codegen) {
2517 auto null_checker = [codegen, instruction]() {
2518 codegen->MaybeRecordImplicitNullCheck(instruction);
Alexey Frunze2923db72016-08-20 01:55:47 -07002519 };
2520 return null_checker;
2521}
2522
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002523void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) {
2524 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08002525 Location obj_loc = locations->InAt(0);
2526 Register obj = obj_loc.AsRegister<Register>();
2527 Location out_loc = locations->Out();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002528 Location index = locations->InAt(1);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01002529 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002530 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002531
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002532 DataType::Type type = instruction->GetType();
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002533 const bool maybe_compressed_char_at = mirror::kUseStringCompression &&
2534 instruction->IsStringCharAt();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002535 switch (type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002536 case DataType::Type::kBool:
2537 case DataType::Type::kUint8: {
Alexey Frunze15958152017-02-09 19:08:30 -08002538 Register out = out_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002539 if (index.IsConstant()) {
2540 size_t offset =
2541 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002542 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002543 } else {
2544 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07002545 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002546 }
2547 break;
2548 }
2549
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002550 case DataType::Type::kInt8: {
Alexey Frunze15958152017-02-09 19:08:30 -08002551 Register out = out_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002552 if (index.IsConstant()) {
2553 size_t offset =
2554 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002555 __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002556 } else {
2557 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07002558 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002559 }
2560 break;
2561 }
2562
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002563 case DataType::Type::kUint16: {
Alexey Frunze15958152017-02-09 19:08:30 -08002564 Register out = out_loc.AsRegister<Register>();
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002565 if (maybe_compressed_char_at) {
2566 uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
2567 __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker);
2568 __ Sll(TMP, TMP, 31); // Extract compression flag into the most significant bit of TMP.
2569 static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u,
2570 "Expecting 0=compressed, 1=uncompressed");
2571 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002572 if (index.IsConstant()) {
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002573 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
2574 if (maybe_compressed_char_at) {
2575 MipsLabel uncompressed_load, done;
2576 __ Bnez(TMP, &uncompressed_load);
2577 __ LoadFromOffset(kLoadUnsignedByte,
2578 out,
2579 obj,
2580 data_offset + (const_index << TIMES_1));
2581 __ B(&done);
2582 __ Bind(&uncompressed_load);
2583 __ LoadFromOffset(kLoadUnsignedHalfword,
2584 out,
2585 obj,
2586 data_offset + (const_index << TIMES_2));
2587 __ Bind(&done);
2588 } else {
2589 __ LoadFromOffset(kLoadUnsignedHalfword,
2590 out,
2591 obj,
2592 data_offset + (const_index << TIMES_2),
2593 null_checker);
2594 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002595 } else {
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002596 Register index_reg = index.AsRegister<Register>();
2597 if (maybe_compressed_char_at) {
2598 MipsLabel uncompressed_load, done;
2599 __ Bnez(TMP, &uncompressed_load);
2600 __ Addu(TMP, obj, index_reg);
2601 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset);
2602 __ B(&done);
2603 __ Bind(&uncompressed_load);
Chris Larsencd0295d2017-03-31 15:26:54 -07002604 __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002605 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset);
2606 __ Bind(&done);
Lena Djokica2901602017-09-21 13:50:52 +02002607 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2608 __ Addu(TMP, index_reg, obj);
2609 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002610 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002611 __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002612 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker);
2613 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002614 }
2615 break;
2616 }
2617
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002618 case DataType::Type::kInt16: {
2619 Register out = out_loc.AsRegister<Register>();
2620 if (index.IsConstant()) {
2621 size_t offset =
2622 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2623 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker);
Lena Djokica2901602017-09-21 13:50:52 +02002624 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2625 __ Addu(TMP, index.AsRegister<Register>(), obj);
2626 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker);
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002627 } else {
2628 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_2, TMP);
2629 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker);
2630 }
2631 break;
2632 }
2633
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002634 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002635 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
Alexey Frunze15958152017-02-09 19:08:30 -08002636 Register out = out_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002637 if (index.IsConstant()) {
2638 size_t offset =
2639 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002640 __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker);
Lena Djokica2901602017-09-21 13:50:52 +02002641 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2642 __ Addu(TMP, index.AsRegister<Register>(), obj);
2643 __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002644 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002645 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002646 __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002647 }
2648 break;
2649 }
2650
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002651 case DataType::Type::kReference: {
Alexey Frunze15958152017-02-09 19:08:30 -08002652 static_assert(
2653 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
2654 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
2655 // /* HeapReference<Object> */ out =
2656 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
2657 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002658 bool temp_needed = index.IsConstant()
2659 ? !kBakerReadBarrierThunksEnableForFields
2660 : !kBakerReadBarrierThunksEnableForArrays;
2661 Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation();
Alexey Frunze15958152017-02-09 19:08:30 -08002662 // Note that a potential implicit null check is handled in this
2663 // CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier call.
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002664 DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0)));
2665 if (index.IsConstant()) {
2666 // Array load with a constant index can be treated as a field load.
2667 size_t offset =
2668 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2669 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
2670 out_loc,
2671 obj,
2672 offset,
2673 temp,
2674 /* needs_null_check */ false);
2675 } else {
2676 codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction,
2677 out_loc,
2678 obj,
2679 data_offset,
2680 index,
2681 temp,
2682 /* needs_null_check */ false);
2683 }
Alexey Frunze15958152017-02-09 19:08:30 -08002684 } else {
2685 Register out = out_loc.AsRegister<Register>();
2686 if (index.IsConstant()) {
2687 size_t offset =
2688 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2689 __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker);
2690 // If read barriers are enabled, emit read barriers other than
2691 // Baker's using a slow path (and also unpoison the loaded
2692 // reference, if heap poisoning is enabled).
2693 codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
2694 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002695 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP);
Alexey Frunze15958152017-02-09 19:08:30 -08002696 __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
2697 // If read barriers are enabled, emit read barriers other than
2698 // Baker's using a slow path (and also unpoison the loaded
2699 // reference, if heap poisoning is enabled).
2700 codegen_->MaybeGenerateReadBarrierSlow(instruction,
2701 out_loc,
2702 out_loc,
2703 obj_loc,
2704 data_offset,
2705 index);
2706 }
2707 }
2708 break;
2709 }
2710
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002711 case DataType::Type::kInt64: {
Alexey Frunze15958152017-02-09 19:08:30 -08002712 Register out = out_loc.AsRegisterPairLow<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002713 if (index.IsConstant()) {
2714 size_t offset =
2715 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002716 __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker);
Lena Djokica2901602017-09-21 13:50:52 +02002717 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2718 __ Addu(TMP, index.AsRegister<Register>(), obj);
2719 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002720 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002721 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002722 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002723 }
2724 break;
2725 }
2726
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002727 case DataType::Type::kFloat32: {
Alexey Frunze15958152017-02-09 19:08:30 -08002728 FRegister out = out_loc.AsFpuRegister<FRegister>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002729 if (index.IsConstant()) {
2730 size_t offset =
2731 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002732 __ LoadSFromOffset(out, obj, offset, null_checker);
Lena Djokica2901602017-09-21 13:50:52 +02002733 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2734 __ Addu(TMP, index.AsRegister<Register>(), obj);
2735 __ LoadSFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002736 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002737 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002738 __ LoadSFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002739 }
2740 break;
2741 }
2742
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002743 case DataType::Type::kFloat64: {
Alexey Frunze15958152017-02-09 19:08:30 -08002744 FRegister out = out_loc.AsFpuRegister<FRegister>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002745 if (index.IsConstant()) {
2746 size_t offset =
2747 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002748 __ LoadDFromOffset(out, obj, offset, null_checker);
Lena Djokica2901602017-09-21 13:50:52 +02002749 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2750 __ Addu(TMP, index.AsRegister<Register>(), obj);
2751 __ LoadDFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002752 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002753 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002754 __ LoadDFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002755 }
2756 break;
2757 }
2758
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002759 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002760 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2761 UNREACHABLE();
2762 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002763}
2764
2765void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01002766 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002767 locations->SetInAt(0, Location::RequiresRegister());
2768 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2769}
2770
2771void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) {
2772 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01002773 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002774 Register obj = locations->InAt(0).AsRegister<Register>();
2775 Register out = locations->Out().AsRegister<Register>();
2776 __ LoadFromOffset(kLoadWord, out, obj, offset);
2777 codegen_->MaybeRecordImplicitNullCheck(instruction);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002778 // Mask out compression flag from String's array length.
2779 if (mirror::kUseStringCompression && instruction->IsStringLength()) {
2780 __ Srl(out, out, 1u);
2781 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002782}
2783
Alexey Frunzef58b2482016-09-02 22:14:06 -07002784Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) {
2785 return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern())
2786 ? Location::ConstantLocation(instruction->AsConstant())
2787 : Location::RequiresRegister();
2788}
2789
2790Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) {
2791 // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register.
2792 // We can store a non-zero float or double constant without first loading it into the FPU,
2793 // but we should only prefer this if the constant has a single use.
2794 if (instruction->IsConstant() &&
2795 (instruction->AsConstant()->IsZeroBitPattern() ||
2796 instruction->GetUses().HasExactlyOneElement())) {
2797 return Location::ConstantLocation(instruction->AsConstant());
2798 // Otherwise fall through and require an FPU register for the constant.
2799 }
2800 return Location::RequiresFpuRegister();
2801}
2802
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002803void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002804 DataType::Type value_type = instruction->GetComponentType();
Alexey Frunze15958152017-02-09 19:08:30 -08002805
2806 bool needs_write_barrier =
2807 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
2808 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
2809
Vladimir Markoca6fff82017-10-03 14:49:14 +01002810 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002811 instruction,
Alexey Frunze15958152017-02-09 19:08:30 -08002812 may_need_runtime_call_for_type_check ?
2813 LocationSummary::kCallOnSlowPath :
2814 LocationSummary::kNoCall);
2815
2816 locations->SetInAt(0, Location::RequiresRegister());
2817 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002818 if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
Alexey Frunze15958152017-02-09 19:08:30 -08002819 locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002820 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08002821 locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2)));
2822 }
2823 if (needs_write_barrier) {
2824 // Temporary register for the write barrier.
2825 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002826 }
2827}
2828
2829void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) {
2830 LocationSummary* locations = instruction->GetLocations();
2831 Register obj = locations->InAt(0).AsRegister<Register>();
2832 Location index = locations->InAt(1);
Alexey Frunzef58b2482016-09-02 22:14:06 -07002833 Location value_location = locations->InAt(2);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002834 DataType::Type value_type = instruction->GetComponentType();
Alexey Frunze15958152017-02-09 19:08:30 -08002835 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002836 bool needs_write_barrier =
2837 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002838 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Alexey Frunzef58b2482016-09-02 22:14:06 -07002839 Register base_reg = index.IsConstant() ? obj : TMP;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002840
2841 switch (value_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002842 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002843 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002844 case DataType::Type::kInt8: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002845 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002846 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002847 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002848 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002849 __ Addu(base_reg, obj, index.AsRegister<Register>());
2850 }
2851 if (value_location.IsConstant()) {
2852 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2853 __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker);
2854 } else {
2855 Register value = value_location.AsRegister<Register>();
2856 __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002857 }
2858 break;
2859 }
2860
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002861 case DataType::Type::kUint16:
2862 case DataType::Type::kInt16: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002863 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002864 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002865 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2;
Lena Djokica2901602017-09-21 13:50:52 +02002866 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2867 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002868 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002869 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_2, base_reg);
Alexey Frunzef58b2482016-09-02 22:14:06 -07002870 }
2871 if (value_location.IsConstant()) {
2872 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2873 __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker);
2874 } else {
2875 Register value = value_location.AsRegister<Register>();
2876 __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002877 }
2878 break;
2879 }
2880
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002881 case DataType::Type::kInt32: {
Alexey Frunze15958152017-02-09 19:08:30 -08002882 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2883 if (index.IsConstant()) {
2884 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Lena Djokica2901602017-09-21 13:50:52 +02002885 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2886 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Alexey Frunze15958152017-02-09 19:08:30 -08002887 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002888 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg);
Alexey Frunze15958152017-02-09 19:08:30 -08002889 }
2890 if (value_location.IsConstant()) {
2891 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2892 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2893 } else {
2894 Register value = value_location.AsRegister<Register>();
2895 __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
2896 }
2897 break;
2898 }
2899
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002900 case DataType::Type::kReference: {
Alexey Frunze15958152017-02-09 19:08:30 -08002901 if (value_location.IsConstant()) {
2902 // Just setting null.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002903 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002904 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002905 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002906 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002907 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002908 }
Alexey Frunze15958152017-02-09 19:08:30 -08002909 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2910 DCHECK_EQ(value, 0);
2911 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2912 DCHECK(!needs_write_barrier);
2913 DCHECK(!may_need_runtime_call_for_type_check);
2914 break;
2915 }
2916
2917 DCHECK(needs_write_barrier);
2918 Register value = value_location.AsRegister<Register>();
2919 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2920 Register temp2 = TMP; // Doesn't need to survive slow path.
2921 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2922 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
2923 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
2924 MipsLabel done;
2925 SlowPathCodeMIPS* slow_path = nullptr;
2926
2927 if (may_need_runtime_call_for_type_check) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01002928 slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS(instruction);
Alexey Frunze15958152017-02-09 19:08:30 -08002929 codegen_->AddSlowPath(slow_path);
2930 if (instruction->GetValueCanBeNull()) {
2931 MipsLabel non_zero;
2932 __ Bnez(value, &non_zero);
2933 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2934 if (index.IsConstant()) {
2935 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Lena Djokica2901602017-09-21 13:50:52 +02002936 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2937 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Alexey Frunzec061de12017-02-14 13:27:23 -08002938 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002939 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg);
Alexey Frunzec061de12017-02-14 13:27:23 -08002940 }
Alexey Frunze15958152017-02-09 19:08:30 -08002941 __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
2942 __ B(&done);
2943 __ Bind(&non_zero);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002944 }
Alexey Frunze15958152017-02-09 19:08:30 -08002945
2946 // Note that when read barriers are enabled, the type checks
2947 // are performed without read barriers. This is fine, even in
2948 // the case where a class object is in the from-space after
2949 // the flip, as a comparison involving such a type would not
2950 // produce a false positive; it may of course produce a false
2951 // negative, in which case we would take the ArraySet slow
2952 // path.
2953
2954 // /* HeapReference<Class> */ temp1 = obj->klass_
2955 __ LoadFromOffset(kLoadWord, temp1, obj, class_offset, null_checker);
2956 __ MaybeUnpoisonHeapReference(temp1);
2957
2958 // /* HeapReference<Class> */ temp1 = temp1->component_type_
2959 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
2960 // /* HeapReference<Class> */ temp2 = value->klass_
2961 __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
2962 // If heap poisoning is enabled, no need to unpoison `temp1`
2963 // nor `temp2`, as we are comparing two poisoned references.
2964
2965 if (instruction->StaticTypeOfArrayIsObjectArray()) {
2966 MipsLabel do_put;
2967 __ Beq(temp1, temp2, &do_put);
2968 // If heap poisoning is enabled, the `temp1` reference has
2969 // not been unpoisoned yet; unpoison it now.
2970 __ MaybeUnpoisonHeapReference(temp1);
2971
2972 // /* HeapReference<Class> */ temp1 = temp1->super_class_
2973 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
2974 // If heap poisoning is enabled, no need to unpoison
2975 // `temp1`, as we are comparing against null below.
2976 __ Bnez(temp1, slow_path->GetEntryLabel());
2977 __ Bind(&do_put);
2978 } else {
2979 __ Bne(temp1, temp2, slow_path->GetEntryLabel());
2980 }
2981 }
2982
2983 Register source = value;
2984 if (kPoisonHeapReferences) {
2985 // Note that in the case where `value` is a null reference,
2986 // we do not enter this block, as a null reference does not
2987 // need poisoning.
2988 __ Move(temp1, value);
2989 __ PoisonHeapReference(temp1);
2990 source = temp1;
2991 }
2992
2993 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2994 if (index.IsConstant()) {
2995 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002996 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002997 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg);
Alexey Frunze15958152017-02-09 19:08:30 -08002998 }
2999 __ StoreToOffset(kStoreWord, source, base_reg, data_offset);
3000
3001 if (!may_need_runtime_call_for_type_check) {
3002 codegen_->MaybeRecordImplicitNullCheck(instruction);
3003 }
3004
3005 codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull());
3006
3007 if (done.IsLinked()) {
3008 __ Bind(&done);
3009 }
3010
3011 if (slow_path != nullptr) {
3012 __ Bind(slow_path->GetExitLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003013 }
3014 break;
3015 }
3016
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003017 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003018 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003019 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07003020 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Lena Djokica2901602017-09-21 13:50:52 +02003021 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
3022 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003023 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07003024 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg);
Alexey Frunzef58b2482016-09-02 22:14:06 -07003025 }
3026 if (value_location.IsConstant()) {
3027 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
3028 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
3029 } else {
3030 Register value = value_location.AsRegisterPairLow<Register>();
3031 __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003032 }
3033 break;
3034 }
3035
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003036 case DataType::Type::kFloat32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003037 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003038 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07003039 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Lena Djokica2901602017-09-21 13:50:52 +02003040 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
3041 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003042 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07003043 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg);
Alexey Frunzef58b2482016-09-02 22:14:06 -07003044 }
3045 if (value_location.IsConstant()) {
3046 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
3047 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
3048 } else {
3049 FRegister value = value_location.AsFpuRegister<FRegister>();
3050 __ StoreSToOffset(value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003051 }
3052 break;
3053 }
3054
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003055 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003056 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003057 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07003058 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Lena Djokica2901602017-09-21 13:50:52 +02003059 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
3060 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003061 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07003062 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg);
Alexey Frunzef58b2482016-09-02 22:14:06 -07003063 }
3064 if (value_location.IsConstant()) {
3065 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
3066 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
3067 } else {
3068 FRegister value = value_location.AsFpuRegister<FRegister>();
3069 __ StoreDToOffset(value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003070 }
3071 break;
3072 }
3073
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003074 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003075 LOG(FATAL) << "Unreachable type " << instruction->GetType();
3076 UNREACHABLE();
3077 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003078}
3079
Lena Djokica2901602017-09-21 13:50:52 +02003080void LocationsBuilderMIPS::VisitIntermediateArrayAddressIndex(
3081 HIntermediateArrayAddressIndex* instruction) {
3082 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003083 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Lena Djokica2901602017-09-21 13:50:52 +02003084
3085 HIntConstant* shift = instruction->GetShift()->AsIntConstant();
3086
3087 locations->SetInAt(0, Location::RequiresRegister());
3088 locations->SetInAt(1, Location::ConstantLocation(shift));
3089 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3090}
3091
3092void InstructionCodeGeneratorMIPS::VisitIntermediateArrayAddressIndex(
3093 HIntermediateArrayAddressIndex* instruction) {
3094 LocationSummary* locations = instruction->GetLocations();
3095 Register index_reg = locations->InAt(0).AsRegister<Register>();
3096 uint32_t shift = instruction->GetShift()->AsIntConstant()->GetValue();
3097 __ Sll(locations->Out().AsRegister<Register>(), index_reg, shift);
3098}
3099
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003100void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01003101 RegisterSet caller_saves = RegisterSet::Empty();
3102 InvokeRuntimeCallingConvention calling_convention;
3103 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3104 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3105 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves);
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01003106
3107 HInstruction* index = instruction->InputAt(0);
3108 HInstruction* length = instruction->InputAt(1);
3109
3110 bool const_index = false;
3111 bool const_length = false;
3112
3113 if (index->IsConstant()) {
3114 if (length->IsConstant()) {
3115 const_index = true;
3116 const_length = true;
3117 } else {
3118 int32_t index_value = index->AsIntConstant()->GetValue();
3119 if (index_value < 0 || IsInt<16>(index_value + 1)) {
3120 const_index = true;
3121 }
3122 }
3123 } else if (length->IsConstant()) {
3124 int32_t length_value = length->AsIntConstant()->GetValue();
3125 if (IsUint<15>(length_value)) {
3126 const_length = true;
3127 }
3128 }
3129
3130 locations->SetInAt(0, const_index
3131 ? Location::ConstantLocation(index->AsConstant())
3132 : Location::RequiresRegister());
3133 locations->SetInAt(1, const_length
3134 ? Location::ConstantLocation(length->AsConstant())
3135 : Location::RequiresRegister());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003136}
3137
3138void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
3139 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01003140 Location index_loc = locations->InAt(0);
3141 Location length_loc = locations->InAt(1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003142
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01003143 if (length_loc.IsConstant()) {
3144 int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue();
3145 if (index_loc.IsConstant()) {
3146 int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue();
3147 if (index < 0 || index >= length) {
3148 BoundsCheckSlowPathMIPS* slow_path =
3149 new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction);
3150 codegen_->AddSlowPath(slow_path);
3151 __ B(slow_path->GetEntryLabel());
3152 } else {
3153 // Nothing to be done.
3154 }
3155 return;
3156 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003157
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01003158 BoundsCheckSlowPathMIPS* slow_path =
3159 new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction);
3160 codegen_->AddSlowPath(slow_path);
3161 Register index = index_loc.AsRegister<Register>();
3162 if (length == 0) {
3163 __ B(slow_path->GetEntryLabel());
3164 } else if (length == 1) {
3165 __ Bnez(index, slow_path->GetEntryLabel());
3166 } else {
3167 DCHECK(IsUint<15>(length)) << length;
3168 __ Sltiu(TMP, index, length);
3169 __ Beqz(TMP, slow_path->GetEntryLabel());
3170 }
3171 } else {
3172 Register length = length_loc.AsRegister<Register>();
3173 BoundsCheckSlowPathMIPS* slow_path =
3174 new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction);
3175 codegen_->AddSlowPath(slow_path);
3176 if (index_loc.IsConstant()) {
3177 int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue();
3178 if (index < 0) {
3179 __ B(slow_path->GetEntryLabel());
3180 } else if (index == 0) {
3181 __ Blez(length, slow_path->GetEntryLabel());
3182 } else {
3183 DCHECK(IsInt<16>(index + 1)) << index;
3184 __ Sltiu(TMP, length, index + 1);
3185 __ Bnez(TMP, slow_path->GetEntryLabel());
3186 }
3187 } else {
3188 Register index = index_loc.AsRegister<Register>();
3189 __ Bgeu(index, length, slow_path->GetEntryLabel());
3190 }
3191 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003192}
3193
Alexey Frunze15958152017-02-09 19:08:30 -08003194// Temp is used for read barrier.
3195static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) {
3196 if (kEmitCompilerReadBarrier &&
Alexey Frunze4147fcc2017-06-17 19:57:27 -07003197 !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) &&
Alexey Frunze15958152017-02-09 19:08:30 -08003198 (kUseBakerReadBarrier ||
3199 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
3200 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
3201 type_check_kind == TypeCheckKind::kArrayObjectCheck)) {
3202 return 1;
3203 }
3204 return 0;
3205}
3206
3207// Extra temp is used for read barrier.
3208static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) {
3209 return 1 + NumberOfInstanceOfTemps(type_check_kind);
3210}
3211
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003212void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003213 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
3214 bool throws_into_catch = instruction->CanThrowIntoCatchBlock();
3215
3216 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
3217 switch (type_check_kind) {
3218 case TypeCheckKind::kExactCheck:
3219 case TypeCheckKind::kAbstractClassCheck:
3220 case TypeCheckKind::kClassHierarchyCheck:
3221 case TypeCheckKind::kArrayObjectCheck:
Alexey Frunze15958152017-02-09 19:08:30 -08003222 call_kind = (throws_into_catch || kEmitCompilerReadBarrier)
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003223 ? LocationSummary::kCallOnSlowPath
3224 : LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path.
3225 break;
3226 case TypeCheckKind::kArrayCheck:
3227 case TypeCheckKind::kUnresolvedCheck:
3228 case TypeCheckKind::kInterfaceCheck:
3229 call_kind = LocationSummary::kCallOnSlowPath;
3230 break;
3231 }
3232
Vladimir Markoca6fff82017-10-03 14:49:14 +01003233 LocationSummary* locations =
3234 new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003235 locations->SetInAt(0, Location::RequiresRegister());
3236 locations->SetInAt(1, Location::RequiresRegister());
Alexey Frunze15958152017-02-09 19:08:30 -08003237 locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003238}
3239
3240void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003241 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003242 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08003243 Location obj_loc = locations->InAt(0);
3244 Register obj = obj_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003245 Register cls = locations->InAt(1).AsRegister<Register>();
Alexey Frunze15958152017-02-09 19:08:30 -08003246 Location temp_loc = locations->GetTemp(0);
3247 Register temp = temp_loc.AsRegister<Register>();
3248 const size_t num_temps = NumberOfCheckCastTemps(type_check_kind);
3249 DCHECK_LE(num_temps, 2u);
3250 Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation();
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003251 const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3252 const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
3253 const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
3254 const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
3255 const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value();
3256 const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value();
3257 const uint32_t object_array_data_offset =
3258 mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value();
3259 MipsLabel done;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003260
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003261 // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases
3262 // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding
3263 // read barriers is done for performance and code size reasons.
3264 bool is_type_check_slow_path_fatal = false;
3265 if (!kEmitCompilerReadBarrier) {
3266 is_type_check_slow_path_fatal =
3267 (type_check_kind == TypeCheckKind::kExactCheck ||
3268 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
3269 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
3270 type_check_kind == TypeCheckKind::kArrayObjectCheck) &&
3271 !instruction->CanThrowIntoCatchBlock();
3272 }
3273 SlowPathCodeMIPS* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01003274 new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS(
3275 instruction, is_type_check_slow_path_fatal);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003276 codegen_->AddSlowPath(slow_path);
3277
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003278 // Avoid this check if we know `obj` is not null.
3279 if (instruction->MustDoNullCheck()) {
3280 __ Beqz(obj, &done);
3281 }
3282
3283 switch (type_check_kind) {
3284 case TypeCheckKind::kExactCheck:
3285 case TypeCheckKind::kArrayCheck: {
3286 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003287 GenerateReferenceLoadTwoRegisters(instruction,
3288 temp_loc,
3289 obj_loc,
3290 class_offset,
3291 maybe_temp2_loc,
3292 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003293 // Jump to slow path for throwing the exception or doing a
3294 // more involved array check.
3295 __ Bne(temp, cls, slow_path->GetEntryLabel());
3296 break;
3297 }
3298
3299 case TypeCheckKind::kAbstractClassCheck: {
3300 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003301 GenerateReferenceLoadTwoRegisters(instruction,
3302 temp_loc,
3303 obj_loc,
3304 class_offset,
3305 maybe_temp2_loc,
3306 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003307 // If the class is abstract, we eagerly fetch the super class of the
3308 // object to avoid doing a comparison we know will fail.
3309 MipsLabel loop;
3310 __ Bind(&loop);
3311 // /* HeapReference<Class> */ temp = temp->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08003312 GenerateReferenceLoadOneRegister(instruction,
3313 temp_loc,
3314 super_offset,
3315 maybe_temp2_loc,
3316 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003317 // If the class reference currently in `temp` is null, jump to the slow path to throw the
3318 // exception.
3319 __ Beqz(temp, slow_path->GetEntryLabel());
3320 // Otherwise, compare the classes.
3321 __ Bne(temp, cls, &loop);
3322 break;
3323 }
3324
3325 case TypeCheckKind::kClassHierarchyCheck: {
3326 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003327 GenerateReferenceLoadTwoRegisters(instruction,
3328 temp_loc,
3329 obj_loc,
3330 class_offset,
3331 maybe_temp2_loc,
3332 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003333 // Walk over the class hierarchy to find a match.
3334 MipsLabel loop;
3335 __ Bind(&loop);
3336 __ Beq(temp, cls, &done);
3337 // /* HeapReference<Class> */ temp = temp->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08003338 GenerateReferenceLoadOneRegister(instruction,
3339 temp_loc,
3340 super_offset,
3341 maybe_temp2_loc,
3342 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003343 // If the class reference currently in `temp` is null, jump to the slow path to throw the
3344 // exception. Otherwise, jump to the beginning of the loop.
3345 __ Bnez(temp, &loop);
3346 __ B(slow_path->GetEntryLabel());
3347 break;
3348 }
3349
3350 case TypeCheckKind::kArrayObjectCheck: {
3351 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003352 GenerateReferenceLoadTwoRegisters(instruction,
3353 temp_loc,
3354 obj_loc,
3355 class_offset,
3356 maybe_temp2_loc,
3357 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003358 // Do an exact check.
3359 __ Beq(temp, cls, &done);
3360 // Otherwise, we need to check that the object's class is a non-primitive array.
3361 // /* HeapReference<Class> */ temp = temp->component_type_
Alexey Frunze15958152017-02-09 19:08:30 -08003362 GenerateReferenceLoadOneRegister(instruction,
3363 temp_loc,
3364 component_offset,
3365 maybe_temp2_loc,
3366 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003367 // If the component type is null, jump to the slow path to throw the exception.
3368 __ Beqz(temp, slow_path->GetEntryLabel());
3369 // Otherwise, the object is indeed an array, further check that this component
3370 // type is not a primitive type.
3371 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
3372 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
3373 __ Bnez(temp, slow_path->GetEntryLabel());
3374 break;
3375 }
3376
3377 case TypeCheckKind::kUnresolvedCheck:
3378 // We always go into the type check slow path for the unresolved check case.
3379 // We cannot directly call the CheckCast runtime entry point
3380 // without resorting to a type checking slow path here (i.e. by
3381 // calling InvokeRuntime directly), as it would require to
3382 // assign fixed registers for the inputs of this HInstanceOf
3383 // instruction (following the runtime calling convention), which
3384 // might be cluttered by the potential first read barrier
3385 // emission at the beginning of this method.
3386 __ B(slow_path->GetEntryLabel());
3387 break;
3388
3389 case TypeCheckKind::kInterfaceCheck: {
3390 // Avoid read barriers to improve performance of the fast path. We can not get false
3391 // positives by doing this.
3392 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003393 GenerateReferenceLoadTwoRegisters(instruction,
3394 temp_loc,
3395 obj_loc,
3396 class_offset,
3397 maybe_temp2_loc,
3398 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003399 // /* HeapReference<Class> */ temp = temp->iftable_
Alexey Frunze15958152017-02-09 19:08:30 -08003400 GenerateReferenceLoadTwoRegisters(instruction,
3401 temp_loc,
3402 temp_loc,
3403 iftable_offset,
3404 maybe_temp2_loc,
3405 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003406 // Iftable is never null.
3407 __ Lw(TMP, temp, array_length_offset);
3408 // Loop through the iftable and check if any class matches.
3409 MipsLabel loop;
3410 __ Bind(&loop);
3411 __ Addiu(temp, temp, 2 * kHeapReferenceSize); // Possibly in delay slot on R2.
3412 __ Beqz(TMP, slow_path->GetEntryLabel());
3413 __ Lw(AT, temp, object_array_data_offset - 2 * kHeapReferenceSize);
3414 __ MaybeUnpoisonHeapReference(AT);
3415 // Go to next interface.
3416 __ Addiu(TMP, TMP, -2);
3417 // Compare the classes and continue the loop if they do not match.
3418 __ Bne(AT, cls, &loop);
3419 break;
3420 }
3421 }
3422
3423 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003424 __ Bind(slow_path->GetExitLabel());
3425}
3426
3427void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) {
3428 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003429 new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003430 locations->SetInAt(0, Location::RequiresRegister());
3431 if (check->HasUses()) {
3432 locations->SetOut(Location::SameAsFirstInput());
3433 }
3434}
3435
3436void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) {
3437 // We assume the class is not null.
Vladimir Marko174b2e22017-10-12 13:34:49 +01003438 SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS(
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003439 check->GetLoadClass(),
3440 check,
3441 check->GetDexPc(),
3442 true);
3443 codegen_->AddSlowPath(slow_path);
3444 GenerateClassInitializationCheck(slow_path,
3445 check->GetLocations()->InAt(0).AsRegister<Register>());
3446}
3447
3448void LocationsBuilderMIPS::VisitCompare(HCompare* compare) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003449 DataType::Type in_type = compare->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003450
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003451 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003452 new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003453
3454 switch (in_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003455 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003456 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003457 case DataType::Type::kInt8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003458 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003459 case DataType::Type::kInt16:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003460 case DataType::Type::kInt32:
Alexey Frunzee7697712016-09-15 21:37:49 -07003461 locations->SetInAt(0, Location::RequiresRegister());
3462 locations->SetInAt(1, Location::RequiresRegister());
3463 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3464 break;
3465
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003466 case DataType::Type::kInt64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003467 locations->SetInAt(0, Location::RequiresRegister());
3468 locations->SetInAt(1, Location::RequiresRegister());
3469 // Output overlaps because it is written before doing the low comparison.
3470 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3471 break;
3472
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003473 case DataType::Type::kFloat32:
3474 case DataType::Type::kFloat64:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003475 locations->SetInAt(0, Location::RequiresFpuRegister());
3476 locations->SetInAt(1, Location::RequiresFpuRegister());
3477 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003478 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003479
3480 default:
3481 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
3482 }
3483}
3484
3485void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) {
3486 LocationSummary* locations = instruction->GetLocations();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003487 Register res = locations->Out().AsRegister<Register>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003488 DataType::Type in_type = instruction->InputAt(0)->GetType();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003489 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003490
3491 // 0 if: left == right
3492 // 1 if: left > right
3493 // -1 if: left < right
3494 switch (in_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003495 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003496 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003497 case DataType::Type::kInt8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003498 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003499 case DataType::Type::kInt16:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003500 case DataType::Type::kInt32: {
Aart Bika19616e2016-02-01 18:57:58 -08003501 Register lhs = locations->InAt(0).AsRegister<Register>();
3502 Register rhs = locations->InAt(1).AsRegister<Register>();
3503 __ Slt(TMP, lhs, rhs);
3504 __ Slt(res, rhs, lhs);
3505 __ Subu(res, res, TMP);
3506 break;
3507 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003508 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003509 MipsLabel done;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003510 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
3511 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
3512 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
3513 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
3514 // TODO: more efficient (direct) comparison with a constant.
3515 __ Slt(TMP, lhs_high, rhs_high);
3516 __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt.
3517 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
3518 __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal.
3519 __ Sltu(TMP, lhs_low, rhs_low);
3520 __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt.
3521 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
3522 __ Bind(&done);
3523 break;
3524 }
3525
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003526 case DataType::Type::kFloat32: {
Roland Levillain32ca3752016-02-17 16:49:37 +00003527 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003528 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3529 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3530 MipsLabel done;
3531 if (isR6) {
3532 __ CmpEqS(FTMP, lhs, rhs);
3533 __ LoadConst32(res, 0);
3534 __ Bc1nez(FTMP, &done);
3535 if (gt_bias) {
3536 __ CmpLtS(FTMP, lhs, rhs);
3537 __ LoadConst32(res, -1);
3538 __ Bc1nez(FTMP, &done);
3539 __ LoadConst32(res, 1);
3540 } else {
3541 __ CmpLtS(FTMP, rhs, lhs);
3542 __ LoadConst32(res, 1);
3543 __ Bc1nez(FTMP, &done);
3544 __ LoadConst32(res, -1);
3545 }
3546 } else {
3547 if (gt_bias) {
3548 __ ColtS(0, lhs, rhs);
3549 __ LoadConst32(res, -1);
3550 __ Bc1t(0, &done);
3551 __ CeqS(0, lhs, rhs);
3552 __ LoadConst32(res, 1);
3553 __ Movt(res, ZERO, 0);
3554 } else {
3555 __ ColtS(0, rhs, lhs);
3556 __ LoadConst32(res, 1);
3557 __ Bc1t(0, &done);
3558 __ CeqS(0, lhs, rhs);
3559 __ LoadConst32(res, -1);
3560 __ Movt(res, ZERO, 0);
3561 }
3562 }
3563 __ Bind(&done);
3564 break;
3565 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003566 case DataType::Type::kFloat64: {
Roland Levillain32ca3752016-02-17 16:49:37 +00003567 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003568 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3569 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3570 MipsLabel done;
3571 if (isR6) {
3572 __ CmpEqD(FTMP, lhs, rhs);
3573 __ LoadConst32(res, 0);
3574 __ Bc1nez(FTMP, &done);
3575 if (gt_bias) {
3576 __ CmpLtD(FTMP, lhs, rhs);
3577 __ LoadConst32(res, -1);
3578 __ Bc1nez(FTMP, &done);
3579 __ LoadConst32(res, 1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003580 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003581 __ CmpLtD(FTMP, rhs, lhs);
3582 __ LoadConst32(res, 1);
3583 __ Bc1nez(FTMP, &done);
3584 __ LoadConst32(res, -1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003585 }
3586 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003587 if (gt_bias) {
3588 __ ColtD(0, lhs, rhs);
3589 __ LoadConst32(res, -1);
3590 __ Bc1t(0, &done);
3591 __ CeqD(0, lhs, rhs);
3592 __ LoadConst32(res, 1);
3593 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003594 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003595 __ ColtD(0, rhs, lhs);
3596 __ LoadConst32(res, 1);
3597 __ Bc1t(0, &done);
3598 __ CeqD(0, lhs, rhs);
3599 __ LoadConst32(res, -1);
3600 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003601 }
3602 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003603 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003604 break;
3605 }
3606
3607 default:
3608 LOG(FATAL) << "Unimplemented compare type " << in_type;
3609 }
3610}
3611
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00003612void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01003613 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003614 switch (instruction->InputAt(0)->GetType()) {
3615 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003616 case DataType::Type::kInt64:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003617 locations->SetInAt(0, Location::RequiresRegister());
3618 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3619 break;
3620
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003621 case DataType::Type::kFloat32:
3622 case DataType::Type::kFloat64:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003623 locations->SetInAt(0, Location::RequiresFpuRegister());
3624 locations->SetInAt(1, Location::RequiresFpuRegister());
3625 break;
3626 }
David Brazdilb3e773e2016-01-26 11:28:37 +00003627 if (!instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003628 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3629 }
3630}
3631
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00003632void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00003633 if (instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003634 return;
3635 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003636
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003637 DataType::Type type = instruction->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003638 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003639
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003640 switch (type) {
3641 default:
3642 // Integer case.
3643 GenerateIntCompare(instruction->GetCondition(), locations);
3644 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003645
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003646 case DataType::Type::kInt64:
Tijana Jakovljevic6d482aa2017-02-03 13:24:08 +01003647 GenerateLongCompare(instruction->GetCondition(), locations);
3648 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003649
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003650 case DataType::Type::kFloat32:
3651 case DataType::Type::kFloat64:
Alexey Frunze2ddb7172016-09-06 17:04:55 -07003652 GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations);
3653 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003654 }
3655}
3656
Alexey Frunze7e99e052015-11-24 19:28:01 -08003657void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
3658 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003659 DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32);
Alexey Frunze7e99e052015-11-24 19:28:01 -08003660
3661 LocationSummary* locations = instruction->GetLocations();
3662 Location second = locations->InAt(1);
3663 DCHECK(second.IsConstant());
3664
3665 Register out = locations->Out().AsRegister<Register>();
3666 Register dividend = locations->InAt(0).AsRegister<Register>();
3667 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
3668 DCHECK(imm == 1 || imm == -1);
3669
3670 if (instruction->IsRem()) {
3671 __ Move(out, ZERO);
3672 } else {
3673 if (imm == -1) {
3674 __ Subu(out, ZERO, dividend);
3675 } else if (out != dividend) {
3676 __ Move(out, dividend);
3677 }
3678 }
3679}
3680
3681void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
3682 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003683 DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32);
Alexey Frunze7e99e052015-11-24 19:28:01 -08003684
3685 LocationSummary* locations = instruction->GetLocations();
3686 Location second = locations->InAt(1);
3687 DCHECK(second.IsConstant());
3688
3689 Register out = locations->Out().AsRegister<Register>();
3690 Register dividend = locations->InAt(0).AsRegister<Register>();
3691 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003692 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Alexey Frunze7e99e052015-11-24 19:28:01 -08003693 int ctz_imm = CTZ(abs_imm);
3694
3695 if (instruction->IsDiv()) {
3696 if (ctz_imm == 1) {
3697 // Fast path for division by +/-2, which is very common.
3698 __ Srl(TMP, dividend, 31);
3699 } else {
3700 __ Sra(TMP, dividend, 31);
3701 __ Srl(TMP, TMP, 32 - ctz_imm);
3702 }
3703 __ Addu(out, dividend, TMP);
3704 __ Sra(out, out, ctz_imm);
3705 if (imm < 0) {
3706 __ Subu(out, ZERO, out);
3707 }
3708 } else {
3709 if (ctz_imm == 1) {
3710 // Fast path for modulo +/-2, which is very common.
3711 __ Sra(TMP, dividend, 31);
3712 __ Subu(out, dividend, TMP);
3713 __ Andi(out, out, 1);
3714 __ Addu(out, out, TMP);
3715 } else {
3716 __ Sra(TMP, dividend, 31);
3717 __ Srl(TMP, TMP, 32 - ctz_imm);
3718 __ Addu(out, dividend, TMP);
3719 if (IsUint<16>(abs_imm - 1)) {
3720 __ Andi(out, out, abs_imm - 1);
3721 } else {
3722 __ Sll(out, out, 32 - ctz_imm);
3723 __ Srl(out, out, 32 - ctz_imm);
3724 }
3725 __ Subu(out, out, TMP);
3726 }
3727 }
3728}
3729
3730void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
3731 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003732 DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32);
Alexey Frunze7e99e052015-11-24 19:28:01 -08003733
3734 LocationSummary* locations = instruction->GetLocations();
3735 Location second = locations->InAt(1);
3736 DCHECK(second.IsConstant());
3737
3738 Register out = locations->Out().AsRegister<Register>();
3739 Register dividend = locations->InAt(0).AsRegister<Register>();
3740 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
3741
3742 int64_t magic;
3743 int shift;
3744 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
3745
3746 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3747
3748 __ LoadConst32(TMP, magic);
3749 if (isR6) {
3750 __ MuhR6(TMP, dividend, TMP);
3751 } else {
3752 __ MultR2(dividend, TMP);
3753 __ Mfhi(TMP);
3754 }
3755 if (imm > 0 && magic < 0) {
3756 __ Addu(TMP, TMP, dividend);
3757 } else if (imm < 0 && magic > 0) {
3758 __ Subu(TMP, TMP, dividend);
3759 }
3760
3761 if (shift != 0) {
3762 __ Sra(TMP, TMP, shift);
3763 }
3764
3765 if (instruction->IsDiv()) {
3766 __ Sra(out, TMP, 31);
3767 __ Subu(out, TMP, out);
3768 } else {
3769 __ Sra(AT, TMP, 31);
3770 __ Subu(AT, TMP, AT);
3771 __ LoadConst32(TMP, imm);
3772 if (isR6) {
3773 __ MulR6(TMP, AT, TMP);
3774 } else {
3775 __ MulR2(TMP, AT, TMP);
3776 }
3777 __ Subu(out, dividend, TMP);
3778 }
3779}
3780
3781void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) {
3782 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003783 DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32);
Alexey Frunze7e99e052015-11-24 19:28:01 -08003784
3785 LocationSummary* locations = instruction->GetLocations();
3786 Register out = locations->Out().AsRegister<Register>();
3787 Location second = locations->InAt(1);
3788
3789 if (second.IsConstant()) {
3790 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
3791 if (imm == 0) {
3792 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
3793 } else if (imm == 1 || imm == -1) {
3794 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003795 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08003796 DivRemByPowerOfTwo(instruction);
3797 } else {
3798 DCHECK(imm <= -2 || imm >= 2);
3799 GenerateDivRemWithAnyConstant(instruction);
3800 }
3801 } else {
3802 Register dividend = locations->InAt(0).AsRegister<Register>();
3803 Register divisor = second.AsRegister<Register>();
3804 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3805 if (instruction->IsDiv()) {
3806 if (isR6) {
3807 __ DivR6(out, dividend, divisor);
3808 } else {
3809 __ DivR2(out, dividend, divisor);
3810 }
3811 } else {
3812 if (isR6) {
3813 __ ModR6(out, dividend, divisor);
3814 } else {
3815 __ ModR2(out, dividend, divisor);
3816 }
3817 }
3818 }
3819}
3820
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003821void LocationsBuilderMIPS::VisitDiv(HDiv* div) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003822 DataType::Type type = div->GetResultType();
3823 LocationSummary::CallKind call_kind = (type == DataType::Type::kInt64)
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003824 ? LocationSummary::kCallOnMainOnly
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003825 : LocationSummary::kNoCall;
3826
Vladimir Markoca6fff82017-10-03 14:49:14 +01003827 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003828
3829 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003830 case DataType::Type::kInt32:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003831 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08003832 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003833 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3834 break;
3835
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003836 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003837 InvokeRuntimeCallingConvention calling_convention;
3838 locations->SetInAt(0, Location::RegisterPairLocation(
3839 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
3840 locations->SetInAt(1, Location::RegisterPairLocation(
3841 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
3842 locations->SetOut(calling_convention.GetReturnLocation(type));
3843 break;
3844 }
3845
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003846 case DataType::Type::kFloat32:
3847 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003848 locations->SetInAt(0, Location::RequiresFpuRegister());
3849 locations->SetInAt(1, Location::RequiresFpuRegister());
3850 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3851 break;
3852
3853 default:
3854 LOG(FATAL) << "Unexpected div type " << type;
3855 }
3856}
3857
3858void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003859 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003860 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003861
3862 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003863 case DataType::Type::kInt32:
Alexey Frunze7e99e052015-11-24 19:28:01 -08003864 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003865 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003866 case DataType::Type::kInt64: {
Serban Constantinescufca16662016-07-14 09:21:59 +01003867 codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003868 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
3869 break;
3870 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003871 case DataType::Type::kFloat32:
3872 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003873 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
3874 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3875 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003876 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003877 __ DivS(dst, lhs, rhs);
3878 } else {
3879 __ DivD(dst, lhs, rhs);
3880 }
3881 break;
3882 }
3883 default:
3884 LOG(FATAL) << "Unexpected div type " << type;
3885 }
3886}
3887
3888void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01003889 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003890 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003891}
3892
3893void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01003894 SlowPathCodeMIPS* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01003895 new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003896 codegen_->AddSlowPath(slow_path);
3897 Location value = instruction->GetLocations()->InAt(0);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003898 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003899
3900 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003901 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003902 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003903 case DataType::Type::kInt8:
3904 case DataType::Type::kUint16:
3905 case DataType::Type::kInt16:
3906 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003907 if (value.IsConstant()) {
3908 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
3909 __ B(slow_path->GetEntryLabel());
3910 } else {
3911 // A division by a non-null constant is valid. We don't need to perform
3912 // any check, so simply fall through.
3913 }
3914 } else {
3915 DCHECK(value.IsRegister()) << value;
3916 __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel());
3917 }
3918 break;
3919 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003920 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003921 if (value.IsConstant()) {
3922 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
3923 __ B(slow_path->GetEntryLabel());
3924 } else {
3925 // A division by a non-null constant is valid. We don't need to perform
3926 // any check, so simply fall through.
3927 }
3928 } else {
3929 DCHECK(value.IsRegisterPair()) << value;
3930 __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>());
3931 __ Beqz(TMP, slow_path->GetEntryLabel());
3932 }
3933 break;
3934 }
3935 default:
3936 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
3937 }
3938}
3939
3940void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) {
3941 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003942 new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003943 locations->SetOut(Location::ConstantLocation(constant));
3944}
3945
3946void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
3947 // Will be generated at use site.
3948}
3949
3950void LocationsBuilderMIPS::VisitExit(HExit* exit) {
3951 exit->SetLocations(nullptr);
3952}
3953
3954void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
3955}
3956
3957void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) {
3958 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003959 new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003960 locations->SetOut(Location::ConstantLocation(constant));
3961}
3962
3963void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
3964 // Will be generated at use site.
3965}
3966
3967void LocationsBuilderMIPS::VisitGoto(HGoto* got) {
3968 got->SetLocations(nullptr);
3969}
3970
3971void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) {
3972 DCHECK(!successor->IsExitBlock());
3973 HBasicBlock* block = got->GetBlock();
3974 HInstruction* previous = got->GetPrevious();
3975 HLoopInformation* info = block->GetLoopInformation();
3976
3977 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003978 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
3979 return;
3980 }
3981 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
3982 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
3983 }
3984 if (!codegen_->GoesToNextBlock(block, successor)) {
3985 __ B(codegen_->GetLabelOf(successor));
3986 }
3987}
3988
3989void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) {
3990 HandleGoto(got, got->GetSuccessor());
3991}
3992
3993void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
3994 try_boundary->SetLocations(nullptr);
3995}
3996
3997void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
3998 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
3999 if (!successor->IsExitBlock()) {
4000 HandleGoto(try_boundary, successor);
4001 }
4002}
4003
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004004void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond,
4005 LocationSummary* locations) {
4006 Register dst = locations->Out().AsRegister<Register>();
4007 Register lhs = locations->InAt(0).AsRegister<Register>();
4008 Location rhs_location = locations->InAt(1);
4009 Register rhs_reg = ZERO;
4010 int64_t rhs_imm = 0;
4011 bool use_imm = rhs_location.IsConstant();
4012 if (use_imm) {
4013 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
4014 } else {
4015 rhs_reg = rhs_location.AsRegister<Register>();
4016 }
4017
4018 switch (cond) {
4019 case kCondEQ:
4020 case kCondNE:
Alexey Frunzee7697712016-09-15 21:37:49 -07004021 if (use_imm && IsInt<16>(-rhs_imm)) {
4022 if (rhs_imm == 0) {
4023 if (cond == kCondEQ) {
4024 __ Sltiu(dst, lhs, 1);
4025 } else {
4026 __ Sltu(dst, ZERO, lhs);
4027 }
4028 } else {
4029 __ Addiu(dst, lhs, -rhs_imm);
4030 if (cond == kCondEQ) {
4031 __ Sltiu(dst, dst, 1);
4032 } else {
4033 __ Sltu(dst, ZERO, dst);
4034 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004035 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004036 } else {
Alexey Frunzee7697712016-09-15 21:37:49 -07004037 if (use_imm && IsUint<16>(rhs_imm)) {
4038 __ Xori(dst, lhs, rhs_imm);
4039 } else {
4040 if (use_imm) {
4041 rhs_reg = TMP;
4042 __ LoadConst32(rhs_reg, rhs_imm);
4043 }
4044 __ Xor(dst, lhs, rhs_reg);
4045 }
4046 if (cond == kCondEQ) {
4047 __ Sltiu(dst, dst, 1);
4048 } else {
4049 __ Sltu(dst, ZERO, dst);
4050 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004051 }
4052 break;
4053
4054 case kCondLT:
4055 case kCondGE:
4056 if (use_imm && IsInt<16>(rhs_imm)) {
4057 __ Slti(dst, lhs, rhs_imm);
4058 } else {
4059 if (use_imm) {
4060 rhs_reg = TMP;
4061 __ LoadConst32(rhs_reg, rhs_imm);
4062 }
4063 __ Slt(dst, lhs, rhs_reg);
4064 }
4065 if (cond == kCondGE) {
4066 // Simulate lhs >= rhs via !(lhs < rhs) since there's
4067 // only the slt instruction but no sge.
4068 __ Xori(dst, dst, 1);
4069 }
4070 break;
4071
4072 case kCondLE:
4073 case kCondGT:
4074 if (use_imm && IsInt<16>(rhs_imm + 1)) {
4075 // Simulate lhs <= rhs via lhs < rhs + 1.
4076 __ Slti(dst, lhs, rhs_imm + 1);
4077 if (cond == kCondGT) {
4078 // Simulate lhs > rhs via !(lhs <= rhs) since there's
4079 // only the slti instruction but no sgti.
4080 __ Xori(dst, dst, 1);
4081 }
4082 } else {
4083 if (use_imm) {
4084 rhs_reg = TMP;
4085 __ LoadConst32(rhs_reg, rhs_imm);
4086 }
4087 __ Slt(dst, rhs_reg, lhs);
4088 if (cond == kCondLE) {
4089 // Simulate lhs <= rhs via !(rhs < lhs) since there's
4090 // only the slt instruction but no sle.
4091 __ Xori(dst, dst, 1);
4092 }
4093 }
4094 break;
4095
4096 case kCondB:
4097 case kCondAE:
4098 if (use_imm && IsInt<16>(rhs_imm)) {
4099 // Sltiu sign-extends its 16-bit immediate operand before
4100 // the comparison and thus lets us compare directly with
4101 // unsigned values in the ranges [0, 0x7fff] and
4102 // [0xffff8000, 0xffffffff].
4103 __ Sltiu(dst, lhs, rhs_imm);
4104 } else {
4105 if (use_imm) {
4106 rhs_reg = TMP;
4107 __ LoadConst32(rhs_reg, rhs_imm);
4108 }
4109 __ Sltu(dst, lhs, rhs_reg);
4110 }
4111 if (cond == kCondAE) {
4112 // Simulate lhs >= rhs via !(lhs < rhs) since there's
4113 // only the sltu instruction but no sgeu.
4114 __ Xori(dst, dst, 1);
4115 }
4116 break;
4117
4118 case kCondBE:
4119 case kCondA:
4120 if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
4121 // Simulate lhs <= rhs via lhs < rhs + 1.
4122 // Note that this only works if rhs + 1 does not overflow
4123 // to 0, hence the check above.
4124 // Sltiu sign-extends its 16-bit immediate operand before
4125 // the comparison and thus lets us compare directly with
4126 // unsigned values in the ranges [0, 0x7fff] and
4127 // [0xffff8000, 0xffffffff].
4128 __ Sltiu(dst, lhs, rhs_imm + 1);
4129 if (cond == kCondA) {
4130 // Simulate lhs > rhs via !(lhs <= rhs) since there's
4131 // only the sltiu instruction but no sgtiu.
4132 __ Xori(dst, dst, 1);
4133 }
4134 } else {
4135 if (use_imm) {
4136 rhs_reg = TMP;
4137 __ LoadConst32(rhs_reg, rhs_imm);
4138 }
4139 __ Sltu(dst, rhs_reg, lhs);
4140 if (cond == kCondBE) {
4141 // Simulate lhs <= rhs via !(rhs < lhs) since there's
4142 // only the sltu instruction but no sleu.
4143 __ Xori(dst, dst, 1);
4144 }
4145 }
4146 break;
4147 }
4148}
4149
Alexey Frunze674b9ee2016-09-20 14:54:15 -07004150bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond,
4151 LocationSummary* input_locations,
4152 Register dst) {
4153 Register lhs = input_locations->InAt(0).AsRegister<Register>();
4154 Location rhs_location = input_locations->InAt(1);
4155 Register rhs_reg = ZERO;
4156 int64_t rhs_imm = 0;
4157 bool use_imm = rhs_location.IsConstant();
4158 if (use_imm) {
4159 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
4160 } else {
4161 rhs_reg = rhs_location.AsRegister<Register>();
4162 }
4163
4164 switch (cond) {
4165 case kCondEQ:
4166 case kCondNE:
4167 if (use_imm && IsInt<16>(-rhs_imm)) {
4168 __ Addiu(dst, lhs, -rhs_imm);
4169 } else if (use_imm && IsUint<16>(rhs_imm)) {
4170 __ Xori(dst, lhs, rhs_imm);
4171 } else {
4172 if (use_imm) {
4173 rhs_reg = TMP;
4174 __ LoadConst32(rhs_reg, rhs_imm);
4175 }
4176 __ Xor(dst, lhs, rhs_reg);
4177 }
4178 return (cond == kCondEQ);
4179
4180 case kCondLT:
4181 case kCondGE:
4182 if (use_imm && IsInt<16>(rhs_imm)) {
4183 __ Slti(dst, lhs, rhs_imm);
4184 } else {
4185 if (use_imm) {
4186 rhs_reg = TMP;
4187 __ LoadConst32(rhs_reg, rhs_imm);
4188 }
4189 __ Slt(dst, lhs, rhs_reg);
4190 }
4191 return (cond == kCondGE);
4192
4193 case kCondLE:
4194 case kCondGT:
4195 if (use_imm && IsInt<16>(rhs_imm + 1)) {
4196 // Simulate lhs <= rhs via lhs < rhs + 1.
4197 __ Slti(dst, lhs, rhs_imm + 1);
4198 return (cond == kCondGT);
4199 } else {
4200 if (use_imm) {
4201 rhs_reg = TMP;
4202 __ LoadConst32(rhs_reg, rhs_imm);
4203 }
4204 __ Slt(dst, rhs_reg, lhs);
4205 return (cond == kCondLE);
4206 }
4207
4208 case kCondB:
4209 case kCondAE:
4210 if (use_imm && IsInt<16>(rhs_imm)) {
4211 // Sltiu sign-extends its 16-bit immediate operand before
4212 // the comparison and thus lets us compare directly with
4213 // unsigned values in the ranges [0, 0x7fff] and
4214 // [0xffff8000, 0xffffffff].
4215 __ Sltiu(dst, lhs, rhs_imm);
4216 } else {
4217 if (use_imm) {
4218 rhs_reg = TMP;
4219 __ LoadConst32(rhs_reg, rhs_imm);
4220 }
4221 __ Sltu(dst, lhs, rhs_reg);
4222 }
4223 return (cond == kCondAE);
4224
4225 case kCondBE:
4226 case kCondA:
4227 if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
4228 // Simulate lhs <= rhs via lhs < rhs + 1.
4229 // Note that this only works if rhs + 1 does not overflow
4230 // to 0, hence the check above.
4231 // Sltiu sign-extends its 16-bit immediate operand before
4232 // the comparison and thus lets us compare directly with
4233 // unsigned values in the ranges [0, 0x7fff] and
4234 // [0xffff8000, 0xffffffff].
4235 __ Sltiu(dst, lhs, rhs_imm + 1);
4236 return (cond == kCondA);
4237 } else {
4238 if (use_imm) {
4239 rhs_reg = TMP;
4240 __ LoadConst32(rhs_reg, rhs_imm);
4241 }
4242 __ Sltu(dst, rhs_reg, lhs);
4243 return (cond == kCondBE);
4244 }
4245 }
4246}
4247
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004248void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond,
4249 LocationSummary* locations,
4250 MipsLabel* label) {
4251 Register lhs = locations->InAt(0).AsRegister<Register>();
4252 Location rhs_location = locations->InAt(1);
4253 Register rhs_reg = ZERO;
Alexey Frunzee7697712016-09-15 21:37:49 -07004254 int64_t rhs_imm = 0;
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004255 bool use_imm = rhs_location.IsConstant();
4256 if (use_imm) {
4257 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
4258 } else {
4259 rhs_reg = rhs_location.AsRegister<Register>();
4260 }
4261
4262 if (use_imm && rhs_imm == 0) {
4263 switch (cond) {
4264 case kCondEQ:
4265 case kCondBE: // <= 0 if zero
4266 __ Beqz(lhs, label);
4267 break;
4268 case kCondNE:
4269 case kCondA: // > 0 if non-zero
4270 __ Bnez(lhs, label);
4271 break;
4272 case kCondLT:
4273 __ Bltz(lhs, label);
4274 break;
4275 case kCondGE:
4276 __ Bgez(lhs, label);
4277 break;
4278 case kCondLE:
4279 __ Blez(lhs, label);
4280 break;
4281 case kCondGT:
4282 __ Bgtz(lhs, label);
4283 break;
4284 case kCondB: // always false
4285 break;
4286 case kCondAE: // always true
4287 __ B(label);
4288 break;
4289 }
4290 } else {
Alexey Frunzee7697712016-09-15 21:37:49 -07004291 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4292 if (isR6 || !use_imm) {
4293 if (use_imm) {
4294 rhs_reg = TMP;
4295 __ LoadConst32(rhs_reg, rhs_imm);
4296 }
4297 switch (cond) {
4298 case kCondEQ:
4299 __ Beq(lhs, rhs_reg, label);
4300 break;
4301 case kCondNE:
4302 __ Bne(lhs, rhs_reg, label);
4303 break;
4304 case kCondLT:
4305 __ Blt(lhs, rhs_reg, label);
4306 break;
4307 case kCondGE:
4308 __ Bge(lhs, rhs_reg, label);
4309 break;
4310 case kCondLE:
4311 __ Bge(rhs_reg, lhs, label);
4312 break;
4313 case kCondGT:
4314 __ Blt(rhs_reg, lhs, label);
4315 break;
4316 case kCondB:
4317 __ Bltu(lhs, rhs_reg, label);
4318 break;
4319 case kCondAE:
4320 __ Bgeu(lhs, rhs_reg, label);
4321 break;
4322 case kCondBE:
4323 __ Bgeu(rhs_reg, lhs, label);
4324 break;
4325 case kCondA:
4326 __ Bltu(rhs_reg, lhs, label);
4327 break;
4328 }
4329 } else {
4330 // Special cases for more efficient comparison with constants on R2.
4331 switch (cond) {
4332 case kCondEQ:
4333 __ LoadConst32(TMP, rhs_imm);
4334 __ Beq(lhs, TMP, label);
4335 break;
4336 case kCondNE:
4337 __ LoadConst32(TMP, rhs_imm);
4338 __ Bne(lhs, TMP, label);
4339 break;
4340 case kCondLT:
4341 if (IsInt<16>(rhs_imm)) {
4342 __ Slti(TMP, lhs, rhs_imm);
4343 __ Bnez(TMP, label);
4344 } else {
4345 __ LoadConst32(TMP, rhs_imm);
4346 __ Blt(lhs, TMP, label);
4347 }
4348 break;
4349 case kCondGE:
4350 if (IsInt<16>(rhs_imm)) {
4351 __ Slti(TMP, lhs, rhs_imm);
4352 __ Beqz(TMP, label);
4353 } else {
4354 __ LoadConst32(TMP, rhs_imm);
4355 __ Bge(lhs, TMP, label);
4356 }
4357 break;
4358 case kCondLE:
4359 if (IsInt<16>(rhs_imm + 1)) {
4360 // Simulate lhs <= rhs via lhs < rhs + 1.
4361 __ Slti(TMP, lhs, rhs_imm + 1);
4362 __ Bnez(TMP, label);
4363 } else {
4364 __ LoadConst32(TMP, rhs_imm);
4365 __ Bge(TMP, lhs, label);
4366 }
4367 break;
4368 case kCondGT:
4369 if (IsInt<16>(rhs_imm + 1)) {
4370 // Simulate lhs > rhs via !(lhs < rhs + 1).
4371 __ Slti(TMP, lhs, rhs_imm + 1);
4372 __ Beqz(TMP, label);
4373 } else {
4374 __ LoadConst32(TMP, rhs_imm);
4375 __ Blt(TMP, lhs, label);
4376 }
4377 break;
4378 case kCondB:
4379 if (IsInt<16>(rhs_imm)) {
4380 __ Sltiu(TMP, lhs, rhs_imm);
4381 __ Bnez(TMP, label);
4382 } else {
4383 __ LoadConst32(TMP, rhs_imm);
4384 __ Bltu(lhs, TMP, label);
4385 }
4386 break;
4387 case kCondAE:
4388 if (IsInt<16>(rhs_imm)) {
4389 __ Sltiu(TMP, lhs, rhs_imm);
4390 __ Beqz(TMP, label);
4391 } else {
4392 __ LoadConst32(TMP, rhs_imm);
4393 __ Bgeu(lhs, TMP, label);
4394 }
4395 break;
4396 case kCondBE:
4397 if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
4398 // Simulate lhs <= rhs via lhs < rhs + 1.
4399 // Note that this only works if rhs + 1 does not overflow
4400 // to 0, hence the check above.
4401 __ Sltiu(TMP, lhs, rhs_imm + 1);
4402 __ Bnez(TMP, label);
4403 } else {
4404 __ LoadConst32(TMP, rhs_imm);
4405 __ Bgeu(TMP, lhs, label);
4406 }
4407 break;
4408 case kCondA:
4409 if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
4410 // Simulate lhs > rhs via !(lhs < rhs + 1).
4411 // Note that this only works if rhs + 1 does not overflow
4412 // to 0, hence the check above.
4413 __ Sltiu(TMP, lhs, rhs_imm + 1);
4414 __ Beqz(TMP, label);
4415 } else {
4416 __ LoadConst32(TMP, rhs_imm);
4417 __ Bltu(TMP, lhs, label);
4418 }
4419 break;
4420 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004421 }
4422 }
4423}
4424
Tijana Jakovljevic6d482aa2017-02-03 13:24:08 +01004425void InstructionCodeGeneratorMIPS::GenerateLongCompare(IfCondition cond,
4426 LocationSummary* locations) {
4427 Register dst = locations->Out().AsRegister<Register>();
4428 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4429 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
4430 Location rhs_location = locations->InAt(1);
4431 Register rhs_high = ZERO;
4432 Register rhs_low = ZERO;
4433 int64_t imm = 0;
4434 uint32_t imm_high = 0;
4435 uint32_t imm_low = 0;
4436 bool use_imm = rhs_location.IsConstant();
4437 if (use_imm) {
4438 imm = rhs_location.GetConstant()->AsLongConstant()->GetValue();
4439 imm_high = High32Bits(imm);
4440 imm_low = Low32Bits(imm);
4441 } else {
4442 rhs_high = rhs_location.AsRegisterPairHigh<Register>();
4443 rhs_low = rhs_location.AsRegisterPairLow<Register>();
4444 }
4445 if (use_imm && imm == 0) {
4446 switch (cond) {
4447 case kCondEQ:
4448 case kCondBE: // <= 0 if zero
4449 __ Or(dst, lhs_high, lhs_low);
4450 __ Sltiu(dst, dst, 1);
4451 break;
4452 case kCondNE:
4453 case kCondA: // > 0 if non-zero
4454 __ Or(dst, lhs_high, lhs_low);
4455 __ Sltu(dst, ZERO, dst);
4456 break;
4457 case kCondLT:
4458 __ Slt(dst, lhs_high, ZERO);
4459 break;
4460 case kCondGE:
4461 __ Slt(dst, lhs_high, ZERO);
4462 __ Xori(dst, dst, 1);
4463 break;
4464 case kCondLE:
4465 __ Or(TMP, lhs_high, lhs_low);
4466 __ Sra(AT, lhs_high, 31);
4467 __ Sltu(dst, AT, TMP);
4468 __ Xori(dst, dst, 1);
4469 break;
4470 case kCondGT:
4471 __ Or(TMP, lhs_high, lhs_low);
4472 __ Sra(AT, lhs_high, 31);
4473 __ Sltu(dst, AT, TMP);
4474 break;
4475 case kCondB: // always false
4476 __ Andi(dst, dst, 0);
4477 break;
4478 case kCondAE: // always true
4479 __ Ori(dst, ZERO, 1);
4480 break;
4481 }
4482 } else if (use_imm) {
4483 // TODO: more efficient comparison with constants without loading them into TMP/AT.
4484 switch (cond) {
4485 case kCondEQ:
4486 __ LoadConst32(TMP, imm_high);
4487 __ Xor(TMP, TMP, lhs_high);
4488 __ LoadConst32(AT, imm_low);
4489 __ Xor(AT, AT, lhs_low);
4490 __ Or(dst, TMP, AT);
4491 __ Sltiu(dst, dst, 1);
4492 break;
4493 case kCondNE:
4494 __ LoadConst32(TMP, imm_high);
4495 __ Xor(TMP, TMP, lhs_high);
4496 __ LoadConst32(AT, imm_low);
4497 __ Xor(AT, AT, lhs_low);
4498 __ Or(dst, TMP, AT);
4499 __ Sltu(dst, ZERO, dst);
4500 break;
4501 case kCondLT:
4502 case kCondGE:
4503 if (dst == lhs_low) {
4504 __ LoadConst32(TMP, imm_low);
4505 __ Sltu(dst, lhs_low, TMP);
4506 }
4507 __ LoadConst32(TMP, imm_high);
4508 __ Slt(AT, lhs_high, TMP);
4509 __ Slt(TMP, TMP, lhs_high);
4510 if (dst != lhs_low) {
4511 __ LoadConst32(dst, imm_low);
4512 __ Sltu(dst, lhs_low, dst);
4513 }
4514 __ Slt(dst, TMP, dst);
4515 __ Or(dst, dst, AT);
4516 if (cond == kCondGE) {
4517 __ Xori(dst, dst, 1);
4518 }
4519 break;
4520 case kCondGT:
4521 case kCondLE:
4522 if (dst == lhs_low) {
4523 __ LoadConst32(TMP, imm_low);
4524 __ Sltu(dst, TMP, lhs_low);
4525 }
4526 __ LoadConst32(TMP, imm_high);
4527 __ Slt(AT, TMP, lhs_high);
4528 __ Slt(TMP, lhs_high, TMP);
4529 if (dst != lhs_low) {
4530 __ LoadConst32(dst, imm_low);
4531 __ Sltu(dst, dst, lhs_low);
4532 }
4533 __ Slt(dst, TMP, dst);
4534 __ Or(dst, dst, AT);
4535 if (cond == kCondLE) {
4536 __ Xori(dst, dst, 1);
4537 }
4538 break;
4539 case kCondB:
4540 case kCondAE:
4541 if (dst == lhs_low) {
4542 __ LoadConst32(TMP, imm_low);
4543 __ Sltu(dst, lhs_low, TMP);
4544 }
4545 __ LoadConst32(TMP, imm_high);
4546 __ Sltu(AT, lhs_high, TMP);
4547 __ Sltu(TMP, TMP, lhs_high);
4548 if (dst != lhs_low) {
4549 __ LoadConst32(dst, imm_low);
4550 __ Sltu(dst, lhs_low, dst);
4551 }
4552 __ Slt(dst, TMP, dst);
4553 __ Or(dst, dst, AT);
4554 if (cond == kCondAE) {
4555 __ Xori(dst, dst, 1);
4556 }
4557 break;
4558 case kCondA:
4559 case kCondBE:
4560 if (dst == lhs_low) {
4561 __ LoadConst32(TMP, imm_low);
4562 __ Sltu(dst, TMP, lhs_low);
4563 }
4564 __ LoadConst32(TMP, imm_high);
4565 __ Sltu(AT, TMP, lhs_high);
4566 __ Sltu(TMP, lhs_high, TMP);
4567 if (dst != lhs_low) {
4568 __ LoadConst32(dst, imm_low);
4569 __ Sltu(dst, dst, lhs_low);
4570 }
4571 __ Slt(dst, TMP, dst);
4572 __ Or(dst, dst, AT);
4573 if (cond == kCondBE) {
4574 __ Xori(dst, dst, 1);
4575 }
4576 break;
4577 }
4578 } else {
4579 switch (cond) {
4580 case kCondEQ:
4581 __ Xor(TMP, lhs_high, rhs_high);
4582 __ Xor(AT, lhs_low, rhs_low);
4583 __ Or(dst, TMP, AT);
4584 __ Sltiu(dst, dst, 1);
4585 break;
4586 case kCondNE:
4587 __ Xor(TMP, lhs_high, rhs_high);
4588 __ Xor(AT, lhs_low, rhs_low);
4589 __ Or(dst, TMP, AT);
4590 __ Sltu(dst, ZERO, dst);
4591 break;
4592 case kCondLT:
4593 case kCondGE:
4594 __ Slt(TMP, rhs_high, lhs_high);
4595 __ Sltu(AT, lhs_low, rhs_low);
4596 __ Slt(TMP, TMP, AT);
4597 __ Slt(AT, lhs_high, rhs_high);
4598 __ Or(dst, AT, TMP);
4599 if (cond == kCondGE) {
4600 __ Xori(dst, dst, 1);
4601 }
4602 break;
4603 case kCondGT:
4604 case kCondLE:
4605 __ Slt(TMP, lhs_high, rhs_high);
4606 __ Sltu(AT, rhs_low, lhs_low);
4607 __ Slt(TMP, TMP, AT);
4608 __ Slt(AT, rhs_high, lhs_high);
4609 __ Or(dst, AT, TMP);
4610 if (cond == kCondLE) {
4611 __ Xori(dst, dst, 1);
4612 }
4613 break;
4614 case kCondB:
4615 case kCondAE:
4616 __ Sltu(TMP, rhs_high, lhs_high);
4617 __ Sltu(AT, lhs_low, rhs_low);
4618 __ Slt(TMP, TMP, AT);
4619 __ Sltu(AT, lhs_high, rhs_high);
4620 __ Or(dst, AT, TMP);
4621 if (cond == kCondAE) {
4622 __ Xori(dst, dst, 1);
4623 }
4624 break;
4625 case kCondA:
4626 case kCondBE:
4627 __ Sltu(TMP, lhs_high, rhs_high);
4628 __ Sltu(AT, rhs_low, lhs_low);
4629 __ Slt(TMP, TMP, AT);
4630 __ Sltu(AT, rhs_high, lhs_high);
4631 __ Or(dst, AT, TMP);
4632 if (cond == kCondBE) {
4633 __ Xori(dst, dst, 1);
4634 }
4635 break;
4636 }
4637 }
4638}
4639
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004640void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond,
4641 LocationSummary* locations,
4642 MipsLabel* label) {
4643 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4644 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
4645 Location rhs_location = locations->InAt(1);
4646 Register rhs_high = ZERO;
4647 Register rhs_low = ZERO;
4648 int64_t imm = 0;
4649 uint32_t imm_high = 0;
4650 uint32_t imm_low = 0;
4651 bool use_imm = rhs_location.IsConstant();
4652 if (use_imm) {
4653 imm = rhs_location.GetConstant()->AsLongConstant()->GetValue();
4654 imm_high = High32Bits(imm);
4655 imm_low = Low32Bits(imm);
4656 } else {
4657 rhs_high = rhs_location.AsRegisterPairHigh<Register>();
4658 rhs_low = rhs_location.AsRegisterPairLow<Register>();
4659 }
4660
4661 if (use_imm && imm == 0) {
4662 switch (cond) {
4663 case kCondEQ:
4664 case kCondBE: // <= 0 if zero
4665 __ Or(TMP, lhs_high, lhs_low);
4666 __ Beqz(TMP, label);
4667 break;
4668 case kCondNE:
4669 case kCondA: // > 0 if non-zero
4670 __ Or(TMP, lhs_high, lhs_low);
4671 __ Bnez(TMP, label);
4672 break;
4673 case kCondLT:
4674 __ Bltz(lhs_high, label);
4675 break;
4676 case kCondGE:
4677 __ Bgez(lhs_high, label);
4678 break;
4679 case kCondLE:
4680 __ Or(TMP, lhs_high, lhs_low);
4681 __ Sra(AT, lhs_high, 31);
4682 __ Bgeu(AT, TMP, label);
4683 break;
4684 case kCondGT:
4685 __ Or(TMP, lhs_high, lhs_low);
4686 __ Sra(AT, lhs_high, 31);
4687 __ Bltu(AT, TMP, label);
4688 break;
4689 case kCondB: // always false
4690 break;
4691 case kCondAE: // always true
4692 __ B(label);
4693 break;
4694 }
4695 } else if (use_imm) {
4696 // TODO: more efficient comparison with constants without loading them into TMP/AT.
4697 switch (cond) {
4698 case kCondEQ:
4699 __ LoadConst32(TMP, imm_high);
4700 __ Xor(TMP, TMP, lhs_high);
4701 __ LoadConst32(AT, imm_low);
4702 __ Xor(AT, AT, lhs_low);
4703 __ Or(TMP, TMP, AT);
4704 __ Beqz(TMP, label);
4705 break;
4706 case kCondNE:
4707 __ LoadConst32(TMP, imm_high);
4708 __ Xor(TMP, TMP, lhs_high);
4709 __ LoadConst32(AT, imm_low);
4710 __ Xor(AT, AT, lhs_low);
4711 __ Or(TMP, TMP, AT);
4712 __ Bnez(TMP, label);
4713 break;
4714 case kCondLT:
4715 __ LoadConst32(TMP, imm_high);
4716 __ Blt(lhs_high, TMP, label);
4717 __ Slt(TMP, TMP, lhs_high);
4718 __ LoadConst32(AT, imm_low);
4719 __ Sltu(AT, lhs_low, AT);
4720 __ Blt(TMP, AT, label);
4721 break;
4722 case kCondGE:
4723 __ LoadConst32(TMP, imm_high);
4724 __ Blt(TMP, lhs_high, label);
4725 __ Slt(TMP, lhs_high, TMP);
4726 __ LoadConst32(AT, imm_low);
4727 __ Sltu(AT, lhs_low, AT);
4728 __ Or(TMP, TMP, AT);
4729 __ Beqz(TMP, label);
4730 break;
4731 case kCondLE:
4732 __ LoadConst32(TMP, imm_high);
4733 __ Blt(lhs_high, TMP, label);
4734 __ Slt(TMP, TMP, lhs_high);
4735 __ LoadConst32(AT, imm_low);
4736 __ Sltu(AT, AT, lhs_low);
4737 __ Or(TMP, TMP, AT);
4738 __ Beqz(TMP, label);
4739 break;
4740 case kCondGT:
4741 __ LoadConst32(TMP, imm_high);
4742 __ Blt(TMP, lhs_high, label);
4743 __ Slt(TMP, lhs_high, TMP);
4744 __ LoadConst32(AT, imm_low);
4745 __ Sltu(AT, AT, lhs_low);
4746 __ Blt(TMP, AT, label);
4747 break;
4748 case kCondB:
4749 __ LoadConst32(TMP, imm_high);
4750 __ Bltu(lhs_high, TMP, label);
4751 __ Sltu(TMP, TMP, lhs_high);
4752 __ LoadConst32(AT, imm_low);
4753 __ Sltu(AT, lhs_low, AT);
4754 __ Blt(TMP, AT, label);
4755 break;
4756 case kCondAE:
4757 __ LoadConst32(TMP, imm_high);
4758 __ Bltu(TMP, lhs_high, label);
4759 __ Sltu(TMP, lhs_high, TMP);
4760 __ LoadConst32(AT, imm_low);
4761 __ Sltu(AT, lhs_low, AT);
4762 __ Or(TMP, TMP, AT);
4763 __ Beqz(TMP, label);
4764 break;
4765 case kCondBE:
4766 __ LoadConst32(TMP, imm_high);
4767 __ Bltu(lhs_high, TMP, label);
4768 __ Sltu(TMP, TMP, lhs_high);
4769 __ LoadConst32(AT, imm_low);
4770 __ Sltu(AT, AT, lhs_low);
4771 __ Or(TMP, TMP, AT);
4772 __ Beqz(TMP, label);
4773 break;
4774 case kCondA:
4775 __ LoadConst32(TMP, imm_high);
4776 __ Bltu(TMP, lhs_high, label);
4777 __ Sltu(TMP, lhs_high, TMP);
4778 __ LoadConst32(AT, imm_low);
4779 __ Sltu(AT, AT, lhs_low);
4780 __ Blt(TMP, AT, label);
4781 break;
4782 }
4783 } else {
4784 switch (cond) {
4785 case kCondEQ:
4786 __ Xor(TMP, lhs_high, rhs_high);
4787 __ Xor(AT, lhs_low, rhs_low);
4788 __ Or(TMP, TMP, AT);
4789 __ Beqz(TMP, label);
4790 break;
4791 case kCondNE:
4792 __ Xor(TMP, lhs_high, rhs_high);
4793 __ Xor(AT, lhs_low, rhs_low);
4794 __ Or(TMP, TMP, AT);
4795 __ Bnez(TMP, label);
4796 break;
4797 case kCondLT:
4798 __ Blt(lhs_high, rhs_high, label);
4799 __ Slt(TMP, rhs_high, lhs_high);
4800 __ Sltu(AT, lhs_low, rhs_low);
4801 __ Blt(TMP, AT, label);
4802 break;
4803 case kCondGE:
4804 __ Blt(rhs_high, lhs_high, label);
4805 __ Slt(TMP, lhs_high, rhs_high);
4806 __ Sltu(AT, lhs_low, rhs_low);
4807 __ Or(TMP, TMP, AT);
4808 __ Beqz(TMP, label);
4809 break;
4810 case kCondLE:
4811 __ Blt(lhs_high, rhs_high, label);
4812 __ Slt(TMP, rhs_high, lhs_high);
4813 __ Sltu(AT, rhs_low, lhs_low);
4814 __ Or(TMP, TMP, AT);
4815 __ Beqz(TMP, label);
4816 break;
4817 case kCondGT:
4818 __ Blt(rhs_high, lhs_high, label);
4819 __ Slt(TMP, lhs_high, rhs_high);
4820 __ Sltu(AT, rhs_low, lhs_low);
4821 __ Blt(TMP, AT, label);
4822 break;
4823 case kCondB:
4824 __ Bltu(lhs_high, rhs_high, label);
4825 __ Sltu(TMP, rhs_high, lhs_high);
4826 __ Sltu(AT, lhs_low, rhs_low);
4827 __ Blt(TMP, AT, label);
4828 break;
4829 case kCondAE:
4830 __ Bltu(rhs_high, lhs_high, label);
4831 __ Sltu(TMP, lhs_high, rhs_high);
4832 __ Sltu(AT, lhs_low, rhs_low);
4833 __ Or(TMP, TMP, AT);
4834 __ Beqz(TMP, label);
4835 break;
4836 case kCondBE:
4837 __ Bltu(lhs_high, rhs_high, label);
4838 __ Sltu(TMP, rhs_high, lhs_high);
4839 __ Sltu(AT, rhs_low, lhs_low);
4840 __ Or(TMP, TMP, AT);
4841 __ Beqz(TMP, label);
4842 break;
4843 case kCondA:
4844 __ Bltu(rhs_high, lhs_high, label);
4845 __ Sltu(TMP, lhs_high, rhs_high);
4846 __ Sltu(AT, rhs_low, lhs_low);
4847 __ Blt(TMP, AT, label);
4848 break;
4849 }
4850 }
4851}
4852
Alexey Frunze2ddb7172016-09-06 17:04:55 -07004853void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond,
4854 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004855 DataType::Type type,
Alexey Frunze2ddb7172016-09-06 17:04:55 -07004856 LocationSummary* locations) {
4857 Register dst = locations->Out().AsRegister<Register>();
4858 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
4859 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
4860 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004861 if (type == DataType::Type::kFloat32) {
Alexey Frunze2ddb7172016-09-06 17:04:55 -07004862 if (isR6) {
4863 switch (cond) {
4864 case kCondEQ:
4865 __ CmpEqS(FTMP, lhs, rhs);
4866 __ Mfc1(dst, FTMP);
4867 __ Andi(dst, dst, 1);
4868 break;
4869 case kCondNE:
4870 __ CmpEqS(FTMP, lhs, rhs);
4871 __ Mfc1(dst, FTMP);
4872 __ Addiu(dst, dst, 1);
4873 break;
4874 case kCondLT:
4875 if (gt_bias) {
4876 __ CmpLtS(FTMP, lhs, rhs);
4877 } else {
4878 __ CmpUltS(FTMP, lhs, rhs);
4879 }
4880 __ Mfc1(dst, FTMP);
4881 __ Andi(dst, dst, 1);
4882 break;
4883 case kCondLE:
4884 if (gt_bias) {
4885 __ CmpLeS(FTMP, lhs, rhs);
4886 } else {
4887 __ CmpUleS(FTMP, lhs, rhs);
4888 }
4889 __ Mfc1(dst, FTMP);
4890 __ Andi(dst, dst, 1);
4891 break;
4892 case kCondGT:
4893 if (gt_bias) {
4894 __ CmpUltS(FTMP, rhs, lhs);
4895 } else {
4896 __ CmpLtS(FTMP, rhs, lhs);
4897 }
4898 __ Mfc1(dst, FTMP);
4899 __ Andi(dst, dst, 1);
4900 break;
4901 case kCondGE:
4902 if (gt_bias) {
4903 __ CmpUleS(FTMP, rhs, lhs);
4904 } else {
4905 __ CmpLeS(FTMP, rhs, lhs);
4906 }
4907 __ Mfc1(dst, FTMP);
4908 __ Andi(dst, dst, 1);
4909 break;
4910 default:
4911 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4912 UNREACHABLE();
4913 }
4914 } else {
4915 switch (cond) {
4916 case kCondEQ:
4917 __ CeqS(0, lhs, rhs);
4918 __ LoadConst32(dst, 1);
4919 __ Movf(dst, ZERO, 0);
4920 break;
4921 case kCondNE:
4922 __ CeqS(0, lhs, rhs);
4923 __ LoadConst32(dst, 1);
4924 __ Movt(dst, ZERO, 0);
4925 break;
4926 case kCondLT:
4927 if (gt_bias) {
4928 __ ColtS(0, lhs, rhs);
4929 } else {
4930 __ CultS(0, lhs, rhs);
4931 }
4932 __ LoadConst32(dst, 1);
4933 __ Movf(dst, ZERO, 0);
4934 break;
4935 case kCondLE:
4936 if (gt_bias) {
4937 __ ColeS(0, lhs, rhs);
4938 } else {
4939 __ CuleS(0, lhs, rhs);
4940 }
4941 __ LoadConst32(dst, 1);
4942 __ Movf(dst, ZERO, 0);
4943 break;
4944 case kCondGT:
4945 if (gt_bias) {
4946 __ CultS(0, rhs, lhs);
4947 } else {
4948 __ ColtS(0, rhs, lhs);
4949 }
4950 __ LoadConst32(dst, 1);
4951 __ Movf(dst, ZERO, 0);
4952 break;
4953 case kCondGE:
4954 if (gt_bias) {
4955 __ CuleS(0, rhs, lhs);
4956 } else {
4957 __ ColeS(0, rhs, lhs);
4958 }
4959 __ LoadConst32(dst, 1);
4960 __ Movf(dst, ZERO, 0);
4961 break;
4962 default:
4963 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4964 UNREACHABLE();
4965 }
4966 }
4967 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004968 DCHECK_EQ(type, DataType::Type::kFloat64);
Alexey Frunze2ddb7172016-09-06 17:04:55 -07004969 if (isR6) {
4970 switch (cond) {
4971 case kCondEQ:
4972 __ CmpEqD(FTMP, lhs, rhs);
4973 __ Mfc1(dst, FTMP);
4974 __ Andi(dst, dst, 1);
4975 break;
4976 case kCondNE:
4977 __ CmpEqD(FTMP, lhs, rhs);
4978 __ Mfc1(dst, FTMP);
4979 __ Addiu(dst, dst, 1);
4980 break;
4981 case kCondLT:
4982 if (gt_bias) {
4983 __ CmpLtD(FTMP, lhs, rhs);
4984 } else {
4985 __ CmpUltD(FTMP, lhs, rhs);
4986 }
4987 __ Mfc1(dst, FTMP);
4988 __ Andi(dst, dst, 1);
4989 break;
4990 case kCondLE:
4991 if (gt_bias) {
4992 __ CmpLeD(FTMP, lhs, rhs);
4993 } else {
4994 __ CmpUleD(FTMP, lhs, rhs);
4995 }
4996 __ Mfc1(dst, FTMP);
4997 __ Andi(dst, dst, 1);
4998 break;
4999 case kCondGT:
5000 if (gt_bias) {
5001 __ CmpUltD(FTMP, rhs, lhs);
5002 } else {
5003 __ CmpLtD(FTMP, rhs, lhs);
5004 }
5005 __ Mfc1(dst, FTMP);
5006 __ Andi(dst, dst, 1);
5007 break;
5008 case kCondGE:
5009 if (gt_bias) {
5010 __ CmpUleD(FTMP, rhs, lhs);
5011 } else {
5012 __ CmpLeD(FTMP, rhs, lhs);
5013 }
5014 __ Mfc1(dst, FTMP);
5015 __ Andi(dst, dst, 1);
5016 break;
5017 default:
5018 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
5019 UNREACHABLE();
5020 }
5021 } else {
5022 switch (cond) {
5023 case kCondEQ:
5024 __ CeqD(0, lhs, rhs);
5025 __ LoadConst32(dst, 1);
5026 __ Movf(dst, ZERO, 0);
5027 break;
5028 case kCondNE:
5029 __ CeqD(0, lhs, rhs);
5030 __ LoadConst32(dst, 1);
5031 __ Movt(dst, ZERO, 0);
5032 break;
5033 case kCondLT:
5034 if (gt_bias) {
5035 __ ColtD(0, lhs, rhs);
5036 } else {
5037 __ CultD(0, lhs, rhs);
5038 }
5039 __ LoadConst32(dst, 1);
5040 __ Movf(dst, ZERO, 0);
5041 break;
5042 case kCondLE:
5043 if (gt_bias) {
5044 __ ColeD(0, lhs, rhs);
5045 } else {
5046 __ CuleD(0, lhs, rhs);
5047 }
5048 __ LoadConst32(dst, 1);
5049 __ Movf(dst, ZERO, 0);
5050 break;
5051 case kCondGT:
5052 if (gt_bias) {
5053 __ CultD(0, rhs, lhs);
5054 } else {
5055 __ ColtD(0, rhs, lhs);
5056 }
5057 __ LoadConst32(dst, 1);
5058 __ Movf(dst, ZERO, 0);
5059 break;
5060 case kCondGE:
5061 if (gt_bias) {
5062 __ CuleD(0, rhs, lhs);
5063 } else {
5064 __ ColeD(0, rhs, lhs);
5065 }
5066 __ LoadConst32(dst, 1);
5067 __ Movf(dst, ZERO, 0);
5068 break;
5069 default:
5070 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
5071 UNREACHABLE();
5072 }
5073 }
5074 }
5075}
5076
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005077bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond,
5078 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005079 DataType::Type type,
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005080 LocationSummary* input_locations,
5081 int cc) {
5082 FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>();
5083 FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>();
5084 CHECK(!codegen_->GetInstructionSetFeatures().IsR6());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005085 if (type == DataType::Type::kFloat32) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005086 switch (cond) {
5087 case kCondEQ:
5088 __ CeqS(cc, lhs, rhs);
5089 return false;
5090 case kCondNE:
5091 __ CeqS(cc, lhs, rhs);
5092 return true;
5093 case kCondLT:
5094 if (gt_bias) {
5095 __ ColtS(cc, lhs, rhs);
5096 } else {
5097 __ CultS(cc, lhs, rhs);
5098 }
5099 return false;
5100 case kCondLE:
5101 if (gt_bias) {
5102 __ ColeS(cc, lhs, rhs);
5103 } else {
5104 __ CuleS(cc, lhs, rhs);
5105 }
5106 return false;
5107 case kCondGT:
5108 if (gt_bias) {
5109 __ CultS(cc, rhs, lhs);
5110 } else {
5111 __ ColtS(cc, rhs, lhs);
5112 }
5113 return false;
5114 case kCondGE:
5115 if (gt_bias) {
5116 __ CuleS(cc, rhs, lhs);
5117 } else {
5118 __ ColeS(cc, rhs, lhs);
5119 }
5120 return false;
5121 default:
5122 LOG(FATAL) << "Unexpected non-floating-point condition";
5123 UNREACHABLE();
5124 }
5125 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005126 DCHECK_EQ(type, DataType::Type::kFloat64);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005127 switch (cond) {
5128 case kCondEQ:
5129 __ CeqD(cc, lhs, rhs);
5130 return false;
5131 case kCondNE:
5132 __ CeqD(cc, lhs, rhs);
5133 return true;
5134 case kCondLT:
5135 if (gt_bias) {
5136 __ ColtD(cc, lhs, rhs);
5137 } else {
5138 __ CultD(cc, lhs, rhs);
5139 }
5140 return false;
5141 case kCondLE:
5142 if (gt_bias) {
5143 __ ColeD(cc, lhs, rhs);
5144 } else {
5145 __ CuleD(cc, lhs, rhs);
5146 }
5147 return false;
5148 case kCondGT:
5149 if (gt_bias) {
5150 __ CultD(cc, rhs, lhs);
5151 } else {
5152 __ ColtD(cc, rhs, lhs);
5153 }
5154 return false;
5155 case kCondGE:
5156 if (gt_bias) {
5157 __ CuleD(cc, rhs, lhs);
5158 } else {
5159 __ ColeD(cc, rhs, lhs);
5160 }
5161 return false;
5162 default:
5163 LOG(FATAL) << "Unexpected non-floating-point condition";
5164 UNREACHABLE();
5165 }
5166 }
5167}
5168
5169bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond,
5170 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005171 DataType::Type type,
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005172 LocationSummary* input_locations,
5173 FRegister dst) {
5174 FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>();
5175 FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>();
5176 CHECK(codegen_->GetInstructionSetFeatures().IsR6());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005177 if (type == DataType::Type::kFloat32) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005178 switch (cond) {
5179 case kCondEQ:
5180 __ CmpEqS(dst, lhs, rhs);
5181 return false;
5182 case kCondNE:
5183 __ CmpEqS(dst, lhs, rhs);
5184 return true;
5185 case kCondLT:
5186 if (gt_bias) {
5187 __ CmpLtS(dst, lhs, rhs);
5188 } else {
5189 __ CmpUltS(dst, lhs, rhs);
5190 }
5191 return false;
5192 case kCondLE:
5193 if (gt_bias) {
5194 __ CmpLeS(dst, lhs, rhs);
5195 } else {
5196 __ CmpUleS(dst, lhs, rhs);
5197 }
5198 return false;
5199 case kCondGT:
5200 if (gt_bias) {
5201 __ CmpUltS(dst, rhs, lhs);
5202 } else {
5203 __ CmpLtS(dst, rhs, lhs);
5204 }
5205 return false;
5206 case kCondGE:
5207 if (gt_bias) {
5208 __ CmpUleS(dst, rhs, lhs);
5209 } else {
5210 __ CmpLeS(dst, rhs, lhs);
5211 }
5212 return false;
5213 default:
5214 LOG(FATAL) << "Unexpected non-floating-point condition";
5215 UNREACHABLE();
5216 }
5217 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005218 DCHECK_EQ(type, DataType::Type::kFloat64);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005219 switch (cond) {
5220 case kCondEQ:
5221 __ CmpEqD(dst, lhs, rhs);
5222 return false;
5223 case kCondNE:
5224 __ CmpEqD(dst, lhs, rhs);
5225 return true;
5226 case kCondLT:
5227 if (gt_bias) {
5228 __ CmpLtD(dst, lhs, rhs);
5229 } else {
5230 __ CmpUltD(dst, lhs, rhs);
5231 }
5232 return false;
5233 case kCondLE:
5234 if (gt_bias) {
5235 __ CmpLeD(dst, lhs, rhs);
5236 } else {
5237 __ CmpUleD(dst, lhs, rhs);
5238 }
5239 return false;
5240 case kCondGT:
5241 if (gt_bias) {
5242 __ CmpUltD(dst, rhs, lhs);
5243 } else {
5244 __ CmpLtD(dst, rhs, lhs);
5245 }
5246 return false;
5247 case kCondGE:
5248 if (gt_bias) {
5249 __ CmpUleD(dst, rhs, lhs);
5250 } else {
5251 __ CmpLeD(dst, rhs, lhs);
5252 }
5253 return false;
5254 default:
5255 LOG(FATAL) << "Unexpected non-floating-point condition";
5256 UNREACHABLE();
5257 }
5258 }
5259}
5260
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005261void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond,
5262 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005263 DataType::Type type,
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005264 LocationSummary* locations,
5265 MipsLabel* label) {
5266 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
5267 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
5268 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005269 if (type == DataType::Type::kFloat32) {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005270 if (isR6) {
5271 switch (cond) {
5272 case kCondEQ:
5273 __ CmpEqS(FTMP, lhs, rhs);
5274 __ Bc1nez(FTMP, label);
5275 break;
5276 case kCondNE:
5277 __ CmpEqS(FTMP, lhs, rhs);
5278 __ Bc1eqz(FTMP, label);
5279 break;
5280 case kCondLT:
5281 if (gt_bias) {
5282 __ CmpLtS(FTMP, lhs, rhs);
5283 } else {
5284 __ CmpUltS(FTMP, lhs, rhs);
5285 }
5286 __ Bc1nez(FTMP, label);
5287 break;
5288 case kCondLE:
5289 if (gt_bias) {
5290 __ CmpLeS(FTMP, lhs, rhs);
5291 } else {
5292 __ CmpUleS(FTMP, lhs, rhs);
5293 }
5294 __ Bc1nez(FTMP, label);
5295 break;
5296 case kCondGT:
5297 if (gt_bias) {
5298 __ CmpUltS(FTMP, rhs, lhs);
5299 } else {
5300 __ CmpLtS(FTMP, rhs, lhs);
5301 }
5302 __ Bc1nez(FTMP, label);
5303 break;
5304 case kCondGE:
5305 if (gt_bias) {
5306 __ CmpUleS(FTMP, rhs, lhs);
5307 } else {
5308 __ CmpLeS(FTMP, rhs, lhs);
5309 }
5310 __ Bc1nez(FTMP, label);
5311 break;
5312 default:
5313 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005314 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005315 }
5316 } else {
5317 switch (cond) {
5318 case kCondEQ:
5319 __ CeqS(0, lhs, rhs);
5320 __ Bc1t(0, label);
5321 break;
5322 case kCondNE:
5323 __ CeqS(0, lhs, rhs);
5324 __ Bc1f(0, label);
5325 break;
5326 case kCondLT:
5327 if (gt_bias) {
5328 __ ColtS(0, lhs, rhs);
5329 } else {
5330 __ CultS(0, lhs, rhs);
5331 }
5332 __ Bc1t(0, label);
5333 break;
5334 case kCondLE:
5335 if (gt_bias) {
5336 __ ColeS(0, lhs, rhs);
5337 } else {
5338 __ CuleS(0, lhs, rhs);
5339 }
5340 __ Bc1t(0, label);
5341 break;
5342 case kCondGT:
5343 if (gt_bias) {
5344 __ CultS(0, rhs, lhs);
5345 } else {
5346 __ ColtS(0, rhs, lhs);
5347 }
5348 __ Bc1t(0, label);
5349 break;
5350 case kCondGE:
5351 if (gt_bias) {
5352 __ CuleS(0, rhs, lhs);
5353 } else {
5354 __ ColeS(0, rhs, lhs);
5355 }
5356 __ Bc1t(0, label);
5357 break;
5358 default:
5359 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005360 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005361 }
5362 }
5363 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005364 DCHECK_EQ(type, DataType::Type::kFloat64);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005365 if (isR6) {
5366 switch (cond) {
5367 case kCondEQ:
5368 __ CmpEqD(FTMP, lhs, rhs);
5369 __ Bc1nez(FTMP, label);
5370 break;
5371 case kCondNE:
5372 __ CmpEqD(FTMP, lhs, rhs);
5373 __ Bc1eqz(FTMP, label);
5374 break;
5375 case kCondLT:
5376 if (gt_bias) {
5377 __ CmpLtD(FTMP, lhs, rhs);
5378 } else {
5379 __ CmpUltD(FTMP, lhs, rhs);
5380 }
5381 __ Bc1nez(FTMP, label);
5382 break;
5383 case kCondLE:
5384 if (gt_bias) {
5385 __ CmpLeD(FTMP, lhs, rhs);
5386 } else {
5387 __ CmpUleD(FTMP, lhs, rhs);
5388 }
5389 __ Bc1nez(FTMP, label);
5390 break;
5391 case kCondGT:
5392 if (gt_bias) {
5393 __ CmpUltD(FTMP, rhs, lhs);
5394 } else {
5395 __ CmpLtD(FTMP, rhs, lhs);
5396 }
5397 __ Bc1nez(FTMP, label);
5398 break;
5399 case kCondGE:
5400 if (gt_bias) {
5401 __ CmpUleD(FTMP, rhs, lhs);
5402 } else {
5403 __ CmpLeD(FTMP, rhs, lhs);
5404 }
5405 __ Bc1nez(FTMP, label);
5406 break;
5407 default:
5408 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005409 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005410 }
5411 } else {
5412 switch (cond) {
5413 case kCondEQ:
5414 __ CeqD(0, lhs, rhs);
5415 __ Bc1t(0, label);
5416 break;
5417 case kCondNE:
5418 __ CeqD(0, lhs, rhs);
5419 __ Bc1f(0, label);
5420 break;
5421 case kCondLT:
5422 if (gt_bias) {
5423 __ ColtD(0, lhs, rhs);
5424 } else {
5425 __ CultD(0, lhs, rhs);
5426 }
5427 __ Bc1t(0, label);
5428 break;
5429 case kCondLE:
5430 if (gt_bias) {
5431 __ ColeD(0, lhs, rhs);
5432 } else {
5433 __ CuleD(0, lhs, rhs);
5434 }
5435 __ Bc1t(0, label);
5436 break;
5437 case kCondGT:
5438 if (gt_bias) {
5439 __ CultD(0, rhs, lhs);
5440 } else {
5441 __ ColtD(0, rhs, lhs);
5442 }
5443 __ Bc1t(0, label);
5444 break;
5445 case kCondGE:
5446 if (gt_bias) {
5447 __ CuleD(0, rhs, lhs);
5448 } else {
5449 __ ColeD(0, rhs, lhs);
5450 }
5451 __ Bc1t(0, label);
5452 break;
5453 default:
5454 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005455 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005456 }
5457 }
5458 }
5459}
5460
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005461void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00005462 size_t condition_input_index,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005463 MipsLabel* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00005464 MipsLabel* false_target) {
5465 HInstruction* cond = instruction->InputAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005466
David Brazdil0debae72015-11-12 18:37:00 +00005467 if (true_target == nullptr && false_target == nullptr) {
5468 // Nothing to do. The code always falls through.
5469 return;
5470 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00005471 // Constant condition, statically compared against "true" (integer value 1).
5472 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00005473 if (true_target != nullptr) {
5474 __ B(true_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005475 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005476 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00005477 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00005478 if (false_target != nullptr) {
5479 __ B(false_target);
5480 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005481 }
David Brazdil0debae72015-11-12 18:37:00 +00005482 return;
5483 }
5484
5485 // The following code generates these patterns:
5486 // (1) true_target == nullptr && false_target != nullptr
5487 // - opposite condition true => branch to false_target
5488 // (2) true_target != nullptr && false_target == nullptr
5489 // - condition true => branch to true_target
5490 // (3) true_target != nullptr && false_target != nullptr
5491 // - condition true => branch to true_target
5492 // - branch to false_target
5493 if (IsBooleanValueOrMaterializedCondition(cond)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005494 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00005495 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005496 DCHECK(cond_val.IsRegister());
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005497 if (true_target == nullptr) {
David Brazdil0debae72015-11-12 18:37:00 +00005498 __ Beqz(cond_val.AsRegister<Register>(), false_target);
5499 } else {
5500 __ Bnez(cond_val.AsRegister<Register>(), true_target);
5501 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005502 } else {
5503 // The condition instruction has not been materialized, use its inputs as
5504 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00005505 HCondition* condition = cond->AsCondition();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005506 DataType::Type type = condition->InputAt(0)->GetType();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005507 LocationSummary* locations = cond->GetLocations();
5508 IfCondition if_cond = condition->GetCondition();
5509 MipsLabel* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00005510
David Brazdil0debae72015-11-12 18:37:00 +00005511 if (true_target == nullptr) {
5512 if_cond = condition->GetOppositeCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005513 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00005514 }
5515
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005516 switch (type) {
5517 default:
5518 GenerateIntCompareAndBranch(if_cond, locations, branch_target);
5519 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005520 case DataType::Type::kInt64:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005521 GenerateLongCompareAndBranch(if_cond, locations, branch_target);
5522 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005523 case DataType::Type::kFloat32:
5524 case DataType::Type::kFloat64:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005525 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
5526 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005527 }
5528 }
David Brazdil0debae72015-11-12 18:37:00 +00005529
5530 // If neither branch falls through (case 3), the conditional branch to `true_target`
5531 // was already emitted (case 2) and we need to emit a jump to `false_target`.
5532 if (true_target != nullptr && false_target != nullptr) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005533 __ B(false_target);
5534 }
5535}
5536
5537void LocationsBuilderMIPS::VisitIf(HIf* if_instr) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01005538 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00005539 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005540 locations->SetInAt(0, Location::RequiresRegister());
5541 }
5542}
5543
5544void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00005545 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
5546 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
5547 MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
5548 nullptr : codegen_->GetLabelOf(true_successor);
5549 MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
5550 nullptr : codegen_->GetLabelOf(false_successor);
5551 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005552}
5553
5554void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01005555 LocationSummary* locations = new (GetGraph()->GetAllocator())
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005556 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01005557 InvokeRuntimeCallingConvention calling_convention;
5558 RegisterSet caller_saves = RegisterSet::Empty();
5559 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5560 locations->SetCustomSlowPathCallerSaves(caller_saves);
David Brazdil0debae72015-11-12 18:37:00 +00005561 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005562 locations->SetInAt(0, Location::RequiresRegister());
5563 }
5564}
5565
5566void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08005567 SlowPathCodeMIPS* slow_path =
5568 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00005569 GenerateTestAndBranch(deoptimize,
5570 /* condition_input_index */ 0,
5571 slow_path->GetEntryLabel(),
5572 /* false_target */ nullptr);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005573}
5574
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005575// This function returns true if a conditional move can be generated for HSelect.
5576// Otherwise it returns false and HSelect must be implemented in terms of conditonal
5577// branches and regular moves.
5578//
5579// If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect.
5580//
5581// While determining feasibility of a conditional move and setting inputs/outputs
5582// are two distinct tasks, this function does both because they share quite a bit
5583// of common logic.
5584static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) {
5585 bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition());
5586 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
5587 HCondition* condition = cond->AsCondition();
5588
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005589 DataType::Type cond_type =
5590 materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType();
5591 DataType::Type dst_type = select->GetType();
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005592
5593 HConstant* cst_true_value = select->GetTrueValue()->AsConstant();
5594 HConstant* cst_false_value = select->GetFalseValue()->AsConstant();
5595 bool is_true_value_zero_constant =
5596 (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern());
5597 bool is_false_value_zero_constant =
5598 (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern());
5599
5600 bool can_move_conditionally = false;
5601 bool use_const_for_false_in = false;
5602 bool use_const_for_true_in = false;
5603
5604 if (!cond->IsConstant()) {
5605 switch (cond_type) {
5606 default:
5607 switch (dst_type) {
5608 default:
5609 // Moving int on int condition.
5610 if (is_r6) {
5611 if (is_true_value_zero_constant) {
5612 // seleqz out_reg, false_reg, cond_reg
5613 can_move_conditionally = true;
5614 use_const_for_true_in = true;
5615 } else if (is_false_value_zero_constant) {
5616 // selnez out_reg, true_reg, cond_reg
5617 can_move_conditionally = true;
5618 use_const_for_false_in = true;
5619 } else if (materialized) {
5620 // Not materializing unmaterialized int conditions
5621 // to keep the instruction count low.
5622 // selnez AT, true_reg, cond_reg
5623 // seleqz TMP, false_reg, cond_reg
5624 // or out_reg, AT, TMP
5625 can_move_conditionally = true;
5626 }
5627 } else {
5628 // movn out_reg, true_reg/ZERO, cond_reg
5629 can_move_conditionally = true;
5630 use_const_for_true_in = is_true_value_zero_constant;
5631 }
5632 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005633 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005634 // Moving long on int condition.
5635 if (is_r6) {
5636 if (is_true_value_zero_constant) {
5637 // seleqz out_reg_lo, false_reg_lo, cond_reg
5638 // seleqz out_reg_hi, false_reg_hi, cond_reg
5639 can_move_conditionally = true;
5640 use_const_for_true_in = true;
5641 } else if (is_false_value_zero_constant) {
5642 // selnez out_reg_lo, true_reg_lo, cond_reg
5643 // selnez out_reg_hi, true_reg_hi, cond_reg
5644 can_move_conditionally = true;
5645 use_const_for_false_in = true;
5646 }
5647 // Other long conditional moves would generate 6+ instructions,
5648 // which is too many.
5649 } else {
5650 // movn out_reg_lo, true_reg_lo/ZERO, cond_reg
5651 // movn out_reg_hi, true_reg_hi/ZERO, cond_reg
5652 can_move_conditionally = true;
5653 use_const_for_true_in = is_true_value_zero_constant;
5654 }
5655 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005656 case DataType::Type::kFloat32:
5657 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005658 // Moving float/double on int condition.
5659 if (is_r6) {
5660 if (materialized) {
5661 // Not materializing unmaterialized int conditions
5662 // to keep the instruction count low.
5663 can_move_conditionally = true;
5664 if (is_true_value_zero_constant) {
5665 // sltu TMP, ZERO, cond_reg
5666 // mtc1 TMP, temp_cond_reg
5667 // seleqz.fmt out_reg, false_reg, temp_cond_reg
5668 use_const_for_true_in = true;
5669 } else if (is_false_value_zero_constant) {
5670 // sltu TMP, ZERO, cond_reg
5671 // mtc1 TMP, temp_cond_reg
5672 // selnez.fmt out_reg, true_reg, temp_cond_reg
5673 use_const_for_false_in = true;
5674 } else {
5675 // sltu TMP, ZERO, cond_reg
5676 // mtc1 TMP, temp_cond_reg
5677 // sel.fmt temp_cond_reg, false_reg, true_reg
5678 // mov.fmt out_reg, temp_cond_reg
5679 }
5680 }
5681 } else {
5682 // movn.fmt out_reg, true_reg, cond_reg
5683 can_move_conditionally = true;
5684 }
5685 break;
5686 }
5687 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005688 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005689 // We don't materialize long comparison now
5690 // and use conditional branches instead.
5691 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005692 case DataType::Type::kFloat32:
5693 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005694 switch (dst_type) {
5695 default:
5696 // Moving int on float/double condition.
5697 if (is_r6) {
5698 if (is_true_value_zero_constant) {
5699 // mfc1 TMP, temp_cond_reg
5700 // seleqz out_reg, false_reg, TMP
5701 can_move_conditionally = true;
5702 use_const_for_true_in = true;
5703 } else if (is_false_value_zero_constant) {
5704 // mfc1 TMP, temp_cond_reg
5705 // selnez out_reg, true_reg, TMP
5706 can_move_conditionally = true;
5707 use_const_for_false_in = true;
5708 } else {
5709 // mfc1 TMP, temp_cond_reg
5710 // selnez AT, true_reg, TMP
5711 // seleqz TMP, false_reg, TMP
5712 // or out_reg, AT, TMP
5713 can_move_conditionally = true;
5714 }
5715 } else {
5716 // movt out_reg, true_reg/ZERO, cc
5717 can_move_conditionally = true;
5718 use_const_for_true_in = is_true_value_zero_constant;
5719 }
5720 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005721 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005722 // Moving long on float/double condition.
5723 if (is_r6) {
5724 if (is_true_value_zero_constant) {
5725 // mfc1 TMP, temp_cond_reg
5726 // seleqz out_reg_lo, false_reg_lo, TMP
5727 // seleqz out_reg_hi, false_reg_hi, TMP
5728 can_move_conditionally = true;
5729 use_const_for_true_in = true;
5730 } else if (is_false_value_zero_constant) {
5731 // mfc1 TMP, temp_cond_reg
5732 // selnez out_reg_lo, true_reg_lo, TMP
5733 // selnez out_reg_hi, true_reg_hi, TMP
5734 can_move_conditionally = true;
5735 use_const_for_false_in = true;
5736 }
5737 // Other long conditional moves would generate 6+ instructions,
5738 // which is too many.
5739 } else {
5740 // movt out_reg_lo, true_reg_lo/ZERO, cc
5741 // movt out_reg_hi, true_reg_hi/ZERO, cc
5742 can_move_conditionally = true;
5743 use_const_for_true_in = is_true_value_zero_constant;
5744 }
5745 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005746 case DataType::Type::kFloat32:
5747 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005748 // Moving float/double on float/double condition.
5749 if (is_r6) {
5750 can_move_conditionally = true;
5751 if (is_true_value_zero_constant) {
5752 // seleqz.fmt out_reg, false_reg, temp_cond_reg
5753 use_const_for_true_in = true;
5754 } else if (is_false_value_zero_constant) {
5755 // selnez.fmt out_reg, true_reg, temp_cond_reg
5756 use_const_for_false_in = true;
5757 } else {
5758 // sel.fmt temp_cond_reg, false_reg, true_reg
5759 // mov.fmt out_reg, temp_cond_reg
5760 }
5761 } else {
5762 // movt.fmt out_reg, true_reg, cc
5763 can_move_conditionally = true;
5764 }
5765 break;
5766 }
5767 break;
5768 }
5769 }
5770
5771 if (can_move_conditionally) {
5772 DCHECK(!use_const_for_false_in || !use_const_for_true_in);
5773 } else {
5774 DCHECK(!use_const_for_false_in);
5775 DCHECK(!use_const_for_true_in);
5776 }
5777
5778 if (locations_to_set != nullptr) {
5779 if (use_const_for_false_in) {
5780 locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value));
5781 } else {
5782 locations_to_set->SetInAt(0,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005783 DataType::IsFloatingPointType(dst_type)
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005784 ? Location::RequiresFpuRegister()
5785 : Location::RequiresRegister());
5786 }
5787 if (use_const_for_true_in) {
5788 locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value));
5789 } else {
5790 locations_to_set->SetInAt(1,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005791 DataType::IsFloatingPointType(dst_type)
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005792 ? Location::RequiresFpuRegister()
5793 : Location::RequiresRegister());
5794 }
5795 if (materialized) {
5796 locations_to_set->SetInAt(2, Location::RequiresRegister());
5797 }
5798 // On R6 we don't require the output to be the same as the
5799 // first input for conditional moves unlike on R2.
5800 bool is_out_same_as_first_in = !can_move_conditionally || !is_r6;
5801 if (is_out_same_as_first_in) {
5802 locations_to_set->SetOut(Location::SameAsFirstInput());
5803 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005804 locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type)
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005805 ? Location::RequiresFpuRegister()
5806 : Location::RequiresRegister());
5807 }
5808 }
5809
5810 return can_move_conditionally;
5811}
5812
5813void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) {
5814 LocationSummary* locations = select->GetLocations();
5815 Location dst = locations->Out();
5816 Location src = locations->InAt(1);
5817 Register src_reg = ZERO;
5818 Register src_reg_high = ZERO;
5819 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
5820 Register cond_reg = TMP;
5821 int cond_cc = 0;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005822 DataType::Type cond_type = DataType::Type::kInt32;
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005823 bool cond_inverted = false;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005824 DataType::Type dst_type = select->GetType();
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005825
5826 if (IsBooleanValueOrMaterializedCondition(cond)) {
5827 cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>();
5828 } else {
5829 HCondition* condition = cond->AsCondition();
5830 LocationSummary* cond_locations = cond->GetLocations();
5831 IfCondition if_cond = condition->GetCondition();
5832 cond_type = condition->InputAt(0)->GetType();
5833 switch (cond_type) {
5834 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005835 DCHECK_NE(cond_type, DataType::Type::kInt64);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005836 cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg);
5837 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005838 case DataType::Type::kFloat32:
5839 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005840 cond_inverted = MaterializeFpCompareR2(if_cond,
5841 condition->IsGtBias(),
5842 cond_type,
5843 cond_locations,
5844 cond_cc);
5845 break;
5846 }
5847 }
5848
5849 DCHECK(dst.Equals(locations->InAt(0)));
5850 if (src.IsRegister()) {
5851 src_reg = src.AsRegister<Register>();
5852 } else if (src.IsRegisterPair()) {
5853 src_reg = src.AsRegisterPairLow<Register>();
5854 src_reg_high = src.AsRegisterPairHigh<Register>();
5855 } else if (src.IsConstant()) {
5856 DCHECK(src.GetConstant()->IsZeroBitPattern());
5857 }
5858
5859 switch (cond_type) {
5860 default:
5861 switch (dst_type) {
5862 default:
5863 if (cond_inverted) {
5864 __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg);
5865 } else {
5866 __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg);
5867 }
5868 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005869 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005870 if (cond_inverted) {
5871 __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg);
5872 __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg);
5873 } else {
5874 __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg);
5875 __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg);
5876 }
5877 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005878 case DataType::Type::kFloat32:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005879 if (cond_inverted) {
5880 __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
5881 } else {
5882 __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
5883 }
5884 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005885 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005886 if (cond_inverted) {
5887 __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
5888 } else {
5889 __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
5890 }
5891 break;
5892 }
5893 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005894 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005895 LOG(FATAL) << "Unreachable";
5896 UNREACHABLE();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005897 case DataType::Type::kFloat32:
5898 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005899 switch (dst_type) {
5900 default:
5901 if (cond_inverted) {
5902 __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc);
5903 } else {
5904 __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc);
5905 }
5906 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005907 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005908 if (cond_inverted) {
5909 __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc);
5910 __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc);
5911 } else {
5912 __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc);
5913 __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc);
5914 }
5915 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005916 case DataType::Type::kFloat32:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005917 if (cond_inverted) {
5918 __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
5919 } else {
5920 __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
5921 }
5922 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005923 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005924 if (cond_inverted) {
5925 __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
5926 } else {
5927 __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
5928 }
5929 break;
5930 }
5931 break;
5932 }
5933}
5934
5935void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) {
5936 LocationSummary* locations = select->GetLocations();
5937 Location dst = locations->Out();
5938 Location false_src = locations->InAt(0);
5939 Location true_src = locations->InAt(1);
5940 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
5941 Register cond_reg = TMP;
5942 FRegister fcond_reg = FTMP;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005943 DataType::Type cond_type = DataType::Type::kInt32;
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005944 bool cond_inverted = false;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005945 DataType::Type dst_type = select->GetType();
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005946
5947 if (IsBooleanValueOrMaterializedCondition(cond)) {
5948 cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>();
5949 } else {
5950 HCondition* condition = cond->AsCondition();
5951 LocationSummary* cond_locations = cond->GetLocations();
5952 IfCondition if_cond = condition->GetCondition();
5953 cond_type = condition->InputAt(0)->GetType();
5954 switch (cond_type) {
5955 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005956 DCHECK_NE(cond_type, DataType::Type::kInt64);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005957 cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg);
5958 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005959 case DataType::Type::kFloat32:
5960 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005961 cond_inverted = MaterializeFpCompareR6(if_cond,
5962 condition->IsGtBias(),
5963 cond_type,
5964 cond_locations,
5965 fcond_reg);
5966 break;
5967 }
5968 }
5969
5970 if (true_src.IsConstant()) {
5971 DCHECK(true_src.GetConstant()->IsZeroBitPattern());
5972 }
5973 if (false_src.IsConstant()) {
5974 DCHECK(false_src.GetConstant()->IsZeroBitPattern());
5975 }
5976
5977 switch (dst_type) {
5978 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005979 if (DataType::IsFloatingPointType(cond_type)) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005980 __ Mfc1(cond_reg, fcond_reg);
5981 }
5982 if (true_src.IsConstant()) {
5983 if (cond_inverted) {
5984 __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg);
5985 } else {
5986 __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg);
5987 }
5988 } else if (false_src.IsConstant()) {
5989 if (cond_inverted) {
5990 __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg);
5991 } else {
5992 __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg);
5993 }
5994 } else {
5995 DCHECK_NE(cond_reg, AT);
5996 if (cond_inverted) {
5997 __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg);
5998 __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg);
5999 } else {
6000 __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg);
6001 __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg);
6002 }
6003 __ Or(dst.AsRegister<Register>(), AT, TMP);
6004 }
6005 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006006 case DataType::Type::kInt64: {
6007 if (DataType::IsFloatingPointType(cond_type)) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006008 __ Mfc1(cond_reg, fcond_reg);
6009 }
6010 Register dst_lo = dst.AsRegisterPairLow<Register>();
6011 Register dst_hi = dst.AsRegisterPairHigh<Register>();
6012 if (true_src.IsConstant()) {
6013 Register src_lo = false_src.AsRegisterPairLow<Register>();
6014 Register src_hi = false_src.AsRegisterPairHigh<Register>();
6015 if (cond_inverted) {
6016 __ Selnez(dst_lo, src_lo, cond_reg);
6017 __ Selnez(dst_hi, src_hi, cond_reg);
6018 } else {
6019 __ Seleqz(dst_lo, src_lo, cond_reg);
6020 __ Seleqz(dst_hi, src_hi, cond_reg);
6021 }
6022 } else {
6023 DCHECK(false_src.IsConstant());
6024 Register src_lo = true_src.AsRegisterPairLow<Register>();
6025 Register src_hi = true_src.AsRegisterPairHigh<Register>();
6026 if (cond_inverted) {
6027 __ Seleqz(dst_lo, src_lo, cond_reg);
6028 __ Seleqz(dst_hi, src_hi, cond_reg);
6029 } else {
6030 __ Selnez(dst_lo, src_lo, cond_reg);
6031 __ Selnez(dst_hi, src_hi, cond_reg);
6032 }
6033 }
6034 break;
6035 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006036 case DataType::Type::kFloat32: {
6037 if (!DataType::IsFloatingPointType(cond_type)) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006038 // sel*.fmt tests bit 0 of the condition register, account for that.
6039 __ Sltu(TMP, ZERO, cond_reg);
6040 __ Mtc1(TMP, fcond_reg);
6041 }
6042 FRegister dst_reg = dst.AsFpuRegister<FRegister>();
6043 if (true_src.IsConstant()) {
6044 FRegister src_reg = false_src.AsFpuRegister<FRegister>();
6045 if (cond_inverted) {
6046 __ SelnezS(dst_reg, src_reg, fcond_reg);
6047 } else {
6048 __ SeleqzS(dst_reg, src_reg, fcond_reg);
6049 }
6050 } else if (false_src.IsConstant()) {
6051 FRegister src_reg = true_src.AsFpuRegister<FRegister>();
6052 if (cond_inverted) {
6053 __ SeleqzS(dst_reg, src_reg, fcond_reg);
6054 } else {
6055 __ SelnezS(dst_reg, src_reg, fcond_reg);
6056 }
6057 } else {
6058 if (cond_inverted) {
6059 __ SelS(fcond_reg,
6060 true_src.AsFpuRegister<FRegister>(),
6061 false_src.AsFpuRegister<FRegister>());
6062 } else {
6063 __ SelS(fcond_reg,
6064 false_src.AsFpuRegister<FRegister>(),
6065 true_src.AsFpuRegister<FRegister>());
6066 }
6067 __ MovS(dst_reg, fcond_reg);
6068 }
6069 break;
6070 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006071 case DataType::Type::kFloat64: {
6072 if (!DataType::IsFloatingPointType(cond_type)) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006073 // sel*.fmt tests bit 0 of the condition register, account for that.
6074 __ Sltu(TMP, ZERO, cond_reg);
6075 __ Mtc1(TMP, fcond_reg);
6076 }
6077 FRegister dst_reg = dst.AsFpuRegister<FRegister>();
6078 if (true_src.IsConstant()) {
6079 FRegister src_reg = false_src.AsFpuRegister<FRegister>();
6080 if (cond_inverted) {
6081 __ SelnezD(dst_reg, src_reg, fcond_reg);
6082 } else {
6083 __ SeleqzD(dst_reg, src_reg, fcond_reg);
6084 }
6085 } else if (false_src.IsConstant()) {
6086 FRegister src_reg = true_src.AsFpuRegister<FRegister>();
6087 if (cond_inverted) {
6088 __ SeleqzD(dst_reg, src_reg, fcond_reg);
6089 } else {
6090 __ SelnezD(dst_reg, src_reg, fcond_reg);
6091 }
6092 } else {
6093 if (cond_inverted) {
6094 __ SelD(fcond_reg,
6095 true_src.AsFpuRegister<FRegister>(),
6096 false_src.AsFpuRegister<FRegister>());
6097 } else {
6098 __ SelD(fcond_reg,
6099 false_src.AsFpuRegister<FRegister>(),
6100 true_src.AsFpuRegister<FRegister>());
6101 }
6102 __ MovD(dst_reg, fcond_reg);
6103 }
6104 break;
6105 }
6106 }
6107}
6108
Goran Jakovljevicc6418422016-12-05 16:31:55 +01006109void LocationsBuilderMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006110 LocationSummary* locations = new (GetGraph()->GetAllocator())
Goran Jakovljevicc6418422016-12-05 16:31:55 +01006111 LocationSummary(flag, LocationSummary::kNoCall);
6112 locations->SetOut(Location::RequiresRegister());
Mingyao Yang063fc772016-08-02 11:02:54 -07006113}
6114
Goran Jakovljevicc6418422016-12-05 16:31:55 +01006115void InstructionCodeGeneratorMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
6116 __ LoadFromOffset(kLoadWord,
6117 flag->GetLocations()->Out().AsRegister<Register>(),
6118 SP,
6119 codegen_->GetStackOffsetOfShouldDeoptimizeFlag());
Mingyao Yang063fc772016-08-02 11:02:54 -07006120}
6121
David Brazdil74eb1b22015-12-14 11:44:01 +00006122void LocationsBuilderMIPS::VisitSelect(HSelect* select) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006123 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006124 CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations);
David Brazdil74eb1b22015-12-14 11:44:01 +00006125}
6126
6127void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006128 bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6();
6129 if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) {
6130 if (is_r6) {
6131 GenConditionalMoveR6(select);
6132 } else {
6133 GenConditionalMoveR2(select);
6134 }
6135 } else {
6136 LocationSummary* locations = select->GetLocations();
6137 MipsLabel false_target;
6138 GenerateTestAndBranch(select,
6139 /* condition_input_index */ 2,
6140 /* true_target */ nullptr,
6141 &false_target);
6142 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
6143 __ Bind(&false_target);
6144 }
David Brazdil74eb1b22015-12-14 11:44:01 +00006145}
6146
David Srbecky0cf44932015-12-09 14:09:59 +00006147void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006148 new (GetGraph()->GetAllocator()) LocationSummary(info);
David Srbecky0cf44932015-12-09 14:09:59 +00006149}
6150
David Srbeckyd28f4a02016-03-14 17:14:24 +00006151void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) {
6152 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00006153}
6154
6155void CodeGeneratorMIPS::GenerateNop() {
6156 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00006157}
6158
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006159void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006160 DataType::Type field_type = field_info.GetFieldType();
6161 bool is_wide = (field_type == DataType::Type::kInt64) || (field_type == DataType::Type::kFloat64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006162 bool generate_volatile = field_info.IsVolatile() && is_wide;
Alexey Frunze15958152017-02-09 19:08:30 -08006163 bool object_field_get_with_read_barrier =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006164 kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference);
Vladimir Markoca6fff82017-10-03 14:49:14 +01006165 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
Alexey Frunze15958152017-02-09 19:08:30 -08006166 instruction,
6167 generate_volatile
6168 ? LocationSummary::kCallOnMainOnly
6169 : (object_field_get_with_read_barrier
6170 ? LocationSummary::kCallOnSlowPath
6171 : LocationSummary::kNoCall));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006172
Alexey Frunzec61c0762017-04-10 13:54:23 -07006173 if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
6174 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
6175 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006176 locations->SetInAt(0, Location::RequiresRegister());
6177 if (generate_volatile) {
6178 InvokeRuntimeCallingConvention calling_convention;
6179 // need A0 to hold base + offset
6180 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006181 if (field_type == DataType::Type::kInt64) {
6182 locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kInt64));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006183 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006184 // Use Location::Any() to prevent situations when running out of available fp registers.
6185 locations->SetOut(Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006186 // Need some temp core regs since FP results are returned in core registers
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006187 Location reg = calling_convention.GetReturnLocation(DataType::Type::kInt64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006188 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>()));
6189 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>()));
6190 }
6191 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006192 if (DataType::IsFloatingPointType(instruction->GetType())) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006193 locations->SetOut(Location::RequiresFpuRegister());
6194 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08006195 // The output overlaps in the case of an object field get with
6196 // read barriers enabled: we do not want the move to overwrite the
6197 // object's location, as we need it to emit the read barrier.
6198 locations->SetOut(Location::RequiresRegister(),
6199 object_field_get_with_read_barrier
6200 ? Location::kOutputOverlap
6201 : Location::kNoOutputOverlap);
6202 }
6203 if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
6204 // We need a temporary register for the read barrier marking slow
6205 // path in CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier.
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006206 if (!kBakerReadBarrierThunksEnableForFields) {
6207 locations->AddTemp(Location::RequiresRegister());
6208 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006209 }
6210 }
6211}
6212
6213void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction,
6214 const FieldInfo& field_info,
6215 uint32_t dex_pc) {
Vladimir Marko61b92282017-10-11 13:23:17 +01006216 DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType()));
6217 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006218 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08006219 Location obj_loc = locations->InAt(0);
6220 Register obj = obj_loc.AsRegister<Register>();
6221 Location dst_loc = locations->Out();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006222 LoadOperandType load_type = kLoadUnsignedByte;
6223 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01006224 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Tijana Jakovljevic57433862017-01-17 16:59:03 +01006225 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006226
6227 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006228 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006229 case DataType::Type::kUint8:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006230 load_type = kLoadUnsignedByte;
6231 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006232 case DataType::Type::kInt8:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006233 load_type = kLoadSignedByte;
6234 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006235 case DataType::Type::kUint16:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006236 load_type = kLoadUnsignedHalfword;
6237 break;
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006238 case DataType::Type::kInt16:
6239 load_type = kLoadSignedHalfword;
6240 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006241 case DataType::Type::kInt32:
6242 case DataType::Type::kFloat32:
6243 case DataType::Type::kReference:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006244 load_type = kLoadWord;
6245 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006246 case DataType::Type::kInt64:
6247 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006248 load_type = kLoadDoubleword;
6249 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006250 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006251 LOG(FATAL) << "Unreachable type " << type;
6252 UNREACHABLE();
6253 }
6254
6255 if (is_volatile && load_type == kLoadDoubleword) {
6256 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01006257 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006258 // Do implicit Null check
Goran Jakovljevic2e61a572017-10-23 08:58:15 +02006259 __ LoadFromOffset(kLoadWord,
6260 ZERO,
6261 locations->GetTemp(0).AsRegister<Register>(),
6262 0,
6263 null_checker);
Serban Constantinescufca16662016-07-14 09:21:59 +01006264 codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006265 CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006266 if (type == DataType::Type::kFloat64) {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006267 // FP results are returned in core registers. Need to move them.
Alexey Frunze15958152017-02-09 19:08:30 -08006268 if (dst_loc.IsFpuRegister()) {
6269 __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), dst_loc.AsFpuRegister<FRegister>());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006270 __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
Alexey Frunze15958152017-02-09 19:08:30 -08006271 dst_loc.AsFpuRegister<FRegister>());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006272 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08006273 DCHECK(dst_loc.IsDoubleStackSlot());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006274 __ StoreToOffset(kStoreWord,
6275 locations->GetTemp(1).AsRegister<Register>(),
6276 SP,
Alexey Frunze15958152017-02-09 19:08:30 -08006277 dst_loc.GetStackIndex());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006278 __ StoreToOffset(kStoreWord,
6279 locations->GetTemp(2).AsRegister<Register>(),
6280 SP,
Alexey Frunze15958152017-02-09 19:08:30 -08006281 dst_loc.GetStackIndex() + 4);
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006282 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006283 }
6284 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006285 if (type == DataType::Type::kReference) {
Alexey Frunze15958152017-02-09 19:08:30 -08006286 // /* HeapReference<Object> */ dst = *(obj + offset)
6287 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006288 Location temp_loc =
6289 kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0);
Alexey Frunze15958152017-02-09 19:08:30 -08006290 // Note that a potential implicit null check is handled in this
6291 // CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier call.
6292 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
6293 dst_loc,
6294 obj,
6295 offset,
6296 temp_loc,
6297 /* needs_null_check */ true);
6298 if (is_volatile) {
6299 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
6300 }
6301 } else {
6302 __ LoadFromOffset(kLoadWord, dst_loc.AsRegister<Register>(), obj, offset, null_checker);
6303 if (is_volatile) {
6304 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
6305 }
6306 // If read barriers are enabled, emit read barriers other than
6307 // Baker's using a slow path (and also unpoison the loaded
6308 // reference, if heap poisoning is enabled).
6309 codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset);
6310 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006311 } else if (!DataType::IsFloatingPointType(type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006312 Register dst;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006313 if (type == DataType::Type::kInt64) {
Alexey Frunze15958152017-02-09 19:08:30 -08006314 DCHECK(dst_loc.IsRegisterPair());
6315 dst = dst_loc.AsRegisterPairLow<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006316 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08006317 DCHECK(dst_loc.IsRegister());
6318 dst = dst_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006319 }
Alexey Frunze2923db72016-08-20 01:55:47 -07006320 __ LoadFromOffset(load_type, dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006321 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08006322 DCHECK(dst_loc.IsFpuRegister());
6323 FRegister dst = dst_loc.AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006324 if (type == DataType::Type::kFloat32) {
Alexey Frunze2923db72016-08-20 01:55:47 -07006325 __ LoadSFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006326 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07006327 __ LoadDFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006328 }
6329 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006330 }
6331
Alexey Frunze15958152017-02-09 19:08:30 -08006332 // Memory barriers, in the case of references, are handled in the
6333 // previous switch statement.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006334 if (is_volatile && (type != DataType::Type::kReference)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006335 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
6336 }
6337}
6338
6339void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006340 DataType::Type field_type = field_info.GetFieldType();
6341 bool is_wide = (field_type == DataType::Type::kInt64) || (field_type == DataType::Type::kFloat64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006342 bool generate_volatile = field_info.IsVolatile() && is_wide;
Vladimir Markoca6fff82017-10-03 14:49:14 +01006343 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006344 instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006345
6346 locations->SetInAt(0, Location::RequiresRegister());
6347 if (generate_volatile) {
6348 InvokeRuntimeCallingConvention calling_convention;
6349 // need A0 to hold base + offset
6350 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006351 if (field_type == DataType::Type::kInt64) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006352 locations->SetInAt(1, Location::RegisterPairLocation(
6353 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
6354 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006355 // Use Location::Any() to prevent situations when running out of available fp registers.
6356 locations->SetInAt(1, Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006357 // Pass FP parameters in core registers.
6358 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
6359 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
6360 }
6361 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006362 if (DataType::IsFloatingPointType(field_type)) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006363 locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006364 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006365 locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006366 }
6367 }
6368}
6369
6370void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction,
6371 const FieldInfo& field_info,
Goran Jakovljevice114da22016-12-26 14:21:43 +01006372 uint32_t dex_pc,
6373 bool value_can_be_null) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006374 DataType::Type type = field_info.GetFieldType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006375 LocationSummary* locations = instruction->GetLocations();
6376 Register obj = locations->InAt(0).AsRegister<Register>();
Alexey Frunzef58b2482016-09-02 22:14:06 -07006377 Location value_location = locations->InAt(1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006378 StoreOperandType store_type = kStoreByte;
6379 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01006380 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Alexey Frunzec061de12017-02-14 13:27:23 -08006381 bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1));
Tijana Jakovljevic57433862017-01-17 16:59:03 +01006382 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006383
6384 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006385 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006386 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006387 case DataType::Type::kInt8:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006388 store_type = kStoreByte;
6389 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006390 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006391 case DataType::Type::kInt16:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006392 store_type = kStoreHalfword;
6393 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006394 case DataType::Type::kInt32:
6395 case DataType::Type::kFloat32:
6396 case DataType::Type::kReference:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006397 store_type = kStoreWord;
6398 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006399 case DataType::Type::kInt64:
6400 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006401 store_type = kStoreDoubleword;
6402 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006403 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006404 LOG(FATAL) << "Unreachable type " << type;
6405 UNREACHABLE();
6406 }
6407
6408 if (is_volatile) {
6409 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
6410 }
6411
6412 if (is_volatile && store_type == kStoreDoubleword) {
6413 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01006414 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006415 // Do implicit Null check.
Goran Jakovljevic2e61a572017-10-23 08:58:15 +02006416 __ LoadFromOffset(kLoadWord,
6417 ZERO,
6418 locations->GetTemp(0).AsRegister<Register>(),
6419 0,
6420 null_checker);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006421 if (type == DataType::Type::kFloat64) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006422 // Pass FP parameters in core registers.
Alexey Frunzef58b2482016-09-02 22:14:06 -07006423 if (value_location.IsFpuRegister()) {
6424 __ Mfc1(locations->GetTemp(1).AsRegister<Register>(),
6425 value_location.AsFpuRegister<FRegister>());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006426 __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
Alexey Frunzef58b2482016-09-02 22:14:06 -07006427 value_location.AsFpuRegister<FRegister>());
6428 } else if (value_location.IsDoubleStackSlot()) {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006429 __ LoadFromOffset(kLoadWord,
6430 locations->GetTemp(1).AsRegister<Register>(),
6431 SP,
Alexey Frunzef58b2482016-09-02 22:14:06 -07006432 value_location.GetStackIndex());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006433 __ LoadFromOffset(kLoadWord,
6434 locations->GetTemp(2).AsRegister<Register>(),
6435 SP,
Alexey Frunzef58b2482016-09-02 22:14:06 -07006436 value_location.GetStackIndex() + 4);
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006437 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006438 DCHECK(value_location.IsConstant());
6439 DCHECK(value_location.GetConstant()->IsDoubleConstant());
6440 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006441 __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(),
6442 locations->GetTemp(1).AsRegister<Register>(),
6443 value);
6444 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006445 }
Serban Constantinescufca16662016-07-14 09:21:59 +01006446 codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006447 CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>();
6448 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006449 if (value_location.IsConstant()) {
6450 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
6451 __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006452 } else if (!DataType::IsFloatingPointType(type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006453 Register src;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006454 if (type == DataType::Type::kInt64) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006455 src = value_location.AsRegisterPairLow<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006456 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006457 src = value_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006458 }
Alexey Frunzec061de12017-02-14 13:27:23 -08006459 if (kPoisonHeapReferences && needs_write_barrier) {
6460 // Note that in the case where `value` is a null reference,
6461 // we do not enter this block, as a null reference does not
6462 // need poisoning.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006463 DCHECK_EQ(type, DataType::Type::kReference);
Alexey Frunzec061de12017-02-14 13:27:23 -08006464 __ PoisonHeapReference(TMP, src);
6465 __ StoreToOffset(store_type, TMP, obj, offset, null_checker);
6466 } else {
6467 __ StoreToOffset(store_type, src, obj, offset, null_checker);
6468 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006469 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006470 FRegister src = value_location.AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006471 if (type == DataType::Type::kFloat32) {
Alexey Frunze2923db72016-08-20 01:55:47 -07006472 __ StoreSToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006473 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07006474 __ StoreDToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006475 }
6476 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006477 }
6478
Alexey Frunzec061de12017-02-14 13:27:23 -08006479 if (needs_write_barrier) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006480 Register src = value_location.AsRegister<Register>();
Goran Jakovljevice114da22016-12-26 14:21:43 +01006481 codegen_->MarkGCCard(obj, src, value_can_be_null);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006482 }
6483
6484 if (is_volatile) {
6485 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
6486 }
6487}
6488
6489void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
6490 HandleFieldGet(instruction, instruction->GetFieldInfo());
6491}
6492
6493void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
6494 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
6495}
6496
6497void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
6498 HandleFieldSet(instruction, instruction->GetFieldInfo());
6499}
6500
6501void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Goran Jakovljevice114da22016-12-26 14:21:43 +01006502 HandleFieldSet(instruction,
6503 instruction->GetFieldInfo(),
6504 instruction->GetDexPc(),
6505 instruction->GetValueCanBeNull());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006506}
6507
Alexey Frunze15958152017-02-09 19:08:30 -08006508void InstructionCodeGeneratorMIPS::GenerateReferenceLoadOneRegister(
6509 HInstruction* instruction,
6510 Location out,
6511 uint32_t offset,
6512 Location maybe_temp,
6513 ReadBarrierOption read_barrier_option) {
6514 Register out_reg = out.AsRegister<Register>();
6515 if (read_barrier_option == kWithReadBarrier) {
6516 CHECK(kEmitCompilerReadBarrier);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006517 if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) {
6518 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
6519 }
Alexey Frunze15958152017-02-09 19:08:30 -08006520 if (kUseBakerReadBarrier) {
6521 // Load with fast path based Baker's read barrier.
6522 // /* HeapReference<Object> */ out = *(out + offset)
6523 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
6524 out,
6525 out_reg,
6526 offset,
6527 maybe_temp,
6528 /* needs_null_check */ false);
6529 } else {
6530 // Load with slow path based read barrier.
6531 // Save the value of `out` into `maybe_temp` before overwriting it
6532 // in the following move operation, as we will need it for the
6533 // read barrier below.
6534 __ Move(maybe_temp.AsRegister<Register>(), out_reg);
6535 // /* HeapReference<Object> */ out = *(out + offset)
6536 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
6537 codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset);
6538 }
6539 } else {
6540 // Plain load with no read barrier.
6541 // /* HeapReference<Object> */ out = *(out + offset)
6542 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
6543 __ MaybeUnpoisonHeapReference(out_reg);
6544 }
6545}
6546
6547void InstructionCodeGeneratorMIPS::GenerateReferenceLoadTwoRegisters(
6548 HInstruction* instruction,
6549 Location out,
6550 Location obj,
6551 uint32_t offset,
6552 Location maybe_temp,
6553 ReadBarrierOption read_barrier_option) {
6554 Register out_reg = out.AsRegister<Register>();
6555 Register obj_reg = obj.AsRegister<Register>();
6556 if (read_barrier_option == kWithReadBarrier) {
6557 CHECK(kEmitCompilerReadBarrier);
6558 if (kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006559 if (!kBakerReadBarrierThunksEnableForFields) {
6560 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
6561 }
Alexey Frunze15958152017-02-09 19:08:30 -08006562 // Load with fast path based Baker's read barrier.
6563 // /* HeapReference<Object> */ out = *(obj + offset)
6564 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
6565 out,
6566 obj_reg,
6567 offset,
6568 maybe_temp,
6569 /* needs_null_check */ false);
6570 } else {
6571 // Load with slow path based read barrier.
6572 // /* HeapReference<Object> */ out = *(obj + offset)
6573 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6574 codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset);
6575 }
6576 } else {
6577 // Plain load with no read barrier.
6578 // /* HeapReference<Object> */ out = *(obj + offset)
6579 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6580 __ MaybeUnpoisonHeapReference(out_reg);
6581 }
6582}
6583
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006584static inline int GetBakerMarkThunkNumber(Register reg) {
6585 static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 21, "Expecting equal");
6586 if (reg >= V0 && reg <= T7) { // 14 consequtive regs.
6587 return reg - V0;
6588 } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs.
6589 return 14 + (reg - S2);
6590 } else if (reg == FP) { // One more.
6591 return 20;
6592 }
6593 LOG(FATAL) << "Unexpected register " << reg;
6594 UNREACHABLE();
6595}
6596
6597static inline int GetBakerMarkFieldArrayThunkDisplacement(Register reg, bool short_offset) {
6598 int num = GetBakerMarkThunkNumber(reg) +
6599 (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0);
6600 return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE;
6601}
6602
6603static inline int GetBakerMarkGcRootThunkDisplacement(Register reg) {
6604 return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE +
6605 BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET;
6606}
6607
Alexey Frunze15958152017-02-09 19:08:30 -08006608void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(HInstruction* instruction,
6609 Location root,
6610 Register obj,
6611 uint32_t offset,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006612 ReadBarrierOption read_barrier_option,
6613 MipsLabel* label_low) {
6614 bool reordering;
6615 if (label_low != nullptr) {
6616 DCHECK_EQ(offset, 0x5678u);
6617 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07006618 Register root_reg = root.AsRegister<Register>();
Alexey Frunze15958152017-02-09 19:08:30 -08006619 if (read_barrier_option == kWithReadBarrier) {
6620 DCHECK(kEmitCompilerReadBarrier);
6621 if (kUseBakerReadBarrier) {
6622 // Fast path implementation of art::ReadBarrier::BarrierForRoot when
6623 // Baker's read barrier are used:
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006624 if (kBakerReadBarrierThunksEnableForGcRoots) {
6625 // Note that we do not actually check the value of `GetIsGcMarking()`
6626 // to decide whether to mark the loaded GC root or not. Instead, we
6627 // load into `temp` (T9) the read barrier mark introspection entrypoint.
6628 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
6629 // vice versa.
6630 //
6631 // We use thunks for the slow path. That thunk checks the reference
6632 // and jumps to the entrypoint if needed.
6633 //
6634 // temp = Thread::Current()->pReadBarrierMarkReg00
6635 // // AKA &art_quick_read_barrier_mark_introspection.
6636 // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load.
6637 // if (temp != nullptr) {
6638 // temp = &gc_root_thunk<root_reg>
6639 // root = temp(root)
6640 // }
Alexey Frunze15958152017-02-09 19:08:30 -08006641
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006642 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
6643 const int32_t entry_point_offset =
6644 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0);
6645 const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg);
6646 int16_t offset_low = Low16Bits(offset);
6647 int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign
6648 // extension in lw.
6649 bool short_offset = IsInt<16>(static_cast<int32_t>(offset));
6650 Register base = short_offset ? obj : TMP;
6651 // Loading the entrypoint does not require a load acquire since it is only changed when
6652 // threads are suspended or running a checkpoint.
6653 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
6654 reordering = __ SetReorder(false);
6655 if (!short_offset) {
6656 DCHECK(!label_low);
6657 __ AddUpper(base, obj, offset_high);
6658 }
Alexey Frunze0cab6562017-07-25 15:19:36 -07006659 MipsLabel skip_call;
6660 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006661 if (label_low != nullptr) {
6662 DCHECK(short_offset);
6663 __ Bind(label_low);
6664 }
6665 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6666 __ LoadFromOffset(kLoadWord, root_reg, base, offset_low); // Single instruction
6667 // in delay slot.
6668 if (isR6) {
6669 __ Jialc(T9, thunk_disp);
6670 } else {
6671 __ Addiu(T9, T9, thunk_disp);
6672 __ Jalr(T9);
6673 __ Nop();
6674 }
Alexey Frunze0cab6562017-07-25 15:19:36 -07006675 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006676 __ SetReorder(reordering);
6677 } else {
6678 // Note that we do not actually check the value of `GetIsGcMarking()`
6679 // to decide whether to mark the loaded GC root or not. Instead, we
6680 // load into `temp` (T9) the read barrier mark entry point corresponding
6681 // to register `root`. If `temp` is null, it means that `GetIsGcMarking()`
6682 // is false, and vice versa.
6683 //
6684 // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load.
6685 // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg()
6686 // if (temp != null) {
6687 // root = temp(root)
6688 // }
Alexey Frunze15958152017-02-09 19:08:30 -08006689
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006690 if (label_low != nullptr) {
6691 reordering = __ SetReorder(false);
6692 __ Bind(label_low);
6693 }
6694 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6695 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6696 if (label_low != nullptr) {
6697 __ SetReorder(reordering);
6698 }
6699 static_assert(
6700 sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>),
6701 "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> "
6702 "have different sizes.");
6703 static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t),
6704 "art::mirror::CompressedReference<mirror::Object> and int32_t "
6705 "have different sizes.");
Alexey Frunze15958152017-02-09 19:08:30 -08006706
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006707 // Slow path marking the GC root `root`.
6708 Location temp = Location::RegisterLocation(T9);
6709 SlowPathCodeMIPS* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01006710 new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS(
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006711 instruction,
6712 root,
6713 /*entrypoint*/ temp);
6714 codegen_->AddSlowPath(slow_path);
6715
6716 const int32_t entry_point_offset =
6717 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(root.reg() - 1);
6718 // Loading the entrypoint does not require a load acquire since it is only changed when
6719 // threads are suspended or running a checkpoint.
6720 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset);
6721 __ Bnez(temp.AsRegister<Register>(), slow_path->GetEntryLabel());
6722 __ Bind(slow_path->GetExitLabel());
6723 }
Alexey Frunze15958152017-02-09 19:08:30 -08006724 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006725 if (label_low != nullptr) {
6726 reordering = __ SetReorder(false);
6727 __ Bind(label_low);
6728 }
Alexey Frunze15958152017-02-09 19:08:30 -08006729 // GC root loaded through a slow path for read barriers other
6730 // than Baker's.
6731 // /* GcRoot<mirror::Object>* */ root = obj + offset
6732 __ Addiu32(root_reg, obj, offset);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006733 if (label_low != nullptr) {
6734 __ SetReorder(reordering);
6735 }
Alexey Frunze15958152017-02-09 19:08:30 -08006736 // /* mirror::Object* */ root = root->Read()
6737 codegen_->GenerateReadBarrierForRootSlow(instruction, root, root);
6738 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07006739 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006740 if (label_low != nullptr) {
6741 reordering = __ SetReorder(false);
6742 __ Bind(label_low);
6743 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07006744 // Plain GC root load with no read barrier.
6745 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6746 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6747 // Note that GC roots are not affected by heap poisoning, thus we
6748 // do not have to unpoison `root_reg` here.
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006749 if (label_low != nullptr) {
6750 __ SetReorder(reordering);
6751 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07006752 }
6753}
6754
Alexey Frunze15958152017-02-09 19:08:30 -08006755void CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
6756 Location ref,
6757 Register obj,
6758 uint32_t offset,
6759 Location temp,
6760 bool needs_null_check) {
6761 DCHECK(kEmitCompilerReadBarrier);
6762 DCHECK(kUseBakerReadBarrier);
6763
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006764 if (kBakerReadBarrierThunksEnableForFields) {
6765 // Note that we do not actually check the value of `GetIsGcMarking()`
6766 // to decide whether to mark the loaded reference or not. Instead, we
6767 // load into `temp` (T9) the read barrier mark introspection entrypoint.
6768 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
6769 // vice versa.
6770 //
6771 // We use thunks for the slow path. That thunk checks the reference
6772 // and jumps to the entrypoint if needed. If the holder is not gray,
6773 // it issues a load-load memory barrier and returns to the original
6774 // reference load.
6775 //
6776 // temp = Thread::Current()->pReadBarrierMarkReg00
6777 // // AKA &art_quick_read_barrier_mark_introspection.
6778 // if (temp != nullptr) {
6779 // temp = &field_array_thunk<holder_reg>
6780 // temp()
6781 // }
6782 // not_gray_return_address:
6783 // // If the offset is too large to fit into the lw instruction, we
6784 // // use an adjusted base register (TMP) here. This register
6785 // // receives bits 16 ... 31 of the offset before the thunk invocation
6786 // // and the thunk benefits from it.
6787 // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load.
6788 // gray_return_address:
6789
6790 DCHECK(temp.IsInvalid());
6791 bool isR6 = GetInstructionSetFeatures().IsR6();
6792 int16_t offset_low = Low16Bits(offset);
6793 int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lw.
6794 bool short_offset = IsInt<16>(static_cast<int32_t>(offset));
6795 bool reordering = __ SetReorder(false);
6796 const int32_t entry_point_offset =
6797 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0);
6798 // There may have or may have not been a null check if the field offset is smaller than
6799 // the page size.
6800 // There must've been a null check in case it's actually a load from an array.
6801 // We will, however, perform an explicit null check in the thunk as it's easier to
6802 // do it than not.
6803 if (instruction->IsArrayGet()) {
6804 DCHECK(!needs_null_check);
6805 }
6806 const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset);
6807 // Loading the entrypoint does not require a load acquire since it is only changed when
6808 // threads are suspended or running a checkpoint.
6809 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
6810 Register ref_reg = ref.AsRegister<Register>();
6811 Register base = short_offset ? obj : TMP;
Alexey Frunze0cab6562017-07-25 15:19:36 -07006812 MipsLabel skip_call;
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006813 if (short_offset) {
6814 if (isR6) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07006815 __ Beqzc(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006816 __ Nop(); // In forbidden slot.
6817 __ Jialc(T9, thunk_disp);
6818 } else {
Alexey Frunze0cab6562017-07-25 15:19:36 -07006819 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006820 __ Addiu(T9, T9, thunk_disp); // In delay slot.
6821 __ Jalr(T9);
6822 __ Nop(); // In delay slot.
6823 }
Alexey Frunze0cab6562017-07-25 15:19:36 -07006824 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006825 } else {
6826 if (isR6) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07006827 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006828 __ Aui(base, obj, offset_high); // In delay slot.
6829 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07006830 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006831 } else {
6832 __ Lui(base, offset_high);
Alexey Frunze0cab6562017-07-25 15:19:36 -07006833 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006834 __ Addiu(T9, T9, thunk_disp); // In delay slot.
6835 __ Jalr(T9);
Alexey Frunze0cab6562017-07-25 15:19:36 -07006836 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006837 __ Addu(base, base, obj); // In delay slot.
6838 }
6839 }
6840 // /* HeapReference<Object> */ ref = *(obj + offset)
6841 __ LoadFromOffset(kLoadWord, ref_reg, base, offset_low); // Single instruction.
6842 if (needs_null_check) {
6843 MaybeRecordImplicitNullCheck(instruction);
6844 }
6845 __ MaybeUnpoisonHeapReference(ref_reg);
6846 __ SetReorder(reordering);
6847 return;
6848 }
6849
Alexey Frunze15958152017-02-09 19:08:30 -08006850 // /* HeapReference<Object> */ ref = *(obj + offset)
6851 Location no_index = Location::NoLocation();
6852 ScaleFactor no_scale_factor = TIMES_1;
6853 GenerateReferenceLoadWithBakerReadBarrier(instruction,
6854 ref,
6855 obj,
6856 offset,
6857 no_index,
6858 no_scale_factor,
6859 temp,
6860 needs_null_check);
6861}
6862
6863void CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
6864 Location ref,
6865 Register obj,
6866 uint32_t data_offset,
6867 Location index,
6868 Location temp,
6869 bool needs_null_check) {
6870 DCHECK(kEmitCompilerReadBarrier);
6871 DCHECK(kUseBakerReadBarrier);
6872
6873 static_assert(
6874 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
6875 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006876 ScaleFactor scale_factor = TIMES_4;
6877
6878 if (kBakerReadBarrierThunksEnableForArrays) {
6879 // Note that we do not actually check the value of `GetIsGcMarking()`
6880 // to decide whether to mark the loaded reference or not. Instead, we
6881 // load into `temp` (T9) the read barrier mark introspection entrypoint.
6882 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
6883 // vice versa.
6884 //
6885 // We use thunks for the slow path. That thunk checks the reference
6886 // and jumps to the entrypoint if needed. If the holder is not gray,
6887 // it issues a load-load memory barrier and returns to the original
6888 // reference load.
6889 //
6890 // temp = Thread::Current()->pReadBarrierMarkReg00
6891 // // AKA &art_quick_read_barrier_mark_introspection.
6892 // if (temp != nullptr) {
6893 // temp = &field_array_thunk<holder_reg>
6894 // temp()
6895 // }
6896 // not_gray_return_address:
6897 // // The element address is pre-calculated in the TMP register before the
6898 // // thunk invocation and the thunk benefits from it.
6899 // HeapReference<mirror::Object> reference = data[index]; // Original reference load.
6900 // gray_return_address:
6901
6902 DCHECK(temp.IsInvalid());
6903 DCHECK(index.IsValid());
6904 bool reordering = __ SetReorder(false);
6905 const int32_t entry_point_offset =
6906 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0);
6907 // We will not do the explicit null check in the thunk as some form of a null check
6908 // must've been done earlier.
6909 DCHECK(!needs_null_check);
6910 const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false);
6911 // Loading the entrypoint does not require a load acquire since it is only changed when
6912 // threads are suspended or running a checkpoint.
6913 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
6914 Register ref_reg = ref.AsRegister<Register>();
6915 Register index_reg = index.IsRegisterPair()
6916 ? index.AsRegisterPairLow<Register>()
6917 : index.AsRegister<Register>();
Alexey Frunze0cab6562017-07-25 15:19:36 -07006918 MipsLabel skip_call;
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006919 if (GetInstructionSetFeatures().IsR6()) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07006920 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006921 __ Lsa(TMP, index_reg, obj, scale_factor); // In delay slot.
6922 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07006923 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006924 } else {
6925 __ Sll(TMP, index_reg, scale_factor);
Alexey Frunze0cab6562017-07-25 15:19:36 -07006926 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006927 __ Addiu(T9, T9, thunk_disp); // In delay slot.
6928 __ Jalr(T9);
Alexey Frunze0cab6562017-07-25 15:19:36 -07006929 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006930 __ Addu(TMP, TMP, obj); // In delay slot.
6931 }
6932 // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor))
6933 DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset;
6934 __ LoadFromOffset(kLoadWord, ref_reg, TMP, data_offset); // Single instruction.
6935 __ MaybeUnpoisonHeapReference(ref_reg);
6936 __ SetReorder(reordering);
6937 return;
6938 }
6939
Alexey Frunze15958152017-02-09 19:08:30 -08006940 // /* HeapReference<Object> */ ref =
6941 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
Alexey Frunze15958152017-02-09 19:08:30 -08006942 GenerateReferenceLoadWithBakerReadBarrier(instruction,
6943 ref,
6944 obj,
6945 data_offset,
6946 index,
6947 scale_factor,
6948 temp,
6949 needs_null_check);
6950}
6951
6952void CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
6953 Location ref,
6954 Register obj,
6955 uint32_t offset,
6956 Location index,
6957 ScaleFactor scale_factor,
6958 Location temp,
6959 bool needs_null_check,
6960 bool always_update_field) {
6961 DCHECK(kEmitCompilerReadBarrier);
6962 DCHECK(kUseBakerReadBarrier);
6963
6964 // In slow path based read barriers, the read barrier call is
6965 // inserted after the original load. However, in fast path based
6966 // Baker's read barriers, we need to perform the load of
6967 // mirror::Object::monitor_ *before* the original reference load.
6968 // This load-load ordering is required by the read barrier.
6969 // The fast path/slow path (for Baker's algorithm) should look like:
6970 //
6971 // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState();
6972 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
6973 // HeapReference<Object> ref = *src; // Original reference load.
6974 // bool is_gray = (rb_state == ReadBarrier::GrayState());
6975 // if (is_gray) {
6976 // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path.
6977 // }
6978 //
6979 // Note: the original implementation in ReadBarrier::Barrier is
6980 // slightly more complex as it performs additional checks that we do
6981 // not do here for performance reasons.
6982
6983 Register ref_reg = ref.AsRegister<Register>();
6984 Register temp_reg = temp.AsRegister<Register>();
6985 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
6986
6987 // /* int32_t */ monitor = obj->monitor_
6988 __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset);
6989 if (needs_null_check) {
6990 MaybeRecordImplicitNullCheck(instruction);
6991 }
6992 // /* LockWord */ lock_word = LockWord(monitor)
6993 static_assert(sizeof(LockWord) == sizeof(int32_t),
6994 "art::LockWord and int32_t have different sizes.");
6995
6996 __ Sync(0); // Barrier to prevent load-load reordering.
6997
6998 // The actual reference load.
6999 if (index.IsValid()) {
7000 // Load types involving an "index": ArrayGet,
7001 // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject
7002 // intrinsics.
7003 // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor))
7004 if (index.IsConstant()) {
7005 size_t computed_offset =
7006 (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset;
7007 __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset);
7008 } else {
7009 // Handle the special case of the
7010 // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject
7011 // intrinsics, which use a register pair as index ("long
7012 // offset"), of which only the low part contains data.
7013 Register index_reg = index.IsRegisterPair()
7014 ? index.AsRegisterPairLow<Register>()
7015 : index.AsRegister<Register>();
Chris Larsencd0295d2017-03-31 15:26:54 -07007016 __ ShiftAndAdd(TMP, index_reg, obj, scale_factor, TMP);
Alexey Frunze15958152017-02-09 19:08:30 -08007017 __ LoadFromOffset(kLoadWord, ref_reg, TMP, offset);
7018 }
7019 } else {
7020 // /* HeapReference<Object> */ ref = *(obj + offset)
7021 __ LoadFromOffset(kLoadWord, ref_reg, obj, offset);
7022 }
7023
7024 // Object* ref = ref_addr->AsMirrorPtr()
7025 __ MaybeUnpoisonHeapReference(ref_reg);
7026
7027 // Slow path marking the object `ref` when it is gray.
7028 SlowPathCodeMIPS* slow_path;
7029 if (always_update_field) {
7030 // ReadBarrierMarkAndUpdateFieldSlowPathMIPS only supports address
7031 // of the form `obj + field_offset`, where `obj` is a register and
7032 // `field_offset` is a register pair (of which only the lower half
7033 // is used). Thus `offset` and `scale_factor` above are expected
7034 // to be null in this code path.
7035 DCHECK_EQ(offset, 0u);
7036 DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1);
Vladimir Marko174b2e22017-10-12 13:34:49 +01007037 slow_path = new (GetScopedAllocator())
Alexey Frunze15958152017-02-09 19:08:30 -08007038 ReadBarrierMarkAndUpdateFieldSlowPathMIPS(instruction,
7039 ref,
7040 obj,
7041 /* field_offset */ index,
7042 temp_reg);
7043 } else {
Vladimir Marko174b2e22017-10-12 13:34:49 +01007044 slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS(instruction, ref);
Alexey Frunze15958152017-02-09 19:08:30 -08007045 }
7046 AddSlowPath(slow_path);
7047
7048 // if (rb_state == ReadBarrier::GrayState())
7049 // ref = ReadBarrier::Mark(ref);
7050 // Given the numeric representation, it's enough to check the low bit of the
7051 // rb_state. We do that by shifting the bit into the sign bit (31) and
7052 // performing a branch on less than zero.
7053 static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0");
7054 static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1");
7055 static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size");
7056 __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift);
7057 __ Bltz(temp_reg, slow_path->GetEntryLabel());
7058 __ Bind(slow_path->GetExitLabel());
7059}
7060
7061void CodeGeneratorMIPS::GenerateReadBarrierSlow(HInstruction* instruction,
7062 Location out,
7063 Location ref,
7064 Location obj,
7065 uint32_t offset,
7066 Location index) {
7067 DCHECK(kEmitCompilerReadBarrier);
7068
7069 // Insert a slow path based read barrier *after* the reference load.
7070 //
7071 // If heap poisoning is enabled, the unpoisoning of the loaded
7072 // reference will be carried out by the runtime within the slow
7073 // path.
7074 //
7075 // Note that `ref` currently does not get unpoisoned (when heap
7076 // poisoning is enabled), which is alright as the `ref` argument is
7077 // not used by the artReadBarrierSlow entry point.
7078 //
7079 // TODO: Unpoison `ref` when it is used by artReadBarrierSlow.
Vladimir Marko174b2e22017-10-12 13:34:49 +01007080 SlowPathCodeMIPS* slow_path = new (GetScopedAllocator())
Alexey Frunze15958152017-02-09 19:08:30 -08007081 ReadBarrierForHeapReferenceSlowPathMIPS(instruction, out, ref, obj, offset, index);
7082 AddSlowPath(slow_path);
7083
7084 __ B(slow_path->GetEntryLabel());
7085 __ Bind(slow_path->GetExitLabel());
7086}
7087
7088void CodeGeneratorMIPS::MaybeGenerateReadBarrierSlow(HInstruction* instruction,
7089 Location out,
7090 Location ref,
7091 Location obj,
7092 uint32_t offset,
7093 Location index) {
7094 if (kEmitCompilerReadBarrier) {
7095 // Baker's read barriers shall be handled by the fast path
7096 // (CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier).
7097 DCHECK(!kUseBakerReadBarrier);
7098 // If heap poisoning is enabled, unpoisoning will be taken care of
7099 // by the runtime within the slow path.
7100 GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index);
7101 } else if (kPoisonHeapReferences) {
7102 __ UnpoisonHeapReference(out.AsRegister<Register>());
7103 }
7104}
7105
7106void CodeGeneratorMIPS::GenerateReadBarrierForRootSlow(HInstruction* instruction,
7107 Location out,
7108 Location root) {
7109 DCHECK(kEmitCompilerReadBarrier);
7110
7111 // Insert a slow path based read barrier *after* the GC root load.
7112 //
7113 // Note that GC roots are not affected by heap poisoning, so we do
7114 // not need to do anything special for this here.
7115 SlowPathCodeMIPS* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01007116 new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS(instruction, out, root);
Alexey Frunze15958152017-02-09 19:08:30 -08007117 AddSlowPath(slow_path);
7118
7119 __ B(slow_path->GetEntryLabel());
7120 __ Bind(slow_path->GetExitLabel());
7121}
7122
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007123void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007124 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
7125 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunzec61c0762017-04-10 13:54:23 -07007126 bool baker_read_barrier_slow_path = false;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007127 switch (type_check_kind) {
7128 case TypeCheckKind::kExactCheck:
7129 case TypeCheckKind::kAbstractClassCheck:
7130 case TypeCheckKind::kClassHierarchyCheck:
7131 case TypeCheckKind::kArrayObjectCheck:
Alexey Frunze15958152017-02-09 19:08:30 -08007132 call_kind =
7133 kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall;
Alexey Frunzec61c0762017-04-10 13:54:23 -07007134 baker_read_barrier_slow_path = kUseBakerReadBarrier;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007135 break;
7136 case TypeCheckKind::kArrayCheck:
7137 case TypeCheckKind::kUnresolvedCheck:
7138 case TypeCheckKind::kInterfaceCheck:
7139 call_kind = LocationSummary::kCallOnSlowPath;
7140 break;
7141 }
7142
Vladimir Markoca6fff82017-10-03 14:49:14 +01007143 LocationSummary* locations =
7144 new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind);
Alexey Frunzec61c0762017-04-10 13:54:23 -07007145 if (baker_read_barrier_slow_path) {
7146 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
7147 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007148 locations->SetInAt(0, Location::RequiresRegister());
7149 locations->SetInAt(1, Location::RequiresRegister());
7150 // The output does overlap inputs.
7151 // Note that TypeCheckSlowPathMIPS uses this register too.
7152 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexey Frunze15958152017-02-09 19:08:30 -08007153 locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007154}
7155
7156void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007157 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007158 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08007159 Location obj_loc = locations->InAt(0);
7160 Register obj = obj_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007161 Register cls = locations->InAt(1).AsRegister<Register>();
Alexey Frunze15958152017-02-09 19:08:30 -08007162 Location out_loc = locations->Out();
7163 Register out = out_loc.AsRegister<Register>();
7164 const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind);
7165 DCHECK_LE(num_temps, 1u);
7166 Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation();
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007167 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
7168 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
7169 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
7170 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007171 MipsLabel done;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007172 SlowPathCodeMIPS* slow_path = nullptr;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007173
7174 // Return 0 if `obj` is null.
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007175 // Avoid this check if we know `obj` is not null.
7176 if (instruction->MustDoNullCheck()) {
7177 __ Move(out, ZERO);
7178 __ Beqz(obj, &done);
7179 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007180
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007181 switch (type_check_kind) {
7182 case TypeCheckKind::kExactCheck: {
7183 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08007184 GenerateReferenceLoadTwoRegisters(instruction,
7185 out_loc,
7186 obj_loc,
7187 class_offset,
7188 maybe_temp_loc,
7189 kCompilerReadBarrierOption);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007190 // Classes must be equal for the instanceof to succeed.
7191 __ Xor(out, out, cls);
7192 __ Sltiu(out, out, 1);
7193 break;
7194 }
7195
7196 case TypeCheckKind::kAbstractClassCheck: {
7197 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08007198 GenerateReferenceLoadTwoRegisters(instruction,
7199 out_loc,
7200 obj_loc,
7201 class_offset,
7202 maybe_temp_loc,
7203 kCompilerReadBarrierOption);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007204 // If the class is abstract, we eagerly fetch the super class of the
7205 // object to avoid doing a comparison we know will fail.
7206 MipsLabel loop;
7207 __ Bind(&loop);
7208 // /* HeapReference<Class> */ out = out->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08007209 GenerateReferenceLoadOneRegister(instruction,
7210 out_loc,
7211 super_offset,
7212 maybe_temp_loc,
7213 kCompilerReadBarrierOption);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007214 // If `out` is null, we use it for the result, and jump to `done`.
7215 __ Beqz(out, &done);
7216 __ Bne(out, cls, &loop);
7217 __ LoadConst32(out, 1);
7218 break;
7219 }
7220
7221 case TypeCheckKind::kClassHierarchyCheck: {
7222 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08007223 GenerateReferenceLoadTwoRegisters(instruction,
7224 out_loc,
7225 obj_loc,
7226 class_offset,
7227 maybe_temp_loc,
7228 kCompilerReadBarrierOption);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007229 // Walk over the class hierarchy to find a match.
7230 MipsLabel loop, success;
7231 __ Bind(&loop);
7232 __ Beq(out, cls, &success);
7233 // /* HeapReference<Class> */ out = out->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08007234 GenerateReferenceLoadOneRegister(instruction,
7235 out_loc,
7236 super_offset,
7237 maybe_temp_loc,
7238 kCompilerReadBarrierOption);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007239 __ Bnez(out, &loop);
7240 // If `out` is null, we use it for the result, and jump to `done`.
7241 __ B(&done);
7242 __ Bind(&success);
7243 __ LoadConst32(out, 1);
7244 break;
7245 }
7246
7247 case TypeCheckKind::kArrayObjectCheck: {
7248 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08007249 GenerateReferenceLoadTwoRegisters(instruction,
7250 out_loc,
7251 obj_loc,
7252 class_offset,
7253 maybe_temp_loc,
7254 kCompilerReadBarrierOption);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007255 // Do an exact check.
7256 MipsLabel success;
7257 __ Beq(out, cls, &success);
7258 // Otherwise, we need to check that the object's class is a non-primitive array.
7259 // /* HeapReference<Class> */ out = out->component_type_
Alexey Frunze15958152017-02-09 19:08:30 -08007260 GenerateReferenceLoadOneRegister(instruction,
7261 out_loc,
7262 component_offset,
7263 maybe_temp_loc,
7264 kCompilerReadBarrierOption);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007265 // If `out` is null, we use it for the result, and jump to `done`.
7266 __ Beqz(out, &done);
7267 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
7268 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
7269 __ Sltiu(out, out, 1);
7270 __ B(&done);
7271 __ Bind(&success);
7272 __ LoadConst32(out, 1);
7273 break;
7274 }
7275
7276 case TypeCheckKind::kArrayCheck: {
7277 // No read barrier since the slow path will retry upon failure.
7278 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08007279 GenerateReferenceLoadTwoRegisters(instruction,
7280 out_loc,
7281 obj_loc,
7282 class_offset,
7283 maybe_temp_loc,
7284 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007285 DCHECK(locations->OnlyCallsOnSlowPath());
Vladimir Marko174b2e22017-10-12 13:34:49 +01007286 slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS(
7287 instruction, /* is_fatal */ false);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007288 codegen_->AddSlowPath(slow_path);
7289 __ Bne(out, cls, slow_path->GetEntryLabel());
7290 __ LoadConst32(out, 1);
7291 break;
7292 }
7293
7294 case TypeCheckKind::kUnresolvedCheck:
7295 case TypeCheckKind::kInterfaceCheck: {
7296 // Note that we indeed only call on slow path, but we always go
7297 // into the slow path for the unresolved and interface check
7298 // cases.
7299 //
7300 // We cannot directly call the InstanceofNonTrivial runtime
7301 // entry point without resorting to a type checking slow path
7302 // here (i.e. by calling InvokeRuntime directly), as it would
7303 // require to assign fixed registers for the inputs of this
7304 // HInstanceOf instruction (following the runtime calling
7305 // convention), which might be cluttered by the potential first
7306 // read barrier emission at the beginning of this method.
7307 //
7308 // TODO: Introduce a new runtime entry point taking the object
7309 // to test (instead of its class) as argument, and let it deal
7310 // with the read barrier issues. This will let us refactor this
7311 // case of the `switch` code as it was previously (with a direct
7312 // call to the runtime not using a type checking slow path).
7313 // This should also be beneficial for the other cases above.
7314 DCHECK(locations->OnlyCallsOnSlowPath());
Vladimir Marko174b2e22017-10-12 13:34:49 +01007315 slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS(
7316 instruction, /* is_fatal */ false);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007317 codegen_->AddSlowPath(slow_path);
7318 __ B(slow_path->GetEntryLabel());
7319 break;
7320 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007321 }
7322
7323 __ Bind(&done);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007324
7325 if (slow_path != nullptr) {
7326 __ Bind(slow_path->GetExitLabel());
7327 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007328}
7329
7330void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01007331 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007332 locations->SetOut(Location::ConstantLocation(constant));
7333}
7334
7335void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
7336 // Will be generated at use site.
7337}
7338
7339void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01007340 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007341 locations->SetOut(Location::ConstantLocation(constant));
7342}
7343
7344void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
7345 // Will be generated at use site.
7346}
7347
7348void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) {
7349 InvokeDexCallingConventionVisitorMIPS calling_convention_visitor;
7350 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
7351}
7352
7353void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
7354 HandleInvoke(invoke);
Alexey Frunze1b8464d2016-11-12 17:22:05 -08007355 // The register T7 is required to be used for the hidden argument in
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007356 // art_quick_imt_conflict_trampoline, so add the hidden argument.
Alexey Frunze1b8464d2016-11-12 17:22:05 -08007357 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T7));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007358}
7359
7360void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
7361 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
7362 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007363 Location receiver = invoke->GetLocations()->InAt(0);
7364 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07007365 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007366
7367 // Set the hidden argument.
7368 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
7369 invoke->GetDexMethodIndex());
7370
7371 // temp = object->GetClass();
7372 if (receiver.IsStackSlot()) {
7373 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
7374 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
7375 } else {
7376 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
7377 }
7378 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexey Frunzec061de12017-02-14 13:27:23 -08007379 // Instead of simply (possibly) unpoisoning `temp` here, we should
7380 // emit a read barrier for the previous class reference load.
7381 // However this is not required in practice, as this is an
7382 // intermediate/temporary reference and because the current
7383 // concurrent copying collector keeps the from-space memory
7384 // intact/accessible until the end of the marking phase (the
7385 // concurrent copying collector may not in the future).
7386 __ MaybeUnpoisonHeapReference(temp);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00007387 __ LoadFromOffset(kLoadWord, temp, temp,
7388 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
7389 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00007390 invoke->GetImtIndex(), kMipsPointerSize));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007391 // temp = temp->GetImtEntryAt(method_offset);
7392 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
7393 // T9 = temp->GetEntryPoint();
7394 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
7395 // T9();
7396 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07007397 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007398 DCHECK(!codegen_->IsLeafMethod());
7399 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
7400}
7401
7402void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen701566a2015-10-27 15:29:13 -07007403 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
7404 if (intrinsic.TryDispatch(invoke)) {
7405 return;
7406 }
7407
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007408 HandleInvoke(invoke);
7409}
7410
7411void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00007412 // Explicit clinit checks triggered by static invokes must have been pruned by
7413 // art::PrepareForRegisterAllocation.
7414 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007415
Alexey Frunze6b892cd2017-01-03 17:11:38 -08007416 bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007417 bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops();
7418 bool has_extra_input = invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007419
Chris Larsen701566a2015-10-27 15:29:13 -07007420 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
7421 if (intrinsic.TryDispatch(invoke)) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007422 if (invoke->GetLocations()->CanCall() && has_extra_input) {
7423 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
7424 }
Chris Larsen701566a2015-10-27 15:29:13 -07007425 return;
7426 }
7427
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007428 HandleInvoke(invoke);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007429
7430 // Add the extra input register if either the dex cache array base register
7431 // or the PC-relative base register for accessing literals is needed.
7432 if (has_extra_input) {
7433 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
7434 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007435}
7436
Orion Hodsonac141392017-01-13 11:53:47 +00007437void LocationsBuilderMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
7438 HandleInvoke(invoke);
7439}
7440
7441void InstructionCodeGeneratorMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
7442 codegen_->GenerateInvokePolymorphicCall(invoke);
7443}
7444
Chris Larsen701566a2015-10-27 15:29:13 -07007445static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007446 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen701566a2015-10-27 15:29:13 -07007447 IntrinsicCodeGeneratorMIPS intrinsic(codegen);
7448 intrinsic.Dispatch(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007449 return true;
7450 }
7451 return false;
7452}
7453
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007454HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind(
Alexey Frunze06a46c42016-07-19 15:00:40 -07007455 HLoadString::LoadKind desired_string_load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007456 switch (desired_string_load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007457 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01007458 case HLoadString::LoadKind::kBootImageInternTable:
Vladimir Markoaad75c62016-10-03 08:46:48 +00007459 case HLoadString::LoadKind::kBssEntry:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007460 DCHECK(!Runtime::Current()->UseJitCompilation());
Alexey Frunze06a46c42016-07-19 15:00:40 -07007461 break;
Nicolas Geoffray132d8362016-11-16 09:19:42 +00007462 case HLoadString::LoadKind::kJitTableAddress:
7463 DCHECK(Runtime::Current()->UseJitCompilation());
Nicolas Geoffray132d8362016-11-16 09:19:42 +00007464 break;
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007465 case HLoadString::LoadKind::kBootImageAddress:
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007466 case HLoadString::LoadKind::kRuntimeCall:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007467 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007468 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007469 return desired_string_load_kind;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007470}
7471
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01007472HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind(
7473 HLoadClass::LoadKind desired_class_load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007474 switch (desired_class_load_kind) {
Nicolas Geoffray83c8e272017-01-31 14:36:37 +00007475 case HLoadClass::LoadKind::kInvalid:
7476 LOG(FATAL) << "UNREACHABLE";
7477 UNREACHABLE();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007478 case HLoadClass::LoadKind::kReferrersClass:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007479 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007480 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko94ec2db2017-09-06 17:21:03 +01007481 case HLoadClass::LoadKind::kBootImageClassTable:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007482 case HLoadClass::LoadKind::kBssEntry:
7483 DCHECK(!Runtime::Current()->UseJitCompilation());
7484 break;
Nicolas Geoffray22384ae2016-12-12 22:33:36 +00007485 case HLoadClass::LoadKind::kJitTableAddress:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007486 DCHECK(Runtime::Current()->UseJitCompilation());
Alexey Frunze06a46c42016-07-19 15:00:40 -07007487 break;
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007488 case HLoadClass::LoadKind::kBootImageAddress:
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007489 case HLoadClass::LoadKind::kRuntimeCall:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007490 break;
7491 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007492 return desired_class_load_kind;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01007493}
7494
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007495Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
7496 Register temp) {
Alexey Frunze6b892cd2017-01-03 17:11:38 -08007497 CHECK(!GetInstructionSetFeatures().IsR6());
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007498 CHECK(!GetGraph()->HasIrreducibleLoops());
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007499 CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
7500 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
7501 if (!invoke->GetLocations()->Intrinsified()) {
7502 return location.AsRegister<Register>();
7503 }
7504 // For intrinsics we allow any location, so it may be on the stack.
7505 if (!location.IsRegister()) {
7506 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
7507 return temp;
7508 }
7509 // For register locations, check if the register was saved. If so, get it from the stack.
7510 // Note: There is a chance that the register was saved but not overwritten, so we could
7511 // save one load. However, since this is just an intrinsic slow path we prefer this
7512 // simple and more robust approach rather that trying to determine if that's the case.
7513 SlowPathCode* slow_path = GetCurrentSlowPath();
7514 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
7515 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
7516 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
7517 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
7518 return temp;
7519 }
7520 return location.AsRegister<Register>();
7521}
7522
Vladimir Markodc151b22015-10-15 18:02:30 +01007523HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch(
7524 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +01007525 HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) {
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007526 return desired_dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01007527}
7528
Vladimir Markoe7197bf2017-06-02 17:00:23 +01007529void CodeGeneratorMIPS::GenerateStaticOrDirectCall(
7530 HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007531 // All registers are assumed to be correctly set up per the calling convention.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007532 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007533 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
7534 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
Alexey Frunze6b892cd2017-01-03 17:11:38 -08007535 bool is_r6 = GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007536 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
7537 Register base_reg = (invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops)
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007538 ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>())
7539 : ZERO;
7540
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007541 switch (method_load_kind) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01007542 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007543 // temp = thread->string_init_entrypoint
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01007544 uint32_t offset =
7545 GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007546 __ LoadFromOffset(kLoadWord,
7547 temp.AsRegister<Register>(),
7548 TR,
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01007549 offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007550 break;
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01007551 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007552 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00007553 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007554 break;
Vladimir Marko65979462017-05-19 17:25:12 +01007555 case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: {
7556 DCHECK(GetCompilerOptions().IsBootImage());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007557 PcRelativePatchInfo* info_high = NewPcRelativeMethodPatch(invoke->GetTargetMethod());
7558 PcRelativePatchInfo* info_low =
7559 NewPcRelativeMethodPatch(invoke->GetTargetMethod(), info_high);
Vladimir Marko65979462017-05-19 17:25:12 +01007560 Register temp_reg = temp.AsRegister<Register>();
Alexey Frunzea663d9d2017-07-31 18:43:18 -07007561 EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg);
7562 __ Addiu(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label);
Vladimir Marko65979462017-05-19 17:25:12 +01007563 break;
7564 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007565 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
7566 __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress());
7567 break;
Vladimir Marko0eb882b2017-05-15 13:39:18 +01007568 case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007569 PcRelativePatchInfo* info_high = NewMethodBssEntryPatch(
Vladimir Marko0eb882b2017-05-15 13:39:18 +01007570 MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()));
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007571 PcRelativePatchInfo* info_low = NewMethodBssEntryPatch(
7572 MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high);
Vladimir Marko0eb882b2017-05-15 13:39:18 +01007573 Register temp_reg = temp.AsRegister<Register>();
Alexey Frunzea663d9d2017-07-31 18:43:18 -07007574 EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg);
7575 __ Lw(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007576 break;
Vladimir Marko0eb882b2017-05-15 13:39:18 +01007577 }
Vladimir Markoe7197bf2017-06-02 17:00:23 +01007578 case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: {
7579 GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path);
7580 return; // No code pointer retrieval; the runtime performs the call directly.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007581 }
7582 }
7583
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007584 switch (code_ptr_location) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007585 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007586 __ Bal(&frame_entry_label_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007587 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007588 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
7589 // T9 = callee_method->entry_point_from_quick_compiled_code_;
Goran Jakovljevic1a878372015-10-26 14:28:52 +01007590 __ LoadFromOffset(kLoadWord,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007591 T9,
7592 callee_method.AsRegister<Register>(),
7593 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07007594 kMipsPointerSize).Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007595 // T9()
7596 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07007597 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007598 break;
7599 }
Vladimir Markoe7197bf2017-06-02 17:00:23 +01007600 RecordPcInfo(invoke, invoke->GetDexPc(), slow_path);
7601
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007602 DCHECK(!IsLeafMethod());
7603}
7604
7605void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00007606 // Explicit clinit checks triggered by static invokes must have been pruned by
7607 // art::PrepareForRegisterAllocation.
7608 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007609
7610 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
7611 return;
7612 }
7613
7614 LocationSummary* locations = invoke->GetLocations();
7615 codegen_->GenerateStaticOrDirectCall(invoke,
7616 locations->HasTemps()
7617 ? locations->GetTemp(0)
7618 : Location::NoLocation());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007619}
7620
Vladimir Markoe7197bf2017-06-02 17:00:23 +01007621void CodeGeneratorMIPS::GenerateVirtualCall(
7622 HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) {
Goran Jakovljevice919b072016-10-04 10:17:34 +02007623 // Use the calling convention instead of the location of the receiver, as
7624 // intrinsics may have put the receiver in a different register. In the intrinsics
7625 // slow path, the arguments have been moved to the right place, so here we are
7626 // guaranteed that the receiver is the first register of the calling convention.
7627 InvokeDexCallingConvention calling_convention;
7628 Register receiver = calling_convention.GetRegisterAt(0);
7629
Chris Larsen3acee732015-11-18 13:31:08 -08007630 Register temp = temp_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007631 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
7632 invoke->GetVTableIndex(), kMipsPointerSize).SizeValue();
7633 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07007634 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007635
7636 // temp = object->GetClass();
Goran Jakovljevice919b072016-10-04 10:17:34 +02007637 __ LoadFromOffset(kLoadWord, temp, receiver, class_offset);
Chris Larsen3acee732015-11-18 13:31:08 -08007638 MaybeRecordImplicitNullCheck(invoke);
Alexey Frunzec061de12017-02-14 13:27:23 -08007639 // Instead of simply (possibly) unpoisoning `temp` here, we should
7640 // emit a read barrier for the previous class reference load.
7641 // However this is not required in practice, as this is an
7642 // intermediate/temporary reference and because the current
7643 // concurrent copying collector keeps the from-space memory
7644 // intact/accessible until the end of the marking phase (the
7645 // concurrent copying collector may not in the future).
7646 __ MaybeUnpoisonHeapReference(temp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007647 // temp = temp->GetMethodAt(method_offset);
7648 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
7649 // T9 = temp->GetEntryPoint();
7650 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
7651 // T9();
7652 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07007653 __ NopIfNoReordering();
Vladimir Markoe7197bf2017-06-02 17:00:23 +01007654 RecordPcInfo(invoke, invoke->GetDexPc(), slow_path);
Chris Larsen3acee732015-11-18 13:31:08 -08007655}
7656
7657void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
7658 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
7659 return;
7660 }
7661
7662 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007663 DCHECK(!codegen_->IsLeafMethod());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007664}
7665
7666void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) {
Vladimir Marko41559982017-01-06 14:04:23 +00007667 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007668 if (load_kind == HLoadClass::LoadKind::kRuntimeCall) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007669 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07007670 Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0));
7671 CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc);
Alexey Frunze06a46c42016-07-19 15:00:40 -07007672 return;
7673 }
Vladimir Marko41559982017-01-06 14:04:23 +00007674 DCHECK(!cls->NeedsAccessCheck());
Alexey Frunzec61c0762017-04-10 13:54:23 -07007675 const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007676 const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops();
Alexey Frunze15958152017-02-09 19:08:30 -08007677 const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage();
7678 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier)
Alexey Frunze06a46c42016-07-19 15:00:40 -07007679 ? LocationSummary::kCallOnSlowPath
7680 : LocationSummary::kNoCall;
Vladimir Markoca6fff82017-10-03 14:49:14 +01007681 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind);
Alexey Frunzec61c0762017-04-10 13:54:23 -07007682 if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) {
7683 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
7684 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007685 switch (load_kind) {
7686 // We need an extra register for PC-relative literals on R2.
Alexey Frunze06a46c42016-07-19 15:00:40 -07007687 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007688 case HLoadClass::LoadKind::kBootImageAddress:
Vladimir Marko94ec2db2017-09-06 17:21:03 +01007689 case HLoadClass::LoadKind::kBootImageClassTable:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007690 case HLoadClass::LoadKind::kBssEntry:
Alexey Frunzec61c0762017-04-10 13:54:23 -07007691 if (isR6) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007692 break;
7693 }
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007694 if (has_irreducible_loops) {
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07007695 if (load_kind != HLoadClass::LoadKind::kBootImageAddress) {
7696 codegen_->ClobberRA();
7697 }
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007698 break;
7699 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007700 FALLTHROUGH_INTENDED;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007701 case HLoadClass::LoadKind::kReferrersClass:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007702 locations->SetInAt(0, Location::RequiresRegister());
7703 break;
7704 default:
7705 break;
7706 }
7707 locations->SetOut(Location::RequiresRegister());
Alexey Frunzec61c0762017-04-10 13:54:23 -07007708 if (load_kind == HLoadClass::LoadKind::kBssEntry) {
7709 if (!kUseReadBarrier || kUseBakerReadBarrier) {
7710 // Rely on the type resolution or initialization and marking to save everything we need.
Alexey Frunzec61c0762017-04-10 13:54:23 -07007711 RegisterSet caller_saves = RegisterSet::Empty();
7712 InvokeRuntimeCallingConvention calling_convention;
7713 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
7714 locations->SetCustomSlowPathCallerSaves(caller_saves);
7715 } else {
7716 // For non-Baker read barriers we have a temp-clobbering call.
7717 }
7718 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007719}
7720
Nicolas Geoffray5247c082017-01-13 14:17:29 +00007721// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
7722// move.
7723void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS {
Vladimir Marko41559982017-01-06 14:04:23 +00007724 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007725 if (load_kind == HLoadClass::LoadKind::kRuntimeCall) {
Vladimir Marko41559982017-01-06 14:04:23 +00007726 codegen_->GenerateLoadClassRuntimeCall(cls);
Pavle Batutae87a7182015-10-28 13:10:42 +01007727 return;
7728 }
Vladimir Marko41559982017-01-06 14:04:23 +00007729 DCHECK(!cls->NeedsAccessCheck());
Pavle Batutae87a7182015-10-28 13:10:42 +01007730
Vladimir Marko41559982017-01-06 14:04:23 +00007731 LocationSummary* locations = cls->GetLocations();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007732 Location out_loc = locations->Out();
7733 Register out = out_loc.AsRegister<Register>();
7734 Register base_or_current_method_reg;
7735 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007736 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007737 switch (load_kind) {
7738 // We need an extra register for PC-relative literals on R2.
Alexey Frunze06a46c42016-07-19 15:00:40 -07007739 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007740 case HLoadClass::LoadKind::kBootImageAddress:
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007741 case HLoadClass::LoadKind::kBootImageClassTable:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007742 case HLoadClass::LoadKind::kBssEntry:
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007743 base_or_current_method_reg =
7744 (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007745 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007746 case HLoadClass::LoadKind::kReferrersClass:
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007747 case HLoadClass::LoadKind::kRuntimeCall:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007748 base_or_current_method_reg = locations->InAt(0).AsRegister<Register>();
7749 break;
7750 default:
7751 base_or_current_method_reg = ZERO;
7752 break;
7753 }
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00007754
Alexey Frunze15958152017-02-09 19:08:30 -08007755 const ReadBarrierOption read_barrier_option = cls->IsInBootImage()
7756 ? kWithoutReadBarrier
7757 : kCompilerReadBarrierOption;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007758 bool generate_null_check = false;
7759 switch (load_kind) {
7760 case HLoadClass::LoadKind::kReferrersClass: {
7761 DCHECK(!cls->CanCallRuntime());
7762 DCHECK(!cls->MustGenerateClinitCheck());
7763 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
7764 GenerateGcRootFieldLoad(cls,
7765 out_loc,
7766 base_or_current_method_reg,
Alexey Frunze15958152017-02-09 19:08:30 -08007767 ArtMethod::DeclaringClassOffset().Int32Value(),
7768 read_barrier_option);
Alexey Frunze06a46c42016-07-19 15:00:40 -07007769 break;
7770 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007771 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007772 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze15958152017-02-09 19:08:30 -08007773 DCHECK_EQ(read_barrier_option, kWithoutReadBarrier);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007774 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
Alexey Frunze06a46c42016-07-19 15:00:40 -07007775 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007776 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
7777 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007778 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high,
7779 out,
Alexey Frunzea663d9d2017-07-31 18:43:18 -07007780 base_or_current_method_reg);
7781 __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label);
Alexey Frunze06a46c42016-07-19 15:00:40 -07007782 break;
7783 }
7784 case HLoadClass::LoadKind::kBootImageAddress: {
Alexey Frunze15958152017-02-09 19:08:30 -08007785 DCHECK_EQ(read_barrier_option, kWithoutReadBarrier);
Nicolas Geoffray5247c082017-01-13 14:17:29 +00007786 uint32_t address = dchecked_integral_cast<uint32_t>(
7787 reinterpret_cast<uintptr_t>(cls->GetClass().Get()));
7788 DCHECK_NE(address, 0u);
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007789 if (isR6 || !has_irreducible_loops) {
7790 __ LoadLiteral(out,
7791 base_or_current_method_reg,
7792 codegen_->DeduplicateBootImageAddressLiteral(address));
7793 } else {
7794 __ LoadConst32(out, address);
7795 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007796 break;
7797 }
Vladimir Marko94ec2db2017-09-06 17:21:03 +01007798 case HLoadClass::LoadKind::kBootImageClassTable: {
7799 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
7800 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
7801 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
7802 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
7803 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high);
7804 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high,
7805 out,
7806 base_or_current_method_reg);
7807 __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label);
7808 // Extract the reference from the slot data, i.e. clear the hash bits.
7809 int32_t masked_hash = ClassTable::TableSlot::MaskHash(
7810 ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex())));
7811 if (masked_hash != 0) {
7812 __ Addiu(out, out, -masked_hash);
7813 }
7814 break;
7815 }
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007816 case HLoadClass::LoadKind::kBssEntry: {
Vladimir Markof3c52b42017-11-17 17:32:12 +00007817 CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high =
7818 codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007819 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
7820 codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007821 codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high,
Vladimir Markof3c52b42017-11-17 17:32:12 +00007822 out,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007823 base_or_current_method_reg);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007824 GenerateGcRootFieldLoad(cls,
7825 out_loc,
Vladimir Markof3c52b42017-11-17 17:32:12 +00007826 out,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007827 /* placeholder */ 0x5678,
7828 read_barrier_option,
7829 &info_low->label);
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007830 generate_null_check = true;
7831 break;
7832 }
Nicolas Geoffray22384ae2016-12-12 22:33:36 +00007833 case HLoadClass::LoadKind::kJitTableAddress: {
Alexey Frunze627c1a02017-01-30 19:28:14 -08007834 CodeGeneratorMIPS::JitPatchInfo* info = codegen_->NewJitRootClassPatch(cls->GetDexFile(),
7835 cls->GetTypeIndex(),
7836 cls->GetClass());
7837 bool reordering = __ SetReorder(false);
7838 __ Bind(&info->high_label);
7839 __ Lui(out, /* placeholder */ 0x1234);
Alexey Frunze627c1a02017-01-30 19:28:14 -08007840 __ SetReorder(reordering);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007841 GenerateGcRootFieldLoad(cls,
7842 out_loc,
7843 out,
7844 /* placeholder */ 0x5678,
7845 read_barrier_option,
7846 &info->low_label);
Alexey Frunze06a46c42016-07-19 15:00:40 -07007847 break;
7848 }
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007849 case HLoadClass::LoadKind::kRuntimeCall:
Nicolas Geoffray83c8e272017-01-31 14:36:37 +00007850 case HLoadClass::LoadKind::kInvalid:
Vladimir Marko41559982017-01-06 14:04:23 +00007851 LOG(FATAL) << "UNREACHABLE";
7852 UNREACHABLE();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007853 }
7854
7855 if (generate_null_check || cls->MustGenerateClinitCheck()) {
7856 DCHECK(cls->CanCallRuntime());
Vladimir Marko174b2e22017-10-12 13:34:49 +01007857 SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS(
Vladimir Markof3c52b42017-11-17 17:32:12 +00007858 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
Alexey Frunze06a46c42016-07-19 15:00:40 -07007859 codegen_->AddSlowPath(slow_path);
7860 if (generate_null_check) {
7861 __ Beqz(out, slow_path->GetEntryLabel());
7862 }
7863 if (cls->MustGenerateClinitCheck()) {
7864 GenerateClassInitializationCheck(slow_path, out);
7865 } else {
7866 __ Bind(slow_path->GetExitLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007867 }
7868 }
7869}
7870
7871static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07007872 return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007873}
7874
7875void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) {
7876 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01007877 new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007878 locations->SetOut(Location::RequiresRegister());
7879}
7880
7881void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) {
7882 Register out = load->GetLocations()->Out().AsRegister<Register>();
7883 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
7884}
7885
7886void LocationsBuilderMIPS::VisitClearException(HClearException* clear) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01007887 new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007888}
7889
7890void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
7891 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
7892}
7893
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007894void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08007895 LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load);
Vladimir Markoca6fff82017-10-03 14:49:14 +01007896 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind);
Alexey Frunze06a46c42016-07-19 15:00:40 -07007897 HLoadString::LoadKind load_kind = load->GetLoadKind();
Alexey Frunzec61c0762017-04-10 13:54:23 -07007898 const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007899 const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007900 switch (load_kind) {
7901 // We need an extra register for PC-relative literals on R2.
Alexey Frunze06a46c42016-07-19 15:00:40 -07007902 case HLoadString::LoadKind::kBootImageAddress:
7903 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01007904 case HLoadString::LoadKind::kBootImageInternTable:
Vladimir Markoaad75c62016-10-03 08:46:48 +00007905 case HLoadString::LoadKind::kBssEntry:
Alexey Frunzec61c0762017-04-10 13:54:23 -07007906 if (isR6) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007907 break;
7908 }
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007909 if (has_irreducible_loops) {
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07007910 if (load_kind != HLoadString::LoadKind::kBootImageAddress) {
7911 codegen_->ClobberRA();
7912 }
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007913 break;
7914 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007915 FALLTHROUGH_INTENDED;
7916 // We need an extra register for PC-relative dex cache accesses.
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007917 case HLoadString::LoadKind::kRuntimeCall:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007918 locations->SetInAt(0, Location::RequiresRegister());
7919 break;
7920 default:
7921 break;
7922 }
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007923 if (load_kind == HLoadString::LoadKind::kRuntimeCall) {
Alexey Frunzebb51df82016-11-01 16:07:32 -07007924 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07007925 locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Alexey Frunzebb51df82016-11-01 16:07:32 -07007926 } else {
7927 locations->SetOut(Location::RequiresRegister());
Alexey Frunzec61c0762017-04-10 13:54:23 -07007928 if (load_kind == HLoadString::LoadKind::kBssEntry) {
7929 if (!kUseReadBarrier || kUseBakerReadBarrier) {
7930 // Rely on the pResolveString and marking to save everything we need.
Alexey Frunzec61c0762017-04-10 13:54:23 -07007931 RegisterSet caller_saves = RegisterSet::Empty();
7932 InvokeRuntimeCallingConvention calling_convention;
7933 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
7934 locations->SetCustomSlowPathCallerSaves(caller_saves);
7935 } else {
7936 // For non-Baker read barriers we have a temp-clobbering call.
7937 }
7938 }
Alexey Frunzebb51df82016-11-01 16:07:32 -07007939 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007940}
7941
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00007942// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
7943// move.
7944void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007945 HLoadString::LoadKind load_kind = load->GetLoadKind();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007946 LocationSummary* locations = load->GetLocations();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007947 Location out_loc = locations->Out();
7948 Register out = out_loc.AsRegister<Register>();
7949 Register base_or_current_method_reg;
7950 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007951 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007952 switch (load_kind) {
7953 // We need an extra register for PC-relative literals on R2.
Alexey Frunze06a46c42016-07-19 15:00:40 -07007954 case HLoadString::LoadKind::kBootImageAddress:
7955 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01007956 case HLoadString::LoadKind::kBootImageInternTable:
Vladimir Markoaad75c62016-10-03 08:46:48 +00007957 case HLoadString::LoadKind::kBssEntry:
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007958 base_or_current_method_reg =
7959 (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007960 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007961 default:
7962 base_or_current_method_reg = ZERO;
7963 break;
7964 }
7965
7966 switch (load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007967 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Markoaad75c62016-10-03 08:46:48 +00007968 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007969 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007970 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007971 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
7972 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007973 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high,
7974 out,
Alexey Frunzea663d9d2017-07-31 18:43:18 -07007975 base_or_current_method_reg);
7976 __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01007977 return;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007978 }
7979 case HLoadString::LoadKind::kBootImageAddress: {
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00007980 uint32_t address = dchecked_integral_cast<uint32_t>(
7981 reinterpret_cast<uintptr_t>(load->GetString().Get()));
7982 DCHECK_NE(address, 0u);
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007983 if (isR6 || !has_irreducible_loops) {
7984 __ LoadLiteral(out,
7985 base_or_current_method_reg,
7986 codegen_->DeduplicateBootImageAddressLiteral(address));
7987 } else {
7988 __ LoadConst32(out, address);
7989 }
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01007990 return;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007991 }
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01007992 case HLoadString::LoadKind::kBootImageInternTable: {
Vladimir Markoaad75c62016-10-03 08:46:48 +00007993 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007994 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007995 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007996 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
7997 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01007998 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high,
7999 out,
8000 base_or_current_method_reg);
8001 __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label);
8002 return;
8003 }
8004 case HLoadString::LoadKind::kBssEntry: {
8005 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
8006 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
8007 codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex());
8008 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
8009 codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008010 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high,
Vladimir Markof3c52b42017-11-17 17:32:12 +00008011 out,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008012 base_or_current_method_reg);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008013 GenerateGcRootFieldLoad(load,
8014 out_loc,
Vladimir Markof3c52b42017-11-17 17:32:12 +00008015 out,
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008016 /* placeholder */ 0x5678,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008017 kCompilerReadBarrierOption,
8018 &info_low->label);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008019 SlowPathCodeMIPS* slow_path =
Vladimir Markof3c52b42017-11-17 17:32:12 +00008020 new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS(load);
Vladimir Markoaad75c62016-10-03 08:46:48 +00008021 codegen_->AddSlowPath(slow_path);
8022 __ Beqz(out, slow_path->GetEntryLabel());
8023 __ Bind(slow_path->GetExitLabel());
8024 return;
8025 }
Alexey Frunze627c1a02017-01-30 19:28:14 -08008026 case HLoadString::LoadKind::kJitTableAddress: {
8027 CodeGeneratorMIPS::JitPatchInfo* info =
8028 codegen_->NewJitRootStringPatch(load->GetDexFile(),
8029 load->GetStringIndex(),
8030 load->GetString());
8031 bool reordering = __ SetReorder(false);
8032 __ Bind(&info->high_label);
8033 __ Lui(out, /* placeholder */ 0x1234);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008034 __ SetReorder(reordering);
Alexey Frunze15958152017-02-09 19:08:30 -08008035 GenerateGcRootFieldLoad(load,
8036 out_loc,
8037 out,
8038 /* placeholder */ 0x5678,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008039 kCompilerReadBarrierOption,
8040 &info->low_label);
Alexey Frunze627c1a02017-01-30 19:28:14 -08008041 return;
8042 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07008043 default:
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07008044 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07008045 }
Nicolas Geoffray917d0162015-11-24 18:25:35 +00008046
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07008047 // TODO: Re-add the compiler code to do string dex cache lookup again.
Vladimir Marko847e6ce2017-06-02 13:55:07 +01008048 DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall);
Vladimir Markoaad75c62016-10-03 08:46:48 +00008049 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07008050 DCHECK_EQ(calling_convention.GetRegisterAt(0), out);
Andreas Gampe8a0128a2016-11-28 07:38:35 -08008051 __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_);
Vladimir Markoaad75c62016-10-03 08:46:48 +00008052 codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc());
8053 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008054}
8055
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008056void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008057 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008058 locations->SetOut(Location::ConstantLocation(constant));
8059}
8060
8061void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
8062 // Will be generated at use site.
8063}
8064
8065void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008066 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
8067 instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008068 InvokeRuntimeCallingConvention calling_convention;
8069 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
8070}
8071
8072void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
8073 if (instruction->IsEnter()) {
Serban Constantinescufca16662016-07-14 09:21:59 +01008074 codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008075 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
8076 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01008077 codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008078 }
8079 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
8080}
8081
8082void LocationsBuilderMIPS::VisitMul(HMul* mul) {
8083 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01008084 new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008085 switch (mul->GetResultType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008086 case DataType::Type::kInt32:
8087 case DataType::Type::kInt64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008088 locations->SetInAt(0, Location::RequiresRegister());
8089 locations->SetInAt(1, Location::RequiresRegister());
8090 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8091 break;
8092
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008093 case DataType::Type::kFloat32:
8094 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008095 locations->SetInAt(0, Location::RequiresFpuRegister());
8096 locations->SetInAt(1, Location::RequiresFpuRegister());
8097 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
8098 break;
8099
8100 default:
8101 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
8102 }
8103}
8104
8105void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008106 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008107 LocationSummary* locations = instruction->GetLocations();
8108 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
8109
8110 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008111 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008112 Register dst = locations->Out().AsRegister<Register>();
8113 Register lhs = locations->InAt(0).AsRegister<Register>();
8114 Register rhs = locations->InAt(1).AsRegister<Register>();
8115
8116 if (isR6) {
8117 __ MulR6(dst, lhs, rhs);
8118 } else {
8119 __ MulR2(dst, lhs, rhs);
8120 }
8121 break;
8122 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008123 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008124 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
8125 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
8126 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
8127 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
8128 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
8129 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
8130
8131 // Extra checks to protect caused by the existance of A1_A2.
8132 // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo:
8133 // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2).
8134 DCHECK_NE(dst_high, lhs_low);
8135 DCHECK_NE(dst_high, rhs_low);
8136
8137 // A_B * C_D
8138 // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ]
8139 // dst_lo: [ low(B*D) ]
8140 // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result.
8141
8142 if (isR6) {
8143 __ MulR6(TMP, lhs_high, rhs_low);
8144 __ MulR6(dst_high, lhs_low, rhs_high);
8145 __ Addu(dst_high, dst_high, TMP);
8146 __ MuhuR6(TMP, lhs_low, rhs_low);
8147 __ Addu(dst_high, dst_high, TMP);
8148 __ MulR6(dst_low, lhs_low, rhs_low);
8149 } else {
8150 __ MulR2(TMP, lhs_high, rhs_low);
8151 __ MulR2(dst_high, lhs_low, rhs_high);
8152 __ Addu(dst_high, dst_high, TMP);
8153 __ MultuR2(lhs_low, rhs_low);
8154 __ Mfhi(TMP);
8155 __ Addu(dst_high, dst_high, TMP);
8156 __ Mflo(dst_low);
8157 }
8158 break;
8159 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008160 case DataType::Type::kFloat32:
8161 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008162 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
8163 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
8164 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008165 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008166 __ MulS(dst, lhs, rhs);
8167 } else {
8168 __ MulD(dst, lhs, rhs);
8169 }
8170 break;
8171 }
8172 default:
8173 LOG(FATAL) << "Unexpected mul type " << type;
8174 }
8175}
8176
8177void LocationsBuilderMIPS::VisitNeg(HNeg* neg) {
8178 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01008179 new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008180 switch (neg->GetResultType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008181 case DataType::Type::kInt32:
8182 case DataType::Type::kInt64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008183 locations->SetInAt(0, Location::RequiresRegister());
8184 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8185 break;
8186
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008187 case DataType::Type::kFloat32:
8188 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008189 locations->SetInAt(0, Location::RequiresFpuRegister());
8190 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
8191 break;
8192
8193 default:
8194 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
8195 }
8196}
8197
8198void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008199 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008200 LocationSummary* locations = instruction->GetLocations();
8201
8202 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008203 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008204 Register dst = locations->Out().AsRegister<Register>();
8205 Register src = locations->InAt(0).AsRegister<Register>();
8206 __ Subu(dst, ZERO, src);
8207 break;
8208 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008209 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008210 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
8211 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
8212 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
8213 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
8214 __ Subu(dst_low, ZERO, src_low);
8215 __ Sltu(TMP, ZERO, dst_low);
8216 __ Subu(dst_high, ZERO, src_high);
8217 __ Subu(dst_high, dst_high, TMP);
8218 break;
8219 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008220 case DataType::Type::kFloat32:
8221 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008222 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
8223 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008224 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008225 __ NegS(dst, src);
8226 } else {
8227 __ NegD(dst, src);
8228 }
8229 break;
8230 }
8231 default:
8232 LOG(FATAL) << "Unexpected neg type " << type;
8233 }
8234}
8235
8236void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008237 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
8238 instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008239 InvokeRuntimeCallingConvention calling_convention;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008240 locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference));
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00008241 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
8242 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008243}
8244
8245void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) {
Alexey Frunzec061de12017-02-14 13:27:23 -08008246 // Note: if heap poisoning is enabled, the entry point takes care
8247 // of poisoning the reference.
Goran Jakovljevic854df412017-06-27 14:41:39 +02008248 QuickEntrypointEnum entrypoint =
8249 CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass());
8250 codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc());
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00008251 CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>();
Goran Jakovljevic854df412017-06-27 14:41:39 +02008252 DCHECK(!codegen_->IsLeafMethod());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008253}
8254
8255void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008256 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
8257 instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008258 InvokeRuntimeCallingConvention calling_convention;
David Brazdil6de19382016-01-08 17:37:10 +00008259 if (instruction->IsStringAlloc()) {
8260 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
8261 } else {
8262 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
David Brazdil6de19382016-01-08 17:37:10 +00008263 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008264 locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008265}
8266
8267void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) {
Alexey Frunzec061de12017-02-14 13:27:23 -08008268 // Note: if heap poisoning is enabled, the entry point takes care
8269 // of poisoning the reference.
David Brazdil6de19382016-01-08 17:37:10 +00008270 if (instruction->IsStringAlloc()) {
8271 // String is allocated through StringFactory. Call NewEmptyString entry point.
8272 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07008273 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00008274 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
8275 __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value());
8276 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07008277 __ NopIfNoReordering();
David Brazdil6de19382016-01-08 17:37:10 +00008278 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
8279 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01008280 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00008281 CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>();
David Brazdil6de19382016-01-08 17:37:10 +00008282 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008283}
8284
8285void LocationsBuilderMIPS::VisitNot(HNot* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008286 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008287 locations->SetInAt(0, Location::RequiresRegister());
8288 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8289}
8290
8291void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008292 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008293 LocationSummary* locations = instruction->GetLocations();
8294
8295 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008296 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008297 Register dst = locations->Out().AsRegister<Register>();
8298 Register src = locations->InAt(0).AsRegister<Register>();
8299 __ Nor(dst, src, ZERO);
8300 break;
8301 }
8302
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008303 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008304 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
8305 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
8306 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
8307 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
8308 __ Nor(dst_high, src_high, ZERO);
8309 __ Nor(dst_low, src_low, ZERO);
8310 break;
8311 }
8312
8313 default:
8314 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
8315 }
8316}
8317
8318void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008319 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008320 locations->SetInAt(0, Location::RequiresRegister());
8321 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8322}
8323
8324void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) {
8325 LocationSummary* locations = instruction->GetLocations();
8326 __ Xori(locations->Out().AsRegister<Register>(),
8327 locations->InAt(0).AsRegister<Register>(),
8328 1);
8329}
8330
8331void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01008332 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
8333 locations->SetInAt(0, Location::RequiresRegister());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008334}
8335
Calin Juravle2ae48182016-03-16 14:05:09 +00008336void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) {
8337 if (CanMoveNullCheckToUser(instruction)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008338 return;
8339 }
8340 Location obj = instruction->GetLocations()->InAt(0);
8341
8342 __ Lw(ZERO, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00008343 RecordPcInfo(instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008344}
8345
Calin Juravle2ae48182016-03-16 14:05:09 +00008346void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01008347 SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) NullCheckSlowPathMIPS(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00008348 AddSlowPath(slow_path);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008349
8350 Location obj = instruction->GetLocations()->InAt(0);
8351
8352 __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
8353}
8354
8355void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00008356 codegen_->GenerateNullCheck(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008357}
8358
8359void LocationsBuilderMIPS::VisitOr(HOr* instruction) {
8360 HandleBinaryOp(instruction);
8361}
8362
8363void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) {
8364 HandleBinaryOp(instruction);
8365}
8366
8367void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
8368 LOG(FATAL) << "Unreachable";
8369}
8370
8371void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) {
Vladimir Markobea75ff2017-10-11 20:39:54 +01008372 if (instruction->GetNext()->IsSuspendCheck() &&
8373 instruction->GetBlock()->GetLoopInformation() != nullptr) {
8374 HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck();
8375 // The back edge will generate the suspend check.
8376 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction);
8377 }
8378
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008379 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
8380}
8381
8382void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008383 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008384 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
8385 if (location.IsStackSlot()) {
8386 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
8387 } else if (location.IsDoubleStackSlot()) {
8388 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
8389 }
8390 locations->SetOut(location);
8391}
8392
8393void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction
8394 ATTRIBUTE_UNUSED) {
8395 // Nothing to do, the parameter is already at its location.
8396}
8397
8398void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) {
8399 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01008400 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008401 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
8402}
8403
8404void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction
8405 ATTRIBUTE_UNUSED) {
8406 // Nothing to do, the method is already at its location.
8407}
8408
8409void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008410 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Vladimir Marko372f10e2016-05-17 16:30:10 +01008411 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008412 locations->SetInAt(i, Location::Any());
8413 }
8414 locations->SetOut(Location::Any());
8415}
8416
8417void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
8418 LOG(FATAL) << "Unreachable";
8419}
8420
8421void LocationsBuilderMIPS::VisitRem(HRem* rem) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008422 DataType::Type type = rem->GetResultType();
8423 LocationSummary::CallKind call_kind = (type == DataType::Type::kInt32)
8424 ? LocationSummary::kNoCall
8425 : LocationSummary::kCallOnMainOnly;
Vladimir Markoca6fff82017-10-03 14:49:14 +01008426 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008427
8428 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008429 case DataType::Type::kInt32:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008430 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08008431 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008432 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8433 break;
8434
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008435 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008436 InvokeRuntimeCallingConvention calling_convention;
8437 locations->SetInAt(0, Location::RegisterPairLocation(
8438 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
8439 locations->SetInAt(1, Location::RegisterPairLocation(
8440 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
8441 locations->SetOut(calling_convention.GetReturnLocation(type));
8442 break;
8443 }
8444
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008445 case DataType::Type::kFloat32:
8446 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008447 InvokeRuntimeCallingConvention calling_convention;
8448 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
8449 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
8450 locations->SetOut(calling_convention.GetReturnLocation(type));
8451 break;
8452 }
8453
8454 default:
8455 LOG(FATAL) << "Unexpected rem type " << type;
8456 }
8457}
8458
8459void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008460 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008461
8462 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008463 case DataType::Type::kInt32:
Alexey Frunze7e99e052015-11-24 19:28:01 -08008464 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008465 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008466 case DataType::Type::kInt64: {
Serban Constantinescufca16662016-07-14 09:21:59 +01008467 codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008468 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
8469 break;
8470 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008471 case DataType::Type::kFloat32: {
Serban Constantinescufca16662016-07-14 09:21:59 +01008472 codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00008473 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008474 break;
8475 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008476 case DataType::Type::kFloat64: {
Serban Constantinescufca16662016-07-14 09:21:59 +01008477 codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00008478 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008479 break;
8480 }
8481 default:
8482 LOG(FATAL) << "Unexpected rem type " << type;
8483 }
8484}
8485
Igor Murashkind01745e2017-04-05 16:40:31 -07008486void LocationsBuilderMIPS::VisitConstructorFence(HConstructorFence* constructor_fence) {
8487 constructor_fence->SetLocations(nullptr);
8488}
8489
8490void InstructionCodeGeneratorMIPS::VisitConstructorFence(
8491 HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) {
8492 GenerateMemoryBarrier(MemBarrierKind::kStoreStore);
8493}
8494
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008495void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
8496 memory_barrier->SetLocations(nullptr);
8497}
8498
8499void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
8500 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
8501}
8502
8503void LocationsBuilderMIPS::VisitReturn(HReturn* ret) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008504 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008505 DataType::Type return_type = ret->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008506 locations->SetInAt(0, MipsReturnLocation(return_type));
8507}
8508
8509void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
8510 codegen_->GenerateFrameExit();
8511}
8512
8513void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) {
8514 ret->SetLocations(nullptr);
8515}
8516
8517void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
8518 codegen_->GenerateFrameExit();
8519}
8520
Alexey Frunze92d90602015-12-18 18:16:36 -08008521void LocationsBuilderMIPS::VisitRor(HRor* ror) {
8522 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00008523}
8524
Alexey Frunze92d90602015-12-18 18:16:36 -08008525void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) {
8526 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00008527}
8528
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008529void LocationsBuilderMIPS::VisitShl(HShl* shl) {
8530 HandleShift(shl);
8531}
8532
8533void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) {
8534 HandleShift(shl);
8535}
8536
8537void LocationsBuilderMIPS::VisitShr(HShr* shr) {
8538 HandleShift(shr);
8539}
8540
8541void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) {
8542 HandleShift(shr);
8543}
8544
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008545void LocationsBuilderMIPS::VisitSub(HSub* instruction) {
8546 HandleBinaryOp(instruction);
8547}
8548
8549void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) {
8550 HandleBinaryOp(instruction);
8551}
8552
8553void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
8554 HandleFieldGet(instruction, instruction->GetFieldInfo());
8555}
8556
8557void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
8558 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
8559}
8560
8561void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
8562 HandleFieldSet(instruction, instruction->GetFieldInfo());
8563}
8564
8565void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Goran Jakovljevice114da22016-12-26 14:21:43 +01008566 HandleFieldSet(instruction,
8567 instruction->GetFieldInfo(),
8568 instruction->GetDexPc(),
8569 instruction->GetValueCanBeNull());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008570}
8571
8572void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet(
8573 HUnresolvedInstanceFieldGet* instruction) {
8574 FieldAccessCallingConventionMIPS calling_convention;
8575 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
8576 instruction->GetFieldType(),
8577 calling_convention);
8578}
8579
8580void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet(
8581 HUnresolvedInstanceFieldGet* instruction) {
8582 FieldAccessCallingConventionMIPS calling_convention;
8583 codegen_->GenerateUnresolvedFieldAccess(instruction,
8584 instruction->GetFieldType(),
8585 instruction->GetFieldIndex(),
8586 instruction->GetDexPc(),
8587 calling_convention);
8588}
8589
8590void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet(
8591 HUnresolvedInstanceFieldSet* instruction) {
8592 FieldAccessCallingConventionMIPS calling_convention;
8593 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
8594 instruction->GetFieldType(),
8595 calling_convention);
8596}
8597
8598void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet(
8599 HUnresolvedInstanceFieldSet* instruction) {
8600 FieldAccessCallingConventionMIPS calling_convention;
8601 codegen_->GenerateUnresolvedFieldAccess(instruction,
8602 instruction->GetFieldType(),
8603 instruction->GetFieldIndex(),
8604 instruction->GetDexPc(),
8605 calling_convention);
8606}
8607
8608void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet(
8609 HUnresolvedStaticFieldGet* instruction) {
8610 FieldAccessCallingConventionMIPS calling_convention;
8611 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
8612 instruction->GetFieldType(),
8613 calling_convention);
8614}
8615
8616void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet(
8617 HUnresolvedStaticFieldGet* instruction) {
8618 FieldAccessCallingConventionMIPS calling_convention;
8619 codegen_->GenerateUnresolvedFieldAccess(instruction,
8620 instruction->GetFieldType(),
8621 instruction->GetFieldIndex(),
8622 instruction->GetDexPc(),
8623 calling_convention);
8624}
8625
8626void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet(
8627 HUnresolvedStaticFieldSet* instruction) {
8628 FieldAccessCallingConventionMIPS calling_convention;
8629 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
8630 instruction->GetFieldType(),
8631 calling_convention);
8632}
8633
8634void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet(
8635 HUnresolvedStaticFieldSet* instruction) {
8636 FieldAccessCallingConventionMIPS calling_convention;
8637 codegen_->GenerateUnresolvedFieldAccess(instruction,
8638 instruction->GetFieldType(),
8639 instruction->GetFieldIndex(),
8640 instruction->GetDexPc(),
8641 calling_convention);
8642}
8643
8644void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008645 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
8646 instruction, LocationSummary::kCallOnSlowPath);
Lena Djokicca8c2952017-05-29 11:31:46 +02008647 // In suspend check slow path, usually there are no caller-save registers at all.
8648 // If SIMD instructions are present, however, we force spilling all live SIMD
8649 // registers in full width (since the runtime only saves/restores lower part).
8650 locations->SetCustomSlowPathCallerSaves(
8651 GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008652}
8653
8654void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
8655 HBasicBlock* block = instruction->GetBlock();
8656 if (block->GetLoopInformation() != nullptr) {
8657 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
8658 // The back edge will generate the suspend check.
8659 return;
8660 }
8661 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
8662 // The goto will generate the suspend check.
8663 return;
8664 }
8665 GenerateSuspendCheck(instruction, nullptr);
8666}
8667
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008668void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008669 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
8670 instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008671 InvokeRuntimeCallingConvention calling_convention;
8672 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
8673}
8674
8675void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) {
Serban Constantinescufca16662016-07-14 09:21:59 +01008676 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008677 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
8678}
8679
8680void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008681 DataType::Type input_type = conversion->GetInputType();
8682 DataType::Type result_type = conversion->GetResultType();
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01008683 DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type))
8684 << input_type << " -> " << result_type;
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008685 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008686
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008687 if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) ||
8688 (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008689 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
8690 }
8691
8692 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008693 if (!isR6 &&
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008694 ((DataType::IsFloatingPointType(result_type) && input_type == DataType::Type::kInt64) ||
8695 (result_type == DataType::Type::kInt64 && DataType::IsFloatingPointType(input_type)))) {
Serban Constantinescu54ff4822016-07-07 18:03:19 +01008696 call_kind = LocationSummary::kCallOnMainOnly;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008697 }
8698
Vladimir Markoca6fff82017-10-03 14:49:14 +01008699 LocationSummary* locations =
8700 new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008701
8702 if (call_kind == LocationSummary::kNoCall) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008703 if (DataType::IsFloatingPointType(input_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008704 locations->SetInAt(0, Location::RequiresFpuRegister());
8705 } else {
8706 locations->SetInAt(0, Location::RequiresRegister());
8707 }
8708
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008709 if (DataType::IsFloatingPointType(result_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008710 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
8711 } else {
8712 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8713 }
8714 } else {
8715 InvokeRuntimeCallingConvention calling_convention;
8716
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008717 if (DataType::IsFloatingPointType(input_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008718 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
8719 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008720 DCHECK_EQ(input_type, DataType::Type::kInt64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008721 locations->SetInAt(0, Location::RegisterPairLocation(
8722 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
8723 }
8724
8725 locations->SetOut(calling_convention.GetReturnLocation(result_type));
8726 }
8727}
8728
8729void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) {
8730 LocationSummary* locations = conversion->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008731 DataType::Type result_type = conversion->GetResultType();
8732 DataType::Type input_type = conversion->GetInputType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008733 bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008734 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008735
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01008736 DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type))
8737 << input_type << " -> " << result_type;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008738
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008739 if (result_type == DataType::Type::kInt64 && DataType::IsIntegralType(input_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008740 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
8741 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
8742 Register src = locations->InAt(0).AsRegister<Register>();
8743
Alexey Frunzea871ef12016-06-27 15:20:11 -07008744 if (dst_low != src) {
8745 __ Move(dst_low, src);
8746 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008747 __ Sra(dst_high, src, 31);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008748 } else if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008749 Register dst = locations->Out().AsRegister<Register>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008750 Register src = (input_type == DataType::Type::kInt64)
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008751 ? locations->InAt(0).AsRegisterPairLow<Register>()
8752 : locations->InAt(0).AsRegister<Register>();
8753
8754 switch (result_type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01008755 case DataType::Type::kUint8:
8756 __ Andi(dst, src, 0xFF);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008757 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008758 case DataType::Type::kInt8:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008759 if (has_sign_extension) {
8760 __ Seb(dst, src);
8761 } else {
8762 __ Sll(dst, src, 24);
8763 __ Sra(dst, dst, 24);
8764 }
8765 break;
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01008766 case DataType::Type::kUint16:
8767 __ Andi(dst, src, 0xFFFF);
8768 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008769 case DataType::Type::kInt16:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008770 if (has_sign_extension) {
8771 __ Seh(dst, src);
8772 } else {
8773 __ Sll(dst, src, 16);
8774 __ Sra(dst, dst, 16);
8775 }
8776 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008777 case DataType::Type::kInt32:
Alexey Frunzea871ef12016-06-27 15:20:11 -07008778 if (dst != src) {
8779 __ Move(dst, src);
8780 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008781 break;
8782
8783 default:
8784 LOG(FATAL) << "Unexpected type conversion from " << input_type
8785 << " to " << result_type;
8786 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008787 } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) {
8788 if (input_type == DataType::Type::kInt64) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008789 if (isR6) {
8790 // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
8791 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
8792 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
8793 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
8794 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
8795 __ Mtc1(src_low, FTMP);
8796 __ Mthc1(src_high, FTMP);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008797 if (result_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008798 __ Cvtsl(dst, FTMP);
8799 } else {
8800 __ Cvtdl(dst, FTMP);
8801 }
8802 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008803 QuickEntrypointEnum entrypoint =
8804 (result_type == DataType::Type::kFloat32) ? kQuickL2f : kQuickL2d;
Serban Constantinescufca16662016-07-14 09:21:59 +01008805 codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008806 if (result_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008807 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
8808 } else {
8809 CheckEntrypointTypes<kQuickL2d, double, int64_t>();
8810 }
8811 }
8812 } else {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008813 Register src = locations->InAt(0).AsRegister<Register>();
8814 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
8815 __ Mtc1(src, FTMP);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008816 if (result_type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008817 __ Cvtsw(dst, FTMP);
8818 } else {
8819 __ Cvtdw(dst, FTMP);
8820 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008821 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008822 } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) {
8823 CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64);
Lena Djokicf4e23a82017-05-09 15:43:45 +02008824
8825 // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum
8826 // value of the output type if the input is outside of the range after the truncation or
8827 // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct
8828 // results. This matches the desired float/double-to-int/long conversion exactly.
8829 //
8830 // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive
8831 // value when the input is either a NaN or is outside of the range of the output type
8832 // after the truncation. IOW, the three special cases (NaN, too small, too big) produce
8833 // the same result.
8834 //
8835 // The code takes care of the different behaviors by first comparing the input to the
8836 // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int).
8837 // If the input is greater than or equal to the minimum, it procedes to the truncate
8838 // instruction, which will handle such an input the same way irrespective of NAN2008.
8839 // Otherwise the input is compared to itself to determine whether it is a NaN or not
8840 // in order to return either zero or the minimum value.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008841 if (result_type == DataType::Type::kInt64) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008842 if (isR6) {
8843 // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
8844 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
8845 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
8846 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
8847 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008848
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008849 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008850 __ TruncLS(FTMP, src);
8851 } else {
8852 __ TruncLD(FTMP, src);
8853 }
8854 __ Mfc1(dst_low, FTMP);
8855 __ Mfhc1(dst_high, FTMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008856 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008857 QuickEntrypointEnum entrypoint =
8858 (input_type == DataType::Type::kFloat32) ? kQuickF2l : kQuickD2l;
Serban Constantinescufca16662016-07-14 09:21:59 +01008859 codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008860 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008861 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
8862 } else {
8863 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
8864 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008865 }
8866 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008867 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
8868 Register dst = locations->Out().AsRegister<Register>();
8869 MipsLabel truncate;
8870 MipsLabel done;
8871
Lena Djokicf4e23a82017-05-09 15:43:45 +02008872 if (!isR6) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008873 if (input_type == DataType::Type::kFloat32) {
Lena Djokicf4e23a82017-05-09 15:43:45 +02008874 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min());
8875 __ LoadConst32(TMP, min_val);
8876 __ Mtc1(TMP, FTMP);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008877 } else {
Lena Djokicf4e23a82017-05-09 15:43:45 +02008878 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min());
8879 __ LoadConst32(TMP, High32Bits(min_val));
8880 __ Mtc1(ZERO, FTMP);
8881 __ MoveToFpuHigh(TMP, FTMP);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008882 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008883
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008884 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008885 __ ColeS(0, FTMP, src);
8886 } else {
8887 __ ColeD(0, FTMP, src);
8888 }
8889 __ Bc1t(0, &truncate);
8890
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008891 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008892 __ CeqS(0, src, src);
8893 } else {
8894 __ CeqD(0, src, src);
8895 }
8896 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
8897 __ Movf(dst, ZERO, 0);
Lena Djokicf4e23a82017-05-09 15:43:45 +02008898
8899 __ B(&done);
8900
8901 __ Bind(&truncate);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008902 }
8903
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008904 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008905 __ TruncWS(FTMP, src);
8906 } else {
8907 __ TruncWD(FTMP, src);
8908 }
8909 __ Mfc1(dst, FTMP);
8910
Lena Djokicf4e23a82017-05-09 15:43:45 +02008911 if (!isR6) {
8912 __ Bind(&done);
8913 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008914 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008915 } else if (DataType::IsFloatingPointType(result_type) &&
8916 DataType::IsFloatingPointType(input_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008917 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
8918 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008919 if (result_type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008920 __ Cvtsd(dst, src);
8921 } else {
8922 __ Cvtds(dst, src);
8923 }
8924 } else {
8925 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
8926 << " to " << result_type;
8927 }
8928}
8929
8930void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) {
8931 HandleShift(ushr);
8932}
8933
8934void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) {
8935 HandleShift(ushr);
8936}
8937
8938void LocationsBuilderMIPS::VisitXor(HXor* instruction) {
8939 HandleBinaryOp(instruction);
8940}
8941
8942void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) {
8943 HandleBinaryOp(instruction);
8944}
8945
8946void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
8947 // Nothing to do, this should be removed during prepare for register allocator.
8948 LOG(FATAL) << "Unreachable";
8949}
8950
8951void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
8952 // Nothing to do, this should be removed during prepare for register allocator.
8953 LOG(FATAL) << "Unreachable";
8954}
8955
8956void LocationsBuilderMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008957 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008958}
8959
8960void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008961 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008962}
8963
8964void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008965 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008966}
8967
8968void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008969 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008970}
8971
8972void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008973 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008974}
8975
8976void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008977 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008978}
8979
8980void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008981 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008982}
8983
8984void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008985 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008986}
8987
8988void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008989 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008990}
8991
8992void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008993 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008994}
8995
8996void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008997 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008998}
8999
9000void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009001 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009002}
9003
9004void LocationsBuilderMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009005 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009006}
9007
9008void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009009 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009010}
9011
9012void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009013 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009014}
9015
9016void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009017 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009018}
9019
9020void LocationsBuilderMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009021 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009022}
9023
9024void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009025 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009026}
9027
9028void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009029 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009030}
9031
9032void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009033 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009034}
9035
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009036void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
9037 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01009038 new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009039 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07009040 if (!codegen_->GetInstructionSetFeatures().IsR6()) {
9041 uint32_t num_entries = switch_instr->GetNumEntries();
9042 if (num_entries > InstructionCodeGeneratorMIPS::kPackedSwitchJumpTableThreshold) {
9043 // When there's no HMipsComputeBaseMethodAddress input, R2 uses the NAL
9044 // instruction to simulate PC-relative addressing when accessing the jump table.
9045 // NAL clobbers RA. Make sure RA is preserved.
9046 codegen_->ClobberRA();
9047 }
9048 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009049}
9050
Alexey Frunze96b66822016-09-10 02:32:44 -07009051void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg,
9052 int32_t lower_bound,
9053 uint32_t num_entries,
9054 HBasicBlock* switch_block,
9055 HBasicBlock* default_block) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009056 // Create a set of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00009057 Register temp_reg = TMP;
9058 __ Addiu32(temp_reg, value_reg, -lower_bound);
9059 // Jump to default if index is negative
9060 // Note: We don't check the case that index is positive while value < lower_bound, because in
9061 // this case, index >= num_entries must be true. So that we can save one branch instruction.
9062 __ Bltz(temp_reg, codegen_->GetLabelOf(default_block));
9063
Alexey Frunze96b66822016-09-10 02:32:44 -07009064 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00009065 // Jump to successors[0] if value == lower_bound.
9066 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0]));
9067 int32_t last_index = 0;
9068 for (; num_entries - last_index > 2; last_index += 2) {
9069 __ Addiu(temp_reg, temp_reg, -2);
9070 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
9071 __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
9072 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
9073 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
9074 }
9075 if (num_entries - last_index == 2) {
9076 // The last missing case_value.
9077 __ Addiu(temp_reg, temp_reg, -1);
9078 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009079 }
9080
Vladimir Markof3e0ee22015-12-17 15:23:13 +00009081 // And the default for any other value.
Alexey Frunze96b66822016-09-10 02:32:44 -07009082 if (!codegen_->GoesToNextBlock(switch_block, default_block)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009083 __ B(codegen_->GetLabelOf(default_block));
9084 }
9085}
9086
Alexey Frunze96b66822016-09-10 02:32:44 -07009087void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg,
9088 Register constant_area,
9089 int32_t lower_bound,
9090 uint32_t num_entries,
9091 HBasicBlock* switch_block,
9092 HBasicBlock* default_block) {
9093 // Create a jump table.
9094 std::vector<MipsLabel*> labels(num_entries);
9095 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
9096 for (uint32_t i = 0; i < num_entries; i++) {
9097 labels[i] = codegen_->GetLabelOf(successors[i]);
9098 }
9099 JumpTable* table = __ CreateJumpTable(std::move(labels));
9100
9101 // Is the value in range?
9102 __ Addiu32(TMP, value_reg, -lower_bound);
9103 if (IsInt<16>(static_cast<int32_t>(num_entries))) {
9104 __ Sltiu(AT, TMP, num_entries);
9105 __ Beqz(AT, codegen_->GetLabelOf(default_block));
9106 } else {
9107 __ LoadConst32(AT, num_entries);
9108 __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block));
9109 }
9110
9111 // We are in the range of the table.
9112 // Load the target address from the jump table, indexing by the value.
9113 __ LoadLabelAddress(AT, constant_area, table->GetLabel());
Chris Larsencd0295d2017-03-31 15:26:54 -07009114 __ ShiftAndAdd(TMP, TMP, AT, 2, TMP);
Alexey Frunze96b66822016-09-10 02:32:44 -07009115 __ Lw(TMP, TMP, 0);
9116 // Compute the absolute target address by adding the table start address
9117 // (the table contains offsets to targets relative to its start).
9118 __ Addu(TMP, TMP, AT);
9119 // And jump.
9120 __ Jr(TMP);
9121 __ NopIfNoReordering();
9122}
9123
9124void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
9125 int32_t lower_bound = switch_instr->GetStartValue();
9126 uint32_t num_entries = switch_instr->GetNumEntries();
9127 LocationSummary* locations = switch_instr->GetLocations();
9128 Register value_reg = locations->InAt(0).AsRegister<Register>();
9129 HBasicBlock* switch_block = switch_instr->GetBlock();
9130 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
9131
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07009132 if (num_entries > kPackedSwitchJumpTableThreshold) {
Alexey Frunze96b66822016-09-10 02:32:44 -07009133 // R6 uses PC-relative addressing to access the jump table.
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07009134 //
9135 // R2, OTOH, uses an HMipsComputeBaseMethodAddress input (when available)
9136 // to access the jump table and it is implemented by changing HPackedSwitch to
9137 // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress (see
9138 // VisitMipsPackedSwitch()).
9139 //
9140 // When there's no HMipsComputeBaseMethodAddress input (e.g. in presence of
9141 // irreducible loops), R2 uses the NAL instruction to simulate PC-relative
9142 // addressing.
Alexey Frunze96b66822016-09-10 02:32:44 -07009143 GenTableBasedPackedSwitch(value_reg,
9144 ZERO,
9145 lower_bound,
9146 num_entries,
9147 switch_block,
9148 default_block);
9149 } else {
9150 GenPackedSwitchWithCompares(value_reg,
9151 lower_bound,
9152 num_entries,
9153 switch_block,
9154 default_block);
9155 }
9156}
9157
9158void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) {
9159 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01009160 new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall);
Alexey Frunze96b66822016-09-10 02:32:44 -07009161 locations->SetInAt(0, Location::RequiresRegister());
9162 // Constant area pointer (HMipsComputeBaseMethodAddress).
9163 locations->SetInAt(1, Location::RequiresRegister());
9164}
9165
9166void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) {
9167 int32_t lower_bound = switch_instr->GetStartValue();
9168 uint32_t num_entries = switch_instr->GetNumEntries();
9169 LocationSummary* locations = switch_instr->GetLocations();
9170 Register value_reg = locations->InAt(0).AsRegister<Register>();
9171 Register constant_area = locations->InAt(1).AsRegister<Register>();
9172 HBasicBlock* switch_block = switch_instr->GetBlock();
9173 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
9174
9175 // This is an R2-only path. HPackedSwitch has been changed to
9176 // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress
9177 // required to address the jump table relative to PC.
9178 GenTableBasedPackedSwitch(value_reg,
9179 constant_area,
9180 lower_bound,
9181 num_entries,
9182 switch_block,
9183 default_block);
9184}
9185
Alexey Frunzee3fb2452016-05-10 16:08:05 -07009186void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress(
9187 HMipsComputeBaseMethodAddress* insn) {
9188 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01009189 new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07009190 locations->SetOut(Location::RequiresRegister());
9191}
9192
9193void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress(
9194 HMipsComputeBaseMethodAddress* insn) {
9195 LocationSummary* locations = insn->GetLocations();
9196 Register reg = locations->Out().AsRegister<Register>();
9197
9198 CHECK(!codegen_->GetInstructionSetFeatures().IsR6());
9199
9200 // Generate a dummy PC-relative call to obtain PC.
9201 __ Nal();
9202 // Grab the return address off RA.
9203 __ Move(reg, RA);
9204
9205 // Remember this offset (the obtained PC value) for later use with constant area.
9206 __ BindPcRelBaseLabel();
9207}
9208
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009209void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
9210 // The trampoline uses the same calling convention as dex calling conventions,
9211 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
9212 // the method_idx.
9213 HandleInvoke(invoke);
9214}
9215
9216void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
9217 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
9218}
9219
Roland Levillain2aba7cd2016-02-03 12:27:20 +00009220void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) {
9221 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01009222 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00009223 locations->SetInAt(0, Location::RequiresRegister());
9224 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00009225}
9226
Roland Levillain2aba7cd2016-02-03 12:27:20 +00009227void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) {
9228 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00009229 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01009230 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Roland Levillain2aba7cd2016-02-03 12:27:20 +00009231 instruction->GetIndex(), kMipsPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01009232 __ LoadFromOffset(kLoadWord,
9233 locations->Out().AsRegister<Register>(),
9234 locations->InAt(0).AsRegister<Register>(),
9235 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00009236 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01009237 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00009238 instruction->GetIndex(), kMipsPointerSize));
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00009239 __ LoadFromOffset(kLoadWord,
9240 locations->Out().AsRegister<Register>(),
9241 locations->InAt(0).AsRegister<Register>(),
9242 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01009243 __ LoadFromOffset(kLoadWord,
9244 locations->Out().AsRegister<Register>(),
9245 locations->Out().AsRegister<Register>(),
9246 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00009247 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00009248}
9249
xueliang.zhonge0eb4832017-10-30 13:43:14 +00009250void LocationsBuilderMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction
9251 ATTRIBUTE_UNUSED) {
9252 LOG(FATAL) << "Unreachable";
9253}
9254
9255void InstructionCodeGeneratorMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction
9256 ATTRIBUTE_UNUSED) {
9257 LOG(FATAL) << "Unreachable";
9258}
9259
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009260#undef __
9261#undef QUICK_ENTRY_POINT
9262
9263} // namespace mips
9264} // namespace art