blob: 507db364b5122992c7a5da4add983302d78a6859 [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:
Aart Bik66c158e2018-01-31 12:55:04 -080061 case DataType::Type::kUint32:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010062 case DataType::Type::kInt32:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020063 return Location::RegisterLocation(V0);
64
Aart Bik66c158e2018-01-31 12:55:04 -080065 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010066 case DataType::Type::kInt64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020067 return Location::RegisterPairLocation(V0, V1);
68
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010069 case DataType::Type::kFloat32:
70 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020071 return Location::FpuRegisterLocation(F0);
72
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010073 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020074 return Location();
75 }
76 UNREACHABLE();
77}
78
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010079Location InvokeDexCallingConventionVisitorMIPS::GetReturnLocation(DataType::Type type) const {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020080 return MipsReturnLocation(type);
81}
82
83Location InvokeDexCallingConventionVisitorMIPS::GetMethodLocation() const {
84 return Location::RegisterLocation(kMethodRegisterArgument);
85}
86
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010087Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(DataType::Type type) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020088 Location next_location;
89
90 switch (type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010091 case DataType::Type::kReference:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010092 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010093 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010094 case DataType::Type::kInt8:
95 case DataType::Type::kUint16:
96 case DataType::Type::kInt16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010097 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020098 uint32_t gp_index = gp_index_++;
99 if (gp_index < calling_convention.GetNumberOfRegisters()) {
100 next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index));
101 } else {
102 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
103 next_location = Location::StackSlot(stack_offset);
104 }
105 break;
106 }
107
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100108 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200109 uint32_t gp_index = gp_index_;
110 gp_index_ += 2;
111 if (gp_index + 1 < calling_convention.GetNumberOfRegisters()) {
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800112 Register reg = calling_convention.GetRegisterAt(gp_index);
113 if (reg == A1 || reg == A3) {
114 gp_index_++; // Skip A1(A3), and use A2_A3(T0_T1) instead.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200115 gp_index++;
116 }
117 Register low_even = calling_convention.GetRegisterAt(gp_index);
118 Register high_odd = calling_convention.GetRegisterAt(gp_index + 1);
119 DCHECK_EQ(low_even + 1, high_odd);
120 next_location = Location::RegisterPairLocation(low_even, high_odd);
121 } else {
122 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
123 next_location = Location::DoubleStackSlot(stack_offset);
124 }
125 break;
126 }
127
128 // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double
129 // will take up the even/odd pair, while floats are stored in even regs only.
130 // On 64 bit FPU, both double and float are stored in even registers only.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100131 case DataType::Type::kFloat32:
132 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200133 uint32_t float_index = float_index_++;
134 if (float_index < calling_convention.GetNumberOfFpuRegisters()) {
135 next_location = Location::FpuRegisterLocation(
136 calling_convention.GetFpuRegisterAt(float_index));
137 } else {
138 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100139 next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
140 : Location::StackSlot(stack_offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200141 }
142 break;
143 }
144
Aart Bik66c158e2018-01-31 12:55:04 -0800145 case DataType::Type::kUint32:
146 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100147 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200148 LOG(FATAL) << "Unexpected parameter type " << type;
149 break;
150 }
151
152 // Space on the stack is reserved for all arguments.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100153 stack_index_ += DataType::Is64BitType(type) ? 2 : 1;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200154
155 return next_location;
156}
157
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100158Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type type) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200159 return MipsReturnLocation(type);
160}
161
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100162// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
163#define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700164#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200165
166class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS {
167 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000168 explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200169
170 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
171 LocationSummary* locations = instruction_->GetLocations();
172 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
173 __ Bind(GetEntryLabel());
174 if (instruction_->CanThrowIntoCatchBlock()) {
175 // Live registers will be restored in the catch block if caught.
176 SaveLiveRegisters(codegen, instruction_->GetLocations());
177 }
178 // We're moving two locations to locations that could overlap, so we need a parallel
179 // move resolver.
180 InvokeRuntimeCallingConvention calling_convention;
181 codegen->EmitParallelMoves(locations->InAt(0),
182 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100183 DataType::Type::kInt32,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200184 locations->InAt(1),
185 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100186 DataType::Type::kInt32);
Serban Constantinescufca16662016-07-14 09:21:59 +0100187 QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt()
188 ? kQuickThrowStringBounds
189 : kQuickThrowArrayBounds;
190 mips_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100191 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200192 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
193 }
194
195 bool IsFatal() const OVERRIDE { return true; }
196
197 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; }
198
199 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200200 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS);
201};
202
203class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS {
204 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000205 explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200206
207 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
208 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
209 __ Bind(GetEntryLabel());
Serban Constantinescufca16662016-07-14 09:21:59 +0100210 mips_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200211 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
212 }
213
214 bool IsFatal() const OVERRIDE { return true; }
215
216 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; }
217
218 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200219 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS);
220};
221
222class LoadClassSlowPathMIPS : public SlowPathCodeMIPS {
223 public:
224 LoadClassSlowPathMIPS(HLoadClass* cls,
225 HInstruction* at,
226 uint32_t dex_pc,
Vladimir Markof3c52b42017-11-17 17:32:12 +0000227 bool do_clinit)
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700228 : SlowPathCodeMIPS(at),
229 cls_(cls),
230 dex_pc_(dex_pc),
Vladimir Markof3c52b42017-11-17 17:32:12 +0000231 do_clinit_(do_clinit) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200232 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
233 }
234
235 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000236 LocationSummary* locations = instruction_->GetLocations();
Alexey Frunzec61c0762017-04-10 13:54:23 -0700237 Location out = locations->Out();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200238 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Alexey Frunzec61c0762017-04-10 13:54:23 -0700239 InvokeRuntimeCallingConvention calling_convention;
240 DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200241 __ Bind(GetEntryLabel());
242 SaveLiveRegisters(codegen, locations);
243
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000244 dex::TypeIndex type_index = cls_->GetTypeIndex();
245 __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_);
Serban Constantinescufca16662016-07-14 09:21:59 +0100246 QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage
247 : kQuickInitializeType;
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000248 mips_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200249 if (do_clinit_) {
250 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
251 } else {
252 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
253 }
254
255 // Move the class to the desired location.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200256 if (out.IsValid()) {
257 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100258 DataType::Type type = instruction_->GetType();
Alexey Frunzec61c0762017-04-10 13:54:23 -0700259 mips_codegen->MoveLocation(out,
260 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
261 type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200262 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200263 RestoreLiveRegisters(codegen, locations);
Alexey Frunzec61c0762017-04-10 13:54:23 -0700264
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200265 __ B(GetExitLabel());
266 }
267
268 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; }
269
270 private:
271 // The class this slow path will load.
272 HLoadClass* const cls_;
273
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200274 // The dex PC of `at_`.
275 const uint32_t dex_pc_;
276
277 // Whether to initialize the class.
278 const bool do_clinit_;
279
280 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS);
281};
282
283class LoadStringSlowPathMIPS : public SlowPathCodeMIPS {
284 public:
Vladimir Markof3c52b42017-11-17 17:32:12 +0000285 explicit LoadStringSlowPathMIPS(HLoadString* instruction)
286 : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200287
288 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexey Frunzec61c0762017-04-10 13:54:23 -0700289 DCHECK(instruction_->IsLoadString());
290 DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200291 LocationSummary* locations = instruction_->GetLocations();
292 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Vladimir Markof3c52b42017-11-17 17:32:12 +0000293 const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200294 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Alexey Frunzec61c0762017-04-10 13:54:23 -0700295 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200296 __ Bind(GetEntryLabel());
297 SaveLiveRegisters(codegen, locations);
298
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000299 __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_);
Serban Constantinescufca16662016-07-14 09:21:59 +0100300 mips_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200301 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Alexey Frunzec61c0762017-04-10 13:54:23 -0700302
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100303 DataType::Type type = instruction_->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200304 mips_codegen->MoveLocation(locations->Out(),
Alexey Frunzec61c0762017-04-10 13:54:23 -0700305 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200306 type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200307 RestoreLiveRegisters(codegen, locations);
Vladimir Markoaad75c62016-10-03 08:46:48 +0000308
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200309 __ B(GetExitLabel());
310 }
311
312 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; }
313
314 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200315 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS);
316};
317
318class NullCheckSlowPathMIPS : public SlowPathCodeMIPS {
319 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000320 explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200321
322 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
323 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
324 __ Bind(GetEntryLabel());
325 if (instruction_->CanThrowIntoCatchBlock()) {
326 // Live registers will be restored in the catch block if caught.
327 SaveLiveRegisters(codegen, instruction_->GetLocations());
328 }
Serban Constantinescufca16662016-07-14 09:21:59 +0100329 mips_codegen->InvokeRuntime(kQuickThrowNullPointer,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200330 instruction_,
331 instruction_->GetDexPc(),
Serban Constantinescufca16662016-07-14 09:21:59 +0100332 this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200333 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
334 }
335
336 bool IsFatal() const OVERRIDE { return true; }
337
338 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; }
339
340 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200341 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS);
342};
343
344class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS {
345 public:
346 SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000347 : SlowPathCodeMIPS(instruction), successor_(successor) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200348
349 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Lena Djokicca8c2952017-05-29 11:31:46 +0200350 LocationSummary* locations = instruction_->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200351 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
352 __ Bind(GetEntryLabel());
Lena Djokicca8c2952017-05-29 11:31:46 +0200353 SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD.
Serban Constantinescufca16662016-07-14 09:21:59 +0100354 mips_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200355 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Lena Djokicca8c2952017-05-29 11:31:46 +0200356 RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200357 if (successor_ == nullptr) {
358 __ B(GetReturnLabel());
359 } else {
360 __ B(mips_codegen->GetLabelOf(successor_));
361 }
362 }
363
364 MipsLabel* GetReturnLabel() {
365 DCHECK(successor_ == nullptr);
366 return &return_label_;
367 }
368
369 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; }
370
Chris Larsena2045912017-11-02 12:39:54 -0700371 HBasicBlock* GetSuccessor() const {
372 return successor_;
373 }
374
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200375 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200376 // If not null, the block to branch to after the suspend check.
377 HBasicBlock* const successor_;
378
379 // If `successor_` is null, the label to branch to after the suspend check.
380 MipsLabel return_label_;
381
382 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS);
383};
384
385class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS {
386 public:
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800387 explicit TypeCheckSlowPathMIPS(HInstruction* instruction, bool is_fatal)
388 : SlowPathCodeMIPS(instruction), is_fatal_(is_fatal) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200389
390 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
391 LocationSummary* locations = instruction_->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200392 uint32_t dex_pc = instruction_->GetDexPc();
393 DCHECK(instruction_->IsCheckCast()
394 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
395 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
396
397 __ Bind(GetEntryLabel());
Alexey Frunzedfc30af2018-01-24 16:25:10 -0800398 if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800399 SaveLiveRegisters(codegen, locations);
400 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200401
402 // We're moving two locations to locations that could overlap, so we need a parallel
403 // move resolver.
404 InvokeRuntimeCallingConvention calling_convention;
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800405 codegen->EmitParallelMoves(locations->InAt(0),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200406 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100407 DataType::Type::kReference,
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800408 locations->InAt(1),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200409 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100410 DataType::Type::kReference);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200411 if (instruction_->IsInstanceOf()) {
Serban Constantinescufca16662016-07-14 09:21:59 +0100412 mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this);
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800413 CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100414 DataType::Type ret_type = instruction_->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200415 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
416 mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200417 } else {
418 DCHECK(instruction_->IsCheckCast());
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800419 mips_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this);
420 CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200421 }
422
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800423 if (!is_fatal_) {
424 RestoreLiveRegisters(codegen, locations);
425 __ B(GetExitLabel());
426 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200427 }
428
429 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; }
430
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800431 bool IsFatal() const OVERRIDE { return is_fatal_; }
432
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200433 private:
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800434 const bool is_fatal_;
435
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200436 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS);
437};
438
439class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS {
440 public:
Aart Bik42249c32016-01-07 15:33:50 -0800441 explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000442 : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200443
444 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800445 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200446 __ Bind(GetEntryLabel());
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +0100447 LocationSummary* locations = instruction_->GetLocations();
448 SaveLiveRegisters(codegen, locations);
449 InvokeRuntimeCallingConvention calling_convention;
450 __ LoadConst32(calling_convention.GetRegisterAt(0),
451 static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind()));
Serban Constantinescufca16662016-07-14 09:21:59 +0100452 mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +0100453 CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200454 }
455
456 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; }
457
458 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200459 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS);
460};
461
Alexey Frunze15958152017-02-09 19:08:30 -0800462class ArraySetSlowPathMIPS : public SlowPathCodeMIPS {
463 public:
464 explicit ArraySetSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {}
465
466 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
467 LocationSummary* locations = instruction_->GetLocations();
468 __ Bind(GetEntryLabel());
469 SaveLiveRegisters(codegen, locations);
470
471 InvokeRuntimeCallingConvention calling_convention;
Vladimir Markoca6fff82017-10-03 14:49:14 +0100472 HParallelMove parallel_move(codegen->GetGraph()->GetAllocator());
Alexey Frunze15958152017-02-09 19:08:30 -0800473 parallel_move.AddMove(
474 locations->InAt(0),
475 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100476 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800477 nullptr);
478 parallel_move.AddMove(
479 locations->InAt(1),
480 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100481 DataType::Type::kInt32,
Alexey Frunze15958152017-02-09 19:08:30 -0800482 nullptr);
483 parallel_move.AddMove(
484 locations->InAt(2),
485 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100486 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800487 nullptr);
488 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
489
490 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
491 mips_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this);
492 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
493 RestoreLiveRegisters(codegen, locations);
494 __ B(GetExitLabel());
495 }
496
497 const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS"; }
498
499 private:
500 DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS);
501};
502
503// Slow path marking an object reference `ref` during a read
504// barrier. The field `obj.field` in the object `obj` holding this
505// reference does not get updated by this slow path after marking (see
506// ReadBarrierMarkAndUpdateFieldSlowPathMIPS below for that).
507//
508// This means that after the execution of this slow path, `ref` will
509// always be up-to-date, but `obj.field` may not; i.e., after the
510// flip, `ref` will be a to-space reference, but `obj.field` will
511// probably still be a from-space reference (unless it gets updated by
512// another thread, or if another thread installed another object
513// reference (different from `ref`) in `obj.field`).
514//
515// If `entrypoint` is a valid location it is assumed to already be
516// holding the entrypoint. The case where the entrypoint is passed in
517// is for the GcRoot read barrier.
518class ReadBarrierMarkSlowPathMIPS : public SlowPathCodeMIPS {
519 public:
520 ReadBarrierMarkSlowPathMIPS(HInstruction* instruction,
521 Location ref,
522 Location entrypoint = Location::NoLocation())
523 : SlowPathCodeMIPS(instruction), ref_(ref), entrypoint_(entrypoint) {
524 DCHECK(kEmitCompilerReadBarrier);
525 }
526
527 const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; }
528
529 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
530 LocationSummary* locations = instruction_->GetLocations();
531 Register ref_reg = ref_.AsRegister<Register>();
532 DCHECK(locations->CanCall());
533 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg;
534 DCHECK(instruction_->IsInstanceFieldGet() ||
535 instruction_->IsStaticFieldGet() ||
536 instruction_->IsArrayGet() ||
537 instruction_->IsArraySet() ||
538 instruction_->IsLoadClass() ||
539 instruction_->IsLoadString() ||
540 instruction_->IsInstanceOf() ||
541 instruction_->IsCheckCast() ||
542 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) ||
543 (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified()))
544 << "Unexpected instruction in read barrier marking slow path: "
545 << instruction_->DebugName();
546
547 __ Bind(GetEntryLabel());
548 // No need to save live registers; it's taken care of by the
549 // entrypoint. Also, there is no need to update the stack mask,
550 // as this runtime call will not trigger a garbage collection.
551 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
552 DCHECK((V0 <= ref_reg && ref_reg <= T7) ||
553 (S2 <= ref_reg && ref_reg <= S7) ||
554 (ref_reg == FP)) << ref_reg;
555 // "Compact" slow path, saving two moves.
556 //
557 // Instead of using the standard runtime calling convention (input
558 // and output in A0 and V0 respectively):
559 //
560 // A0 <- ref
561 // V0 <- ReadBarrierMark(A0)
562 // ref <- V0
563 //
564 // we just use rX (the register containing `ref`) as input and output
565 // of a dedicated entrypoint:
566 //
567 // rX <- ReadBarrierMarkRegX(rX)
568 //
569 if (entrypoint_.IsValid()) {
570 mips_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this);
571 DCHECK_EQ(entrypoint_.AsRegister<Register>(), T9);
572 __ Jalr(entrypoint_.AsRegister<Register>());
573 __ NopIfNoReordering();
574 } else {
575 int32_t entry_point_offset =
Roland Levillain97c46462017-05-11 14:04:03 +0100576 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1);
Alexey Frunze15958152017-02-09 19:08:30 -0800577 // This runtime call does not require a stack map.
578 mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset,
579 instruction_,
580 this,
581 /* direct */ false);
582 }
583 __ B(GetExitLabel());
584 }
585
586 private:
587 // The location (register) of the marked object reference.
588 const Location ref_;
589
590 // The location of the entrypoint if already loaded.
591 const Location entrypoint_;
592
593 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS);
594};
595
596// Slow path marking an object reference `ref` during a read barrier,
597// and if needed, atomically updating the field `obj.field` in the
598// object `obj` holding this reference after marking (contrary to
599// ReadBarrierMarkSlowPathMIPS above, which never tries to update
600// `obj.field`).
601//
602// This means that after the execution of this slow path, both `ref`
603// and `obj.field` will be up-to-date; i.e., after the flip, both will
604// hold the same to-space reference (unless another thread installed
605// another object reference (different from `ref`) in `obj.field`).
606class ReadBarrierMarkAndUpdateFieldSlowPathMIPS : public SlowPathCodeMIPS {
607 public:
608 ReadBarrierMarkAndUpdateFieldSlowPathMIPS(HInstruction* instruction,
609 Location ref,
610 Register obj,
611 Location field_offset,
612 Register temp1)
613 : SlowPathCodeMIPS(instruction),
614 ref_(ref),
615 obj_(obj),
616 field_offset_(field_offset),
617 temp1_(temp1) {
618 DCHECK(kEmitCompilerReadBarrier);
619 }
620
621 const char* GetDescription() const OVERRIDE {
622 return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS";
623 }
624
625 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
626 LocationSummary* locations = instruction_->GetLocations();
627 Register ref_reg = ref_.AsRegister<Register>();
628 DCHECK(locations->CanCall());
629 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg;
630 // This slow path is only used by the UnsafeCASObject intrinsic.
631 DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()))
632 << "Unexpected instruction in read barrier marking and field updating slow path: "
633 << instruction_->DebugName();
634 DCHECK(instruction_->GetLocations()->Intrinsified());
635 DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject);
636 DCHECK(field_offset_.IsRegisterPair()) << field_offset_;
637
638 __ Bind(GetEntryLabel());
639
640 // Save the old reference.
641 // Note that we cannot use AT or TMP to save the old reference, as those
642 // are used by the code that follows, but we need the old reference after
643 // the call to the ReadBarrierMarkRegX entry point.
644 DCHECK_NE(temp1_, AT);
645 DCHECK_NE(temp1_, TMP);
646 __ Move(temp1_, ref_reg);
647
648 // No need to save live registers; it's taken care of by the
649 // entrypoint. Also, there is no need to update the stack mask,
650 // as this runtime call will not trigger a garbage collection.
651 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
652 DCHECK((V0 <= ref_reg && ref_reg <= T7) ||
653 (S2 <= ref_reg && ref_reg <= S7) ||
654 (ref_reg == FP)) << ref_reg;
655 // "Compact" slow path, saving two moves.
656 //
657 // Instead of using the standard runtime calling convention (input
658 // and output in A0 and V0 respectively):
659 //
660 // A0 <- ref
661 // V0 <- ReadBarrierMark(A0)
662 // ref <- V0
663 //
664 // we just use rX (the register containing `ref`) as input and output
665 // of a dedicated entrypoint:
666 //
667 // rX <- ReadBarrierMarkRegX(rX)
668 //
669 int32_t entry_point_offset =
Roland Levillain97c46462017-05-11 14:04:03 +0100670 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1);
Alexey Frunze15958152017-02-09 19:08:30 -0800671 // This runtime call does not require a stack map.
672 mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset,
673 instruction_,
674 this,
675 /* direct */ false);
676
677 // If the new reference is different from the old reference,
678 // update the field in the holder (`*(obj_ + field_offset_)`).
679 //
680 // Note that this field could also hold a different object, if
681 // another thread had concurrently changed it. In that case, the
682 // the compare-and-set (CAS) loop below would abort, leaving the
683 // field as-is.
684 MipsLabel done;
685 __ Beq(temp1_, ref_reg, &done);
686
687 // Update the the holder's field atomically. This may fail if
688 // mutator updates before us, but it's OK. This is achieved
689 // using a strong compare-and-set (CAS) operation with relaxed
690 // memory synchronization ordering, where the expected value is
691 // the old reference and the desired value is the new reference.
692
693 // Convenience aliases.
694 Register base = obj_;
695 // The UnsafeCASObject intrinsic uses a register pair as field
696 // offset ("long offset"), of which only the low part contains
697 // data.
698 Register offset = field_offset_.AsRegisterPairLow<Register>();
699 Register expected = temp1_;
700 Register value = ref_reg;
701 Register tmp_ptr = TMP; // Pointer to actual memory.
702 Register tmp = AT; // Value in memory.
703
704 __ Addu(tmp_ptr, base, offset);
705
706 if (kPoisonHeapReferences) {
707 __ PoisonHeapReference(expected);
708 // Do not poison `value` if it is the same register as
709 // `expected`, which has just been poisoned.
710 if (value != expected) {
711 __ PoisonHeapReference(value);
712 }
713 }
714
715 // do {
716 // tmp = [r_ptr] - expected;
717 // } while (tmp == 0 && failure([r_ptr] <- r_new_value));
718
719 bool is_r6 = mips_codegen->GetInstructionSetFeatures().IsR6();
720 MipsLabel loop_head, exit_loop;
721 __ Bind(&loop_head);
722 if (is_r6) {
723 __ LlR6(tmp, tmp_ptr);
724 } else {
725 __ LlR2(tmp, tmp_ptr);
726 }
727 __ Bne(tmp, expected, &exit_loop);
728 __ Move(tmp, value);
729 if (is_r6) {
730 __ ScR6(tmp, tmp_ptr);
731 } else {
732 __ ScR2(tmp, tmp_ptr);
733 }
734 __ Beqz(tmp, &loop_head);
735 __ Bind(&exit_loop);
736
737 if (kPoisonHeapReferences) {
738 __ UnpoisonHeapReference(expected);
739 // Do not unpoison `value` if it is the same register as
740 // `expected`, which has just been unpoisoned.
741 if (value != expected) {
742 __ UnpoisonHeapReference(value);
743 }
744 }
745
746 __ Bind(&done);
747 __ B(GetExitLabel());
748 }
749
750 private:
751 // The location (register) of the marked object reference.
752 const Location ref_;
753 // The register containing the object holding the marked object reference field.
754 const Register obj_;
755 // The location of the offset of the marked reference field within `obj_`.
756 Location field_offset_;
757
758 const Register temp1_;
759
760 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS);
761};
762
763// Slow path generating a read barrier for a heap reference.
764class ReadBarrierForHeapReferenceSlowPathMIPS : public SlowPathCodeMIPS {
765 public:
766 ReadBarrierForHeapReferenceSlowPathMIPS(HInstruction* instruction,
767 Location out,
768 Location ref,
769 Location obj,
770 uint32_t offset,
771 Location index)
772 : SlowPathCodeMIPS(instruction),
773 out_(out),
774 ref_(ref),
775 obj_(obj),
776 offset_(offset),
777 index_(index) {
778 DCHECK(kEmitCompilerReadBarrier);
779 // If `obj` is equal to `out` or `ref`, it means the initial object
780 // has been overwritten by (or after) the heap object reference load
781 // to be instrumented, e.g.:
782 //
783 // __ LoadFromOffset(kLoadWord, out, out, offset);
784 // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset);
785 //
786 // In that case, we have lost the information about the original
787 // object, and the emitted read barrier cannot work properly.
788 DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out;
789 DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref;
790 }
791
792 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
793 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
794 LocationSummary* locations = instruction_->GetLocations();
795 Register reg_out = out_.AsRegister<Register>();
796 DCHECK(locations->CanCall());
797 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
798 DCHECK(instruction_->IsInstanceFieldGet() ||
799 instruction_->IsStaticFieldGet() ||
800 instruction_->IsArrayGet() ||
801 instruction_->IsInstanceOf() ||
802 instruction_->IsCheckCast() ||
803 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()))
804 << "Unexpected instruction in read barrier for heap reference slow path: "
805 << instruction_->DebugName();
806
807 __ Bind(GetEntryLabel());
808 SaveLiveRegisters(codegen, locations);
809
810 // We may have to change the index's value, but as `index_` is a
811 // constant member (like other "inputs" of this slow path),
812 // introduce a copy of it, `index`.
813 Location index = index_;
814 if (index_.IsValid()) {
815 // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
816 if (instruction_->IsArrayGet()) {
817 // Compute the actual memory offset and store it in `index`.
818 Register index_reg = index_.AsRegister<Register>();
819 DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg));
820 if (codegen->IsCoreCalleeSaveRegister(index_reg)) {
821 // We are about to change the value of `index_reg` (see the
822 // calls to art::mips::MipsAssembler::Sll and
823 // art::mips::MipsAssembler::Addiu32 below), but it has
824 // not been saved by the previous call to
825 // art::SlowPathCode::SaveLiveRegisters, as it is a
826 // callee-save register --
827 // art::SlowPathCode::SaveLiveRegisters does not consider
828 // callee-save registers, as it has been designed with the
829 // assumption that callee-save registers are supposed to be
830 // handled by the called function. So, as a callee-save
831 // register, `index_reg` _would_ eventually be saved onto
832 // the stack, but it would be too late: we would have
833 // changed its value earlier. Therefore, we manually save
834 // it here into another freely available register,
835 // `free_reg`, chosen of course among the caller-save
836 // registers (as a callee-save `free_reg` register would
837 // exhibit the same problem).
838 //
839 // Note we could have requested a temporary register from
840 // the register allocator instead; but we prefer not to, as
841 // this is a slow path, and we know we can find a
842 // caller-save register that is available.
843 Register free_reg = FindAvailableCallerSaveRegister(codegen);
844 __ Move(free_reg, index_reg);
845 index_reg = free_reg;
846 index = Location::RegisterLocation(index_reg);
847 } else {
848 // The initial register stored in `index_` has already been
849 // saved in the call to art::SlowPathCode::SaveLiveRegisters
850 // (as it is not a callee-save register), so we can freely
851 // use it.
852 }
853 // Shifting the index value contained in `index_reg` by the scale
854 // factor (2) cannot overflow in practice, as the runtime is
855 // unable to allocate object arrays with a size larger than
856 // 2^26 - 1 (that is, 2^28 - 4 bytes).
857 __ Sll(index_reg, index_reg, TIMES_4);
858 static_assert(
859 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
860 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
861 __ Addiu32(index_reg, index_reg, offset_);
862 } else {
863 // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile
864 // intrinsics, `index_` is not shifted by a scale factor of 2
865 // (as in the case of ArrayGet), as it is actually an offset
866 // to an object field within an object.
867 DCHECK(instruction_->IsInvoke()) << instruction_->DebugName();
868 DCHECK(instruction_->GetLocations()->Intrinsified());
869 DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) ||
870 (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile))
871 << instruction_->AsInvoke()->GetIntrinsic();
872 DCHECK_EQ(offset_, 0U);
873 DCHECK(index_.IsRegisterPair());
874 // UnsafeGet's offset location is a register pair, the low
875 // part contains the correct offset.
876 index = index_.ToLow();
877 }
878 }
879
880 // We're moving two or three locations to locations that could
881 // overlap, so we need a parallel move resolver.
882 InvokeRuntimeCallingConvention calling_convention;
Vladimir Markoca6fff82017-10-03 14:49:14 +0100883 HParallelMove parallel_move(codegen->GetGraph()->GetAllocator());
Alexey Frunze15958152017-02-09 19:08:30 -0800884 parallel_move.AddMove(ref_,
885 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100886 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800887 nullptr);
888 parallel_move.AddMove(obj_,
889 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100890 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800891 nullptr);
892 if (index.IsValid()) {
893 parallel_move.AddMove(index,
894 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100895 DataType::Type::kInt32,
Alexey Frunze15958152017-02-09 19:08:30 -0800896 nullptr);
897 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
898 } else {
899 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
900 __ LoadConst32(calling_convention.GetRegisterAt(2), offset_);
901 }
902 mips_codegen->InvokeRuntime(kQuickReadBarrierSlow,
903 instruction_,
904 instruction_->GetDexPc(),
905 this);
906 CheckEntrypointTypes<
907 kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>();
Lena Djokic8098da92017-06-28 12:07:50 +0200908 mips_codegen->MoveLocation(out_,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100909 calling_convention.GetReturnLocation(DataType::Type::kReference),
910 DataType::Type::kReference);
Alexey Frunze15958152017-02-09 19:08:30 -0800911
912 RestoreLiveRegisters(codegen, locations);
913 __ B(GetExitLabel());
914 }
915
916 const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathMIPS"; }
917
918 private:
919 Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) {
920 size_t ref = static_cast<int>(ref_.AsRegister<Register>());
921 size_t obj = static_cast<int>(obj_.AsRegister<Register>());
922 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
923 if (i != ref &&
924 i != obj &&
925 !codegen->IsCoreCalleeSaveRegister(i) &&
926 !codegen->IsBlockedCoreRegister(i)) {
927 return static_cast<Register>(i);
928 }
929 }
930 // We shall never fail to find a free caller-save register, as
931 // there are more than two core caller-save registers on MIPS
932 // (meaning it is possible to find one which is different from
933 // `ref` and `obj`).
934 DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u);
935 LOG(FATAL) << "Could not find a free caller-save register";
936 UNREACHABLE();
937 }
938
939 const Location out_;
940 const Location ref_;
941 const Location obj_;
942 const uint32_t offset_;
943 // An additional location containing an index to an array.
944 // Only used for HArrayGet and the UnsafeGetObject &
945 // UnsafeGetObjectVolatile intrinsics.
946 const Location index_;
947
948 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS);
949};
950
951// Slow path generating a read barrier for a GC root.
952class ReadBarrierForRootSlowPathMIPS : public SlowPathCodeMIPS {
953 public:
954 ReadBarrierForRootSlowPathMIPS(HInstruction* instruction, Location out, Location root)
955 : SlowPathCodeMIPS(instruction), out_(out), root_(root) {
956 DCHECK(kEmitCompilerReadBarrier);
957 }
958
959 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
960 LocationSummary* locations = instruction_->GetLocations();
961 Register reg_out = out_.AsRegister<Register>();
962 DCHECK(locations->CanCall());
963 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
964 DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString())
965 << "Unexpected instruction in read barrier for GC root slow path: "
966 << instruction_->DebugName();
967
968 __ Bind(GetEntryLabel());
969 SaveLiveRegisters(codegen, locations);
970
971 InvokeRuntimeCallingConvention calling_convention;
972 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Lena Djokic8098da92017-06-28 12:07:50 +0200973 mips_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
974 root_,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100975 DataType::Type::kReference);
Alexey Frunze15958152017-02-09 19:08:30 -0800976 mips_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow,
977 instruction_,
978 instruction_->GetDexPc(),
979 this);
980 CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>();
Lena Djokic8098da92017-06-28 12:07:50 +0200981 mips_codegen->MoveLocation(out_,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100982 calling_convention.GetReturnLocation(DataType::Type::kReference),
983 DataType::Type::kReference);
Alexey Frunze15958152017-02-09 19:08:30 -0800984
985 RestoreLiveRegisters(codegen, locations);
986 __ B(GetExitLabel());
987 }
988
989 const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS"; }
990
991 private:
992 const Location out_;
993 const Location root_;
994
995 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS);
996};
997
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200998CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph,
999 const MipsInstructionSetFeatures& isa_features,
1000 const CompilerOptions& compiler_options,
1001 OptimizingCompilerStats* stats)
1002 : CodeGenerator(graph,
1003 kNumberOfCoreRegisters,
1004 kNumberOfFRegisters,
1005 kNumberOfRegisterPairs,
1006 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
1007 arraysize(kCoreCalleeSaves)),
1008 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
1009 arraysize(kFpuCalleeSaves)),
1010 compiler_options,
1011 stats),
1012 block_labels_(nullptr),
1013 location_builder_(graph, this),
1014 instruction_visitor_(graph, this),
Vladimir Markoca6fff82017-10-03 14:49:14 +01001015 move_resolver_(graph->GetAllocator(), this),
1016 assembler_(graph->GetAllocator(), &isa_features),
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001017 isa_features_(isa_features),
Alexey Frunze06a46c42016-07-19 15:00:40 -07001018 uint32_literals_(std::less<uint32_t>(),
Vladimir Markoca6fff82017-10-03 14:49:14 +01001019 graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001020 boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markoca6fff82017-10-03 14:49:14 +01001021 method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001022 boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markoca6fff82017-10-03 14:49:14 +01001023 type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001024 boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markoca6fff82017-10-03 14:49:14 +01001025 string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1026 jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1027 jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze06a46c42016-07-19 15:00:40 -07001028 clobbered_ra_(false) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001029 // Save RA (containing the return address) to mimic Quick.
1030 AddAllocatedRegister(Location::RegisterLocation(RA));
1031}
1032
1033#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +01001034// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
1035#define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -07001036#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001037
1038void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) {
1039 // Ensure that we fix up branches.
1040 __ FinalizeCode();
1041
1042 // Adjust native pc offsets in stack maps.
Vladimir Marko174b2e22017-10-12 13:34:49 +01001043 StackMapStream* stack_map_stream = GetStackMapStream();
1044 for (size_t i = 0, num = stack_map_stream->GetNumberOfStackMaps(); i != num; ++i) {
David Srbeckyd02b23f2018-05-29 23:27:22 +01001045 uint32_t old_position = stack_map_stream->GetStackMapNativePcOffset(i);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001046 uint32_t new_position = __ GetAdjustedPosition(old_position);
1047 DCHECK_GE(new_position, old_position);
Vladimir Marko174b2e22017-10-12 13:34:49 +01001048 stack_map_stream->SetStackMapNativePcOffset(i, new_position);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001049 }
1050
1051 // Adjust pc offsets for the disassembly information.
1052 if (disasm_info_ != nullptr) {
1053 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
1054 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
1055 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
1056 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
1057 it.second.start = __ GetAdjustedPosition(it.second.start);
1058 it.second.end = __ GetAdjustedPosition(it.second.end);
1059 }
1060 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
1061 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
1062 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
1063 }
1064 }
1065
1066 CodeGenerator::Finalize(allocator);
1067}
1068
1069MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const {
1070 return codegen_->GetAssembler();
1071}
1072
1073void ParallelMoveResolverMIPS::EmitMove(size_t index) {
1074 DCHECK_LT(index, moves_.size());
1075 MoveOperands* move = moves_[index];
1076 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
1077}
1078
1079void ParallelMoveResolverMIPS::EmitSwap(size_t index) {
1080 DCHECK_LT(index, moves_.size());
1081 MoveOperands* move = moves_[index];
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001082 DataType::Type type = move->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001083 Location loc1 = move->GetDestination();
1084 Location loc2 = move->GetSource();
1085
1086 DCHECK(!loc1.IsConstant());
1087 DCHECK(!loc2.IsConstant());
1088
1089 if (loc1.Equals(loc2)) {
1090 return;
1091 }
1092
1093 if (loc1.IsRegister() && loc2.IsRegister()) {
1094 // Swap 2 GPRs.
1095 Register r1 = loc1.AsRegister<Register>();
1096 Register r2 = loc2.AsRegister<Register>();
1097 __ Move(TMP, r2);
1098 __ Move(r2, r1);
1099 __ Move(r1, TMP);
1100 } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) {
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001101 if (codegen_->GetGraph()->HasSIMD()) {
1102 __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(loc1));
1103 __ MoveV(VectorRegisterFrom(loc1), VectorRegisterFrom(loc2));
1104 __ MoveV(VectorRegisterFrom(loc2), static_cast<VectorRegister>(FTMP));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001105 } else {
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001106 FRegister f1 = loc1.AsFpuRegister<FRegister>();
1107 FRegister f2 = loc2.AsFpuRegister<FRegister>();
1108 if (type == DataType::Type::kFloat32) {
1109 __ MovS(FTMP, f2);
1110 __ MovS(f2, f1);
1111 __ MovS(f1, FTMP);
1112 } else {
1113 DCHECK_EQ(type, DataType::Type::kFloat64);
1114 __ MovD(FTMP, f2);
1115 __ MovD(f2, f1);
1116 __ MovD(f1, FTMP);
1117 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001118 }
1119 } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) ||
1120 (loc1.IsFpuRegister() && loc2.IsRegister())) {
1121 // Swap FPR and GPR.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001122 DCHECK_EQ(type, DataType::Type::kFloat32); // Can only swap a float.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001123 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
1124 : loc2.AsFpuRegister<FRegister>();
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001125 Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001126 __ Move(TMP, r2);
1127 __ Mfc1(r2, f1);
1128 __ Mtc1(TMP, f1);
1129 } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) {
1130 // Swap 2 GPR register pairs.
1131 Register r1 = loc1.AsRegisterPairLow<Register>();
1132 Register r2 = loc2.AsRegisterPairLow<Register>();
1133 __ Move(TMP, r2);
1134 __ Move(r2, r1);
1135 __ Move(r1, TMP);
1136 r1 = loc1.AsRegisterPairHigh<Register>();
1137 r2 = loc2.AsRegisterPairHigh<Register>();
1138 __ Move(TMP, r2);
1139 __ Move(r2, r1);
1140 __ Move(r1, TMP);
1141 } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) ||
1142 (loc1.IsFpuRegister() && loc2.IsRegisterPair())) {
1143 // Swap FPR and GPR register pair.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001144 DCHECK_EQ(type, DataType::Type::kFloat64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001145 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
1146 : loc2.AsFpuRegister<FRegister>();
1147 Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
1148 : loc2.AsRegisterPairLow<Register>();
1149 Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
1150 : loc2.AsRegisterPairHigh<Register>();
1151 // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and
1152 // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR
1153 // unpredictable and the following mfch1 will fail.
1154 __ Mfc1(TMP, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -08001155 __ MoveFromFpuHigh(AT, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001156 __ Mtc1(r2_l, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -08001157 __ MoveToFpuHigh(r2_h, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001158 __ Move(r2_l, TMP);
1159 __ Move(r2_h, AT);
1160 } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) {
1161 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false);
1162 } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) {
1163 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true);
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001164 } else if (loc1.IsSIMDStackSlot() && loc2.IsSIMDStackSlot()) {
1165 ExchangeQuadSlots(loc1.GetStackIndex(), loc2.GetStackIndex());
David Brazdilcc0f3112016-01-28 17:14:52 +00001166 } else if ((loc1.IsRegister() && loc2.IsStackSlot()) ||
1167 (loc1.IsStackSlot() && loc2.IsRegister())) {
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001168 Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>();
1169 intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex();
David Brazdilcc0f3112016-01-28 17:14:52 +00001170 __ Move(TMP, reg);
1171 __ LoadFromOffset(kLoadWord, reg, SP, offset);
1172 __ StoreToOffset(kStoreWord, TMP, SP, offset);
1173 } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) ||
1174 (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) {
1175 Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
1176 : loc2.AsRegisterPairLow<Register>();
1177 Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
1178 : loc2.AsRegisterPairHigh<Register>();
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001179 intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex();
David Brazdilcc0f3112016-01-28 17:14:52 +00001180 intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize)
1181 : loc2.GetHighStackIndex(kMipsWordSize);
1182 __ Move(TMP, reg_l);
David Brazdilcc0f3112016-01-28 17:14:52 +00001183 __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l);
David Brazdilcc0f3112016-01-28 17:14:52 +00001184 __ StoreToOffset(kStoreWord, TMP, SP, offset_l);
David Brazdil04d3e872016-01-29 09:50:09 +00001185 __ Move(TMP, reg_h);
1186 __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h);
1187 __ StoreToOffset(kStoreWord, TMP, SP, offset_h);
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001188 } else if ((loc1.IsFpuRegister() && loc2.IsSIMDStackSlot()) ||
1189 (loc1.IsSIMDStackSlot() && loc2.IsFpuRegister())) {
1190 Location fp_loc = loc1.IsFpuRegister() ? loc1 : loc2;
1191 intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex();
1192 __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(fp_loc));
1193 __ LoadQFromOffset(fp_loc.AsFpuRegister<FRegister>(), SP, offset);
1194 __ StoreQToOffset(FTMP, SP, offset);
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001195 } else if (loc1.IsFpuRegister() || loc2.IsFpuRegister()) {
1196 FRegister reg = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
1197 : loc2.AsFpuRegister<FRegister>();
1198 intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001199 if (type == DataType::Type::kFloat32) {
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001200 __ MovS(FTMP, reg);
1201 __ LoadSFromOffset(reg, SP, offset);
1202 __ StoreSToOffset(FTMP, SP, offset);
1203 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001204 DCHECK_EQ(type, DataType::Type::kFloat64);
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001205 __ MovD(FTMP, reg);
1206 __ LoadDFromOffset(reg, SP, offset);
1207 __ StoreDToOffset(FTMP, SP, offset);
1208 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001209 } else {
1210 LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported";
1211 }
1212}
1213
1214void ParallelMoveResolverMIPS::RestoreScratch(int reg) {
1215 __ Pop(static_cast<Register>(reg));
1216}
1217
1218void ParallelMoveResolverMIPS::SpillScratch(int reg) {
1219 __ Push(static_cast<Register>(reg));
1220}
1221
1222void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) {
1223 // Allocate a scratch register other than TMP, if available.
1224 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
1225 // automatically unspilled when the scratch scope object is destroyed).
1226 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
1227 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
Chris Larsen715f43e2017-10-23 11:00:32 -07001228 int stack_offset = ensure_scratch.IsSpilled() ? kStackAlignment : 0;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001229 for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) {
1230 __ LoadFromOffset(kLoadWord,
1231 Register(ensure_scratch.GetRegister()),
1232 SP,
1233 index1 + stack_offset);
1234 __ LoadFromOffset(kLoadWord,
1235 TMP,
1236 SP,
1237 index2 + stack_offset);
1238 __ StoreToOffset(kStoreWord,
1239 Register(ensure_scratch.GetRegister()),
1240 SP,
1241 index2 + stack_offset);
1242 __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset);
1243 }
1244}
1245
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001246void ParallelMoveResolverMIPS::ExchangeQuadSlots(int index1, int index2) {
1247 __ LoadQFromOffset(FTMP, SP, index1);
1248 __ LoadQFromOffset(FTMP2, SP, index2);
1249 __ StoreQToOffset(FTMP, SP, index2);
1250 __ StoreQToOffset(FTMP2, SP, index1);
1251}
1252
Alexey Frunze73296a72016-06-03 22:51:46 -07001253void CodeGeneratorMIPS::ComputeSpillMask() {
1254 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
1255 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
1256 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
1257 // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved
1258 // registers, include the ZERO register to force alignment of FPU callee-saved registers
1259 // within the stack frame.
1260 if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) {
1261 core_spill_mask_ |= (1 << ZERO);
1262 }
Alexey Frunze58320ce2016-08-30 21:40:46 -07001263}
1264
1265bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const {
Alexey Frunze06a46c42016-07-19 15:00:40 -07001266 // If RA is clobbered by PC-relative operations on R2 and it's the only spilled register
Alexey Frunze58320ce2016-08-30 21:40:46 -07001267 // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration()
1268 // into the path that creates a stack frame so that RA can be explicitly saved and restored.
1269 // RA can't otherwise be saved/restored when it's the only spilled register.
Alexey Frunze58320ce2016-08-30 21:40:46 -07001270 return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_;
Alexey Frunze73296a72016-06-03 22:51:46 -07001271}
1272
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001273static dwarf::Reg DWARFReg(Register reg) {
1274 return dwarf::Reg::MipsCore(static_cast<int>(reg));
1275}
1276
1277// TODO: mapping of floating-point registers to DWARF.
1278
1279void CodeGeneratorMIPS::GenerateFrameEntry() {
1280 __ Bind(&frame_entry_label_);
1281
Nicolas Geoffray8d728322018-01-18 22:44:32 +00001282 if (GetCompilerOptions().CountHotnessInCompiledCode()) {
Goran Jakovljevicfeec1672018-02-08 10:20:14 +01001283 __ Lhu(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value());
1284 __ Addiu(TMP, TMP, 1);
1285 __ Sh(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value());
Nicolas Geoffray8d728322018-01-18 22:44:32 +00001286 }
1287
Vladimir Marko33bff252017-11-01 14:35:42 +00001288 bool do_overflow_check =
1289 FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips) || !IsLeafMethod();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001290
1291 if (do_overflow_check) {
1292 __ LoadFromOffset(kLoadWord,
1293 ZERO,
1294 SP,
Vladimir Marko33bff252017-11-01 14:35:42 +00001295 -static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kMips)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001296 RecordPcInfo(nullptr, 0);
1297 }
1298
1299 if (HasEmptyFrame()) {
Alexey Frunze58320ce2016-08-30 21:40:46 -07001300 CHECK_EQ(fpu_spill_mask_, 0u);
1301 CHECK_EQ(core_spill_mask_, 1u << RA);
1302 CHECK(!clobbered_ra_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001303 return;
1304 }
1305
1306 // Make sure the frame size isn't unreasonably large.
Vladimir Marko33bff252017-11-01 14:35:42 +00001307 if (GetFrameSize() > GetStackOverflowReservedBytes(InstructionSet::kMips)) {
1308 LOG(FATAL) << "Stack frame larger than "
1309 << GetStackOverflowReservedBytes(InstructionSet::kMips) << " bytes";
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001310 }
1311
1312 // Spill callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001313
Alexey Frunze73296a72016-06-03 22:51:46 -07001314 uint32_t ofs = GetFrameSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001315 __ IncreaseFrameSize(ofs);
1316
Alexey Frunze73296a72016-06-03 22:51:46 -07001317 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
1318 Register reg = static_cast<Register>(MostSignificantBit(mask));
1319 mask ^= 1u << reg;
1320 ofs -= kMipsWordSize;
1321 // The ZERO register is only included for alignment.
1322 if (reg != ZERO) {
1323 __ StoreToOffset(kStoreWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001324 __ cfi().RelOffset(DWARFReg(reg), ofs);
1325 }
1326 }
1327
Alexey Frunze73296a72016-06-03 22:51:46 -07001328 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
1329 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
1330 mask ^= 1u << reg;
1331 ofs -= kMipsDoublewordSize;
1332 __ StoreDToOffset(reg, SP, ofs);
1333 // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001334 }
1335
Nicolas Geoffray96eeb4e2016-10-12 22:03:31 +01001336 // Save the current method if we need it. Note that we do not
1337 // do this in HCurrentMethod, as the instruction might have been removed
1338 // in the SSA graph.
1339 if (RequiresCurrentMethod()) {
1340 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
1341 }
Goran Jakovljevicc6418422016-12-05 16:31:55 +01001342
1343 if (GetGraph()->HasShouldDeoptimizeFlag()) {
1344 // Initialize should deoptimize flag to 0.
1345 __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag());
1346 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001347}
1348
1349void CodeGeneratorMIPS::GenerateFrameExit() {
1350 __ cfi().RememberState();
1351
1352 if (!HasEmptyFrame()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001353 // Restore callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001354
Alexey Frunze73296a72016-06-03 22:51:46 -07001355 // For better instruction scheduling restore RA before other registers.
1356 uint32_t ofs = GetFrameSize();
1357 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
1358 Register reg = static_cast<Register>(MostSignificantBit(mask));
1359 mask ^= 1u << reg;
1360 ofs -= kMipsWordSize;
1361 // The ZERO register is only included for alignment.
1362 if (reg != ZERO) {
1363 __ LoadFromOffset(kLoadWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001364 __ cfi().Restore(DWARFReg(reg));
1365 }
1366 }
1367
Alexey Frunze73296a72016-06-03 22:51:46 -07001368 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
1369 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
1370 mask ^= 1u << reg;
1371 ofs -= kMipsDoublewordSize;
1372 __ LoadDFromOffset(reg, SP, ofs);
1373 // TODO: __ cfi().Restore(DWARFReg(reg));
1374 }
1375
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001376 size_t frame_size = GetFrameSize();
1377 // Adjust the stack pointer in the delay slot if doing so doesn't break CFI.
1378 bool exchange = IsInt<16>(static_cast<int32_t>(frame_size));
1379 bool reordering = __ SetReorder(false);
1380 if (exchange) {
1381 __ Jr(RA);
1382 __ DecreaseFrameSize(frame_size); // Single instruction in delay slot.
1383 } else {
1384 __ DecreaseFrameSize(frame_size);
1385 __ Jr(RA);
1386 __ Nop(); // In delay slot.
1387 }
1388 __ SetReorder(reordering);
1389 } else {
1390 __ Jr(RA);
1391 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001392 }
1393
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001394 __ cfi().RestoreState();
1395 __ cfi().DefCFAOffset(GetFrameSize());
1396}
1397
1398void CodeGeneratorMIPS::Bind(HBasicBlock* block) {
1399 __ Bind(GetLabelOf(block));
1400}
1401
Lena Djokicca8c2952017-05-29 11:31:46 +02001402VectorRegister VectorRegisterFrom(Location location) {
1403 DCHECK(location.IsFpuRegister());
1404 return static_cast<VectorRegister>(location.AsFpuRegister<FRegister>());
1405}
1406
Lena Djokic8098da92017-06-28 12:07:50 +02001407void CodeGeneratorMIPS::MoveLocation(Location destination,
1408 Location source,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001409 DataType::Type dst_type) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001410 if (source.Equals(destination)) {
1411 return;
1412 }
1413
Lena Djokic8098da92017-06-28 12:07:50 +02001414 if (source.IsConstant()) {
1415 MoveConstant(destination, source.GetConstant());
1416 } else {
1417 if (destination.IsRegister()) {
1418 if (source.IsRegister()) {
1419 __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>());
1420 } else if (source.IsFpuRegister()) {
1421 __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>());
1422 } else {
1423 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001424 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Lena Djokic8098da92017-06-28 12:07:50 +02001425 }
1426 } else if (destination.IsRegisterPair()) {
1427 if (source.IsRegisterPair()) {
1428 __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
1429 __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
1430 } else if (source.IsFpuRegister()) {
1431 Register dst_high = destination.AsRegisterPairHigh<Register>();
1432 Register dst_low = destination.AsRegisterPairLow<Register>();
1433 FRegister src = source.AsFpuRegister<FRegister>();
1434 __ Mfc1(dst_low, src);
1435 __ MoveFromFpuHigh(dst_high, src);
1436 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001437 DCHECK(source.IsDoubleStackSlot())
1438 << "Cannot move from " << source << " to " << destination;
Lena Djokic8098da92017-06-28 12:07:50 +02001439 int32_t off = source.GetStackIndex();
1440 Register r = destination.AsRegisterPairLow<Register>();
1441 __ LoadFromOffset(kLoadDoubleword, r, SP, off);
1442 }
1443 } else if (destination.IsFpuRegister()) {
1444 if (source.IsRegister()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001445 DCHECK(!DataType::Is64BitType(dst_type));
Lena Djokic8098da92017-06-28 12:07:50 +02001446 __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>());
1447 } else if (source.IsRegisterPair()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001448 DCHECK(DataType::Is64BitType(dst_type));
Lena Djokic8098da92017-06-28 12:07:50 +02001449 FRegister dst = destination.AsFpuRegister<FRegister>();
1450 Register src_high = source.AsRegisterPairHigh<Register>();
1451 Register src_low = source.AsRegisterPairLow<Register>();
1452 __ Mtc1(src_low, dst);
1453 __ MoveToFpuHigh(src_high, dst);
1454 } else if (source.IsFpuRegister()) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001455 if (GetGraph()->HasSIMD()) {
1456 __ MoveV(VectorRegisterFrom(destination),
1457 VectorRegisterFrom(source));
Lena Djokic8098da92017-06-28 12:07:50 +02001458 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001459 if (DataType::Is64BitType(dst_type)) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001460 __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
1461 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001462 DCHECK_EQ(dst_type, DataType::Type::kFloat32);
Lena Djokicca8c2952017-05-29 11:31:46 +02001463 __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
1464 }
Lena Djokic8098da92017-06-28 12:07:50 +02001465 }
Lena Djokicca8c2952017-05-29 11:31:46 +02001466 } else if (source.IsSIMDStackSlot()) {
1467 __ LoadQFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
Lena Djokic8098da92017-06-28 12:07:50 +02001468 } else if (source.IsDoubleStackSlot()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001469 DCHECK(DataType::Is64BitType(dst_type));
Lena Djokic8098da92017-06-28 12:07:50 +02001470 __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
1471 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001472 DCHECK(!DataType::Is64BitType(dst_type));
Lena Djokic8098da92017-06-28 12:07:50 +02001473 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
1474 __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
1475 }
Lena Djokicca8c2952017-05-29 11:31:46 +02001476 } else if (destination.IsSIMDStackSlot()) {
1477 if (source.IsFpuRegister()) {
1478 __ StoreQToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex());
1479 } else {
1480 DCHECK(source.IsSIMDStackSlot());
1481 __ LoadQFromOffset(FTMP, SP, source.GetStackIndex());
1482 __ StoreQToOffset(FTMP, SP, destination.GetStackIndex());
1483 }
Lena Djokic8098da92017-06-28 12:07:50 +02001484 } else if (destination.IsDoubleStackSlot()) {
1485 int32_t dst_offset = destination.GetStackIndex();
1486 if (source.IsRegisterPair()) {
1487 __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, dst_offset);
1488 } else if (source.IsFpuRegister()) {
1489 __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset);
1490 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001491 DCHECK(source.IsDoubleStackSlot())
1492 << "Cannot move from " << source << " to " << destination;
Lena Djokic8098da92017-06-28 12:07:50 +02001493 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
1494 __ StoreToOffset(kStoreWord, TMP, SP, dst_offset);
1495 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4);
1496 __ StoreToOffset(kStoreWord, TMP, SP, dst_offset + 4);
1497 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001498 } else {
Lena Djokic8098da92017-06-28 12:07:50 +02001499 DCHECK(destination.IsStackSlot()) << destination;
1500 int32_t dst_offset = destination.GetStackIndex();
1501 if (source.IsRegister()) {
1502 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, dst_offset);
1503 } else if (source.IsFpuRegister()) {
1504 __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset);
1505 } else {
1506 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
1507 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
1508 __ StoreToOffset(kStoreWord, TMP, SP, dst_offset);
1509 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001510 }
1511 }
1512}
1513
1514void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) {
1515 if (c->IsIntConstant() || c->IsNullConstant()) {
1516 // Move 32 bit constant.
1517 int32_t value = GetInt32ValueOf(c);
1518 if (destination.IsRegister()) {
1519 Register dst = destination.AsRegister<Register>();
1520 __ LoadConst32(dst, value);
1521 } else {
1522 DCHECK(destination.IsStackSlot())
1523 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -07001524 __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001525 }
1526 } else if (c->IsLongConstant()) {
1527 // Move 64 bit constant.
1528 int64_t value = GetInt64ValueOf(c);
1529 if (destination.IsRegisterPair()) {
1530 Register r_h = destination.AsRegisterPairHigh<Register>();
1531 Register r_l = destination.AsRegisterPairLow<Register>();
1532 __ LoadConst64(r_h, r_l, value);
1533 } else {
1534 DCHECK(destination.IsDoubleStackSlot())
1535 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -07001536 __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001537 }
1538 } else if (c->IsFloatConstant()) {
1539 // Move 32 bit float constant.
1540 int32_t value = GetInt32ValueOf(c);
1541 if (destination.IsFpuRegister()) {
1542 __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP);
1543 } else {
1544 DCHECK(destination.IsStackSlot())
1545 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -07001546 __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001547 }
1548 } else {
1549 // Move 64 bit double constant.
1550 DCHECK(c->IsDoubleConstant()) << c->DebugName();
1551 int64_t value = GetInt64ValueOf(c);
1552 if (destination.IsFpuRegister()) {
1553 FRegister fd = destination.AsFpuRegister<FRegister>();
1554 __ LoadDConst64(fd, value, TMP);
1555 } else {
1556 DCHECK(destination.IsDoubleStackSlot())
1557 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -07001558 __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001559 }
1560 }
1561}
1562
1563void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) {
1564 DCHECK(destination.IsRegister());
1565 Register dst = destination.AsRegister<Register>();
1566 __ LoadConst32(dst, value);
1567}
1568
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001569void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) {
1570 if (location.IsRegister()) {
1571 locations->AddTemp(location);
Alexey Frunzec9e94f32015-10-26 16:11:39 -07001572 } else if (location.IsRegisterPair()) {
1573 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
1574 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001575 } else {
1576 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
1577 }
1578}
1579
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001580template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
Vladimir Markoaad75c62016-10-03 08:46:48 +00001581inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches(
1582 const ArenaDeque<PcRelativePatchInfo>& infos,
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001583 ArenaVector<linker::LinkerPatch>* linker_patches) {
Vladimir Markoaad75c62016-10-03 08:46:48 +00001584 for (const PcRelativePatchInfo& info : infos) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001585 const DexFile* dex_file = info.target_dex_file;
Vladimir Markoaad75c62016-10-03 08:46:48 +00001586 size_t offset_or_index = info.offset_or_index;
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001587 DCHECK(info.label.IsBound());
1588 uint32_t literal_offset = __ GetLabelLocation(&info.label);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001589 // On R2 we use HMipsComputeBaseMethodAddress and patch relative to
1590 // the assembler's base label used for PC-relative addressing.
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001591 const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info;
1592 uint32_t pc_rel_offset = info_high.pc_rel_label.IsBound()
1593 ? __ GetLabelLocation(&info_high.pc_rel_label)
Vladimir Markoaad75c62016-10-03 08:46:48 +00001594 : __ GetPcRelBaseLabelLocation();
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001595 linker_patches->push_back(Factory(literal_offset, dex_file, pc_rel_offset, offset_or_index));
Vladimir Markoaad75c62016-10-03 08:46:48 +00001596 }
1597}
1598
Vladimir Markob066d432018-01-03 13:14:37 +00001599linker::LinkerPatch DataBimgRelRoPatchAdapter(size_t literal_offset,
1600 const DexFile* target_dex_file,
1601 uint32_t pc_insn_offset,
1602 uint32_t boot_image_offset) {
1603 DCHECK(target_dex_file == nullptr); // Unused for DataBimgRelRoPatch(), should be null.
1604 return linker::LinkerPatch::DataBimgRelRoPatch(literal_offset, pc_insn_offset, boot_image_offset);
1605}
1606
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001607void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001608 DCHECK(linker_patches->empty());
1609 size_t size =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001610 boot_image_method_patches_.size() +
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001611 method_bss_entry_patches_.size() +
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001612 boot_image_type_patches_.size() +
Vladimir Marko65979462017-05-19 17:25:12 +01001613 type_bss_entry_patches_.size() +
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001614 boot_image_string_patches_.size() +
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01001615 string_bss_entry_patches_.size();
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001616 linker_patches->reserve(size);
Vladimir Marko65979462017-05-19 17:25:12 +01001617 if (GetCompilerOptions().IsBootImage()) {
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001618 EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>(
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001619 boot_image_method_patches_, linker_patches);
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001620 EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>(
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001621 boot_image_type_patches_, linker_patches);
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001622 EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>(
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001623 boot_image_string_patches_, linker_patches);
Vladimir Marko65979462017-05-19 17:25:12 +01001624 } else {
Vladimir Markob066d432018-01-03 13:14:37 +00001625 EmitPcRelativeLinkerPatches<DataBimgRelRoPatchAdapter>(
1626 boot_image_method_patches_, linker_patches);
Vladimir Markoe47f60c2018-02-21 13:43:28 +00001627 DCHECK(boot_image_type_patches_.empty());
1628 DCHECK(boot_image_string_patches_.empty());
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001629 }
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001630 EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>(
1631 method_bss_entry_patches_, linker_patches);
1632 EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>(
1633 type_bss_entry_patches_, linker_patches);
1634 EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>(
1635 string_bss_entry_patches_, linker_patches);
Vladimir Marko1998cd02017-01-13 13:02:58 +00001636 DCHECK_EQ(size, linker_patches->size());
Alexey Frunze06a46c42016-07-19 15:00:40 -07001637}
1638
Vladimir Markob066d432018-01-03 13:14:37 +00001639CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageRelRoPatch(
1640 uint32_t boot_image_offset,
1641 const PcRelativePatchInfo* info_high) {
1642 return NewPcRelativePatch(
1643 /* dex_file */ nullptr, boot_image_offset, info_high, &boot_image_method_patches_);
1644}
1645
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001646CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageMethodPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001647 MethodReference target_method,
1648 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001649 return NewPcRelativePatch(
1650 target_method.dex_file, target_method.index, info_high, &boot_image_method_patches_);
Alexey Frunze06a46c42016-07-19 15:00:40 -07001651}
1652
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001653CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewMethodBssEntryPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001654 MethodReference target_method,
1655 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001656 return NewPcRelativePatch(
1657 target_method.dex_file, target_method.index, info_high, &method_bss_entry_patches_);
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001658}
1659
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001660CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageTypePatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001661 const DexFile& dex_file,
1662 dex::TypeIndex type_index,
1663 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001664 return NewPcRelativePatch(&dex_file, type_index.index_, info_high, &boot_image_type_patches_);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001665}
1666
Vladimir Marko1998cd02017-01-13 13:02:58 +00001667CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewTypeBssEntryPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001668 const DexFile& dex_file,
1669 dex::TypeIndex type_index,
1670 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001671 return NewPcRelativePatch(&dex_file, type_index.index_, info_high, &type_bss_entry_patches_);
Vladimir Marko1998cd02017-01-13 13:02:58 +00001672}
1673
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001674CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageStringPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001675 const DexFile& dex_file,
1676 dex::StringIndex string_index,
1677 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001678 return NewPcRelativePatch(
1679 &dex_file, string_index.index_, info_high, &boot_image_string_patches_);
Vladimir Marko65979462017-05-19 17:25:12 +01001680}
1681
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01001682CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewStringBssEntryPatch(
1683 const DexFile& dex_file,
1684 dex::StringIndex string_index,
1685 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001686 return NewPcRelativePatch(&dex_file, string_index.index_, info_high, &string_bss_entry_patches_);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01001687}
1688
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001689CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch(
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001690 const DexFile* dex_file,
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001691 uint32_t offset_or_index,
1692 const PcRelativePatchInfo* info_high,
1693 ArenaDeque<PcRelativePatchInfo>* patches) {
1694 patches->emplace_back(dex_file, offset_or_index, info_high);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001695 return &patches->back();
1696}
1697
Alexey Frunze06a46c42016-07-19 15:00:40 -07001698Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
1699 return map->GetOrCreate(
1700 value,
1701 [this, value]() { return __ NewLiteral<uint32_t>(value); });
1702}
1703
Alexey Frunze06a46c42016-07-19 15:00:40 -07001704Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) {
Richard Uhlerc52f3032017-03-02 13:45:45 +00001705 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_);
Alexey Frunze06a46c42016-07-19 15:00:40 -07001706}
1707
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001708void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high,
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001709 Register out,
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001710 Register base) {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001711 DCHECK(!info_high->patch_info_high);
Alexey Frunze6079dca2017-05-28 19:10:28 -07001712 DCHECK_NE(out, base);
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001713 bool reordering = __ SetReorder(false);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001714 if (GetInstructionSetFeatures().IsR6()) {
1715 DCHECK_EQ(base, ZERO);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001716 __ Bind(&info_high->label);
1717 __ Bind(&info_high->pc_rel_label);
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001718 // Add the high half of a 32-bit offset to PC.
Vladimir Markoaad75c62016-10-03 08:46:48 +00001719 __ Auipc(out, /* placeholder */ 0x1234);
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001720 __ SetReorder(reordering);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001721 } else {
1722 // If base is ZERO, emit NAL to obtain the actual base.
1723 if (base == ZERO) {
1724 // Generate a dummy PC-relative call to obtain PC.
1725 __ Nal();
1726 }
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001727 __ Bind(&info_high->label);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001728 __ Lui(out, /* placeholder */ 0x1234);
1729 // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding
1730 // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler.
1731 if (base == ZERO) {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001732 __ Bind(&info_high->pc_rel_label);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001733 }
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001734 __ SetReorder(reordering);
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001735 // Add the high half of a 32-bit offset to PC.
Vladimir Markoaad75c62016-10-03 08:46:48 +00001736 __ Addu(out, out, (base == ZERO) ? RA : base);
1737 }
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001738 // A following instruction will add the sign-extended low half of the 32-bit
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001739 // offset to `out` (e.g. lw, jialc, addiu).
Vladimir Markoaad75c62016-10-03 08:46:48 +00001740}
1741
Alexey Frunze627c1a02017-01-30 19:28:14 -08001742CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootStringPatch(
1743 const DexFile& dex_file,
Vladimir Marko174b2e22017-10-12 13:34:49 +01001744 dex::StringIndex string_index,
Alexey Frunze627c1a02017-01-30 19:28:14 -08001745 Handle<mirror::String> handle) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01001746 ReserveJitStringRoot(StringReference(&dex_file, string_index), handle);
1747 jit_string_patches_.emplace_back(dex_file, string_index.index_);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001748 return &jit_string_patches_.back();
1749}
1750
1751CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootClassPatch(
1752 const DexFile& dex_file,
Vladimir Marko174b2e22017-10-12 13:34:49 +01001753 dex::TypeIndex type_index,
Alexey Frunze627c1a02017-01-30 19:28:14 -08001754 Handle<mirror::Class> handle) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01001755 ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle);
1756 jit_class_patches_.emplace_back(dex_file, type_index.index_);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001757 return &jit_class_patches_.back();
1758}
1759
1760void CodeGeneratorMIPS::PatchJitRootUse(uint8_t* code,
1761 const uint8_t* roots_data,
1762 const CodeGeneratorMIPS::JitPatchInfo& info,
1763 uint64_t index_in_table) const {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001764 uint32_t high_literal_offset = GetAssembler().GetLabelLocation(&info.high_label);
1765 uint32_t low_literal_offset = GetAssembler().GetLabelLocation(&info.low_label);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001766 uintptr_t address =
1767 reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>);
1768 uint32_t addr32 = dchecked_integral_cast<uint32_t>(address);
1769 // lui reg, addr32_high
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001770 DCHECK_EQ(code[high_literal_offset + 0], 0x34);
1771 DCHECK_EQ(code[high_literal_offset + 1], 0x12);
1772 DCHECK_EQ((code[high_literal_offset + 2] & 0xE0), 0x00);
1773 DCHECK_EQ(code[high_literal_offset + 3], 0x3C);
Alexey Frunzec61c0762017-04-10 13:54:23 -07001774 // instr reg, reg, addr32_low
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001775 DCHECK_EQ(code[low_literal_offset + 0], 0x78);
1776 DCHECK_EQ(code[low_literal_offset + 1], 0x56);
Alexey Frunzec61c0762017-04-10 13:54:23 -07001777 addr32 += (addr32 & 0x8000) << 1; // Account for sign extension in "instr reg, reg, addr32_low".
Alexey Frunze627c1a02017-01-30 19:28:14 -08001778 // lui reg, addr32_high
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001779 code[high_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 16);
1780 code[high_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 24);
Alexey Frunzec61c0762017-04-10 13:54:23 -07001781 // instr reg, reg, addr32_low
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001782 code[low_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 0);
1783 code[low_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 8);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001784}
1785
1786void CodeGeneratorMIPS::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) {
1787 for (const JitPatchInfo& info : jit_string_patches_) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01001788 StringReference string_reference(&info.target_dex_file, dex::StringIndex(info.index));
1789 uint64_t index_in_table = GetJitStringRootIndex(string_reference);
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001790 PatchJitRootUse(code, roots_data, info, index_in_table);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001791 }
1792 for (const JitPatchInfo& info : jit_class_patches_) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01001793 TypeReference type_reference(&info.target_dex_file, dex::TypeIndex(info.index));
1794 uint64_t index_in_table = GetJitClassRootIndex(type_reference);
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001795 PatchJitRootUse(code, roots_data, info, index_in_table);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001796 }
1797}
1798
Goran Jakovljevice114da22016-12-26 14:21:43 +01001799void CodeGeneratorMIPS::MarkGCCard(Register object,
1800 Register value,
1801 bool value_can_be_null) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001802 MipsLabel done;
1803 Register card = AT;
1804 Register temp = TMP;
Goran Jakovljevice114da22016-12-26 14:21:43 +01001805 if (value_can_be_null) {
1806 __ Beqz(value, &done);
1807 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001808 __ LoadFromOffset(kLoadWord,
1809 card,
1810 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001811 Thread::CardTableOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001812 __ Srl(temp, object, gc::accounting::CardTable::kCardShift);
1813 __ Addu(temp, card, temp);
1814 __ Sb(card, temp, 0);
Goran Jakovljevice114da22016-12-26 14:21:43 +01001815 if (value_can_be_null) {
1816 __ Bind(&done);
1817 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001818}
1819
David Brazdil58282f42016-01-14 12:45:10 +00001820void CodeGeneratorMIPS::SetupBlockedRegisters() const {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001821 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
1822 blocked_core_registers_[ZERO] = true;
1823 blocked_core_registers_[K0] = true;
1824 blocked_core_registers_[K1] = true;
1825 blocked_core_registers_[GP] = true;
1826 blocked_core_registers_[SP] = true;
1827 blocked_core_registers_[RA] = true;
1828
1829 // AT and TMP(T8) are used as temporary/scratch registers
1830 // (similar to how AT is used by MIPS assemblers).
1831 blocked_core_registers_[AT] = true;
1832 blocked_core_registers_[TMP] = true;
1833 blocked_fpu_registers_[FTMP] = true;
1834
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001835 if (GetInstructionSetFeatures().HasMsa()) {
1836 // To be used just for MSA instructions.
1837 blocked_fpu_registers_[FTMP2] = true;
1838 }
1839
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001840 // Reserve suspend and thread registers.
1841 blocked_core_registers_[S0] = true;
1842 blocked_core_registers_[TR] = true;
1843
1844 // Reserve T9 for function calls
1845 blocked_core_registers_[T9] = true;
1846
1847 // Reserve odd-numbered FPU registers.
1848 for (size_t i = 1; i < kNumberOfFRegisters; i += 2) {
1849 blocked_fpu_registers_[i] = true;
1850 }
1851
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02001852 if (GetGraph()->IsDebuggable()) {
1853 // Stubs do not save callee-save floating point registers. If the graph
1854 // is debuggable, we need to deal with these registers differently. For
1855 // now, just block them.
1856 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1857 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1858 }
1859 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001860}
1861
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001862size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1863 __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index);
1864 return kMipsWordSize;
1865}
1866
1867size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1868 __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index);
1869 return kMipsWordSize;
1870}
1871
1872size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001873 if (GetGraph()->HasSIMD()) {
1874 __ StoreQToOffset(FRegister(reg_id), SP, stack_index);
1875 } else {
1876 __ StoreDToOffset(FRegister(reg_id), SP, stack_index);
1877 }
1878 return GetFloatingPointSpillSlotSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001879}
1880
1881size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001882 if (GetGraph()->HasSIMD()) {
1883 __ LoadQFromOffset(FRegister(reg_id), SP, stack_index);
1884 } else {
1885 __ LoadDFromOffset(FRegister(reg_id), SP, stack_index);
1886 }
1887 return GetFloatingPointSpillSlotSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001888}
1889
1890void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001891 stream << Register(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001892}
1893
1894void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001895 stream << FRegister(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001896}
1897
Serban Constantinescufca16662016-07-14 09:21:59 +01001898constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16;
1899
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001900void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint,
1901 HInstruction* instruction,
1902 uint32_t dex_pc,
1903 SlowPathCode* slow_path) {
Alexandre Rames91a65162016-09-19 13:54:30 +01001904 ValidateInvokeRuntime(entrypoint, instruction, slow_path);
Alexey Frunze15958152017-02-09 19:08:30 -08001905 GenerateInvokeRuntime(GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value(),
1906 IsDirectEntrypoint(entrypoint));
1907 if (EntrypointRequiresStackMap(entrypoint)) {
1908 RecordPcInfo(instruction, dex_pc, slow_path);
1909 }
1910}
1911
1912void CodeGeneratorMIPS::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
1913 HInstruction* instruction,
1914 SlowPathCode* slow_path,
1915 bool direct) {
1916 ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path);
1917 GenerateInvokeRuntime(entry_point_offset, direct);
1918}
1919
1920void CodeGeneratorMIPS::GenerateInvokeRuntime(int32_t entry_point_offset, bool direct) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001921 bool reordering = __ SetReorder(false);
Alexey Frunze15958152017-02-09 19:08:30 -08001922 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001923 __ Jalr(T9);
Alexey Frunze15958152017-02-09 19:08:30 -08001924 if (direct) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001925 // Reserve argument space on stack (for $a0-$a3) for
1926 // entrypoints that directly reference native implementations.
1927 // Called function may use this space to store $a0-$a3 regs.
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001928 __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001929 __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001930 } else {
1931 __ Nop(); // In delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001932 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001933 __ SetReorder(reordering);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001934}
1935
1936void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path,
1937 Register class_reg) {
Vladimir Markodc682aa2018-01-04 18:42:57 +00001938 constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf();
1939 const size_t status_byte_offset =
1940 mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte);
1941 constexpr uint32_t shifted_initialized_value =
1942 enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte);
1943
1944 __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, status_byte_offset);
Lena Djokic3177e102018-02-28 11:32:40 +01001945 __ Sltiu(TMP, TMP, shifted_initialized_value);
1946 __ Bnez(TMP, slow_path->GetEntryLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001947 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
1948 __ Sync(0);
1949 __ Bind(slow_path->GetExitLabel());
1950}
1951
Vladimir Marko175e7862018-03-27 09:03:13 +00001952void InstructionCodeGeneratorMIPS::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check,
1953 Register temp) {
1954 uint32_t path_to_root = check->GetBitstringPathToRoot();
1955 uint32_t mask = check->GetBitstringMask();
1956 DCHECK(IsPowerOfTwo(mask + 1));
1957 size_t mask_bits = WhichPowerOf2(mask + 1);
1958
1959 if (mask_bits == 16u) {
1960 // Load only the bitstring part of the status word.
1961 __ LoadFromOffset(
1962 kLoadUnsignedHalfword, temp, temp, mirror::Class::StatusOffset().Int32Value());
1963 // Compare the bitstring bits using XOR.
1964 __ Xori(temp, temp, dchecked_integral_cast<uint16_t>(path_to_root));
1965 } else {
1966 // /* uint32_t */ temp = temp->status_
1967 __ LoadFromOffset(kLoadWord, temp, temp, mirror::Class::StatusOffset().Int32Value());
1968 // Compare the bitstring bits using XOR.
1969 if (IsUint<16>(path_to_root)) {
1970 __ Xori(temp, temp, dchecked_integral_cast<uint16_t>(path_to_root));
1971 } else {
1972 __ LoadConst32(TMP, path_to_root);
1973 __ Xor(temp, temp, TMP);
1974 }
1975 // Shift out bits that do not contribute to the comparison.
1976 __ Sll(temp, temp, 32 - mask_bits);
1977 }
1978}
1979
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001980void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1981 __ Sync(0); // Only stype 0 is supported.
1982}
1983
1984void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction,
1985 HBasicBlock* successor) {
1986 SuspendCheckSlowPathMIPS* slow_path =
Chris Larsena2045912017-11-02 12:39:54 -07001987 down_cast<SuspendCheckSlowPathMIPS*>(instruction->GetSlowPath());
1988
1989 if (slow_path == nullptr) {
1990 slow_path =
1991 new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS(instruction, successor);
1992 instruction->SetSlowPath(slow_path);
1993 codegen_->AddSlowPath(slow_path);
1994 if (successor != nullptr) {
1995 DCHECK(successor->IsLoopHeader());
1996 }
1997 } else {
1998 DCHECK_EQ(slow_path->GetSuccessor(), successor);
1999 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002000
2001 __ LoadFromOffset(kLoadUnsignedHalfword,
2002 TMP,
2003 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07002004 Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002005 if (successor == nullptr) {
2006 __ Bnez(TMP, slow_path->GetEntryLabel());
2007 __ Bind(slow_path->GetReturnLabel());
2008 } else {
2009 __ Beqz(TMP, codegen_->GetLabelOf(successor));
2010 __ B(slow_path->GetEntryLabel());
2011 // slow_path will return to GetLabelOf(successor).
2012 }
2013}
2014
2015InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph,
2016 CodeGeneratorMIPS* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08002017 : InstructionCodeGenerator(graph, codegen),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002018 assembler_(codegen->GetAssembler()),
2019 codegen_(codegen) {}
2020
2021void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
2022 DCHECK_EQ(instruction->InputCount(), 2U);
Vladimir Markoca6fff82017-10-03 14:49:14 +01002023 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002024 DataType::Type type = instruction->GetResultType();
Lena Djokic38530172017-11-16 11:11:50 +01002025 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002026 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002027 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002028 locations->SetInAt(0, Location::RequiresRegister());
2029 HInstruction* right = instruction->InputAt(1);
2030 bool can_use_imm = false;
2031 if (right->IsConstant()) {
2032 int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant());
2033 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
2034 can_use_imm = IsUint<16>(imm);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002035 } else {
Lena Djokic38530172017-11-16 11:11:50 +01002036 DCHECK(instruction->IsSub() || instruction->IsAdd());
2037 if (instruction->IsSub()) {
2038 imm = -imm;
2039 }
2040 if (isR6) {
2041 bool single_use = right->GetUses().HasExactlyOneElement();
2042 int16_t imm_high = High16Bits(imm);
2043 int16_t imm_low = Low16Bits(imm);
2044 if (imm_low < 0) {
2045 imm_high += 1;
2046 }
2047 can_use_imm = !((imm_high != 0) && (imm_low != 0)) || single_use;
2048 } else {
2049 can_use_imm = IsInt<16>(imm);
2050 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002051 }
2052 }
2053 if (can_use_imm)
2054 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
2055 else
2056 locations->SetInAt(1, Location::RequiresRegister());
2057 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2058 break;
2059 }
2060
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002061 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002062 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002063 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2064 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002065 break;
2066 }
2067
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002068 case DataType::Type::kFloat32:
2069 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002070 DCHECK(instruction->IsAdd() || instruction->IsSub());
2071 locations->SetInAt(0, Location::RequiresFpuRegister());
2072 locations->SetInAt(1, Location::RequiresFpuRegister());
2073 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2074 break;
2075
2076 default:
2077 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
2078 }
2079}
2080
2081void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002082 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002083 LocationSummary* locations = instruction->GetLocations();
Lena Djokic38530172017-11-16 11:11:50 +01002084 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002085
2086 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002087 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002088 Register dst = locations->Out().AsRegister<Register>();
2089 Register lhs = locations->InAt(0).AsRegister<Register>();
2090 Location rhs_location = locations->InAt(1);
2091
2092 Register rhs_reg = ZERO;
2093 int32_t rhs_imm = 0;
2094 bool use_imm = rhs_location.IsConstant();
2095 if (use_imm) {
2096 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2097 } else {
2098 rhs_reg = rhs_location.AsRegister<Register>();
2099 }
2100
2101 if (instruction->IsAnd()) {
2102 if (use_imm)
2103 __ Andi(dst, lhs, rhs_imm);
2104 else
2105 __ And(dst, lhs, rhs_reg);
2106 } else if (instruction->IsOr()) {
2107 if (use_imm)
2108 __ Ori(dst, lhs, rhs_imm);
2109 else
2110 __ Or(dst, lhs, rhs_reg);
2111 } else if (instruction->IsXor()) {
2112 if (use_imm)
2113 __ Xori(dst, lhs, rhs_imm);
2114 else
2115 __ Xor(dst, lhs, rhs_reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002116 } else {
Lena Djokic38530172017-11-16 11:11:50 +01002117 DCHECK(instruction->IsAdd() || instruction->IsSub());
2118 if (use_imm) {
2119 if (instruction->IsSub()) {
2120 rhs_imm = -rhs_imm;
2121 }
2122 if (IsInt<16>(rhs_imm)) {
2123 __ Addiu(dst, lhs, rhs_imm);
2124 } else {
2125 DCHECK(isR6);
2126 int16_t rhs_imm_high = High16Bits(rhs_imm);
2127 int16_t rhs_imm_low = Low16Bits(rhs_imm);
2128 if (rhs_imm_low < 0) {
2129 rhs_imm_high += 1;
2130 }
2131 __ Aui(dst, lhs, rhs_imm_high);
2132 if (rhs_imm_low != 0) {
2133 __ Addiu(dst, dst, rhs_imm_low);
2134 }
2135 }
2136 } else if (instruction->IsAdd()) {
2137 __ Addu(dst, lhs, rhs_reg);
2138 } else {
2139 DCHECK(instruction->IsSub());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002140 __ Subu(dst, lhs, rhs_reg);
Lena Djokic38530172017-11-16 11:11:50 +01002141 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002142 }
2143 break;
2144 }
2145
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002146 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002147 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
2148 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
2149 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2150 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002151 Location rhs_location = locations->InAt(1);
2152 bool use_imm = rhs_location.IsConstant();
2153 if (!use_imm) {
2154 Register rhs_high = rhs_location.AsRegisterPairHigh<Register>();
2155 Register rhs_low = rhs_location.AsRegisterPairLow<Register>();
2156 if (instruction->IsAnd()) {
2157 __ And(dst_low, lhs_low, rhs_low);
2158 __ And(dst_high, lhs_high, rhs_high);
2159 } else if (instruction->IsOr()) {
2160 __ Or(dst_low, lhs_low, rhs_low);
2161 __ Or(dst_high, lhs_high, rhs_high);
2162 } else if (instruction->IsXor()) {
2163 __ Xor(dst_low, lhs_low, rhs_low);
2164 __ Xor(dst_high, lhs_high, rhs_high);
2165 } else if (instruction->IsAdd()) {
2166 if (lhs_low == rhs_low) {
2167 // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs.
2168 __ Slt(TMP, lhs_low, ZERO);
2169 __ Addu(dst_low, lhs_low, rhs_low);
2170 } else {
2171 __ Addu(dst_low, lhs_low, rhs_low);
2172 // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged.
2173 __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low);
2174 }
2175 __ Addu(dst_high, lhs_high, rhs_high);
2176 __ Addu(dst_high, dst_high, TMP);
2177 } else {
2178 DCHECK(instruction->IsSub());
2179 __ Sltu(TMP, lhs_low, rhs_low);
2180 __ Subu(dst_low, lhs_low, rhs_low);
2181 __ Subu(dst_high, lhs_high, rhs_high);
2182 __ Subu(dst_high, dst_high, TMP);
2183 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002184 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002185 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
2186 if (instruction->IsOr()) {
2187 uint32_t low = Low32Bits(value);
2188 uint32_t high = High32Bits(value);
2189 if (IsUint<16>(low)) {
2190 if (dst_low != lhs_low || low != 0) {
2191 __ Ori(dst_low, lhs_low, low);
2192 }
2193 } else {
2194 __ LoadConst32(TMP, low);
2195 __ Or(dst_low, lhs_low, TMP);
2196 }
2197 if (IsUint<16>(high)) {
2198 if (dst_high != lhs_high || high != 0) {
2199 __ Ori(dst_high, lhs_high, high);
2200 }
2201 } else {
2202 if (high != low) {
2203 __ LoadConst32(TMP, high);
2204 }
2205 __ Or(dst_high, lhs_high, TMP);
2206 }
2207 } else if (instruction->IsXor()) {
2208 uint32_t low = Low32Bits(value);
2209 uint32_t high = High32Bits(value);
2210 if (IsUint<16>(low)) {
2211 if (dst_low != lhs_low || low != 0) {
2212 __ Xori(dst_low, lhs_low, low);
2213 }
2214 } else {
2215 __ LoadConst32(TMP, low);
2216 __ Xor(dst_low, lhs_low, TMP);
2217 }
2218 if (IsUint<16>(high)) {
2219 if (dst_high != lhs_high || high != 0) {
2220 __ Xori(dst_high, lhs_high, high);
2221 }
2222 } else {
2223 if (high != low) {
2224 __ LoadConst32(TMP, high);
2225 }
2226 __ Xor(dst_high, lhs_high, TMP);
2227 }
2228 } else if (instruction->IsAnd()) {
2229 uint32_t low = Low32Bits(value);
2230 uint32_t high = High32Bits(value);
2231 if (IsUint<16>(low)) {
2232 __ Andi(dst_low, lhs_low, low);
2233 } else if (low != 0xFFFFFFFF) {
2234 __ LoadConst32(TMP, low);
2235 __ And(dst_low, lhs_low, TMP);
2236 } else if (dst_low != lhs_low) {
2237 __ Move(dst_low, lhs_low);
2238 }
2239 if (IsUint<16>(high)) {
2240 __ Andi(dst_high, lhs_high, high);
2241 } else if (high != 0xFFFFFFFF) {
2242 if (high != low) {
2243 __ LoadConst32(TMP, high);
2244 }
2245 __ And(dst_high, lhs_high, TMP);
2246 } else if (dst_high != lhs_high) {
2247 __ Move(dst_high, lhs_high);
2248 }
2249 } else {
2250 if (instruction->IsSub()) {
2251 value = -value;
2252 } else {
2253 DCHECK(instruction->IsAdd());
2254 }
2255 int32_t low = Low32Bits(value);
2256 int32_t high = High32Bits(value);
2257 if (IsInt<16>(low)) {
2258 if (dst_low != lhs_low || low != 0) {
2259 __ Addiu(dst_low, lhs_low, low);
2260 }
2261 if (low != 0) {
2262 __ Sltiu(AT, dst_low, low);
2263 }
2264 } else {
2265 __ LoadConst32(TMP, low);
2266 __ Addu(dst_low, lhs_low, TMP);
2267 __ Sltu(AT, dst_low, TMP);
2268 }
2269 if (IsInt<16>(high)) {
2270 if (dst_high != lhs_high || high != 0) {
2271 __ Addiu(dst_high, lhs_high, high);
2272 }
2273 } else {
2274 if (high != low) {
2275 __ LoadConst32(TMP, high);
2276 }
2277 __ Addu(dst_high, lhs_high, TMP);
2278 }
2279 if (low != 0) {
2280 __ Addu(dst_high, dst_high, AT);
2281 }
2282 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002283 }
2284 break;
2285 }
2286
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002287 case DataType::Type::kFloat32:
2288 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002289 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
2290 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2291 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2292 if (instruction->IsAdd()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002293 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002294 __ AddS(dst, lhs, rhs);
2295 } else {
2296 __ AddD(dst, lhs, rhs);
2297 }
2298 } else {
2299 DCHECK(instruction->IsSub());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002300 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002301 __ SubS(dst, lhs, rhs);
2302 } else {
2303 __ SubD(dst, lhs, rhs);
2304 }
2305 }
2306 break;
2307 }
2308
2309 default:
2310 LOG(FATAL) << "Unexpected binary operation type " << type;
2311 }
2312}
2313
2314void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002315 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002316
Vladimir Markoca6fff82017-10-03 14:49:14 +01002317 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002318 DataType::Type type = instr->GetResultType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002319 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002320 case DataType::Type::kInt32:
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002321 locations->SetInAt(0, Location::RequiresRegister());
2322 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
2323 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2324 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002325 case DataType::Type::kInt64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002326 locations->SetInAt(0, Location::RequiresRegister());
2327 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
2328 locations->SetOut(Location::RequiresRegister());
2329 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002330 default:
2331 LOG(FATAL) << "Unexpected shift type " << type;
2332 }
2333}
2334
2335static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte;
2336
2337void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002338 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002339 LocationSummary* locations = instr->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002340 DataType::Type type = instr->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002341
2342 Location rhs_location = locations->InAt(1);
2343 bool use_imm = rhs_location.IsConstant();
2344 Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>();
2345 int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0;
Roland Levillain5b5b9312016-03-22 14:57:31 +00002346 const uint32_t shift_mask =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002347 (type == DataType::Type::kInt32) ? kMaxIntShiftDistance : kMaxLongShiftDistance;
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002348 const uint32_t shift_value = rhs_imm & shift_mask;
Alexey Frunze92d90602015-12-18 18:16:36 -08002349 // Are the INS (Insert Bit Field) and ROTR instructions supported?
2350 bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002351
2352 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002353 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002354 Register dst = locations->Out().AsRegister<Register>();
2355 Register lhs = locations->InAt(0).AsRegister<Register>();
2356 if (use_imm) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002357 if (shift_value == 0) {
2358 if (dst != lhs) {
2359 __ Move(dst, lhs);
2360 }
2361 } else if (instr->IsShl()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002362 __ Sll(dst, lhs, shift_value);
2363 } else if (instr->IsShr()) {
2364 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002365 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002366 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002367 } else {
2368 if (has_ins_rotr) {
2369 __ Rotr(dst, lhs, shift_value);
2370 } else {
2371 __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask);
2372 __ Srl(dst, lhs, shift_value);
2373 __ Or(dst, dst, TMP);
2374 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002375 }
2376 } else {
2377 if (instr->IsShl()) {
2378 __ Sllv(dst, lhs, rhs_reg);
2379 } else if (instr->IsShr()) {
2380 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002381 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002382 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002383 } else {
2384 if (has_ins_rotr) {
2385 __ Rotrv(dst, lhs, rhs_reg);
2386 } else {
2387 __ Subu(TMP, ZERO, rhs_reg);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002388 // 32-bit shift instructions use the 5 least significant bits of the shift count, so
2389 // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case
2390 // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out
2391 // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`,
2392 // IOW, the OR'd values are equal.
Alexey Frunze92d90602015-12-18 18:16:36 -08002393 __ Sllv(TMP, lhs, TMP);
2394 __ Srlv(dst, lhs, rhs_reg);
2395 __ Or(dst, dst, TMP);
2396 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002397 }
2398 }
2399 break;
2400 }
2401
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002402 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002403 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
2404 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
2405 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2406 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
2407 if (use_imm) {
2408 if (shift_value == 0) {
Lena Djokic8098da92017-06-28 12:07:50 +02002409 codegen_->MoveLocation(locations->Out(), locations->InAt(0), type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002410 } else if (shift_value < kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002411 if (has_ins_rotr) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002412 if (instr->IsShl()) {
2413 __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
2414 __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value);
2415 __ Sll(dst_low, lhs_low, shift_value);
2416 } else if (instr->IsShr()) {
2417 __ Srl(dst_low, lhs_low, shift_value);
2418 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
2419 __ Sra(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002420 } else if (instr->IsUShr()) {
2421 __ Srl(dst_low, lhs_low, shift_value);
2422 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
2423 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002424 } else {
2425 __ Srl(dst_low, lhs_low, shift_value);
2426 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
2427 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002428 __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002429 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002430 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002431 if (instr->IsShl()) {
2432 __ Sll(dst_low, lhs_low, shift_value);
2433 __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value);
2434 __ Sll(dst_high, lhs_high, shift_value);
2435 __ Or(dst_high, dst_high, TMP);
2436 } else if (instr->IsShr()) {
2437 __ Sra(dst_high, lhs_high, shift_value);
2438 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
2439 __ Srl(dst_low, lhs_low, shift_value);
2440 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08002441 } else if (instr->IsUShr()) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002442 __ Srl(dst_high, lhs_high, shift_value);
2443 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
2444 __ Srl(dst_low, lhs_low, shift_value);
2445 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08002446 } else {
2447 __ Srl(TMP, lhs_low, shift_value);
2448 __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value);
2449 __ Or(dst_low, dst_low, TMP);
2450 __ Srl(TMP, lhs_high, shift_value);
2451 __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
2452 __ Or(dst_high, dst_high, TMP);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002453 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002454 }
2455 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002456 const uint32_t shift_value_high = shift_value - kMipsBitsPerWord;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002457 if (instr->IsShl()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002458 __ Sll(dst_high, lhs_low, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002459 __ Move(dst_low, ZERO);
2460 } else if (instr->IsShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002461 __ Sra(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002462 __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1);
Alexey Frunze92d90602015-12-18 18:16:36 -08002463 } else if (instr->IsUShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002464 __ Srl(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002465 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08002466 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002467 if (shift_value == kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002468 // 64-bit rotation by 32 is just a swap.
2469 __ Move(dst_low, lhs_high);
2470 __ Move(dst_high, lhs_low);
2471 } else {
2472 if (has_ins_rotr) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002473 __ Srl(dst_low, lhs_high, shift_value_high);
2474 __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high);
2475 __ Srl(dst_high, lhs_low, shift_value_high);
2476 __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08002477 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002478 __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high);
2479 __ Srl(dst_low, lhs_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08002480 __ Or(dst_low, dst_low, TMP);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002481 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high);
2482 __ Srl(dst_high, lhs_low, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08002483 __ Or(dst_high, dst_high, TMP);
2484 }
2485 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002486 }
2487 }
2488 } else {
Chris Larsen3e5fecd2017-11-09 14:21:28 -08002489 const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002490 MipsLabel done;
2491 if (instr->IsShl()) {
2492 __ Sllv(dst_low, lhs_low, rhs_reg);
2493 __ Nor(AT, ZERO, rhs_reg);
2494 __ Srl(TMP, lhs_low, 1);
2495 __ Srlv(TMP, TMP, AT);
2496 __ Sllv(dst_high, lhs_high, rhs_reg);
2497 __ Or(dst_high, dst_high, TMP);
2498 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
Chris Larsen3e5fecd2017-11-09 14:21:28 -08002499 if (isR6) {
2500 __ Beqzc(TMP, &done, /* is_bare */ true);
2501 __ Move(dst_high, dst_low);
2502 __ Move(dst_low, ZERO);
2503 } else {
2504 __ Movn(dst_high, dst_low, TMP);
2505 __ Movn(dst_low, ZERO, TMP);
2506 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002507 } else if (instr->IsShr()) {
2508 __ Srav(dst_high, lhs_high, rhs_reg);
2509 __ Nor(AT, ZERO, rhs_reg);
2510 __ Sll(TMP, lhs_high, 1);
2511 __ Sllv(TMP, TMP, AT);
2512 __ Srlv(dst_low, lhs_low, rhs_reg);
2513 __ Or(dst_low, dst_low, TMP);
2514 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
Chris Larsen3e5fecd2017-11-09 14:21:28 -08002515 if (isR6) {
2516 __ Beqzc(TMP, &done, /* is_bare */ true);
2517 __ Move(dst_low, dst_high);
2518 __ Sra(dst_high, dst_high, 31);
2519 } else {
2520 __ Sra(AT, dst_high, 31);
2521 __ Movn(dst_low, dst_high, TMP);
2522 __ Movn(dst_high, AT, TMP);
2523 }
Alexey Frunze92d90602015-12-18 18:16:36 -08002524 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002525 __ Srlv(dst_high, lhs_high, rhs_reg);
2526 __ Nor(AT, ZERO, rhs_reg);
2527 __ Sll(TMP, lhs_high, 1);
2528 __ Sllv(TMP, TMP, AT);
2529 __ Srlv(dst_low, lhs_low, rhs_reg);
2530 __ Or(dst_low, dst_low, TMP);
2531 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
Chris Larsen3e5fecd2017-11-09 14:21:28 -08002532 if (isR6) {
2533 __ Beqzc(TMP, &done, /* is_bare */ true);
2534 __ Move(dst_low, dst_high);
2535 __ Move(dst_high, ZERO);
2536 } else {
2537 __ Movn(dst_low, dst_high, TMP);
2538 __ Movn(dst_high, ZERO, TMP);
2539 }
2540 } else { // Rotate.
Alexey Frunze92d90602015-12-18 18:16:36 -08002541 __ Nor(AT, ZERO, rhs_reg);
2542 __ Srlv(TMP, lhs_low, rhs_reg);
2543 __ Sll(dst_low, lhs_high, 1);
2544 __ Sllv(dst_low, dst_low, AT);
2545 __ Or(dst_low, dst_low, TMP);
2546 __ Srlv(TMP, lhs_high, rhs_reg);
2547 __ Sll(dst_high, lhs_low, 1);
2548 __ Sllv(dst_high, dst_high, AT);
2549 __ Or(dst_high, dst_high, TMP);
2550 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
Chris Larsen3e5fecd2017-11-09 14:21:28 -08002551 if (isR6) {
2552 __ Beqzc(TMP, &done, /* is_bare */ true);
2553 __ Move(TMP, dst_high);
2554 __ Move(dst_high, dst_low);
2555 __ Move(dst_low, TMP);
2556 } else {
2557 __ Movn(AT, dst_high, TMP);
2558 __ Movn(dst_high, dst_low, TMP);
2559 __ Movn(dst_low, AT, TMP);
2560 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002561 }
2562 __ Bind(&done);
2563 }
2564 break;
2565 }
2566
2567 default:
2568 LOG(FATAL) << "Unexpected shift operation type " << type;
2569 }
2570}
2571
2572void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) {
2573 HandleBinaryOp(instruction);
2574}
2575
2576void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) {
2577 HandleBinaryOp(instruction);
2578}
2579
2580void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) {
2581 HandleBinaryOp(instruction);
2582}
2583
2584void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) {
2585 HandleBinaryOp(instruction);
2586}
2587
2588void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002589 DataType::Type type = instruction->GetType();
Alexey Frunze15958152017-02-09 19:08:30 -08002590 bool object_array_get_with_read_barrier =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002591 kEmitCompilerReadBarrier && (type == DataType::Type::kReference);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002592 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01002593 new (GetGraph()->GetAllocator()) LocationSummary(instruction,
2594 object_array_get_with_read_barrier
2595 ? LocationSummary::kCallOnSlowPath
2596 : LocationSummary::kNoCall);
Alexey Frunzec61c0762017-04-10 13:54:23 -07002597 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
2598 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
2599 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002600 locations->SetInAt(0, Location::RequiresRegister());
2601 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002602 if (DataType::IsFloatingPointType(type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002603 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2604 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08002605 // The output overlaps in the case of an object array get with
2606 // read barriers enabled: we do not want the move to overwrite the
2607 // array's location, as we need it to emit the read barrier.
2608 locations->SetOut(Location::RequiresRegister(),
2609 object_array_get_with_read_barrier
2610 ? Location::kOutputOverlap
2611 : Location::kNoOutputOverlap);
2612 }
2613 // We need a temporary register for the read barrier marking slow
2614 // path in CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier.
2615 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002616 bool temp_needed = instruction->GetIndex()->IsConstant()
2617 ? !kBakerReadBarrierThunksEnableForFields
2618 : !kBakerReadBarrierThunksEnableForArrays;
2619 if (temp_needed) {
2620 locations->AddTemp(Location::RequiresRegister());
2621 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002622 }
2623}
2624
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002625static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS* codegen) {
2626 auto null_checker = [codegen, instruction]() {
2627 codegen->MaybeRecordImplicitNullCheck(instruction);
Alexey Frunze2923db72016-08-20 01:55:47 -07002628 };
2629 return null_checker;
2630}
2631
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002632void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) {
2633 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08002634 Location obj_loc = locations->InAt(0);
2635 Register obj = obj_loc.AsRegister<Register>();
2636 Location out_loc = locations->Out();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002637 Location index = locations->InAt(1);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01002638 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002639 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002640
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002641 DataType::Type type = instruction->GetType();
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002642 const bool maybe_compressed_char_at = mirror::kUseStringCompression &&
2643 instruction->IsStringCharAt();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002644 switch (type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002645 case DataType::Type::kBool:
2646 case DataType::Type::kUint8: {
Alexey Frunze15958152017-02-09 19:08:30 -08002647 Register out = out_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002648 if (index.IsConstant()) {
2649 size_t offset =
2650 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002651 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002652 } else {
2653 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07002654 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002655 }
2656 break;
2657 }
2658
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002659 case DataType::Type::kInt8: {
Alexey Frunze15958152017-02-09 19:08:30 -08002660 Register out = out_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002661 if (index.IsConstant()) {
2662 size_t offset =
2663 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002664 __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002665 } else {
2666 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07002667 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002668 }
2669 break;
2670 }
2671
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002672 case DataType::Type::kUint16: {
Alexey Frunze15958152017-02-09 19:08:30 -08002673 Register out = out_loc.AsRegister<Register>();
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002674 if (maybe_compressed_char_at) {
2675 uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
2676 __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker);
2677 __ Sll(TMP, TMP, 31); // Extract compression flag into the most significant bit of TMP.
2678 static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u,
2679 "Expecting 0=compressed, 1=uncompressed");
2680 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002681 if (index.IsConstant()) {
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002682 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
2683 if (maybe_compressed_char_at) {
2684 MipsLabel uncompressed_load, done;
2685 __ Bnez(TMP, &uncompressed_load);
2686 __ LoadFromOffset(kLoadUnsignedByte,
2687 out,
2688 obj,
2689 data_offset + (const_index << TIMES_1));
2690 __ B(&done);
2691 __ Bind(&uncompressed_load);
2692 __ LoadFromOffset(kLoadUnsignedHalfword,
2693 out,
2694 obj,
2695 data_offset + (const_index << TIMES_2));
2696 __ Bind(&done);
2697 } else {
2698 __ LoadFromOffset(kLoadUnsignedHalfword,
2699 out,
2700 obj,
2701 data_offset + (const_index << TIMES_2),
2702 null_checker);
2703 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002704 } else {
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002705 Register index_reg = index.AsRegister<Register>();
2706 if (maybe_compressed_char_at) {
2707 MipsLabel uncompressed_load, done;
2708 __ Bnez(TMP, &uncompressed_load);
2709 __ Addu(TMP, obj, index_reg);
2710 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset);
2711 __ B(&done);
2712 __ Bind(&uncompressed_load);
Chris Larsencd0295d2017-03-31 15:26:54 -07002713 __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002714 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset);
2715 __ Bind(&done);
Lena Djokica2901602017-09-21 13:50:52 +02002716 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2717 __ Addu(TMP, index_reg, obj);
2718 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002719 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002720 __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002721 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker);
2722 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002723 }
2724 break;
2725 }
2726
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002727 case DataType::Type::kInt16: {
2728 Register out = out_loc.AsRegister<Register>();
2729 if (index.IsConstant()) {
2730 size_t offset =
2731 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2732 __ LoadFromOffset(kLoadSignedHalfword, 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 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker);
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002736 } else {
2737 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_2, TMP);
2738 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker);
2739 }
2740 break;
2741 }
2742
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002743 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002744 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
Alexey Frunze15958152017-02-09 19:08:30 -08002745 Register out = out_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002746 if (index.IsConstant()) {
2747 size_t offset =
2748 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002749 __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker);
Lena Djokica2901602017-09-21 13:50:52 +02002750 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2751 __ Addu(TMP, index.AsRegister<Register>(), obj);
2752 __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002753 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002754 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002755 __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002756 }
2757 break;
2758 }
2759
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002760 case DataType::Type::kReference: {
Alexey Frunze15958152017-02-09 19:08:30 -08002761 static_assert(
2762 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
2763 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
2764 // /* HeapReference<Object> */ out =
2765 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
2766 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002767 bool temp_needed = index.IsConstant()
2768 ? !kBakerReadBarrierThunksEnableForFields
2769 : !kBakerReadBarrierThunksEnableForArrays;
2770 Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation();
Alexey Frunze15958152017-02-09 19:08:30 -08002771 // Note that a potential implicit null check is handled in this
2772 // CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier call.
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002773 DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0)));
2774 if (index.IsConstant()) {
2775 // Array load with a constant index can be treated as a field load.
2776 size_t offset =
2777 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2778 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
2779 out_loc,
2780 obj,
2781 offset,
2782 temp,
2783 /* needs_null_check */ false);
2784 } else {
2785 codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction,
2786 out_loc,
2787 obj,
2788 data_offset,
2789 index,
2790 temp,
2791 /* needs_null_check */ false);
2792 }
Alexey Frunze15958152017-02-09 19:08:30 -08002793 } else {
2794 Register out = out_loc.AsRegister<Register>();
2795 if (index.IsConstant()) {
2796 size_t offset =
2797 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2798 __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker);
2799 // If read barriers are enabled, emit read barriers other than
2800 // Baker's using a slow path (and also unpoison the loaded
2801 // reference, if heap poisoning is enabled).
2802 codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
2803 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002804 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP);
Alexey Frunze15958152017-02-09 19:08:30 -08002805 __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
2806 // If read barriers are enabled, emit read barriers other than
2807 // Baker's using a slow path (and also unpoison the loaded
2808 // reference, if heap poisoning is enabled).
2809 codegen_->MaybeGenerateReadBarrierSlow(instruction,
2810 out_loc,
2811 out_loc,
2812 obj_loc,
2813 data_offset,
2814 index);
2815 }
2816 }
2817 break;
2818 }
2819
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002820 case DataType::Type::kInt64: {
Alexey Frunze15958152017-02-09 19:08:30 -08002821 Register out = out_loc.AsRegisterPairLow<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002822 if (index.IsConstant()) {
2823 size_t offset =
2824 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002825 __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker);
Lena Djokica2901602017-09-21 13:50:52 +02002826 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2827 __ Addu(TMP, index.AsRegister<Register>(), obj);
2828 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002829 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002830 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002831 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002832 }
2833 break;
2834 }
2835
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002836 case DataType::Type::kFloat32: {
Alexey Frunze15958152017-02-09 19:08:30 -08002837 FRegister out = out_loc.AsFpuRegister<FRegister>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002838 if (index.IsConstant()) {
2839 size_t offset =
2840 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002841 __ LoadSFromOffset(out, obj, offset, null_checker);
Lena Djokica2901602017-09-21 13:50:52 +02002842 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2843 __ Addu(TMP, index.AsRegister<Register>(), obj);
2844 __ LoadSFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002845 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002846 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002847 __ LoadSFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002848 }
2849 break;
2850 }
2851
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002852 case DataType::Type::kFloat64: {
Alexey Frunze15958152017-02-09 19:08:30 -08002853 FRegister out = out_loc.AsFpuRegister<FRegister>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002854 if (index.IsConstant()) {
2855 size_t offset =
2856 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002857 __ LoadDFromOffset(out, obj, offset, null_checker);
Lena Djokica2901602017-09-21 13:50:52 +02002858 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2859 __ Addu(TMP, index.AsRegister<Register>(), obj);
2860 __ LoadDFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002861 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002862 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002863 __ LoadDFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002864 }
2865 break;
2866 }
2867
Aart Bik66c158e2018-01-31 12:55:04 -08002868 case DataType::Type::kUint32:
2869 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002870 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002871 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2872 UNREACHABLE();
2873 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002874}
2875
2876void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01002877 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002878 locations->SetInAt(0, Location::RequiresRegister());
2879 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2880}
2881
2882void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) {
2883 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01002884 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002885 Register obj = locations->InAt(0).AsRegister<Register>();
2886 Register out = locations->Out().AsRegister<Register>();
2887 __ LoadFromOffset(kLoadWord, out, obj, offset);
2888 codegen_->MaybeRecordImplicitNullCheck(instruction);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002889 // Mask out compression flag from String's array length.
2890 if (mirror::kUseStringCompression && instruction->IsStringLength()) {
2891 __ Srl(out, out, 1u);
2892 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002893}
2894
Alexey Frunzef58b2482016-09-02 22:14:06 -07002895Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) {
2896 return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern())
2897 ? Location::ConstantLocation(instruction->AsConstant())
2898 : Location::RequiresRegister();
2899}
2900
2901Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) {
2902 // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register.
2903 // We can store a non-zero float or double constant without first loading it into the FPU,
2904 // but we should only prefer this if the constant has a single use.
2905 if (instruction->IsConstant() &&
2906 (instruction->AsConstant()->IsZeroBitPattern() ||
2907 instruction->GetUses().HasExactlyOneElement())) {
2908 return Location::ConstantLocation(instruction->AsConstant());
2909 // Otherwise fall through and require an FPU register for the constant.
2910 }
2911 return Location::RequiresFpuRegister();
2912}
2913
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002914void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002915 DataType::Type value_type = instruction->GetComponentType();
Alexey Frunze15958152017-02-09 19:08:30 -08002916
2917 bool needs_write_barrier =
2918 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
2919 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
2920
Vladimir Markoca6fff82017-10-03 14:49:14 +01002921 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002922 instruction,
Alexey Frunze15958152017-02-09 19:08:30 -08002923 may_need_runtime_call_for_type_check ?
2924 LocationSummary::kCallOnSlowPath :
2925 LocationSummary::kNoCall);
2926
2927 locations->SetInAt(0, Location::RequiresRegister());
2928 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002929 if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
Alexey Frunze15958152017-02-09 19:08:30 -08002930 locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002931 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08002932 locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2)));
2933 }
2934 if (needs_write_barrier) {
2935 // Temporary register for the write barrier.
2936 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002937 }
2938}
2939
2940void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) {
2941 LocationSummary* locations = instruction->GetLocations();
2942 Register obj = locations->InAt(0).AsRegister<Register>();
2943 Location index = locations->InAt(1);
Alexey Frunzef58b2482016-09-02 22:14:06 -07002944 Location value_location = locations->InAt(2);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002945 DataType::Type value_type = instruction->GetComponentType();
Alexey Frunze15958152017-02-09 19:08:30 -08002946 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002947 bool needs_write_barrier =
2948 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002949 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Alexey Frunzef58b2482016-09-02 22:14:06 -07002950 Register base_reg = index.IsConstant() ? obj : TMP;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002951
2952 switch (value_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002953 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002954 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002955 case DataType::Type::kInt8: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002956 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002957 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002958 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002959 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002960 __ Addu(base_reg, obj, index.AsRegister<Register>());
2961 }
2962 if (value_location.IsConstant()) {
2963 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2964 __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker);
2965 } else {
2966 Register value = value_location.AsRegister<Register>();
2967 __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002968 }
2969 break;
2970 }
2971
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002972 case DataType::Type::kUint16:
2973 case DataType::Type::kInt16: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002974 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002975 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002976 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2;
Lena Djokica2901602017-09-21 13:50:52 +02002977 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2978 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002979 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002980 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_2, base_reg);
Alexey Frunzef58b2482016-09-02 22:14:06 -07002981 }
2982 if (value_location.IsConstant()) {
2983 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2984 __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker);
2985 } else {
2986 Register value = value_location.AsRegister<Register>();
2987 __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002988 }
2989 break;
2990 }
2991
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002992 case DataType::Type::kInt32: {
Alexey Frunze15958152017-02-09 19:08:30 -08002993 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2994 if (index.IsConstant()) {
2995 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Lena Djokica2901602017-09-21 13:50:52 +02002996 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2997 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Alexey Frunze15958152017-02-09 19:08:30 -08002998 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002999 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg);
Alexey Frunze15958152017-02-09 19:08:30 -08003000 }
3001 if (value_location.IsConstant()) {
3002 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
3003 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
3004 } else {
3005 Register value = value_location.AsRegister<Register>();
3006 __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
3007 }
3008 break;
3009 }
3010
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003011 case DataType::Type::kReference: {
Alexey Frunze15958152017-02-09 19:08:30 -08003012 if (value_location.IsConstant()) {
3013 // Just setting null.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003014 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003015 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07003016 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003017 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07003018 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003019 }
Alexey Frunze15958152017-02-09 19:08:30 -08003020 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
3021 DCHECK_EQ(value, 0);
3022 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
3023 DCHECK(!needs_write_barrier);
3024 DCHECK(!may_need_runtime_call_for_type_check);
3025 break;
3026 }
3027
3028 DCHECK(needs_write_barrier);
3029 Register value = value_location.AsRegister<Register>();
3030 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
3031 Register temp2 = TMP; // Doesn't need to survive slow path.
3032 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3033 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
3034 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
3035 MipsLabel done;
3036 SlowPathCodeMIPS* slow_path = nullptr;
3037
3038 if (may_need_runtime_call_for_type_check) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01003039 slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS(instruction);
Alexey Frunze15958152017-02-09 19:08:30 -08003040 codegen_->AddSlowPath(slow_path);
3041 if (instruction->GetValueCanBeNull()) {
3042 MipsLabel non_zero;
3043 __ Bnez(value, &non_zero);
3044 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
3045 if (index.IsConstant()) {
3046 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Lena Djokica2901602017-09-21 13:50:52 +02003047 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
3048 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Alexey Frunzec061de12017-02-14 13:27:23 -08003049 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07003050 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg);
Alexey Frunzec061de12017-02-14 13:27:23 -08003051 }
Alexey Frunze15958152017-02-09 19:08:30 -08003052 __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
3053 __ B(&done);
3054 __ Bind(&non_zero);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003055 }
Alexey Frunze15958152017-02-09 19:08:30 -08003056
3057 // Note that when read barriers are enabled, the type checks
3058 // are performed without read barriers. This is fine, even in
3059 // the case where a class object is in the from-space after
3060 // the flip, as a comparison involving such a type would not
3061 // produce a false positive; it may of course produce a false
3062 // negative, in which case we would take the ArraySet slow
3063 // path.
3064
3065 // /* HeapReference<Class> */ temp1 = obj->klass_
3066 __ LoadFromOffset(kLoadWord, temp1, obj, class_offset, null_checker);
3067 __ MaybeUnpoisonHeapReference(temp1);
3068
3069 // /* HeapReference<Class> */ temp1 = temp1->component_type_
3070 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
3071 // /* HeapReference<Class> */ temp2 = value->klass_
3072 __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
3073 // If heap poisoning is enabled, no need to unpoison `temp1`
3074 // nor `temp2`, as we are comparing two poisoned references.
3075
3076 if (instruction->StaticTypeOfArrayIsObjectArray()) {
3077 MipsLabel do_put;
3078 __ Beq(temp1, temp2, &do_put);
3079 // If heap poisoning is enabled, the `temp1` reference has
3080 // not been unpoisoned yet; unpoison it now.
3081 __ MaybeUnpoisonHeapReference(temp1);
3082
3083 // /* HeapReference<Class> */ temp1 = temp1->super_class_
3084 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
3085 // If heap poisoning is enabled, no need to unpoison
3086 // `temp1`, as we are comparing against null below.
3087 __ Bnez(temp1, slow_path->GetEntryLabel());
3088 __ Bind(&do_put);
3089 } else {
3090 __ Bne(temp1, temp2, slow_path->GetEntryLabel());
3091 }
3092 }
3093
3094 Register source = value;
3095 if (kPoisonHeapReferences) {
3096 // Note that in the case where `value` is a null reference,
3097 // we do not enter this block, as a null reference does not
3098 // need poisoning.
3099 __ Move(temp1, value);
3100 __ PoisonHeapReference(temp1);
3101 source = temp1;
3102 }
3103
3104 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
3105 if (index.IsConstant()) {
3106 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003107 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07003108 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg);
Alexey Frunze15958152017-02-09 19:08:30 -08003109 }
3110 __ StoreToOffset(kStoreWord, source, base_reg, data_offset);
3111
3112 if (!may_need_runtime_call_for_type_check) {
3113 codegen_->MaybeRecordImplicitNullCheck(instruction);
3114 }
3115
3116 codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull());
3117
3118 if (done.IsLinked()) {
3119 __ Bind(&done);
3120 }
3121
3122 if (slow_path != nullptr) {
3123 __ Bind(slow_path->GetExitLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003124 }
3125 break;
3126 }
3127
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003128 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003129 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003130 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07003131 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Lena Djokica2901602017-09-21 13:50:52 +02003132 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
3133 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003134 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07003135 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg);
Alexey Frunzef58b2482016-09-02 22:14:06 -07003136 }
3137 if (value_location.IsConstant()) {
3138 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
3139 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
3140 } else {
3141 Register value = value_location.AsRegisterPairLow<Register>();
3142 __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003143 }
3144 break;
3145 }
3146
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003147 case DataType::Type::kFloat32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003148 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003149 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07003150 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Lena Djokica2901602017-09-21 13:50:52 +02003151 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
3152 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003153 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07003154 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg);
Alexey Frunzef58b2482016-09-02 22:14:06 -07003155 }
3156 if (value_location.IsConstant()) {
3157 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
3158 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
3159 } else {
3160 FRegister value = value_location.AsFpuRegister<FRegister>();
3161 __ StoreSToOffset(value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003162 }
3163 break;
3164 }
3165
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003166 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003167 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003168 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07003169 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Lena Djokica2901602017-09-21 13:50:52 +02003170 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
3171 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003172 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07003173 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg);
Alexey Frunzef58b2482016-09-02 22:14:06 -07003174 }
3175 if (value_location.IsConstant()) {
3176 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
3177 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
3178 } else {
3179 FRegister value = value_location.AsFpuRegister<FRegister>();
3180 __ StoreDToOffset(value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003181 }
3182 break;
3183 }
3184
Aart Bik66c158e2018-01-31 12:55:04 -08003185 case DataType::Type::kUint32:
3186 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003187 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003188 LOG(FATAL) << "Unreachable type " << instruction->GetType();
3189 UNREACHABLE();
3190 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003191}
3192
Lena Djokica2901602017-09-21 13:50:52 +02003193void LocationsBuilderMIPS::VisitIntermediateArrayAddressIndex(
3194 HIntermediateArrayAddressIndex* instruction) {
3195 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003196 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Lena Djokica2901602017-09-21 13:50:52 +02003197
3198 HIntConstant* shift = instruction->GetShift()->AsIntConstant();
3199
3200 locations->SetInAt(0, Location::RequiresRegister());
3201 locations->SetInAt(1, Location::ConstantLocation(shift));
3202 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3203}
3204
3205void InstructionCodeGeneratorMIPS::VisitIntermediateArrayAddressIndex(
3206 HIntermediateArrayAddressIndex* instruction) {
3207 LocationSummary* locations = instruction->GetLocations();
3208 Register index_reg = locations->InAt(0).AsRegister<Register>();
3209 uint32_t shift = instruction->GetShift()->AsIntConstant()->GetValue();
3210 __ Sll(locations->Out().AsRegister<Register>(), index_reg, shift);
3211}
3212
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003213void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01003214 RegisterSet caller_saves = RegisterSet::Empty();
3215 InvokeRuntimeCallingConvention calling_convention;
3216 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3217 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3218 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves);
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01003219
3220 HInstruction* index = instruction->InputAt(0);
3221 HInstruction* length = instruction->InputAt(1);
3222
3223 bool const_index = false;
3224 bool const_length = false;
3225
3226 if (index->IsConstant()) {
3227 if (length->IsConstant()) {
3228 const_index = true;
3229 const_length = true;
3230 } else {
3231 int32_t index_value = index->AsIntConstant()->GetValue();
3232 if (index_value < 0 || IsInt<16>(index_value + 1)) {
3233 const_index = true;
3234 }
3235 }
3236 } else if (length->IsConstant()) {
3237 int32_t length_value = length->AsIntConstant()->GetValue();
3238 if (IsUint<15>(length_value)) {
3239 const_length = true;
3240 }
3241 }
3242
3243 locations->SetInAt(0, const_index
3244 ? Location::ConstantLocation(index->AsConstant())
3245 : Location::RequiresRegister());
3246 locations->SetInAt(1, const_length
3247 ? Location::ConstantLocation(length->AsConstant())
3248 : Location::RequiresRegister());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003249}
3250
3251void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
3252 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01003253 Location index_loc = locations->InAt(0);
3254 Location length_loc = locations->InAt(1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003255
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01003256 if (length_loc.IsConstant()) {
3257 int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue();
3258 if (index_loc.IsConstant()) {
3259 int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue();
3260 if (index < 0 || index >= length) {
3261 BoundsCheckSlowPathMIPS* slow_path =
3262 new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction);
3263 codegen_->AddSlowPath(slow_path);
3264 __ B(slow_path->GetEntryLabel());
3265 } else {
3266 // Nothing to be done.
3267 }
3268 return;
3269 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003270
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01003271 BoundsCheckSlowPathMIPS* slow_path =
3272 new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction);
3273 codegen_->AddSlowPath(slow_path);
3274 Register index = index_loc.AsRegister<Register>();
3275 if (length == 0) {
3276 __ B(slow_path->GetEntryLabel());
3277 } else if (length == 1) {
3278 __ Bnez(index, slow_path->GetEntryLabel());
3279 } else {
3280 DCHECK(IsUint<15>(length)) << length;
3281 __ Sltiu(TMP, index, length);
3282 __ Beqz(TMP, slow_path->GetEntryLabel());
3283 }
3284 } else {
3285 Register length = length_loc.AsRegister<Register>();
3286 BoundsCheckSlowPathMIPS* slow_path =
3287 new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction);
3288 codegen_->AddSlowPath(slow_path);
3289 if (index_loc.IsConstant()) {
3290 int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue();
3291 if (index < 0) {
3292 __ B(slow_path->GetEntryLabel());
3293 } else if (index == 0) {
3294 __ Blez(length, slow_path->GetEntryLabel());
3295 } else {
3296 DCHECK(IsInt<16>(index + 1)) << index;
3297 __ Sltiu(TMP, length, index + 1);
3298 __ Bnez(TMP, slow_path->GetEntryLabel());
3299 }
3300 } else {
3301 Register index = index_loc.AsRegister<Register>();
3302 __ Bgeu(index, length, slow_path->GetEntryLabel());
3303 }
3304 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003305}
3306
Alexey Frunze15958152017-02-09 19:08:30 -08003307// Temp is used for read barrier.
3308static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) {
3309 if (kEmitCompilerReadBarrier &&
Alexey Frunze4147fcc2017-06-17 19:57:27 -07003310 !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) &&
Alexey Frunze15958152017-02-09 19:08:30 -08003311 (kUseBakerReadBarrier ||
3312 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
3313 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
3314 type_check_kind == TypeCheckKind::kArrayObjectCheck)) {
3315 return 1;
3316 }
3317 return 0;
3318}
3319
3320// Extra temp is used for read barrier.
3321static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) {
3322 return 1 + NumberOfInstanceOfTemps(type_check_kind);
3323}
3324
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003325void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003326 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunzedfc30af2018-01-24 16:25:10 -08003327 LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction);
Vladimir Markoca6fff82017-10-03 14:49:14 +01003328 LocationSummary* locations =
3329 new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003330 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko175e7862018-03-27 09:03:13 +00003331 if (type_check_kind == TypeCheckKind::kBitstringCheck) {
3332 locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant()));
3333 locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant()));
3334 locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant()));
3335 } else {
3336 locations->SetInAt(1, Location::RequiresRegister());
3337 }
Alexey Frunze15958152017-02-09 19:08:30 -08003338 locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003339}
3340
3341void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003342 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003343 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08003344 Location obj_loc = locations->InAt(0);
3345 Register obj = obj_loc.AsRegister<Register>();
Vladimir Marko175e7862018-03-27 09:03:13 +00003346 Location cls = locations->InAt(1);
Alexey Frunze15958152017-02-09 19:08:30 -08003347 Location temp_loc = locations->GetTemp(0);
3348 Register temp = temp_loc.AsRegister<Register>();
3349 const size_t num_temps = NumberOfCheckCastTemps(type_check_kind);
3350 DCHECK_LE(num_temps, 2u);
3351 Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation();
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003352 const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3353 const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
3354 const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
3355 const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
3356 const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value();
3357 const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value();
3358 const uint32_t object_array_data_offset =
3359 mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value();
3360 MipsLabel done;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003361
Alexey Frunzedfc30af2018-01-24 16:25:10 -08003362 bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003363 SlowPathCodeMIPS* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01003364 new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS(
3365 instruction, is_type_check_slow_path_fatal);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003366 codegen_->AddSlowPath(slow_path);
3367
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003368 // Avoid this check if we know `obj` is not null.
3369 if (instruction->MustDoNullCheck()) {
3370 __ Beqz(obj, &done);
3371 }
3372
3373 switch (type_check_kind) {
3374 case TypeCheckKind::kExactCheck:
3375 case TypeCheckKind::kArrayCheck: {
3376 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003377 GenerateReferenceLoadTwoRegisters(instruction,
3378 temp_loc,
3379 obj_loc,
3380 class_offset,
3381 maybe_temp2_loc,
3382 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003383 // Jump to slow path for throwing the exception or doing a
3384 // more involved array check.
Vladimir Marko175e7862018-03-27 09:03:13 +00003385 __ Bne(temp, cls.AsRegister<Register>(), slow_path->GetEntryLabel());
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003386 break;
3387 }
3388
3389 case TypeCheckKind::kAbstractClassCheck: {
3390 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003391 GenerateReferenceLoadTwoRegisters(instruction,
3392 temp_loc,
3393 obj_loc,
3394 class_offset,
3395 maybe_temp2_loc,
3396 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003397 // If the class is abstract, we eagerly fetch the super class of the
3398 // object to avoid doing a comparison we know will fail.
3399 MipsLabel loop;
3400 __ Bind(&loop);
3401 // /* HeapReference<Class> */ temp = temp->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08003402 GenerateReferenceLoadOneRegister(instruction,
3403 temp_loc,
3404 super_offset,
3405 maybe_temp2_loc,
3406 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003407 // If the class reference currently in `temp` is null, jump to the slow path to throw the
3408 // exception.
3409 __ Beqz(temp, slow_path->GetEntryLabel());
3410 // Otherwise, compare the classes.
Vladimir Marko175e7862018-03-27 09:03:13 +00003411 __ Bne(temp, cls.AsRegister<Register>(), &loop);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003412 break;
3413 }
3414
3415 case TypeCheckKind::kClassHierarchyCheck: {
3416 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003417 GenerateReferenceLoadTwoRegisters(instruction,
3418 temp_loc,
3419 obj_loc,
3420 class_offset,
3421 maybe_temp2_loc,
3422 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003423 // Walk over the class hierarchy to find a match.
3424 MipsLabel loop;
3425 __ Bind(&loop);
Vladimir Marko175e7862018-03-27 09:03:13 +00003426 __ Beq(temp, cls.AsRegister<Register>(), &done);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003427 // /* HeapReference<Class> */ temp = temp->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08003428 GenerateReferenceLoadOneRegister(instruction,
3429 temp_loc,
3430 super_offset,
3431 maybe_temp2_loc,
3432 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003433 // If the class reference currently in `temp` is null, jump to the slow path to throw the
3434 // exception. Otherwise, jump to the beginning of the loop.
3435 __ Bnez(temp, &loop);
3436 __ B(slow_path->GetEntryLabel());
3437 break;
3438 }
3439
3440 case TypeCheckKind::kArrayObjectCheck: {
3441 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003442 GenerateReferenceLoadTwoRegisters(instruction,
3443 temp_loc,
3444 obj_loc,
3445 class_offset,
3446 maybe_temp2_loc,
3447 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003448 // Do an exact check.
Vladimir Marko175e7862018-03-27 09:03:13 +00003449 __ Beq(temp, cls.AsRegister<Register>(), &done);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003450 // Otherwise, we need to check that the object's class is a non-primitive array.
3451 // /* HeapReference<Class> */ temp = temp->component_type_
Alexey Frunze15958152017-02-09 19:08:30 -08003452 GenerateReferenceLoadOneRegister(instruction,
3453 temp_loc,
3454 component_offset,
3455 maybe_temp2_loc,
3456 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003457 // If the component type is null, jump to the slow path to throw the exception.
3458 __ Beqz(temp, slow_path->GetEntryLabel());
3459 // Otherwise, the object is indeed an array, further check that this component
3460 // type is not a primitive type.
3461 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
3462 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
3463 __ Bnez(temp, slow_path->GetEntryLabel());
3464 break;
3465 }
3466
3467 case TypeCheckKind::kUnresolvedCheck:
3468 // We always go into the type check slow path for the unresolved check case.
3469 // We cannot directly call the CheckCast runtime entry point
3470 // without resorting to a type checking slow path here (i.e. by
3471 // calling InvokeRuntime directly), as it would require to
3472 // assign fixed registers for the inputs of this HInstanceOf
3473 // instruction (following the runtime calling convention), which
3474 // might be cluttered by the potential first read barrier
3475 // emission at the beginning of this method.
3476 __ B(slow_path->GetEntryLabel());
3477 break;
3478
3479 case TypeCheckKind::kInterfaceCheck: {
3480 // Avoid read barriers to improve performance of the fast path. We can not get false
3481 // positives by doing this.
3482 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003483 GenerateReferenceLoadTwoRegisters(instruction,
3484 temp_loc,
3485 obj_loc,
3486 class_offset,
3487 maybe_temp2_loc,
3488 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003489 // /* HeapReference<Class> */ temp = temp->iftable_
Alexey Frunze15958152017-02-09 19:08:30 -08003490 GenerateReferenceLoadTwoRegisters(instruction,
3491 temp_loc,
3492 temp_loc,
3493 iftable_offset,
3494 maybe_temp2_loc,
3495 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003496 // Iftable is never null.
3497 __ Lw(TMP, temp, array_length_offset);
3498 // Loop through the iftable and check if any class matches.
3499 MipsLabel loop;
3500 __ Bind(&loop);
3501 __ Addiu(temp, temp, 2 * kHeapReferenceSize); // Possibly in delay slot on R2.
3502 __ Beqz(TMP, slow_path->GetEntryLabel());
3503 __ Lw(AT, temp, object_array_data_offset - 2 * kHeapReferenceSize);
3504 __ MaybeUnpoisonHeapReference(AT);
3505 // Go to next interface.
3506 __ Addiu(TMP, TMP, -2);
3507 // Compare the classes and continue the loop if they do not match.
Vladimir Marko175e7862018-03-27 09:03:13 +00003508 __ Bne(AT, cls.AsRegister<Register>(), &loop);
3509 break;
3510 }
3511
3512 case TypeCheckKind::kBitstringCheck: {
3513 // /* HeapReference<Class> */ temp = obj->klass_
3514 GenerateReferenceLoadTwoRegisters(instruction,
3515 temp_loc,
3516 obj_loc,
3517 class_offset,
3518 maybe_temp2_loc,
3519 kWithoutReadBarrier);
3520
3521 GenerateBitstringTypeCheckCompare(instruction, temp);
3522 __ Bnez(temp, slow_path->GetEntryLabel());
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003523 break;
3524 }
3525 }
3526
3527 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003528 __ Bind(slow_path->GetExitLabel());
3529}
3530
3531void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) {
3532 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003533 new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003534 locations->SetInAt(0, Location::RequiresRegister());
3535 if (check->HasUses()) {
3536 locations->SetOut(Location::SameAsFirstInput());
3537 }
3538}
3539
3540void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) {
3541 // We assume the class is not null.
Vladimir Marko174b2e22017-10-12 13:34:49 +01003542 SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS(
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003543 check->GetLoadClass(),
3544 check,
3545 check->GetDexPc(),
3546 true);
3547 codegen_->AddSlowPath(slow_path);
3548 GenerateClassInitializationCheck(slow_path,
3549 check->GetLocations()->InAt(0).AsRegister<Register>());
3550}
3551
3552void LocationsBuilderMIPS::VisitCompare(HCompare* compare) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003553 DataType::Type in_type = compare->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003554
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003555 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003556 new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003557
3558 switch (in_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003559 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003560 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003561 case DataType::Type::kInt8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003562 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003563 case DataType::Type::kInt16:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003564 case DataType::Type::kInt32:
Alexey Frunzee7697712016-09-15 21:37:49 -07003565 locations->SetInAt(0, Location::RequiresRegister());
3566 locations->SetInAt(1, Location::RequiresRegister());
3567 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3568 break;
3569
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003570 case DataType::Type::kInt64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003571 locations->SetInAt(0, Location::RequiresRegister());
3572 locations->SetInAt(1, Location::RequiresRegister());
3573 // Output overlaps because it is written before doing the low comparison.
3574 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3575 break;
3576
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003577 case DataType::Type::kFloat32:
3578 case DataType::Type::kFloat64:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003579 locations->SetInAt(0, Location::RequiresFpuRegister());
3580 locations->SetInAt(1, Location::RequiresFpuRegister());
3581 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003582 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003583
3584 default:
3585 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
3586 }
3587}
3588
3589void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) {
3590 LocationSummary* locations = instruction->GetLocations();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003591 Register res = locations->Out().AsRegister<Register>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003592 DataType::Type in_type = instruction->InputAt(0)->GetType();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003593 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003594
3595 // 0 if: left == right
3596 // 1 if: left > right
3597 // -1 if: left < right
3598 switch (in_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003599 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003600 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003601 case DataType::Type::kInt8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003602 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003603 case DataType::Type::kInt16:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003604 case DataType::Type::kInt32: {
Aart Bika19616e2016-02-01 18:57:58 -08003605 Register lhs = locations->InAt(0).AsRegister<Register>();
3606 Register rhs = locations->InAt(1).AsRegister<Register>();
3607 __ Slt(TMP, lhs, rhs);
3608 __ Slt(res, rhs, lhs);
3609 __ Subu(res, res, TMP);
3610 break;
3611 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003612 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003613 MipsLabel done;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003614 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
3615 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
3616 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
3617 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
3618 // TODO: more efficient (direct) comparison with a constant.
3619 __ Slt(TMP, lhs_high, rhs_high);
3620 __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt.
3621 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
3622 __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal.
3623 __ Sltu(TMP, lhs_low, rhs_low);
3624 __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt.
3625 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
3626 __ Bind(&done);
3627 break;
3628 }
3629
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003630 case DataType::Type::kFloat32: {
Roland Levillain32ca3752016-02-17 16:49:37 +00003631 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003632 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3633 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3634 MipsLabel done;
3635 if (isR6) {
3636 __ CmpEqS(FTMP, lhs, rhs);
3637 __ LoadConst32(res, 0);
3638 __ Bc1nez(FTMP, &done);
3639 if (gt_bias) {
3640 __ CmpLtS(FTMP, lhs, rhs);
3641 __ LoadConst32(res, -1);
3642 __ Bc1nez(FTMP, &done);
3643 __ LoadConst32(res, 1);
3644 } else {
3645 __ CmpLtS(FTMP, rhs, lhs);
3646 __ LoadConst32(res, 1);
3647 __ Bc1nez(FTMP, &done);
3648 __ LoadConst32(res, -1);
3649 }
3650 } else {
3651 if (gt_bias) {
3652 __ ColtS(0, lhs, rhs);
3653 __ LoadConst32(res, -1);
3654 __ Bc1t(0, &done);
3655 __ CeqS(0, lhs, rhs);
3656 __ LoadConst32(res, 1);
3657 __ Movt(res, ZERO, 0);
3658 } else {
3659 __ ColtS(0, rhs, lhs);
3660 __ LoadConst32(res, 1);
3661 __ Bc1t(0, &done);
3662 __ CeqS(0, lhs, rhs);
3663 __ LoadConst32(res, -1);
3664 __ Movt(res, ZERO, 0);
3665 }
3666 }
3667 __ Bind(&done);
3668 break;
3669 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003670 case DataType::Type::kFloat64: {
Roland Levillain32ca3752016-02-17 16:49:37 +00003671 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003672 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3673 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3674 MipsLabel done;
3675 if (isR6) {
3676 __ CmpEqD(FTMP, lhs, rhs);
3677 __ LoadConst32(res, 0);
3678 __ Bc1nez(FTMP, &done);
3679 if (gt_bias) {
3680 __ CmpLtD(FTMP, lhs, rhs);
3681 __ LoadConst32(res, -1);
3682 __ Bc1nez(FTMP, &done);
3683 __ LoadConst32(res, 1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003684 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003685 __ CmpLtD(FTMP, rhs, lhs);
3686 __ LoadConst32(res, 1);
3687 __ Bc1nez(FTMP, &done);
3688 __ LoadConst32(res, -1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003689 }
3690 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003691 if (gt_bias) {
3692 __ ColtD(0, lhs, rhs);
3693 __ LoadConst32(res, -1);
3694 __ Bc1t(0, &done);
3695 __ CeqD(0, lhs, rhs);
3696 __ LoadConst32(res, 1);
3697 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003698 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003699 __ ColtD(0, rhs, lhs);
3700 __ LoadConst32(res, 1);
3701 __ Bc1t(0, &done);
3702 __ CeqD(0, lhs, rhs);
3703 __ LoadConst32(res, -1);
3704 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003705 }
3706 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003707 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003708 break;
3709 }
3710
3711 default:
3712 LOG(FATAL) << "Unimplemented compare type " << in_type;
3713 }
3714}
3715
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00003716void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01003717 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003718 switch (instruction->InputAt(0)->GetType()) {
3719 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003720 case DataType::Type::kInt64:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003721 locations->SetInAt(0, Location::RequiresRegister());
3722 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3723 break;
3724
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003725 case DataType::Type::kFloat32:
3726 case DataType::Type::kFloat64:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003727 locations->SetInAt(0, Location::RequiresFpuRegister());
3728 locations->SetInAt(1, Location::RequiresFpuRegister());
3729 break;
3730 }
David Brazdilb3e773e2016-01-26 11:28:37 +00003731 if (!instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003732 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3733 }
3734}
3735
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00003736void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00003737 if (instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003738 return;
3739 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003740
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003741 DataType::Type type = instruction->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003742 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003743
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003744 switch (type) {
3745 default:
3746 // Integer case.
3747 GenerateIntCompare(instruction->GetCondition(), locations);
3748 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003749
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003750 case DataType::Type::kInt64:
Tijana Jakovljevic6d482aa2017-02-03 13:24:08 +01003751 GenerateLongCompare(instruction->GetCondition(), locations);
3752 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003753
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003754 case DataType::Type::kFloat32:
3755 case DataType::Type::kFloat64:
Alexey Frunze2ddb7172016-09-06 17:04:55 -07003756 GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations);
3757 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003758 }
3759}
3760
Alexey Frunze7e99e052015-11-24 19:28:01 -08003761void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
3762 DCHECK(instruction->IsDiv() || instruction->IsRem());
Alexey Frunze7e99e052015-11-24 19:28:01 -08003763
3764 LocationSummary* locations = instruction->GetLocations();
3765 Location second = locations->InAt(1);
3766 DCHECK(second.IsConstant());
Lena Djokic4b8025c2017-12-21 16:15:50 +01003767 int64_t imm = Int64FromConstant(second.GetConstant());
Alexey Frunze7e99e052015-11-24 19:28:01 -08003768 DCHECK(imm == 1 || imm == -1);
3769
Lena Djokic4b8025c2017-12-21 16:15:50 +01003770 if (instruction->GetResultType() == DataType::Type::kInt32) {
3771 Register out = locations->Out().AsRegister<Register>();
3772 Register dividend = locations->InAt(0).AsRegister<Register>();
3773
3774 if (instruction->IsRem()) {
3775 __ Move(out, ZERO);
3776 } else {
3777 if (imm == -1) {
3778 __ Subu(out, ZERO, dividend);
3779 } else if (out != dividend) {
3780 __ Move(out, dividend);
3781 }
3782 }
Alexey Frunze7e99e052015-11-24 19:28:01 -08003783 } else {
Lena Djokic4b8025c2017-12-21 16:15:50 +01003784 DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64);
3785 Register out_high = locations->Out().AsRegisterPairHigh<Register>();
3786 Register out_low = locations->Out().AsRegisterPairLow<Register>();
3787 Register in_high = locations->InAt(0).AsRegisterPairHigh<Register>();
3788 Register in_low = locations->InAt(0).AsRegisterPairLow<Register>();
3789
3790 if (instruction->IsRem()) {
3791 __ Move(out_high, ZERO);
3792 __ Move(out_low, ZERO);
3793 } else {
3794 if (imm == -1) {
3795 __ Subu(out_low, ZERO, in_low);
3796 __ Sltu(AT, ZERO, out_low);
3797 __ Subu(out_high, ZERO, in_high);
3798 __ Subu(out_high, out_high, AT);
3799 } else {
3800 __ Move(out_low, in_low);
3801 __ Move(out_high, in_high);
3802 }
Alexey Frunze7e99e052015-11-24 19:28:01 -08003803 }
3804 }
3805}
3806
3807void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
3808 DCHECK(instruction->IsDiv() || instruction->IsRem());
Alexey Frunze7e99e052015-11-24 19:28:01 -08003809
3810 LocationSummary* locations = instruction->GetLocations();
3811 Location second = locations->InAt(1);
Lena Djokic4b8025c2017-12-21 16:15:50 +01003812 const bool is_r2_or_newer = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
3813 const bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6();
Alexey Frunze7e99e052015-11-24 19:28:01 -08003814 DCHECK(second.IsConstant());
3815
Lena Djokic4b8025c2017-12-21 16:15:50 +01003816 if (instruction->GetResultType() == DataType::Type::kInt32) {
3817 Register out = locations->Out().AsRegister<Register>();
3818 Register dividend = locations->InAt(0).AsRegister<Register>();
3819 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
3820 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
3821 int ctz_imm = CTZ(abs_imm);
Alexey Frunze7e99e052015-11-24 19:28:01 -08003822
Lena Djokic4b8025c2017-12-21 16:15:50 +01003823 if (instruction->IsDiv()) {
3824 if (ctz_imm == 1) {
3825 // Fast path for division by +/-2, which is very common.
3826 __ Srl(TMP, dividend, 31);
3827 } else {
3828 __ Sra(TMP, dividend, 31);
3829 __ Srl(TMP, TMP, 32 - ctz_imm);
3830 }
3831 __ Addu(out, dividend, TMP);
3832 __ Sra(out, out, ctz_imm);
3833 if (imm < 0) {
3834 __ Subu(out, ZERO, out);
3835 }
Alexey Frunze7e99e052015-11-24 19:28:01 -08003836 } else {
Lena Djokic4b8025c2017-12-21 16:15:50 +01003837 if (ctz_imm == 1) {
3838 // Fast path for modulo +/-2, which is very common.
3839 __ Sra(TMP, dividend, 31);
3840 __ Subu(out, dividend, TMP);
3841 __ Andi(out, out, 1);
3842 __ Addu(out, out, TMP);
3843 } else {
3844 __ Sra(TMP, dividend, 31);
3845 __ Srl(TMP, TMP, 32 - ctz_imm);
3846 __ Addu(out, dividend, TMP);
3847 if (IsUint<16>(abs_imm - 1)) {
3848 __ Andi(out, out, abs_imm - 1);
3849 } else {
3850 if (is_r2_or_newer) {
3851 __ Ins(out, ZERO, ctz_imm, 32 - ctz_imm);
3852 } else {
3853 __ Sll(out, out, 32 - ctz_imm);
3854 __ Srl(out, out, 32 - ctz_imm);
3855 }
3856 }
3857 __ Subu(out, out, TMP);
3858 }
Alexey Frunze7e99e052015-11-24 19:28:01 -08003859 }
3860 } else {
Lena Djokic4b8025c2017-12-21 16:15:50 +01003861 DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64);
3862 Register out_high = locations->Out().AsRegisterPairHigh<Register>();
3863 Register out_low = locations->Out().AsRegisterPairLow<Register>();
3864 Register in_high = locations->InAt(0).AsRegisterPairHigh<Register>();
3865 Register in_low = locations->InAt(0).AsRegisterPairLow<Register>();
3866 int64_t imm = Int64FromConstant(second.GetConstant());
3867 uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm));
3868 int ctz_imm = CTZ(abs_imm);
3869
3870 if (instruction->IsDiv()) {
3871 if (ctz_imm < 32) {
3872 if (ctz_imm == 1) {
3873 __ Srl(AT, in_high, 31);
Lena Djokica556e6b2017-12-13 12:09:42 +01003874 } else {
Lena Djokic4b8025c2017-12-21 16:15:50 +01003875 __ Sra(AT, in_high, 31);
3876 __ Srl(AT, AT, 32 - ctz_imm);
Lena Djokica556e6b2017-12-13 12:09:42 +01003877 }
Lena Djokic4b8025c2017-12-21 16:15:50 +01003878 __ Addu(AT, AT, in_low);
3879 __ Sltu(TMP, AT, in_low);
3880 __ Addu(out_high, in_high, TMP);
3881 __ Srl(out_low, AT, ctz_imm);
3882 if (is_r2_or_newer) {
3883 __ Ins(out_low, out_high, 32 - ctz_imm, ctz_imm);
3884 __ Sra(out_high, out_high, ctz_imm);
3885 } else {
3886 __ Sll(AT, out_high, 32 - ctz_imm);
3887 __ Sra(out_high, out_high, ctz_imm);
3888 __ Or(out_low, out_low, AT);
3889 }
3890 if (imm < 0) {
3891 __ Subu(out_low, ZERO, out_low);
3892 __ Sltu(AT, ZERO, out_low);
3893 __ Subu(out_high, ZERO, out_high);
3894 __ Subu(out_high, out_high, AT);
3895 }
3896 } else if (ctz_imm == 32) {
3897 __ Sra(AT, in_high, 31);
3898 __ Addu(AT, AT, in_low);
3899 __ Sltu(AT, AT, in_low);
3900 __ Addu(out_low, in_high, AT);
3901 if (imm < 0) {
3902 __ Srl(TMP, out_low, 31);
3903 __ Subu(out_low, ZERO, out_low);
3904 __ Sltu(AT, ZERO, out_low);
3905 __ Subu(out_high, TMP, AT);
3906 } else {
3907 __ Sra(out_high, out_low, 31);
3908 }
3909 } else if (ctz_imm < 63) {
3910 __ Sra(AT, in_high, 31);
3911 __ Srl(TMP, AT, 64 - ctz_imm);
3912 __ Addu(AT, AT, in_low);
3913 __ Sltu(AT, AT, in_low);
3914 __ Addu(out_low, in_high, AT);
3915 __ Addu(out_low, out_low, TMP);
3916 __ Sra(out_low, out_low, ctz_imm - 32);
3917 if (imm < 0) {
3918 __ Subu(out_low, ZERO, out_low);
3919 }
3920 __ Sra(out_high, out_low, 31);
3921 } else {
3922 DCHECK_LT(imm, 0);
3923 if (is_r6) {
3924 __ Aui(AT, in_high, 0x8000);
3925 } else {
3926 __ Lui(AT, 0x8000);
3927 __ Xor(AT, AT, in_high);
3928 }
3929 __ Or(AT, AT, in_low);
3930 __ Sltiu(out_low, AT, 1);
3931 __ Move(out_high, ZERO);
Alexey Frunze7e99e052015-11-24 19:28:01 -08003932 }
Lena Djokic4b8025c2017-12-21 16:15:50 +01003933 } else {
3934 if ((ctz_imm == 1) && !is_r6) {
3935 __ Andi(AT, in_low, 1);
3936 __ Sll(TMP, in_low, 31);
3937 __ And(TMP, in_high, TMP);
3938 __ Sra(out_high, TMP, 31);
3939 __ Or(out_low, out_high, AT);
3940 } else if (ctz_imm < 32) {
3941 __ Sra(AT, in_high, 31);
3942 if (ctz_imm <= 16) {
3943 __ Andi(out_low, in_low, abs_imm - 1);
3944 } else if (is_r2_or_newer) {
3945 __ Ext(out_low, in_low, 0, ctz_imm);
3946 } else {
3947 __ Sll(out_low, in_low, 32 - ctz_imm);
3948 __ Srl(out_low, out_low, 32 - ctz_imm);
3949 }
3950 if (is_r6) {
3951 __ Selnez(out_high, AT, out_low);
3952 } else {
3953 __ Movz(AT, ZERO, out_low);
3954 __ Move(out_high, AT);
3955 }
3956 if (is_r2_or_newer) {
3957 __ Ins(out_low, out_high, ctz_imm, 32 - ctz_imm);
3958 } else {
3959 __ Sll(AT, out_high, ctz_imm);
3960 __ Or(out_low, out_low, AT);
3961 }
3962 } else if (ctz_imm == 32) {
3963 __ Sra(AT, in_high, 31);
3964 __ Move(out_low, in_low);
3965 if (is_r6) {
3966 __ Selnez(out_high, AT, out_low);
3967 } else {
3968 __ Movz(AT, ZERO, out_low);
3969 __ Move(out_high, AT);
3970 }
3971 } else if (ctz_imm < 63) {
3972 __ Sra(AT, in_high, 31);
3973 __ Move(TMP, in_low);
3974 if (ctz_imm - 32 <= 16) {
3975 __ Andi(out_high, in_high, (1 << (ctz_imm - 32)) - 1);
3976 } else if (is_r2_or_newer) {
3977 __ Ext(out_high, in_high, 0, ctz_imm - 32);
3978 } else {
3979 __ Sll(out_high, in_high, 64 - ctz_imm);
3980 __ Srl(out_high, out_high, 64 - ctz_imm);
3981 }
3982 __ Move(out_low, TMP);
3983 __ Or(TMP, TMP, out_high);
3984 if (is_r6) {
3985 __ Selnez(AT, AT, TMP);
3986 } else {
3987 __ Movz(AT, ZERO, TMP);
3988 }
3989 if (is_r2_or_newer) {
3990 __ Ins(out_high, AT, ctz_imm - 32, 64 - ctz_imm);
3991 } else {
3992 __ Sll(AT, AT, ctz_imm - 32);
3993 __ Or(out_high, out_high, AT);
3994 }
3995 } else {
3996 if (is_r6) {
3997 __ Aui(AT, in_high, 0x8000);
3998 } else {
3999 __ Lui(AT, 0x8000);
4000 __ Xor(AT, AT, in_high);
4001 }
4002 __ Or(AT, AT, in_low);
4003 __ Sltiu(AT, AT, 1);
4004 __ Sll(AT, AT, 31);
4005 __ Move(out_low, in_low);
4006 __ Xor(out_high, in_high, AT);
4007 }
Alexey Frunze7e99e052015-11-24 19:28:01 -08004008 }
4009 }
4010}
4011
4012void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
4013 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004014 DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32);
Alexey Frunze7e99e052015-11-24 19:28:01 -08004015
4016 LocationSummary* locations = instruction->GetLocations();
4017 Location second = locations->InAt(1);
4018 DCHECK(second.IsConstant());
4019
4020 Register out = locations->Out().AsRegister<Register>();
4021 Register dividend = locations->InAt(0).AsRegister<Register>();
4022 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
4023
4024 int64_t magic;
4025 int shift;
4026 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
4027
4028 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4029
4030 __ LoadConst32(TMP, magic);
4031 if (isR6) {
4032 __ MuhR6(TMP, dividend, TMP);
4033 } else {
4034 __ MultR2(dividend, TMP);
4035 __ Mfhi(TMP);
4036 }
4037 if (imm > 0 && magic < 0) {
4038 __ Addu(TMP, TMP, dividend);
4039 } else if (imm < 0 && magic > 0) {
4040 __ Subu(TMP, TMP, dividend);
4041 }
4042
4043 if (shift != 0) {
4044 __ Sra(TMP, TMP, shift);
4045 }
4046
4047 if (instruction->IsDiv()) {
4048 __ Sra(out, TMP, 31);
4049 __ Subu(out, TMP, out);
4050 } else {
4051 __ Sra(AT, TMP, 31);
4052 __ Subu(AT, TMP, AT);
4053 __ LoadConst32(TMP, imm);
4054 if (isR6) {
4055 __ MulR6(TMP, AT, TMP);
4056 } else {
4057 __ MulR2(TMP, AT, TMP);
4058 }
4059 __ Subu(out, dividend, TMP);
4060 }
4061}
4062
4063void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) {
4064 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004065 DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32);
Alexey Frunze7e99e052015-11-24 19:28:01 -08004066
4067 LocationSummary* locations = instruction->GetLocations();
4068 Register out = locations->Out().AsRegister<Register>();
4069 Location second = locations->InAt(1);
4070
4071 if (second.IsConstant()) {
4072 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
4073 if (imm == 0) {
4074 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
4075 } else if (imm == 1 || imm == -1) {
4076 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00004077 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08004078 DivRemByPowerOfTwo(instruction);
4079 } else {
4080 DCHECK(imm <= -2 || imm >= 2);
4081 GenerateDivRemWithAnyConstant(instruction);
4082 }
4083 } else {
4084 Register dividend = locations->InAt(0).AsRegister<Register>();
4085 Register divisor = second.AsRegister<Register>();
4086 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4087 if (instruction->IsDiv()) {
4088 if (isR6) {
4089 __ DivR6(out, dividend, divisor);
4090 } else {
4091 __ DivR2(out, dividend, divisor);
4092 }
4093 } else {
4094 if (isR6) {
4095 __ ModR6(out, dividend, divisor);
4096 } else {
4097 __ ModR2(out, dividend, divisor);
4098 }
4099 }
4100 }
4101}
4102
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004103void LocationsBuilderMIPS::VisitDiv(HDiv* div) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004104 DataType::Type type = div->GetResultType();
Lena Djokic4b8025c2017-12-21 16:15:50 +01004105 bool call_long_div = false;
4106 if (type == DataType::Type::kInt64) {
4107 if (div->InputAt(1)->IsConstant()) {
4108 int64_t imm = CodeGenerator::GetInt64ValueOf(div->InputAt(1)->AsConstant());
4109 call_long_div = (imm != 0) && !IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm)));
4110 } else {
4111 call_long_div = true;
4112 }
4113 }
4114 LocationSummary::CallKind call_kind = call_long_div
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004115 ? LocationSummary::kCallOnMainOnly
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004116 : LocationSummary::kNoCall;
4117
Vladimir Markoca6fff82017-10-03 14:49:14 +01004118 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004119
4120 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004121 case DataType::Type::kInt32:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004122 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08004123 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004124 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4125 break;
4126
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004127 case DataType::Type::kInt64: {
Lena Djokic4b8025c2017-12-21 16:15:50 +01004128 if (call_long_div) {
4129 InvokeRuntimeCallingConvention calling_convention;
4130 locations->SetInAt(0, Location::RegisterPairLocation(
4131 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
4132 locations->SetInAt(1, Location::RegisterPairLocation(
4133 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
4134 locations->SetOut(calling_convention.GetReturnLocation(type));
4135 } else {
4136 locations->SetInAt(0, Location::RequiresRegister());
4137 locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant()));
4138 locations->SetOut(Location::RequiresRegister());
4139 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004140 break;
4141 }
4142
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004143 case DataType::Type::kFloat32:
4144 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004145 locations->SetInAt(0, Location::RequiresFpuRegister());
4146 locations->SetInAt(1, Location::RequiresFpuRegister());
4147 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4148 break;
4149
4150 default:
4151 LOG(FATAL) << "Unexpected div type " << type;
4152 }
4153}
4154
4155void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004156 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004157 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004158
4159 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004160 case DataType::Type::kInt32:
Alexey Frunze7e99e052015-11-24 19:28:01 -08004161 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004162 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004163 case DataType::Type::kInt64: {
Lena Djokic4b8025c2017-12-21 16:15:50 +01004164 if (locations->InAt(1).IsConstant()) {
4165 int64_t imm = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue();
4166 if (imm == 0) {
4167 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
4168 } else if (imm == 1 || imm == -1) {
4169 DivRemOneOrMinusOne(instruction);
4170 } else {
4171 DCHECK(IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm))));
4172 DivRemByPowerOfTwo(instruction);
4173 }
4174 } else {
4175 codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc());
4176 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
4177 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004178 break;
4179 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004180 case DataType::Type::kFloat32:
4181 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004182 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4183 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
4184 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004185 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004186 __ DivS(dst, lhs, rhs);
4187 } else {
4188 __ DivD(dst, lhs, rhs);
4189 }
4190 break;
4191 }
4192 default:
4193 LOG(FATAL) << "Unexpected div type " << type;
4194 }
4195}
4196
4197void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01004198 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004199 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004200}
4201
4202void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004203 SlowPathCodeMIPS* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01004204 new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004205 codegen_->AddSlowPath(slow_path);
4206 Location value = instruction->GetLocations()->InAt(0);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004207 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004208
4209 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004210 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01004211 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004212 case DataType::Type::kInt8:
4213 case DataType::Type::kUint16:
4214 case DataType::Type::kInt16:
4215 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004216 if (value.IsConstant()) {
4217 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
4218 __ B(slow_path->GetEntryLabel());
4219 } else {
4220 // A division by a non-null constant is valid. We don't need to perform
4221 // any check, so simply fall through.
4222 }
4223 } else {
4224 DCHECK(value.IsRegister()) << value;
4225 __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel());
4226 }
4227 break;
4228 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004229 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004230 if (value.IsConstant()) {
4231 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
4232 __ B(slow_path->GetEntryLabel());
4233 } else {
4234 // A division by a non-null constant is valid. We don't need to perform
4235 // any check, so simply fall through.
4236 }
4237 } else {
4238 DCHECK(value.IsRegisterPair()) << value;
4239 __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>());
4240 __ Beqz(TMP, slow_path->GetEntryLabel());
4241 }
4242 break;
4243 }
4244 default:
4245 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
4246 }
4247}
4248
4249void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) {
4250 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01004251 new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004252 locations->SetOut(Location::ConstantLocation(constant));
4253}
4254
4255void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
4256 // Will be generated at use site.
4257}
4258
4259void LocationsBuilderMIPS::VisitExit(HExit* exit) {
4260 exit->SetLocations(nullptr);
4261}
4262
4263void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
4264}
4265
4266void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) {
4267 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01004268 new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004269 locations->SetOut(Location::ConstantLocation(constant));
4270}
4271
4272void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
4273 // Will be generated at use site.
4274}
4275
4276void LocationsBuilderMIPS::VisitGoto(HGoto* got) {
4277 got->SetLocations(nullptr);
4278}
4279
4280void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Aart Bika8b8e9b2018-01-09 11:01:02 -08004281 if (successor->IsExitBlock()) {
4282 DCHECK(got->GetPrevious()->AlwaysThrows());
4283 return; // no code needed
4284 }
4285
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004286 HBasicBlock* block = got->GetBlock();
4287 HInstruction* previous = got->GetPrevious();
4288 HLoopInformation* info = block->GetLoopInformation();
4289
4290 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Goran Jakovljevicfeec1672018-02-08 10:20:14 +01004291 if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) {
4292 __ Lw(AT, SP, kCurrentMethodStackOffset);
4293 __ Lhu(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value());
4294 __ Addiu(TMP, TMP, 1);
4295 __ Sh(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value());
4296 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004297 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
4298 return;
4299 }
4300 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
4301 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
4302 }
4303 if (!codegen_->GoesToNextBlock(block, successor)) {
4304 __ B(codegen_->GetLabelOf(successor));
4305 }
4306}
4307
4308void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) {
4309 HandleGoto(got, got->GetSuccessor());
4310}
4311
4312void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
4313 try_boundary->SetLocations(nullptr);
4314}
4315
4316void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
4317 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
4318 if (!successor->IsExitBlock()) {
4319 HandleGoto(try_boundary, successor);
4320 }
4321}
4322
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004323void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond,
4324 LocationSummary* locations) {
4325 Register dst = locations->Out().AsRegister<Register>();
4326 Register lhs = locations->InAt(0).AsRegister<Register>();
4327 Location rhs_location = locations->InAt(1);
4328 Register rhs_reg = ZERO;
4329 int64_t rhs_imm = 0;
4330 bool use_imm = rhs_location.IsConstant();
4331 if (use_imm) {
4332 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
4333 } else {
4334 rhs_reg = rhs_location.AsRegister<Register>();
4335 }
4336
4337 switch (cond) {
4338 case kCondEQ:
4339 case kCondNE:
Alexey Frunzee7697712016-09-15 21:37:49 -07004340 if (use_imm && IsInt<16>(-rhs_imm)) {
4341 if (rhs_imm == 0) {
4342 if (cond == kCondEQ) {
4343 __ Sltiu(dst, lhs, 1);
4344 } else {
4345 __ Sltu(dst, ZERO, lhs);
4346 }
4347 } else {
4348 __ Addiu(dst, lhs, -rhs_imm);
4349 if (cond == kCondEQ) {
4350 __ Sltiu(dst, dst, 1);
4351 } else {
4352 __ Sltu(dst, ZERO, dst);
4353 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004354 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004355 } else {
Alexey Frunzee7697712016-09-15 21:37:49 -07004356 if (use_imm && IsUint<16>(rhs_imm)) {
4357 __ Xori(dst, lhs, rhs_imm);
4358 } else {
4359 if (use_imm) {
4360 rhs_reg = TMP;
4361 __ LoadConst32(rhs_reg, rhs_imm);
4362 }
4363 __ Xor(dst, lhs, rhs_reg);
4364 }
4365 if (cond == kCondEQ) {
4366 __ Sltiu(dst, dst, 1);
4367 } else {
4368 __ Sltu(dst, ZERO, dst);
4369 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004370 }
4371 break;
4372
4373 case kCondLT:
4374 case kCondGE:
4375 if (use_imm && IsInt<16>(rhs_imm)) {
4376 __ Slti(dst, lhs, rhs_imm);
4377 } else {
4378 if (use_imm) {
4379 rhs_reg = TMP;
4380 __ LoadConst32(rhs_reg, rhs_imm);
4381 }
4382 __ Slt(dst, lhs, rhs_reg);
4383 }
4384 if (cond == kCondGE) {
4385 // Simulate lhs >= rhs via !(lhs < rhs) since there's
4386 // only the slt instruction but no sge.
4387 __ Xori(dst, dst, 1);
4388 }
4389 break;
4390
4391 case kCondLE:
4392 case kCondGT:
4393 if (use_imm && IsInt<16>(rhs_imm + 1)) {
4394 // Simulate lhs <= rhs via lhs < rhs + 1.
4395 __ Slti(dst, lhs, rhs_imm + 1);
4396 if (cond == kCondGT) {
4397 // Simulate lhs > rhs via !(lhs <= rhs) since there's
4398 // only the slti instruction but no sgti.
4399 __ Xori(dst, dst, 1);
4400 }
4401 } else {
4402 if (use_imm) {
4403 rhs_reg = TMP;
4404 __ LoadConst32(rhs_reg, rhs_imm);
4405 }
4406 __ Slt(dst, rhs_reg, lhs);
4407 if (cond == kCondLE) {
4408 // Simulate lhs <= rhs via !(rhs < lhs) since there's
4409 // only the slt instruction but no sle.
4410 __ Xori(dst, dst, 1);
4411 }
4412 }
4413 break;
4414
4415 case kCondB:
4416 case kCondAE:
4417 if (use_imm && IsInt<16>(rhs_imm)) {
4418 // Sltiu sign-extends its 16-bit immediate operand before
4419 // the comparison and thus lets us compare directly with
4420 // unsigned values in the ranges [0, 0x7fff] and
4421 // [0xffff8000, 0xffffffff].
4422 __ Sltiu(dst, lhs, rhs_imm);
4423 } else {
4424 if (use_imm) {
4425 rhs_reg = TMP;
4426 __ LoadConst32(rhs_reg, rhs_imm);
4427 }
4428 __ Sltu(dst, lhs, rhs_reg);
4429 }
4430 if (cond == kCondAE) {
4431 // Simulate lhs >= rhs via !(lhs < rhs) since there's
4432 // only the sltu instruction but no sgeu.
4433 __ Xori(dst, dst, 1);
4434 }
4435 break;
4436
4437 case kCondBE:
4438 case kCondA:
4439 if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
4440 // Simulate lhs <= rhs via lhs < rhs + 1.
4441 // Note that this only works if rhs + 1 does not overflow
4442 // to 0, hence the check above.
4443 // Sltiu sign-extends its 16-bit immediate operand before
4444 // the comparison and thus lets us compare directly with
4445 // unsigned values in the ranges [0, 0x7fff] and
4446 // [0xffff8000, 0xffffffff].
4447 __ Sltiu(dst, lhs, rhs_imm + 1);
4448 if (cond == kCondA) {
4449 // Simulate lhs > rhs via !(lhs <= rhs) since there's
4450 // only the sltiu instruction but no sgtiu.
4451 __ Xori(dst, dst, 1);
4452 }
4453 } else {
4454 if (use_imm) {
4455 rhs_reg = TMP;
4456 __ LoadConst32(rhs_reg, rhs_imm);
4457 }
4458 __ Sltu(dst, rhs_reg, lhs);
4459 if (cond == kCondBE) {
4460 // Simulate lhs <= rhs via !(rhs < lhs) since there's
4461 // only the sltu instruction but no sleu.
4462 __ Xori(dst, dst, 1);
4463 }
4464 }
4465 break;
4466 }
4467}
4468
Alexey Frunze674b9ee2016-09-20 14:54:15 -07004469bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond,
4470 LocationSummary* input_locations,
4471 Register dst) {
4472 Register lhs = input_locations->InAt(0).AsRegister<Register>();
4473 Location rhs_location = input_locations->InAt(1);
4474 Register rhs_reg = ZERO;
4475 int64_t rhs_imm = 0;
4476 bool use_imm = rhs_location.IsConstant();
4477 if (use_imm) {
4478 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
4479 } else {
4480 rhs_reg = rhs_location.AsRegister<Register>();
4481 }
4482
4483 switch (cond) {
4484 case kCondEQ:
4485 case kCondNE:
4486 if (use_imm && IsInt<16>(-rhs_imm)) {
4487 __ Addiu(dst, lhs, -rhs_imm);
4488 } else if (use_imm && IsUint<16>(rhs_imm)) {
4489 __ Xori(dst, lhs, rhs_imm);
4490 } else {
4491 if (use_imm) {
4492 rhs_reg = TMP;
4493 __ LoadConst32(rhs_reg, rhs_imm);
4494 }
4495 __ Xor(dst, lhs, rhs_reg);
4496 }
4497 return (cond == kCondEQ);
4498
4499 case kCondLT:
4500 case kCondGE:
4501 if (use_imm && IsInt<16>(rhs_imm)) {
4502 __ Slti(dst, lhs, rhs_imm);
4503 } else {
4504 if (use_imm) {
4505 rhs_reg = TMP;
4506 __ LoadConst32(rhs_reg, rhs_imm);
4507 }
4508 __ Slt(dst, lhs, rhs_reg);
4509 }
4510 return (cond == kCondGE);
4511
4512 case kCondLE:
4513 case kCondGT:
4514 if (use_imm && IsInt<16>(rhs_imm + 1)) {
4515 // Simulate lhs <= rhs via lhs < rhs + 1.
4516 __ Slti(dst, lhs, rhs_imm + 1);
4517 return (cond == kCondGT);
4518 } else {
4519 if (use_imm) {
4520 rhs_reg = TMP;
4521 __ LoadConst32(rhs_reg, rhs_imm);
4522 }
4523 __ Slt(dst, rhs_reg, lhs);
4524 return (cond == kCondLE);
4525 }
4526
4527 case kCondB:
4528 case kCondAE:
4529 if (use_imm && IsInt<16>(rhs_imm)) {
4530 // Sltiu sign-extends its 16-bit immediate operand before
4531 // the comparison and thus lets us compare directly with
4532 // unsigned values in the ranges [0, 0x7fff] and
4533 // [0xffff8000, 0xffffffff].
4534 __ Sltiu(dst, lhs, rhs_imm);
4535 } else {
4536 if (use_imm) {
4537 rhs_reg = TMP;
4538 __ LoadConst32(rhs_reg, rhs_imm);
4539 }
4540 __ Sltu(dst, lhs, rhs_reg);
4541 }
4542 return (cond == kCondAE);
4543
4544 case kCondBE:
4545 case kCondA:
4546 if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
4547 // Simulate lhs <= rhs via lhs < rhs + 1.
4548 // Note that this only works if rhs + 1 does not overflow
4549 // to 0, hence the check above.
4550 // Sltiu sign-extends its 16-bit immediate operand before
4551 // the comparison and thus lets us compare directly with
4552 // unsigned values in the ranges [0, 0x7fff] and
4553 // [0xffff8000, 0xffffffff].
4554 __ Sltiu(dst, lhs, rhs_imm + 1);
4555 return (cond == kCondA);
4556 } else {
4557 if (use_imm) {
4558 rhs_reg = TMP;
4559 __ LoadConst32(rhs_reg, rhs_imm);
4560 }
4561 __ Sltu(dst, rhs_reg, lhs);
4562 return (cond == kCondBE);
4563 }
4564 }
4565}
4566
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004567void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond,
4568 LocationSummary* locations,
4569 MipsLabel* label) {
4570 Register lhs = locations->InAt(0).AsRegister<Register>();
4571 Location rhs_location = locations->InAt(1);
4572 Register rhs_reg = ZERO;
Alexey Frunzee7697712016-09-15 21:37:49 -07004573 int64_t rhs_imm = 0;
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004574 bool use_imm = rhs_location.IsConstant();
4575 if (use_imm) {
4576 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
4577 } else {
4578 rhs_reg = rhs_location.AsRegister<Register>();
4579 }
4580
4581 if (use_imm && rhs_imm == 0) {
4582 switch (cond) {
4583 case kCondEQ:
4584 case kCondBE: // <= 0 if zero
4585 __ Beqz(lhs, label);
4586 break;
4587 case kCondNE:
4588 case kCondA: // > 0 if non-zero
4589 __ Bnez(lhs, label);
4590 break;
4591 case kCondLT:
4592 __ Bltz(lhs, label);
4593 break;
4594 case kCondGE:
4595 __ Bgez(lhs, label);
4596 break;
4597 case kCondLE:
4598 __ Blez(lhs, label);
4599 break;
4600 case kCondGT:
4601 __ Bgtz(lhs, label);
4602 break;
4603 case kCondB: // always false
4604 break;
4605 case kCondAE: // always true
4606 __ B(label);
4607 break;
4608 }
4609 } else {
Alexey Frunzee7697712016-09-15 21:37:49 -07004610 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4611 if (isR6 || !use_imm) {
4612 if (use_imm) {
4613 rhs_reg = TMP;
4614 __ LoadConst32(rhs_reg, rhs_imm);
4615 }
4616 switch (cond) {
4617 case kCondEQ:
4618 __ Beq(lhs, rhs_reg, label);
4619 break;
4620 case kCondNE:
4621 __ Bne(lhs, rhs_reg, label);
4622 break;
4623 case kCondLT:
4624 __ Blt(lhs, rhs_reg, label);
4625 break;
4626 case kCondGE:
4627 __ Bge(lhs, rhs_reg, label);
4628 break;
4629 case kCondLE:
4630 __ Bge(rhs_reg, lhs, label);
4631 break;
4632 case kCondGT:
4633 __ Blt(rhs_reg, lhs, label);
4634 break;
4635 case kCondB:
4636 __ Bltu(lhs, rhs_reg, label);
4637 break;
4638 case kCondAE:
4639 __ Bgeu(lhs, rhs_reg, label);
4640 break;
4641 case kCondBE:
4642 __ Bgeu(rhs_reg, lhs, label);
4643 break;
4644 case kCondA:
4645 __ Bltu(rhs_reg, lhs, label);
4646 break;
4647 }
4648 } else {
4649 // Special cases for more efficient comparison with constants on R2.
4650 switch (cond) {
4651 case kCondEQ:
4652 __ LoadConst32(TMP, rhs_imm);
4653 __ Beq(lhs, TMP, label);
4654 break;
4655 case kCondNE:
4656 __ LoadConst32(TMP, rhs_imm);
4657 __ Bne(lhs, TMP, label);
4658 break;
4659 case kCondLT:
4660 if (IsInt<16>(rhs_imm)) {
4661 __ Slti(TMP, lhs, rhs_imm);
4662 __ Bnez(TMP, label);
4663 } else {
4664 __ LoadConst32(TMP, rhs_imm);
4665 __ Blt(lhs, TMP, label);
4666 }
4667 break;
4668 case kCondGE:
4669 if (IsInt<16>(rhs_imm)) {
4670 __ Slti(TMP, lhs, rhs_imm);
4671 __ Beqz(TMP, label);
4672 } else {
4673 __ LoadConst32(TMP, rhs_imm);
4674 __ Bge(lhs, TMP, label);
4675 }
4676 break;
4677 case kCondLE:
4678 if (IsInt<16>(rhs_imm + 1)) {
4679 // Simulate lhs <= rhs via lhs < rhs + 1.
4680 __ Slti(TMP, lhs, rhs_imm + 1);
4681 __ Bnez(TMP, label);
4682 } else {
4683 __ LoadConst32(TMP, rhs_imm);
4684 __ Bge(TMP, lhs, label);
4685 }
4686 break;
4687 case kCondGT:
4688 if (IsInt<16>(rhs_imm + 1)) {
4689 // Simulate lhs > rhs via !(lhs < rhs + 1).
4690 __ Slti(TMP, lhs, rhs_imm + 1);
4691 __ Beqz(TMP, label);
4692 } else {
4693 __ LoadConst32(TMP, rhs_imm);
4694 __ Blt(TMP, lhs, label);
4695 }
4696 break;
4697 case kCondB:
4698 if (IsInt<16>(rhs_imm)) {
4699 __ Sltiu(TMP, lhs, rhs_imm);
4700 __ Bnez(TMP, label);
4701 } else {
4702 __ LoadConst32(TMP, rhs_imm);
4703 __ Bltu(lhs, TMP, label);
4704 }
4705 break;
4706 case kCondAE:
4707 if (IsInt<16>(rhs_imm)) {
4708 __ Sltiu(TMP, lhs, rhs_imm);
4709 __ Beqz(TMP, label);
4710 } else {
4711 __ LoadConst32(TMP, rhs_imm);
4712 __ Bgeu(lhs, TMP, label);
4713 }
4714 break;
4715 case kCondBE:
4716 if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
4717 // Simulate lhs <= rhs via lhs < rhs + 1.
4718 // Note that this only works if rhs + 1 does not overflow
4719 // to 0, hence the check above.
4720 __ Sltiu(TMP, lhs, rhs_imm + 1);
4721 __ Bnez(TMP, label);
4722 } else {
4723 __ LoadConst32(TMP, rhs_imm);
4724 __ Bgeu(TMP, lhs, label);
4725 }
4726 break;
4727 case kCondA:
4728 if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
4729 // Simulate lhs > rhs via !(lhs < rhs + 1).
4730 // Note that this only works if rhs + 1 does not overflow
4731 // to 0, hence the check above.
4732 __ Sltiu(TMP, lhs, rhs_imm + 1);
4733 __ Beqz(TMP, label);
4734 } else {
4735 __ LoadConst32(TMP, rhs_imm);
4736 __ Bltu(TMP, lhs, label);
4737 }
4738 break;
4739 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004740 }
4741 }
4742}
4743
Tijana Jakovljevic6d482aa2017-02-03 13:24:08 +01004744void InstructionCodeGeneratorMIPS::GenerateLongCompare(IfCondition cond,
4745 LocationSummary* locations) {
4746 Register dst = locations->Out().AsRegister<Register>();
4747 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4748 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
4749 Location rhs_location = locations->InAt(1);
4750 Register rhs_high = ZERO;
4751 Register rhs_low = ZERO;
4752 int64_t imm = 0;
4753 uint32_t imm_high = 0;
4754 uint32_t imm_low = 0;
4755 bool use_imm = rhs_location.IsConstant();
4756 if (use_imm) {
4757 imm = rhs_location.GetConstant()->AsLongConstant()->GetValue();
4758 imm_high = High32Bits(imm);
4759 imm_low = Low32Bits(imm);
4760 } else {
4761 rhs_high = rhs_location.AsRegisterPairHigh<Register>();
4762 rhs_low = rhs_location.AsRegisterPairLow<Register>();
4763 }
4764 if (use_imm && imm == 0) {
4765 switch (cond) {
4766 case kCondEQ:
4767 case kCondBE: // <= 0 if zero
4768 __ Or(dst, lhs_high, lhs_low);
4769 __ Sltiu(dst, dst, 1);
4770 break;
4771 case kCondNE:
4772 case kCondA: // > 0 if non-zero
4773 __ Or(dst, lhs_high, lhs_low);
4774 __ Sltu(dst, ZERO, dst);
4775 break;
4776 case kCondLT:
4777 __ Slt(dst, lhs_high, ZERO);
4778 break;
4779 case kCondGE:
4780 __ Slt(dst, lhs_high, ZERO);
4781 __ Xori(dst, dst, 1);
4782 break;
4783 case kCondLE:
4784 __ Or(TMP, lhs_high, lhs_low);
4785 __ Sra(AT, lhs_high, 31);
4786 __ Sltu(dst, AT, TMP);
4787 __ Xori(dst, dst, 1);
4788 break;
4789 case kCondGT:
4790 __ Or(TMP, lhs_high, lhs_low);
4791 __ Sra(AT, lhs_high, 31);
4792 __ Sltu(dst, AT, TMP);
4793 break;
4794 case kCondB: // always false
4795 __ Andi(dst, dst, 0);
4796 break;
4797 case kCondAE: // always true
4798 __ Ori(dst, ZERO, 1);
4799 break;
4800 }
4801 } else if (use_imm) {
4802 // TODO: more efficient comparison with constants without loading them into TMP/AT.
4803 switch (cond) {
4804 case kCondEQ:
4805 __ LoadConst32(TMP, imm_high);
4806 __ Xor(TMP, TMP, lhs_high);
4807 __ LoadConst32(AT, imm_low);
4808 __ Xor(AT, AT, lhs_low);
4809 __ Or(dst, TMP, AT);
4810 __ Sltiu(dst, dst, 1);
4811 break;
4812 case kCondNE:
4813 __ LoadConst32(TMP, imm_high);
4814 __ Xor(TMP, TMP, lhs_high);
4815 __ LoadConst32(AT, imm_low);
4816 __ Xor(AT, AT, lhs_low);
4817 __ Or(dst, TMP, AT);
4818 __ Sltu(dst, ZERO, dst);
4819 break;
4820 case kCondLT:
4821 case kCondGE:
4822 if (dst == lhs_low) {
4823 __ LoadConst32(TMP, imm_low);
4824 __ Sltu(dst, lhs_low, TMP);
4825 }
4826 __ LoadConst32(TMP, imm_high);
4827 __ Slt(AT, lhs_high, TMP);
4828 __ Slt(TMP, TMP, lhs_high);
4829 if (dst != lhs_low) {
4830 __ LoadConst32(dst, imm_low);
4831 __ Sltu(dst, lhs_low, dst);
4832 }
4833 __ Slt(dst, TMP, dst);
4834 __ Or(dst, dst, AT);
4835 if (cond == kCondGE) {
4836 __ Xori(dst, dst, 1);
4837 }
4838 break;
4839 case kCondGT:
4840 case kCondLE:
4841 if (dst == lhs_low) {
4842 __ LoadConst32(TMP, imm_low);
4843 __ Sltu(dst, TMP, lhs_low);
4844 }
4845 __ LoadConst32(TMP, imm_high);
4846 __ Slt(AT, TMP, lhs_high);
4847 __ Slt(TMP, lhs_high, TMP);
4848 if (dst != lhs_low) {
4849 __ LoadConst32(dst, imm_low);
4850 __ Sltu(dst, dst, lhs_low);
4851 }
4852 __ Slt(dst, TMP, dst);
4853 __ Or(dst, dst, AT);
4854 if (cond == kCondLE) {
4855 __ Xori(dst, dst, 1);
4856 }
4857 break;
4858 case kCondB:
4859 case kCondAE:
4860 if (dst == lhs_low) {
4861 __ LoadConst32(TMP, imm_low);
4862 __ Sltu(dst, lhs_low, TMP);
4863 }
4864 __ LoadConst32(TMP, imm_high);
4865 __ Sltu(AT, lhs_high, TMP);
4866 __ Sltu(TMP, TMP, lhs_high);
4867 if (dst != lhs_low) {
4868 __ LoadConst32(dst, imm_low);
4869 __ Sltu(dst, lhs_low, dst);
4870 }
4871 __ Slt(dst, TMP, dst);
4872 __ Or(dst, dst, AT);
4873 if (cond == kCondAE) {
4874 __ Xori(dst, dst, 1);
4875 }
4876 break;
4877 case kCondA:
4878 case kCondBE:
4879 if (dst == lhs_low) {
4880 __ LoadConst32(TMP, imm_low);
4881 __ Sltu(dst, TMP, lhs_low);
4882 }
4883 __ LoadConst32(TMP, imm_high);
4884 __ Sltu(AT, TMP, lhs_high);
4885 __ Sltu(TMP, lhs_high, TMP);
4886 if (dst != lhs_low) {
4887 __ LoadConst32(dst, imm_low);
4888 __ Sltu(dst, dst, lhs_low);
4889 }
4890 __ Slt(dst, TMP, dst);
4891 __ Or(dst, dst, AT);
4892 if (cond == kCondBE) {
4893 __ Xori(dst, dst, 1);
4894 }
4895 break;
4896 }
4897 } else {
4898 switch (cond) {
4899 case kCondEQ:
4900 __ Xor(TMP, lhs_high, rhs_high);
4901 __ Xor(AT, lhs_low, rhs_low);
4902 __ Or(dst, TMP, AT);
4903 __ Sltiu(dst, dst, 1);
4904 break;
4905 case kCondNE:
4906 __ Xor(TMP, lhs_high, rhs_high);
4907 __ Xor(AT, lhs_low, rhs_low);
4908 __ Or(dst, TMP, AT);
4909 __ Sltu(dst, ZERO, dst);
4910 break;
4911 case kCondLT:
4912 case kCondGE:
4913 __ Slt(TMP, rhs_high, lhs_high);
4914 __ Sltu(AT, lhs_low, rhs_low);
4915 __ Slt(TMP, TMP, AT);
4916 __ Slt(AT, lhs_high, rhs_high);
4917 __ Or(dst, AT, TMP);
4918 if (cond == kCondGE) {
4919 __ Xori(dst, dst, 1);
4920 }
4921 break;
4922 case kCondGT:
4923 case kCondLE:
4924 __ Slt(TMP, lhs_high, rhs_high);
4925 __ Sltu(AT, rhs_low, lhs_low);
4926 __ Slt(TMP, TMP, AT);
4927 __ Slt(AT, rhs_high, lhs_high);
4928 __ Or(dst, AT, TMP);
4929 if (cond == kCondLE) {
4930 __ Xori(dst, dst, 1);
4931 }
4932 break;
4933 case kCondB:
4934 case kCondAE:
4935 __ Sltu(TMP, rhs_high, lhs_high);
4936 __ Sltu(AT, lhs_low, rhs_low);
4937 __ Slt(TMP, TMP, AT);
4938 __ Sltu(AT, lhs_high, rhs_high);
4939 __ Or(dst, AT, TMP);
4940 if (cond == kCondAE) {
4941 __ Xori(dst, dst, 1);
4942 }
4943 break;
4944 case kCondA:
4945 case kCondBE:
4946 __ Sltu(TMP, lhs_high, rhs_high);
4947 __ Sltu(AT, rhs_low, lhs_low);
4948 __ Slt(TMP, TMP, AT);
4949 __ Sltu(AT, rhs_high, lhs_high);
4950 __ Or(dst, AT, TMP);
4951 if (cond == kCondBE) {
4952 __ Xori(dst, dst, 1);
4953 }
4954 break;
4955 }
4956 }
4957}
4958
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004959void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond,
4960 LocationSummary* locations,
4961 MipsLabel* label) {
4962 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4963 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
4964 Location rhs_location = locations->InAt(1);
4965 Register rhs_high = ZERO;
4966 Register rhs_low = ZERO;
4967 int64_t imm = 0;
4968 uint32_t imm_high = 0;
4969 uint32_t imm_low = 0;
4970 bool use_imm = rhs_location.IsConstant();
4971 if (use_imm) {
4972 imm = rhs_location.GetConstant()->AsLongConstant()->GetValue();
4973 imm_high = High32Bits(imm);
4974 imm_low = Low32Bits(imm);
4975 } else {
4976 rhs_high = rhs_location.AsRegisterPairHigh<Register>();
4977 rhs_low = rhs_location.AsRegisterPairLow<Register>();
4978 }
4979
4980 if (use_imm && imm == 0) {
4981 switch (cond) {
4982 case kCondEQ:
4983 case kCondBE: // <= 0 if zero
4984 __ Or(TMP, lhs_high, lhs_low);
4985 __ Beqz(TMP, label);
4986 break;
4987 case kCondNE:
4988 case kCondA: // > 0 if non-zero
4989 __ Or(TMP, lhs_high, lhs_low);
4990 __ Bnez(TMP, label);
4991 break;
4992 case kCondLT:
4993 __ Bltz(lhs_high, label);
4994 break;
4995 case kCondGE:
4996 __ Bgez(lhs_high, label);
4997 break;
4998 case kCondLE:
4999 __ Or(TMP, lhs_high, lhs_low);
5000 __ Sra(AT, lhs_high, 31);
5001 __ Bgeu(AT, TMP, label);
5002 break;
5003 case kCondGT:
5004 __ Or(TMP, lhs_high, lhs_low);
5005 __ Sra(AT, lhs_high, 31);
5006 __ Bltu(AT, TMP, label);
5007 break;
5008 case kCondB: // always false
5009 break;
5010 case kCondAE: // always true
5011 __ B(label);
5012 break;
5013 }
5014 } else if (use_imm) {
5015 // TODO: more efficient comparison with constants without loading them into TMP/AT.
5016 switch (cond) {
5017 case kCondEQ:
5018 __ LoadConst32(TMP, imm_high);
5019 __ Xor(TMP, TMP, lhs_high);
5020 __ LoadConst32(AT, imm_low);
5021 __ Xor(AT, AT, lhs_low);
5022 __ Or(TMP, TMP, AT);
5023 __ Beqz(TMP, label);
5024 break;
5025 case kCondNE:
5026 __ LoadConst32(TMP, imm_high);
5027 __ Xor(TMP, TMP, lhs_high);
5028 __ LoadConst32(AT, imm_low);
5029 __ Xor(AT, AT, lhs_low);
5030 __ Or(TMP, TMP, AT);
5031 __ Bnez(TMP, label);
5032 break;
5033 case kCondLT:
5034 __ LoadConst32(TMP, imm_high);
5035 __ Blt(lhs_high, TMP, label);
5036 __ Slt(TMP, TMP, lhs_high);
5037 __ LoadConst32(AT, imm_low);
5038 __ Sltu(AT, lhs_low, AT);
5039 __ Blt(TMP, AT, label);
5040 break;
5041 case kCondGE:
5042 __ LoadConst32(TMP, imm_high);
5043 __ Blt(TMP, lhs_high, label);
5044 __ Slt(TMP, lhs_high, TMP);
5045 __ LoadConst32(AT, imm_low);
5046 __ Sltu(AT, lhs_low, AT);
5047 __ Or(TMP, TMP, AT);
5048 __ Beqz(TMP, label);
5049 break;
5050 case kCondLE:
5051 __ LoadConst32(TMP, imm_high);
5052 __ Blt(lhs_high, TMP, label);
5053 __ Slt(TMP, TMP, lhs_high);
5054 __ LoadConst32(AT, imm_low);
5055 __ Sltu(AT, AT, lhs_low);
5056 __ Or(TMP, TMP, AT);
5057 __ Beqz(TMP, label);
5058 break;
5059 case kCondGT:
5060 __ LoadConst32(TMP, imm_high);
5061 __ Blt(TMP, lhs_high, label);
5062 __ Slt(TMP, lhs_high, TMP);
5063 __ LoadConst32(AT, imm_low);
5064 __ Sltu(AT, AT, lhs_low);
5065 __ Blt(TMP, AT, label);
5066 break;
5067 case kCondB:
5068 __ LoadConst32(TMP, imm_high);
5069 __ Bltu(lhs_high, TMP, label);
5070 __ Sltu(TMP, TMP, lhs_high);
5071 __ LoadConst32(AT, imm_low);
5072 __ Sltu(AT, lhs_low, AT);
5073 __ Blt(TMP, AT, label);
5074 break;
5075 case kCondAE:
5076 __ LoadConst32(TMP, imm_high);
5077 __ Bltu(TMP, lhs_high, label);
5078 __ Sltu(TMP, lhs_high, TMP);
5079 __ LoadConst32(AT, imm_low);
5080 __ Sltu(AT, lhs_low, AT);
5081 __ Or(TMP, TMP, AT);
5082 __ Beqz(TMP, label);
5083 break;
5084 case kCondBE:
5085 __ LoadConst32(TMP, imm_high);
5086 __ Bltu(lhs_high, TMP, label);
5087 __ Sltu(TMP, TMP, lhs_high);
5088 __ LoadConst32(AT, imm_low);
5089 __ Sltu(AT, AT, lhs_low);
5090 __ Or(TMP, TMP, AT);
5091 __ Beqz(TMP, label);
5092 break;
5093 case kCondA:
5094 __ LoadConst32(TMP, imm_high);
5095 __ Bltu(TMP, lhs_high, label);
5096 __ Sltu(TMP, lhs_high, TMP);
5097 __ LoadConst32(AT, imm_low);
5098 __ Sltu(AT, AT, lhs_low);
5099 __ Blt(TMP, AT, label);
5100 break;
5101 }
5102 } else {
5103 switch (cond) {
5104 case kCondEQ:
5105 __ Xor(TMP, lhs_high, rhs_high);
5106 __ Xor(AT, lhs_low, rhs_low);
5107 __ Or(TMP, TMP, AT);
5108 __ Beqz(TMP, label);
5109 break;
5110 case kCondNE:
5111 __ Xor(TMP, lhs_high, rhs_high);
5112 __ Xor(AT, lhs_low, rhs_low);
5113 __ Or(TMP, TMP, AT);
5114 __ Bnez(TMP, label);
5115 break;
5116 case kCondLT:
5117 __ Blt(lhs_high, rhs_high, label);
5118 __ Slt(TMP, rhs_high, lhs_high);
5119 __ Sltu(AT, lhs_low, rhs_low);
5120 __ Blt(TMP, AT, label);
5121 break;
5122 case kCondGE:
5123 __ Blt(rhs_high, lhs_high, label);
5124 __ Slt(TMP, lhs_high, rhs_high);
5125 __ Sltu(AT, lhs_low, rhs_low);
5126 __ Or(TMP, TMP, AT);
5127 __ Beqz(TMP, label);
5128 break;
5129 case kCondLE:
5130 __ Blt(lhs_high, rhs_high, label);
5131 __ Slt(TMP, rhs_high, lhs_high);
5132 __ Sltu(AT, rhs_low, lhs_low);
5133 __ Or(TMP, TMP, AT);
5134 __ Beqz(TMP, label);
5135 break;
5136 case kCondGT:
5137 __ Blt(rhs_high, lhs_high, label);
5138 __ Slt(TMP, lhs_high, rhs_high);
5139 __ Sltu(AT, rhs_low, lhs_low);
5140 __ Blt(TMP, AT, label);
5141 break;
5142 case kCondB:
5143 __ Bltu(lhs_high, rhs_high, label);
5144 __ Sltu(TMP, rhs_high, lhs_high);
5145 __ Sltu(AT, lhs_low, rhs_low);
5146 __ Blt(TMP, AT, label);
5147 break;
5148 case kCondAE:
5149 __ Bltu(rhs_high, lhs_high, label);
5150 __ Sltu(TMP, lhs_high, rhs_high);
5151 __ Sltu(AT, lhs_low, rhs_low);
5152 __ Or(TMP, TMP, AT);
5153 __ Beqz(TMP, label);
5154 break;
5155 case kCondBE:
5156 __ Bltu(lhs_high, rhs_high, label);
5157 __ Sltu(TMP, rhs_high, lhs_high);
5158 __ Sltu(AT, rhs_low, lhs_low);
5159 __ Or(TMP, TMP, AT);
5160 __ Beqz(TMP, label);
5161 break;
5162 case kCondA:
5163 __ Bltu(rhs_high, lhs_high, label);
5164 __ Sltu(TMP, lhs_high, rhs_high);
5165 __ Sltu(AT, rhs_low, lhs_low);
5166 __ Blt(TMP, AT, label);
5167 break;
5168 }
5169 }
5170}
5171
Alexey Frunze2ddb7172016-09-06 17:04:55 -07005172void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond,
5173 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005174 DataType::Type type,
Alexey Frunze2ddb7172016-09-06 17:04:55 -07005175 LocationSummary* locations) {
5176 Register dst = locations->Out().AsRegister<Register>();
5177 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
5178 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
5179 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005180 if (type == DataType::Type::kFloat32) {
Alexey Frunze2ddb7172016-09-06 17:04:55 -07005181 if (isR6) {
5182 switch (cond) {
5183 case kCondEQ:
5184 __ CmpEqS(FTMP, lhs, rhs);
5185 __ Mfc1(dst, FTMP);
5186 __ Andi(dst, dst, 1);
5187 break;
5188 case kCondNE:
5189 __ CmpEqS(FTMP, lhs, rhs);
5190 __ Mfc1(dst, FTMP);
5191 __ Addiu(dst, dst, 1);
5192 break;
5193 case kCondLT:
5194 if (gt_bias) {
5195 __ CmpLtS(FTMP, lhs, rhs);
5196 } else {
5197 __ CmpUltS(FTMP, lhs, rhs);
5198 }
5199 __ Mfc1(dst, FTMP);
5200 __ Andi(dst, dst, 1);
5201 break;
5202 case kCondLE:
5203 if (gt_bias) {
5204 __ CmpLeS(FTMP, lhs, rhs);
5205 } else {
5206 __ CmpUleS(FTMP, lhs, rhs);
5207 }
5208 __ Mfc1(dst, FTMP);
5209 __ Andi(dst, dst, 1);
5210 break;
5211 case kCondGT:
5212 if (gt_bias) {
5213 __ CmpUltS(FTMP, rhs, lhs);
5214 } else {
5215 __ CmpLtS(FTMP, rhs, lhs);
5216 }
5217 __ Mfc1(dst, FTMP);
5218 __ Andi(dst, dst, 1);
5219 break;
5220 case kCondGE:
5221 if (gt_bias) {
5222 __ CmpUleS(FTMP, rhs, lhs);
5223 } else {
5224 __ CmpLeS(FTMP, rhs, lhs);
5225 }
5226 __ Mfc1(dst, FTMP);
5227 __ Andi(dst, dst, 1);
5228 break;
5229 default:
5230 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
5231 UNREACHABLE();
5232 }
5233 } else {
5234 switch (cond) {
5235 case kCondEQ:
5236 __ CeqS(0, lhs, rhs);
5237 __ LoadConst32(dst, 1);
5238 __ Movf(dst, ZERO, 0);
5239 break;
5240 case kCondNE:
5241 __ CeqS(0, lhs, rhs);
5242 __ LoadConst32(dst, 1);
5243 __ Movt(dst, ZERO, 0);
5244 break;
5245 case kCondLT:
5246 if (gt_bias) {
5247 __ ColtS(0, lhs, rhs);
5248 } else {
5249 __ CultS(0, lhs, rhs);
5250 }
5251 __ LoadConst32(dst, 1);
5252 __ Movf(dst, ZERO, 0);
5253 break;
5254 case kCondLE:
5255 if (gt_bias) {
5256 __ ColeS(0, lhs, rhs);
5257 } else {
5258 __ CuleS(0, lhs, rhs);
5259 }
5260 __ LoadConst32(dst, 1);
5261 __ Movf(dst, ZERO, 0);
5262 break;
5263 case kCondGT:
5264 if (gt_bias) {
5265 __ CultS(0, rhs, lhs);
5266 } else {
5267 __ ColtS(0, rhs, lhs);
5268 }
5269 __ LoadConst32(dst, 1);
5270 __ Movf(dst, ZERO, 0);
5271 break;
5272 case kCondGE:
5273 if (gt_bias) {
5274 __ CuleS(0, rhs, lhs);
5275 } else {
5276 __ ColeS(0, rhs, lhs);
5277 }
5278 __ LoadConst32(dst, 1);
5279 __ Movf(dst, ZERO, 0);
5280 break;
5281 default:
5282 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
5283 UNREACHABLE();
5284 }
5285 }
5286 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005287 DCHECK_EQ(type, DataType::Type::kFloat64);
Alexey Frunze2ddb7172016-09-06 17:04:55 -07005288 if (isR6) {
5289 switch (cond) {
5290 case kCondEQ:
5291 __ CmpEqD(FTMP, lhs, rhs);
5292 __ Mfc1(dst, FTMP);
5293 __ Andi(dst, dst, 1);
5294 break;
5295 case kCondNE:
5296 __ CmpEqD(FTMP, lhs, rhs);
5297 __ Mfc1(dst, FTMP);
5298 __ Addiu(dst, dst, 1);
5299 break;
5300 case kCondLT:
5301 if (gt_bias) {
5302 __ CmpLtD(FTMP, lhs, rhs);
5303 } else {
5304 __ CmpUltD(FTMP, lhs, rhs);
5305 }
5306 __ Mfc1(dst, FTMP);
5307 __ Andi(dst, dst, 1);
5308 break;
5309 case kCondLE:
5310 if (gt_bias) {
5311 __ CmpLeD(FTMP, lhs, rhs);
5312 } else {
5313 __ CmpUleD(FTMP, lhs, rhs);
5314 }
5315 __ Mfc1(dst, FTMP);
5316 __ Andi(dst, dst, 1);
5317 break;
5318 case kCondGT:
5319 if (gt_bias) {
5320 __ CmpUltD(FTMP, rhs, lhs);
5321 } else {
5322 __ CmpLtD(FTMP, rhs, lhs);
5323 }
5324 __ Mfc1(dst, FTMP);
5325 __ Andi(dst, dst, 1);
5326 break;
5327 case kCondGE:
5328 if (gt_bias) {
5329 __ CmpUleD(FTMP, rhs, lhs);
5330 } else {
5331 __ CmpLeD(FTMP, rhs, lhs);
5332 }
5333 __ Mfc1(dst, FTMP);
5334 __ Andi(dst, dst, 1);
5335 break;
5336 default:
5337 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
5338 UNREACHABLE();
5339 }
5340 } else {
5341 switch (cond) {
5342 case kCondEQ:
5343 __ CeqD(0, lhs, rhs);
5344 __ LoadConst32(dst, 1);
5345 __ Movf(dst, ZERO, 0);
5346 break;
5347 case kCondNE:
5348 __ CeqD(0, lhs, rhs);
5349 __ LoadConst32(dst, 1);
5350 __ Movt(dst, ZERO, 0);
5351 break;
5352 case kCondLT:
5353 if (gt_bias) {
5354 __ ColtD(0, lhs, rhs);
5355 } else {
5356 __ CultD(0, lhs, rhs);
5357 }
5358 __ LoadConst32(dst, 1);
5359 __ Movf(dst, ZERO, 0);
5360 break;
5361 case kCondLE:
5362 if (gt_bias) {
5363 __ ColeD(0, lhs, rhs);
5364 } else {
5365 __ CuleD(0, lhs, rhs);
5366 }
5367 __ LoadConst32(dst, 1);
5368 __ Movf(dst, ZERO, 0);
5369 break;
5370 case kCondGT:
5371 if (gt_bias) {
5372 __ CultD(0, rhs, lhs);
5373 } else {
5374 __ ColtD(0, rhs, lhs);
5375 }
5376 __ LoadConst32(dst, 1);
5377 __ Movf(dst, ZERO, 0);
5378 break;
5379 case kCondGE:
5380 if (gt_bias) {
5381 __ CuleD(0, rhs, lhs);
5382 } else {
5383 __ ColeD(0, rhs, lhs);
5384 }
5385 __ LoadConst32(dst, 1);
5386 __ Movf(dst, ZERO, 0);
5387 break;
5388 default:
5389 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
5390 UNREACHABLE();
5391 }
5392 }
5393 }
5394}
5395
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005396bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond,
5397 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005398 DataType::Type type,
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005399 LocationSummary* input_locations,
5400 int cc) {
5401 FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>();
5402 FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>();
5403 CHECK(!codegen_->GetInstructionSetFeatures().IsR6());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005404 if (type == DataType::Type::kFloat32) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005405 switch (cond) {
5406 case kCondEQ:
5407 __ CeqS(cc, lhs, rhs);
5408 return false;
5409 case kCondNE:
5410 __ CeqS(cc, lhs, rhs);
5411 return true;
5412 case kCondLT:
5413 if (gt_bias) {
5414 __ ColtS(cc, lhs, rhs);
5415 } else {
5416 __ CultS(cc, lhs, rhs);
5417 }
5418 return false;
5419 case kCondLE:
5420 if (gt_bias) {
5421 __ ColeS(cc, lhs, rhs);
5422 } else {
5423 __ CuleS(cc, lhs, rhs);
5424 }
5425 return false;
5426 case kCondGT:
5427 if (gt_bias) {
5428 __ CultS(cc, rhs, lhs);
5429 } else {
5430 __ ColtS(cc, rhs, lhs);
5431 }
5432 return false;
5433 case kCondGE:
5434 if (gt_bias) {
5435 __ CuleS(cc, rhs, lhs);
5436 } else {
5437 __ ColeS(cc, rhs, lhs);
5438 }
5439 return false;
5440 default:
5441 LOG(FATAL) << "Unexpected non-floating-point condition";
5442 UNREACHABLE();
5443 }
5444 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005445 DCHECK_EQ(type, DataType::Type::kFloat64);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005446 switch (cond) {
5447 case kCondEQ:
5448 __ CeqD(cc, lhs, rhs);
5449 return false;
5450 case kCondNE:
5451 __ CeqD(cc, lhs, rhs);
5452 return true;
5453 case kCondLT:
5454 if (gt_bias) {
5455 __ ColtD(cc, lhs, rhs);
5456 } else {
5457 __ CultD(cc, lhs, rhs);
5458 }
5459 return false;
5460 case kCondLE:
5461 if (gt_bias) {
5462 __ ColeD(cc, lhs, rhs);
5463 } else {
5464 __ CuleD(cc, lhs, rhs);
5465 }
5466 return false;
5467 case kCondGT:
5468 if (gt_bias) {
5469 __ CultD(cc, rhs, lhs);
5470 } else {
5471 __ ColtD(cc, rhs, lhs);
5472 }
5473 return false;
5474 case kCondGE:
5475 if (gt_bias) {
5476 __ CuleD(cc, rhs, lhs);
5477 } else {
5478 __ ColeD(cc, rhs, lhs);
5479 }
5480 return false;
5481 default:
5482 LOG(FATAL) << "Unexpected non-floating-point condition";
5483 UNREACHABLE();
5484 }
5485 }
5486}
5487
5488bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond,
5489 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005490 DataType::Type type,
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005491 LocationSummary* input_locations,
5492 FRegister dst) {
5493 FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>();
5494 FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>();
5495 CHECK(codegen_->GetInstructionSetFeatures().IsR6());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005496 if (type == DataType::Type::kFloat32) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005497 switch (cond) {
5498 case kCondEQ:
5499 __ CmpEqS(dst, lhs, rhs);
5500 return false;
5501 case kCondNE:
5502 __ CmpEqS(dst, lhs, rhs);
5503 return true;
5504 case kCondLT:
5505 if (gt_bias) {
5506 __ CmpLtS(dst, lhs, rhs);
5507 } else {
5508 __ CmpUltS(dst, lhs, rhs);
5509 }
5510 return false;
5511 case kCondLE:
5512 if (gt_bias) {
5513 __ CmpLeS(dst, lhs, rhs);
5514 } else {
5515 __ CmpUleS(dst, lhs, rhs);
5516 }
5517 return false;
5518 case kCondGT:
5519 if (gt_bias) {
5520 __ CmpUltS(dst, rhs, lhs);
5521 } else {
5522 __ CmpLtS(dst, rhs, lhs);
5523 }
5524 return false;
5525 case kCondGE:
5526 if (gt_bias) {
5527 __ CmpUleS(dst, rhs, lhs);
5528 } else {
5529 __ CmpLeS(dst, rhs, lhs);
5530 }
5531 return false;
5532 default:
5533 LOG(FATAL) << "Unexpected non-floating-point condition";
5534 UNREACHABLE();
5535 }
5536 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005537 DCHECK_EQ(type, DataType::Type::kFloat64);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005538 switch (cond) {
5539 case kCondEQ:
5540 __ CmpEqD(dst, lhs, rhs);
5541 return false;
5542 case kCondNE:
5543 __ CmpEqD(dst, lhs, rhs);
5544 return true;
5545 case kCondLT:
5546 if (gt_bias) {
5547 __ CmpLtD(dst, lhs, rhs);
5548 } else {
5549 __ CmpUltD(dst, lhs, rhs);
5550 }
5551 return false;
5552 case kCondLE:
5553 if (gt_bias) {
5554 __ CmpLeD(dst, lhs, rhs);
5555 } else {
5556 __ CmpUleD(dst, lhs, rhs);
5557 }
5558 return false;
5559 case kCondGT:
5560 if (gt_bias) {
5561 __ CmpUltD(dst, rhs, lhs);
5562 } else {
5563 __ CmpLtD(dst, rhs, lhs);
5564 }
5565 return false;
5566 case kCondGE:
5567 if (gt_bias) {
5568 __ CmpUleD(dst, rhs, lhs);
5569 } else {
5570 __ CmpLeD(dst, rhs, lhs);
5571 }
5572 return false;
5573 default:
5574 LOG(FATAL) << "Unexpected non-floating-point condition";
5575 UNREACHABLE();
5576 }
5577 }
5578}
5579
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005580void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond,
5581 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005582 DataType::Type type,
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005583 LocationSummary* locations,
5584 MipsLabel* label) {
5585 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
5586 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
5587 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005588 if (type == DataType::Type::kFloat32) {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005589 if (isR6) {
5590 switch (cond) {
5591 case kCondEQ:
5592 __ CmpEqS(FTMP, lhs, rhs);
5593 __ Bc1nez(FTMP, label);
5594 break;
5595 case kCondNE:
5596 __ CmpEqS(FTMP, lhs, rhs);
5597 __ Bc1eqz(FTMP, label);
5598 break;
5599 case kCondLT:
5600 if (gt_bias) {
5601 __ CmpLtS(FTMP, lhs, rhs);
5602 } else {
5603 __ CmpUltS(FTMP, lhs, rhs);
5604 }
5605 __ Bc1nez(FTMP, label);
5606 break;
5607 case kCondLE:
5608 if (gt_bias) {
5609 __ CmpLeS(FTMP, lhs, rhs);
5610 } else {
5611 __ CmpUleS(FTMP, lhs, rhs);
5612 }
5613 __ Bc1nez(FTMP, label);
5614 break;
5615 case kCondGT:
5616 if (gt_bias) {
5617 __ CmpUltS(FTMP, rhs, lhs);
5618 } else {
5619 __ CmpLtS(FTMP, rhs, lhs);
5620 }
5621 __ Bc1nez(FTMP, label);
5622 break;
5623 case kCondGE:
5624 if (gt_bias) {
5625 __ CmpUleS(FTMP, rhs, lhs);
5626 } else {
5627 __ CmpLeS(FTMP, rhs, lhs);
5628 }
5629 __ Bc1nez(FTMP, label);
5630 break;
5631 default:
5632 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005633 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005634 }
5635 } else {
5636 switch (cond) {
5637 case kCondEQ:
5638 __ CeqS(0, lhs, rhs);
5639 __ Bc1t(0, label);
5640 break;
5641 case kCondNE:
5642 __ CeqS(0, lhs, rhs);
5643 __ Bc1f(0, label);
5644 break;
5645 case kCondLT:
5646 if (gt_bias) {
5647 __ ColtS(0, lhs, rhs);
5648 } else {
5649 __ CultS(0, lhs, rhs);
5650 }
5651 __ Bc1t(0, label);
5652 break;
5653 case kCondLE:
5654 if (gt_bias) {
5655 __ ColeS(0, lhs, rhs);
5656 } else {
5657 __ CuleS(0, lhs, rhs);
5658 }
5659 __ Bc1t(0, label);
5660 break;
5661 case kCondGT:
5662 if (gt_bias) {
5663 __ CultS(0, rhs, lhs);
5664 } else {
5665 __ ColtS(0, rhs, lhs);
5666 }
5667 __ Bc1t(0, label);
5668 break;
5669 case kCondGE:
5670 if (gt_bias) {
5671 __ CuleS(0, rhs, lhs);
5672 } else {
5673 __ ColeS(0, rhs, lhs);
5674 }
5675 __ Bc1t(0, label);
5676 break;
5677 default:
5678 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005679 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005680 }
5681 }
5682 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005683 DCHECK_EQ(type, DataType::Type::kFloat64);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005684 if (isR6) {
5685 switch (cond) {
5686 case kCondEQ:
5687 __ CmpEqD(FTMP, lhs, rhs);
5688 __ Bc1nez(FTMP, label);
5689 break;
5690 case kCondNE:
5691 __ CmpEqD(FTMP, lhs, rhs);
5692 __ Bc1eqz(FTMP, label);
5693 break;
5694 case kCondLT:
5695 if (gt_bias) {
5696 __ CmpLtD(FTMP, lhs, rhs);
5697 } else {
5698 __ CmpUltD(FTMP, lhs, rhs);
5699 }
5700 __ Bc1nez(FTMP, label);
5701 break;
5702 case kCondLE:
5703 if (gt_bias) {
5704 __ CmpLeD(FTMP, lhs, rhs);
5705 } else {
5706 __ CmpUleD(FTMP, lhs, rhs);
5707 }
5708 __ Bc1nez(FTMP, label);
5709 break;
5710 case kCondGT:
5711 if (gt_bias) {
5712 __ CmpUltD(FTMP, rhs, lhs);
5713 } else {
5714 __ CmpLtD(FTMP, rhs, lhs);
5715 }
5716 __ Bc1nez(FTMP, label);
5717 break;
5718 case kCondGE:
5719 if (gt_bias) {
5720 __ CmpUleD(FTMP, rhs, lhs);
5721 } else {
5722 __ CmpLeD(FTMP, rhs, lhs);
5723 }
5724 __ Bc1nez(FTMP, label);
5725 break;
5726 default:
5727 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005728 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005729 }
5730 } else {
5731 switch (cond) {
5732 case kCondEQ:
5733 __ CeqD(0, lhs, rhs);
5734 __ Bc1t(0, label);
5735 break;
5736 case kCondNE:
5737 __ CeqD(0, lhs, rhs);
5738 __ Bc1f(0, label);
5739 break;
5740 case kCondLT:
5741 if (gt_bias) {
5742 __ ColtD(0, lhs, rhs);
5743 } else {
5744 __ CultD(0, lhs, rhs);
5745 }
5746 __ Bc1t(0, label);
5747 break;
5748 case kCondLE:
5749 if (gt_bias) {
5750 __ ColeD(0, lhs, rhs);
5751 } else {
5752 __ CuleD(0, lhs, rhs);
5753 }
5754 __ Bc1t(0, label);
5755 break;
5756 case kCondGT:
5757 if (gt_bias) {
5758 __ CultD(0, rhs, lhs);
5759 } else {
5760 __ ColtD(0, rhs, lhs);
5761 }
5762 __ Bc1t(0, label);
5763 break;
5764 case kCondGE:
5765 if (gt_bias) {
5766 __ CuleD(0, rhs, lhs);
5767 } else {
5768 __ ColeD(0, rhs, lhs);
5769 }
5770 __ Bc1t(0, label);
5771 break;
5772 default:
5773 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005774 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005775 }
5776 }
5777 }
5778}
5779
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005780void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00005781 size_t condition_input_index,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005782 MipsLabel* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00005783 MipsLabel* false_target) {
5784 HInstruction* cond = instruction->InputAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005785
David Brazdil0debae72015-11-12 18:37:00 +00005786 if (true_target == nullptr && false_target == nullptr) {
5787 // Nothing to do. The code always falls through.
5788 return;
5789 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00005790 // Constant condition, statically compared against "true" (integer value 1).
5791 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00005792 if (true_target != nullptr) {
5793 __ B(true_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005794 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005795 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00005796 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00005797 if (false_target != nullptr) {
5798 __ B(false_target);
5799 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005800 }
David Brazdil0debae72015-11-12 18:37:00 +00005801 return;
5802 }
5803
5804 // The following code generates these patterns:
5805 // (1) true_target == nullptr && false_target != nullptr
5806 // - opposite condition true => branch to false_target
5807 // (2) true_target != nullptr && false_target == nullptr
5808 // - condition true => branch to true_target
5809 // (3) true_target != nullptr && false_target != nullptr
5810 // - condition true => branch to true_target
5811 // - branch to false_target
5812 if (IsBooleanValueOrMaterializedCondition(cond)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005813 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00005814 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005815 DCHECK(cond_val.IsRegister());
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005816 if (true_target == nullptr) {
David Brazdil0debae72015-11-12 18:37:00 +00005817 __ Beqz(cond_val.AsRegister<Register>(), false_target);
5818 } else {
5819 __ Bnez(cond_val.AsRegister<Register>(), true_target);
5820 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005821 } else {
5822 // The condition instruction has not been materialized, use its inputs as
5823 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00005824 HCondition* condition = cond->AsCondition();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005825 DataType::Type type = condition->InputAt(0)->GetType();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005826 LocationSummary* locations = cond->GetLocations();
5827 IfCondition if_cond = condition->GetCondition();
5828 MipsLabel* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00005829
David Brazdil0debae72015-11-12 18:37:00 +00005830 if (true_target == nullptr) {
5831 if_cond = condition->GetOppositeCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005832 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00005833 }
5834
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005835 switch (type) {
5836 default:
5837 GenerateIntCompareAndBranch(if_cond, locations, branch_target);
5838 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005839 case DataType::Type::kInt64:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005840 GenerateLongCompareAndBranch(if_cond, locations, branch_target);
5841 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005842 case DataType::Type::kFloat32:
5843 case DataType::Type::kFloat64:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005844 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
5845 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005846 }
5847 }
David Brazdil0debae72015-11-12 18:37:00 +00005848
5849 // If neither branch falls through (case 3), the conditional branch to `true_target`
5850 // was already emitted (case 2) and we need to emit a jump to `false_target`.
5851 if (true_target != nullptr && false_target != nullptr) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005852 __ B(false_target);
5853 }
5854}
5855
5856void LocationsBuilderMIPS::VisitIf(HIf* if_instr) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01005857 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00005858 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005859 locations->SetInAt(0, Location::RequiresRegister());
5860 }
5861}
5862
5863void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00005864 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
5865 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
5866 MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
5867 nullptr : codegen_->GetLabelOf(true_successor);
5868 MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
5869 nullptr : codegen_->GetLabelOf(false_successor);
5870 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005871}
5872
5873void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01005874 LocationSummary* locations = new (GetGraph()->GetAllocator())
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005875 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01005876 InvokeRuntimeCallingConvention calling_convention;
5877 RegisterSet caller_saves = RegisterSet::Empty();
5878 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5879 locations->SetCustomSlowPathCallerSaves(caller_saves);
David Brazdil0debae72015-11-12 18:37:00 +00005880 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005881 locations->SetInAt(0, Location::RequiresRegister());
5882 }
5883}
5884
5885void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08005886 SlowPathCodeMIPS* slow_path =
5887 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00005888 GenerateTestAndBranch(deoptimize,
5889 /* condition_input_index */ 0,
5890 slow_path->GetEntryLabel(),
5891 /* false_target */ nullptr);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005892}
5893
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005894// This function returns true if a conditional move can be generated for HSelect.
5895// Otherwise it returns false and HSelect must be implemented in terms of conditonal
5896// branches and regular moves.
5897//
5898// If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect.
5899//
5900// While determining feasibility of a conditional move and setting inputs/outputs
5901// are two distinct tasks, this function does both because they share quite a bit
5902// of common logic.
5903static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) {
5904 bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition());
5905 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
5906 HCondition* condition = cond->AsCondition();
5907
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005908 DataType::Type cond_type =
5909 materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType();
5910 DataType::Type dst_type = select->GetType();
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005911
5912 HConstant* cst_true_value = select->GetTrueValue()->AsConstant();
5913 HConstant* cst_false_value = select->GetFalseValue()->AsConstant();
5914 bool is_true_value_zero_constant =
5915 (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern());
5916 bool is_false_value_zero_constant =
5917 (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern());
5918
5919 bool can_move_conditionally = false;
5920 bool use_const_for_false_in = false;
5921 bool use_const_for_true_in = false;
5922
5923 if (!cond->IsConstant()) {
5924 switch (cond_type) {
5925 default:
5926 switch (dst_type) {
5927 default:
5928 // Moving int on int condition.
5929 if (is_r6) {
5930 if (is_true_value_zero_constant) {
5931 // seleqz out_reg, false_reg, cond_reg
5932 can_move_conditionally = true;
5933 use_const_for_true_in = true;
5934 } else if (is_false_value_zero_constant) {
5935 // selnez out_reg, true_reg, cond_reg
5936 can_move_conditionally = true;
5937 use_const_for_false_in = true;
5938 } else if (materialized) {
5939 // Not materializing unmaterialized int conditions
5940 // to keep the instruction count low.
5941 // selnez AT, true_reg, cond_reg
5942 // seleqz TMP, false_reg, cond_reg
5943 // or out_reg, AT, TMP
5944 can_move_conditionally = true;
5945 }
5946 } else {
5947 // movn out_reg, true_reg/ZERO, cond_reg
5948 can_move_conditionally = true;
5949 use_const_for_true_in = is_true_value_zero_constant;
5950 }
5951 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005952 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005953 // Moving long on int condition.
5954 if (is_r6) {
5955 if (is_true_value_zero_constant) {
5956 // seleqz out_reg_lo, false_reg_lo, cond_reg
5957 // seleqz out_reg_hi, false_reg_hi, cond_reg
5958 can_move_conditionally = true;
5959 use_const_for_true_in = true;
5960 } else if (is_false_value_zero_constant) {
5961 // selnez out_reg_lo, true_reg_lo, cond_reg
5962 // selnez out_reg_hi, true_reg_hi, cond_reg
5963 can_move_conditionally = true;
5964 use_const_for_false_in = true;
5965 }
5966 // Other long conditional moves would generate 6+ instructions,
5967 // which is too many.
5968 } else {
5969 // movn out_reg_lo, true_reg_lo/ZERO, cond_reg
5970 // movn out_reg_hi, true_reg_hi/ZERO, cond_reg
5971 can_move_conditionally = true;
5972 use_const_for_true_in = is_true_value_zero_constant;
5973 }
5974 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005975 case DataType::Type::kFloat32:
5976 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005977 // Moving float/double on int condition.
5978 if (is_r6) {
5979 if (materialized) {
5980 // Not materializing unmaterialized int conditions
5981 // to keep the instruction count low.
5982 can_move_conditionally = true;
5983 if (is_true_value_zero_constant) {
5984 // sltu TMP, ZERO, cond_reg
5985 // mtc1 TMP, temp_cond_reg
5986 // seleqz.fmt out_reg, false_reg, temp_cond_reg
5987 use_const_for_true_in = true;
5988 } else if (is_false_value_zero_constant) {
5989 // sltu TMP, ZERO, cond_reg
5990 // mtc1 TMP, temp_cond_reg
5991 // selnez.fmt out_reg, true_reg, temp_cond_reg
5992 use_const_for_false_in = true;
5993 } else {
5994 // sltu TMP, ZERO, cond_reg
5995 // mtc1 TMP, temp_cond_reg
5996 // sel.fmt temp_cond_reg, false_reg, true_reg
5997 // mov.fmt out_reg, temp_cond_reg
5998 }
5999 }
6000 } else {
6001 // movn.fmt out_reg, true_reg, cond_reg
6002 can_move_conditionally = true;
6003 }
6004 break;
6005 }
6006 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006007 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006008 // We don't materialize long comparison now
6009 // and use conditional branches instead.
6010 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006011 case DataType::Type::kFloat32:
6012 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006013 switch (dst_type) {
6014 default:
6015 // Moving int on float/double condition.
6016 if (is_r6) {
6017 if (is_true_value_zero_constant) {
6018 // mfc1 TMP, temp_cond_reg
6019 // seleqz out_reg, false_reg, TMP
6020 can_move_conditionally = true;
6021 use_const_for_true_in = true;
6022 } else if (is_false_value_zero_constant) {
6023 // mfc1 TMP, temp_cond_reg
6024 // selnez out_reg, true_reg, TMP
6025 can_move_conditionally = true;
6026 use_const_for_false_in = true;
6027 } else {
6028 // mfc1 TMP, temp_cond_reg
6029 // selnez AT, true_reg, TMP
6030 // seleqz TMP, false_reg, TMP
6031 // or out_reg, AT, TMP
6032 can_move_conditionally = true;
6033 }
6034 } else {
6035 // movt out_reg, true_reg/ZERO, cc
6036 can_move_conditionally = true;
6037 use_const_for_true_in = is_true_value_zero_constant;
6038 }
6039 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006040 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006041 // Moving long on float/double condition.
6042 if (is_r6) {
6043 if (is_true_value_zero_constant) {
6044 // mfc1 TMP, temp_cond_reg
6045 // seleqz out_reg_lo, false_reg_lo, TMP
6046 // seleqz out_reg_hi, false_reg_hi, TMP
6047 can_move_conditionally = true;
6048 use_const_for_true_in = true;
6049 } else if (is_false_value_zero_constant) {
6050 // mfc1 TMP, temp_cond_reg
6051 // selnez out_reg_lo, true_reg_lo, TMP
6052 // selnez out_reg_hi, true_reg_hi, TMP
6053 can_move_conditionally = true;
6054 use_const_for_false_in = true;
6055 }
6056 // Other long conditional moves would generate 6+ instructions,
6057 // which is too many.
6058 } else {
6059 // movt out_reg_lo, true_reg_lo/ZERO, cc
6060 // movt out_reg_hi, true_reg_hi/ZERO, cc
6061 can_move_conditionally = true;
6062 use_const_for_true_in = is_true_value_zero_constant;
6063 }
6064 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006065 case DataType::Type::kFloat32:
6066 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006067 // Moving float/double on float/double condition.
6068 if (is_r6) {
6069 can_move_conditionally = true;
6070 if (is_true_value_zero_constant) {
6071 // seleqz.fmt out_reg, false_reg, temp_cond_reg
6072 use_const_for_true_in = true;
6073 } else if (is_false_value_zero_constant) {
6074 // selnez.fmt out_reg, true_reg, temp_cond_reg
6075 use_const_for_false_in = true;
6076 } else {
6077 // sel.fmt temp_cond_reg, false_reg, true_reg
6078 // mov.fmt out_reg, temp_cond_reg
6079 }
6080 } else {
6081 // movt.fmt out_reg, true_reg, cc
6082 can_move_conditionally = true;
6083 }
6084 break;
6085 }
6086 break;
6087 }
6088 }
6089
6090 if (can_move_conditionally) {
6091 DCHECK(!use_const_for_false_in || !use_const_for_true_in);
6092 } else {
6093 DCHECK(!use_const_for_false_in);
6094 DCHECK(!use_const_for_true_in);
6095 }
6096
6097 if (locations_to_set != nullptr) {
6098 if (use_const_for_false_in) {
6099 locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value));
6100 } else {
6101 locations_to_set->SetInAt(0,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006102 DataType::IsFloatingPointType(dst_type)
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006103 ? Location::RequiresFpuRegister()
6104 : Location::RequiresRegister());
6105 }
6106 if (use_const_for_true_in) {
6107 locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value));
6108 } else {
6109 locations_to_set->SetInAt(1,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006110 DataType::IsFloatingPointType(dst_type)
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006111 ? Location::RequiresFpuRegister()
6112 : Location::RequiresRegister());
6113 }
6114 if (materialized) {
6115 locations_to_set->SetInAt(2, Location::RequiresRegister());
6116 }
6117 // On R6 we don't require the output to be the same as the
6118 // first input for conditional moves unlike on R2.
6119 bool is_out_same_as_first_in = !can_move_conditionally || !is_r6;
6120 if (is_out_same_as_first_in) {
6121 locations_to_set->SetOut(Location::SameAsFirstInput());
6122 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006123 locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type)
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006124 ? Location::RequiresFpuRegister()
6125 : Location::RequiresRegister());
6126 }
6127 }
6128
6129 return can_move_conditionally;
6130}
6131
6132void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) {
6133 LocationSummary* locations = select->GetLocations();
6134 Location dst = locations->Out();
6135 Location src = locations->InAt(1);
6136 Register src_reg = ZERO;
6137 Register src_reg_high = ZERO;
6138 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
6139 Register cond_reg = TMP;
6140 int cond_cc = 0;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006141 DataType::Type cond_type = DataType::Type::kInt32;
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006142 bool cond_inverted = false;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006143 DataType::Type dst_type = select->GetType();
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006144
6145 if (IsBooleanValueOrMaterializedCondition(cond)) {
6146 cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>();
6147 } else {
6148 HCondition* condition = cond->AsCondition();
6149 LocationSummary* cond_locations = cond->GetLocations();
6150 IfCondition if_cond = condition->GetCondition();
6151 cond_type = condition->InputAt(0)->GetType();
6152 switch (cond_type) {
6153 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006154 DCHECK_NE(cond_type, DataType::Type::kInt64);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006155 cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg);
6156 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006157 case DataType::Type::kFloat32:
6158 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006159 cond_inverted = MaterializeFpCompareR2(if_cond,
6160 condition->IsGtBias(),
6161 cond_type,
6162 cond_locations,
6163 cond_cc);
6164 break;
6165 }
6166 }
6167
6168 DCHECK(dst.Equals(locations->InAt(0)));
6169 if (src.IsRegister()) {
6170 src_reg = src.AsRegister<Register>();
6171 } else if (src.IsRegisterPair()) {
6172 src_reg = src.AsRegisterPairLow<Register>();
6173 src_reg_high = src.AsRegisterPairHigh<Register>();
6174 } else if (src.IsConstant()) {
6175 DCHECK(src.GetConstant()->IsZeroBitPattern());
6176 }
6177
6178 switch (cond_type) {
6179 default:
6180 switch (dst_type) {
6181 default:
6182 if (cond_inverted) {
6183 __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg);
6184 } else {
6185 __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg);
6186 }
6187 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006188 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006189 if (cond_inverted) {
6190 __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg);
6191 __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg);
6192 } else {
6193 __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg);
6194 __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg);
6195 }
6196 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006197 case DataType::Type::kFloat32:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006198 if (cond_inverted) {
6199 __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
6200 } else {
6201 __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
6202 }
6203 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006204 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006205 if (cond_inverted) {
6206 __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
6207 } else {
6208 __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
6209 }
6210 break;
6211 }
6212 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006213 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006214 LOG(FATAL) << "Unreachable";
6215 UNREACHABLE();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006216 case DataType::Type::kFloat32:
6217 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006218 switch (dst_type) {
6219 default:
6220 if (cond_inverted) {
6221 __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc);
6222 } else {
6223 __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc);
6224 }
6225 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006226 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006227 if (cond_inverted) {
6228 __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc);
6229 __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc);
6230 } else {
6231 __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc);
6232 __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc);
6233 }
6234 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006235 case DataType::Type::kFloat32:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006236 if (cond_inverted) {
6237 __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
6238 } else {
6239 __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
6240 }
6241 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006242 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006243 if (cond_inverted) {
6244 __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
6245 } else {
6246 __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
6247 }
6248 break;
6249 }
6250 break;
6251 }
6252}
6253
6254void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) {
6255 LocationSummary* locations = select->GetLocations();
6256 Location dst = locations->Out();
6257 Location false_src = locations->InAt(0);
6258 Location true_src = locations->InAt(1);
6259 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
6260 Register cond_reg = TMP;
6261 FRegister fcond_reg = FTMP;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006262 DataType::Type cond_type = DataType::Type::kInt32;
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006263 bool cond_inverted = false;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006264 DataType::Type dst_type = select->GetType();
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006265
6266 if (IsBooleanValueOrMaterializedCondition(cond)) {
6267 cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>();
6268 } else {
6269 HCondition* condition = cond->AsCondition();
6270 LocationSummary* cond_locations = cond->GetLocations();
6271 IfCondition if_cond = condition->GetCondition();
6272 cond_type = condition->InputAt(0)->GetType();
6273 switch (cond_type) {
6274 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006275 DCHECK_NE(cond_type, DataType::Type::kInt64);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006276 cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg);
6277 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006278 case DataType::Type::kFloat32:
6279 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006280 cond_inverted = MaterializeFpCompareR6(if_cond,
6281 condition->IsGtBias(),
6282 cond_type,
6283 cond_locations,
6284 fcond_reg);
6285 break;
6286 }
6287 }
6288
6289 if (true_src.IsConstant()) {
6290 DCHECK(true_src.GetConstant()->IsZeroBitPattern());
6291 }
6292 if (false_src.IsConstant()) {
6293 DCHECK(false_src.GetConstant()->IsZeroBitPattern());
6294 }
6295
6296 switch (dst_type) {
6297 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006298 if (DataType::IsFloatingPointType(cond_type)) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006299 __ Mfc1(cond_reg, fcond_reg);
6300 }
6301 if (true_src.IsConstant()) {
6302 if (cond_inverted) {
6303 __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg);
6304 } else {
6305 __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg);
6306 }
6307 } else if (false_src.IsConstant()) {
6308 if (cond_inverted) {
6309 __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg);
6310 } else {
6311 __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg);
6312 }
6313 } else {
6314 DCHECK_NE(cond_reg, AT);
6315 if (cond_inverted) {
6316 __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg);
6317 __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg);
6318 } else {
6319 __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg);
6320 __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg);
6321 }
6322 __ Or(dst.AsRegister<Register>(), AT, TMP);
6323 }
6324 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006325 case DataType::Type::kInt64: {
6326 if (DataType::IsFloatingPointType(cond_type)) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006327 __ Mfc1(cond_reg, fcond_reg);
6328 }
6329 Register dst_lo = dst.AsRegisterPairLow<Register>();
6330 Register dst_hi = dst.AsRegisterPairHigh<Register>();
6331 if (true_src.IsConstant()) {
6332 Register src_lo = false_src.AsRegisterPairLow<Register>();
6333 Register src_hi = false_src.AsRegisterPairHigh<Register>();
6334 if (cond_inverted) {
6335 __ Selnez(dst_lo, src_lo, cond_reg);
6336 __ Selnez(dst_hi, src_hi, cond_reg);
6337 } else {
6338 __ Seleqz(dst_lo, src_lo, cond_reg);
6339 __ Seleqz(dst_hi, src_hi, cond_reg);
6340 }
6341 } else {
6342 DCHECK(false_src.IsConstant());
6343 Register src_lo = true_src.AsRegisterPairLow<Register>();
6344 Register src_hi = true_src.AsRegisterPairHigh<Register>();
6345 if (cond_inverted) {
6346 __ Seleqz(dst_lo, src_lo, cond_reg);
6347 __ Seleqz(dst_hi, src_hi, cond_reg);
6348 } else {
6349 __ Selnez(dst_lo, src_lo, cond_reg);
6350 __ Selnez(dst_hi, src_hi, cond_reg);
6351 }
6352 }
6353 break;
6354 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006355 case DataType::Type::kFloat32: {
6356 if (!DataType::IsFloatingPointType(cond_type)) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006357 // sel*.fmt tests bit 0 of the condition register, account for that.
6358 __ Sltu(TMP, ZERO, cond_reg);
6359 __ Mtc1(TMP, fcond_reg);
6360 }
6361 FRegister dst_reg = dst.AsFpuRegister<FRegister>();
6362 if (true_src.IsConstant()) {
6363 FRegister src_reg = false_src.AsFpuRegister<FRegister>();
6364 if (cond_inverted) {
6365 __ SelnezS(dst_reg, src_reg, fcond_reg);
6366 } else {
6367 __ SeleqzS(dst_reg, src_reg, fcond_reg);
6368 }
6369 } else if (false_src.IsConstant()) {
6370 FRegister src_reg = true_src.AsFpuRegister<FRegister>();
6371 if (cond_inverted) {
6372 __ SeleqzS(dst_reg, src_reg, fcond_reg);
6373 } else {
6374 __ SelnezS(dst_reg, src_reg, fcond_reg);
6375 }
6376 } else {
6377 if (cond_inverted) {
6378 __ SelS(fcond_reg,
6379 true_src.AsFpuRegister<FRegister>(),
6380 false_src.AsFpuRegister<FRegister>());
6381 } else {
6382 __ SelS(fcond_reg,
6383 false_src.AsFpuRegister<FRegister>(),
6384 true_src.AsFpuRegister<FRegister>());
6385 }
6386 __ MovS(dst_reg, fcond_reg);
6387 }
6388 break;
6389 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006390 case DataType::Type::kFloat64: {
6391 if (!DataType::IsFloatingPointType(cond_type)) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006392 // sel*.fmt tests bit 0 of the condition register, account for that.
6393 __ Sltu(TMP, ZERO, cond_reg);
6394 __ Mtc1(TMP, fcond_reg);
6395 }
6396 FRegister dst_reg = dst.AsFpuRegister<FRegister>();
6397 if (true_src.IsConstant()) {
6398 FRegister src_reg = false_src.AsFpuRegister<FRegister>();
6399 if (cond_inverted) {
6400 __ SelnezD(dst_reg, src_reg, fcond_reg);
6401 } else {
6402 __ SeleqzD(dst_reg, src_reg, fcond_reg);
6403 }
6404 } else if (false_src.IsConstant()) {
6405 FRegister src_reg = true_src.AsFpuRegister<FRegister>();
6406 if (cond_inverted) {
6407 __ SeleqzD(dst_reg, src_reg, fcond_reg);
6408 } else {
6409 __ SelnezD(dst_reg, src_reg, fcond_reg);
6410 }
6411 } else {
6412 if (cond_inverted) {
6413 __ SelD(fcond_reg,
6414 true_src.AsFpuRegister<FRegister>(),
6415 false_src.AsFpuRegister<FRegister>());
6416 } else {
6417 __ SelD(fcond_reg,
6418 false_src.AsFpuRegister<FRegister>(),
6419 true_src.AsFpuRegister<FRegister>());
6420 }
6421 __ MovD(dst_reg, fcond_reg);
6422 }
6423 break;
6424 }
6425 }
6426}
6427
Goran Jakovljevicc6418422016-12-05 16:31:55 +01006428void LocationsBuilderMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006429 LocationSummary* locations = new (GetGraph()->GetAllocator())
Goran Jakovljevicc6418422016-12-05 16:31:55 +01006430 LocationSummary(flag, LocationSummary::kNoCall);
6431 locations->SetOut(Location::RequiresRegister());
Mingyao Yang063fc772016-08-02 11:02:54 -07006432}
6433
Goran Jakovljevicc6418422016-12-05 16:31:55 +01006434void InstructionCodeGeneratorMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
6435 __ LoadFromOffset(kLoadWord,
6436 flag->GetLocations()->Out().AsRegister<Register>(),
6437 SP,
6438 codegen_->GetStackOffsetOfShouldDeoptimizeFlag());
Mingyao Yang063fc772016-08-02 11:02:54 -07006439}
6440
David Brazdil74eb1b22015-12-14 11:44:01 +00006441void LocationsBuilderMIPS::VisitSelect(HSelect* select) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006442 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006443 CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations);
David Brazdil74eb1b22015-12-14 11:44:01 +00006444}
6445
6446void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006447 bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6();
6448 if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) {
6449 if (is_r6) {
6450 GenConditionalMoveR6(select);
6451 } else {
6452 GenConditionalMoveR2(select);
6453 }
6454 } else {
6455 LocationSummary* locations = select->GetLocations();
6456 MipsLabel false_target;
6457 GenerateTestAndBranch(select,
6458 /* condition_input_index */ 2,
6459 /* true_target */ nullptr,
6460 &false_target);
6461 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
6462 __ Bind(&false_target);
6463 }
David Brazdil74eb1b22015-12-14 11:44:01 +00006464}
6465
David Srbecky0cf44932015-12-09 14:09:59 +00006466void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006467 new (GetGraph()->GetAllocator()) LocationSummary(info);
David Srbecky0cf44932015-12-09 14:09:59 +00006468}
6469
David Srbeckyd28f4a02016-03-14 17:14:24 +00006470void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) {
6471 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00006472}
6473
6474void CodeGeneratorMIPS::GenerateNop() {
6475 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00006476}
6477
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006478void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006479 DataType::Type field_type = field_info.GetFieldType();
6480 bool is_wide = (field_type == DataType::Type::kInt64) || (field_type == DataType::Type::kFloat64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006481 bool generate_volatile = field_info.IsVolatile() && is_wide;
Alexey Frunze15958152017-02-09 19:08:30 -08006482 bool object_field_get_with_read_barrier =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006483 kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference);
Vladimir Markoca6fff82017-10-03 14:49:14 +01006484 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
Alexey Frunze15958152017-02-09 19:08:30 -08006485 instruction,
6486 generate_volatile
6487 ? LocationSummary::kCallOnMainOnly
6488 : (object_field_get_with_read_barrier
6489 ? LocationSummary::kCallOnSlowPath
6490 : LocationSummary::kNoCall));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006491
Alexey Frunzec61c0762017-04-10 13:54:23 -07006492 if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
6493 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
6494 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006495 locations->SetInAt(0, Location::RequiresRegister());
6496 if (generate_volatile) {
6497 InvokeRuntimeCallingConvention calling_convention;
6498 // need A0 to hold base + offset
6499 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006500 if (field_type == DataType::Type::kInt64) {
6501 locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kInt64));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006502 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006503 // Use Location::Any() to prevent situations when running out of available fp registers.
6504 locations->SetOut(Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006505 // Need some temp core regs since FP results are returned in core registers
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006506 Location reg = calling_convention.GetReturnLocation(DataType::Type::kInt64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006507 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>()));
6508 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>()));
6509 }
6510 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006511 if (DataType::IsFloatingPointType(instruction->GetType())) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006512 locations->SetOut(Location::RequiresFpuRegister());
6513 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08006514 // The output overlaps in the case of an object field get with
6515 // read barriers enabled: we do not want the move to overwrite the
6516 // object's location, as we need it to emit the read barrier.
6517 locations->SetOut(Location::RequiresRegister(),
6518 object_field_get_with_read_barrier
6519 ? Location::kOutputOverlap
6520 : Location::kNoOutputOverlap);
6521 }
6522 if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
6523 // We need a temporary register for the read barrier marking slow
6524 // path in CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier.
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006525 if (!kBakerReadBarrierThunksEnableForFields) {
6526 locations->AddTemp(Location::RequiresRegister());
6527 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006528 }
6529 }
6530}
6531
6532void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction,
6533 const FieldInfo& field_info,
6534 uint32_t dex_pc) {
Vladimir Marko61b92282017-10-11 13:23:17 +01006535 DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType()));
6536 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006537 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08006538 Location obj_loc = locations->InAt(0);
6539 Register obj = obj_loc.AsRegister<Register>();
6540 Location dst_loc = locations->Out();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006541 LoadOperandType load_type = kLoadUnsignedByte;
6542 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01006543 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Tijana Jakovljevic57433862017-01-17 16:59:03 +01006544 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006545
6546 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006547 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006548 case DataType::Type::kUint8:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006549 load_type = kLoadUnsignedByte;
6550 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006551 case DataType::Type::kInt8:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006552 load_type = kLoadSignedByte;
6553 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006554 case DataType::Type::kUint16:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006555 load_type = kLoadUnsignedHalfword;
6556 break;
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006557 case DataType::Type::kInt16:
6558 load_type = kLoadSignedHalfword;
6559 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006560 case DataType::Type::kInt32:
6561 case DataType::Type::kFloat32:
6562 case DataType::Type::kReference:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006563 load_type = kLoadWord;
6564 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006565 case DataType::Type::kInt64:
6566 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006567 load_type = kLoadDoubleword;
6568 break;
Aart Bik66c158e2018-01-31 12:55:04 -08006569 case DataType::Type::kUint32:
6570 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006571 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006572 LOG(FATAL) << "Unreachable type " << type;
6573 UNREACHABLE();
6574 }
6575
6576 if (is_volatile && load_type == kLoadDoubleword) {
6577 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01006578 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006579 // Do implicit Null check
Goran Jakovljevic2e61a572017-10-23 08:58:15 +02006580 __ LoadFromOffset(kLoadWord,
6581 ZERO,
6582 locations->GetTemp(0).AsRegister<Register>(),
6583 0,
6584 null_checker);
Serban Constantinescufca16662016-07-14 09:21:59 +01006585 codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006586 CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006587 if (type == DataType::Type::kFloat64) {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006588 // FP results are returned in core registers. Need to move them.
Alexey Frunze15958152017-02-09 19:08:30 -08006589 if (dst_loc.IsFpuRegister()) {
6590 __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), dst_loc.AsFpuRegister<FRegister>());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006591 __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
Alexey Frunze15958152017-02-09 19:08:30 -08006592 dst_loc.AsFpuRegister<FRegister>());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006593 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08006594 DCHECK(dst_loc.IsDoubleStackSlot());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006595 __ StoreToOffset(kStoreWord,
6596 locations->GetTemp(1).AsRegister<Register>(),
6597 SP,
Alexey Frunze15958152017-02-09 19:08:30 -08006598 dst_loc.GetStackIndex());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006599 __ StoreToOffset(kStoreWord,
6600 locations->GetTemp(2).AsRegister<Register>(),
6601 SP,
Alexey Frunze15958152017-02-09 19:08:30 -08006602 dst_loc.GetStackIndex() + 4);
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006603 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006604 }
6605 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006606 if (type == DataType::Type::kReference) {
Alexey Frunze15958152017-02-09 19:08:30 -08006607 // /* HeapReference<Object> */ dst = *(obj + offset)
6608 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006609 Location temp_loc =
6610 kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0);
Alexey Frunze15958152017-02-09 19:08:30 -08006611 // Note that a potential implicit null check is handled in this
6612 // CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier call.
6613 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
6614 dst_loc,
6615 obj,
6616 offset,
6617 temp_loc,
6618 /* needs_null_check */ true);
6619 if (is_volatile) {
6620 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
6621 }
6622 } else {
6623 __ LoadFromOffset(kLoadWord, dst_loc.AsRegister<Register>(), obj, offset, null_checker);
6624 if (is_volatile) {
6625 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
6626 }
6627 // If read barriers are enabled, emit read barriers other than
6628 // Baker's using a slow path (and also unpoison the loaded
6629 // reference, if heap poisoning is enabled).
6630 codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset);
6631 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006632 } else if (!DataType::IsFloatingPointType(type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006633 Register dst;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006634 if (type == DataType::Type::kInt64) {
Alexey Frunze15958152017-02-09 19:08:30 -08006635 DCHECK(dst_loc.IsRegisterPair());
6636 dst = dst_loc.AsRegisterPairLow<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006637 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08006638 DCHECK(dst_loc.IsRegister());
6639 dst = dst_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006640 }
Alexey Frunze2923db72016-08-20 01:55:47 -07006641 __ LoadFromOffset(load_type, dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006642 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08006643 DCHECK(dst_loc.IsFpuRegister());
6644 FRegister dst = dst_loc.AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006645 if (type == DataType::Type::kFloat32) {
Alexey Frunze2923db72016-08-20 01:55:47 -07006646 __ LoadSFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006647 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07006648 __ LoadDFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006649 }
6650 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006651 }
6652
Alexey Frunze15958152017-02-09 19:08:30 -08006653 // Memory barriers, in the case of references, are handled in the
6654 // previous switch statement.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006655 if (is_volatile && (type != DataType::Type::kReference)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006656 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
6657 }
6658}
6659
6660void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006661 DataType::Type field_type = field_info.GetFieldType();
6662 bool is_wide = (field_type == DataType::Type::kInt64) || (field_type == DataType::Type::kFloat64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006663 bool generate_volatile = field_info.IsVolatile() && is_wide;
Vladimir Markoca6fff82017-10-03 14:49:14 +01006664 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006665 instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006666
6667 locations->SetInAt(0, Location::RequiresRegister());
6668 if (generate_volatile) {
6669 InvokeRuntimeCallingConvention calling_convention;
6670 // need A0 to hold base + offset
6671 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006672 if (field_type == DataType::Type::kInt64) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006673 locations->SetInAt(1, Location::RegisterPairLocation(
6674 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
6675 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006676 // Use Location::Any() to prevent situations when running out of available fp registers.
6677 locations->SetInAt(1, Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006678 // Pass FP parameters in core registers.
6679 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
6680 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
6681 }
6682 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006683 if (DataType::IsFloatingPointType(field_type)) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006684 locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006685 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006686 locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006687 }
6688 }
6689}
6690
6691void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction,
6692 const FieldInfo& field_info,
Goran Jakovljevice114da22016-12-26 14:21:43 +01006693 uint32_t dex_pc,
6694 bool value_can_be_null) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006695 DataType::Type type = field_info.GetFieldType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006696 LocationSummary* locations = instruction->GetLocations();
6697 Register obj = locations->InAt(0).AsRegister<Register>();
Alexey Frunzef58b2482016-09-02 22:14:06 -07006698 Location value_location = locations->InAt(1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006699 StoreOperandType store_type = kStoreByte;
6700 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01006701 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Alexey Frunzec061de12017-02-14 13:27:23 -08006702 bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1));
Tijana Jakovljevic57433862017-01-17 16:59:03 +01006703 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006704
6705 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006706 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006707 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006708 case DataType::Type::kInt8:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006709 store_type = kStoreByte;
6710 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006711 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006712 case DataType::Type::kInt16:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006713 store_type = kStoreHalfword;
6714 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006715 case DataType::Type::kInt32:
6716 case DataType::Type::kFloat32:
6717 case DataType::Type::kReference:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006718 store_type = kStoreWord;
6719 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006720 case DataType::Type::kInt64:
6721 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006722 store_type = kStoreDoubleword;
6723 break;
Aart Bik66c158e2018-01-31 12:55:04 -08006724 case DataType::Type::kUint32:
6725 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006726 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006727 LOG(FATAL) << "Unreachable type " << type;
6728 UNREACHABLE();
6729 }
6730
6731 if (is_volatile) {
6732 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
6733 }
6734
6735 if (is_volatile && store_type == kStoreDoubleword) {
6736 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01006737 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006738 // Do implicit Null check.
Goran Jakovljevic2e61a572017-10-23 08:58:15 +02006739 __ LoadFromOffset(kLoadWord,
6740 ZERO,
6741 locations->GetTemp(0).AsRegister<Register>(),
6742 0,
6743 null_checker);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006744 if (type == DataType::Type::kFloat64) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006745 // Pass FP parameters in core registers.
Alexey Frunzef58b2482016-09-02 22:14:06 -07006746 if (value_location.IsFpuRegister()) {
6747 __ Mfc1(locations->GetTemp(1).AsRegister<Register>(),
6748 value_location.AsFpuRegister<FRegister>());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006749 __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
Alexey Frunzef58b2482016-09-02 22:14:06 -07006750 value_location.AsFpuRegister<FRegister>());
6751 } else if (value_location.IsDoubleStackSlot()) {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006752 __ LoadFromOffset(kLoadWord,
6753 locations->GetTemp(1).AsRegister<Register>(),
6754 SP,
Alexey Frunzef58b2482016-09-02 22:14:06 -07006755 value_location.GetStackIndex());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006756 __ LoadFromOffset(kLoadWord,
6757 locations->GetTemp(2).AsRegister<Register>(),
6758 SP,
Alexey Frunzef58b2482016-09-02 22:14:06 -07006759 value_location.GetStackIndex() + 4);
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006760 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006761 DCHECK(value_location.IsConstant());
6762 DCHECK(value_location.GetConstant()->IsDoubleConstant());
6763 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006764 __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(),
6765 locations->GetTemp(1).AsRegister<Register>(),
6766 value);
6767 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006768 }
Serban Constantinescufca16662016-07-14 09:21:59 +01006769 codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006770 CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>();
6771 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006772 if (value_location.IsConstant()) {
6773 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
6774 __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006775 } else if (!DataType::IsFloatingPointType(type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006776 Register src;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006777 if (type == DataType::Type::kInt64) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006778 src = value_location.AsRegisterPairLow<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006779 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006780 src = value_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006781 }
Alexey Frunzec061de12017-02-14 13:27:23 -08006782 if (kPoisonHeapReferences && needs_write_barrier) {
6783 // Note that in the case where `value` is a null reference,
6784 // we do not enter this block, as a null reference does not
6785 // need poisoning.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006786 DCHECK_EQ(type, DataType::Type::kReference);
Alexey Frunzec061de12017-02-14 13:27:23 -08006787 __ PoisonHeapReference(TMP, src);
6788 __ StoreToOffset(store_type, TMP, obj, offset, null_checker);
6789 } else {
6790 __ StoreToOffset(store_type, src, obj, offset, null_checker);
6791 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006792 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006793 FRegister src = value_location.AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006794 if (type == DataType::Type::kFloat32) {
Alexey Frunze2923db72016-08-20 01:55:47 -07006795 __ StoreSToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006796 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07006797 __ StoreDToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006798 }
6799 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006800 }
6801
Alexey Frunzec061de12017-02-14 13:27:23 -08006802 if (needs_write_barrier) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006803 Register src = value_location.AsRegister<Register>();
Goran Jakovljevice114da22016-12-26 14:21:43 +01006804 codegen_->MarkGCCard(obj, src, value_can_be_null);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006805 }
6806
6807 if (is_volatile) {
6808 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
6809 }
6810}
6811
6812void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
6813 HandleFieldGet(instruction, instruction->GetFieldInfo());
6814}
6815
6816void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
6817 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
6818}
6819
6820void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
6821 HandleFieldSet(instruction, instruction->GetFieldInfo());
6822}
6823
6824void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Goran Jakovljevice114da22016-12-26 14:21:43 +01006825 HandleFieldSet(instruction,
6826 instruction->GetFieldInfo(),
6827 instruction->GetDexPc(),
6828 instruction->GetValueCanBeNull());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006829}
6830
Alexey Frunze15958152017-02-09 19:08:30 -08006831void InstructionCodeGeneratorMIPS::GenerateReferenceLoadOneRegister(
6832 HInstruction* instruction,
6833 Location out,
6834 uint32_t offset,
6835 Location maybe_temp,
6836 ReadBarrierOption read_barrier_option) {
6837 Register out_reg = out.AsRegister<Register>();
6838 if (read_barrier_option == kWithReadBarrier) {
6839 CHECK(kEmitCompilerReadBarrier);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006840 if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) {
6841 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
6842 }
Alexey Frunze15958152017-02-09 19:08:30 -08006843 if (kUseBakerReadBarrier) {
6844 // Load with fast path based Baker's read barrier.
6845 // /* HeapReference<Object> */ out = *(out + offset)
6846 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
6847 out,
6848 out_reg,
6849 offset,
6850 maybe_temp,
6851 /* needs_null_check */ false);
6852 } else {
6853 // Load with slow path based read barrier.
6854 // Save the value of `out` into `maybe_temp` before overwriting it
6855 // in the following move operation, as we will need it for the
6856 // read barrier below.
6857 __ Move(maybe_temp.AsRegister<Register>(), out_reg);
6858 // /* HeapReference<Object> */ out = *(out + offset)
6859 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
6860 codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset);
6861 }
6862 } else {
6863 // Plain load with no read barrier.
6864 // /* HeapReference<Object> */ out = *(out + offset)
6865 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
6866 __ MaybeUnpoisonHeapReference(out_reg);
6867 }
6868}
6869
6870void InstructionCodeGeneratorMIPS::GenerateReferenceLoadTwoRegisters(
6871 HInstruction* instruction,
6872 Location out,
6873 Location obj,
6874 uint32_t offset,
6875 Location maybe_temp,
6876 ReadBarrierOption read_barrier_option) {
6877 Register out_reg = out.AsRegister<Register>();
6878 Register obj_reg = obj.AsRegister<Register>();
6879 if (read_barrier_option == kWithReadBarrier) {
6880 CHECK(kEmitCompilerReadBarrier);
6881 if (kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006882 if (!kBakerReadBarrierThunksEnableForFields) {
6883 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
6884 }
Alexey Frunze15958152017-02-09 19:08:30 -08006885 // Load with fast path based Baker's read barrier.
6886 // /* HeapReference<Object> */ out = *(obj + offset)
6887 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
6888 out,
6889 obj_reg,
6890 offset,
6891 maybe_temp,
6892 /* needs_null_check */ false);
6893 } else {
6894 // Load with slow path based read barrier.
6895 // /* HeapReference<Object> */ out = *(obj + offset)
6896 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6897 codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset);
6898 }
6899 } else {
6900 // Plain load with no read barrier.
6901 // /* HeapReference<Object> */ out = *(obj + offset)
6902 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6903 __ MaybeUnpoisonHeapReference(out_reg);
6904 }
6905}
6906
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006907static inline int GetBakerMarkThunkNumber(Register reg) {
6908 static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 21, "Expecting equal");
6909 if (reg >= V0 && reg <= T7) { // 14 consequtive regs.
6910 return reg - V0;
6911 } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs.
6912 return 14 + (reg - S2);
6913 } else if (reg == FP) { // One more.
6914 return 20;
6915 }
6916 LOG(FATAL) << "Unexpected register " << reg;
6917 UNREACHABLE();
6918}
6919
6920static inline int GetBakerMarkFieldArrayThunkDisplacement(Register reg, bool short_offset) {
6921 int num = GetBakerMarkThunkNumber(reg) +
6922 (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0);
6923 return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE;
6924}
6925
6926static inline int GetBakerMarkGcRootThunkDisplacement(Register reg) {
6927 return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE +
6928 BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET;
6929}
6930
Alexey Frunze15958152017-02-09 19:08:30 -08006931void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(HInstruction* instruction,
6932 Location root,
6933 Register obj,
6934 uint32_t offset,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006935 ReadBarrierOption read_barrier_option,
6936 MipsLabel* label_low) {
6937 bool reordering;
6938 if (label_low != nullptr) {
6939 DCHECK_EQ(offset, 0x5678u);
6940 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07006941 Register root_reg = root.AsRegister<Register>();
Alexey Frunze15958152017-02-09 19:08:30 -08006942 if (read_barrier_option == kWithReadBarrier) {
6943 DCHECK(kEmitCompilerReadBarrier);
6944 if (kUseBakerReadBarrier) {
6945 // Fast path implementation of art::ReadBarrier::BarrierForRoot when
6946 // Baker's read barrier are used:
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006947 if (kBakerReadBarrierThunksEnableForGcRoots) {
6948 // Note that we do not actually check the value of `GetIsGcMarking()`
6949 // to decide whether to mark the loaded GC root or not. Instead, we
6950 // load into `temp` (T9) the read barrier mark introspection entrypoint.
6951 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
6952 // vice versa.
6953 //
6954 // We use thunks for the slow path. That thunk checks the reference
6955 // and jumps to the entrypoint if needed.
6956 //
6957 // temp = Thread::Current()->pReadBarrierMarkReg00
6958 // // AKA &art_quick_read_barrier_mark_introspection.
6959 // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load.
6960 // if (temp != nullptr) {
6961 // temp = &gc_root_thunk<root_reg>
6962 // root = temp(root)
6963 // }
Alexey Frunze15958152017-02-09 19:08:30 -08006964
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006965 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
6966 const int32_t entry_point_offset =
6967 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0);
6968 const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg);
6969 int16_t offset_low = Low16Bits(offset);
6970 int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign
6971 // extension in lw.
6972 bool short_offset = IsInt<16>(static_cast<int32_t>(offset));
6973 Register base = short_offset ? obj : TMP;
6974 // Loading the entrypoint does not require a load acquire since it is only changed when
6975 // threads are suspended or running a checkpoint.
6976 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
6977 reordering = __ SetReorder(false);
6978 if (!short_offset) {
6979 DCHECK(!label_low);
6980 __ AddUpper(base, obj, offset_high);
6981 }
Alexey Frunze0cab6562017-07-25 15:19:36 -07006982 MipsLabel skip_call;
6983 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006984 if (label_low != nullptr) {
6985 DCHECK(short_offset);
6986 __ Bind(label_low);
6987 }
6988 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6989 __ LoadFromOffset(kLoadWord, root_reg, base, offset_low); // Single instruction
6990 // in delay slot.
6991 if (isR6) {
6992 __ Jialc(T9, thunk_disp);
6993 } else {
6994 __ Addiu(T9, T9, thunk_disp);
6995 __ Jalr(T9);
6996 __ Nop();
6997 }
Alexey Frunze0cab6562017-07-25 15:19:36 -07006998 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006999 __ SetReorder(reordering);
7000 } else {
7001 // Note that we do not actually check the value of `GetIsGcMarking()`
7002 // to decide whether to mark the loaded GC root or not. Instead, we
7003 // load into `temp` (T9) the read barrier mark entry point corresponding
7004 // to register `root`. If `temp` is null, it means that `GetIsGcMarking()`
7005 // is false, and vice versa.
7006 //
7007 // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load.
7008 // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg()
7009 // if (temp != null) {
7010 // root = temp(root)
7011 // }
Alexey Frunze15958152017-02-09 19:08:30 -08007012
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007013 if (label_low != nullptr) {
7014 reordering = __ SetReorder(false);
7015 __ Bind(label_low);
7016 }
7017 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
7018 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
7019 if (label_low != nullptr) {
7020 __ SetReorder(reordering);
7021 }
7022 static_assert(
7023 sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>),
7024 "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> "
7025 "have different sizes.");
7026 static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t),
7027 "art::mirror::CompressedReference<mirror::Object> and int32_t "
7028 "have different sizes.");
Alexey Frunze15958152017-02-09 19:08:30 -08007029
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007030 // Slow path marking the GC root `root`.
7031 Location temp = Location::RegisterLocation(T9);
7032 SlowPathCodeMIPS* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01007033 new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS(
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007034 instruction,
7035 root,
7036 /*entrypoint*/ temp);
7037 codegen_->AddSlowPath(slow_path);
7038
7039 const int32_t entry_point_offset =
7040 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(root.reg() - 1);
7041 // Loading the entrypoint does not require a load acquire since it is only changed when
7042 // threads are suspended or running a checkpoint.
7043 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset);
7044 __ Bnez(temp.AsRegister<Register>(), slow_path->GetEntryLabel());
7045 __ Bind(slow_path->GetExitLabel());
7046 }
Alexey Frunze15958152017-02-09 19:08:30 -08007047 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007048 if (label_low != nullptr) {
7049 reordering = __ SetReorder(false);
7050 __ Bind(label_low);
7051 }
Alexey Frunze15958152017-02-09 19:08:30 -08007052 // GC root loaded through a slow path for read barriers other
7053 // than Baker's.
7054 // /* GcRoot<mirror::Object>* */ root = obj + offset
7055 __ Addiu32(root_reg, obj, offset);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007056 if (label_low != nullptr) {
7057 __ SetReorder(reordering);
7058 }
Alexey Frunze15958152017-02-09 19:08:30 -08007059 // /* mirror::Object* */ root = root->Read()
7060 codegen_->GenerateReadBarrierForRootSlow(instruction, root, root);
7061 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007062 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007063 if (label_low != nullptr) {
7064 reordering = __ SetReorder(false);
7065 __ Bind(label_low);
7066 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007067 // Plain GC root load with no read barrier.
7068 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
7069 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
7070 // Note that GC roots are not affected by heap poisoning, thus we
7071 // do not have to unpoison `root_reg` here.
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007072 if (label_low != nullptr) {
7073 __ SetReorder(reordering);
7074 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007075 }
7076}
7077
Alexey Frunze15958152017-02-09 19:08:30 -08007078void CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
7079 Location ref,
7080 Register obj,
7081 uint32_t offset,
7082 Location temp,
7083 bool needs_null_check) {
7084 DCHECK(kEmitCompilerReadBarrier);
7085 DCHECK(kUseBakerReadBarrier);
7086
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007087 if (kBakerReadBarrierThunksEnableForFields) {
7088 // Note that we do not actually check the value of `GetIsGcMarking()`
7089 // to decide whether to mark the loaded reference or not. Instead, we
7090 // load into `temp` (T9) the read barrier mark introspection entrypoint.
7091 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
7092 // vice versa.
7093 //
7094 // We use thunks for the slow path. That thunk checks the reference
7095 // and jumps to the entrypoint if needed. If the holder is not gray,
7096 // it issues a load-load memory barrier and returns to the original
7097 // reference load.
7098 //
7099 // temp = Thread::Current()->pReadBarrierMarkReg00
7100 // // AKA &art_quick_read_barrier_mark_introspection.
7101 // if (temp != nullptr) {
7102 // temp = &field_array_thunk<holder_reg>
7103 // temp()
7104 // }
7105 // not_gray_return_address:
7106 // // If the offset is too large to fit into the lw instruction, we
7107 // // use an adjusted base register (TMP) here. This register
7108 // // receives bits 16 ... 31 of the offset before the thunk invocation
7109 // // and the thunk benefits from it.
7110 // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load.
7111 // gray_return_address:
7112
7113 DCHECK(temp.IsInvalid());
7114 bool isR6 = GetInstructionSetFeatures().IsR6();
7115 int16_t offset_low = Low16Bits(offset);
7116 int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lw.
7117 bool short_offset = IsInt<16>(static_cast<int32_t>(offset));
7118 bool reordering = __ SetReorder(false);
7119 const int32_t entry_point_offset =
7120 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0);
7121 // There may have or may have not been a null check if the field offset is smaller than
7122 // the page size.
7123 // There must've been a null check in case it's actually a load from an array.
7124 // We will, however, perform an explicit null check in the thunk as it's easier to
7125 // do it than not.
7126 if (instruction->IsArrayGet()) {
7127 DCHECK(!needs_null_check);
7128 }
7129 const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset);
7130 // Loading the entrypoint does not require a load acquire since it is only changed when
7131 // threads are suspended or running a checkpoint.
7132 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
7133 Register ref_reg = ref.AsRegister<Register>();
7134 Register base = short_offset ? obj : TMP;
Alexey Frunze0cab6562017-07-25 15:19:36 -07007135 MipsLabel skip_call;
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007136 if (short_offset) {
7137 if (isR6) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07007138 __ Beqzc(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007139 __ Nop(); // In forbidden slot.
7140 __ Jialc(T9, thunk_disp);
7141 } else {
Alexey Frunze0cab6562017-07-25 15:19:36 -07007142 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007143 __ Addiu(T9, T9, thunk_disp); // In delay slot.
7144 __ Jalr(T9);
7145 __ Nop(); // In delay slot.
7146 }
Alexey Frunze0cab6562017-07-25 15:19:36 -07007147 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007148 } else {
7149 if (isR6) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07007150 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007151 __ Aui(base, obj, offset_high); // In delay slot.
7152 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07007153 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007154 } else {
7155 __ Lui(base, offset_high);
Alexey Frunze0cab6562017-07-25 15:19:36 -07007156 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007157 __ Addiu(T9, T9, thunk_disp); // In delay slot.
7158 __ Jalr(T9);
Alexey Frunze0cab6562017-07-25 15:19:36 -07007159 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007160 __ Addu(base, base, obj); // In delay slot.
7161 }
7162 }
7163 // /* HeapReference<Object> */ ref = *(obj + offset)
7164 __ LoadFromOffset(kLoadWord, ref_reg, base, offset_low); // Single instruction.
7165 if (needs_null_check) {
7166 MaybeRecordImplicitNullCheck(instruction);
7167 }
7168 __ MaybeUnpoisonHeapReference(ref_reg);
7169 __ SetReorder(reordering);
7170 return;
7171 }
7172
Alexey Frunze15958152017-02-09 19:08:30 -08007173 // /* HeapReference<Object> */ ref = *(obj + offset)
7174 Location no_index = Location::NoLocation();
7175 ScaleFactor no_scale_factor = TIMES_1;
7176 GenerateReferenceLoadWithBakerReadBarrier(instruction,
7177 ref,
7178 obj,
7179 offset,
7180 no_index,
7181 no_scale_factor,
7182 temp,
7183 needs_null_check);
7184}
7185
7186void CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
7187 Location ref,
7188 Register obj,
7189 uint32_t data_offset,
7190 Location index,
7191 Location temp,
7192 bool needs_null_check) {
7193 DCHECK(kEmitCompilerReadBarrier);
7194 DCHECK(kUseBakerReadBarrier);
7195
7196 static_assert(
7197 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
7198 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007199 ScaleFactor scale_factor = TIMES_4;
7200
7201 if (kBakerReadBarrierThunksEnableForArrays) {
7202 // Note that we do not actually check the value of `GetIsGcMarking()`
7203 // to decide whether to mark the loaded reference or not. Instead, we
7204 // load into `temp` (T9) the read barrier mark introspection entrypoint.
7205 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
7206 // vice versa.
7207 //
7208 // We use thunks for the slow path. That thunk checks the reference
7209 // and jumps to the entrypoint if needed. If the holder is not gray,
7210 // it issues a load-load memory barrier and returns to the original
7211 // reference load.
7212 //
7213 // temp = Thread::Current()->pReadBarrierMarkReg00
7214 // // AKA &art_quick_read_barrier_mark_introspection.
7215 // if (temp != nullptr) {
7216 // temp = &field_array_thunk<holder_reg>
7217 // temp()
7218 // }
7219 // not_gray_return_address:
7220 // // The element address is pre-calculated in the TMP register before the
7221 // // thunk invocation and the thunk benefits from it.
7222 // HeapReference<mirror::Object> reference = data[index]; // Original reference load.
7223 // gray_return_address:
7224
7225 DCHECK(temp.IsInvalid());
7226 DCHECK(index.IsValid());
7227 bool reordering = __ SetReorder(false);
7228 const int32_t entry_point_offset =
7229 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0);
7230 // We will not do the explicit null check in the thunk as some form of a null check
7231 // must've been done earlier.
7232 DCHECK(!needs_null_check);
7233 const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false);
7234 // Loading the entrypoint does not require a load acquire since it is only changed when
7235 // threads are suspended or running a checkpoint.
7236 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
7237 Register ref_reg = ref.AsRegister<Register>();
7238 Register index_reg = index.IsRegisterPair()
7239 ? index.AsRegisterPairLow<Register>()
7240 : index.AsRegister<Register>();
Alexey Frunze0cab6562017-07-25 15:19:36 -07007241 MipsLabel skip_call;
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007242 if (GetInstructionSetFeatures().IsR6()) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07007243 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007244 __ Lsa(TMP, index_reg, obj, scale_factor); // In delay slot.
7245 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07007246 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007247 } else {
7248 __ Sll(TMP, index_reg, scale_factor);
Alexey Frunze0cab6562017-07-25 15:19:36 -07007249 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007250 __ Addiu(T9, T9, thunk_disp); // In delay slot.
7251 __ Jalr(T9);
Alexey Frunze0cab6562017-07-25 15:19:36 -07007252 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007253 __ Addu(TMP, TMP, obj); // In delay slot.
7254 }
7255 // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor))
7256 DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset;
7257 __ LoadFromOffset(kLoadWord, ref_reg, TMP, data_offset); // Single instruction.
7258 __ MaybeUnpoisonHeapReference(ref_reg);
7259 __ SetReorder(reordering);
7260 return;
7261 }
7262
Alexey Frunze15958152017-02-09 19:08:30 -08007263 // /* HeapReference<Object> */ ref =
7264 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
Alexey Frunze15958152017-02-09 19:08:30 -08007265 GenerateReferenceLoadWithBakerReadBarrier(instruction,
7266 ref,
7267 obj,
7268 data_offset,
7269 index,
7270 scale_factor,
7271 temp,
7272 needs_null_check);
7273}
7274
7275void CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
7276 Location ref,
7277 Register obj,
7278 uint32_t offset,
7279 Location index,
7280 ScaleFactor scale_factor,
7281 Location temp,
7282 bool needs_null_check,
7283 bool always_update_field) {
7284 DCHECK(kEmitCompilerReadBarrier);
7285 DCHECK(kUseBakerReadBarrier);
7286
7287 // In slow path based read barriers, the read barrier call is
7288 // inserted after the original load. However, in fast path based
7289 // Baker's read barriers, we need to perform the load of
7290 // mirror::Object::monitor_ *before* the original reference load.
7291 // This load-load ordering is required by the read barrier.
7292 // The fast path/slow path (for Baker's algorithm) should look like:
7293 //
7294 // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState();
7295 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
7296 // HeapReference<Object> ref = *src; // Original reference load.
7297 // bool is_gray = (rb_state == ReadBarrier::GrayState());
7298 // if (is_gray) {
7299 // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path.
7300 // }
7301 //
7302 // Note: the original implementation in ReadBarrier::Barrier is
7303 // slightly more complex as it performs additional checks that we do
7304 // not do here for performance reasons.
7305
7306 Register ref_reg = ref.AsRegister<Register>();
7307 Register temp_reg = temp.AsRegister<Register>();
7308 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
7309
7310 // /* int32_t */ monitor = obj->monitor_
7311 __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset);
7312 if (needs_null_check) {
7313 MaybeRecordImplicitNullCheck(instruction);
7314 }
7315 // /* LockWord */ lock_word = LockWord(monitor)
7316 static_assert(sizeof(LockWord) == sizeof(int32_t),
7317 "art::LockWord and int32_t have different sizes.");
7318
7319 __ Sync(0); // Barrier to prevent load-load reordering.
7320
7321 // The actual reference load.
7322 if (index.IsValid()) {
7323 // Load types involving an "index": ArrayGet,
7324 // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject
7325 // intrinsics.
7326 // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor))
7327 if (index.IsConstant()) {
7328 size_t computed_offset =
7329 (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset;
7330 __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset);
7331 } else {
7332 // Handle the special case of the
7333 // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject
7334 // intrinsics, which use a register pair as index ("long
7335 // offset"), of which only the low part contains data.
7336 Register index_reg = index.IsRegisterPair()
7337 ? index.AsRegisterPairLow<Register>()
7338 : index.AsRegister<Register>();
Chris Larsencd0295d2017-03-31 15:26:54 -07007339 __ ShiftAndAdd(TMP, index_reg, obj, scale_factor, TMP);
Alexey Frunze15958152017-02-09 19:08:30 -08007340 __ LoadFromOffset(kLoadWord, ref_reg, TMP, offset);
7341 }
7342 } else {
7343 // /* HeapReference<Object> */ ref = *(obj + offset)
7344 __ LoadFromOffset(kLoadWord, ref_reg, obj, offset);
7345 }
7346
7347 // Object* ref = ref_addr->AsMirrorPtr()
7348 __ MaybeUnpoisonHeapReference(ref_reg);
7349
7350 // Slow path marking the object `ref` when it is gray.
7351 SlowPathCodeMIPS* slow_path;
7352 if (always_update_field) {
7353 // ReadBarrierMarkAndUpdateFieldSlowPathMIPS only supports address
7354 // of the form `obj + field_offset`, where `obj` is a register and
7355 // `field_offset` is a register pair (of which only the lower half
7356 // is used). Thus `offset` and `scale_factor` above are expected
7357 // to be null in this code path.
7358 DCHECK_EQ(offset, 0u);
7359 DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1);
Vladimir Marko174b2e22017-10-12 13:34:49 +01007360 slow_path = new (GetScopedAllocator())
Alexey Frunze15958152017-02-09 19:08:30 -08007361 ReadBarrierMarkAndUpdateFieldSlowPathMIPS(instruction,
7362 ref,
7363 obj,
7364 /* field_offset */ index,
7365 temp_reg);
7366 } else {
Vladimir Marko174b2e22017-10-12 13:34:49 +01007367 slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS(instruction, ref);
Alexey Frunze15958152017-02-09 19:08:30 -08007368 }
7369 AddSlowPath(slow_path);
7370
7371 // if (rb_state == ReadBarrier::GrayState())
7372 // ref = ReadBarrier::Mark(ref);
7373 // Given the numeric representation, it's enough to check the low bit of the
7374 // rb_state. We do that by shifting the bit into the sign bit (31) and
7375 // performing a branch on less than zero.
7376 static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0");
7377 static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1");
7378 static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size");
7379 __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift);
7380 __ Bltz(temp_reg, slow_path->GetEntryLabel());
7381 __ Bind(slow_path->GetExitLabel());
7382}
7383
7384void CodeGeneratorMIPS::GenerateReadBarrierSlow(HInstruction* instruction,
7385 Location out,
7386 Location ref,
7387 Location obj,
7388 uint32_t offset,
7389 Location index) {
7390 DCHECK(kEmitCompilerReadBarrier);
7391
7392 // Insert a slow path based read barrier *after* the reference load.
7393 //
7394 // If heap poisoning is enabled, the unpoisoning of the loaded
7395 // reference will be carried out by the runtime within the slow
7396 // path.
7397 //
7398 // Note that `ref` currently does not get unpoisoned (when heap
7399 // poisoning is enabled), which is alright as the `ref` argument is
7400 // not used by the artReadBarrierSlow entry point.
7401 //
7402 // TODO: Unpoison `ref` when it is used by artReadBarrierSlow.
Vladimir Marko174b2e22017-10-12 13:34:49 +01007403 SlowPathCodeMIPS* slow_path = new (GetScopedAllocator())
Alexey Frunze15958152017-02-09 19:08:30 -08007404 ReadBarrierForHeapReferenceSlowPathMIPS(instruction, out, ref, obj, offset, index);
7405 AddSlowPath(slow_path);
7406
7407 __ B(slow_path->GetEntryLabel());
7408 __ Bind(slow_path->GetExitLabel());
7409}
7410
7411void CodeGeneratorMIPS::MaybeGenerateReadBarrierSlow(HInstruction* instruction,
7412 Location out,
7413 Location ref,
7414 Location obj,
7415 uint32_t offset,
7416 Location index) {
7417 if (kEmitCompilerReadBarrier) {
7418 // Baker's read barriers shall be handled by the fast path
7419 // (CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier).
7420 DCHECK(!kUseBakerReadBarrier);
7421 // If heap poisoning is enabled, unpoisoning will be taken care of
7422 // by the runtime within the slow path.
7423 GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index);
7424 } else if (kPoisonHeapReferences) {
7425 __ UnpoisonHeapReference(out.AsRegister<Register>());
7426 }
7427}
7428
7429void CodeGeneratorMIPS::GenerateReadBarrierForRootSlow(HInstruction* instruction,
7430 Location out,
7431 Location root) {
7432 DCHECK(kEmitCompilerReadBarrier);
7433
7434 // Insert a slow path based read barrier *after* the GC root load.
7435 //
7436 // Note that GC roots are not affected by heap poisoning, so we do
7437 // not need to do anything special for this here.
7438 SlowPathCodeMIPS* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01007439 new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS(instruction, out, root);
Alexey Frunze15958152017-02-09 19:08:30 -08007440 AddSlowPath(slow_path);
7441
7442 __ B(slow_path->GetEntryLabel());
7443 __ Bind(slow_path->GetExitLabel());
7444}
7445
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007446void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007447 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
7448 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunzec61c0762017-04-10 13:54:23 -07007449 bool baker_read_barrier_slow_path = false;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007450 switch (type_check_kind) {
7451 case TypeCheckKind::kExactCheck:
7452 case TypeCheckKind::kAbstractClassCheck:
7453 case TypeCheckKind::kClassHierarchyCheck:
Alexey Frunzedfc30af2018-01-24 16:25:10 -08007454 case TypeCheckKind::kArrayObjectCheck: {
7455 bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction);
7456 call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall;
7457 baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007458 break;
Alexey Frunzedfc30af2018-01-24 16:25:10 -08007459 }
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007460 case TypeCheckKind::kArrayCheck:
7461 case TypeCheckKind::kUnresolvedCheck:
7462 case TypeCheckKind::kInterfaceCheck:
7463 call_kind = LocationSummary::kCallOnSlowPath;
7464 break;
Vladimir Marko175e7862018-03-27 09:03:13 +00007465 case TypeCheckKind::kBitstringCheck:
7466 break;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007467 }
7468
Vladimir Markoca6fff82017-10-03 14:49:14 +01007469 LocationSummary* locations =
7470 new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind);
Alexey Frunzec61c0762017-04-10 13:54:23 -07007471 if (baker_read_barrier_slow_path) {
7472 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
7473 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007474 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko175e7862018-03-27 09:03:13 +00007475 if (type_check_kind == TypeCheckKind::kBitstringCheck) {
7476 locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant()));
7477 locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant()));
7478 locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant()));
7479 } else {
7480 locations->SetInAt(1, Location::RequiresRegister());
7481 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007482 // The output does overlap inputs.
7483 // Note that TypeCheckSlowPathMIPS uses this register too.
7484 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexey Frunze15958152017-02-09 19:08:30 -08007485 locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007486}
7487
7488void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007489 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007490 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08007491 Location obj_loc = locations->InAt(0);
7492 Register obj = obj_loc.AsRegister<Register>();
Vladimir Marko175e7862018-03-27 09:03:13 +00007493 Location cls = locations->InAt(1);
Alexey Frunze15958152017-02-09 19:08:30 -08007494 Location out_loc = locations->Out();
7495 Register out = out_loc.AsRegister<Register>();
7496 const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind);
7497 DCHECK_LE(num_temps, 1u);
7498 Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation();
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007499 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
7500 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
7501 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
7502 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007503 MipsLabel done;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007504 SlowPathCodeMIPS* slow_path = nullptr;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007505
7506 // Return 0 if `obj` is null.
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007507 // Avoid this check if we know `obj` is not null.
7508 if (instruction->MustDoNullCheck()) {
7509 __ Move(out, ZERO);
7510 __ Beqz(obj, &done);
7511 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007512
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007513 switch (type_check_kind) {
7514 case TypeCheckKind::kExactCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08007515 ReadBarrierOption read_barrier_option =
7516 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007517 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08007518 GenerateReferenceLoadTwoRegisters(instruction,
7519 out_loc,
7520 obj_loc,
7521 class_offset,
7522 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08007523 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007524 // Classes must be equal for the instanceof to succeed.
Vladimir Marko175e7862018-03-27 09:03:13 +00007525 __ Xor(out, out, cls.AsRegister<Register>());
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007526 __ Sltiu(out, out, 1);
7527 break;
7528 }
7529
7530 case TypeCheckKind::kAbstractClassCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08007531 ReadBarrierOption read_barrier_option =
7532 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007533 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08007534 GenerateReferenceLoadTwoRegisters(instruction,
7535 out_loc,
7536 obj_loc,
7537 class_offset,
7538 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08007539 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007540 // If the class is abstract, we eagerly fetch the super class of the
7541 // object to avoid doing a comparison we know will fail.
7542 MipsLabel loop;
7543 __ Bind(&loop);
7544 // /* HeapReference<Class> */ out = out->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08007545 GenerateReferenceLoadOneRegister(instruction,
7546 out_loc,
7547 super_offset,
7548 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08007549 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007550 // If `out` is null, we use it for the result, and jump to `done`.
7551 __ Beqz(out, &done);
Vladimir Marko175e7862018-03-27 09:03:13 +00007552 __ Bne(out, cls.AsRegister<Register>(), &loop);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007553 __ LoadConst32(out, 1);
7554 break;
7555 }
7556
7557 case TypeCheckKind::kClassHierarchyCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08007558 ReadBarrierOption read_barrier_option =
7559 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007560 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08007561 GenerateReferenceLoadTwoRegisters(instruction,
7562 out_loc,
7563 obj_loc,
7564 class_offset,
7565 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08007566 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007567 // Walk over the class hierarchy to find a match.
7568 MipsLabel loop, success;
7569 __ Bind(&loop);
Vladimir Marko175e7862018-03-27 09:03:13 +00007570 __ Beq(out, cls.AsRegister<Register>(), &success);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007571 // /* HeapReference<Class> */ out = out->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08007572 GenerateReferenceLoadOneRegister(instruction,
7573 out_loc,
7574 super_offset,
7575 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08007576 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007577 __ Bnez(out, &loop);
7578 // If `out` is null, we use it for the result, and jump to `done`.
7579 __ B(&done);
7580 __ Bind(&success);
7581 __ LoadConst32(out, 1);
7582 break;
7583 }
7584
7585 case TypeCheckKind::kArrayObjectCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08007586 ReadBarrierOption read_barrier_option =
7587 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007588 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08007589 GenerateReferenceLoadTwoRegisters(instruction,
7590 out_loc,
7591 obj_loc,
7592 class_offset,
7593 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08007594 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007595 // Do an exact check.
7596 MipsLabel success;
Vladimir Marko175e7862018-03-27 09:03:13 +00007597 __ Beq(out, cls.AsRegister<Register>(), &success);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007598 // Otherwise, we need to check that the object's class is a non-primitive array.
7599 // /* HeapReference<Class> */ out = out->component_type_
Alexey Frunze15958152017-02-09 19:08:30 -08007600 GenerateReferenceLoadOneRegister(instruction,
7601 out_loc,
7602 component_offset,
7603 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08007604 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007605 // If `out` is null, we use it for the result, and jump to `done`.
7606 __ Beqz(out, &done);
7607 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
7608 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
7609 __ Sltiu(out, out, 1);
7610 __ B(&done);
7611 __ Bind(&success);
7612 __ LoadConst32(out, 1);
7613 break;
7614 }
7615
7616 case TypeCheckKind::kArrayCheck: {
7617 // No read barrier since the slow path will retry upon failure.
7618 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08007619 GenerateReferenceLoadTwoRegisters(instruction,
7620 out_loc,
7621 obj_loc,
7622 class_offset,
7623 maybe_temp_loc,
7624 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007625 DCHECK(locations->OnlyCallsOnSlowPath());
Vladimir Marko174b2e22017-10-12 13:34:49 +01007626 slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS(
7627 instruction, /* is_fatal */ false);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007628 codegen_->AddSlowPath(slow_path);
Vladimir Marko175e7862018-03-27 09:03:13 +00007629 __ Bne(out, cls.AsRegister<Register>(), slow_path->GetEntryLabel());
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007630 __ LoadConst32(out, 1);
7631 break;
7632 }
7633
7634 case TypeCheckKind::kUnresolvedCheck:
7635 case TypeCheckKind::kInterfaceCheck: {
7636 // Note that we indeed only call on slow path, but we always go
7637 // into the slow path for the unresolved and interface check
7638 // cases.
7639 //
7640 // We cannot directly call the InstanceofNonTrivial runtime
7641 // entry point without resorting to a type checking slow path
7642 // here (i.e. by calling InvokeRuntime directly), as it would
7643 // require to assign fixed registers for the inputs of this
7644 // HInstanceOf instruction (following the runtime calling
7645 // convention), which might be cluttered by the potential first
7646 // read barrier emission at the beginning of this method.
7647 //
7648 // TODO: Introduce a new runtime entry point taking the object
7649 // to test (instead of its class) as argument, and let it deal
7650 // with the read barrier issues. This will let us refactor this
7651 // case of the `switch` code as it was previously (with a direct
7652 // call to the runtime not using a type checking slow path).
7653 // This should also be beneficial for the other cases above.
7654 DCHECK(locations->OnlyCallsOnSlowPath());
Vladimir Marko174b2e22017-10-12 13:34:49 +01007655 slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS(
7656 instruction, /* is_fatal */ false);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007657 codegen_->AddSlowPath(slow_path);
7658 __ B(slow_path->GetEntryLabel());
7659 break;
7660 }
Vladimir Marko175e7862018-03-27 09:03:13 +00007661
7662 case TypeCheckKind::kBitstringCheck: {
7663 // /* HeapReference<Class> */ temp = obj->klass_
7664 GenerateReferenceLoadTwoRegisters(instruction,
7665 out_loc,
7666 obj_loc,
7667 class_offset,
7668 maybe_temp_loc,
7669 kWithoutReadBarrier);
7670
7671 GenerateBitstringTypeCheckCompare(instruction, out);
7672 __ Sltiu(out, out, 1);
7673 break;
7674 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007675 }
7676
7677 __ Bind(&done);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007678
7679 if (slow_path != nullptr) {
7680 __ Bind(slow_path->GetExitLabel());
7681 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007682}
7683
7684void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01007685 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007686 locations->SetOut(Location::ConstantLocation(constant));
7687}
7688
7689void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
7690 // Will be generated at use site.
7691}
7692
7693void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01007694 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007695 locations->SetOut(Location::ConstantLocation(constant));
7696}
7697
7698void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
7699 // Will be generated at use site.
7700}
7701
7702void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) {
7703 InvokeDexCallingConventionVisitorMIPS calling_convention_visitor;
7704 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
7705}
7706
7707void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
7708 HandleInvoke(invoke);
Alexey Frunze1b8464d2016-11-12 17:22:05 -08007709 // The register T7 is required to be used for the hidden argument in
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007710 // art_quick_imt_conflict_trampoline, so add the hidden argument.
Alexey Frunze1b8464d2016-11-12 17:22:05 -08007711 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T7));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007712}
7713
7714void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
7715 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
7716 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007717 Location receiver = invoke->GetLocations()->InAt(0);
7718 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07007719 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007720
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007721 // temp = object->GetClass();
7722 if (receiver.IsStackSlot()) {
7723 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
7724 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
7725 } else {
7726 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
7727 }
7728 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexey Frunzec061de12017-02-14 13:27:23 -08007729 // Instead of simply (possibly) unpoisoning `temp` here, we should
7730 // emit a read barrier for the previous class reference load.
7731 // However this is not required in practice, as this is an
7732 // intermediate/temporary reference and because the current
7733 // concurrent copying collector keeps the from-space memory
7734 // intact/accessible until the end of the marking phase (the
7735 // concurrent copying collector may not in the future).
7736 __ MaybeUnpoisonHeapReference(temp);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00007737 __ LoadFromOffset(kLoadWord, temp, temp,
7738 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
7739 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00007740 invoke->GetImtIndex(), kMipsPointerSize));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007741 // temp = temp->GetImtEntryAt(method_offset);
7742 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
7743 // T9 = temp->GetEntryPoint();
7744 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
Lena Djokic3177e102018-02-28 11:32:40 +01007745 // Set the hidden argument.
7746 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
7747 invoke->GetDexMethodIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007748 // T9();
7749 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07007750 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007751 DCHECK(!codegen_->IsLeafMethod());
7752 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
7753}
7754
7755void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen701566a2015-10-27 15:29:13 -07007756 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
7757 if (intrinsic.TryDispatch(invoke)) {
7758 return;
7759 }
7760
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007761 HandleInvoke(invoke);
7762}
7763
7764void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00007765 // Explicit clinit checks triggered by static invokes must have been pruned by
7766 // art::PrepareForRegisterAllocation.
7767 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007768
Alexey Frunze6b892cd2017-01-03 17:11:38 -08007769 bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007770 bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops();
7771 bool has_extra_input = invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007772
Chris Larsen701566a2015-10-27 15:29:13 -07007773 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
7774 if (intrinsic.TryDispatch(invoke)) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007775 if (invoke->GetLocations()->CanCall() && has_extra_input) {
7776 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
7777 }
Chris Larsen701566a2015-10-27 15:29:13 -07007778 return;
7779 }
7780
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007781 HandleInvoke(invoke);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007782
7783 // Add the extra input register if either the dex cache array base register
7784 // or the PC-relative base register for accessing literals is needed.
7785 if (has_extra_input) {
7786 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
7787 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007788}
7789
Orion Hodsonac141392017-01-13 11:53:47 +00007790void LocationsBuilderMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
7791 HandleInvoke(invoke);
7792}
7793
7794void InstructionCodeGeneratorMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
7795 codegen_->GenerateInvokePolymorphicCall(invoke);
7796}
7797
Orion Hodson4c8e12e2018-05-18 08:33:20 +01007798void LocationsBuilderMIPS::VisitInvokeCustom(HInvokeCustom* invoke) {
7799 HandleInvoke(invoke);
7800}
7801
7802void InstructionCodeGeneratorMIPS::VisitInvokeCustom(HInvokeCustom* invoke) {
7803 codegen_->GenerateInvokeCustomCall(invoke);
7804}
7805
Chris Larsen701566a2015-10-27 15:29:13 -07007806static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007807 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen701566a2015-10-27 15:29:13 -07007808 IntrinsicCodeGeneratorMIPS intrinsic(codegen);
7809 intrinsic.Dispatch(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007810 return true;
7811 }
7812 return false;
7813}
7814
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007815HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind(
Alexey Frunze06a46c42016-07-19 15:00:40 -07007816 HLoadString::LoadKind desired_string_load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007817 switch (desired_string_load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007818 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Markoe47f60c2018-02-21 13:43:28 +00007819 case HLoadString::LoadKind::kBootImageRelRo:
Vladimir Markoaad75c62016-10-03 08:46:48 +00007820 case HLoadString::LoadKind::kBssEntry:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007821 DCHECK(!Runtime::Current()->UseJitCompilation());
Alexey Frunze06a46c42016-07-19 15:00:40 -07007822 break;
Nicolas Geoffray132d8362016-11-16 09:19:42 +00007823 case HLoadString::LoadKind::kJitTableAddress:
7824 DCHECK(Runtime::Current()->UseJitCompilation());
Nicolas Geoffray132d8362016-11-16 09:19:42 +00007825 break;
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007826 case HLoadString::LoadKind::kBootImageAddress:
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007827 case HLoadString::LoadKind::kRuntimeCall:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007828 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007829 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007830 return desired_string_load_kind;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007831}
7832
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01007833HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind(
7834 HLoadClass::LoadKind desired_class_load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007835 switch (desired_class_load_kind) {
Nicolas Geoffray83c8e272017-01-31 14:36:37 +00007836 case HLoadClass::LoadKind::kInvalid:
7837 LOG(FATAL) << "UNREACHABLE";
7838 UNREACHABLE();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007839 case HLoadClass::LoadKind::kReferrersClass:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007840 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007841 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Markoe47f60c2018-02-21 13:43:28 +00007842 case HLoadClass::LoadKind::kBootImageRelRo:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007843 case HLoadClass::LoadKind::kBssEntry:
7844 DCHECK(!Runtime::Current()->UseJitCompilation());
7845 break;
Nicolas Geoffray22384ae2016-12-12 22:33:36 +00007846 case HLoadClass::LoadKind::kJitTableAddress:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007847 DCHECK(Runtime::Current()->UseJitCompilation());
Alexey Frunze06a46c42016-07-19 15:00:40 -07007848 break;
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007849 case HLoadClass::LoadKind::kBootImageAddress:
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007850 case HLoadClass::LoadKind::kRuntimeCall:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007851 break;
7852 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007853 return desired_class_load_kind;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01007854}
7855
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007856Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
7857 Register temp) {
Alexey Frunze6b892cd2017-01-03 17:11:38 -08007858 CHECK(!GetInstructionSetFeatures().IsR6());
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007859 CHECK(!GetGraph()->HasIrreducibleLoops());
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007860 CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
7861 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
7862 if (!invoke->GetLocations()->Intrinsified()) {
7863 return location.AsRegister<Register>();
7864 }
7865 // For intrinsics we allow any location, so it may be on the stack.
7866 if (!location.IsRegister()) {
7867 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
7868 return temp;
7869 }
7870 // For register locations, check if the register was saved. If so, get it from the stack.
7871 // Note: There is a chance that the register was saved but not overwritten, so we could
7872 // save one load. However, since this is just an intrinsic slow path we prefer this
7873 // simple and more robust approach rather that trying to determine if that's the case.
7874 SlowPathCode* slow_path = GetCurrentSlowPath();
7875 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
7876 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
7877 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
7878 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
7879 return temp;
7880 }
7881 return location.AsRegister<Register>();
7882}
7883
Vladimir Markodc151b22015-10-15 18:02:30 +01007884HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch(
7885 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +01007886 HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) {
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007887 return desired_dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01007888}
7889
Vladimir Markoe7197bf2017-06-02 17:00:23 +01007890void CodeGeneratorMIPS::GenerateStaticOrDirectCall(
7891 HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007892 // All registers are assumed to be correctly set up per the calling convention.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007893 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007894 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
7895 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
Alexey Frunze6b892cd2017-01-03 17:11:38 -08007896 bool is_r6 = GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007897 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
7898 Register base_reg = (invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops)
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007899 ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>())
7900 : ZERO;
7901
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007902 switch (method_load_kind) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01007903 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007904 // temp = thread->string_init_entrypoint
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01007905 uint32_t offset =
7906 GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007907 __ LoadFromOffset(kLoadWord,
7908 temp.AsRegister<Register>(),
7909 TR,
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01007910 offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007911 break;
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01007912 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007913 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00007914 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007915 break;
Vladimir Marko65979462017-05-19 17:25:12 +01007916 case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: {
7917 DCHECK(GetCompilerOptions().IsBootImage());
Vladimir Marko59eb30f2018-02-20 11:52:34 +00007918 PcRelativePatchInfo* info_high = NewBootImageMethodPatch(invoke->GetTargetMethod());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007919 PcRelativePatchInfo* info_low =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00007920 NewBootImageMethodPatch(invoke->GetTargetMethod(), info_high);
Vladimir Marko65979462017-05-19 17:25:12 +01007921 Register temp_reg = temp.AsRegister<Register>();
Alexey Frunzea663d9d2017-07-31 18:43:18 -07007922 EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg);
7923 __ Addiu(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label);
Vladimir Marko65979462017-05-19 17:25:12 +01007924 break;
7925 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007926 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
7927 __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress());
7928 break;
Vladimir Markob066d432018-01-03 13:14:37 +00007929 case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: {
Vladimir Markoe47f60c2018-02-21 13:43:28 +00007930 uint32_t boot_image_offset = GetBootImageOffset(invoke);
Vladimir Markob066d432018-01-03 13:14:37 +00007931 PcRelativePatchInfo* info_high = NewBootImageRelRoPatch(boot_image_offset);
7932 PcRelativePatchInfo* info_low = NewBootImageRelRoPatch(boot_image_offset, info_high);
7933 Register temp_reg = temp.AsRegister<Register>();
7934 EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg);
7935 __ Lw(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label);
7936 break;
7937 }
Vladimir Marko0eb882b2017-05-15 13:39:18 +01007938 case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007939 PcRelativePatchInfo* info_high = NewMethodBssEntryPatch(
Vladimir Marko0eb882b2017-05-15 13:39:18 +01007940 MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()));
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007941 PcRelativePatchInfo* info_low = NewMethodBssEntryPatch(
7942 MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high);
Vladimir Marko0eb882b2017-05-15 13:39:18 +01007943 Register temp_reg = temp.AsRegister<Register>();
Alexey Frunzea663d9d2017-07-31 18:43:18 -07007944 EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg);
7945 __ Lw(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007946 break;
Vladimir Marko0eb882b2017-05-15 13:39:18 +01007947 }
Vladimir Markoe7197bf2017-06-02 17:00:23 +01007948 case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: {
7949 GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path);
7950 return; // No code pointer retrieval; the runtime performs the call directly.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007951 }
7952 }
7953
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007954 switch (code_ptr_location) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007955 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007956 __ Bal(&frame_entry_label_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007957 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007958 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
7959 // T9 = callee_method->entry_point_from_quick_compiled_code_;
Goran Jakovljevic1a878372015-10-26 14:28:52 +01007960 __ LoadFromOffset(kLoadWord,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007961 T9,
7962 callee_method.AsRegister<Register>(),
7963 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07007964 kMipsPointerSize).Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007965 // T9()
7966 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07007967 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007968 break;
7969 }
Vladimir Markoe7197bf2017-06-02 17:00:23 +01007970 RecordPcInfo(invoke, invoke->GetDexPc(), slow_path);
7971
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007972 DCHECK(!IsLeafMethod());
7973}
7974
7975void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00007976 // Explicit clinit checks triggered by static invokes must have been pruned by
7977 // art::PrepareForRegisterAllocation.
7978 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007979
7980 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
7981 return;
7982 }
7983
7984 LocationSummary* locations = invoke->GetLocations();
7985 codegen_->GenerateStaticOrDirectCall(invoke,
7986 locations->HasTemps()
7987 ? locations->GetTemp(0)
7988 : Location::NoLocation());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007989}
7990
Vladimir Markoe7197bf2017-06-02 17:00:23 +01007991void CodeGeneratorMIPS::GenerateVirtualCall(
7992 HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) {
Goran Jakovljevice919b072016-10-04 10:17:34 +02007993 // Use the calling convention instead of the location of the receiver, as
7994 // intrinsics may have put the receiver in a different register. In the intrinsics
7995 // slow path, the arguments have been moved to the right place, so here we are
7996 // guaranteed that the receiver is the first register of the calling convention.
7997 InvokeDexCallingConvention calling_convention;
7998 Register receiver = calling_convention.GetRegisterAt(0);
7999
Chris Larsen3acee732015-11-18 13:31:08 -08008000 Register temp = temp_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008001 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
8002 invoke->GetVTableIndex(), kMipsPointerSize).SizeValue();
8003 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07008004 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008005
8006 // temp = object->GetClass();
Goran Jakovljevice919b072016-10-04 10:17:34 +02008007 __ LoadFromOffset(kLoadWord, temp, receiver, class_offset);
Chris Larsen3acee732015-11-18 13:31:08 -08008008 MaybeRecordImplicitNullCheck(invoke);
Alexey Frunzec061de12017-02-14 13:27:23 -08008009 // Instead of simply (possibly) unpoisoning `temp` here, we should
8010 // emit a read barrier for the previous class reference load.
8011 // However this is not required in practice, as this is an
8012 // intermediate/temporary reference and because the current
8013 // concurrent copying collector keeps the from-space memory
8014 // intact/accessible until the end of the marking phase (the
8015 // concurrent copying collector may not in the future).
8016 __ MaybeUnpoisonHeapReference(temp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008017 // temp = temp->GetMethodAt(method_offset);
8018 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
8019 // T9 = temp->GetEntryPoint();
8020 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
8021 // T9();
8022 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07008023 __ NopIfNoReordering();
Vladimir Markoe7197bf2017-06-02 17:00:23 +01008024 RecordPcInfo(invoke, invoke->GetDexPc(), slow_path);
Chris Larsen3acee732015-11-18 13:31:08 -08008025}
8026
8027void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
8028 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
8029 return;
8030 }
8031
8032 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008033 DCHECK(!codegen_->IsLeafMethod());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008034}
8035
8036void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) {
Vladimir Marko41559982017-01-06 14:04:23 +00008037 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
Vladimir Marko847e6ce2017-06-02 13:55:07 +01008038 if (load_kind == HLoadClass::LoadKind::kRuntimeCall) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07008039 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07008040 Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0));
8041 CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc);
Alexey Frunze06a46c42016-07-19 15:00:40 -07008042 return;
8043 }
Vladimir Marko41559982017-01-06 14:04:23 +00008044 DCHECK(!cls->NeedsAccessCheck());
Alexey Frunzec61c0762017-04-10 13:54:23 -07008045 const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02008046 const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops();
Alexey Frunze15958152017-02-09 19:08:30 -08008047 const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage();
8048 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier)
Alexey Frunze06a46c42016-07-19 15:00:40 -07008049 ? LocationSummary::kCallOnSlowPath
8050 : LocationSummary::kNoCall;
Vladimir Markoca6fff82017-10-03 14:49:14 +01008051 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind);
Alexey Frunzec61c0762017-04-10 13:54:23 -07008052 if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) {
8053 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
8054 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07008055 switch (load_kind) {
8056 // We need an extra register for PC-relative literals on R2.
Alexey Frunze06a46c42016-07-19 15:00:40 -07008057 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00008058 case HLoadClass::LoadKind::kBootImageAddress:
Vladimir Markoe47f60c2018-02-21 13:43:28 +00008059 case HLoadClass::LoadKind::kBootImageRelRo:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00008060 case HLoadClass::LoadKind::kBssEntry:
Alexey Frunzec61c0762017-04-10 13:54:23 -07008061 if (isR6) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07008062 break;
8063 }
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02008064 if (has_irreducible_loops) {
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07008065 if (load_kind != HLoadClass::LoadKind::kBootImageAddress) {
8066 codegen_->ClobberRA();
8067 }
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02008068 break;
8069 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07008070 FALLTHROUGH_INTENDED;
Alexey Frunze06a46c42016-07-19 15:00:40 -07008071 case HLoadClass::LoadKind::kReferrersClass:
Alexey Frunze06a46c42016-07-19 15:00:40 -07008072 locations->SetInAt(0, Location::RequiresRegister());
8073 break;
8074 default:
8075 break;
8076 }
8077 locations->SetOut(Location::RequiresRegister());
Alexey Frunzec61c0762017-04-10 13:54:23 -07008078 if (load_kind == HLoadClass::LoadKind::kBssEntry) {
8079 if (!kUseReadBarrier || kUseBakerReadBarrier) {
8080 // Rely on the type resolution or initialization and marking to save everything we need.
Alexey Frunzec61c0762017-04-10 13:54:23 -07008081 RegisterSet caller_saves = RegisterSet::Empty();
8082 InvokeRuntimeCallingConvention calling_convention;
8083 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
8084 locations->SetCustomSlowPathCallerSaves(caller_saves);
8085 } else {
8086 // For non-Baker read barriers we have a temp-clobbering call.
8087 }
8088 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008089}
8090
Nicolas Geoffray5247c082017-01-13 14:17:29 +00008091// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
8092// move.
8093void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS {
Vladimir Marko41559982017-01-06 14:04:23 +00008094 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
Vladimir Marko847e6ce2017-06-02 13:55:07 +01008095 if (load_kind == HLoadClass::LoadKind::kRuntimeCall) {
Vladimir Marko41559982017-01-06 14:04:23 +00008096 codegen_->GenerateLoadClassRuntimeCall(cls);
Pavle Batutae87a7182015-10-28 13:10:42 +01008097 return;
8098 }
Vladimir Marko41559982017-01-06 14:04:23 +00008099 DCHECK(!cls->NeedsAccessCheck());
Pavle Batutae87a7182015-10-28 13:10:42 +01008100
Vladimir Marko41559982017-01-06 14:04:23 +00008101 LocationSummary* locations = cls->GetLocations();
Alexey Frunze06a46c42016-07-19 15:00:40 -07008102 Location out_loc = locations->Out();
8103 Register out = out_loc.AsRegister<Register>();
8104 Register base_or_current_method_reg;
8105 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02008106 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
Alexey Frunze06a46c42016-07-19 15:00:40 -07008107 switch (load_kind) {
8108 // We need an extra register for PC-relative literals on R2.
Alexey Frunze06a46c42016-07-19 15:00:40 -07008109 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00008110 case HLoadClass::LoadKind::kBootImageAddress:
Vladimir Markoe47f60c2018-02-21 13:43:28 +00008111 case HLoadClass::LoadKind::kBootImageRelRo:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00008112 case HLoadClass::LoadKind::kBssEntry:
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02008113 base_or_current_method_reg =
8114 (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>();
Alexey Frunze06a46c42016-07-19 15:00:40 -07008115 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07008116 case HLoadClass::LoadKind::kReferrersClass:
Vladimir Marko847e6ce2017-06-02 13:55:07 +01008117 case HLoadClass::LoadKind::kRuntimeCall:
Alexey Frunze06a46c42016-07-19 15:00:40 -07008118 base_or_current_method_reg = locations->InAt(0).AsRegister<Register>();
8119 break;
8120 default:
8121 base_or_current_method_reg = ZERO;
8122 break;
8123 }
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00008124
Alexey Frunze15958152017-02-09 19:08:30 -08008125 const ReadBarrierOption read_barrier_option = cls->IsInBootImage()
8126 ? kWithoutReadBarrier
8127 : kCompilerReadBarrierOption;
Alexey Frunze06a46c42016-07-19 15:00:40 -07008128 bool generate_null_check = false;
8129 switch (load_kind) {
8130 case HLoadClass::LoadKind::kReferrersClass: {
8131 DCHECK(!cls->CanCallRuntime());
8132 DCHECK(!cls->MustGenerateClinitCheck());
8133 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
8134 GenerateGcRootFieldLoad(cls,
8135 out_loc,
8136 base_or_current_method_reg,
Alexey Frunze15958152017-02-09 19:08:30 -08008137 ArtMethod::DeclaringClassOffset().Int32Value(),
8138 read_barrier_option);
Alexey Frunze06a46c42016-07-19 15:00:40 -07008139 break;
8140 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07008141 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Marko6bec91c2017-01-09 15:03:12 +00008142 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze15958152017-02-09 19:08:30 -08008143 DCHECK_EQ(read_barrier_option, kWithoutReadBarrier);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008144 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00008145 codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008146 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00008147 codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008148 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high,
8149 out,
Alexey Frunzea663d9d2017-07-31 18:43:18 -07008150 base_or_current_method_reg);
8151 __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label);
Alexey Frunze06a46c42016-07-19 15:00:40 -07008152 break;
8153 }
8154 case HLoadClass::LoadKind::kBootImageAddress: {
Alexey Frunze15958152017-02-09 19:08:30 -08008155 DCHECK_EQ(read_barrier_option, kWithoutReadBarrier);
Nicolas Geoffray5247c082017-01-13 14:17:29 +00008156 uint32_t address = dchecked_integral_cast<uint32_t>(
8157 reinterpret_cast<uintptr_t>(cls->GetClass().Get()));
8158 DCHECK_NE(address, 0u);
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02008159 if (isR6 || !has_irreducible_loops) {
8160 __ LoadLiteral(out,
8161 base_or_current_method_reg,
8162 codegen_->DeduplicateBootImageAddressLiteral(address));
8163 } else {
8164 __ LoadConst32(out, address);
8165 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07008166 break;
8167 }
Vladimir Markoe47f60c2018-02-21 13:43:28 +00008168 case HLoadClass::LoadKind::kBootImageRelRo: {
Vladimir Marko94ec2db2017-09-06 17:21:03 +01008169 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
Vladimir Markoe47f60c2018-02-21 13:43:28 +00008170 uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls);
Vladimir Marko94ec2db2017-09-06 17:21:03 +01008171 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
Vladimir Markoe47f60c2018-02-21 13:43:28 +00008172 codegen_->NewBootImageRelRoPatch(boot_image_offset);
Vladimir Marko94ec2db2017-09-06 17:21:03 +01008173 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
Vladimir Markoe47f60c2018-02-21 13:43:28 +00008174 codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high);
Vladimir Marko94ec2db2017-09-06 17:21:03 +01008175 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high,
8176 out,
8177 base_or_current_method_reg);
8178 __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label);
Vladimir Marko94ec2db2017-09-06 17:21:03 +01008179 break;
8180 }
Vladimir Marko6bec91c2017-01-09 15:03:12 +00008181 case HLoadClass::LoadKind::kBssEntry: {
Vladimir Markof3c52b42017-11-17 17:32:12 +00008182 CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high =
8183 codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008184 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
8185 codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008186 codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high,
Vladimir Markof3c52b42017-11-17 17:32:12 +00008187 out,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008188 base_or_current_method_reg);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008189 GenerateGcRootFieldLoad(cls,
8190 out_loc,
Vladimir Markof3c52b42017-11-17 17:32:12 +00008191 out,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008192 /* placeholder */ 0x5678,
8193 read_barrier_option,
8194 &info_low->label);
Vladimir Marko6bec91c2017-01-09 15:03:12 +00008195 generate_null_check = true;
8196 break;
8197 }
Nicolas Geoffray22384ae2016-12-12 22:33:36 +00008198 case HLoadClass::LoadKind::kJitTableAddress: {
Alexey Frunze627c1a02017-01-30 19:28:14 -08008199 CodeGeneratorMIPS::JitPatchInfo* info = codegen_->NewJitRootClassPatch(cls->GetDexFile(),
8200 cls->GetTypeIndex(),
8201 cls->GetClass());
8202 bool reordering = __ SetReorder(false);
8203 __ Bind(&info->high_label);
8204 __ Lui(out, /* placeholder */ 0x1234);
Alexey Frunze627c1a02017-01-30 19:28:14 -08008205 __ SetReorder(reordering);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008206 GenerateGcRootFieldLoad(cls,
8207 out_loc,
8208 out,
8209 /* placeholder */ 0x5678,
8210 read_barrier_option,
8211 &info->low_label);
Alexey Frunze06a46c42016-07-19 15:00:40 -07008212 break;
8213 }
Vladimir Marko847e6ce2017-06-02 13:55:07 +01008214 case HLoadClass::LoadKind::kRuntimeCall:
Nicolas Geoffray83c8e272017-01-31 14:36:37 +00008215 case HLoadClass::LoadKind::kInvalid:
Vladimir Marko41559982017-01-06 14:04:23 +00008216 LOG(FATAL) << "UNREACHABLE";
8217 UNREACHABLE();
Alexey Frunze06a46c42016-07-19 15:00:40 -07008218 }
8219
8220 if (generate_null_check || cls->MustGenerateClinitCheck()) {
8221 DCHECK(cls->CanCallRuntime());
Vladimir Marko174b2e22017-10-12 13:34:49 +01008222 SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS(
Vladimir Markof3c52b42017-11-17 17:32:12 +00008223 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
Alexey Frunze06a46c42016-07-19 15:00:40 -07008224 codegen_->AddSlowPath(slow_path);
8225 if (generate_null_check) {
8226 __ Beqz(out, slow_path->GetEntryLabel());
8227 }
8228 if (cls->MustGenerateClinitCheck()) {
8229 GenerateClassInitializationCheck(slow_path, out);
8230 } else {
8231 __ Bind(slow_path->GetExitLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008232 }
8233 }
8234}
8235
Orion Hodsondbaa5c72018-05-10 08:22:46 +01008236void LocationsBuilderMIPS::VisitLoadMethodHandle(HLoadMethodHandle* load) {
8237 InvokeRuntimeCallingConvention calling_convention;
8238 Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0));
8239 CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, loc, loc);
8240}
8241
8242void InstructionCodeGeneratorMIPS::VisitLoadMethodHandle(HLoadMethodHandle* load) {
8243 codegen_->GenerateLoadMethodHandleRuntimeCall(load);
8244}
8245
Orion Hodson18259d72018-04-12 11:18:23 +01008246void LocationsBuilderMIPS::VisitLoadMethodType(HLoadMethodType* load) {
8247 InvokeRuntimeCallingConvention calling_convention;
8248 Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0));
8249 CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, loc, loc);
8250}
8251
8252void InstructionCodeGeneratorMIPS::VisitLoadMethodType(HLoadMethodType* load) {
8253 codegen_->GenerateLoadMethodTypeRuntimeCall(load);
8254}
8255
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008256static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07008257 return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008258}
8259
8260void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) {
8261 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01008262 new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008263 locations->SetOut(Location::RequiresRegister());
8264}
8265
8266void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) {
8267 Register out = load->GetLocations()->Out().AsRegister<Register>();
8268 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
8269}
8270
8271void LocationsBuilderMIPS::VisitClearException(HClearException* clear) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008272 new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008273}
8274
8275void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
8276 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
8277}
8278
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008279void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08008280 LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load);
Vladimir Markoca6fff82017-10-03 14:49:14 +01008281 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind);
Alexey Frunze06a46c42016-07-19 15:00:40 -07008282 HLoadString::LoadKind load_kind = load->GetLoadKind();
Alexey Frunzec61c0762017-04-10 13:54:23 -07008283 const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02008284 const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops();
Alexey Frunze06a46c42016-07-19 15:00:40 -07008285 switch (load_kind) {
8286 // We need an extra register for PC-relative literals on R2.
Alexey Frunze06a46c42016-07-19 15:00:40 -07008287 case HLoadString::LoadKind::kBootImageAddress:
8288 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Markoe47f60c2018-02-21 13:43:28 +00008289 case HLoadString::LoadKind::kBootImageRelRo:
Vladimir Markoaad75c62016-10-03 08:46:48 +00008290 case HLoadString::LoadKind::kBssEntry:
Alexey Frunzec61c0762017-04-10 13:54:23 -07008291 if (isR6) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07008292 break;
8293 }
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02008294 if (has_irreducible_loops) {
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07008295 if (load_kind != HLoadString::LoadKind::kBootImageAddress) {
8296 codegen_->ClobberRA();
8297 }
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02008298 break;
8299 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07008300 FALLTHROUGH_INTENDED;
8301 // We need an extra register for PC-relative dex cache accesses.
Vladimir Marko847e6ce2017-06-02 13:55:07 +01008302 case HLoadString::LoadKind::kRuntimeCall:
Alexey Frunze06a46c42016-07-19 15:00:40 -07008303 locations->SetInAt(0, Location::RequiresRegister());
8304 break;
8305 default:
8306 break;
8307 }
Vladimir Marko847e6ce2017-06-02 13:55:07 +01008308 if (load_kind == HLoadString::LoadKind::kRuntimeCall) {
Alexey Frunzebb51df82016-11-01 16:07:32 -07008309 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07008310 locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Alexey Frunzebb51df82016-11-01 16:07:32 -07008311 } else {
8312 locations->SetOut(Location::RequiresRegister());
Alexey Frunzec61c0762017-04-10 13:54:23 -07008313 if (load_kind == HLoadString::LoadKind::kBssEntry) {
8314 if (!kUseReadBarrier || kUseBakerReadBarrier) {
8315 // Rely on the pResolveString and marking to save everything we need.
Alexey Frunzec61c0762017-04-10 13:54:23 -07008316 RegisterSet caller_saves = RegisterSet::Empty();
8317 InvokeRuntimeCallingConvention calling_convention;
8318 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
8319 locations->SetCustomSlowPathCallerSaves(caller_saves);
8320 } else {
8321 // For non-Baker read barriers we have a temp-clobbering call.
8322 }
8323 }
Alexey Frunzebb51df82016-11-01 16:07:32 -07008324 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008325}
8326
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00008327// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
8328// move.
8329void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS {
Alexey Frunze06a46c42016-07-19 15:00:40 -07008330 HLoadString::LoadKind load_kind = load->GetLoadKind();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008331 LocationSummary* locations = load->GetLocations();
Alexey Frunze06a46c42016-07-19 15:00:40 -07008332 Location out_loc = locations->Out();
8333 Register out = out_loc.AsRegister<Register>();
8334 Register base_or_current_method_reg;
8335 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02008336 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
Alexey Frunze06a46c42016-07-19 15:00:40 -07008337 switch (load_kind) {
8338 // We need an extra register for PC-relative literals on R2.
Alexey Frunze06a46c42016-07-19 15:00:40 -07008339 case HLoadString::LoadKind::kBootImageAddress:
8340 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Markoe47f60c2018-02-21 13:43:28 +00008341 case HLoadString::LoadKind::kBootImageRelRo:
Vladimir Markoaad75c62016-10-03 08:46:48 +00008342 case HLoadString::LoadKind::kBssEntry:
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02008343 base_or_current_method_reg =
8344 (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>();
Alexey Frunze06a46c42016-07-19 15:00:40 -07008345 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07008346 default:
8347 base_or_current_method_reg = ZERO;
8348 break;
8349 }
8350
8351 switch (load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07008352 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Markoaad75c62016-10-03 08:46:48 +00008353 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008354 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00008355 codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008356 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00008357 codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008358 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high,
8359 out,
Alexey Frunzea663d9d2017-07-31 18:43:18 -07008360 base_or_current_method_reg);
8361 __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01008362 return;
Alexey Frunze06a46c42016-07-19 15:00:40 -07008363 }
8364 case HLoadString::LoadKind::kBootImageAddress: {
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00008365 uint32_t address = dchecked_integral_cast<uint32_t>(
8366 reinterpret_cast<uintptr_t>(load->GetString().Get()));
8367 DCHECK_NE(address, 0u);
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02008368 if (isR6 || !has_irreducible_loops) {
8369 __ LoadLiteral(out,
8370 base_or_current_method_reg,
8371 codegen_->DeduplicateBootImageAddressLiteral(address));
8372 } else {
8373 __ LoadConst32(out, address);
8374 }
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01008375 return;
Alexey Frunze06a46c42016-07-19 15:00:40 -07008376 }
Vladimir Markoe47f60c2018-02-21 13:43:28 +00008377 case HLoadString::LoadKind::kBootImageRelRo: {
Vladimir Markoaad75c62016-10-03 08:46:48 +00008378 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
Vladimir Markoe47f60c2018-02-21 13:43:28 +00008379 uint32_t boot_image_offset = codegen_->GetBootImageOffset(load);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008380 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
Vladimir Markoe47f60c2018-02-21 13:43:28 +00008381 codegen_->NewBootImageRelRoPatch(boot_image_offset);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008382 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
Vladimir Markoe47f60c2018-02-21 13:43:28 +00008383 codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01008384 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high,
8385 out,
8386 base_or_current_method_reg);
8387 __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label);
8388 return;
8389 }
8390 case HLoadString::LoadKind::kBssEntry: {
8391 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
8392 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
8393 codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex());
8394 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
8395 codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008396 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high,
Vladimir Markof3c52b42017-11-17 17:32:12 +00008397 out,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008398 base_or_current_method_reg);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008399 GenerateGcRootFieldLoad(load,
8400 out_loc,
Vladimir Markof3c52b42017-11-17 17:32:12 +00008401 out,
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008402 /* placeholder */ 0x5678,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008403 kCompilerReadBarrierOption,
8404 &info_low->label);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008405 SlowPathCodeMIPS* slow_path =
Vladimir Markof3c52b42017-11-17 17:32:12 +00008406 new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS(load);
Vladimir Markoaad75c62016-10-03 08:46:48 +00008407 codegen_->AddSlowPath(slow_path);
8408 __ Beqz(out, slow_path->GetEntryLabel());
8409 __ Bind(slow_path->GetExitLabel());
8410 return;
8411 }
Alexey Frunze627c1a02017-01-30 19:28:14 -08008412 case HLoadString::LoadKind::kJitTableAddress: {
8413 CodeGeneratorMIPS::JitPatchInfo* info =
8414 codegen_->NewJitRootStringPatch(load->GetDexFile(),
8415 load->GetStringIndex(),
8416 load->GetString());
8417 bool reordering = __ SetReorder(false);
8418 __ Bind(&info->high_label);
8419 __ Lui(out, /* placeholder */ 0x1234);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008420 __ SetReorder(reordering);
Alexey Frunze15958152017-02-09 19:08:30 -08008421 GenerateGcRootFieldLoad(load,
8422 out_loc,
8423 out,
8424 /* placeholder */ 0x5678,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008425 kCompilerReadBarrierOption,
8426 &info->low_label);
Alexey Frunze627c1a02017-01-30 19:28:14 -08008427 return;
8428 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07008429 default:
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07008430 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07008431 }
Nicolas Geoffray917d0162015-11-24 18:25:35 +00008432
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07008433 // TODO: Re-add the compiler code to do string dex cache lookup again.
Vladimir Marko847e6ce2017-06-02 13:55:07 +01008434 DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall);
Vladimir Markoaad75c62016-10-03 08:46:48 +00008435 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07008436 DCHECK_EQ(calling_convention.GetRegisterAt(0), out);
Andreas Gampe8a0128a2016-11-28 07:38:35 -08008437 __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_);
Vladimir Markoaad75c62016-10-03 08:46:48 +00008438 codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc());
8439 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008440}
8441
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008442void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008443 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008444 locations->SetOut(Location::ConstantLocation(constant));
8445}
8446
8447void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
8448 // Will be generated at use site.
8449}
8450
8451void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008452 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
8453 instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008454 InvokeRuntimeCallingConvention calling_convention;
8455 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
8456}
8457
8458void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
8459 if (instruction->IsEnter()) {
Serban Constantinescufca16662016-07-14 09:21:59 +01008460 codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008461 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
8462 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01008463 codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008464 }
8465 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
8466}
8467
8468void LocationsBuilderMIPS::VisitMul(HMul* mul) {
8469 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01008470 new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008471 switch (mul->GetResultType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008472 case DataType::Type::kInt32:
8473 case DataType::Type::kInt64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008474 locations->SetInAt(0, Location::RequiresRegister());
8475 locations->SetInAt(1, Location::RequiresRegister());
8476 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8477 break;
8478
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008479 case DataType::Type::kFloat32:
8480 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008481 locations->SetInAt(0, Location::RequiresFpuRegister());
8482 locations->SetInAt(1, Location::RequiresFpuRegister());
8483 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
8484 break;
8485
8486 default:
8487 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
8488 }
8489}
8490
8491void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008492 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008493 LocationSummary* locations = instruction->GetLocations();
8494 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
8495
8496 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008497 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008498 Register dst = locations->Out().AsRegister<Register>();
8499 Register lhs = locations->InAt(0).AsRegister<Register>();
8500 Register rhs = locations->InAt(1).AsRegister<Register>();
8501
8502 if (isR6) {
8503 __ MulR6(dst, lhs, rhs);
8504 } else {
8505 __ MulR2(dst, lhs, rhs);
8506 }
8507 break;
8508 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008509 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008510 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
8511 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
8512 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
8513 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
8514 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
8515 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
8516
8517 // Extra checks to protect caused by the existance of A1_A2.
8518 // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo:
8519 // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2).
8520 DCHECK_NE(dst_high, lhs_low);
8521 DCHECK_NE(dst_high, rhs_low);
8522
8523 // A_B * C_D
8524 // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ]
8525 // dst_lo: [ low(B*D) ]
8526 // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result.
8527
8528 if (isR6) {
8529 __ MulR6(TMP, lhs_high, rhs_low);
8530 __ MulR6(dst_high, lhs_low, rhs_high);
8531 __ Addu(dst_high, dst_high, TMP);
8532 __ MuhuR6(TMP, lhs_low, rhs_low);
8533 __ Addu(dst_high, dst_high, TMP);
8534 __ MulR6(dst_low, lhs_low, rhs_low);
8535 } else {
8536 __ MulR2(TMP, lhs_high, rhs_low);
8537 __ MulR2(dst_high, lhs_low, rhs_high);
8538 __ Addu(dst_high, dst_high, TMP);
8539 __ MultuR2(lhs_low, rhs_low);
8540 __ Mfhi(TMP);
8541 __ Addu(dst_high, dst_high, TMP);
8542 __ Mflo(dst_low);
8543 }
8544 break;
8545 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008546 case DataType::Type::kFloat32:
8547 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008548 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
8549 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
8550 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008551 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008552 __ MulS(dst, lhs, rhs);
8553 } else {
8554 __ MulD(dst, lhs, rhs);
8555 }
8556 break;
8557 }
8558 default:
8559 LOG(FATAL) << "Unexpected mul type " << type;
8560 }
8561}
8562
8563void LocationsBuilderMIPS::VisitNeg(HNeg* neg) {
8564 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01008565 new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008566 switch (neg->GetResultType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008567 case DataType::Type::kInt32:
8568 case DataType::Type::kInt64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008569 locations->SetInAt(0, Location::RequiresRegister());
8570 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8571 break;
8572
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008573 case DataType::Type::kFloat32:
8574 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008575 locations->SetInAt(0, Location::RequiresFpuRegister());
8576 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
8577 break;
8578
8579 default:
8580 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
8581 }
8582}
8583
8584void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008585 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008586 LocationSummary* locations = instruction->GetLocations();
8587
8588 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008589 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008590 Register dst = locations->Out().AsRegister<Register>();
8591 Register src = locations->InAt(0).AsRegister<Register>();
8592 __ Subu(dst, ZERO, src);
8593 break;
8594 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008595 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008596 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
8597 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
8598 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
8599 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
8600 __ Subu(dst_low, ZERO, src_low);
8601 __ Sltu(TMP, ZERO, dst_low);
8602 __ Subu(dst_high, ZERO, src_high);
8603 __ Subu(dst_high, dst_high, TMP);
8604 break;
8605 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008606 case DataType::Type::kFloat32:
8607 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008608 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
8609 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008610 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008611 __ NegS(dst, src);
8612 } else {
8613 __ NegD(dst, src);
8614 }
8615 break;
8616 }
8617 default:
8618 LOG(FATAL) << "Unexpected neg type " << type;
8619 }
8620}
8621
8622void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008623 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
8624 instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008625 InvokeRuntimeCallingConvention calling_convention;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008626 locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference));
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00008627 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
8628 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008629}
8630
8631void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) {
Alexey Frunzec061de12017-02-14 13:27:23 -08008632 // Note: if heap poisoning is enabled, the entry point takes care
8633 // of poisoning the reference.
Goran Jakovljevic854df412017-06-27 14:41:39 +02008634 QuickEntrypointEnum entrypoint =
8635 CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass());
8636 codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc());
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00008637 CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>();
Goran Jakovljevic854df412017-06-27 14:41:39 +02008638 DCHECK(!codegen_->IsLeafMethod());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008639}
8640
8641void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008642 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
8643 instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008644 InvokeRuntimeCallingConvention calling_convention;
David Brazdil6de19382016-01-08 17:37:10 +00008645 if (instruction->IsStringAlloc()) {
8646 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
8647 } else {
8648 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
David Brazdil6de19382016-01-08 17:37:10 +00008649 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008650 locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008651}
8652
8653void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) {
Alexey Frunzec061de12017-02-14 13:27:23 -08008654 // Note: if heap poisoning is enabled, the entry point takes care
8655 // of poisoning the reference.
David Brazdil6de19382016-01-08 17:37:10 +00008656 if (instruction->IsStringAlloc()) {
8657 // String is allocated through StringFactory. Call NewEmptyString entry point.
8658 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07008659 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00008660 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
8661 __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value());
8662 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07008663 __ NopIfNoReordering();
David Brazdil6de19382016-01-08 17:37:10 +00008664 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
8665 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01008666 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00008667 CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>();
David Brazdil6de19382016-01-08 17:37:10 +00008668 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008669}
8670
8671void LocationsBuilderMIPS::VisitNot(HNot* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008672 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008673 locations->SetInAt(0, Location::RequiresRegister());
8674 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8675}
8676
8677void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008678 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008679 LocationSummary* locations = instruction->GetLocations();
8680
8681 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008682 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008683 Register dst = locations->Out().AsRegister<Register>();
8684 Register src = locations->InAt(0).AsRegister<Register>();
8685 __ Nor(dst, src, ZERO);
8686 break;
8687 }
8688
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008689 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008690 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
8691 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
8692 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
8693 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
8694 __ Nor(dst_high, src_high, ZERO);
8695 __ Nor(dst_low, src_low, ZERO);
8696 break;
8697 }
8698
8699 default:
8700 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
8701 }
8702}
8703
8704void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008705 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008706 locations->SetInAt(0, Location::RequiresRegister());
8707 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8708}
8709
8710void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) {
8711 LocationSummary* locations = instruction->GetLocations();
8712 __ Xori(locations->Out().AsRegister<Register>(),
8713 locations->InAt(0).AsRegister<Register>(),
8714 1);
8715}
8716
8717void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01008718 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
8719 locations->SetInAt(0, Location::RequiresRegister());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008720}
8721
Calin Juravle2ae48182016-03-16 14:05:09 +00008722void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) {
8723 if (CanMoveNullCheckToUser(instruction)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008724 return;
8725 }
8726 Location obj = instruction->GetLocations()->InAt(0);
8727
8728 __ Lw(ZERO, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00008729 RecordPcInfo(instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008730}
8731
Calin Juravle2ae48182016-03-16 14:05:09 +00008732void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01008733 SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) NullCheckSlowPathMIPS(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00008734 AddSlowPath(slow_path);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008735
8736 Location obj = instruction->GetLocations()->InAt(0);
8737
8738 __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
8739}
8740
8741void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00008742 codegen_->GenerateNullCheck(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008743}
8744
8745void LocationsBuilderMIPS::VisitOr(HOr* instruction) {
8746 HandleBinaryOp(instruction);
8747}
8748
8749void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) {
8750 HandleBinaryOp(instruction);
8751}
8752
8753void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
8754 LOG(FATAL) << "Unreachable";
8755}
8756
8757void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) {
Vladimir Markobea75ff2017-10-11 20:39:54 +01008758 if (instruction->GetNext()->IsSuspendCheck() &&
8759 instruction->GetBlock()->GetLoopInformation() != nullptr) {
8760 HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck();
8761 // The back edge will generate the suspend check.
8762 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction);
8763 }
8764
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008765 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
8766}
8767
8768void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008769 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008770 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
8771 if (location.IsStackSlot()) {
8772 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
8773 } else if (location.IsDoubleStackSlot()) {
8774 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
8775 }
8776 locations->SetOut(location);
8777}
8778
8779void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction
8780 ATTRIBUTE_UNUSED) {
8781 // Nothing to do, the parameter is already at its location.
8782}
8783
8784void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) {
8785 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01008786 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008787 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
8788}
8789
8790void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction
8791 ATTRIBUTE_UNUSED) {
8792 // Nothing to do, the method is already at its location.
8793}
8794
8795void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008796 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Vladimir Marko372f10e2016-05-17 16:30:10 +01008797 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008798 locations->SetInAt(i, Location::Any());
8799 }
8800 locations->SetOut(Location::Any());
8801}
8802
8803void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
8804 LOG(FATAL) << "Unreachable";
8805}
8806
8807void LocationsBuilderMIPS::VisitRem(HRem* rem) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008808 DataType::Type type = rem->GetResultType();
Lena Djokic4b8025c2017-12-21 16:15:50 +01008809 bool call_rem;
8810 if ((type == DataType::Type::kInt64) && rem->InputAt(1)->IsConstant()) {
8811 int64_t imm = CodeGenerator::GetInt64ValueOf(rem->InputAt(1)->AsConstant());
8812 call_rem = (imm != 0) && !IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm)));
8813 } else {
8814 call_rem = (type != DataType::Type::kInt32);
8815 }
8816 LocationSummary::CallKind call_kind = call_rem
8817 ? LocationSummary::kCallOnMainOnly
8818 : LocationSummary::kNoCall;
Vladimir Markoca6fff82017-10-03 14:49:14 +01008819 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008820
8821 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008822 case DataType::Type::kInt32:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008823 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08008824 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008825 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8826 break;
8827
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008828 case DataType::Type::kInt64: {
Lena Djokic4b8025c2017-12-21 16:15:50 +01008829 if (call_rem) {
8830 InvokeRuntimeCallingConvention calling_convention;
8831 locations->SetInAt(0, Location::RegisterPairLocation(
8832 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
8833 locations->SetInAt(1, Location::RegisterPairLocation(
8834 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
8835 locations->SetOut(calling_convention.GetReturnLocation(type));
8836 } else {
8837 locations->SetInAt(0, Location::RequiresRegister());
8838 locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant()));
8839 locations->SetOut(Location::RequiresRegister());
8840 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008841 break;
8842 }
8843
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008844 case DataType::Type::kFloat32:
8845 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008846 InvokeRuntimeCallingConvention calling_convention;
8847 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
8848 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
8849 locations->SetOut(calling_convention.GetReturnLocation(type));
8850 break;
8851 }
8852
8853 default:
8854 LOG(FATAL) << "Unexpected rem type " << type;
8855 }
8856}
8857
8858void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008859 DataType::Type type = instruction->GetType();
Lena Djokic4b8025c2017-12-21 16:15:50 +01008860 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008861
8862 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008863 case DataType::Type::kInt32:
Alexey Frunze7e99e052015-11-24 19:28:01 -08008864 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008865 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008866 case DataType::Type::kInt64: {
Lena Djokic4b8025c2017-12-21 16:15:50 +01008867 if (locations->InAt(1).IsConstant()) {
8868 int64_t imm = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue();
8869 if (imm == 0) {
8870 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
8871 } else if (imm == 1 || imm == -1) {
8872 DivRemOneOrMinusOne(instruction);
8873 } else {
8874 DCHECK(IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm))));
8875 DivRemByPowerOfTwo(instruction);
8876 }
8877 } else {
8878 codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc());
8879 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
8880 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008881 break;
8882 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008883 case DataType::Type::kFloat32: {
Serban Constantinescufca16662016-07-14 09:21:59 +01008884 codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00008885 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008886 break;
8887 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008888 case DataType::Type::kFloat64: {
Serban Constantinescufca16662016-07-14 09:21:59 +01008889 codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00008890 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008891 break;
8892 }
8893 default:
8894 LOG(FATAL) << "Unexpected rem type " << type;
8895 }
8896}
8897
Aart Bik1f8d51b2018-02-15 10:42:37 -08008898static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) {
8899 LocationSummary* locations = new (allocator) LocationSummary(minmax);
8900 switch (minmax->GetResultType()) {
8901 case DataType::Type::kInt32:
8902 case DataType::Type::kInt64:
8903 locations->SetInAt(0, Location::RequiresRegister());
8904 locations->SetInAt(1, Location::RequiresRegister());
8905 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8906 break;
8907 case DataType::Type::kFloat32:
8908 case DataType::Type::kFloat64:
8909 locations->SetInAt(0, Location::RequiresFpuRegister());
8910 locations->SetInAt(1, Location::RequiresFpuRegister());
8911 locations->SetOut(Location::RequiresFpuRegister(), Location::kOutputOverlap);
8912 break;
8913 default:
8914 LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType();
8915 }
8916}
8917
Aart Bik351df3e2018-03-07 11:54:57 -08008918void InstructionCodeGeneratorMIPS::GenerateMinMaxInt(LocationSummary* locations,
8919 bool is_min,
8920 bool isR6,
8921 DataType::Type type) {
Aart Bik1f8d51b2018-02-15 10:42:37 -08008922 if (isR6) {
8923 // Some architectures, such as ARM and MIPS (prior to r6), have a
8924 // conditional move instruction which only changes the target
8925 // (output) register if the condition is true (MIPS prior to r6 had
8926 // MOVF, MOVT, MOVN, and MOVZ). The SELEQZ and SELNEZ instructions
8927 // always change the target (output) register. If the condition is
8928 // true the output register gets the contents of the "rs" register;
8929 // otherwise, the output register is set to zero. One consequence
8930 // of this is that to implement something like "rd = c==0 ? rs : rt"
8931 // MIPS64r6 needs to use a pair of SELEQZ/SELNEZ instructions.
8932 // After executing this pair of instructions one of the output
8933 // registers from the pair will necessarily contain zero. Then the
8934 // code ORs the output registers from the SELEQZ/SELNEZ instructions
8935 // to get the final result.
8936 //
8937 // The initial test to see if the output register is same as the
8938 // first input register is needed to make sure that value in the
8939 // first input register isn't clobbered before we've finished
8940 // computing the output value. The logic in the corresponding else
8941 // clause performs the same task but makes sure the second input
8942 // register isn't clobbered in the event that it's the same register
8943 // as the output register; the else clause also handles the case
8944 // where the output register is distinct from both the first, and the
8945 // second input registers.
8946 if (type == DataType::Type::kInt64) {
8947 Register a_lo = locations->InAt(0).AsRegisterPairLow<Register>();
8948 Register a_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
8949 Register b_lo = locations->InAt(1).AsRegisterPairLow<Register>();
8950 Register b_hi = locations->InAt(1).AsRegisterPairHigh<Register>();
8951 Register out_lo = locations->Out().AsRegisterPairLow<Register>();
8952 Register out_hi = locations->Out().AsRegisterPairHigh<Register>();
8953
8954 MipsLabel compare_done;
8955
8956 if (a_lo == b_lo) {
8957 if (out_lo != a_lo) {
8958 __ Move(out_lo, a_lo);
8959 __ Move(out_hi, a_hi);
8960 }
8961 } else {
8962 __ Slt(TMP, b_hi, a_hi);
8963 __ Bne(b_hi, a_hi, &compare_done);
8964
8965 __ Sltu(TMP, b_lo, a_lo);
8966
8967 __ Bind(&compare_done);
8968
8969 if (is_min) {
8970 __ Seleqz(AT, a_lo, TMP);
8971 __ Selnez(out_lo, b_lo, TMP); // Safe even if out_lo == a_lo/b_lo
8972 // because at this point we're
8973 // done using a_lo/b_lo.
8974 } else {
8975 __ Selnez(AT, a_lo, TMP);
8976 __ Seleqz(out_lo, b_lo, TMP); // ditto
8977 }
8978 __ Or(out_lo, out_lo, AT);
8979 if (is_min) {
8980 __ Seleqz(AT, a_hi, TMP);
8981 __ Selnez(out_hi, b_hi, TMP); // ditto but for out_hi & a_hi/b_hi
8982 } else {
8983 __ Selnez(AT, a_hi, TMP);
8984 __ Seleqz(out_hi, b_hi, TMP); // ditto but for out_hi & a_hi/b_hi
8985 }
8986 __ Or(out_hi, out_hi, AT);
8987 }
8988 } else {
8989 DCHECK_EQ(type, DataType::Type::kInt32);
8990 Register a = locations->InAt(0).AsRegister<Register>();
8991 Register b = locations->InAt(1).AsRegister<Register>();
8992 Register out = locations->Out().AsRegister<Register>();
8993
8994 if (a == b) {
8995 if (out != a) {
8996 __ Move(out, a);
8997 }
8998 } else {
8999 __ Slt(AT, b, a);
9000 if (is_min) {
9001 __ Seleqz(TMP, a, AT);
9002 __ Selnez(AT, b, AT);
9003 } else {
9004 __ Selnez(TMP, a, AT);
9005 __ Seleqz(AT, b, AT);
9006 }
9007 __ Or(out, TMP, AT);
9008 }
9009 }
9010 } else { // !isR6
9011 if (type == DataType::Type::kInt64) {
9012 Register a_lo = locations->InAt(0).AsRegisterPairLow<Register>();
9013 Register a_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
9014 Register b_lo = locations->InAt(1).AsRegisterPairLow<Register>();
9015 Register b_hi = locations->InAt(1).AsRegisterPairHigh<Register>();
9016 Register out_lo = locations->Out().AsRegisterPairLow<Register>();
9017 Register out_hi = locations->Out().AsRegisterPairHigh<Register>();
9018
9019 MipsLabel compare_done;
9020
9021 if (a_lo == b_lo) {
9022 if (out_lo != a_lo) {
9023 __ Move(out_lo, a_lo);
9024 __ Move(out_hi, a_hi);
9025 }
9026 } else {
9027 __ Slt(TMP, a_hi, b_hi);
9028 __ Bne(a_hi, b_hi, &compare_done);
9029
9030 __ Sltu(TMP, a_lo, b_lo);
9031
9032 __ Bind(&compare_done);
9033
9034 if (is_min) {
9035 if (out_lo != a_lo) {
9036 __ Movn(out_hi, a_hi, TMP);
9037 __ Movn(out_lo, a_lo, TMP);
9038 }
9039 if (out_lo != b_lo) {
9040 __ Movz(out_hi, b_hi, TMP);
9041 __ Movz(out_lo, b_lo, TMP);
9042 }
9043 } else {
9044 if (out_lo != a_lo) {
9045 __ Movz(out_hi, a_hi, TMP);
9046 __ Movz(out_lo, a_lo, TMP);
9047 }
9048 if (out_lo != b_lo) {
9049 __ Movn(out_hi, b_hi, TMP);
9050 __ Movn(out_lo, b_lo, TMP);
9051 }
9052 }
9053 }
9054 } else {
9055 DCHECK_EQ(type, DataType::Type::kInt32);
9056 Register a = locations->InAt(0).AsRegister<Register>();
9057 Register b = locations->InAt(1).AsRegister<Register>();
9058 Register out = locations->Out().AsRegister<Register>();
9059
9060 if (a == b) {
9061 if (out != a) {
9062 __ Move(out, a);
9063 }
9064 } else {
9065 __ Slt(AT, a, b);
9066 if (is_min) {
9067 if (out != a) {
9068 __ Movn(out, a, AT);
9069 }
9070 if (out != b) {
9071 __ Movz(out, b, AT);
9072 }
9073 } else {
9074 if (out != a) {
9075 __ Movz(out, a, AT);
9076 }
9077 if (out != b) {
9078 __ Movn(out, b, AT);
9079 }
9080 }
9081 }
9082 }
9083 }
9084}
9085
9086void InstructionCodeGeneratorMIPS::GenerateMinMaxFP(LocationSummary* locations,
9087 bool is_min,
9088 bool isR6,
9089 DataType::Type type) {
9090 FRegister out = locations->Out().AsFpuRegister<FRegister>();
9091 FRegister a = locations->InAt(0).AsFpuRegister<FRegister>();
9092 FRegister b = locations->InAt(1).AsFpuRegister<FRegister>();
9093
9094 if (isR6) {
9095 MipsLabel noNaNs;
9096 MipsLabel done;
9097 FRegister ftmp = ((out != a) && (out != b)) ? out : FTMP;
9098
9099 // When Java computes min/max it prefers a NaN to a number; the
9100 // behavior of MIPSR6 is to prefer numbers to NaNs, i.e., if one of
9101 // the inputs is a NaN and the other is a valid number, the MIPS
9102 // instruction will return the number; Java wants the NaN value
9103 // returned. This is why there is extra logic preceding the use of
9104 // the MIPS min.fmt/max.fmt instructions. If either a, or b holds a
9105 // NaN, return the NaN, otherwise return the min/max.
9106 if (type == DataType::Type::kFloat64) {
9107 __ CmpUnD(FTMP, a, b);
9108 __ Bc1eqz(FTMP, &noNaNs);
9109
9110 // One of the inputs is a NaN
9111 __ CmpEqD(ftmp, a, a);
9112 // If a == a then b is the NaN, otherwise a is the NaN.
9113 __ SelD(ftmp, a, b);
9114
9115 if (ftmp != out) {
9116 __ MovD(out, ftmp);
9117 }
9118
9119 __ B(&done);
9120
9121 __ Bind(&noNaNs);
9122
9123 if (is_min) {
9124 __ MinD(out, a, b);
9125 } else {
9126 __ MaxD(out, a, b);
9127 }
9128 } else {
9129 DCHECK_EQ(type, DataType::Type::kFloat32);
9130 __ CmpUnS(FTMP, a, b);
9131 __ Bc1eqz(FTMP, &noNaNs);
9132
9133 // One of the inputs is a NaN
9134 __ CmpEqS(ftmp, a, a);
9135 // If a == a then b is the NaN, otherwise a is the NaN.
9136 __ SelS(ftmp, a, b);
9137
9138 if (ftmp != out) {
9139 __ MovS(out, ftmp);
9140 }
9141
9142 __ B(&done);
9143
9144 __ Bind(&noNaNs);
9145
9146 if (is_min) {
9147 __ MinS(out, a, b);
9148 } else {
9149 __ MaxS(out, a, b);
9150 }
9151 }
9152
9153 __ Bind(&done);
9154
9155 } else { // !isR6
9156 MipsLabel ordered;
9157 MipsLabel compare;
9158 MipsLabel select;
9159 MipsLabel done;
9160
9161 if (type == DataType::Type::kFloat64) {
9162 __ CunD(a, b);
9163 } else {
9164 DCHECK_EQ(type, DataType::Type::kFloat32);
9165 __ CunS(a, b);
9166 }
9167 __ Bc1f(&ordered);
9168
9169 // a or b (or both) is a NaN. Return one, which is a NaN.
9170 if (type == DataType::Type::kFloat64) {
9171 __ CeqD(b, b);
9172 } else {
9173 __ CeqS(b, b);
9174 }
9175 __ B(&select);
9176
9177 __ Bind(&ordered);
9178
9179 // Neither is a NaN.
9180 // a == b? (-0.0 compares equal with +0.0)
9181 // If equal, handle zeroes, else compare further.
9182 if (type == DataType::Type::kFloat64) {
9183 __ CeqD(a, b);
9184 } else {
9185 __ CeqS(a, b);
9186 }
9187 __ Bc1f(&compare);
9188
9189 // a == b either bit for bit or one is -0.0 and the other is +0.0.
9190 if (type == DataType::Type::kFloat64) {
9191 __ MoveFromFpuHigh(TMP, a);
9192 __ MoveFromFpuHigh(AT, b);
9193 } else {
9194 __ Mfc1(TMP, a);
9195 __ Mfc1(AT, b);
9196 }
9197
9198 if (is_min) {
9199 // -0.0 prevails over +0.0.
9200 __ Or(TMP, TMP, AT);
9201 } else {
9202 // +0.0 prevails over -0.0.
9203 __ And(TMP, TMP, AT);
9204 }
9205
9206 if (type == DataType::Type::kFloat64) {
9207 __ Mfc1(AT, a);
9208 __ Mtc1(AT, out);
9209 __ MoveToFpuHigh(TMP, out);
9210 } else {
9211 __ Mtc1(TMP, out);
9212 }
9213 __ B(&done);
9214
9215 __ Bind(&compare);
9216
9217 if (type == DataType::Type::kFloat64) {
9218 if (is_min) {
9219 // return (a <= b) ? a : b;
9220 __ ColeD(a, b);
9221 } else {
9222 // return (a >= b) ? a : b;
9223 __ ColeD(b, a); // b <= a
9224 }
9225 } else {
9226 if (is_min) {
9227 // return (a <= b) ? a : b;
9228 __ ColeS(a, b);
9229 } else {
9230 // return (a >= b) ? a : b;
9231 __ ColeS(b, a); // b <= a
9232 }
9233 }
9234
9235 __ Bind(&select);
9236
9237 if (type == DataType::Type::kFloat64) {
9238 __ MovtD(out, a);
9239 __ MovfD(out, b);
9240 } else {
9241 __ MovtS(out, a);
9242 __ MovfS(out, b);
9243 }
9244
9245 __ Bind(&done);
9246 }
9247}
9248
Aart Bik351df3e2018-03-07 11:54:57 -08009249void InstructionCodeGeneratorMIPS::GenerateMinMax(HBinaryOperation* minmax, bool is_min) {
9250 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
9251 DataType::Type type = minmax->GetResultType();
9252 switch (type) {
9253 case DataType::Type::kInt32:
9254 case DataType::Type::kInt64:
9255 GenerateMinMaxInt(minmax->GetLocations(), is_min, isR6, type);
9256 break;
9257 case DataType::Type::kFloat32:
9258 case DataType::Type::kFloat64:
9259 GenerateMinMaxFP(minmax->GetLocations(), is_min, isR6, type);
9260 break;
9261 default:
9262 LOG(FATAL) << "Unexpected type for HMinMax " << type;
9263 }
9264}
9265
Aart Bik1f8d51b2018-02-15 10:42:37 -08009266void LocationsBuilderMIPS::VisitMin(HMin* min) {
9267 CreateMinMaxLocations(GetGraph()->GetAllocator(), min);
9268}
9269
9270void InstructionCodeGeneratorMIPS::VisitMin(HMin* min) {
Aart Bik351df3e2018-03-07 11:54:57 -08009271 GenerateMinMax(min, /*is_min*/ true);
Aart Bik1f8d51b2018-02-15 10:42:37 -08009272}
9273
9274void LocationsBuilderMIPS::VisitMax(HMax* max) {
9275 CreateMinMaxLocations(GetGraph()->GetAllocator(), max);
9276}
9277
9278void InstructionCodeGeneratorMIPS::VisitMax(HMax* max) {
Aart Bik351df3e2018-03-07 11:54:57 -08009279 GenerateMinMax(max, /*is_min*/ false);
Aart Bik1f8d51b2018-02-15 10:42:37 -08009280}
9281
Aart Bik3dad3412018-02-28 12:01:46 -08009282void LocationsBuilderMIPS::VisitAbs(HAbs* abs) {
9283 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs);
9284 switch (abs->GetResultType()) {
9285 case DataType::Type::kInt32:
9286 case DataType::Type::kInt64:
9287 locations->SetInAt(0, Location::RequiresRegister());
9288 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
9289 break;
9290 case DataType::Type::kFloat32:
9291 case DataType::Type::kFloat64:
9292 locations->SetInAt(0, Location::RequiresFpuRegister());
9293 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
9294 break;
9295 default:
9296 LOG(FATAL) << "Unexpected abs type " << abs->GetResultType();
9297 }
9298}
9299
9300void InstructionCodeGeneratorMIPS::GenerateAbsFP(LocationSummary* locations,
9301 DataType::Type type,
9302 bool isR2OrNewer,
9303 bool isR6) {
9304 FRegister in = locations->InAt(0).AsFpuRegister<FRegister>();
9305 FRegister out = locations->Out().AsFpuRegister<FRegister>();
9306
9307 // Note, as a "quality of implementation", rather than pure "spec compliance", we require that
9308 // Math.abs() clears the sign bit (but changes nothing else) for all numbers, including NaN
9309 // (signaling NaN may become quiet though).
9310 //
9311 // The ABS.fmt instructions (abs.s and abs.d) do exactly that when NAN2008=1 (R6). For this case,
9312 // both regular floating point numbers and NAN values are treated alike, only the sign bit is
9313 // affected by this instruction.
9314 // But when NAN2008=0 (R2 and before), the ABS.fmt instructions can't be used. For this case, any
9315 // NaN operand signals invalid operation. This means that other bits (not just sign bit) might be
9316 // changed when doing abs(NaN). Because of that, we clear sign bit in a different way.
9317 if (isR6) {
9318 if (type == DataType::Type::kFloat64) {
9319 __ AbsD(out, in);
9320 } else {
9321 DCHECK_EQ(type, DataType::Type::kFloat32);
9322 __ AbsS(out, in);
9323 }
9324 } else {
9325 if (type == DataType::Type::kFloat64) {
9326 if (in != out) {
9327 __ MovD(out, in);
9328 }
9329 __ MoveFromFpuHigh(TMP, in);
9330 // ins instruction is not available for R1.
9331 if (isR2OrNewer) {
9332 __ Ins(TMP, ZERO, 31, 1);
9333 } else {
9334 __ Sll(TMP, TMP, 1);
9335 __ Srl(TMP, TMP, 1);
9336 }
9337 __ MoveToFpuHigh(TMP, out);
9338 } else {
9339 DCHECK_EQ(type, DataType::Type::kFloat32);
9340 __ Mfc1(TMP, in);
9341 // ins instruction is not available for R1.
9342 if (isR2OrNewer) {
9343 __ Ins(TMP, ZERO, 31, 1);
9344 } else {
9345 __ Sll(TMP, TMP, 1);
9346 __ Srl(TMP, TMP, 1);
9347 }
9348 __ Mtc1(TMP, out);
9349 }
9350 }
9351}
9352
9353void InstructionCodeGeneratorMIPS::VisitAbs(HAbs* abs) {
9354 LocationSummary* locations = abs->GetLocations();
9355 bool isR2OrNewer = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
9356 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
9357 switch (abs->GetResultType()) {
9358 case DataType::Type::kInt32: {
9359 Register in = locations->InAt(0).AsRegister<Register>();
9360 Register out = locations->Out().AsRegister<Register>();
9361 __ Sra(AT, in, 31);
9362 __ Xor(out, in, AT);
9363 __ Subu(out, out, AT);
9364 break;
9365 }
9366 case DataType::Type::kInt64: {
9367 Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>();
9368 Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
9369 Register out_lo = locations->Out().AsRegisterPairLow<Register>();
9370 Register out_hi = locations->Out().AsRegisterPairHigh<Register>();
9371 // The comments in this section show the analogous operations which would
9372 // be performed if we had 64-bit registers "in", and "out".
9373 // __ Dsra32(AT, in, 31);
9374 __ Sra(AT, in_hi, 31);
9375 // __ Xor(out, in, AT);
9376 __ Xor(TMP, in_lo, AT);
9377 __ Xor(out_hi, in_hi, AT);
9378 // __ Dsubu(out, out, AT);
9379 __ Subu(out_lo, TMP, AT);
9380 __ Sltu(TMP, out_lo, TMP);
9381 __ Addu(out_hi, out_hi, TMP);
9382 break;
9383 }
9384 case DataType::Type::kFloat32:
9385 case DataType::Type::kFloat64:
9386 GenerateAbsFP(locations, abs->GetResultType(), isR2OrNewer, isR6);
9387 break;
9388 default:
9389 LOG(FATAL) << "Unexpected abs type " << abs->GetResultType();
9390 }
9391}
9392
Igor Murashkind01745e2017-04-05 16:40:31 -07009393void LocationsBuilderMIPS::VisitConstructorFence(HConstructorFence* constructor_fence) {
9394 constructor_fence->SetLocations(nullptr);
9395}
9396
9397void InstructionCodeGeneratorMIPS::VisitConstructorFence(
9398 HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) {
9399 GenerateMemoryBarrier(MemBarrierKind::kStoreStore);
9400}
9401
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009402void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
9403 memory_barrier->SetLocations(nullptr);
9404}
9405
9406void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
9407 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
9408}
9409
9410void LocationsBuilderMIPS::VisitReturn(HReturn* ret) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01009411 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009412 DataType::Type return_type = ret->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009413 locations->SetInAt(0, MipsReturnLocation(return_type));
9414}
9415
9416void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
9417 codegen_->GenerateFrameExit();
9418}
9419
9420void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) {
9421 ret->SetLocations(nullptr);
9422}
9423
9424void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
9425 codegen_->GenerateFrameExit();
9426}
9427
Alexey Frunze92d90602015-12-18 18:16:36 -08009428void LocationsBuilderMIPS::VisitRor(HRor* ror) {
9429 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00009430}
9431
Alexey Frunze92d90602015-12-18 18:16:36 -08009432void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) {
9433 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00009434}
9435
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009436void LocationsBuilderMIPS::VisitShl(HShl* shl) {
9437 HandleShift(shl);
9438}
9439
9440void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) {
9441 HandleShift(shl);
9442}
9443
9444void LocationsBuilderMIPS::VisitShr(HShr* shr) {
9445 HandleShift(shr);
9446}
9447
9448void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) {
9449 HandleShift(shr);
9450}
9451
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009452void LocationsBuilderMIPS::VisitSub(HSub* instruction) {
9453 HandleBinaryOp(instruction);
9454}
9455
9456void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) {
9457 HandleBinaryOp(instruction);
9458}
9459
9460void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
9461 HandleFieldGet(instruction, instruction->GetFieldInfo());
9462}
9463
9464void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
9465 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
9466}
9467
9468void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
9469 HandleFieldSet(instruction, instruction->GetFieldInfo());
9470}
9471
9472void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Goran Jakovljevice114da22016-12-26 14:21:43 +01009473 HandleFieldSet(instruction,
9474 instruction->GetFieldInfo(),
9475 instruction->GetDexPc(),
9476 instruction->GetValueCanBeNull());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009477}
9478
9479void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet(
9480 HUnresolvedInstanceFieldGet* instruction) {
9481 FieldAccessCallingConventionMIPS calling_convention;
9482 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
9483 instruction->GetFieldType(),
9484 calling_convention);
9485}
9486
9487void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet(
9488 HUnresolvedInstanceFieldGet* instruction) {
9489 FieldAccessCallingConventionMIPS calling_convention;
9490 codegen_->GenerateUnresolvedFieldAccess(instruction,
9491 instruction->GetFieldType(),
9492 instruction->GetFieldIndex(),
9493 instruction->GetDexPc(),
9494 calling_convention);
9495}
9496
9497void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet(
9498 HUnresolvedInstanceFieldSet* instruction) {
9499 FieldAccessCallingConventionMIPS calling_convention;
9500 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
9501 instruction->GetFieldType(),
9502 calling_convention);
9503}
9504
9505void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet(
9506 HUnresolvedInstanceFieldSet* instruction) {
9507 FieldAccessCallingConventionMIPS calling_convention;
9508 codegen_->GenerateUnresolvedFieldAccess(instruction,
9509 instruction->GetFieldType(),
9510 instruction->GetFieldIndex(),
9511 instruction->GetDexPc(),
9512 calling_convention);
9513}
9514
9515void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet(
9516 HUnresolvedStaticFieldGet* instruction) {
9517 FieldAccessCallingConventionMIPS calling_convention;
9518 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
9519 instruction->GetFieldType(),
9520 calling_convention);
9521}
9522
9523void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet(
9524 HUnresolvedStaticFieldGet* instruction) {
9525 FieldAccessCallingConventionMIPS calling_convention;
9526 codegen_->GenerateUnresolvedFieldAccess(instruction,
9527 instruction->GetFieldType(),
9528 instruction->GetFieldIndex(),
9529 instruction->GetDexPc(),
9530 calling_convention);
9531}
9532
9533void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet(
9534 HUnresolvedStaticFieldSet* instruction) {
9535 FieldAccessCallingConventionMIPS calling_convention;
9536 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
9537 instruction->GetFieldType(),
9538 calling_convention);
9539}
9540
9541void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet(
9542 HUnresolvedStaticFieldSet* instruction) {
9543 FieldAccessCallingConventionMIPS calling_convention;
9544 codegen_->GenerateUnresolvedFieldAccess(instruction,
9545 instruction->GetFieldType(),
9546 instruction->GetFieldIndex(),
9547 instruction->GetDexPc(),
9548 calling_convention);
9549}
9550
9551void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01009552 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
9553 instruction, LocationSummary::kCallOnSlowPath);
Lena Djokicca8c2952017-05-29 11:31:46 +02009554 // In suspend check slow path, usually there are no caller-save registers at all.
9555 // If SIMD instructions are present, however, we force spilling all live SIMD
9556 // registers in full width (since the runtime only saves/restores lower part).
9557 locations->SetCustomSlowPathCallerSaves(
9558 GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009559}
9560
9561void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
9562 HBasicBlock* block = instruction->GetBlock();
9563 if (block->GetLoopInformation() != nullptr) {
9564 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
9565 // The back edge will generate the suspend check.
9566 return;
9567 }
9568 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
9569 // The goto will generate the suspend check.
9570 return;
9571 }
9572 GenerateSuspendCheck(instruction, nullptr);
9573}
9574
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009575void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01009576 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
9577 instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009578 InvokeRuntimeCallingConvention calling_convention;
9579 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
9580}
9581
9582void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) {
Serban Constantinescufca16662016-07-14 09:21:59 +01009583 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009584 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
9585}
9586
9587void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009588 DataType::Type input_type = conversion->GetInputType();
9589 DataType::Type result_type = conversion->GetResultType();
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01009590 DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type))
9591 << input_type << " -> " << result_type;
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009592 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009593
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009594 if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) ||
9595 (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009596 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
9597 }
9598
9599 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009600 if (!isR6 &&
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009601 ((DataType::IsFloatingPointType(result_type) && input_type == DataType::Type::kInt64) ||
9602 (result_type == DataType::Type::kInt64 && DataType::IsFloatingPointType(input_type)))) {
Serban Constantinescu54ff4822016-07-07 18:03:19 +01009603 call_kind = LocationSummary::kCallOnMainOnly;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009604 }
9605
Vladimir Markoca6fff82017-10-03 14:49:14 +01009606 LocationSummary* locations =
9607 new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009608
9609 if (call_kind == LocationSummary::kNoCall) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009610 if (DataType::IsFloatingPointType(input_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009611 locations->SetInAt(0, Location::RequiresFpuRegister());
9612 } else {
9613 locations->SetInAt(0, Location::RequiresRegister());
9614 }
9615
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009616 if (DataType::IsFloatingPointType(result_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009617 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
9618 } else {
9619 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
9620 }
9621 } else {
9622 InvokeRuntimeCallingConvention calling_convention;
9623
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009624 if (DataType::IsFloatingPointType(input_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009625 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
9626 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009627 DCHECK_EQ(input_type, DataType::Type::kInt64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009628 locations->SetInAt(0, Location::RegisterPairLocation(
9629 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
9630 }
9631
9632 locations->SetOut(calling_convention.GetReturnLocation(result_type));
9633 }
9634}
9635
9636void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) {
9637 LocationSummary* locations = conversion->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009638 DataType::Type result_type = conversion->GetResultType();
9639 DataType::Type input_type = conversion->GetInputType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009640 bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009641 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009642
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01009643 DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type))
9644 << input_type << " -> " << result_type;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009645
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009646 if (result_type == DataType::Type::kInt64 && DataType::IsIntegralType(input_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009647 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
9648 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
9649 Register src = locations->InAt(0).AsRegister<Register>();
9650
Alexey Frunzea871ef12016-06-27 15:20:11 -07009651 if (dst_low != src) {
9652 __ Move(dst_low, src);
9653 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009654 __ Sra(dst_high, src, 31);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009655 } else if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009656 Register dst = locations->Out().AsRegister<Register>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009657 Register src = (input_type == DataType::Type::kInt64)
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009658 ? locations->InAt(0).AsRegisterPairLow<Register>()
9659 : locations->InAt(0).AsRegister<Register>();
9660
9661 switch (result_type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01009662 case DataType::Type::kUint8:
9663 __ Andi(dst, src, 0xFF);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009664 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009665 case DataType::Type::kInt8:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009666 if (has_sign_extension) {
9667 __ Seb(dst, src);
9668 } else {
9669 __ Sll(dst, src, 24);
9670 __ Sra(dst, dst, 24);
9671 }
9672 break;
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01009673 case DataType::Type::kUint16:
9674 __ Andi(dst, src, 0xFFFF);
9675 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009676 case DataType::Type::kInt16:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009677 if (has_sign_extension) {
9678 __ Seh(dst, src);
9679 } else {
9680 __ Sll(dst, src, 16);
9681 __ Sra(dst, dst, 16);
9682 }
9683 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009684 case DataType::Type::kInt32:
Alexey Frunzea871ef12016-06-27 15:20:11 -07009685 if (dst != src) {
9686 __ Move(dst, src);
9687 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009688 break;
9689
9690 default:
9691 LOG(FATAL) << "Unexpected type conversion from " << input_type
9692 << " to " << result_type;
9693 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009694 } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) {
9695 if (input_type == DataType::Type::kInt64) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009696 if (isR6) {
9697 // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
9698 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
9699 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
9700 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
9701 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
9702 __ Mtc1(src_low, FTMP);
9703 __ Mthc1(src_high, FTMP);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009704 if (result_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009705 __ Cvtsl(dst, FTMP);
9706 } else {
9707 __ Cvtdl(dst, FTMP);
9708 }
9709 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009710 QuickEntrypointEnum entrypoint =
9711 (result_type == DataType::Type::kFloat32) ? kQuickL2f : kQuickL2d;
Serban Constantinescufca16662016-07-14 09:21:59 +01009712 codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009713 if (result_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009714 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
9715 } else {
9716 CheckEntrypointTypes<kQuickL2d, double, int64_t>();
9717 }
9718 }
9719 } else {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009720 Register src = locations->InAt(0).AsRegister<Register>();
9721 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
9722 __ Mtc1(src, FTMP);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009723 if (result_type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009724 __ Cvtsw(dst, FTMP);
9725 } else {
9726 __ Cvtdw(dst, FTMP);
9727 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009728 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009729 } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) {
9730 CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64);
Lena Djokicf4e23a82017-05-09 15:43:45 +02009731
9732 // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum
9733 // value of the output type if the input is outside of the range after the truncation or
9734 // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct
9735 // results. This matches the desired float/double-to-int/long conversion exactly.
9736 //
9737 // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive
9738 // value when the input is either a NaN or is outside of the range of the output type
9739 // after the truncation. IOW, the three special cases (NaN, too small, too big) produce
9740 // the same result.
9741 //
9742 // The code takes care of the different behaviors by first comparing the input to the
9743 // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int).
9744 // If the input is greater than or equal to the minimum, it procedes to the truncate
9745 // instruction, which will handle such an input the same way irrespective of NAN2008.
9746 // Otherwise the input is compared to itself to determine whether it is a NaN or not
9747 // in order to return either zero or the minimum value.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009748 if (result_type == DataType::Type::kInt64) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009749 if (isR6) {
9750 // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
9751 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
9752 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
9753 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
9754 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009755
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009756 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009757 __ TruncLS(FTMP, src);
9758 } else {
9759 __ TruncLD(FTMP, src);
9760 }
9761 __ Mfc1(dst_low, FTMP);
9762 __ Mfhc1(dst_high, FTMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009763 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009764 QuickEntrypointEnum entrypoint =
9765 (input_type == DataType::Type::kFloat32) ? kQuickF2l : kQuickD2l;
Serban Constantinescufca16662016-07-14 09:21:59 +01009766 codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009767 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009768 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
9769 } else {
9770 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
9771 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009772 }
9773 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009774 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
9775 Register dst = locations->Out().AsRegister<Register>();
9776 MipsLabel truncate;
9777 MipsLabel done;
9778
Lena Djokicf4e23a82017-05-09 15:43:45 +02009779 if (!isR6) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009780 if (input_type == DataType::Type::kFloat32) {
Lena Djokicf4e23a82017-05-09 15:43:45 +02009781 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min());
9782 __ LoadConst32(TMP, min_val);
9783 __ Mtc1(TMP, FTMP);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009784 } else {
Lena Djokicf4e23a82017-05-09 15:43:45 +02009785 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min());
9786 __ LoadConst32(TMP, High32Bits(min_val));
9787 __ Mtc1(ZERO, FTMP);
9788 __ MoveToFpuHigh(TMP, FTMP);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009789 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009790
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009791 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009792 __ ColeS(0, FTMP, src);
9793 } else {
9794 __ ColeD(0, FTMP, src);
9795 }
9796 __ Bc1t(0, &truncate);
9797
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009798 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009799 __ CeqS(0, src, src);
9800 } else {
9801 __ CeqD(0, src, src);
9802 }
9803 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
9804 __ Movf(dst, ZERO, 0);
Lena Djokicf4e23a82017-05-09 15:43:45 +02009805
9806 __ B(&done);
9807
9808 __ Bind(&truncate);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009809 }
9810
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009811 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08009812 __ TruncWS(FTMP, src);
9813 } else {
9814 __ TruncWD(FTMP, src);
9815 }
9816 __ Mfc1(dst, FTMP);
9817
Lena Djokicf4e23a82017-05-09 15:43:45 +02009818 if (!isR6) {
9819 __ Bind(&done);
9820 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009821 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009822 } else if (DataType::IsFloatingPointType(result_type) &&
9823 DataType::IsFloatingPointType(input_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009824 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
9825 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01009826 if (result_type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009827 __ Cvtsd(dst, src);
9828 } else {
9829 __ Cvtds(dst, src);
9830 }
9831 } else {
9832 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
9833 << " to " << result_type;
9834 }
9835}
9836
9837void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) {
9838 HandleShift(ushr);
9839}
9840
9841void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) {
9842 HandleShift(ushr);
9843}
9844
9845void LocationsBuilderMIPS::VisitXor(HXor* instruction) {
9846 HandleBinaryOp(instruction);
9847}
9848
9849void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) {
9850 HandleBinaryOp(instruction);
9851}
9852
9853void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
9854 // Nothing to do, this should be removed during prepare for register allocator.
9855 LOG(FATAL) << "Unreachable";
9856}
9857
9858void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
9859 // Nothing to do, this should be removed during prepare for register allocator.
9860 LOG(FATAL) << "Unreachable";
9861}
9862
9863void LocationsBuilderMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009864 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009865}
9866
9867void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009868 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009869}
9870
9871void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009872 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009873}
9874
9875void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009876 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009877}
9878
9879void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009880 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009881}
9882
9883void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009884 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009885}
9886
9887void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009888 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009889}
9890
9891void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009892 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009893}
9894
9895void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009896 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009897}
9898
9899void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009900 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009901}
9902
9903void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009904 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009905}
9906
9907void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009908 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009909}
9910
9911void LocationsBuilderMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009912 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009913}
9914
9915void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009916 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009917}
9918
9919void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009920 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009921}
9922
9923void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009924 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009925}
9926
9927void LocationsBuilderMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009928 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009929}
9930
9931void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009932 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009933}
9934
9935void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009936 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009937}
9938
9939void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009940 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009941}
9942
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009943void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
9944 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01009945 new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009946 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07009947 if (!codegen_->GetInstructionSetFeatures().IsR6()) {
9948 uint32_t num_entries = switch_instr->GetNumEntries();
9949 if (num_entries > InstructionCodeGeneratorMIPS::kPackedSwitchJumpTableThreshold) {
9950 // When there's no HMipsComputeBaseMethodAddress input, R2 uses the NAL
9951 // instruction to simulate PC-relative addressing when accessing the jump table.
9952 // NAL clobbers RA. Make sure RA is preserved.
9953 codegen_->ClobberRA();
9954 }
9955 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009956}
9957
Alexey Frunze96b66822016-09-10 02:32:44 -07009958void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg,
9959 int32_t lower_bound,
9960 uint32_t num_entries,
9961 HBasicBlock* switch_block,
9962 HBasicBlock* default_block) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009963 // Create a set of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00009964 Register temp_reg = TMP;
9965 __ Addiu32(temp_reg, value_reg, -lower_bound);
9966 // Jump to default if index is negative
9967 // Note: We don't check the case that index is positive while value < lower_bound, because in
9968 // this case, index >= num_entries must be true. So that we can save one branch instruction.
9969 __ Bltz(temp_reg, codegen_->GetLabelOf(default_block));
9970
Alexey Frunze96b66822016-09-10 02:32:44 -07009971 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00009972 // Jump to successors[0] if value == lower_bound.
9973 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0]));
9974 int32_t last_index = 0;
9975 for (; num_entries - last_index > 2; last_index += 2) {
9976 __ Addiu(temp_reg, temp_reg, -2);
9977 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
9978 __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
9979 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
9980 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
9981 }
9982 if (num_entries - last_index == 2) {
9983 // The last missing case_value.
9984 __ Addiu(temp_reg, temp_reg, -1);
9985 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009986 }
9987
Vladimir Markof3e0ee22015-12-17 15:23:13 +00009988 // And the default for any other value.
Alexey Frunze96b66822016-09-10 02:32:44 -07009989 if (!codegen_->GoesToNextBlock(switch_block, default_block)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009990 __ B(codegen_->GetLabelOf(default_block));
9991 }
9992}
9993
Alexey Frunze96b66822016-09-10 02:32:44 -07009994void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg,
9995 Register constant_area,
9996 int32_t lower_bound,
9997 uint32_t num_entries,
9998 HBasicBlock* switch_block,
9999 HBasicBlock* default_block) {
10000 // Create a jump table.
10001 std::vector<MipsLabel*> labels(num_entries);
10002 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
10003 for (uint32_t i = 0; i < num_entries; i++) {
10004 labels[i] = codegen_->GetLabelOf(successors[i]);
10005 }
10006 JumpTable* table = __ CreateJumpTable(std::move(labels));
10007
10008 // Is the value in range?
10009 __ Addiu32(TMP, value_reg, -lower_bound);
10010 if (IsInt<16>(static_cast<int32_t>(num_entries))) {
10011 __ Sltiu(AT, TMP, num_entries);
10012 __ Beqz(AT, codegen_->GetLabelOf(default_block));
10013 } else {
10014 __ LoadConst32(AT, num_entries);
10015 __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block));
10016 }
10017
10018 // We are in the range of the table.
10019 // Load the target address from the jump table, indexing by the value.
10020 __ LoadLabelAddress(AT, constant_area, table->GetLabel());
Chris Larsencd0295d2017-03-31 15:26:54 -070010021 __ ShiftAndAdd(TMP, TMP, AT, 2, TMP);
Alexey Frunze96b66822016-09-10 02:32:44 -070010022 __ Lw(TMP, TMP, 0);
10023 // Compute the absolute target address by adding the table start address
10024 // (the table contains offsets to targets relative to its start).
10025 __ Addu(TMP, TMP, AT);
10026 // And jump.
10027 __ Jr(TMP);
10028 __ NopIfNoReordering();
10029}
10030
10031void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
10032 int32_t lower_bound = switch_instr->GetStartValue();
10033 uint32_t num_entries = switch_instr->GetNumEntries();
10034 LocationSummary* locations = switch_instr->GetLocations();
10035 Register value_reg = locations->InAt(0).AsRegister<Register>();
10036 HBasicBlock* switch_block = switch_instr->GetBlock();
10037 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
10038
Alexey Frunze3b8c82f2017-10-10 23:01:34 -070010039 if (num_entries > kPackedSwitchJumpTableThreshold) {
Alexey Frunze96b66822016-09-10 02:32:44 -070010040 // R6 uses PC-relative addressing to access the jump table.
Alexey Frunze3b8c82f2017-10-10 23:01:34 -070010041 //
10042 // R2, OTOH, uses an HMipsComputeBaseMethodAddress input (when available)
10043 // to access the jump table and it is implemented by changing HPackedSwitch to
10044 // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress (see
10045 // VisitMipsPackedSwitch()).
10046 //
10047 // When there's no HMipsComputeBaseMethodAddress input (e.g. in presence of
10048 // irreducible loops), R2 uses the NAL instruction to simulate PC-relative
10049 // addressing.
Alexey Frunze96b66822016-09-10 02:32:44 -070010050 GenTableBasedPackedSwitch(value_reg,
10051 ZERO,
10052 lower_bound,
10053 num_entries,
10054 switch_block,
10055 default_block);
10056 } else {
10057 GenPackedSwitchWithCompares(value_reg,
10058 lower_bound,
10059 num_entries,
10060 switch_block,
10061 default_block);
10062 }
10063}
10064
10065void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) {
10066 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +010010067 new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall);
Alexey Frunze96b66822016-09-10 02:32:44 -070010068 locations->SetInAt(0, Location::RequiresRegister());
10069 // Constant area pointer (HMipsComputeBaseMethodAddress).
10070 locations->SetInAt(1, Location::RequiresRegister());
10071}
10072
10073void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) {
10074 int32_t lower_bound = switch_instr->GetStartValue();
10075 uint32_t num_entries = switch_instr->GetNumEntries();
10076 LocationSummary* locations = switch_instr->GetLocations();
10077 Register value_reg = locations->InAt(0).AsRegister<Register>();
10078 Register constant_area = locations->InAt(1).AsRegister<Register>();
10079 HBasicBlock* switch_block = switch_instr->GetBlock();
10080 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
10081
10082 // This is an R2-only path. HPackedSwitch has been changed to
10083 // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress
10084 // required to address the jump table relative to PC.
10085 GenTableBasedPackedSwitch(value_reg,
10086 constant_area,
10087 lower_bound,
10088 num_entries,
10089 switch_block,
10090 default_block);
10091}
10092
Alexey Frunzee3fb2452016-05-10 16:08:05 -070010093void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress(
10094 HMipsComputeBaseMethodAddress* insn) {
10095 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +010010096 new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall);
Alexey Frunzee3fb2452016-05-10 16:08:05 -070010097 locations->SetOut(Location::RequiresRegister());
10098}
10099
10100void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress(
10101 HMipsComputeBaseMethodAddress* insn) {
10102 LocationSummary* locations = insn->GetLocations();
10103 Register reg = locations->Out().AsRegister<Register>();
10104
10105 CHECK(!codegen_->GetInstructionSetFeatures().IsR6());
10106
10107 // Generate a dummy PC-relative call to obtain PC.
10108 __ Nal();
10109 // Grab the return address off RA.
10110 __ Move(reg, RA);
10111
10112 // Remember this offset (the obtained PC value) for later use with constant area.
10113 __ BindPcRelBaseLabel();
10114}
10115
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020010116void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
10117 // The trampoline uses the same calling convention as dex calling conventions,
10118 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
10119 // the method_idx.
10120 HandleInvoke(invoke);
10121}
10122
10123void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
10124 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
10125}
10126
Roland Levillain2aba7cd2016-02-03 12:27:20 +000010127void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) {
10128 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +010010129 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Roland Levillain2aba7cd2016-02-03 12:27:20 +000010130 locations->SetInAt(0, Location::RequiresRegister());
10131 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000010132}
10133
Roland Levillain2aba7cd2016-02-03 12:27:20 +000010134void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) {
10135 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +000010136 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +010010137 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Roland Levillain2aba7cd2016-02-03 12:27:20 +000010138 instruction->GetIndex(), kMipsPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +010010139 __ LoadFromOffset(kLoadWord,
10140 locations->Out().AsRegister<Register>(),
10141 locations->InAt(0).AsRegister<Register>(),
10142 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +000010143 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +010010144 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +000010145 instruction->GetIndex(), kMipsPointerSize));
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +000010146 __ LoadFromOffset(kLoadWord,
10147 locations->Out().AsRegister<Register>(),
10148 locations->InAt(0).AsRegister<Register>(),
10149 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
Nicolas Geoffrayff484b92016-07-13 14:13:48 +010010150 __ LoadFromOffset(kLoadWord,
10151 locations->Out().AsRegister<Register>(),
10152 locations->Out().AsRegister<Register>(),
10153 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +000010154 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000010155}
10156
xueliang.zhonge0eb4832017-10-30 13:43:14 +000010157void LocationsBuilderMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction
10158 ATTRIBUTE_UNUSED) {
10159 LOG(FATAL) << "Unreachable";
10160}
10161
10162void InstructionCodeGeneratorMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction
10163 ATTRIBUTE_UNUSED) {
10164 LOG(FATAL) << "Unreachable";
10165}
10166
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020010167#undef __
10168#undef QUICK_ENTRY_POINT
10169
10170} // namespace mips
10171} // namespace art