blob: 7713faf6eb41fc519aef6f4603e287f9fccbcf2a [file] [log] [blame]
Alexey Frunze4dda3372015-06-01 18:31:49 -07001/*
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_mips64.h"
18
Alexey Frunze4147fcc2017-06-17 19:57:27 -070019#include "arch/mips64/asm_support_mips64.h"
Alexey Frunzec857c742015-09-23 15:12:39 -070020#include "art_method.h"
Vladimir Marko94ec2db2017-09-06 17:21:03 +010021#include "class_table.h"
Alexey Frunzec857c742015-09-23 15:12:39 -070022#include "code_generator_utils.h"
Alexey Frunze19f6c692016-11-30 19:19:55 -080023#include "compiled_method.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070024#include "entrypoints/quick/quick_entrypoints.h"
25#include "entrypoints/quick/quick_entrypoints_enum.h"
26#include "gc/accounting/card_table.h"
Andreas Gampe09659c22017-09-18 18:23:32 -070027#include "heap_poisoning.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070028#include "intrinsics.h"
Chris Larsen3039e382015-08-26 07:54:08 -070029#include "intrinsics_mips64.h"
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010030#include "linker/linker_patch.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070031#include "mirror/array-inl.h"
32#include "mirror/class-inl.h"
33#include "offsets.h"
Vladimir Marko174b2e22017-10-12 13:34:49 +010034#include "stack_map_stream.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070035#include "thread.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070036#include "utils/assembler.h"
Alexey Frunzea0e87b02015-09-24 22:57:20 -070037#include "utils/mips64/assembler_mips64.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070038#include "utils/stack_checks.h"
39
40namespace art {
41namespace mips64 {
42
43static constexpr int kCurrentMethodStackOffset = 0;
44static constexpr GpuRegister kMethodRegisterArgument = A0;
45
Alexey Frunze4147fcc2017-06-17 19:57:27 -070046// Flags controlling the use of thunks for Baker read barriers.
47constexpr bool kBakerReadBarrierThunksEnableForFields = true;
48constexpr bool kBakerReadBarrierThunksEnableForArrays = true;
49constexpr bool kBakerReadBarrierThunksEnableForGcRoots = true;
50
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010051Location Mips64ReturnLocation(DataType::Type return_type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -070052 switch (return_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010053 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010054 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010055 case DataType::Type::kInt8:
56 case DataType::Type::kUint16:
57 case DataType::Type::kInt16:
Aart Bik66c158e2018-01-31 12:55:04 -080058 case DataType::Type::kUint32:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010059 case DataType::Type::kInt32:
60 case DataType::Type::kReference:
Aart Bik66c158e2018-01-31 12:55:04 -080061 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010062 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -070063 return Location::RegisterLocation(V0);
64
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010065 case DataType::Type::kFloat32:
66 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -070067 return Location::FpuRegisterLocation(F0);
68
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010069 case DataType::Type::kVoid:
Alexey Frunze4dda3372015-06-01 18:31:49 -070070 return Location();
71 }
72 UNREACHABLE();
73}
74
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010075Location InvokeDexCallingConventionVisitorMIPS64::GetReturnLocation(DataType::Type type) const {
Alexey Frunze4dda3372015-06-01 18:31:49 -070076 return Mips64ReturnLocation(type);
77}
78
79Location InvokeDexCallingConventionVisitorMIPS64::GetMethodLocation() const {
80 return Location::RegisterLocation(kMethodRegisterArgument);
81}
82
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010083Location InvokeDexCallingConventionVisitorMIPS64::GetNextLocation(DataType::Type type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -070084 Location next_location;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010085 if (type == DataType::Type::kVoid) {
Alexey Frunze4dda3372015-06-01 18:31:49 -070086 LOG(FATAL) << "Unexpected parameter type " << type;
87 }
88
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010089 if (DataType::IsFloatingPointType(type) &&
Alexey Frunze4dda3372015-06-01 18:31:49 -070090 (float_index_ < calling_convention.GetNumberOfFpuRegisters())) {
91 next_location = Location::FpuRegisterLocation(
92 calling_convention.GetFpuRegisterAt(float_index_++));
93 gp_index_++;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010094 } else if (!DataType::IsFloatingPointType(type) &&
Alexey Frunze4dda3372015-06-01 18:31:49 -070095 (gp_index_ < calling_convention.GetNumberOfRegisters())) {
96 next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index_++));
97 float_index_++;
98 } else {
99 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100100 next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
101 : Location::StackSlot(stack_offset);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700102 }
103
104 // Space on the stack is reserved for all arguments.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100105 stack_index_ += DataType::Is64BitType(type) ? 2 : 1;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700106
Alexey Frunze4dda3372015-06-01 18:31:49 -0700107 return next_location;
108}
109
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100110Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700111 return Mips64ReturnLocation(type);
112}
113
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100114// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
115#define __ down_cast<CodeGeneratorMIPS64*>(codegen)->GetAssembler()-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700116#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value()
Alexey Frunze4dda3372015-06-01 18:31:49 -0700117
118class BoundsCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
119 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000120 explicit BoundsCheckSlowPathMIPS64(HBoundsCheck* instruction) : SlowPathCodeMIPS64(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700121
122 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100123 LocationSummary* locations = instruction_->GetLocations();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700124 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
125 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000126 if (instruction_->CanThrowIntoCatchBlock()) {
127 // Live registers will be restored in the catch block if caught.
128 SaveLiveRegisters(codegen, instruction_->GetLocations());
129 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700130 // We're moving two locations to locations that could overlap, so we need a parallel
131 // move resolver.
132 InvokeRuntimeCallingConvention calling_convention;
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100133 codegen->EmitParallelMoves(locations->InAt(0),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700134 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100135 DataType::Type::kInt32,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100136 locations->InAt(1),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700137 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100138 DataType::Type::kInt32);
Serban Constantinescufc734082016-07-19 17:18:07 +0100139 QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt()
140 ? kQuickThrowStringBounds
141 : kQuickThrowArrayBounds;
142 mips64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100143 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700144 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
145 }
146
Alexandre Rames8158f282015-08-07 10:26:17 +0100147 bool IsFatal() const OVERRIDE { return true; }
148
Roland Levillain46648892015-06-19 16:07:18 +0100149 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS64"; }
150
Alexey Frunze4dda3372015-06-01 18:31:49 -0700151 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700152 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS64);
153};
154
155class DivZeroCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
156 public:
Alexey Frunzec61c0762017-04-10 13:54:23 -0700157 explicit DivZeroCheckSlowPathMIPS64(HDivZeroCheck* instruction)
158 : SlowPathCodeMIPS64(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700159
160 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
161 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
162 __ Bind(GetEntryLabel());
Serban Constantinescufc734082016-07-19 17:18:07 +0100163 mips64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700164 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
165 }
166
Alexandre Rames8158f282015-08-07 10:26:17 +0100167 bool IsFatal() const OVERRIDE { return true; }
168
Roland Levillain46648892015-06-19 16:07:18 +0100169 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS64"; }
170
Alexey Frunze4dda3372015-06-01 18:31:49 -0700171 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700172 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS64);
173};
174
175class LoadClassSlowPathMIPS64 : public SlowPathCodeMIPS64 {
176 public:
177 LoadClassSlowPathMIPS64(HLoadClass* cls,
178 HInstruction* at,
179 uint32_t dex_pc,
Vladimir Markof3c52b42017-11-17 17:32:12 +0000180 bool do_clinit)
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700181 : SlowPathCodeMIPS64(at),
182 cls_(cls),
183 dex_pc_(dex_pc),
Vladimir Markof3c52b42017-11-17 17:32:12 +0000184 do_clinit_(do_clinit) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700185 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
186 }
187
188 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000189 LocationSummary* locations = instruction_->GetLocations();
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700190 Location out = locations->Out();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700191 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700192 InvokeRuntimeCallingConvention calling_convention;
193 DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700194 __ Bind(GetEntryLabel());
195 SaveLiveRegisters(codegen, locations);
196
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000197 dex::TypeIndex type_index = cls_->GetTypeIndex();
198 __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_);
Serban Constantinescufc734082016-07-19 17:18:07 +0100199 QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage
200 : kQuickInitializeType;
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000201 mips64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700202 if (do_clinit_) {
203 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
204 } else {
205 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
206 }
207
208 // Move the class to the desired location.
Alexey Frunze4dda3372015-06-01 18:31:49 -0700209 if (out.IsValid()) {
210 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100211 DataType::Type type = instruction_->GetType();
Alexey Frunzec61c0762017-04-10 13:54:23 -0700212 mips64_codegen->MoveLocation(out,
213 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
214 type);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700215 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700216 RestoreLiveRegisters(codegen, locations);
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700217
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700218 __ Bc(GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700219 }
220
Roland Levillain46648892015-06-19 16:07:18 +0100221 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS64"; }
222
Alexey Frunze4dda3372015-06-01 18:31:49 -0700223 private:
224 // The class this slow path will load.
225 HLoadClass* const cls_;
226
Alexey Frunze4dda3372015-06-01 18:31:49 -0700227 // The dex PC of `at_`.
228 const uint32_t dex_pc_;
229
230 // Whether to initialize the class.
231 const bool do_clinit_;
232
233 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS64);
234};
235
236class LoadStringSlowPathMIPS64 : public SlowPathCodeMIPS64 {
237 public:
Vladimir Markof3c52b42017-11-17 17:32:12 +0000238 explicit LoadStringSlowPathMIPS64(HLoadString* instruction)
239 : SlowPathCodeMIPS64(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700240
241 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700242 DCHECK(instruction_->IsLoadString());
243 DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700244 LocationSummary* locations = instruction_->GetLocations();
245 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Vladimir Markof3c52b42017-11-17 17:32:12 +0000246 const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700247 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700248 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700249 __ Bind(GetEntryLabel());
250 SaveLiveRegisters(codegen, locations);
251
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000252 __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_);
Serban Constantinescufc734082016-07-19 17:18:07 +0100253 mips64_codegen->InvokeRuntime(kQuickResolveString,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700254 instruction_,
255 instruction_->GetDexPc(),
256 this);
257 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700258
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100259 DataType::Type type = instruction_->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700260 mips64_codegen->MoveLocation(locations->Out(),
Alexey Frunzec61c0762017-04-10 13:54:23 -0700261 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700262 type);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700263 RestoreLiveRegisters(codegen, locations);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800264
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700265 __ Bc(GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700266 }
267
Roland Levillain46648892015-06-19 16:07:18 +0100268 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS64"; }
269
Alexey Frunze4dda3372015-06-01 18:31:49 -0700270 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700271 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS64);
272};
273
274class NullCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
275 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000276 explicit NullCheckSlowPathMIPS64(HNullCheck* instr) : SlowPathCodeMIPS64(instr) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700277
278 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
279 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
280 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000281 if (instruction_->CanThrowIntoCatchBlock()) {
282 // Live registers will be restored in the catch block if caught.
283 SaveLiveRegisters(codegen, instruction_->GetLocations());
284 }
Serban Constantinescufc734082016-07-19 17:18:07 +0100285 mips64_codegen->InvokeRuntime(kQuickThrowNullPointer,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700286 instruction_,
287 instruction_->GetDexPc(),
288 this);
289 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
290 }
291
Alexandre Rames8158f282015-08-07 10:26:17 +0100292 bool IsFatal() const OVERRIDE { return true; }
293
Roland Levillain46648892015-06-19 16:07:18 +0100294 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS64"; }
295
Alexey Frunze4dda3372015-06-01 18:31:49 -0700296 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700297 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS64);
298};
299
300class SuspendCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
301 public:
Roland Levillain3887c462015-08-12 18:15:42 +0100302 SuspendCheckSlowPathMIPS64(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000303 : SlowPathCodeMIPS64(instruction), successor_(successor) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700304
305 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +0200306 LocationSummary* locations = instruction_->GetLocations();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700307 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
308 __ Bind(GetEntryLabel());
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +0200309 SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD.
Serban Constantinescufc734082016-07-19 17:18:07 +0100310 mips64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700311 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +0200312 RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD.
Alexey Frunze4dda3372015-06-01 18:31:49 -0700313 if (successor_ == nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700314 __ Bc(GetReturnLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700315 } else {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700316 __ Bc(mips64_codegen->GetLabelOf(successor_));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700317 }
318 }
319
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700320 Mips64Label* GetReturnLabel() {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700321 DCHECK(successor_ == nullptr);
322 return &return_label_;
323 }
324
Roland Levillain46648892015-06-19 16:07:18 +0100325 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS64"; }
326
Chris Larsena2045912017-11-02 12:39:54 -0700327 HBasicBlock* GetSuccessor() const {
328 return successor_;
329 }
330
Alexey Frunze4dda3372015-06-01 18:31:49 -0700331 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700332 // If not null, the block to branch to after the suspend check.
333 HBasicBlock* const successor_;
334
335 // If `successor_` is null, the label to branch to after the suspend check.
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700336 Mips64Label return_label_;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700337
338 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS64);
339};
340
341class TypeCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
342 public:
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800343 explicit TypeCheckSlowPathMIPS64(HInstruction* instruction, bool is_fatal)
344 : SlowPathCodeMIPS64(instruction), is_fatal_(is_fatal) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700345
346 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
347 LocationSummary* locations = instruction_->GetLocations();
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800348
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100349 uint32_t dex_pc = instruction_->GetDexPc();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700350 DCHECK(instruction_->IsCheckCast()
351 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
352 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
353
354 __ Bind(GetEntryLabel());
Alexey Frunzedfc30af2018-01-24 16:25:10 -0800355 if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800356 SaveLiveRegisters(codegen, locations);
357 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700358
359 // We're moving two locations to locations that could overlap, so we need a parallel
360 // move resolver.
361 InvokeRuntimeCallingConvention calling_convention;
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800362 codegen->EmitParallelMoves(locations->InAt(0),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700363 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100364 DataType::Type::kReference,
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800365 locations->InAt(1),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700366 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100367 DataType::Type::kReference);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700368 if (instruction_->IsInstanceOf()) {
Serban Constantinescufc734082016-07-19 17:18:07 +0100369 mips64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this);
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800370 CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100371 DataType::Type ret_type = instruction_->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700372 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
373 mips64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700374 } else {
375 DCHECK(instruction_->IsCheckCast());
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800376 mips64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this);
377 CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700378 }
379
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800380 if (!is_fatal_) {
381 RestoreLiveRegisters(codegen, locations);
382 __ Bc(GetExitLabel());
383 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700384 }
385
Roland Levillain46648892015-06-19 16:07:18 +0100386 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS64"; }
387
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800388 bool IsFatal() const OVERRIDE { return is_fatal_; }
389
Alexey Frunze4dda3372015-06-01 18:31:49 -0700390 private:
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800391 const bool is_fatal_;
392
Alexey Frunze4dda3372015-06-01 18:31:49 -0700393 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS64);
394};
395
396class DeoptimizationSlowPathMIPS64 : public SlowPathCodeMIPS64 {
397 public:
Aart Bik42249c32016-01-07 15:33:50 -0800398 explicit DeoptimizationSlowPathMIPS64(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000399 : SlowPathCodeMIPS64(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700400
401 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800402 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700403 __ Bind(GetEntryLabel());
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +0100404 LocationSummary* locations = instruction_->GetLocations();
405 SaveLiveRegisters(codegen, locations);
406 InvokeRuntimeCallingConvention calling_convention;
407 __ LoadConst32(calling_convention.GetRegisterAt(0),
408 static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind()));
Serban Constantinescufc734082016-07-19 17:18:07 +0100409 mips64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +0100410 CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700411 }
412
Roland Levillain46648892015-06-19 16:07:18 +0100413 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS64"; }
414
Alexey Frunze4dda3372015-06-01 18:31:49 -0700415 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700416 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64);
417};
418
Alexey Frunze15958152017-02-09 19:08:30 -0800419class ArraySetSlowPathMIPS64 : public SlowPathCodeMIPS64 {
420 public:
421 explicit ArraySetSlowPathMIPS64(HInstruction* instruction) : SlowPathCodeMIPS64(instruction) {}
422
423 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
424 LocationSummary* locations = instruction_->GetLocations();
425 __ Bind(GetEntryLabel());
426 SaveLiveRegisters(codegen, locations);
427
428 InvokeRuntimeCallingConvention calling_convention;
Vladimir Markoca6fff82017-10-03 14:49:14 +0100429 HParallelMove parallel_move(codegen->GetGraph()->GetAllocator());
Alexey Frunze15958152017-02-09 19:08:30 -0800430 parallel_move.AddMove(
431 locations->InAt(0),
432 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100433 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800434 nullptr);
435 parallel_move.AddMove(
436 locations->InAt(1),
437 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100438 DataType::Type::kInt32,
Alexey Frunze15958152017-02-09 19:08:30 -0800439 nullptr);
440 parallel_move.AddMove(
441 locations->InAt(2),
442 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100443 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800444 nullptr);
445 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
446
447 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
448 mips64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this);
449 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
450 RestoreLiveRegisters(codegen, locations);
451 __ Bc(GetExitLabel());
452 }
453
454 const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS64"; }
455
456 private:
457 DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS64);
458};
459
460// Slow path marking an object reference `ref` during a read
461// barrier. The field `obj.field` in the object `obj` holding this
462// reference does not get updated by this slow path after marking (see
463// ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 below for that).
464//
465// This means that after the execution of this slow path, `ref` will
466// always be up-to-date, but `obj.field` may not; i.e., after the
467// flip, `ref` will be a to-space reference, but `obj.field` will
468// probably still be a from-space reference (unless it gets updated by
469// another thread, or if another thread installed another object
470// reference (different from `ref`) in `obj.field`).
471//
472// If `entrypoint` is a valid location it is assumed to already be
473// holding the entrypoint. The case where the entrypoint is passed in
474// is for the GcRoot read barrier.
475class ReadBarrierMarkSlowPathMIPS64 : public SlowPathCodeMIPS64 {
476 public:
477 ReadBarrierMarkSlowPathMIPS64(HInstruction* instruction,
478 Location ref,
479 Location entrypoint = Location::NoLocation())
480 : SlowPathCodeMIPS64(instruction), ref_(ref), entrypoint_(entrypoint) {
481 DCHECK(kEmitCompilerReadBarrier);
482 }
483
484 const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; }
485
486 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
487 LocationSummary* locations = instruction_->GetLocations();
488 GpuRegister ref_reg = ref_.AsRegister<GpuRegister>();
489 DCHECK(locations->CanCall());
490 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg;
491 DCHECK(instruction_->IsInstanceFieldGet() ||
492 instruction_->IsStaticFieldGet() ||
493 instruction_->IsArrayGet() ||
494 instruction_->IsArraySet() ||
495 instruction_->IsLoadClass() ||
496 instruction_->IsLoadString() ||
497 instruction_->IsInstanceOf() ||
498 instruction_->IsCheckCast() ||
499 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) ||
500 (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified()))
501 << "Unexpected instruction in read barrier marking slow path: "
502 << instruction_->DebugName();
503
504 __ Bind(GetEntryLabel());
505 // No need to save live registers; it's taken care of by the
506 // entrypoint. Also, there is no need to update the stack mask,
507 // as this runtime call will not trigger a garbage collection.
508 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
509 DCHECK((V0 <= ref_reg && ref_reg <= T2) ||
510 (S2 <= ref_reg && ref_reg <= S7) ||
511 (ref_reg == S8)) << ref_reg;
512 // "Compact" slow path, saving two moves.
513 //
514 // Instead of using the standard runtime calling convention (input
515 // and output in A0 and V0 respectively):
516 //
517 // A0 <- ref
518 // V0 <- ReadBarrierMark(A0)
519 // ref <- V0
520 //
521 // we just use rX (the register containing `ref`) as input and output
522 // of a dedicated entrypoint:
523 //
524 // rX <- ReadBarrierMarkRegX(rX)
525 //
526 if (entrypoint_.IsValid()) {
527 mips64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this);
528 DCHECK_EQ(entrypoint_.AsRegister<GpuRegister>(), T9);
529 __ Jalr(entrypoint_.AsRegister<GpuRegister>());
530 __ Nop();
531 } else {
532 int32_t entry_point_offset =
Roland Levillain97c46462017-05-11 14:04:03 +0100533 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1);
Alexey Frunze15958152017-02-09 19:08:30 -0800534 // This runtime call does not require a stack map.
535 mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset,
536 instruction_,
537 this);
538 }
539 __ Bc(GetExitLabel());
540 }
541
542 private:
543 // The location (register) of the marked object reference.
544 const Location ref_;
545
546 // The location of the entrypoint if already loaded.
547 const Location entrypoint_;
548
549 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS64);
550};
551
552// Slow path marking an object reference `ref` during a read barrier,
553// and if needed, atomically updating the field `obj.field` in the
554// object `obj` holding this reference after marking (contrary to
555// ReadBarrierMarkSlowPathMIPS64 above, which never tries to update
556// `obj.field`).
557//
558// This means that after the execution of this slow path, both `ref`
559// and `obj.field` will be up-to-date; i.e., after the flip, both will
560// hold the same to-space reference (unless another thread installed
561// another object reference (different from `ref`) in `obj.field`).
562class ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 : public SlowPathCodeMIPS64 {
563 public:
564 ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(HInstruction* instruction,
565 Location ref,
566 GpuRegister obj,
567 Location field_offset,
568 GpuRegister temp1)
569 : SlowPathCodeMIPS64(instruction),
570 ref_(ref),
571 obj_(obj),
572 field_offset_(field_offset),
573 temp1_(temp1) {
574 DCHECK(kEmitCompilerReadBarrier);
575 }
576
577 const char* GetDescription() const OVERRIDE {
578 return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS64";
579 }
580
581 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
582 LocationSummary* locations = instruction_->GetLocations();
583 GpuRegister ref_reg = ref_.AsRegister<GpuRegister>();
584 DCHECK(locations->CanCall());
585 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg;
586 // This slow path is only used by the UnsafeCASObject intrinsic.
587 DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()))
588 << "Unexpected instruction in read barrier marking and field updating slow path: "
589 << instruction_->DebugName();
590 DCHECK(instruction_->GetLocations()->Intrinsified());
591 DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject);
592 DCHECK(field_offset_.IsRegister()) << field_offset_;
593
594 __ Bind(GetEntryLabel());
595
596 // Save the old reference.
597 // Note that we cannot use AT or TMP to save the old reference, as those
598 // are used by the code that follows, but we need the old reference after
599 // the call to the ReadBarrierMarkRegX entry point.
600 DCHECK_NE(temp1_, AT);
601 DCHECK_NE(temp1_, TMP);
602 __ Move(temp1_, ref_reg);
603
604 // No need to save live registers; it's taken care of by the
605 // entrypoint. Also, there is no need to update the stack mask,
606 // as this runtime call will not trigger a garbage collection.
607 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
608 DCHECK((V0 <= ref_reg && ref_reg <= T2) ||
609 (S2 <= ref_reg && ref_reg <= S7) ||
610 (ref_reg == S8)) << ref_reg;
611 // "Compact" slow path, saving two moves.
612 //
613 // Instead of using the standard runtime calling convention (input
614 // and output in A0 and V0 respectively):
615 //
616 // A0 <- ref
617 // V0 <- ReadBarrierMark(A0)
618 // ref <- V0
619 //
620 // we just use rX (the register containing `ref`) as input and output
621 // of a dedicated entrypoint:
622 //
623 // rX <- ReadBarrierMarkRegX(rX)
624 //
625 int32_t entry_point_offset =
Roland Levillain97c46462017-05-11 14:04:03 +0100626 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1);
Alexey Frunze15958152017-02-09 19:08:30 -0800627 // This runtime call does not require a stack map.
628 mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset,
629 instruction_,
630 this);
631
632 // If the new reference is different from the old reference,
633 // update the field in the holder (`*(obj_ + field_offset_)`).
634 //
635 // Note that this field could also hold a different object, if
636 // another thread had concurrently changed it. In that case, the
637 // the compare-and-set (CAS) loop below would abort, leaving the
638 // field as-is.
639 Mips64Label done;
640 __ Beqc(temp1_, ref_reg, &done);
641
642 // Update the the holder's field atomically. This may fail if
643 // mutator updates before us, but it's OK. This is achieved
644 // using a strong compare-and-set (CAS) operation with relaxed
645 // memory synchronization ordering, where the expected value is
646 // the old reference and the desired value is the new reference.
647
648 // Convenience aliases.
649 GpuRegister base = obj_;
650 GpuRegister offset = field_offset_.AsRegister<GpuRegister>();
651 GpuRegister expected = temp1_;
652 GpuRegister value = ref_reg;
653 GpuRegister tmp_ptr = TMP; // Pointer to actual memory.
654 GpuRegister tmp = AT; // Value in memory.
655
656 __ Daddu(tmp_ptr, base, offset);
657
658 if (kPoisonHeapReferences) {
659 __ PoisonHeapReference(expected);
660 // Do not poison `value` if it is the same register as
661 // `expected`, which has just been poisoned.
662 if (value != expected) {
663 __ PoisonHeapReference(value);
664 }
665 }
666
667 // do {
668 // tmp = [r_ptr] - expected;
669 // } while (tmp == 0 && failure([r_ptr] <- r_new_value));
670
671 Mips64Label loop_head, exit_loop;
672 __ Bind(&loop_head);
673 __ Ll(tmp, tmp_ptr);
674 // The LL instruction sign-extends the 32-bit value, but
675 // 32-bit references must be zero-extended. Zero-extend `tmp`.
676 __ Dext(tmp, tmp, 0, 32);
677 __ Bnec(tmp, expected, &exit_loop);
678 __ Move(tmp, value);
679 __ Sc(tmp, tmp_ptr);
680 __ Beqzc(tmp, &loop_head);
681 __ Bind(&exit_loop);
682
683 if (kPoisonHeapReferences) {
684 __ UnpoisonHeapReference(expected);
685 // Do not unpoison `value` if it is the same register as
686 // `expected`, which has just been unpoisoned.
687 if (value != expected) {
688 __ UnpoisonHeapReference(value);
689 }
690 }
691
692 __ Bind(&done);
693 __ Bc(GetExitLabel());
694 }
695
696 private:
697 // The location (register) of the marked object reference.
698 const Location ref_;
699 // The register containing the object holding the marked object reference field.
700 const GpuRegister obj_;
701 // The location of the offset of the marked reference field within `obj_`.
702 Location field_offset_;
703
704 const GpuRegister temp1_;
705
706 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS64);
707};
708
709// Slow path generating a read barrier for a heap reference.
710class ReadBarrierForHeapReferenceSlowPathMIPS64 : public SlowPathCodeMIPS64 {
711 public:
712 ReadBarrierForHeapReferenceSlowPathMIPS64(HInstruction* instruction,
713 Location out,
714 Location ref,
715 Location obj,
716 uint32_t offset,
717 Location index)
718 : SlowPathCodeMIPS64(instruction),
719 out_(out),
720 ref_(ref),
721 obj_(obj),
722 offset_(offset),
723 index_(index) {
724 DCHECK(kEmitCompilerReadBarrier);
725 // If `obj` is equal to `out` or `ref`, it means the initial object
726 // has been overwritten by (or after) the heap object reference load
727 // to be instrumented, e.g.:
728 //
729 // __ LoadFromOffset(kLoadWord, out, out, offset);
730 // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset);
731 //
732 // In that case, we have lost the information about the original
733 // object, and the emitted read barrier cannot work properly.
734 DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out;
735 DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref;
736 }
737
738 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
739 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
740 LocationSummary* locations = instruction_->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100741 DataType::Type type = DataType::Type::kReference;
Alexey Frunze15958152017-02-09 19:08:30 -0800742 GpuRegister reg_out = out_.AsRegister<GpuRegister>();
743 DCHECK(locations->CanCall());
744 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
745 DCHECK(instruction_->IsInstanceFieldGet() ||
746 instruction_->IsStaticFieldGet() ||
747 instruction_->IsArrayGet() ||
748 instruction_->IsInstanceOf() ||
749 instruction_->IsCheckCast() ||
750 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()))
751 << "Unexpected instruction in read barrier for heap reference slow path: "
752 << instruction_->DebugName();
753
754 __ Bind(GetEntryLabel());
755 SaveLiveRegisters(codegen, locations);
756
757 // We may have to change the index's value, but as `index_` is a
758 // constant member (like other "inputs" of this slow path),
759 // introduce a copy of it, `index`.
760 Location index = index_;
761 if (index_.IsValid()) {
762 // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
763 if (instruction_->IsArrayGet()) {
764 // Compute the actual memory offset and store it in `index`.
765 GpuRegister index_reg = index_.AsRegister<GpuRegister>();
766 DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg));
767 if (codegen->IsCoreCalleeSaveRegister(index_reg)) {
768 // We are about to change the value of `index_reg` (see the
769 // calls to art::mips64::Mips64Assembler::Sll and
770 // art::mips64::MipsAssembler::Addiu32 below), but it has
771 // not been saved by the previous call to
772 // art::SlowPathCode::SaveLiveRegisters, as it is a
773 // callee-save register --
774 // art::SlowPathCode::SaveLiveRegisters does not consider
775 // callee-save registers, as it has been designed with the
776 // assumption that callee-save registers are supposed to be
777 // handled by the called function. So, as a callee-save
778 // register, `index_reg` _would_ eventually be saved onto
779 // the stack, but it would be too late: we would have
780 // changed its value earlier. Therefore, we manually save
781 // it here into another freely available register,
782 // `free_reg`, chosen of course among the caller-save
783 // registers (as a callee-save `free_reg` register would
784 // exhibit the same problem).
785 //
786 // Note we could have requested a temporary register from
787 // the register allocator instead; but we prefer not to, as
788 // this is a slow path, and we know we can find a
789 // caller-save register that is available.
790 GpuRegister free_reg = FindAvailableCallerSaveRegister(codegen);
791 __ Move(free_reg, index_reg);
792 index_reg = free_reg;
793 index = Location::RegisterLocation(index_reg);
794 } else {
795 // The initial register stored in `index_` has already been
796 // saved in the call to art::SlowPathCode::SaveLiveRegisters
797 // (as it is not a callee-save register), so we can freely
798 // use it.
799 }
800 // Shifting the index value contained in `index_reg` by the scale
801 // factor (2) cannot overflow in practice, as the runtime is
802 // unable to allocate object arrays with a size larger than
803 // 2^26 - 1 (that is, 2^28 - 4 bytes).
804 __ Sll(index_reg, index_reg, TIMES_4);
805 static_assert(
806 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
807 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
808 __ Addiu32(index_reg, index_reg, offset_);
809 } else {
810 // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile
811 // intrinsics, `index_` is not shifted by a scale factor of 2
812 // (as in the case of ArrayGet), as it is actually an offset
813 // to an object field within an object.
814 DCHECK(instruction_->IsInvoke()) << instruction_->DebugName();
815 DCHECK(instruction_->GetLocations()->Intrinsified());
816 DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) ||
817 (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile))
818 << instruction_->AsInvoke()->GetIntrinsic();
819 DCHECK_EQ(offset_, 0U);
820 DCHECK(index_.IsRegister());
821 }
822 }
823
824 // We're moving two or three locations to locations that could
825 // overlap, so we need a parallel move resolver.
826 InvokeRuntimeCallingConvention calling_convention;
Vladimir Markoca6fff82017-10-03 14:49:14 +0100827 HParallelMove parallel_move(codegen->GetGraph()->GetAllocator());
Alexey Frunze15958152017-02-09 19:08:30 -0800828 parallel_move.AddMove(ref_,
829 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100830 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800831 nullptr);
832 parallel_move.AddMove(obj_,
833 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100834 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800835 nullptr);
836 if (index.IsValid()) {
837 parallel_move.AddMove(index,
838 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100839 DataType::Type::kInt32,
Alexey Frunze15958152017-02-09 19:08:30 -0800840 nullptr);
841 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
842 } else {
843 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
844 __ LoadConst32(calling_convention.GetRegisterAt(2), offset_);
845 }
846 mips64_codegen->InvokeRuntime(kQuickReadBarrierSlow,
847 instruction_,
848 instruction_->GetDexPc(),
849 this);
850 CheckEntrypointTypes<
851 kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>();
852 mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type);
853
854 RestoreLiveRegisters(codegen, locations);
855 __ Bc(GetExitLabel());
856 }
857
858 const char* GetDescription() const OVERRIDE {
859 return "ReadBarrierForHeapReferenceSlowPathMIPS64";
860 }
861
862 private:
863 GpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) {
864 size_t ref = static_cast<int>(ref_.AsRegister<GpuRegister>());
865 size_t obj = static_cast<int>(obj_.AsRegister<GpuRegister>());
866 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
867 if (i != ref &&
868 i != obj &&
869 !codegen->IsCoreCalleeSaveRegister(i) &&
870 !codegen->IsBlockedCoreRegister(i)) {
871 return static_cast<GpuRegister>(i);
872 }
873 }
874 // We shall never fail to find a free caller-save register, as
875 // there are more than two core caller-save registers on MIPS64
876 // (meaning it is possible to find one which is different from
877 // `ref` and `obj`).
878 DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u);
879 LOG(FATAL) << "Could not find a free caller-save register";
880 UNREACHABLE();
881 }
882
883 const Location out_;
884 const Location ref_;
885 const Location obj_;
886 const uint32_t offset_;
887 // An additional location containing an index to an array.
888 // Only used for HArrayGet and the UnsafeGetObject &
889 // UnsafeGetObjectVolatile intrinsics.
890 const Location index_;
891
892 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS64);
893};
894
895// Slow path generating a read barrier for a GC root.
896class ReadBarrierForRootSlowPathMIPS64 : public SlowPathCodeMIPS64 {
897 public:
898 ReadBarrierForRootSlowPathMIPS64(HInstruction* instruction, Location out, Location root)
899 : SlowPathCodeMIPS64(instruction), out_(out), root_(root) {
900 DCHECK(kEmitCompilerReadBarrier);
901 }
902
903 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
904 LocationSummary* locations = instruction_->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100905 DataType::Type type = DataType::Type::kReference;
Alexey Frunze15958152017-02-09 19:08:30 -0800906 GpuRegister reg_out = out_.AsRegister<GpuRegister>();
907 DCHECK(locations->CanCall());
908 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
909 DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString())
910 << "Unexpected instruction in read barrier for GC root slow path: "
911 << instruction_->DebugName();
912
913 __ Bind(GetEntryLabel());
914 SaveLiveRegisters(codegen, locations);
915
916 InvokeRuntimeCallingConvention calling_convention;
917 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
918 mips64_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
919 root_,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100920 DataType::Type::kReference);
Alexey Frunze15958152017-02-09 19:08:30 -0800921 mips64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow,
922 instruction_,
923 instruction_->GetDexPc(),
924 this);
925 CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>();
926 mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type);
927
928 RestoreLiveRegisters(codegen, locations);
929 __ Bc(GetExitLabel());
930 }
931
932 const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS64"; }
933
934 private:
935 const Location out_;
936 const Location root_;
937
938 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS64);
939};
940
Alexey Frunze4dda3372015-06-01 18:31:49 -0700941CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph,
942 const Mips64InstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100943 const CompilerOptions& compiler_options,
944 OptimizingCompilerStats* stats)
Alexey Frunze4dda3372015-06-01 18:31:49 -0700945 : CodeGenerator(graph,
946 kNumberOfGpuRegisters,
947 kNumberOfFpuRegisters,
Roland Levillain0d5a2812015-11-13 10:07:31 +0000948 /* number_of_register_pairs */ 0,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700949 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
950 arraysize(kCoreCalleeSaves)),
951 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
952 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +0100953 compiler_options,
954 stats),
Vladimir Marko225b6462015-09-28 12:17:40 +0100955 block_labels_(nullptr),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700956 location_builder_(graph, this),
957 instruction_visitor_(graph, this),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100958 move_resolver_(graph->GetAllocator(), this),
959 assembler_(graph->GetAllocator(), &isa_features),
Alexey Frunze19f6c692016-11-30 19:19:55 -0800960 isa_features_(isa_features),
Alexey Frunzef63f5692016-12-13 17:43:11 -0800961 uint32_literals_(std::less<uint32_t>(),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100962 graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze19f6c692016-11-30 19:19:55 -0800963 uint64_literals_(std::less<uint64_t>(),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100964 graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000965 boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100966 method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000967 boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100968 type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000969 boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100970 string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze627c1a02017-01-30 19:28:14 -0800971 jit_string_patches_(StringReferenceValueComparator(),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100972 graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze627c1a02017-01-30 19:28:14 -0800973 jit_class_patches_(TypeReferenceValueComparator(),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100974 graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700975 // Save RA (containing the return address) to mimic Quick.
976 AddAllocatedRegister(Location::RegisterLocation(RA));
977}
978
979#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100980// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
981#define __ down_cast<Mips64Assembler*>(GetAssembler())-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700982#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value()
Alexey Frunze4dda3372015-06-01 18:31:49 -0700983
984void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700985 // Ensure that we fix up branches.
986 __ FinalizeCode();
987
988 // Adjust native pc offsets in stack maps.
Vladimir Marko174b2e22017-10-12 13:34:49 +0100989 StackMapStream* stack_map_stream = GetStackMapStream();
990 for (size_t i = 0, num = stack_map_stream->GetNumberOfStackMaps(); i != num; ++i) {
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800991 uint32_t old_position =
Vladimir Marko33bff252017-11-01 14:35:42 +0000992 stack_map_stream->GetStackMap(i).native_pc_code_offset.Uint32Value(InstructionSet::kMips64);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700993 uint32_t new_position = __ GetAdjustedPosition(old_position);
994 DCHECK_GE(new_position, old_position);
Vladimir Marko174b2e22017-10-12 13:34:49 +0100995 stack_map_stream->SetStackMapNativePcOffset(i, new_position);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700996 }
997
998 // Adjust pc offsets for the disassembly information.
999 if (disasm_info_ != nullptr) {
1000 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
1001 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
1002 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
1003 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
1004 it.second.start = __ GetAdjustedPosition(it.second.start);
1005 it.second.end = __ GetAdjustedPosition(it.second.end);
1006 }
1007 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
1008 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
1009 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
1010 }
1011 }
1012
Alexey Frunze4dda3372015-06-01 18:31:49 -07001013 CodeGenerator::Finalize(allocator);
1014}
1015
1016Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const {
1017 return codegen_->GetAssembler();
1018}
1019
1020void ParallelMoveResolverMIPS64::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01001021 MoveOperands* move = moves_[index];
Alexey Frunze4dda3372015-06-01 18:31:49 -07001022 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
1023}
1024
1025void ParallelMoveResolverMIPS64::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01001026 MoveOperands* move = moves_[index];
Alexey Frunze4dda3372015-06-01 18:31:49 -07001027 codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType());
1028}
1029
1030void ParallelMoveResolverMIPS64::RestoreScratch(int reg) {
1031 // Pop reg
1032 __ Ld(GpuRegister(reg), SP, 0);
Lazar Trsicd9672662015-09-03 17:33:01 +02001033 __ DecreaseFrameSize(kMips64DoublewordSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001034}
1035
1036void ParallelMoveResolverMIPS64::SpillScratch(int reg) {
1037 // Push reg
Lazar Trsicd9672662015-09-03 17:33:01 +02001038 __ IncreaseFrameSize(kMips64DoublewordSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001039 __ Sd(GpuRegister(reg), SP, 0);
1040}
1041
1042void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) {
1043 LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord;
1044 StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord;
1045 // Allocate a scratch register other than TMP, if available.
1046 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
1047 // automatically unspilled when the scratch scope object is destroyed).
1048 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
1049 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
Lazar Trsicd9672662015-09-03 17:33:01 +02001050 int stack_offset = ensure_scratch.IsSpilled() ? kMips64DoublewordSize : 0;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001051 __ LoadFromOffset(load_type,
1052 GpuRegister(ensure_scratch.GetRegister()),
1053 SP,
1054 index1 + stack_offset);
1055 __ LoadFromOffset(load_type,
1056 TMP,
1057 SP,
1058 index2 + stack_offset);
1059 __ StoreToOffset(store_type,
1060 GpuRegister(ensure_scratch.GetRegister()),
1061 SP,
1062 index2 + stack_offset);
1063 __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset);
1064}
1065
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001066void ParallelMoveResolverMIPS64::ExchangeQuadSlots(int index1, int index2) {
1067 __ LoadFpuFromOffset(kLoadQuadword, FTMP, SP, index1);
1068 __ LoadFpuFromOffset(kLoadQuadword, FTMP2, SP, index2);
1069 __ StoreFpuToOffset(kStoreQuadword, FTMP, SP, index2);
1070 __ StoreFpuToOffset(kStoreQuadword, FTMP2, SP, index1);
1071}
1072
Alexey Frunze4dda3372015-06-01 18:31:49 -07001073static dwarf::Reg DWARFReg(GpuRegister reg) {
1074 return dwarf::Reg::Mips64Core(static_cast<int>(reg));
1075}
1076
David Srbeckyba702002016-02-01 18:15:29 +00001077static dwarf::Reg DWARFReg(FpuRegister reg) {
1078 return dwarf::Reg::Mips64Fp(static_cast<int>(reg));
1079}
Alexey Frunze4dda3372015-06-01 18:31:49 -07001080
1081void CodeGeneratorMIPS64::GenerateFrameEntry() {
1082 __ Bind(&frame_entry_label_);
1083
Nicolas Geoffray8d728322018-01-18 22:44:32 +00001084 if (GetCompilerOptions().CountHotnessInCompiledCode()) {
Goran Jakovljevicfeec1672018-02-08 10:20:14 +01001085 __ Lhu(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value());
1086 __ Addiu(TMP, TMP, 1);
1087 __ Sh(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value());
Nicolas Geoffray8d728322018-01-18 22:44:32 +00001088 }
1089
Vladimir Marko33bff252017-11-01 14:35:42 +00001090 bool do_overflow_check =
1091 FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips64) || !IsLeafMethod();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001092
1093 if (do_overflow_check) {
Vladimir Marko33bff252017-11-01 14:35:42 +00001094 __ LoadFromOffset(
1095 kLoadWord,
1096 ZERO,
1097 SP,
1098 -static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kMips64)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07001099 RecordPcInfo(nullptr, 0);
1100 }
1101
Alexey Frunze4dda3372015-06-01 18:31:49 -07001102 if (HasEmptyFrame()) {
1103 return;
1104 }
1105
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001106 // Make sure the frame size isn't unreasonably large.
Vladimir Marko33bff252017-11-01 14:35:42 +00001107 if (GetFrameSize() > GetStackOverflowReservedBytes(InstructionSet::kMips64)) {
1108 LOG(FATAL) << "Stack frame larger than "
1109 << GetStackOverflowReservedBytes(InstructionSet::kMips64) << " bytes";
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001110 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001111
1112 // Spill callee-saved registers.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001113
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001114 uint32_t ofs = GetFrameSize();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001115 __ IncreaseFrameSize(ofs);
1116
1117 for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) {
1118 GpuRegister reg = kCoreCalleeSaves[i];
1119 if (allocated_registers_.ContainsCoreRegister(reg)) {
Lazar Trsicd9672662015-09-03 17:33:01 +02001120 ofs -= kMips64DoublewordSize;
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001121 __ StoreToOffset(kStoreDoubleword, reg, SP, ofs);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001122 __ cfi().RelOffset(DWARFReg(reg), ofs);
1123 }
1124 }
1125
1126 for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) {
1127 FpuRegister reg = kFpuCalleeSaves[i];
1128 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
Lazar Trsicd9672662015-09-03 17:33:01 +02001129 ofs -= kMips64DoublewordSize;
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001130 __ StoreFpuToOffset(kStoreDoubleword, reg, SP, ofs);
David Srbeckyba702002016-02-01 18:15:29 +00001131 __ cfi().RelOffset(DWARFReg(reg), ofs);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001132 }
1133 }
1134
Nicolas Geoffray96eeb4e2016-10-12 22:03:31 +01001135 // Save the current method if we need it. Note that we do not
1136 // do this in HCurrentMethod, as the instruction might have been removed
1137 // in the SSA graph.
1138 if (RequiresCurrentMethod()) {
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001139 __ StoreToOffset(kStoreDoubleword, kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
Nicolas Geoffray96eeb4e2016-10-12 22:03:31 +01001140 }
Goran Jakovljevicc6418422016-12-05 16:31:55 +01001141
1142 if (GetGraph()->HasShouldDeoptimizeFlag()) {
1143 // Initialize should_deoptimize flag to 0.
1144 __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag());
1145 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001146}
1147
1148void CodeGeneratorMIPS64::GenerateFrameExit() {
1149 __ cfi().RememberState();
1150
Alexey Frunze4dda3372015-06-01 18:31:49 -07001151 if (!HasEmptyFrame()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001152 // Restore callee-saved registers.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001153
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001154 // For better instruction scheduling restore RA before other registers.
1155 uint32_t ofs = GetFrameSize();
1156 for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001157 GpuRegister reg = kCoreCalleeSaves[i];
1158 if (allocated_registers_.ContainsCoreRegister(reg)) {
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001159 ofs -= kMips64DoublewordSize;
1160 __ LoadFromOffset(kLoadDoubleword, reg, SP, ofs);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001161 __ cfi().Restore(DWARFReg(reg));
1162 }
1163 }
1164
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001165 for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) {
1166 FpuRegister reg = kFpuCalleeSaves[i];
1167 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
1168 ofs -= kMips64DoublewordSize;
1169 __ LoadFpuFromOffset(kLoadDoubleword, reg, SP, ofs);
1170 __ cfi().Restore(DWARFReg(reg));
1171 }
1172 }
1173
1174 __ DecreaseFrameSize(GetFrameSize());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001175 }
1176
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001177 __ Jic(RA, 0);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001178
1179 __ cfi().RestoreState();
1180 __ cfi().DefCFAOffset(GetFrameSize());
1181}
1182
1183void CodeGeneratorMIPS64::Bind(HBasicBlock* block) {
1184 __ Bind(GetLabelOf(block));
1185}
1186
1187void CodeGeneratorMIPS64::MoveLocation(Location destination,
1188 Location source,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001189 DataType::Type dst_type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001190 if (source.Equals(destination)) {
1191 return;
1192 }
1193
1194 // A valid move can always be inferred from the destination and source
1195 // locations. When moving from and to a register, the argument type can be
1196 // used to generate 32bit instead of 64bit moves.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001197 bool unspecified_type = (dst_type == DataType::Type::kVoid);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001198 DCHECK_EQ(unspecified_type, false);
1199
1200 if (destination.IsRegister() || destination.IsFpuRegister()) {
1201 if (unspecified_type) {
1202 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
1203 if (source.IsStackSlot() ||
1204 (src_cst != nullptr && (src_cst->IsIntConstant()
1205 || src_cst->IsFloatConstant()
1206 || src_cst->IsNullConstant()))) {
1207 // For stack slots and 32bit constants, a 64bit type is appropriate.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001208 dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001209 } else {
1210 // If the source is a double stack slot or a 64bit constant, a 64bit
1211 // type is appropriate. Else the source is a register, and since the
1212 // type has not been specified, we chose a 64bit type to force a 64bit
1213 // move.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001214 dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001215 }
1216 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001217 DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) ||
1218 (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07001219 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
1220 // Move to GPR/FPR from stack
1221 LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001222 if (DataType::IsFloatingPointType(dst_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001223 __ LoadFpuFromOffset(load_type,
1224 destination.AsFpuRegister<FpuRegister>(),
1225 SP,
1226 source.GetStackIndex());
1227 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001228 // TODO: use load_type = kLoadUnsignedWord when type == DataType::Type::kReference.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001229 __ LoadFromOffset(load_type,
1230 destination.AsRegister<GpuRegister>(),
1231 SP,
1232 source.GetStackIndex());
1233 }
Lena Djokicca8c2952017-05-29 11:31:46 +02001234 } else if (source.IsSIMDStackSlot()) {
1235 __ LoadFpuFromOffset(kLoadQuadword,
1236 destination.AsFpuRegister<FpuRegister>(),
1237 SP,
1238 source.GetStackIndex());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001239 } else if (source.IsConstant()) {
1240 // Move to GPR/FPR from constant
1241 GpuRegister gpr = AT;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001242 if (!DataType::IsFloatingPointType(dst_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001243 gpr = destination.AsRegister<GpuRegister>();
1244 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001245 if (dst_type == DataType::Type::kInt32 || dst_type == DataType::Type::kFloat32) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001246 int32_t value = GetInt32ValueOf(source.GetConstant()->AsConstant());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001247 if (DataType::IsFloatingPointType(dst_type) && value == 0) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001248 gpr = ZERO;
1249 } else {
1250 __ LoadConst32(gpr, value);
1251 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001252 } else {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001253 int64_t value = GetInt64ValueOf(source.GetConstant()->AsConstant());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001254 if (DataType::IsFloatingPointType(dst_type) && value == 0) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001255 gpr = ZERO;
1256 } else {
1257 __ LoadConst64(gpr, value);
1258 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001259 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001260 if (dst_type == DataType::Type::kFloat32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001261 __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001262 } else if (dst_type == DataType::Type::kFloat64) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001263 __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>());
1264 }
Calin Juravlee460d1d2015-09-29 04:52:17 +01001265 } else if (source.IsRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001266 if (destination.IsRegister()) {
1267 // Move to GPR from GPR
1268 __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>());
1269 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +01001270 DCHECK(destination.IsFpuRegister());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001271 if (DataType::Is64BitType(dst_type)) {
Calin Juravlee460d1d2015-09-29 04:52:17 +01001272 __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>());
1273 } else {
1274 __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>());
1275 }
1276 }
1277 } else if (source.IsFpuRegister()) {
1278 if (destination.IsFpuRegister()) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001279 if (GetGraph()->HasSIMD()) {
1280 __ MoveV(VectorRegisterFrom(destination),
1281 VectorRegisterFrom(source));
Alexey Frunze4dda3372015-06-01 18:31:49 -07001282 } else {
Lena Djokicca8c2952017-05-29 11:31:46 +02001283 // Move to FPR from FPR
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001284 if (dst_type == DataType::Type::kFloat32) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001285 __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
1286 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001287 DCHECK_EQ(dst_type, DataType::Type::kFloat64);
Lena Djokicca8c2952017-05-29 11:31:46 +02001288 __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
1289 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001290 }
Calin Juravlee460d1d2015-09-29 04:52:17 +01001291 } else {
1292 DCHECK(destination.IsRegister());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001293 if (DataType::Is64BitType(dst_type)) {
Calin Juravlee460d1d2015-09-29 04:52:17 +01001294 __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>());
1295 } else {
1296 __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>());
1297 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001298 }
1299 }
Lena Djokicca8c2952017-05-29 11:31:46 +02001300 } else if (destination.IsSIMDStackSlot()) {
1301 if (source.IsFpuRegister()) {
1302 __ StoreFpuToOffset(kStoreQuadword,
1303 source.AsFpuRegister<FpuRegister>(),
1304 SP,
1305 destination.GetStackIndex());
1306 } else {
1307 DCHECK(source.IsSIMDStackSlot());
1308 __ LoadFpuFromOffset(kLoadQuadword,
1309 FTMP,
1310 SP,
1311 source.GetStackIndex());
1312 __ StoreFpuToOffset(kStoreQuadword,
1313 FTMP,
1314 SP,
1315 destination.GetStackIndex());
1316 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001317 } else { // The destination is not a register. It must be a stack slot.
1318 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
1319 if (source.IsRegister() || source.IsFpuRegister()) {
1320 if (unspecified_type) {
1321 if (source.IsRegister()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001322 dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001323 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001324 dst_type =
1325 destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001326 }
1327 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001328 DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) &&
1329 (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07001330 // Move to stack from GPR/FPR
1331 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
1332 if (source.IsRegister()) {
1333 __ StoreToOffset(store_type,
1334 source.AsRegister<GpuRegister>(),
1335 SP,
1336 destination.GetStackIndex());
1337 } else {
1338 __ StoreFpuToOffset(store_type,
1339 source.AsFpuRegister<FpuRegister>(),
1340 SP,
1341 destination.GetStackIndex());
1342 }
1343 } else if (source.IsConstant()) {
1344 // Move to stack from constant
1345 HConstant* src_cst = source.GetConstant();
1346 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001347 GpuRegister gpr = ZERO;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001348 if (destination.IsStackSlot()) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001349 int32_t value = GetInt32ValueOf(src_cst->AsConstant());
1350 if (value != 0) {
1351 gpr = TMP;
1352 __ LoadConst32(gpr, value);
1353 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001354 } else {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001355 DCHECK(destination.IsDoubleStackSlot());
1356 int64_t value = GetInt64ValueOf(src_cst->AsConstant());
1357 if (value != 0) {
1358 gpr = TMP;
1359 __ LoadConst64(gpr, value);
1360 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001361 }
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001362 __ StoreToOffset(store_type, gpr, SP, destination.GetStackIndex());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001363 } else {
1364 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
1365 DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot());
1366 // Move to stack from stack
1367 if (destination.IsStackSlot()) {
1368 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
1369 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
1370 } else {
1371 __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex());
1372 __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex());
1373 }
1374 }
1375 }
1376}
1377
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001378void CodeGeneratorMIPS64::SwapLocations(Location loc1, Location loc2, DataType::Type type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001379 DCHECK(!loc1.IsConstant());
1380 DCHECK(!loc2.IsConstant());
1381
1382 if (loc1.Equals(loc2)) {
1383 return;
1384 }
1385
1386 bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot();
1387 bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot();
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001388 bool is_simd1 = loc1.IsSIMDStackSlot();
1389 bool is_simd2 = loc2.IsSIMDStackSlot();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001390 bool is_fp_reg1 = loc1.IsFpuRegister();
1391 bool is_fp_reg2 = loc2.IsFpuRegister();
1392
1393 if (loc2.IsRegister() && loc1.IsRegister()) {
1394 // Swap 2 GPRs
1395 GpuRegister r1 = loc1.AsRegister<GpuRegister>();
1396 GpuRegister r2 = loc2.AsRegister<GpuRegister>();
1397 __ Move(TMP, r2);
1398 __ Move(r2, r1);
1399 __ Move(r1, TMP);
1400 } else if (is_fp_reg2 && is_fp_reg1) {
1401 // Swap 2 FPRs
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001402 if (GetGraph()->HasSIMD()) {
1403 __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(loc1));
1404 __ MoveV(VectorRegisterFrom(loc1), VectorRegisterFrom(loc2));
1405 __ MoveV(VectorRegisterFrom(loc2), static_cast<VectorRegister>(FTMP));
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001406 } else {
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001407 FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>();
1408 FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>();
1409 if (type == DataType::Type::kFloat32) {
1410 __ MovS(FTMP, r1);
1411 __ MovS(r1, r2);
1412 __ MovS(r2, FTMP);
1413 } else {
1414 DCHECK_EQ(type, DataType::Type::kFloat64);
1415 __ MovD(FTMP, r1);
1416 __ MovD(r1, r2);
1417 __ MovD(r2, FTMP);
1418 }
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001419 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001420 } else if (is_slot1 != is_slot2) {
1421 // Swap GPR/FPR and stack slot
1422 Location reg_loc = is_slot1 ? loc2 : loc1;
1423 Location mem_loc = is_slot1 ? loc1 : loc2;
1424 LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword;
1425 StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001426 // TODO: use load_type = kLoadUnsignedWord when type == DataType::Type::kReference.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001427 __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex());
1428 if (reg_loc.IsFpuRegister()) {
1429 __ StoreFpuToOffset(store_type,
1430 reg_loc.AsFpuRegister<FpuRegister>(),
1431 SP,
1432 mem_loc.GetStackIndex());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001433 if (mem_loc.IsStackSlot()) {
1434 __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
1435 } else {
1436 DCHECK(mem_loc.IsDoubleStackSlot());
1437 __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
1438 }
1439 } else {
1440 __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex());
1441 __ Move(reg_loc.AsRegister<GpuRegister>(), TMP);
1442 }
1443 } else if (is_slot1 && is_slot2) {
1444 move_resolver_.Exchange(loc1.GetStackIndex(),
1445 loc2.GetStackIndex(),
1446 loc1.IsDoubleStackSlot());
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001447 } else if (is_simd1 && is_simd2) {
1448 move_resolver_.ExchangeQuadSlots(loc1.GetStackIndex(), loc2.GetStackIndex());
1449 } else if ((is_fp_reg1 && is_simd2) || (is_fp_reg2 && is_simd1)) {
1450 Location fp_reg_loc = is_fp_reg1 ? loc1 : loc2;
1451 Location mem_loc = is_fp_reg1 ? loc2 : loc1;
1452 __ LoadFpuFromOffset(kLoadQuadword, FTMP, SP, mem_loc.GetStackIndex());
1453 __ StoreFpuToOffset(kStoreQuadword,
1454 fp_reg_loc.AsFpuRegister<FpuRegister>(),
1455 SP,
1456 mem_loc.GetStackIndex());
1457 __ MoveV(VectorRegisterFrom(fp_reg_loc), static_cast<VectorRegister>(FTMP));
Alexey Frunze4dda3372015-06-01 18:31:49 -07001458 } else {
1459 LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2;
1460 }
1461}
1462
Calin Juravle175dc732015-08-25 15:42:32 +01001463void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) {
1464 DCHECK(location.IsRegister());
1465 __ LoadConst32(location.AsRegister<GpuRegister>(), value);
1466}
1467
Calin Juravlee460d1d2015-09-29 04:52:17 +01001468void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) {
1469 if (location.IsRegister()) {
1470 locations->AddTemp(location);
1471 } else {
1472 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
1473 }
1474}
1475
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01001476void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object,
1477 GpuRegister value,
1478 bool value_can_be_null) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001479 Mips64Label done;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001480 GpuRegister card = AT;
1481 GpuRegister temp = TMP;
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01001482 if (value_can_be_null) {
1483 __ Beqzc(value, &done);
1484 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001485 __ LoadFromOffset(kLoadDoubleword,
1486 card,
1487 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001488 Thread::CardTableOffset<kMips64PointerSize>().Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001489 __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift);
1490 __ Daddu(temp, card, temp);
1491 __ Sb(card, temp, 0);
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01001492 if (value_can_be_null) {
1493 __ Bind(&done);
1494 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001495}
1496
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001497template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
Alexey Frunze19f6c692016-11-30 19:19:55 -08001498inline void CodeGeneratorMIPS64::EmitPcRelativeLinkerPatches(
1499 const ArenaDeque<PcRelativePatchInfo>& infos,
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001500 ArenaVector<linker::LinkerPatch>* linker_patches) {
Alexey Frunze19f6c692016-11-30 19:19:55 -08001501 for (const PcRelativePatchInfo& info : infos) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001502 const DexFile* dex_file = info.target_dex_file;
Alexey Frunze19f6c692016-11-30 19:19:55 -08001503 size_t offset_or_index = info.offset_or_index;
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001504 DCHECK(info.label.IsBound());
1505 uint32_t literal_offset = __ GetLabelLocation(&info.label);
1506 const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info;
1507 uint32_t pc_rel_offset = __ GetLabelLocation(&info_high.label);
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001508 linker_patches->push_back(Factory(literal_offset, dex_file, pc_rel_offset, offset_or_index));
Alexey Frunze19f6c692016-11-30 19:19:55 -08001509 }
1510}
1511
Vladimir Markob066d432018-01-03 13:14:37 +00001512linker::LinkerPatch DataBimgRelRoPatchAdapter(size_t literal_offset,
1513 const DexFile* target_dex_file,
1514 uint32_t pc_insn_offset,
1515 uint32_t boot_image_offset) {
1516 DCHECK(target_dex_file == nullptr); // Unused for DataBimgRelRoPatch(), should be null.
1517 return linker::LinkerPatch::DataBimgRelRoPatch(literal_offset, pc_insn_offset, boot_image_offset);
1518}
1519
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001520void CodeGeneratorMIPS64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) {
Alexey Frunze19f6c692016-11-30 19:19:55 -08001521 DCHECK(linker_patches->empty());
1522 size_t size =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001523 boot_image_method_patches_.size() +
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001524 method_bss_entry_patches_.size() +
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001525 boot_image_type_patches_.size() +
Vladimir Marko65979462017-05-19 17:25:12 +01001526 type_bss_entry_patches_.size() +
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001527 boot_image_string_patches_.size() +
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01001528 string_bss_entry_patches_.size();
Alexey Frunze19f6c692016-11-30 19:19:55 -08001529 linker_patches->reserve(size);
Vladimir Marko65979462017-05-19 17:25:12 +01001530 if (GetCompilerOptions().IsBootImage()) {
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001531 EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>(
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001532 boot_image_method_patches_, linker_patches);
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001533 EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>(
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001534 boot_image_type_patches_, linker_patches);
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001535 EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>(
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001536 boot_image_string_patches_, linker_patches);
Vladimir Marko65979462017-05-19 17:25:12 +01001537 } else {
Vladimir Markob066d432018-01-03 13:14:37 +00001538 EmitPcRelativeLinkerPatches<DataBimgRelRoPatchAdapter>(
1539 boot_image_method_patches_, linker_patches);
Vladimir Markoe47f60c2018-02-21 13:43:28 +00001540 DCHECK(boot_image_type_patches_.empty());
1541 DCHECK(boot_image_string_patches_.empty());
Alexey Frunzef63f5692016-12-13 17:43:11 -08001542 }
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001543 EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>(
1544 method_bss_entry_patches_, linker_patches);
1545 EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>(
1546 type_bss_entry_patches_, linker_patches);
1547 EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>(
1548 string_bss_entry_patches_, linker_patches);
Vladimir Marko1998cd02017-01-13 13:02:58 +00001549 DCHECK_EQ(size, linker_patches->size());
Alexey Frunzef63f5692016-12-13 17:43:11 -08001550}
1551
Vladimir Markob066d432018-01-03 13:14:37 +00001552CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageRelRoPatch(
1553 uint32_t boot_image_offset,
1554 const PcRelativePatchInfo* info_high) {
1555 return NewPcRelativePatch(
1556 /* dex_file */ nullptr, boot_image_offset, info_high, &boot_image_method_patches_);
1557}
1558
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001559CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageMethodPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001560 MethodReference target_method,
1561 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001562 return NewPcRelativePatch(
1563 target_method.dex_file, target_method.index, info_high, &boot_image_method_patches_);
Alexey Frunzef63f5692016-12-13 17:43:11 -08001564}
1565
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001566CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewMethodBssEntryPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001567 MethodReference target_method,
1568 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001569 return NewPcRelativePatch(
1570 target_method.dex_file, target_method.index, info_high, &method_bss_entry_patches_);
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001571}
1572
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001573CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageTypePatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001574 const DexFile& dex_file,
1575 dex::TypeIndex type_index,
1576 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001577 return NewPcRelativePatch(&dex_file, type_index.index_, info_high, &boot_image_type_patches_);
Alexey Frunze19f6c692016-11-30 19:19:55 -08001578}
1579
Vladimir Marko1998cd02017-01-13 13:02:58 +00001580CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewTypeBssEntryPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001581 const DexFile& dex_file,
1582 dex::TypeIndex type_index,
1583 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001584 return NewPcRelativePatch(&dex_file, type_index.index_, info_high, &type_bss_entry_patches_);
Vladimir Marko1998cd02017-01-13 13:02:58 +00001585}
1586
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001587CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageStringPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001588 const DexFile& dex_file,
1589 dex::StringIndex string_index,
1590 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001591 return NewPcRelativePatch(
1592 &dex_file, string_index.index_, info_high, &boot_image_string_patches_);
Vladimir Marko65979462017-05-19 17:25:12 +01001593}
1594
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01001595CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewStringBssEntryPatch(
1596 const DexFile& dex_file,
1597 dex::StringIndex string_index,
1598 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001599 return NewPcRelativePatch(&dex_file, string_index.index_, info_high, &string_bss_entry_patches_);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01001600}
1601
Alexey Frunze19f6c692016-11-30 19:19:55 -08001602CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativePatch(
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001603 const DexFile* dex_file,
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001604 uint32_t offset_or_index,
1605 const PcRelativePatchInfo* info_high,
1606 ArenaDeque<PcRelativePatchInfo>* patches) {
1607 patches->emplace_back(dex_file, offset_or_index, info_high);
Alexey Frunze19f6c692016-11-30 19:19:55 -08001608 return &patches->back();
1609}
1610
Alexey Frunzef63f5692016-12-13 17:43:11 -08001611Literal* CodeGeneratorMIPS64::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
1612 return map->GetOrCreate(
1613 value,
1614 [this, value]() { return __ NewLiteral<uint32_t>(value); });
1615}
1616
Alexey Frunze19f6c692016-11-30 19:19:55 -08001617Literal* CodeGeneratorMIPS64::DeduplicateUint64Literal(uint64_t value) {
1618 return uint64_literals_.GetOrCreate(
1619 value,
1620 [this, value]() { return __ NewLiteral<uint64_t>(value); });
1621}
1622
Alexey Frunzef63f5692016-12-13 17:43:11 -08001623Literal* CodeGeneratorMIPS64::DeduplicateBootImageAddressLiteral(uint64_t address) {
Richard Uhlerc52f3032017-03-02 13:45:45 +00001624 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_);
Alexey Frunzef63f5692016-12-13 17:43:11 -08001625}
1626
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001627void CodeGeneratorMIPS64::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high,
1628 GpuRegister out,
1629 PcRelativePatchInfo* info_low) {
1630 DCHECK(!info_high->patch_info_high);
1631 __ Bind(&info_high->label);
Alexey Frunze19f6c692016-11-30 19:19:55 -08001632 // Add the high half of a 32-bit offset to PC.
1633 __ Auipc(out, /* placeholder */ 0x1234);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001634 // A following instruction will add the sign-extended low half of the 32-bit
Alexey Frunzef63f5692016-12-13 17:43:11 -08001635 // offset to `out` (e.g. ld, jialc, daddiu).
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001636 if (info_low != nullptr) {
1637 DCHECK_EQ(info_low->patch_info_high, info_high);
1638 __ Bind(&info_low->label);
1639 }
Alexey Frunze19f6c692016-11-30 19:19:55 -08001640}
1641
Alexey Frunze627c1a02017-01-30 19:28:14 -08001642Literal* CodeGeneratorMIPS64::DeduplicateJitStringLiteral(const DexFile& dex_file,
1643 dex::StringIndex string_index,
1644 Handle<mirror::String> handle) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01001645 ReserveJitStringRoot(StringReference(&dex_file, string_index), handle);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001646 return jit_string_patches_.GetOrCreate(
1647 StringReference(&dex_file, string_index),
1648 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1649}
1650
1651Literal* CodeGeneratorMIPS64::DeduplicateJitClassLiteral(const DexFile& dex_file,
1652 dex::TypeIndex type_index,
1653 Handle<mirror::Class> handle) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01001654 ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001655 return jit_class_patches_.GetOrCreate(
1656 TypeReference(&dex_file, type_index),
1657 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1658}
1659
1660void CodeGeneratorMIPS64::PatchJitRootUse(uint8_t* code,
1661 const uint8_t* roots_data,
1662 const Literal* literal,
1663 uint64_t index_in_table) const {
1664 uint32_t literal_offset = GetAssembler().GetLabelLocation(literal->GetLabel());
1665 uintptr_t address =
1666 reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>);
1667 reinterpret_cast<uint32_t*>(code + literal_offset)[0] = dchecked_integral_cast<uint32_t>(address);
1668}
1669
1670void CodeGeneratorMIPS64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) {
1671 for (const auto& entry : jit_string_patches_) {
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001672 const StringReference& string_reference = entry.first;
1673 Literal* table_entry_literal = entry.second;
Vladimir Marko174b2e22017-10-12 13:34:49 +01001674 uint64_t index_in_table = GetJitStringRootIndex(string_reference);
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001675 PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001676 }
1677 for (const auto& entry : jit_class_patches_) {
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001678 const TypeReference& type_reference = entry.first;
1679 Literal* table_entry_literal = entry.second;
Vladimir Marko174b2e22017-10-12 13:34:49 +01001680 uint64_t index_in_table = GetJitClassRootIndex(type_reference);
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001681 PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001682 }
1683}
1684
David Brazdil58282f42016-01-14 12:45:10 +00001685void CodeGeneratorMIPS64::SetupBlockedRegisters() const {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001686 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
1687 blocked_core_registers_[ZERO] = true;
1688 blocked_core_registers_[K0] = true;
1689 blocked_core_registers_[K1] = true;
1690 blocked_core_registers_[GP] = true;
1691 blocked_core_registers_[SP] = true;
1692 blocked_core_registers_[RA] = true;
1693
Lazar Trsicd9672662015-09-03 17:33:01 +02001694 // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch
1695 // registers (similar to how AT is used by MIPS assemblers).
Alexey Frunze4dda3372015-06-01 18:31:49 -07001696 blocked_core_registers_[AT] = true;
1697 blocked_core_registers_[TMP] = true;
Lazar Trsicd9672662015-09-03 17:33:01 +02001698 blocked_core_registers_[TMP2] = true;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001699 blocked_fpu_registers_[FTMP] = true;
1700
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001701 if (GetInstructionSetFeatures().HasMsa()) {
1702 // To be used just for MSA instructions.
1703 blocked_fpu_registers_[FTMP2] = true;
1704 }
1705
Alexey Frunze4dda3372015-06-01 18:31:49 -07001706 // Reserve suspend and thread registers.
1707 blocked_core_registers_[S0] = true;
1708 blocked_core_registers_[TR] = true;
1709
1710 // Reserve T9 for function calls
1711 blocked_core_registers_[T9] = true;
1712
Goran Jakovljevic782be112016-06-21 12:39:04 +02001713 if (GetGraph()->IsDebuggable()) {
1714 // Stubs do not save callee-save floating point registers. If the graph
1715 // is debuggable, we need to deal with these registers differently. For
1716 // now, just block them.
1717 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1718 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1719 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001720 }
1721}
1722
Alexey Frunze4dda3372015-06-01 18:31:49 -07001723size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1724 __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index);
Lazar Trsicd9672662015-09-03 17:33:01 +02001725 return kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001726}
1727
1728size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1729 __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index);
Lazar Trsicd9672662015-09-03 17:33:01 +02001730 return kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001731}
1732
1733size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001734 __ StoreFpuToOffset(GetGraph()->HasSIMD() ? kStoreQuadword : kStoreDoubleword,
1735 FpuRegister(reg_id),
1736 SP,
1737 stack_index);
1738 return GetFloatingPointSpillSlotSize();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001739}
1740
1741size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001742 __ LoadFpuFromOffset(GetGraph()->HasSIMD() ? kLoadQuadword : kLoadDoubleword,
1743 FpuRegister(reg_id),
1744 SP,
1745 stack_index);
1746 return GetFloatingPointSpillSlotSize();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001747}
1748
1749void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdil9f0dece2015-09-21 18:20:26 +01001750 stream << GpuRegister(reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001751}
1752
1753void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdil9f0dece2015-09-21 18:20:26 +01001754 stream << FpuRegister(reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001755}
1756
Calin Juravle175dc732015-08-25 15:42:32 +01001757void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint,
Alexey Frunze4dda3372015-06-01 18:31:49 -07001758 HInstruction* instruction,
1759 uint32_t dex_pc,
1760 SlowPathCode* slow_path) {
Alexandre Rames91a65162016-09-19 13:54:30 +01001761 ValidateInvokeRuntime(entrypoint, instruction, slow_path);
Alexey Frunze15958152017-02-09 19:08:30 -08001762 GenerateInvokeRuntime(GetThreadOffset<kMips64PointerSize>(entrypoint).Int32Value());
Serban Constantinescufc734082016-07-19 17:18:07 +01001763 if (EntrypointRequiresStackMap(entrypoint)) {
1764 RecordPcInfo(instruction, dex_pc, slow_path);
1765 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001766}
1767
Alexey Frunze15958152017-02-09 19:08:30 -08001768void CodeGeneratorMIPS64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
1769 HInstruction* instruction,
1770 SlowPathCode* slow_path) {
1771 ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path);
1772 GenerateInvokeRuntime(entry_point_offset);
1773}
1774
1775void CodeGeneratorMIPS64::GenerateInvokeRuntime(int32_t entry_point_offset) {
1776 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
1777 __ Jalr(T9);
1778 __ Nop();
1779}
1780
Alexey Frunze4dda3372015-06-01 18:31:49 -07001781void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path,
1782 GpuRegister class_reg) {
Vladimir Markodc682aa2018-01-04 18:42:57 +00001783 constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf();
1784 const size_t status_byte_offset =
1785 mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte);
1786 constexpr uint32_t shifted_initialized_value =
1787 enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte);
1788
1789 __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, status_byte_offset);
Lena Djokic3177e102018-02-28 11:32:40 +01001790 __ Sltiu(TMP, TMP, shifted_initialized_value);
1791 __ Bnezc(TMP, slow_path->GetEntryLabel());
Alexey Frunze15958152017-02-09 19:08:30 -08001792 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
1793 __ Sync(0);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001794 __ Bind(slow_path->GetExitLabel());
1795}
1796
1797void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1798 __ Sync(0); // only stype 0 is supported
1799}
1800
1801void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction,
1802 HBasicBlock* successor) {
1803 SuspendCheckSlowPathMIPS64* slow_path =
Chris Larsena2045912017-11-02 12:39:54 -07001804 down_cast<SuspendCheckSlowPathMIPS64*>(instruction->GetSlowPath());
1805
1806 if (slow_path == nullptr) {
1807 slow_path =
1808 new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS64(instruction, successor);
1809 instruction->SetSlowPath(slow_path);
1810 codegen_->AddSlowPath(slow_path);
1811 if (successor != nullptr) {
1812 DCHECK(successor->IsLoopHeader());
1813 }
1814 } else {
1815 DCHECK_EQ(slow_path->GetSuccessor(), successor);
1816 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001817
1818 __ LoadFromOffset(kLoadUnsignedHalfword,
1819 TMP,
1820 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001821 Thread::ThreadFlagsOffset<kMips64PointerSize>().Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001822 if (successor == nullptr) {
1823 __ Bnezc(TMP, slow_path->GetEntryLabel());
1824 __ Bind(slow_path->GetReturnLabel());
1825 } else {
1826 __ Beqzc(TMP, codegen_->GetLabelOf(successor));
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001827 __ Bc(slow_path->GetEntryLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001828 // slow_path will return to GetLabelOf(successor).
1829 }
1830}
1831
1832InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph,
1833 CodeGeneratorMIPS64* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001834 : InstructionCodeGenerator(graph, codegen),
Alexey Frunze4dda3372015-06-01 18:31:49 -07001835 assembler_(codegen->GetAssembler()),
1836 codegen_(codegen) {}
1837
1838void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
1839 DCHECK_EQ(instruction->InputCount(), 2U);
Vladimir Markoca6fff82017-10-03 14:49:14 +01001840 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001841 DataType::Type type = instruction->GetResultType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001842 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001843 case DataType::Type::kInt32:
1844 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001845 locations->SetInAt(0, Location::RequiresRegister());
1846 HInstruction* right = instruction->InputAt(1);
1847 bool can_use_imm = false;
1848 if (right->IsConstant()) {
1849 int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant());
1850 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1851 can_use_imm = IsUint<16>(imm);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001852 } else {
Lena Djokic38530172017-11-16 11:11:50 +01001853 DCHECK(instruction->IsAdd() || instruction->IsSub());
1854 bool single_use = right->GetUses().HasExactlyOneElement();
1855 if (instruction->IsSub()) {
1856 if (!(type == DataType::Type::kInt32 && imm == INT32_MIN)) {
1857 imm = -imm;
1858 }
1859 }
1860 if (type == DataType::Type::kInt32) {
1861 can_use_imm = IsInt<16>(imm) || (Low16Bits(imm) == 0) || single_use;
1862 } else {
1863 can_use_imm = IsInt<16>(imm) || (IsInt<32>(imm) && (Low16Bits(imm) == 0)) || single_use;
1864 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001865 }
1866 }
1867 if (can_use_imm)
1868 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1869 else
1870 locations->SetInAt(1, Location::RequiresRegister());
1871 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1872 }
1873 break;
1874
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001875 case DataType::Type::kFloat32:
1876 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07001877 locations->SetInAt(0, Location::RequiresFpuRegister());
1878 locations->SetInAt(1, Location::RequiresFpuRegister());
1879 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1880 break;
1881
1882 default:
1883 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1884 }
1885}
1886
1887void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001888 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001889 LocationSummary* locations = instruction->GetLocations();
1890
1891 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001892 case DataType::Type::kInt32:
1893 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001894 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1895 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1896 Location rhs_location = locations->InAt(1);
1897
1898 GpuRegister rhs_reg = ZERO;
1899 int64_t rhs_imm = 0;
1900 bool use_imm = rhs_location.IsConstant();
1901 if (use_imm) {
1902 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
1903 } else {
1904 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1905 }
1906
1907 if (instruction->IsAnd()) {
1908 if (use_imm)
1909 __ Andi(dst, lhs, rhs_imm);
1910 else
1911 __ And(dst, lhs, rhs_reg);
1912 } else if (instruction->IsOr()) {
1913 if (use_imm)
1914 __ Ori(dst, lhs, rhs_imm);
1915 else
1916 __ Or(dst, lhs, rhs_reg);
1917 } else if (instruction->IsXor()) {
1918 if (use_imm)
1919 __ Xori(dst, lhs, rhs_imm);
1920 else
1921 __ Xor(dst, lhs, rhs_reg);
Lena Djokic38530172017-11-16 11:11:50 +01001922 } else if (instruction->IsAdd() || instruction->IsSub()) {
1923 if (instruction->IsSub()) {
1924 rhs_imm = -rhs_imm;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001925 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001926 if (type == DataType::Type::kInt32) {
Lena Djokic38530172017-11-16 11:11:50 +01001927 if (use_imm) {
1928 if (IsInt<16>(rhs_imm)) {
1929 __ Addiu(dst, lhs, rhs_imm);
1930 } else {
1931 int16_t rhs_imm_high = High16Bits(rhs_imm);
1932 int16_t rhs_imm_low = Low16Bits(rhs_imm);
1933 if (rhs_imm_low < 0) {
1934 rhs_imm_high += 1;
1935 }
1936 __ Aui(dst, lhs, rhs_imm_high);
1937 if (rhs_imm_low != 0) {
1938 __ Addiu(dst, dst, rhs_imm_low);
1939 }
1940 }
1941 } else {
1942 if (instruction->IsAdd()) {
1943 __ Addu(dst, lhs, rhs_reg);
1944 } else {
1945 DCHECK(instruction->IsSub());
1946 __ Subu(dst, lhs, rhs_reg);
1947 }
1948 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001949 } else {
Lena Djokic38530172017-11-16 11:11:50 +01001950 if (use_imm) {
1951 if (IsInt<16>(rhs_imm)) {
1952 __ Daddiu(dst, lhs, rhs_imm);
1953 } else if (IsInt<32>(rhs_imm)) {
1954 int16_t rhs_imm_high = High16Bits(rhs_imm);
1955 int16_t rhs_imm_low = Low16Bits(rhs_imm);
1956 bool overflow_hi16 = false;
1957 if (rhs_imm_low < 0) {
1958 rhs_imm_high += 1;
1959 overflow_hi16 = (rhs_imm_high == -32768);
1960 }
1961 __ Daui(dst, lhs, rhs_imm_high);
1962 if (rhs_imm_low != 0) {
1963 __ Daddiu(dst, dst, rhs_imm_low);
1964 }
1965 if (overflow_hi16) {
1966 __ Dahi(dst, 1);
1967 }
1968 } else {
1969 int16_t rhs_imm_low = Low16Bits(Low32Bits(rhs_imm));
1970 if (rhs_imm_low < 0) {
1971 rhs_imm += (INT64_C(1) << 16);
1972 }
1973 int16_t rhs_imm_upper = High16Bits(Low32Bits(rhs_imm));
1974 if (rhs_imm_upper < 0) {
1975 rhs_imm += (INT64_C(1) << 32);
1976 }
1977 int16_t rhs_imm_high = Low16Bits(High32Bits(rhs_imm));
1978 if (rhs_imm_high < 0) {
1979 rhs_imm += (INT64_C(1) << 48);
1980 }
1981 int16_t rhs_imm_top = High16Bits(High32Bits(rhs_imm));
1982 GpuRegister tmp = lhs;
1983 if (rhs_imm_low != 0) {
1984 __ Daddiu(dst, tmp, rhs_imm_low);
1985 tmp = dst;
1986 }
1987 // Dahi and Dati must use the same input and output register, so we have to initialize
1988 // the dst register using Daddiu or Daui, even when the intermediate value is zero:
1989 // Daui(dst, lhs, 0).
1990 if ((rhs_imm_upper != 0) || (rhs_imm_low == 0)) {
1991 __ Daui(dst, tmp, rhs_imm_upper);
1992 }
1993 if (rhs_imm_high != 0) {
1994 __ Dahi(dst, rhs_imm_high);
1995 }
1996 if (rhs_imm_top != 0) {
1997 __ Dati(dst, rhs_imm_top);
1998 }
1999 }
2000 } else if (instruction->IsAdd()) {
2001 __ Daddu(dst, lhs, rhs_reg);
2002 } else {
2003 DCHECK(instruction->IsSub());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002004 __ Dsubu(dst, lhs, rhs_reg);
Lena Djokic38530172017-11-16 11:11:50 +01002005 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002006 }
2007 }
2008 break;
2009 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002010 case DataType::Type::kFloat32:
2011 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002012 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2013 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
2014 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
2015 if (instruction->IsAdd()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002016 if (type == DataType::Type::kFloat32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07002017 __ AddS(dst, lhs, rhs);
2018 else
2019 __ AddD(dst, lhs, rhs);
2020 } else if (instruction->IsSub()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002021 if (type == DataType::Type::kFloat32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07002022 __ SubS(dst, lhs, rhs);
2023 else
2024 __ SubD(dst, lhs, rhs);
2025 } else {
2026 LOG(FATAL) << "Unexpected floating-point binary operation";
2027 }
2028 break;
2029 }
2030 default:
2031 LOG(FATAL) << "Unexpected binary operation type " << type;
2032 }
2033}
2034
2035void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002036 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002037
Vladimir Markoca6fff82017-10-03 14:49:14 +01002038 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002039 DataType::Type type = instr->GetResultType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002040 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002041 case DataType::Type::kInt32:
2042 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002043 locations->SetInAt(0, Location::RequiresRegister());
2044 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07002045 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002046 break;
2047 }
2048 default:
2049 LOG(FATAL) << "Unexpected shift type " << type;
2050 }
2051}
2052
2053void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002054 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002055 LocationSummary* locations = instr->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002056 DataType::Type type = instr->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002057
2058 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002059 case DataType::Type::kInt32:
2060 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002061 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2062 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2063 Location rhs_location = locations->InAt(1);
2064
2065 GpuRegister rhs_reg = ZERO;
2066 int64_t rhs_imm = 0;
2067 bool use_imm = rhs_location.IsConstant();
2068 if (use_imm) {
2069 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
2070 } else {
2071 rhs_reg = rhs_location.AsRegister<GpuRegister>();
2072 }
2073
2074 if (use_imm) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00002075 uint32_t shift_value = rhs_imm &
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002076 (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002077
Alexey Frunze92d90602015-12-18 18:16:36 -08002078 if (shift_value == 0) {
2079 if (dst != lhs) {
2080 __ Move(dst, lhs);
2081 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002082 } else if (type == DataType::Type::kInt32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002083 if (instr->IsShl()) {
2084 __ Sll(dst, lhs, shift_value);
2085 } else if (instr->IsShr()) {
2086 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002087 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002088 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002089 } else {
2090 __ Rotr(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002091 }
2092 } else {
2093 if (shift_value < 32) {
2094 if (instr->IsShl()) {
2095 __ Dsll(dst, lhs, shift_value);
2096 } else if (instr->IsShr()) {
2097 __ Dsra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002098 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002099 __ Dsrl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002100 } else {
2101 __ Drotr(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002102 }
2103 } else {
2104 shift_value -= 32;
2105 if (instr->IsShl()) {
2106 __ Dsll32(dst, lhs, shift_value);
2107 } else if (instr->IsShr()) {
2108 __ Dsra32(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002109 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002110 __ Dsrl32(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002111 } else {
2112 __ Drotr32(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002113 }
2114 }
2115 }
2116 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002117 if (type == DataType::Type::kInt32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002118 if (instr->IsShl()) {
2119 __ Sllv(dst, lhs, rhs_reg);
2120 } else if (instr->IsShr()) {
2121 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002122 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002123 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002124 } else {
2125 __ Rotrv(dst, lhs, rhs_reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002126 }
2127 } else {
2128 if (instr->IsShl()) {
2129 __ Dsllv(dst, lhs, rhs_reg);
2130 } else if (instr->IsShr()) {
2131 __ Dsrav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002132 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002133 __ Dsrlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002134 } else {
2135 __ Drotrv(dst, lhs, rhs_reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002136 }
2137 }
2138 }
2139 break;
2140 }
2141 default:
2142 LOG(FATAL) << "Unexpected shift operation type " << type;
2143 }
2144}
2145
2146void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) {
2147 HandleBinaryOp(instruction);
2148}
2149
2150void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) {
2151 HandleBinaryOp(instruction);
2152}
2153
2154void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) {
2155 HandleBinaryOp(instruction);
2156}
2157
2158void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) {
2159 HandleBinaryOp(instruction);
2160}
2161
2162void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002163 DataType::Type type = instruction->GetType();
Alexey Frunze15958152017-02-09 19:08:30 -08002164 bool object_array_get_with_read_barrier =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002165 kEmitCompilerReadBarrier && (type == DataType::Type::kReference);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002166 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01002167 new (GetGraph()->GetAllocator()) LocationSummary(instruction,
2168 object_array_get_with_read_barrier
2169 ? LocationSummary::kCallOnSlowPath
2170 : LocationSummary::kNoCall);
Alexey Frunzec61c0762017-04-10 13:54:23 -07002171 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
2172 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
2173 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002174 locations->SetInAt(0, Location::RequiresRegister());
2175 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002176 if (DataType::IsFloatingPointType(type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002177 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2178 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08002179 // The output overlaps in the case of an object array get with
2180 // read barriers enabled: we do not want the move to overwrite the
2181 // array's location, as we need it to emit the read barrier.
2182 locations->SetOut(Location::RequiresRegister(),
2183 object_array_get_with_read_barrier
2184 ? Location::kOutputOverlap
2185 : Location::kNoOutputOverlap);
2186 }
2187 // We need a temporary register for the read barrier marking slow
2188 // path in CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier.
2189 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002190 bool temp_needed = instruction->GetIndex()->IsConstant()
2191 ? !kBakerReadBarrierThunksEnableForFields
2192 : !kBakerReadBarrierThunksEnableForArrays;
2193 if (temp_needed) {
2194 locations->AddTemp(Location::RequiresRegister());
2195 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002196 }
2197}
2198
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002199static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS64* codegen) {
2200 auto null_checker = [codegen, instruction]() {
2201 codegen->MaybeRecordImplicitNullCheck(instruction);
2202 };
2203 return null_checker;
2204}
2205
Alexey Frunze4dda3372015-06-01 18:31:49 -07002206void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) {
2207 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08002208 Location obj_loc = locations->InAt(0);
2209 GpuRegister obj = obj_loc.AsRegister<GpuRegister>();
2210 Location out_loc = locations->Out();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002211 Location index = locations->InAt(1);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01002212 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002213 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002214
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002215 DataType::Type type = instruction->GetType();
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002216 const bool maybe_compressed_char_at = mirror::kUseStringCompression &&
2217 instruction->IsStringCharAt();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002218 switch (type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002219 case DataType::Type::kBool:
2220 case DataType::Type::kUint8: {
Alexey Frunze15958152017-02-09 19:08:30 -08002221 GpuRegister out = out_loc.AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002222 if (index.IsConstant()) {
2223 size_t offset =
2224 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002225 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002226 } else {
2227 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002228 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002229 }
2230 break;
2231 }
2232
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002233 case DataType::Type::kInt8: {
Alexey Frunze15958152017-02-09 19:08:30 -08002234 GpuRegister out = out_loc.AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002235 if (index.IsConstant()) {
2236 size_t offset =
2237 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002238 __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002239 } else {
2240 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002241 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002242 }
2243 break;
2244 }
2245
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002246 case DataType::Type::kUint16: {
Alexey Frunze15958152017-02-09 19:08:30 -08002247 GpuRegister out = out_loc.AsRegister<GpuRegister>();
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002248 if (maybe_compressed_char_at) {
2249 uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002250 __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002251 __ Dext(TMP, TMP, 0, 1);
2252 static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u,
2253 "Expecting 0=compressed, 1=uncompressed");
2254 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002255 if (index.IsConstant()) {
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002256 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
2257 if (maybe_compressed_char_at) {
2258 Mips64Label uncompressed_load, done;
2259 __ Bnezc(TMP, &uncompressed_load);
2260 __ LoadFromOffset(kLoadUnsignedByte,
2261 out,
2262 obj,
2263 data_offset + (const_index << TIMES_1));
2264 __ Bc(&done);
2265 __ Bind(&uncompressed_load);
2266 __ LoadFromOffset(kLoadUnsignedHalfword,
2267 out,
2268 obj,
2269 data_offset + (const_index << TIMES_2));
2270 __ Bind(&done);
2271 } else {
2272 __ LoadFromOffset(kLoadUnsignedHalfword,
2273 out,
2274 obj,
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002275 data_offset + (const_index << TIMES_2),
2276 null_checker);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002277 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002278 } else {
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002279 GpuRegister index_reg = index.AsRegister<GpuRegister>();
2280 if (maybe_compressed_char_at) {
2281 Mips64Label uncompressed_load, done;
2282 __ Bnezc(TMP, &uncompressed_load);
2283 __ Daddu(TMP, obj, index_reg);
2284 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset);
2285 __ Bc(&done);
2286 __ Bind(&uncompressed_load);
Chris Larsencd0295d2017-03-31 15:26:54 -07002287 __ Dlsa(TMP, index_reg, obj, TIMES_2);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002288 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset);
2289 __ Bind(&done);
2290 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002291 __ Dlsa(TMP, index_reg, obj, TIMES_2);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002292 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002293 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002294 }
2295 break;
2296 }
2297
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002298 case DataType::Type::kInt16: {
2299 GpuRegister out = out_loc.AsRegister<GpuRegister>();
2300 if (index.IsConstant()) {
2301 size_t offset =
2302 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2303 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker);
2304 } else {
2305 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_2);
2306 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker);
2307 }
2308 break;
2309 }
2310
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002311 case DataType::Type::kInt32: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002312 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
Alexey Frunze15958152017-02-09 19:08:30 -08002313 GpuRegister out = out_loc.AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002314 LoadOperandType load_type =
2315 (type == DataType::Type::kReference) ? kLoadUnsignedWord : kLoadWord;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002316 if (index.IsConstant()) {
2317 size_t offset =
2318 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002319 __ LoadFromOffset(load_type, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002320 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002321 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002322 __ LoadFromOffset(load_type, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002323 }
2324 break;
2325 }
2326
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002327 case DataType::Type::kReference: {
Alexey Frunze15958152017-02-09 19:08:30 -08002328 static_assert(
2329 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
2330 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
2331 // /* HeapReference<Object> */ out =
2332 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
2333 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002334 bool temp_needed = index.IsConstant()
2335 ? !kBakerReadBarrierThunksEnableForFields
2336 : !kBakerReadBarrierThunksEnableForArrays;
2337 Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation();
Alexey Frunze15958152017-02-09 19:08:30 -08002338 // Note that a potential implicit null check is handled in this
2339 // CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier call.
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002340 DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0)));
2341 if (index.IsConstant()) {
2342 // Array load with a constant index can be treated as a field load.
2343 size_t offset =
2344 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2345 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
2346 out_loc,
2347 obj,
2348 offset,
2349 temp,
2350 /* needs_null_check */ false);
2351 } else {
2352 codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction,
2353 out_loc,
2354 obj,
2355 data_offset,
2356 index,
2357 temp,
2358 /* needs_null_check */ false);
2359 }
Alexey Frunze15958152017-02-09 19:08:30 -08002360 } else {
2361 GpuRegister out = out_loc.AsRegister<GpuRegister>();
2362 if (index.IsConstant()) {
2363 size_t offset =
2364 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2365 __ LoadFromOffset(kLoadUnsignedWord, out, obj, offset, null_checker);
2366 // If read barriers are enabled, emit read barriers other than
2367 // Baker's using a slow path (and also unpoison the loaded
2368 // reference, if heap poisoning is enabled).
2369 codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
2370 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002371 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Alexey Frunze15958152017-02-09 19:08:30 -08002372 __ LoadFromOffset(kLoadUnsignedWord, out, TMP, data_offset, null_checker);
2373 // If read barriers are enabled, emit read barriers other than
2374 // Baker's using a slow path (and also unpoison the loaded
2375 // reference, if heap poisoning is enabled).
2376 codegen_->MaybeGenerateReadBarrierSlow(instruction,
2377 out_loc,
2378 out_loc,
2379 obj_loc,
2380 data_offset,
2381 index);
2382 }
2383 }
2384 break;
2385 }
2386
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002387 case DataType::Type::kInt64: {
Alexey Frunze15958152017-02-09 19:08:30 -08002388 GpuRegister out = out_loc.AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002389 if (index.IsConstant()) {
2390 size_t offset =
2391 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002392 __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002393 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002394 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002395 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002396 }
2397 break;
2398 }
2399
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002400 case DataType::Type::kFloat32: {
Alexey Frunze15958152017-02-09 19:08:30 -08002401 FpuRegister out = out_loc.AsFpuRegister<FpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002402 if (index.IsConstant()) {
2403 size_t offset =
2404 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002405 __ LoadFpuFromOffset(kLoadWord, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002406 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002407 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002408 __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002409 }
2410 break;
2411 }
2412
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002413 case DataType::Type::kFloat64: {
Alexey Frunze15958152017-02-09 19:08:30 -08002414 FpuRegister out = out_loc.AsFpuRegister<FpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002415 if (index.IsConstant()) {
2416 size_t offset =
2417 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002418 __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002419 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002420 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002421 __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002422 }
2423 break;
2424 }
2425
Aart Bik66c158e2018-01-31 12:55:04 -08002426 case DataType::Type::kUint32:
2427 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002428 case DataType::Type::kVoid:
Alexey Frunze4dda3372015-06-01 18:31:49 -07002429 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2430 UNREACHABLE();
2431 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002432}
2433
2434void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01002435 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002436 locations->SetInAt(0, Location::RequiresRegister());
2437 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2438}
2439
2440void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) {
2441 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01002442 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002443 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2444 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2445 __ LoadFromOffset(kLoadWord, out, obj, offset);
2446 codegen_->MaybeRecordImplicitNullCheck(instruction);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002447 // Mask out compression flag from String's array length.
2448 if (mirror::kUseStringCompression && instruction->IsStringLength()) {
2449 __ Srl(out, out, 1u);
2450 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002451}
2452
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002453Location LocationsBuilderMIPS64::RegisterOrZeroConstant(HInstruction* instruction) {
2454 return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern())
2455 ? Location::ConstantLocation(instruction->AsConstant())
2456 : Location::RequiresRegister();
2457}
2458
2459Location LocationsBuilderMIPS64::FpuRegisterOrConstantForStore(HInstruction* instruction) {
2460 // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register.
2461 // We can store a non-zero float or double constant without first loading it into the FPU,
2462 // but we should only prefer this if the constant has a single use.
2463 if (instruction->IsConstant() &&
2464 (instruction->AsConstant()->IsZeroBitPattern() ||
2465 instruction->GetUses().HasExactlyOneElement())) {
2466 return Location::ConstantLocation(instruction->AsConstant());
2467 // Otherwise fall through and require an FPU register for the constant.
2468 }
2469 return Location::RequiresFpuRegister();
2470}
2471
Alexey Frunze4dda3372015-06-01 18:31:49 -07002472void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002473 DataType::Type value_type = instruction->GetComponentType();
Alexey Frunze15958152017-02-09 19:08:30 -08002474
2475 bool needs_write_barrier =
2476 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
2477 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
2478
Vladimir Markoca6fff82017-10-03 14:49:14 +01002479 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
Alexey Frunze4dda3372015-06-01 18:31:49 -07002480 instruction,
Alexey Frunze15958152017-02-09 19:08:30 -08002481 may_need_runtime_call_for_type_check ?
2482 LocationSummary::kCallOnSlowPath :
2483 LocationSummary::kNoCall);
2484
2485 locations->SetInAt(0, Location::RequiresRegister());
2486 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002487 if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
Alexey Frunze15958152017-02-09 19:08:30 -08002488 locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002489 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08002490 locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2)));
2491 }
2492 if (needs_write_barrier) {
2493 // Temporary register for the write barrier.
2494 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002495 }
2496}
2497
2498void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) {
2499 LocationSummary* locations = instruction->GetLocations();
2500 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2501 Location index = locations->InAt(1);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002502 Location value_location = locations->InAt(2);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002503 DataType::Type value_type = instruction->GetComponentType();
Alexey Frunze15958152017-02-09 19:08:30 -08002504 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002505 bool needs_write_barrier =
2506 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002507 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002508 GpuRegister base_reg = index.IsConstant() ? obj : TMP;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002509
2510 switch (value_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002511 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002512 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002513 case DataType::Type::kInt8: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002514 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002515 if (index.IsConstant()) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002516 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002517 } else {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002518 __ Daddu(base_reg, obj, index.AsRegister<GpuRegister>());
2519 }
2520 if (value_location.IsConstant()) {
2521 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2522 __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker);
2523 } else {
2524 GpuRegister value = value_location.AsRegister<GpuRegister>();
2525 __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002526 }
2527 break;
2528 }
2529
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002530 case DataType::Type::kUint16:
2531 case DataType::Type::kInt16: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002532 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002533 if (index.IsConstant()) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002534 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002535 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002536 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_2);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002537 }
2538 if (value_location.IsConstant()) {
2539 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2540 __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker);
2541 } else {
2542 GpuRegister value = value_location.AsRegister<GpuRegister>();
2543 __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002544 }
2545 break;
2546 }
2547
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002548 case DataType::Type::kInt32: {
Alexey Frunze15958152017-02-09 19:08:30 -08002549 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2550 if (index.IsConstant()) {
2551 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
2552 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002553 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Alexey Frunze15958152017-02-09 19:08:30 -08002554 }
2555 if (value_location.IsConstant()) {
2556 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2557 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2558 } else {
2559 GpuRegister value = value_location.AsRegister<GpuRegister>();
2560 __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
2561 }
2562 break;
2563 }
2564
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002565 case DataType::Type::kReference: {
Alexey Frunze15958152017-02-09 19:08:30 -08002566 if (value_location.IsConstant()) {
2567 // Just setting null.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002568 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002569 if (index.IsConstant()) {
Alexey Frunzec061de12017-02-14 13:27:23 -08002570 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002571 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002572 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Alexey Frunzec061de12017-02-14 13:27:23 -08002573 }
Alexey Frunze15958152017-02-09 19:08:30 -08002574 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2575 DCHECK_EQ(value, 0);
2576 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2577 DCHECK(!needs_write_barrier);
2578 DCHECK(!may_need_runtime_call_for_type_check);
2579 break;
2580 }
2581
2582 DCHECK(needs_write_barrier);
2583 GpuRegister value = value_location.AsRegister<GpuRegister>();
2584 GpuRegister temp1 = locations->GetTemp(0).AsRegister<GpuRegister>();
2585 GpuRegister temp2 = TMP; // Doesn't need to survive slow path.
2586 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2587 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
2588 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
2589 Mips64Label done;
2590 SlowPathCodeMIPS64* slow_path = nullptr;
2591
2592 if (may_need_runtime_call_for_type_check) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01002593 slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS64(instruction);
Alexey Frunze15958152017-02-09 19:08:30 -08002594 codegen_->AddSlowPath(slow_path);
2595 if (instruction->GetValueCanBeNull()) {
2596 Mips64Label non_zero;
2597 __ Bnezc(value, &non_zero);
2598 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2599 if (index.IsConstant()) {
2600 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002601 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002602 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002603 }
Alexey Frunze15958152017-02-09 19:08:30 -08002604 __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
2605 __ Bc(&done);
2606 __ Bind(&non_zero);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002607 }
Alexey Frunze15958152017-02-09 19:08:30 -08002608
2609 // Note that when read barriers are enabled, the type checks
2610 // are performed without read barriers. This is fine, even in
2611 // the case where a class object is in the from-space after
2612 // the flip, as a comparison involving such a type would not
2613 // produce a false positive; it may of course produce a false
2614 // negative, in which case we would take the ArraySet slow
2615 // path.
2616
2617 // /* HeapReference<Class> */ temp1 = obj->klass_
2618 __ LoadFromOffset(kLoadUnsignedWord, temp1, obj, class_offset, null_checker);
2619 __ MaybeUnpoisonHeapReference(temp1);
2620
2621 // /* HeapReference<Class> */ temp1 = temp1->component_type_
2622 __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, component_offset);
2623 // /* HeapReference<Class> */ temp2 = value->klass_
2624 __ LoadFromOffset(kLoadUnsignedWord, temp2, value, class_offset);
2625 // If heap poisoning is enabled, no need to unpoison `temp1`
2626 // nor `temp2`, as we are comparing two poisoned references.
2627
2628 if (instruction->StaticTypeOfArrayIsObjectArray()) {
2629 Mips64Label do_put;
2630 __ Beqc(temp1, temp2, &do_put);
2631 // If heap poisoning is enabled, the `temp1` reference has
2632 // not been unpoisoned yet; unpoison it now.
2633 __ MaybeUnpoisonHeapReference(temp1);
2634
2635 // /* HeapReference<Class> */ temp1 = temp1->super_class_
2636 __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, super_offset);
2637 // If heap poisoning is enabled, no need to unpoison
2638 // `temp1`, as we are comparing against null below.
2639 __ Bnezc(temp1, slow_path->GetEntryLabel());
2640 __ Bind(&do_put);
2641 } else {
2642 __ Bnec(temp1, temp2, slow_path->GetEntryLabel());
2643 }
2644 }
2645
2646 GpuRegister source = value;
2647 if (kPoisonHeapReferences) {
2648 // Note that in the case where `value` is a null reference,
2649 // we do not enter this block, as a null reference does not
2650 // need poisoning.
2651 __ Move(temp1, value);
2652 __ PoisonHeapReference(temp1);
2653 source = temp1;
2654 }
2655
2656 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2657 if (index.IsConstant()) {
2658 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002659 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002660 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Alexey Frunze15958152017-02-09 19:08:30 -08002661 }
2662 __ StoreToOffset(kStoreWord, source, base_reg, data_offset);
2663
2664 if (!may_need_runtime_call_for_type_check) {
2665 codegen_->MaybeRecordImplicitNullCheck(instruction);
2666 }
2667
2668 codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull());
2669
2670 if (done.IsLinked()) {
2671 __ Bind(&done);
2672 }
2673
2674 if (slow_path != nullptr) {
2675 __ Bind(slow_path->GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002676 }
2677 break;
2678 }
2679
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002680 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002681 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002682 if (index.IsConstant()) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002683 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002684 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002685 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002686 }
2687 if (value_location.IsConstant()) {
2688 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
2689 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
2690 } else {
2691 GpuRegister value = value_location.AsRegister<GpuRegister>();
2692 __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002693 }
2694 break;
2695 }
2696
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002697 case DataType::Type::kFloat32: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002698 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002699 if (index.IsConstant()) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002700 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002701 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002702 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002703 }
2704 if (value_location.IsConstant()) {
2705 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2706 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2707 } else {
2708 FpuRegister value = value_location.AsFpuRegister<FpuRegister>();
2709 __ StoreFpuToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002710 }
2711 break;
2712 }
2713
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002714 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002715 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002716 if (index.IsConstant()) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002717 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002718 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002719 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002720 }
2721 if (value_location.IsConstant()) {
2722 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
2723 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
2724 } else {
2725 FpuRegister value = value_location.AsFpuRegister<FpuRegister>();
2726 __ StoreFpuToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002727 }
2728 break;
2729 }
2730
Aart Bik66c158e2018-01-31 12:55:04 -08002731 case DataType::Type::kUint32:
2732 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002733 case DataType::Type::kVoid:
Alexey Frunze4dda3372015-06-01 18:31:49 -07002734 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2735 UNREACHABLE();
2736 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002737}
2738
2739void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01002740 RegisterSet caller_saves = RegisterSet::Empty();
2741 InvokeRuntimeCallingConvention calling_convention;
2742 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2743 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2744 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves);
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01002745
2746 HInstruction* index = instruction->InputAt(0);
2747 HInstruction* length = instruction->InputAt(1);
2748
2749 bool const_index = false;
2750 bool const_length = false;
2751
2752 if (index->IsConstant()) {
2753 if (length->IsConstant()) {
2754 const_index = true;
2755 const_length = true;
2756 } else {
2757 int32_t index_value = index->AsIntConstant()->GetValue();
2758 if (index_value < 0 || IsInt<16>(index_value + 1)) {
2759 const_index = true;
2760 }
2761 }
2762 } else if (length->IsConstant()) {
2763 int32_t length_value = length->AsIntConstant()->GetValue();
2764 if (IsUint<15>(length_value)) {
2765 const_length = true;
2766 }
2767 }
2768
2769 locations->SetInAt(0, const_index
2770 ? Location::ConstantLocation(index->AsConstant())
2771 : Location::RequiresRegister());
2772 locations->SetInAt(1, const_length
2773 ? Location::ConstantLocation(length->AsConstant())
2774 : Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002775}
2776
2777void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
2778 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01002779 Location index_loc = locations->InAt(0);
2780 Location length_loc = locations->InAt(1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002781
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01002782 if (length_loc.IsConstant()) {
2783 int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue();
2784 if (index_loc.IsConstant()) {
2785 int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue();
2786 if (index < 0 || index >= length) {
2787 BoundsCheckSlowPathMIPS64* slow_path =
2788 new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction);
2789 codegen_->AddSlowPath(slow_path);
2790 __ Bc(slow_path->GetEntryLabel());
2791 } else {
2792 // Nothing to be done.
2793 }
2794 return;
2795 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002796
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01002797 BoundsCheckSlowPathMIPS64* slow_path =
2798 new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction);
2799 codegen_->AddSlowPath(slow_path);
2800 GpuRegister index = index_loc.AsRegister<GpuRegister>();
2801 if (length == 0) {
2802 __ Bc(slow_path->GetEntryLabel());
2803 } else if (length == 1) {
2804 __ Bnezc(index, slow_path->GetEntryLabel());
2805 } else {
2806 DCHECK(IsUint<15>(length)) << length;
2807 __ Sltiu(TMP, index, length);
2808 __ Beqzc(TMP, slow_path->GetEntryLabel());
2809 }
2810 } else {
2811 GpuRegister length = length_loc.AsRegister<GpuRegister>();
2812 BoundsCheckSlowPathMIPS64* slow_path =
2813 new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction);
2814 codegen_->AddSlowPath(slow_path);
2815 if (index_loc.IsConstant()) {
2816 int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue();
2817 if (index < 0) {
2818 __ Bc(slow_path->GetEntryLabel());
2819 } else if (index == 0) {
2820 __ Blezc(length, slow_path->GetEntryLabel());
2821 } else {
2822 DCHECK(IsInt<16>(index + 1)) << index;
2823 __ Sltiu(TMP, length, index + 1);
2824 __ Bnezc(TMP, slow_path->GetEntryLabel());
2825 }
2826 } else {
2827 GpuRegister index = index_loc.AsRegister<GpuRegister>();
2828 __ Bgeuc(index, length, slow_path->GetEntryLabel());
2829 }
2830 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002831}
2832
Alexey Frunze15958152017-02-09 19:08:30 -08002833// Temp is used for read barrier.
2834static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) {
2835 if (kEmitCompilerReadBarrier &&
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002836 !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) &&
Alexey Frunze15958152017-02-09 19:08:30 -08002837 (kUseBakerReadBarrier ||
2838 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
2839 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
2840 type_check_kind == TypeCheckKind::kArrayObjectCheck)) {
2841 return 1;
2842 }
2843 return 0;
2844}
2845
2846// Extra temp is used for read barrier.
2847static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) {
2848 return 1 + NumberOfInstanceOfTemps(type_check_kind);
2849}
2850
Alexey Frunze4dda3372015-06-01 18:31:49 -07002851void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002852 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunzedfc30af2018-01-24 16:25:10 -08002853 LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction);
Vladimir Markoca6fff82017-10-03 14:49:14 +01002854 LocationSummary* locations =
2855 new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002856 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00002857 locations->SetInAt(1, Location::RequiresRegister());
Alexey Frunze15958152017-02-09 19:08:30 -08002858 locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002859}
2860
2861void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002862 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002863 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08002864 Location obj_loc = locations->InAt(0);
2865 GpuRegister obj = obj_loc.AsRegister<GpuRegister>();
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00002866 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
Alexey Frunze15958152017-02-09 19:08:30 -08002867 Location temp_loc = locations->GetTemp(0);
2868 GpuRegister temp = temp_loc.AsRegister<GpuRegister>();
2869 const size_t num_temps = NumberOfCheckCastTemps(type_check_kind);
2870 DCHECK_LE(num_temps, 2u);
2871 Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation();
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002872 const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2873 const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
2874 const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
2875 const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
2876 const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value();
2877 const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value();
2878 const uint32_t object_array_data_offset =
2879 mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value();
2880 Mips64Label done;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002881
Alexey Frunzedfc30af2018-01-24 16:25:10 -08002882 bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction);
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01002883 SlowPathCodeMIPS64* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01002884 new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64(
2885 instruction, is_type_check_slow_path_fatal);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002886 codegen_->AddSlowPath(slow_path);
2887
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002888 // Avoid this check if we know `obj` is not null.
2889 if (instruction->MustDoNullCheck()) {
2890 __ Beqzc(obj, &done);
2891 }
2892
2893 switch (type_check_kind) {
2894 case TypeCheckKind::kExactCheck:
2895 case TypeCheckKind::kArrayCheck: {
2896 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08002897 GenerateReferenceLoadTwoRegisters(instruction,
2898 temp_loc,
2899 obj_loc,
2900 class_offset,
2901 maybe_temp2_loc,
2902 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002903 // Jump to slow path for throwing the exception or doing a
2904 // more involved array check.
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00002905 __ Bnec(temp, cls, slow_path->GetEntryLabel());
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002906 break;
2907 }
2908
2909 case TypeCheckKind::kAbstractClassCheck: {
2910 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08002911 GenerateReferenceLoadTwoRegisters(instruction,
2912 temp_loc,
2913 obj_loc,
2914 class_offset,
2915 maybe_temp2_loc,
2916 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002917 // If the class is abstract, we eagerly fetch the super class of the
2918 // object to avoid doing a comparison we know will fail.
2919 Mips64Label loop;
2920 __ Bind(&loop);
2921 // /* HeapReference<Class> */ temp = temp->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08002922 GenerateReferenceLoadOneRegister(instruction,
2923 temp_loc,
2924 super_offset,
2925 maybe_temp2_loc,
2926 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002927 // If the class reference currently in `temp` is null, jump to the slow path to throw the
2928 // exception.
2929 __ Beqzc(temp, slow_path->GetEntryLabel());
2930 // Otherwise, compare the classes.
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00002931 __ Bnec(temp, cls, &loop);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002932 break;
2933 }
2934
2935 case TypeCheckKind::kClassHierarchyCheck: {
2936 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08002937 GenerateReferenceLoadTwoRegisters(instruction,
2938 temp_loc,
2939 obj_loc,
2940 class_offset,
2941 maybe_temp2_loc,
2942 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002943 // Walk over the class hierarchy to find a match.
2944 Mips64Label loop;
2945 __ Bind(&loop);
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00002946 __ Beqc(temp, cls, &done);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002947 // /* HeapReference<Class> */ temp = temp->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08002948 GenerateReferenceLoadOneRegister(instruction,
2949 temp_loc,
2950 super_offset,
2951 maybe_temp2_loc,
2952 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002953 // If the class reference currently in `temp` is null, jump to the slow path to throw the
2954 // exception. Otherwise, jump to the beginning of the loop.
2955 __ Bnezc(temp, &loop);
2956 __ Bc(slow_path->GetEntryLabel());
2957 break;
2958 }
2959
2960 case TypeCheckKind::kArrayObjectCheck: {
2961 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08002962 GenerateReferenceLoadTwoRegisters(instruction,
2963 temp_loc,
2964 obj_loc,
2965 class_offset,
2966 maybe_temp2_loc,
2967 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002968 // Do an exact check.
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00002969 __ Beqc(temp, cls, &done);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002970 // Otherwise, we need to check that the object's class is a non-primitive array.
2971 // /* HeapReference<Class> */ temp = temp->component_type_
Alexey Frunze15958152017-02-09 19:08:30 -08002972 GenerateReferenceLoadOneRegister(instruction,
2973 temp_loc,
2974 component_offset,
2975 maybe_temp2_loc,
2976 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002977 // If the component type is null, jump to the slow path to throw the exception.
2978 __ Beqzc(temp, slow_path->GetEntryLabel());
2979 // Otherwise, the object is indeed an array, further check that this component
2980 // type is not a primitive type.
2981 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
2982 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
2983 __ Bnezc(temp, slow_path->GetEntryLabel());
2984 break;
2985 }
2986
2987 case TypeCheckKind::kUnresolvedCheck:
2988 // We always go into the type check slow path for the unresolved check case.
2989 // We cannot directly call the CheckCast runtime entry point
2990 // without resorting to a type checking slow path here (i.e. by
2991 // calling InvokeRuntime directly), as it would require to
2992 // assign fixed registers for the inputs of this HInstanceOf
2993 // instruction (following the runtime calling convention), which
2994 // might be cluttered by the potential first read barrier
2995 // emission at the beginning of this method.
2996 __ Bc(slow_path->GetEntryLabel());
2997 break;
2998
2999 case TypeCheckKind::kInterfaceCheck: {
3000 // Avoid read barriers to improve performance of the fast path. We can not get false
3001 // positives by doing this.
3002 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003003 GenerateReferenceLoadTwoRegisters(instruction,
3004 temp_loc,
3005 obj_loc,
3006 class_offset,
3007 maybe_temp2_loc,
3008 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003009 // /* HeapReference<Class> */ temp = temp->iftable_
Alexey Frunze15958152017-02-09 19:08:30 -08003010 GenerateReferenceLoadTwoRegisters(instruction,
3011 temp_loc,
3012 temp_loc,
3013 iftable_offset,
3014 maybe_temp2_loc,
3015 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003016 // Iftable is never null.
3017 __ Lw(TMP, temp, array_length_offset);
3018 // Loop through the iftable and check if any class matches.
3019 Mips64Label loop;
3020 __ Bind(&loop);
3021 __ Beqzc(TMP, slow_path->GetEntryLabel());
3022 __ Lwu(AT, temp, object_array_data_offset);
3023 __ MaybeUnpoisonHeapReference(AT);
3024 // Go to next interface.
3025 __ Daddiu(temp, temp, 2 * kHeapReferenceSize);
3026 __ Addiu(TMP, TMP, -2);
3027 // Compare the classes and continue the loop if they do not match.
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00003028 __ Bnec(AT, cls, &loop);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003029 break;
3030 }
3031 }
3032
3033 __ Bind(&done);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003034 __ Bind(slow_path->GetExitLabel());
3035}
3036
3037void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) {
3038 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003039 new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003040 locations->SetInAt(0, Location::RequiresRegister());
3041 if (check->HasUses()) {
3042 locations->SetOut(Location::SameAsFirstInput());
3043 }
3044}
3045
3046void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) {
3047 // We assume the class is not null.
Vladimir Marko174b2e22017-10-12 13:34:49 +01003048 SlowPathCodeMIPS64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64(
Alexey Frunze4dda3372015-06-01 18:31:49 -07003049 check->GetLoadClass(),
3050 check,
3051 check->GetDexPc(),
3052 true);
3053 codegen_->AddSlowPath(slow_path);
3054 GenerateClassInitializationCheck(slow_path,
3055 check->GetLocations()->InAt(0).AsRegister<GpuRegister>());
3056}
3057
3058void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003059 DataType::Type in_type = compare->InputAt(0)->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003060
Vladimir Markoca6fff82017-10-03 14:49:14 +01003061 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(compare);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003062
3063 switch (in_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003064 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003065 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003066 case DataType::Type::kInt8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003067 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003068 case DataType::Type::kInt16:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003069 case DataType::Type::kInt32:
3070 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07003071 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07003072 locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003073 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3074 break;
3075
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003076 case DataType::Type::kFloat32:
3077 case DataType::Type::kFloat64:
Alexey Frunze299a9392015-12-08 16:08:02 -08003078 locations->SetInAt(0, Location::RequiresFpuRegister());
3079 locations->SetInAt(1, Location::RequiresFpuRegister());
3080 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003081 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003082
3083 default:
3084 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
3085 }
3086}
3087
3088void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) {
3089 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze299a9392015-12-08 16:08:02 -08003090 GpuRegister res = locations->Out().AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003091 DataType::Type in_type = instruction->InputAt(0)->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003092
3093 // 0 if: left == right
3094 // 1 if: left > right
3095 // -1 if: left < right
3096 switch (in_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003097 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003098 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003099 case DataType::Type::kInt8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003100 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003101 case DataType::Type::kInt16:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003102 case DataType::Type::kInt32:
3103 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003104 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07003105 Location rhs_location = locations->InAt(1);
3106 bool use_imm = rhs_location.IsConstant();
3107 GpuRegister rhs = ZERO;
3108 if (use_imm) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003109 if (in_type == DataType::Type::kInt64) {
Aart Bika19616e2016-02-01 18:57:58 -08003110 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
3111 if (value != 0) {
3112 rhs = AT;
3113 __ LoadConst64(rhs, value);
3114 }
Roland Levillaina5c4a402016-03-15 15:02:50 +00003115 } else {
3116 int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant());
3117 if (value != 0) {
3118 rhs = AT;
3119 __ LoadConst32(rhs, value);
3120 }
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07003121 }
3122 } else {
3123 rhs = rhs_location.AsRegister<GpuRegister>();
3124 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003125 __ Slt(TMP, lhs, rhs);
Alexey Frunze299a9392015-12-08 16:08:02 -08003126 __ Slt(res, rhs, lhs);
3127 __ Subu(res, res, TMP);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003128 break;
3129 }
3130
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003131 case DataType::Type::kFloat32: {
Alexey Frunze299a9392015-12-08 16:08:02 -08003132 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
3133 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
3134 Mips64Label done;
3135 __ CmpEqS(FTMP, lhs, rhs);
3136 __ LoadConst32(res, 0);
3137 __ Bc1nez(FTMP, &done);
Roland Levillain32ca3752016-02-17 16:49:37 +00003138 if (instruction->IsGtBias()) {
Alexey Frunze299a9392015-12-08 16:08:02 -08003139 __ CmpLtS(FTMP, lhs, rhs);
3140 __ LoadConst32(res, -1);
3141 __ Bc1nez(FTMP, &done);
3142 __ LoadConst32(res, 1);
3143 } else {
3144 __ CmpLtS(FTMP, rhs, lhs);
3145 __ LoadConst32(res, 1);
3146 __ Bc1nez(FTMP, &done);
3147 __ LoadConst32(res, -1);
3148 }
3149 __ Bind(&done);
3150 break;
3151 }
3152
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003153 case DataType::Type::kFloat64: {
Alexey Frunze299a9392015-12-08 16:08:02 -08003154 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
3155 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
3156 Mips64Label done;
3157 __ CmpEqD(FTMP, lhs, rhs);
3158 __ LoadConst32(res, 0);
3159 __ Bc1nez(FTMP, &done);
Roland Levillain32ca3752016-02-17 16:49:37 +00003160 if (instruction->IsGtBias()) {
Alexey Frunze299a9392015-12-08 16:08:02 -08003161 __ CmpLtD(FTMP, lhs, rhs);
3162 __ LoadConst32(res, -1);
3163 __ Bc1nez(FTMP, &done);
3164 __ LoadConst32(res, 1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003165 } else {
Alexey Frunze299a9392015-12-08 16:08:02 -08003166 __ CmpLtD(FTMP, rhs, lhs);
3167 __ LoadConst32(res, 1);
3168 __ Bc1nez(FTMP, &done);
3169 __ LoadConst32(res, -1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003170 }
Alexey Frunze299a9392015-12-08 16:08:02 -08003171 __ Bind(&done);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003172 break;
3173 }
3174
3175 default:
3176 LOG(FATAL) << "Unimplemented compare type " << in_type;
3177 }
3178}
3179
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00003180void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01003181 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunze299a9392015-12-08 16:08:02 -08003182 switch (instruction->InputAt(0)->GetType()) {
3183 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003184 case DataType::Type::kInt64:
Alexey Frunze299a9392015-12-08 16:08:02 -08003185 locations->SetInAt(0, Location::RequiresRegister());
3186 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3187 break;
3188
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003189 case DataType::Type::kFloat32:
3190 case DataType::Type::kFloat64:
Alexey Frunze299a9392015-12-08 16:08:02 -08003191 locations->SetInAt(0, Location::RequiresFpuRegister());
3192 locations->SetInAt(1, Location::RequiresFpuRegister());
3193 break;
3194 }
David Brazdilb3e773e2016-01-26 11:28:37 +00003195 if (!instruction->IsEmittedAtUseSite()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003196 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3197 }
3198}
3199
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00003200void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00003201 if (instruction->IsEmittedAtUseSite()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003202 return;
3203 }
3204
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003205 DataType::Type type = instruction->InputAt(0)->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003206 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze299a9392015-12-08 16:08:02 -08003207 switch (type) {
3208 default:
3209 // Integer case.
3210 GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations);
3211 return;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003212 case DataType::Type::kInt64:
Alexey Frunze299a9392015-12-08 16:08:02 -08003213 GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations);
3214 return;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003215 case DataType::Type::kFloat32:
3216 case DataType::Type::kFloat64:
Tijana Jakovljevic43758192016-12-30 09:23:01 +01003217 GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations);
3218 return;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003219 }
3220}
3221
Alexey Frunzec857c742015-09-23 15:12:39 -07003222void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
3223 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003224 DataType::Type type = instruction->GetResultType();
Alexey Frunzec857c742015-09-23 15:12:39 -07003225
3226 LocationSummary* locations = instruction->GetLocations();
3227 Location second = locations->InAt(1);
3228 DCHECK(second.IsConstant());
3229
3230 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3231 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
3232 int64_t imm = Int64FromConstant(second.GetConstant());
3233 DCHECK(imm == 1 || imm == -1);
3234
3235 if (instruction->IsRem()) {
3236 __ Move(out, ZERO);
3237 } else {
3238 if (imm == -1) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003239 if (type == DataType::Type::kInt32) {
Alexey Frunzec857c742015-09-23 15:12:39 -07003240 __ Subu(out, ZERO, dividend);
3241 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003242 DCHECK_EQ(type, DataType::Type::kInt64);
Alexey Frunzec857c742015-09-23 15:12:39 -07003243 __ Dsubu(out, ZERO, dividend);
3244 }
3245 } else if (out != dividend) {
3246 __ Move(out, dividend);
3247 }
3248 }
3249}
3250
3251void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
3252 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003253 DataType::Type type = instruction->GetResultType();
Alexey Frunzec857c742015-09-23 15:12:39 -07003254
3255 LocationSummary* locations = instruction->GetLocations();
3256 Location second = locations->InAt(1);
3257 DCHECK(second.IsConstant());
3258
3259 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3260 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
3261 int64_t imm = Int64FromConstant(second.GetConstant());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003262 uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm));
Alexey Frunzec857c742015-09-23 15:12:39 -07003263 int ctz_imm = CTZ(abs_imm);
3264
3265 if (instruction->IsDiv()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003266 if (type == DataType::Type::kInt32) {
Alexey Frunzec857c742015-09-23 15:12:39 -07003267 if (ctz_imm == 1) {
3268 // Fast path for division by +/-2, which is very common.
3269 __ Srl(TMP, dividend, 31);
3270 } else {
3271 __ Sra(TMP, dividend, 31);
3272 __ Srl(TMP, TMP, 32 - ctz_imm);
3273 }
3274 __ Addu(out, dividend, TMP);
3275 __ Sra(out, out, ctz_imm);
3276 if (imm < 0) {
3277 __ Subu(out, ZERO, out);
3278 }
3279 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003280 DCHECK_EQ(type, DataType::Type::kInt64);
Alexey Frunzec857c742015-09-23 15:12:39 -07003281 if (ctz_imm == 1) {
3282 // Fast path for division by +/-2, which is very common.
3283 __ Dsrl32(TMP, dividend, 31);
3284 } else {
3285 __ Dsra32(TMP, dividend, 31);
3286 if (ctz_imm > 32) {
3287 __ Dsrl(TMP, TMP, 64 - ctz_imm);
3288 } else {
3289 __ Dsrl32(TMP, TMP, 32 - ctz_imm);
3290 }
3291 }
3292 __ Daddu(out, dividend, TMP);
3293 if (ctz_imm < 32) {
3294 __ Dsra(out, out, ctz_imm);
3295 } else {
3296 __ Dsra32(out, out, ctz_imm - 32);
3297 }
3298 if (imm < 0) {
3299 __ Dsubu(out, ZERO, out);
3300 }
3301 }
3302 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003303 if (type == DataType::Type::kInt32) {
Alexey Frunzec857c742015-09-23 15:12:39 -07003304 if (ctz_imm == 1) {
3305 // Fast path for modulo +/-2, which is very common.
3306 __ Sra(TMP, dividend, 31);
3307 __ Subu(out, dividend, TMP);
3308 __ Andi(out, out, 1);
3309 __ Addu(out, out, TMP);
3310 } else {
3311 __ Sra(TMP, dividend, 31);
3312 __ Srl(TMP, TMP, 32 - ctz_imm);
3313 __ Addu(out, dividend, TMP);
Lena Djokica556e6b2017-12-13 12:09:42 +01003314 __ Ins(out, ZERO, ctz_imm, 32 - ctz_imm);
Alexey Frunzec857c742015-09-23 15:12:39 -07003315 __ Subu(out, out, TMP);
3316 }
3317 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003318 DCHECK_EQ(type, DataType::Type::kInt64);
Alexey Frunzec857c742015-09-23 15:12:39 -07003319 if (ctz_imm == 1) {
3320 // Fast path for modulo +/-2, which is very common.
3321 __ Dsra32(TMP, dividend, 31);
3322 __ Dsubu(out, dividend, TMP);
3323 __ Andi(out, out, 1);
3324 __ Daddu(out, out, TMP);
3325 } else {
3326 __ Dsra32(TMP, dividend, 31);
3327 if (ctz_imm > 32) {
3328 __ Dsrl(TMP, TMP, 64 - ctz_imm);
3329 } else {
3330 __ Dsrl32(TMP, TMP, 32 - ctz_imm);
3331 }
3332 __ Daddu(out, dividend, TMP);
Lena Djokica556e6b2017-12-13 12:09:42 +01003333 __ DblIns(out, ZERO, ctz_imm, 64 - ctz_imm);
Alexey Frunzec857c742015-09-23 15:12:39 -07003334 __ Dsubu(out, out, TMP);
3335 }
3336 }
3337 }
3338}
3339
3340void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
3341 DCHECK(instruction->IsDiv() || instruction->IsRem());
3342
3343 LocationSummary* locations = instruction->GetLocations();
3344 Location second = locations->InAt(1);
3345 DCHECK(second.IsConstant());
3346
3347 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3348 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
3349 int64_t imm = Int64FromConstant(second.GetConstant());
3350
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003351 DataType::Type type = instruction->GetResultType();
3352 DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type;
Alexey Frunzec857c742015-09-23 15:12:39 -07003353
3354 int64_t magic;
3355 int shift;
3356 CalculateMagicAndShiftForDivRem(imm,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003357 (type == DataType::Type::kInt64),
Alexey Frunzec857c742015-09-23 15:12:39 -07003358 &magic,
3359 &shift);
3360
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003361 if (type == DataType::Type::kInt32) {
Alexey Frunzec857c742015-09-23 15:12:39 -07003362 __ LoadConst32(TMP, magic);
3363 __ MuhR6(TMP, dividend, TMP);
3364
3365 if (imm > 0 && magic < 0) {
3366 __ Addu(TMP, TMP, dividend);
3367 } else if (imm < 0 && magic > 0) {
3368 __ Subu(TMP, TMP, dividend);
3369 }
3370
3371 if (shift != 0) {
3372 __ Sra(TMP, TMP, shift);
3373 }
3374
3375 if (instruction->IsDiv()) {
3376 __ Sra(out, TMP, 31);
3377 __ Subu(out, TMP, out);
3378 } else {
3379 __ Sra(AT, TMP, 31);
3380 __ Subu(AT, TMP, AT);
3381 __ LoadConst32(TMP, imm);
3382 __ MulR6(TMP, AT, TMP);
3383 __ Subu(out, dividend, TMP);
3384 }
3385 } else {
3386 __ LoadConst64(TMP, magic);
3387 __ Dmuh(TMP, dividend, TMP);
3388
3389 if (imm > 0 && magic < 0) {
3390 __ Daddu(TMP, TMP, dividend);
3391 } else if (imm < 0 && magic > 0) {
3392 __ Dsubu(TMP, TMP, dividend);
3393 }
3394
3395 if (shift >= 32) {
3396 __ Dsra32(TMP, TMP, shift - 32);
3397 } else if (shift > 0) {
3398 __ Dsra(TMP, TMP, shift);
3399 }
3400
3401 if (instruction->IsDiv()) {
3402 __ Dsra32(out, TMP, 31);
3403 __ Dsubu(out, TMP, out);
3404 } else {
3405 __ Dsra32(AT, TMP, 31);
3406 __ Dsubu(AT, TMP, AT);
3407 __ LoadConst64(TMP, imm);
3408 __ Dmul(TMP, AT, TMP);
3409 __ Dsubu(out, dividend, TMP);
3410 }
3411 }
3412}
3413
3414void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) {
3415 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003416 DataType::Type type = instruction->GetResultType();
3417 DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type;
Alexey Frunzec857c742015-09-23 15:12:39 -07003418
3419 LocationSummary* locations = instruction->GetLocations();
3420 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3421 Location second = locations->InAt(1);
3422
3423 if (second.IsConstant()) {
3424 int64_t imm = Int64FromConstant(second.GetConstant());
3425 if (imm == 0) {
3426 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
3427 } else if (imm == 1 || imm == -1) {
3428 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003429 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunzec857c742015-09-23 15:12:39 -07003430 DivRemByPowerOfTwo(instruction);
3431 } else {
3432 DCHECK(imm <= -2 || imm >= 2);
3433 GenerateDivRemWithAnyConstant(instruction);
3434 }
3435 } else {
3436 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
3437 GpuRegister divisor = second.AsRegister<GpuRegister>();
3438 if (instruction->IsDiv()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003439 if (type == DataType::Type::kInt32)
Alexey Frunzec857c742015-09-23 15:12:39 -07003440 __ DivR6(out, dividend, divisor);
3441 else
3442 __ Ddiv(out, dividend, divisor);
3443 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003444 if (type == DataType::Type::kInt32)
Alexey Frunzec857c742015-09-23 15:12:39 -07003445 __ ModR6(out, dividend, divisor);
3446 else
3447 __ Dmod(out, dividend, divisor);
3448 }
3449 }
3450}
3451
Alexey Frunze4dda3372015-06-01 18:31:49 -07003452void LocationsBuilderMIPS64::VisitDiv(HDiv* div) {
3453 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003454 new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003455 switch (div->GetResultType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003456 case DataType::Type::kInt32:
3457 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07003458 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunzec857c742015-09-23 15:12:39 -07003459 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003460 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3461 break;
3462
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003463 case DataType::Type::kFloat32:
3464 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07003465 locations->SetInAt(0, Location::RequiresFpuRegister());
3466 locations->SetInAt(1, Location::RequiresFpuRegister());
3467 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3468 break;
3469
3470 default:
3471 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
3472 }
3473}
3474
3475void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003476 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003477 LocationSummary* locations = instruction->GetLocations();
3478
3479 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003480 case DataType::Type::kInt32:
3481 case DataType::Type::kInt64:
Alexey Frunzec857c742015-09-23 15:12:39 -07003482 GenerateDivRemIntegral(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003483 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003484 case DataType::Type::kFloat32:
3485 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003486 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3487 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
3488 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003489 if (type == DataType::Type::kFloat32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07003490 __ DivS(dst, lhs, rhs);
3491 else
3492 __ DivD(dst, lhs, rhs);
3493 break;
3494 }
3495 default:
3496 LOG(FATAL) << "Unexpected div type " << type;
3497 }
3498}
3499
3500void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01003501 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003502 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003503}
3504
3505void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
3506 SlowPathCodeMIPS64* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01003507 new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003508 codegen_->AddSlowPath(slow_path);
3509 Location value = instruction->GetLocations()->InAt(0);
3510
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003511 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003512
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003513 if (!DataType::IsIntegralType(type)) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00003514 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
Serguei Katkov8c0676c2015-08-03 13:55:33 +06003515 return;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003516 }
3517
3518 if (value.IsConstant()) {
3519 int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant());
3520 if (divisor == 0) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003521 __ Bc(slow_path->GetEntryLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003522 } else {
3523 // A division by a non-null constant is valid. We don't need to perform
3524 // any check, so simply fall through.
3525 }
3526 } else {
3527 __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
3528 }
3529}
3530
3531void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) {
3532 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003533 new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003534 locations->SetOut(Location::ConstantLocation(constant));
3535}
3536
3537void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
3538 // Will be generated at use site.
3539}
3540
3541void LocationsBuilderMIPS64::VisitExit(HExit* exit) {
3542 exit->SetLocations(nullptr);
3543}
3544
3545void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
3546}
3547
3548void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) {
3549 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003550 new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003551 locations->SetOut(Location::ConstantLocation(constant));
3552}
3553
3554void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
3555 // Will be generated at use site.
3556}
3557
David Brazdilfc6a86a2015-06-26 10:33:45 +00003558void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Aart Bika8b8e9b2018-01-09 11:01:02 -08003559 if (successor->IsExitBlock()) {
3560 DCHECK(got->GetPrevious()->AlwaysThrows());
3561 return; // no code needed
3562 }
3563
Alexey Frunze4dda3372015-06-01 18:31:49 -07003564 HBasicBlock* block = got->GetBlock();
3565 HInstruction* previous = got->GetPrevious();
3566 HLoopInformation* info = block->GetLoopInformation();
3567
3568 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Goran Jakovljevicfeec1672018-02-08 10:20:14 +01003569 if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) {
3570 __ Ld(AT, SP, kCurrentMethodStackOffset);
3571 __ Lhu(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value());
3572 __ Addiu(TMP, TMP, 1);
3573 __ Sh(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value());
3574 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003575 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
3576 return;
3577 }
3578 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
3579 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
3580 }
3581 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003582 __ Bc(codegen_->GetLabelOf(successor));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003583 }
3584}
3585
David Brazdilfc6a86a2015-06-26 10:33:45 +00003586void LocationsBuilderMIPS64::VisitGoto(HGoto* got) {
3587 got->SetLocations(nullptr);
3588}
3589
3590void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) {
3591 HandleGoto(got, got->GetSuccessor());
3592}
3593
3594void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
3595 try_boundary->SetLocations(nullptr);
3596}
3597
3598void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
3599 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
3600 if (!successor->IsExitBlock()) {
3601 HandleGoto(try_boundary, successor);
3602 }
3603}
3604
Alexey Frunze299a9392015-12-08 16:08:02 -08003605void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond,
3606 bool is64bit,
3607 LocationSummary* locations) {
3608 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3609 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
3610 Location rhs_location = locations->InAt(1);
3611 GpuRegister rhs_reg = ZERO;
3612 int64_t rhs_imm = 0;
3613 bool use_imm = rhs_location.IsConstant();
3614 if (use_imm) {
3615 if (is64bit) {
3616 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
3617 } else {
3618 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
3619 }
3620 } else {
3621 rhs_reg = rhs_location.AsRegister<GpuRegister>();
3622 }
3623 int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1);
3624
3625 switch (cond) {
3626 case kCondEQ:
3627 case kCondNE:
Goran Jakovljevicdb3deee2016-12-28 14:33:21 +01003628 if (use_imm && IsInt<16>(-rhs_imm)) {
3629 if (rhs_imm == 0) {
3630 if (cond == kCondEQ) {
3631 __ Sltiu(dst, lhs, 1);
3632 } else {
3633 __ Sltu(dst, ZERO, lhs);
3634 }
3635 } else {
3636 if (is64bit) {
3637 __ Daddiu(dst, lhs, -rhs_imm);
3638 } else {
3639 __ Addiu(dst, lhs, -rhs_imm);
3640 }
3641 if (cond == kCondEQ) {
3642 __ Sltiu(dst, dst, 1);
3643 } else {
3644 __ Sltu(dst, ZERO, dst);
3645 }
Alexey Frunze299a9392015-12-08 16:08:02 -08003646 }
Alexey Frunze299a9392015-12-08 16:08:02 -08003647 } else {
Goran Jakovljevicdb3deee2016-12-28 14:33:21 +01003648 if (use_imm && IsUint<16>(rhs_imm)) {
3649 __ Xori(dst, lhs, rhs_imm);
3650 } else {
3651 if (use_imm) {
3652 rhs_reg = TMP;
3653 __ LoadConst64(rhs_reg, rhs_imm);
3654 }
3655 __ Xor(dst, lhs, rhs_reg);
3656 }
3657 if (cond == kCondEQ) {
3658 __ Sltiu(dst, dst, 1);
3659 } else {
3660 __ Sltu(dst, ZERO, dst);
3661 }
Alexey Frunze299a9392015-12-08 16:08:02 -08003662 }
3663 break;
3664
3665 case kCondLT:
3666 case kCondGE:
3667 if (use_imm && IsInt<16>(rhs_imm)) {
3668 __ Slti(dst, lhs, rhs_imm);
3669 } else {
3670 if (use_imm) {
3671 rhs_reg = TMP;
3672 __ LoadConst64(rhs_reg, rhs_imm);
3673 }
3674 __ Slt(dst, lhs, rhs_reg);
3675 }
3676 if (cond == kCondGE) {
3677 // Simulate lhs >= rhs via !(lhs < rhs) since there's
3678 // only the slt instruction but no sge.
3679 __ Xori(dst, dst, 1);
3680 }
3681 break;
3682
3683 case kCondLE:
3684 case kCondGT:
3685 if (use_imm && IsInt<16>(rhs_imm_plus_one)) {
3686 // Simulate lhs <= rhs via lhs < rhs + 1.
3687 __ Slti(dst, lhs, rhs_imm_plus_one);
3688 if (cond == kCondGT) {
3689 // Simulate lhs > rhs via !(lhs <= rhs) since there's
3690 // only the slti instruction but no sgti.
3691 __ Xori(dst, dst, 1);
3692 }
3693 } else {
3694 if (use_imm) {
3695 rhs_reg = TMP;
3696 __ LoadConst64(rhs_reg, rhs_imm);
3697 }
3698 __ Slt(dst, rhs_reg, lhs);
3699 if (cond == kCondLE) {
3700 // Simulate lhs <= rhs via !(rhs < lhs) since there's
3701 // only the slt instruction but no sle.
3702 __ Xori(dst, dst, 1);
3703 }
3704 }
3705 break;
3706
3707 case kCondB:
3708 case kCondAE:
3709 if (use_imm && IsInt<16>(rhs_imm)) {
3710 // Sltiu sign-extends its 16-bit immediate operand before
3711 // the comparison and thus lets us compare directly with
3712 // unsigned values in the ranges [0, 0x7fff] and
3713 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
3714 __ Sltiu(dst, lhs, rhs_imm);
3715 } else {
3716 if (use_imm) {
3717 rhs_reg = TMP;
3718 __ LoadConst64(rhs_reg, rhs_imm);
3719 }
3720 __ Sltu(dst, lhs, rhs_reg);
3721 }
3722 if (cond == kCondAE) {
3723 // Simulate lhs >= rhs via !(lhs < rhs) since there's
3724 // only the sltu instruction but no sgeu.
3725 __ Xori(dst, dst, 1);
3726 }
3727 break;
3728
3729 case kCondBE:
3730 case kCondA:
3731 if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) {
3732 // Simulate lhs <= rhs via lhs < rhs + 1.
3733 // Note that this only works if rhs + 1 does not overflow
3734 // to 0, hence the check above.
3735 // Sltiu sign-extends its 16-bit immediate operand before
3736 // the comparison and thus lets us compare directly with
3737 // unsigned values in the ranges [0, 0x7fff] and
3738 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
3739 __ Sltiu(dst, lhs, rhs_imm_plus_one);
3740 if (cond == kCondA) {
3741 // Simulate lhs > rhs via !(lhs <= rhs) since there's
3742 // only the sltiu instruction but no sgtiu.
3743 __ Xori(dst, dst, 1);
3744 }
3745 } else {
3746 if (use_imm) {
3747 rhs_reg = TMP;
3748 __ LoadConst64(rhs_reg, rhs_imm);
3749 }
3750 __ Sltu(dst, rhs_reg, lhs);
3751 if (cond == kCondBE) {
3752 // Simulate lhs <= rhs via !(rhs < lhs) since there's
3753 // only the sltu instruction but no sleu.
3754 __ Xori(dst, dst, 1);
3755 }
3756 }
3757 break;
3758 }
3759}
3760
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02003761bool InstructionCodeGeneratorMIPS64::MaterializeIntLongCompare(IfCondition cond,
3762 bool is64bit,
3763 LocationSummary* input_locations,
3764 GpuRegister dst) {
3765 GpuRegister lhs = input_locations->InAt(0).AsRegister<GpuRegister>();
3766 Location rhs_location = input_locations->InAt(1);
3767 GpuRegister rhs_reg = ZERO;
3768 int64_t rhs_imm = 0;
3769 bool use_imm = rhs_location.IsConstant();
3770 if (use_imm) {
3771 if (is64bit) {
3772 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
3773 } else {
3774 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
3775 }
3776 } else {
3777 rhs_reg = rhs_location.AsRegister<GpuRegister>();
3778 }
3779 int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1);
3780
3781 switch (cond) {
3782 case kCondEQ:
3783 case kCondNE:
3784 if (use_imm && IsInt<16>(-rhs_imm)) {
3785 if (is64bit) {
3786 __ Daddiu(dst, lhs, -rhs_imm);
3787 } else {
3788 __ Addiu(dst, lhs, -rhs_imm);
3789 }
3790 } else if (use_imm && IsUint<16>(rhs_imm)) {
3791 __ Xori(dst, lhs, rhs_imm);
3792 } else {
3793 if (use_imm) {
3794 rhs_reg = TMP;
3795 __ LoadConst64(rhs_reg, rhs_imm);
3796 }
3797 __ Xor(dst, lhs, rhs_reg);
3798 }
3799 return (cond == kCondEQ);
3800
3801 case kCondLT:
3802 case kCondGE:
3803 if (use_imm && IsInt<16>(rhs_imm)) {
3804 __ Slti(dst, lhs, rhs_imm);
3805 } else {
3806 if (use_imm) {
3807 rhs_reg = TMP;
3808 __ LoadConst64(rhs_reg, rhs_imm);
3809 }
3810 __ Slt(dst, lhs, rhs_reg);
3811 }
3812 return (cond == kCondGE);
3813
3814 case kCondLE:
3815 case kCondGT:
3816 if (use_imm && IsInt<16>(rhs_imm_plus_one)) {
3817 // Simulate lhs <= rhs via lhs < rhs + 1.
3818 __ Slti(dst, lhs, rhs_imm_plus_one);
3819 return (cond == kCondGT);
3820 } else {
3821 if (use_imm) {
3822 rhs_reg = TMP;
3823 __ LoadConst64(rhs_reg, rhs_imm);
3824 }
3825 __ Slt(dst, rhs_reg, lhs);
3826 return (cond == kCondLE);
3827 }
3828
3829 case kCondB:
3830 case kCondAE:
3831 if (use_imm && IsInt<16>(rhs_imm)) {
3832 // Sltiu sign-extends its 16-bit immediate operand before
3833 // the comparison and thus lets us compare directly with
3834 // unsigned values in the ranges [0, 0x7fff] and
3835 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
3836 __ Sltiu(dst, lhs, rhs_imm);
3837 } else {
3838 if (use_imm) {
3839 rhs_reg = TMP;
3840 __ LoadConst64(rhs_reg, rhs_imm);
3841 }
3842 __ Sltu(dst, lhs, rhs_reg);
3843 }
3844 return (cond == kCondAE);
3845
3846 case kCondBE:
3847 case kCondA:
3848 if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) {
3849 // Simulate lhs <= rhs via lhs < rhs + 1.
3850 // Note that this only works if rhs + 1 does not overflow
3851 // to 0, hence the check above.
3852 // Sltiu sign-extends its 16-bit immediate operand before
3853 // the comparison and thus lets us compare directly with
3854 // unsigned values in the ranges [0, 0x7fff] and
3855 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
3856 __ Sltiu(dst, lhs, rhs_imm_plus_one);
3857 return (cond == kCondA);
3858 } else {
3859 if (use_imm) {
3860 rhs_reg = TMP;
3861 __ LoadConst64(rhs_reg, rhs_imm);
3862 }
3863 __ Sltu(dst, rhs_reg, lhs);
3864 return (cond == kCondBE);
3865 }
3866 }
3867}
3868
Alexey Frunze299a9392015-12-08 16:08:02 -08003869void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond,
3870 bool is64bit,
3871 LocationSummary* locations,
3872 Mips64Label* label) {
3873 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
3874 Location rhs_location = locations->InAt(1);
3875 GpuRegister rhs_reg = ZERO;
3876 int64_t rhs_imm = 0;
3877 bool use_imm = rhs_location.IsConstant();
3878 if (use_imm) {
3879 if (is64bit) {
3880 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
3881 } else {
3882 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
3883 }
3884 } else {
3885 rhs_reg = rhs_location.AsRegister<GpuRegister>();
3886 }
3887
3888 if (use_imm && rhs_imm == 0) {
3889 switch (cond) {
3890 case kCondEQ:
3891 case kCondBE: // <= 0 if zero
3892 __ Beqzc(lhs, label);
3893 break;
3894 case kCondNE:
3895 case kCondA: // > 0 if non-zero
3896 __ Bnezc(lhs, label);
3897 break;
3898 case kCondLT:
3899 __ Bltzc(lhs, label);
3900 break;
3901 case kCondGE:
3902 __ Bgezc(lhs, label);
3903 break;
3904 case kCondLE:
3905 __ Blezc(lhs, label);
3906 break;
3907 case kCondGT:
3908 __ Bgtzc(lhs, label);
3909 break;
3910 case kCondB: // always false
3911 break;
3912 case kCondAE: // always true
3913 __ Bc(label);
3914 break;
3915 }
3916 } else {
3917 if (use_imm) {
3918 rhs_reg = TMP;
3919 __ LoadConst64(rhs_reg, rhs_imm);
3920 }
3921 switch (cond) {
3922 case kCondEQ:
3923 __ Beqc(lhs, rhs_reg, label);
3924 break;
3925 case kCondNE:
3926 __ Bnec(lhs, rhs_reg, label);
3927 break;
3928 case kCondLT:
3929 __ Bltc(lhs, rhs_reg, label);
3930 break;
3931 case kCondGE:
3932 __ Bgec(lhs, rhs_reg, label);
3933 break;
3934 case kCondLE:
3935 __ Bgec(rhs_reg, lhs, label);
3936 break;
3937 case kCondGT:
3938 __ Bltc(rhs_reg, lhs, label);
3939 break;
3940 case kCondB:
3941 __ Bltuc(lhs, rhs_reg, label);
3942 break;
3943 case kCondAE:
3944 __ Bgeuc(lhs, rhs_reg, label);
3945 break;
3946 case kCondBE:
3947 __ Bgeuc(rhs_reg, lhs, label);
3948 break;
3949 case kCondA:
3950 __ Bltuc(rhs_reg, lhs, label);
3951 break;
3952 }
3953 }
3954}
3955
Tijana Jakovljevic43758192016-12-30 09:23:01 +01003956void InstructionCodeGeneratorMIPS64::GenerateFpCompare(IfCondition cond,
3957 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003958 DataType::Type type,
Tijana Jakovljevic43758192016-12-30 09:23:01 +01003959 LocationSummary* locations) {
3960 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3961 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
3962 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003963 if (type == DataType::Type::kFloat32) {
Tijana Jakovljevic43758192016-12-30 09:23:01 +01003964 switch (cond) {
3965 case kCondEQ:
3966 __ CmpEqS(FTMP, lhs, rhs);
3967 __ Mfc1(dst, FTMP);
3968 __ Andi(dst, dst, 1);
3969 break;
3970 case kCondNE:
3971 __ CmpEqS(FTMP, lhs, rhs);
3972 __ Mfc1(dst, FTMP);
3973 __ Addiu(dst, dst, 1);
3974 break;
3975 case kCondLT:
3976 if (gt_bias) {
3977 __ CmpLtS(FTMP, lhs, rhs);
3978 } else {
3979 __ CmpUltS(FTMP, lhs, rhs);
3980 }
3981 __ Mfc1(dst, FTMP);
3982 __ Andi(dst, dst, 1);
3983 break;
3984 case kCondLE:
3985 if (gt_bias) {
3986 __ CmpLeS(FTMP, lhs, rhs);
3987 } else {
3988 __ CmpUleS(FTMP, lhs, rhs);
3989 }
3990 __ Mfc1(dst, FTMP);
3991 __ Andi(dst, dst, 1);
3992 break;
3993 case kCondGT:
3994 if (gt_bias) {
3995 __ CmpUltS(FTMP, rhs, lhs);
3996 } else {
3997 __ CmpLtS(FTMP, rhs, lhs);
3998 }
3999 __ Mfc1(dst, FTMP);
4000 __ Andi(dst, dst, 1);
4001 break;
4002 case kCondGE:
4003 if (gt_bias) {
4004 __ CmpUleS(FTMP, rhs, lhs);
4005 } else {
4006 __ CmpLeS(FTMP, rhs, lhs);
4007 }
4008 __ Mfc1(dst, FTMP);
4009 __ Andi(dst, dst, 1);
4010 break;
4011 default:
4012 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4013 UNREACHABLE();
4014 }
4015 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004016 DCHECK_EQ(type, DataType::Type::kFloat64);
Tijana Jakovljevic43758192016-12-30 09:23:01 +01004017 switch (cond) {
4018 case kCondEQ:
4019 __ CmpEqD(FTMP, lhs, rhs);
4020 __ Mfc1(dst, FTMP);
4021 __ Andi(dst, dst, 1);
4022 break;
4023 case kCondNE:
4024 __ CmpEqD(FTMP, lhs, rhs);
4025 __ Mfc1(dst, FTMP);
4026 __ Addiu(dst, dst, 1);
4027 break;
4028 case kCondLT:
4029 if (gt_bias) {
4030 __ CmpLtD(FTMP, lhs, rhs);
4031 } else {
4032 __ CmpUltD(FTMP, lhs, rhs);
4033 }
4034 __ Mfc1(dst, FTMP);
4035 __ Andi(dst, dst, 1);
4036 break;
4037 case kCondLE:
4038 if (gt_bias) {
4039 __ CmpLeD(FTMP, lhs, rhs);
4040 } else {
4041 __ CmpUleD(FTMP, lhs, rhs);
4042 }
4043 __ Mfc1(dst, FTMP);
4044 __ Andi(dst, dst, 1);
4045 break;
4046 case kCondGT:
4047 if (gt_bias) {
4048 __ CmpUltD(FTMP, rhs, lhs);
4049 } else {
4050 __ CmpLtD(FTMP, rhs, lhs);
4051 }
4052 __ Mfc1(dst, FTMP);
4053 __ Andi(dst, dst, 1);
4054 break;
4055 case kCondGE:
4056 if (gt_bias) {
4057 __ CmpUleD(FTMP, rhs, lhs);
4058 } else {
4059 __ CmpLeD(FTMP, rhs, lhs);
4060 }
4061 __ Mfc1(dst, FTMP);
4062 __ Andi(dst, dst, 1);
4063 break;
4064 default:
4065 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4066 UNREACHABLE();
4067 }
4068 }
4069}
4070
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004071bool InstructionCodeGeneratorMIPS64::MaterializeFpCompare(IfCondition cond,
4072 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004073 DataType::Type type,
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004074 LocationSummary* input_locations,
4075 FpuRegister dst) {
4076 FpuRegister lhs = input_locations->InAt(0).AsFpuRegister<FpuRegister>();
4077 FpuRegister rhs = input_locations->InAt(1).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004078 if (type == DataType::Type::kFloat32) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004079 switch (cond) {
4080 case kCondEQ:
4081 __ CmpEqS(dst, lhs, rhs);
4082 return false;
4083 case kCondNE:
4084 __ CmpEqS(dst, lhs, rhs);
4085 return true;
4086 case kCondLT:
4087 if (gt_bias) {
4088 __ CmpLtS(dst, lhs, rhs);
4089 } else {
4090 __ CmpUltS(dst, lhs, rhs);
4091 }
4092 return false;
4093 case kCondLE:
4094 if (gt_bias) {
4095 __ CmpLeS(dst, lhs, rhs);
4096 } else {
4097 __ CmpUleS(dst, lhs, rhs);
4098 }
4099 return false;
4100 case kCondGT:
4101 if (gt_bias) {
4102 __ CmpUltS(dst, rhs, lhs);
4103 } else {
4104 __ CmpLtS(dst, rhs, lhs);
4105 }
4106 return false;
4107 case kCondGE:
4108 if (gt_bias) {
4109 __ CmpUleS(dst, rhs, lhs);
4110 } else {
4111 __ CmpLeS(dst, rhs, lhs);
4112 }
4113 return false;
4114 default:
4115 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4116 UNREACHABLE();
4117 }
4118 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004119 DCHECK_EQ(type, DataType::Type::kFloat64);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004120 switch (cond) {
4121 case kCondEQ:
4122 __ CmpEqD(dst, lhs, rhs);
4123 return false;
4124 case kCondNE:
4125 __ CmpEqD(dst, lhs, rhs);
4126 return true;
4127 case kCondLT:
4128 if (gt_bias) {
4129 __ CmpLtD(dst, lhs, rhs);
4130 } else {
4131 __ CmpUltD(dst, lhs, rhs);
4132 }
4133 return false;
4134 case kCondLE:
4135 if (gt_bias) {
4136 __ CmpLeD(dst, lhs, rhs);
4137 } else {
4138 __ CmpUleD(dst, lhs, rhs);
4139 }
4140 return false;
4141 case kCondGT:
4142 if (gt_bias) {
4143 __ CmpUltD(dst, rhs, lhs);
4144 } else {
4145 __ CmpLtD(dst, rhs, lhs);
4146 }
4147 return false;
4148 case kCondGE:
4149 if (gt_bias) {
4150 __ CmpUleD(dst, rhs, lhs);
4151 } else {
4152 __ CmpLeD(dst, rhs, lhs);
4153 }
4154 return false;
4155 default:
4156 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4157 UNREACHABLE();
4158 }
4159 }
4160}
4161
Alexey Frunze299a9392015-12-08 16:08:02 -08004162void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond,
4163 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004164 DataType::Type type,
Alexey Frunze299a9392015-12-08 16:08:02 -08004165 LocationSummary* locations,
4166 Mips64Label* label) {
4167 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
4168 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004169 if (type == DataType::Type::kFloat32) {
Alexey Frunze299a9392015-12-08 16:08:02 -08004170 switch (cond) {
4171 case kCondEQ:
4172 __ CmpEqS(FTMP, lhs, rhs);
4173 __ Bc1nez(FTMP, label);
4174 break;
4175 case kCondNE:
4176 __ CmpEqS(FTMP, lhs, rhs);
4177 __ Bc1eqz(FTMP, label);
4178 break;
4179 case kCondLT:
4180 if (gt_bias) {
4181 __ CmpLtS(FTMP, lhs, rhs);
4182 } else {
4183 __ CmpUltS(FTMP, lhs, rhs);
4184 }
4185 __ Bc1nez(FTMP, label);
4186 break;
4187 case kCondLE:
4188 if (gt_bias) {
4189 __ CmpLeS(FTMP, lhs, rhs);
4190 } else {
4191 __ CmpUleS(FTMP, lhs, rhs);
4192 }
4193 __ Bc1nez(FTMP, label);
4194 break;
4195 case kCondGT:
4196 if (gt_bias) {
4197 __ CmpUltS(FTMP, rhs, lhs);
4198 } else {
4199 __ CmpLtS(FTMP, rhs, lhs);
4200 }
4201 __ Bc1nez(FTMP, label);
4202 break;
4203 case kCondGE:
4204 if (gt_bias) {
4205 __ CmpUleS(FTMP, rhs, lhs);
4206 } else {
4207 __ CmpLeS(FTMP, rhs, lhs);
4208 }
4209 __ Bc1nez(FTMP, label);
4210 break;
4211 default:
4212 LOG(FATAL) << "Unexpected non-floating-point condition";
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004213 UNREACHABLE();
Alexey Frunze299a9392015-12-08 16:08:02 -08004214 }
4215 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004216 DCHECK_EQ(type, DataType::Type::kFloat64);
Alexey Frunze299a9392015-12-08 16:08:02 -08004217 switch (cond) {
4218 case kCondEQ:
4219 __ CmpEqD(FTMP, lhs, rhs);
4220 __ Bc1nez(FTMP, label);
4221 break;
4222 case kCondNE:
4223 __ CmpEqD(FTMP, lhs, rhs);
4224 __ Bc1eqz(FTMP, label);
4225 break;
4226 case kCondLT:
4227 if (gt_bias) {
4228 __ CmpLtD(FTMP, lhs, rhs);
4229 } else {
4230 __ CmpUltD(FTMP, lhs, rhs);
4231 }
4232 __ Bc1nez(FTMP, label);
4233 break;
4234 case kCondLE:
4235 if (gt_bias) {
4236 __ CmpLeD(FTMP, lhs, rhs);
4237 } else {
4238 __ CmpUleD(FTMP, lhs, rhs);
4239 }
4240 __ Bc1nez(FTMP, label);
4241 break;
4242 case kCondGT:
4243 if (gt_bias) {
4244 __ CmpUltD(FTMP, rhs, lhs);
4245 } else {
4246 __ CmpLtD(FTMP, rhs, lhs);
4247 }
4248 __ Bc1nez(FTMP, label);
4249 break;
4250 case kCondGE:
4251 if (gt_bias) {
4252 __ CmpUleD(FTMP, rhs, lhs);
4253 } else {
4254 __ CmpLeD(FTMP, rhs, lhs);
4255 }
4256 __ Bc1nez(FTMP, label);
4257 break;
4258 default:
4259 LOG(FATAL) << "Unexpected non-floating-point condition";
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004260 UNREACHABLE();
Alexey Frunze299a9392015-12-08 16:08:02 -08004261 }
4262 }
4263}
4264
Alexey Frunze4dda3372015-06-01 18:31:49 -07004265void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00004266 size_t condition_input_index,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004267 Mips64Label* true_target,
4268 Mips64Label* false_target) {
David Brazdil0debae72015-11-12 18:37:00 +00004269 HInstruction* cond = instruction->InputAt(condition_input_index);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004270
David Brazdil0debae72015-11-12 18:37:00 +00004271 if (true_target == nullptr && false_target == nullptr) {
4272 // Nothing to do. The code always falls through.
4273 return;
4274 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00004275 // Constant condition, statically compared against "true" (integer value 1).
4276 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00004277 if (true_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004278 __ Bc(true_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004279 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004280 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00004281 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00004282 if (false_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004283 __ Bc(false_target);
David Brazdil0debae72015-11-12 18:37:00 +00004284 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004285 }
David Brazdil0debae72015-11-12 18:37:00 +00004286 return;
4287 }
4288
4289 // The following code generates these patterns:
4290 // (1) true_target == nullptr && false_target != nullptr
4291 // - opposite condition true => branch to false_target
4292 // (2) true_target != nullptr && false_target == nullptr
4293 // - condition true => branch to true_target
4294 // (3) true_target != nullptr && false_target != nullptr
4295 // - condition true => branch to true_target
4296 // - branch to false_target
4297 if (IsBooleanValueOrMaterializedCondition(cond)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07004298 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00004299 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004300 DCHECK(cond_val.IsRegister());
David Brazdil0debae72015-11-12 18:37:00 +00004301 if (true_target == nullptr) {
4302 __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target);
4303 } else {
4304 __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target);
4305 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004306 } else {
4307 // The condition instruction has not been materialized, use its inputs as
4308 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00004309 HCondition* condition = cond->AsCondition();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004310 DataType::Type type = condition->InputAt(0)->GetType();
Alexey Frunze299a9392015-12-08 16:08:02 -08004311 LocationSummary* locations = cond->GetLocations();
4312 IfCondition if_cond = condition->GetCondition();
4313 Mips64Label* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00004314
David Brazdil0debae72015-11-12 18:37:00 +00004315 if (true_target == nullptr) {
4316 if_cond = condition->GetOppositeCondition();
Alexey Frunze299a9392015-12-08 16:08:02 -08004317 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00004318 }
4319
Alexey Frunze299a9392015-12-08 16:08:02 -08004320 switch (type) {
4321 default:
4322 GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target);
4323 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004324 case DataType::Type::kInt64:
Alexey Frunze299a9392015-12-08 16:08:02 -08004325 GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target);
4326 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004327 case DataType::Type::kFloat32:
4328 case DataType::Type::kFloat64:
Alexey Frunze299a9392015-12-08 16:08:02 -08004329 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
4330 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07004331 }
4332 }
David Brazdil0debae72015-11-12 18:37:00 +00004333
4334 // If neither branch falls through (case 3), the conditional branch to `true_target`
4335 // was already emitted (case 2) and we need to emit a jump to `false_target`.
4336 if (true_target != nullptr && false_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004337 __ Bc(false_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004338 }
4339}
4340
4341void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004342 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00004343 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07004344 locations->SetInAt(0, Location::RequiresRegister());
4345 }
4346}
4347
4348void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00004349 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
4350 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004351 Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
David Brazdil0debae72015-11-12 18:37:00 +00004352 nullptr : codegen_->GetLabelOf(true_successor);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004353 Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
David Brazdil0debae72015-11-12 18:37:00 +00004354 nullptr : codegen_->GetLabelOf(false_successor);
4355 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004356}
4357
4358void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004359 LocationSummary* locations = new (GetGraph()->GetAllocator())
Alexey Frunze4dda3372015-06-01 18:31:49 -07004360 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01004361 InvokeRuntimeCallingConvention calling_convention;
4362 RegisterSet caller_saves = RegisterSet::Empty();
4363 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4364 locations->SetCustomSlowPathCallerSaves(caller_saves);
David Brazdil0debae72015-11-12 18:37:00 +00004365 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07004366 locations->SetInAt(0, Location::RequiresRegister());
4367 }
4368}
4369
4370void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08004371 SlowPathCodeMIPS64* slow_path =
4372 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00004373 GenerateTestAndBranch(deoptimize,
4374 /* condition_input_index */ 0,
4375 slow_path->GetEntryLabel(),
4376 /* false_target */ nullptr);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004377}
4378
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004379// This function returns true if a conditional move can be generated for HSelect.
4380// Otherwise it returns false and HSelect must be implemented in terms of conditonal
4381// branches and regular moves.
4382//
4383// If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect.
4384//
4385// While determining feasibility of a conditional move and setting inputs/outputs
4386// are two distinct tasks, this function does both because they share quite a bit
4387// of common logic.
4388static bool CanMoveConditionally(HSelect* select, LocationSummary* locations_to_set) {
4389 bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition());
4390 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
4391 HCondition* condition = cond->AsCondition();
4392
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004393 DataType::Type cond_type =
4394 materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType();
4395 DataType::Type dst_type = select->GetType();
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004396
4397 HConstant* cst_true_value = select->GetTrueValue()->AsConstant();
4398 HConstant* cst_false_value = select->GetFalseValue()->AsConstant();
4399 bool is_true_value_zero_constant =
4400 (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern());
4401 bool is_false_value_zero_constant =
4402 (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern());
4403
4404 bool can_move_conditionally = false;
4405 bool use_const_for_false_in = false;
4406 bool use_const_for_true_in = false;
4407
4408 if (!cond->IsConstant()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004409 if (!DataType::IsFloatingPointType(cond_type)) {
4410 if (!DataType::IsFloatingPointType(dst_type)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004411 // Moving int/long on int/long condition.
4412 if (is_true_value_zero_constant) {
4413 // seleqz out_reg, false_reg, cond_reg
4414 can_move_conditionally = true;
4415 use_const_for_true_in = true;
4416 } else if (is_false_value_zero_constant) {
4417 // selnez out_reg, true_reg, cond_reg
4418 can_move_conditionally = true;
4419 use_const_for_false_in = true;
4420 } else if (materialized) {
4421 // Not materializing unmaterialized int conditions
4422 // to keep the instruction count low.
4423 // selnez AT, true_reg, cond_reg
4424 // seleqz TMP, false_reg, cond_reg
4425 // or out_reg, AT, TMP
4426 can_move_conditionally = true;
4427 }
4428 } else {
4429 // Moving float/double on int/long condition.
4430 if (materialized) {
4431 // Not materializing unmaterialized int conditions
4432 // to keep the instruction count low.
4433 can_move_conditionally = true;
4434 if (is_true_value_zero_constant) {
4435 // sltu TMP, ZERO, cond_reg
4436 // mtc1 TMP, temp_cond_reg
4437 // seleqz.fmt out_reg, false_reg, temp_cond_reg
4438 use_const_for_true_in = true;
4439 } else if (is_false_value_zero_constant) {
4440 // sltu TMP, ZERO, cond_reg
4441 // mtc1 TMP, temp_cond_reg
4442 // selnez.fmt out_reg, true_reg, temp_cond_reg
4443 use_const_for_false_in = true;
4444 } else {
4445 // sltu TMP, ZERO, cond_reg
4446 // mtc1 TMP, temp_cond_reg
4447 // sel.fmt temp_cond_reg, false_reg, true_reg
4448 // mov.fmt out_reg, temp_cond_reg
4449 }
4450 }
4451 }
4452 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004453 if (!DataType::IsFloatingPointType(dst_type)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004454 // Moving int/long on float/double condition.
4455 can_move_conditionally = true;
4456 if (is_true_value_zero_constant) {
4457 // mfc1 TMP, temp_cond_reg
4458 // seleqz out_reg, false_reg, TMP
4459 use_const_for_true_in = true;
4460 } else if (is_false_value_zero_constant) {
4461 // mfc1 TMP, temp_cond_reg
4462 // selnez out_reg, true_reg, TMP
4463 use_const_for_false_in = true;
4464 } else {
4465 // mfc1 TMP, temp_cond_reg
4466 // selnez AT, true_reg, TMP
4467 // seleqz TMP, false_reg, TMP
4468 // or out_reg, AT, TMP
4469 }
4470 } else {
4471 // Moving float/double on float/double condition.
4472 can_move_conditionally = true;
4473 if (is_true_value_zero_constant) {
4474 // seleqz.fmt out_reg, false_reg, temp_cond_reg
4475 use_const_for_true_in = true;
4476 } else if (is_false_value_zero_constant) {
4477 // selnez.fmt out_reg, true_reg, temp_cond_reg
4478 use_const_for_false_in = true;
4479 } else {
4480 // sel.fmt temp_cond_reg, false_reg, true_reg
4481 // mov.fmt out_reg, temp_cond_reg
4482 }
4483 }
4484 }
4485 }
4486
4487 if (can_move_conditionally) {
4488 DCHECK(!use_const_for_false_in || !use_const_for_true_in);
4489 } else {
4490 DCHECK(!use_const_for_false_in);
4491 DCHECK(!use_const_for_true_in);
4492 }
4493
4494 if (locations_to_set != nullptr) {
4495 if (use_const_for_false_in) {
4496 locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value));
4497 } else {
4498 locations_to_set->SetInAt(0,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004499 DataType::IsFloatingPointType(dst_type)
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004500 ? Location::RequiresFpuRegister()
4501 : Location::RequiresRegister());
4502 }
4503 if (use_const_for_true_in) {
4504 locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value));
4505 } else {
4506 locations_to_set->SetInAt(1,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004507 DataType::IsFloatingPointType(dst_type)
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004508 ? Location::RequiresFpuRegister()
4509 : Location::RequiresRegister());
4510 }
4511 if (materialized) {
4512 locations_to_set->SetInAt(2, Location::RequiresRegister());
4513 }
4514
4515 if (can_move_conditionally) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004516 locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type)
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004517 ? Location::RequiresFpuRegister()
4518 : Location::RequiresRegister());
4519 } else {
4520 locations_to_set->SetOut(Location::SameAsFirstInput());
4521 }
4522 }
4523
4524 return can_move_conditionally;
4525}
4526
4527
4528void InstructionCodeGeneratorMIPS64::GenConditionalMove(HSelect* select) {
4529 LocationSummary* locations = select->GetLocations();
4530 Location dst = locations->Out();
4531 Location false_src = locations->InAt(0);
4532 Location true_src = locations->InAt(1);
4533 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
4534 GpuRegister cond_reg = TMP;
4535 FpuRegister fcond_reg = FTMP;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004536 DataType::Type cond_type = DataType::Type::kInt32;
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004537 bool cond_inverted = false;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004538 DataType::Type dst_type = select->GetType();
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004539
4540 if (IsBooleanValueOrMaterializedCondition(cond)) {
4541 cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<GpuRegister>();
4542 } else {
4543 HCondition* condition = cond->AsCondition();
4544 LocationSummary* cond_locations = cond->GetLocations();
4545 IfCondition if_cond = condition->GetCondition();
4546 cond_type = condition->InputAt(0)->GetType();
4547 switch (cond_type) {
4548 default:
4549 cond_inverted = MaterializeIntLongCompare(if_cond,
4550 /* is64bit */ false,
4551 cond_locations,
4552 cond_reg);
4553 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004554 case DataType::Type::kInt64:
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004555 cond_inverted = MaterializeIntLongCompare(if_cond,
4556 /* is64bit */ true,
4557 cond_locations,
4558 cond_reg);
4559 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004560 case DataType::Type::kFloat32:
4561 case DataType::Type::kFloat64:
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004562 cond_inverted = MaterializeFpCompare(if_cond,
4563 condition->IsGtBias(),
4564 cond_type,
4565 cond_locations,
4566 fcond_reg);
4567 break;
4568 }
4569 }
4570
4571 if (true_src.IsConstant()) {
4572 DCHECK(true_src.GetConstant()->IsZeroBitPattern());
4573 }
4574 if (false_src.IsConstant()) {
4575 DCHECK(false_src.GetConstant()->IsZeroBitPattern());
4576 }
4577
4578 switch (dst_type) {
4579 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004580 if (DataType::IsFloatingPointType(cond_type)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004581 __ Mfc1(cond_reg, fcond_reg);
4582 }
4583 if (true_src.IsConstant()) {
4584 if (cond_inverted) {
4585 __ Selnez(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg);
4586 } else {
4587 __ Seleqz(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg);
4588 }
4589 } else if (false_src.IsConstant()) {
4590 if (cond_inverted) {
4591 __ Seleqz(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg);
4592 } else {
4593 __ Selnez(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg);
4594 }
4595 } else {
4596 DCHECK_NE(cond_reg, AT);
4597 if (cond_inverted) {
4598 __ Seleqz(AT, true_src.AsRegister<GpuRegister>(), cond_reg);
4599 __ Selnez(TMP, false_src.AsRegister<GpuRegister>(), cond_reg);
4600 } else {
4601 __ Selnez(AT, true_src.AsRegister<GpuRegister>(), cond_reg);
4602 __ Seleqz(TMP, false_src.AsRegister<GpuRegister>(), cond_reg);
4603 }
4604 __ Or(dst.AsRegister<GpuRegister>(), AT, TMP);
4605 }
4606 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004607 case DataType::Type::kFloat32: {
4608 if (!DataType::IsFloatingPointType(cond_type)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004609 // sel*.fmt tests bit 0 of the condition register, account for that.
4610 __ Sltu(TMP, ZERO, cond_reg);
4611 __ Mtc1(TMP, fcond_reg);
4612 }
4613 FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>();
4614 if (true_src.IsConstant()) {
4615 FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>();
4616 if (cond_inverted) {
4617 __ SelnezS(dst_reg, src_reg, fcond_reg);
4618 } else {
4619 __ SeleqzS(dst_reg, src_reg, fcond_reg);
4620 }
4621 } else if (false_src.IsConstant()) {
4622 FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>();
4623 if (cond_inverted) {
4624 __ SeleqzS(dst_reg, src_reg, fcond_reg);
4625 } else {
4626 __ SelnezS(dst_reg, src_reg, fcond_reg);
4627 }
4628 } else {
4629 if (cond_inverted) {
4630 __ SelS(fcond_reg,
4631 true_src.AsFpuRegister<FpuRegister>(),
4632 false_src.AsFpuRegister<FpuRegister>());
4633 } else {
4634 __ SelS(fcond_reg,
4635 false_src.AsFpuRegister<FpuRegister>(),
4636 true_src.AsFpuRegister<FpuRegister>());
4637 }
4638 __ MovS(dst_reg, fcond_reg);
4639 }
4640 break;
4641 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004642 case DataType::Type::kFloat64: {
4643 if (!DataType::IsFloatingPointType(cond_type)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004644 // sel*.fmt tests bit 0 of the condition register, account for that.
4645 __ Sltu(TMP, ZERO, cond_reg);
4646 __ Mtc1(TMP, fcond_reg);
4647 }
4648 FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>();
4649 if (true_src.IsConstant()) {
4650 FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>();
4651 if (cond_inverted) {
4652 __ SelnezD(dst_reg, src_reg, fcond_reg);
4653 } else {
4654 __ SeleqzD(dst_reg, src_reg, fcond_reg);
4655 }
4656 } else if (false_src.IsConstant()) {
4657 FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>();
4658 if (cond_inverted) {
4659 __ SeleqzD(dst_reg, src_reg, fcond_reg);
4660 } else {
4661 __ SelnezD(dst_reg, src_reg, fcond_reg);
4662 }
4663 } else {
4664 if (cond_inverted) {
4665 __ SelD(fcond_reg,
4666 true_src.AsFpuRegister<FpuRegister>(),
4667 false_src.AsFpuRegister<FpuRegister>());
4668 } else {
4669 __ SelD(fcond_reg,
4670 false_src.AsFpuRegister<FpuRegister>(),
4671 true_src.AsFpuRegister<FpuRegister>());
4672 }
4673 __ MovD(dst_reg, fcond_reg);
4674 }
4675 break;
4676 }
4677 }
4678}
4679
Goran Jakovljevicc6418422016-12-05 16:31:55 +01004680void LocationsBuilderMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004681 LocationSummary* locations = new (GetGraph()->GetAllocator())
Goran Jakovljevicc6418422016-12-05 16:31:55 +01004682 LocationSummary(flag, LocationSummary::kNoCall);
4683 locations->SetOut(Location::RequiresRegister());
Mingyao Yang063fc772016-08-02 11:02:54 -07004684}
4685
Goran Jakovljevicc6418422016-12-05 16:31:55 +01004686void InstructionCodeGeneratorMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
4687 __ LoadFromOffset(kLoadWord,
4688 flag->GetLocations()->Out().AsRegister<GpuRegister>(),
4689 SP,
4690 codegen_->GetStackOffsetOfShouldDeoptimizeFlag());
Mingyao Yang063fc772016-08-02 11:02:54 -07004691}
4692
David Brazdil74eb1b22015-12-14 11:44:01 +00004693void LocationsBuilderMIPS64::VisitSelect(HSelect* select) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004694 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004695 CanMoveConditionally(select, locations);
David Brazdil74eb1b22015-12-14 11:44:01 +00004696}
4697
4698void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004699 if (CanMoveConditionally(select, /* locations_to_set */ nullptr)) {
4700 GenConditionalMove(select);
4701 } else {
4702 LocationSummary* locations = select->GetLocations();
4703 Mips64Label false_target;
4704 GenerateTestAndBranch(select,
4705 /* condition_input_index */ 2,
4706 /* true_target */ nullptr,
4707 &false_target);
4708 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
4709 __ Bind(&false_target);
4710 }
David Brazdil74eb1b22015-12-14 11:44:01 +00004711}
4712
David Srbecky0cf44932015-12-09 14:09:59 +00004713void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004714 new (GetGraph()->GetAllocator()) LocationSummary(info);
David Srbecky0cf44932015-12-09 14:09:59 +00004715}
4716
David Srbeckyd28f4a02016-03-14 17:14:24 +00004717void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) {
4718 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00004719}
4720
4721void CodeGeneratorMIPS64::GenerateNop() {
4722 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00004723}
4724
Alexey Frunze4dda3372015-06-01 18:31:49 -07004725void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction,
Alexey Frunze15958152017-02-09 19:08:30 -08004726 const FieldInfo& field_info) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004727 DataType::Type field_type = field_info.GetFieldType();
Alexey Frunze15958152017-02-09 19:08:30 -08004728 bool object_field_get_with_read_barrier =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004729 kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference);
Vladimir Markoca6fff82017-10-03 14:49:14 +01004730 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
Alexey Frunze15958152017-02-09 19:08:30 -08004731 instruction,
4732 object_field_get_with_read_barrier
4733 ? LocationSummary::kCallOnSlowPath
4734 : LocationSummary::kNoCall);
Alexey Frunzec61c0762017-04-10 13:54:23 -07004735 if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
4736 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
4737 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004738 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004739 if (DataType::IsFloatingPointType(instruction->GetType())) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07004740 locations->SetOut(Location::RequiresFpuRegister());
4741 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08004742 // The output overlaps in the case of an object field get with
4743 // read barriers enabled: we do not want the move to overwrite the
4744 // object's location, as we need it to emit the read barrier.
4745 locations->SetOut(Location::RequiresRegister(),
4746 object_field_get_with_read_barrier
4747 ? Location::kOutputOverlap
4748 : Location::kNoOutputOverlap);
4749 }
4750 if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
4751 // We need a temporary register for the read barrier marking slow
4752 // path in CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier.
Alexey Frunze4147fcc2017-06-17 19:57:27 -07004753 if (!kBakerReadBarrierThunksEnableForFields) {
4754 locations->AddTemp(Location::RequiresRegister());
4755 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004756 }
4757}
4758
4759void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction,
4760 const FieldInfo& field_info) {
Vladimir Marko61b92282017-10-11 13:23:17 +01004761 DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType()));
4762 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07004763 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08004764 Location obj_loc = locations->InAt(0);
4765 GpuRegister obj = obj_loc.AsRegister<GpuRegister>();
4766 Location dst_loc = locations->Out();
Alexey Frunze4dda3372015-06-01 18:31:49 -07004767 LoadOperandType load_type = kLoadUnsignedByte;
Alexey Frunze15958152017-02-09 19:08:30 -08004768 bool is_volatile = field_info.IsVolatile();
Alexey Frunzec061de12017-02-14 13:27:23 -08004769 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Tijana Jakovljevic57433862017-01-17 16:59:03 +01004770 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
4771
Alexey Frunze4dda3372015-06-01 18:31:49 -07004772 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004773 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01004774 case DataType::Type::kUint8:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004775 load_type = kLoadUnsignedByte;
4776 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004777 case DataType::Type::kInt8:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004778 load_type = kLoadSignedByte;
4779 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004780 case DataType::Type::kUint16:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004781 load_type = kLoadUnsignedHalfword;
4782 break;
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01004783 case DataType::Type::kInt16:
4784 load_type = kLoadSignedHalfword;
4785 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004786 case DataType::Type::kInt32:
4787 case DataType::Type::kFloat32:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004788 load_type = kLoadWord;
4789 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004790 case DataType::Type::kInt64:
4791 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004792 load_type = kLoadDoubleword;
4793 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004794 case DataType::Type::kReference:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004795 load_type = kLoadUnsignedWord;
4796 break;
Aart Bik66c158e2018-01-31 12:55:04 -08004797 case DataType::Type::kUint32:
4798 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004799 case DataType::Type::kVoid:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004800 LOG(FATAL) << "Unreachable type " << type;
4801 UNREACHABLE();
4802 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004803 if (!DataType::IsFloatingPointType(type)) {
Alexey Frunze15958152017-02-09 19:08:30 -08004804 DCHECK(dst_loc.IsRegister());
4805 GpuRegister dst = dst_loc.AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004806 if (type == DataType::Type::kReference) {
Alexey Frunze15958152017-02-09 19:08:30 -08004807 // /* HeapReference<Object> */ dst = *(obj + offset)
4808 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07004809 Location temp_loc =
4810 kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0);
Alexey Frunze15958152017-02-09 19:08:30 -08004811 // Note that a potential implicit null check is handled in this
4812 // CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier call.
4813 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4814 dst_loc,
4815 obj,
4816 offset,
4817 temp_loc,
4818 /* needs_null_check */ true);
4819 if (is_volatile) {
4820 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4821 }
4822 } else {
4823 __ LoadFromOffset(kLoadUnsignedWord, dst, obj, offset, null_checker);
4824 if (is_volatile) {
4825 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4826 }
4827 // If read barriers are enabled, emit read barriers other than
4828 // Baker's using a slow path (and also unpoison the loaded
4829 // reference, if heap poisoning is enabled).
4830 codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset);
4831 }
4832 } else {
4833 __ LoadFromOffset(load_type, dst, obj, offset, null_checker);
4834 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004835 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08004836 DCHECK(dst_loc.IsFpuRegister());
4837 FpuRegister dst = dst_loc.AsFpuRegister<FpuRegister>();
Tijana Jakovljevic57433862017-01-17 16:59:03 +01004838 __ LoadFpuFromOffset(load_type, dst, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004839 }
Alexey Frunzec061de12017-02-14 13:27:23 -08004840
Alexey Frunze15958152017-02-09 19:08:30 -08004841 // Memory barriers, in the case of references, are handled in the
4842 // previous switch statement.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004843 if (is_volatile && (type != DataType::Type::kReference)) {
Alexey Frunze15958152017-02-09 19:08:30 -08004844 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
Alexey Frunzec061de12017-02-14 13:27:23 -08004845 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004846}
4847
4848void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction,
4849 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
4850 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01004851 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004852 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004853 if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004854 locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07004855 } else {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004856 locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07004857 }
4858}
4859
4860void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction,
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01004861 const FieldInfo& field_info,
4862 bool value_can_be_null) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004863 DataType::Type type = field_info.GetFieldType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07004864 LocationSummary* locations = instruction->GetLocations();
4865 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004866 Location value_location = locations->InAt(1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004867 StoreOperandType store_type = kStoreByte;
Alexey Frunze15958152017-02-09 19:08:30 -08004868 bool is_volatile = field_info.IsVolatile();
Alexey Frunzec061de12017-02-14 13:27:23 -08004869 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
4870 bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1));
Tijana Jakovljevic57433862017-01-17 16:59:03 +01004871 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
4872
Alexey Frunze4dda3372015-06-01 18:31:49 -07004873 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004874 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01004875 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004876 case DataType::Type::kInt8:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004877 store_type = kStoreByte;
4878 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004879 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01004880 case DataType::Type::kInt16:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004881 store_type = kStoreHalfword;
4882 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004883 case DataType::Type::kInt32:
4884 case DataType::Type::kFloat32:
4885 case DataType::Type::kReference:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004886 store_type = kStoreWord;
4887 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004888 case DataType::Type::kInt64:
4889 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004890 store_type = kStoreDoubleword;
4891 break;
Aart Bik66c158e2018-01-31 12:55:04 -08004892 case DataType::Type::kUint32:
4893 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004894 case DataType::Type::kVoid:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004895 LOG(FATAL) << "Unreachable type " << type;
4896 UNREACHABLE();
4897 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004898
Alexey Frunze15958152017-02-09 19:08:30 -08004899 if (is_volatile) {
4900 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
4901 }
4902
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004903 if (value_location.IsConstant()) {
4904 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
4905 __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker);
4906 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004907 if (!DataType::IsFloatingPointType(type)) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004908 DCHECK(value_location.IsRegister());
4909 GpuRegister src = value_location.AsRegister<GpuRegister>();
4910 if (kPoisonHeapReferences && needs_write_barrier) {
4911 // Note that in the case where `value` is a null reference,
4912 // we do not enter this block, as a null reference does not
4913 // need poisoning.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004914 DCHECK_EQ(type, DataType::Type::kReference);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004915 __ PoisonHeapReference(TMP, src);
4916 __ StoreToOffset(store_type, TMP, obj, offset, null_checker);
4917 } else {
4918 __ StoreToOffset(store_type, src, obj, offset, null_checker);
4919 }
4920 } else {
4921 DCHECK(value_location.IsFpuRegister());
4922 FpuRegister src = value_location.AsFpuRegister<FpuRegister>();
4923 __ StoreFpuToOffset(store_type, src, obj, offset, null_checker);
4924 }
4925 }
Alexey Frunze15958152017-02-09 19:08:30 -08004926
Alexey Frunzec061de12017-02-14 13:27:23 -08004927 if (needs_write_barrier) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004928 DCHECK(value_location.IsRegister());
4929 GpuRegister src = value_location.AsRegister<GpuRegister>();
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01004930 codegen_->MarkGCCard(obj, src, value_can_be_null);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004931 }
Alexey Frunze15958152017-02-09 19:08:30 -08004932
4933 if (is_volatile) {
4934 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
4935 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004936}
4937
4938void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4939 HandleFieldGet(instruction, instruction->GetFieldInfo());
4940}
4941
4942void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4943 HandleFieldGet(instruction, instruction->GetFieldInfo());
4944}
4945
4946void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
4947 HandleFieldSet(instruction, instruction->GetFieldInfo());
4948}
4949
4950void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01004951 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Alexey Frunze4dda3372015-06-01 18:31:49 -07004952}
4953
Alexey Frunze15958152017-02-09 19:08:30 -08004954void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadOneRegister(
4955 HInstruction* instruction,
4956 Location out,
4957 uint32_t offset,
4958 Location maybe_temp,
4959 ReadBarrierOption read_barrier_option) {
4960 GpuRegister out_reg = out.AsRegister<GpuRegister>();
4961 if (read_barrier_option == kWithReadBarrier) {
4962 CHECK(kEmitCompilerReadBarrier);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07004963 if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) {
4964 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
4965 }
Alexey Frunze15958152017-02-09 19:08:30 -08004966 if (kUseBakerReadBarrier) {
4967 // Load with fast path based Baker's read barrier.
4968 // /* HeapReference<Object> */ out = *(out + offset)
4969 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4970 out,
4971 out_reg,
4972 offset,
4973 maybe_temp,
4974 /* needs_null_check */ false);
4975 } else {
4976 // Load with slow path based read barrier.
4977 // Save the value of `out` into `maybe_temp` before overwriting it
4978 // in the following move operation, as we will need it for the
4979 // read barrier below.
4980 __ Move(maybe_temp.AsRegister<GpuRegister>(), out_reg);
4981 // /* HeapReference<Object> */ out = *(out + offset)
4982 __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset);
4983 codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset);
4984 }
4985 } else {
4986 // Plain load with no read barrier.
4987 // /* HeapReference<Object> */ out = *(out + offset)
4988 __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset);
4989 __ MaybeUnpoisonHeapReference(out_reg);
4990 }
4991}
4992
4993void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadTwoRegisters(
4994 HInstruction* instruction,
4995 Location out,
4996 Location obj,
4997 uint32_t offset,
4998 Location maybe_temp,
4999 ReadBarrierOption read_barrier_option) {
5000 GpuRegister out_reg = out.AsRegister<GpuRegister>();
5001 GpuRegister obj_reg = obj.AsRegister<GpuRegister>();
5002 if (read_barrier_option == kWithReadBarrier) {
5003 CHECK(kEmitCompilerReadBarrier);
5004 if (kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005005 if (!kBakerReadBarrierThunksEnableForFields) {
5006 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
5007 }
Alexey Frunze15958152017-02-09 19:08:30 -08005008 // Load with fast path based Baker's read barrier.
5009 // /* HeapReference<Object> */ out = *(obj + offset)
5010 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
5011 out,
5012 obj_reg,
5013 offset,
5014 maybe_temp,
5015 /* needs_null_check */ false);
5016 } else {
5017 // Load with slow path based read barrier.
5018 // /* HeapReference<Object> */ out = *(obj + offset)
5019 __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset);
5020 codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset);
5021 }
5022 } else {
5023 // Plain load with no read barrier.
5024 // /* HeapReference<Object> */ out = *(obj + offset)
5025 __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset);
5026 __ MaybeUnpoisonHeapReference(out_reg);
5027 }
5028}
5029
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005030static inline int GetBakerMarkThunkNumber(GpuRegister reg) {
5031 static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 20, "Expecting equal");
5032 if (reg >= V0 && reg <= T2) { // 13 consequtive regs.
5033 return reg - V0;
5034 } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs.
5035 return 13 + (reg - S2);
5036 } else if (reg == S8) { // One more.
5037 return 19;
5038 }
5039 LOG(FATAL) << "Unexpected register " << reg;
5040 UNREACHABLE();
5041}
5042
5043static inline int GetBakerMarkFieldArrayThunkDisplacement(GpuRegister reg, bool short_offset) {
5044 int num = GetBakerMarkThunkNumber(reg) +
5045 (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0);
5046 return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE;
5047}
5048
5049static inline int GetBakerMarkGcRootThunkDisplacement(GpuRegister reg) {
5050 return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE +
5051 BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET;
5052}
5053
5054void InstructionCodeGeneratorMIPS64::GenerateGcRootFieldLoad(HInstruction* instruction,
5055 Location root,
5056 GpuRegister obj,
5057 uint32_t offset,
5058 ReadBarrierOption read_barrier_option,
5059 Mips64Label* label_low) {
5060 if (label_low != nullptr) {
5061 DCHECK_EQ(offset, 0x5678u);
5062 }
Alexey Frunzef63f5692016-12-13 17:43:11 -08005063 GpuRegister root_reg = root.AsRegister<GpuRegister>();
Alexey Frunze15958152017-02-09 19:08:30 -08005064 if (read_barrier_option == kWithReadBarrier) {
5065 DCHECK(kEmitCompilerReadBarrier);
5066 if (kUseBakerReadBarrier) {
5067 // Fast path implementation of art::ReadBarrier::BarrierForRoot when
5068 // Baker's read barrier are used:
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005069 if (kBakerReadBarrierThunksEnableForGcRoots) {
5070 // Note that we do not actually check the value of `GetIsGcMarking()`
5071 // to decide whether to mark the loaded GC root or not. Instead, we
5072 // load into `temp` (T9) the read barrier mark introspection entrypoint.
5073 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
5074 // vice versa.
5075 //
5076 // We use thunks for the slow path. That thunk checks the reference
5077 // and jumps to the entrypoint if needed.
5078 //
5079 // temp = Thread::Current()->pReadBarrierMarkReg00
5080 // // AKA &art_quick_read_barrier_mark_introspection.
5081 // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load.
5082 // if (temp != nullptr) {
5083 // temp = &gc_root_thunk<root_reg>
5084 // root = temp(root)
5085 // }
Alexey Frunze15958152017-02-09 19:08:30 -08005086
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005087 const int32_t entry_point_offset =
5088 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0);
5089 const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg);
5090 int16_t offset_low = Low16Bits(offset);
5091 int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign
5092 // extension in lwu.
5093 bool short_offset = IsInt<16>(static_cast<int32_t>(offset));
5094 GpuRegister base = short_offset ? obj : TMP;
5095 // Loading the entrypoint does not require a load acquire since it is only changed when
5096 // threads are suspended or running a checkpoint.
5097 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
5098 if (!short_offset) {
5099 DCHECK(!label_low);
5100 __ Daui(base, obj, offset_high);
5101 }
Alexey Frunze0cab6562017-07-25 15:19:36 -07005102 Mips64Label skip_call;
5103 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005104 if (label_low != nullptr) {
5105 DCHECK(short_offset);
5106 __ Bind(label_low);
5107 }
5108 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
5109 __ LoadFromOffset(kLoadUnsignedWord, root_reg, base, offset_low); // Single instruction
5110 // in delay slot.
5111 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07005112 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005113 } else {
5114 // Note that we do not actually check the value of `GetIsGcMarking()`
5115 // to decide whether to mark the loaded GC root or not. Instead, we
5116 // load into `temp` (T9) the read barrier mark entry point corresponding
5117 // to register `root`. If `temp` is null, it means that `GetIsGcMarking()`
5118 // is false, and vice versa.
5119 //
5120 // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load.
5121 // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg()
5122 // if (temp != null) {
5123 // root = temp(root)
5124 // }
Alexey Frunze15958152017-02-09 19:08:30 -08005125
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005126 if (label_low != nullptr) {
5127 __ Bind(label_low);
5128 }
5129 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
5130 __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset);
5131 static_assert(
5132 sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>),
5133 "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> "
5134 "have different sizes.");
5135 static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t),
5136 "art::mirror::CompressedReference<mirror::Object> and int32_t "
5137 "have different sizes.");
Alexey Frunze15958152017-02-09 19:08:30 -08005138
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005139 // Slow path marking the GC root `root`.
5140 Location temp = Location::RegisterLocation(T9);
5141 SlowPathCodeMIPS64* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01005142 new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64(
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005143 instruction,
5144 root,
5145 /*entrypoint*/ temp);
5146 codegen_->AddSlowPath(slow_path);
5147
5148 const int32_t entry_point_offset =
5149 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(root.reg() - 1);
5150 // Loading the entrypoint does not require a load acquire since it is only changed when
5151 // threads are suspended or running a checkpoint.
5152 __ LoadFromOffset(kLoadDoubleword, temp.AsRegister<GpuRegister>(), TR, entry_point_offset);
5153 __ Bnezc(temp.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
5154 __ Bind(slow_path->GetExitLabel());
5155 }
Alexey Frunze15958152017-02-09 19:08:30 -08005156 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005157 if (label_low != nullptr) {
5158 __ Bind(label_low);
5159 }
Alexey Frunze15958152017-02-09 19:08:30 -08005160 // GC root loaded through a slow path for read barriers other
5161 // than Baker's.
5162 // /* GcRoot<mirror::Object>* */ root = obj + offset
5163 __ Daddiu64(root_reg, obj, static_cast<int32_t>(offset));
5164 // /* mirror::Object* */ root = root->Read()
5165 codegen_->GenerateReadBarrierForRootSlow(instruction, root, root);
5166 }
Alexey Frunzef63f5692016-12-13 17:43:11 -08005167 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005168 if (label_low != nullptr) {
5169 __ Bind(label_low);
5170 }
Alexey Frunzef63f5692016-12-13 17:43:11 -08005171 // Plain GC root load with no read barrier.
5172 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
5173 __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset);
5174 // Note that GC roots are not affected by heap poisoning, thus we
5175 // do not have to unpoison `root_reg` here.
5176 }
5177}
5178
Alexey Frunze15958152017-02-09 19:08:30 -08005179void CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
5180 Location ref,
5181 GpuRegister obj,
5182 uint32_t offset,
5183 Location temp,
5184 bool needs_null_check) {
5185 DCHECK(kEmitCompilerReadBarrier);
5186 DCHECK(kUseBakerReadBarrier);
5187
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005188 if (kBakerReadBarrierThunksEnableForFields) {
5189 // Note that we do not actually check the value of `GetIsGcMarking()`
5190 // to decide whether to mark the loaded reference or not. Instead, we
5191 // load into `temp` (T9) the read barrier mark introspection entrypoint.
5192 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
5193 // vice versa.
5194 //
5195 // We use thunks for the slow path. That thunk checks the reference
5196 // and jumps to the entrypoint if needed. If the holder is not gray,
5197 // it issues a load-load memory barrier and returns to the original
5198 // reference load.
5199 //
5200 // temp = Thread::Current()->pReadBarrierMarkReg00
5201 // // AKA &art_quick_read_barrier_mark_introspection.
5202 // if (temp != nullptr) {
5203 // temp = &field_array_thunk<holder_reg>
5204 // temp()
5205 // }
5206 // not_gray_return_address:
5207 // // If the offset is too large to fit into the lw instruction, we
5208 // // use an adjusted base register (TMP) here. This register
5209 // // receives bits 16 ... 31 of the offset before the thunk invocation
5210 // // and the thunk benefits from it.
5211 // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load.
5212 // gray_return_address:
5213
5214 DCHECK(temp.IsInvalid());
5215 bool short_offset = IsInt<16>(static_cast<int32_t>(offset));
5216 const int32_t entry_point_offset =
5217 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0);
5218 // There may have or may have not been a null check if the field offset is smaller than
5219 // the page size.
5220 // There must've been a null check in case it's actually a load from an array.
5221 // We will, however, perform an explicit null check in the thunk as it's easier to
5222 // do it than not.
5223 if (instruction->IsArrayGet()) {
5224 DCHECK(!needs_null_check);
5225 }
5226 const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset);
5227 // Loading the entrypoint does not require a load acquire since it is only changed when
5228 // threads are suspended or running a checkpoint.
5229 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
5230 GpuRegister ref_reg = ref.AsRegister<GpuRegister>();
Alexey Frunze0cab6562017-07-25 15:19:36 -07005231 Mips64Label skip_call;
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005232 if (short_offset) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07005233 __ Beqzc(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005234 __ Nop(); // In forbidden slot.
5235 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07005236 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005237 // /* HeapReference<Object> */ ref = *(obj + offset)
5238 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); // Single instruction.
5239 } else {
5240 int16_t offset_low = Low16Bits(offset);
5241 int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lwu.
Alexey Frunze0cab6562017-07-25 15:19:36 -07005242 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005243 __ Daui(TMP, obj, offset_high); // In delay slot.
5244 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07005245 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005246 // /* HeapReference<Object> */ ref = *(obj + offset)
5247 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset_low); // Single instruction.
5248 }
5249 if (needs_null_check) {
5250 MaybeRecordImplicitNullCheck(instruction);
5251 }
5252 __ MaybeUnpoisonHeapReference(ref_reg);
5253 return;
5254 }
5255
Alexey Frunze15958152017-02-09 19:08:30 -08005256 // /* HeapReference<Object> */ ref = *(obj + offset)
5257 Location no_index = Location::NoLocation();
5258 ScaleFactor no_scale_factor = TIMES_1;
5259 GenerateReferenceLoadWithBakerReadBarrier(instruction,
5260 ref,
5261 obj,
5262 offset,
5263 no_index,
5264 no_scale_factor,
5265 temp,
5266 needs_null_check);
5267}
5268
5269void CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
5270 Location ref,
5271 GpuRegister obj,
5272 uint32_t data_offset,
5273 Location index,
5274 Location temp,
5275 bool needs_null_check) {
5276 DCHECK(kEmitCompilerReadBarrier);
5277 DCHECK(kUseBakerReadBarrier);
5278
5279 static_assert(
5280 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
5281 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005282 ScaleFactor scale_factor = TIMES_4;
5283
5284 if (kBakerReadBarrierThunksEnableForArrays) {
5285 // Note that we do not actually check the value of `GetIsGcMarking()`
5286 // to decide whether to mark the loaded reference or not. Instead, we
5287 // load into `temp` (T9) the read barrier mark introspection entrypoint.
5288 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
5289 // vice versa.
5290 //
5291 // We use thunks for the slow path. That thunk checks the reference
5292 // and jumps to the entrypoint if needed. If the holder is not gray,
5293 // it issues a load-load memory barrier and returns to the original
5294 // reference load.
5295 //
5296 // temp = Thread::Current()->pReadBarrierMarkReg00
5297 // // AKA &art_quick_read_barrier_mark_introspection.
5298 // if (temp != nullptr) {
5299 // temp = &field_array_thunk<holder_reg>
5300 // temp()
5301 // }
5302 // not_gray_return_address:
5303 // // The element address is pre-calculated in the TMP register before the
5304 // // thunk invocation and the thunk benefits from it.
5305 // HeapReference<mirror::Object> reference = data[index]; // Original reference load.
5306 // gray_return_address:
5307
5308 DCHECK(temp.IsInvalid());
5309 DCHECK(index.IsValid());
5310 const int32_t entry_point_offset =
5311 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0);
5312 // We will not do the explicit null check in the thunk as some form of a null check
5313 // must've been done earlier.
5314 DCHECK(!needs_null_check);
5315 const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false);
5316 // Loading the entrypoint does not require a load acquire since it is only changed when
5317 // threads are suspended or running a checkpoint.
5318 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
Alexey Frunze0cab6562017-07-25 15:19:36 -07005319 Mips64Label skip_call;
5320 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005321 GpuRegister ref_reg = ref.AsRegister<GpuRegister>();
5322 GpuRegister index_reg = index.AsRegister<GpuRegister>();
5323 __ Dlsa(TMP, index_reg, obj, scale_factor); // In delay slot.
5324 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07005325 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005326 // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor))
5327 DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset;
5328 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, data_offset); // Single instruction.
5329 __ MaybeUnpoisonHeapReference(ref_reg);
5330 return;
5331 }
5332
Alexey Frunze15958152017-02-09 19:08:30 -08005333 // /* HeapReference<Object> */ ref =
5334 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
Alexey Frunze15958152017-02-09 19:08:30 -08005335 GenerateReferenceLoadWithBakerReadBarrier(instruction,
5336 ref,
5337 obj,
5338 data_offset,
5339 index,
5340 scale_factor,
5341 temp,
5342 needs_null_check);
5343}
5344
5345void CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
5346 Location ref,
5347 GpuRegister obj,
5348 uint32_t offset,
5349 Location index,
5350 ScaleFactor scale_factor,
5351 Location temp,
5352 bool needs_null_check,
5353 bool always_update_field) {
5354 DCHECK(kEmitCompilerReadBarrier);
5355 DCHECK(kUseBakerReadBarrier);
5356
5357 // In slow path based read barriers, the read barrier call is
5358 // inserted after the original load. However, in fast path based
5359 // Baker's read barriers, we need to perform the load of
5360 // mirror::Object::monitor_ *before* the original reference load.
5361 // This load-load ordering is required by the read barrier.
5362 // The fast path/slow path (for Baker's algorithm) should look like:
5363 //
5364 // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState();
5365 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
5366 // HeapReference<Object> ref = *src; // Original reference load.
5367 // bool is_gray = (rb_state == ReadBarrier::GrayState());
5368 // if (is_gray) {
5369 // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path.
5370 // }
5371 //
5372 // Note: the original implementation in ReadBarrier::Barrier is
5373 // slightly more complex as it performs additional checks that we do
5374 // not do here for performance reasons.
5375
5376 GpuRegister ref_reg = ref.AsRegister<GpuRegister>();
5377 GpuRegister temp_reg = temp.AsRegister<GpuRegister>();
5378 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
5379
5380 // /* int32_t */ monitor = obj->monitor_
5381 __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset);
5382 if (needs_null_check) {
5383 MaybeRecordImplicitNullCheck(instruction);
5384 }
5385 // /* LockWord */ lock_word = LockWord(monitor)
5386 static_assert(sizeof(LockWord) == sizeof(int32_t),
5387 "art::LockWord and int32_t have different sizes.");
5388
5389 __ Sync(0); // Barrier to prevent load-load reordering.
5390
5391 // The actual reference load.
5392 if (index.IsValid()) {
5393 // Load types involving an "index": ArrayGet,
5394 // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject
5395 // intrinsics.
5396 // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor))
5397 if (index.IsConstant()) {
5398 size_t computed_offset =
5399 (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset;
5400 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, computed_offset);
5401 } else {
5402 GpuRegister index_reg = index.AsRegister<GpuRegister>();
Chris Larsencd0295d2017-03-31 15:26:54 -07005403 if (scale_factor == TIMES_1) {
5404 __ Daddu(TMP, index_reg, obj);
5405 } else {
5406 __ Dlsa(TMP, index_reg, obj, scale_factor);
5407 }
Alexey Frunze15958152017-02-09 19:08:30 -08005408 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset);
5409 }
5410 } else {
5411 // /* HeapReference<Object> */ ref = *(obj + offset)
5412 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset);
5413 }
5414
5415 // Object* ref = ref_addr->AsMirrorPtr()
5416 __ MaybeUnpoisonHeapReference(ref_reg);
5417
5418 // Slow path marking the object `ref` when it is gray.
5419 SlowPathCodeMIPS64* slow_path;
5420 if (always_update_field) {
5421 // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 only supports address
5422 // of the form `obj + field_offset`, where `obj` is a register and
5423 // `field_offset` is a register. Thus `offset` and `scale_factor`
5424 // above are expected to be null in this code path.
5425 DCHECK_EQ(offset, 0u);
5426 DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1);
Vladimir Marko174b2e22017-10-12 13:34:49 +01005427 slow_path = new (GetScopedAllocator())
Alexey Frunze15958152017-02-09 19:08:30 -08005428 ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(instruction,
5429 ref,
5430 obj,
5431 /* field_offset */ index,
5432 temp_reg);
5433 } else {
Vladimir Marko174b2e22017-10-12 13:34:49 +01005434 slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64(instruction, ref);
Alexey Frunze15958152017-02-09 19:08:30 -08005435 }
5436 AddSlowPath(slow_path);
5437
5438 // if (rb_state == ReadBarrier::GrayState())
5439 // ref = ReadBarrier::Mark(ref);
5440 // Given the numeric representation, it's enough to check the low bit of the
5441 // rb_state. We do that by shifting the bit into the sign bit (31) and
5442 // performing a branch on less than zero.
5443 static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0");
5444 static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1");
5445 static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size");
5446 __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift);
5447 __ Bltzc(temp_reg, slow_path->GetEntryLabel());
5448 __ Bind(slow_path->GetExitLabel());
5449}
5450
5451void CodeGeneratorMIPS64::GenerateReadBarrierSlow(HInstruction* instruction,
5452 Location out,
5453 Location ref,
5454 Location obj,
5455 uint32_t offset,
5456 Location index) {
5457 DCHECK(kEmitCompilerReadBarrier);
5458
5459 // Insert a slow path based read barrier *after* the reference load.
5460 //
5461 // If heap poisoning is enabled, the unpoisoning of the loaded
5462 // reference will be carried out by the runtime within the slow
5463 // path.
5464 //
5465 // Note that `ref` currently does not get unpoisoned (when heap
5466 // poisoning is enabled), which is alright as the `ref` argument is
5467 // not used by the artReadBarrierSlow entry point.
5468 //
5469 // TODO: Unpoison `ref` when it is used by artReadBarrierSlow.
Vladimir Marko174b2e22017-10-12 13:34:49 +01005470 SlowPathCodeMIPS64* slow_path = new (GetScopedAllocator())
Alexey Frunze15958152017-02-09 19:08:30 -08005471 ReadBarrierForHeapReferenceSlowPathMIPS64(instruction, out, ref, obj, offset, index);
5472 AddSlowPath(slow_path);
5473
5474 __ Bc(slow_path->GetEntryLabel());
5475 __ Bind(slow_path->GetExitLabel());
5476}
5477
5478void CodeGeneratorMIPS64::MaybeGenerateReadBarrierSlow(HInstruction* instruction,
5479 Location out,
5480 Location ref,
5481 Location obj,
5482 uint32_t offset,
5483 Location index) {
5484 if (kEmitCompilerReadBarrier) {
5485 // Baker's read barriers shall be handled by the fast path
5486 // (CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier).
5487 DCHECK(!kUseBakerReadBarrier);
5488 // If heap poisoning is enabled, unpoisoning will be taken care of
5489 // by the runtime within the slow path.
5490 GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index);
5491 } else if (kPoisonHeapReferences) {
5492 __ UnpoisonHeapReference(out.AsRegister<GpuRegister>());
5493 }
5494}
5495
5496void CodeGeneratorMIPS64::GenerateReadBarrierForRootSlow(HInstruction* instruction,
5497 Location out,
5498 Location root) {
5499 DCHECK(kEmitCompilerReadBarrier);
5500
5501 // Insert a slow path based read barrier *after* the GC root load.
5502 //
5503 // Note that GC roots are not affected by heap poisoning, so we do
5504 // not need to do anything special for this here.
5505 SlowPathCodeMIPS64* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01005506 new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS64(instruction, out, root);
Alexey Frunze15958152017-02-09 19:08:30 -08005507 AddSlowPath(slow_path);
5508
5509 __ Bc(slow_path->GetEntryLabel());
5510 __ Bind(slow_path->GetExitLabel());
5511}
5512
Alexey Frunze4dda3372015-06-01 18:31:49 -07005513void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005514 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
5515 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunzec61c0762017-04-10 13:54:23 -07005516 bool baker_read_barrier_slow_path = false;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005517 switch (type_check_kind) {
5518 case TypeCheckKind::kExactCheck:
5519 case TypeCheckKind::kAbstractClassCheck:
5520 case TypeCheckKind::kClassHierarchyCheck:
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005521 case TypeCheckKind::kArrayObjectCheck: {
5522 bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction);
5523 call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall;
5524 baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005525 break;
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005526 }
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005527 case TypeCheckKind::kArrayCheck:
5528 case TypeCheckKind::kUnresolvedCheck:
5529 case TypeCheckKind::kInterfaceCheck:
5530 call_kind = LocationSummary::kCallOnSlowPath;
5531 break;
5532 }
5533
Vladimir Markoca6fff82017-10-03 14:49:14 +01005534 LocationSummary* locations =
5535 new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind);
Alexey Frunzec61c0762017-04-10 13:54:23 -07005536 if (baker_read_barrier_slow_path) {
5537 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
5538 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005539 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00005540 locations->SetInAt(1, Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07005541 // The output does overlap inputs.
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01005542 // Note that TypeCheckSlowPathMIPS64 uses this register too.
Alexey Frunze4dda3372015-06-01 18:31:49 -07005543 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexey Frunze15958152017-02-09 19:08:30 -08005544 locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind));
Alexey Frunze4dda3372015-06-01 18:31:49 -07005545}
5546
5547void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005548 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunze4dda3372015-06-01 18:31:49 -07005549 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08005550 Location obj_loc = locations->InAt(0);
5551 GpuRegister obj = obj_loc.AsRegister<GpuRegister>();
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00005552 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
Alexey Frunze15958152017-02-09 19:08:30 -08005553 Location out_loc = locations->Out();
5554 GpuRegister out = out_loc.AsRegister<GpuRegister>();
5555 const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind);
5556 DCHECK_LE(num_temps, 1u);
5557 Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation();
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005558 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
5559 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5560 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5561 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07005562 Mips64Label done;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005563 SlowPathCodeMIPS64* slow_path = nullptr;
Alexey Frunze4dda3372015-06-01 18:31:49 -07005564
5565 // Return 0 if `obj` is null.
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005566 // Avoid this check if we know `obj` is not null.
5567 if (instruction->MustDoNullCheck()) {
5568 __ Move(out, ZERO);
5569 __ Beqzc(obj, &done);
5570 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005571
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005572 switch (type_check_kind) {
5573 case TypeCheckKind::kExactCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005574 ReadBarrierOption read_barrier_option =
5575 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005576 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08005577 GenerateReferenceLoadTwoRegisters(instruction,
5578 out_loc,
5579 obj_loc,
5580 class_offset,
5581 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005582 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005583 // Classes must be equal for the instanceof to succeed.
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00005584 __ Xor(out, out, cls);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005585 __ Sltiu(out, out, 1);
5586 break;
5587 }
5588
5589 case TypeCheckKind::kAbstractClassCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005590 ReadBarrierOption read_barrier_option =
5591 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005592 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08005593 GenerateReferenceLoadTwoRegisters(instruction,
5594 out_loc,
5595 obj_loc,
5596 class_offset,
5597 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005598 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005599 // If the class is abstract, we eagerly fetch the super class of the
5600 // object to avoid doing a comparison we know will fail.
5601 Mips64Label loop;
5602 __ Bind(&loop);
5603 // /* HeapReference<Class> */ out = out->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08005604 GenerateReferenceLoadOneRegister(instruction,
5605 out_loc,
5606 super_offset,
5607 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005608 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005609 // If `out` is null, we use it for the result, and jump to `done`.
5610 __ Beqzc(out, &done);
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00005611 __ Bnec(out, cls, &loop);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005612 __ LoadConst32(out, 1);
5613 break;
5614 }
5615
5616 case TypeCheckKind::kClassHierarchyCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005617 ReadBarrierOption read_barrier_option =
5618 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005619 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08005620 GenerateReferenceLoadTwoRegisters(instruction,
5621 out_loc,
5622 obj_loc,
5623 class_offset,
5624 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005625 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005626 // Walk over the class hierarchy to find a match.
5627 Mips64Label loop, success;
5628 __ Bind(&loop);
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00005629 __ Beqc(out, cls, &success);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005630 // /* HeapReference<Class> */ out = out->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08005631 GenerateReferenceLoadOneRegister(instruction,
5632 out_loc,
5633 super_offset,
5634 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005635 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005636 __ Bnezc(out, &loop);
5637 // If `out` is null, we use it for the result, and jump to `done`.
5638 __ Bc(&done);
5639 __ Bind(&success);
5640 __ LoadConst32(out, 1);
5641 break;
5642 }
5643
5644 case TypeCheckKind::kArrayObjectCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005645 ReadBarrierOption read_barrier_option =
5646 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005647 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08005648 GenerateReferenceLoadTwoRegisters(instruction,
5649 out_loc,
5650 obj_loc,
5651 class_offset,
5652 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005653 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005654 // Do an exact check.
5655 Mips64Label success;
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00005656 __ Beqc(out, cls, &success);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005657 // Otherwise, we need to check that the object's class is a non-primitive array.
5658 // /* HeapReference<Class> */ out = out->component_type_
Alexey Frunze15958152017-02-09 19:08:30 -08005659 GenerateReferenceLoadOneRegister(instruction,
5660 out_loc,
5661 component_offset,
5662 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005663 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005664 // If `out` is null, we use it for the result, and jump to `done`.
5665 __ Beqzc(out, &done);
5666 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
5667 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
5668 __ Sltiu(out, out, 1);
5669 __ Bc(&done);
5670 __ Bind(&success);
5671 __ LoadConst32(out, 1);
5672 break;
5673 }
5674
5675 case TypeCheckKind::kArrayCheck: {
5676 // No read barrier since the slow path will retry upon failure.
5677 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08005678 GenerateReferenceLoadTwoRegisters(instruction,
5679 out_loc,
5680 obj_loc,
5681 class_offset,
5682 maybe_temp_loc,
5683 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005684 DCHECK(locations->OnlyCallsOnSlowPath());
Vladimir Marko174b2e22017-10-12 13:34:49 +01005685 slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64(
5686 instruction, /* is_fatal */ false);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005687 codegen_->AddSlowPath(slow_path);
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00005688 __ Bnec(out, cls, slow_path->GetEntryLabel());
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005689 __ LoadConst32(out, 1);
5690 break;
5691 }
5692
5693 case TypeCheckKind::kUnresolvedCheck:
5694 case TypeCheckKind::kInterfaceCheck: {
5695 // Note that we indeed only call on slow path, but we always go
5696 // into the slow path for the unresolved and interface check
5697 // cases.
5698 //
5699 // We cannot directly call the InstanceofNonTrivial runtime
5700 // entry point without resorting to a type checking slow path
5701 // here (i.e. by calling InvokeRuntime directly), as it would
5702 // require to assign fixed registers for the inputs of this
5703 // HInstanceOf instruction (following the runtime calling
5704 // convention), which might be cluttered by the potential first
5705 // read barrier emission at the beginning of this method.
5706 //
5707 // TODO: Introduce a new runtime entry point taking the object
5708 // to test (instead of its class) as argument, and let it deal
5709 // with the read barrier issues. This will let us refactor this
5710 // case of the `switch` code as it was previously (with a direct
5711 // call to the runtime not using a type checking slow path).
5712 // This should also be beneficial for the other cases above.
5713 DCHECK(locations->OnlyCallsOnSlowPath());
Vladimir Marko174b2e22017-10-12 13:34:49 +01005714 slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64(
5715 instruction, /* is_fatal */ false);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005716 codegen_->AddSlowPath(slow_path);
5717 __ Bc(slow_path->GetEntryLabel());
5718 break;
5719 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005720 }
5721
5722 __ Bind(&done);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005723
5724 if (slow_path != nullptr) {
5725 __ Bind(slow_path->GetExitLabel());
5726 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005727}
5728
5729void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01005730 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005731 locations->SetOut(Location::ConstantLocation(constant));
5732}
5733
5734void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
5735 // Will be generated at use site.
5736}
5737
5738void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01005739 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005740 locations->SetOut(Location::ConstantLocation(constant));
5741}
5742
5743void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
5744 // Will be generated at use site.
5745}
5746
Calin Juravle175dc732015-08-25 15:42:32 +01005747void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5748 // The trampoline uses the same calling convention as dex calling conventions,
5749 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
5750 // the method_idx.
5751 HandleInvoke(invoke);
5752}
5753
5754void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5755 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
5756}
5757
Alexey Frunze4dda3372015-06-01 18:31:49 -07005758void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) {
5759 InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor;
5760 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
5761}
5762
5763void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
5764 HandleInvoke(invoke);
5765 // The register T0 is required to be used for the hidden argument in
5766 // art_quick_imt_conflict_trampoline, so add the hidden argument.
5767 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
5768}
5769
5770void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
5771 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
5772 GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07005773 Location receiver = invoke->GetLocations()->InAt(0);
5774 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07005775 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005776
5777 // Set the hidden argument.
5778 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(),
5779 invoke->GetDexMethodIndex());
5780
5781 // temp = object->GetClass();
5782 if (receiver.IsStackSlot()) {
5783 __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex());
5784 __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset);
5785 } else {
5786 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset);
5787 }
5788 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexey Frunzec061de12017-02-14 13:27:23 -08005789 // Instead of simply (possibly) unpoisoning `temp` here, we should
5790 // emit a read barrier for the previous class reference load.
5791 // However this is not required in practice, as this is an
5792 // intermediate/temporary reference and because the current
5793 // concurrent copying collector keeps the from-space memory
5794 // intact/accessible until the end of the marking phase (the
5795 // concurrent copying collector may not in the future).
5796 __ MaybeUnpoisonHeapReference(temp);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00005797 __ LoadFromOffset(kLoadDoubleword, temp, temp,
5798 mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value());
5799 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00005800 invoke->GetImtIndex(), kMips64PointerSize));
Alexey Frunze4dda3372015-06-01 18:31:49 -07005801 // temp = temp->GetImtEntryAt(method_offset);
5802 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
5803 // T9 = temp->GetEntryPoint();
5804 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
5805 // T9();
5806 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07005807 __ Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -07005808 DCHECK(!codegen_->IsLeafMethod());
5809 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
5810}
5811
5812void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen3039e382015-08-26 07:54:08 -07005813 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
5814 if (intrinsic.TryDispatch(invoke)) {
5815 return;
5816 }
5817
Alexey Frunze4dda3372015-06-01 18:31:49 -07005818 HandleInvoke(invoke);
5819}
5820
5821void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00005822 // Explicit clinit checks triggered by static invokes must have been pruned by
5823 // art::PrepareForRegisterAllocation.
5824 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Alexey Frunze4dda3372015-06-01 18:31:49 -07005825
Chris Larsen3039e382015-08-26 07:54:08 -07005826 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
5827 if (intrinsic.TryDispatch(invoke)) {
5828 return;
5829 }
5830
Alexey Frunze4dda3372015-06-01 18:31:49 -07005831 HandleInvoke(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005832}
5833
Orion Hodsonac141392017-01-13 11:53:47 +00005834void LocationsBuilderMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
5835 HandleInvoke(invoke);
5836}
5837
5838void InstructionCodeGeneratorMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
5839 codegen_->GenerateInvokePolymorphicCall(invoke);
5840}
5841
Chris Larsen3039e382015-08-26 07:54:08 -07005842static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07005843 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen3039e382015-08-26 07:54:08 -07005844 IntrinsicCodeGeneratorMIPS64 intrinsic(codegen);
5845 intrinsic.Dispatch(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005846 return true;
5847 }
5848 return false;
5849}
5850
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005851HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind(
Alexey Frunzef63f5692016-12-13 17:43:11 -08005852 HLoadString::LoadKind desired_string_load_kind) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08005853 bool fallback_load = false;
5854 switch (desired_string_load_kind) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08005855 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Markoe47f60c2018-02-21 13:43:28 +00005856 case HLoadString::LoadKind::kBootImageRelRo:
Alexey Frunzef63f5692016-12-13 17:43:11 -08005857 case HLoadString::LoadKind::kBssEntry:
5858 DCHECK(!Runtime::Current()->UseJitCompilation());
5859 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08005860 case HLoadString::LoadKind::kJitTableAddress:
5861 DCHECK(Runtime::Current()->UseJitCompilation());
Alexey Frunzef63f5692016-12-13 17:43:11 -08005862 break;
Vladimir Marko764d4542017-05-16 10:31:41 +01005863 case HLoadString::LoadKind::kBootImageAddress:
Vladimir Marko847e6ce2017-06-02 13:55:07 +01005864 case HLoadString::LoadKind::kRuntimeCall:
Vladimir Marko764d4542017-05-16 10:31:41 +01005865 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08005866 }
5867 if (fallback_load) {
Vladimir Marko847e6ce2017-06-02 13:55:07 +01005868 desired_string_load_kind = HLoadString::LoadKind::kRuntimeCall;
Alexey Frunzef63f5692016-12-13 17:43:11 -08005869 }
5870 return desired_string_load_kind;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005871}
5872
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005873HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind(
5874 HLoadClass::LoadKind desired_class_load_kind) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08005875 bool fallback_load = false;
5876 switch (desired_class_load_kind) {
Nicolas Geoffray83c8e272017-01-31 14:36:37 +00005877 case HLoadClass::LoadKind::kInvalid:
5878 LOG(FATAL) << "UNREACHABLE";
5879 UNREACHABLE();
Alexey Frunzef63f5692016-12-13 17:43:11 -08005880 case HLoadClass::LoadKind::kReferrersClass:
5881 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08005882 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Markoe47f60c2018-02-21 13:43:28 +00005883 case HLoadClass::LoadKind::kBootImageRelRo:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00005884 case HLoadClass::LoadKind::kBssEntry:
5885 DCHECK(!Runtime::Current()->UseJitCompilation());
5886 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08005887 case HLoadClass::LoadKind::kJitTableAddress:
5888 DCHECK(Runtime::Current()->UseJitCompilation());
Alexey Frunzef63f5692016-12-13 17:43:11 -08005889 break;
Vladimir Marko764d4542017-05-16 10:31:41 +01005890 case HLoadClass::LoadKind::kBootImageAddress:
Vladimir Marko847e6ce2017-06-02 13:55:07 +01005891 case HLoadClass::LoadKind::kRuntimeCall:
Alexey Frunzef63f5692016-12-13 17:43:11 -08005892 break;
5893 }
5894 if (fallback_load) {
Vladimir Marko847e6ce2017-06-02 13:55:07 +01005895 desired_class_load_kind = HLoadClass::LoadKind::kRuntimeCall;
Alexey Frunzef63f5692016-12-13 17:43:11 -08005896 }
5897 return desired_class_load_kind;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005898}
5899
Vladimir Markodc151b22015-10-15 18:02:30 +01005900HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch(
5901 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +01005902 HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) {
Alexey Frunze19f6c692016-11-30 19:19:55 -08005903 // On MIPS64 we support all dispatch types.
5904 return desired_dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01005905}
5906
Vladimir Markoe7197bf2017-06-02 17:00:23 +01005907void CodeGeneratorMIPS64::GenerateStaticOrDirectCall(
5908 HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07005909 // All registers are assumed to be correctly set up per the calling convention.
Vladimir Marko58155012015-08-19 12:49:41 +00005910 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
Alexey Frunze19f6c692016-11-30 19:19:55 -08005911 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
5912 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
5913
Alexey Frunze19f6c692016-11-30 19:19:55 -08005914 switch (method_load_kind) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01005915 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
Vladimir Marko58155012015-08-19 12:49:41 +00005916 // temp = thread->string_init_entrypoint
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01005917 uint32_t offset =
5918 GetThreadOffset<kMips64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
Vladimir Marko58155012015-08-19 12:49:41 +00005919 __ LoadFromOffset(kLoadDoubleword,
5920 temp.AsRegister<GpuRegister>(),
5921 TR,
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01005922 offset);
Vladimir Marko58155012015-08-19 12:49:41 +00005923 break;
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01005924 }
Vladimir Marko58155012015-08-19 12:49:41 +00005925 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00005926 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00005927 break;
Vladimir Marko65979462017-05-19 17:25:12 +01005928 case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: {
5929 DCHECK(GetCompilerOptions().IsBootImage());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07005930 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00005931 NewBootImageMethodPatch(invoke->GetTargetMethod());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07005932 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00005933 NewBootImageMethodPatch(invoke->GetTargetMethod(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07005934 EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Vladimir Marko65979462017-05-19 17:25:12 +01005935 __ Daddiu(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678);
5936 break;
5937 }
Vladimir Marko58155012015-08-19 12:49:41 +00005938 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
Alexey Frunze19f6c692016-11-30 19:19:55 -08005939 __ LoadLiteral(temp.AsRegister<GpuRegister>(),
5940 kLoadDoubleword,
5941 DeduplicateUint64Literal(invoke->GetMethodAddress()));
Vladimir Marko58155012015-08-19 12:49:41 +00005942 break;
Vladimir Markob066d432018-01-03 13:14:37 +00005943 case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: {
Vladimir Markoe47f60c2018-02-21 13:43:28 +00005944 uint32_t boot_image_offset = GetBootImageOffset(invoke);
Vladimir Markob066d432018-01-03 13:14:37 +00005945 PcRelativePatchInfo* info_high = NewBootImageRelRoPatch(boot_image_offset);
5946 PcRelativePatchInfo* info_low = NewBootImageRelRoPatch(boot_image_offset, info_high);
5947 EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
5948 // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load.
5949 __ Lwu(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678);
5950 break;
5951 }
Vladimir Marko0eb882b2017-05-15 13:39:18 +01005952 case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07005953 PcRelativePatchInfo* info_high = NewMethodBssEntryPatch(
Vladimir Marko0eb882b2017-05-15 13:39:18 +01005954 MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()));
Alexey Frunze5fa5c042017-06-01 21:07:52 -07005955 PcRelativePatchInfo* info_low = NewMethodBssEntryPatch(
5956 MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high);
5957 EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Alexey Frunze19f6c692016-11-30 19:19:55 -08005958 __ Ld(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678);
5959 break;
5960 }
Vladimir Markoe7197bf2017-06-02 17:00:23 +01005961 case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: {
5962 GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path);
5963 return; // No code pointer retrieval; the runtime performs the call directly.
Alexey Frunze4dda3372015-06-01 18:31:49 -07005964 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005965 }
5966
Alexey Frunze19f6c692016-11-30 19:19:55 -08005967 switch (code_ptr_location) {
Vladimir Marko58155012015-08-19 12:49:41 +00005968 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
Alexey Frunze19f6c692016-11-30 19:19:55 -08005969 __ Balc(&frame_entry_label_);
Vladimir Marko58155012015-08-19 12:49:41 +00005970 break;
Vladimir Marko58155012015-08-19 12:49:41 +00005971 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
5972 // T9 = callee_method->entry_point_from_quick_compiled_code_;
5973 __ LoadFromOffset(kLoadDoubleword,
5974 T9,
5975 callee_method.AsRegister<GpuRegister>(),
5976 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07005977 kMips64PointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00005978 // T9()
5979 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07005980 __ Nop();
Vladimir Marko58155012015-08-19 12:49:41 +00005981 break;
5982 }
Vladimir Markoe7197bf2017-06-02 17:00:23 +01005983 RecordPcInfo(invoke, invoke->GetDexPc(), slow_path);
5984
Alexey Frunze4dda3372015-06-01 18:31:49 -07005985 DCHECK(!IsLeafMethod());
5986}
5987
5988void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00005989 // Explicit clinit checks triggered by static invokes must have been pruned by
5990 // art::PrepareForRegisterAllocation.
5991 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Alexey Frunze4dda3372015-06-01 18:31:49 -07005992
5993 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
5994 return;
5995 }
5996
5997 LocationSummary* locations = invoke->GetLocations();
5998 codegen_->GenerateStaticOrDirectCall(invoke,
5999 locations->HasTemps()
6000 ? locations->GetTemp(0)
6001 : Location::NoLocation());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006002}
6003
Vladimir Markoe7197bf2017-06-02 17:00:23 +01006004void CodeGeneratorMIPS64::GenerateVirtualCall(
6005 HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) {
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006006 // Use the calling convention instead of the location of the receiver, as
6007 // intrinsics may have put the receiver in a different register. In the intrinsics
6008 // slow path, the arguments have been moved to the right place, so here we are
6009 // guaranteed that the receiver is the first register of the calling convention.
6010 InvokeDexCallingConvention calling_convention;
6011 GpuRegister receiver = calling_convention.GetRegisterAt(0);
6012
Alexey Frunze53afca12015-11-05 16:34:23 -08006013 GpuRegister temp = temp_location.AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006014 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
6015 invoke->GetVTableIndex(), kMips64PointerSize).SizeValue();
6016 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07006017 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006018
6019 // temp = object->GetClass();
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006020 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset);
Alexey Frunze53afca12015-11-05 16:34:23 -08006021 MaybeRecordImplicitNullCheck(invoke);
Alexey Frunzec061de12017-02-14 13:27:23 -08006022 // Instead of simply (possibly) unpoisoning `temp` here, we should
6023 // emit a read barrier for the previous class reference load.
6024 // However this is not required in practice, as this is an
6025 // intermediate/temporary reference and because the current
6026 // concurrent copying collector keeps the from-space memory
6027 // intact/accessible until the end of the marking phase (the
6028 // concurrent copying collector may not in the future).
6029 __ MaybeUnpoisonHeapReference(temp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006030 // temp = temp->GetMethodAt(method_offset);
6031 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
6032 // T9 = temp->GetEntryPoint();
6033 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
6034 // T9();
6035 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07006036 __ Nop();
Vladimir Markoe7197bf2017-06-02 17:00:23 +01006037 RecordPcInfo(invoke, invoke->GetDexPc(), slow_path);
Alexey Frunze53afca12015-11-05 16:34:23 -08006038}
6039
6040void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
6041 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
6042 return;
6043 }
6044
6045 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Alexey Frunze4dda3372015-06-01 18:31:49 -07006046 DCHECK(!codegen_->IsLeafMethod());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006047}
6048
6049void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) {
Vladimir Marko41559982017-01-06 14:04:23 +00006050 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006051 if (load_kind == HLoadClass::LoadKind::kRuntimeCall) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006052 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07006053 Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0));
6054 CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006055 return;
6056 }
Vladimir Marko41559982017-01-06 14:04:23 +00006057 DCHECK(!cls->NeedsAccessCheck());
Alexey Frunzef63f5692016-12-13 17:43:11 -08006058
Alexey Frunze15958152017-02-09 19:08:30 -08006059 const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage();
6060 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier)
Alexey Frunzef63f5692016-12-13 17:43:11 -08006061 ? LocationSummary::kCallOnSlowPath
6062 : LocationSummary::kNoCall;
Vladimir Markoca6fff82017-10-03 14:49:14 +01006063 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind);
Alexey Frunzec61c0762017-04-10 13:54:23 -07006064 if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) {
6065 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
6066 }
Vladimir Marko41559982017-01-06 14:04:23 +00006067 if (load_kind == HLoadClass::LoadKind::kReferrersClass) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006068 locations->SetInAt(0, Location::RequiresRegister());
6069 }
6070 locations->SetOut(Location::RequiresRegister());
Alexey Frunzec61c0762017-04-10 13:54:23 -07006071 if (load_kind == HLoadClass::LoadKind::kBssEntry) {
6072 if (!kUseReadBarrier || kUseBakerReadBarrier) {
6073 // Rely on the type resolution or initialization and marking to save everything we need.
6074 RegisterSet caller_saves = RegisterSet::Empty();
6075 InvokeRuntimeCallingConvention calling_convention;
6076 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6077 locations->SetCustomSlowPathCallerSaves(caller_saves);
6078 } else {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006079 // For non-Baker read barriers we have a temp-clobbering call.
Alexey Frunzec61c0762017-04-10 13:54:23 -07006080 }
6081 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006082}
6083
Nicolas Geoffray5247c082017-01-13 14:17:29 +00006084// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
6085// move.
6086void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS {
Vladimir Marko41559982017-01-06 14:04:23 +00006087 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006088 if (load_kind == HLoadClass::LoadKind::kRuntimeCall) {
Vladimir Marko41559982017-01-06 14:04:23 +00006089 codegen_->GenerateLoadClassRuntimeCall(cls);
Calin Juravle580b6092015-10-06 17:35:58 +01006090 return;
6091 }
Vladimir Marko41559982017-01-06 14:04:23 +00006092 DCHECK(!cls->NeedsAccessCheck());
Calin Juravle580b6092015-10-06 17:35:58 +01006093
Vladimir Marko41559982017-01-06 14:04:23 +00006094 LocationSummary* locations = cls->GetLocations();
Alexey Frunzef63f5692016-12-13 17:43:11 -08006095 Location out_loc = locations->Out();
6096 GpuRegister out = out_loc.AsRegister<GpuRegister>();
6097 GpuRegister current_method_reg = ZERO;
6098 if (load_kind == HLoadClass::LoadKind::kReferrersClass ||
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006099 load_kind == HLoadClass::LoadKind::kRuntimeCall) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006100 current_method_reg = locations->InAt(0).AsRegister<GpuRegister>();
6101 }
6102
Alexey Frunze15958152017-02-09 19:08:30 -08006103 const ReadBarrierOption read_barrier_option = cls->IsInBootImage()
6104 ? kWithoutReadBarrier
6105 : kCompilerReadBarrierOption;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006106 bool generate_null_check = false;
6107 switch (load_kind) {
6108 case HLoadClass::LoadKind::kReferrersClass:
6109 DCHECK(!cls->CanCallRuntime());
6110 DCHECK(!cls->MustGenerateClinitCheck());
6111 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
6112 GenerateGcRootFieldLoad(cls,
6113 out_loc,
6114 current_method_reg,
Alexey Frunze15958152017-02-09 19:08:30 -08006115 ArtMethod::DeclaringClassOffset().Int32Value(),
6116 read_barrier_option);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006117 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006118 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Marko6bec91c2017-01-09 15:03:12 +00006119 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze15958152017-02-09 19:08:30 -08006120 DCHECK_EQ(read_barrier_option, kWithoutReadBarrier);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006121 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006122 codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006123 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006124 codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006125 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006126 __ Daddiu(out, AT, /* placeholder */ 0x5678);
6127 break;
6128 }
6129 case HLoadClass::LoadKind::kBootImageAddress: {
Alexey Frunze15958152017-02-09 19:08:30 -08006130 DCHECK_EQ(read_barrier_option, kWithoutReadBarrier);
Nicolas Geoffray5247c082017-01-13 14:17:29 +00006131 uint32_t address = dchecked_integral_cast<uint32_t>(
6132 reinterpret_cast<uintptr_t>(cls->GetClass().Get()));
6133 DCHECK_NE(address, 0u);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006134 __ LoadLiteral(out,
6135 kLoadUnsignedWord,
6136 codegen_->DeduplicateBootImageAddressLiteral(address));
6137 break;
6138 }
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006139 case HLoadClass::LoadKind::kBootImageRelRo: {
Vladimir Marko94ec2db2017-09-06 17:21:03 +01006140 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006141 uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls);
Vladimir Marko94ec2db2017-09-06 17:21:03 +01006142 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006143 codegen_->NewBootImageRelRoPatch(boot_image_offset);
Vladimir Marko94ec2db2017-09-06 17:21:03 +01006144 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006145 codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high);
Vladimir Marko94ec2db2017-09-06 17:21:03 +01006146 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
6147 __ Lwu(out, AT, /* placeholder */ 0x5678);
Vladimir Marko94ec2db2017-09-06 17:21:03 +01006148 break;
6149 }
Vladimir Marko6bec91c2017-01-09 15:03:12 +00006150 case HLoadClass::LoadKind::kBssEntry: {
Vladimir Markof3c52b42017-11-17 17:32:12 +00006151 CodeGeneratorMIPS64::PcRelativePatchInfo* bss_info_high =
6152 codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006153 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
6154 codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high);
Vladimir Markof3c52b42017-11-17 17:32:12 +00006155 codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, out);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006156 GenerateGcRootFieldLoad(cls,
6157 out_loc,
Vladimir Markof3c52b42017-11-17 17:32:12 +00006158 out,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006159 /* placeholder */ 0x5678,
6160 read_barrier_option,
6161 &info_low->label);
Vladimir Marko6bec91c2017-01-09 15:03:12 +00006162 generate_null_check = true;
6163 break;
6164 }
Alexey Frunze627c1a02017-01-30 19:28:14 -08006165 case HLoadClass::LoadKind::kJitTableAddress:
6166 __ LoadLiteral(out,
6167 kLoadUnsignedWord,
6168 codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(),
6169 cls->GetTypeIndex(),
6170 cls->GetClass()));
Alexey Frunze15958152017-02-09 19:08:30 -08006171 GenerateGcRootFieldLoad(cls, out_loc, out, 0, read_barrier_option);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006172 break;
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006173 case HLoadClass::LoadKind::kRuntimeCall:
Nicolas Geoffray83c8e272017-01-31 14:36:37 +00006174 case HLoadClass::LoadKind::kInvalid:
Vladimir Marko41559982017-01-06 14:04:23 +00006175 LOG(FATAL) << "UNREACHABLE";
6176 UNREACHABLE();
Alexey Frunzef63f5692016-12-13 17:43:11 -08006177 }
6178
6179 if (generate_null_check || cls->MustGenerateClinitCheck()) {
6180 DCHECK(cls->CanCallRuntime());
Vladimir Marko174b2e22017-10-12 13:34:49 +01006181 SlowPathCodeMIPS64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64(
Vladimir Markof3c52b42017-11-17 17:32:12 +00006182 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
Alexey Frunzef63f5692016-12-13 17:43:11 -08006183 codegen_->AddSlowPath(slow_path);
6184 if (generate_null_check) {
6185 __ Beqzc(out, slow_path->GetEntryLabel());
6186 }
6187 if (cls->MustGenerateClinitCheck()) {
6188 GenerateClassInitializationCheck(slow_path, out);
6189 } else {
6190 __ Bind(slow_path->GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006191 }
6192 }
6193}
6194
David Brazdilcb1c0552015-08-04 16:22:25 +01006195static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07006196 return Thread::ExceptionOffset<kMips64PointerSize>().Int32Value();
David Brazdilcb1c0552015-08-04 16:22:25 +01006197}
6198
Alexey Frunze4dda3372015-06-01 18:31:49 -07006199void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) {
6200 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01006201 new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006202 locations->SetOut(Location::RequiresRegister());
6203}
6204
6205void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) {
6206 GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>();
David Brazdilcb1c0552015-08-04 16:22:25 +01006207 __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset());
6208}
6209
6210void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006211 new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall);
David Brazdilcb1c0552015-08-04 16:22:25 +01006212}
6213
6214void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
6215 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006216}
6217
Alexey Frunze4dda3372015-06-01 18:31:49 -07006218void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006219 HLoadString::LoadKind load_kind = load->GetLoadKind();
6220 LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load);
Vladimir Markoca6fff82017-10-03 14:49:14 +01006221 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind);
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006222 if (load_kind == HLoadString::LoadKind::kRuntimeCall) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006223 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07006224 locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Alexey Frunzef63f5692016-12-13 17:43:11 -08006225 } else {
6226 locations->SetOut(Location::RequiresRegister());
Alexey Frunzec61c0762017-04-10 13:54:23 -07006227 if (load_kind == HLoadString::LoadKind::kBssEntry) {
6228 if (!kUseReadBarrier || kUseBakerReadBarrier) {
6229 // Rely on the pResolveString and marking to save everything we need.
6230 RegisterSet caller_saves = RegisterSet::Empty();
6231 InvokeRuntimeCallingConvention calling_convention;
6232 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6233 locations->SetCustomSlowPathCallerSaves(caller_saves);
6234 } else {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006235 // For non-Baker read barriers we have a temp-clobbering call.
Alexey Frunzec61c0762017-04-10 13:54:23 -07006236 }
6237 }
Alexey Frunzef63f5692016-12-13 17:43:11 -08006238 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006239}
6240
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00006241// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
6242// move.
6243void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006244 HLoadString::LoadKind load_kind = load->GetLoadKind();
6245 LocationSummary* locations = load->GetLocations();
6246 Location out_loc = locations->Out();
6247 GpuRegister out = out_loc.AsRegister<GpuRegister>();
6248
6249 switch (load_kind) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006250 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
6251 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006252 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006253 codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006254 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006255 codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006256 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006257 __ Daddiu(out, AT, /* placeholder */ 0x5678);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01006258 return;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006259 }
6260 case HLoadString::LoadKind::kBootImageAddress: {
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00006261 uint32_t address = dchecked_integral_cast<uint32_t>(
6262 reinterpret_cast<uintptr_t>(load->GetString().Get()));
6263 DCHECK_NE(address, 0u);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006264 __ LoadLiteral(out,
6265 kLoadUnsignedWord,
6266 codegen_->DeduplicateBootImageAddressLiteral(address));
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01006267 return;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006268 }
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006269 case HLoadString::LoadKind::kBootImageRelRo: {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006270 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006271 uint32_t boot_image_offset = codegen_->GetBootImageOffset(load);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006272 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006273 codegen_->NewBootImageRelRoPatch(boot_image_offset);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006274 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006275 codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01006276 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
6277 __ Lwu(out, AT, /* placeholder */ 0x5678);
6278 return;
6279 }
6280 case HLoadString::LoadKind::kBssEntry: {
6281 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
6282 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
6283 codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex());
6284 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
6285 codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high);
Vladimir Markof3c52b42017-11-17 17:32:12 +00006286 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, out);
Alexey Frunze15958152017-02-09 19:08:30 -08006287 GenerateGcRootFieldLoad(load,
6288 out_loc,
Vladimir Markof3c52b42017-11-17 17:32:12 +00006289 out,
Alexey Frunze15958152017-02-09 19:08:30 -08006290 /* placeholder */ 0x5678,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006291 kCompilerReadBarrierOption,
6292 &info_low->label);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006293 SlowPathCodeMIPS64* slow_path =
Vladimir Markof3c52b42017-11-17 17:32:12 +00006294 new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS64(load);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006295 codegen_->AddSlowPath(slow_path);
6296 __ Beqzc(out, slow_path->GetEntryLabel());
6297 __ Bind(slow_path->GetExitLabel());
6298 return;
6299 }
Alexey Frunze627c1a02017-01-30 19:28:14 -08006300 case HLoadString::LoadKind::kJitTableAddress:
6301 __ LoadLiteral(out,
6302 kLoadUnsignedWord,
6303 codegen_->DeduplicateJitStringLiteral(load->GetDexFile(),
6304 load->GetStringIndex(),
6305 load->GetString()));
Alexey Frunze15958152017-02-09 19:08:30 -08006306 GenerateGcRootFieldLoad(load, out_loc, out, 0, kCompilerReadBarrierOption);
Alexey Frunze627c1a02017-01-30 19:28:14 -08006307 return;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006308 default:
6309 break;
6310 }
6311
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07006312 // TODO: Re-add the compiler code to do string dex cache lookup again.
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006313 DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006314 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07006315 DCHECK_EQ(calling_convention.GetRegisterAt(0), out);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006316 __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_);
6317 codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc());
6318 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006319}
6320
Alexey Frunze4dda3372015-06-01 18:31:49 -07006321void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006322 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006323 locations->SetOut(Location::ConstantLocation(constant));
6324}
6325
6326void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
6327 // Will be generated at use site.
6328}
6329
6330void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006331 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
6332 instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006333 InvokeRuntimeCallingConvention calling_convention;
6334 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6335}
6336
6337void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
Serban Constantinescufc734082016-07-19 17:18:07 +01006338 codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject,
Alexey Frunze4dda3372015-06-01 18:31:49 -07006339 instruction,
Serban Constantinescufc734082016-07-19 17:18:07 +01006340 instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00006341 if (instruction->IsEnter()) {
6342 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
6343 } else {
6344 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
6345 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006346}
6347
6348void LocationsBuilderMIPS64::VisitMul(HMul* mul) {
6349 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01006350 new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006351 switch (mul->GetResultType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006352 case DataType::Type::kInt32:
6353 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07006354 locations->SetInAt(0, Location::RequiresRegister());
6355 locations->SetInAt(1, Location::RequiresRegister());
6356 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6357 break;
6358
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006359 case DataType::Type::kFloat32:
6360 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07006361 locations->SetInAt(0, Location::RequiresFpuRegister());
6362 locations->SetInAt(1, Location::RequiresFpuRegister());
6363 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
6364 break;
6365
6366 default:
6367 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
6368 }
6369}
6370
6371void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006372 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006373 LocationSummary* locations = instruction->GetLocations();
6374
6375 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006376 case DataType::Type::kInt32:
6377 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006378 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
6379 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
6380 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006381 if (type == DataType::Type::kInt32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07006382 __ MulR6(dst, lhs, rhs);
6383 else
6384 __ Dmul(dst, lhs, rhs);
6385 break;
6386 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006387 case DataType::Type::kFloat32:
6388 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006389 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
6390 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
6391 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006392 if (type == DataType::Type::kFloat32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07006393 __ MulS(dst, lhs, rhs);
6394 else
6395 __ MulD(dst, lhs, rhs);
6396 break;
6397 }
6398 default:
6399 LOG(FATAL) << "Unexpected mul type " << type;
6400 }
6401}
6402
6403void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) {
6404 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01006405 new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006406 switch (neg->GetResultType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006407 case DataType::Type::kInt32:
6408 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07006409 locations->SetInAt(0, Location::RequiresRegister());
6410 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6411 break;
6412
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006413 case DataType::Type::kFloat32:
6414 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07006415 locations->SetInAt(0, Location::RequiresFpuRegister());
6416 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
6417 break;
6418
6419 default:
6420 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
6421 }
6422}
6423
6424void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006425 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006426 LocationSummary* locations = instruction->GetLocations();
6427
6428 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006429 case DataType::Type::kInt32:
6430 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006431 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
6432 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006433 if (type == DataType::Type::kInt32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07006434 __ Subu(dst, ZERO, src);
6435 else
6436 __ Dsubu(dst, ZERO, src);
6437 break;
6438 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006439 case DataType::Type::kFloat32:
6440 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006441 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
6442 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006443 if (type == DataType::Type::kFloat32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07006444 __ NegS(dst, src);
6445 else
6446 __ NegD(dst, src);
6447 break;
6448 }
6449 default:
6450 LOG(FATAL) << "Unexpected neg type " << type;
6451 }
6452}
6453
6454void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006455 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
6456 instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006457 InvokeRuntimeCallingConvention calling_convention;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006458 locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference));
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00006459 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6460 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07006461}
6462
6463void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) {
Alexey Frunzec061de12017-02-14 13:27:23 -08006464 // Note: if heap poisoning is enabled, the entry point takes care
6465 // of poisoning the reference.
Goran Jakovljevic854df412017-06-27 14:41:39 +02006466 QuickEntrypointEnum entrypoint =
6467 CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass());
6468 codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc());
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00006469 CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>();
Goran Jakovljevic854df412017-06-27 14:41:39 +02006470 DCHECK(!codegen_->IsLeafMethod());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006471}
6472
6473void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006474 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
6475 instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006476 InvokeRuntimeCallingConvention calling_convention;
David Brazdil6de19382016-01-08 17:37:10 +00006477 if (instruction->IsStringAlloc()) {
6478 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
6479 } else {
6480 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
David Brazdil6de19382016-01-08 17:37:10 +00006481 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006482 locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference));
Alexey Frunze4dda3372015-06-01 18:31:49 -07006483}
6484
6485void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) {
Alexey Frunzec061de12017-02-14 13:27:23 -08006486 // Note: if heap poisoning is enabled, the entry point takes care
6487 // of poisoning the reference.
David Brazdil6de19382016-01-08 17:37:10 +00006488 if (instruction->IsStringAlloc()) {
6489 // String is allocated through StringFactory. Call NewEmptyString entry point.
6490 GpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
Lazar Trsicd9672662015-09-03 17:33:01 +02006491 MemberOffset code_offset =
Andreas Gampe542451c2016-07-26 09:02:02 -07006492 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00006493 __ LoadFromOffset(kLoadDoubleword, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
6494 __ LoadFromOffset(kLoadDoubleword, T9, temp, code_offset.Int32Value());
6495 __ Jalr(T9);
6496 __ Nop();
6497 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
6498 } else {
Serban Constantinescufc734082016-07-19 17:18:07 +01006499 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00006500 CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>();
David Brazdil6de19382016-01-08 17:37:10 +00006501 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006502}
6503
6504void LocationsBuilderMIPS64::VisitNot(HNot* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006505 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006506 locations->SetInAt(0, Location::RequiresRegister());
6507 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6508}
6509
6510void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006511 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006512 LocationSummary* locations = instruction->GetLocations();
6513
6514 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006515 case DataType::Type::kInt32:
6516 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006517 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
6518 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
6519 __ Nor(dst, src, ZERO);
6520 break;
6521 }
6522
6523 default:
6524 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
6525 }
6526}
6527
6528void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006529 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006530 locations->SetInAt(0, Location::RequiresRegister());
6531 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6532}
6533
6534void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
6535 LocationSummary* locations = instruction->GetLocations();
6536 __ Xori(locations->Out().AsRegister<GpuRegister>(),
6537 locations->InAt(0).AsRegister<GpuRegister>(),
6538 1);
6539}
6540
6541void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01006542 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
6543 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006544}
6545
Calin Juravle2ae48182016-03-16 14:05:09 +00006546void CodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) {
6547 if (CanMoveNullCheckToUser(instruction)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006548 return;
6549 }
6550 Location obj = instruction->GetLocations()->InAt(0);
6551
6552 __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00006553 RecordPcInfo(instruction, instruction->GetDexPc());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006554}
6555
Calin Juravle2ae48182016-03-16 14:05:09 +00006556void CodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006557 SlowPathCodeMIPS64* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01006558 new (GetScopedAllocator()) NullCheckSlowPathMIPS64(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00006559 AddSlowPath(slow_path);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006560
6561 Location obj = instruction->GetLocations()->InAt(0);
6562
6563 __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
6564}
6565
6566void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00006567 codegen_->GenerateNullCheck(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006568}
6569
6570void LocationsBuilderMIPS64::VisitOr(HOr* instruction) {
6571 HandleBinaryOp(instruction);
6572}
6573
6574void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) {
6575 HandleBinaryOp(instruction);
6576}
6577
6578void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
6579 LOG(FATAL) << "Unreachable";
6580}
6581
6582void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) {
Vladimir Markobea75ff2017-10-11 20:39:54 +01006583 if (instruction->GetNext()->IsSuspendCheck() &&
6584 instruction->GetBlock()->GetLoopInformation() != nullptr) {
6585 HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck();
6586 // The back edge will generate the suspend check.
6587 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction);
6588 }
6589
Alexey Frunze4dda3372015-06-01 18:31:49 -07006590 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
6591}
6592
6593void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006594 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006595 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
6596 if (location.IsStackSlot()) {
6597 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
6598 } else if (location.IsDoubleStackSlot()) {
6599 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
6600 }
6601 locations->SetOut(location);
6602}
6603
6604void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction
6605 ATTRIBUTE_UNUSED) {
6606 // Nothing to do, the parameter is already at its location.
6607}
6608
6609void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) {
6610 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01006611 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006612 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
6613}
6614
6615void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction
6616 ATTRIBUTE_UNUSED) {
6617 // Nothing to do, the method is already at its location.
6618}
6619
6620void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006621 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Vladimir Marko372f10e2016-05-17 16:30:10 +01006622 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006623 locations->SetInAt(i, Location::Any());
6624 }
6625 locations->SetOut(Location::Any());
6626}
6627
6628void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
6629 LOG(FATAL) << "Unreachable";
6630}
6631
6632void LocationsBuilderMIPS64::VisitRem(HRem* rem) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006633 DataType::Type type = rem->GetResultType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006634 LocationSummary::CallKind call_kind =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006635 DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly
6636 : LocationSummary::kNoCall;
Vladimir Markoca6fff82017-10-03 14:49:14 +01006637 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006638
6639 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006640 case DataType::Type::kInt32:
6641 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07006642 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunzec857c742015-09-23 15:12:39 -07006643 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07006644 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6645 break;
6646
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006647 case DataType::Type::kFloat32:
6648 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006649 InvokeRuntimeCallingConvention calling_convention;
6650 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
6651 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
6652 locations->SetOut(calling_convention.GetReturnLocation(type));
6653 break;
6654 }
6655
6656 default:
6657 LOG(FATAL) << "Unexpected rem type " << type;
6658 }
6659}
6660
6661void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006662 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006663
6664 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006665 case DataType::Type::kInt32:
6666 case DataType::Type::kInt64:
Alexey Frunzec857c742015-09-23 15:12:39 -07006667 GenerateDivRemIntegral(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006668 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07006669
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006670 case DataType::Type::kFloat32:
6671 case DataType::Type::kFloat64: {
6672 QuickEntrypointEnum entrypoint =
6673 (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod;
Serban Constantinescufc734082016-07-19 17:18:07 +01006674 codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006675 if (type == DataType::Type::kFloat32) {
Roland Levillain888d0672015-11-23 18:53:50 +00006676 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
6677 } else {
6678 CheckEntrypointTypes<kQuickFmod, double, double, double>();
6679 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006680 break;
6681 }
6682 default:
6683 LOG(FATAL) << "Unexpected rem type " << type;
6684 }
6685}
6686
Aart Bik3dad3412018-02-28 12:01:46 -08006687void LocationsBuilderMIPS64::VisitAbs(HAbs* abs) {
6688 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs);
6689 switch (abs->GetResultType()) {
6690 case DataType::Type::kInt32:
6691 case DataType::Type::kInt64:
6692 locations->SetInAt(0, Location::RequiresRegister());
6693 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6694 break;
6695 case DataType::Type::kFloat32:
6696 case DataType::Type::kFloat64:
6697 locations->SetInAt(0, Location::RequiresFpuRegister());
6698 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
6699 break;
6700 default:
6701 LOG(FATAL) << "Unexpected abs type " << abs->GetResultType();
6702 }
6703}
6704
6705void InstructionCodeGeneratorMIPS64::VisitAbs(HAbs* abs) {
6706 LocationSummary* locations = abs->GetLocations();
6707 switch (abs->GetResultType()) {
6708 case DataType::Type::kInt32: {
6709 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
6710 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
6711 __ Sra(AT, in, 31);
6712 __ Xor(out, in, AT);
6713 __ Subu(out, out, AT);
6714 break;
6715 }
6716 case DataType::Type::kInt64: {
6717 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
6718 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
6719 __ Dsra32(AT, in, 31);
6720 __ Xor(out, in, AT);
6721 __ Dsubu(out, out, AT);
6722 break;
6723 }
6724 case DataType::Type::kFloat32: {
6725 FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>();
6726 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
6727 __ AbsS(out, in);
6728 break;
6729 }
6730 case DataType::Type::kFloat64: {
6731 FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>();
6732 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
6733 __ AbsD(out, in);
6734 break;
6735 }
6736 default:
6737 LOG(FATAL) << "Unexpected abs type " << abs->GetResultType();
6738 }
6739}
6740
Igor Murashkind01745e2017-04-05 16:40:31 -07006741void LocationsBuilderMIPS64::VisitConstructorFence(HConstructorFence* constructor_fence) {
6742 constructor_fence->SetLocations(nullptr);
6743}
6744
6745void InstructionCodeGeneratorMIPS64::VisitConstructorFence(
6746 HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) {
6747 GenerateMemoryBarrier(MemBarrierKind::kStoreStore);
6748}
6749
Alexey Frunze4dda3372015-06-01 18:31:49 -07006750void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
6751 memory_barrier->SetLocations(nullptr);
6752}
6753
6754void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
6755 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
6756}
6757
6758void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006759 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006760 DataType::Type return_type = ret->InputAt(0)->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006761 locations->SetInAt(0, Mips64ReturnLocation(return_type));
6762}
6763
6764void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
6765 codegen_->GenerateFrameExit();
6766}
6767
6768void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) {
6769 ret->SetLocations(nullptr);
6770}
6771
6772void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
6773 codegen_->GenerateFrameExit();
6774}
6775
Alexey Frunze92d90602015-12-18 18:16:36 -08006776void LocationsBuilderMIPS64::VisitRor(HRor* ror) {
6777 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00006778}
6779
Alexey Frunze92d90602015-12-18 18:16:36 -08006780void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) {
6781 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00006782}
6783
Alexey Frunze4dda3372015-06-01 18:31:49 -07006784void LocationsBuilderMIPS64::VisitShl(HShl* shl) {
6785 HandleShift(shl);
6786}
6787
6788void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) {
6789 HandleShift(shl);
6790}
6791
6792void LocationsBuilderMIPS64::VisitShr(HShr* shr) {
6793 HandleShift(shr);
6794}
6795
6796void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) {
6797 HandleShift(shr);
6798}
6799
Alexey Frunze4dda3372015-06-01 18:31:49 -07006800void LocationsBuilderMIPS64::VisitSub(HSub* instruction) {
6801 HandleBinaryOp(instruction);
6802}
6803
6804void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) {
6805 HandleBinaryOp(instruction);
6806}
6807
6808void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
6809 HandleFieldGet(instruction, instruction->GetFieldInfo());
6810}
6811
6812void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
6813 HandleFieldGet(instruction, instruction->GetFieldInfo());
6814}
6815
6816void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
6817 HandleFieldSet(instruction, instruction->GetFieldInfo());
6818}
6819
6820void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01006821 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006822}
6823
Calin Juravlee460d1d2015-09-29 04:52:17 +01006824void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet(
6825 HUnresolvedInstanceFieldGet* instruction) {
6826 FieldAccessCallingConventionMIPS64 calling_convention;
6827 codegen_->CreateUnresolvedFieldLocationSummary(
6828 instruction, instruction->GetFieldType(), calling_convention);
6829}
6830
6831void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet(
6832 HUnresolvedInstanceFieldGet* instruction) {
6833 FieldAccessCallingConventionMIPS64 calling_convention;
6834 codegen_->GenerateUnresolvedFieldAccess(instruction,
6835 instruction->GetFieldType(),
6836 instruction->GetFieldIndex(),
6837 instruction->GetDexPc(),
6838 calling_convention);
6839}
6840
6841void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet(
6842 HUnresolvedInstanceFieldSet* instruction) {
6843 FieldAccessCallingConventionMIPS64 calling_convention;
6844 codegen_->CreateUnresolvedFieldLocationSummary(
6845 instruction, instruction->GetFieldType(), calling_convention);
6846}
6847
6848void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet(
6849 HUnresolvedInstanceFieldSet* instruction) {
6850 FieldAccessCallingConventionMIPS64 calling_convention;
6851 codegen_->GenerateUnresolvedFieldAccess(instruction,
6852 instruction->GetFieldType(),
6853 instruction->GetFieldIndex(),
6854 instruction->GetDexPc(),
6855 calling_convention);
6856}
6857
6858void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet(
6859 HUnresolvedStaticFieldGet* instruction) {
6860 FieldAccessCallingConventionMIPS64 calling_convention;
6861 codegen_->CreateUnresolvedFieldLocationSummary(
6862 instruction, instruction->GetFieldType(), calling_convention);
6863}
6864
6865void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet(
6866 HUnresolvedStaticFieldGet* instruction) {
6867 FieldAccessCallingConventionMIPS64 calling_convention;
6868 codegen_->GenerateUnresolvedFieldAccess(instruction,
6869 instruction->GetFieldType(),
6870 instruction->GetFieldIndex(),
6871 instruction->GetDexPc(),
6872 calling_convention);
6873}
6874
6875void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet(
6876 HUnresolvedStaticFieldSet* instruction) {
6877 FieldAccessCallingConventionMIPS64 calling_convention;
6878 codegen_->CreateUnresolvedFieldLocationSummary(
6879 instruction, instruction->GetFieldType(), calling_convention);
6880}
6881
6882void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet(
6883 HUnresolvedStaticFieldSet* instruction) {
6884 FieldAccessCallingConventionMIPS64 calling_convention;
6885 codegen_->GenerateUnresolvedFieldAccess(instruction,
6886 instruction->GetFieldType(),
6887 instruction->GetFieldIndex(),
6888 instruction->GetDexPc(),
6889 calling_convention);
6890}
6891
Alexey Frunze4dda3372015-06-01 18:31:49 -07006892void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006893 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
6894 instruction, LocationSummary::kCallOnSlowPath);
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02006895 // In suspend check slow path, usually there are no caller-save registers at all.
6896 // If SIMD instructions are present, however, we force spilling all live SIMD
6897 // registers in full width (since the runtime only saves/restores lower part).
6898 locations->SetCustomSlowPathCallerSaves(
6899 GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006900}
6901
6902void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
6903 HBasicBlock* block = instruction->GetBlock();
6904 if (block->GetLoopInformation() != nullptr) {
6905 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
6906 // The back edge will generate the suspend check.
6907 return;
6908 }
6909 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
6910 // The goto will generate the suspend check.
6911 return;
6912 }
6913 GenerateSuspendCheck(instruction, nullptr);
6914}
6915
Alexey Frunze4dda3372015-06-01 18:31:49 -07006916void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006917 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
6918 instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006919 InvokeRuntimeCallingConvention calling_convention;
6920 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6921}
6922
6923void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) {
Serban Constantinescufc734082016-07-19 17:18:07 +01006924 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006925 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
6926}
6927
6928void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006929 DataType::Type input_type = conversion->GetInputType();
6930 DataType::Type result_type = conversion->GetResultType();
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006931 DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type))
6932 << input_type << " -> " << result_type;
Alexey Frunze4dda3372015-06-01 18:31:49 -07006933
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006934 if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) ||
6935 (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006936 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
6937 }
6938
Vladimir Markoca6fff82017-10-03 14:49:14 +01006939 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(conversion);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006940
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006941 if (DataType::IsFloatingPointType(input_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006942 locations->SetInAt(0, Location::RequiresFpuRegister());
6943 } else {
6944 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006945 }
6946
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006947 if (DataType::IsFloatingPointType(result_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006948 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006949 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006950 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006951 }
6952}
6953
6954void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
6955 LocationSummary* locations = conversion->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006956 DataType::Type result_type = conversion->GetResultType();
6957 DataType::Type input_type = conversion->GetInputType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006958
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006959 DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type))
6960 << input_type << " -> " << result_type;
Alexey Frunze4dda3372015-06-01 18:31:49 -07006961
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006962 if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006963 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
6964 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
6965
6966 switch (result_type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006967 case DataType::Type::kUint8:
6968 __ Andi(dst, src, 0xFF);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006969 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006970 case DataType::Type::kInt8:
6971 if (input_type == DataType::Type::kInt64) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00006972 // Type conversion from long to types narrower than int is a result of code
6973 // transformations. To avoid unpredictable results for SEB and SEH, we first
6974 // need to sign-extend the low 32-bit value into bits 32 through 63.
6975 __ Sll(dst, src, 0);
6976 __ Seb(dst, dst);
6977 } else {
6978 __ Seb(dst, src);
6979 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006980 break;
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006981 case DataType::Type::kUint16:
6982 __ Andi(dst, src, 0xFFFF);
6983 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006984 case DataType::Type::kInt16:
6985 if (input_type == DataType::Type::kInt64) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00006986 // Type conversion from long to types narrower than int is a result of code
6987 // transformations. To avoid unpredictable results for SEB and SEH, we first
6988 // need to sign-extend the low 32-bit value into bits 32 through 63.
6989 __ Sll(dst, src, 0);
6990 __ Seh(dst, dst);
6991 } else {
6992 __ Seh(dst, src);
6993 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006994 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006995 case DataType::Type::kInt32:
6996 case DataType::Type::kInt64:
Goran Jakovljevic992bdb92016-12-28 16:21:48 +01006997 // Sign-extend 32-bit int into bits 32 through 63 for int-to-long and long-to-int
6998 // conversions, except when the input and output registers are the same and we are not
6999 // converting longs to shorter types. In these cases, do nothing.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007000 if ((input_type == DataType::Type::kInt64) || (dst != src)) {
Goran Jakovljevic992bdb92016-12-28 16:21:48 +01007001 __ Sll(dst, src, 0);
7002 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07007003 break;
7004
7005 default:
7006 LOG(FATAL) << "Unexpected type conversion from " << input_type
7007 << " to " << result_type;
7008 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007009 } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007010 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
7011 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007012 if (input_type == DataType::Type::kInt64) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007013 __ Dmtc1(src, FTMP);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007014 if (result_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007015 __ Cvtsl(dst, FTMP);
7016 } else {
7017 __ Cvtdl(dst, FTMP);
7018 }
7019 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -07007020 __ Mtc1(src, FTMP);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007021 if (result_type == DataType::Type::kFloat32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07007022 __ Cvtsw(dst, FTMP);
7023 } else {
7024 __ Cvtdw(dst, FTMP);
7025 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07007026 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007027 } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) {
7028 CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007029 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
7030 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007031
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007032 if (result_type == DataType::Type::kInt64) {
7033 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007034 __ TruncLS(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00007035 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007036 __ TruncLD(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00007037 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007038 __ Dmfc1(dst, FTMP);
Roland Levillain888d0672015-11-23 18:53:50 +00007039 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007040 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007041 __ TruncWS(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00007042 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007043 __ TruncWD(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00007044 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007045 __ Mfc1(dst, FTMP);
Roland Levillain888d0672015-11-23 18:53:50 +00007046 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007047 } else if (DataType::IsFloatingPointType(result_type) &&
7048 DataType::IsFloatingPointType(input_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07007049 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
7050 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007051 if (result_type == DataType::Type::kFloat32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07007052 __ Cvtsd(dst, src);
7053 } else {
7054 __ Cvtds(dst, src);
7055 }
7056 } else {
7057 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
7058 << " to " << result_type;
7059 }
7060}
7061
7062void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) {
7063 HandleShift(ushr);
7064}
7065
7066void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) {
7067 HandleShift(ushr);
7068}
7069
7070void LocationsBuilderMIPS64::VisitXor(HXor* instruction) {
7071 HandleBinaryOp(instruction);
7072}
7073
7074void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) {
7075 HandleBinaryOp(instruction);
7076}
7077
7078void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
7079 // Nothing to do, this should be removed during prepare for register allocator.
7080 LOG(FATAL) << "Unreachable";
7081}
7082
7083void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
7084 // Nothing to do, this should be removed during prepare for register allocator.
7085 LOG(FATAL) << "Unreachable";
7086}
7087
7088void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007089 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007090}
7091
7092void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007093 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007094}
7095
7096void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007097 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007098}
7099
7100void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007101 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007102}
7103
7104void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007105 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007106}
7107
7108void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007109 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007110}
7111
7112void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007113 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007114}
7115
7116void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007117 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007118}
7119
7120void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007121 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007122}
7123
7124void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007125 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007126}
7127
7128void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007129 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007130}
7131
7132void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007133 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007134}
7135
Aart Bike9f37602015-10-09 11:15:55 -07007136void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007137 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007138}
7139
7140void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007141 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007142}
7143
7144void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007145 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007146}
7147
7148void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007149 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007150}
7151
7152void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007153 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007154}
7155
7156void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007157 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007158}
7159
7160void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007161 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007162}
7163
7164void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007165 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007166}
7167
Mark Mendellfe57faa2015-09-18 09:26:15 -04007168// Simple implementation of packed switch - generate cascaded compare/jumps.
7169void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7170 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01007171 new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall);
Mark Mendellfe57faa2015-09-18 09:26:15 -04007172 locations->SetInAt(0, Location::RequiresRegister());
7173}
7174
Alexey Frunze0960ac52016-12-20 17:24:59 -08007175void InstructionCodeGeneratorMIPS64::GenPackedSwitchWithCompares(GpuRegister value_reg,
7176 int32_t lower_bound,
7177 uint32_t num_entries,
7178 HBasicBlock* switch_block,
7179 HBasicBlock* default_block) {
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007180 // Create a set of compare/jumps.
7181 GpuRegister temp_reg = TMP;
Alexey Frunze0960ac52016-12-20 17:24:59 -08007182 __ Addiu32(temp_reg, value_reg, -lower_bound);
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007183 // Jump to default if index is negative
7184 // Note: We don't check the case that index is positive while value < lower_bound, because in
7185 // this case, index >= num_entries must be true. So that we can save one branch instruction.
7186 __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block));
7187
Alexey Frunze0960ac52016-12-20 17:24:59 -08007188 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007189 // Jump to successors[0] if value == lower_bound.
7190 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0]));
7191 int32_t last_index = 0;
7192 for (; num_entries - last_index > 2; last_index += 2) {
7193 __ Addiu(temp_reg, temp_reg, -2);
7194 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
7195 __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
7196 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
7197 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
7198 }
7199 if (num_entries - last_index == 2) {
7200 // The last missing case_value.
7201 __ Addiu(temp_reg, temp_reg, -1);
7202 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Mark Mendellfe57faa2015-09-18 09:26:15 -04007203 }
7204
7205 // And the default for any other value.
Alexey Frunze0960ac52016-12-20 17:24:59 -08007206 if (!codegen_->GoesToNextBlock(switch_block, default_block)) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07007207 __ Bc(codegen_->GetLabelOf(default_block));
Mark Mendellfe57faa2015-09-18 09:26:15 -04007208 }
7209}
7210
Alexey Frunze0960ac52016-12-20 17:24:59 -08007211void InstructionCodeGeneratorMIPS64::GenTableBasedPackedSwitch(GpuRegister value_reg,
7212 int32_t lower_bound,
7213 uint32_t num_entries,
7214 HBasicBlock* switch_block,
7215 HBasicBlock* default_block) {
7216 // Create a jump table.
7217 std::vector<Mips64Label*> labels(num_entries);
7218 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
7219 for (uint32_t i = 0; i < num_entries; i++) {
7220 labels[i] = codegen_->GetLabelOf(successors[i]);
7221 }
7222 JumpTable* table = __ CreateJumpTable(std::move(labels));
7223
7224 // Is the value in range?
7225 __ Addiu32(TMP, value_reg, -lower_bound);
7226 __ LoadConst32(AT, num_entries);
7227 __ Bgeuc(TMP, AT, codegen_->GetLabelOf(default_block));
7228
7229 // We are in the range of the table.
7230 // Load the target address from the jump table, indexing by the value.
7231 __ LoadLabelAddress(AT, table->GetLabel());
Chris Larsencd0295d2017-03-31 15:26:54 -07007232 __ Dlsa(TMP, TMP, AT, 2);
Alexey Frunze0960ac52016-12-20 17:24:59 -08007233 __ Lw(TMP, TMP, 0);
7234 // Compute the absolute target address by adding the table start address
7235 // (the table contains offsets to targets relative to its start).
7236 __ Daddu(TMP, TMP, AT);
7237 // And jump.
7238 __ Jr(TMP);
7239 __ Nop();
7240}
7241
7242void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7243 int32_t lower_bound = switch_instr->GetStartValue();
7244 uint32_t num_entries = switch_instr->GetNumEntries();
7245 LocationSummary* locations = switch_instr->GetLocations();
7246 GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>();
7247 HBasicBlock* switch_block = switch_instr->GetBlock();
7248 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
7249
7250 if (num_entries > kPackedSwitchJumpTableThreshold) {
7251 GenTableBasedPackedSwitch(value_reg,
7252 lower_bound,
7253 num_entries,
7254 switch_block,
7255 default_block);
7256 } else {
7257 GenPackedSwitchWithCompares(value_reg,
7258 lower_bound,
7259 num_entries,
7260 switch_block,
7261 default_block);
7262 }
7263}
7264
Chris Larsenc9905a62017-03-13 17:06:18 -07007265void LocationsBuilderMIPS64::VisitClassTableGet(HClassTableGet* instruction) {
7266 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01007267 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Chris Larsenc9905a62017-03-13 17:06:18 -07007268 locations->SetInAt(0, Location::RequiresRegister());
7269 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007270}
7271
Chris Larsenc9905a62017-03-13 17:06:18 -07007272void InstructionCodeGeneratorMIPS64::VisitClassTableGet(HClassTableGet* instruction) {
7273 LocationSummary* locations = instruction->GetLocations();
7274 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
7275 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
7276 instruction->GetIndex(), kMips64PointerSize).SizeValue();
7277 __ LoadFromOffset(kLoadDoubleword,
7278 locations->Out().AsRegister<GpuRegister>(),
7279 locations->InAt(0).AsRegister<GpuRegister>(),
7280 method_offset);
7281 } else {
7282 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
7283 instruction->GetIndex(), kMips64PointerSize));
7284 __ LoadFromOffset(kLoadDoubleword,
7285 locations->Out().AsRegister<GpuRegister>(),
7286 locations->InAt(0).AsRegister<GpuRegister>(),
7287 mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value());
7288 __ LoadFromOffset(kLoadDoubleword,
7289 locations->Out().AsRegister<GpuRegister>(),
7290 locations->Out().AsRegister<GpuRegister>(),
7291 method_offset);
7292 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007293}
7294
xueliang.zhonge0eb4832017-10-30 13:43:14 +00007295void LocationsBuilderMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction
7296 ATTRIBUTE_UNUSED) {
7297 LOG(FATAL) << "Unreachable";
7298}
7299
7300void InstructionCodeGeneratorMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction
7301 ATTRIBUTE_UNUSED) {
7302 LOG(FATAL) << "Unreachable";
7303}
7304
Alexey Frunze4dda3372015-06-01 18:31:49 -07007305} // namespace mips64
7306} // namespace art