blob: 78db1a397cadb237d3b45c418981de710ec0e716 [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 Markod8dbc8d2017-09-20 13:37:47 +01001540 EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>(
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001541 boot_image_type_patches_, linker_patches);
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001542 EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>(
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001543 boot_image_string_patches_, linker_patches);
Alexey Frunzef63f5692016-12-13 17:43:11 -08001544 }
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001545 EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>(
1546 method_bss_entry_patches_, linker_patches);
1547 EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>(
1548 type_bss_entry_patches_, linker_patches);
1549 EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>(
1550 string_bss_entry_patches_, linker_patches);
Vladimir Marko1998cd02017-01-13 13:02:58 +00001551 DCHECK_EQ(size, linker_patches->size());
Alexey Frunzef63f5692016-12-13 17:43:11 -08001552}
1553
Vladimir Markob066d432018-01-03 13:14:37 +00001554CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageRelRoPatch(
1555 uint32_t boot_image_offset,
1556 const PcRelativePatchInfo* info_high) {
1557 return NewPcRelativePatch(
1558 /* dex_file */ nullptr, boot_image_offset, info_high, &boot_image_method_patches_);
1559}
1560
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001561CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageMethodPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001562 MethodReference target_method,
1563 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001564 return NewPcRelativePatch(
1565 target_method.dex_file, target_method.index, info_high, &boot_image_method_patches_);
Alexey Frunzef63f5692016-12-13 17:43:11 -08001566}
1567
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001568CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewMethodBssEntryPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001569 MethodReference target_method,
1570 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001571 return NewPcRelativePatch(
1572 target_method.dex_file, target_method.index, info_high, &method_bss_entry_patches_);
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001573}
1574
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001575CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageTypePatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001576 const DexFile& dex_file,
1577 dex::TypeIndex type_index,
1578 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001579 return NewPcRelativePatch(&dex_file, type_index.index_, info_high, &boot_image_type_patches_);
Alexey Frunze19f6c692016-11-30 19:19:55 -08001580}
1581
Vladimir Marko1998cd02017-01-13 13:02:58 +00001582CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewTypeBssEntryPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001583 const DexFile& dex_file,
1584 dex::TypeIndex type_index,
1585 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001586 return NewPcRelativePatch(&dex_file, type_index.index_, info_high, &type_bss_entry_patches_);
Vladimir Marko1998cd02017-01-13 13:02:58 +00001587}
1588
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001589CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageStringPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001590 const DexFile& dex_file,
1591 dex::StringIndex string_index,
1592 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001593 return NewPcRelativePatch(
1594 &dex_file, string_index.index_, info_high, &boot_image_string_patches_);
Vladimir Marko65979462017-05-19 17:25:12 +01001595}
1596
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01001597CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewStringBssEntryPatch(
1598 const DexFile& dex_file,
1599 dex::StringIndex string_index,
1600 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001601 return NewPcRelativePatch(&dex_file, string_index.index_, info_high, &string_bss_entry_patches_);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01001602}
1603
Alexey Frunze19f6c692016-11-30 19:19:55 -08001604CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativePatch(
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001605 const DexFile* dex_file,
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001606 uint32_t offset_or_index,
1607 const PcRelativePatchInfo* info_high,
1608 ArenaDeque<PcRelativePatchInfo>* patches) {
1609 patches->emplace_back(dex_file, offset_or_index, info_high);
Alexey Frunze19f6c692016-11-30 19:19:55 -08001610 return &patches->back();
1611}
1612
Alexey Frunzef63f5692016-12-13 17:43:11 -08001613Literal* CodeGeneratorMIPS64::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
1614 return map->GetOrCreate(
1615 value,
1616 [this, value]() { return __ NewLiteral<uint32_t>(value); });
1617}
1618
Alexey Frunze19f6c692016-11-30 19:19:55 -08001619Literal* CodeGeneratorMIPS64::DeduplicateUint64Literal(uint64_t value) {
1620 return uint64_literals_.GetOrCreate(
1621 value,
1622 [this, value]() { return __ NewLiteral<uint64_t>(value); });
1623}
1624
Alexey Frunzef63f5692016-12-13 17:43:11 -08001625Literal* CodeGeneratorMIPS64::DeduplicateBootImageAddressLiteral(uint64_t address) {
Richard Uhlerc52f3032017-03-02 13:45:45 +00001626 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_);
Alexey Frunzef63f5692016-12-13 17:43:11 -08001627}
1628
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001629void CodeGeneratorMIPS64::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high,
1630 GpuRegister out,
1631 PcRelativePatchInfo* info_low) {
1632 DCHECK(!info_high->patch_info_high);
1633 __ Bind(&info_high->label);
Alexey Frunze19f6c692016-11-30 19:19:55 -08001634 // Add the high half of a 32-bit offset to PC.
1635 __ Auipc(out, /* placeholder */ 0x1234);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001636 // A following instruction will add the sign-extended low half of the 32-bit
Alexey Frunzef63f5692016-12-13 17:43:11 -08001637 // offset to `out` (e.g. ld, jialc, daddiu).
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001638 if (info_low != nullptr) {
1639 DCHECK_EQ(info_low->patch_info_high, info_high);
1640 __ Bind(&info_low->label);
1641 }
Alexey Frunze19f6c692016-11-30 19:19:55 -08001642}
1643
Alexey Frunze627c1a02017-01-30 19:28:14 -08001644Literal* CodeGeneratorMIPS64::DeduplicateJitStringLiteral(const DexFile& dex_file,
1645 dex::StringIndex string_index,
1646 Handle<mirror::String> handle) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01001647 ReserveJitStringRoot(StringReference(&dex_file, string_index), handle);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001648 return jit_string_patches_.GetOrCreate(
1649 StringReference(&dex_file, string_index),
1650 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1651}
1652
1653Literal* CodeGeneratorMIPS64::DeduplicateJitClassLiteral(const DexFile& dex_file,
1654 dex::TypeIndex type_index,
1655 Handle<mirror::Class> handle) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01001656 ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001657 return jit_class_patches_.GetOrCreate(
1658 TypeReference(&dex_file, type_index),
1659 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1660}
1661
1662void CodeGeneratorMIPS64::PatchJitRootUse(uint8_t* code,
1663 const uint8_t* roots_data,
1664 const Literal* literal,
1665 uint64_t index_in_table) const {
1666 uint32_t literal_offset = GetAssembler().GetLabelLocation(literal->GetLabel());
1667 uintptr_t address =
1668 reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>);
1669 reinterpret_cast<uint32_t*>(code + literal_offset)[0] = dchecked_integral_cast<uint32_t>(address);
1670}
1671
1672void CodeGeneratorMIPS64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) {
1673 for (const auto& entry : jit_string_patches_) {
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001674 const StringReference& string_reference = entry.first;
1675 Literal* table_entry_literal = entry.second;
Vladimir Marko174b2e22017-10-12 13:34:49 +01001676 uint64_t index_in_table = GetJitStringRootIndex(string_reference);
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001677 PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001678 }
1679 for (const auto& entry : jit_class_patches_) {
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001680 const TypeReference& type_reference = entry.first;
1681 Literal* table_entry_literal = entry.second;
Vladimir Marko174b2e22017-10-12 13:34:49 +01001682 uint64_t index_in_table = GetJitClassRootIndex(type_reference);
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001683 PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001684 }
1685}
1686
David Brazdil58282f42016-01-14 12:45:10 +00001687void CodeGeneratorMIPS64::SetupBlockedRegisters() const {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001688 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
1689 blocked_core_registers_[ZERO] = true;
1690 blocked_core_registers_[K0] = true;
1691 blocked_core_registers_[K1] = true;
1692 blocked_core_registers_[GP] = true;
1693 blocked_core_registers_[SP] = true;
1694 blocked_core_registers_[RA] = true;
1695
Lazar Trsicd9672662015-09-03 17:33:01 +02001696 // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch
1697 // registers (similar to how AT is used by MIPS assemblers).
Alexey Frunze4dda3372015-06-01 18:31:49 -07001698 blocked_core_registers_[AT] = true;
1699 blocked_core_registers_[TMP] = true;
Lazar Trsicd9672662015-09-03 17:33:01 +02001700 blocked_core_registers_[TMP2] = true;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001701 blocked_fpu_registers_[FTMP] = true;
1702
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001703 if (GetInstructionSetFeatures().HasMsa()) {
1704 // To be used just for MSA instructions.
1705 blocked_fpu_registers_[FTMP2] = true;
1706 }
1707
Alexey Frunze4dda3372015-06-01 18:31:49 -07001708 // Reserve suspend and thread registers.
1709 blocked_core_registers_[S0] = true;
1710 blocked_core_registers_[TR] = true;
1711
1712 // Reserve T9 for function calls
1713 blocked_core_registers_[T9] = true;
1714
Goran Jakovljevic782be112016-06-21 12:39:04 +02001715 if (GetGraph()->IsDebuggable()) {
1716 // Stubs do not save callee-save floating point registers. If the graph
1717 // is debuggable, we need to deal with these registers differently. For
1718 // now, just block them.
1719 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1720 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1721 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001722 }
1723}
1724
Alexey Frunze4dda3372015-06-01 18:31:49 -07001725size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1726 __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index);
Lazar Trsicd9672662015-09-03 17:33:01 +02001727 return kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001728}
1729
1730size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1731 __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index);
Lazar Trsicd9672662015-09-03 17:33:01 +02001732 return kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001733}
1734
1735size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001736 __ StoreFpuToOffset(GetGraph()->HasSIMD() ? kStoreQuadword : kStoreDoubleword,
1737 FpuRegister(reg_id),
1738 SP,
1739 stack_index);
1740 return GetFloatingPointSpillSlotSize();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001741}
1742
1743size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001744 __ LoadFpuFromOffset(GetGraph()->HasSIMD() ? kLoadQuadword : kLoadDoubleword,
1745 FpuRegister(reg_id),
1746 SP,
1747 stack_index);
1748 return GetFloatingPointSpillSlotSize();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001749}
1750
1751void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdil9f0dece2015-09-21 18:20:26 +01001752 stream << GpuRegister(reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001753}
1754
1755void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdil9f0dece2015-09-21 18:20:26 +01001756 stream << FpuRegister(reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001757}
1758
Calin Juravle175dc732015-08-25 15:42:32 +01001759void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint,
Alexey Frunze4dda3372015-06-01 18:31:49 -07001760 HInstruction* instruction,
1761 uint32_t dex_pc,
1762 SlowPathCode* slow_path) {
Alexandre Rames91a65162016-09-19 13:54:30 +01001763 ValidateInvokeRuntime(entrypoint, instruction, slow_path);
Alexey Frunze15958152017-02-09 19:08:30 -08001764 GenerateInvokeRuntime(GetThreadOffset<kMips64PointerSize>(entrypoint).Int32Value());
Serban Constantinescufc734082016-07-19 17:18:07 +01001765 if (EntrypointRequiresStackMap(entrypoint)) {
1766 RecordPcInfo(instruction, dex_pc, slow_path);
1767 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001768}
1769
Alexey Frunze15958152017-02-09 19:08:30 -08001770void CodeGeneratorMIPS64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
1771 HInstruction* instruction,
1772 SlowPathCode* slow_path) {
1773 ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path);
1774 GenerateInvokeRuntime(entry_point_offset);
1775}
1776
1777void CodeGeneratorMIPS64::GenerateInvokeRuntime(int32_t entry_point_offset) {
1778 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
1779 __ Jalr(T9);
1780 __ Nop();
1781}
1782
Alexey Frunze4dda3372015-06-01 18:31:49 -07001783void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path,
1784 GpuRegister class_reg) {
Vladimir Markodc682aa2018-01-04 18:42:57 +00001785 constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf();
1786 const size_t status_byte_offset =
1787 mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte);
1788 constexpr uint32_t shifted_initialized_value =
1789 enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte);
1790
1791 __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, status_byte_offset);
Lena Djokic3177e102018-02-28 11:32:40 +01001792 __ Sltiu(TMP, TMP, shifted_initialized_value);
1793 __ Bnezc(TMP, slow_path->GetEntryLabel());
Alexey Frunze15958152017-02-09 19:08:30 -08001794 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
1795 __ Sync(0);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001796 __ Bind(slow_path->GetExitLabel());
1797}
1798
1799void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1800 __ Sync(0); // only stype 0 is supported
1801}
1802
1803void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction,
1804 HBasicBlock* successor) {
1805 SuspendCheckSlowPathMIPS64* slow_path =
Chris Larsena2045912017-11-02 12:39:54 -07001806 down_cast<SuspendCheckSlowPathMIPS64*>(instruction->GetSlowPath());
1807
1808 if (slow_path == nullptr) {
1809 slow_path =
1810 new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS64(instruction, successor);
1811 instruction->SetSlowPath(slow_path);
1812 codegen_->AddSlowPath(slow_path);
1813 if (successor != nullptr) {
1814 DCHECK(successor->IsLoopHeader());
1815 }
1816 } else {
1817 DCHECK_EQ(slow_path->GetSuccessor(), successor);
1818 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001819
1820 __ LoadFromOffset(kLoadUnsignedHalfword,
1821 TMP,
1822 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001823 Thread::ThreadFlagsOffset<kMips64PointerSize>().Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001824 if (successor == nullptr) {
1825 __ Bnezc(TMP, slow_path->GetEntryLabel());
1826 __ Bind(slow_path->GetReturnLabel());
1827 } else {
1828 __ Beqzc(TMP, codegen_->GetLabelOf(successor));
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001829 __ Bc(slow_path->GetEntryLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001830 // slow_path will return to GetLabelOf(successor).
1831 }
1832}
1833
1834InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph,
1835 CodeGeneratorMIPS64* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001836 : InstructionCodeGenerator(graph, codegen),
Alexey Frunze4dda3372015-06-01 18:31:49 -07001837 assembler_(codegen->GetAssembler()),
1838 codegen_(codegen) {}
1839
1840void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
1841 DCHECK_EQ(instruction->InputCount(), 2U);
Vladimir Markoca6fff82017-10-03 14:49:14 +01001842 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001843 DataType::Type type = instruction->GetResultType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001844 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001845 case DataType::Type::kInt32:
1846 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001847 locations->SetInAt(0, Location::RequiresRegister());
1848 HInstruction* right = instruction->InputAt(1);
1849 bool can_use_imm = false;
1850 if (right->IsConstant()) {
1851 int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant());
1852 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1853 can_use_imm = IsUint<16>(imm);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001854 } else {
Lena Djokic38530172017-11-16 11:11:50 +01001855 DCHECK(instruction->IsAdd() || instruction->IsSub());
1856 bool single_use = right->GetUses().HasExactlyOneElement();
1857 if (instruction->IsSub()) {
1858 if (!(type == DataType::Type::kInt32 && imm == INT32_MIN)) {
1859 imm = -imm;
1860 }
1861 }
1862 if (type == DataType::Type::kInt32) {
1863 can_use_imm = IsInt<16>(imm) || (Low16Bits(imm) == 0) || single_use;
1864 } else {
1865 can_use_imm = IsInt<16>(imm) || (IsInt<32>(imm) && (Low16Bits(imm) == 0)) || single_use;
1866 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001867 }
1868 }
1869 if (can_use_imm)
1870 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1871 else
1872 locations->SetInAt(1, Location::RequiresRegister());
1873 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1874 }
1875 break;
1876
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001877 case DataType::Type::kFloat32:
1878 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07001879 locations->SetInAt(0, Location::RequiresFpuRegister());
1880 locations->SetInAt(1, Location::RequiresFpuRegister());
1881 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1882 break;
1883
1884 default:
1885 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1886 }
1887}
1888
1889void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001890 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001891 LocationSummary* locations = instruction->GetLocations();
1892
1893 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001894 case DataType::Type::kInt32:
1895 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001896 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1897 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1898 Location rhs_location = locations->InAt(1);
1899
1900 GpuRegister rhs_reg = ZERO;
1901 int64_t rhs_imm = 0;
1902 bool use_imm = rhs_location.IsConstant();
1903 if (use_imm) {
1904 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
1905 } else {
1906 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1907 }
1908
1909 if (instruction->IsAnd()) {
1910 if (use_imm)
1911 __ Andi(dst, lhs, rhs_imm);
1912 else
1913 __ And(dst, lhs, rhs_reg);
1914 } else if (instruction->IsOr()) {
1915 if (use_imm)
1916 __ Ori(dst, lhs, rhs_imm);
1917 else
1918 __ Or(dst, lhs, rhs_reg);
1919 } else if (instruction->IsXor()) {
1920 if (use_imm)
1921 __ Xori(dst, lhs, rhs_imm);
1922 else
1923 __ Xor(dst, lhs, rhs_reg);
Lena Djokic38530172017-11-16 11:11:50 +01001924 } else if (instruction->IsAdd() || instruction->IsSub()) {
1925 if (instruction->IsSub()) {
1926 rhs_imm = -rhs_imm;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001927 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001928 if (type == DataType::Type::kInt32) {
Lena Djokic38530172017-11-16 11:11:50 +01001929 if (use_imm) {
1930 if (IsInt<16>(rhs_imm)) {
1931 __ Addiu(dst, lhs, rhs_imm);
1932 } else {
1933 int16_t rhs_imm_high = High16Bits(rhs_imm);
1934 int16_t rhs_imm_low = Low16Bits(rhs_imm);
1935 if (rhs_imm_low < 0) {
1936 rhs_imm_high += 1;
1937 }
1938 __ Aui(dst, lhs, rhs_imm_high);
1939 if (rhs_imm_low != 0) {
1940 __ Addiu(dst, dst, rhs_imm_low);
1941 }
1942 }
1943 } else {
1944 if (instruction->IsAdd()) {
1945 __ Addu(dst, lhs, rhs_reg);
1946 } else {
1947 DCHECK(instruction->IsSub());
1948 __ Subu(dst, lhs, rhs_reg);
1949 }
1950 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001951 } else {
Lena Djokic38530172017-11-16 11:11:50 +01001952 if (use_imm) {
1953 if (IsInt<16>(rhs_imm)) {
1954 __ Daddiu(dst, lhs, rhs_imm);
1955 } else if (IsInt<32>(rhs_imm)) {
1956 int16_t rhs_imm_high = High16Bits(rhs_imm);
1957 int16_t rhs_imm_low = Low16Bits(rhs_imm);
1958 bool overflow_hi16 = false;
1959 if (rhs_imm_low < 0) {
1960 rhs_imm_high += 1;
1961 overflow_hi16 = (rhs_imm_high == -32768);
1962 }
1963 __ Daui(dst, lhs, rhs_imm_high);
1964 if (rhs_imm_low != 0) {
1965 __ Daddiu(dst, dst, rhs_imm_low);
1966 }
1967 if (overflow_hi16) {
1968 __ Dahi(dst, 1);
1969 }
1970 } else {
1971 int16_t rhs_imm_low = Low16Bits(Low32Bits(rhs_imm));
1972 if (rhs_imm_low < 0) {
1973 rhs_imm += (INT64_C(1) << 16);
1974 }
1975 int16_t rhs_imm_upper = High16Bits(Low32Bits(rhs_imm));
1976 if (rhs_imm_upper < 0) {
1977 rhs_imm += (INT64_C(1) << 32);
1978 }
1979 int16_t rhs_imm_high = Low16Bits(High32Bits(rhs_imm));
1980 if (rhs_imm_high < 0) {
1981 rhs_imm += (INT64_C(1) << 48);
1982 }
1983 int16_t rhs_imm_top = High16Bits(High32Bits(rhs_imm));
1984 GpuRegister tmp = lhs;
1985 if (rhs_imm_low != 0) {
1986 __ Daddiu(dst, tmp, rhs_imm_low);
1987 tmp = dst;
1988 }
1989 // Dahi and Dati must use the same input and output register, so we have to initialize
1990 // the dst register using Daddiu or Daui, even when the intermediate value is zero:
1991 // Daui(dst, lhs, 0).
1992 if ((rhs_imm_upper != 0) || (rhs_imm_low == 0)) {
1993 __ Daui(dst, tmp, rhs_imm_upper);
1994 }
1995 if (rhs_imm_high != 0) {
1996 __ Dahi(dst, rhs_imm_high);
1997 }
1998 if (rhs_imm_top != 0) {
1999 __ Dati(dst, rhs_imm_top);
2000 }
2001 }
2002 } else if (instruction->IsAdd()) {
2003 __ Daddu(dst, lhs, rhs_reg);
2004 } else {
2005 DCHECK(instruction->IsSub());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002006 __ Dsubu(dst, lhs, rhs_reg);
Lena Djokic38530172017-11-16 11:11:50 +01002007 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002008 }
2009 }
2010 break;
2011 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002012 case DataType::Type::kFloat32:
2013 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002014 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2015 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
2016 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
2017 if (instruction->IsAdd()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002018 if (type == DataType::Type::kFloat32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07002019 __ AddS(dst, lhs, rhs);
2020 else
2021 __ AddD(dst, lhs, rhs);
2022 } else if (instruction->IsSub()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002023 if (type == DataType::Type::kFloat32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07002024 __ SubS(dst, lhs, rhs);
2025 else
2026 __ SubD(dst, lhs, rhs);
2027 } else {
2028 LOG(FATAL) << "Unexpected floating-point binary operation";
2029 }
2030 break;
2031 }
2032 default:
2033 LOG(FATAL) << "Unexpected binary operation type " << type;
2034 }
2035}
2036
2037void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002038 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002039
Vladimir Markoca6fff82017-10-03 14:49:14 +01002040 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002041 DataType::Type type = instr->GetResultType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002042 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002043 case DataType::Type::kInt32:
2044 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002045 locations->SetInAt(0, Location::RequiresRegister());
2046 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07002047 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002048 break;
2049 }
2050 default:
2051 LOG(FATAL) << "Unexpected shift type " << type;
2052 }
2053}
2054
2055void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002056 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002057 LocationSummary* locations = instr->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002058 DataType::Type type = instr->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002059
2060 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002061 case DataType::Type::kInt32:
2062 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002063 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2064 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2065 Location rhs_location = locations->InAt(1);
2066
2067 GpuRegister rhs_reg = ZERO;
2068 int64_t rhs_imm = 0;
2069 bool use_imm = rhs_location.IsConstant();
2070 if (use_imm) {
2071 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
2072 } else {
2073 rhs_reg = rhs_location.AsRegister<GpuRegister>();
2074 }
2075
2076 if (use_imm) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00002077 uint32_t shift_value = rhs_imm &
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002078 (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002079
Alexey Frunze92d90602015-12-18 18:16:36 -08002080 if (shift_value == 0) {
2081 if (dst != lhs) {
2082 __ Move(dst, lhs);
2083 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002084 } else if (type == DataType::Type::kInt32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002085 if (instr->IsShl()) {
2086 __ Sll(dst, lhs, shift_value);
2087 } else if (instr->IsShr()) {
2088 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002089 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002090 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002091 } else {
2092 __ Rotr(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002093 }
2094 } else {
2095 if (shift_value < 32) {
2096 if (instr->IsShl()) {
2097 __ Dsll(dst, lhs, shift_value);
2098 } else if (instr->IsShr()) {
2099 __ Dsra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002100 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002101 __ Dsrl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002102 } else {
2103 __ Drotr(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002104 }
2105 } else {
2106 shift_value -= 32;
2107 if (instr->IsShl()) {
2108 __ Dsll32(dst, lhs, shift_value);
2109 } else if (instr->IsShr()) {
2110 __ Dsra32(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002111 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002112 __ Dsrl32(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002113 } else {
2114 __ Drotr32(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002115 }
2116 }
2117 }
2118 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002119 if (type == DataType::Type::kInt32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002120 if (instr->IsShl()) {
2121 __ Sllv(dst, lhs, rhs_reg);
2122 } else if (instr->IsShr()) {
2123 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002124 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002125 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002126 } else {
2127 __ Rotrv(dst, lhs, rhs_reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002128 }
2129 } else {
2130 if (instr->IsShl()) {
2131 __ Dsllv(dst, lhs, rhs_reg);
2132 } else if (instr->IsShr()) {
2133 __ Dsrav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002134 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002135 __ Dsrlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002136 } else {
2137 __ Drotrv(dst, lhs, rhs_reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002138 }
2139 }
2140 }
2141 break;
2142 }
2143 default:
2144 LOG(FATAL) << "Unexpected shift operation type " << type;
2145 }
2146}
2147
2148void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) {
2149 HandleBinaryOp(instruction);
2150}
2151
2152void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) {
2153 HandleBinaryOp(instruction);
2154}
2155
2156void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) {
2157 HandleBinaryOp(instruction);
2158}
2159
2160void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) {
2161 HandleBinaryOp(instruction);
2162}
2163
2164void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002165 DataType::Type type = instruction->GetType();
Alexey Frunze15958152017-02-09 19:08:30 -08002166 bool object_array_get_with_read_barrier =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002167 kEmitCompilerReadBarrier && (type == DataType::Type::kReference);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002168 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01002169 new (GetGraph()->GetAllocator()) LocationSummary(instruction,
2170 object_array_get_with_read_barrier
2171 ? LocationSummary::kCallOnSlowPath
2172 : LocationSummary::kNoCall);
Alexey Frunzec61c0762017-04-10 13:54:23 -07002173 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
2174 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
2175 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002176 locations->SetInAt(0, Location::RequiresRegister());
2177 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002178 if (DataType::IsFloatingPointType(type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002179 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2180 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08002181 // The output overlaps in the case of an object array get with
2182 // read barriers enabled: we do not want the move to overwrite the
2183 // array's location, as we need it to emit the read barrier.
2184 locations->SetOut(Location::RequiresRegister(),
2185 object_array_get_with_read_barrier
2186 ? Location::kOutputOverlap
2187 : Location::kNoOutputOverlap);
2188 }
2189 // We need a temporary register for the read barrier marking slow
2190 // path in CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier.
2191 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002192 bool temp_needed = instruction->GetIndex()->IsConstant()
2193 ? !kBakerReadBarrierThunksEnableForFields
2194 : !kBakerReadBarrierThunksEnableForArrays;
2195 if (temp_needed) {
2196 locations->AddTemp(Location::RequiresRegister());
2197 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002198 }
2199}
2200
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002201static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS64* codegen) {
2202 auto null_checker = [codegen, instruction]() {
2203 codegen->MaybeRecordImplicitNullCheck(instruction);
2204 };
2205 return null_checker;
2206}
2207
Alexey Frunze4dda3372015-06-01 18:31:49 -07002208void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) {
2209 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08002210 Location obj_loc = locations->InAt(0);
2211 GpuRegister obj = obj_loc.AsRegister<GpuRegister>();
2212 Location out_loc = locations->Out();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002213 Location index = locations->InAt(1);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01002214 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002215 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002216
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002217 DataType::Type type = instruction->GetType();
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002218 const bool maybe_compressed_char_at = mirror::kUseStringCompression &&
2219 instruction->IsStringCharAt();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002220 switch (type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002221 case DataType::Type::kBool:
2222 case DataType::Type::kUint8: {
Alexey Frunze15958152017-02-09 19:08:30 -08002223 GpuRegister out = out_loc.AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002224 if (index.IsConstant()) {
2225 size_t offset =
2226 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002227 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002228 } else {
2229 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002230 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002231 }
2232 break;
2233 }
2234
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002235 case DataType::Type::kInt8: {
Alexey Frunze15958152017-02-09 19:08:30 -08002236 GpuRegister out = out_loc.AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002237 if (index.IsConstant()) {
2238 size_t offset =
2239 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002240 __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002241 } else {
2242 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002243 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002244 }
2245 break;
2246 }
2247
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002248 case DataType::Type::kUint16: {
Alexey Frunze15958152017-02-09 19:08:30 -08002249 GpuRegister out = out_loc.AsRegister<GpuRegister>();
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002250 if (maybe_compressed_char_at) {
2251 uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002252 __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002253 __ Dext(TMP, TMP, 0, 1);
2254 static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u,
2255 "Expecting 0=compressed, 1=uncompressed");
2256 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002257 if (index.IsConstant()) {
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002258 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
2259 if (maybe_compressed_char_at) {
2260 Mips64Label uncompressed_load, done;
2261 __ Bnezc(TMP, &uncompressed_load);
2262 __ LoadFromOffset(kLoadUnsignedByte,
2263 out,
2264 obj,
2265 data_offset + (const_index << TIMES_1));
2266 __ Bc(&done);
2267 __ Bind(&uncompressed_load);
2268 __ LoadFromOffset(kLoadUnsignedHalfword,
2269 out,
2270 obj,
2271 data_offset + (const_index << TIMES_2));
2272 __ Bind(&done);
2273 } else {
2274 __ LoadFromOffset(kLoadUnsignedHalfword,
2275 out,
2276 obj,
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002277 data_offset + (const_index << TIMES_2),
2278 null_checker);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002279 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002280 } else {
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002281 GpuRegister index_reg = index.AsRegister<GpuRegister>();
2282 if (maybe_compressed_char_at) {
2283 Mips64Label uncompressed_load, done;
2284 __ Bnezc(TMP, &uncompressed_load);
2285 __ Daddu(TMP, obj, index_reg);
2286 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset);
2287 __ Bc(&done);
2288 __ Bind(&uncompressed_load);
Chris Larsencd0295d2017-03-31 15:26:54 -07002289 __ Dlsa(TMP, index_reg, obj, TIMES_2);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002290 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset);
2291 __ Bind(&done);
2292 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002293 __ Dlsa(TMP, index_reg, obj, TIMES_2);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002294 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002295 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002296 }
2297 break;
2298 }
2299
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002300 case DataType::Type::kInt16: {
2301 GpuRegister out = out_loc.AsRegister<GpuRegister>();
2302 if (index.IsConstant()) {
2303 size_t offset =
2304 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2305 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker);
2306 } else {
2307 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_2);
2308 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker);
2309 }
2310 break;
2311 }
2312
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002313 case DataType::Type::kInt32: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002314 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
Alexey Frunze15958152017-02-09 19:08:30 -08002315 GpuRegister out = out_loc.AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002316 LoadOperandType load_type =
2317 (type == DataType::Type::kReference) ? kLoadUnsignedWord : kLoadWord;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002318 if (index.IsConstant()) {
2319 size_t offset =
2320 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002321 __ LoadFromOffset(load_type, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002322 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002323 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002324 __ LoadFromOffset(load_type, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002325 }
2326 break;
2327 }
2328
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002329 case DataType::Type::kReference: {
Alexey Frunze15958152017-02-09 19:08:30 -08002330 static_assert(
2331 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
2332 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
2333 // /* HeapReference<Object> */ out =
2334 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
2335 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002336 bool temp_needed = index.IsConstant()
2337 ? !kBakerReadBarrierThunksEnableForFields
2338 : !kBakerReadBarrierThunksEnableForArrays;
2339 Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation();
Alexey Frunze15958152017-02-09 19:08:30 -08002340 // Note that a potential implicit null check is handled in this
2341 // CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier call.
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002342 DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0)));
2343 if (index.IsConstant()) {
2344 // Array load with a constant index can be treated as a field load.
2345 size_t offset =
2346 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2347 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
2348 out_loc,
2349 obj,
2350 offset,
2351 temp,
2352 /* needs_null_check */ false);
2353 } else {
2354 codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction,
2355 out_loc,
2356 obj,
2357 data_offset,
2358 index,
2359 temp,
2360 /* needs_null_check */ false);
2361 }
Alexey Frunze15958152017-02-09 19:08:30 -08002362 } else {
2363 GpuRegister out = out_loc.AsRegister<GpuRegister>();
2364 if (index.IsConstant()) {
2365 size_t offset =
2366 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2367 __ LoadFromOffset(kLoadUnsignedWord, out, obj, offset, null_checker);
2368 // If read barriers are enabled, emit read barriers other than
2369 // Baker's using a slow path (and also unpoison the loaded
2370 // reference, if heap poisoning is enabled).
2371 codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
2372 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002373 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Alexey Frunze15958152017-02-09 19:08:30 -08002374 __ LoadFromOffset(kLoadUnsignedWord, out, TMP, data_offset, null_checker);
2375 // If read barriers are enabled, emit read barriers other than
2376 // Baker's using a slow path (and also unpoison the loaded
2377 // reference, if heap poisoning is enabled).
2378 codegen_->MaybeGenerateReadBarrierSlow(instruction,
2379 out_loc,
2380 out_loc,
2381 obj_loc,
2382 data_offset,
2383 index);
2384 }
2385 }
2386 break;
2387 }
2388
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002389 case DataType::Type::kInt64: {
Alexey Frunze15958152017-02-09 19:08:30 -08002390 GpuRegister out = out_loc.AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002391 if (index.IsConstant()) {
2392 size_t offset =
2393 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002394 __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002395 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002396 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002397 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002398 }
2399 break;
2400 }
2401
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002402 case DataType::Type::kFloat32: {
Alexey Frunze15958152017-02-09 19:08:30 -08002403 FpuRegister out = out_loc.AsFpuRegister<FpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002404 if (index.IsConstant()) {
2405 size_t offset =
2406 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002407 __ LoadFpuFromOffset(kLoadWord, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002408 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002409 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002410 __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002411 }
2412 break;
2413 }
2414
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002415 case DataType::Type::kFloat64: {
Alexey Frunze15958152017-02-09 19:08:30 -08002416 FpuRegister out = out_loc.AsFpuRegister<FpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002417 if (index.IsConstant()) {
2418 size_t offset =
2419 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002420 __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002421 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002422 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002423 __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002424 }
2425 break;
2426 }
2427
Aart Bik66c158e2018-01-31 12:55:04 -08002428 case DataType::Type::kUint32:
2429 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002430 case DataType::Type::kVoid:
Alexey Frunze4dda3372015-06-01 18:31:49 -07002431 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2432 UNREACHABLE();
2433 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002434}
2435
2436void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01002437 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002438 locations->SetInAt(0, Location::RequiresRegister());
2439 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2440}
2441
2442void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) {
2443 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01002444 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002445 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2446 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2447 __ LoadFromOffset(kLoadWord, out, obj, offset);
2448 codegen_->MaybeRecordImplicitNullCheck(instruction);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002449 // Mask out compression flag from String's array length.
2450 if (mirror::kUseStringCompression && instruction->IsStringLength()) {
2451 __ Srl(out, out, 1u);
2452 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002453}
2454
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002455Location LocationsBuilderMIPS64::RegisterOrZeroConstant(HInstruction* instruction) {
2456 return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern())
2457 ? Location::ConstantLocation(instruction->AsConstant())
2458 : Location::RequiresRegister();
2459}
2460
2461Location LocationsBuilderMIPS64::FpuRegisterOrConstantForStore(HInstruction* instruction) {
2462 // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register.
2463 // We can store a non-zero float or double constant without first loading it into the FPU,
2464 // but we should only prefer this if the constant has a single use.
2465 if (instruction->IsConstant() &&
2466 (instruction->AsConstant()->IsZeroBitPattern() ||
2467 instruction->GetUses().HasExactlyOneElement())) {
2468 return Location::ConstantLocation(instruction->AsConstant());
2469 // Otherwise fall through and require an FPU register for the constant.
2470 }
2471 return Location::RequiresFpuRegister();
2472}
2473
Alexey Frunze4dda3372015-06-01 18:31:49 -07002474void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002475 DataType::Type value_type = instruction->GetComponentType();
Alexey Frunze15958152017-02-09 19:08:30 -08002476
2477 bool needs_write_barrier =
2478 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
2479 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
2480
Vladimir Markoca6fff82017-10-03 14:49:14 +01002481 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
Alexey Frunze4dda3372015-06-01 18:31:49 -07002482 instruction,
Alexey Frunze15958152017-02-09 19:08:30 -08002483 may_need_runtime_call_for_type_check ?
2484 LocationSummary::kCallOnSlowPath :
2485 LocationSummary::kNoCall);
2486
2487 locations->SetInAt(0, Location::RequiresRegister());
2488 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002489 if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
Alexey Frunze15958152017-02-09 19:08:30 -08002490 locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002491 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08002492 locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2)));
2493 }
2494 if (needs_write_barrier) {
2495 // Temporary register for the write barrier.
2496 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002497 }
2498}
2499
2500void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) {
2501 LocationSummary* locations = instruction->GetLocations();
2502 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2503 Location index = locations->InAt(1);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002504 Location value_location = locations->InAt(2);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002505 DataType::Type value_type = instruction->GetComponentType();
Alexey Frunze15958152017-02-09 19:08:30 -08002506 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002507 bool needs_write_barrier =
2508 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002509 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002510 GpuRegister base_reg = index.IsConstant() ? obj : TMP;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002511
2512 switch (value_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002513 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002514 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002515 case DataType::Type::kInt8: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002516 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002517 if (index.IsConstant()) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002518 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002519 } else {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002520 __ Daddu(base_reg, obj, index.AsRegister<GpuRegister>());
2521 }
2522 if (value_location.IsConstant()) {
2523 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2524 __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker);
2525 } else {
2526 GpuRegister value = value_location.AsRegister<GpuRegister>();
2527 __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002528 }
2529 break;
2530 }
2531
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002532 case DataType::Type::kUint16:
2533 case DataType::Type::kInt16: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002534 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002535 if (index.IsConstant()) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002536 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002537 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002538 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_2);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002539 }
2540 if (value_location.IsConstant()) {
2541 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2542 __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker);
2543 } else {
2544 GpuRegister value = value_location.AsRegister<GpuRegister>();
2545 __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002546 }
2547 break;
2548 }
2549
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002550 case DataType::Type::kInt32: {
Alexey Frunze15958152017-02-09 19:08:30 -08002551 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2552 if (index.IsConstant()) {
2553 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
2554 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002555 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Alexey Frunze15958152017-02-09 19:08:30 -08002556 }
2557 if (value_location.IsConstant()) {
2558 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2559 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2560 } else {
2561 GpuRegister value = value_location.AsRegister<GpuRegister>();
2562 __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
2563 }
2564 break;
2565 }
2566
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002567 case DataType::Type::kReference: {
Alexey Frunze15958152017-02-09 19:08:30 -08002568 if (value_location.IsConstant()) {
2569 // Just setting null.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002570 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002571 if (index.IsConstant()) {
Alexey Frunzec061de12017-02-14 13:27:23 -08002572 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002573 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002574 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Alexey Frunzec061de12017-02-14 13:27:23 -08002575 }
Alexey Frunze15958152017-02-09 19:08:30 -08002576 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2577 DCHECK_EQ(value, 0);
2578 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2579 DCHECK(!needs_write_barrier);
2580 DCHECK(!may_need_runtime_call_for_type_check);
2581 break;
2582 }
2583
2584 DCHECK(needs_write_barrier);
2585 GpuRegister value = value_location.AsRegister<GpuRegister>();
2586 GpuRegister temp1 = locations->GetTemp(0).AsRegister<GpuRegister>();
2587 GpuRegister temp2 = TMP; // Doesn't need to survive slow path.
2588 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2589 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
2590 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
2591 Mips64Label done;
2592 SlowPathCodeMIPS64* slow_path = nullptr;
2593
2594 if (may_need_runtime_call_for_type_check) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01002595 slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS64(instruction);
Alexey Frunze15958152017-02-09 19:08:30 -08002596 codegen_->AddSlowPath(slow_path);
2597 if (instruction->GetValueCanBeNull()) {
2598 Mips64Label non_zero;
2599 __ Bnezc(value, &non_zero);
2600 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2601 if (index.IsConstant()) {
2602 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002603 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002604 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002605 }
Alexey Frunze15958152017-02-09 19:08:30 -08002606 __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
2607 __ Bc(&done);
2608 __ Bind(&non_zero);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002609 }
Alexey Frunze15958152017-02-09 19:08:30 -08002610
2611 // Note that when read barriers are enabled, the type checks
2612 // are performed without read barriers. This is fine, even in
2613 // the case where a class object is in the from-space after
2614 // the flip, as a comparison involving such a type would not
2615 // produce a false positive; it may of course produce a false
2616 // negative, in which case we would take the ArraySet slow
2617 // path.
2618
2619 // /* HeapReference<Class> */ temp1 = obj->klass_
2620 __ LoadFromOffset(kLoadUnsignedWord, temp1, obj, class_offset, null_checker);
2621 __ MaybeUnpoisonHeapReference(temp1);
2622
2623 // /* HeapReference<Class> */ temp1 = temp1->component_type_
2624 __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, component_offset);
2625 // /* HeapReference<Class> */ temp2 = value->klass_
2626 __ LoadFromOffset(kLoadUnsignedWord, temp2, value, class_offset);
2627 // If heap poisoning is enabled, no need to unpoison `temp1`
2628 // nor `temp2`, as we are comparing two poisoned references.
2629
2630 if (instruction->StaticTypeOfArrayIsObjectArray()) {
2631 Mips64Label do_put;
2632 __ Beqc(temp1, temp2, &do_put);
2633 // If heap poisoning is enabled, the `temp1` reference has
2634 // not been unpoisoned yet; unpoison it now.
2635 __ MaybeUnpoisonHeapReference(temp1);
2636
2637 // /* HeapReference<Class> */ temp1 = temp1->super_class_
2638 __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, super_offset);
2639 // If heap poisoning is enabled, no need to unpoison
2640 // `temp1`, as we are comparing against null below.
2641 __ Bnezc(temp1, slow_path->GetEntryLabel());
2642 __ Bind(&do_put);
2643 } else {
2644 __ Bnec(temp1, temp2, slow_path->GetEntryLabel());
2645 }
2646 }
2647
2648 GpuRegister source = value;
2649 if (kPoisonHeapReferences) {
2650 // Note that in the case where `value` is a null reference,
2651 // we do not enter this block, as a null reference does not
2652 // need poisoning.
2653 __ Move(temp1, value);
2654 __ PoisonHeapReference(temp1);
2655 source = temp1;
2656 }
2657
2658 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2659 if (index.IsConstant()) {
2660 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002661 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002662 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Alexey Frunze15958152017-02-09 19:08:30 -08002663 }
2664 __ StoreToOffset(kStoreWord, source, base_reg, data_offset);
2665
2666 if (!may_need_runtime_call_for_type_check) {
2667 codegen_->MaybeRecordImplicitNullCheck(instruction);
2668 }
2669
2670 codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull());
2671
2672 if (done.IsLinked()) {
2673 __ Bind(&done);
2674 }
2675
2676 if (slow_path != nullptr) {
2677 __ Bind(slow_path->GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002678 }
2679 break;
2680 }
2681
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002682 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002683 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002684 if (index.IsConstant()) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002685 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002686 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002687 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002688 }
2689 if (value_location.IsConstant()) {
2690 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
2691 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
2692 } else {
2693 GpuRegister value = value_location.AsRegister<GpuRegister>();
2694 __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002695 }
2696 break;
2697 }
2698
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002699 case DataType::Type::kFloat32: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002700 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002701 if (index.IsConstant()) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002702 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002703 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002704 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002705 }
2706 if (value_location.IsConstant()) {
2707 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2708 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2709 } else {
2710 FpuRegister value = value_location.AsFpuRegister<FpuRegister>();
2711 __ StoreFpuToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002712 }
2713 break;
2714 }
2715
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002716 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002717 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002718 if (index.IsConstant()) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002719 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002720 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002721 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002722 }
2723 if (value_location.IsConstant()) {
2724 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
2725 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
2726 } else {
2727 FpuRegister value = value_location.AsFpuRegister<FpuRegister>();
2728 __ StoreFpuToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002729 }
2730 break;
2731 }
2732
Aart Bik66c158e2018-01-31 12:55:04 -08002733 case DataType::Type::kUint32:
2734 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002735 case DataType::Type::kVoid:
Alexey Frunze4dda3372015-06-01 18:31:49 -07002736 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2737 UNREACHABLE();
2738 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002739}
2740
2741void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01002742 RegisterSet caller_saves = RegisterSet::Empty();
2743 InvokeRuntimeCallingConvention calling_convention;
2744 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2745 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2746 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves);
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01002747
2748 HInstruction* index = instruction->InputAt(0);
2749 HInstruction* length = instruction->InputAt(1);
2750
2751 bool const_index = false;
2752 bool const_length = false;
2753
2754 if (index->IsConstant()) {
2755 if (length->IsConstant()) {
2756 const_index = true;
2757 const_length = true;
2758 } else {
2759 int32_t index_value = index->AsIntConstant()->GetValue();
2760 if (index_value < 0 || IsInt<16>(index_value + 1)) {
2761 const_index = true;
2762 }
2763 }
2764 } else if (length->IsConstant()) {
2765 int32_t length_value = length->AsIntConstant()->GetValue();
2766 if (IsUint<15>(length_value)) {
2767 const_length = true;
2768 }
2769 }
2770
2771 locations->SetInAt(0, const_index
2772 ? Location::ConstantLocation(index->AsConstant())
2773 : Location::RequiresRegister());
2774 locations->SetInAt(1, const_length
2775 ? Location::ConstantLocation(length->AsConstant())
2776 : Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002777}
2778
2779void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
2780 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01002781 Location index_loc = locations->InAt(0);
2782 Location length_loc = locations->InAt(1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002783
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01002784 if (length_loc.IsConstant()) {
2785 int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue();
2786 if (index_loc.IsConstant()) {
2787 int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue();
2788 if (index < 0 || index >= length) {
2789 BoundsCheckSlowPathMIPS64* slow_path =
2790 new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction);
2791 codegen_->AddSlowPath(slow_path);
2792 __ Bc(slow_path->GetEntryLabel());
2793 } else {
2794 // Nothing to be done.
2795 }
2796 return;
2797 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002798
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01002799 BoundsCheckSlowPathMIPS64* slow_path =
2800 new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction);
2801 codegen_->AddSlowPath(slow_path);
2802 GpuRegister index = index_loc.AsRegister<GpuRegister>();
2803 if (length == 0) {
2804 __ Bc(slow_path->GetEntryLabel());
2805 } else if (length == 1) {
2806 __ Bnezc(index, slow_path->GetEntryLabel());
2807 } else {
2808 DCHECK(IsUint<15>(length)) << length;
2809 __ Sltiu(TMP, index, length);
2810 __ Beqzc(TMP, slow_path->GetEntryLabel());
2811 }
2812 } else {
2813 GpuRegister length = length_loc.AsRegister<GpuRegister>();
2814 BoundsCheckSlowPathMIPS64* slow_path =
2815 new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction);
2816 codegen_->AddSlowPath(slow_path);
2817 if (index_loc.IsConstant()) {
2818 int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue();
2819 if (index < 0) {
2820 __ Bc(slow_path->GetEntryLabel());
2821 } else if (index == 0) {
2822 __ Blezc(length, slow_path->GetEntryLabel());
2823 } else {
2824 DCHECK(IsInt<16>(index + 1)) << index;
2825 __ Sltiu(TMP, length, index + 1);
2826 __ Bnezc(TMP, slow_path->GetEntryLabel());
2827 }
2828 } else {
2829 GpuRegister index = index_loc.AsRegister<GpuRegister>();
2830 __ Bgeuc(index, length, slow_path->GetEntryLabel());
2831 }
2832 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002833}
2834
Alexey Frunze15958152017-02-09 19:08:30 -08002835// Temp is used for read barrier.
2836static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) {
2837 if (kEmitCompilerReadBarrier &&
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002838 !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) &&
Alexey Frunze15958152017-02-09 19:08:30 -08002839 (kUseBakerReadBarrier ||
2840 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
2841 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
2842 type_check_kind == TypeCheckKind::kArrayObjectCheck)) {
2843 return 1;
2844 }
2845 return 0;
2846}
2847
2848// Extra temp is used for read barrier.
2849static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) {
2850 return 1 + NumberOfInstanceOfTemps(type_check_kind);
2851}
2852
Alexey Frunze4dda3372015-06-01 18:31:49 -07002853void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002854 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunzedfc30af2018-01-24 16:25:10 -08002855 LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction);
Vladimir Markoca6fff82017-10-03 14:49:14 +01002856 LocationSummary* locations =
2857 new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002858 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00002859 locations->SetInAt(1, Location::RequiresRegister());
Alexey Frunze15958152017-02-09 19:08:30 -08002860 locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002861}
2862
2863void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002864 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002865 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08002866 Location obj_loc = locations->InAt(0);
2867 GpuRegister obj = obj_loc.AsRegister<GpuRegister>();
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00002868 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
Alexey Frunze15958152017-02-09 19:08:30 -08002869 Location temp_loc = locations->GetTemp(0);
2870 GpuRegister temp = temp_loc.AsRegister<GpuRegister>();
2871 const size_t num_temps = NumberOfCheckCastTemps(type_check_kind);
2872 DCHECK_LE(num_temps, 2u);
2873 Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation();
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002874 const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2875 const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
2876 const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
2877 const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
2878 const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value();
2879 const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value();
2880 const uint32_t object_array_data_offset =
2881 mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value();
2882 Mips64Label done;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002883
Alexey Frunzedfc30af2018-01-24 16:25:10 -08002884 bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction);
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01002885 SlowPathCodeMIPS64* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01002886 new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64(
2887 instruction, is_type_check_slow_path_fatal);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002888 codegen_->AddSlowPath(slow_path);
2889
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002890 // Avoid this check if we know `obj` is not null.
2891 if (instruction->MustDoNullCheck()) {
2892 __ Beqzc(obj, &done);
2893 }
2894
2895 switch (type_check_kind) {
2896 case TypeCheckKind::kExactCheck:
2897 case TypeCheckKind::kArrayCheck: {
2898 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08002899 GenerateReferenceLoadTwoRegisters(instruction,
2900 temp_loc,
2901 obj_loc,
2902 class_offset,
2903 maybe_temp2_loc,
2904 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002905 // Jump to slow path for throwing the exception or doing a
2906 // more involved array check.
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00002907 __ Bnec(temp, cls, slow_path->GetEntryLabel());
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002908 break;
2909 }
2910
2911 case TypeCheckKind::kAbstractClassCheck: {
2912 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08002913 GenerateReferenceLoadTwoRegisters(instruction,
2914 temp_loc,
2915 obj_loc,
2916 class_offset,
2917 maybe_temp2_loc,
2918 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002919 // If the class is abstract, we eagerly fetch the super class of the
2920 // object to avoid doing a comparison we know will fail.
2921 Mips64Label loop;
2922 __ Bind(&loop);
2923 // /* HeapReference<Class> */ temp = temp->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08002924 GenerateReferenceLoadOneRegister(instruction,
2925 temp_loc,
2926 super_offset,
2927 maybe_temp2_loc,
2928 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002929 // If the class reference currently in `temp` is null, jump to the slow path to throw the
2930 // exception.
2931 __ Beqzc(temp, slow_path->GetEntryLabel());
2932 // Otherwise, compare the classes.
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00002933 __ Bnec(temp, cls, &loop);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002934 break;
2935 }
2936
2937 case TypeCheckKind::kClassHierarchyCheck: {
2938 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08002939 GenerateReferenceLoadTwoRegisters(instruction,
2940 temp_loc,
2941 obj_loc,
2942 class_offset,
2943 maybe_temp2_loc,
2944 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002945 // Walk over the class hierarchy to find a match.
2946 Mips64Label loop;
2947 __ Bind(&loop);
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00002948 __ Beqc(temp, cls, &done);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002949 // /* HeapReference<Class> */ temp = temp->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08002950 GenerateReferenceLoadOneRegister(instruction,
2951 temp_loc,
2952 super_offset,
2953 maybe_temp2_loc,
2954 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002955 // If the class reference currently in `temp` is null, jump to the slow path to throw the
2956 // exception. Otherwise, jump to the beginning of the loop.
2957 __ Bnezc(temp, &loop);
2958 __ Bc(slow_path->GetEntryLabel());
2959 break;
2960 }
2961
2962 case TypeCheckKind::kArrayObjectCheck: {
2963 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08002964 GenerateReferenceLoadTwoRegisters(instruction,
2965 temp_loc,
2966 obj_loc,
2967 class_offset,
2968 maybe_temp2_loc,
2969 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002970 // Do an exact check.
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00002971 __ Beqc(temp, cls, &done);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002972 // Otherwise, we need to check that the object's class is a non-primitive array.
2973 // /* HeapReference<Class> */ temp = temp->component_type_
Alexey Frunze15958152017-02-09 19:08:30 -08002974 GenerateReferenceLoadOneRegister(instruction,
2975 temp_loc,
2976 component_offset,
2977 maybe_temp2_loc,
2978 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002979 // If the component type is null, jump to the slow path to throw the exception.
2980 __ Beqzc(temp, slow_path->GetEntryLabel());
2981 // Otherwise, the object is indeed an array, further check that this component
2982 // type is not a primitive type.
2983 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
2984 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
2985 __ Bnezc(temp, slow_path->GetEntryLabel());
2986 break;
2987 }
2988
2989 case TypeCheckKind::kUnresolvedCheck:
2990 // We always go into the type check slow path for the unresolved check case.
2991 // We cannot directly call the CheckCast runtime entry point
2992 // without resorting to a type checking slow path here (i.e. by
2993 // calling InvokeRuntime directly), as it would require to
2994 // assign fixed registers for the inputs of this HInstanceOf
2995 // instruction (following the runtime calling convention), which
2996 // might be cluttered by the potential first read barrier
2997 // emission at the beginning of this method.
2998 __ Bc(slow_path->GetEntryLabel());
2999 break;
3000
3001 case TypeCheckKind::kInterfaceCheck: {
3002 // Avoid read barriers to improve performance of the fast path. We can not get false
3003 // positives by doing this.
3004 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003005 GenerateReferenceLoadTwoRegisters(instruction,
3006 temp_loc,
3007 obj_loc,
3008 class_offset,
3009 maybe_temp2_loc,
3010 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003011 // /* HeapReference<Class> */ temp = temp->iftable_
Alexey Frunze15958152017-02-09 19:08:30 -08003012 GenerateReferenceLoadTwoRegisters(instruction,
3013 temp_loc,
3014 temp_loc,
3015 iftable_offset,
3016 maybe_temp2_loc,
3017 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003018 // Iftable is never null.
3019 __ Lw(TMP, temp, array_length_offset);
3020 // Loop through the iftable and check if any class matches.
3021 Mips64Label loop;
3022 __ Bind(&loop);
3023 __ Beqzc(TMP, slow_path->GetEntryLabel());
3024 __ Lwu(AT, temp, object_array_data_offset);
3025 __ MaybeUnpoisonHeapReference(AT);
3026 // Go to next interface.
3027 __ Daddiu(temp, temp, 2 * kHeapReferenceSize);
3028 __ Addiu(TMP, TMP, -2);
3029 // Compare the classes and continue the loop if they do not match.
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00003030 __ Bnec(AT, cls, &loop);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003031 break;
3032 }
3033 }
3034
3035 __ Bind(&done);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003036 __ Bind(slow_path->GetExitLabel());
3037}
3038
3039void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) {
3040 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003041 new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003042 locations->SetInAt(0, Location::RequiresRegister());
3043 if (check->HasUses()) {
3044 locations->SetOut(Location::SameAsFirstInput());
3045 }
3046}
3047
3048void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) {
3049 // We assume the class is not null.
Vladimir Marko174b2e22017-10-12 13:34:49 +01003050 SlowPathCodeMIPS64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64(
Alexey Frunze4dda3372015-06-01 18:31:49 -07003051 check->GetLoadClass(),
3052 check,
3053 check->GetDexPc(),
3054 true);
3055 codegen_->AddSlowPath(slow_path);
3056 GenerateClassInitializationCheck(slow_path,
3057 check->GetLocations()->InAt(0).AsRegister<GpuRegister>());
3058}
3059
3060void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003061 DataType::Type in_type = compare->InputAt(0)->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003062
Vladimir Markoca6fff82017-10-03 14:49:14 +01003063 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(compare);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003064
3065 switch (in_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003066 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003067 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003068 case DataType::Type::kInt8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003069 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003070 case DataType::Type::kInt16:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003071 case DataType::Type::kInt32:
3072 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07003073 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07003074 locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003075 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3076 break;
3077
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003078 case DataType::Type::kFloat32:
3079 case DataType::Type::kFloat64:
Alexey Frunze299a9392015-12-08 16:08:02 -08003080 locations->SetInAt(0, Location::RequiresFpuRegister());
3081 locations->SetInAt(1, Location::RequiresFpuRegister());
3082 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003083 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003084
3085 default:
3086 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
3087 }
3088}
3089
3090void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) {
3091 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze299a9392015-12-08 16:08:02 -08003092 GpuRegister res = locations->Out().AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003093 DataType::Type in_type = instruction->InputAt(0)->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003094
3095 // 0 if: left == right
3096 // 1 if: left > right
3097 // -1 if: left < right
3098 switch (in_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003099 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003100 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003101 case DataType::Type::kInt8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003102 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003103 case DataType::Type::kInt16:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003104 case DataType::Type::kInt32:
3105 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003106 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07003107 Location rhs_location = locations->InAt(1);
3108 bool use_imm = rhs_location.IsConstant();
3109 GpuRegister rhs = ZERO;
3110 if (use_imm) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003111 if (in_type == DataType::Type::kInt64) {
Aart Bika19616e2016-02-01 18:57:58 -08003112 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
3113 if (value != 0) {
3114 rhs = AT;
3115 __ LoadConst64(rhs, value);
3116 }
Roland Levillaina5c4a402016-03-15 15:02:50 +00003117 } else {
3118 int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant());
3119 if (value != 0) {
3120 rhs = AT;
3121 __ LoadConst32(rhs, value);
3122 }
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07003123 }
3124 } else {
3125 rhs = rhs_location.AsRegister<GpuRegister>();
3126 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003127 __ Slt(TMP, lhs, rhs);
Alexey Frunze299a9392015-12-08 16:08:02 -08003128 __ Slt(res, rhs, lhs);
3129 __ Subu(res, res, TMP);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003130 break;
3131 }
3132
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003133 case DataType::Type::kFloat32: {
Alexey Frunze299a9392015-12-08 16:08:02 -08003134 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
3135 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
3136 Mips64Label done;
3137 __ CmpEqS(FTMP, lhs, rhs);
3138 __ LoadConst32(res, 0);
3139 __ Bc1nez(FTMP, &done);
Roland Levillain32ca3752016-02-17 16:49:37 +00003140 if (instruction->IsGtBias()) {
Alexey Frunze299a9392015-12-08 16:08:02 -08003141 __ CmpLtS(FTMP, lhs, rhs);
3142 __ LoadConst32(res, -1);
3143 __ Bc1nez(FTMP, &done);
3144 __ LoadConst32(res, 1);
3145 } else {
3146 __ CmpLtS(FTMP, rhs, lhs);
3147 __ LoadConst32(res, 1);
3148 __ Bc1nez(FTMP, &done);
3149 __ LoadConst32(res, -1);
3150 }
3151 __ Bind(&done);
3152 break;
3153 }
3154
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003155 case DataType::Type::kFloat64: {
Alexey Frunze299a9392015-12-08 16:08:02 -08003156 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
3157 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
3158 Mips64Label done;
3159 __ CmpEqD(FTMP, lhs, rhs);
3160 __ LoadConst32(res, 0);
3161 __ Bc1nez(FTMP, &done);
Roland Levillain32ca3752016-02-17 16:49:37 +00003162 if (instruction->IsGtBias()) {
Alexey Frunze299a9392015-12-08 16:08:02 -08003163 __ CmpLtD(FTMP, lhs, rhs);
3164 __ LoadConst32(res, -1);
3165 __ Bc1nez(FTMP, &done);
3166 __ LoadConst32(res, 1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003167 } else {
Alexey Frunze299a9392015-12-08 16:08:02 -08003168 __ CmpLtD(FTMP, rhs, lhs);
3169 __ LoadConst32(res, 1);
3170 __ Bc1nez(FTMP, &done);
3171 __ LoadConst32(res, -1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003172 }
Alexey Frunze299a9392015-12-08 16:08:02 -08003173 __ Bind(&done);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003174 break;
3175 }
3176
3177 default:
3178 LOG(FATAL) << "Unimplemented compare type " << in_type;
3179 }
3180}
3181
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00003182void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01003183 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunze299a9392015-12-08 16:08:02 -08003184 switch (instruction->InputAt(0)->GetType()) {
3185 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003186 case DataType::Type::kInt64:
Alexey Frunze299a9392015-12-08 16:08:02 -08003187 locations->SetInAt(0, Location::RequiresRegister());
3188 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3189 break;
3190
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003191 case DataType::Type::kFloat32:
3192 case DataType::Type::kFloat64:
Alexey Frunze299a9392015-12-08 16:08:02 -08003193 locations->SetInAt(0, Location::RequiresFpuRegister());
3194 locations->SetInAt(1, Location::RequiresFpuRegister());
3195 break;
3196 }
David Brazdilb3e773e2016-01-26 11:28:37 +00003197 if (!instruction->IsEmittedAtUseSite()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003198 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3199 }
3200}
3201
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00003202void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00003203 if (instruction->IsEmittedAtUseSite()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003204 return;
3205 }
3206
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003207 DataType::Type type = instruction->InputAt(0)->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003208 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze299a9392015-12-08 16:08:02 -08003209 switch (type) {
3210 default:
3211 // Integer case.
3212 GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations);
3213 return;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003214 case DataType::Type::kInt64:
Alexey Frunze299a9392015-12-08 16:08:02 -08003215 GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations);
3216 return;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003217 case DataType::Type::kFloat32:
3218 case DataType::Type::kFloat64:
Tijana Jakovljevic43758192016-12-30 09:23:01 +01003219 GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations);
3220 return;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003221 }
3222}
3223
Alexey Frunzec857c742015-09-23 15:12:39 -07003224void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
3225 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003226 DataType::Type type = instruction->GetResultType();
Alexey Frunzec857c742015-09-23 15:12:39 -07003227
3228 LocationSummary* locations = instruction->GetLocations();
3229 Location second = locations->InAt(1);
3230 DCHECK(second.IsConstant());
3231
3232 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3233 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
3234 int64_t imm = Int64FromConstant(second.GetConstant());
3235 DCHECK(imm == 1 || imm == -1);
3236
3237 if (instruction->IsRem()) {
3238 __ Move(out, ZERO);
3239 } else {
3240 if (imm == -1) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003241 if (type == DataType::Type::kInt32) {
Alexey Frunzec857c742015-09-23 15:12:39 -07003242 __ Subu(out, ZERO, dividend);
3243 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003244 DCHECK_EQ(type, DataType::Type::kInt64);
Alexey Frunzec857c742015-09-23 15:12:39 -07003245 __ Dsubu(out, ZERO, dividend);
3246 }
3247 } else if (out != dividend) {
3248 __ Move(out, dividend);
3249 }
3250 }
3251}
3252
3253void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
3254 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003255 DataType::Type type = instruction->GetResultType();
Alexey Frunzec857c742015-09-23 15:12:39 -07003256
3257 LocationSummary* locations = instruction->GetLocations();
3258 Location second = locations->InAt(1);
3259 DCHECK(second.IsConstant());
3260
3261 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3262 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
3263 int64_t imm = Int64FromConstant(second.GetConstant());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003264 uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm));
Alexey Frunzec857c742015-09-23 15:12:39 -07003265 int ctz_imm = CTZ(abs_imm);
3266
3267 if (instruction->IsDiv()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003268 if (type == DataType::Type::kInt32) {
Alexey Frunzec857c742015-09-23 15:12:39 -07003269 if (ctz_imm == 1) {
3270 // Fast path for division by +/-2, which is very common.
3271 __ Srl(TMP, dividend, 31);
3272 } else {
3273 __ Sra(TMP, dividend, 31);
3274 __ Srl(TMP, TMP, 32 - ctz_imm);
3275 }
3276 __ Addu(out, dividend, TMP);
3277 __ Sra(out, out, ctz_imm);
3278 if (imm < 0) {
3279 __ Subu(out, ZERO, out);
3280 }
3281 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003282 DCHECK_EQ(type, DataType::Type::kInt64);
Alexey Frunzec857c742015-09-23 15:12:39 -07003283 if (ctz_imm == 1) {
3284 // Fast path for division by +/-2, which is very common.
3285 __ Dsrl32(TMP, dividend, 31);
3286 } else {
3287 __ Dsra32(TMP, dividend, 31);
3288 if (ctz_imm > 32) {
3289 __ Dsrl(TMP, TMP, 64 - ctz_imm);
3290 } else {
3291 __ Dsrl32(TMP, TMP, 32 - ctz_imm);
3292 }
3293 }
3294 __ Daddu(out, dividend, TMP);
3295 if (ctz_imm < 32) {
3296 __ Dsra(out, out, ctz_imm);
3297 } else {
3298 __ Dsra32(out, out, ctz_imm - 32);
3299 }
3300 if (imm < 0) {
3301 __ Dsubu(out, ZERO, out);
3302 }
3303 }
3304 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003305 if (type == DataType::Type::kInt32) {
Alexey Frunzec857c742015-09-23 15:12:39 -07003306 if (ctz_imm == 1) {
3307 // Fast path for modulo +/-2, which is very common.
3308 __ Sra(TMP, dividend, 31);
3309 __ Subu(out, dividend, TMP);
3310 __ Andi(out, out, 1);
3311 __ Addu(out, out, TMP);
3312 } else {
3313 __ Sra(TMP, dividend, 31);
3314 __ Srl(TMP, TMP, 32 - ctz_imm);
3315 __ Addu(out, dividend, TMP);
Lena Djokica556e6b2017-12-13 12:09:42 +01003316 __ Ins(out, ZERO, ctz_imm, 32 - ctz_imm);
Alexey Frunzec857c742015-09-23 15:12:39 -07003317 __ Subu(out, out, TMP);
3318 }
3319 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003320 DCHECK_EQ(type, DataType::Type::kInt64);
Alexey Frunzec857c742015-09-23 15:12:39 -07003321 if (ctz_imm == 1) {
3322 // Fast path for modulo +/-2, which is very common.
3323 __ Dsra32(TMP, dividend, 31);
3324 __ Dsubu(out, dividend, TMP);
3325 __ Andi(out, out, 1);
3326 __ Daddu(out, out, TMP);
3327 } else {
3328 __ Dsra32(TMP, dividend, 31);
3329 if (ctz_imm > 32) {
3330 __ Dsrl(TMP, TMP, 64 - ctz_imm);
3331 } else {
3332 __ Dsrl32(TMP, TMP, 32 - ctz_imm);
3333 }
3334 __ Daddu(out, dividend, TMP);
Lena Djokica556e6b2017-12-13 12:09:42 +01003335 __ DblIns(out, ZERO, ctz_imm, 64 - ctz_imm);
Alexey Frunzec857c742015-09-23 15:12:39 -07003336 __ Dsubu(out, out, TMP);
3337 }
3338 }
3339 }
3340}
3341
3342void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
3343 DCHECK(instruction->IsDiv() || instruction->IsRem());
3344
3345 LocationSummary* locations = instruction->GetLocations();
3346 Location second = locations->InAt(1);
3347 DCHECK(second.IsConstant());
3348
3349 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3350 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
3351 int64_t imm = Int64FromConstant(second.GetConstant());
3352
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003353 DataType::Type type = instruction->GetResultType();
3354 DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type;
Alexey Frunzec857c742015-09-23 15:12:39 -07003355
3356 int64_t magic;
3357 int shift;
3358 CalculateMagicAndShiftForDivRem(imm,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003359 (type == DataType::Type::kInt64),
Alexey Frunzec857c742015-09-23 15:12:39 -07003360 &magic,
3361 &shift);
3362
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003363 if (type == DataType::Type::kInt32) {
Alexey Frunzec857c742015-09-23 15:12:39 -07003364 __ LoadConst32(TMP, magic);
3365 __ MuhR6(TMP, dividend, TMP);
3366
3367 if (imm > 0 && magic < 0) {
3368 __ Addu(TMP, TMP, dividend);
3369 } else if (imm < 0 && magic > 0) {
3370 __ Subu(TMP, TMP, dividend);
3371 }
3372
3373 if (shift != 0) {
3374 __ Sra(TMP, TMP, shift);
3375 }
3376
3377 if (instruction->IsDiv()) {
3378 __ Sra(out, TMP, 31);
3379 __ Subu(out, TMP, out);
3380 } else {
3381 __ Sra(AT, TMP, 31);
3382 __ Subu(AT, TMP, AT);
3383 __ LoadConst32(TMP, imm);
3384 __ MulR6(TMP, AT, TMP);
3385 __ Subu(out, dividend, TMP);
3386 }
3387 } else {
3388 __ LoadConst64(TMP, magic);
3389 __ Dmuh(TMP, dividend, TMP);
3390
3391 if (imm > 0 && magic < 0) {
3392 __ Daddu(TMP, TMP, dividend);
3393 } else if (imm < 0 && magic > 0) {
3394 __ Dsubu(TMP, TMP, dividend);
3395 }
3396
3397 if (shift >= 32) {
3398 __ Dsra32(TMP, TMP, shift - 32);
3399 } else if (shift > 0) {
3400 __ Dsra(TMP, TMP, shift);
3401 }
3402
3403 if (instruction->IsDiv()) {
3404 __ Dsra32(out, TMP, 31);
3405 __ Dsubu(out, TMP, out);
3406 } else {
3407 __ Dsra32(AT, TMP, 31);
3408 __ Dsubu(AT, TMP, AT);
3409 __ LoadConst64(TMP, imm);
3410 __ Dmul(TMP, AT, TMP);
3411 __ Dsubu(out, dividend, TMP);
3412 }
3413 }
3414}
3415
3416void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) {
3417 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003418 DataType::Type type = instruction->GetResultType();
3419 DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type;
Alexey Frunzec857c742015-09-23 15:12:39 -07003420
3421 LocationSummary* locations = instruction->GetLocations();
3422 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3423 Location second = locations->InAt(1);
3424
3425 if (second.IsConstant()) {
3426 int64_t imm = Int64FromConstant(second.GetConstant());
3427 if (imm == 0) {
3428 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
3429 } else if (imm == 1 || imm == -1) {
3430 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003431 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunzec857c742015-09-23 15:12:39 -07003432 DivRemByPowerOfTwo(instruction);
3433 } else {
3434 DCHECK(imm <= -2 || imm >= 2);
3435 GenerateDivRemWithAnyConstant(instruction);
3436 }
3437 } else {
3438 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
3439 GpuRegister divisor = second.AsRegister<GpuRegister>();
3440 if (instruction->IsDiv()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003441 if (type == DataType::Type::kInt32)
Alexey Frunzec857c742015-09-23 15:12:39 -07003442 __ DivR6(out, dividend, divisor);
3443 else
3444 __ Ddiv(out, dividend, divisor);
3445 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003446 if (type == DataType::Type::kInt32)
Alexey Frunzec857c742015-09-23 15:12:39 -07003447 __ ModR6(out, dividend, divisor);
3448 else
3449 __ Dmod(out, dividend, divisor);
3450 }
3451 }
3452}
3453
Alexey Frunze4dda3372015-06-01 18:31:49 -07003454void LocationsBuilderMIPS64::VisitDiv(HDiv* div) {
3455 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003456 new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003457 switch (div->GetResultType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003458 case DataType::Type::kInt32:
3459 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07003460 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunzec857c742015-09-23 15:12:39 -07003461 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003462 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3463 break;
3464
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003465 case DataType::Type::kFloat32:
3466 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07003467 locations->SetInAt(0, Location::RequiresFpuRegister());
3468 locations->SetInAt(1, Location::RequiresFpuRegister());
3469 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3470 break;
3471
3472 default:
3473 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
3474 }
3475}
3476
3477void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003478 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003479 LocationSummary* locations = instruction->GetLocations();
3480
3481 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003482 case DataType::Type::kInt32:
3483 case DataType::Type::kInt64:
Alexey Frunzec857c742015-09-23 15:12:39 -07003484 GenerateDivRemIntegral(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003485 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003486 case DataType::Type::kFloat32:
3487 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003488 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3489 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
3490 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003491 if (type == DataType::Type::kFloat32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07003492 __ DivS(dst, lhs, rhs);
3493 else
3494 __ DivD(dst, lhs, rhs);
3495 break;
3496 }
3497 default:
3498 LOG(FATAL) << "Unexpected div type " << type;
3499 }
3500}
3501
3502void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01003503 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003504 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003505}
3506
3507void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
3508 SlowPathCodeMIPS64* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01003509 new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003510 codegen_->AddSlowPath(slow_path);
3511 Location value = instruction->GetLocations()->InAt(0);
3512
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003513 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003514
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003515 if (!DataType::IsIntegralType(type)) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00003516 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
Serguei Katkov8c0676c2015-08-03 13:55:33 +06003517 return;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003518 }
3519
3520 if (value.IsConstant()) {
3521 int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant());
3522 if (divisor == 0) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003523 __ Bc(slow_path->GetEntryLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003524 } else {
3525 // A division by a non-null constant is valid. We don't need to perform
3526 // any check, so simply fall through.
3527 }
3528 } else {
3529 __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
3530 }
3531}
3532
3533void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) {
3534 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003535 new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003536 locations->SetOut(Location::ConstantLocation(constant));
3537}
3538
3539void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
3540 // Will be generated at use site.
3541}
3542
3543void LocationsBuilderMIPS64::VisitExit(HExit* exit) {
3544 exit->SetLocations(nullptr);
3545}
3546
3547void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
3548}
3549
3550void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) {
3551 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003552 new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003553 locations->SetOut(Location::ConstantLocation(constant));
3554}
3555
3556void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
3557 // Will be generated at use site.
3558}
3559
David Brazdilfc6a86a2015-06-26 10:33:45 +00003560void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Aart Bika8b8e9b2018-01-09 11:01:02 -08003561 if (successor->IsExitBlock()) {
3562 DCHECK(got->GetPrevious()->AlwaysThrows());
3563 return; // no code needed
3564 }
3565
Alexey Frunze4dda3372015-06-01 18:31:49 -07003566 HBasicBlock* block = got->GetBlock();
3567 HInstruction* previous = got->GetPrevious();
3568 HLoopInformation* info = block->GetLoopInformation();
3569
3570 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Goran Jakovljevicfeec1672018-02-08 10:20:14 +01003571 if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) {
3572 __ Ld(AT, SP, kCurrentMethodStackOffset);
3573 __ Lhu(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value());
3574 __ Addiu(TMP, TMP, 1);
3575 __ Sh(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value());
3576 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003577 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
3578 return;
3579 }
3580 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
3581 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
3582 }
3583 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003584 __ Bc(codegen_->GetLabelOf(successor));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003585 }
3586}
3587
David Brazdilfc6a86a2015-06-26 10:33:45 +00003588void LocationsBuilderMIPS64::VisitGoto(HGoto* got) {
3589 got->SetLocations(nullptr);
3590}
3591
3592void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) {
3593 HandleGoto(got, got->GetSuccessor());
3594}
3595
3596void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
3597 try_boundary->SetLocations(nullptr);
3598}
3599
3600void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
3601 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
3602 if (!successor->IsExitBlock()) {
3603 HandleGoto(try_boundary, successor);
3604 }
3605}
3606
Alexey Frunze299a9392015-12-08 16:08:02 -08003607void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond,
3608 bool is64bit,
3609 LocationSummary* locations) {
3610 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3611 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
3612 Location rhs_location = locations->InAt(1);
3613 GpuRegister rhs_reg = ZERO;
3614 int64_t rhs_imm = 0;
3615 bool use_imm = rhs_location.IsConstant();
3616 if (use_imm) {
3617 if (is64bit) {
3618 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
3619 } else {
3620 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
3621 }
3622 } else {
3623 rhs_reg = rhs_location.AsRegister<GpuRegister>();
3624 }
3625 int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1);
3626
3627 switch (cond) {
3628 case kCondEQ:
3629 case kCondNE:
Goran Jakovljevicdb3deee2016-12-28 14:33:21 +01003630 if (use_imm && IsInt<16>(-rhs_imm)) {
3631 if (rhs_imm == 0) {
3632 if (cond == kCondEQ) {
3633 __ Sltiu(dst, lhs, 1);
3634 } else {
3635 __ Sltu(dst, ZERO, lhs);
3636 }
3637 } else {
3638 if (is64bit) {
3639 __ Daddiu(dst, lhs, -rhs_imm);
3640 } else {
3641 __ Addiu(dst, lhs, -rhs_imm);
3642 }
3643 if (cond == kCondEQ) {
3644 __ Sltiu(dst, dst, 1);
3645 } else {
3646 __ Sltu(dst, ZERO, dst);
3647 }
Alexey Frunze299a9392015-12-08 16:08:02 -08003648 }
Alexey Frunze299a9392015-12-08 16:08:02 -08003649 } else {
Goran Jakovljevicdb3deee2016-12-28 14:33:21 +01003650 if (use_imm && IsUint<16>(rhs_imm)) {
3651 __ Xori(dst, lhs, rhs_imm);
3652 } else {
3653 if (use_imm) {
3654 rhs_reg = TMP;
3655 __ LoadConst64(rhs_reg, rhs_imm);
3656 }
3657 __ Xor(dst, lhs, rhs_reg);
3658 }
3659 if (cond == kCondEQ) {
3660 __ Sltiu(dst, dst, 1);
3661 } else {
3662 __ Sltu(dst, ZERO, dst);
3663 }
Alexey Frunze299a9392015-12-08 16:08:02 -08003664 }
3665 break;
3666
3667 case kCondLT:
3668 case kCondGE:
3669 if (use_imm && IsInt<16>(rhs_imm)) {
3670 __ Slti(dst, lhs, rhs_imm);
3671 } else {
3672 if (use_imm) {
3673 rhs_reg = TMP;
3674 __ LoadConst64(rhs_reg, rhs_imm);
3675 }
3676 __ Slt(dst, lhs, rhs_reg);
3677 }
3678 if (cond == kCondGE) {
3679 // Simulate lhs >= rhs via !(lhs < rhs) since there's
3680 // only the slt instruction but no sge.
3681 __ Xori(dst, dst, 1);
3682 }
3683 break;
3684
3685 case kCondLE:
3686 case kCondGT:
3687 if (use_imm && IsInt<16>(rhs_imm_plus_one)) {
3688 // Simulate lhs <= rhs via lhs < rhs + 1.
3689 __ Slti(dst, lhs, rhs_imm_plus_one);
3690 if (cond == kCondGT) {
3691 // Simulate lhs > rhs via !(lhs <= rhs) since there's
3692 // only the slti instruction but no sgti.
3693 __ Xori(dst, dst, 1);
3694 }
3695 } else {
3696 if (use_imm) {
3697 rhs_reg = TMP;
3698 __ LoadConst64(rhs_reg, rhs_imm);
3699 }
3700 __ Slt(dst, rhs_reg, lhs);
3701 if (cond == kCondLE) {
3702 // Simulate lhs <= rhs via !(rhs < lhs) since there's
3703 // only the slt instruction but no sle.
3704 __ Xori(dst, dst, 1);
3705 }
3706 }
3707 break;
3708
3709 case kCondB:
3710 case kCondAE:
3711 if (use_imm && IsInt<16>(rhs_imm)) {
3712 // Sltiu sign-extends its 16-bit immediate operand before
3713 // the comparison and thus lets us compare directly with
3714 // unsigned values in the ranges [0, 0x7fff] and
3715 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
3716 __ Sltiu(dst, lhs, rhs_imm);
3717 } else {
3718 if (use_imm) {
3719 rhs_reg = TMP;
3720 __ LoadConst64(rhs_reg, rhs_imm);
3721 }
3722 __ Sltu(dst, lhs, rhs_reg);
3723 }
3724 if (cond == kCondAE) {
3725 // Simulate lhs >= rhs via !(lhs < rhs) since there's
3726 // only the sltu instruction but no sgeu.
3727 __ Xori(dst, dst, 1);
3728 }
3729 break;
3730
3731 case kCondBE:
3732 case kCondA:
3733 if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) {
3734 // Simulate lhs <= rhs via lhs < rhs + 1.
3735 // Note that this only works if rhs + 1 does not overflow
3736 // to 0, hence the check above.
3737 // Sltiu sign-extends its 16-bit immediate operand before
3738 // the comparison and thus lets us compare directly with
3739 // unsigned values in the ranges [0, 0x7fff] and
3740 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
3741 __ Sltiu(dst, lhs, rhs_imm_plus_one);
3742 if (cond == kCondA) {
3743 // Simulate lhs > rhs via !(lhs <= rhs) since there's
3744 // only the sltiu instruction but no sgtiu.
3745 __ Xori(dst, dst, 1);
3746 }
3747 } else {
3748 if (use_imm) {
3749 rhs_reg = TMP;
3750 __ LoadConst64(rhs_reg, rhs_imm);
3751 }
3752 __ Sltu(dst, rhs_reg, lhs);
3753 if (cond == kCondBE) {
3754 // Simulate lhs <= rhs via !(rhs < lhs) since there's
3755 // only the sltu instruction but no sleu.
3756 __ Xori(dst, dst, 1);
3757 }
3758 }
3759 break;
3760 }
3761}
3762
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02003763bool InstructionCodeGeneratorMIPS64::MaterializeIntLongCompare(IfCondition cond,
3764 bool is64bit,
3765 LocationSummary* input_locations,
3766 GpuRegister dst) {
3767 GpuRegister lhs = input_locations->InAt(0).AsRegister<GpuRegister>();
3768 Location rhs_location = input_locations->InAt(1);
3769 GpuRegister rhs_reg = ZERO;
3770 int64_t rhs_imm = 0;
3771 bool use_imm = rhs_location.IsConstant();
3772 if (use_imm) {
3773 if (is64bit) {
3774 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
3775 } else {
3776 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
3777 }
3778 } else {
3779 rhs_reg = rhs_location.AsRegister<GpuRegister>();
3780 }
3781 int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1);
3782
3783 switch (cond) {
3784 case kCondEQ:
3785 case kCondNE:
3786 if (use_imm && IsInt<16>(-rhs_imm)) {
3787 if (is64bit) {
3788 __ Daddiu(dst, lhs, -rhs_imm);
3789 } else {
3790 __ Addiu(dst, lhs, -rhs_imm);
3791 }
3792 } else if (use_imm && IsUint<16>(rhs_imm)) {
3793 __ Xori(dst, lhs, rhs_imm);
3794 } else {
3795 if (use_imm) {
3796 rhs_reg = TMP;
3797 __ LoadConst64(rhs_reg, rhs_imm);
3798 }
3799 __ Xor(dst, lhs, rhs_reg);
3800 }
3801 return (cond == kCondEQ);
3802
3803 case kCondLT:
3804 case kCondGE:
3805 if (use_imm && IsInt<16>(rhs_imm)) {
3806 __ Slti(dst, lhs, rhs_imm);
3807 } else {
3808 if (use_imm) {
3809 rhs_reg = TMP;
3810 __ LoadConst64(rhs_reg, rhs_imm);
3811 }
3812 __ Slt(dst, lhs, rhs_reg);
3813 }
3814 return (cond == kCondGE);
3815
3816 case kCondLE:
3817 case kCondGT:
3818 if (use_imm && IsInt<16>(rhs_imm_plus_one)) {
3819 // Simulate lhs <= rhs via lhs < rhs + 1.
3820 __ Slti(dst, lhs, rhs_imm_plus_one);
3821 return (cond == kCondGT);
3822 } else {
3823 if (use_imm) {
3824 rhs_reg = TMP;
3825 __ LoadConst64(rhs_reg, rhs_imm);
3826 }
3827 __ Slt(dst, rhs_reg, lhs);
3828 return (cond == kCondLE);
3829 }
3830
3831 case kCondB:
3832 case kCondAE:
3833 if (use_imm && IsInt<16>(rhs_imm)) {
3834 // Sltiu sign-extends its 16-bit immediate operand before
3835 // the comparison and thus lets us compare directly with
3836 // unsigned values in the ranges [0, 0x7fff] and
3837 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
3838 __ Sltiu(dst, lhs, rhs_imm);
3839 } else {
3840 if (use_imm) {
3841 rhs_reg = TMP;
3842 __ LoadConst64(rhs_reg, rhs_imm);
3843 }
3844 __ Sltu(dst, lhs, rhs_reg);
3845 }
3846 return (cond == kCondAE);
3847
3848 case kCondBE:
3849 case kCondA:
3850 if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) {
3851 // Simulate lhs <= rhs via lhs < rhs + 1.
3852 // Note that this only works if rhs + 1 does not overflow
3853 // to 0, hence the check above.
3854 // Sltiu sign-extends its 16-bit immediate operand before
3855 // the comparison and thus lets us compare directly with
3856 // unsigned values in the ranges [0, 0x7fff] and
3857 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
3858 __ Sltiu(dst, lhs, rhs_imm_plus_one);
3859 return (cond == kCondA);
3860 } else {
3861 if (use_imm) {
3862 rhs_reg = TMP;
3863 __ LoadConst64(rhs_reg, rhs_imm);
3864 }
3865 __ Sltu(dst, rhs_reg, lhs);
3866 return (cond == kCondBE);
3867 }
3868 }
3869}
3870
Alexey Frunze299a9392015-12-08 16:08:02 -08003871void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond,
3872 bool is64bit,
3873 LocationSummary* locations,
3874 Mips64Label* label) {
3875 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
3876 Location rhs_location = locations->InAt(1);
3877 GpuRegister rhs_reg = ZERO;
3878 int64_t rhs_imm = 0;
3879 bool use_imm = rhs_location.IsConstant();
3880 if (use_imm) {
3881 if (is64bit) {
3882 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
3883 } else {
3884 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
3885 }
3886 } else {
3887 rhs_reg = rhs_location.AsRegister<GpuRegister>();
3888 }
3889
3890 if (use_imm && rhs_imm == 0) {
3891 switch (cond) {
3892 case kCondEQ:
3893 case kCondBE: // <= 0 if zero
3894 __ Beqzc(lhs, label);
3895 break;
3896 case kCondNE:
3897 case kCondA: // > 0 if non-zero
3898 __ Bnezc(lhs, label);
3899 break;
3900 case kCondLT:
3901 __ Bltzc(lhs, label);
3902 break;
3903 case kCondGE:
3904 __ Bgezc(lhs, label);
3905 break;
3906 case kCondLE:
3907 __ Blezc(lhs, label);
3908 break;
3909 case kCondGT:
3910 __ Bgtzc(lhs, label);
3911 break;
3912 case kCondB: // always false
3913 break;
3914 case kCondAE: // always true
3915 __ Bc(label);
3916 break;
3917 }
3918 } else {
3919 if (use_imm) {
3920 rhs_reg = TMP;
3921 __ LoadConst64(rhs_reg, rhs_imm);
3922 }
3923 switch (cond) {
3924 case kCondEQ:
3925 __ Beqc(lhs, rhs_reg, label);
3926 break;
3927 case kCondNE:
3928 __ Bnec(lhs, rhs_reg, label);
3929 break;
3930 case kCondLT:
3931 __ Bltc(lhs, rhs_reg, label);
3932 break;
3933 case kCondGE:
3934 __ Bgec(lhs, rhs_reg, label);
3935 break;
3936 case kCondLE:
3937 __ Bgec(rhs_reg, lhs, label);
3938 break;
3939 case kCondGT:
3940 __ Bltc(rhs_reg, lhs, label);
3941 break;
3942 case kCondB:
3943 __ Bltuc(lhs, rhs_reg, label);
3944 break;
3945 case kCondAE:
3946 __ Bgeuc(lhs, rhs_reg, label);
3947 break;
3948 case kCondBE:
3949 __ Bgeuc(rhs_reg, lhs, label);
3950 break;
3951 case kCondA:
3952 __ Bltuc(rhs_reg, lhs, label);
3953 break;
3954 }
3955 }
3956}
3957
Tijana Jakovljevic43758192016-12-30 09:23:01 +01003958void InstructionCodeGeneratorMIPS64::GenerateFpCompare(IfCondition cond,
3959 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003960 DataType::Type type,
Tijana Jakovljevic43758192016-12-30 09:23:01 +01003961 LocationSummary* locations) {
3962 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3963 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
3964 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003965 if (type == DataType::Type::kFloat32) {
Tijana Jakovljevic43758192016-12-30 09:23:01 +01003966 switch (cond) {
3967 case kCondEQ:
3968 __ CmpEqS(FTMP, lhs, rhs);
3969 __ Mfc1(dst, FTMP);
3970 __ Andi(dst, dst, 1);
3971 break;
3972 case kCondNE:
3973 __ CmpEqS(FTMP, lhs, rhs);
3974 __ Mfc1(dst, FTMP);
3975 __ Addiu(dst, dst, 1);
3976 break;
3977 case kCondLT:
3978 if (gt_bias) {
3979 __ CmpLtS(FTMP, lhs, rhs);
3980 } else {
3981 __ CmpUltS(FTMP, lhs, rhs);
3982 }
3983 __ Mfc1(dst, FTMP);
3984 __ Andi(dst, dst, 1);
3985 break;
3986 case kCondLE:
3987 if (gt_bias) {
3988 __ CmpLeS(FTMP, lhs, rhs);
3989 } else {
3990 __ CmpUleS(FTMP, lhs, rhs);
3991 }
3992 __ Mfc1(dst, FTMP);
3993 __ Andi(dst, dst, 1);
3994 break;
3995 case kCondGT:
3996 if (gt_bias) {
3997 __ CmpUltS(FTMP, rhs, lhs);
3998 } else {
3999 __ CmpLtS(FTMP, rhs, lhs);
4000 }
4001 __ Mfc1(dst, FTMP);
4002 __ Andi(dst, dst, 1);
4003 break;
4004 case kCondGE:
4005 if (gt_bias) {
4006 __ CmpUleS(FTMP, rhs, lhs);
4007 } else {
4008 __ CmpLeS(FTMP, rhs, lhs);
4009 }
4010 __ Mfc1(dst, FTMP);
4011 __ Andi(dst, dst, 1);
4012 break;
4013 default:
4014 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4015 UNREACHABLE();
4016 }
4017 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004018 DCHECK_EQ(type, DataType::Type::kFloat64);
Tijana Jakovljevic43758192016-12-30 09:23:01 +01004019 switch (cond) {
4020 case kCondEQ:
4021 __ CmpEqD(FTMP, lhs, rhs);
4022 __ Mfc1(dst, FTMP);
4023 __ Andi(dst, dst, 1);
4024 break;
4025 case kCondNE:
4026 __ CmpEqD(FTMP, lhs, rhs);
4027 __ Mfc1(dst, FTMP);
4028 __ Addiu(dst, dst, 1);
4029 break;
4030 case kCondLT:
4031 if (gt_bias) {
4032 __ CmpLtD(FTMP, lhs, rhs);
4033 } else {
4034 __ CmpUltD(FTMP, lhs, rhs);
4035 }
4036 __ Mfc1(dst, FTMP);
4037 __ Andi(dst, dst, 1);
4038 break;
4039 case kCondLE:
4040 if (gt_bias) {
4041 __ CmpLeD(FTMP, lhs, rhs);
4042 } else {
4043 __ CmpUleD(FTMP, lhs, rhs);
4044 }
4045 __ Mfc1(dst, FTMP);
4046 __ Andi(dst, dst, 1);
4047 break;
4048 case kCondGT:
4049 if (gt_bias) {
4050 __ CmpUltD(FTMP, rhs, lhs);
4051 } else {
4052 __ CmpLtD(FTMP, rhs, lhs);
4053 }
4054 __ Mfc1(dst, FTMP);
4055 __ Andi(dst, dst, 1);
4056 break;
4057 case kCondGE:
4058 if (gt_bias) {
4059 __ CmpUleD(FTMP, rhs, lhs);
4060 } else {
4061 __ CmpLeD(FTMP, rhs, lhs);
4062 }
4063 __ Mfc1(dst, FTMP);
4064 __ Andi(dst, dst, 1);
4065 break;
4066 default:
4067 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4068 UNREACHABLE();
4069 }
4070 }
4071}
4072
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004073bool InstructionCodeGeneratorMIPS64::MaterializeFpCompare(IfCondition cond,
4074 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004075 DataType::Type type,
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004076 LocationSummary* input_locations,
4077 FpuRegister dst) {
4078 FpuRegister lhs = input_locations->InAt(0).AsFpuRegister<FpuRegister>();
4079 FpuRegister rhs = input_locations->InAt(1).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004080 if (type == DataType::Type::kFloat32) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004081 switch (cond) {
4082 case kCondEQ:
4083 __ CmpEqS(dst, lhs, rhs);
4084 return false;
4085 case kCondNE:
4086 __ CmpEqS(dst, lhs, rhs);
4087 return true;
4088 case kCondLT:
4089 if (gt_bias) {
4090 __ CmpLtS(dst, lhs, rhs);
4091 } else {
4092 __ CmpUltS(dst, lhs, rhs);
4093 }
4094 return false;
4095 case kCondLE:
4096 if (gt_bias) {
4097 __ CmpLeS(dst, lhs, rhs);
4098 } else {
4099 __ CmpUleS(dst, lhs, rhs);
4100 }
4101 return false;
4102 case kCondGT:
4103 if (gt_bias) {
4104 __ CmpUltS(dst, rhs, lhs);
4105 } else {
4106 __ CmpLtS(dst, rhs, lhs);
4107 }
4108 return false;
4109 case kCondGE:
4110 if (gt_bias) {
4111 __ CmpUleS(dst, rhs, lhs);
4112 } else {
4113 __ CmpLeS(dst, rhs, lhs);
4114 }
4115 return false;
4116 default:
4117 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4118 UNREACHABLE();
4119 }
4120 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004121 DCHECK_EQ(type, DataType::Type::kFloat64);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004122 switch (cond) {
4123 case kCondEQ:
4124 __ CmpEqD(dst, lhs, rhs);
4125 return false;
4126 case kCondNE:
4127 __ CmpEqD(dst, lhs, rhs);
4128 return true;
4129 case kCondLT:
4130 if (gt_bias) {
4131 __ CmpLtD(dst, lhs, rhs);
4132 } else {
4133 __ CmpUltD(dst, lhs, rhs);
4134 }
4135 return false;
4136 case kCondLE:
4137 if (gt_bias) {
4138 __ CmpLeD(dst, lhs, rhs);
4139 } else {
4140 __ CmpUleD(dst, lhs, rhs);
4141 }
4142 return false;
4143 case kCondGT:
4144 if (gt_bias) {
4145 __ CmpUltD(dst, rhs, lhs);
4146 } else {
4147 __ CmpLtD(dst, rhs, lhs);
4148 }
4149 return false;
4150 case kCondGE:
4151 if (gt_bias) {
4152 __ CmpUleD(dst, rhs, lhs);
4153 } else {
4154 __ CmpLeD(dst, rhs, lhs);
4155 }
4156 return false;
4157 default:
4158 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4159 UNREACHABLE();
4160 }
4161 }
4162}
4163
Alexey Frunze299a9392015-12-08 16:08:02 -08004164void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond,
4165 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004166 DataType::Type type,
Alexey Frunze299a9392015-12-08 16:08:02 -08004167 LocationSummary* locations,
4168 Mips64Label* label) {
4169 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
4170 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004171 if (type == DataType::Type::kFloat32) {
Alexey Frunze299a9392015-12-08 16:08:02 -08004172 switch (cond) {
4173 case kCondEQ:
4174 __ CmpEqS(FTMP, lhs, rhs);
4175 __ Bc1nez(FTMP, label);
4176 break;
4177 case kCondNE:
4178 __ CmpEqS(FTMP, lhs, rhs);
4179 __ Bc1eqz(FTMP, label);
4180 break;
4181 case kCondLT:
4182 if (gt_bias) {
4183 __ CmpLtS(FTMP, lhs, rhs);
4184 } else {
4185 __ CmpUltS(FTMP, lhs, rhs);
4186 }
4187 __ Bc1nez(FTMP, label);
4188 break;
4189 case kCondLE:
4190 if (gt_bias) {
4191 __ CmpLeS(FTMP, lhs, rhs);
4192 } else {
4193 __ CmpUleS(FTMP, lhs, rhs);
4194 }
4195 __ Bc1nez(FTMP, label);
4196 break;
4197 case kCondGT:
4198 if (gt_bias) {
4199 __ CmpUltS(FTMP, rhs, lhs);
4200 } else {
4201 __ CmpLtS(FTMP, rhs, lhs);
4202 }
4203 __ Bc1nez(FTMP, label);
4204 break;
4205 case kCondGE:
4206 if (gt_bias) {
4207 __ CmpUleS(FTMP, rhs, lhs);
4208 } else {
4209 __ CmpLeS(FTMP, rhs, lhs);
4210 }
4211 __ Bc1nez(FTMP, label);
4212 break;
4213 default:
4214 LOG(FATAL) << "Unexpected non-floating-point condition";
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004215 UNREACHABLE();
Alexey Frunze299a9392015-12-08 16:08:02 -08004216 }
4217 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004218 DCHECK_EQ(type, DataType::Type::kFloat64);
Alexey Frunze299a9392015-12-08 16:08:02 -08004219 switch (cond) {
4220 case kCondEQ:
4221 __ CmpEqD(FTMP, lhs, rhs);
4222 __ Bc1nez(FTMP, label);
4223 break;
4224 case kCondNE:
4225 __ CmpEqD(FTMP, lhs, rhs);
4226 __ Bc1eqz(FTMP, label);
4227 break;
4228 case kCondLT:
4229 if (gt_bias) {
4230 __ CmpLtD(FTMP, lhs, rhs);
4231 } else {
4232 __ CmpUltD(FTMP, lhs, rhs);
4233 }
4234 __ Bc1nez(FTMP, label);
4235 break;
4236 case kCondLE:
4237 if (gt_bias) {
4238 __ CmpLeD(FTMP, lhs, rhs);
4239 } else {
4240 __ CmpUleD(FTMP, lhs, rhs);
4241 }
4242 __ Bc1nez(FTMP, label);
4243 break;
4244 case kCondGT:
4245 if (gt_bias) {
4246 __ CmpUltD(FTMP, rhs, lhs);
4247 } else {
4248 __ CmpLtD(FTMP, rhs, lhs);
4249 }
4250 __ Bc1nez(FTMP, label);
4251 break;
4252 case kCondGE:
4253 if (gt_bias) {
4254 __ CmpUleD(FTMP, rhs, lhs);
4255 } else {
4256 __ CmpLeD(FTMP, rhs, lhs);
4257 }
4258 __ Bc1nez(FTMP, label);
4259 break;
4260 default:
4261 LOG(FATAL) << "Unexpected non-floating-point condition";
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004262 UNREACHABLE();
Alexey Frunze299a9392015-12-08 16:08:02 -08004263 }
4264 }
4265}
4266
Alexey Frunze4dda3372015-06-01 18:31:49 -07004267void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00004268 size_t condition_input_index,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004269 Mips64Label* true_target,
4270 Mips64Label* false_target) {
David Brazdil0debae72015-11-12 18:37:00 +00004271 HInstruction* cond = instruction->InputAt(condition_input_index);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004272
David Brazdil0debae72015-11-12 18:37:00 +00004273 if (true_target == nullptr && false_target == nullptr) {
4274 // Nothing to do. The code always falls through.
4275 return;
4276 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00004277 // Constant condition, statically compared against "true" (integer value 1).
4278 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00004279 if (true_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004280 __ Bc(true_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004281 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004282 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00004283 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00004284 if (false_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004285 __ Bc(false_target);
David Brazdil0debae72015-11-12 18:37:00 +00004286 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004287 }
David Brazdil0debae72015-11-12 18:37:00 +00004288 return;
4289 }
4290
4291 // The following code generates these patterns:
4292 // (1) true_target == nullptr && false_target != nullptr
4293 // - opposite condition true => branch to false_target
4294 // (2) true_target != nullptr && false_target == nullptr
4295 // - condition true => branch to true_target
4296 // (3) true_target != nullptr && false_target != nullptr
4297 // - condition true => branch to true_target
4298 // - branch to false_target
4299 if (IsBooleanValueOrMaterializedCondition(cond)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07004300 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00004301 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004302 DCHECK(cond_val.IsRegister());
David Brazdil0debae72015-11-12 18:37:00 +00004303 if (true_target == nullptr) {
4304 __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target);
4305 } else {
4306 __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target);
4307 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004308 } else {
4309 // The condition instruction has not been materialized, use its inputs as
4310 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00004311 HCondition* condition = cond->AsCondition();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004312 DataType::Type type = condition->InputAt(0)->GetType();
Alexey Frunze299a9392015-12-08 16:08:02 -08004313 LocationSummary* locations = cond->GetLocations();
4314 IfCondition if_cond = condition->GetCondition();
4315 Mips64Label* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00004316
David Brazdil0debae72015-11-12 18:37:00 +00004317 if (true_target == nullptr) {
4318 if_cond = condition->GetOppositeCondition();
Alexey Frunze299a9392015-12-08 16:08:02 -08004319 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00004320 }
4321
Alexey Frunze299a9392015-12-08 16:08:02 -08004322 switch (type) {
4323 default:
4324 GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target);
4325 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004326 case DataType::Type::kInt64:
Alexey Frunze299a9392015-12-08 16:08:02 -08004327 GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target);
4328 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004329 case DataType::Type::kFloat32:
4330 case DataType::Type::kFloat64:
Alexey Frunze299a9392015-12-08 16:08:02 -08004331 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
4332 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07004333 }
4334 }
David Brazdil0debae72015-11-12 18:37:00 +00004335
4336 // If neither branch falls through (case 3), the conditional branch to `true_target`
4337 // was already emitted (case 2) and we need to emit a jump to `false_target`.
4338 if (true_target != nullptr && false_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004339 __ Bc(false_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004340 }
4341}
4342
4343void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004344 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00004345 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07004346 locations->SetInAt(0, Location::RequiresRegister());
4347 }
4348}
4349
4350void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00004351 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
4352 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004353 Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
David Brazdil0debae72015-11-12 18:37:00 +00004354 nullptr : codegen_->GetLabelOf(true_successor);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004355 Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
David Brazdil0debae72015-11-12 18:37:00 +00004356 nullptr : codegen_->GetLabelOf(false_successor);
4357 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004358}
4359
4360void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004361 LocationSummary* locations = new (GetGraph()->GetAllocator())
Alexey Frunze4dda3372015-06-01 18:31:49 -07004362 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01004363 InvokeRuntimeCallingConvention calling_convention;
4364 RegisterSet caller_saves = RegisterSet::Empty();
4365 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4366 locations->SetCustomSlowPathCallerSaves(caller_saves);
David Brazdil0debae72015-11-12 18:37:00 +00004367 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07004368 locations->SetInAt(0, Location::RequiresRegister());
4369 }
4370}
4371
4372void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08004373 SlowPathCodeMIPS64* slow_path =
4374 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00004375 GenerateTestAndBranch(deoptimize,
4376 /* condition_input_index */ 0,
4377 slow_path->GetEntryLabel(),
4378 /* false_target */ nullptr);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004379}
4380
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004381// This function returns true if a conditional move can be generated for HSelect.
4382// Otherwise it returns false and HSelect must be implemented in terms of conditonal
4383// branches and regular moves.
4384//
4385// If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect.
4386//
4387// While determining feasibility of a conditional move and setting inputs/outputs
4388// are two distinct tasks, this function does both because they share quite a bit
4389// of common logic.
4390static bool CanMoveConditionally(HSelect* select, LocationSummary* locations_to_set) {
4391 bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition());
4392 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
4393 HCondition* condition = cond->AsCondition();
4394
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004395 DataType::Type cond_type =
4396 materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType();
4397 DataType::Type dst_type = select->GetType();
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004398
4399 HConstant* cst_true_value = select->GetTrueValue()->AsConstant();
4400 HConstant* cst_false_value = select->GetFalseValue()->AsConstant();
4401 bool is_true_value_zero_constant =
4402 (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern());
4403 bool is_false_value_zero_constant =
4404 (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern());
4405
4406 bool can_move_conditionally = false;
4407 bool use_const_for_false_in = false;
4408 bool use_const_for_true_in = false;
4409
4410 if (!cond->IsConstant()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004411 if (!DataType::IsFloatingPointType(cond_type)) {
4412 if (!DataType::IsFloatingPointType(dst_type)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004413 // Moving int/long on int/long condition.
4414 if (is_true_value_zero_constant) {
4415 // seleqz out_reg, false_reg, cond_reg
4416 can_move_conditionally = true;
4417 use_const_for_true_in = true;
4418 } else if (is_false_value_zero_constant) {
4419 // selnez out_reg, true_reg, cond_reg
4420 can_move_conditionally = true;
4421 use_const_for_false_in = true;
4422 } else if (materialized) {
4423 // Not materializing unmaterialized int conditions
4424 // to keep the instruction count low.
4425 // selnez AT, true_reg, cond_reg
4426 // seleqz TMP, false_reg, cond_reg
4427 // or out_reg, AT, TMP
4428 can_move_conditionally = true;
4429 }
4430 } else {
4431 // Moving float/double on int/long condition.
4432 if (materialized) {
4433 // Not materializing unmaterialized int conditions
4434 // to keep the instruction count low.
4435 can_move_conditionally = true;
4436 if (is_true_value_zero_constant) {
4437 // sltu TMP, ZERO, cond_reg
4438 // mtc1 TMP, temp_cond_reg
4439 // seleqz.fmt out_reg, false_reg, temp_cond_reg
4440 use_const_for_true_in = true;
4441 } else if (is_false_value_zero_constant) {
4442 // sltu TMP, ZERO, cond_reg
4443 // mtc1 TMP, temp_cond_reg
4444 // selnez.fmt out_reg, true_reg, temp_cond_reg
4445 use_const_for_false_in = true;
4446 } else {
4447 // sltu TMP, ZERO, cond_reg
4448 // mtc1 TMP, temp_cond_reg
4449 // sel.fmt temp_cond_reg, false_reg, true_reg
4450 // mov.fmt out_reg, temp_cond_reg
4451 }
4452 }
4453 }
4454 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004455 if (!DataType::IsFloatingPointType(dst_type)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004456 // Moving int/long on float/double condition.
4457 can_move_conditionally = true;
4458 if (is_true_value_zero_constant) {
4459 // mfc1 TMP, temp_cond_reg
4460 // seleqz out_reg, false_reg, TMP
4461 use_const_for_true_in = true;
4462 } else if (is_false_value_zero_constant) {
4463 // mfc1 TMP, temp_cond_reg
4464 // selnez out_reg, true_reg, TMP
4465 use_const_for_false_in = true;
4466 } else {
4467 // mfc1 TMP, temp_cond_reg
4468 // selnez AT, true_reg, TMP
4469 // seleqz TMP, false_reg, TMP
4470 // or out_reg, AT, TMP
4471 }
4472 } else {
4473 // Moving float/double on float/double condition.
4474 can_move_conditionally = true;
4475 if (is_true_value_zero_constant) {
4476 // seleqz.fmt out_reg, false_reg, temp_cond_reg
4477 use_const_for_true_in = true;
4478 } else if (is_false_value_zero_constant) {
4479 // selnez.fmt out_reg, true_reg, temp_cond_reg
4480 use_const_for_false_in = true;
4481 } else {
4482 // sel.fmt temp_cond_reg, false_reg, true_reg
4483 // mov.fmt out_reg, temp_cond_reg
4484 }
4485 }
4486 }
4487 }
4488
4489 if (can_move_conditionally) {
4490 DCHECK(!use_const_for_false_in || !use_const_for_true_in);
4491 } else {
4492 DCHECK(!use_const_for_false_in);
4493 DCHECK(!use_const_for_true_in);
4494 }
4495
4496 if (locations_to_set != nullptr) {
4497 if (use_const_for_false_in) {
4498 locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value));
4499 } else {
4500 locations_to_set->SetInAt(0,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004501 DataType::IsFloatingPointType(dst_type)
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004502 ? Location::RequiresFpuRegister()
4503 : Location::RequiresRegister());
4504 }
4505 if (use_const_for_true_in) {
4506 locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value));
4507 } else {
4508 locations_to_set->SetInAt(1,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004509 DataType::IsFloatingPointType(dst_type)
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004510 ? Location::RequiresFpuRegister()
4511 : Location::RequiresRegister());
4512 }
4513 if (materialized) {
4514 locations_to_set->SetInAt(2, Location::RequiresRegister());
4515 }
4516
4517 if (can_move_conditionally) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004518 locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type)
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004519 ? Location::RequiresFpuRegister()
4520 : Location::RequiresRegister());
4521 } else {
4522 locations_to_set->SetOut(Location::SameAsFirstInput());
4523 }
4524 }
4525
4526 return can_move_conditionally;
4527}
4528
4529
4530void InstructionCodeGeneratorMIPS64::GenConditionalMove(HSelect* select) {
4531 LocationSummary* locations = select->GetLocations();
4532 Location dst = locations->Out();
4533 Location false_src = locations->InAt(0);
4534 Location true_src = locations->InAt(1);
4535 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
4536 GpuRegister cond_reg = TMP;
4537 FpuRegister fcond_reg = FTMP;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004538 DataType::Type cond_type = DataType::Type::kInt32;
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004539 bool cond_inverted = false;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004540 DataType::Type dst_type = select->GetType();
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004541
4542 if (IsBooleanValueOrMaterializedCondition(cond)) {
4543 cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<GpuRegister>();
4544 } else {
4545 HCondition* condition = cond->AsCondition();
4546 LocationSummary* cond_locations = cond->GetLocations();
4547 IfCondition if_cond = condition->GetCondition();
4548 cond_type = condition->InputAt(0)->GetType();
4549 switch (cond_type) {
4550 default:
4551 cond_inverted = MaterializeIntLongCompare(if_cond,
4552 /* is64bit */ false,
4553 cond_locations,
4554 cond_reg);
4555 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004556 case DataType::Type::kInt64:
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004557 cond_inverted = MaterializeIntLongCompare(if_cond,
4558 /* is64bit */ true,
4559 cond_locations,
4560 cond_reg);
4561 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004562 case DataType::Type::kFloat32:
4563 case DataType::Type::kFloat64:
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004564 cond_inverted = MaterializeFpCompare(if_cond,
4565 condition->IsGtBias(),
4566 cond_type,
4567 cond_locations,
4568 fcond_reg);
4569 break;
4570 }
4571 }
4572
4573 if (true_src.IsConstant()) {
4574 DCHECK(true_src.GetConstant()->IsZeroBitPattern());
4575 }
4576 if (false_src.IsConstant()) {
4577 DCHECK(false_src.GetConstant()->IsZeroBitPattern());
4578 }
4579
4580 switch (dst_type) {
4581 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004582 if (DataType::IsFloatingPointType(cond_type)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004583 __ Mfc1(cond_reg, fcond_reg);
4584 }
4585 if (true_src.IsConstant()) {
4586 if (cond_inverted) {
4587 __ Selnez(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg);
4588 } else {
4589 __ Seleqz(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg);
4590 }
4591 } else if (false_src.IsConstant()) {
4592 if (cond_inverted) {
4593 __ Seleqz(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg);
4594 } else {
4595 __ Selnez(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg);
4596 }
4597 } else {
4598 DCHECK_NE(cond_reg, AT);
4599 if (cond_inverted) {
4600 __ Seleqz(AT, true_src.AsRegister<GpuRegister>(), cond_reg);
4601 __ Selnez(TMP, false_src.AsRegister<GpuRegister>(), cond_reg);
4602 } else {
4603 __ Selnez(AT, true_src.AsRegister<GpuRegister>(), cond_reg);
4604 __ Seleqz(TMP, false_src.AsRegister<GpuRegister>(), cond_reg);
4605 }
4606 __ Or(dst.AsRegister<GpuRegister>(), AT, TMP);
4607 }
4608 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004609 case DataType::Type::kFloat32: {
4610 if (!DataType::IsFloatingPointType(cond_type)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004611 // sel*.fmt tests bit 0 of the condition register, account for that.
4612 __ Sltu(TMP, ZERO, cond_reg);
4613 __ Mtc1(TMP, fcond_reg);
4614 }
4615 FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>();
4616 if (true_src.IsConstant()) {
4617 FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>();
4618 if (cond_inverted) {
4619 __ SelnezS(dst_reg, src_reg, fcond_reg);
4620 } else {
4621 __ SeleqzS(dst_reg, src_reg, fcond_reg);
4622 }
4623 } else if (false_src.IsConstant()) {
4624 FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>();
4625 if (cond_inverted) {
4626 __ SeleqzS(dst_reg, src_reg, fcond_reg);
4627 } else {
4628 __ SelnezS(dst_reg, src_reg, fcond_reg);
4629 }
4630 } else {
4631 if (cond_inverted) {
4632 __ SelS(fcond_reg,
4633 true_src.AsFpuRegister<FpuRegister>(),
4634 false_src.AsFpuRegister<FpuRegister>());
4635 } else {
4636 __ SelS(fcond_reg,
4637 false_src.AsFpuRegister<FpuRegister>(),
4638 true_src.AsFpuRegister<FpuRegister>());
4639 }
4640 __ MovS(dst_reg, fcond_reg);
4641 }
4642 break;
4643 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004644 case DataType::Type::kFloat64: {
4645 if (!DataType::IsFloatingPointType(cond_type)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004646 // sel*.fmt tests bit 0 of the condition register, account for that.
4647 __ Sltu(TMP, ZERO, cond_reg);
4648 __ Mtc1(TMP, fcond_reg);
4649 }
4650 FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>();
4651 if (true_src.IsConstant()) {
4652 FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>();
4653 if (cond_inverted) {
4654 __ SelnezD(dst_reg, src_reg, fcond_reg);
4655 } else {
4656 __ SeleqzD(dst_reg, src_reg, fcond_reg);
4657 }
4658 } else if (false_src.IsConstant()) {
4659 FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>();
4660 if (cond_inverted) {
4661 __ SeleqzD(dst_reg, src_reg, fcond_reg);
4662 } else {
4663 __ SelnezD(dst_reg, src_reg, fcond_reg);
4664 }
4665 } else {
4666 if (cond_inverted) {
4667 __ SelD(fcond_reg,
4668 true_src.AsFpuRegister<FpuRegister>(),
4669 false_src.AsFpuRegister<FpuRegister>());
4670 } else {
4671 __ SelD(fcond_reg,
4672 false_src.AsFpuRegister<FpuRegister>(),
4673 true_src.AsFpuRegister<FpuRegister>());
4674 }
4675 __ MovD(dst_reg, fcond_reg);
4676 }
4677 break;
4678 }
4679 }
4680}
4681
Goran Jakovljevicc6418422016-12-05 16:31:55 +01004682void LocationsBuilderMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004683 LocationSummary* locations = new (GetGraph()->GetAllocator())
Goran Jakovljevicc6418422016-12-05 16:31:55 +01004684 LocationSummary(flag, LocationSummary::kNoCall);
4685 locations->SetOut(Location::RequiresRegister());
Mingyao Yang063fc772016-08-02 11:02:54 -07004686}
4687
Goran Jakovljevicc6418422016-12-05 16:31:55 +01004688void InstructionCodeGeneratorMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
4689 __ LoadFromOffset(kLoadWord,
4690 flag->GetLocations()->Out().AsRegister<GpuRegister>(),
4691 SP,
4692 codegen_->GetStackOffsetOfShouldDeoptimizeFlag());
Mingyao Yang063fc772016-08-02 11:02:54 -07004693}
4694
David Brazdil74eb1b22015-12-14 11:44:01 +00004695void LocationsBuilderMIPS64::VisitSelect(HSelect* select) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004696 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004697 CanMoveConditionally(select, locations);
David Brazdil74eb1b22015-12-14 11:44:01 +00004698}
4699
4700void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004701 if (CanMoveConditionally(select, /* locations_to_set */ nullptr)) {
4702 GenConditionalMove(select);
4703 } else {
4704 LocationSummary* locations = select->GetLocations();
4705 Mips64Label false_target;
4706 GenerateTestAndBranch(select,
4707 /* condition_input_index */ 2,
4708 /* true_target */ nullptr,
4709 &false_target);
4710 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
4711 __ Bind(&false_target);
4712 }
David Brazdil74eb1b22015-12-14 11:44:01 +00004713}
4714
David Srbecky0cf44932015-12-09 14:09:59 +00004715void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004716 new (GetGraph()->GetAllocator()) LocationSummary(info);
David Srbecky0cf44932015-12-09 14:09:59 +00004717}
4718
David Srbeckyd28f4a02016-03-14 17:14:24 +00004719void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) {
4720 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00004721}
4722
4723void CodeGeneratorMIPS64::GenerateNop() {
4724 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00004725}
4726
Alexey Frunze4dda3372015-06-01 18:31:49 -07004727void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction,
Alexey Frunze15958152017-02-09 19:08:30 -08004728 const FieldInfo& field_info) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004729 DataType::Type field_type = field_info.GetFieldType();
Alexey Frunze15958152017-02-09 19:08:30 -08004730 bool object_field_get_with_read_barrier =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004731 kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference);
Vladimir Markoca6fff82017-10-03 14:49:14 +01004732 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
Alexey Frunze15958152017-02-09 19:08:30 -08004733 instruction,
4734 object_field_get_with_read_barrier
4735 ? LocationSummary::kCallOnSlowPath
4736 : LocationSummary::kNoCall);
Alexey Frunzec61c0762017-04-10 13:54:23 -07004737 if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
4738 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
4739 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004740 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004741 if (DataType::IsFloatingPointType(instruction->GetType())) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07004742 locations->SetOut(Location::RequiresFpuRegister());
4743 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08004744 // The output overlaps in the case of an object field get with
4745 // read barriers enabled: we do not want the move to overwrite the
4746 // object's location, as we need it to emit the read barrier.
4747 locations->SetOut(Location::RequiresRegister(),
4748 object_field_get_with_read_barrier
4749 ? Location::kOutputOverlap
4750 : Location::kNoOutputOverlap);
4751 }
4752 if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
4753 // We need a temporary register for the read barrier marking slow
4754 // path in CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier.
Alexey Frunze4147fcc2017-06-17 19:57:27 -07004755 if (!kBakerReadBarrierThunksEnableForFields) {
4756 locations->AddTemp(Location::RequiresRegister());
4757 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004758 }
4759}
4760
4761void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction,
4762 const FieldInfo& field_info) {
Vladimir Marko61b92282017-10-11 13:23:17 +01004763 DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType()));
4764 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07004765 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08004766 Location obj_loc = locations->InAt(0);
4767 GpuRegister obj = obj_loc.AsRegister<GpuRegister>();
4768 Location dst_loc = locations->Out();
Alexey Frunze4dda3372015-06-01 18:31:49 -07004769 LoadOperandType load_type = kLoadUnsignedByte;
Alexey Frunze15958152017-02-09 19:08:30 -08004770 bool is_volatile = field_info.IsVolatile();
Alexey Frunzec061de12017-02-14 13:27:23 -08004771 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Tijana Jakovljevic57433862017-01-17 16:59:03 +01004772 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
4773
Alexey Frunze4dda3372015-06-01 18:31:49 -07004774 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004775 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01004776 case DataType::Type::kUint8:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004777 load_type = kLoadUnsignedByte;
4778 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004779 case DataType::Type::kInt8:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004780 load_type = kLoadSignedByte;
4781 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004782 case DataType::Type::kUint16:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004783 load_type = kLoadUnsignedHalfword;
4784 break;
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01004785 case DataType::Type::kInt16:
4786 load_type = kLoadSignedHalfword;
4787 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004788 case DataType::Type::kInt32:
4789 case DataType::Type::kFloat32:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004790 load_type = kLoadWord;
4791 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004792 case DataType::Type::kInt64:
4793 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004794 load_type = kLoadDoubleword;
4795 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004796 case DataType::Type::kReference:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004797 load_type = kLoadUnsignedWord;
4798 break;
Aart Bik66c158e2018-01-31 12:55:04 -08004799 case DataType::Type::kUint32:
4800 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004801 case DataType::Type::kVoid:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004802 LOG(FATAL) << "Unreachable type " << type;
4803 UNREACHABLE();
4804 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004805 if (!DataType::IsFloatingPointType(type)) {
Alexey Frunze15958152017-02-09 19:08:30 -08004806 DCHECK(dst_loc.IsRegister());
4807 GpuRegister dst = dst_loc.AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004808 if (type == DataType::Type::kReference) {
Alexey Frunze15958152017-02-09 19:08:30 -08004809 // /* HeapReference<Object> */ dst = *(obj + offset)
4810 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07004811 Location temp_loc =
4812 kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0);
Alexey Frunze15958152017-02-09 19:08:30 -08004813 // Note that a potential implicit null check is handled in this
4814 // CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier call.
4815 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4816 dst_loc,
4817 obj,
4818 offset,
4819 temp_loc,
4820 /* needs_null_check */ true);
4821 if (is_volatile) {
4822 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4823 }
4824 } else {
4825 __ LoadFromOffset(kLoadUnsignedWord, dst, obj, offset, null_checker);
4826 if (is_volatile) {
4827 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4828 }
4829 // If read barriers are enabled, emit read barriers other than
4830 // Baker's using a slow path (and also unpoison the loaded
4831 // reference, if heap poisoning is enabled).
4832 codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset);
4833 }
4834 } else {
4835 __ LoadFromOffset(load_type, dst, obj, offset, null_checker);
4836 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004837 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08004838 DCHECK(dst_loc.IsFpuRegister());
4839 FpuRegister dst = dst_loc.AsFpuRegister<FpuRegister>();
Tijana Jakovljevic57433862017-01-17 16:59:03 +01004840 __ LoadFpuFromOffset(load_type, dst, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004841 }
Alexey Frunzec061de12017-02-14 13:27:23 -08004842
Alexey Frunze15958152017-02-09 19:08:30 -08004843 // Memory barriers, in the case of references, are handled in the
4844 // previous switch statement.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004845 if (is_volatile && (type != DataType::Type::kReference)) {
Alexey Frunze15958152017-02-09 19:08:30 -08004846 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
Alexey Frunzec061de12017-02-14 13:27:23 -08004847 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004848}
4849
4850void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction,
4851 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
4852 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01004853 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004854 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004855 if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004856 locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07004857 } else {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004858 locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07004859 }
4860}
4861
4862void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction,
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01004863 const FieldInfo& field_info,
4864 bool value_can_be_null) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004865 DataType::Type type = field_info.GetFieldType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07004866 LocationSummary* locations = instruction->GetLocations();
4867 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004868 Location value_location = locations->InAt(1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004869 StoreOperandType store_type = kStoreByte;
Alexey Frunze15958152017-02-09 19:08:30 -08004870 bool is_volatile = field_info.IsVolatile();
Alexey Frunzec061de12017-02-14 13:27:23 -08004871 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
4872 bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1));
Tijana Jakovljevic57433862017-01-17 16:59:03 +01004873 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
4874
Alexey Frunze4dda3372015-06-01 18:31:49 -07004875 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004876 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01004877 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004878 case DataType::Type::kInt8:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004879 store_type = kStoreByte;
4880 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004881 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01004882 case DataType::Type::kInt16:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004883 store_type = kStoreHalfword;
4884 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004885 case DataType::Type::kInt32:
4886 case DataType::Type::kFloat32:
4887 case DataType::Type::kReference:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004888 store_type = kStoreWord;
4889 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004890 case DataType::Type::kInt64:
4891 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004892 store_type = kStoreDoubleword;
4893 break;
Aart Bik66c158e2018-01-31 12:55:04 -08004894 case DataType::Type::kUint32:
4895 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004896 case DataType::Type::kVoid:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004897 LOG(FATAL) << "Unreachable type " << type;
4898 UNREACHABLE();
4899 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004900
Alexey Frunze15958152017-02-09 19:08:30 -08004901 if (is_volatile) {
4902 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
4903 }
4904
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004905 if (value_location.IsConstant()) {
4906 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
4907 __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker);
4908 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004909 if (!DataType::IsFloatingPointType(type)) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004910 DCHECK(value_location.IsRegister());
4911 GpuRegister src = value_location.AsRegister<GpuRegister>();
4912 if (kPoisonHeapReferences && needs_write_barrier) {
4913 // Note that in the case where `value` is a null reference,
4914 // we do not enter this block, as a null reference does not
4915 // need poisoning.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004916 DCHECK_EQ(type, DataType::Type::kReference);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004917 __ PoisonHeapReference(TMP, src);
4918 __ StoreToOffset(store_type, TMP, obj, offset, null_checker);
4919 } else {
4920 __ StoreToOffset(store_type, src, obj, offset, null_checker);
4921 }
4922 } else {
4923 DCHECK(value_location.IsFpuRegister());
4924 FpuRegister src = value_location.AsFpuRegister<FpuRegister>();
4925 __ StoreFpuToOffset(store_type, src, obj, offset, null_checker);
4926 }
4927 }
Alexey Frunze15958152017-02-09 19:08:30 -08004928
Alexey Frunzec061de12017-02-14 13:27:23 -08004929 if (needs_write_barrier) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004930 DCHECK(value_location.IsRegister());
4931 GpuRegister src = value_location.AsRegister<GpuRegister>();
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01004932 codegen_->MarkGCCard(obj, src, value_can_be_null);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004933 }
Alexey Frunze15958152017-02-09 19:08:30 -08004934
4935 if (is_volatile) {
4936 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
4937 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004938}
4939
4940void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4941 HandleFieldGet(instruction, instruction->GetFieldInfo());
4942}
4943
4944void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4945 HandleFieldGet(instruction, instruction->GetFieldInfo());
4946}
4947
4948void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
4949 HandleFieldSet(instruction, instruction->GetFieldInfo());
4950}
4951
4952void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01004953 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Alexey Frunze4dda3372015-06-01 18:31:49 -07004954}
4955
Alexey Frunze15958152017-02-09 19:08:30 -08004956void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadOneRegister(
4957 HInstruction* instruction,
4958 Location out,
4959 uint32_t offset,
4960 Location maybe_temp,
4961 ReadBarrierOption read_barrier_option) {
4962 GpuRegister out_reg = out.AsRegister<GpuRegister>();
4963 if (read_barrier_option == kWithReadBarrier) {
4964 CHECK(kEmitCompilerReadBarrier);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07004965 if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) {
4966 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
4967 }
Alexey Frunze15958152017-02-09 19:08:30 -08004968 if (kUseBakerReadBarrier) {
4969 // Load with fast path based Baker's read barrier.
4970 // /* HeapReference<Object> */ out = *(out + offset)
4971 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4972 out,
4973 out_reg,
4974 offset,
4975 maybe_temp,
4976 /* needs_null_check */ false);
4977 } else {
4978 // Load with slow path based read barrier.
4979 // Save the value of `out` into `maybe_temp` before overwriting it
4980 // in the following move operation, as we will need it for the
4981 // read barrier below.
4982 __ Move(maybe_temp.AsRegister<GpuRegister>(), out_reg);
4983 // /* HeapReference<Object> */ out = *(out + offset)
4984 __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset);
4985 codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset);
4986 }
4987 } else {
4988 // Plain load with no read barrier.
4989 // /* HeapReference<Object> */ out = *(out + offset)
4990 __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset);
4991 __ MaybeUnpoisonHeapReference(out_reg);
4992 }
4993}
4994
4995void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadTwoRegisters(
4996 HInstruction* instruction,
4997 Location out,
4998 Location obj,
4999 uint32_t offset,
5000 Location maybe_temp,
5001 ReadBarrierOption read_barrier_option) {
5002 GpuRegister out_reg = out.AsRegister<GpuRegister>();
5003 GpuRegister obj_reg = obj.AsRegister<GpuRegister>();
5004 if (read_barrier_option == kWithReadBarrier) {
5005 CHECK(kEmitCompilerReadBarrier);
5006 if (kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005007 if (!kBakerReadBarrierThunksEnableForFields) {
5008 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
5009 }
Alexey Frunze15958152017-02-09 19:08:30 -08005010 // Load with fast path based Baker's read barrier.
5011 // /* HeapReference<Object> */ out = *(obj + offset)
5012 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
5013 out,
5014 obj_reg,
5015 offset,
5016 maybe_temp,
5017 /* needs_null_check */ false);
5018 } else {
5019 // Load with slow path based read barrier.
5020 // /* HeapReference<Object> */ out = *(obj + offset)
5021 __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset);
5022 codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset);
5023 }
5024 } else {
5025 // Plain load with no read barrier.
5026 // /* HeapReference<Object> */ out = *(obj + offset)
5027 __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset);
5028 __ MaybeUnpoisonHeapReference(out_reg);
5029 }
5030}
5031
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005032static inline int GetBakerMarkThunkNumber(GpuRegister reg) {
5033 static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 20, "Expecting equal");
5034 if (reg >= V0 && reg <= T2) { // 13 consequtive regs.
5035 return reg - V0;
5036 } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs.
5037 return 13 + (reg - S2);
5038 } else if (reg == S8) { // One more.
5039 return 19;
5040 }
5041 LOG(FATAL) << "Unexpected register " << reg;
5042 UNREACHABLE();
5043}
5044
5045static inline int GetBakerMarkFieldArrayThunkDisplacement(GpuRegister reg, bool short_offset) {
5046 int num = GetBakerMarkThunkNumber(reg) +
5047 (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0);
5048 return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE;
5049}
5050
5051static inline int GetBakerMarkGcRootThunkDisplacement(GpuRegister reg) {
5052 return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE +
5053 BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET;
5054}
5055
5056void InstructionCodeGeneratorMIPS64::GenerateGcRootFieldLoad(HInstruction* instruction,
5057 Location root,
5058 GpuRegister obj,
5059 uint32_t offset,
5060 ReadBarrierOption read_barrier_option,
5061 Mips64Label* label_low) {
5062 if (label_low != nullptr) {
5063 DCHECK_EQ(offset, 0x5678u);
5064 }
Alexey Frunzef63f5692016-12-13 17:43:11 -08005065 GpuRegister root_reg = root.AsRegister<GpuRegister>();
Alexey Frunze15958152017-02-09 19:08:30 -08005066 if (read_barrier_option == kWithReadBarrier) {
5067 DCHECK(kEmitCompilerReadBarrier);
5068 if (kUseBakerReadBarrier) {
5069 // Fast path implementation of art::ReadBarrier::BarrierForRoot when
5070 // Baker's read barrier are used:
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005071 if (kBakerReadBarrierThunksEnableForGcRoots) {
5072 // Note that we do not actually check the value of `GetIsGcMarking()`
5073 // to decide whether to mark the loaded GC root or not. Instead, we
5074 // load into `temp` (T9) the read barrier mark introspection entrypoint.
5075 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
5076 // vice versa.
5077 //
5078 // We use thunks for the slow path. That thunk checks the reference
5079 // and jumps to the entrypoint if needed.
5080 //
5081 // temp = Thread::Current()->pReadBarrierMarkReg00
5082 // // AKA &art_quick_read_barrier_mark_introspection.
5083 // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load.
5084 // if (temp != nullptr) {
5085 // temp = &gc_root_thunk<root_reg>
5086 // root = temp(root)
5087 // }
Alexey Frunze15958152017-02-09 19:08:30 -08005088
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005089 const int32_t entry_point_offset =
5090 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0);
5091 const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg);
5092 int16_t offset_low = Low16Bits(offset);
5093 int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign
5094 // extension in lwu.
5095 bool short_offset = IsInt<16>(static_cast<int32_t>(offset));
5096 GpuRegister base = short_offset ? obj : TMP;
5097 // Loading the entrypoint does not require a load acquire since it is only changed when
5098 // threads are suspended or running a checkpoint.
5099 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
5100 if (!short_offset) {
5101 DCHECK(!label_low);
5102 __ Daui(base, obj, offset_high);
5103 }
Alexey Frunze0cab6562017-07-25 15:19:36 -07005104 Mips64Label skip_call;
5105 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005106 if (label_low != nullptr) {
5107 DCHECK(short_offset);
5108 __ Bind(label_low);
5109 }
5110 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
5111 __ LoadFromOffset(kLoadUnsignedWord, root_reg, base, offset_low); // Single instruction
5112 // in delay slot.
5113 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07005114 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005115 } else {
5116 // Note that we do not actually check the value of `GetIsGcMarking()`
5117 // to decide whether to mark the loaded GC root or not. Instead, we
5118 // load into `temp` (T9) the read barrier mark entry point corresponding
5119 // to register `root`. If `temp` is null, it means that `GetIsGcMarking()`
5120 // is false, and vice versa.
5121 //
5122 // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load.
5123 // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg()
5124 // if (temp != null) {
5125 // root = temp(root)
5126 // }
Alexey Frunze15958152017-02-09 19:08:30 -08005127
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005128 if (label_low != nullptr) {
5129 __ Bind(label_low);
5130 }
5131 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
5132 __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset);
5133 static_assert(
5134 sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>),
5135 "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> "
5136 "have different sizes.");
5137 static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t),
5138 "art::mirror::CompressedReference<mirror::Object> and int32_t "
5139 "have different sizes.");
Alexey Frunze15958152017-02-09 19:08:30 -08005140
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005141 // Slow path marking the GC root `root`.
5142 Location temp = Location::RegisterLocation(T9);
5143 SlowPathCodeMIPS64* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01005144 new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64(
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005145 instruction,
5146 root,
5147 /*entrypoint*/ temp);
5148 codegen_->AddSlowPath(slow_path);
5149
5150 const int32_t entry_point_offset =
5151 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(root.reg() - 1);
5152 // Loading the entrypoint does not require a load acquire since it is only changed when
5153 // threads are suspended or running a checkpoint.
5154 __ LoadFromOffset(kLoadDoubleword, temp.AsRegister<GpuRegister>(), TR, entry_point_offset);
5155 __ Bnezc(temp.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
5156 __ Bind(slow_path->GetExitLabel());
5157 }
Alexey Frunze15958152017-02-09 19:08:30 -08005158 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005159 if (label_low != nullptr) {
5160 __ Bind(label_low);
5161 }
Alexey Frunze15958152017-02-09 19:08:30 -08005162 // GC root loaded through a slow path for read barriers other
5163 // than Baker's.
5164 // /* GcRoot<mirror::Object>* */ root = obj + offset
5165 __ Daddiu64(root_reg, obj, static_cast<int32_t>(offset));
5166 // /* mirror::Object* */ root = root->Read()
5167 codegen_->GenerateReadBarrierForRootSlow(instruction, root, root);
5168 }
Alexey Frunzef63f5692016-12-13 17:43:11 -08005169 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005170 if (label_low != nullptr) {
5171 __ Bind(label_low);
5172 }
Alexey Frunzef63f5692016-12-13 17:43:11 -08005173 // Plain GC root load with no read barrier.
5174 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
5175 __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset);
5176 // Note that GC roots are not affected by heap poisoning, thus we
5177 // do not have to unpoison `root_reg` here.
5178 }
5179}
5180
Alexey Frunze15958152017-02-09 19:08:30 -08005181void CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
5182 Location ref,
5183 GpuRegister obj,
5184 uint32_t offset,
5185 Location temp,
5186 bool needs_null_check) {
5187 DCHECK(kEmitCompilerReadBarrier);
5188 DCHECK(kUseBakerReadBarrier);
5189
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005190 if (kBakerReadBarrierThunksEnableForFields) {
5191 // Note that we do not actually check the value of `GetIsGcMarking()`
5192 // to decide whether to mark the loaded reference or not. Instead, we
5193 // load into `temp` (T9) the read barrier mark introspection entrypoint.
5194 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
5195 // vice versa.
5196 //
5197 // We use thunks for the slow path. That thunk checks the reference
5198 // and jumps to the entrypoint if needed. If the holder is not gray,
5199 // it issues a load-load memory barrier and returns to the original
5200 // reference load.
5201 //
5202 // temp = Thread::Current()->pReadBarrierMarkReg00
5203 // // AKA &art_quick_read_barrier_mark_introspection.
5204 // if (temp != nullptr) {
5205 // temp = &field_array_thunk<holder_reg>
5206 // temp()
5207 // }
5208 // not_gray_return_address:
5209 // // If the offset is too large to fit into the lw instruction, we
5210 // // use an adjusted base register (TMP) here. This register
5211 // // receives bits 16 ... 31 of the offset before the thunk invocation
5212 // // and the thunk benefits from it.
5213 // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load.
5214 // gray_return_address:
5215
5216 DCHECK(temp.IsInvalid());
5217 bool short_offset = IsInt<16>(static_cast<int32_t>(offset));
5218 const int32_t entry_point_offset =
5219 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0);
5220 // There may have or may have not been a null check if the field offset is smaller than
5221 // the page size.
5222 // There must've been a null check in case it's actually a load from an array.
5223 // We will, however, perform an explicit null check in the thunk as it's easier to
5224 // do it than not.
5225 if (instruction->IsArrayGet()) {
5226 DCHECK(!needs_null_check);
5227 }
5228 const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset);
5229 // Loading the entrypoint does not require a load acquire since it is only changed when
5230 // threads are suspended or running a checkpoint.
5231 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
5232 GpuRegister ref_reg = ref.AsRegister<GpuRegister>();
Alexey Frunze0cab6562017-07-25 15:19:36 -07005233 Mips64Label skip_call;
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005234 if (short_offset) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07005235 __ Beqzc(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005236 __ Nop(); // In forbidden slot.
5237 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07005238 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005239 // /* HeapReference<Object> */ ref = *(obj + offset)
5240 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); // Single instruction.
5241 } else {
5242 int16_t offset_low = Low16Bits(offset);
5243 int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lwu.
Alexey Frunze0cab6562017-07-25 15:19:36 -07005244 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005245 __ Daui(TMP, obj, offset_high); // In delay slot.
5246 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07005247 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005248 // /* HeapReference<Object> */ ref = *(obj + offset)
5249 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset_low); // Single instruction.
5250 }
5251 if (needs_null_check) {
5252 MaybeRecordImplicitNullCheck(instruction);
5253 }
5254 __ MaybeUnpoisonHeapReference(ref_reg);
5255 return;
5256 }
5257
Alexey Frunze15958152017-02-09 19:08:30 -08005258 // /* HeapReference<Object> */ ref = *(obj + offset)
5259 Location no_index = Location::NoLocation();
5260 ScaleFactor no_scale_factor = TIMES_1;
5261 GenerateReferenceLoadWithBakerReadBarrier(instruction,
5262 ref,
5263 obj,
5264 offset,
5265 no_index,
5266 no_scale_factor,
5267 temp,
5268 needs_null_check);
5269}
5270
5271void CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
5272 Location ref,
5273 GpuRegister obj,
5274 uint32_t data_offset,
5275 Location index,
5276 Location temp,
5277 bool needs_null_check) {
5278 DCHECK(kEmitCompilerReadBarrier);
5279 DCHECK(kUseBakerReadBarrier);
5280
5281 static_assert(
5282 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
5283 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005284 ScaleFactor scale_factor = TIMES_4;
5285
5286 if (kBakerReadBarrierThunksEnableForArrays) {
5287 // Note that we do not actually check the value of `GetIsGcMarking()`
5288 // to decide whether to mark the loaded reference or not. Instead, we
5289 // load into `temp` (T9) the read barrier mark introspection entrypoint.
5290 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
5291 // vice versa.
5292 //
5293 // We use thunks for the slow path. That thunk checks the reference
5294 // and jumps to the entrypoint if needed. If the holder is not gray,
5295 // it issues a load-load memory barrier and returns to the original
5296 // reference load.
5297 //
5298 // temp = Thread::Current()->pReadBarrierMarkReg00
5299 // // AKA &art_quick_read_barrier_mark_introspection.
5300 // if (temp != nullptr) {
5301 // temp = &field_array_thunk<holder_reg>
5302 // temp()
5303 // }
5304 // not_gray_return_address:
5305 // // The element address is pre-calculated in the TMP register before the
5306 // // thunk invocation and the thunk benefits from it.
5307 // HeapReference<mirror::Object> reference = data[index]; // Original reference load.
5308 // gray_return_address:
5309
5310 DCHECK(temp.IsInvalid());
5311 DCHECK(index.IsValid());
5312 const int32_t entry_point_offset =
5313 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0);
5314 // We will not do the explicit null check in the thunk as some form of a null check
5315 // must've been done earlier.
5316 DCHECK(!needs_null_check);
5317 const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false);
5318 // Loading the entrypoint does not require a load acquire since it is only changed when
5319 // threads are suspended or running a checkpoint.
5320 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
Alexey Frunze0cab6562017-07-25 15:19:36 -07005321 Mips64Label skip_call;
5322 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005323 GpuRegister ref_reg = ref.AsRegister<GpuRegister>();
5324 GpuRegister index_reg = index.AsRegister<GpuRegister>();
5325 __ Dlsa(TMP, index_reg, obj, scale_factor); // In delay slot.
5326 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07005327 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005328 // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor))
5329 DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset;
5330 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, data_offset); // Single instruction.
5331 __ MaybeUnpoisonHeapReference(ref_reg);
5332 return;
5333 }
5334
Alexey Frunze15958152017-02-09 19:08:30 -08005335 // /* HeapReference<Object> */ ref =
5336 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
Alexey Frunze15958152017-02-09 19:08:30 -08005337 GenerateReferenceLoadWithBakerReadBarrier(instruction,
5338 ref,
5339 obj,
5340 data_offset,
5341 index,
5342 scale_factor,
5343 temp,
5344 needs_null_check);
5345}
5346
5347void CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
5348 Location ref,
5349 GpuRegister obj,
5350 uint32_t offset,
5351 Location index,
5352 ScaleFactor scale_factor,
5353 Location temp,
5354 bool needs_null_check,
5355 bool always_update_field) {
5356 DCHECK(kEmitCompilerReadBarrier);
5357 DCHECK(kUseBakerReadBarrier);
5358
5359 // In slow path based read barriers, the read barrier call is
5360 // inserted after the original load. However, in fast path based
5361 // Baker's read barriers, we need to perform the load of
5362 // mirror::Object::monitor_ *before* the original reference load.
5363 // This load-load ordering is required by the read barrier.
5364 // The fast path/slow path (for Baker's algorithm) should look like:
5365 //
5366 // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState();
5367 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
5368 // HeapReference<Object> ref = *src; // Original reference load.
5369 // bool is_gray = (rb_state == ReadBarrier::GrayState());
5370 // if (is_gray) {
5371 // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path.
5372 // }
5373 //
5374 // Note: the original implementation in ReadBarrier::Barrier is
5375 // slightly more complex as it performs additional checks that we do
5376 // not do here for performance reasons.
5377
5378 GpuRegister ref_reg = ref.AsRegister<GpuRegister>();
5379 GpuRegister temp_reg = temp.AsRegister<GpuRegister>();
5380 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
5381
5382 // /* int32_t */ monitor = obj->monitor_
5383 __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset);
5384 if (needs_null_check) {
5385 MaybeRecordImplicitNullCheck(instruction);
5386 }
5387 // /* LockWord */ lock_word = LockWord(monitor)
5388 static_assert(sizeof(LockWord) == sizeof(int32_t),
5389 "art::LockWord and int32_t have different sizes.");
5390
5391 __ Sync(0); // Barrier to prevent load-load reordering.
5392
5393 // The actual reference load.
5394 if (index.IsValid()) {
5395 // Load types involving an "index": ArrayGet,
5396 // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject
5397 // intrinsics.
5398 // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor))
5399 if (index.IsConstant()) {
5400 size_t computed_offset =
5401 (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset;
5402 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, computed_offset);
5403 } else {
5404 GpuRegister index_reg = index.AsRegister<GpuRegister>();
Chris Larsencd0295d2017-03-31 15:26:54 -07005405 if (scale_factor == TIMES_1) {
5406 __ Daddu(TMP, index_reg, obj);
5407 } else {
5408 __ Dlsa(TMP, index_reg, obj, scale_factor);
5409 }
Alexey Frunze15958152017-02-09 19:08:30 -08005410 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset);
5411 }
5412 } else {
5413 // /* HeapReference<Object> */ ref = *(obj + offset)
5414 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset);
5415 }
5416
5417 // Object* ref = ref_addr->AsMirrorPtr()
5418 __ MaybeUnpoisonHeapReference(ref_reg);
5419
5420 // Slow path marking the object `ref` when it is gray.
5421 SlowPathCodeMIPS64* slow_path;
5422 if (always_update_field) {
5423 // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 only supports address
5424 // of the form `obj + field_offset`, where `obj` is a register and
5425 // `field_offset` is a register. Thus `offset` and `scale_factor`
5426 // above are expected to be null in this code path.
5427 DCHECK_EQ(offset, 0u);
5428 DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1);
Vladimir Marko174b2e22017-10-12 13:34:49 +01005429 slow_path = new (GetScopedAllocator())
Alexey Frunze15958152017-02-09 19:08:30 -08005430 ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(instruction,
5431 ref,
5432 obj,
5433 /* field_offset */ index,
5434 temp_reg);
5435 } else {
Vladimir Marko174b2e22017-10-12 13:34:49 +01005436 slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64(instruction, ref);
Alexey Frunze15958152017-02-09 19:08:30 -08005437 }
5438 AddSlowPath(slow_path);
5439
5440 // if (rb_state == ReadBarrier::GrayState())
5441 // ref = ReadBarrier::Mark(ref);
5442 // Given the numeric representation, it's enough to check the low bit of the
5443 // rb_state. We do that by shifting the bit into the sign bit (31) and
5444 // performing a branch on less than zero.
5445 static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0");
5446 static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1");
5447 static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size");
5448 __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift);
5449 __ Bltzc(temp_reg, slow_path->GetEntryLabel());
5450 __ Bind(slow_path->GetExitLabel());
5451}
5452
5453void CodeGeneratorMIPS64::GenerateReadBarrierSlow(HInstruction* instruction,
5454 Location out,
5455 Location ref,
5456 Location obj,
5457 uint32_t offset,
5458 Location index) {
5459 DCHECK(kEmitCompilerReadBarrier);
5460
5461 // Insert a slow path based read barrier *after* the reference load.
5462 //
5463 // If heap poisoning is enabled, the unpoisoning of the loaded
5464 // reference will be carried out by the runtime within the slow
5465 // path.
5466 //
5467 // Note that `ref` currently does not get unpoisoned (when heap
5468 // poisoning is enabled), which is alright as the `ref` argument is
5469 // not used by the artReadBarrierSlow entry point.
5470 //
5471 // TODO: Unpoison `ref` when it is used by artReadBarrierSlow.
Vladimir Marko174b2e22017-10-12 13:34:49 +01005472 SlowPathCodeMIPS64* slow_path = new (GetScopedAllocator())
Alexey Frunze15958152017-02-09 19:08:30 -08005473 ReadBarrierForHeapReferenceSlowPathMIPS64(instruction, out, ref, obj, offset, index);
5474 AddSlowPath(slow_path);
5475
5476 __ Bc(slow_path->GetEntryLabel());
5477 __ Bind(slow_path->GetExitLabel());
5478}
5479
5480void CodeGeneratorMIPS64::MaybeGenerateReadBarrierSlow(HInstruction* instruction,
5481 Location out,
5482 Location ref,
5483 Location obj,
5484 uint32_t offset,
5485 Location index) {
5486 if (kEmitCompilerReadBarrier) {
5487 // Baker's read barriers shall be handled by the fast path
5488 // (CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier).
5489 DCHECK(!kUseBakerReadBarrier);
5490 // If heap poisoning is enabled, unpoisoning will be taken care of
5491 // by the runtime within the slow path.
5492 GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index);
5493 } else if (kPoisonHeapReferences) {
5494 __ UnpoisonHeapReference(out.AsRegister<GpuRegister>());
5495 }
5496}
5497
5498void CodeGeneratorMIPS64::GenerateReadBarrierForRootSlow(HInstruction* instruction,
5499 Location out,
5500 Location root) {
5501 DCHECK(kEmitCompilerReadBarrier);
5502
5503 // Insert a slow path based read barrier *after* the GC root load.
5504 //
5505 // Note that GC roots are not affected by heap poisoning, so we do
5506 // not need to do anything special for this here.
5507 SlowPathCodeMIPS64* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01005508 new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS64(instruction, out, root);
Alexey Frunze15958152017-02-09 19:08:30 -08005509 AddSlowPath(slow_path);
5510
5511 __ Bc(slow_path->GetEntryLabel());
5512 __ Bind(slow_path->GetExitLabel());
5513}
5514
Alexey Frunze4dda3372015-06-01 18:31:49 -07005515void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005516 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
5517 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunzec61c0762017-04-10 13:54:23 -07005518 bool baker_read_barrier_slow_path = false;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005519 switch (type_check_kind) {
5520 case TypeCheckKind::kExactCheck:
5521 case TypeCheckKind::kAbstractClassCheck:
5522 case TypeCheckKind::kClassHierarchyCheck:
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005523 case TypeCheckKind::kArrayObjectCheck: {
5524 bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction);
5525 call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall;
5526 baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005527 break;
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005528 }
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005529 case TypeCheckKind::kArrayCheck:
5530 case TypeCheckKind::kUnresolvedCheck:
5531 case TypeCheckKind::kInterfaceCheck:
5532 call_kind = LocationSummary::kCallOnSlowPath;
5533 break;
5534 }
5535
Vladimir Markoca6fff82017-10-03 14:49:14 +01005536 LocationSummary* locations =
5537 new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind);
Alexey Frunzec61c0762017-04-10 13:54:23 -07005538 if (baker_read_barrier_slow_path) {
5539 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
5540 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005541 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00005542 locations->SetInAt(1, Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07005543 // The output does overlap inputs.
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01005544 // Note that TypeCheckSlowPathMIPS64 uses this register too.
Alexey Frunze4dda3372015-06-01 18:31:49 -07005545 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexey Frunze15958152017-02-09 19:08:30 -08005546 locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind));
Alexey Frunze4dda3372015-06-01 18:31:49 -07005547}
5548
5549void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005550 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunze4dda3372015-06-01 18:31:49 -07005551 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08005552 Location obj_loc = locations->InAt(0);
5553 GpuRegister obj = obj_loc.AsRegister<GpuRegister>();
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00005554 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
Alexey Frunze15958152017-02-09 19:08:30 -08005555 Location out_loc = locations->Out();
5556 GpuRegister out = out_loc.AsRegister<GpuRegister>();
5557 const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind);
5558 DCHECK_LE(num_temps, 1u);
5559 Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation();
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005560 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
5561 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5562 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5563 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07005564 Mips64Label done;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005565 SlowPathCodeMIPS64* slow_path = nullptr;
Alexey Frunze4dda3372015-06-01 18:31:49 -07005566
5567 // Return 0 if `obj` is null.
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005568 // Avoid this check if we know `obj` is not null.
5569 if (instruction->MustDoNullCheck()) {
5570 __ Move(out, ZERO);
5571 __ Beqzc(obj, &done);
5572 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005573
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005574 switch (type_check_kind) {
5575 case TypeCheckKind::kExactCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005576 ReadBarrierOption read_barrier_option =
5577 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005578 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08005579 GenerateReferenceLoadTwoRegisters(instruction,
5580 out_loc,
5581 obj_loc,
5582 class_offset,
5583 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005584 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005585 // Classes must be equal for the instanceof to succeed.
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00005586 __ Xor(out, out, cls);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005587 __ Sltiu(out, out, 1);
5588 break;
5589 }
5590
5591 case TypeCheckKind::kAbstractClassCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005592 ReadBarrierOption read_barrier_option =
5593 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005594 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08005595 GenerateReferenceLoadTwoRegisters(instruction,
5596 out_loc,
5597 obj_loc,
5598 class_offset,
5599 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005600 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005601 // If the class is abstract, we eagerly fetch the super class of the
5602 // object to avoid doing a comparison we know will fail.
5603 Mips64Label loop;
5604 __ Bind(&loop);
5605 // /* HeapReference<Class> */ out = out->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08005606 GenerateReferenceLoadOneRegister(instruction,
5607 out_loc,
5608 super_offset,
5609 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005610 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005611 // If `out` is null, we use it for the result, and jump to `done`.
5612 __ Beqzc(out, &done);
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00005613 __ Bnec(out, cls, &loop);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005614 __ LoadConst32(out, 1);
5615 break;
5616 }
5617
5618 case TypeCheckKind::kClassHierarchyCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005619 ReadBarrierOption read_barrier_option =
5620 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005621 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08005622 GenerateReferenceLoadTwoRegisters(instruction,
5623 out_loc,
5624 obj_loc,
5625 class_offset,
5626 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005627 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005628 // Walk over the class hierarchy to find a match.
5629 Mips64Label loop, success;
5630 __ Bind(&loop);
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00005631 __ Beqc(out, cls, &success);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005632 // /* HeapReference<Class> */ out = out->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08005633 GenerateReferenceLoadOneRegister(instruction,
5634 out_loc,
5635 super_offset,
5636 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005637 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005638 __ Bnezc(out, &loop);
5639 // If `out` is null, we use it for the result, and jump to `done`.
5640 __ Bc(&done);
5641 __ Bind(&success);
5642 __ LoadConst32(out, 1);
5643 break;
5644 }
5645
5646 case TypeCheckKind::kArrayObjectCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005647 ReadBarrierOption read_barrier_option =
5648 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005649 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08005650 GenerateReferenceLoadTwoRegisters(instruction,
5651 out_loc,
5652 obj_loc,
5653 class_offset,
5654 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005655 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005656 // Do an exact check.
5657 Mips64Label success;
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00005658 __ Beqc(out, cls, &success);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005659 // Otherwise, we need to check that the object's class is a non-primitive array.
5660 // /* HeapReference<Class> */ out = out->component_type_
Alexey Frunze15958152017-02-09 19:08:30 -08005661 GenerateReferenceLoadOneRegister(instruction,
5662 out_loc,
5663 component_offset,
5664 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005665 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005666 // If `out` is null, we use it for the result, and jump to `done`.
5667 __ Beqzc(out, &done);
5668 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
5669 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
5670 __ Sltiu(out, out, 1);
5671 __ Bc(&done);
5672 __ Bind(&success);
5673 __ LoadConst32(out, 1);
5674 break;
5675 }
5676
5677 case TypeCheckKind::kArrayCheck: {
5678 // No read barrier since the slow path will retry upon failure.
5679 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08005680 GenerateReferenceLoadTwoRegisters(instruction,
5681 out_loc,
5682 obj_loc,
5683 class_offset,
5684 maybe_temp_loc,
5685 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005686 DCHECK(locations->OnlyCallsOnSlowPath());
Vladimir Marko174b2e22017-10-12 13:34:49 +01005687 slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64(
5688 instruction, /* is_fatal */ false);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005689 codegen_->AddSlowPath(slow_path);
Nicolas Geoffraybff7a522018-01-25 13:33:07 +00005690 __ Bnec(out, cls, slow_path->GetEntryLabel());
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005691 __ LoadConst32(out, 1);
5692 break;
5693 }
5694
5695 case TypeCheckKind::kUnresolvedCheck:
5696 case TypeCheckKind::kInterfaceCheck: {
5697 // Note that we indeed only call on slow path, but we always go
5698 // into the slow path for the unresolved and interface check
5699 // cases.
5700 //
5701 // We cannot directly call the InstanceofNonTrivial runtime
5702 // entry point without resorting to a type checking slow path
5703 // here (i.e. by calling InvokeRuntime directly), as it would
5704 // require to assign fixed registers for the inputs of this
5705 // HInstanceOf instruction (following the runtime calling
5706 // convention), which might be cluttered by the potential first
5707 // read barrier emission at the beginning of this method.
5708 //
5709 // TODO: Introduce a new runtime entry point taking the object
5710 // to test (instead of its class) as argument, and let it deal
5711 // with the read barrier issues. This will let us refactor this
5712 // case of the `switch` code as it was previously (with a direct
5713 // call to the runtime not using a type checking slow path).
5714 // This should also be beneficial for the other cases above.
5715 DCHECK(locations->OnlyCallsOnSlowPath());
Vladimir Marko174b2e22017-10-12 13:34:49 +01005716 slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64(
5717 instruction, /* is_fatal */ false);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005718 codegen_->AddSlowPath(slow_path);
5719 __ Bc(slow_path->GetEntryLabel());
5720 break;
5721 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005722 }
5723
5724 __ Bind(&done);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005725
5726 if (slow_path != nullptr) {
5727 __ Bind(slow_path->GetExitLabel());
5728 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005729}
5730
5731void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01005732 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005733 locations->SetOut(Location::ConstantLocation(constant));
5734}
5735
5736void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
5737 // Will be generated at use site.
5738}
5739
5740void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01005741 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005742 locations->SetOut(Location::ConstantLocation(constant));
5743}
5744
5745void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
5746 // Will be generated at use site.
5747}
5748
Calin Juravle175dc732015-08-25 15:42:32 +01005749void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5750 // The trampoline uses the same calling convention as dex calling conventions,
5751 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
5752 // the method_idx.
5753 HandleInvoke(invoke);
5754}
5755
5756void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5757 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
5758}
5759
Alexey Frunze4dda3372015-06-01 18:31:49 -07005760void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) {
5761 InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor;
5762 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
5763}
5764
5765void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
5766 HandleInvoke(invoke);
5767 // The register T0 is required to be used for the hidden argument in
5768 // art_quick_imt_conflict_trampoline, so add the hidden argument.
5769 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
5770}
5771
5772void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
5773 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
5774 GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07005775 Location receiver = invoke->GetLocations()->InAt(0);
5776 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07005777 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005778
5779 // Set the hidden argument.
5780 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(),
5781 invoke->GetDexMethodIndex());
5782
5783 // temp = object->GetClass();
5784 if (receiver.IsStackSlot()) {
5785 __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex());
5786 __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset);
5787 } else {
5788 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset);
5789 }
5790 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexey Frunzec061de12017-02-14 13:27:23 -08005791 // Instead of simply (possibly) unpoisoning `temp` here, we should
5792 // emit a read barrier for the previous class reference load.
5793 // However this is not required in practice, as this is an
5794 // intermediate/temporary reference and because the current
5795 // concurrent copying collector keeps the from-space memory
5796 // intact/accessible until the end of the marking phase (the
5797 // concurrent copying collector may not in the future).
5798 __ MaybeUnpoisonHeapReference(temp);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00005799 __ LoadFromOffset(kLoadDoubleword, temp, temp,
5800 mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value());
5801 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00005802 invoke->GetImtIndex(), kMips64PointerSize));
Alexey Frunze4dda3372015-06-01 18:31:49 -07005803 // temp = temp->GetImtEntryAt(method_offset);
5804 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
5805 // T9 = temp->GetEntryPoint();
5806 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
5807 // T9();
5808 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07005809 __ Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -07005810 DCHECK(!codegen_->IsLeafMethod());
5811 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
5812}
5813
5814void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen3039e382015-08-26 07:54:08 -07005815 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
5816 if (intrinsic.TryDispatch(invoke)) {
5817 return;
5818 }
5819
Alexey Frunze4dda3372015-06-01 18:31:49 -07005820 HandleInvoke(invoke);
5821}
5822
5823void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00005824 // Explicit clinit checks triggered by static invokes must have been pruned by
5825 // art::PrepareForRegisterAllocation.
5826 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Alexey Frunze4dda3372015-06-01 18:31:49 -07005827
Chris Larsen3039e382015-08-26 07:54:08 -07005828 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
5829 if (intrinsic.TryDispatch(invoke)) {
5830 return;
5831 }
5832
Alexey Frunze4dda3372015-06-01 18:31:49 -07005833 HandleInvoke(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005834}
5835
Orion Hodsonac141392017-01-13 11:53:47 +00005836void LocationsBuilderMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
5837 HandleInvoke(invoke);
5838}
5839
5840void InstructionCodeGeneratorMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
5841 codegen_->GenerateInvokePolymorphicCall(invoke);
5842}
5843
Chris Larsen3039e382015-08-26 07:54:08 -07005844static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07005845 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen3039e382015-08-26 07:54:08 -07005846 IntrinsicCodeGeneratorMIPS64 intrinsic(codegen);
5847 intrinsic.Dispatch(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005848 return true;
5849 }
5850 return false;
5851}
5852
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005853HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind(
Alexey Frunzef63f5692016-12-13 17:43:11 -08005854 HLoadString::LoadKind desired_string_load_kind) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08005855 bool fallback_load = false;
5856 switch (desired_string_load_kind) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08005857 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01005858 case HLoadString::LoadKind::kBootImageInternTable:
Alexey Frunzef63f5692016-12-13 17:43:11 -08005859 case HLoadString::LoadKind::kBssEntry:
5860 DCHECK(!Runtime::Current()->UseJitCompilation());
5861 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08005862 case HLoadString::LoadKind::kJitTableAddress:
5863 DCHECK(Runtime::Current()->UseJitCompilation());
Alexey Frunzef63f5692016-12-13 17:43:11 -08005864 break;
Vladimir Marko764d4542017-05-16 10:31:41 +01005865 case HLoadString::LoadKind::kBootImageAddress:
Vladimir Marko847e6ce2017-06-02 13:55:07 +01005866 case HLoadString::LoadKind::kRuntimeCall:
Vladimir Marko764d4542017-05-16 10:31:41 +01005867 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08005868 }
5869 if (fallback_load) {
Vladimir Marko847e6ce2017-06-02 13:55:07 +01005870 desired_string_load_kind = HLoadString::LoadKind::kRuntimeCall;
Alexey Frunzef63f5692016-12-13 17:43:11 -08005871 }
5872 return desired_string_load_kind;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005873}
5874
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005875HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind(
5876 HLoadClass::LoadKind desired_class_load_kind) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08005877 bool fallback_load = false;
5878 switch (desired_class_load_kind) {
Nicolas Geoffray83c8e272017-01-31 14:36:37 +00005879 case HLoadClass::LoadKind::kInvalid:
5880 LOG(FATAL) << "UNREACHABLE";
5881 UNREACHABLE();
Alexey Frunzef63f5692016-12-13 17:43:11 -08005882 case HLoadClass::LoadKind::kReferrersClass:
5883 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08005884 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko94ec2db2017-09-06 17:21:03 +01005885 case HLoadClass::LoadKind::kBootImageClassTable:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00005886 case HLoadClass::LoadKind::kBssEntry:
5887 DCHECK(!Runtime::Current()->UseJitCompilation());
5888 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08005889 case HLoadClass::LoadKind::kJitTableAddress:
5890 DCHECK(Runtime::Current()->UseJitCompilation());
Alexey Frunzef63f5692016-12-13 17:43:11 -08005891 break;
Vladimir Marko764d4542017-05-16 10:31:41 +01005892 case HLoadClass::LoadKind::kBootImageAddress:
Vladimir Marko847e6ce2017-06-02 13:55:07 +01005893 case HLoadClass::LoadKind::kRuntimeCall:
Alexey Frunzef63f5692016-12-13 17:43:11 -08005894 break;
5895 }
5896 if (fallback_load) {
Vladimir Marko847e6ce2017-06-02 13:55:07 +01005897 desired_class_load_kind = HLoadClass::LoadKind::kRuntimeCall;
Alexey Frunzef63f5692016-12-13 17:43:11 -08005898 }
5899 return desired_class_load_kind;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005900}
5901
Vladimir Markodc151b22015-10-15 18:02:30 +01005902HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch(
5903 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +01005904 HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) {
Alexey Frunze19f6c692016-11-30 19:19:55 -08005905 // On MIPS64 we support all dispatch types.
5906 return desired_dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01005907}
5908
Vladimir Markoe7197bf2017-06-02 17:00:23 +01005909void CodeGeneratorMIPS64::GenerateStaticOrDirectCall(
5910 HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07005911 // All registers are assumed to be correctly set up per the calling convention.
Vladimir Marko58155012015-08-19 12:49:41 +00005912 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
Alexey Frunze19f6c692016-11-30 19:19:55 -08005913 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
5914 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
5915
Alexey Frunze19f6c692016-11-30 19:19:55 -08005916 switch (method_load_kind) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01005917 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
Vladimir Marko58155012015-08-19 12:49:41 +00005918 // temp = thread->string_init_entrypoint
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01005919 uint32_t offset =
5920 GetThreadOffset<kMips64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
Vladimir Marko58155012015-08-19 12:49:41 +00005921 __ LoadFromOffset(kLoadDoubleword,
5922 temp.AsRegister<GpuRegister>(),
5923 TR,
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01005924 offset);
Vladimir Marko58155012015-08-19 12:49:41 +00005925 break;
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01005926 }
Vladimir Marko58155012015-08-19 12:49:41 +00005927 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00005928 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00005929 break;
Vladimir Marko65979462017-05-19 17:25:12 +01005930 case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: {
5931 DCHECK(GetCompilerOptions().IsBootImage());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07005932 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00005933 NewBootImageMethodPatch(invoke->GetTargetMethod());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07005934 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00005935 NewBootImageMethodPatch(invoke->GetTargetMethod(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07005936 EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Vladimir Marko65979462017-05-19 17:25:12 +01005937 __ Daddiu(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678);
5938 break;
5939 }
Vladimir Marko58155012015-08-19 12:49:41 +00005940 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
Alexey Frunze19f6c692016-11-30 19:19:55 -08005941 __ LoadLiteral(temp.AsRegister<GpuRegister>(),
5942 kLoadDoubleword,
5943 DeduplicateUint64Literal(invoke->GetMethodAddress()));
Vladimir Marko58155012015-08-19 12:49:41 +00005944 break;
Vladimir Markob066d432018-01-03 13:14:37 +00005945 case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: {
5946 uint32_t boot_image_offset = invoke->GetDispatchInfo().method_load_data;
5947 PcRelativePatchInfo* info_high = NewBootImageRelRoPatch(boot_image_offset);
5948 PcRelativePatchInfo* info_low = NewBootImageRelRoPatch(boot_image_offset, info_high);
5949 EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
5950 // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load.
5951 __ Lwu(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678);
5952 break;
5953 }
Vladimir Marko0eb882b2017-05-15 13:39:18 +01005954 case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07005955 PcRelativePatchInfo* info_high = NewMethodBssEntryPatch(
Vladimir Marko0eb882b2017-05-15 13:39:18 +01005956 MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()));
Alexey Frunze5fa5c042017-06-01 21:07:52 -07005957 PcRelativePatchInfo* info_low = NewMethodBssEntryPatch(
5958 MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high);
5959 EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Alexey Frunze19f6c692016-11-30 19:19:55 -08005960 __ Ld(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678);
5961 break;
5962 }
Vladimir Markoe7197bf2017-06-02 17:00:23 +01005963 case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: {
5964 GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path);
5965 return; // No code pointer retrieval; the runtime performs the call directly.
Alexey Frunze4dda3372015-06-01 18:31:49 -07005966 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005967 }
5968
Alexey Frunze19f6c692016-11-30 19:19:55 -08005969 switch (code_ptr_location) {
Vladimir Marko58155012015-08-19 12:49:41 +00005970 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
Alexey Frunze19f6c692016-11-30 19:19:55 -08005971 __ Balc(&frame_entry_label_);
Vladimir Marko58155012015-08-19 12:49:41 +00005972 break;
Vladimir Marko58155012015-08-19 12:49:41 +00005973 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
5974 // T9 = callee_method->entry_point_from_quick_compiled_code_;
5975 __ LoadFromOffset(kLoadDoubleword,
5976 T9,
5977 callee_method.AsRegister<GpuRegister>(),
5978 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07005979 kMips64PointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00005980 // T9()
5981 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07005982 __ Nop();
Vladimir Marko58155012015-08-19 12:49:41 +00005983 break;
5984 }
Vladimir Markoe7197bf2017-06-02 17:00:23 +01005985 RecordPcInfo(invoke, invoke->GetDexPc(), slow_path);
5986
Alexey Frunze4dda3372015-06-01 18:31:49 -07005987 DCHECK(!IsLeafMethod());
5988}
5989
5990void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00005991 // Explicit clinit checks triggered by static invokes must have been pruned by
5992 // art::PrepareForRegisterAllocation.
5993 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Alexey Frunze4dda3372015-06-01 18:31:49 -07005994
5995 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
5996 return;
5997 }
5998
5999 LocationSummary* locations = invoke->GetLocations();
6000 codegen_->GenerateStaticOrDirectCall(invoke,
6001 locations->HasTemps()
6002 ? locations->GetTemp(0)
6003 : Location::NoLocation());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006004}
6005
Vladimir Markoe7197bf2017-06-02 17:00:23 +01006006void CodeGeneratorMIPS64::GenerateVirtualCall(
6007 HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) {
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006008 // Use the calling convention instead of the location of the receiver, as
6009 // intrinsics may have put the receiver in a different register. In the intrinsics
6010 // slow path, the arguments have been moved to the right place, so here we are
6011 // guaranteed that the receiver is the first register of the calling convention.
6012 InvokeDexCallingConvention calling_convention;
6013 GpuRegister receiver = calling_convention.GetRegisterAt(0);
6014
Alexey Frunze53afca12015-11-05 16:34:23 -08006015 GpuRegister temp = temp_location.AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006016 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
6017 invoke->GetVTableIndex(), kMips64PointerSize).SizeValue();
6018 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07006019 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006020
6021 // temp = object->GetClass();
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006022 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset);
Alexey Frunze53afca12015-11-05 16:34:23 -08006023 MaybeRecordImplicitNullCheck(invoke);
Alexey Frunzec061de12017-02-14 13:27:23 -08006024 // Instead of simply (possibly) unpoisoning `temp` here, we should
6025 // emit a read barrier for the previous class reference load.
6026 // However this is not required in practice, as this is an
6027 // intermediate/temporary reference and because the current
6028 // concurrent copying collector keeps the from-space memory
6029 // intact/accessible until the end of the marking phase (the
6030 // concurrent copying collector may not in the future).
6031 __ MaybeUnpoisonHeapReference(temp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006032 // temp = temp->GetMethodAt(method_offset);
6033 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
6034 // T9 = temp->GetEntryPoint();
6035 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
6036 // T9();
6037 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07006038 __ Nop();
Vladimir Markoe7197bf2017-06-02 17:00:23 +01006039 RecordPcInfo(invoke, invoke->GetDexPc(), slow_path);
Alexey Frunze53afca12015-11-05 16:34:23 -08006040}
6041
6042void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
6043 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
6044 return;
6045 }
6046
6047 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Alexey Frunze4dda3372015-06-01 18:31:49 -07006048 DCHECK(!codegen_->IsLeafMethod());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006049}
6050
6051void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) {
Vladimir Marko41559982017-01-06 14:04:23 +00006052 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006053 if (load_kind == HLoadClass::LoadKind::kRuntimeCall) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006054 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07006055 Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0));
6056 CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006057 return;
6058 }
Vladimir Marko41559982017-01-06 14:04:23 +00006059 DCHECK(!cls->NeedsAccessCheck());
Alexey Frunzef63f5692016-12-13 17:43:11 -08006060
Alexey Frunze15958152017-02-09 19:08:30 -08006061 const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage();
6062 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier)
Alexey Frunzef63f5692016-12-13 17:43:11 -08006063 ? LocationSummary::kCallOnSlowPath
6064 : LocationSummary::kNoCall;
Vladimir Markoca6fff82017-10-03 14:49:14 +01006065 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind);
Alexey Frunzec61c0762017-04-10 13:54:23 -07006066 if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) {
6067 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
6068 }
Vladimir Marko41559982017-01-06 14:04:23 +00006069 if (load_kind == HLoadClass::LoadKind::kReferrersClass) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006070 locations->SetInAt(0, Location::RequiresRegister());
6071 }
6072 locations->SetOut(Location::RequiresRegister());
Alexey Frunzec61c0762017-04-10 13:54:23 -07006073 if (load_kind == HLoadClass::LoadKind::kBssEntry) {
6074 if (!kUseReadBarrier || kUseBakerReadBarrier) {
6075 // Rely on the type resolution or initialization and marking to save everything we need.
6076 RegisterSet caller_saves = RegisterSet::Empty();
6077 InvokeRuntimeCallingConvention calling_convention;
6078 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6079 locations->SetCustomSlowPathCallerSaves(caller_saves);
6080 } else {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006081 // For non-Baker read barriers we have a temp-clobbering call.
Alexey Frunzec61c0762017-04-10 13:54:23 -07006082 }
6083 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006084}
6085
Nicolas Geoffray5247c082017-01-13 14:17:29 +00006086// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
6087// move.
6088void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS {
Vladimir Marko41559982017-01-06 14:04:23 +00006089 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006090 if (load_kind == HLoadClass::LoadKind::kRuntimeCall) {
Vladimir Marko41559982017-01-06 14:04:23 +00006091 codegen_->GenerateLoadClassRuntimeCall(cls);
Calin Juravle580b6092015-10-06 17:35:58 +01006092 return;
6093 }
Vladimir Marko41559982017-01-06 14:04:23 +00006094 DCHECK(!cls->NeedsAccessCheck());
Calin Juravle580b6092015-10-06 17:35:58 +01006095
Vladimir Marko41559982017-01-06 14:04:23 +00006096 LocationSummary* locations = cls->GetLocations();
Alexey Frunzef63f5692016-12-13 17:43:11 -08006097 Location out_loc = locations->Out();
6098 GpuRegister out = out_loc.AsRegister<GpuRegister>();
6099 GpuRegister current_method_reg = ZERO;
6100 if (load_kind == HLoadClass::LoadKind::kReferrersClass ||
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006101 load_kind == HLoadClass::LoadKind::kRuntimeCall) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006102 current_method_reg = locations->InAt(0).AsRegister<GpuRegister>();
6103 }
6104
Alexey Frunze15958152017-02-09 19:08:30 -08006105 const ReadBarrierOption read_barrier_option = cls->IsInBootImage()
6106 ? kWithoutReadBarrier
6107 : kCompilerReadBarrierOption;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006108 bool generate_null_check = false;
6109 switch (load_kind) {
6110 case HLoadClass::LoadKind::kReferrersClass:
6111 DCHECK(!cls->CanCallRuntime());
6112 DCHECK(!cls->MustGenerateClinitCheck());
6113 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
6114 GenerateGcRootFieldLoad(cls,
6115 out_loc,
6116 current_method_reg,
Alexey Frunze15958152017-02-09 19:08:30 -08006117 ArtMethod::DeclaringClassOffset().Int32Value(),
6118 read_barrier_option);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006119 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006120 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Marko6bec91c2017-01-09 15:03:12 +00006121 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze15958152017-02-09 19:08:30 -08006122 DCHECK_EQ(read_barrier_option, kWithoutReadBarrier);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006123 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006124 codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006125 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006126 codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006127 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006128 __ Daddiu(out, AT, /* placeholder */ 0x5678);
6129 break;
6130 }
6131 case HLoadClass::LoadKind::kBootImageAddress: {
Alexey Frunze15958152017-02-09 19:08:30 -08006132 DCHECK_EQ(read_barrier_option, kWithoutReadBarrier);
Nicolas Geoffray5247c082017-01-13 14:17:29 +00006133 uint32_t address = dchecked_integral_cast<uint32_t>(
6134 reinterpret_cast<uintptr_t>(cls->GetClass().Get()));
6135 DCHECK_NE(address, 0u);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006136 __ LoadLiteral(out,
6137 kLoadUnsignedWord,
6138 codegen_->DeduplicateBootImageAddressLiteral(address));
6139 break;
6140 }
Vladimir Marko94ec2db2017-09-06 17:21:03 +01006141 case HLoadClass::LoadKind::kBootImageClassTable: {
6142 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
6143 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006144 codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
Vladimir Marko94ec2db2017-09-06 17:21:03 +01006145 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006146 codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high);
Vladimir Marko94ec2db2017-09-06 17:21:03 +01006147 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
6148 __ Lwu(out, AT, /* placeholder */ 0x5678);
6149 // Extract the reference from the slot data, i.e. clear the hash bits.
6150 int32_t masked_hash = ClassTable::TableSlot::MaskHash(
6151 ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex())));
6152 if (masked_hash != 0) {
6153 __ Daddiu(out, out, -masked_hash);
6154 }
6155 break;
6156 }
Vladimir Marko6bec91c2017-01-09 15:03:12 +00006157 case HLoadClass::LoadKind::kBssEntry: {
Vladimir Markof3c52b42017-11-17 17:32:12 +00006158 CodeGeneratorMIPS64::PcRelativePatchInfo* bss_info_high =
6159 codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006160 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
6161 codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high);
Vladimir Markof3c52b42017-11-17 17:32:12 +00006162 codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, out);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006163 GenerateGcRootFieldLoad(cls,
6164 out_loc,
Vladimir Markof3c52b42017-11-17 17:32:12 +00006165 out,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006166 /* placeholder */ 0x5678,
6167 read_barrier_option,
6168 &info_low->label);
Vladimir Marko6bec91c2017-01-09 15:03:12 +00006169 generate_null_check = true;
6170 break;
6171 }
Alexey Frunze627c1a02017-01-30 19:28:14 -08006172 case HLoadClass::LoadKind::kJitTableAddress:
6173 __ LoadLiteral(out,
6174 kLoadUnsignedWord,
6175 codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(),
6176 cls->GetTypeIndex(),
6177 cls->GetClass()));
Alexey Frunze15958152017-02-09 19:08:30 -08006178 GenerateGcRootFieldLoad(cls, out_loc, out, 0, read_barrier_option);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006179 break;
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006180 case HLoadClass::LoadKind::kRuntimeCall:
Nicolas Geoffray83c8e272017-01-31 14:36:37 +00006181 case HLoadClass::LoadKind::kInvalid:
Vladimir Marko41559982017-01-06 14:04:23 +00006182 LOG(FATAL) << "UNREACHABLE";
6183 UNREACHABLE();
Alexey Frunzef63f5692016-12-13 17:43:11 -08006184 }
6185
6186 if (generate_null_check || cls->MustGenerateClinitCheck()) {
6187 DCHECK(cls->CanCallRuntime());
Vladimir Marko174b2e22017-10-12 13:34:49 +01006188 SlowPathCodeMIPS64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64(
Vladimir Markof3c52b42017-11-17 17:32:12 +00006189 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
Alexey Frunzef63f5692016-12-13 17:43:11 -08006190 codegen_->AddSlowPath(slow_path);
6191 if (generate_null_check) {
6192 __ Beqzc(out, slow_path->GetEntryLabel());
6193 }
6194 if (cls->MustGenerateClinitCheck()) {
6195 GenerateClassInitializationCheck(slow_path, out);
6196 } else {
6197 __ Bind(slow_path->GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006198 }
6199 }
6200}
6201
David Brazdilcb1c0552015-08-04 16:22:25 +01006202static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07006203 return Thread::ExceptionOffset<kMips64PointerSize>().Int32Value();
David Brazdilcb1c0552015-08-04 16:22:25 +01006204}
6205
Alexey Frunze4dda3372015-06-01 18:31:49 -07006206void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) {
6207 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01006208 new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006209 locations->SetOut(Location::RequiresRegister());
6210}
6211
6212void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) {
6213 GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>();
David Brazdilcb1c0552015-08-04 16:22:25 +01006214 __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset());
6215}
6216
6217void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006218 new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall);
David Brazdilcb1c0552015-08-04 16:22:25 +01006219}
6220
6221void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
6222 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006223}
6224
Alexey Frunze4dda3372015-06-01 18:31:49 -07006225void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006226 HLoadString::LoadKind load_kind = load->GetLoadKind();
6227 LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load);
Vladimir Markoca6fff82017-10-03 14:49:14 +01006228 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind);
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006229 if (load_kind == HLoadString::LoadKind::kRuntimeCall) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006230 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07006231 locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Alexey Frunzef63f5692016-12-13 17:43:11 -08006232 } else {
6233 locations->SetOut(Location::RequiresRegister());
Alexey Frunzec61c0762017-04-10 13:54:23 -07006234 if (load_kind == HLoadString::LoadKind::kBssEntry) {
6235 if (!kUseReadBarrier || kUseBakerReadBarrier) {
6236 // Rely on the pResolveString and marking to save everything we need.
6237 RegisterSet caller_saves = RegisterSet::Empty();
6238 InvokeRuntimeCallingConvention calling_convention;
6239 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6240 locations->SetCustomSlowPathCallerSaves(caller_saves);
6241 } else {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006242 // For non-Baker read barriers we have a temp-clobbering call.
Alexey Frunzec61c0762017-04-10 13:54:23 -07006243 }
6244 }
Alexey Frunzef63f5692016-12-13 17:43:11 -08006245 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006246}
6247
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00006248// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
6249// move.
6250void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006251 HLoadString::LoadKind load_kind = load->GetLoadKind();
6252 LocationSummary* locations = load->GetLocations();
6253 Location out_loc = locations->Out();
6254 GpuRegister out = out_loc.AsRegister<GpuRegister>();
6255
6256 switch (load_kind) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006257 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
6258 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006259 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006260 codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006261 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006262 codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006263 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006264 __ Daddiu(out, AT, /* placeholder */ 0x5678);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01006265 return;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006266 }
6267 case HLoadString::LoadKind::kBootImageAddress: {
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00006268 uint32_t address = dchecked_integral_cast<uint32_t>(
6269 reinterpret_cast<uintptr_t>(load->GetString().Get()));
6270 DCHECK_NE(address, 0u);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006271 __ LoadLiteral(out,
6272 kLoadUnsignedWord,
6273 codegen_->DeduplicateBootImageAddressLiteral(address));
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01006274 return;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006275 }
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01006276 case HLoadString::LoadKind::kBootImageInternTable: {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006277 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006278 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006279 codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006280 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006281 codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01006282 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
6283 __ Lwu(out, AT, /* placeholder */ 0x5678);
6284 return;
6285 }
6286 case HLoadString::LoadKind::kBssEntry: {
6287 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
6288 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
6289 codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex());
6290 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
6291 codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high);
Vladimir Markof3c52b42017-11-17 17:32:12 +00006292 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, out);
Alexey Frunze15958152017-02-09 19:08:30 -08006293 GenerateGcRootFieldLoad(load,
6294 out_loc,
Vladimir Markof3c52b42017-11-17 17:32:12 +00006295 out,
Alexey Frunze15958152017-02-09 19:08:30 -08006296 /* placeholder */ 0x5678,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006297 kCompilerReadBarrierOption,
6298 &info_low->label);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006299 SlowPathCodeMIPS64* slow_path =
Vladimir Markof3c52b42017-11-17 17:32:12 +00006300 new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS64(load);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006301 codegen_->AddSlowPath(slow_path);
6302 __ Beqzc(out, slow_path->GetEntryLabel());
6303 __ Bind(slow_path->GetExitLabel());
6304 return;
6305 }
Alexey Frunze627c1a02017-01-30 19:28:14 -08006306 case HLoadString::LoadKind::kJitTableAddress:
6307 __ LoadLiteral(out,
6308 kLoadUnsignedWord,
6309 codegen_->DeduplicateJitStringLiteral(load->GetDexFile(),
6310 load->GetStringIndex(),
6311 load->GetString()));
Alexey Frunze15958152017-02-09 19:08:30 -08006312 GenerateGcRootFieldLoad(load, out_loc, out, 0, kCompilerReadBarrierOption);
Alexey Frunze627c1a02017-01-30 19:28:14 -08006313 return;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006314 default:
6315 break;
6316 }
6317
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07006318 // TODO: Re-add the compiler code to do string dex cache lookup again.
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006319 DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006320 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07006321 DCHECK_EQ(calling_convention.GetRegisterAt(0), out);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006322 __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_);
6323 codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc());
6324 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006325}
6326
Alexey Frunze4dda3372015-06-01 18:31:49 -07006327void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006328 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006329 locations->SetOut(Location::ConstantLocation(constant));
6330}
6331
6332void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
6333 // Will be generated at use site.
6334}
6335
6336void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006337 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
6338 instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006339 InvokeRuntimeCallingConvention calling_convention;
6340 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6341}
6342
6343void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
Serban Constantinescufc734082016-07-19 17:18:07 +01006344 codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject,
Alexey Frunze4dda3372015-06-01 18:31:49 -07006345 instruction,
Serban Constantinescufc734082016-07-19 17:18:07 +01006346 instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00006347 if (instruction->IsEnter()) {
6348 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
6349 } else {
6350 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
6351 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006352}
6353
6354void LocationsBuilderMIPS64::VisitMul(HMul* mul) {
6355 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01006356 new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006357 switch (mul->GetResultType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006358 case DataType::Type::kInt32:
6359 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07006360 locations->SetInAt(0, Location::RequiresRegister());
6361 locations->SetInAt(1, Location::RequiresRegister());
6362 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6363 break;
6364
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006365 case DataType::Type::kFloat32:
6366 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07006367 locations->SetInAt(0, Location::RequiresFpuRegister());
6368 locations->SetInAt(1, Location::RequiresFpuRegister());
6369 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
6370 break;
6371
6372 default:
6373 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
6374 }
6375}
6376
6377void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006378 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006379 LocationSummary* locations = instruction->GetLocations();
6380
6381 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006382 case DataType::Type::kInt32:
6383 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006384 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
6385 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
6386 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006387 if (type == DataType::Type::kInt32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07006388 __ MulR6(dst, lhs, rhs);
6389 else
6390 __ Dmul(dst, lhs, rhs);
6391 break;
6392 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006393 case DataType::Type::kFloat32:
6394 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006395 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
6396 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
6397 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006398 if (type == DataType::Type::kFloat32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07006399 __ MulS(dst, lhs, rhs);
6400 else
6401 __ MulD(dst, lhs, rhs);
6402 break;
6403 }
6404 default:
6405 LOG(FATAL) << "Unexpected mul type " << type;
6406 }
6407}
6408
6409void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) {
6410 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01006411 new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006412 switch (neg->GetResultType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006413 case DataType::Type::kInt32:
6414 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07006415 locations->SetInAt(0, Location::RequiresRegister());
6416 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6417 break;
6418
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006419 case DataType::Type::kFloat32:
6420 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07006421 locations->SetInAt(0, Location::RequiresFpuRegister());
6422 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
6423 break;
6424
6425 default:
6426 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
6427 }
6428}
6429
6430void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006431 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006432 LocationSummary* locations = instruction->GetLocations();
6433
6434 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006435 case DataType::Type::kInt32:
6436 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006437 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
6438 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006439 if (type == DataType::Type::kInt32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07006440 __ Subu(dst, ZERO, src);
6441 else
6442 __ Dsubu(dst, ZERO, src);
6443 break;
6444 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006445 case DataType::Type::kFloat32:
6446 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006447 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
6448 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006449 if (type == DataType::Type::kFloat32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07006450 __ NegS(dst, src);
6451 else
6452 __ NegD(dst, src);
6453 break;
6454 }
6455 default:
6456 LOG(FATAL) << "Unexpected neg type " << type;
6457 }
6458}
6459
6460void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006461 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
6462 instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006463 InvokeRuntimeCallingConvention calling_convention;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006464 locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference));
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00006465 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6466 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07006467}
6468
6469void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) {
Alexey Frunzec061de12017-02-14 13:27:23 -08006470 // Note: if heap poisoning is enabled, the entry point takes care
6471 // of poisoning the reference.
Goran Jakovljevic854df412017-06-27 14:41:39 +02006472 QuickEntrypointEnum entrypoint =
6473 CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass());
6474 codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc());
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00006475 CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>();
Goran Jakovljevic854df412017-06-27 14:41:39 +02006476 DCHECK(!codegen_->IsLeafMethod());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006477}
6478
6479void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006480 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
6481 instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006482 InvokeRuntimeCallingConvention calling_convention;
David Brazdil6de19382016-01-08 17:37:10 +00006483 if (instruction->IsStringAlloc()) {
6484 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
6485 } else {
6486 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
David Brazdil6de19382016-01-08 17:37:10 +00006487 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006488 locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference));
Alexey Frunze4dda3372015-06-01 18:31:49 -07006489}
6490
6491void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) {
Alexey Frunzec061de12017-02-14 13:27:23 -08006492 // Note: if heap poisoning is enabled, the entry point takes care
6493 // of poisoning the reference.
David Brazdil6de19382016-01-08 17:37:10 +00006494 if (instruction->IsStringAlloc()) {
6495 // String is allocated through StringFactory. Call NewEmptyString entry point.
6496 GpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
Lazar Trsicd9672662015-09-03 17:33:01 +02006497 MemberOffset code_offset =
Andreas Gampe542451c2016-07-26 09:02:02 -07006498 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00006499 __ LoadFromOffset(kLoadDoubleword, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
6500 __ LoadFromOffset(kLoadDoubleword, T9, temp, code_offset.Int32Value());
6501 __ Jalr(T9);
6502 __ Nop();
6503 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
6504 } else {
Serban Constantinescufc734082016-07-19 17:18:07 +01006505 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00006506 CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>();
David Brazdil6de19382016-01-08 17:37:10 +00006507 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006508}
6509
6510void LocationsBuilderMIPS64::VisitNot(HNot* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006511 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006512 locations->SetInAt(0, Location::RequiresRegister());
6513 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6514}
6515
6516void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006517 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006518 LocationSummary* locations = instruction->GetLocations();
6519
6520 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006521 case DataType::Type::kInt32:
6522 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006523 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
6524 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
6525 __ Nor(dst, src, ZERO);
6526 break;
6527 }
6528
6529 default:
6530 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
6531 }
6532}
6533
6534void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006535 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006536 locations->SetInAt(0, Location::RequiresRegister());
6537 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6538}
6539
6540void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
6541 LocationSummary* locations = instruction->GetLocations();
6542 __ Xori(locations->Out().AsRegister<GpuRegister>(),
6543 locations->InAt(0).AsRegister<GpuRegister>(),
6544 1);
6545}
6546
6547void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01006548 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
6549 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006550}
6551
Calin Juravle2ae48182016-03-16 14:05:09 +00006552void CodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) {
6553 if (CanMoveNullCheckToUser(instruction)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006554 return;
6555 }
6556 Location obj = instruction->GetLocations()->InAt(0);
6557
6558 __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00006559 RecordPcInfo(instruction, instruction->GetDexPc());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006560}
6561
Calin Juravle2ae48182016-03-16 14:05:09 +00006562void CodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006563 SlowPathCodeMIPS64* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01006564 new (GetScopedAllocator()) NullCheckSlowPathMIPS64(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00006565 AddSlowPath(slow_path);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006566
6567 Location obj = instruction->GetLocations()->InAt(0);
6568
6569 __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
6570}
6571
6572void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00006573 codegen_->GenerateNullCheck(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006574}
6575
6576void LocationsBuilderMIPS64::VisitOr(HOr* instruction) {
6577 HandleBinaryOp(instruction);
6578}
6579
6580void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) {
6581 HandleBinaryOp(instruction);
6582}
6583
6584void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
6585 LOG(FATAL) << "Unreachable";
6586}
6587
6588void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) {
Vladimir Markobea75ff2017-10-11 20:39:54 +01006589 if (instruction->GetNext()->IsSuspendCheck() &&
6590 instruction->GetBlock()->GetLoopInformation() != nullptr) {
6591 HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck();
6592 // The back edge will generate the suspend check.
6593 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction);
6594 }
6595
Alexey Frunze4dda3372015-06-01 18:31:49 -07006596 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
6597}
6598
6599void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006600 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006601 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
6602 if (location.IsStackSlot()) {
6603 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
6604 } else if (location.IsDoubleStackSlot()) {
6605 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
6606 }
6607 locations->SetOut(location);
6608}
6609
6610void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction
6611 ATTRIBUTE_UNUSED) {
6612 // Nothing to do, the parameter is already at its location.
6613}
6614
6615void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) {
6616 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01006617 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006618 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
6619}
6620
6621void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction
6622 ATTRIBUTE_UNUSED) {
6623 // Nothing to do, the method is already at its location.
6624}
6625
6626void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006627 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Vladimir Marko372f10e2016-05-17 16:30:10 +01006628 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006629 locations->SetInAt(i, Location::Any());
6630 }
6631 locations->SetOut(Location::Any());
6632}
6633
6634void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
6635 LOG(FATAL) << "Unreachable";
6636}
6637
6638void LocationsBuilderMIPS64::VisitRem(HRem* rem) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006639 DataType::Type type = rem->GetResultType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006640 LocationSummary::CallKind call_kind =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006641 DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly
6642 : LocationSummary::kNoCall;
Vladimir Markoca6fff82017-10-03 14:49:14 +01006643 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006644
6645 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006646 case DataType::Type::kInt32:
6647 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07006648 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunzec857c742015-09-23 15:12:39 -07006649 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07006650 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6651 break;
6652
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006653 case DataType::Type::kFloat32:
6654 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006655 InvokeRuntimeCallingConvention calling_convention;
6656 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
6657 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
6658 locations->SetOut(calling_convention.GetReturnLocation(type));
6659 break;
6660 }
6661
6662 default:
6663 LOG(FATAL) << "Unexpected rem type " << type;
6664 }
6665}
6666
6667void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006668 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006669
6670 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006671 case DataType::Type::kInt32:
6672 case DataType::Type::kInt64:
Alexey Frunzec857c742015-09-23 15:12:39 -07006673 GenerateDivRemIntegral(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006674 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07006675
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006676 case DataType::Type::kFloat32:
6677 case DataType::Type::kFloat64: {
6678 QuickEntrypointEnum entrypoint =
6679 (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod;
Serban Constantinescufc734082016-07-19 17:18:07 +01006680 codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006681 if (type == DataType::Type::kFloat32) {
Roland Levillain888d0672015-11-23 18:53:50 +00006682 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
6683 } else {
6684 CheckEntrypointTypes<kQuickFmod, double, double, double>();
6685 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006686 break;
6687 }
6688 default:
6689 LOG(FATAL) << "Unexpected rem type " << type;
6690 }
6691}
6692
Aart Bik3dad3412018-02-28 12:01:46 -08006693void LocationsBuilderMIPS64::VisitAbs(HAbs* abs) {
6694 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs);
6695 switch (abs->GetResultType()) {
6696 case DataType::Type::kInt32:
6697 case DataType::Type::kInt64:
6698 locations->SetInAt(0, Location::RequiresRegister());
6699 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6700 break;
6701 case DataType::Type::kFloat32:
6702 case DataType::Type::kFloat64:
6703 locations->SetInAt(0, Location::RequiresFpuRegister());
6704 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
6705 break;
6706 default:
6707 LOG(FATAL) << "Unexpected abs type " << abs->GetResultType();
6708 }
6709}
6710
6711void InstructionCodeGeneratorMIPS64::VisitAbs(HAbs* abs) {
6712 LocationSummary* locations = abs->GetLocations();
6713 switch (abs->GetResultType()) {
6714 case DataType::Type::kInt32: {
6715 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
6716 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
6717 __ Sra(AT, in, 31);
6718 __ Xor(out, in, AT);
6719 __ Subu(out, out, AT);
6720 break;
6721 }
6722 case DataType::Type::kInt64: {
6723 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
6724 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
6725 __ Dsra32(AT, in, 31);
6726 __ Xor(out, in, AT);
6727 __ Dsubu(out, out, AT);
6728 break;
6729 }
6730 case DataType::Type::kFloat32: {
6731 FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>();
6732 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
6733 __ AbsS(out, in);
6734 break;
6735 }
6736 case DataType::Type::kFloat64: {
6737 FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>();
6738 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
6739 __ AbsD(out, in);
6740 break;
6741 }
6742 default:
6743 LOG(FATAL) << "Unexpected abs type " << abs->GetResultType();
6744 }
6745}
6746
Igor Murashkind01745e2017-04-05 16:40:31 -07006747void LocationsBuilderMIPS64::VisitConstructorFence(HConstructorFence* constructor_fence) {
6748 constructor_fence->SetLocations(nullptr);
6749}
6750
6751void InstructionCodeGeneratorMIPS64::VisitConstructorFence(
6752 HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) {
6753 GenerateMemoryBarrier(MemBarrierKind::kStoreStore);
6754}
6755
Alexey Frunze4dda3372015-06-01 18:31:49 -07006756void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
6757 memory_barrier->SetLocations(nullptr);
6758}
6759
6760void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
6761 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
6762}
6763
6764void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006765 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006766 DataType::Type return_type = ret->InputAt(0)->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006767 locations->SetInAt(0, Mips64ReturnLocation(return_type));
6768}
6769
6770void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
6771 codegen_->GenerateFrameExit();
6772}
6773
6774void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) {
6775 ret->SetLocations(nullptr);
6776}
6777
6778void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
6779 codegen_->GenerateFrameExit();
6780}
6781
Alexey Frunze92d90602015-12-18 18:16:36 -08006782void LocationsBuilderMIPS64::VisitRor(HRor* ror) {
6783 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00006784}
6785
Alexey Frunze92d90602015-12-18 18:16:36 -08006786void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) {
6787 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00006788}
6789
Alexey Frunze4dda3372015-06-01 18:31:49 -07006790void LocationsBuilderMIPS64::VisitShl(HShl* shl) {
6791 HandleShift(shl);
6792}
6793
6794void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) {
6795 HandleShift(shl);
6796}
6797
6798void LocationsBuilderMIPS64::VisitShr(HShr* shr) {
6799 HandleShift(shr);
6800}
6801
6802void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) {
6803 HandleShift(shr);
6804}
6805
Alexey Frunze4dda3372015-06-01 18:31:49 -07006806void LocationsBuilderMIPS64::VisitSub(HSub* instruction) {
6807 HandleBinaryOp(instruction);
6808}
6809
6810void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) {
6811 HandleBinaryOp(instruction);
6812}
6813
6814void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
6815 HandleFieldGet(instruction, instruction->GetFieldInfo());
6816}
6817
6818void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
6819 HandleFieldGet(instruction, instruction->GetFieldInfo());
6820}
6821
6822void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
6823 HandleFieldSet(instruction, instruction->GetFieldInfo());
6824}
6825
6826void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01006827 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006828}
6829
Calin Juravlee460d1d2015-09-29 04:52:17 +01006830void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet(
6831 HUnresolvedInstanceFieldGet* instruction) {
6832 FieldAccessCallingConventionMIPS64 calling_convention;
6833 codegen_->CreateUnresolvedFieldLocationSummary(
6834 instruction, instruction->GetFieldType(), calling_convention);
6835}
6836
6837void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet(
6838 HUnresolvedInstanceFieldGet* instruction) {
6839 FieldAccessCallingConventionMIPS64 calling_convention;
6840 codegen_->GenerateUnresolvedFieldAccess(instruction,
6841 instruction->GetFieldType(),
6842 instruction->GetFieldIndex(),
6843 instruction->GetDexPc(),
6844 calling_convention);
6845}
6846
6847void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet(
6848 HUnresolvedInstanceFieldSet* instruction) {
6849 FieldAccessCallingConventionMIPS64 calling_convention;
6850 codegen_->CreateUnresolvedFieldLocationSummary(
6851 instruction, instruction->GetFieldType(), calling_convention);
6852}
6853
6854void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet(
6855 HUnresolvedInstanceFieldSet* instruction) {
6856 FieldAccessCallingConventionMIPS64 calling_convention;
6857 codegen_->GenerateUnresolvedFieldAccess(instruction,
6858 instruction->GetFieldType(),
6859 instruction->GetFieldIndex(),
6860 instruction->GetDexPc(),
6861 calling_convention);
6862}
6863
6864void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet(
6865 HUnresolvedStaticFieldGet* instruction) {
6866 FieldAccessCallingConventionMIPS64 calling_convention;
6867 codegen_->CreateUnresolvedFieldLocationSummary(
6868 instruction, instruction->GetFieldType(), calling_convention);
6869}
6870
6871void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet(
6872 HUnresolvedStaticFieldGet* instruction) {
6873 FieldAccessCallingConventionMIPS64 calling_convention;
6874 codegen_->GenerateUnresolvedFieldAccess(instruction,
6875 instruction->GetFieldType(),
6876 instruction->GetFieldIndex(),
6877 instruction->GetDexPc(),
6878 calling_convention);
6879}
6880
6881void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet(
6882 HUnresolvedStaticFieldSet* instruction) {
6883 FieldAccessCallingConventionMIPS64 calling_convention;
6884 codegen_->CreateUnresolvedFieldLocationSummary(
6885 instruction, instruction->GetFieldType(), calling_convention);
6886}
6887
6888void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet(
6889 HUnresolvedStaticFieldSet* instruction) {
6890 FieldAccessCallingConventionMIPS64 calling_convention;
6891 codegen_->GenerateUnresolvedFieldAccess(instruction,
6892 instruction->GetFieldType(),
6893 instruction->GetFieldIndex(),
6894 instruction->GetDexPc(),
6895 calling_convention);
6896}
6897
Alexey Frunze4dda3372015-06-01 18:31:49 -07006898void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006899 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
6900 instruction, LocationSummary::kCallOnSlowPath);
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02006901 // In suspend check slow path, usually there are no caller-save registers at all.
6902 // If SIMD instructions are present, however, we force spilling all live SIMD
6903 // registers in full width (since the runtime only saves/restores lower part).
6904 locations->SetCustomSlowPathCallerSaves(
6905 GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006906}
6907
6908void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
6909 HBasicBlock* block = instruction->GetBlock();
6910 if (block->GetLoopInformation() != nullptr) {
6911 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
6912 // The back edge will generate the suspend check.
6913 return;
6914 }
6915 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
6916 // The goto will generate the suspend check.
6917 return;
6918 }
6919 GenerateSuspendCheck(instruction, nullptr);
6920}
6921
Alexey Frunze4dda3372015-06-01 18:31:49 -07006922void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006923 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
6924 instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006925 InvokeRuntimeCallingConvention calling_convention;
6926 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6927}
6928
6929void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) {
Serban Constantinescufc734082016-07-19 17:18:07 +01006930 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006931 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
6932}
6933
6934void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006935 DataType::Type input_type = conversion->GetInputType();
6936 DataType::Type result_type = conversion->GetResultType();
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006937 DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type))
6938 << input_type << " -> " << result_type;
Alexey Frunze4dda3372015-06-01 18:31:49 -07006939
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006940 if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) ||
6941 (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006942 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
6943 }
6944
Vladimir Markoca6fff82017-10-03 14:49:14 +01006945 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(conversion);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006946
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006947 if (DataType::IsFloatingPointType(input_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006948 locations->SetInAt(0, Location::RequiresFpuRegister());
6949 } else {
6950 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006951 }
6952
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006953 if (DataType::IsFloatingPointType(result_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006954 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006955 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08006956 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006957 }
6958}
6959
6960void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
6961 LocationSummary* locations = conversion->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006962 DataType::Type result_type = conversion->GetResultType();
6963 DataType::Type input_type = conversion->GetInputType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006964
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006965 DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type))
6966 << input_type << " -> " << result_type;
Alexey Frunze4dda3372015-06-01 18:31:49 -07006967
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006968 if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006969 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
6970 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
6971
6972 switch (result_type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006973 case DataType::Type::kUint8:
6974 __ Andi(dst, src, 0xFF);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006975 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006976 case DataType::Type::kInt8:
6977 if (input_type == DataType::Type::kInt64) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00006978 // Type conversion from long to types narrower than int is a result of code
6979 // transformations. To avoid unpredictable results for SEB and SEH, we first
6980 // need to sign-extend the low 32-bit value into bits 32 through 63.
6981 __ Sll(dst, src, 0);
6982 __ Seb(dst, dst);
6983 } else {
6984 __ Seb(dst, src);
6985 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006986 break;
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006987 case DataType::Type::kUint16:
6988 __ Andi(dst, src, 0xFFFF);
6989 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006990 case DataType::Type::kInt16:
6991 if (input_type == DataType::Type::kInt64) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00006992 // Type conversion from long to types narrower than int is a result of code
6993 // transformations. To avoid unpredictable results for SEB and SEH, we first
6994 // need to sign-extend the low 32-bit value into bits 32 through 63.
6995 __ Sll(dst, src, 0);
6996 __ Seh(dst, dst);
6997 } else {
6998 __ Seh(dst, src);
6999 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07007000 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007001 case DataType::Type::kInt32:
7002 case DataType::Type::kInt64:
Goran Jakovljevic992bdb92016-12-28 16:21:48 +01007003 // Sign-extend 32-bit int into bits 32 through 63 for int-to-long and long-to-int
7004 // conversions, except when the input and output registers are the same and we are not
7005 // converting longs to shorter types. In these cases, do nothing.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007006 if ((input_type == DataType::Type::kInt64) || (dst != src)) {
Goran Jakovljevic992bdb92016-12-28 16:21:48 +01007007 __ Sll(dst, src, 0);
7008 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07007009 break;
7010
7011 default:
7012 LOG(FATAL) << "Unexpected type conversion from " << input_type
7013 << " to " << result_type;
7014 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007015 } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007016 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
7017 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007018 if (input_type == DataType::Type::kInt64) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007019 __ Dmtc1(src, FTMP);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007020 if (result_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007021 __ Cvtsl(dst, FTMP);
7022 } else {
7023 __ Cvtdl(dst, FTMP);
7024 }
7025 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -07007026 __ Mtc1(src, FTMP);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007027 if (result_type == DataType::Type::kFloat32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07007028 __ Cvtsw(dst, FTMP);
7029 } else {
7030 __ Cvtdw(dst, FTMP);
7031 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07007032 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007033 } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) {
7034 CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007035 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
7036 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007037
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007038 if (result_type == DataType::Type::kInt64) {
7039 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007040 __ TruncLS(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00007041 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007042 __ TruncLD(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00007043 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007044 __ Dmfc1(dst, FTMP);
Roland Levillain888d0672015-11-23 18:53:50 +00007045 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007046 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007047 __ TruncWS(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00007048 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007049 __ TruncWD(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00007050 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007051 __ Mfc1(dst, FTMP);
Roland Levillain888d0672015-11-23 18:53:50 +00007052 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007053 } else if (DataType::IsFloatingPointType(result_type) &&
7054 DataType::IsFloatingPointType(input_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07007055 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
7056 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007057 if (result_type == DataType::Type::kFloat32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07007058 __ Cvtsd(dst, src);
7059 } else {
7060 __ Cvtds(dst, src);
7061 }
7062 } else {
7063 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
7064 << " to " << result_type;
7065 }
7066}
7067
7068void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) {
7069 HandleShift(ushr);
7070}
7071
7072void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) {
7073 HandleShift(ushr);
7074}
7075
7076void LocationsBuilderMIPS64::VisitXor(HXor* instruction) {
7077 HandleBinaryOp(instruction);
7078}
7079
7080void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) {
7081 HandleBinaryOp(instruction);
7082}
7083
7084void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
7085 // Nothing to do, this should be removed during prepare for register allocator.
7086 LOG(FATAL) << "Unreachable";
7087}
7088
7089void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
7090 // Nothing to do, this should be removed during prepare for register allocator.
7091 LOG(FATAL) << "Unreachable";
7092}
7093
7094void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007095 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007096}
7097
7098void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007099 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007100}
7101
7102void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007103 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007104}
7105
7106void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007107 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007108}
7109
7110void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007111 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007112}
7113
7114void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007115 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007116}
7117
7118void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007119 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007120}
7121
7122void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007123 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007124}
7125
7126void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007127 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007128}
7129
7130void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007131 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007132}
7133
7134void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007135 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007136}
7137
7138void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007139 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007140}
7141
Aart Bike9f37602015-10-09 11:15:55 -07007142void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007143 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007144}
7145
7146void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007147 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007148}
7149
7150void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007151 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007152}
7153
7154void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007155 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007156}
7157
7158void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007159 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007160}
7161
7162void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007163 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007164}
7165
7166void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007167 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007168}
7169
7170void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007171 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007172}
7173
Mark Mendellfe57faa2015-09-18 09:26:15 -04007174// Simple implementation of packed switch - generate cascaded compare/jumps.
7175void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7176 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01007177 new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall);
Mark Mendellfe57faa2015-09-18 09:26:15 -04007178 locations->SetInAt(0, Location::RequiresRegister());
7179}
7180
Alexey Frunze0960ac52016-12-20 17:24:59 -08007181void InstructionCodeGeneratorMIPS64::GenPackedSwitchWithCompares(GpuRegister value_reg,
7182 int32_t lower_bound,
7183 uint32_t num_entries,
7184 HBasicBlock* switch_block,
7185 HBasicBlock* default_block) {
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007186 // Create a set of compare/jumps.
7187 GpuRegister temp_reg = TMP;
Alexey Frunze0960ac52016-12-20 17:24:59 -08007188 __ Addiu32(temp_reg, value_reg, -lower_bound);
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007189 // Jump to default if index is negative
7190 // Note: We don't check the case that index is positive while value < lower_bound, because in
7191 // this case, index >= num_entries must be true. So that we can save one branch instruction.
7192 __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block));
7193
Alexey Frunze0960ac52016-12-20 17:24:59 -08007194 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007195 // Jump to successors[0] if value == lower_bound.
7196 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0]));
7197 int32_t last_index = 0;
7198 for (; num_entries - last_index > 2; last_index += 2) {
7199 __ Addiu(temp_reg, temp_reg, -2);
7200 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
7201 __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
7202 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
7203 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
7204 }
7205 if (num_entries - last_index == 2) {
7206 // The last missing case_value.
7207 __ Addiu(temp_reg, temp_reg, -1);
7208 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Mark Mendellfe57faa2015-09-18 09:26:15 -04007209 }
7210
7211 // And the default for any other value.
Alexey Frunze0960ac52016-12-20 17:24:59 -08007212 if (!codegen_->GoesToNextBlock(switch_block, default_block)) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07007213 __ Bc(codegen_->GetLabelOf(default_block));
Mark Mendellfe57faa2015-09-18 09:26:15 -04007214 }
7215}
7216
Alexey Frunze0960ac52016-12-20 17:24:59 -08007217void InstructionCodeGeneratorMIPS64::GenTableBasedPackedSwitch(GpuRegister value_reg,
7218 int32_t lower_bound,
7219 uint32_t num_entries,
7220 HBasicBlock* switch_block,
7221 HBasicBlock* default_block) {
7222 // Create a jump table.
7223 std::vector<Mips64Label*> labels(num_entries);
7224 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
7225 for (uint32_t i = 0; i < num_entries; i++) {
7226 labels[i] = codegen_->GetLabelOf(successors[i]);
7227 }
7228 JumpTable* table = __ CreateJumpTable(std::move(labels));
7229
7230 // Is the value in range?
7231 __ Addiu32(TMP, value_reg, -lower_bound);
7232 __ LoadConst32(AT, num_entries);
7233 __ Bgeuc(TMP, AT, codegen_->GetLabelOf(default_block));
7234
7235 // We are in the range of the table.
7236 // Load the target address from the jump table, indexing by the value.
7237 __ LoadLabelAddress(AT, table->GetLabel());
Chris Larsencd0295d2017-03-31 15:26:54 -07007238 __ Dlsa(TMP, TMP, AT, 2);
Alexey Frunze0960ac52016-12-20 17:24:59 -08007239 __ Lw(TMP, TMP, 0);
7240 // Compute the absolute target address by adding the table start address
7241 // (the table contains offsets to targets relative to its start).
7242 __ Daddu(TMP, TMP, AT);
7243 // And jump.
7244 __ Jr(TMP);
7245 __ Nop();
7246}
7247
7248void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7249 int32_t lower_bound = switch_instr->GetStartValue();
7250 uint32_t num_entries = switch_instr->GetNumEntries();
7251 LocationSummary* locations = switch_instr->GetLocations();
7252 GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>();
7253 HBasicBlock* switch_block = switch_instr->GetBlock();
7254 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
7255
7256 if (num_entries > kPackedSwitchJumpTableThreshold) {
7257 GenTableBasedPackedSwitch(value_reg,
7258 lower_bound,
7259 num_entries,
7260 switch_block,
7261 default_block);
7262 } else {
7263 GenPackedSwitchWithCompares(value_reg,
7264 lower_bound,
7265 num_entries,
7266 switch_block,
7267 default_block);
7268 }
7269}
7270
Chris Larsenc9905a62017-03-13 17:06:18 -07007271void LocationsBuilderMIPS64::VisitClassTableGet(HClassTableGet* instruction) {
7272 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01007273 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Chris Larsenc9905a62017-03-13 17:06:18 -07007274 locations->SetInAt(0, Location::RequiresRegister());
7275 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007276}
7277
Chris Larsenc9905a62017-03-13 17:06:18 -07007278void InstructionCodeGeneratorMIPS64::VisitClassTableGet(HClassTableGet* instruction) {
7279 LocationSummary* locations = instruction->GetLocations();
7280 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
7281 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
7282 instruction->GetIndex(), kMips64PointerSize).SizeValue();
7283 __ LoadFromOffset(kLoadDoubleword,
7284 locations->Out().AsRegister<GpuRegister>(),
7285 locations->InAt(0).AsRegister<GpuRegister>(),
7286 method_offset);
7287 } else {
7288 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
7289 instruction->GetIndex(), kMips64PointerSize));
7290 __ LoadFromOffset(kLoadDoubleword,
7291 locations->Out().AsRegister<GpuRegister>(),
7292 locations->InAt(0).AsRegister<GpuRegister>(),
7293 mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value());
7294 __ LoadFromOffset(kLoadDoubleword,
7295 locations->Out().AsRegister<GpuRegister>(),
7296 locations->Out().AsRegister<GpuRegister>(),
7297 method_offset);
7298 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007299}
7300
xueliang.zhonge0eb4832017-10-30 13:43:14 +00007301void LocationsBuilderMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction
7302 ATTRIBUTE_UNUSED) {
7303 LOG(FATAL) << "Unreachable";
7304}
7305
7306void InstructionCodeGeneratorMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction
7307 ATTRIBUTE_UNUSED) {
7308 LOG(FATAL) << "Unreachable";
7309}
7310
Alexey Frunze4dda3372015-06-01 18:31:49 -07007311} // namespace mips64
7312} // namespace art