blob: 9eff30d4247c8998d3812d06534d3704e47971a7 [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"
Vladimir Markoeebb8212018-06-05 14:57:24 +010027#include "gc/space/image_space.h"
Andreas Gampe09659c22017-09-18 18:23:32 -070028#include "heap_poisoning.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070029#include "intrinsics.h"
Chris Larsen3039e382015-08-26 07:54:08 -070030#include "intrinsics_mips64.h"
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010031#include "linker/linker_patch.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070032#include "mirror/array-inl.h"
33#include "mirror/class-inl.h"
34#include "offsets.h"
Vladimir Marko174b2e22017-10-12 13:34:49 +010035#include "stack_map_stream.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070036#include "thread.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070037#include "utils/assembler.h"
Alexey Frunzea0e87b02015-09-24 22:57:20 -070038#include "utils/mips64/assembler_mips64.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070039#include "utils/stack_checks.h"
40
Vladimir Markoe2727152019-10-10 10:46:42 +010041namespace art HIDDEN {
Alexey Frunze4dda3372015-06-01 18:31:49 -070042namespace mips64 {
43
44static constexpr int kCurrentMethodStackOffset = 0;
45static constexpr GpuRegister kMethodRegisterArgument = A0;
46
Alexey Frunze4147fcc2017-06-17 19:57:27 -070047// Flags controlling the use of thunks for Baker read barriers.
48constexpr bool kBakerReadBarrierThunksEnableForFields = true;
49constexpr bool kBakerReadBarrierThunksEnableForArrays = true;
50constexpr bool kBakerReadBarrierThunksEnableForGcRoots = true;
51
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010052Location Mips64ReturnLocation(DataType::Type return_type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -070053 switch (return_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010054 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010055 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010056 case DataType::Type::kInt8:
57 case DataType::Type::kUint16:
58 case DataType::Type::kInt16:
Aart Bik66c158e2018-01-31 12:55:04 -080059 case DataType::Type::kUint32:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010060 case DataType::Type::kInt32:
61 case DataType::Type::kReference:
Aart Bik66c158e2018-01-31 12:55:04 -080062 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010063 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -070064 return Location::RegisterLocation(V0);
65
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010066 case DataType::Type::kFloat32:
67 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -070068 return Location::FpuRegisterLocation(F0);
69
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010070 case DataType::Type::kVoid:
Alexey Frunze4dda3372015-06-01 18:31:49 -070071 return Location();
72 }
73 UNREACHABLE();
74}
75
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010076Location InvokeDexCallingConventionVisitorMIPS64::GetReturnLocation(DataType::Type type) const {
Alexey Frunze4dda3372015-06-01 18:31:49 -070077 return Mips64ReturnLocation(type);
78}
79
80Location InvokeDexCallingConventionVisitorMIPS64::GetMethodLocation() const {
81 return Location::RegisterLocation(kMethodRegisterArgument);
82}
83
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010084Location InvokeDexCallingConventionVisitorMIPS64::GetNextLocation(DataType::Type type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -070085 Location next_location;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010086 if (type == DataType::Type::kVoid) {
Alexey Frunze4dda3372015-06-01 18:31:49 -070087 LOG(FATAL) << "Unexpected parameter type " << type;
88 }
89
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010090 if (DataType::IsFloatingPointType(type) &&
Alexey Frunze4dda3372015-06-01 18:31:49 -070091 (float_index_ < calling_convention.GetNumberOfFpuRegisters())) {
92 next_location = Location::FpuRegisterLocation(
93 calling_convention.GetFpuRegisterAt(float_index_++));
94 gp_index_++;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010095 } else if (!DataType::IsFloatingPointType(type) &&
Alexey Frunze4dda3372015-06-01 18:31:49 -070096 (gp_index_ < calling_convention.GetNumberOfRegisters())) {
97 next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index_++));
98 float_index_++;
99 } else {
100 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100101 next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
102 : Location::StackSlot(stack_offset);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700103 }
104
105 // Space on the stack is reserved for all arguments.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100106 stack_index_ += DataType::Is64BitType(type) ? 2 : 1;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700107
Alexey Frunze4dda3372015-06-01 18:31:49 -0700108 return next_location;
109}
110
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100111Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700112 return Mips64ReturnLocation(type);
113}
114
Vladimir Marko3232dbb2018-07-25 15:42:46 +0100115static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() {
116 InvokeRuntimeCallingConvention calling_convention;
117 RegisterSet caller_saves = RegisterSet::Empty();
118 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
119 // The reference is returned in the same register. This differs from the standard return location.
120 return caller_saves;
121}
122
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100123// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
124#define __ down_cast<CodeGeneratorMIPS64*>(codegen)->GetAssembler()-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700125#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value()
Alexey Frunze4dda3372015-06-01 18:31:49 -0700126
127class BoundsCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
128 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000129 explicit BoundsCheckSlowPathMIPS64(HBoundsCheck* instruction) : SlowPathCodeMIPS64(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700130
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100131 void EmitNativeCode(CodeGenerator* codegen) override {
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100132 LocationSummary* locations = instruction_->GetLocations();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700133 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
134 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000135 if (instruction_->CanThrowIntoCatchBlock()) {
136 // Live registers will be restored in the catch block if caught.
137 SaveLiveRegisters(codegen, instruction_->GetLocations());
138 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700139 // We're moving two locations to locations that could overlap, so we need a parallel
140 // move resolver.
141 InvokeRuntimeCallingConvention calling_convention;
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100142 codegen->EmitParallelMoves(locations->InAt(0),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700143 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100144 DataType::Type::kInt32,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100145 locations->InAt(1),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700146 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100147 DataType::Type::kInt32);
Serban Constantinescufc734082016-07-19 17:18:07 +0100148 QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt()
149 ? kQuickThrowStringBounds
150 : kQuickThrowArrayBounds;
151 mips64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100152 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700153 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
154 }
155
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100156 bool IsFatal() const override { return true; }
Alexandre Rames8158f282015-08-07 10:26:17 +0100157
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100158 const char* GetDescription() const override { return "BoundsCheckSlowPathMIPS64"; }
Roland Levillain46648892015-06-19 16:07:18 +0100159
Alexey Frunze4dda3372015-06-01 18:31:49 -0700160 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700161 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS64);
162};
163
164class DivZeroCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
165 public:
Alexey Frunzec61c0762017-04-10 13:54:23 -0700166 explicit DivZeroCheckSlowPathMIPS64(HDivZeroCheck* instruction)
167 : SlowPathCodeMIPS64(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700168
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100169 void EmitNativeCode(CodeGenerator* codegen) override {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700170 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
171 __ Bind(GetEntryLabel());
Serban Constantinescufc734082016-07-19 17:18:07 +0100172 mips64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700173 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
174 }
175
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100176 bool IsFatal() const override { return true; }
Alexandre Rames8158f282015-08-07 10:26:17 +0100177
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100178 const char* GetDescription() const override { return "DivZeroCheckSlowPathMIPS64"; }
Roland Levillain46648892015-06-19 16:07:18 +0100179
Alexey Frunze4dda3372015-06-01 18:31:49 -0700180 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700181 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS64);
182};
183
184class LoadClassSlowPathMIPS64 : public SlowPathCodeMIPS64 {
185 public:
Vladimir Markoa9f303c2018-07-20 16:43:56 +0100186 LoadClassSlowPathMIPS64(HLoadClass* cls, HInstruction* at)
187 : SlowPathCodeMIPS64(at), cls_(cls) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700188 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
Vladimir Markoa9f303c2018-07-20 16:43:56 +0100189 DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700190 }
191
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100192 void EmitNativeCode(CodeGenerator* codegen) override {
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000193 LocationSummary* locations = instruction_->GetLocations();
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700194 Location out = locations->Out();
Vladimir Markoa9f303c2018-07-20 16:43:56 +0100195 const uint32_t dex_pc = instruction_->GetDexPc();
196 bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath();
197 bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck();
198
Alexey Frunze4dda3372015-06-01 18:31:49 -0700199 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700200 __ Bind(GetEntryLabel());
201 SaveLiveRegisters(codegen, locations);
202
Vladimir Markoa9f303c2018-07-20 16:43:56 +0100203 InvokeRuntimeCallingConvention calling_convention;
204 if (must_resolve_type) {
205 DCHECK(IsSameDexFile(cls_->GetDexFile(), mips64_codegen->GetGraph()->GetDexFile()));
206 dex::TypeIndex type_index = cls_->GetTypeIndex();
207 __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_);
Vladimir Marko9d479252018-07-24 11:35:20 +0100208 mips64_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this);
209 CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>();
Vladimir Markoa9f303c2018-07-20 16:43:56 +0100210 // If we also must_do_clinit, the resolved type is now in the correct register.
211 } else {
212 DCHECK(must_do_clinit);
213 Location source = instruction_->IsLoadClass() ? out : locations->InAt(0);
214 mips64_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
215 source,
216 cls_->GetType());
217 }
218 if (must_do_clinit) {
219 mips64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this);
220 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700221 }
222
223 // Move the class to the desired location.
Alexey Frunze4dda3372015-06-01 18:31:49 -0700224 if (out.IsValid()) {
225 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100226 DataType::Type type = instruction_->GetType();
Alexey Frunzec61c0762017-04-10 13:54:23 -0700227 mips64_codegen->MoveLocation(out,
228 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
229 type);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700230 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700231 RestoreLiveRegisters(codegen, locations);
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700232
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700233 __ Bc(GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700234 }
235
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100236 const char* GetDescription() const override { return "LoadClassSlowPathMIPS64"; }
Roland Levillain46648892015-06-19 16:07:18 +0100237
Alexey Frunze4dda3372015-06-01 18:31:49 -0700238 private:
239 // The class this slow path will load.
240 HLoadClass* const cls_;
241
Alexey Frunze4dda3372015-06-01 18:31:49 -0700242 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS64);
243};
244
245class LoadStringSlowPathMIPS64 : public SlowPathCodeMIPS64 {
246 public:
Vladimir Markof3c52b42017-11-17 17:32:12 +0000247 explicit LoadStringSlowPathMIPS64(HLoadString* instruction)
248 : SlowPathCodeMIPS64(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700249
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100250 void EmitNativeCode(CodeGenerator* codegen) override {
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700251 DCHECK(instruction_->IsLoadString());
252 DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700253 LocationSummary* locations = instruction_->GetLocations();
254 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Vladimir Markof3c52b42017-11-17 17:32:12 +0000255 const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700256 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700257 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700258 __ Bind(GetEntryLabel());
259 SaveLiveRegisters(codegen, locations);
260
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000261 __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_);
Serban Constantinescufc734082016-07-19 17:18:07 +0100262 mips64_codegen->InvokeRuntime(kQuickResolveString,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700263 instruction_,
264 instruction_->GetDexPc(),
265 this);
266 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700267
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100268 DataType::Type type = instruction_->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700269 mips64_codegen->MoveLocation(locations->Out(),
Alexey Frunzec61c0762017-04-10 13:54:23 -0700270 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700271 type);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700272 RestoreLiveRegisters(codegen, locations);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800273
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700274 __ Bc(GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700275 }
276
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100277 const char* GetDescription() const override { return "LoadStringSlowPathMIPS64"; }
Roland Levillain46648892015-06-19 16:07:18 +0100278
Alexey Frunze4dda3372015-06-01 18:31:49 -0700279 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700280 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS64);
281};
282
283class NullCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
284 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000285 explicit NullCheckSlowPathMIPS64(HNullCheck* instr) : SlowPathCodeMIPS64(instr) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700286
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100287 void EmitNativeCode(CodeGenerator* codegen) override {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700288 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
289 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000290 if (instruction_->CanThrowIntoCatchBlock()) {
291 // Live registers will be restored in the catch block if caught.
292 SaveLiveRegisters(codegen, instruction_->GetLocations());
293 }
Serban Constantinescufc734082016-07-19 17:18:07 +0100294 mips64_codegen->InvokeRuntime(kQuickThrowNullPointer,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700295 instruction_,
296 instruction_->GetDexPc(),
297 this);
298 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
299 }
300
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100301 bool IsFatal() const override { return true; }
Alexandre Rames8158f282015-08-07 10:26:17 +0100302
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100303 const char* GetDescription() const override { return "NullCheckSlowPathMIPS64"; }
Roland Levillain46648892015-06-19 16:07:18 +0100304
Alexey Frunze4dda3372015-06-01 18:31:49 -0700305 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700306 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS64);
307};
308
309class SuspendCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
310 public:
Roland Levillain3887c462015-08-12 18:15:42 +0100311 SuspendCheckSlowPathMIPS64(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000312 : SlowPathCodeMIPS64(instruction), successor_(successor) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700313
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100314 void EmitNativeCode(CodeGenerator* codegen) override {
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +0200315 LocationSummary* locations = instruction_->GetLocations();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700316 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
317 __ Bind(GetEntryLabel());
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +0200318 SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD.
Serban Constantinescufc734082016-07-19 17:18:07 +0100319 mips64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700320 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +0200321 RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD.
Alexey Frunze4dda3372015-06-01 18:31:49 -0700322 if (successor_ == nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700323 __ Bc(GetReturnLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700324 } else {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700325 __ Bc(mips64_codegen->GetLabelOf(successor_));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700326 }
327 }
328
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700329 Mips64Label* GetReturnLabel() {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700330 DCHECK(successor_ == nullptr);
331 return &return_label_;
332 }
333
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100334 const char* GetDescription() const override { return "SuspendCheckSlowPathMIPS64"; }
Roland Levillain46648892015-06-19 16:07:18 +0100335
Chris Larsena2045912017-11-02 12:39:54 -0700336 HBasicBlock* GetSuccessor() const {
337 return successor_;
338 }
339
Alexey Frunze4dda3372015-06-01 18:31:49 -0700340 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700341 // If not null, the block to branch to after the suspend check.
342 HBasicBlock* const successor_;
343
344 // If `successor_` is null, the label to branch to after the suspend check.
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700345 Mips64Label return_label_;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700346
347 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS64);
348};
349
350class TypeCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
351 public:
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800352 explicit TypeCheckSlowPathMIPS64(HInstruction* instruction, bool is_fatal)
353 : SlowPathCodeMIPS64(instruction), is_fatal_(is_fatal) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700354
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100355 void EmitNativeCode(CodeGenerator* codegen) override {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700356 LocationSummary* locations = instruction_->GetLocations();
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800357
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100358 uint32_t dex_pc = instruction_->GetDexPc();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700359 DCHECK(instruction_->IsCheckCast()
360 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
361 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
362
363 __ Bind(GetEntryLabel());
Alexey Frunzedfc30af2018-01-24 16:25:10 -0800364 if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800365 SaveLiveRegisters(codegen, locations);
366 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700367
368 // We're moving two locations to locations that could overlap, so we need a parallel
369 // move resolver.
370 InvokeRuntimeCallingConvention calling_convention;
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800371 codegen->EmitParallelMoves(locations->InAt(0),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700372 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100373 DataType::Type::kReference,
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800374 locations->InAt(1),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700375 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100376 DataType::Type::kReference);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700377 if (instruction_->IsInstanceOf()) {
Serban Constantinescufc734082016-07-19 17:18:07 +0100378 mips64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this);
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800379 CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100380 DataType::Type ret_type = instruction_->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700381 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
382 mips64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700383 } else {
384 DCHECK(instruction_->IsCheckCast());
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800385 mips64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this);
386 CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700387 }
388
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800389 if (!is_fatal_) {
390 RestoreLiveRegisters(codegen, locations);
391 __ Bc(GetExitLabel());
392 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700393 }
394
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100395 const char* GetDescription() const override { return "TypeCheckSlowPathMIPS64"; }
Roland Levillain46648892015-06-19 16:07:18 +0100396
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100397 bool IsFatal() const override { return is_fatal_; }
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800398
Alexey Frunze4dda3372015-06-01 18:31:49 -0700399 private:
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800400 const bool is_fatal_;
401
Alexey Frunze4dda3372015-06-01 18:31:49 -0700402 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS64);
403};
404
405class DeoptimizationSlowPathMIPS64 : public SlowPathCodeMIPS64 {
406 public:
Aart Bik42249c32016-01-07 15:33:50 -0800407 explicit DeoptimizationSlowPathMIPS64(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000408 : SlowPathCodeMIPS64(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700409
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100410 void EmitNativeCode(CodeGenerator* codegen) override {
Aart Bik42249c32016-01-07 15:33:50 -0800411 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700412 __ Bind(GetEntryLabel());
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +0100413 LocationSummary* locations = instruction_->GetLocations();
414 SaveLiveRegisters(codegen, locations);
415 InvokeRuntimeCallingConvention calling_convention;
416 __ LoadConst32(calling_convention.GetRegisterAt(0),
417 static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind()));
Serban Constantinescufc734082016-07-19 17:18:07 +0100418 mips64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +0100419 CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700420 }
421
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100422 const char* GetDescription() const override { return "DeoptimizationSlowPathMIPS64"; }
Roland Levillain46648892015-06-19 16:07:18 +0100423
Alexey Frunze4dda3372015-06-01 18:31:49 -0700424 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700425 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64);
426};
427
Alexey Frunze15958152017-02-09 19:08:30 -0800428class ArraySetSlowPathMIPS64 : public SlowPathCodeMIPS64 {
429 public:
430 explicit ArraySetSlowPathMIPS64(HInstruction* instruction) : SlowPathCodeMIPS64(instruction) {}
431
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100432 void EmitNativeCode(CodeGenerator* codegen) override {
Alexey Frunze15958152017-02-09 19:08:30 -0800433 LocationSummary* locations = instruction_->GetLocations();
434 __ Bind(GetEntryLabel());
435 SaveLiveRegisters(codegen, locations);
436
437 InvokeRuntimeCallingConvention calling_convention;
Vladimir Markoca6fff82017-10-03 14:49:14 +0100438 HParallelMove parallel_move(codegen->GetGraph()->GetAllocator());
Alexey Frunze15958152017-02-09 19:08:30 -0800439 parallel_move.AddMove(
440 locations->InAt(0),
441 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100442 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800443 nullptr);
444 parallel_move.AddMove(
445 locations->InAt(1),
446 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100447 DataType::Type::kInt32,
Alexey Frunze15958152017-02-09 19:08:30 -0800448 nullptr);
449 parallel_move.AddMove(
450 locations->InAt(2),
451 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100452 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800453 nullptr);
454 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
455
456 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
457 mips64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this);
458 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
459 RestoreLiveRegisters(codegen, locations);
460 __ Bc(GetExitLabel());
461 }
462
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100463 const char* GetDescription() const override { return "ArraySetSlowPathMIPS64"; }
Alexey Frunze15958152017-02-09 19:08:30 -0800464
465 private:
466 DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS64);
467};
468
469// Slow path marking an object reference `ref` during a read
470// barrier. The field `obj.field` in the object `obj` holding this
471// reference does not get updated by this slow path after marking (see
472// ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 below for that).
473//
474// This means that after the execution of this slow path, `ref` will
475// always be up-to-date, but `obj.field` may not; i.e., after the
476// flip, `ref` will be a to-space reference, but `obj.field` will
477// probably still be a from-space reference (unless it gets updated by
478// another thread, or if another thread installed another object
479// reference (different from `ref`) in `obj.field`).
480//
481// If `entrypoint` is a valid location it is assumed to already be
482// holding the entrypoint. The case where the entrypoint is passed in
483// is for the GcRoot read barrier.
484class ReadBarrierMarkSlowPathMIPS64 : public SlowPathCodeMIPS64 {
485 public:
486 ReadBarrierMarkSlowPathMIPS64(HInstruction* instruction,
487 Location ref,
488 Location entrypoint = Location::NoLocation())
489 : SlowPathCodeMIPS64(instruction), ref_(ref), entrypoint_(entrypoint) {
490 DCHECK(kEmitCompilerReadBarrier);
491 }
492
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100493 const char* GetDescription() const override { return "ReadBarrierMarkSlowPathMIPS"; }
Alexey Frunze15958152017-02-09 19:08:30 -0800494
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100495 void EmitNativeCode(CodeGenerator* codegen) override {
Alexey Frunze15958152017-02-09 19:08:30 -0800496 LocationSummary* locations = instruction_->GetLocations();
497 GpuRegister ref_reg = ref_.AsRegister<GpuRegister>();
498 DCHECK(locations->CanCall());
499 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg;
500 DCHECK(instruction_->IsInstanceFieldGet() ||
501 instruction_->IsStaticFieldGet() ||
502 instruction_->IsArrayGet() ||
503 instruction_->IsArraySet() ||
504 instruction_->IsLoadClass() ||
505 instruction_->IsLoadString() ||
506 instruction_->IsInstanceOf() ||
507 instruction_->IsCheckCast() ||
508 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) ||
509 (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified()))
510 << "Unexpected instruction in read barrier marking slow path: "
511 << instruction_->DebugName();
512
513 __ Bind(GetEntryLabel());
514 // No need to save live registers; it's taken care of by the
515 // entrypoint. Also, there is no need to update the stack mask,
516 // as this runtime call will not trigger a garbage collection.
517 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
518 DCHECK((V0 <= ref_reg && ref_reg <= T2) ||
519 (S2 <= ref_reg && ref_reg <= S7) ||
520 (ref_reg == S8)) << ref_reg;
521 // "Compact" slow path, saving two moves.
522 //
523 // Instead of using the standard runtime calling convention (input
524 // and output in A0 and V0 respectively):
525 //
526 // A0 <- ref
527 // V0 <- ReadBarrierMark(A0)
528 // ref <- V0
529 //
530 // we just use rX (the register containing `ref`) as input and output
531 // of a dedicated entrypoint:
532 //
533 // rX <- ReadBarrierMarkRegX(rX)
534 //
535 if (entrypoint_.IsValid()) {
536 mips64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this);
537 DCHECK_EQ(entrypoint_.AsRegister<GpuRegister>(), T9);
538 __ Jalr(entrypoint_.AsRegister<GpuRegister>());
539 __ Nop();
540 } else {
541 int32_t entry_point_offset =
Roland Levillain97c46462017-05-11 14:04:03 +0100542 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1);
Alexey Frunze15958152017-02-09 19:08:30 -0800543 // This runtime call does not require a stack map.
544 mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset,
545 instruction_,
546 this);
547 }
548 __ Bc(GetExitLabel());
549 }
550
551 private:
552 // The location (register) of the marked object reference.
553 const Location ref_;
554
555 // The location of the entrypoint if already loaded.
556 const Location entrypoint_;
557
558 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS64);
559};
560
561// Slow path marking an object reference `ref` during a read barrier,
562// and if needed, atomically updating the field `obj.field` in the
563// object `obj` holding this reference after marking (contrary to
564// ReadBarrierMarkSlowPathMIPS64 above, which never tries to update
565// `obj.field`).
566//
567// This means that after the execution of this slow path, both `ref`
568// and `obj.field` will be up-to-date; i.e., after the flip, both will
569// hold the same to-space reference (unless another thread installed
570// another object reference (different from `ref`) in `obj.field`).
571class ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 : public SlowPathCodeMIPS64 {
572 public:
573 ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(HInstruction* instruction,
574 Location ref,
575 GpuRegister obj,
576 Location field_offset,
577 GpuRegister temp1)
578 : SlowPathCodeMIPS64(instruction),
579 ref_(ref),
580 obj_(obj),
581 field_offset_(field_offset),
582 temp1_(temp1) {
583 DCHECK(kEmitCompilerReadBarrier);
584 }
585
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100586 const char* GetDescription() const override {
Alexey Frunze15958152017-02-09 19:08:30 -0800587 return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS64";
588 }
589
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100590 void EmitNativeCode(CodeGenerator* codegen) override {
Alexey Frunze15958152017-02-09 19:08:30 -0800591 LocationSummary* locations = instruction_->GetLocations();
592 GpuRegister ref_reg = ref_.AsRegister<GpuRegister>();
593 DCHECK(locations->CanCall());
594 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg;
595 // This slow path is only used by the UnsafeCASObject intrinsic.
596 DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()))
597 << "Unexpected instruction in read barrier marking and field updating slow path: "
598 << instruction_->DebugName();
599 DCHECK(instruction_->GetLocations()->Intrinsified());
600 DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject);
601 DCHECK(field_offset_.IsRegister()) << field_offset_;
602
603 __ Bind(GetEntryLabel());
604
605 // Save the old reference.
606 // Note that we cannot use AT or TMP to save the old reference, as those
607 // are used by the code that follows, but we need the old reference after
608 // the call to the ReadBarrierMarkRegX entry point.
609 DCHECK_NE(temp1_, AT);
610 DCHECK_NE(temp1_, TMP);
611 __ Move(temp1_, ref_reg);
612
613 // No need to save live registers; it's taken care of by the
614 // entrypoint. Also, there is no need to update the stack mask,
615 // as this runtime call will not trigger a garbage collection.
616 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
617 DCHECK((V0 <= ref_reg && ref_reg <= T2) ||
618 (S2 <= ref_reg && ref_reg <= S7) ||
619 (ref_reg == S8)) << ref_reg;
620 // "Compact" slow path, saving two moves.
621 //
622 // Instead of using the standard runtime calling convention (input
623 // and output in A0 and V0 respectively):
624 //
625 // A0 <- ref
626 // V0 <- ReadBarrierMark(A0)
627 // ref <- V0
628 //
629 // we just use rX (the register containing `ref`) as input and output
630 // of a dedicated entrypoint:
631 //
632 // rX <- ReadBarrierMarkRegX(rX)
633 //
634 int32_t entry_point_offset =
Roland Levillain97c46462017-05-11 14:04:03 +0100635 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1);
Alexey Frunze15958152017-02-09 19:08:30 -0800636 // This runtime call does not require a stack map.
637 mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset,
638 instruction_,
639 this);
640
641 // If the new reference is different from the old reference,
642 // update the field in the holder (`*(obj_ + field_offset_)`).
643 //
644 // Note that this field could also hold a different object, if
645 // another thread had concurrently changed it. In that case, the
646 // the compare-and-set (CAS) loop below would abort, leaving the
647 // field as-is.
648 Mips64Label done;
649 __ Beqc(temp1_, ref_reg, &done);
650
651 // Update the the holder's field atomically. This may fail if
652 // mutator updates before us, but it's OK. This is achieved
653 // using a strong compare-and-set (CAS) operation with relaxed
654 // memory synchronization ordering, where the expected value is
655 // the old reference and the desired value is the new reference.
656
657 // Convenience aliases.
658 GpuRegister base = obj_;
659 GpuRegister offset = field_offset_.AsRegister<GpuRegister>();
660 GpuRegister expected = temp1_;
661 GpuRegister value = ref_reg;
662 GpuRegister tmp_ptr = TMP; // Pointer to actual memory.
663 GpuRegister tmp = AT; // Value in memory.
664
665 __ Daddu(tmp_ptr, base, offset);
666
667 if (kPoisonHeapReferences) {
668 __ PoisonHeapReference(expected);
669 // Do not poison `value` if it is the same register as
670 // `expected`, which has just been poisoned.
671 if (value != expected) {
672 __ PoisonHeapReference(value);
673 }
674 }
675
676 // do {
677 // tmp = [r_ptr] - expected;
678 // } while (tmp == 0 && failure([r_ptr] <- r_new_value));
679
680 Mips64Label loop_head, exit_loop;
681 __ Bind(&loop_head);
682 __ Ll(tmp, tmp_ptr);
683 // The LL instruction sign-extends the 32-bit value, but
684 // 32-bit references must be zero-extended. Zero-extend `tmp`.
685 __ Dext(tmp, tmp, 0, 32);
686 __ Bnec(tmp, expected, &exit_loop);
687 __ Move(tmp, value);
688 __ Sc(tmp, tmp_ptr);
689 __ Beqzc(tmp, &loop_head);
690 __ Bind(&exit_loop);
691
692 if (kPoisonHeapReferences) {
693 __ UnpoisonHeapReference(expected);
694 // Do not unpoison `value` if it is the same register as
695 // `expected`, which has just been unpoisoned.
696 if (value != expected) {
697 __ UnpoisonHeapReference(value);
698 }
699 }
700
701 __ Bind(&done);
702 __ Bc(GetExitLabel());
703 }
704
705 private:
706 // The location (register) of the marked object reference.
707 const Location ref_;
708 // The register containing the object holding the marked object reference field.
709 const GpuRegister obj_;
710 // The location of the offset of the marked reference field within `obj_`.
711 Location field_offset_;
712
713 const GpuRegister temp1_;
714
715 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS64);
716};
717
718// Slow path generating a read barrier for a heap reference.
719class ReadBarrierForHeapReferenceSlowPathMIPS64 : public SlowPathCodeMIPS64 {
720 public:
721 ReadBarrierForHeapReferenceSlowPathMIPS64(HInstruction* instruction,
722 Location out,
723 Location ref,
724 Location obj,
725 uint32_t offset,
726 Location index)
727 : SlowPathCodeMIPS64(instruction),
728 out_(out),
729 ref_(ref),
730 obj_(obj),
731 offset_(offset),
732 index_(index) {
733 DCHECK(kEmitCompilerReadBarrier);
734 // If `obj` is equal to `out` or `ref`, it means the initial object
735 // has been overwritten by (or after) the heap object reference load
736 // to be instrumented, e.g.:
737 //
738 // __ LoadFromOffset(kLoadWord, out, out, offset);
739 // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset);
740 //
741 // In that case, we have lost the information about the original
742 // object, and the emitted read barrier cannot work properly.
743 DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out;
744 DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref;
745 }
746
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100747 void EmitNativeCode(CodeGenerator* codegen) override {
Alexey Frunze15958152017-02-09 19:08:30 -0800748 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
749 LocationSummary* locations = instruction_->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100750 DataType::Type type = DataType::Type::kReference;
Alexey Frunze15958152017-02-09 19:08:30 -0800751 GpuRegister reg_out = out_.AsRegister<GpuRegister>();
752 DCHECK(locations->CanCall());
753 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
754 DCHECK(instruction_->IsInstanceFieldGet() ||
755 instruction_->IsStaticFieldGet() ||
756 instruction_->IsArrayGet() ||
757 instruction_->IsInstanceOf() ||
758 instruction_->IsCheckCast() ||
759 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()))
760 << "Unexpected instruction in read barrier for heap reference slow path: "
761 << instruction_->DebugName();
762
763 __ Bind(GetEntryLabel());
764 SaveLiveRegisters(codegen, locations);
765
766 // We may have to change the index's value, but as `index_` is a
767 // constant member (like other "inputs" of this slow path),
768 // introduce a copy of it, `index`.
769 Location index = index_;
770 if (index_.IsValid()) {
771 // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
772 if (instruction_->IsArrayGet()) {
773 // Compute the actual memory offset and store it in `index`.
774 GpuRegister index_reg = index_.AsRegister<GpuRegister>();
775 DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg));
776 if (codegen->IsCoreCalleeSaveRegister(index_reg)) {
777 // We are about to change the value of `index_reg` (see the
778 // calls to art::mips64::Mips64Assembler::Sll and
779 // art::mips64::MipsAssembler::Addiu32 below), but it has
780 // not been saved by the previous call to
781 // art::SlowPathCode::SaveLiveRegisters, as it is a
782 // callee-save register --
783 // art::SlowPathCode::SaveLiveRegisters does not consider
784 // callee-save registers, as it has been designed with the
785 // assumption that callee-save registers are supposed to be
786 // handled by the called function. So, as a callee-save
787 // register, `index_reg` _would_ eventually be saved onto
788 // the stack, but it would be too late: we would have
789 // changed its value earlier. Therefore, we manually save
790 // it here into another freely available register,
791 // `free_reg`, chosen of course among the caller-save
792 // registers (as a callee-save `free_reg` register would
793 // exhibit the same problem).
794 //
795 // Note we could have requested a temporary register from
796 // the register allocator instead; but we prefer not to, as
797 // this is a slow path, and we know we can find a
798 // caller-save register that is available.
799 GpuRegister free_reg = FindAvailableCallerSaveRegister(codegen);
800 __ Move(free_reg, index_reg);
801 index_reg = free_reg;
802 index = Location::RegisterLocation(index_reg);
803 } else {
804 // The initial register stored in `index_` has already been
805 // saved in the call to art::SlowPathCode::SaveLiveRegisters
806 // (as it is not a callee-save register), so we can freely
807 // use it.
808 }
809 // Shifting the index value contained in `index_reg` by the scale
810 // factor (2) cannot overflow in practice, as the runtime is
811 // unable to allocate object arrays with a size larger than
812 // 2^26 - 1 (that is, 2^28 - 4 bytes).
813 __ Sll(index_reg, index_reg, TIMES_4);
814 static_assert(
815 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
816 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
817 __ Addiu32(index_reg, index_reg, offset_);
818 } else {
819 // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile
820 // intrinsics, `index_` is not shifted by a scale factor of 2
821 // (as in the case of ArrayGet), as it is actually an offset
822 // to an object field within an object.
823 DCHECK(instruction_->IsInvoke()) << instruction_->DebugName();
824 DCHECK(instruction_->GetLocations()->Intrinsified());
825 DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) ||
826 (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile))
827 << instruction_->AsInvoke()->GetIntrinsic();
828 DCHECK_EQ(offset_, 0U);
829 DCHECK(index_.IsRegister());
830 }
831 }
832
833 // We're moving two or three locations to locations that could
834 // overlap, so we need a parallel move resolver.
835 InvokeRuntimeCallingConvention calling_convention;
Vladimir Markoca6fff82017-10-03 14:49:14 +0100836 HParallelMove parallel_move(codegen->GetGraph()->GetAllocator());
Alexey Frunze15958152017-02-09 19:08:30 -0800837 parallel_move.AddMove(ref_,
838 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100839 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800840 nullptr);
841 parallel_move.AddMove(obj_,
842 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100843 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800844 nullptr);
845 if (index.IsValid()) {
846 parallel_move.AddMove(index,
847 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100848 DataType::Type::kInt32,
Alexey Frunze15958152017-02-09 19:08:30 -0800849 nullptr);
850 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
851 } else {
852 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
853 __ LoadConst32(calling_convention.GetRegisterAt(2), offset_);
854 }
855 mips64_codegen->InvokeRuntime(kQuickReadBarrierSlow,
856 instruction_,
857 instruction_->GetDexPc(),
858 this);
859 CheckEntrypointTypes<
860 kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>();
861 mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type);
862
863 RestoreLiveRegisters(codegen, locations);
864 __ Bc(GetExitLabel());
865 }
866
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100867 const char* GetDescription() const override {
Alexey Frunze15958152017-02-09 19:08:30 -0800868 return "ReadBarrierForHeapReferenceSlowPathMIPS64";
869 }
870
871 private:
872 GpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) {
873 size_t ref = static_cast<int>(ref_.AsRegister<GpuRegister>());
874 size_t obj = static_cast<int>(obj_.AsRegister<GpuRegister>());
875 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
876 if (i != ref &&
877 i != obj &&
878 !codegen->IsCoreCalleeSaveRegister(i) &&
879 !codegen->IsBlockedCoreRegister(i)) {
880 return static_cast<GpuRegister>(i);
881 }
882 }
883 // We shall never fail to find a free caller-save register, as
884 // there are more than two core caller-save registers on MIPS64
885 // (meaning it is possible to find one which is different from
886 // `ref` and `obj`).
887 DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u);
888 LOG(FATAL) << "Could not find a free caller-save register";
889 UNREACHABLE();
890 }
891
892 const Location out_;
893 const Location ref_;
894 const Location obj_;
895 const uint32_t offset_;
896 // An additional location containing an index to an array.
897 // Only used for HArrayGet and the UnsafeGetObject &
898 // UnsafeGetObjectVolatile intrinsics.
899 const Location index_;
900
901 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS64);
902};
903
904// Slow path generating a read barrier for a GC root.
905class ReadBarrierForRootSlowPathMIPS64 : public SlowPathCodeMIPS64 {
906 public:
907 ReadBarrierForRootSlowPathMIPS64(HInstruction* instruction, Location out, Location root)
908 : SlowPathCodeMIPS64(instruction), out_(out), root_(root) {
909 DCHECK(kEmitCompilerReadBarrier);
910 }
911
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100912 void EmitNativeCode(CodeGenerator* codegen) override {
Alexey Frunze15958152017-02-09 19:08:30 -0800913 LocationSummary* locations = instruction_->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100914 DataType::Type type = DataType::Type::kReference;
Alexey Frunze15958152017-02-09 19:08:30 -0800915 GpuRegister reg_out = out_.AsRegister<GpuRegister>();
916 DCHECK(locations->CanCall());
917 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
918 DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString())
919 << "Unexpected instruction in read barrier for GC root slow path: "
920 << instruction_->DebugName();
921
922 __ Bind(GetEntryLabel());
923 SaveLiveRegisters(codegen, locations);
924
925 InvokeRuntimeCallingConvention calling_convention;
926 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
927 mips64_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
928 root_,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100929 DataType::Type::kReference);
Alexey Frunze15958152017-02-09 19:08:30 -0800930 mips64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow,
931 instruction_,
932 instruction_->GetDexPc(),
933 this);
934 CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>();
935 mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type);
936
937 RestoreLiveRegisters(codegen, locations);
938 __ Bc(GetExitLabel());
939 }
940
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100941 const char* GetDescription() const override { return "ReadBarrierForRootSlowPathMIPS64"; }
Alexey Frunze15958152017-02-09 19:08:30 -0800942
943 private:
944 const Location out_;
945 const Location root_;
946
947 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS64);
948};
949
Alexey Frunze4dda3372015-06-01 18:31:49 -0700950CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100951 const CompilerOptions& compiler_options,
952 OptimizingCompilerStats* stats)
Alexey Frunze4dda3372015-06-01 18:31:49 -0700953 : CodeGenerator(graph,
954 kNumberOfGpuRegisters,
955 kNumberOfFpuRegisters,
Andreas Gampe3db70682018-12-26 15:12:03 -0800956 /* number_of_register_pairs= */ 0,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700957 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
958 arraysize(kCoreCalleeSaves)),
959 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
960 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +0100961 compiler_options,
962 stats),
Vladimir Marko225b6462015-09-28 12:17:40 +0100963 block_labels_(nullptr),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700964 location_builder_(graph, this),
965 instruction_visitor_(graph, this),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100966 move_resolver_(graph->GetAllocator(), this),
Vladimir Markoa0431112018-06-25 09:32:54 +0100967 assembler_(graph->GetAllocator(),
968 compiler_options.GetInstructionSetFeatures()->AsMips64InstructionSetFeatures()),
Alexey Frunzef63f5692016-12-13 17:43:11 -0800969 uint32_literals_(std::less<uint32_t>(),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100970 graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze19f6c692016-11-30 19:19:55 -0800971 uint64_literals_(std::less<uint64_t>(),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100972 graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000973 boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100974 method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000975 boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100976 type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000977 boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100978 string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko2d06e022019-07-08 15:45:19 +0100979 boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze627c1a02017-01-30 19:28:14 -0800980 jit_string_patches_(StringReferenceValueComparator(),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100981 graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze627c1a02017-01-30 19:28:14 -0800982 jit_class_patches_(TypeReferenceValueComparator(),
Vladimir Markoca6fff82017-10-03 14:49:14 +0100983 graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700984 // Save RA (containing the return address) to mimic Quick.
985 AddAllocatedRegister(Location::RegisterLocation(RA));
986}
987
988#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100989// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
990#define __ down_cast<Mips64Assembler*>(GetAssembler())-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700991#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value()
Alexey Frunze4dda3372015-06-01 18:31:49 -0700992
993void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700994 // Ensure that we fix up branches.
995 __ FinalizeCode();
996
997 // Adjust native pc offsets in stack maps.
Vladimir Marko174b2e22017-10-12 13:34:49 +0100998 StackMapStream* stack_map_stream = GetStackMapStream();
999 for (size_t i = 0, num = stack_map_stream->GetNumberOfStackMaps(); i != num; ++i) {
David Srbeckyd02b23f2018-05-29 23:27:22 +01001000 uint32_t old_position = stack_map_stream->GetStackMapNativePcOffset(i);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001001 uint32_t new_position = __ GetAdjustedPosition(old_position);
1002 DCHECK_GE(new_position, old_position);
Vladimir Marko174b2e22017-10-12 13:34:49 +01001003 stack_map_stream->SetStackMapNativePcOffset(i, new_position);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001004 }
1005
1006 // Adjust pc offsets for the disassembly information.
1007 if (disasm_info_ != nullptr) {
1008 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
1009 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
1010 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
1011 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
1012 it.second.start = __ GetAdjustedPosition(it.second.start);
1013 it.second.end = __ GetAdjustedPosition(it.second.end);
1014 }
1015 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
1016 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
1017 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
1018 }
1019 }
1020
Alexey Frunze4dda3372015-06-01 18:31:49 -07001021 CodeGenerator::Finalize(allocator);
1022}
1023
1024Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const {
1025 return codegen_->GetAssembler();
1026}
1027
1028void ParallelMoveResolverMIPS64::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01001029 MoveOperands* move = moves_[index];
Alexey Frunze4dda3372015-06-01 18:31:49 -07001030 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
1031}
1032
1033void ParallelMoveResolverMIPS64::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01001034 MoveOperands* move = moves_[index];
Alexey Frunze4dda3372015-06-01 18:31:49 -07001035 codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType());
1036}
1037
1038void ParallelMoveResolverMIPS64::RestoreScratch(int reg) {
1039 // Pop reg
1040 __ Ld(GpuRegister(reg), SP, 0);
Lazar Trsicd9672662015-09-03 17:33:01 +02001041 __ DecreaseFrameSize(kMips64DoublewordSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001042}
1043
1044void ParallelMoveResolverMIPS64::SpillScratch(int reg) {
1045 // Push reg
Lazar Trsicd9672662015-09-03 17:33:01 +02001046 __ IncreaseFrameSize(kMips64DoublewordSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001047 __ Sd(GpuRegister(reg), SP, 0);
1048}
1049
1050void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) {
1051 LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord;
1052 StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord;
1053 // Allocate a scratch register other than TMP, if available.
1054 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
1055 // automatically unspilled when the scratch scope object is destroyed).
1056 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
1057 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
Lazar Trsicd9672662015-09-03 17:33:01 +02001058 int stack_offset = ensure_scratch.IsSpilled() ? kMips64DoublewordSize : 0;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001059 __ LoadFromOffset(load_type,
1060 GpuRegister(ensure_scratch.GetRegister()),
1061 SP,
1062 index1 + stack_offset);
1063 __ LoadFromOffset(load_type,
1064 TMP,
1065 SP,
1066 index2 + stack_offset);
1067 __ StoreToOffset(store_type,
1068 GpuRegister(ensure_scratch.GetRegister()),
1069 SP,
1070 index2 + stack_offset);
1071 __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset);
1072}
1073
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001074void ParallelMoveResolverMIPS64::ExchangeQuadSlots(int index1, int index2) {
1075 __ LoadFpuFromOffset(kLoadQuadword, FTMP, SP, index1);
1076 __ LoadFpuFromOffset(kLoadQuadword, FTMP2, SP, index2);
1077 __ StoreFpuToOffset(kStoreQuadword, FTMP, SP, index2);
1078 __ StoreFpuToOffset(kStoreQuadword, FTMP2, SP, index1);
1079}
1080
Alexey Frunze4dda3372015-06-01 18:31:49 -07001081static dwarf::Reg DWARFReg(GpuRegister reg) {
1082 return dwarf::Reg::Mips64Core(static_cast<int>(reg));
1083}
1084
David Srbeckyba702002016-02-01 18:15:29 +00001085static dwarf::Reg DWARFReg(FpuRegister reg) {
1086 return dwarf::Reg::Mips64Fp(static_cast<int>(reg));
1087}
Alexey Frunze4dda3372015-06-01 18:31:49 -07001088
1089void CodeGeneratorMIPS64::GenerateFrameEntry() {
1090 __ Bind(&frame_entry_label_);
1091
Nicolas Geoffray8d728322018-01-18 22:44:32 +00001092 if (GetCompilerOptions().CountHotnessInCompiledCode()) {
Goran Jakovljevicfeec1672018-02-08 10:20:14 +01001093 __ Lhu(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value());
1094 __ Addiu(TMP, TMP, 1);
1095 __ Sh(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value());
Nicolas Geoffray8d728322018-01-18 22:44:32 +00001096 }
1097
Vladimir Marko33bff252017-11-01 14:35:42 +00001098 bool do_overflow_check =
1099 FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips64) || !IsLeafMethod();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001100
1101 if (do_overflow_check) {
Vladimir Marko33bff252017-11-01 14:35:42 +00001102 __ LoadFromOffset(
1103 kLoadWord,
1104 ZERO,
1105 SP,
1106 -static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kMips64)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07001107 RecordPcInfo(nullptr, 0);
1108 }
1109
Alexey Frunze4dda3372015-06-01 18:31:49 -07001110 if (HasEmptyFrame()) {
1111 return;
1112 }
1113
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001114 // Make sure the frame size isn't unreasonably large.
Vladimir Marko33bff252017-11-01 14:35:42 +00001115 if (GetFrameSize() > GetStackOverflowReservedBytes(InstructionSet::kMips64)) {
1116 LOG(FATAL) << "Stack frame larger than "
1117 << GetStackOverflowReservedBytes(InstructionSet::kMips64) << " bytes";
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001118 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001119
1120 // Spill callee-saved registers.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001121
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001122 uint32_t ofs = GetFrameSize();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001123 __ IncreaseFrameSize(ofs);
1124
1125 for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) {
1126 GpuRegister reg = kCoreCalleeSaves[i];
1127 if (allocated_registers_.ContainsCoreRegister(reg)) {
Lazar Trsicd9672662015-09-03 17:33:01 +02001128 ofs -= kMips64DoublewordSize;
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001129 __ StoreToOffset(kStoreDoubleword, reg, SP, ofs);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001130 __ cfi().RelOffset(DWARFReg(reg), ofs);
1131 }
1132 }
1133
1134 for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) {
1135 FpuRegister reg = kFpuCalleeSaves[i];
1136 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
Lazar Trsicd9672662015-09-03 17:33:01 +02001137 ofs -= kMips64DoublewordSize;
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001138 __ StoreFpuToOffset(kStoreDoubleword, reg, SP, ofs);
David Srbeckyba702002016-02-01 18:15:29 +00001139 __ cfi().RelOffset(DWARFReg(reg), ofs);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001140 }
1141 }
1142
Nicolas Geoffray96eeb4e2016-10-12 22:03:31 +01001143 // Save the current method if we need it. Note that we do not
1144 // do this in HCurrentMethod, as the instruction might have been removed
1145 // in the SSA graph.
1146 if (RequiresCurrentMethod()) {
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001147 __ StoreToOffset(kStoreDoubleword, kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
Nicolas Geoffray96eeb4e2016-10-12 22:03:31 +01001148 }
Goran Jakovljevicc6418422016-12-05 16:31:55 +01001149
1150 if (GetGraph()->HasShouldDeoptimizeFlag()) {
1151 // Initialize should_deoptimize flag to 0.
1152 __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag());
1153 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001154}
1155
1156void CodeGeneratorMIPS64::GenerateFrameExit() {
1157 __ cfi().RememberState();
1158
Alexey Frunze4dda3372015-06-01 18:31:49 -07001159 if (!HasEmptyFrame()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001160 // Restore callee-saved registers.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001161
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001162 // For better instruction scheduling restore RA before other registers.
1163 uint32_t ofs = GetFrameSize();
1164 for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001165 GpuRegister reg = kCoreCalleeSaves[i];
1166 if (allocated_registers_.ContainsCoreRegister(reg)) {
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001167 ofs -= kMips64DoublewordSize;
1168 __ LoadFromOffset(kLoadDoubleword, reg, SP, ofs);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001169 __ cfi().Restore(DWARFReg(reg));
1170 }
1171 }
1172
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001173 for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) {
1174 FpuRegister reg = kFpuCalleeSaves[i];
1175 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
1176 ofs -= kMips64DoublewordSize;
1177 __ LoadFpuFromOffset(kLoadDoubleword, reg, SP, ofs);
1178 __ cfi().Restore(DWARFReg(reg));
1179 }
1180 }
1181
1182 __ DecreaseFrameSize(GetFrameSize());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001183 }
1184
Alexey Frunzee104d6e2017-03-21 20:16:05 -07001185 __ Jic(RA, 0);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001186
1187 __ cfi().RestoreState();
1188 __ cfi().DefCFAOffset(GetFrameSize());
1189}
1190
1191void CodeGeneratorMIPS64::Bind(HBasicBlock* block) {
1192 __ Bind(GetLabelOf(block));
1193}
1194
1195void CodeGeneratorMIPS64::MoveLocation(Location destination,
1196 Location source,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001197 DataType::Type dst_type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001198 if (source.Equals(destination)) {
1199 return;
1200 }
1201
1202 // A valid move can always be inferred from the destination and source
1203 // locations. When moving from and to a register, the argument type can be
1204 // used to generate 32bit instead of 64bit moves.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001205 bool unspecified_type = (dst_type == DataType::Type::kVoid);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001206 DCHECK_EQ(unspecified_type, false);
1207
1208 if (destination.IsRegister() || destination.IsFpuRegister()) {
1209 if (unspecified_type) {
1210 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
1211 if (source.IsStackSlot() ||
1212 (src_cst != nullptr && (src_cst->IsIntConstant()
1213 || src_cst->IsFloatConstant()
1214 || src_cst->IsNullConstant()))) {
1215 // For stack slots and 32bit constants, a 64bit type is appropriate.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001216 dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001217 } else {
1218 // If the source is a double stack slot or a 64bit constant, a 64bit
1219 // type is appropriate. Else the source is a register, and since the
1220 // type has not been specified, we chose a 64bit type to force a 64bit
1221 // move.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001222 dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001223 }
1224 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001225 DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) ||
1226 (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07001227 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
1228 // Move to GPR/FPR from stack
1229 LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001230 if (DataType::IsFloatingPointType(dst_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001231 __ LoadFpuFromOffset(load_type,
1232 destination.AsFpuRegister<FpuRegister>(),
1233 SP,
1234 source.GetStackIndex());
1235 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001236 // TODO: use load_type = kLoadUnsignedWord when type == DataType::Type::kReference.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001237 __ LoadFromOffset(load_type,
1238 destination.AsRegister<GpuRegister>(),
1239 SP,
1240 source.GetStackIndex());
1241 }
Lena Djokicca8c2952017-05-29 11:31:46 +02001242 } else if (source.IsSIMDStackSlot()) {
1243 __ LoadFpuFromOffset(kLoadQuadword,
1244 destination.AsFpuRegister<FpuRegister>(),
1245 SP,
1246 source.GetStackIndex());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001247 } else if (source.IsConstant()) {
1248 // Move to GPR/FPR from constant
1249 GpuRegister gpr = AT;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001250 if (!DataType::IsFloatingPointType(dst_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001251 gpr = destination.AsRegister<GpuRegister>();
1252 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001253 if (dst_type == DataType::Type::kInt32 || dst_type == DataType::Type::kFloat32) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001254 int32_t value = GetInt32ValueOf(source.GetConstant()->AsConstant());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001255 if (DataType::IsFloatingPointType(dst_type) && value == 0) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001256 gpr = ZERO;
1257 } else {
1258 __ LoadConst32(gpr, value);
1259 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001260 } else {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001261 int64_t value = GetInt64ValueOf(source.GetConstant()->AsConstant());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001262 if (DataType::IsFloatingPointType(dst_type) && value == 0) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001263 gpr = ZERO;
1264 } else {
1265 __ LoadConst64(gpr, value);
1266 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001267 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001268 if (dst_type == DataType::Type::kFloat32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001269 __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001270 } else if (dst_type == DataType::Type::kFloat64) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001271 __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>());
1272 }
Calin Juravlee460d1d2015-09-29 04:52:17 +01001273 } else if (source.IsRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001274 if (destination.IsRegister()) {
1275 // Move to GPR from GPR
1276 __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>());
1277 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +01001278 DCHECK(destination.IsFpuRegister());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001279 if (DataType::Is64BitType(dst_type)) {
Calin Juravlee460d1d2015-09-29 04:52:17 +01001280 __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>());
1281 } else {
1282 __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>());
1283 }
1284 }
1285 } else if (source.IsFpuRegister()) {
1286 if (destination.IsFpuRegister()) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001287 if (GetGraph()->HasSIMD()) {
1288 __ MoveV(VectorRegisterFrom(destination),
1289 VectorRegisterFrom(source));
Alexey Frunze4dda3372015-06-01 18:31:49 -07001290 } else {
Lena Djokicca8c2952017-05-29 11:31:46 +02001291 // Move to FPR from FPR
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001292 if (dst_type == DataType::Type::kFloat32) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001293 __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
1294 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001295 DCHECK_EQ(dst_type, DataType::Type::kFloat64);
Lena Djokicca8c2952017-05-29 11:31:46 +02001296 __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
1297 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001298 }
Calin Juravlee460d1d2015-09-29 04:52:17 +01001299 } else {
1300 DCHECK(destination.IsRegister());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001301 if (DataType::Is64BitType(dst_type)) {
Calin Juravlee460d1d2015-09-29 04:52:17 +01001302 __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>());
1303 } else {
1304 __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>());
1305 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001306 }
1307 }
Lena Djokicca8c2952017-05-29 11:31:46 +02001308 } else if (destination.IsSIMDStackSlot()) {
1309 if (source.IsFpuRegister()) {
1310 __ StoreFpuToOffset(kStoreQuadword,
1311 source.AsFpuRegister<FpuRegister>(),
1312 SP,
1313 destination.GetStackIndex());
1314 } else {
1315 DCHECK(source.IsSIMDStackSlot());
1316 __ LoadFpuFromOffset(kLoadQuadword,
1317 FTMP,
1318 SP,
1319 source.GetStackIndex());
1320 __ StoreFpuToOffset(kStoreQuadword,
1321 FTMP,
1322 SP,
1323 destination.GetStackIndex());
1324 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001325 } else { // The destination is not a register. It must be a stack slot.
1326 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
1327 if (source.IsRegister() || source.IsFpuRegister()) {
1328 if (unspecified_type) {
1329 if (source.IsRegister()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001330 dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001331 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001332 dst_type =
1333 destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001334 }
1335 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001336 DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) &&
1337 (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07001338 // Move to stack from GPR/FPR
1339 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
1340 if (source.IsRegister()) {
1341 __ StoreToOffset(store_type,
1342 source.AsRegister<GpuRegister>(),
1343 SP,
1344 destination.GetStackIndex());
1345 } else {
1346 __ StoreFpuToOffset(store_type,
1347 source.AsFpuRegister<FpuRegister>(),
1348 SP,
1349 destination.GetStackIndex());
1350 }
1351 } else if (source.IsConstant()) {
1352 // Move to stack from constant
1353 HConstant* src_cst = source.GetConstant();
1354 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001355 GpuRegister gpr = ZERO;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001356 if (destination.IsStackSlot()) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001357 int32_t value = GetInt32ValueOf(src_cst->AsConstant());
1358 if (value != 0) {
1359 gpr = TMP;
1360 __ LoadConst32(gpr, value);
1361 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001362 } else {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001363 DCHECK(destination.IsDoubleStackSlot());
1364 int64_t value = GetInt64ValueOf(src_cst->AsConstant());
1365 if (value != 0) {
1366 gpr = TMP;
1367 __ LoadConst64(gpr, value);
1368 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001369 }
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001370 __ StoreToOffset(store_type, gpr, SP, destination.GetStackIndex());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001371 } else {
1372 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
1373 DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot());
1374 // Move to stack from stack
1375 if (destination.IsStackSlot()) {
1376 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
1377 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
1378 } else {
1379 __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex());
1380 __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex());
1381 }
1382 }
1383 }
1384}
1385
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001386void CodeGeneratorMIPS64::SwapLocations(Location loc1, Location loc2, DataType::Type type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001387 DCHECK(!loc1.IsConstant());
1388 DCHECK(!loc2.IsConstant());
1389
1390 if (loc1.Equals(loc2)) {
1391 return;
1392 }
1393
1394 bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot();
1395 bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot();
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001396 bool is_simd1 = loc1.IsSIMDStackSlot();
1397 bool is_simd2 = loc2.IsSIMDStackSlot();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001398 bool is_fp_reg1 = loc1.IsFpuRegister();
1399 bool is_fp_reg2 = loc2.IsFpuRegister();
1400
1401 if (loc2.IsRegister() && loc1.IsRegister()) {
1402 // Swap 2 GPRs
1403 GpuRegister r1 = loc1.AsRegister<GpuRegister>();
1404 GpuRegister r2 = loc2.AsRegister<GpuRegister>();
1405 __ Move(TMP, r2);
1406 __ Move(r2, r1);
1407 __ Move(r1, TMP);
1408 } else if (is_fp_reg2 && is_fp_reg1) {
1409 // Swap 2 FPRs
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001410 if (GetGraph()->HasSIMD()) {
1411 __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(loc1));
1412 __ MoveV(VectorRegisterFrom(loc1), VectorRegisterFrom(loc2));
1413 __ MoveV(VectorRegisterFrom(loc2), static_cast<VectorRegister>(FTMP));
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001414 } else {
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001415 FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>();
1416 FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>();
1417 if (type == DataType::Type::kFloat32) {
1418 __ MovS(FTMP, r1);
1419 __ MovS(r1, r2);
1420 __ MovS(r2, FTMP);
1421 } else {
1422 DCHECK_EQ(type, DataType::Type::kFloat64);
1423 __ MovD(FTMP, r1);
1424 __ MovD(r1, r2);
1425 __ MovD(r2, FTMP);
1426 }
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001427 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001428 } else if (is_slot1 != is_slot2) {
1429 // Swap GPR/FPR and stack slot
1430 Location reg_loc = is_slot1 ? loc2 : loc1;
1431 Location mem_loc = is_slot1 ? loc1 : loc2;
1432 LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword;
1433 StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001434 // TODO: use load_type = kLoadUnsignedWord when type == DataType::Type::kReference.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001435 __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex());
1436 if (reg_loc.IsFpuRegister()) {
1437 __ StoreFpuToOffset(store_type,
1438 reg_loc.AsFpuRegister<FpuRegister>(),
1439 SP,
1440 mem_loc.GetStackIndex());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001441 if (mem_loc.IsStackSlot()) {
1442 __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
1443 } else {
1444 DCHECK(mem_loc.IsDoubleStackSlot());
1445 __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
1446 }
1447 } else {
1448 __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex());
1449 __ Move(reg_loc.AsRegister<GpuRegister>(), TMP);
1450 }
1451 } else if (is_slot1 && is_slot2) {
1452 move_resolver_.Exchange(loc1.GetStackIndex(),
1453 loc2.GetStackIndex(),
1454 loc1.IsDoubleStackSlot());
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001455 } else if (is_simd1 && is_simd2) {
1456 move_resolver_.ExchangeQuadSlots(loc1.GetStackIndex(), loc2.GetStackIndex());
1457 } else if ((is_fp_reg1 && is_simd2) || (is_fp_reg2 && is_simd1)) {
1458 Location fp_reg_loc = is_fp_reg1 ? loc1 : loc2;
1459 Location mem_loc = is_fp_reg1 ? loc2 : loc1;
1460 __ LoadFpuFromOffset(kLoadQuadword, FTMP, SP, mem_loc.GetStackIndex());
1461 __ StoreFpuToOffset(kStoreQuadword,
1462 fp_reg_loc.AsFpuRegister<FpuRegister>(),
1463 SP,
1464 mem_loc.GetStackIndex());
1465 __ MoveV(VectorRegisterFrom(fp_reg_loc), static_cast<VectorRegister>(FTMP));
Alexey Frunze4dda3372015-06-01 18:31:49 -07001466 } else {
1467 LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2;
1468 }
1469}
1470
Calin Juravle175dc732015-08-25 15:42:32 +01001471void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) {
1472 DCHECK(location.IsRegister());
1473 __ LoadConst32(location.AsRegister<GpuRegister>(), value);
1474}
1475
Calin Juravlee460d1d2015-09-29 04:52:17 +01001476void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) {
1477 if (location.IsRegister()) {
1478 locations->AddTemp(location);
1479 } else {
1480 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
1481 }
1482}
1483
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01001484void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object,
1485 GpuRegister value,
1486 bool value_can_be_null) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001487 Mips64Label done;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001488 GpuRegister card = AT;
1489 GpuRegister temp = TMP;
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01001490 if (value_can_be_null) {
1491 __ Beqzc(value, &done);
1492 }
Roland Levillainc73f0522018-08-14 15:16:50 +01001493 // Load the address of the card table into `card`.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001494 __ LoadFromOffset(kLoadDoubleword,
1495 card,
1496 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001497 Thread::CardTableOffset<kMips64PointerSize>().Int32Value());
Roland Levillainc73f0522018-08-14 15:16:50 +01001498 // Calculate the address of the card corresponding to `object`.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001499 __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift);
1500 __ Daddu(temp, card, temp);
Roland Levillainc73f0522018-08-14 15:16:50 +01001501 // Write the `art::gc::accounting::CardTable::kCardDirty` value into the
1502 // `object`'s card.
1503 //
1504 // Register `card` contains the address of the card table. Note that the card
1505 // table's base is biased during its creation so that it always starts at an
1506 // address whose least-significant byte is equal to `kCardDirty` (see
1507 // art::gc::accounting::CardTable::Create). Therefore the SB instruction
1508 // below writes the `kCardDirty` (byte) value into the `object`'s card
1509 // (located at `card + object >> kCardShift`).
1510 //
1511 // This dual use of the value in register `card` (1. to calculate the location
1512 // of the card to mark; and 2. to load the `kCardDirty` value) saves a load
1513 // (no need to explicitly load `kCardDirty` as an immediate value).
Alexey Frunze4dda3372015-06-01 18:31:49 -07001514 __ Sb(card, temp, 0);
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01001515 if (value_can_be_null) {
1516 __ Bind(&done);
1517 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001518}
1519
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001520template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
Alexey Frunze19f6c692016-11-30 19:19:55 -08001521inline void CodeGeneratorMIPS64::EmitPcRelativeLinkerPatches(
1522 const ArenaDeque<PcRelativePatchInfo>& infos,
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001523 ArenaVector<linker::LinkerPatch>* linker_patches) {
Alexey Frunze19f6c692016-11-30 19:19:55 -08001524 for (const PcRelativePatchInfo& info : infos) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001525 const DexFile* dex_file = info.target_dex_file;
Alexey Frunze19f6c692016-11-30 19:19:55 -08001526 size_t offset_or_index = info.offset_or_index;
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001527 DCHECK(info.label.IsBound());
1528 uint32_t literal_offset = __ GetLabelLocation(&info.label);
1529 const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info;
1530 uint32_t pc_rel_offset = __ GetLabelLocation(&info_high.label);
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001531 linker_patches->push_back(Factory(literal_offset, dex_file, pc_rel_offset, offset_or_index));
Alexey Frunze19f6c692016-11-30 19:19:55 -08001532 }
1533}
1534
Vladimir Marko6fd16062018-06-26 11:02:04 +01001535template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)>
1536linker::LinkerPatch NoDexFileAdapter(size_t literal_offset,
1537 const DexFile* target_dex_file,
1538 uint32_t pc_insn_offset,
1539 uint32_t boot_image_offset) {
1540 DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null.
1541 return Factory(literal_offset, pc_insn_offset, boot_image_offset);
Vladimir Markob066d432018-01-03 13:14:37 +00001542}
1543
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001544void CodeGeneratorMIPS64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) {
Alexey Frunze19f6c692016-11-30 19:19:55 -08001545 DCHECK(linker_patches->empty());
1546 size_t size =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001547 boot_image_method_patches_.size() +
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001548 method_bss_entry_patches_.size() +
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001549 boot_image_type_patches_.size() +
Vladimir Marko65979462017-05-19 17:25:12 +01001550 type_bss_entry_patches_.size() +
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001551 boot_image_string_patches_.size() +
Vladimir Marko6fd16062018-06-26 11:02:04 +01001552 string_bss_entry_patches_.size() +
Vladimir Marko2d06e022019-07-08 15:45:19 +01001553 boot_image_other_patches_.size();
Alexey Frunze19f6c692016-11-30 19:19:55 -08001554 linker_patches->reserve(size);
Vladimir Marko44ca0752019-07-29 10:18:25 +01001555 if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) {
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001556 EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>(
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001557 boot_image_method_patches_, linker_patches);
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001558 EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>(
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001559 boot_image_type_patches_, linker_patches);
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001560 EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>(
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001561 boot_image_string_patches_, linker_patches);
Vladimir Marko65979462017-05-19 17:25:12 +01001562 } else {
Vladimir Marko2d06e022019-07-08 15:45:19 +01001563 DCHECK(boot_image_method_patches_.empty());
Vladimir Markoe47f60c2018-02-21 13:43:28 +00001564 DCHECK(boot_image_type_patches_.empty());
1565 DCHECK(boot_image_string_patches_.empty());
Vladimir Marko2d06e022019-07-08 15:45:19 +01001566 }
1567 if (GetCompilerOptions().IsBootImage()) {
1568 EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>(
1569 boot_image_other_patches_, linker_patches);
1570 } else {
1571 EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>(
1572 boot_image_other_patches_, linker_patches);
Alexey Frunzef63f5692016-12-13 17:43:11 -08001573 }
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001574 EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>(
1575 method_bss_entry_patches_, linker_patches);
1576 EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>(
1577 type_bss_entry_patches_, linker_patches);
1578 EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>(
1579 string_bss_entry_patches_, linker_patches);
Vladimir Marko1998cd02017-01-13 13:02:58 +00001580 DCHECK_EQ(size, linker_patches->size());
Alexey Frunzef63f5692016-12-13 17:43:11 -08001581}
1582
Vladimir Marko6fd16062018-06-26 11:02:04 +01001583CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageIntrinsicPatch(
1584 uint32_t intrinsic_data,
1585 const PcRelativePatchInfo* info_high) {
1586 return NewPcRelativePatch(
Vladimir Marko2d06e022019-07-08 15:45:19 +01001587 /* dex_file= */ nullptr, intrinsic_data, info_high, &boot_image_other_patches_);
Vladimir Marko6fd16062018-06-26 11:02:04 +01001588}
1589
Vladimir Markob066d432018-01-03 13:14:37 +00001590CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageRelRoPatch(
1591 uint32_t boot_image_offset,
1592 const PcRelativePatchInfo* info_high) {
1593 return NewPcRelativePatch(
Vladimir Marko2d06e022019-07-08 15:45:19 +01001594 /* dex_file= */ nullptr, boot_image_offset, info_high, &boot_image_other_patches_);
Vladimir Markob066d432018-01-03 13:14:37 +00001595}
1596
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001597CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageMethodPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001598 MethodReference target_method,
1599 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001600 return NewPcRelativePatch(
1601 target_method.dex_file, target_method.index, info_high, &boot_image_method_patches_);
Alexey Frunzef63f5692016-12-13 17:43:11 -08001602}
1603
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001604CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewMethodBssEntryPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001605 MethodReference target_method,
1606 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001607 return NewPcRelativePatch(
1608 target_method.dex_file, target_method.index, info_high, &method_bss_entry_patches_);
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001609}
1610
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001611CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageTypePatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001612 const DexFile& dex_file,
1613 dex::TypeIndex type_index,
1614 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001615 return NewPcRelativePatch(&dex_file, type_index.index_, info_high, &boot_image_type_patches_);
Alexey Frunze19f6c692016-11-30 19:19:55 -08001616}
1617
Vladimir Marko1998cd02017-01-13 13:02:58 +00001618CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewTypeBssEntryPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001619 const DexFile& dex_file,
1620 dex::TypeIndex type_index,
1621 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001622 return NewPcRelativePatch(&dex_file, type_index.index_, info_high, &type_bss_entry_patches_);
Vladimir Marko1998cd02017-01-13 13:02:58 +00001623}
1624
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001625CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageStringPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001626 const DexFile& dex_file,
1627 dex::StringIndex string_index,
1628 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001629 return NewPcRelativePatch(
1630 &dex_file, string_index.index_, info_high, &boot_image_string_patches_);
Vladimir Marko65979462017-05-19 17:25:12 +01001631}
1632
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01001633CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewStringBssEntryPatch(
1634 const DexFile& dex_file,
1635 dex::StringIndex string_index,
1636 const PcRelativePatchInfo* info_high) {
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001637 return NewPcRelativePatch(&dex_file, string_index.index_, info_high, &string_bss_entry_patches_);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01001638}
1639
Alexey Frunze19f6c692016-11-30 19:19:55 -08001640CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativePatch(
Vladimir Marko59eb30f2018-02-20 11:52:34 +00001641 const DexFile* dex_file,
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001642 uint32_t offset_or_index,
1643 const PcRelativePatchInfo* info_high,
1644 ArenaDeque<PcRelativePatchInfo>* patches) {
1645 patches->emplace_back(dex_file, offset_or_index, info_high);
Alexey Frunze19f6c692016-11-30 19:19:55 -08001646 return &patches->back();
1647}
1648
Alexey Frunzef63f5692016-12-13 17:43:11 -08001649Literal* CodeGeneratorMIPS64::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
1650 return map->GetOrCreate(
1651 value,
1652 [this, value]() { return __ NewLiteral<uint32_t>(value); });
1653}
1654
Alexey Frunze19f6c692016-11-30 19:19:55 -08001655Literal* CodeGeneratorMIPS64::DeduplicateUint64Literal(uint64_t value) {
1656 return uint64_literals_.GetOrCreate(
1657 value,
1658 [this, value]() { return __ NewLiteral<uint64_t>(value); });
1659}
1660
Alexey Frunzef63f5692016-12-13 17:43:11 -08001661Literal* CodeGeneratorMIPS64::DeduplicateBootImageAddressLiteral(uint64_t address) {
Richard Uhlerc52f3032017-03-02 13:45:45 +00001662 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_);
Alexey Frunzef63f5692016-12-13 17:43:11 -08001663}
1664
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001665void CodeGeneratorMIPS64::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high,
1666 GpuRegister out,
1667 PcRelativePatchInfo* info_low) {
1668 DCHECK(!info_high->patch_info_high);
1669 __ Bind(&info_high->label);
Alexey Frunze19f6c692016-11-30 19:19:55 -08001670 // Add the high half of a 32-bit offset to PC.
Andreas Gampe3db70682018-12-26 15:12:03 -08001671 __ Auipc(out, /* imm16= */ 0x1234);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001672 // A following instruction will add the sign-extended low half of the 32-bit
Alexey Frunzef63f5692016-12-13 17:43:11 -08001673 // offset to `out` (e.g. ld, jialc, daddiu).
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001674 if (info_low != nullptr) {
1675 DCHECK_EQ(info_low->patch_info_high, info_high);
1676 __ Bind(&info_low->label);
1677 }
Alexey Frunze19f6c692016-11-30 19:19:55 -08001678}
1679
Vladimir Marko6fd16062018-06-26 11:02:04 +01001680void CodeGeneratorMIPS64::LoadBootImageAddress(GpuRegister reg, uint32_t boot_image_reference) {
1681 if (GetCompilerOptions().IsBootImage()) {
1682 PcRelativePatchInfo* info_high = NewBootImageIntrinsicPatch(boot_image_reference);
1683 PcRelativePatchInfo* info_low = NewBootImageIntrinsicPatch(boot_image_reference, info_high);
1684 EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Andreas Gampe3db70682018-12-26 15:12:03 -08001685 __ Daddiu(reg, AT, /* imm16= */ 0x5678);
Vladimir Markoa2da9b92018-10-10 14:21:55 +01001686 } else if (GetCompilerOptions().GetCompilePic()) {
Vladimir Marko6fd16062018-06-26 11:02:04 +01001687 PcRelativePatchInfo* info_high = NewBootImageRelRoPatch(boot_image_reference);
1688 PcRelativePatchInfo* info_low = NewBootImageRelRoPatch(boot_image_reference, info_high);
Vladimir Markoeebb8212018-06-05 14:57:24 +01001689 EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
1690 // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load.
Andreas Gampe3db70682018-12-26 15:12:03 -08001691 __ Lwu(reg, AT, /* imm16= */ 0x5678);
Vladimir Markoeebb8212018-06-05 14:57:24 +01001692 } else {
Vladimir Marko8e524ad2018-07-13 10:27:43 +01001693 DCHECK(Runtime::Current()->UseJitCompilation());
Vladimir Markoeebb8212018-06-05 14:57:24 +01001694 gc::Heap* heap = Runtime::Current()->GetHeap();
1695 DCHECK(!heap->GetBootImageSpaces().empty());
1696 uintptr_t address =
Vladimir Marko6fd16062018-06-26 11:02:04 +01001697 reinterpret_cast<uintptr_t>(heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference);
Vladimir Markoeebb8212018-06-05 14:57:24 +01001698 __ LoadLiteral(reg, kLoadDoubleword, DeduplicateBootImageAddressLiteral(address));
1699 }
1700}
1701
Vladimir Marko6fd16062018-06-26 11:02:04 +01001702void CodeGeneratorMIPS64::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke,
1703 uint32_t boot_image_offset) {
1704 DCHECK(invoke->IsStatic());
1705 InvokeRuntimeCallingConvention calling_convention;
1706 GpuRegister argument = calling_convention.GetRegisterAt(0);
1707 if (GetCompilerOptions().IsBootImage()) {
1708 DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference);
1709 // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative.
1710 MethodReference target_method = invoke->GetTargetMethod();
1711 dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_;
1712 PcRelativePatchInfo* info_high = NewBootImageTypePatch(*target_method.dex_file, type_idx);
1713 PcRelativePatchInfo* info_low =
1714 NewBootImageTypePatch(*target_method.dex_file, type_idx, info_high);
1715 EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Andreas Gampe3db70682018-12-26 15:12:03 -08001716 __ Daddiu(argument, AT, /* imm16= */ 0x5678);
Vladimir Marko6fd16062018-06-26 11:02:04 +01001717 } else {
1718 LoadBootImageAddress(argument, boot_image_offset);
1719 }
1720 InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc());
1721 CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>();
1722}
1723
Alexey Frunze627c1a02017-01-30 19:28:14 -08001724Literal* CodeGeneratorMIPS64::DeduplicateJitStringLiteral(const DexFile& dex_file,
1725 dex::StringIndex string_index,
1726 Handle<mirror::String> handle) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01001727 ReserveJitStringRoot(StringReference(&dex_file, string_index), handle);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001728 return jit_string_patches_.GetOrCreate(
1729 StringReference(&dex_file, string_index),
Andreas Gampe3db70682018-12-26 15:12:03 -08001730 [this]() { return __ NewLiteral<uint32_t>(/* value= */ 0u); });
Alexey Frunze627c1a02017-01-30 19:28:14 -08001731}
1732
1733Literal* CodeGeneratorMIPS64::DeduplicateJitClassLiteral(const DexFile& dex_file,
1734 dex::TypeIndex type_index,
1735 Handle<mirror::Class> handle) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01001736 ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001737 return jit_class_patches_.GetOrCreate(
1738 TypeReference(&dex_file, type_index),
Andreas Gampe3db70682018-12-26 15:12:03 -08001739 [this]() { return __ NewLiteral<uint32_t>(/* value= */ 0u); });
Alexey Frunze627c1a02017-01-30 19:28:14 -08001740}
1741
1742void CodeGeneratorMIPS64::PatchJitRootUse(uint8_t* code,
1743 const uint8_t* roots_data,
1744 const Literal* literal,
1745 uint64_t index_in_table) const {
1746 uint32_t literal_offset = GetAssembler().GetLabelLocation(literal->GetLabel());
1747 uintptr_t address =
1748 reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>);
1749 reinterpret_cast<uint32_t*>(code + literal_offset)[0] = dchecked_integral_cast<uint32_t>(address);
1750}
1751
1752void CodeGeneratorMIPS64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) {
1753 for (const auto& entry : jit_string_patches_) {
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001754 const StringReference& string_reference = entry.first;
1755 Literal* table_entry_literal = entry.second;
Vladimir Marko174b2e22017-10-12 13:34:49 +01001756 uint64_t index_in_table = GetJitStringRootIndex(string_reference);
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001757 PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001758 }
1759 for (const auto& entry : jit_class_patches_) {
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001760 const TypeReference& type_reference = entry.first;
1761 Literal* table_entry_literal = entry.second;
Vladimir Marko174b2e22017-10-12 13:34:49 +01001762 uint64_t index_in_table = GetJitClassRootIndex(type_reference);
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001763 PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001764 }
1765}
1766
David Brazdil58282f42016-01-14 12:45:10 +00001767void CodeGeneratorMIPS64::SetupBlockedRegisters() const {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001768 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
1769 blocked_core_registers_[ZERO] = true;
1770 blocked_core_registers_[K0] = true;
1771 blocked_core_registers_[K1] = true;
1772 blocked_core_registers_[GP] = true;
1773 blocked_core_registers_[SP] = true;
1774 blocked_core_registers_[RA] = true;
1775
Lazar Trsicd9672662015-09-03 17:33:01 +02001776 // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch
1777 // registers (similar to how AT is used by MIPS assemblers).
Alexey Frunze4dda3372015-06-01 18:31:49 -07001778 blocked_core_registers_[AT] = true;
1779 blocked_core_registers_[TMP] = true;
Lazar Trsicd9672662015-09-03 17:33:01 +02001780 blocked_core_registers_[TMP2] = true;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001781 blocked_fpu_registers_[FTMP] = true;
1782
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +01001783 if (GetInstructionSetFeatures().HasMsa()) {
1784 // To be used just for MSA instructions.
1785 blocked_fpu_registers_[FTMP2] = true;
1786 }
1787
Alexey Frunze4dda3372015-06-01 18:31:49 -07001788 // Reserve suspend and thread registers.
1789 blocked_core_registers_[S0] = true;
1790 blocked_core_registers_[TR] = true;
1791
1792 // Reserve T9 for function calls
1793 blocked_core_registers_[T9] = true;
1794
Goran Jakovljevic782be112016-06-21 12:39:04 +02001795 if (GetGraph()->IsDebuggable()) {
1796 // Stubs do not save callee-save floating point registers. If the graph
1797 // is debuggable, we need to deal with these registers differently. For
1798 // now, just block them.
1799 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1800 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1801 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001802 }
1803}
1804
Alexey Frunze4dda3372015-06-01 18:31:49 -07001805size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1806 __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index);
Lazar Trsicd9672662015-09-03 17:33:01 +02001807 return kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001808}
1809
1810size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1811 __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index);
Lazar Trsicd9672662015-09-03 17:33:01 +02001812 return kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001813}
1814
1815size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001816 __ StoreFpuToOffset(GetGraph()->HasSIMD() ? kStoreQuadword : kStoreDoubleword,
1817 FpuRegister(reg_id),
1818 SP,
1819 stack_index);
Artem Serov6a0b6572019-07-26 20:38:37 +01001820 return GetSlowPathFPWidth();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001821}
1822
1823size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001824 __ LoadFpuFromOffset(GetGraph()->HasSIMD() ? kLoadQuadword : kLoadDoubleword,
1825 FpuRegister(reg_id),
1826 SP,
1827 stack_index);
Artem Serov6a0b6572019-07-26 20:38:37 +01001828 return GetSlowPathFPWidth();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001829}
1830
1831void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdil9f0dece2015-09-21 18:20:26 +01001832 stream << GpuRegister(reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001833}
1834
1835void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdil9f0dece2015-09-21 18:20:26 +01001836 stream << FpuRegister(reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001837}
1838
Vladimir Markoa0431112018-06-25 09:32:54 +01001839const Mips64InstructionSetFeatures& CodeGeneratorMIPS64::GetInstructionSetFeatures() const {
1840 return *GetCompilerOptions().GetInstructionSetFeatures()->AsMips64InstructionSetFeatures();
1841}
1842
Calin Juravle175dc732015-08-25 15:42:32 +01001843void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint,
Alexey Frunze4dda3372015-06-01 18:31:49 -07001844 HInstruction* instruction,
1845 uint32_t dex_pc,
1846 SlowPathCode* slow_path) {
Alexandre Rames91a65162016-09-19 13:54:30 +01001847 ValidateInvokeRuntime(entrypoint, instruction, slow_path);
Alexey Frunze15958152017-02-09 19:08:30 -08001848 GenerateInvokeRuntime(GetThreadOffset<kMips64PointerSize>(entrypoint).Int32Value());
Serban Constantinescufc734082016-07-19 17:18:07 +01001849 if (EntrypointRequiresStackMap(entrypoint)) {
1850 RecordPcInfo(instruction, dex_pc, slow_path);
1851 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001852}
1853
Alexey Frunze15958152017-02-09 19:08:30 -08001854void CodeGeneratorMIPS64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
1855 HInstruction* instruction,
1856 SlowPathCode* slow_path) {
1857 ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path);
1858 GenerateInvokeRuntime(entry_point_offset);
1859}
1860
1861void CodeGeneratorMIPS64::GenerateInvokeRuntime(int32_t entry_point_offset) {
1862 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
1863 __ Jalr(T9);
1864 __ Nop();
1865}
1866
Alexey Frunze4dda3372015-06-01 18:31:49 -07001867void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path,
1868 GpuRegister class_reg) {
Vladimir Markodc682aa2018-01-04 18:42:57 +00001869 constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf();
1870 const size_t status_byte_offset =
1871 mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte);
1872 constexpr uint32_t shifted_initialized_value =
1873 enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte);
1874
1875 __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, status_byte_offset);
Lena Djokic3177e102018-02-28 11:32:40 +01001876 __ Sltiu(TMP, TMP, shifted_initialized_value);
1877 __ Bnezc(TMP, slow_path->GetEntryLabel());
Alexey Frunze15958152017-02-09 19:08:30 -08001878 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
1879 __ Sync(0);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001880 __ Bind(slow_path->GetExitLabel());
1881}
1882
Vladimir Marko175e7862018-03-27 09:03:13 +00001883void InstructionCodeGeneratorMIPS64::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check,
1884 GpuRegister temp) {
1885 uint32_t path_to_root = check->GetBitstringPathToRoot();
1886 uint32_t mask = check->GetBitstringMask();
1887 DCHECK(IsPowerOfTwo(mask + 1));
1888 size_t mask_bits = WhichPowerOf2(mask + 1);
1889
1890 if (mask_bits == 16u) {
1891 // Load only the bitstring part of the status word.
1892 __ LoadFromOffset(
1893 kLoadUnsignedHalfword, temp, temp, mirror::Class::StatusOffset().Int32Value());
1894 // Compare the bitstring bits using XOR.
1895 __ Xori(temp, temp, dchecked_integral_cast<uint16_t>(path_to_root));
1896 } else {
1897 // /* uint32_t */ temp = temp->status_
1898 __ LoadFromOffset(kLoadWord, temp, temp, mirror::Class::StatusOffset().Int32Value());
1899 // Compare the bitstring bits using XOR.
1900 if (IsUint<16>(path_to_root)) {
1901 __ Xori(temp, temp, dchecked_integral_cast<uint16_t>(path_to_root));
1902 } else {
1903 __ LoadConst32(TMP, path_to_root);
1904 __ Xor(temp, temp, TMP);
1905 }
1906 // Shift out bits that do not contribute to the comparison.
1907 __ Sll(temp, temp, 32 - mask_bits);
1908 }
1909}
1910
Alexey Frunze4dda3372015-06-01 18:31:49 -07001911void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1912 __ Sync(0); // only stype 0 is supported
1913}
1914
1915void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction,
1916 HBasicBlock* successor) {
1917 SuspendCheckSlowPathMIPS64* slow_path =
Chris Larsena2045912017-11-02 12:39:54 -07001918 down_cast<SuspendCheckSlowPathMIPS64*>(instruction->GetSlowPath());
1919
1920 if (slow_path == nullptr) {
1921 slow_path =
1922 new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS64(instruction, successor);
1923 instruction->SetSlowPath(slow_path);
1924 codegen_->AddSlowPath(slow_path);
1925 if (successor != nullptr) {
1926 DCHECK(successor->IsLoopHeader());
1927 }
1928 } else {
1929 DCHECK_EQ(slow_path->GetSuccessor(), successor);
1930 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001931
1932 __ LoadFromOffset(kLoadUnsignedHalfword,
1933 TMP,
1934 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001935 Thread::ThreadFlagsOffset<kMips64PointerSize>().Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001936 if (successor == nullptr) {
1937 __ Bnezc(TMP, slow_path->GetEntryLabel());
1938 __ Bind(slow_path->GetReturnLabel());
1939 } else {
1940 __ Beqzc(TMP, codegen_->GetLabelOf(successor));
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001941 __ Bc(slow_path->GetEntryLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001942 // slow_path will return to GetLabelOf(successor).
1943 }
1944}
1945
1946InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph,
1947 CodeGeneratorMIPS64* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001948 : InstructionCodeGenerator(graph, codegen),
Alexey Frunze4dda3372015-06-01 18:31:49 -07001949 assembler_(codegen->GetAssembler()),
1950 codegen_(codegen) {}
1951
1952void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
1953 DCHECK_EQ(instruction->InputCount(), 2U);
Vladimir Markoca6fff82017-10-03 14:49:14 +01001954 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001955 DataType::Type type = instruction->GetResultType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001956 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001957 case DataType::Type::kInt32:
1958 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001959 locations->SetInAt(0, Location::RequiresRegister());
1960 HInstruction* right = instruction->InputAt(1);
1961 bool can_use_imm = false;
1962 if (right->IsConstant()) {
1963 int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant());
1964 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1965 can_use_imm = IsUint<16>(imm);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001966 } else {
Lena Djokic38530172017-11-16 11:11:50 +01001967 DCHECK(instruction->IsAdd() || instruction->IsSub());
1968 bool single_use = right->GetUses().HasExactlyOneElement();
1969 if (instruction->IsSub()) {
1970 if (!(type == DataType::Type::kInt32 && imm == INT32_MIN)) {
1971 imm = -imm;
1972 }
1973 }
1974 if (type == DataType::Type::kInt32) {
1975 can_use_imm = IsInt<16>(imm) || (Low16Bits(imm) == 0) || single_use;
1976 } else {
1977 can_use_imm = IsInt<16>(imm) || (IsInt<32>(imm) && (Low16Bits(imm) == 0)) || single_use;
1978 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001979 }
1980 }
1981 if (can_use_imm)
1982 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1983 else
1984 locations->SetInAt(1, Location::RequiresRegister());
1985 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1986 }
1987 break;
1988
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001989 case DataType::Type::kFloat32:
1990 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07001991 locations->SetInAt(0, Location::RequiresFpuRegister());
1992 locations->SetInAt(1, Location::RequiresFpuRegister());
1993 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1994 break;
1995
1996 default:
1997 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1998 }
1999}
2000
2001void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002002 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002003 LocationSummary* locations = instruction->GetLocations();
2004
2005 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002006 case DataType::Type::kInt32:
2007 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002008 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2009 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2010 Location rhs_location = locations->InAt(1);
2011
2012 GpuRegister rhs_reg = ZERO;
2013 int64_t rhs_imm = 0;
2014 bool use_imm = rhs_location.IsConstant();
2015 if (use_imm) {
2016 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
2017 } else {
2018 rhs_reg = rhs_location.AsRegister<GpuRegister>();
2019 }
2020
2021 if (instruction->IsAnd()) {
2022 if (use_imm)
2023 __ Andi(dst, lhs, rhs_imm);
2024 else
2025 __ And(dst, lhs, rhs_reg);
2026 } else if (instruction->IsOr()) {
2027 if (use_imm)
2028 __ Ori(dst, lhs, rhs_imm);
2029 else
2030 __ Or(dst, lhs, rhs_reg);
2031 } else if (instruction->IsXor()) {
2032 if (use_imm)
2033 __ Xori(dst, lhs, rhs_imm);
2034 else
2035 __ Xor(dst, lhs, rhs_reg);
Lena Djokic38530172017-11-16 11:11:50 +01002036 } else if (instruction->IsAdd() || instruction->IsSub()) {
2037 if (instruction->IsSub()) {
2038 rhs_imm = -rhs_imm;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002039 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002040 if (type == DataType::Type::kInt32) {
Lena Djokic38530172017-11-16 11:11:50 +01002041 if (use_imm) {
2042 if (IsInt<16>(rhs_imm)) {
2043 __ Addiu(dst, lhs, rhs_imm);
2044 } else {
2045 int16_t rhs_imm_high = High16Bits(rhs_imm);
2046 int16_t rhs_imm_low = Low16Bits(rhs_imm);
2047 if (rhs_imm_low < 0) {
2048 rhs_imm_high += 1;
2049 }
2050 __ Aui(dst, lhs, rhs_imm_high);
2051 if (rhs_imm_low != 0) {
2052 __ Addiu(dst, dst, rhs_imm_low);
2053 }
2054 }
2055 } else {
2056 if (instruction->IsAdd()) {
2057 __ Addu(dst, lhs, rhs_reg);
2058 } else {
2059 DCHECK(instruction->IsSub());
2060 __ Subu(dst, lhs, rhs_reg);
2061 }
2062 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002063 } else {
Lena Djokic38530172017-11-16 11:11:50 +01002064 if (use_imm) {
2065 if (IsInt<16>(rhs_imm)) {
2066 __ Daddiu(dst, lhs, rhs_imm);
2067 } else if (IsInt<32>(rhs_imm)) {
2068 int16_t rhs_imm_high = High16Bits(rhs_imm);
2069 int16_t rhs_imm_low = Low16Bits(rhs_imm);
2070 bool overflow_hi16 = false;
2071 if (rhs_imm_low < 0) {
2072 rhs_imm_high += 1;
2073 overflow_hi16 = (rhs_imm_high == -32768);
2074 }
2075 __ Daui(dst, lhs, rhs_imm_high);
2076 if (rhs_imm_low != 0) {
2077 __ Daddiu(dst, dst, rhs_imm_low);
2078 }
2079 if (overflow_hi16) {
2080 __ Dahi(dst, 1);
2081 }
2082 } else {
2083 int16_t rhs_imm_low = Low16Bits(Low32Bits(rhs_imm));
2084 if (rhs_imm_low < 0) {
2085 rhs_imm += (INT64_C(1) << 16);
2086 }
2087 int16_t rhs_imm_upper = High16Bits(Low32Bits(rhs_imm));
2088 if (rhs_imm_upper < 0) {
2089 rhs_imm += (INT64_C(1) << 32);
2090 }
2091 int16_t rhs_imm_high = Low16Bits(High32Bits(rhs_imm));
2092 if (rhs_imm_high < 0) {
2093 rhs_imm += (INT64_C(1) << 48);
2094 }
2095 int16_t rhs_imm_top = High16Bits(High32Bits(rhs_imm));
2096 GpuRegister tmp = lhs;
2097 if (rhs_imm_low != 0) {
2098 __ Daddiu(dst, tmp, rhs_imm_low);
2099 tmp = dst;
2100 }
2101 // Dahi and Dati must use the same input and output register, so we have to initialize
2102 // the dst register using Daddiu or Daui, even when the intermediate value is zero:
2103 // Daui(dst, lhs, 0).
2104 if ((rhs_imm_upper != 0) || (rhs_imm_low == 0)) {
2105 __ Daui(dst, tmp, rhs_imm_upper);
2106 }
2107 if (rhs_imm_high != 0) {
2108 __ Dahi(dst, rhs_imm_high);
2109 }
2110 if (rhs_imm_top != 0) {
2111 __ Dati(dst, rhs_imm_top);
2112 }
2113 }
2114 } else if (instruction->IsAdd()) {
2115 __ Daddu(dst, lhs, rhs_reg);
2116 } else {
2117 DCHECK(instruction->IsSub());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002118 __ Dsubu(dst, lhs, rhs_reg);
Lena Djokic38530172017-11-16 11:11:50 +01002119 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002120 }
2121 }
2122 break;
2123 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002124 case DataType::Type::kFloat32:
2125 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002126 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2127 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
2128 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
2129 if (instruction->IsAdd()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002130 if (type == DataType::Type::kFloat32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07002131 __ AddS(dst, lhs, rhs);
2132 else
2133 __ AddD(dst, lhs, rhs);
2134 } else if (instruction->IsSub()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002135 if (type == DataType::Type::kFloat32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07002136 __ SubS(dst, lhs, rhs);
2137 else
2138 __ SubD(dst, lhs, rhs);
2139 } else {
2140 LOG(FATAL) << "Unexpected floating-point binary operation";
2141 }
2142 break;
2143 }
2144 default:
2145 LOG(FATAL) << "Unexpected binary operation type " << type;
2146 }
2147}
2148
2149void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002150 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002151
Vladimir Markoca6fff82017-10-03 14:49:14 +01002152 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002153 DataType::Type type = instr->GetResultType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002154 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002155 case DataType::Type::kInt32:
2156 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002157 locations->SetInAt(0, Location::RequiresRegister());
2158 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07002159 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002160 break;
2161 }
2162 default:
2163 LOG(FATAL) << "Unexpected shift type " << type;
2164 }
2165}
2166
2167void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002168 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002169 LocationSummary* locations = instr->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002170 DataType::Type type = instr->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002171
2172 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002173 case DataType::Type::kInt32:
2174 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002175 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2176 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2177 Location rhs_location = locations->InAt(1);
2178
2179 GpuRegister rhs_reg = ZERO;
2180 int64_t rhs_imm = 0;
2181 bool use_imm = rhs_location.IsConstant();
2182 if (use_imm) {
2183 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
2184 } else {
2185 rhs_reg = rhs_location.AsRegister<GpuRegister>();
2186 }
2187
2188 if (use_imm) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00002189 uint32_t shift_value = rhs_imm &
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002190 (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002191
Alexey Frunze92d90602015-12-18 18:16:36 -08002192 if (shift_value == 0) {
2193 if (dst != lhs) {
2194 __ Move(dst, lhs);
2195 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002196 } else if (type == DataType::Type::kInt32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002197 if (instr->IsShl()) {
2198 __ Sll(dst, lhs, shift_value);
2199 } else if (instr->IsShr()) {
2200 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002201 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002202 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002203 } else {
2204 __ Rotr(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002205 }
2206 } else {
2207 if (shift_value < 32) {
2208 if (instr->IsShl()) {
2209 __ Dsll(dst, lhs, shift_value);
2210 } else if (instr->IsShr()) {
2211 __ Dsra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002212 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002213 __ Dsrl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002214 } else {
2215 __ Drotr(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002216 }
2217 } else {
2218 shift_value -= 32;
2219 if (instr->IsShl()) {
2220 __ Dsll32(dst, lhs, shift_value);
2221 } else if (instr->IsShr()) {
2222 __ Dsra32(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002223 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002224 __ Dsrl32(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002225 } else {
2226 __ Drotr32(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002227 }
2228 }
2229 }
2230 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002231 if (type == DataType::Type::kInt32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002232 if (instr->IsShl()) {
2233 __ Sllv(dst, lhs, rhs_reg);
2234 } else if (instr->IsShr()) {
2235 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002236 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002237 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002238 } else {
2239 __ Rotrv(dst, lhs, rhs_reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002240 }
2241 } else {
2242 if (instr->IsShl()) {
2243 __ Dsllv(dst, lhs, rhs_reg);
2244 } else if (instr->IsShr()) {
2245 __ Dsrav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002246 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002247 __ Dsrlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002248 } else {
2249 __ Drotrv(dst, lhs, rhs_reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002250 }
2251 }
2252 }
2253 break;
2254 }
2255 default:
2256 LOG(FATAL) << "Unexpected shift operation type " << type;
2257 }
2258}
2259
2260void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) {
2261 HandleBinaryOp(instruction);
2262}
2263
2264void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) {
2265 HandleBinaryOp(instruction);
2266}
2267
2268void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) {
2269 HandleBinaryOp(instruction);
2270}
2271
2272void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) {
2273 HandleBinaryOp(instruction);
2274}
2275
2276void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002277 DataType::Type type = instruction->GetType();
Alexey Frunze15958152017-02-09 19:08:30 -08002278 bool object_array_get_with_read_barrier =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002279 kEmitCompilerReadBarrier && (type == DataType::Type::kReference);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002280 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01002281 new (GetGraph()->GetAllocator()) LocationSummary(instruction,
2282 object_array_get_with_read_barrier
2283 ? LocationSummary::kCallOnSlowPath
2284 : LocationSummary::kNoCall);
Alexey Frunzec61c0762017-04-10 13:54:23 -07002285 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
2286 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
2287 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002288 locations->SetInAt(0, Location::RequiresRegister());
2289 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002290 if (DataType::IsFloatingPointType(type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002291 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2292 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08002293 // The output overlaps in the case of an object array get with
2294 // read barriers enabled: we do not want the move to overwrite the
2295 // array's location, as we need it to emit the read barrier.
2296 locations->SetOut(Location::RequiresRegister(),
2297 object_array_get_with_read_barrier
2298 ? Location::kOutputOverlap
2299 : Location::kNoOutputOverlap);
2300 }
2301 // We need a temporary register for the read barrier marking slow
2302 // path in CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier.
2303 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002304 bool temp_needed = instruction->GetIndex()->IsConstant()
2305 ? !kBakerReadBarrierThunksEnableForFields
2306 : !kBakerReadBarrierThunksEnableForArrays;
2307 if (temp_needed) {
2308 locations->AddTemp(Location::RequiresRegister());
2309 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002310 }
2311}
2312
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002313static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS64* codegen) {
2314 auto null_checker = [codegen, instruction]() {
2315 codegen->MaybeRecordImplicitNullCheck(instruction);
2316 };
2317 return null_checker;
2318}
2319
Alexey Frunze4dda3372015-06-01 18:31:49 -07002320void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) {
2321 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08002322 Location obj_loc = locations->InAt(0);
2323 GpuRegister obj = obj_loc.AsRegister<GpuRegister>();
2324 Location out_loc = locations->Out();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002325 Location index = locations->InAt(1);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01002326 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002327 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002328
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002329 DataType::Type type = instruction->GetType();
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002330 const bool maybe_compressed_char_at = mirror::kUseStringCompression &&
2331 instruction->IsStringCharAt();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002332 switch (type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002333 case DataType::Type::kBool:
2334 case DataType::Type::kUint8: {
Alexey Frunze15958152017-02-09 19:08:30 -08002335 GpuRegister out = out_loc.AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002336 if (index.IsConstant()) {
2337 size_t offset =
2338 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002339 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002340 } else {
2341 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002342 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002343 }
2344 break;
2345 }
2346
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002347 case DataType::Type::kInt8: {
Alexey Frunze15958152017-02-09 19:08:30 -08002348 GpuRegister out = out_loc.AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002349 if (index.IsConstant()) {
2350 size_t offset =
2351 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002352 __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002353 } else {
2354 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002355 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002356 }
2357 break;
2358 }
2359
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002360 case DataType::Type::kUint16: {
Alexey Frunze15958152017-02-09 19:08:30 -08002361 GpuRegister out = out_loc.AsRegister<GpuRegister>();
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002362 if (maybe_compressed_char_at) {
2363 uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002364 __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002365 __ Dext(TMP, TMP, 0, 1);
2366 static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u,
2367 "Expecting 0=compressed, 1=uncompressed");
2368 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002369 if (index.IsConstant()) {
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002370 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
2371 if (maybe_compressed_char_at) {
2372 Mips64Label uncompressed_load, done;
2373 __ Bnezc(TMP, &uncompressed_load);
2374 __ LoadFromOffset(kLoadUnsignedByte,
2375 out,
2376 obj,
2377 data_offset + (const_index << TIMES_1));
2378 __ Bc(&done);
2379 __ Bind(&uncompressed_load);
2380 __ LoadFromOffset(kLoadUnsignedHalfword,
2381 out,
2382 obj,
2383 data_offset + (const_index << TIMES_2));
2384 __ Bind(&done);
2385 } else {
2386 __ LoadFromOffset(kLoadUnsignedHalfword,
2387 out,
2388 obj,
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002389 data_offset + (const_index << TIMES_2),
2390 null_checker);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002391 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002392 } else {
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002393 GpuRegister index_reg = index.AsRegister<GpuRegister>();
2394 if (maybe_compressed_char_at) {
2395 Mips64Label uncompressed_load, done;
2396 __ Bnezc(TMP, &uncompressed_load);
2397 __ Daddu(TMP, obj, index_reg);
2398 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset);
2399 __ Bc(&done);
2400 __ Bind(&uncompressed_load);
Chris Larsencd0295d2017-03-31 15:26:54 -07002401 __ Dlsa(TMP, index_reg, obj, TIMES_2);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002402 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset);
2403 __ Bind(&done);
2404 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002405 __ Dlsa(TMP, index_reg, obj, TIMES_2);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002406 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002407 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002408 }
2409 break;
2410 }
2411
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002412 case DataType::Type::kInt16: {
2413 GpuRegister out = out_loc.AsRegister<GpuRegister>();
2414 if (index.IsConstant()) {
2415 size_t offset =
2416 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2417 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker);
2418 } else {
2419 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_2);
2420 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker);
2421 }
2422 break;
2423 }
2424
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002425 case DataType::Type::kInt32: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002426 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
Alexey Frunze15958152017-02-09 19:08:30 -08002427 GpuRegister out = out_loc.AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002428 LoadOperandType load_type =
2429 (type == DataType::Type::kReference) ? kLoadUnsignedWord : kLoadWord;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002430 if (index.IsConstant()) {
2431 size_t offset =
2432 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002433 __ LoadFromOffset(load_type, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002434 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002435 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002436 __ LoadFromOffset(load_type, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002437 }
2438 break;
2439 }
2440
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002441 case DataType::Type::kReference: {
Alexey Frunze15958152017-02-09 19:08:30 -08002442 static_assert(
2443 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
2444 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
2445 // /* HeapReference<Object> */ out =
2446 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
2447 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002448 bool temp_needed = index.IsConstant()
2449 ? !kBakerReadBarrierThunksEnableForFields
2450 : !kBakerReadBarrierThunksEnableForArrays;
2451 Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation();
Alexey Frunze15958152017-02-09 19:08:30 -08002452 // Note that a potential implicit null check is handled in this
2453 // CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier call.
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002454 DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0)));
2455 if (index.IsConstant()) {
2456 // Array load with a constant index can be treated as a field load.
2457 size_t offset =
2458 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2459 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
2460 out_loc,
2461 obj,
2462 offset,
2463 temp,
Andreas Gampe3db70682018-12-26 15:12:03 -08002464 /* needs_null_check= */ false);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002465 } else {
2466 codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction,
2467 out_loc,
2468 obj,
2469 data_offset,
2470 index,
2471 temp,
Andreas Gampe3db70682018-12-26 15:12:03 -08002472 /* needs_null_check= */ false);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002473 }
Alexey Frunze15958152017-02-09 19:08:30 -08002474 } else {
2475 GpuRegister out = out_loc.AsRegister<GpuRegister>();
2476 if (index.IsConstant()) {
2477 size_t offset =
2478 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2479 __ LoadFromOffset(kLoadUnsignedWord, out, obj, offset, null_checker);
2480 // If read barriers are enabled, emit read barriers other than
2481 // Baker's using a slow path (and also unpoison the loaded
2482 // reference, if heap poisoning is enabled).
2483 codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
2484 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002485 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Alexey Frunze15958152017-02-09 19:08:30 -08002486 __ LoadFromOffset(kLoadUnsignedWord, out, TMP, data_offset, null_checker);
2487 // If read barriers are enabled, emit read barriers other than
2488 // Baker's using a slow path (and also unpoison the loaded
2489 // reference, if heap poisoning is enabled).
2490 codegen_->MaybeGenerateReadBarrierSlow(instruction,
2491 out_loc,
2492 out_loc,
2493 obj_loc,
2494 data_offset,
2495 index);
2496 }
2497 }
2498 break;
2499 }
2500
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002501 case DataType::Type::kInt64: {
Alexey Frunze15958152017-02-09 19:08:30 -08002502 GpuRegister out = out_loc.AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002503 if (index.IsConstant()) {
2504 size_t offset =
2505 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002506 __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002507 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002508 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002509 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002510 }
2511 break;
2512 }
2513
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002514 case DataType::Type::kFloat32: {
Alexey Frunze15958152017-02-09 19:08:30 -08002515 FpuRegister out = out_loc.AsFpuRegister<FpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002516 if (index.IsConstant()) {
2517 size_t offset =
2518 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002519 __ LoadFpuFromOffset(kLoadWord, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002520 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002521 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002522 __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002523 }
2524 break;
2525 }
2526
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002527 case DataType::Type::kFloat64: {
Alexey Frunze15958152017-02-09 19:08:30 -08002528 FpuRegister out = out_loc.AsFpuRegister<FpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002529 if (index.IsConstant()) {
2530 size_t offset =
2531 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002532 __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002533 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002534 __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002535 __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002536 }
2537 break;
2538 }
2539
Aart Bik66c158e2018-01-31 12:55:04 -08002540 case DataType::Type::kUint32:
2541 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002542 case DataType::Type::kVoid:
Alexey Frunze4dda3372015-06-01 18:31:49 -07002543 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2544 UNREACHABLE();
2545 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002546}
2547
2548void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01002549 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002550 locations->SetInAt(0, Location::RequiresRegister());
2551 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2552}
2553
2554void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) {
2555 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01002556 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002557 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2558 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2559 __ LoadFromOffset(kLoadWord, out, obj, offset);
2560 codegen_->MaybeRecordImplicitNullCheck(instruction);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002561 // Mask out compression flag from String's array length.
2562 if (mirror::kUseStringCompression && instruction->IsStringLength()) {
2563 __ Srl(out, out, 1u);
2564 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002565}
2566
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002567Location LocationsBuilderMIPS64::RegisterOrZeroConstant(HInstruction* instruction) {
2568 return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern())
2569 ? Location::ConstantLocation(instruction->AsConstant())
2570 : Location::RequiresRegister();
2571}
2572
2573Location LocationsBuilderMIPS64::FpuRegisterOrConstantForStore(HInstruction* instruction) {
2574 // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register.
2575 // We can store a non-zero float or double constant without first loading it into the FPU,
2576 // but we should only prefer this if the constant has a single use.
2577 if (instruction->IsConstant() &&
2578 (instruction->AsConstant()->IsZeroBitPattern() ||
2579 instruction->GetUses().HasExactlyOneElement())) {
2580 return Location::ConstantLocation(instruction->AsConstant());
2581 // Otherwise fall through and require an FPU register for the constant.
2582 }
2583 return Location::RequiresFpuRegister();
2584}
2585
Alexey Frunze4dda3372015-06-01 18:31:49 -07002586void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002587 DataType::Type value_type = instruction->GetComponentType();
Alexey Frunze15958152017-02-09 19:08:30 -08002588
2589 bool needs_write_barrier =
2590 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
2591 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
2592
Vladimir Markoca6fff82017-10-03 14:49:14 +01002593 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
Alexey Frunze4dda3372015-06-01 18:31:49 -07002594 instruction,
Alexey Frunze15958152017-02-09 19:08:30 -08002595 may_need_runtime_call_for_type_check ?
2596 LocationSummary::kCallOnSlowPath :
2597 LocationSummary::kNoCall);
2598
2599 locations->SetInAt(0, Location::RequiresRegister());
2600 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002601 if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
Alexey Frunze15958152017-02-09 19:08:30 -08002602 locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002603 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08002604 locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2)));
2605 }
2606 if (needs_write_barrier) {
2607 // Temporary register for the write barrier.
2608 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002609 }
2610}
2611
2612void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) {
2613 LocationSummary* locations = instruction->GetLocations();
2614 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2615 Location index = locations->InAt(1);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002616 Location value_location = locations->InAt(2);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002617 DataType::Type value_type = instruction->GetComponentType();
Alexey Frunze15958152017-02-09 19:08:30 -08002618 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002619 bool needs_write_barrier =
2620 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002621 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002622 GpuRegister base_reg = index.IsConstant() ? obj : TMP;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002623
2624 switch (value_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002625 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002626 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002627 case DataType::Type::kInt8: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002628 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002629 if (index.IsConstant()) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002630 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002631 } else {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002632 __ Daddu(base_reg, obj, index.AsRegister<GpuRegister>());
2633 }
2634 if (value_location.IsConstant()) {
2635 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2636 __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker);
2637 } else {
2638 GpuRegister value = value_location.AsRegister<GpuRegister>();
2639 __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002640 }
2641 break;
2642 }
2643
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002644 case DataType::Type::kUint16:
2645 case DataType::Type::kInt16: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002646 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002647 if (index.IsConstant()) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002648 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002649 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002650 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_2);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002651 }
2652 if (value_location.IsConstant()) {
2653 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2654 __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker);
2655 } else {
2656 GpuRegister value = value_location.AsRegister<GpuRegister>();
2657 __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002658 }
2659 break;
2660 }
2661
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002662 case DataType::Type::kInt32: {
Alexey Frunze15958152017-02-09 19:08:30 -08002663 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2664 if (index.IsConstant()) {
2665 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
2666 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002667 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Alexey Frunze15958152017-02-09 19:08:30 -08002668 }
2669 if (value_location.IsConstant()) {
2670 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2671 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2672 } else {
2673 GpuRegister value = value_location.AsRegister<GpuRegister>();
2674 __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
2675 }
2676 break;
2677 }
2678
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002679 case DataType::Type::kReference: {
Alexey Frunze15958152017-02-09 19:08:30 -08002680 if (value_location.IsConstant()) {
2681 // Just setting null.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002682 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002683 if (index.IsConstant()) {
Alexey Frunzec061de12017-02-14 13:27:23 -08002684 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002685 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002686 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Alexey Frunzec061de12017-02-14 13:27:23 -08002687 }
Alexey Frunze15958152017-02-09 19:08:30 -08002688 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2689 DCHECK_EQ(value, 0);
2690 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2691 DCHECK(!needs_write_barrier);
2692 DCHECK(!may_need_runtime_call_for_type_check);
2693 break;
2694 }
2695
2696 DCHECK(needs_write_barrier);
2697 GpuRegister value = value_location.AsRegister<GpuRegister>();
2698 GpuRegister temp1 = locations->GetTemp(0).AsRegister<GpuRegister>();
2699 GpuRegister temp2 = TMP; // Doesn't need to survive slow path.
2700 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2701 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
2702 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
2703 Mips64Label done;
2704 SlowPathCodeMIPS64* slow_path = nullptr;
2705
2706 if (may_need_runtime_call_for_type_check) {
Vladimir Marko174b2e22017-10-12 13:34:49 +01002707 slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS64(instruction);
Alexey Frunze15958152017-02-09 19:08:30 -08002708 codegen_->AddSlowPath(slow_path);
2709 if (instruction->GetValueCanBeNull()) {
2710 Mips64Label non_zero;
2711 __ Bnezc(value, &non_zero);
2712 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2713 if (index.IsConstant()) {
2714 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002715 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002716 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002717 }
Alexey Frunze15958152017-02-09 19:08:30 -08002718 __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
2719 __ Bc(&done);
2720 __ Bind(&non_zero);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002721 }
Alexey Frunze15958152017-02-09 19:08:30 -08002722
2723 // Note that when read barriers are enabled, the type checks
2724 // are performed without read barriers. This is fine, even in
2725 // the case where a class object is in the from-space after
2726 // the flip, as a comparison involving such a type would not
2727 // produce a false positive; it may of course produce a false
2728 // negative, in which case we would take the ArraySet slow
2729 // path.
2730
2731 // /* HeapReference<Class> */ temp1 = obj->klass_
2732 __ LoadFromOffset(kLoadUnsignedWord, temp1, obj, class_offset, null_checker);
2733 __ MaybeUnpoisonHeapReference(temp1);
2734
2735 // /* HeapReference<Class> */ temp1 = temp1->component_type_
2736 __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, component_offset);
2737 // /* HeapReference<Class> */ temp2 = value->klass_
2738 __ LoadFromOffset(kLoadUnsignedWord, temp2, value, class_offset);
2739 // If heap poisoning is enabled, no need to unpoison `temp1`
2740 // nor `temp2`, as we are comparing two poisoned references.
2741
2742 if (instruction->StaticTypeOfArrayIsObjectArray()) {
2743 Mips64Label do_put;
2744 __ Beqc(temp1, temp2, &do_put);
2745 // If heap poisoning is enabled, the `temp1` reference has
2746 // not been unpoisoned yet; unpoison it now.
2747 __ MaybeUnpoisonHeapReference(temp1);
2748
2749 // /* HeapReference<Class> */ temp1 = temp1->super_class_
2750 __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, super_offset);
2751 // If heap poisoning is enabled, no need to unpoison
2752 // `temp1`, as we are comparing against null below.
2753 __ Bnezc(temp1, slow_path->GetEntryLabel());
2754 __ Bind(&do_put);
2755 } else {
2756 __ Bnec(temp1, temp2, slow_path->GetEntryLabel());
2757 }
2758 }
2759
2760 GpuRegister source = value;
2761 if (kPoisonHeapReferences) {
2762 // Note that in the case where `value` is a null reference,
2763 // we do not enter this block, as a null reference does not
2764 // need poisoning.
2765 __ Move(temp1, value);
2766 __ PoisonHeapReference(temp1);
2767 source = temp1;
2768 }
2769
2770 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2771 if (index.IsConstant()) {
2772 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002773 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002774 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Alexey Frunze15958152017-02-09 19:08:30 -08002775 }
2776 __ StoreToOffset(kStoreWord, source, base_reg, data_offset);
2777
2778 if (!may_need_runtime_call_for_type_check) {
2779 codegen_->MaybeRecordImplicitNullCheck(instruction);
2780 }
2781
2782 codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull());
2783
2784 if (done.IsLinked()) {
2785 __ Bind(&done);
2786 }
2787
2788 if (slow_path != nullptr) {
2789 __ Bind(slow_path->GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002790 }
2791 break;
2792 }
2793
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002794 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002795 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002796 if (index.IsConstant()) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002797 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002798 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002799 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002800 }
2801 if (value_location.IsConstant()) {
2802 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
2803 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
2804 } else {
2805 GpuRegister value = value_location.AsRegister<GpuRegister>();
2806 __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002807 }
2808 break;
2809 }
2810
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002811 case DataType::Type::kFloat32: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002812 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002813 if (index.IsConstant()) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002814 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002815 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002816 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002817 }
2818 if (value_location.IsConstant()) {
2819 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2820 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2821 } else {
2822 FpuRegister value = value_location.AsFpuRegister<FpuRegister>();
2823 __ StoreFpuToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002824 }
2825 break;
2826 }
2827
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002828 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002829 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002830 if (index.IsConstant()) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002831 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002832 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002833 __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01002834 }
2835 if (value_location.IsConstant()) {
2836 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
2837 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
2838 } else {
2839 FpuRegister value = value_location.AsFpuRegister<FpuRegister>();
2840 __ StoreFpuToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002841 }
2842 break;
2843 }
2844
Aart Bik66c158e2018-01-31 12:55:04 -08002845 case DataType::Type::kUint32:
2846 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002847 case DataType::Type::kVoid:
Alexey Frunze4dda3372015-06-01 18:31:49 -07002848 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2849 UNREACHABLE();
2850 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002851}
2852
2853void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01002854 RegisterSet caller_saves = RegisterSet::Empty();
2855 InvokeRuntimeCallingConvention calling_convention;
2856 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2857 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2858 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves);
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01002859
2860 HInstruction* index = instruction->InputAt(0);
2861 HInstruction* length = instruction->InputAt(1);
2862
2863 bool const_index = false;
2864 bool const_length = false;
2865
2866 if (index->IsConstant()) {
2867 if (length->IsConstant()) {
2868 const_index = true;
2869 const_length = true;
2870 } else {
2871 int32_t index_value = index->AsIntConstant()->GetValue();
2872 if (index_value < 0 || IsInt<16>(index_value + 1)) {
2873 const_index = true;
2874 }
2875 }
2876 } else if (length->IsConstant()) {
2877 int32_t length_value = length->AsIntConstant()->GetValue();
2878 if (IsUint<15>(length_value)) {
2879 const_length = true;
2880 }
2881 }
2882
2883 locations->SetInAt(0, const_index
2884 ? Location::ConstantLocation(index->AsConstant())
2885 : Location::RequiresRegister());
2886 locations->SetInAt(1, const_length
2887 ? Location::ConstantLocation(length->AsConstant())
2888 : Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002889}
2890
2891void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
2892 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01002893 Location index_loc = locations->InAt(0);
2894 Location length_loc = locations->InAt(1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002895
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01002896 if (length_loc.IsConstant()) {
2897 int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue();
2898 if (index_loc.IsConstant()) {
2899 int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue();
2900 if (index < 0 || index >= length) {
2901 BoundsCheckSlowPathMIPS64* slow_path =
2902 new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction);
2903 codegen_->AddSlowPath(slow_path);
2904 __ Bc(slow_path->GetEntryLabel());
2905 } else {
2906 // Nothing to be done.
2907 }
2908 return;
2909 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002910
Goran Jakovljevicdbd43032017-11-15 16:31:56 +01002911 BoundsCheckSlowPathMIPS64* slow_path =
2912 new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction);
2913 codegen_->AddSlowPath(slow_path);
2914 GpuRegister index = index_loc.AsRegister<GpuRegister>();
2915 if (length == 0) {
2916 __ Bc(slow_path->GetEntryLabel());
2917 } else if (length == 1) {
2918 __ Bnezc(index, slow_path->GetEntryLabel());
2919 } else {
2920 DCHECK(IsUint<15>(length)) << length;
2921 __ Sltiu(TMP, index, length);
2922 __ Beqzc(TMP, slow_path->GetEntryLabel());
2923 }
2924 } else {
2925 GpuRegister length = length_loc.AsRegister<GpuRegister>();
2926 BoundsCheckSlowPathMIPS64* slow_path =
2927 new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction);
2928 codegen_->AddSlowPath(slow_path);
2929 if (index_loc.IsConstant()) {
2930 int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue();
2931 if (index < 0) {
2932 __ Bc(slow_path->GetEntryLabel());
2933 } else if (index == 0) {
2934 __ Blezc(length, slow_path->GetEntryLabel());
2935 } else {
2936 DCHECK(IsInt<16>(index + 1)) << index;
2937 __ Sltiu(TMP, length, index + 1);
2938 __ Bnezc(TMP, slow_path->GetEntryLabel());
2939 }
2940 } else {
2941 GpuRegister index = index_loc.AsRegister<GpuRegister>();
2942 __ Bgeuc(index, length, slow_path->GetEntryLabel());
2943 }
2944 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002945}
2946
Alexey Frunze15958152017-02-09 19:08:30 -08002947// Temp is used for read barrier.
2948static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) {
2949 if (kEmitCompilerReadBarrier &&
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002950 !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) &&
Alexey Frunze15958152017-02-09 19:08:30 -08002951 (kUseBakerReadBarrier ||
2952 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
2953 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
2954 type_check_kind == TypeCheckKind::kArrayObjectCheck)) {
2955 return 1;
2956 }
2957 return 0;
2958}
2959
2960// Extra temp is used for read barrier.
2961static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) {
2962 return 1 + NumberOfInstanceOfTemps(type_check_kind);
2963}
2964
Alexey Frunze4dda3372015-06-01 18:31:49 -07002965void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002966 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunzedfc30af2018-01-24 16:25:10 -08002967 LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction);
Vladimir Markoca6fff82017-10-03 14:49:14 +01002968 LocationSummary* locations =
2969 new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002970 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko175e7862018-03-27 09:03:13 +00002971 if (type_check_kind == TypeCheckKind::kBitstringCheck) {
2972 locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant()));
2973 locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant()));
2974 locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant()));
2975 } else {
2976 locations->SetInAt(1, Location::RequiresRegister());
2977 }
Alexey Frunze15958152017-02-09 19:08:30 -08002978 locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002979}
2980
2981void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002982 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002983 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08002984 Location obj_loc = locations->InAt(0);
2985 GpuRegister obj = obj_loc.AsRegister<GpuRegister>();
Vladimir Marko175e7862018-03-27 09:03:13 +00002986 Location cls = locations->InAt(1);
Alexey Frunze15958152017-02-09 19:08:30 -08002987 Location temp_loc = locations->GetTemp(0);
2988 GpuRegister temp = temp_loc.AsRegister<GpuRegister>();
2989 const size_t num_temps = NumberOfCheckCastTemps(type_check_kind);
2990 DCHECK_LE(num_temps, 2u);
2991 Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation();
Alexey Frunze66b69ad2017-02-24 00:51:44 -08002992 const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2993 const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
2994 const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
2995 const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
2996 const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value();
2997 const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value();
2998 const uint32_t object_array_data_offset =
2999 mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value();
3000 Mips64Label done;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003001
Alexey Frunzedfc30af2018-01-24 16:25:10 -08003002 bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction);
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01003003 SlowPathCodeMIPS64* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01003004 new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64(
3005 instruction, is_type_check_slow_path_fatal);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003006 codegen_->AddSlowPath(slow_path);
3007
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003008 // Avoid this check if we know `obj` is not null.
3009 if (instruction->MustDoNullCheck()) {
3010 __ Beqzc(obj, &done);
3011 }
3012
3013 switch (type_check_kind) {
3014 case TypeCheckKind::kExactCheck:
3015 case TypeCheckKind::kArrayCheck: {
3016 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003017 GenerateReferenceLoadTwoRegisters(instruction,
3018 temp_loc,
3019 obj_loc,
3020 class_offset,
3021 maybe_temp2_loc,
3022 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003023 // Jump to slow path for throwing the exception or doing a
3024 // more involved array check.
Vladimir Marko175e7862018-03-27 09:03:13 +00003025 __ Bnec(temp, cls.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003026 break;
3027 }
3028
3029 case TypeCheckKind::kAbstractClassCheck: {
3030 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003031 GenerateReferenceLoadTwoRegisters(instruction,
3032 temp_loc,
3033 obj_loc,
3034 class_offset,
3035 maybe_temp2_loc,
3036 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003037 // If the class is abstract, we eagerly fetch the super class of the
3038 // object to avoid doing a comparison we know will fail.
3039 Mips64Label loop;
3040 __ Bind(&loop);
3041 // /* HeapReference<Class> */ temp = temp->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08003042 GenerateReferenceLoadOneRegister(instruction,
3043 temp_loc,
3044 super_offset,
3045 maybe_temp2_loc,
3046 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003047 // If the class reference currently in `temp` is null, jump to the slow path to throw the
3048 // exception.
3049 __ Beqzc(temp, slow_path->GetEntryLabel());
3050 // Otherwise, compare the classes.
Vladimir Marko175e7862018-03-27 09:03:13 +00003051 __ Bnec(temp, cls.AsRegister<GpuRegister>(), &loop);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003052 break;
3053 }
3054
3055 case TypeCheckKind::kClassHierarchyCheck: {
3056 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003057 GenerateReferenceLoadTwoRegisters(instruction,
3058 temp_loc,
3059 obj_loc,
3060 class_offset,
3061 maybe_temp2_loc,
3062 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003063 // Walk over the class hierarchy to find a match.
3064 Mips64Label loop;
3065 __ Bind(&loop);
Vladimir Marko175e7862018-03-27 09:03:13 +00003066 __ Beqc(temp, cls.AsRegister<GpuRegister>(), &done);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003067 // /* HeapReference<Class> */ temp = temp->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08003068 GenerateReferenceLoadOneRegister(instruction,
3069 temp_loc,
3070 super_offset,
3071 maybe_temp2_loc,
3072 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003073 // If the class reference currently in `temp` is null, jump to the slow path to throw the
3074 // exception. Otherwise, jump to the beginning of the loop.
3075 __ Bnezc(temp, &loop);
3076 __ Bc(slow_path->GetEntryLabel());
3077 break;
3078 }
3079
3080 case TypeCheckKind::kArrayObjectCheck: {
3081 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003082 GenerateReferenceLoadTwoRegisters(instruction,
3083 temp_loc,
3084 obj_loc,
3085 class_offset,
3086 maybe_temp2_loc,
3087 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003088 // Do an exact check.
Vladimir Marko175e7862018-03-27 09:03:13 +00003089 __ Beqc(temp, cls.AsRegister<GpuRegister>(), &done);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003090 // Otherwise, we need to check that the object's class is a non-primitive array.
3091 // /* HeapReference<Class> */ temp = temp->component_type_
Alexey Frunze15958152017-02-09 19:08:30 -08003092 GenerateReferenceLoadOneRegister(instruction,
3093 temp_loc,
3094 component_offset,
3095 maybe_temp2_loc,
3096 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003097 // If the component type is null, jump to the slow path to throw the exception.
3098 __ Beqzc(temp, slow_path->GetEntryLabel());
3099 // Otherwise, the object is indeed an array, further check that this component
3100 // type is not a primitive type.
3101 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
3102 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
3103 __ Bnezc(temp, slow_path->GetEntryLabel());
3104 break;
3105 }
3106
3107 case TypeCheckKind::kUnresolvedCheck:
3108 // We always go into the type check slow path for the unresolved check case.
3109 // We cannot directly call the CheckCast runtime entry point
3110 // without resorting to a type checking slow path here (i.e. by
3111 // calling InvokeRuntime directly), as it would require to
3112 // assign fixed registers for the inputs of this HInstanceOf
3113 // instruction (following the runtime calling convention), which
3114 // might be cluttered by the potential first read barrier
3115 // emission at the beginning of this method.
3116 __ Bc(slow_path->GetEntryLabel());
3117 break;
3118
3119 case TypeCheckKind::kInterfaceCheck: {
3120 // Avoid read barriers to improve performance of the fast path. We can not get false
3121 // positives by doing this.
3122 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003123 GenerateReferenceLoadTwoRegisters(instruction,
3124 temp_loc,
3125 obj_loc,
3126 class_offset,
3127 maybe_temp2_loc,
3128 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003129 // /* HeapReference<Class> */ temp = temp->iftable_
Alexey Frunze15958152017-02-09 19:08:30 -08003130 GenerateReferenceLoadTwoRegisters(instruction,
3131 temp_loc,
3132 temp_loc,
3133 iftable_offset,
3134 maybe_temp2_loc,
3135 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003136 // Iftable is never null.
3137 __ Lw(TMP, temp, array_length_offset);
3138 // Loop through the iftable and check if any class matches.
3139 Mips64Label loop;
3140 __ Bind(&loop);
3141 __ Beqzc(TMP, slow_path->GetEntryLabel());
3142 __ Lwu(AT, temp, object_array_data_offset);
3143 __ MaybeUnpoisonHeapReference(AT);
3144 // Go to next interface.
3145 __ Daddiu(temp, temp, 2 * kHeapReferenceSize);
3146 __ Addiu(TMP, TMP, -2);
3147 // Compare the classes and continue the loop if they do not match.
Vladimir Marko175e7862018-03-27 09:03:13 +00003148 __ Bnec(AT, cls.AsRegister<GpuRegister>(), &loop);
3149 break;
3150 }
3151
3152 case TypeCheckKind::kBitstringCheck: {
3153 // /* HeapReference<Class> */ temp = obj->klass_
3154 GenerateReferenceLoadTwoRegisters(instruction,
3155 temp_loc,
3156 obj_loc,
3157 class_offset,
3158 maybe_temp2_loc,
3159 kWithoutReadBarrier);
3160
3161 GenerateBitstringTypeCheckCompare(instruction, temp);
3162 __ Bnezc(temp, slow_path->GetEntryLabel());
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003163 break;
3164 }
3165 }
3166
3167 __ Bind(&done);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003168 __ Bind(slow_path->GetExitLabel());
3169}
3170
3171void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) {
3172 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003173 new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003174 locations->SetInAt(0, Location::RequiresRegister());
3175 if (check->HasUses()) {
3176 locations->SetOut(Location::SameAsFirstInput());
3177 }
Vladimir Marko3232dbb2018-07-25 15:42:46 +01003178 // Rely on the type initialization to save everything we need.
3179 locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003180}
3181
3182void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) {
3183 // We assume the class is not null.
Vladimir Markoa9f303c2018-07-20 16:43:56 +01003184 SlowPathCodeMIPS64* slow_path =
3185 new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64(check->GetLoadClass(), check);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003186 codegen_->AddSlowPath(slow_path);
3187 GenerateClassInitializationCheck(slow_path,
3188 check->GetLocations()->InAt(0).AsRegister<GpuRegister>());
3189}
3190
3191void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003192 DataType::Type in_type = compare->InputAt(0)->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003193
Vladimir Markoca6fff82017-10-03 14:49:14 +01003194 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(compare);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003195
3196 switch (in_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003197 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003198 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003199 case DataType::Type::kInt8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003200 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003201 case DataType::Type::kInt16:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003202 case DataType::Type::kInt32:
3203 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07003204 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07003205 locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003206 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3207 break;
3208
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003209 case DataType::Type::kFloat32:
3210 case DataType::Type::kFloat64:
Alexey Frunze299a9392015-12-08 16:08:02 -08003211 locations->SetInAt(0, Location::RequiresFpuRegister());
3212 locations->SetInAt(1, Location::RequiresFpuRegister());
3213 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003214 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003215
3216 default:
3217 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
3218 }
3219}
3220
3221void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) {
3222 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze299a9392015-12-08 16:08:02 -08003223 GpuRegister res = locations->Out().AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003224 DataType::Type in_type = instruction->InputAt(0)->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003225
3226 // 0 if: left == right
3227 // 1 if: left > right
3228 // -1 if: left < right
3229 switch (in_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003230 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003231 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003232 case DataType::Type::kInt8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003233 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003234 case DataType::Type::kInt16:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003235 case DataType::Type::kInt32:
3236 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003237 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07003238 Location rhs_location = locations->InAt(1);
3239 bool use_imm = rhs_location.IsConstant();
3240 GpuRegister rhs = ZERO;
3241 if (use_imm) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003242 if (in_type == DataType::Type::kInt64) {
Aart Bika19616e2016-02-01 18:57:58 -08003243 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
3244 if (value != 0) {
3245 rhs = AT;
3246 __ LoadConst64(rhs, value);
3247 }
Roland Levillaina5c4a402016-03-15 15:02:50 +00003248 } else {
3249 int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant());
3250 if (value != 0) {
3251 rhs = AT;
3252 __ LoadConst32(rhs, value);
3253 }
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07003254 }
3255 } else {
3256 rhs = rhs_location.AsRegister<GpuRegister>();
3257 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003258 __ Slt(TMP, lhs, rhs);
Alexey Frunze299a9392015-12-08 16:08:02 -08003259 __ Slt(res, rhs, lhs);
3260 __ Subu(res, res, TMP);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003261 break;
3262 }
3263
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003264 case DataType::Type::kFloat32: {
Alexey Frunze299a9392015-12-08 16:08:02 -08003265 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
3266 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
3267 Mips64Label done;
3268 __ CmpEqS(FTMP, lhs, rhs);
3269 __ LoadConst32(res, 0);
3270 __ Bc1nez(FTMP, &done);
Roland Levillain32ca3752016-02-17 16:49:37 +00003271 if (instruction->IsGtBias()) {
Alexey Frunze299a9392015-12-08 16:08:02 -08003272 __ CmpLtS(FTMP, lhs, rhs);
3273 __ LoadConst32(res, -1);
3274 __ Bc1nez(FTMP, &done);
3275 __ LoadConst32(res, 1);
3276 } else {
3277 __ CmpLtS(FTMP, rhs, lhs);
3278 __ LoadConst32(res, 1);
3279 __ Bc1nez(FTMP, &done);
3280 __ LoadConst32(res, -1);
3281 }
3282 __ Bind(&done);
3283 break;
3284 }
3285
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003286 case DataType::Type::kFloat64: {
Alexey Frunze299a9392015-12-08 16:08:02 -08003287 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
3288 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
3289 Mips64Label done;
3290 __ CmpEqD(FTMP, lhs, rhs);
3291 __ LoadConst32(res, 0);
3292 __ Bc1nez(FTMP, &done);
Roland Levillain32ca3752016-02-17 16:49:37 +00003293 if (instruction->IsGtBias()) {
Alexey Frunze299a9392015-12-08 16:08:02 -08003294 __ CmpLtD(FTMP, lhs, rhs);
3295 __ LoadConst32(res, -1);
3296 __ Bc1nez(FTMP, &done);
3297 __ LoadConst32(res, 1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003298 } else {
Alexey Frunze299a9392015-12-08 16:08:02 -08003299 __ CmpLtD(FTMP, rhs, lhs);
3300 __ LoadConst32(res, 1);
3301 __ Bc1nez(FTMP, &done);
3302 __ LoadConst32(res, -1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003303 }
Alexey Frunze299a9392015-12-08 16:08:02 -08003304 __ Bind(&done);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003305 break;
3306 }
3307
3308 default:
3309 LOG(FATAL) << "Unimplemented compare type " << in_type;
3310 }
3311}
3312
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00003313void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01003314 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunze299a9392015-12-08 16:08:02 -08003315 switch (instruction->InputAt(0)->GetType()) {
3316 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003317 case DataType::Type::kInt64:
Alexey Frunze299a9392015-12-08 16:08:02 -08003318 locations->SetInAt(0, Location::RequiresRegister());
3319 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3320 break;
3321
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003322 case DataType::Type::kFloat32:
3323 case DataType::Type::kFloat64:
Alexey Frunze299a9392015-12-08 16:08:02 -08003324 locations->SetInAt(0, Location::RequiresFpuRegister());
3325 locations->SetInAt(1, Location::RequiresFpuRegister());
3326 break;
3327 }
David Brazdilb3e773e2016-01-26 11:28:37 +00003328 if (!instruction->IsEmittedAtUseSite()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003329 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3330 }
3331}
3332
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00003333void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00003334 if (instruction->IsEmittedAtUseSite()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003335 return;
3336 }
3337
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003338 DataType::Type type = instruction->InputAt(0)->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003339 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze299a9392015-12-08 16:08:02 -08003340 switch (type) {
3341 default:
3342 // Integer case.
Andreas Gampe3db70682018-12-26 15:12:03 -08003343 GenerateIntLongCompare(instruction->GetCondition(), /* is64bit= */ false, locations);
Alexey Frunze299a9392015-12-08 16:08:02 -08003344 return;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003345 case DataType::Type::kInt64:
Andreas Gampe3db70682018-12-26 15:12:03 -08003346 GenerateIntLongCompare(instruction->GetCondition(), /* is64bit= */ true, locations);
Alexey Frunze299a9392015-12-08 16:08:02 -08003347 return;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003348 case DataType::Type::kFloat32:
3349 case DataType::Type::kFloat64:
Tijana Jakovljevic43758192016-12-30 09:23:01 +01003350 GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations);
3351 return;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003352 }
3353}
3354
Alexey Frunzec857c742015-09-23 15:12:39 -07003355void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
3356 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003357 DataType::Type type = instruction->GetResultType();
Alexey Frunzec857c742015-09-23 15:12:39 -07003358
3359 LocationSummary* locations = instruction->GetLocations();
3360 Location second = locations->InAt(1);
3361 DCHECK(second.IsConstant());
3362
3363 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3364 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
3365 int64_t imm = Int64FromConstant(second.GetConstant());
3366 DCHECK(imm == 1 || imm == -1);
3367
3368 if (instruction->IsRem()) {
3369 __ Move(out, ZERO);
3370 } else {
3371 if (imm == -1) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003372 if (type == DataType::Type::kInt32) {
Alexey Frunzec857c742015-09-23 15:12:39 -07003373 __ Subu(out, ZERO, dividend);
3374 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003375 DCHECK_EQ(type, DataType::Type::kInt64);
Alexey Frunzec857c742015-09-23 15:12:39 -07003376 __ Dsubu(out, ZERO, dividend);
3377 }
3378 } else if (out != dividend) {
3379 __ Move(out, dividend);
3380 }
3381 }
3382}
3383
3384void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
3385 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003386 DataType::Type type = instruction->GetResultType();
Alexey Frunzec857c742015-09-23 15:12:39 -07003387
3388 LocationSummary* locations = instruction->GetLocations();
3389 Location second = locations->InAt(1);
3390 DCHECK(second.IsConstant());
3391
3392 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3393 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
3394 int64_t imm = Int64FromConstant(second.GetConstant());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003395 uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm));
Alexey Frunzec857c742015-09-23 15:12:39 -07003396 int ctz_imm = CTZ(abs_imm);
3397
3398 if (instruction->IsDiv()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003399 if (type == DataType::Type::kInt32) {
Alexey Frunzec857c742015-09-23 15:12:39 -07003400 if (ctz_imm == 1) {
3401 // Fast path for division by +/-2, which is very common.
3402 __ Srl(TMP, dividend, 31);
3403 } else {
3404 __ Sra(TMP, dividend, 31);
3405 __ Srl(TMP, TMP, 32 - ctz_imm);
3406 }
3407 __ Addu(out, dividend, TMP);
3408 __ Sra(out, out, ctz_imm);
3409 if (imm < 0) {
3410 __ Subu(out, ZERO, out);
3411 }
3412 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003413 DCHECK_EQ(type, DataType::Type::kInt64);
Alexey Frunzec857c742015-09-23 15:12:39 -07003414 if (ctz_imm == 1) {
3415 // Fast path for division by +/-2, which is very common.
3416 __ Dsrl32(TMP, dividend, 31);
3417 } else {
3418 __ Dsra32(TMP, dividend, 31);
3419 if (ctz_imm > 32) {
3420 __ Dsrl(TMP, TMP, 64 - ctz_imm);
3421 } else {
3422 __ Dsrl32(TMP, TMP, 32 - ctz_imm);
3423 }
3424 }
3425 __ Daddu(out, dividend, TMP);
3426 if (ctz_imm < 32) {
3427 __ Dsra(out, out, ctz_imm);
3428 } else {
3429 __ Dsra32(out, out, ctz_imm - 32);
3430 }
3431 if (imm < 0) {
3432 __ Dsubu(out, ZERO, out);
3433 }
3434 }
3435 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003436 if (type == DataType::Type::kInt32) {
Alexey Frunzec857c742015-09-23 15:12:39 -07003437 if (ctz_imm == 1) {
3438 // Fast path for modulo +/-2, which is very common.
3439 __ Sra(TMP, dividend, 31);
3440 __ Subu(out, dividend, TMP);
3441 __ Andi(out, out, 1);
3442 __ Addu(out, out, TMP);
3443 } else {
3444 __ Sra(TMP, dividend, 31);
3445 __ Srl(TMP, TMP, 32 - ctz_imm);
3446 __ Addu(out, dividend, TMP);
Lena Djokica556e6b2017-12-13 12:09:42 +01003447 __ Ins(out, ZERO, ctz_imm, 32 - ctz_imm);
Alexey Frunzec857c742015-09-23 15:12:39 -07003448 __ Subu(out, out, TMP);
3449 }
3450 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003451 DCHECK_EQ(type, DataType::Type::kInt64);
Alexey Frunzec857c742015-09-23 15:12:39 -07003452 if (ctz_imm == 1) {
3453 // Fast path for modulo +/-2, which is very common.
3454 __ Dsra32(TMP, dividend, 31);
3455 __ Dsubu(out, dividend, TMP);
3456 __ Andi(out, out, 1);
3457 __ Daddu(out, out, TMP);
3458 } else {
3459 __ Dsra32(TMP, dividend, 31);
3460 if (ctz_imm > 32) {
3461 __ Dsrl(TMP, TMP, 64 - ctz_imm);
3462 } else {
3463 __ Dsrl32(TMP, TMP, 32 - ctz_imm);
3464 }
3465 __ Daddu(out, dividend, TMP);
Lena Djokica556e6b2017-12-13 12:09:42 +01003466 __ DblIns(out, ZERO, ctz_imm, 64 - ctz_imm);
Alexey Frunzec857c742015-09-23 15:12:39 -07003467 __ Dsubu(out, out, TMP);
3468 }
3469 }
3470 }
3471}
3472
3473void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
3474 DCHECK(instruction->IsDiv() || instruction->IsRem());
3475
3476 LocationSummary* locations = instruction->GetLocations();
3477 Location second = locations->InAt(1);
3478 DCHECK(second.IsConstant());
3479
3480 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3481 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
3482 int64_t imm = Int64FromConstant(second.GetConstant());
3483
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003484 DataType::Type type = instruction->GetResultType();
3485 DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type;
Alexey Frunzec857c742015-09-23 15:12:39 -07003486
3487 int64_t magic;
3488 int shift;
3489 CalculateMagicAndShiftForDivRem(imm,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003490 (type == DataType::Type::kInt64),
Alexey Frunzec857c742015-09-23 15:12:39 -07003491 &magic,
3492 &shift);
3493
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003494 if (type == DataType::Type::kInt32) {
Alexey Frunzec857c742015-09-23 15:12:39 -07003495 __ LoadConst32(TMP, magic);
3496 __ MuhR6(TMP, dividend, TMP);
3497
3498 if (imm > 0 && magic < 0) {
3499 __ Addu(TMP, TMP, dividend);
3500 } else if (imm < 0 && magic > 0) {
3501 __ Subu(TMP, TMP, dividend);
3502 }
3503
3504 if (shift != 0) {
3505 __ Sra(TMP, TMP, shift);
3506 }
3507
3508 if (instruction->IsDiv()) {
3509 __ Sra(out, TMP, 31);
3510 __ Subu(out, TMP, out);
3511 } else {
3512 __ Sra(AT, TMP, 31);
3513 __ Subu(AT, TMP, AT);
3514 __ LoadConst32(TMP, imm);
3515 __ MulR6(TMP, AT, TMP);
3516 __ Subu(out, dividend, TMP);
3517 }
3518 } else {
3519 __ LoadConst64(TMP, magic);
3520 __ Dmuh(TMP, dividend, TMP);
3521
3522 if (imm > 0 && magic < 0) {
3523 __ Daddu(TMP, TMP, dividend);
3524 } else if (imm < 0 && magic > 0) {
3525 __ Dsubu(TMP, TMP, dividend);
3526 }
3527
3528 if (shift >= 32) {
3529 __ Dsra32(TMP, TMP, shift - 32);
3530 } else if (shift > 0) {
3531 __ Dsra(TMP, TMP, shift);
3532 }
3533
3534 if (instruction->IsDiv()) {
3535 __ Dsra32(out, TMP, 31);
3536 __ Dsubu(out, TMP, out);
3537 } else {
3538 __ Dsra32(AT, TMP, 31);
3539 __ Dsubu(AT, TMP, AT);
3540 __ LoadConst64(TMP, imm);
3541 __ Dmul(TMP, AT, TMP);
3542 __ Dsubu(out, dividend, TMP);
3543 }
3544 }
3545}
3546
3547void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) {
3548 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003549 DataType::Type type = instruction->GetResultType();
3550 DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type;
Alexey Frunzec857c742015-09-23 15:12:39 -07003551
3552 LocationSummary* locations = instruction->GetLocations();
3553 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3554 Location second = locations->InAt(1);
3555
3556 if (second.IsConstant()) {
3557 int64_t imm = Int64FromConstant(second.GetConstant());
3558 if (imm == 0) {
3559 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
3560 } else if (imm == 1 || imm == -1) {
3561 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003562 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunzec857c742015-09-23 15:12:39 -07003563 DivRemByPowerOfTwo(instruction);
3564 } else {
3565 DCHECK(imm <= -2 || imm >= 2);
3566 GenerateDivRemWithAnyConstant(instruction);
3567 }
3568 } else {
3569 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
3570 GpuRegister divisor = second.AsRegister<GpuRegister>();
3571 if (instruction->IsDiv()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003572 if (type == DataType::Type::kInt32)
Alexey Frunzec857c742015-09-23 15:12:39 -07003573 __ DivR6(out, dividend, divisor);
3574 else
3575 __ Ddiv(out, dividend, divisor);
3576 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003577 if (type == DataType::Type::kInt32)
Alexey Frunzec857c742015-09-23 15:12:39 -07003578 __ ModR6(out, dividend, divisor);
3579 else
3580 __ Dmod(out, dividend, divisor);
3581 }
3582 }
3583}
3584
Alexey Frunze4dda3372015-06-01 18:31:49 -07003585void LocationsBuilderMIPS64::VisitDiv(HDiv* div) {
3586 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003587 new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003588 switch (div->GetResultType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003589 case DataType::Type::kInt32:
3590 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07003591 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunzec857c742015-09-23 15:12:39 -07003592 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003593 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3594 break;
3595
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003596 case DataType::Type::kFloat32:
3597 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07003598 locations->SetInAt(0, Location::RequiresFpuRegister());
3599 locations->SetInAt(1, Location::RequiresFpuRegister());
3600 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3601 break;
3602
3603 default:
3604 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
3605 }
3606}
3607
3608void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003609 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003610 LocationSummary* locations = instruction->GetLocations();
3611
3612 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003613 case DataType::Type::kInt32:
3614 case DataType::Type::kInt64:
Alexey Frunzec857c742015-09-23 15:12:39 -07003615 GenerateDivRemIntegral(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003616 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003617 case DataType::Type::kFloat32:
3618 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003619 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3620 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
3621 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003622 if (type == DataType::Type::kFloat32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07003623 __ DivS(dst, lhs, rhs);
3624 else
3625 __ DivD(dst, lhs, rhs);
3626 break;
3627 }
3628 default:
3629 LOG(FATAL) << "Unexpected div type " << type;
3630 }
3631}
3632
3633void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01003634 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003635 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003636}
3637
3638void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
3639 SlowPathCodeMIPS64* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01003640 new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003641 codegen_->AddSlowPath(slow_path);
3642 Location value = instruction->GetLocations()->InAt(0);
3643
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003644 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003645
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003646 if (!DataType::IsIntegralType(type)) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00003647 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
Elliott Hughesc1896c92018-11-29 11:33:18 -08003648 UNREACHABLE();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003649 }
3650
3651 if (value.IsConstant()) {
3652 int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant());
3653 if (divisor == 0) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003654 __ Bc(slow_path->GetEntryLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003655 } else {
3656 // A division by a non-null constant is valid. We don't need to perform
3657 // any check, so simply fall through.
3658 }
3659 } else {
3660 __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
3661 }
3662}
3663
3664void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) {
3665 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003666 new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003667 locations->SetOut(Location::ConstantLocation(constant));
3668}
3669
3670void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
3671 // Will be generated at use site.
3672}
3673
3674void LocationsBuilderMIPS64::VisitExit(HExit* exit) {
3675 exit->SetLocations(nullptr);
3676}
3677
3678void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
3679}
3680
3681void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) {
3682 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003683 new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003684 locations->SetOut(Location::ConstantLocation(constant));
3685}
3686
3687void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
3688 // Will be generated at use site.
3689}
3690
David Brazdilfc6a86a2015-06-26 10:33:45 +00003691void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Aart Bika8b8e9b2018-01-09 11:01:02 -08003692 if (successor->IsExitBlock()) {
3693 DCHECK(got->GetPrevious()->AlwaysThrows());
3694 return; // no code needed
3695 }
3696
Alexey Frunze4dda3372015-06-01 18:31:49 -07003697 HBasicBlock* block = got->GetBlock();
3698 HInstruction* previous = got->GetPrevious();
3699 HLoopInformation* info = block->GetLoopInformation();
3700
3701 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Goran Jakovljevicfeec1672018-02-08 10:20:14 +01003702 if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) {
3703 __ Ld(AT, SP, kCurrentMethodStackOffset);
3704 __ Lhu(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value());
3705 __ Addiu(TMP, TMP, 1);
3706 __ Sh(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value());
3707 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003708 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
3709 return;
3710 }
3711 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
3712 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
3713 }
3714 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003715 __ Bc(codegen_->GetLabelOf(successor));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003716 }
3717}
3718
David Brazdilfc6a86a2015-06-26 10:33:45 +00003719void LocationsBuilderMIPS64::VisitGoto(HGoto* got) {
3720 got->SetLocations(nullptr);
3721}
3722
3723void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) {
3724 HandleGoto(got, got->GetSuccessor());
3725}
3726
3727void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
3728 try_boundary->SetLocations(nullptr);
3729}
3730
3731void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
3732 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
3733 if (!successor->IsExitBlock()) {
3734 HandleGoto(try_boundary, successor);
3735 }
3736}
3737
Alexey Frunze299a9392015-12-08 16:08:02 -08003738void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond,
3739 bool is64bit,
3740 LocationSummary* locations) {
3741 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3742 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
3743 Location rhs_location = locations->InAt(1);
3744 GpuRegister rhs_reg = ZERO;
3745 int64_t rhs_imm = 0;
3746 bool use_imm = rhs_location.IsConstant();
3747 if (use_imm) {
3748 if (is64bit) {
3749 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
3750 } else {
3751 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
3752 }
3753 } else {
3754 rhs_reg = rhs_location.AsRegister<GpuRegister>();
3755 }
3756 int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1);
3757
3758 switch (cond) {
3759 case kCondEQ:
3760 case kCondNE:
Goran Jakovljevicdb3deee2016-12-28 14:33:21 +01003761 if (use_imm && IsInt<16>(-rhs_imm)) {
3762 if (rhs_imm == 0) {
3763 if (cond == kCondEQ) {
3764 __ Sltiu(dst, lhs, 1);
3765 } else {
3766 __ Sltu(dst, ZERO, lhs);
3767 }
3768 } else {
3769 if (is64bit) {
3770 __ Daddiu(dst, lhs, -rhs_imm);
3771 } else {
3772 __ Addiu(dst, lhs, -rhs_imm);
3773 }
3774 if (cond == kCondEQ) {
3775 __ Sltiu(dst, dst, 1);
3776 } else {
3777 __ Sltu(dst, ZERO, dst);
3778 }
Alexey Frunze299a9392015-12-08 16:08:02 -08003779 }
Alexey Frunze299a9392015-12-08 16:08:02 -08003780 } else {
Goran Jakovljevicdb3deee2016-12-28 14:33:21 +01003781 if (use_imm && IsUint<16>(rhs_imm)) {
3782 __ Xori(dst, lhs, rhs_imm);
3783 } else {
3784 if (use_imm) {
3785 rhs_reg = TMP;
3786 __ LoadConst64(rhs_reg, rhs_imm);
3787 }
3788 __ Xor(dst, lhs, rhs_reg);
3789 }
3790 if (cond == kCondEQ) {
3791 __ Sltiu(dst, dst, 1);
3792 } else {
3793 __ Sltu(dst, ZERO, dst);
3794 }
Alexey Frunze299a9392015-12-08 16:08:02 -08003795 }
3796 break;
3797
3798 case kCondLT:
3799 case kCondGE:
3800 if (use_imm && IsInt<16>(rhs_imm)) {
3801 __ Slti(dst, lhs, rhs_imm);
3802 } else {
3803 if (use_imm) {
3804 rhs_reg = TMP;
3805 __ LoadConst64(rhs_reg, rhs_imm);
3806 }
3807 __ Slt(dst, lhs, rhs_reg);
3808 }
3809 if (cond == kCondGE) {
3810 // Simulate lhs >= rhs via !(lhs < rhs) since there's
3811 // only the slt instruction but no sge.
3812 __ Xori(dst, dst, 1);
3813 }
3814 break;
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 if (cond == kCondGT) {
3822 // Simulate lhs > rhs via !(lhs <= rhs) since there's
3823 // only the slti instruction but no sgti.
3824 __ Xori(dst, dst, 1);
3825 }
3826 } else {
3827 if (use_imm) {
3828 rhs_reg = TMP;
3829 __ LoadConst64(rhs_reg, rhs_imm);
3830 }
3831 __ Slt(dst, rhs_reg, lhs);
3832 if (cond == kCondLE) {
3833 // Simulate lhs <= rhs via !(rhs < lhs) since there's
3834 // only the slt instruction but no sle.
3835 __ Xori(dst, dst, 1);
3836 }
3837 }
3838 break;
3839
3840 case kCondB:
3841 case kCondAE:
3842 if (use_imm && IsInt<16>(rhs_imm)) {
3843 // Sltiu sign-extends its 16-bit immediate operand before
3844 // the comparison and thus lets us compare directly with
3845 // unsigned values in the ranges [0, 0x7fff] and
3846 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
3847 __ Sltiu(dst, lhs, rhs_imm);
3848 } else {
3849 if (use_imm) {
3850 rhs_reg = TMP;
3851 __ LoadConst64(rhs_reg, rhs_imm);
3852 }
3853 __ Sltu(dst, lhs, rhs_reg);
3854 }
3855 if (cond == kCondAE) {
3856 // Simulate lhs >= rhs via !(lhs < rhs) since there's
3857 // only the sltu instruction but no sgeu.
3858 __ Xori(dst, dst, 1);
3859 }
3860 break;
3861
3862 case kCondBE:
3863 case kCondA:
3864 if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) {
3865 // Simulate lhs <= rhs via lhs < rhs + 1.
3866 // Note that this only works if rhs + 1 does not overflow
3867 // to 0, hence the check above.
3868 // Sltiu sign-extends its 16-bit immediate operand before
3869 // the comparison and thus lets us compare directly with
3870 // unsigned values in the ranges [0, 0x7fff] and
3871 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
3872 __ Sltiu(dst, lhs, rhs_imm_plus_one);
3873 if (cond == kCondA) {
3874 // Simulate lhs > rhs via !(lhs <= rhs) since there's
3875 // only the sltiu instruction but no sgtiu.
3876 __ Xori(dst, dst, 1);
3877 }
3878 } else {
3879 if (use_imm) {
3880 rhs_reg = TMP;
3881 __ LoadConst64(rhs_reg, rhs_imm);
3882 }
3883 __ Sltu(dst, rhs_reg, lhs);
3884 if (cond == kCondBE) {
3885 // Simulate lhs <= rhs via !(rhs < lhs) since there's
3886 // only the sltu instruction but no sleu.
3887 __ Xori(dst, dst, 1);
3888 }
3889 }
3890 break;
3891 }
3892}
3893
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02003894bool InstructionCodeGeneratorMIPS64::MaterializeIntLongCompare(IfCondition cond,
3895 bool is64bit,
3896 LocationSummary* input_locations,
3897 GpuRegister dst) {
3898 GpuRegister lhs = input_locations->InAt(0).AsRegister<GpuRegister>();
3899 Location rhs_location = input_locations->InAt(1);
3900 GpuRegister rhs_reg = ZERO;
3901 int64_t rhs_imm = 0;
3902 bool use_imm = rhs_location.IsConstant();
3903 if (use_imm) {
3904 if (is64bit) {
3905 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
3906 } else {
3907 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
3908 }
3909 } else {
3910 rhs_reg = rhs_location.AsRegister<GpuRegister>();
3911 }
3912 int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1);
3913
3914 switch (cond) {
3915 case kCondEQ:
3916 case kCondNE:
3917 if (use_imm && IsInt<16>(-rhs_imm)) {
3918 if (is64bit) {
3919 __ Daddiu(dst, lhs, -rhs_imm);
3920 } else {
3921 __ Addiu(dst, lhs, -rhs_imm);
3922 }
3923 } else if (use_imm && IsUint<16>(rhs_imm)) {
3924 __ Xori(dst, lhs, rhs_imm);
3925 } else {
3926 if (use_imm) {
3927 rhs_reg = TMP;
3928 __ LoadConst64(rhs_reg, rhs_imm);
3929 }
3930 __ Xor(dst, lhs, rhs_reg);
3931 }
3932 return (cond == kCondEQ);
3933
3934 case kCondLT:
3935 case kCondGE:
3936 if (use_imm && IsInt<16>(rhs_imm)) {
3937 __ Slti(dst, lhs, rhs_imm);
3938 } else {
3939 if (use_imm) {
3940 rhs_reg = TMP;
3941 __ LoadConst64(rhs_reg, rhs_imm);
3942 }
3943 __ Slt(dst, lhs, rhs_reg);
3944 }
3945 return (cond == kCondGE);
3946
3947 case kCondLE:
3948 case kCondGT:
3949 if (use_imm && IsInt<16>(rhs_imm_plus_one)) {
3950 // Simulate lhs <= rhs via lhs < rhs + 1.
3951 __ Slti(dst, lhs, rhs_imm_plus_one);
3952 return (cond == kCondGT);
3953 } else {
3954 if (use_imm) {
3955 rhs_reg = TMP;
3956 __ LoadConst64(rhs_reg, rhs_imm);
3957 }
3958 __ Slt(dst, rhs_reg, lhs);
3959 return (cond == kCondLE);
3960 }
3961
3962 case kCondB:
3963 case kCondAE:
3964 if (use_imm && IsInt<16>(rhs_imm)) {
3965 // Sltiu sign-extends its 16-bit immediate operand before
3966 // the comparison and thus lets us compare directly with
3967 // unsigned values in the ranges [0, 0x7fff] and
3968 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
3969 __ Sltiu(dst, lhs, rhs_imm);
3970 } else {
3971 if (use_imm) {
3972 rhs_reg = TMP;
3973 __ LoadConst64(rhs_reg, rhs_imm);
3974 }
3975 __ Sltu(dst, lhs, rhs_reg);
3976 }
3977 return (cond == kCondAE);
3978
3979 case kCondBE:
3980 case kCondA:
3981 if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) {
3982 // Simulate lhs <= rhs via lhs < rhs + 1.
3983 // Note that this only works if rhs + 1 does not overflow
3984 // to 0, hence the check above.
3985 // Sltiu sign-extends its 16-bit immediate operand before
3986 // the comparison and thus lets us compare directly with
3987 // unsigned values in the ranges [0, 0x7fff] and
3988 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
3989 __ Sltiu(dst, lhs, rhs_imm_plus_one);
3990 return (cond == kCondA);
3991 } else {
3992 if (use_imm) {
3993 rhs_reg = TMP;
3994 __ LoadConst64(rhs_reg, rhs_imm);
3995 }
3996 __ Sltu(dst, rhs_reg, lhs);
3997 return (cond == kCondBE);
3998 }
3999 }
4000}
4001
Alexey Frunze299a9392015-12-08 16:08:02 -08004002void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond,
4003 bool is64bit,
4004 LocationSummary* locations,
4005 Mips64Label* label) {
4006 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
4007 Location rhs_location = locations->InAt(1);
4008 GpuRegister rhs_reg = ZERO;
4009 int64_t rhs_imm = 0;
4010 bool use_imm = rhs_location.IsConstant();
4011 if (use_imm) {
4012 if (is64bit) {
4013 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
4014 } else {
4015 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
4016 }
4017 } else {
4018 rhs_reg = rhs_location.AsRegister<GpuRegister>();
4019 }
4020
4021 if (use_imm && rhs_imm == 0) {
4022 switch (cond) {
4023 case kCondEQ:
4024 case kCondBE: // <= 0 if zero
4025 __ Beqzc(lhs, label);
4026 break;
4027 case kCondNE:
4028 case kCondA: // > 0 if non-zero
4029 __ Bnezc(lhs, label);
4030 break;
4031 case kCondLT:
4032 __ Bltzc(lhs, label);
4033 break;
4034 case kCondGE:
4035 __ Bgezc(lhs, label);
4036 break;
4037 case kCondLE:
4038 __ Blezc(lhs, label);
4039 break;
4040 case kCondGT:
4041 __ Bgtzc(lhs, label);
4042 break;
4043 case kCondB: // always false
4044 break;
4045 case kCondAE: // always true
4046 __ Bc(label);
4047 break;
4048 }
4049 } else {
4050 if (use_imm) {
4051 rhs_reg = TMP;
4052 __ LoadConst64(rhs_reg, rhs_imm);
4053 }
4054 switch (cond) {
4055 case kCondEQ:
4056 __ Beqc(lhs, rhs_reg, label);
4057 break;
4058 case kCondNE:
4059 __ Bnec(lhs, rhs_reg, label);
4060 break;
4061 case kCondLT:
4062 __ Bltc(lhs, rhs_reg, label);
4063 break;
4064 case kCondGE:
4065 __ Bgec(lhs, rhs_reg, label);
4066 break;
4067 case kCondLE:
4068 __ Bgec(rhs_reg, lhs, label);
4069 break;
4070 case kCondGT:
4071 __ Bltc(rhs_reg, lhs, label);
4072 break;
4073 case kCondB:
4074 __ Bltuc(lhs, rhs_reg, label);
4075 break;
4076 case kCondAE:
4077 __ Bgeuc(lhs, rhs_reg, label);
4078 break;
4079 case kCondBE:
4080 __ Bgeuc(rhs_reg, lhs, label);
4081 break;
4082 case kCondA:
4083 __ Bltuc(rhs_reg, lhs, label);
4084 break;
4085 }
4086 }
4087}
4088
Tijana Jakovljevic43758192016-12-30 09:23:01 +01004089void InstructionCodeGeneratorMIPS64::GenerateFpCompare(IfCondition cond,
4090 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004091 DataType::Type type,
Tijana Jakovljevic43758192016-12-30 09:23:01 +01004092 LocationSummary* locations) {
4093 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
4094 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
4095 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004096 if (type == DataType::Type::kFloat32) {
Tijana Jakovljevic43758192016-12-30 09:23:01 +01004097 switch (cond) {
4098 case kCondEQ:
4099 __ CmpEqS(FTMP, lhs, rhs);
4100 __ Mfc1(dst, FTMP);
4101 __ Andi(dst, dst, 1);
4102 break;
4103 case kCondNE:
4104 __ CmpEqS(FTMP, lhs, rhs);
4105 __ Mfc1(dst, FTMP);
4106 __ Addiu(dst, dst, 1);
4107 break;
4108 case kCondLT:
4109 if (gt_bias) {
4110 __ CmpLtS(FTMP, lhs, rhs);
4111 } else {
4112 __ CmpUltS(FTMP, lhs, rhs);
4113 }
4114 __ Mfc1(dst, FTMP);
4115 __ Andi(dst, dst, 1);
4116 break;
4117 case kCondLE:
4118 if (gt_bias) {
4119 __ CmpLeS(FTMP, lhs, rhs);
4120 } else {
4121 __ CmpUleS(FTMP, lhs, rhs);
4122 }
4123 __ Mfc1(dst, FTMP);
4124 __ Andi(dst, dst, 1);
4125 break;
4126 case kCondGT:
4127 if (gt_bias) {
4128 __ CmpUltS(FTMP, rhs, lhs);
4129 } else {
4130 __ CmpLtS(FTMP, rhs, lhs);
4131 }
4132 __ Mfc1(dst, FTMP);
4133 __ Andi(dst, dst, 1);
4134 break;
4135 case kCondGE:
4136 if (gt_bias) {
4137 __ CmpUleS(FTMP, rhs, lhs);
4138 } else {
4139 __ CmpLeS(FTMP, rhs, lhs);
4140 }
4141 __ Mfc1(dst, FTMP);
4142 __ Andi(dst, dst, 1);
4143 break;
4144 default:
4145 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4146 UNREACHABLE();
4147 }
4148 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004149 DCHECK_EQ(type, DataType::Type::kFloat64);
Tijana Jakovljevic43758192016-12-30 09:23:01 +01004150 switch (cond) {
4151 case kCondEQ:
4152 __ CmpEqD(FTMP, lhs, rhs);
4153 __ Mfc1(dst, FTMP);
4154 __ Andi(dst, dst, 1);
4155 break;
4156 case kCondNE:
4157 __ CmpEqD(FTMP, lhs, rhs);
4158 __ Mfc1(dst, FTMP);
4159 __ Addiu(dst, dst, 1);
4160 break;
4161 case kCondLT:
4162 if (gt_bias) {
4163 __ CmpLtD(FTMP, lhs, rhs);
4164 } else {
4165 __ CmpUltD(FTMP, lhs, rhs);
4166 }
4167 __ Mfc1(dst, FTMP);
4168 __ Andi(dst, dst, 1);
4169 break;
4170 case kCondLE:
4171 if (gt_bias) {
4172 __ CmpLeD(FTMP, lhs, rhs);
4173 } else {
4174 __ CmpUleD(FTMP, lhs, rhs);
4175 }
4176 __ Mfc1(dst, FTMP);
4177 __ Andi(dst, dst, 1);
4178 break;
4179 case kCondGT:
4180 if (gt_bias) {
4181 __ CmpUltD(FTMP, rhs, lhs);
4182 } else {
4183 __ CmpLtD(FTMP, rhs, lhs);
4184 }
4185 __ Mfc1(dst, FTMP);
4186 __ Andi(dst, dst, 1);
4187 break;
4188 case kCondGE:
4189 if (gt_bias) {
4190 __ CmpUleD(FTMP, rhs, lhs);
4191 } else {
4192 __ CmpLeD(FTMP, rhs, lhs);
4193 }
4194 __ Mfc1(dst, FTMP);
4195 __ Andi(dst, dst, 1);
4196 break;
4197 default:
4198 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4199 UNREACHABLE();
4200 }
4201 }
4202}
4203
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004204bool InstructionCodeGeneratorMIPS64::MaterializeFpCompare(IfCondition cond,
4205 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004206 DataType::Type type,
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004207 LocationSummary* input_locations,
4208 FpuRegister dst) {
4209 FpuRegister lhs = input_locations->InAt(0).AsFpuRegister<FpuRegister>();
4210 FpuRegister rhs = input_locations->InAt(1).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004211 if (type == DataType::Type::kFloat32) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004212 switch (cond) {
4213 case kCondEQ:
4214 __ CmpEqS(dst, lhs, rhs);
4215 return false;
4216 case kCondNE:
4217 __ CmpEqS(dst, lhs, rhs);
4218 return true;
4219 case kCondLT:
4220 if (gt_bias) {
4221 __ CmpLtS(dst, lhs, rhs);
4222 } else {
4223 __ CmpUltS(dst, lhs, rhs);
4224 }
4225 return false;
4226 case kCondLE:
4227 if (gt_bias) {
4228 __ CmpLeS(dst, lhs, rhs);
4229 } else {
4230 __ CmpUleS(dst, lhs, rhs);
4231 }
4232 return false;
4233 case kCondGT:
4234 if (gt_bias) {
4235 __ CmpUltS(dst, rhs, lhs);
4236 } else {
4237 __ CmpLtS(dst, rhs, lhs);
4238 }
4239 return false;
4240 case kCondGE:
4241 if (gt_bias) {
4242 __ CmpUleS(dst, rhs, lhs);
4243 } else {
4244 __ CmpLeS(dst, rhs, lhs);
4245 }
4246 return false;
4247 default:
4248 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4249 UNREACHABLE();
4250 }
4251 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004252 DCHECK_EQ(type, DataType::Type::kFloat64);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004253 switch (cond) {
4254 case kCondEQ:
4255 __ CmpEqD(dst, lhs, rhs);
4256 return false;
4257 case kCondNE:
4258 __ CmpEqD(dst, lhs, rhs);
4259 return true;
4260 case kCondLT:
4261 if (gt_bias) {
4262 __ CmpLtD(dst, lhs, rhs);
4263 } else {
4264 __ CmpUltD(dst, lhs, rhs);
4265 }
4266 return false;
4267 case kCondLE:
4268 if (gt_bias) {
4269 __ CmpLeD(dst, lhs, rhs);
4270 } else {
4271 __ CmpUleD(dst, lhs, rhs);
4272 }
4273 return false;
4274 case kCondGT:
4275 if (gt_bias) {
4276 __ CmpUltD(dst, rhs, lhs);
4277 } else {
4278 __ CmpLtD(dst, rhs, lhs);
4279 }
4280 return false;
4281 case kCondGE:
4282 if (gt_bias) {
4283 __ CmpUleD(dst, rhs, lhs);
4284 } else {
4285 __ CmpLeD(dst, rhs, lhs);
4286 }
4287 return false;
4288 default:
4289 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4290 UNREACHABLE();
4291 }
4292 }
4293}
4294
Alexey Frunze299a9392015-12-08 16:08:02 -08004295void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond,
4296 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004297 DataType::Type type,
Alexey Frunze299a9392015-12-08 16:08:02 -08004298 LocationSummary* locations,
4299 Mips64Label* label) {
4300 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
4301 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004302 if (type == DataType::Type::kFloat32) {
Alexey Frunze299a9392015-12-08 16:08:02 -08004303 switch (cond) {
4304 case kCondEQ:
4305 __ CmpEqS(FTMP, lhs, rhs);
4306 __ Bc1nez(FTMP, label);
4307 break;
4308 case kCondNE:
4309 __ CmpEqS(FTMP, lhs, rhs);
4310 __ Bc1eqz(FTMP, label);
4311 break;
4312 case kCondLT:
4313 if (gt_bias) {
4314 __ CmpLtS(FTMP, lhs, rhs);
4315 } else {
4316 __ CmpUltS(FTMP, lhs, rhs);
4317 }
4318 __ Bc1nez(FTMP, label);
4319 break;
4320 case kCondLE:
4321 if (gt_bias) {
4322 __ CmpLeS(FTMP, lhs, rhs);
4323 } else {
4324 __ CmpUleS(FTMP, lhs, rhs);
4325 }
4326 __ Bc1nez(FTMP, label);
4327 break;
4328 case kCondGT:
4329 if (gt_bias) {
4330 __ CmpUltS(FTMP, rhs, lhs);
4331 } else {
4332 __ CmpLtS(FTMP, rhs, lhs);
4333 }
4334 __ Bc1nez(FTMP, label);
4335 break;
4336 case kCondGE:
4337 if (gt_bias) {
4338 __ CmpUleS(FTMP, rhs, lhs);
4339 } else {
4340 __ CmpLeS(FTMP, rhs, lhs);
4341 }
4342 __ Bc1nez(FTMP, label);
4343 break;
4344 default:
4345 LOG(FATAL) << "Unexpected non-floating-point condition";
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004346 UNREACHABLE();
Alexey Frunze299a9392015-12-08 16:08:02 -08004347 }
4348 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004349 DCHECK_EQ(type, DataType::Type::kFloat64);
Alexey Frunze299a9392015-12-08 16:08:02 -08004350 switch (cond) {
4351 case kCondEQ:
4352 __ CmpEqD(FTMP, lhs, rhs);
4353 __ Bc1nez(FTMP, label);
4354 break;
4355 case kCondNE:
4356 __ CmpEqD(FTMP, lhs, rhs);
4357 __ Bc1eqz(FTMP, label);
4358 break;
4359 case kCondLT:
4360 if (gt_bias) {
4361 __ CmpLtD(FTMP, lhs, rhs);
4362 } else {
4363 __ CmpUltD(FTMP, lhs, rhs);
4364 }
4365 __ Bc1nez(FTMP, label);
4366 break;
4367 case kCondLE:
4368 if (gt_bias) {
4369 __ CmpLeD(FTMP, lhs, rhs);
4370 } else {
4371 __ CmpUleD(FTMP, lhs, rhs);
4372 }
4373 __ Bc1nez(FTMP, label);
4374 break;
4375 case kCondGT:
4376 if (gt_bias) {
4377 __ CmpUltD(FTMP, rhs, lhs);
4378 } else {
4379 __ CmpLtD(FTMP, rhs, lhs);
4380 }
4381 __ Bc1nez(FTMP, label);
4382 break;
4383 case kCondGE:
4384 if (gt_bias) {
4385 __ CmpUleD(FTMP, rhs, lhs);
4386 } else {
4387 __ CmpLeD(FTMP, rhs, lhs);
4388 }
4389 __ Bc1nez(FTMP, label);
4390 break;
4391 default:
4392 LOG(FATAL) << "Unexpected non-floating-point condition";
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004393 UNREACHABLE();
Alexey Frunze299a9392015-12-08 16:08:02 -08004394 }
4395 }
4396}
4397
Alexey Frunze4dda3372015-06-01 18:31:49 -07004398void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00004399 size_t condition_input_index,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004400 Mips64Label* true_target,
4401 Mips64Label* false_target) {
David Brazdil0debae72015-11-12 18:37:00 +00004402 HInstruction* cond = instruction->InputAt(condition_input_index);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004403
David Brazdil0debae72015-11-12 18:37:00 +00004404 if (true_target == nullptr && false_target == nullptr) {
4405 // Nothing to do. The code always falls through.
4406 return;
4407 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00004408 // Constant condition, statically compared against "true" (integer value 1).
4409 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00004410 if (true_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004411 __ Bc(true_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004412 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004413 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00004414 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00004415 if (false_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004416 __ Bc(false_target);
David Brazdil0debae72015-11-12 18:37:00 +00004417 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004418 }
David Brazdil0debae72015-11-12 18:37:00 +00004419 return;
4420 }
4421
4422 // The following code generates these patterns:
4423 // (1) true_target == nullptr && false_target != nullptr
4424 // - opposite condition true => branch to false_target
4425 // (2) true_target != nullptr && false_target == nullptr
4426 // - condition true => branch to true_target
4427 // (3) true_target != nullptr && false_target != nullptr
4428 // - condition true => branch to true_target
4429 // - branch to false_target
4430 if (IsBooleanValueOrMaterializedCondition(cond)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07004431 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00004432 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004433 DCHECK(cond_val.IsRegister());
David Brazdil0debae72015-11-12 18:37:00 +00004434 if (true_target == nullptr) {
4435 __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target);
4436 } else {
4437 __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target);
4438 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004439 } else {
4440 // The condition instruction has not been materialized, use its inputs as
4441 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00004442 HCondition* condition = cond->AsCondition();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004443 DataType::Type type = condition->InputAt(0)->GetType();
Alexey Frunze299a9392015-12-08 16:08:02 -08004444 LocationSummary* locations = cond->GetLocations();
4445 IfCondition if_cond = condition->GetCondition();
4446 Mips64Label* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00004447
David Brazdil0debae72015-11-12 18:37:00 +00004448 if (true_target == nullptr) {
4449 if_cond = condition->GetOppositeCondition();
Alexey Frunze299a9392015-12-08 16:08:02 -08004450 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00004451 }
4452
Alexey Frunze299a9392015-12-08 16:08:02 -08004453 switch (type) {
4454 default:
Andreas Gampe3db70682018-12-26 15:12:03 -08004455 GenerateIntLongCompareAndBranch(if_cond, /* is64bit= */ false, locations, branch_target);
Alexey Frunze299a9392015-12-08 16:08:02 -08004456 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004457 case DataType::Type::kInt64:
Andreas Gampe3db70682018-12-26 15:12:03 -08004458 GenerateIntLongCompareAndBranch(if_cond, /* is64bit= */ true, locations, branch_target);
Alexey Frunze299a9392015-12-08 16:08:02 -08004459 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004460 case DataType::Type::kFloat32:
4461 case DataType::Type::kFloat64:
Alexey Frunze299a9392015-12-08 16:08:02 -08004462 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
4463 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07004464 }
4465 }
David Brazdil0debae72015-11-12 18:37:00 +00004466
4467 // If neither branch falls through (case 3), the conditional branch to `true_target`
4468 // was already emitted (case 2) and we need to emit a jump to `false_target`.
4469 if (true_target != nullptr && false_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004470 __ Bc(false_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004471 }
4472}
4473
4474void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004475 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00004476 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07004477 locations->SetInAt(0, Location::RequiresRegister());
4478 }
4479}
4480
4481void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00004482 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
4483 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004484 Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
David Brazdil0debae72015-11-12 18:37:00 +00004485 nullptr : codegen_->GetLabelOf(true_successor);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004486 Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
David Brazdil0debae72015-11-12 18:37:00 +00004487 nullptr : codegen_->GetLabelOf(false_successor);
Andreas Gampe3db70682018-12-26 15:12:03 -08004488 GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004489}
4490
4491void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004492 LocationSummary* locations = new (GetGraph()->GetAllocator())
Alexey Frunze4dda3372015-06-01 18:31:49 -07004493 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01004494 InvokeRuntimeCallingConvention calling_convention;
4495 RegisterSet caller_saves = RegisterSet::Empty();
4496 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4497 locations->SetCustomSlowPathCallerSaves(caller_saves);
David Brazdil0debae72015-11-12 18:37:00 +00004498 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07004499 locations->SetInAt(0, Location::RequiresRegister());
4500 }
4501}
4502
4503void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08004504 SlowPathCodeMIPS64* slow_path =
4505 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00004506 GenerateTestAndBranch(deoptimize,
Andreas Gampe3db70682018-12-26 15:12:03 -08004507 /* condition_input_index= */ 0,
David Brazdil0debae72015-11-12 18:37:00 +00004508 slow_path->GetEntryLabel(),
Andreas Gampe3db70682018-12-26 15:12:03 -08004509 /* false_target= */ nullptr);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004510}
4511
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004512// This function returns true if a conditional move can be generated for HSelect.
4513// Otherwise it returns false and HSelect must be implemented in terms of conditonal
4514// branches and regular moves.
4515//
4516// If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect.
4517//
4518// While determining feasibility of a conditional move and setting inputs/outputs
4519// are two distinct tasks, this function does both because they share quite a bit
4520// of common logic.
4521static bool CanMoveConditionally(HSelect* select, LocationSummary* locations_to_set) {
4522 bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition());
Andreas Gampe3db70682018-12-26 15:12:03 -08004523 HInstruction* cond = select->InputAt(/* i= */ 2);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004524 HCondition* condition = cond->AsCondition();
4525
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004526 DataType::Type cond_type =
4527 materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType();
4528 DataType::Type dst_type = select->GetType();
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004529
4530 HConstant* cst_true_value = select->GetTrueValue()->AsConstant();
4531 HConstant* cst_false_value = select->GetFalseValue()->AsConstant();
4532 bool is_true_value_zero_constant =
4533 (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern());
4534 bool is_false_value_zero_constant =
4535 (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern());
4536
4537 bool can_move_conditionally = false;
4538 bool use_const_for_false_in = false;
4539 bool use_const_for_true_in = false;
4540
4541 if (!cond->IsConstant()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004542 if (!DataType::IsFloatingPointType(cond_type)) {
4543 if (!DataType::IsFloatingPointType(dst_type)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004544 // Moving int/long on int/long condition.
4545 if (is_true_value_zero_constant) {
4546 // seleqz out_reg, false_reg, cond_reg
4547 can_move_conditionally = true;
4548 use_const_for_true_in = true;
4549 } else if (is_false_value_zero_constant) {
4550 // selnez out_reg, true_reg, cond_reg
4551 can_move_conditionally = true;
4552 use_const_for_false_in = true;
4553 } else if (materialized) {
4554 // Not materializing unmaterialized int conditions
4555 // to keep the instruction count low.
4556 // selnez AT, true_reg, cond_reg
4557 // seleqz TMP, false_reg, cond_reg
4558 // or out_reg, AT, TMP
4559 can_move_conditionally = true;
4560 }
4561 } else {
4562 // Moving float/double on int/long condition.
4563 if (materialized) {
4564 // Not materializing unmaterialized int conditions
4565 // to keep the instruction count low.
4566 can_move_conditionally = true;
4567 if (is_true_value_zero_constant) {
4568 // sltu TMP, ZERO, cond_reg
4569 // mtc1 TMP, temp_cond_reg
4570 // seleqz.fmt out_reg, false_reg, temp_cond_reg
4571 use_const_for_true_in = true;
4572 } else if (is_false_value_zero_constant) {
4573 // sltu TMP, ZERO, cond_reg
4574 // mtc1 TMP, temp_cond_reg
4575 // selnez.fmt out_reg, true_reg, temp_cond_reg
4576 use_const_for_false_in = true;
4577 } else {
4578 // sltu TMP, ZERO, cond_reg
4579 // mtc1 TMP, temp_cond_reg
4580 // sel.fmt temp_cond_reg, false_reg, true_reg
4581 // mov.fmt out_reg, temp_cond_reg
4582 }
4583 }
4584 }
4585 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004586 if (!DataType::IsFloatingPointType(dst_type)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004587 // Moving int/long on float/double condition.
4588 can_move_conditionally = true;
4589 if (is_true_value_zero_constant) {
4590 // mfc1 TMP, temp_cond_reg
4591 // seleqz out_reg, false_reg, TMP
4592 use_const_for_true_in = true;
4593 } else if (is_false_value_zero_constant) {
4594 // mfc1 TMP, temp_cond_reg
4595 // selnez out_reg, true_reg, TMP
4596 use_const_for_false_in = true;
4597 } else {
4598 // mfc1 TMP, temp_cond_reg
4599 // selnez AT, true_reg, TMP
4600 // seleqz TMP, false_reg, TMP
4601 // or out_reg, AT, TMP
4602 }
4603 } else {
4604 // Moving float/double on float/double condition.
4605 can_move_conditionally = true;
4606 if (is_true_value_zero_constant) {
4607 // seleqz.fmt out_reg, false_reg, temp_cond_reg
4608 use_const_for_true_in = true;
4609 } else if (is_false_value_zero_constant) {
4610 // selnez.fmt out_reg, true_reg, temp_cond_reg
4611 use_const_for_false_in = true;
4612 } else {
4613 // sel.fmt temp_cond_reg, false_reg, true_reg
4614 // mov.fmt out_reg, temp_cond_reg
4615 }
4616 }
4617 }
4618 }
4619
4620 if (can_move_conditionally) {
4621 DCHECK(!use_const_for_false_in || !use_const_for_true_in);
4622 } else {
4623 DCHECK(!use_const_for_false_in);
4624 DCHECK(!use_const_for_true_in);
4625 }
4626
4627 if (locations_to_set != nullptr) {
4628 if (use_const_for_false_in) {
4629 locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value));
4630 } else {
4631 locations_to_set->SetInAt(0,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004632 DataType::IsFloatingPointType(dst_type)
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004633 ? Location::RequiresFpuRegister()
4634 : Location::RequiresRegister());
4635 }
4636 if (use_const_for_true_in) {
4637 locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value));
4638 } else {
4639 locations_to_set->SetInAt(1,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004640 DataType::IsFloatingPointType(dst_type)
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004641 ? Location::RequiresFpuRegister()
4642 : Location::RequiresRegister());
4643 }
4644 if (materialized) {
4645 locations_to_set->SetInAt(2, Location::RequiresRegister());
4646 }
4647
4648 if (can_move_conditionally) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004649 locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type)
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004650 ? Location::RequiresFpuRegister()
4651 : Location::RequiresRegister());
4652 } else {
4653 locations_to_set->SetOut(Location::SameAsFirstInput());
4654 }
4655 }
4656
4657 return can_move_conditionally;
4658}
4659
4660
4661void InstructionCodeGeneratorMIPS64::GenConditionalMove(HSelect* select) {
4662 LocationSummary* locations = select->GetLocations();
4663 Location dst = locations->Out();
4664 Location false_src = locations->InAt(0);
4665 Location true_src = locations->InAt(1);
Andreas Gampe3db70682018-12-26 15:12:03 -08004666 HInstruction* cond = select->InputAt(/* i= */ 2);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004667 GpuRegister cond_reg = TMP;
4668 FpuRegister fcond_reg = FTMP;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004669 DataType::Type cond_type = DataType::Type::kInt32;
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004670 bool cond_inverted = false;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004671 DataType::Type dst_type = select->GetType();
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004672
4673 if (IsBooleanValueOrMaterializedCondition(cond)) {
Andreas Gampe3db70682018-12-26 15:12:03 -08004674 cond_reg = locations->InAt(/* at= */ 2).AsRegister<GpuRegister>();
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004675 } else {
4676 HCondition* condition = cond->AsCondition();
4677 LocationSummary* cond_locations = cond->GetLocations();
4678 IfCondition if_cond = condition->GetCondition();
4679 cond_type = condition->InputAt(0)->GetType();
4680 switch (cond_type) {
4681 default:
4682 cond_inverted = MaterializeIntLongCompare(if_cond,
Andreas Gampe3db70682018-12-26 15:12:03 -08004683 /* is64bit= */ false,
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004684 cond_locations,
4685 cond_reg);
4686 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004687 case DataType::Type::kInt64:
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004688 cond_inverted = MaterializeIntLongCompare(if_cond,
Andreas Gampe3db70682018-12-26 15:12:03 -08004689 /* is64bit= */ true,
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004690 cond_locations,
4691 cond_reg);
4692 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004693 case DataType::Type::kFloat32:
4694 case DataType::Type::kFloat64:
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004695 cond_inverted = MaterializeFpCompare(if_cond,
4696 condition->IsGtBias(),
4697 cond_type,
4698 cond_locations,
4699 fcond_reg);
4700 break;
4701 }
4702 }
4703
4704 if (true_src.IsConstant()) {
4705 DCHECK(true_src.GetConstant()->IsZeroBitPattern());
4706 }
4707 if (false_src.IsConstant()) {
4708 DCHECK(false_src.GetConstant()->IsZeroBitPattern());
4709 }
4710
4711 switch (dst_type) {
4712 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004713 if (DataType::IsFloatingPointType(cond_type)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004714 __ Mfc1(cond_reg, fcond_reg);
4715 }
4716 if (true_src.IsConstant()) {
4717 if (cond_inverted) {
4718 __ Selnez(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg);
4719 } else {
4720 __ Seleqz(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg);
4721 }
4722 } else if (false_src.IsConstant()) {
4723 if (cond_inverted) {
4724 __ Seleqz(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg);
4725 } else {
4726 __ Selnez(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg);
4727 }
4728 } else {
4729 DCHECK_NE(cond_reg, AT);
4730 if (cond_inverted) {
4731 __ Seleqz(AT, true_src.AsRegister<GpuRegister>(), cond_reg);
4732 __ Selnez(TMP, false_src.AsRegister<GpuRegister>(), cond_reg);
4733 } else {
4734 __ Selnez(AT, true_src.AsRegister<GpuRegister>(), cond_reg);
4735 __ Seleqz(TMP, false_src.AsRegister<GpuRegister>(), cond_reg);
4736 }
4737 __ Or(dst.AsRegister<GpuRegister>(), AT, TMP);
4738 }
4739 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004740 case DataType::Type::kFloat32: {
4741 if (!DataType::IsFloatingPointType(cond_type)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004742 // sel*.fmt tests bit 0 of the condition register, account for that.
4743 __ Sltu(TMP, ZERO, cond_reg);
4744 __ Mtc1(TMP, fcond_reg);
4745 }
4746 FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>();
4747 if (true_src.IsConstant()) {
4748 FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>();
4749 if (cond_inverted) {
4750 __ SelnezS(dst_reg, src_reg, fcond_reg);
4751 } else {
4752 __ SeleqzS(dst_reg, src_reg, fcond_reg);
4753 }
4754 } else if (false_src.IsConstant()) {
4755 FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>();
4756 if (cond_inverted) {
4757 __ SeleqzS(dst_reg, src_reg, fcond_reg);
4758 } else {
4759 __ SelnezS(dst_reg, src_reg, fcond_reg);
4760 }
4761 } else {
4762 if (cond_inverted) {
4763 __ SelS(fcond_reg,
4764 true_src.AsFpuRegister<FpuRegister>(),
4765 false_src.AsFpuRegister<FpuRegister>());
4766 } else {
4767 __ SelS(fcond_reg,
4768 false_src.AsFpuRegister<FpuRegister>(),
4769 true_src.AsFpuRegister<FpuRegister>());
4770 }
4771 __ MovS(dst_reg, fcond_reg);
4772 }
4773 break;
4774 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004775 case DataType::Type::kFloat64: {
4776 if (!DataType::IsFloatingPointType(cond_type)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004777 // sel*.fmt tests bit 0 of the condition register, account for that.
4778 __ Sltu(TMP, ZERO, cond_reg);
4779 __ Mtc1(TMP, fcond_reg);
4780 }
4781 FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>();
4782 if (true_src.IsConstant()) {
4783 FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>();
4784 if (cond_inverted) {
4785 __ SelnezD(dst_reg, src_reg, fcond_reg);
4786 } else {
4787 __ SeleqzD(dst_reg, src_reg, fcond_reg);
4788 }
4789 } else if (false_src.IsConstant()) {
4790 FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>();
4791 if (cond_inverted) {
4792 __ SeleqzD(dst_reg, src_reg, fcond_reg);
4793 } else {
4794 __ SelnezD(dst_reg, src_reg, fcond_reg);
4795 }
4796 } else {
4797 if (cond_inverted) {
4798 __ SelD(fcond_reg,
4799 true_src.AsFpuRegister<FpuRegister>(),
4800 false_src.AsFpuRegister<FpuRegister>());
4801 } else {
4802 __ SelD(fcond_reg,
4803 false_src.AsFpuRegister<FpuRegister>(),
4804 true_src.AsFpuRegister<FpuRegister>());
4805 }
4806 __ MovD(dst_reg, fcond_reg);
4807 }
4808 break;
4809 }
4810 }
4811}
4812
Goran Jakovljevicc6418422016-12-05 16:31:55 +01004813void LocationsBuilderMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004814 LocationSummary* locations = new (GetGraph()->GetAllocator())
Goran Jakovljevicc6418422016-12-05 16:31:55 +01004815 LocationSummary(flag, LocationSummary::kNoCall);
4816 locations->SetOut(Location::RequiresRegister());
Mingyao Yang063fc772016-08-02 11:02:54 -07004817}
4818
Goran Jakovljevicc6418422016-12-05 16:31:55 +01004819void InstructionCodeGeneratorMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
4820 __ LoadFromOffset(kLoadWord,
4821 flag->GetLocations()->Out().AsRegister<GpuRegister>(),
4822 SP,
4823 codegen_->GetStackOffsetOfShouldDeoptimizeFlag());
Mingyao Yang063fc772016-08-02 11:02:54 -07004824}
4825
David Brazdil74eb1b22015-12-14 11:44:01 +00004826void LocationsBuilderMIPS64::VisitSelect(HSelect* select) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004827 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004828 CanMoveConditionally(select, locations);
David Brazdil74eb1b22015-12-14 11:44:01 +00004829}
4830
4831void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) {
Andreas Gampe3db70682018-12-26 15:12:03 -08004832 if (CanMoveConditionally(select, /* locations_to_set= */ nullptr)) {
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004833 GenConditionalMove(select);
4834 } else {
4835 LocationSummary* locations = select->GetLocations();
4836 Mips64Label false_target;
4837 GenerateTestAndBranch(select,
Andreas Gampe3db70682018-12-26 15:12:03 -08004838 /* condition_input_index= */ 2,
4839 /* true_target= */ nullptr,
Goran Jakovljevic2dec9272017-08-02 11:41:26 +02004840 &false_target);
4841 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
4842 __ Bind(&false_target);
4843 }
David Brazdil74eb1b22015-12-14 11:44:01 +00004844}
4845
David Srbecky0cf44932015-12-09 14:09:59 +00004846void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01004847 new (GetGraph()->GetAllocator()) LocationSummary(info);
David Srbecky0cf44932015-12-09 14:09:59 +00004848}
4849
David Srbeckyd28f4a02016-03-14 17:14:24 +00004850void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) {
4851 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00004852}
4853
4854void CodeGeneratorMIPS64::GenerateNop() {
4855 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00004856}
4857
Alexey Frunze4dda3372015-06-01 18:31:49 -07004858void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction,
Alexey Frunze15958152017-02-09 19:08:30 -08004859 const FieldInfo& field_info) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004860 DataType::Type field_type = field_info.GetFieldType();
Alexey Frunze15958152017-02-09 19:08:30 -08004861 bool object_field_get_with_read_barrier =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004862 kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference);
Vladimir Markoca6fff82017-10-03 14:49:14 +01004863 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
Alexey Frunze15958152017-02-09 19:08:30 -08004864 instruction,
4865 object_field_get_with_read_barrier
4866 ? LocationSummary::kCallOnSlowPath
4867 : LocationSummary::kNoCall);
Alexey Frunzec61c0762017-04-10 13:54:23 -07004868 if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
4869 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
4870 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004871 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004872 if (DataType::IsFloatingPointType(instruction->GetType())) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07004873 locations->SetOut(Location::RequiresFpuRegister());
4874 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08004875 // The output overlaps in the case of an object field get with
4876 // read barriers enabled: we do not want the move to overwrite the
4877 // object's location, as we need it to emit the read barrier.
4878 locations->SetOut(Location::RequiresRegister(),
4879 object_field_get_with_read_barrier
4880 ? Location::kOutputOverlap
4881 : Location::kNoOutputOverlap);
4882 }
4883 if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
4884 // We need a temporary register for the read barrier marking slow
4885 // path in CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier.
Alexey Frunze4147fcc2017-06-17 19:57:27 -07004886 if (!kBakerReadBarrierThunksEnableForFields) {
4887 locations->AddTemp(Location::RequiresRegister());
4888 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004889 }
4890}
4891
4892void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction,
4893 const FieldInfo& field_info) {
Vladimir Marko61b92282017-10-11 13:23:17 +01004894 DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType()));
4895 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07004896 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08004897 Location obj_loc = locations->InAt(0);
4898 GpuRegister obj = obj_loc.AsRegister<GpuRegister>();
4899 Location dst_loc = locations->Out();
Alexey Frunze4dda3372015-06-01 18:31:49 -07004900 LoadOperandType load_type = kLoadUnsignedByte;
Alexey Frunze15958152017-02-09 19:08:30 -08004901 bool is_volatile = field_info.IsVolatile();
Alexey Frunzec061de12017-02-14 13:27:23 -08004902 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Tijana Jakovljevic57433862017-01-17 16:59:03 +01004903 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
4904
Alexey Frunze4dda3372015-06-01 18:31:49 -07004905 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004906 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01004907 case DataType::Type::kUint8:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004908 load_type = kLoadUnsignedByte;
4909 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004910 case DataType::Type::kInt8:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004911 load_type = kLoadSignedByte;
4912 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004913 case DataType::Type::kUint16:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004914 load_type = kLoadUnsignedHalfword;
4915 break;
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01004916 case DataType::Type::kInt16:
4917 load_type = kLoadSignedHalfword;
4918 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004919 case DataType::Type::kInt32:
4920 case DataType::Type::kFloat32:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004921 load_type = kLoadWord;
4922 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004923 case DataType::Type::kInt64:
4924 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004925 load_type = kLoadDoubleword;
4926 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004927 case DataType::Type::kReference:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004928 load_type = kLoadUnsignedWord;
4929 break;
Aart Bik66c158e2018-01-31 12:55:04 -08004930 case DataType::Type::kUint32:
4931 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004932 case DataType::Type::kVoid:
Alexey Frunze4dda3372015-06-01 18:31:49 -07004933 LOG(FATAL) << "Unreachable type " << type;
4934 UNREACHABLE();
4935 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004936 if (!DataType::IsFloatingPointType(type)) {
Alexey Frunze15958152017-02-09 19:08:30 -08004937 DCHECK(dst_loc.IsRegister());
4938 GpuRegister dst = dst_loc.AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004939 if (type == DataType::Type::kReference) {
Alexey Frunze15958152017-02-09 19:08:30 -08004940 // /* HeapReference<Object> */ dst = *(obj + offset)
4941 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07004942 Location temp_loc =
4943 kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0);
Alexey Frunze15958152017-02-09 19:08:30 -08004944 // Note that a potential implicit null check is handled in this
4945 // CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier call.
4946 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4947 dst_loc,
4948 obj,
4949 offset,
4950 temp_loc,
Andreas Gampe3db70682018-12-26 15:12:03 -08004951 /* needs_null_check= */ true);
Alexey Frunze15958152017-02-09 19:08:30 -08004952 if (is_volatile) {
4953 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4954 }
4955 } else {
4956 __ LoadFromOffset(kLoadUnsignedWord, dst, obj, offset, null_checker);
4957 if (is_volatile) {
4958 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4959 }
4960 // If read barriers are enabled, emit read barriers other than
4961 // Baker's using a slow path (and also unpoison the loaded
4962 // reference, if heap poisoning is enabled).
4963 codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset);
4964 }
4965 } else {
4966 __ LoadFromOffset(load_type, dst, obj, offset, null_checker);
4967 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004968 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08004969 DCHECK(dst_loc.IsFpuRegister());
4970 FpuRegister dst = dst_loc.AsFpuRegister<FpuRegister>();
Tijana Jakovljevic57433862017-01-17 16:59:03 +01004971 __ LoadFpuFromOffset(load_type, dst, obj, offset, null_checker);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004972 }
Alexey Frunzec061de12017-02-14 13:27:23 -08004973
Alexey Frunze15958152017-02-09 19:08:30 -08004974 // Memory barriers, in the case of references, are handled in the
4975 // previous switch statement.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004976 if (is_volatile && (type != DataType::Type::kReference)) {
Alexey Frunze15958152017-02-09 19:08:30 -08004977 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
Alexey Frunzec061de12017-02-14 13:27:23 -08004978 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004979}
4980
4981void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction,
4982 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
4983 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01004984 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004985 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004986 if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004987 locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07004988 } else {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004989 locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07004990 }
4991}
4992
4993void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction,
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01004994 const FieldInfo& field_info,
4995 bool value_can_be_null) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004996 DataType::Type type = field_info.GetFieldType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07004997 LocationSummary* locations = instruction->GetLocations();
4998 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01004999 Location value_location = locations->InAt(1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005000 StoreOperandType store_type = kStoreByte;
Alexey Frunze15958152017-02-09 19:08:30 -08005001 bool is_volatile = field_info.IsVolatile();
Alexey Frunzec061de12017-02-14 13:27:23 -08005002 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
5003 bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1));
Tijana Jakovljevic57433862017-01-17 16:59:03 +01005004 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
5005
Alexey Frunze4dda3372015-06-01 18:31:49 -07005006 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005007 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01005008 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005009 case DataType::Type::kInt8:
Alexey Frunze4dda3372015-06-01 18:31:49 -07005010 store_type = kStoreByte;
5011 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005012 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01005013 case DataType::Type::kInt16:
Alexey Frunze4dda3372015-06-01 18:31:49 -07005014 store_type = kStoreHalfword;
5015 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005016 case DataType::Type::kInt32:
5017 case DataType::Type::kFloat32:
5018 case DataType::Type::kReference:
Alexey Frunze4dda3372015-06-01 18:31:49 -07005019 store_type = kStoreWord;
5020 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005021 case DataType::Type::kInt64:
5022 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07005023 store_type = kStoreDoubleword;
5024 break;
Aart Bik66c158e2018-01-31 12:55:04 -08005025 case DataType::Type::kUint32:
5026 case DataType::Type::kUint64:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005027 case DataType::Type::kVoid:
Alexey Frunze4dda3372015-06-01 18:31:49 -07005028 LOG(FATAL) << "Unreachable type " << type;
5029 UNREACHABLE();
5030 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005031
Alexey Frunze15958152017-02-09 19:08:30 -08005032 if (is_volatile) {
5033 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
5034 }
5035
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01005036 if (value_location.IsConstant()) {
5037 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
5038 __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker);
5039 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005040 if (!DataType::IsFloatingPointType(type)) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01005041 DCHECK(value_location.IsRegister());
5042 GpuRegister src = value_location.AsRegister<GpuRegister>();
5043 if (kPoisonHeapReferences && needs_write_barrier) {
5044 // Note that in the case where `value` is a null reference,
5045 // we do not enter this block, as a null reference does not
5046 // need poisoning.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005047 DCHECK_EQ(type, DataType::Type::kReference);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01005048 __ PoisonHeapReference(TMP, src);
5049 __ StoreToOffset(store_type, TMP, obj, offset, null_checker);
5050 } else {
5051 __ StoreToOffset(store_type, src, obj, offset, null_checker);
5052 }
5053 } else {
5054 DCHECK(value_location.IsFpuRegister());
5055 FpuRegister src = value_location.AsFpuRegister<FpuRegister>();
5056 __ StoreFpuToOffset(store_type, src, obj, offset, null_checker);
5057 }
5058 }
Alexey Frunze15958152017-02-09 19:08:30 -08005059
Alexey Frunzec061de12017-02-14 13:27:23 -08005060 if (needs_write_barrier) {
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01005061 DCHECK(value_location.IsRegister());
5062 GpuRegister src = value_location.AsRegister<GpuRegister>();
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01005063 codegen_->MarkGCCard(obj, src, value_can_be_null);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005064 }
Alexey Frunze15958152017-02-09 19:08:30 -08005065
5066 if (is_volatile) {
5067 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
5068 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005069}
5070
5071void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
5072 HandleFieldGet(instruction, instruction->GetFieldInfo());
5073}
5074
5075void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
5076 HandleFieldGet(instruction, instruction->GetFieldInfo());
5077}
5078
5079void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
5080 HandleFieldSet(instruction, instruction->GetFieldInfo());
5081}
5082
5083void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01005084 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Alexey Frunze4dda3372015-06-01 18:31:49 -07005085}
5086
Alexey Frunze15958152017-02-09 19:08:30 -08005087void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadOneRegister(
5088 HInstruction* instruction,
5089 Location out,
5090 uint32_t offset,
5091 Location maybe_temp,
5092 ReadBarrierOption read_barrier_option) {
5093 GpuRegister out_reg = out.AsRegister<GpuRegister>();
5094 if (read_barrier_option == kWithReadBarrier) {
5095 CHECK(kEmitCompilerReadBarrier);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005096 if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) {
5097 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
5098 }
Alexey Frunze15958152017-02-09 19:08:30 -08005099 if (kUseBakerReadBarrier) {
5100 // Load with fast path based Baker's read barrier.
5101 // /* HeapReference<Object> */ out = *(out + offset)
5102 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
5103 out,
5104 out_reg,
5105 offset,
5106 maybe_temp,
Andreas Gampe3db70682018-12-26 15:12:03 -08005107 /* needs_null_check= */ false);
Alexey Frunze15958152017-02-09 19:08:30 -08005108 } else {
5109 // Load with slow path based read barrier.
5110 // Save the value of `out` into `maybe_temp` before overwriting it
5111 // in the following move operation, as we will need it for the
5112 // read barrier below.
5113 __ Move(maybe_temp.AsRegister<GpuRegister>(), out_reg);
5114 // /* HeapReference<Object> */ out = *(out + offset)
5115 __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset);
5116 codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset);
5117 }
5118 } else {
5119 // Plain load with no read barrier.
5120 // /* HeapReference<Object> */ out = *(out + offset)
5121 __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset);
5122 __ MaybeUnpoisonHeapReference(out_reg);
5123 }
5124}
5125
5126void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadTwoRegisters(
5127 HInstruction* instruction,
5128 Location out,
5129 Location obj,
5130 uint32_t offset,
5131 Location maybe_temp,
5132 ReadBarrierOption read_barrier_option) {
5133 GpuRegister out_reg = out.AsRegister<GpuRegister>();
5134 GpuRegister obj_reg = obj.AsRegister<GpuRegister>();
5135 if (read_barrier_option == kWithReadBarrier) {
5136 CHECK(kEmitCompilerReadBarrier);
5137 if (kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005138 if (!kBakerReadBarrierThunksEnableForFields) {
5139 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
5140 }
Alexey Frunze15958152017-02-09 19:08:30 -08005141 // Load with fast path based Baker's read barrier.
5142 // /* HeapReference<Object> */ out = *(obj + offset)
5143 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
5144 out,
5145 obj_reg,
5146 offset,
5147 maybe_temp,
Andreas Gampe3db70682018-12-26 15:12:03 -08005148 /* needs_null_check= */ false);
Alexey Frunze15958152017-02-09 19:08:30 -08005149 } else {
5150 // Load with slow path based read barrier.
5151 // /* HeapReference<Object> */ out = *(obj + offset)
5152 __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset);
5153 codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset);
5154 }
5155 } else {
5156 // Plain load with no read barrier.
5157 // /* HeapReference<Object> */ out = *(obj + offset)
5158 __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset);
5159 __ MaybeUnpoisonHeapReference(out_reg);
5160 }
5161}
5162
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005163static inline int GetBakerMarkThunkNumber(GpuRegister reg) {
5164 static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 20, "Expecting equal");
5165 if (reg >= V0 && reg <= T2) { // 13 consequtive regs.
5166 return reg - V0;
5167 } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs.
5168 return 13 + (reg - S2);
5169 } else if (reg == S8) { // One more.
5170 return 19;
5171 }
5172 LOG(FATAL) << "Unexpected register " << reg;
5173 UNREACHABLE();
5174}
5175
5176static inline int GetBakerMarkFieldArrayThunkDisplacement(GpuRegister reg, bool short_offset) {
5177 int num = GetBakerMarkThunkNumber(reg) +
5178 (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0);
5179 return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE;
5180}
5181
5182static inline int GetBakerMarkGcRootThunkDisplacement(GpuRegister reg) {
5183 return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE +
5184 BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET;
5185}
5186
5187void InstructionCodeGeneratorMIPS64::GenerateGcRootFieldLoad(HInstruction* instruction,
5188 Location root,
5189 GpuRegister obj,
5190 uint32_t offset,
5191 ReadBarrierOption read_barrier_option,
5192 Mips64Label* label_low) {
5193 if (label_low != nullptr) {
5194 DCHECK_EQ(offset, 0x5678u);
5195 }
Alexey Frunzef63f5692016-12-13 17:43:11 -08005196 GpuRegister root_reg = root.AsRegister<GpuRegister>();
Alexey Frunze15958152017-02-09 19:08:30 -08005197 if (read_barrier_option == kWithReadBarrier) {
5198 DCHECK(kEmitCompilerReadBarrier);
5199 if (kUseBakerReadBarrier) {
5200 // Fast path implementation of art::ReadBarrier::BarrierForRoot when
5201 // Baker's read barrier are used:
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005202 if (kBakerReadBarrierThunksEnableForGcRoots) {
5203 // Note that we do not actually check the value of `GetIsGcMarking()`
5204 // to decide whether to mark the loaded GC root or not. Instead, we
5205 // load into `temp` (T9) the read barrier mark introspection entrypoint.
5206 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
5207 // vice versa.
5208 //
5209 // We use thunks for the slow path. That thunk checks the reference
5210 // and jumps to the entrypoint if needed.
5211 //
5212 // temp = Thread::Current()->pReadBarrierMarkReg00
5213 // // AKA &art_quick_read_barrier_mark_introspection.
5214 // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load.
5215 // if (temp != nullptr) {
5216 // temp = &gc_root_thunk<root_reg>
5217 // root = temp(root)
5218 // }
Alexey Frunze15958152017-02-09 19:08:30 -08005219
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005220 const int32_t entry_point_offset =
5221 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0);
5222 const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg);
5223 int16_t offset_low = Low16Bits(offset);
5224 int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign
5225 // extension in lwu.
5226 bool short_offset = IsInt<16>(static_cast<int32_t>(offset));
5227 GpuRegister base = short_offset ? obj : TMP;
5228 // Loading the entrypoint does not require a load acquire since it is only changed when
5229 // threads are suspended or running a checkpoint.
5230 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
5231 if (!short_offset) {
5232 DCHECK(!label_low);
5233 __ Daui(base, obj, offset_high);
5234 }
Alexey Frunze0cab6562017-07-25 15:19:36 -07005235 Mips64Label skip_call;
Andreas Gampe3db70682018-12-26 15:12:03 -08005236 __ Beqz(T9, &skip_call, /* is_bare= */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005237 if (label_low != nullptr) {
5238 DCHECK(short_offset);
5239 __ Bind(label_low);
5240 }
5241 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
5242 __ LoadFromOffset(kLoadUnsignedWord, root_reg, base, offset_low); // Single instruction
5243 // in delay slot.
5244 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07005245 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005246 } else {
5247 // Note that we do not actually check the value of `GetIsGcMarking()`
5248 // to decide whether to mark the loaded GC root or not. Instead, we
5249 // load into `temp` (T9) the read barrier mark entry point corresponding
5250 // to register `root`. If `temp` is null, it means that `GetIsGcMarking()`
5251 // is false, and vice versa.
5252 //
5253 // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load.
5254 // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg()
5255 // if (temp != null) {
5256 // root = temp(root)
5257 // }
Alexey Frunze15958152017-02-09 19:08:30 -08005258
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005259 if (label_low != nullptr) {
5260 __ Bind(label_low);
5261 }
5262 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
5263 __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset);
5264 static_assert(
5265 sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>),
5266 "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> "
5267 "have different sizes.");
5268 static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t),
5269 "art::mirror::CompressedReference<mirror::Object> and int32_t "
5270 "have different sizes.");
Alexey Frunze15958152017-02-09 19:08:30 -08005271
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005272 // Slow path marking the GC root `root`.
5273 Location temp = Location::RegisterLocation(T9);
5274 SlowPathCodeMIPS64* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01005275 new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64(
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005276 instruction,
5277 root,
5278 /*entrypoint*/ temp);
5279 codegen_->AddSlowPath(slow_path);
5280
5281 const int32_t entry_point_offset =
5282 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(root.reg() - 1);
5283 // Loading the entrypoint does not require a load acquire since it is only changed when
5284 // threads are suspended or running a checkpoint.
5285 __ LoadFromOffset(kLoadDoubleword, temp.AsRegister<GpuRegister>(), TR, entry_point_offset);
5286 __ Bnezc(temp.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
5287 __ Bind(slow_path->GetExitLabel());
5288 }
Alexey Frunze15958152017-02-09 19:08:30 -08005289 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005290 if (label_low != nullptr) {
5291 __ Bind(label_low);
5292 }
Alexey Frunze15958152017-02-09 19:08:30 -08005293 // GC root loaded through a slow path for read barriers other
5294 // than Baker's.
5295 // /* GcRoot<mirror::Object>* */ root = obj + offset
5296 __ Daddiu64(root_reg, obj, static_cast<int32_t>(offset));
5297 // /* mirror::Object* */ root = root->Read()
5298 codegen_->GenerateReadBarrierForRootSlow(instruction, root, root);
5299 }
Alexey Frunzef63f5692016-12-13 17:43:11 -08005300 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005301 if (label_low != nullptr) {
5302 __ Bind(label_low);
5303 }
Alexey Frunzef63f5692016-12-13 17:43:11 -08005304 // Plain GC root load with no read barrier.
5305 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
5306 __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset);
5307 // Note that GC roots are not affected by heap poisoning, thus we
5308 // do not have to unpoison `root_reg` here.
5309 }
5310}
5311
Alexey Frunze15958152017-02-09 19:08:30 -08005312void CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
5313 Location ref,
5314 GpuRegister obj,
5315 uint32_t offset,
5316 Location temp,
5317 bool needs_null_check) {
5318 DCHECK(kEmitCompilerReadBarrier);
5319 DCHECK(kUseBakerReadBarrier);
5320
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005321 if (kBakerReadBarrierThunksEnableForFields) {
5322 // Note that we do not actually check the value of `GetIsGcMarking()`
5323 // to decide whether to mark the loaded reference or not. Instead, we
5324 // load into `temp` (T9) the read barrier mark introspection entrypoint.
5325 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
5326 // vice versa.
5327 //
5328 // We use thunks for the slow path. That thunk checks the reference
5329 // and jumps to the entrypoint if needed. If the holder is not gray,
5330 // it issues a load-load memory barrier and returns to the original
5331 // reference load.
5332 //
5333 // temp = Thread::Current()->pReadBarrierMarkReg00
5334 // // AKA &art_quick_read_barrier_mark_introspection.
5335 // if (temp != nullptr) {
5336 // temp = &field_array_thunk<holder_reg>
5337 // temp()
5338 // }
5339 // not_gray_return_address:
5340 // // If the offset is too large to fit into the lw instruction, we
5341 // // use an adjusted base register (TMP) here. This register
5342 // // receives bits 16 ... 31 of the offset before the thunk invocation
5343 // // and the thunk benefits from it.
5344 // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load.
5345 // gray_return_address:
5346
5347 DCHECK(temp.IsInvalid());
5348 bool short_offset = IsInt<16>(static_cast<int32_t>(offset));
5349 const int32_t entry_point_offset =
5350 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0);
5351 // There may have or may have not been a null check if the field offset is smaller than
5352 // the page size.
5353 // There must've been a null check in case it's actually a load from an array.
5354 // We will, however, perform an explicit null check in the thunk as it's easier to
5355 // do it than not.
5356 if (instruction->IsArrayGet()) {
5357 DCHECK(!needs_null_check);
5358 }
5359 const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset);
5360 // Loading the entrypoint does not require a load acquire since it is only changed when
5361 // threads are suspended or running a checkpoint.
5362 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
5363 GpuRegister ref_reg = ref.AsRegister<GpuRegister>();
Alexey Frunze0cab6562017-07-25 15:19:36 -07005364 Mips64Label skip_call;
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005365 if (short_offset) {
Andreas Gampe3db70682018-12-26 15:12:03 -08005366 __ Beqzc(T9, &skip_call, /* is_bare= */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005367 __ Nop(); // In forbidden slot.
5368 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07005369 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005370 // /* HeapReference<Object> */ ref = *(obj + offset)
5371 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); // Single instruction.
5372 } else {
5373 int16_t offset_low = Low16Bits(offset);
5374 int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lwu.
Andreas Gampe3db70682018-12-26 15:12:03 -08005375 __ Beqz(T9, &skip_call, /* is_bare= */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005376 __ Daui(TMP, obj, offset_high); // In delay slot.
5377 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07005378 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005379 // /* HeapReference<Object> */ ref = *(obj + offset)
5380 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset_low); // Single instruction.
5381 }
5382 if (needs_null_check) {
5383 MaybeRecordImplicitNullCheck(instruction);
5384 }
5385 __ MaybeUnpoisonHeapReference(ref_reg);
5386 return;
5387 }
5388
Alexey Frunze15958152017-02-09 19:08:30 -08005389 // /* HeapReference<Object> */ ref = *(obj + offset)
5390 Location no_index = Location::NoLocation();
5391 ScaleFactor no_scale_factor = TIMES_1;
5392 GenerateReferenceLoadWithBakerReadBarrier(instruction,
5393 ref,
5394 obj,
5395 offset,
5396 no_index,
5397 no_scale_factor,
5398 temp,
5399 needs_null_check);
5400}
5401
5402void CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
5403 Location ref,
5404 GpuRegister obj,
5405 uint32_t data_offset,
5406 Location index,
5407 Location temp,
5408 bool needs_null_check) {
5409 DCHECK(kEmitCompilerReadBarrier);
5410 DCHECK(kUseBakerReadBarrier);
5411
5412 static_assert(
5413 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
5414 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005415 ScaleFactor scale_factor = TIMES_4;
5416
5417 if (kBakerReadBarrierThunksEnableForArrays) {
5418 // Note that we do not actually check the value of `GetIsGcMarking()`
5419 // to decide whether to mark the loaded reference or not. Instead, we
5420 // load into `temp` (T9) the read barrier mark introspection entrypoint.
5421 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
5422 // vice versa.
5423 //
5424 // We use thunks for the slow path. That thunk checks the reference
5425 // and jumps to the entrypoint if needed. If the holder is not gray,
5426 // it issues a load-load memory barrier and returns to the original
5427 // reference load.
5428 //
5429 // temp = Thread::Current()->pReadBarrierMarkReg00
5430 // // AKA &art_quick_read_barrier_mark_introspection.
5431 // if (temp != nullptr) {
5432 // temp = &field_array_thunk<holder_reg>
5433 // temp()
5434 // }
5435 // not_gray_return_address:
5436 // // The element address is pre-calculated in the TMP register before the
5437 // // thunk invocation and the thunk benefits from it.
5438 // HeapReference<mirror::Object> reference = data[index]; // Original reference load.
5439 // gray_return_address:
5440
5441 DCHECK(temp.IsInvalid());
5442 DCHECK(index.IsValid());
5443 const int32_t entry_point_offset =
5444 Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0);
5445 // We will not do the explicit null check in the thunk as some form of a null check
5446 // must've been done earlier.
5447 DCHECK(!needs_null_check);
Andreas Gampe3db70682018-12-26 15:12:03 -08005448 const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset= */ false);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005449 // Loading the entrypoint does not require a load acquire since it is only changed when
5450 // threads are suspended or running a checkpoint.
5451 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
Alexey Frunze0cab6562017-07-25 15:19:36 -07005452 Mips64Label skip_call;
Andreas Gampe3db70682018-12-26 15:12:03 -08005453 __ Beqz(T9, &skip_call, /* is_bare= */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005454 GpuRegister ref_reg = ref.AsRegister<GpuRegister>();
5455 GpuRegister index_reg = index.AsRegister<GpuRegister>();
5456 __ Dlsa(TMP, index_reg, obj, scale_factor); // In delay slot.
5457 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07005458 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07005459 // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor))
5460 DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset;
5461 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, data_offset); // Single instruction.
5462 __ MaybeUnpoisonHeapReference(ref_reg);
5463 return;
5464 }
5465
Alexey Frunze15958152017-02-09 19:08:30 -08005466 // /* HeapReference<Object> */ ref =
5467 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
Alexey Frunze15958152017-02-09 19:08:30 -08005468 GenerateReferenceLoadWithBakerReadBarrier(instruction,
5469 ref,
5470 obj,
5471 data_offset,
5472 index,
5473 scale_factor,
5474 temp,
5475 needs_null_check);
5476}
5477
5478void CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
5479 Location ref,
5480 GpuRegister obj,
5481 uint32_t offset,
5482 Location index,
5483 ScaleFactor scale_factor,
5484 Location temp,
5485 bool needs_null_check,
5486 bool always_update_field) {
5487 DCHECK(kEmitCompilerReadBarrier);
5488 DCHECK(kUseBakerReadBarrier);
5489
5490 // In slow path based read barriers, the read barrier call is
5491 // inserted after the original load. However, in fast path based
5492 // Baker's read barriers, we need to perform the load of
5493 // mirror::Object::monitor_ *before* the original reference load.
5494 // This load-load ordering is required by the read barrier.
5495 // The fast path/slow path (for Baker's algorithm) should look like:
5496 //
5497 // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState();
5498 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
5499 // HeapReference<Object> ref = *src; // Original reference load.
5500 // bool is_gray = (rb_state == ReadBarrier::GrayState());
5501 // if (is_gray) {
5502 // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path.
5503 // }
5504 //
5505 // Note: the original implementation in ReadBarrier::Barrier is
5506 // slightly more complex as it performs additional checks that we do
5507 // not do here for performance reasons.
5508
5509 GpuRegister ref_reg = ref.AsRegister<GpuRegister>();
5510 GpuRegister temp_reg = temp.AsRegister<GpuRegister>();
5511 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
5512
5513 // /* int32_t */ monitor = obj->monitor_
5514 __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset);
5515 if (needs_null_check) {
5516 MaybeRecordImplicitNullCheck(instruction);
5517 }
5518 // /* LockWord */ lock_word = LockWord(monitor)
5519 static_assert(sizeof(LockWord) == sizeof(int32_t),
5520 "art::LockWord and int32_t have different sizes.");
5521
5522 __ Sync(0); // Barrier to prevent load-load reordering.
5523
5524 // The actual reference load.
5525 if (index.IsValid()) {
5526 // Load types involving an "index": ArrayGet,
5527 // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject
5528 // intrinsics.
5529 // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor))
5530 if (index.IsConstant()) {
5531 size_t computed_offset =
5532 (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset;
5533 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, computed_offset);
5534 } else {
5535 GpuRegister index_reg = index.AsRegister<GpuRegister>();
Chris Larsencd0295d2017-03-31 15:26:54 -07005536 if (scale_factor == TIMES_1) {
5537 __ Daddu(TMP, index_reg, obj);
5538 } else {
5539 __ Dlsa(TMP, index_reg, obj, scale_factor);
5540 }
Alexey Frunze15958152017-02-09 19:08:30 -08005541 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset);
5542 }
5543 } else {
5544 // /* HeapReference<Object> */ ref = *(obj + offset)
5545 __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset);
5546 }
5547
5548 // Object* ref = ref_addr->AsMirrorPtr()
5549 __ MaybeUnpoisonHeapReference(ref_reg);
5550
5551 // Slow path marking the object `ref` when it is gray.
5552 SlowPathCodeMIPS64* slow_path;
5553 if (always_update_field) {
5554 // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 only supports address
5555 // of the form `obj + field_offset`, where `obj` is a register and
5556 // `field_offset` is a register. Thus `offset` and `scale_factor`
5557 // above are expected to be null in this code path.
5558 DCHECK_EQ(offset, 0u);
5559 DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1);
Vladimir Marko174b2e22017-10-12 13:34:49 +01005560 slow_path = new (GetScopedAllocator())
Alexey Frunze15958152017-02-09 19:08:30 -08005561 ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(instruction,
5562 ref,
5563 obj,
Andreas Gampe3db70682018-12-26 15:12:03 -08005564 /* field_offset= */ index,
Alexey Frunze15958152017-02-09 19:08:30 -08005565 temp_reg);
5566 } else {
Vladimir Marko174b2e22017-10-12 13:34:49 +01005567 slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64(instruction, ref);
Alexey Frunze15958152017-02-09 19:08:30 -08005568 }
5569 AddSlowPath(slow_path);
5570
5571 // if (rb_state == ReadBarrier::GrayState())
5572 // ref = ReadBarrier::Mark(ref);
5573 // Given the numeric representation, it's enough to check the low bit of the
5574 // rb_state. We do that by shifting the bit into the sign bit (31) and
5575 // performing a branch on less than zero.
Roland Levillain14e5a292018-06-28 12:00:56 +01005576 static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0");
Alexey Frunze15958152017-02-09 19:08:30 -08005577 static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1");
5578 static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size");
5579 __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift);
5580 __ Bltzc(temp_reg, slow_path->GetEntryLabel());
5581 __ Bind(slow_path->GetExitLabel());
5582}
5583
5584void CodeGeneratorMIPS64::GenerateReadBarrierSlow(HInstruction* instruction,
5585 Location out,
5586 Location ref,
5587 Location obj,
5588 uint32_t offset,
5589 Location index) {
5590 DCHECK(kEmitCompilerReadBarrier);
5591
5592 // Insert a slow path based read barrier *after* the reference load.
5593 //
5594 // If heap poisoning is enabled, the unpoisoning of the loaded
5595 // reference will be carried out by the runtime within the slow
5596 // path.
5597 //
5598 // Note that `ref` currently does not get unpoisoned (when heap
5599 // poisoning is enabled), which is alright as the `ref` argument is
5600 // not used by the artReadBarrierSlow entry point.
5601 //
5602 // TODO: Unpoison `ref` when it is used by artReadBarrierSlow.
Vladimir Marko174b2e22017-10-12 13:34:49 +01005603 SlowPathCodeMIPS64* slow_path = new (GetScopedAllocator())
Alexey Frunze15958152017-02-09 19:08:30 -08005604 ReadBarrierForHeapReferenceSlowPathMIPS64(instruction, out, ref, obj, offset, index);
5605 AddSlowPath(slow_path);
5606
5607 __ Bc(slow_path->GetEntryLabel());
5608 __ Bind(slow_path->GetExitLabel());
5609}
5610
5611void CodeGeneratorMIPS64::MaybeGenerateReadBarrierSlow(HInstruction* instruction,
5612 Location out,
5613 Location ref,
5614 Location obj,
5615 uint32_t offset,
5616 Location index) {
5617 if (kEmitCompilerReadBarrier) {
5618 // Baker's read barriers shall be handled by the fast path
5619 // (CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier).
5620 DCHECK(!kUseBakerReadBarrier);
5621 // If heap poisoning is enabled, unpoisoning will be taken care of
5622 // by the runtime within the slow path.
5623 GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index);
5624 } else if (kPoisonHeapReferences) {
5625 __ UnpoisonHeapReference(out.AsRegister<GpuRegister>());
5626 }
5627}
5628
5629void CodeGeneratorMIPS64::GenerateReadBarrierForRootSlow(HInstruction* instruction,
5630 Location out,
5631 Location root) {
5632 DCHECK(kEmitCompilerReadBarrier);
5633
5634 // Insert a slow path based read barrier *after* the GC root load.
5635 //
5636 // Note that GC roots are not affected by heap poisoning, so we do
5637 // not need to do anything special for this here.
5638 SlowPathCodeMIPS64* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01005639 new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS64(instruction, out, root);
Alexey Frunze15958152017-02-09 19:08:30 -08005640 AddSlowPath(slow_path);
5641
5642 __ Bc(slow_path->GetEntryLabel());
5643 __ Bind(slow_path->GetExitLabel());
5644}
5645
Alexey Frunze4dda3372015-06-01 18:31:49 -07005646void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005647 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
5648 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunzec61c0762017-04-10 13:54:23 -07005649 bool baker_read_barrier_slow_path = false;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005650 switch (type_check_kind) {
5651 case TypeCheckKind::kExactCheck:
5652 case TypeCheckKind::kAbstractClassCheck:
5653 case TypeCheckKind::kClassHierarchyCheck:
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005654 case TypeCheckKind::kArrayObjectCheck: {
5655 bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction);
5656 call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall;
5657 baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005658 break;
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005659 }
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005660 case TypeCheckKind::kArrayCheck:
5661 case TypeCheckKind::kUnresolvedCheck:
5662 case TypeCheckKind::kInterfaceCheck:
5663 call_kind = LocationSummary::kCallOnSlowPath;
5664 break;
Vladimir Marko175e7862018-03-27 09:03:13 +00005665 case TypeCheckKind::kBitstringCheck:
5666 break;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005667 }
5668
Vladimir Markoca6fff82017-10-03 14:49:14 +01005669 LocationSummary* locations =
5670 new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind);
Alexey Frunzec61c0762017-04-10 13:54:23 -07005671 if (baker_read_barrier_slow_path) {
5672 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
5673 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005674 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko175e7862018-03-27 09:03:13 +00005675 if (type_check_kind == TypeCheckKind::kBitstringCheck) {
5676 locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant()));
5677 locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant()));
5678 locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant()));
5679 } else {
5680 locations->SetInAt(1, Location::RequiresRegister());
5681 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005682 // The output does overlap inputs.
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01005683 // Note that TypeCheckSlowPathMIPS64 uses this register too.
Alexey Frunze4dda3372015-06-01 18:31:49 -07005684 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexey Frunze15958152017-02-09 19:08:30 -08005685 locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind));
Alexey Frunze4dda3372015-06-01 18:31:49 -07005686}
5687
5688void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005689 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunze4dda3372015-06-01 18:31:49 -07005690 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08005691 Location obj_loc = locations->InAt(0);
5692 GpuRegister obj = obj_loc.AsRegister<GpuRegister>();
Vladimir Marko175e7862018-03-27 09:03:13 +00005693 Location cls = locations->InAt(1);
Alexey Frunze15958152017-02-09 19:08:30 -08005694 Location out_loc = locations->Out();
5695 GpuRegister out = out_loc.AsRegister<GpuRegister>();
5696 const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind);
5697 DCHECK_LE(num_temps, 1u);
5698 Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation();
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005699 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
5700 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5701 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5702 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07005703 Mips64Label done;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005704 SlowPathCodeMIPS64* slow_path = nullptr;
Alexey Frunze4dda3372015-06-01 18:31:49 -07005705
5706 // Return 0 if `obj` is null.
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005707 // Avoid this check if we know `obj` is not null.
5708 if (instruction->MustDoNullCheck()) {
5709 __ Move(out, ZERO);
5710 __ Beqzc(obj, &done);
5711 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005712
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005713 switch (type_check_kind) {
5714 case TypeCheckKind::kExactCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005715 ReadBarrierOption read_barrier_option =
5716 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005717 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08005718 GenerateReferenceLoadTwoRegisters(instruction,
5719 out_loc,
5720 obj_loc,
5721 class_offset,
5722 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005723 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005724 // Classes must be equal for the instanceof to succeed.
Vladimir Marko175e7862018-03-27 09:03:13 +00005725 __ Xor(out, out, cls.AsRegister<GpuRegister>());
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005726 __ Sltiu(out, out, 1);
5727 break;
5728 }
5729
5730 case TypeCheckKind::kAbstractClassCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005731 ReadBarrierOption read_barrier_option =
5732 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005733 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08005734 GenerateReferenceLoadTwoRegisters(instruction,
5735 out_loc,
5736 obj_loc,
5737 class_offset,
5738 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005739 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005740 // If the class is abstract, we eagerly fetch the super class of the
5741 // object to avoid doing a comparison we know will fail.
5742 Mips64Label loop;
5743 __ Bind(&loop);
5744 // /* HeapReference<Class> */ out = out->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08005745 GenerateReferenceLoadOneRegister(instruction,
5746 out_loc,
5747 super_offset,
5748 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005749 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005750 // If `out` is null, we use it for the result, and jump to `done`.
5751 __ Beqzc(out, &done);
Vladimir Marko175e7862018-03-27 09:03:13 +00005752 __ Bnec(out, cls.AsRegister<GpuRegister>(), &loop);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005753 __ LoadConst32(out, 1);
5754 break;
5755 }
5756
5757 case TypeCheckKind::kClassHierarchyCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005758 ReadBarrierOption read_barrier_option =
5759 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005760 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08005761 GenerateReferenceLoadTwoRegisters(instruction,
5762 out_loc,
5763 obj_loc,
5764 class_offset,
5765 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005766 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005767 // Walk over the class hierarchy to find a match.
5768 Mips64Label loop, success;
5769 __ Bind(&loop);
Vladimir Marko175e7862018-03-27 09:03:13 +00005770 __ Beqc(out, cls.AsRegister<GpuRegister>(), &success);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005771 // /* HeapReference<Class> */ out = out->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08005772 GenerateReferenceLoadOneRegister(instruction,
5773 out_loc,
5774 super_offset,
5775 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005776 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005777 __ Bnezc(out, &loop);
5778 // If `out` is null, we use it for the result, and jump to `done`.
5779 __ Bc(&done);
5780 __ Bind(&success);
5781 __ LoadConst32(out, 1);
5782 break;
5783 }
5784
5785 case TypeCheckKind::kArrayObjectCheck: {
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005786 ReadBarrierOption read_barrier_option =
5787 CodeGenerator::ReadBarrierOptionForInstanceOf(instruction);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005788 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08005789 GenerateReferenceLoadTwoRegisters(instruction,
5790 out_loc,
5791 obj_loc,
5792 class_offset,
5793 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005794 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005795 // Do an exact check.
5796 Mips64Label success;
Vladimir Marko175e7862018-03-27 09:03:13 +00005797 __ Beqc(out, cls.AsRegister<GpuRegister>(), &success);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005798 // Otherwise, we need to check that the object's class is a non-primitive array.
5799 // /* HeapReference<Class> */ out = out->component_type_
Alexey Frunze15958152017-02-09 19:08:30 -08005800 GenerateReferenceLoadOneRegister(instruction,
5801 out_loc,
5802 component_offset,
5803 maybe_temp_loc,
Alexey Frunzedfc30af2018-01-24 16:25:10 -08005804 read_barrier_option);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005805 // If `out` is null, we use it for the result, and jump to `done`.
5806 __ Beqzc(out, &done);
5807 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
5808 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
5809 __ Sltiu(out, out, 1);
5810 __ Bc(&done);
5811 __ Bind(&success);
5812 __ LoadConst32(out, 1);
5813 break;
5814 }
5815
5816 case TypeCheckKind::kArrayCheck: {
5817 // No read barrier since the slow path will retry upon failure.
5818 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08005819 GenerateReferenceLoadTwoRegisters(instruction,
5820 out_loc,
5821 obj_loc,
5822 class_offset,
5823 maybe_temp_loc,
5824 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005825 DCHECK(locations->OnlyCallsOnSlowPath());
Vladimir Marko174b2e22017-10-12 13:34:49 +01005826 slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64(
Andreas Gampe3db70682018-12-26 15:12:03 -08005827 instruction, /* is_fatal= */ false);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005828 codegen_->AddSlowPath(slow_path);
Vladimir Marko175e7862018-03-27 09:03:13 +00005829 __ Bnec(out, cls.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005830 __ LoadConst32(out, 1);
5831 break;
5832 }
5833
5834 case TypeCheckKind::kUnresolvedCheck:
5835 case TypeCheckKind::kInterfaceCheck: {
5836 // Note that we indeed only call on slow path, but we always go
5837 // into the slow path for the unresolved and interface check
5838 // cases.
5839 //
5840 // We cannot directly call the InstanceofNonTrivial runtime
5841 // entry point without resorting to a type checking slow path
5842 // here (i.e. by calling InvokeRuntime directly), as it would
5843 // require to assign fixed registers for the inputs of this
5844 // HInstanceOf instruction (following the runtime calling
5845 // convention), which might be cluttered by the potential first
5846 // read barrier emission at the beginning of this method.
5847 //
5848 // TODO: Introduce a new runtime entry point taking the object
5849 // to test (instead of its class) as argument, and let it deal
5850 // with the read barrier issues. This will let us refactor this
5851 // case of the `switch` code as it was previously (with a direct
5852 // call to the runtime not using a type checking slow path).
5853 // This should also be beneficial for the other cases above.
5854 DCHECK(locations->OnlyCallsOnSlowPath());
Vladimir Marko174b2e22017-10-12 13:34:49 +01005855 slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64(
Andreas Gampe3db70682018-12-26 15:12:03 -08005856 instruction, /* is_fatal= */ false);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005857 codegen_->AddSlowPath(slow_path);
5858 __ Bc(slow_path->GetEntryLabel());
5859 break;
5860 }
Vladimir Marko175e7862018-03-27 09:03:13 +00005861
5862 case TypeCheckKind::kBitstringCheck: {
5863 // /* HeapReference<Class> */ temp = obj->klass_
5864 GenerateReferenceLoadTwoRegisters(instruction,
5865 out_loc,
5866 obj_loc,
5867 class_offset,
5868 maybe_temp_loc,
5869 kWithoutReadBarrier);
5870
5871 GenerateBitstringTypeCheckCompare(instruction, out);
5872 __ Sltiu(out, out, 1);
5873 break;
5874 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005875 }
5876
5877 __ Bind(&done);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08005878
5879 if (slow_path != nullptr) {
5880 __ Bind(slow_path->GetExitLabel());
5881 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07005882}
5883
5884void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01005885 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005886 locations->SetOut(Location::ConstantLocation(constant));
5887}
5888
5889void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
5890 // Will be generated at use site.
5891}
5892
5893void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01005894 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005895 locations->SetOut(Location::ConstantLocation(constant));
5896}
5897
5898void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
5899 // Will be generated at use site.
5900}
5901
Calin Juravle175dc732015-08-25 15:42:32 +01005902void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5903 // The trampoline uses the same calling convention as dex calling conventions,
5904 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
5905 // the method_idx.
5906 HandleInvoke(invoke);
5907}
5908
5909void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5910 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
5911}
5912
Alexey Frunze4dda3372015-06-01 18:31:49 -07005913void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) {
5914 InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor;
5915 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
5916}
5917
5918void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
5919 HandleInvoke(invoke);
5920 // The register T0 is required to be used for the hidden argument in
5921 // art_quick_imt_conflict_trampoline, so add the hidden argument.
5922 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
5923}
5924
5925void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
5926 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
5927 GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07005928 Location receiver = invoke->GetLocations()->InAt(0);
5929 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07005930 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005931
5932 // Set the hidden argument.
5933 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(),
5934 invoke->GetDexMethodIndex());
5935
5936 // temp = object->GetClass();
5937 if (receiver.IsStackSlot()) {
5938 __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex());
5939 __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset);
5940 } else {
5941 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset);
5942 }
5943 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexey Frunzec061de12017-02-14 13:27:23 -08005944 // Instead of simply (possibly) unpoisoning `temp` here, we should
5945 // emit a read barrier for the previous class reference load.
5946 // However this is not required in practice, as this is an
5947 // intermediate/temporary reference and because the current
5948 // concurrent copying collector keeps the from-space memory
5949 // intact/accessible until the end of the marking phase (the
5950 // concurrent copying collector may not in the future).
5951 __ MaybeUnpoisonHeapReference(temp);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00005952 __ LoadFromOffset(kLoadDoubleword, temp, temp,
5953 mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value());
5954 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00005955 invoke->GetImtIndex(), kMips64PointerSize));
Alexey Frunze4dda3372015-06-01 18:31:49 -07005956 // temp = temp->GetImtEntryAt(method_offset);
5957 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
5958 // T9 = temp->GetEntryPoint();
5959 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
5960 // T9();
5961 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07005962 __ Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -07005963 DCHECK(!codegen_->IsLeafMethod());
5964 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
5965}
5966
5967void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen3039e382015-08-26 07:54:08 -07005968 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
5969 if (intrinsic.TryDispatch(invoke)) {
5970 return;
5971 }
5972
Alexey Frunze4dda3372015-06-01 18:31:49 -07005973 HandleInvoke(invoke);
5974}
5975
5976void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00005977 // Explicit clinit checks triggered by static invokes must have been pruned by
5978 // art::PrepareForRegisterAllocation.
5979 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Alexey Frunze4dda3372015-06-01 18:31:49 -07005980
Chris Larsen3039e382015-08-26 07:54:08 -07005981 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
5982 if (intrinsic.TryDispatch(invoke)) {
5983 return;
5984 }
5985
Alexey Frunze4dda3372015-06-01 18:31:49 -07005986 HandleInvoke(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07005987}
5988
Orion Hodsonac141392017-01-13 11:53:47 +00005989void LocationsBuilderMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
5990 HandleInvoke(invoke);
5991}
5992
5993void InstructionCodeGeneratorMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
5994 codegen_->GenerateInvokePolymorphicCall(invoke);
5995}
5996
Orion Hodson4c8e12e2018-05-18 08:33:20 +01005997void LocationsBuilderMIPS64::VisitInvokeCustom(HInvokeCustom* invoke) {
5998 HandleInvoke(invoke);
5999}
6000
6001void InstructionCodeGeneratorMIPS64::VisitInvokeCustom(HInvokeCustom* invoke) {
6002 codegen_->GenerateInvokeCustomCall(invoke);
6003}
6004
Chris Larsen3039e382015-08-26 07:54:08 -07006005static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006006 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen3039e382015-08-26 07:54:08 -07006007 IntrinsicCodeGeneratorMIPS64 intrinsic(codegen);
6008 intrinsic.Dispatch(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006009 return true;
6010 }
6011 return false;
6012}
6013
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006014HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind(
Alexey Frunzef63f5692016-12-13 17:43:11 -08006015 HLoadString::LoadKind desired_string_load_kind) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006016 bool fallback_load = false;
6017 switch (desired_string_load_kind) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006018 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006019 case HLoadString::LoadKind::kBootImageRelRo:
Alexey Frunzef63f5692016-12-13 17:43:11 -08006020 case HLoadString::LoadKind::kBssEntry:
6021 DCHECK(!Runtime::Current()->UseJitCompilation());
6022 break;
Vladimir Marko8e524ad2018-07-13 10:27:43 +01006023 case HLoadString::LoadKind::kJitBootImageAddress:
Alexey Frunzef63f5692016-12-13 17:43:11 -08006024 case HLoadString::LoadKind::kJitTableAddress:
6025 DCHECK(Runtime::Current()->UseJitCompilation());
Alexey Frunzef63f5692016-12-13 17:43:11 -08006026 break;
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006027 case HLoadString::LoadKind::kRuntimeCall:
Vladimir Marko764d4542017-05-16 10:31:41 +01006028 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006029 }
6030 if (fallback_load) {
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006031 desired_string_load_kind = HLoadString::LoadKind::kRuntimeCall;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006032 }
6033 return desired_string_load_kind;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006034}
6035
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006036HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind(
6037 HLoadClass::LoadKind desired_class_load_kind) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006038 bool fallback_load = false;
6039 switch (desired_class_load_kind) {
Nicolas Geoffray83c8e272017-01-31 14:36:37 +00006040 case HLoadClass::LoadKind::kInvalid:
6041 LOG(FATAL) << "UNREACHABLE";
6042 UNREACHABLE();
Alexey Frunzef63f5692016-12-13 17:43:11 -08006043 case HLoadClass::LoadKind::kReferrersClass:
6044 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006045 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006046 case HLoadClass::LoadKind::kBootImageRelRo:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00006047 case HLoadClass::LoadKind::kBssEntry:
6048 DCHECK(!Runtime::Current()->UseJitCompilation());
6049 break;
Vladimir Marko8e524ad2018-07-13 10:27:43 +01006050 case HLoadClass::LoadKind::kJitBootImageAddress:
Alexey Frunzef63f5692016-12-13 17:43:11 -08006051 case HLoadClass::LoadKind::kJitTableAddress:
6052 DCHECK(Runtime::Current()->UseJitCompilation());
Alexey Frunzef63f5692016-12-13 17:43:11 -08006053 break;
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006054 case HLoadClass::LoadKind::kRuntimeCall:
Alexey Frunzef63f5692016-12-13 17:43:11 -08006055 break;
6056 }
6057 if (fallback_load) {
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006058 desired_class_load_kind = HLoadClass::LoadKind::kRuntimeCall;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006059 }
6060 return desired_class_load_kind;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006061}
6062
Vladimir Markodc151b22015-10-15 18:02:30 +01006063HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch(
6064 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffraybdb2ecc2018-09-18 14:33:55 +01006065 ArtMethod* method ATTRIBUTE_UNUSED) {
Alexey Frunze19f6c692016-11-30 19:19:55 -08006066 // On MIPS64 we support all dispatch types.
6067 return desired_dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01006068}
6069
Vladimir Markoe7197bf2017-06-02 17:00:23 +01006070void CodeGeneratorMIPS64::GenerateStaticOrDirectCall(
6071 HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006072 // All registers are assumed to be correctly set up per the calling convention.
Vladimir Marko58155012015-08-19 12:49:41 +00006073 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
Alexey Frunze19f6c692016-11-30 19:19:55 -08006074 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
6075 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
6076
Alexey Frunze19f6c692016-11-30 19:19:55 -08006077 switch (method_load_kind) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01006078 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
Vladimir Marko58155012015-08-19 12:49:41 +00006079 // temp = thread->string_init_entrypoint
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01006080 uint32_t offset =
6081 GetThreadOffset<kMips64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
Vladimir Marko58155012015-08-19 12:49:41 +00006082 __ LoadFromOffset(kLoadDoubleword,
6083 temp.AsRegister<GpuRegister>(),
6084 TR,
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01006085 offset);
Vladimir Marko58155012015-08-19 12:49:41 +00006086 break;
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01006087 }
Vladimir Marko58155012015-08-19 12:49:41 +00006088 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00006089 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00006090 break;
Vladimir Marko65979462017-05-19 17:25:12 +01006091 case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: {
Vladimir Marko44ca0752019-07-29 10:18:25 +01006092 DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006093 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006094 NewBootImageMethodPatch(invoke->GetTargetMethod());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006095 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006096 NewBootImageMethodPatch(invoke->GetTargetMethod(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006097 EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Andreas Gampe3db70682018-12-26 15:12:03 -08006098 __ Daddiu(temp.AsRegister<GpuRegister>(), AT, /* imm16= */ 0x5678);
Vladimir Marko65979462017-05-19 17:25:12 +01006099 break;
6100 }
Vladimir Markob066d432018-01-03 13:14:37 +00006101 case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: {
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006102 uint32_t boot_image_offset = GetBootImageOffset(invoke);
Vladimir Markob066d432018-01-03 13:14:37 +00006103 PcRelativePatchInfo* info_high = NewBootImageRelRoPatch(boot_image_offset);
6104 PcRelativePatchInfo* info_low = NewBootImageRelRoPatch(boot_image_offset, info_high);
6105 EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
6106 // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load.
Andreas Gampe3db70682018-12-26 15:12:03 -08006107 __ Lwu(temp.AsRegister<GpuRegister>(), AT, /* imm16= */ 0x5678);
Vladimir Markob066d432018-01-03 13:14:37 +00006108 break;
6109 }
Vladimir Marko0eb882b2017-05-15 13:39:18 +01006110 case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006111 PcRelativePatchInfo* info_high = NewMethodBssEntryPatch(
Vladimir Marko0eb882b2017-05-15 13:39:18 +01006112 MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()));
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006113 PcRelativePatchInfo* info_low = NewMethodBssEntryPatch(
6114 MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high);
6115 EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Andreas Gampe3db70682018-12-26 15:12:03 -08006116 __ Ld(temp.AsRegister<GpuRegister>(), AT, /* imm16= */ 0x5678);
Alexey Frunze19f6c692016-11-30 19:19:55 -08006117 break;
6118 }
Vladimir Marko8e524ad2018-07-13 10:27:43 +01006119 case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress:
6120 __ LoadLiteral(temp.AsRegister<GpuRegister>(),
6121 kLoadDoubleword,
6122 DeduplicateUint64Literal(invoke->GetMethodAddress()));
6123 break;
Vladimir Markoe7197bf2017-06-02 17:00:23 +01006124 case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: {
6125 GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path);
6126 return; // No code pointer retrieval; the runtime performs the call directly.
Alexey Frunze4dda3372015-06-01 18:31:49 -07006127 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006128 }
6129
Alexey Frunze19f6c692016-11-30 19:19:55 -08006130 switch (code_ptr_location) {
Vladimir Marko58155012015-08-19 12:49:41 +00006131 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
Alexey Frunze19f6c692016-11-30 19:19:55 -08006132 __ Balc(&frame_entry_label_);
Vladimir Marko58155012015-08-19 12:49:41 +00006133 break;
Vladimir Marko58155012015-08-19 12:49:41 +00006134 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
6135 // T9 = callee_method->entry_point_from_quick_compiled_code_;
6136 __ LoadFromOffset(kLoadDoubleword,
6137 T9,
6138 callee_method.AsRegister<GpuRegister>(),
6139 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006140 kMips64PointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00006141 // T9()
6142 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07006143 __ Nop();
Vladimir Marko58155012015-08-19 12:49:41 +00006144 break;
6145 }
Vladimir Markoe7197bf2017-06-02 17:00:23 +01006146 RecordPcInfo(invoke, invoke->GetDexPc(), slow_path);
6147
Alexey Frunze4dda3372015-06-01 18:31:49 -07006148 DCHECK(!IsLeafMethod());
6149}
6150
6151void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00006152 // Explicit clinit checks triggered by static invokes must have been pruned by
6153 // art::PrepareForRegisterAllocation.
6154 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006155
6156 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
6157 return;
6158 }
6159
6160 LocationSummary* locations = invoke->GetLocations();
6161 codegen_->GenerateStaticOrDirectCall(invoke,
6162 locations->HasTemps()
6163 ? locations->GetTemp(0)
6164 : Location::NoLocation());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006165}
6166
Vladimir Markoe7197bf2017-06-02 17:00:23 +01006167void CodeGeneratorMIPS64::GenerateVirtualCall(
6168 HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) {
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006169 // Use the calling convention instead of the location of the receiver, as
6170 // intrinsics may have put the receiver in a different register. In the intrinsics
6171 // slow path, the arguments have been moved to the right place, so here we are
6172 // guaranteed that the receiver is the first register of the calling convention.
6173 InvokeDexCallingConvention calling_convention;
6174 GpuRegister receiver = calling_convention.GetRegisterAt(0);
6175
Alexey Frunze53afca12015-11-05 16:34:23 -08006176 GpuRegister temp = temp_location.AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006177 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
6178 invoke->GetVTableIndex(), kMips64PointerSize).SizeValue();
6179 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07006180 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006181
6182 // temp = object->GetClass();
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006183 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset);
Alexey Frunze53afca12015-11-05 16:34:23 -08006184 MaybeRecordImplicitNullCheck(invoke);
Alexey Frunzec061de12017-02-14 13:27:23 -08006185 // Instead of simply (possibly) unpoisoning `temp` here, we should
6186 // emit a read barrier for the previous class reference load.
6187 // However this is not required in practice, as this is an
6188 // intermediate/temporary reference and because the current
6189 // concurrent copying collector keeps the from-space memory
6190 // intact/accessible until the end of the marking phase (the
6191 // concurrent copying collector may not in the future).
6192 __ MaybeUnpoisonHeapReference(temp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006193 // temp = temp->GetMethodAt(method_offset);
6194 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
6195 // T9 = temp->GetEntryPoint();
6196 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
6197 // T9();
6198 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07006199 __ Nop();
Vladimir Markoe7197bf2017-06-02 17:00:23 +01006200 RecordPcInfo(invoke, invoke->GetDexPc(), slow_path);
Alexey Frunze53afca12015-11-05 16:34:23 -08006201}
6202
6203void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
6204 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
6205 return;
6206 }
6207
6208 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Alexey Frunze4dda3372015-06-01 18:31:49 -07006209 DCHECK(!codegen_->IsLeafMethod());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006210}
6211
6212void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) {
Vladimir Marko41559982017-01-06 14:04:23 +00006213 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006214 if (load_kind == HLoadClass::LoadKind::kRuntimeCall) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006215 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07006216 Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0));
6217 CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006218 return;
6219 }
Vladimir Marko41559982017-01-06 14:04:23 +00006220 DCHECK(!cls->NeedsAccessCheck());
Alexey Frunzef63f5692016-12-13 17:43:11 -08006221
Alexey Frunze15958152017-02-09 19:08:30 -08006222 const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage();
6223 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier)
Alexey Frunzef63f5692016-12-13 17:43:11 -08006224 ? LocationSummary::kCallOnSlowPath
6225 : LocationSummary::kNoCall;
Vladimir Markoca6fff82017-10-03 14:49:14 +01006226 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind);
Alexey Frunzec61c0762017-04-10 13:54:23 -07006227 if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) {
6228 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
6229 }
Vladimir Marko41559982017-01-06 14:04:23 +00006230 if (load_kind == HLoadClass::LoadKind::kReferrersClass) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006231 locations->SetInAt(0, Location::RequiresRegister());
6232 }
6233 locations->SetOut(Location::RequiresRegister());
Alexey Frunzec61c0762017-04-10 13:54:23 -07006234 if (load_kind == HLoadClass::LoadKind::kBssEntry) {
6235 if (!kUseReadBarrier || kUseBakerReadBarrier) {
6236 // Rely on the type resolution or initialization and marking to save everything we need.
Vladimir Marko3232dbb2018-07-25 15:42:46 +01006237 locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves());
Alexey Frunzec61c0762017-04-10 13:54:23 -07006238 } else {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006239 // For non-Baker read barriers we have a temp-clobbering call.
Alexey Frunzec61c0762017-04-10 13:54:23 -07006240 }
6241 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006242}
6243
Nicolas Geoffray5247c082017-01-13 14:17:29 +00006244// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
6245// move.
6246void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS {
Vladimir Marko41559982017-01-06 14:04:23 +00006247 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006248 if (load_kind == HLoadClass::LoadKind::kRuntimeCall) {
Vladimir Marko41559982017-01-06 14:04:23 +00006249 codegen_->GenerateLoadClassRuntimeCall(cls);
Calin Juravle580b6092015-10-06 17:35:58 +01006250 return;
6251 }
Vladimir Marko41559982017-01-06 14:04:23 +00006252 DCHECK(!cls->NeedsAccessCheck());
Calin Juravle580b6092015-10-06 17:35:58 +01006253
Vladimir Marko41559982017-01-06 14:04:23 +00006254 LocationSummary* locations = cls->GetLocations();
Alexey Frunzef63f5692016-12-13 17:43:11 -08006255 Location out_loc = locations->Out();
6256 GpuRegister out = out_loc.AsRegister<GpuRegister>();
6257 GpuRegister current_method_reg = ZERO;
6258 if (load_kind == HLoadClass::LoadKind::kReferrersClass ||
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006259 load_kind == HLoadClass::LoadKind::kRuntimeCall) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006260 current_method_reg = locations->InAt(0).AsRegister<GpuRegister>();
6261 }
6262
Alexey Frunze15958152017-02-09 19:08:30 -08006263 const ReadBarrierOption read_barrier_option = cls->IsInBootImage()
6264 ? kWithoutReadBarrier
6265 : kCompilerReadBarrierOption;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006266 bool generate_null_check = false;
6267 switch (load_kind) {
6268 case HLoadClass::LoadKind::kReferrersClass:
6269 DCHECK(!cls->CanCallRuntime());
6270 DCHECK(!cls->MustGenerateClinitCheck());
6271 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
6272 GenerateGcRootFieldLoad(cls,
6273 out_loc,
6274 current_method_reg,
Alexey Frunze15958152017-02-09 19:08:30 -08006275 ArtMethod::DeclaringClassOffset().Int32Value(),
6276 read_barrier_option);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006277 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006278 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Marko44ca0752019-07-29 10:18:25 +01006279 DCHECK(codegen_->GetCompilerOptions().IsBootImage() ||
6280 codegen_->GetCompilerOptions().IsBootImageExtension());
Alexey Frunze15958152017-02-09 19:08:30 -08006281 DCHECK_EQ(read_barrier_option, kWithoutReadBarrier);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006282 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006283 codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006284 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006285 codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006286 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Andreas Gampe3db70682018-12-26 15:12:03 -08006287 __ Daddiu(out, AT, /* imm16= */ 0x5678);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006288 break;
6289 }
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006290 case HLoadClass::LoadKind::kBootImageRelRo: {
Vladimir Marko94ec2db2017-09-06 17:21:03 +01006291 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006292 uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls);
Vladimir Marko94ec2db2017-09-06 17:21:03 +01006293 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006294 codegen_->NewBootImageRelRoPatch(boot_image_offset);
Vladimir Marko94ec2db2017-09-06 17:21:03 +01006295 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006296 codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high);
Vladimir Marko94ec2db2017-09-06 17:21:03 +01006297 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Andreas Gampe3db70682018-12-26 15:12:03 -08006298 __ Lwu(out, AT, /* imm16= */ 0x5678);
Vladimir Marko94ec2db2017-09-06 17:21:03 +01006299 break;
6300 }
Vladimir Marko6bec91c2017-01-09 15:03:12 +00006301 case HLoadClass::LoadKind::kBssEntry: {
Vladimir Markof3c52b42017-11-17 17:32:12 +00006302 CodeGeneratorMIPS64::PcRelativePatchInfo* bss_info_high =
6303 codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006304 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
6305 codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high);
Vladimir Markof3c52b42017-11-17 17:32:12 +00006306 codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, out);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006307 GenerateGcRootFieldLoad(cls,
6308 out_loc,
Vladimir Markof3c52b42017-11-17 17:32:12 +00006309 out,
Andreas Gampe3db70682018-12-26 15:12:03 -08006310 /* offset= */ 0x5678,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006311 read_barrier_option,
6312 &info_low->label);
Vladimir Marko6bec91c2017-01-09 15:03:12 +00006313 generate_null_check = true;
6314 break;
6315 }
Vladimir Marko8e524ad2018-07-13 10:27:43 +01006316 case HLoadClass::LoadKind::kJitBootImageAddress: {
6317 DCHECK_EQ(read_barrier_option, kWithoutReadBarrier);
6318 uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get());
6319 DCHECK_NE(address, 0u);
6320 __ LoadLiteral(out,
6321 kLoadUnsignedWord,
6322 codegen_->DeduplicateBootImageAddressLiteral(address));
6323 break;
6324 }
Alexey Frunze627c1a02017-01-30 19:28:14 -08006325 case HLoadClass::LoadKind::kJitTableAddress:
6326 __ LoadLiteral(out,
6327 kLoadUnsignedWord,
6328 codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(),
6329 cls->GetTypeIndex(),
6330 cls->GetClass()));
Alexey Frunze15958152017-02-09 19:08:30 -08006331 GenerateGcRootFieldLoad(cls, out_loc, out, 0, read_barrier_option);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006332 break;
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006333 case HLoadClass::LoadKind::kRuntimeCall:
Nicolas Geoffray83c8e272017-01-31 14:36:37 +00006334 case HLoadClass::LoadKind::kInvalid:
Vladimir Marko41559982017-01-06 14:04:23 +00006335 LOG(FATAL) << "UNREACHABLE";
6336 UNREACHABLE();
Alexey Frunzef63f5692016-12-13 17:43:11 -08006337 }
6338
6339 if (generate_null_check || cls->MustGenerateClinitCheck()) {
6340 DCHECK(cls->CanCallRuntime());
Vladimir Markoa9f303c2018-07-20 16:43:56 +01006341 SlowPathCodeMIPS64* slow_path =
6342 new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64(cls, cls);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006343 codegen_->AddSlowPath(slow_path);
6344 if (generate_null_check) {
6345 __ Beqzc(out, slow_path->GetEntryLabel());
6346 }
6347 if (cls->MustGenerateClinitCheck()) {
6348 GenerateClassInitializationCheck(slow_path, out);
6349 } else {
6350 __ Bind(slow_path->GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006351 }
6352 }
6353}
6354
Orion Hodsondbaa5c72018-05-10 08:22:46 +01006355void LocationsBuilderMIPS64::VisitLoadMethodHandle(HLoadMethodHandle* load) {
6356 InvokeRuntimeCallingConvention calling_convention;
6357 Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0));
6358 CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, loc, loc);
6359}
6360
6361void InstructionCodeGeneratorMIPS64::VisitLoadMethodHandle(HLoadMethodHandle* load) {
6362 codegen_->GenerateLoadMethodHandleRuntimeCall(load);
6363}
6364
Orion Hodson18259d72018-04-12 11:18:23 +01006365void LocationsBuilderMIPS64::VisitLoadMethodType(HLoadMethodType* load) {
6366 InvokeRuntimeCallingConvention calling_convention;
6367 Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0));
6368 CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, loc, loc);
6369}
6370
6371void InstructionCodeGeneratorMIPS64::VisitLoadMethodType(HLoadMethodType* load) {
6372 codegen_->GenerateLoadMethodTypeRuntimeCall(load);
6373}
6374
David Brazdilcb1c0552015-08-04 16:22:25 +01006375static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07006376 return Thread::ExceptionOffset<kMips64PointerSize>().Int32Value();
David Brazdilcb1c0552015-08-04 16:22:25 +01006377}
6378
Alexey Frunze4dda3372015-06-01 18:31:49 -07006379void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) {
6380 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01006381 new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006382 locations->SetOut(Location::RequiresRegister());
6383}
6384
6385void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) {
6386 GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>();
David Brazdilcb1c0552015-08-04 16:22:25 +01006387 __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset());
6388}
6389
6390void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006391 new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall);
David Brazdilcb1c0552015-08-04 16:22:25 +01006392}
6393
6394void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
6395 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006396}
6397
Alexey Frunze4dda3372015-06-01 18:31:49 -07006398void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006399 HLoadString::LoadKind load_kind = load->GetLoadKind();
6400 LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load);
Vladimir Markoca6fff82017-10-03 14:49:14 +01006401 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind);
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006402 if (load_kind == HLoadString::LoadKind::kRuntimeCall) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006403 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07006404 locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Alexey Frunzef63f5692016-12-13 17:43:11 -08006405 } else {
6406 locations->SetOut(Location::RequiresRegister());
Alexey Frunzec61c0762017-04-10 13:54:23 -07006407 if (load_kind == HLoadString::LoadKind::kBssEntry) {
6408 if (!kUseReadBarrier || kUseBakerReadBarrier) {
6409 // Rely on the pResolveString and marking to save everything we need.
Vladimir Marko3232dbb2018-07-25 15:42:46 +01006410 locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves());
Alexey Frunzec61c0762017-04-10 13:54:23 -07006411 } else {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006412 // For non-Baker read barriers we have a temp-clobbering call.
Alexey Frunzec61c0762017-04-10 13:54:23 -07006413 }
6414 }
Alexey Frunzef63f5692016-12-13 17:43:11 -08006415 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006416}
6417
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00006418// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
6419// move.
6420void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006421 HLoadString::LoadKind load_kind = load->GetLoadKind();
6422 LocationSummary* locations = load->GetLocations();
6423 Location out_loc = locations->Out();
6424 GpuRegister out = out_loc.AsRegister<GpuRegister>();
6425
6426 switch (load_kind) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006427 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Marko44ca0752019-07-29 10:18:25 +01006428 DCHECK(codegen_->GetCompilerOptions().IsBootImage() ||
6429 codegen_->GetCompilerOptions().IsBootImageExtension());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006430 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006431 codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006432 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
Vladimir Marko59eb30f2018-02-20 11:52:34 +00006433 codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006434 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Andreas Gampe3db70682018-12-26 15:12:03 -08006435 __ Daddiu(out, AT, /* imm16= */ 0x5678);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01006436 return;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006437 }
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006438 case HLoadString::LoadKind::kBootImageRelRo: {
Alexey Frunzef63f5692016-12-13 17:43:11 -08006439 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006440 uint32_t boot_image_offset = codegen_->GetBootImageOffset(load);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006441 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006442 codegen_->NewBootImageRelRoPatch(boot_image_offset);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006443 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
Vladimir Markoe47f60c2018-02-21 13:43:28 +00006444 codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01006445 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low);
Andreas Gampe3db70682018-12-26 15:12:03 -08006446 __ Lwu(out, AT, /* imm16= */ 0x5678);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01006447 return;
6448 }
6449 case HLoadString::LoadKind::kBssEntry: {
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01006450 CodeGeneratorMIPS64::PcRelativePatchInfo* info_high =
6451 codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex());
6452 CodeGeneratorMIPS64::PcRelativePatchInfo* info_low =
6453 codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high);
Vladimir Markof3c52b42017-11-17 17:32:12 +00006454 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, out);
Alexey Frunze15958152017-02-09 19:08:30 -08006455 GenerateGcRootFieldLoad(load,
6456 out_loc,
Vladimir Markof3c52b42017-11-17 17:32:12 +00006457 out,
Andreas Gampe3db70682018-12-26 15:12:03 -08006458 /* offset= */ 0x5678,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006459 kCompilerReadBarrierOption,
6460 &info_low->label);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07006461 SlowPathCodeMIPS64* slow_path =
Vladimir Markof3c52b42017-11-17 17:32:12 +00006462 new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS64(load);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006463 codegen_->AddSlowPath(slow_path);
6464 __ Beqzc(out, slow_path->GetEntryLabel());
6465 __ Bind(slow_path->GetExitLabel());
6466 return;
6467 }
Vladimir Marko8e524ad2018-07-13 10:27:43 +01006468 case HLoadString::LoadKind::kJitBootImageAddress: {
6469 uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get());
6470 DCHECK_NE(address, 0u);
6471 __ LoadLiteral(out,
6472 kLoadUnsignedWord,
6473 codegen_->DeduplicateBootImageAddressLiteral(address));
6474 return;
6475 }
Alexey Frunze627c1a02017-01-30 19:28:14 -08006476 case HLoadString::LoadKind::kJitTableAddress:
6477 __ LoadLiteral(out,
6478 kLoadUnsignedWord,
6479 codegen_->DeduplicateJitStringLiteral(load->GetDexFile(),
6480 load->GetStringIndex(),
6481 load->GetString()));
Alexey Frunze15958152017-02-09 19:08:30 -08006482 GenerateGcRootFieldLoad(load, out_loc, out, 0, kCompilerReadBarrierOption);
Alexey Frunze627c1a02017-01-30 19:28:14 -08006483 return;
Alexey Frunzef63f5692016-12-13 17:43:11 -08006484 default:
6485 break;
6486 }
6487
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07006488 // TODO: Re-add the compiler code to do string dex cache lookup again.
Vladimir Marko847e6ce2017-06-02 13:55:07 +01006489 DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006490 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07006491 DCHECK_EQ(calling_convention.GetRegisterAt(0), out);
Alexey Frunzef63f5692016-12-13 17:43:11 -08006492 __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_);
6493 codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc());
6494 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006495}
6496
Alexey Frunze4dda3372015-06-01 18:31:49 -07006497void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006498 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006499 locations->SetOut(Location::ConstantLocation(constant));
6500}
6501
6502void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
6503 // Will be generated at use site.
6504}
6505
6506void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006507 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
6508 instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006509 InvokeRuntimeCallingConvention calling_convention;
6510 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6511}
6512
6513void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
Serban Constantinescufc734082016-07-19 17:18:07 +01006514 codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject,
Alexey Frunze4dda3372015-06-01 18:31:49 -07006515 instruction,
Serban Constantinescufc734082016-07-19 17:18:07 +01006516 instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00006517 if (instruction->IsEnter()) {
6518 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
6519 } else {
6520 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
6521 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006522}
6523
6524void LocationsBuilderMIPS64::VisitMul(HMul* mul) {
6525 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01006526 new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006527 switch (mul->GetResultType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006528 case DataType::Type::kInt32:
6529 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07006530 locations->SetInAt(0, Location::RequiresRegister());
6531 locations->SetInAt(1, Location::RequiresRegister());
6532 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6533 break;
6534
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006535 case DataType::Type::kFloat32:
6536 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07006537 locations->SetInAt(0, Location::RequiresFpuRegister());
6538 locations->SetInAt(1, Location::RequiresFpuRegister());
6539 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
6540 break;
6541
6542 default:
6543 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
6544 }
6545}
6546
6547void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006548 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006549 LocationSummary* locations = instruction->GetLocations();
6550
6551 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006552 case DataType::Type::kInt32:
6553 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006554 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
6555 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
6556 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006557 if (type == DataType::Type::kInt32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07006558 __ MulR6(dst, lhs, rhs);
6559 else
6560 __ Dmul(dst, lhs, rhs);
6561 break;
6562 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006563 case DataType::Type::kFloat32:
6564 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006565 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
6566 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
6567 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006568 if (type == DataType::Type::kFloat32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07006569 __ MulS(dst, lhs, rhs);
6570 else
6571 __ MulD(dst, lhs, rhs);
6572 break;
6573 }
6574 default:
6575 LOG(FATAL) << "Unexpected mul type " << type;
6576 }
6577}
6578
6579void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) {
6580 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01006581 new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006582 switch (neg->GetResultType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006583 case DataType::Type::kInt32:
6584 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07006585 locations->SetInAt(0, Location::RequiresRegister());
6586 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6587 break;
6588
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006589 case DataType::Type::kFloat32:
6590 case DataType::Type::kFloat64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07006591 locations->SetInAt(0, Location::RequiresFpuRegister());
6592 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
6593 break;
6594
6595 default:
6596 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
6597 }
6598}
6599
6600void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006601 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006602 LocationSummary* locations = instruction->GetLocations();
6603
6604 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006605 case DataType::Type::kInt32:
6606 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006607 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
6608 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006609 if (type == DataType::Type::kInt32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07006610 __ Subu(dst, ZERO, src);
6611 else
6612 __ Dsubu(dst, ZERO, src);
6613 break;
6614 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006615 case DataType::Type::kFloat32:
6616 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006617 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
6618 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006619 if (type == DataType::Type::kFloat32)
Alexey Frunze4dda3372015-06-01 18:31:49 -07006620 __ NegS(dst, src);
6621 else
6622 __ NegD(dst, src);
6623 break;
6624 }
6625 default:
6626 LOG(FATAL) << "Unexpected neg type " << type;
6627 }
6628}
6629
6630void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006631 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
6632 instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006633 InvokeRuntimeCallingConvention calling_convention;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006634 locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference));
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00006635 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6636 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07006637}
6638
6639void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) {
Vladimir Markob5461632018-10-15 14:24:21 +01006640 // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference.
6641 QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction);
Goran Jakovljevic854df412017-06-27 14:41:39 +02006642 codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc());
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00006643 CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>();
Goran Jakovljevic854df412017-06-27 14:41:39 +02006644 DCHECK(!codegen_->IsLeafMethod());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006645}
6646
6647void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006648 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
6649 instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006650 InvokeRuntimeCallingConvention calling_convention;
Alex Lightd109e302018-06-27 10:25:41 -07006651 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006652 locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference));
Alexey Frunze4dda3372015-06-01 18:31:49 -07006653}
6654
6655void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) {
Alex Lightd109e302018-06-27 10:25:41 -07006656 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
6657 CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006658}
6659
6660void LocationsBuilderMIPS64::VisitNot(HNot* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006661 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006662 locations->SetInAt(0, Location::RequiresRegister());
6663 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6664}
6665
6666void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006667 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006668 LocationSummary* locations = instruction->GetLocations();
6669
6670 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006671 case DataType::Type::kInt32:
6672 case DataType::Type::kInt64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006673 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
6674 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
6675 __ Nor(dst, src, ZERO);
6676 break;
6677 }
6678
6679 default:
6680 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
6681 }
6682}
6683
6684void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006685 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006686 locations->SetInAt(0, Location::RequiresRegister());
6687 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6688}
6689
6690void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
6691 LocationSummary* locations = instruction->GetLocations();
6692 __ Xori(locations->Out().AsRegister<GpuRegister>(),
6693 locations->InAt(0).AsRegister<GpuRegister>(),
6694 1);
6695}
6696
6697void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01006698 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
6699 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006700}
6701
Calin Juravle2ae48182016-03-16 14:05:09 +00006702void CodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) {
6703 if (CanMoveNullCheckToUser(instruction)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006704 return;
6705 }
6706 Location obj = instruction->GetLocations()->InAt(0);
6707
6708 __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00006709 RecordPcInfo(instruction, instruction->GetDexPc());
Alexey Frunze4dda3372015-06-01 18:31:49 -07006710}
6711
Calin Juravle2ae48182016-03-16 14:05:09 +00006712void CodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006713 SlowPathCodeMIPS64* slow_path =
Vladimir Marko174b2e22017-10-12 13:34:49 +01006714 new (GetScopedAllocator()) NullCheckSlowPathMIPS64(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00006715 AddSlowPath(slow_path);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006716
6717 Location obj = instruction->GetLocations()->InAt(0);
6718
6719 __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
6720}
6721
6722void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00006723 codegen_->GenerateNullCheck(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006724}
6725
6726void LocationsBuilderMIPS64::VisitOr(HOr* instruction) {
6727 HandleBinaryOp(instruction);
6728}
6729
6730void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) {
6731 HandleBinaryOp(instruction);
6732}
6733
6734void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
6735 LOG(FATAL) << "Unreachable";
6736}
6737
6738void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) {
Vladimir Markobea75ff2017-10-11 20:39:54 +01006739 if (instruction->GetNext()->IsSuspendCheck() &&
6740 instruction->GetBlock()->GetLoopInformation() != nullptr) {
6741 HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck();
6742 // The back edge will generate the suspend check.
6743 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction);
6744 }
6745
Alexey Frunze4dda3372015-06-01 18:31:49 -07006746 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
6747}
6748
6749void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006750 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006751 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
6752 if (location.IsStackSlot()) {
6753 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
6754 } else if (location.IsDoubleStackSlot()) {
6755 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
6756 }
6757 locations->SetOut(location);
6758}
6759
6760void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction
6761 ATTRIBUTE_UNUSED) {
6762 // Nothing to do, the parameter is already at its location.
6763}
6764
6765void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) {
6766 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01006767 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006768 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
6769}
6770
6771void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction
6772 ATTRIBUTE_UNUSED) {
6773 // Nothing to do, the method is already at its location.
6774}
6775
6776void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006777 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Vladimir Marko372f10e2016-05-17 16:30:10 +01006778 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006779 locations->SetInAt(i, Location::Any());
6780 }
6781 locations->SetOut(Location::Any());
6782}
6783
6784void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
6785 LOG(FATAL) << "Unreachable";
6786}
6787
6788void LocationsBuilderMIPS64::VisitRem(HRem* rem) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006789 DataType::Type type = rem->GetResultType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006790 LocationSummary::CallKind call_kind =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006791 DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly
6792 : LocationSummary::kNoCall;
Vladimir Markoca6fff82017-10-03 14:49:14 +01006793 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006794
6795 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006796 case DataType::Type::kInt32:
6797 case DataType::Type::kInt64:
Alexey Frunze4dda3372015-06-01 18:31:49 -07006798 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunzec857c742015-09-23 15:12:39 -07006799 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07006800 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6801 break;
6802
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006803 case DataType::Type::kFloat32:
6804 case DataType::Type::kFloat64: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07006805 InvokeRuntimeCallingConvention calling_convention;
6806 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
6807 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
6808 locations->SetOut(calling_convention.GetReturnLocation(type));
6809 break;
6810 }
6811
6812 default:
6813 LOG(FATAL) << "Unexpected rem type " << type;
6814 }
6815}
6816
6817void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006818 DataType::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07006819
6820 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006821 case DataType::Type::kInt32:
6822 case DataType::Type::kInt64:
Alexey Frunzec857c742015-09-23 15:12:39 -07006823 GenerateDivRemIntegral(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07006824 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07006825
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006826 case DataType::Type::kFloat32:
6827 case DataType::Type::kFloat64: {
6828 QuickEntrypointEnum entrypoint =
6829 (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod;
Serban Constantinescufc734082016-07-19 17:18:07 +01006830 codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006831 if (type == DataType::Type::kFloat32) {
Roland Levillain888d0672015-11-23 18:53:50 +00006832 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
6833 } else {
6834 CheckEntrypointTypes<kQuickFmod, double, double, double>();
6835 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07006836 break;
6837 }
6838 default:
6839 LOG(FATAL) << "Unexpected rem type " << type;
6840 }
6841}
6842
Aart Bik1f8d51b2018-02-15 10:42:37 -08006843static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) {
6844 LocationSummary* locations = new (allocator) LocationSummary(minmax);
6845 switch (minmax->GetResultType()) {
6846 case DataType::Type::kInt32:
6847 case DataType::Type::kInt64:
6848 locations->SetInAt(0, Location::RequiresRegister());
6849 locations->SetInAt(1, Location::RequiresRegister());
6850 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6851 break;
6852 case DataType::Type::kFloat32:
6853 case DataType::Type::kFloat64:
6854 locations->SetInAt(0, Location::RequiresFpuRegister());
6855 locations->SetInAt(1, Location::RequiresFpuRegister());
6856 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
6857 break;
6858 default:
6859 LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType();
6860 }
6861}
6862
Aart Bik351df3e2018-03-07 11:54:57 -08006863void InstructionCodeGeneratorMIPS64::GenerateMinMaxInt(LocationSummary* locations, bool is_min) {
Aart Bik1f8d51b2018-02-15 10:42:37 -08006864 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
6865 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
6866 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
6867
6868 if (lhs == rhs) {
6869 if (out != lhs) {
6870 __ Move(out, lhs);
6871 }
6872 } else {
6873 // Some architectures, such as ARM and MIPS (prior to r6), have a
6874 // conditional move instruction which only changes the target
6875 // (output) register if the condition is true (MIPS prior to r6 had
6876 // MOVF, MOVT, and MOVZ). The SELEQZ and SELNEZ instructions always
6877 // change the target (output) register. If the condition is true the
6878 // output register gets the contents of the "rs" register; otherwise,
6879 // the output register is set to zero. One consequence of this is
6880 // that to implement something like "rd = c==0 ? rs : rt" MIPS64r6
6881 // needs to use a pair of SELEQZ/SELNEZ instructions. After
6882 // executing this pair of instructions one of the output registers
6883 // from the pair will necessarily contain zero. Then the code ORs the
6884 // output registers from the SELEQZ/SELNEZ instructions to get the
6885 // final result.
6886 //
6887 // The initial test to see if the output register is same as the
6888 // first input register is needed to make sure that value in the
6889 // first input register isn't clobbered before we've finished
6890 // computing the output value. The logic in the corresponding else
6891 // clause performs the same task but makes sure the second input
6892 // register isn't clobbered in the event that it's the same register
6893 // as the output register; the else clause also handles the case
6894 // where the output register is distinct from both the first, and the
6895 // second input registers.
6896 if (out == lhs) {
6897 __ Slt(AT, rhs, lhs);
6898 if (is_min) {
6899 __ Seleqz(out, lhs, AT);
6900 __ Selnez(AT, rhs, AT);
6901 } else {
6902 __ Selnez(out, lhs, AT);
6903 __ Seleqz(AT, rhs, AT);
6904 }
6905 } else {
6906 __ Slt(AT, lhs, rhs);
6907 if (is_min) {
6908 __ Seleqz(out, rhs, AT);
6909 __ Selnez(AT, lhs, AT);
6910 } else {
6911 __ Selnez(out, rhs, AT);
6912 __ Seleqz(AT, lhs, AT);
6913 }
6914 }
6915 __ Or(out, out, AT);
6916 }
6917}
6918
6919void InstructionCodeGeneratorMIPS64::GenerateMinMaxFP(LocationSummary* locations,
6920 bool is_min,
6921 DataType::Type type) {
6922 FpuRegister a = locations->InAt(0).AsFpuRegister<FpuRegister>();
6923 FpuRegister b = locations->InAt(1).AsFpuRegister<FpuRegister>();
6924 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
6925
6926 Mips64Label noNaNs;
6927 Mips64Label done;
6928 FpuRegister ftmp = ((out != a) && (out != b)) ? out : FTMP;
6929
6930 // When Java computes min/max it prefers a NaN to a number; the
6931 // behavior of MIPSR6 is to prefer numbers to NaNs, i.e., if one of
6932 // the inputs is a NaN and the other is a valid number, the MIPS
6933 // instruction will return the number; Java wants the NaN value
6934 // returned. This is why there is extra logic preceding the use of
6935 // the MIPS min.fmt/max.fmt instructions. If either a, or b holds a
6936 // NaN, return the NaN, otherwise return the min/max.
6937 if (type == DataType::Type::kFloat64) {
6938 __ CmpUnD(FTMP, a, b);
6939 __ Bc1eqz(FTMP, &noNaNs);
6940
6941 // One of the inputs is a NaN
6942 __ CmpEqD(ftmp, a, a);
6943 // If a == a then b is the NaN, otherwise a is the NaN.
6944 __ SelD(ftmp, a, b);
6945
6946 if (ftmp != out) {
6947 __ MovD(out, ftmp);
6948 }
6949
6950 __ Bc(&done);
6951
6952 __ Bind(&noNaNs);
6953
6954 if (is_min) {
6955 __ MinD(out, a, b);
6956 } else {
6957 __ MaxD(out, a, b);
6958 }
6959 } else {
6960 DCHECK_EQ(type, DataType::Type::kFloat32);
6961 __ CmpUnS(FTMP, a, b);
6962 __ Bc1eqz(FTMP, &noNaNs);
6963
6964 // One of the inputs is a NaN
6965 __ CmpEqS(ftmp, a, a);
6966 // If a == a then b is the NaN, otherwise a is the NaN.
6967 __ SelS(ftmp, a, b);
6968
6969 if (ftmp != out) {
6970 __ MovS(out, ftmp);
6971 }
6972
6973 __ Bc(&done);
6974
6975 __ Bind(&noNaNs);
6976
6977 if (is_min) {
6978 __ MinS(out, a, b);
6979 } else {
6980 __ MaxS(out, a, b);
6981 }
6982 }
6983
6984 __ Bind(&done);
6985}
6986
Aart Bik351df3e2018-03-07 11:54:57 -08006987void InstructionCodeGeneratorMIPS64::GenerateMinMax(HBinaryOperation* minmax, bool is_min) {
6988 DataType::Type type = minmax->GetResultType();
6989 switch (type) {
6990 case DataType::Type::kInt32:
6991 case DataType::Type::kInt64:
6992 GenerateMinMaxInt(minmax->GetLocations(), is_min);
6993 break;
6994 case DataType::Type::kFloat32:
6995 case DataType::Type::kFloat64:
6996 GenerateMinMaxFP(minmax->GetLocations(), is_min, type);
6997 break;
6998 default:
6999 LOG(FATAL) << "Unexpected type for HMinMax " << type;
7000 }
7001}
7002
Aart Bik1f8d51b2018-02-15 10:42:37 -08007003void LocationsBuilderMIPS64::VisitMin(HMin* min) {
7004 CreateMinMaxLocations(GetGraph()->GetAllocator(), min);
7005}
7006
7007void InstructionCodeGeneratorMIPS64::VisitMin(HMin* min) {
Aart Bik351df3e2018-03-07 11:54:57 -08007008 GenerateMinMax(min, /*is_min*/ true);
Aart Bik1f8d51b2018-02-15 10:42:37 -08007009}
7010
7011void LocationsBuilderMIPS64::VisitMax(HMax* max) {
7012 CreateMinMaxLocations(GetGraph()->GetAllocator(), max);
7013}
7014
7015void InstructionCodeGeneratorMIPS64::VisitMax(HMax* max) {
Aart Bik351df3e2018-03-07 11:54:57 -08007016 GenerateMinMax(max, /*is_min*/ false);
Aart Bik1f8d51b2018-02-15 10:42:37 -08007017}
7018
Aart Bik3dad3412018-02-28 12:01:46 -08007019void LocationsBuilderMIPS64::VisitAbs(HAbs* abs) {
7020 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs);
7021 switch (abs->GetResultType()) {
7022 case DataType::Type::kInt32:
7023 case DataType::Type::kInt64:
7024 locations->SetInAt(0, Location::RequiresRegister());
7025 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
7026 break;
7027 case DataType::Type::kFloat32:
7028 case DataType::Type::kFloat64:
7029 locations->SetInAt(0, Location::RequiresFpuRegister());
7030 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
7031 break;
7032 default:
7033 LOG(FATAL) << "Unexpected abs type " << abs->GetResultType();
7034 }
7035}
7036
7037void InstructionCodeGeneratorMIPS64::VisitAbs(HAbs* abs) {
7038 LocationSummary* locations = abs->GetLocations();
7039 switch (abs->GetResultType()) {
7040 case DataType::Type::kInt32: {
7041 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
7042 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
7043 __ Sra(AT, in, 31);
7044 __ Xor(out, in, AT);
7045 __ Subu(out, out, AT);
7046 break;
7047 }
7048 case DataType::Type::kInt64: {
7049 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
7050 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
7051 __ Dsra32(AT, in, 31);
7052 __ Xor(out, in, AT);
7053 __ Dsubu(out, out, AT);
7054 break;
7055 }
7056 case DataType::Type::kFloat32: {
7057 FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>();
7058 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
7059 __ AbsS(out, in);
7060 break;
7061 }
7062 case DataType::Type::kFloat64: {
7063 FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>();
7064 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
7065 __ AbsD(out, in);
7066 break;
7067 }
7068 default:
7069 LOG(FATAL) << "Unexpected abs type " << abs->GetResultType();
7070 }
7071}
7072
Igor Murashkind01745e2017-04-05 16:40:31 -07007073void LocationsBuilderMIPS64::VisitConstructorFence(HConstructorFence* constructor_fence) {
7074 constructor_fence->SetLocations(nullptr);
7075}
7076
7077void InstructionCodeGeneratorMIPS64::VisitConstructorFence(
7078 HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) {
7079 GenerateMemoryBarrier(MemBarrierKind::kStoreStore);
7080}
7081
Alexey Frunze4dda3372015-06-01 18:31:49 -07007082void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
7083 memory_barrier->SetLocations(nullptr);
7084}
7085
7086void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
7087 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
7088}
7089
7090void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01007091 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007092 DataType::Type return_type = ret->InputAt(0)->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07007093 locations->SetInAt(0, Mips64ReturnLocation(return_type));
7094}
7095
7096void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
7097 codegen_->GenerateFrameExit();
7098}
7099
7100void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) {
7101 ret->SetLocations(nullptr);
7102}
7103
7104void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
7105 codegen_->GenerateFrameExit();
7106}
7107
Alexey Frunze92d90602015-12-18 18:16:36 -08007108void LocationsBuilderMIPS64::VisitRor(HRor* ror) {
7109 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00007110}
7111
Alexey Frunze92d90602015-12-18 18:16:36 -08007112void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) {
7113 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00007114}
7115
Alexey Frunze4dda3372015-06-01 18:31:49 -07007116void LocationsBuilderMIPS64::VisitShl(HShl* shl) {
7117 HandleShift(shl);
7118}
7119
7120void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) {
7121 HandleShift(shl);
7122}
7123
7124void LocationsBuilderMIPS64::VisitShr(HShr* shr) {
7125 HandleShift(shr);
7126}
7127
7128void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) {
7129 HandleShift(shr);
7130}
7131
Alexey Frunze4dda3372015-06-01 18:31:49 -07007132void LocationsBuilderMIPS64::VisitSub(HSub* instruction) {
7133 HandleBinaryOp(instruction);
7134}
7135
7136void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) {
7137 HandleBinaryOp(instruction);
7138}
7139
7140void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
7141 HandleFieldGet(instruction, instruction->GetFieldInfo());
7142}
7143
7144void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
7145 HandleFieldGet(instruction, instruction->GetFieldInfo());
7146}
7147
7148void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
7149 HandleFieldSet(instruction, instruction->GetFieldInfo());
7150}
7151
7152void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01007153 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Alexey Frunze4dda3372015-06-01 18:31:49 -07007154}
7155
Vladimir Marko552a1342017-10-31 10:56:47 +00007156void LocationsBuilderMIPS64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) {
7157 codegen_->CreateStringBuilderAppendLocations(instruction, Location::RegisterLocation(V0));
7158}
7159
7160void InstructionCodeGeneratorMIPS64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) {
7161 __ LoadConst32(A0, instruction->GetFormat()->GetValue());
7162 codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc());
7163}
7164
Calin Juravlee460d1d2015-09-29 04:52:17 +01007165void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet(
7166 HUnresolvedInstanceFieldGet* instruction) {
7167 FieldAccessCallingConventionMIPS64 calling_convention;
7168 codegen_->CreateUnresolvedFieldLocationSummary(
7169 instruction, instruction->GetFieldType(), calling_convention);
7170}
7171
7172void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet(
7173 HUnresolvedInstanceFieldGet* instruction) {
7174 FieldAccessCallingConventionMIPS64 calling_convention;
7175 codegen_->GenerateUnresolvedFieldAccess(instruction,
7176 instruction->GetFieldType(),
7177 instruction->GetFieldIndex(),
7178 instruction->GetDexPc(),
7179 calling_convention);
7180}
7181
7182void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet(
7183 HUnresolvedInstanceFieldSet* instruction) {
7184 FieldAccessCallingConventionMIPS64 calling_convention;
7185 codegen_->CreateUnresolvedFieldLocationSummary(
7186 instruction, instruction->GetFieldType(), calling_convention);
7187}
7188
7189void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet(
7190 HUnresolvedInstanceFieldSet* instruction) {
7191 FieldAccessCallingConventionMIPS64 calling_convention;
7192 codegen_->GenerateUnresolvedFieldAccess(instruction,
7193 instruction->GetFieldType(),
7194 instruction->GetFieldIndex(),
7195 instruction->GetDexPc(),
7196 calling_convention);
7197}
7198
7199void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet(
7200 HUnresolvedStaticFieldGet* instruction) {
7201 FieldAccessCallingConventionMIPS64 calling_convention;
7202 codegen_->CreateUnresolvedFieldLocationSummary(
7203 instruction, instruction->GetFieldType(), calling_convention);
7204}
7205
7206void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet(
7207 HUnresolvedStaticFieldGet* instruction) {
7208 FieldAccessCallingConventionMIPS64 calling_convention;
7209 codegen_->GenerateUnresolvedFieldAccess(instruction,
7210 instruction->GetFieldType(),
7211 instruction->GetFieldIndex(),
7212 instruction->GetDexPc(),
7213 calling_convention);
7214}
7215
7216void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet(
7217 HUnresolvedStaticFieldSet* instruction) {
7218 FieldAccessCallingConventionMIPS64 calling_convention;
7219 codegen_->CreateUnresolvedFieldLocationSummary(
7220 instruction, instruction->GetFieldType(), calling_convention);
7221}
7222
7223void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet(
7224 HUnresolvedStaticFieldSet* instruction) {
7225 FieldAccessCallingConventionMIPS64 calling_convention;
7226 codegen_->GenerateUnresolvedFieldAccess(instruction,
7227 instruction->GetFieldType(),
7228 instruction->GetFieldIndex(),
7229 instruction->GetDexPc(),
7230 calling_convention);
7231}
7232
Alexey Frunze4dda3372015-06-01 18:31:49 -07007233void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01007234 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
7235 instruction, LocationSummary::kCallOnSlowPath);
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02007236 // In suspend check slow path, usually there are no caller-save registers at all.
7237 // If SIMD instructions are present, however, we force spilling all live SIMD
7238 // registers in full width (since the runtime only saves/restores lower part).
7239 locations->SetCustomSlowPathCallerSaves(
7240 GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty());
Alexey Frunze4dda3372015-06-01 18:31:49 -07007241}
7242
7243void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
7244 HBasicBlock* block = instruction->GetBlock();
7245 if (block->GetLoopInformation() != nullptr) {
7246 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
7247 // The back edge will generate the suspend check.
7248 return;
7249 }
7250 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
7251 // The goto will generate the suspend check.
7252 return;
7253 }
7254 GenerateSuspendCheck(instruction, nullptr);
7255}
7256
Alexey Frunze4dda3372015-06-01 18:31:49 -07007257void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01007258 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
7259 instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007260 InvokeRuntimeCallingConvention calling_convention;
7261 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
7262}
7263
7264void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) {
Serban Constantinescufc734082016-07-19 17:18:07 +01007265 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Alexey Frunze4dda3372015-06-01 18:31:49 -07007266 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
7267}
7268
7269void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007270 DataType::Type input_type = conversion->GetInputType();
7271 DataType::Type result_type = conversion->GetResultType();
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01007272 DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type))
7273 << input_type << " -> " << result_type;
Alexey Frunze4dda3372015-06-01 18:31:49 -07007274
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007275 if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) ||
7276 (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07007277 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
7278 }
7279
Vladimir Markoca6fff82017-10-03 14:49:14 +01007280 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(conversion);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007281
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007282 if (DataType::IsFloatingPointType(input_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007283 locations->SetInAt(0, Location::RequiresFpuRegister());
7284 } else {
7285 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07007286 }
7287
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007288 if (DataType::IsFloatingPointType(result_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007289 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007290 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007291 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007292 }
7293}
7294
7295void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
7296 LocationSummary* locations = conversion->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007297 DataType::Type result_type = conversion->GetResultType();
7298 DataType::Type input_type = conversion->GetInputType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07007299
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01007300 DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type))
7301 << input_type << " -> " << result_type;
Alexey Frunze4dda3372015-06-01 18:31:49 -07007302
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007303 if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07007304 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
7305 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
7306
7307 switch (result_type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01007308 case DataType::Type::kUint8:
7309 __ Andi(dst, src, 0xFF);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007310 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007311 case DataType::Type::kInt8:
7312 if (input_type == DataType::Type::kInt64) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00007313 // Type conversion from long to types narrower than int is a result of code
7314 // transformations. To avoid unpredictable results for SEB and SEH, we first
7315 // need to sign-extend the low 32-bit value into bits 32 through 63.
7316 __ Sll(dst, src, 0);
7317 __ Seb(dst, dst);
7318 } else {
7319 __ Seb(dst, src);
7320 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07007321 break;
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01007322 case DataType::Type::kUint16:
7323 __ Andi(dst, src, 0xFFFF);
7324 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007325 case DataType::Type::kInt16:
7326 if (input_type == DataType::Type::kInt64) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00007327 // Type conversion from long to types narrower than int is a result of code
7328 // transformations. To avoid unpredictable results for SEB and SEH, we first
7329 // need to sign-extend the low 32-bit value into bits 32 through 63.
7330 __ Sll(dst, src, 0);
7331 __ Seh(dst, dst);
7332 } else {
7333 __ Seh(dst, src);
7334 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07007335 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007336 case DataType::Type::kInt32:
7337 case DataType::Type::kInt64:
Goran Jakovljevic992bdb92016-12-28 16:21:48 +01007338 // Sign-extend 32-bit int into bits 32 through 63 for int-to-long and long-to-int
7339 // conversions, except when the input and output registers are the same and we are not
7340 // converting longs to shorter types. In these cases, do nothing.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007341 if ((input_type == DataType::Type::kInt64) || (dst != src)) {
Goran Jakovljevic992bdb92016-12-28 16:21:48 +01007342 __ Sll(dst, src, 0);
7343 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07007344 break;
7345
7346 default:
7347 LOG(FATAL) << "Unexpected type conversion from " << input_type
7348 << " to " << result_type;
7349 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007350 } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007351 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
7352 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007353 if (input_type == DataType::Type::kInt64) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007354 __ Dmtc1(src, FTMP);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007355 if (result_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007356 __ Cvtsl(dst, FTMP);
7357 } else {
7358 __ Cvtdl(dst, FTMP);
7359 }
7360 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -07007361 __ Mtc1(src, FTMP);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007362 if (result_type == DataType::Type::kFloat32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07007363 __ Cvtsw(dst, FTMP);
7364 } else {
7365 __ Cvtdw(dst, FTMP);
7366 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07007367 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007368 } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) {
7369 CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007370 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
7371 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007372
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007373 if (result_type == DataType::Type::kInt64) {
7374 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007375 __ TruncLS(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00007376 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007377 __ TruncLD(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00007378 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007379 __ Dmfc1(dst, FTMP);
Roland Levillain888d0672015-11-23 18:53:50 +00007380 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007381 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007382 __ TruncWS(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00007383 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007384 __ TruncWD(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00007385 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08007386 __ Mfc1(dst, FTMP);
Roland Levillain888d0672015-11-23 18:53:50 +00007387 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007388 } else if (DataType::IsFloatingPointType(result_type) &&
7389 DataType::IsFloatingPointType(input_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07007390 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
7391 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01007392 if (result_type == DataType::Type::kFloat32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07007393 __ Cvtsd(dst, src);
7394 } else {
7395 __ Cvtds(dst, src);
7396 }
7397 } else {
7398 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
7399 << " to " << result_type;
7400 }
7401}
7402
7403void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) {
7404 HandleShift(ushr);
7405}
7406
7407void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) {
7408 HandleShift(ushr);
7409}
7410
7411void LocationsBuilderMIPS64::VisitXor(HXor* instruction) {
7412 HandleBinaryOp(instruction);
7413}
7414
7415void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) {
7416 HandleBinaryOp(instruction);
7417}
7418
7419void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
7420 // Nothing to do, this should be removed during prepare for register allocator.
7421 LOG(FATAL) << "Unreachable";
7422}
7423
7424void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
7425 // Nothing to do, this should be removed during prepare for register allocator.
7426 LOG(FATAL) << "Unreachable";
7427}
7428
7429void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007430 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007431}
7432
7433void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007434 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007435}
7436
7437void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007438 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007439}
7440
7441void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007442 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007443}
7444
7445void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007446 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007447}
7448
7449void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007450 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007451}
7452
7453void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007454 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007455}
7456
7457void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007458 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007459}
7460
7461void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007462 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007463}
7464
7465void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007466 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007467}
7468
7469void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007470 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007471}
7472
7473void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007474 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07007475}
7476
Aart Bike9f37602015-10-09 11:15:55 -07007477void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007478 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007479}
7480
7481void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007482 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007483}
7484
7485void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007486 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007487}
7488
7489void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007490 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007491}
7492
7493void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007494 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007495}
7496
7497void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007498 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007499}
7500
7501void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007502 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007503}
7504
7505void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00007506 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07007507}
7508
Mark Mendellfe57faa2015-09-18 09:26:15 -04007509// Simple implementation of packed switch - generate cascaded compare/jumps.
7510void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7511 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01007512 new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall);
Mark Mendellfe57faa2015-09-18 09:26:15 -04007513 locations->SetInAt(0, Location::RequiresRegister());
7514}
7515
Alexey Frunze0960ac52016-12-20 17:24:59 -08007516void InstructionCodeGeneratorMIPS64::GenPackedSwitchWithCompares(GpuRegister value_reg,
7517 int32_t lower_bound,
7518 uint32_t num_entries,
7519 HBasicBlock* switch_block,
7520 HBasicBlock* default_block) {
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007521 // Create a set of compare/jumps.
7522 GpuRegister temp_reg = TMP;
Alexey Frunze0960ac52016-12-20 17:24:59 -08007523 __ Addiu32(temp_reg, value_reg, -lower_bound);
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007524 // Jump to default if index is negative
7525 // Note: We don't check the case that index is positive while value < lower_bound, because in
7526 // this case, index >= num_entries must be true. So that we can save one branch instruction.
7527 __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block));
7528
Alexey Frunze0960ac52016-12-20 17:24:59 -08007529 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007530 // Jump to successors[0] if value == lower_bound.
7531 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0]));
7532 int32_t last_index = 0;
7533 for (; num_entries - last_index > 2; last_index += 2) {
7534 __ Addiu(temp_reg, temp_reg, -2);
7535 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
7536 __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
7537 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
7538 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
7539 }
7540 if (num_entries - last_index == 2) {
7541 // The last missing case_value.
7542 __ Addiu(temp_reg, temp_reg, -1);
7543 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Mark Mendellfe57faa2015-09-18 09:26:15 -04007544 }
7545
7546 // And the default for any other value.
Alexey Frunze0960ac52016-12-20 17:24:59 -08007547 if (!codegen_->GoesToNextBlock(switch_block, default_block)) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07007548 __ Bc(codegen_->GetLabelOf(default_block));
Mark Mendellfe57faa2015-09-18 09:26:15 -04007549 }
7550}
7551
Alexey Frunze0960ac52016-12-20 17:24:59 -08007552void InstructionCodeGeneratorMIPS64::GenTableBasedPackedSwitch(GpuRegister value_reg,
7553 int32_t lower_bound,
7554 uint32_t num_entries,
7555 HBasicBlock* switch_block,
7556 HBasicBlock* default_block) {
7557 // Create a jump table.
7558 std::vector<Mips64Label*> labels(num_entries);
7559 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
7560 for (uint32_t i = 0; i < num_entries; i++) {
7561 labels[i] = codegen_->GetLabelOf(successors[i]);
7562 }
7563 JumpTable* table = __ CreateJumpTable(std::move(labels));
7564
7565 // Is the value in range?
7566 __ Addiu32(TMP, value_reg, -lower_bound);
7567 __ LoadConst32(AT, num_entries);
7568 __ Bgeuc(TMP, AT, codegen_->GetLabelOf(default_block));
7569
7570 // We are in the range of the table.
7571 // Load the target address from the jump table, indexing by the value.
7572 __ LoadLabelAddress(AT, table->GetLabel());
Chris Larsencd0295d2017-03-31 15:26:54 -07007573 __ Dlsa(TMP, TMP, AT, 2);
Alexey Frunze0960ac52016-12-20 17:24:59 -08007574 __ Lw(TMP, TMP, 0);
7575 // Compute the absolute target address by adding the table start address
7576 // (the table contains offsets to targets relative to its start).
7577 __ Daddu(TMP, TMP, AT);
7578 // And jump.
7579 __ Jr(TMP);
7580 __ Nop();
7581}
7582
7583void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7584 int32_t lower_bound = switch_instr->GetStartValue();
7585 uint32_t num_entries = switch_instr->GetNumEntries();
7586 LocationSummary* locations = switch_instr->GetLocations();
7587 GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>();
7588 HBasicBlock* switch_block = switch_instr->GetBlock();
7589 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
7590
7591 if (num_entries > kPackedSwitchJumpTableThreshold) {
7592 GenTableBasedPackedSwitch(value_reg,
7593 lower_bound,
7594 num_entries,
7595 switch_block,
7596 default_block);
7597 } else {
7598 GenPackedSwitchWithCompares(value_reg,
7599 lower_bound,
7600 num_entries,
7601 switch_block,
7602 default_block);
7603 }
7604}
7605
Chris Larsenc9905a62017-03-13 17:06:18 -07007606void LocationsBuilderMIPS64::VisitClassTableGet(HClassTableGet* instruction) {
7607 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01007608 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Chris Larsenc9905a62017-03-13 17:06:18 -07007609 locations->SetInAt(0, Location::RequiresRegister());
7610 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007611}
7612
Chris Larsenc9905a62017-03-13 17:06:18 -07007613void InstructionCodeGeneratorMIPS64::VisitClassTableGet(HClassTableGet* instruction) {
7614 LocationSummary* locations = instruction->GetLocations();
7615 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
7616 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
7617 instruction->GetIndex(), kMips64PointerSize).SizeValue();
7618 __ LoadFromOffset(kLoadDoubleword,
7619 locations->Out().AsRegister<GpuRegister>(),
7620 locations->InAt(0).AsRegister<GpuRegister>(),
7621 method_offset);
7622 } else {
7623 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
7624 instruction->GetIndex(), kMips64PointerSize));
7625 __ LoadFromOffset(kLoadDoubleword,
7626 locations->Out().AsRegister<GpuRegister>(),
7627 locations->InAt(0).AsRegister<GpuRegister>(),
7628 mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value());
7629 __ LoadFromOffset(kLoadDoubleword,
7630 locations->Out().AsRegister<GpuRegister>(),
7631 locations->Out().AsRegister<GpuRegister>(),
7632 method_offset);
7633 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007634}
7635
xueliang.zhonge0eb4832017-10-30 13:43:14 +00007636void LocationsBuilderMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction
7637 ATTRIBUTE_UNUSED) {
7638 LOG(FATAL) << "Unreachable";
7639}
7640
7641void InstructionCodeGeneratorMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction
7642 ATTRIBUTE_UNUSED) {
7643 LOG(FATAL) << "Unreachable";
7644}
7645
Alexey Frunze4dda3372015-06-01 18:31:49 -07007646} // namespace mips64
7647} // namespace art