blob: 7ea7b9cee26b5f13ef1de4fe7365f410b049b415 [file] [log] [blame]
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "code_generator_mips.h"
18
Alexey Frunze4147fcc2017-06-17 19:57:27 -070019#include "arch/mips/asm_support_mips.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020020#include "arch/mips/entrypoints_direct_mips.h"
21#include "arch/mips/instruction_set_features_mips.h"
22#include "art_method.h"
Vladimir Marko94ec2db2017-09-06 17:21:03 +010023#include "class_table.h"
Chris Larsen701566a2015-10-27 15:29:13 -070024#include "code_generator_utils.h"
Vladimir Marko3a21e382016-09-02 12:38:38 +010025#include "compiled_method.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020026#include "entrypoints/quick/quick_entrypoints.h"
27#include "entrypoints/quick/quick_entrypoints_enum.h"
28#include "gc/accounting/card_table.h"
Andreas Gampe09659c22017-09-18 18:23:32 -070029#include "heap_poisoning.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020030#include "intrinsics.h"
Chris Larsen701566a2015-10-27 15:29:13 -070031#include "intrinsics_mips.h"
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010032#include "linker/linker_patch.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020033#include "mirror/array-inl.h"
34#include "mirror/class-inl.h"
35#include "offsets.h"
36#include "thread.h"
37#include "utils/assembler.h"
38#include "utils/mips/assembler_mips.h"
39#include "utils/stack_checks.h"
40
41namespace art {
42namespace mips {
43
44static constexpr int kCurrentMethodStackOffset = 0;
45static constexpr Register 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 MipsReturnLocation(DataType::Type return_type) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020053 switch (return_type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010054 case DataType::Type::kReference:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010055 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010056 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010057 case DataType::Type::kInt8:
58 case DataType::Type::kUint16:
59 case DataType::Type::kInt16:
60 case DataType::Type::kInt32:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020061 return Location::RegisterLocation(V0);
62
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010063 case DataType::Type::kInt64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020064 return Location::RegisterPairLocation(V0, V1);
65
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010066 case DataType::Type::kFloat32:
67 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020068 return Location::FpuRegisterLocation(F0);
69
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010070 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020071 return Location();
72 }
73 UNREACHABLE();
74}
75
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010076Location InvokeDexCallingConventionVisitorMIPS::GetReturnLocation(DataType::Type type) const {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020077 return MipsReturnLocation(type);
78}
79
80Location InvokeDexCallingConventionVisitorMIPS::GetMethodLocation() const {
81 return Location::RegisterLocation(kMethodRegisterArgument);
82}
83
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010084Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(DataType::Type type) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020085 Location next_location;
86
87 switch (type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010088 case DataType::Type::kReference:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010089 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010090 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010091 case DataType::Type::kInt8:
92 case DataType::Type::kUint16:
93 case DataType::Type::kInt16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +010094 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020095 uint32_t gp_index = gp_index_++;
96 if (gp_index < calling_convention.GetNumberOfRegisters()) {
97 next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index));
98 } else {
99 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
100 next_location = Location::StackSlot(stack_offset);
101 }
102 break;
103 }
104
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100105 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200106 uint32_t gp_index = gp_index_;
107 gp_index_ += 2;
108 if (gp_index + 1 < calling_convention.GetNumberOfRegisters()) {
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800109 Register reg = calling_convention.GetRegisterAt(gp_index);
110 if (reg == A1 || reg == A3) {
111 gp_index_++; // Skip A1(A3), and use A2_A3(T0_T1) instead.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200112 gp_index++;
113 }
114 Register low_even = calling_convention.GetRegisterAt(gp_index);
115 Register high_odd = calling_convention.GetRegisterAt(gp_index + 1);
116 DCHECK_EQ(low_even + 1, high_odd);
117 next_location = Location::RegisterPairLocation(low_even, high_odd);
118 } else {
119 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
120 next_location = Location::DoubleStackSlot(stack_offset);
121 }
122 break;
123 }
124
125 // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double
126 // will take up the even/odd pair, while floats are stored in even regs only.
127 // On 64 bit FPU, both double and float are stored in even registers only.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100128 case DataType::Type::kFloat32:
129 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200130 uint32_t float_index = float_index_++;
131 if (float_index < calling_convention.GetNumberOfFpuRegisters()) {
132 next_location = Location::FpuRegisterLocation(
133 calling_convention.GetFpuRegisterAt(float_index));
134 } else {
135 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100136 next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
137 : Location::StackSlot(stack_offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200138 }
139 break;
140 }
141
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100142 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200143 LOG(FATAL) << "Unexpected parameter type " << type;
144 break;
145 }
146
147 // Space on the stack is reserved for all arguments.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100148 stack_index_ += DataType::Is64BitType(type) ? 2 : 1;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200149
150 return next_location;
151}
152
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100153Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type type) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200154 return MipsReturnLocation(type);
155}
156
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100157// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
158#define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700159#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200160
161class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS {
162 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000163 explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200164
165 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
166 LocationSummary* locations = instruction_->GetLocations();
167 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
168 __ Bind(GetEntryLabel());
169 if (instruction_->CanThrowIntoCatchBlock()) {
170 // Live registers will be restored in the catch block if caught.
171 SaveLiveRegisters(codegen, instruction_->GetLocations());
172 }
173 // We're moving two locations to locations that could overlap, so we need a parallel
174 // move resolver.
175 InvokeRuntimeCallingConvention calling_convention;
176 codegen->EmitParallelMoves(locations->InAt(0),
177 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100178 DataType::Type::kInt32,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200179 locations->InAt(1),
180 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100181 DataType::Type::kInt32);
Serban Constantinescufca16662016-07-14 09:21:59 +0100182 QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt()
183 ? kQuickThrowStringBounds
184 : kQuickThrowArrayBounds;
185 mips_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100186 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200187 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
188 }
189
190 bool IsFatal() const OVERRIDE { return true; }
191
192 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; }
193
194 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200195 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS);
196};
197
198class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS {
199 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000200 explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200201
202 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
203 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
204 __ Bind(GetEntryLabel());
Serban Constantinescufca16662016-07-14 09:21:59 +0100205 mips_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200206 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
207 }
208
209 bool IsFatal() const OVERRIDE { return true; }
210
211 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; }
212
213 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200214 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS);
215};
216
217class LoadClassSlowPathMIPS : public SlowPathCodeMIPS {
218 public:
219 LoadClassSlowPathMIPS(HLoadClass* cls,
220 HInstruction* at,
221 uint32_t dex_pc,
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700222 bool do_clinit,
223 const CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high = nullptr)
224 : SlowPathCodeMIPS(at),
225 cls_(cls),
226 dex_pc_(dex_pc),
227 do_clinit_(do_clinit),
228 bss_info_high_(bss_info_high) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200229 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
230 }
231
232 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000233 LocationSummary* locations = instruction_->GetLocations();
Alexey Frunzec61c0762017-04-10 13:54:23 -0700234 Location out = locations->Out();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200235 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700236 const bool baker_or_no_read_barriers = (!kUseReadBarrier || kUseBakerReadBarrier);
Alexey Frunzec61c0762017-04-10 13:54:23 -0700237 InvokeRuntimeCallingConvention calling_convention;
238 DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_);
239 const bool is_load_class_bss_entry =
240 (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200241 __ Bind(GetEntryLabel());
242 SaveLiveRegisters(codegen, locations);
243
Alexey Frunzec61c0762017-04-10 13:54:23 -0700244 // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry.
245 Register entry_address = kNoRegister;
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700246 if (is_load_class_bss_entry && baker_or_no_read_barriers) {
Alexey Frunzec61c0762017-04-10 13:54:23 -0700247 Register temp = locations->GetTemp(0).AsRegister<Register>();
248 bool temp_is_a0 = (temp == calling_convention.GetRegisterAt(0));
249 // In the unlucky case that `temp` is A0, we preserve the address in `out` across the
250 // kSaveEverything call.
251 entry_address = temp_is_a0 ? out.AsRegister<Register>() : temp;
252 DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0));
253 if (temp_is_a0) {
254 __ Move(entry_address, temp);
255 }
256 }
257
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000258 dex::TypeIndex type_index = cls_->GetTypeIndex();
259 __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_);
Serban Constantinescufca16662016-07-14 09:21:59 +0100260 QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage
261 : kQuickInitializeType;
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000262 mips_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200263 if (do_clinit_) {
264 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
265 } else {
266 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
267 }
268
Alexey Frunzec61c0762017-04-10 13:54:23 -0700269 // For HLoadClass/kBssEntry, store the resolved class to the BSS entry.
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700270 if (is_load_class_bss_entry && baker_or_no_read_barriers) {
Alexey Frunzec61c0762017-04-10 13:54:23 -0700271 // The class entry address was preserved in `entry_address` thanks to kSaveEverything.
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700272 DCHECK(bss_info_high_);
273 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
274 mips_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index, bss_info_high_);
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700275 __ Sw(calling_convention.GetRegisterAt(0),
276 entry_address,
277 /* placeholder */ 0x5678,
278 &info_low->label);
Alexey Frunzec61c0762017-04-10 13:54:23 -0700279 }
280
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200281 // Move the class to the desired location.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200282 if (out.IsValid()) {
283 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100284 DataType::Type type = instruction_->GetType();
Alexey Frunzec61c0762017-04-10 13:54:23 -0700285 mips_codegen->MoveLocation(out,
286 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
287 type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200288 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200289 RestoreLiveRegisters(codegen, locations);
Alexey Frunzec61c0762017-04-10 13:54:23 -0700290
291 // For HLoadClass/kBssEntry, store the resolved class to the BSS entry.
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700292 if (is_load_class_bss_entry && !baker_or_no_read_barriers) {
293 // For non-Baker read barriers we need to re-calculate the address of
Alexey Frunzec61c0762017-04-10 13:54:23 -0700294 // the class entry.
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700295 const bool isR6 = mips_codegen->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +0200296 const bool has_irreducible_loops = codegen->GetGraph()->HasIrreducibleLoops();
297 Register base =
298 (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>();
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700299 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
Vladimir Marko1998cd02017-01-13 13:02:58 +0000300 mips_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index);
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700301 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
302 mips_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index, info_high);
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700303 mips_codegen->EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base);
304 __ Sw(out.AsRegister<Register>(), TMP, /* placeholder */ 0x5678, &info_low->label);
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000305 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200306 __ B(GetExitLabel());
307 }
308
309 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; }
310
311 private:
312 // The class this slow path will load.
313 HLoadClass* const cls_;
314
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200315 // The dex PC of `at_`.
316 const uint32_t dex_pc_;
317
318 // Whether to initialize the class.
319 const bool do_clinit_;
320
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700321 // Pointer to the high half PC-relative patch info for HLoadClass/kBssEntry.
322 const CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high_;
323
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200324 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS);
325};
326
327class LoadStringSlowPathMIPS : public SlowPathCodeMIPS {
328 public:
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700329 explicit LoadStringSlowPathMIPS(HLoadString* instruction,
330 const CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high)
331 : SlowPathCodeMIPS(instruction), bss_info_high_(bss_info_high) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200332
333 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexey Frunzec61c0762017-04-10 13:54:23 -0700334 DCHECK(instruction_->IsLoadString());
335 DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200336 LocationSummary* locations = instruction_->GetLocations();
337 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Alexey Frunzec61c0762017-04-10 13:54:23 -0700338 HLoadString* load = instruction_->AsLoadString();
339 const dex::StringIndex string_index = load->GetStringIndex();
340 Register out = locations->Out().AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200341 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700342 const bool baker_or_no_read_barriers = (!kUseReadBarrier || kUseBakerReadBarrier);
Alexey Frunzec61c0762017-04-10 13:54:23 -0700343 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200344 __ Bind(GetEntryLabel());
345 SaveLiveRegisters(codegen, locations);
346
Alexey Frunzec61c0762017-04-10 13:54:23 -0700347 // For HLoadString/kBssEntry/kSaveEverything, make sure we preserve the address of the entry.
348 Register entry_address = kNoRegister;
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700349 if (baker_or_no_read_barriers) {
Alexey Frunzec61c0762017-04-10 13:54:23 -0700350 Register temp = locations->GetTemp(0).AsRegister<Register>();
351 bool temp_is_a0 = (temp == calling_convention.GetRegisterAt(0));
352 // In the unlucky case that `temp` is A0, we preserve the address in `out` across the
353 // kSaveEverything call.
354 entry_address = temp_is_a0 ? out : temp;
355 DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0));
356 if (temp_is_a0) {
357 __ Move(entry_address, temp);
358 }
359 }
360
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000361 __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_);
Serban Constantinescufca16662016-07-14 09:21:59 +0100362 mips_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200363 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Alexey Frunzec61c0762017-04-10 13:54:23 -0700364
365 // Store the resolved string to the BSS entry.
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700366 if (baker_or_no_read_barriers) {
Alexey Frunzec61c0762017-04-10 13:54:23 -0700367 // The string entry address was preserved in `entry_address` thanks to kSaveEverything.
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700368 DCHECK(bss_info_high_);
369 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100370 mips_codegen->NewStringBssEntryPatch(load->GetDexFile(), string_index, bss_info_high_);
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700371 __ Sw(calling_convention.GetRegisterAt(0),
372 entry_address,
373 /* placeholder */ 0x5678,
374 &info_low->label);
Alexey Frunzec61c0762017-04-10 13:54:23 -0700375 }
376
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100377 DataType::Type type = instruction_->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200378 mips_codegen->MoveLocation(locations->Out(),
Alexey Frunzec61c0762017-04-10 13:54:23 -0700379 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200380 type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200381 RestoreLiveRegisters(codegen, locations);
Vladimir Markoaad75c62016-10-03 08:46:48 +0000382
Alexey Frunzec61c0762017-04-10 13:54:23 -0700383 // Store the resolved string to the BSS entry.
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700384 if (!baker_or_no_read_barriers) {
385 // For non-Baker read barriers we need to re-calculate the address of
Alexey Frunzec61c0762017-04-10 13:54:23 -0700386 // the string entry.
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700387 const bool isR6 = mips_codegen->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +0200388 const bool has_irreducible_loops = codegen->GetGraph()->HasIrreducibleLoops();
389 Register base =
390 (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>();
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700391 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100392 mips_codegen->NewStringBssEntryPatch(load->GetDexFile(), string_index);
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700393 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100394 mips_codegen->NewStringBssEntryPatch(load->GetDexFile(), string_index, info_high);
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700395 mips_codegen->EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base);
396 __ Sw(out, TMP, /* placeholder */ 0x5678, &info_low->label);
Alexey Frunzec61c0762017-04-10 13:54:23 -0700397 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200398 __ B(GetExitLabel());
399 }
400
401 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; }
402
403 private:
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700404 // Pointer to the high half PC-relative patch info.
405 const CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high_;
406
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200407 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS);
408};
409
410class NullCheckSlowPathMIPS : public SlowPathCodeMIPS {
411 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000412 explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200413
414 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
415 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
416 __ Bind(GetEntryLabel());
417 if (instruction_->CanThrowIntoCatchBlock()) {
418 // Live registers will be restored in the catch block if caught.
419 SaveLiveRegisters(codegen, instruction_->GetLocations());
420 }
Serban Constantinescufca16662016-07-14 09:21:59 +0100421 mips_codegen->InvokeRuntime(kQuickThrowNullPointer,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200422 instruction_,
423 instruction_->GetDexPc(),
Serban Constantinescufca16662016-07-14 09:21:59 +0100424 this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200425 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
426 }
427
428 bool IsFatal() const OVERRIDE { return true; }
429
430 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; }
431
432 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200433 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS);
434};
435
436class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS {
437 public:
438 SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000439 : SlowPathCodeMIPS(instruction), successor_(successor) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200440
441 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Lena Djokicca8c2952017-05-29 11:31:46 +0200442 LocationSummary* locations = instruction_->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200443 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
444 __ Bind(GetEntryLabel());
Lena Djokicca8c2952017-05-29 11:31:46 +0200445 SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD.
Serban Constantinescufca16662016-07-14 09:21:59 +0100446 mips_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200447 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Lena Djokicca8c2952017-05-29 11:31:46 +0200448 RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200449 if (successor_ == nullptr) {
450 __ B(GetReturnLabel());
451 } else {
452 __ B(mips_codegen->GetLabelOf(successor_));
453 }
454 }
455
456 MipsLabel* GetReturnLabel() {
457 DCHECK(successor_ == nullptr);
458 return &return_label_;
459 }
460
461 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; }
462
463 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200464 // If not null, the block to branch to after the suspend check.
465 HBasicBlock* const successor_;
466
467 // If `successor_` is null, the label to branch to after the suspend check.
468 MipsLabel return_label_;
469
470 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS);
471};
472
473class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS {
474 public:
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800475 explicit TypeCheckSlowPathMIPS(HInstruction* instruction, bool is_fatal)
476 : SlowPathCodeMIPS(instruction), is_fatal_(is_fatal) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200477
478 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
479 LocationSummary* locations = instruction_->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200480 uint32_t dex_pc = instruction_->GetDexPc();
481 DCHECK(instruction_->IsCheckCast()
482 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
483 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
484
485 __ Bind(GetEntryLabel());
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800486 if (!is_fatal_) {
487 SaveLiveRegisters(codegen, locations);
488 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200489
490 // We're moving two locations to locations that could overlap, so we need a parallel
491 // move resolver.
492 InvokeRuntimeCallingConvention calling_convention;
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800493 codegen->EmitParallelMoves(locations->InAt(0),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200494 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100495 DataType::Type::kReference,
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800496 locations->InAt(1),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200497 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100498 DataType::Type::kReference);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200499 if (instruction_->IsInstanceOf()) {
Serban Constantinescufca16662016-07-14 09:21:59 +0100500 mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this);
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800501 CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100502 DataType::Type ret_type = instruction_->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200503 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
504 mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200505 } else {
506 DCHECK(instruction_->IsCheckCast());
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800507 mips_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this);
508 CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200509 }
510
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800511 if (!is_fatal_) {
512 RestoreLiveRegisters(codegen, locations);
513 __ B(GetExitLabel());
514 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200515 }
516
517 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; }
518
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800519 bool IsFatal() const OVERRIDE { return is_fatal_; }
520
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200521 private:
Alexey Frunze66b69ad2017-02-24 00:51:44 -0800522 const bool is_fatal_;
523
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200524 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS);
525};
526
527class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS {
528 public:
Aart Bik42249c32016-01-07 15:33:50 -0800529 explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000530 : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200531
532 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800533 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200534 __ Bind(GetEntryLabel());
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +0100535 LocationSummary* locations = instruction_->GetLocations();
536 SaveLiveRegisters(codegen, locations);
537 InvokeRuntimeCallingConvention calling_convention;
538 __ LoadConst32(calling_convention.GetRegisterAt(0),
539 static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind()));
Serban Constantinescufca16662016-07-14 09:21:59 +0100540 mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +0100541 CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200542 }
543
544 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; }
545
546 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200547 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS);
548};
549
Alexey Frunze15958152017-02-09 19:08:30 -0800550class ArraySetSlowPathMIPS : public SlowPathCodeMIPS {
551 public:
552 explicit ArraySetSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {}
553
554 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
555 LocationSummary* locations = instruction_->GetLocations();
556 __ Bind(GetEntryLabel());
557 SaveLiveRegisters(codegen, locations);
558
559 InvokeRuntimeCallingConvention calling_convention;
Vladimir Markoca6fff82017-10-03 14:49:14 +0100560 HParallelMove parallel_move(codegen->GetGraph()->GetAllocator());
Alexey Frunze15958152017-02-09 19:08:30 -0800561 parallel_move.AddMove(
562 locations->InAt(0),
563 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100564 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800565 nullptr);
566 parallel_move.AddMove(
567 locations->InAt(1),
568 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100569 DataType::Type::kInt32,
Alexey Frunze15958152017-02-09 19:08:30 -0800570 nullptr);
571 parallel_move.AddMove(
572 locations->InAt(2),
573 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100574 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800575 nullptr);
576 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
577
578 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
579 mips_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this);
580 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
581 RestoreLiveRegisters(codegen, locations);
582 __ B(GetExitLabel());
583 }
584
585 const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS"; }
586
587 private:
588 DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS);
589};
590
591// Slow path marking an object reference `ref` during a read
592// barrier. The field `obj.field` in the object `obj` holding this
593// reference does not get updated by this slow path after marking (see
594// ReadBarrierMarkAndUpdateFieldSlowPathMIPS below for that).
595//
596// This means that after the execution of this slow path, `ref` will
597// always be up-to-date, but `obj.field` may not; i.e., after the
598// flip, `ref` will be a to-space reference, but `obj.field` will
599// probably still be a from-space reference (unless it gets updated by
600// another thread, or if another thread installed another object
601// reference (different from `ref`) in `obj.field`).
602//
603// If `entrypoint` is a valid location it is assumed to already be
604// holding the entrypoint. The case where the entrypoint is passed in
605// is for the GcRoot read barrier.
606class ReadBarrierMarkSlowPathMIPS : public SlowPathCodeMIPS {
607 public:
608 ReadBarrierMarkSlowPathMIPS(HInstruction* instruction,
609 Location ref,
610 Location entrypoint = Location::NoLocation())
611 : SlowPathCodeMIPS(instruction), ref_(ref), entrypoint_(entrypoint) {
612 DCHECK(kEmitCompilerReadBarrier);
613 }
614
615 const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; }
616
617 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
618 LocationSummary* locations = instruction_->GetLocations();
619 Register ref_reg = ref_.AsRegister<Register>();
620 DCHECK(locations->CanCall());
621 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg;
622 DCHECK(instruction_->IsInstanceFieldGet() ||
623 instruction_->IsStaticFieldGet() ||
624 instruction_->IsArrayGet() ||
625 instruction_->IsArraySet() ||
626 instruction_->IsLoadClass() ||
627 instruction_->IsLoadString() ||
628 instruction_->IsInstanceOf() ||
629 instruction_->IsCheckCast() ||
630 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) ||
631 (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified()))
632 << "Unexpected instruction in read barrier marking slow path: "
633 << instruction_->DebugName();
634
635 __ Bind(GetEntryLabel());
636 // No need to save live registers; it's taken care of by the
637 // entrypoint. Also, there is no need to update the stack mask,
638 // as this runtime call will not trigger a garbage collection.
639 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
640 DCHECK((V0 <= ref_reg && ref_reg <= T7) ||
641 (S2 <= ref_reg && ref_reg <= S7) ||
642 (ref_reg == FP)) << ref_reg;
643 // "Compact" slow path, saving two moves.
644 //
645 // Instead of using the standard runtime calling convention (input
646 // and output in A0 and V0 respectively):
647 //
648 // A0 <- ref
649 // V0 <- ReadBarrierMark(A0)
650 // ref <- V0
651 //
652 // we just use rX (the register containing `ref`) as input and output
653 // of a dedicated entrypoint:
654 //
655 // rX <- ReadBarrierMarkRegX(rX)
656 //
657 if (entrypoint_.IsValid()) {
658 mips_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this);
659 DCHECK_EQ(entrypoint_.AsRegister<Register>(), T9);
660 __ Jalr(entrypoint_.AsRegister<Register>());
661 __ NopIfNoReordering();
662 } else {
663 int32_t entry_point_offset =
Roland Levillain97c46462017-05-11 14:04:03 +0100664 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1);
Alexey Frunze15958152017-02-09 19:08:30 -0800665 // This runtime call does not require a stack map.
666 mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset,
667 instruction_,
668 this,
669 /* direct */ false);
670 }
671 __ B(GetExitLabel());
672 }
673
674 private:
675 // The location (register) of the marked object reference.
676 const Location ref_;
677
678 // The location of the entrypoint if already loaded.
679 const Location entrypoint_;
680
681 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS);
682};
683
684// Slow path marking an object reference `ref` during a read barrier,
685// and if needed, atomically updating the field `obj.field` in the
686// object `obj` holding this reference after marking (contrary to
687// ReadBarrierMarkSlowPathMIPS above, which never tries to update
688// `obj.field`).
689//
690// This means that after the execution of this slow path, both `ref`
691// and `obj.field` will be up-to-date; i.e., after the flip, both will
692// hold the same to-space reference (unless another thread installed
693// another object reference (different from `ref`) in `obj.field`).
694class ReadBarrierMarkAndUpdateFieldSlowPathMIPS : public SlowPathCodeMIPS {
695 public:
696 ReadBarrierMarkAndUpdateFieldSlowPathMIPS(HInstruction* instruction,
697 Location ref,
698 Register obj,
699 Location field_offset,
700 Register temp1)
701 : SlowPathCodeMIPS(instruction),
702 ref_(ref),
703 obj_(obj),
704 field_offset_(field_offset),
705 temp1_(temp1) {
706 DCHECK(kEmitCompilerReadBarrier);
707 }
708
709 const char* GetDescription() const OVERRIDE {
710 return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS";
711 }
712
713 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
714 LocationSummary* locations = instruction_->GetLocations();
715 Register ref_reg = ref_.AsRegister<Register>();
716 DCHECK(locations->CanCall());
717 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg;
718 // This slow path is only used by the UnsafeCASObject intrinsic.
719 DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()))
720 << "Unexpected instruction in read barrier marking and field updating slow path: "
721 << instruction_->DebugName();
722 DCHECK(instruction_->GetLocations()->Intrinsified());
723 DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject);
724 DCHECK(field_offset_.IsRegisterPair()) << field_offset_;
725
726 __ Bind(GetEntryLabel());
727
728 // Save the old reference.
729 // Note that we cannot use AT or TMP to save the old reference, as those
730 // are used by the code that follows, but we need the old reference after
731 // the call to the ReadBarrierMarkRegX entry point.
732 DCHECK_NE(temp1_, AT);
733 DCHECK_NE(temp1_, TMP);
734 __ Move(temp1_, ref_reg);
735
736 // No need to save live registers; it's taken care of by the
737 // entrypoint. Also, there is no need to update the stack mask,
738 // as this runtime call will not trigger a garbage collection.
739 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
740 DCHECK((V0 <= ref_reg && ref_reg <= T7) ||
741 (S2 <= ref_reg && ref_reg <= S7) ||
742 (ref_reg == FP)) << ref_reg;
743 // "Compact" slow path, saving two moves.
744 //
745 // Instead of using the standard runtime calling convention (input
746 // and output in A0 and V0 respectively):
747 //
748 // A0 <- ref
749 // V0 <- ReadBarrierMark(A0)
750 // ref <- V0
751 //
752 // we just use rX (the register containing `ref`) as input and output
753 // of a dedicated entrypoint:
754 //
755 // rX <- ReadBarrierMarkRegX(rX)
756 //
757 int32_t entry_point_offset =
Roland Levillain97c46462017-05-11 14:04:03 +0100758 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1);
Alexey Frunze15958152017-02-09 19:08:30 -0800759 // This runtime call does not require a stack map.
760 mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset,
761 instruction_,
762 this,
763 /* direct */ false);
764
765 // If the new reference is different from the old reference,
766 // update the field in the holder (`*(obj_ + field_offset_)`).
767 //
768 // Note that this field could also hold a different object, if
769 // another thread had concurrently changed it. In that case, the
770 // the compare-and-set (CAS) loop below would abort, leaving the
771 // field as-is.
772 MipsLabel done;
773 __ Beq(temp1_, ref_reg, &done);
774
775 // Update the the holder's field atomically. This may fail if
776 // mutator updates before us, but it's OK. This is achieved
777 // using a strong compare-and-set (CAS) operation with relaxed
778 // memory synchronization ordering, where the expected value is
779 // the old reference and the desired value is the new reference.
780
781 // Convenience aliases.
782 Register base = obj_;
783 // The UnsafeCASObject intrinsic uses a register pair as field
784 // offset ("long offset"), of which only the low part contains
785 // data.
786 Register offset = field_offset_.AsRegisterPairLow<Register>();
787 Register expected = temp1_;
788 Register value = ref_reg;
789 Register tmp_ptr = TMP; // Pointer to actual memory.
790 Register tmp = AT; // Value in memory.
791
792 __ Addu(tmp_ptr, base, offset);
793
794 if (kPoisonHeapReferences) {
795 __ PoisonHeapReference(expected);
796 // Do not poison `value` if it is the same register as
797 // `expected`, which has just been poisoned.
798 if (value != expected) {
799 __ PoisonHeapReference(value);
800 }
801 }
802
803 // do {
804 // tmp = [r_ptr] - expected;
805 // } while (tmp == 0 && failure([r_ptr] <- r_new_value));
806
807 bool is_r6 = mips_codegen->GetInstructionSetFeatures().IsR6();
808 MipsLabel loop_head, exit_loop;
809 __ Bind(&loop_head);
810 if (is_r6) {
811 __ LlR6(tmp, tmp_ptr);
812 } else {
813 __ LlR2(tmp, tmp_ptr);
814 }
815 __ Bne(tmp, expected, &exit_loop);
816 __ Move(tmp, value);
817 if (is_r6) {
818 __ ScR6(tmp, tmp_ptr);
819 } else {
820 __ ScR2(tmp, tmp_ptr);
821 }
822 __ Beqz(tmp, &loop_head);
823 __ Bind(&exit_loop);
824
825 if (kPoisonHeapReferences) {
826 __ UnpoisonHeapReference(expected);
827 // Do not unpoison `value` if it is the same register as
828 // `expected`, which has just been unpoisoned.
829 if (value != expected) {
830 __ UnpoisonHeapReference(value);
831 }
832 }
833
834 __ Bind(&done);
835 __ B(GetExitLabel());
836 }
837
838 private:
839 // The location (register) of the marked object reference.
840 const Location ref_;
841 // The register containing the object holding the marked object reference field.
842 const Register obj_;
843 // The location of the offset of the marked reference field within `obj_`.
844 Location field_offset_;
845
846 const Register temp1_;
847
848 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS);
849};
850
851// Slow path generating a read barrier for a heap reference.
852class ReadBarrierForHeapReferenceSlowPathMIPS : public SlowPathCodeMIPS {
853 public:
854 ReadBarrierForHeapReferenceSlowPathMIPS(HInstruction* instruction,
855 Location out,
856 Location ref,
857 Location obj,
858 uint32_t offset,
859 Location index)
860 : SlowPathCodeMIPS(instruction),
861 out_(out),
862 ref_(ref),
863 obj_(obj),
864 offset_(offset),
865 index_(index) {
866 DCHECK(kEmitCompilerReadBarrier);
867 // If `obj` is equal to `out` or `ref`, it means the initial object
868 // has been overwritten by (or after) the heap object reference load
869 // to be instrumented, e.g.:
870 //
871 // __ LoadFromOffset(kLoadWord, out, out, offset);
872 // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset);
873 //
874 // In that case, we have lost the information about the original
875 // object, and the emitted read barrier cannot work properly.
876 DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out;
877 DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref;
878 }
879
880 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
881 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
882 LocationSummary* locations = instruction_->GetLocations();
883 Register reg_out = out_.AsRegister<Register>();
884 DCHECK(locations->CanCall());
885 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
886 DCHECK(instruction_->IsInstanceFieldGet() ||
887 instruction_->IsStaticFieldGet() ||
888 instruction_->IsArrayGet() ||
889 instruction_->IsInstanceOf() ||
890 instruction_->IsCheckCast() ||
891 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()))
892 << "Unexpected instruction in read barrier for heap reference slow path: "
893 << instruction_->DebugName();
894
895 __ Bind(GetEntryLabel());
896 SaveLiveRegisters(codegen, locations);
897
898 // We may have to change the index's value, but as `index_` is a
899 // constant member (like other "inputs" of this slow path),
900 // introduce a copy of it, `index`.
901 Location index = index_;
902 if (index_.IsValid()) {
903 // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
904 if (instruction_->IsArrayGet()) {
905 // Compute the actual memory offset and store it in `index`.
906 Register index_reg = index_.AsRegister<Register>();
907 DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg));
908 if (codegen->IsCoreCalleeSaveRegister(index_reg)) {
909 // We are about to change the value of `index_reg` (see the
910 // calls to art::mips::MipsAssembler::Sll and
911 // art::mips::MipsAssembler::Addiu32 below), but it has
912 // not been saved by the previous call to
913 // art::SlowPathCode::SaveLiveRegisters, as it is a
914 // callee-save register --
915 // art::SlowPathCode::SaveLiveRegisters does not consider
916 // callee-save registers, as it has been designed with the
917 // assumption that callee-save registers are supposed to be
918 // handled by the called function. So, as a callee-save
919 // register, `index_reg` _would_ eventually be saved onto
920 // the stack, but it would be too late: we would have
921 // changed its value earlier. Therefore, we manually save
922 // it here into another freely available register,
923 // `free_reg`, chosen of course among the caller-save
924 // registers (as a callee-save `free_reg` register would
925 // exhibit the same problem).
926 //
927 // Note we could have requested a temporary register from
928 // the register allocator instead; but we prefer not to, as
929 // this is a slow path, and we know we can find a
930 // caller-save register that is available.
931 Register free_reg = FindAvailableCallerSaveRegister(codegen);
932 __ Move(free_reg, index_reg);
933 index_reg = free_reg;
934 index = Location::RegisterLocation(index_reg);
935 } else {
936 // The initial register stored in `index_` has already been
937 // saved in the call to art::SlowPathCode::SaveLiveRegisters
938 // (as it is not a callee-save register), so we can freely
939 // use it.
940 }
941 // Shifting the index value contained in `index_reg` by the scale
942 // factor (2) cannot overflow in practice, as the runtime is
943 // unable to allocate object arrays with a size larger than
944 // 2^26 - 1 (that is, 2^28 - 4 bytes).
945 __ Sll(index_reg, index_reg, TIMES_4);
946 static_assert(
947 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
948 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
949 __ Addiu32(index_reg, index_reg, offset_);
950 } else {
951 // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile
952 // intrinsics, `index_` is not shifted by a scale factor of 2
953 // (as in the case of ArrayGet), as it is actually an offset
954 // to an object field within an object.
955 DCHECK(instruction_->IsInvoke()) << instruction_->DebugName();
956 DCHECK(instruction_->GetLocations()->Intrinsified());
957 DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) ||
958 (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile))
959 << instruction_->AsInvoke()->GetIntrinsic();
960 DCHECK_EQ(offset_, 0U);
961 DCHECK(index_.IsRegisterPair());
962 // UnsafeGet's offset location is a register pair, the low
963 // part contains the correct offset.
964 index = index_.ToLow();
965 }
966 }
967
968 // We're moving two or three locations to locations that could
969 // overlap, so we need a parallel move resolver.
970 InvokeRuntimeCallingConvention calling_convention;
Vladimir Markoca6fff82017-10-03 14:49:14 +0100971 HParallelMove parallel_move(codegen->GetGraph()->GetAllocator());
Alexey Frunze15958152017-02-09 19:08:30 -0800972 parallel_move.AddMove(ref_,
973 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100974 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800975 nullptr);
976 parallel_move.AddMove(obj_,
977 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100978 DataType::Type::kReference,
Alexey Frunze15958152017-02-09 19:08:30 -0800979 nullptr);
980 if (index.IsValid()) {
981 parallel_move.AddMove(index,
982 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100983 DataType::Type::kInt32,
Alexey Frunze15958152017-02-09 19:08:30 -0800984 nullptr);
985 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
986 } else {
987 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
988 __ LoadConst32(calling_convention.GetRegisterAt(2), offset_);
989 }
990 mips_codegen->InvokeRuntime(kQuickReadBarrierSlow,
991 instruction_,
992 instruction_->GetDexPc(),
993 this);
994 CheckEntrypointTypes<
995 kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>();
Lena Djokic8098da92017-06-28 12:07:50 +0200996 mips_codegen->MoveLocation(out_,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100997 calling_convention.GetReturnLocation(DataType::Type::kReference),
998 DataType::Type::kReference);
Alexey Frunze15958152017-02-09 19:08:30 -0800999
1000 RestoreLiveRegisters(codegen, locations);
1001 __ B(GetExitLabel());
1002 }
1003
1004 const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathMIPS"; }
1005
1006 private:
1007 Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) {
1008 size_t ref = static_cast<int>(ref_.AsRegister<Register>());
1009 size_t obj = static_cast<int>(obj_.AsRegister<Register>());
1010 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
1011 if (i != ref &&
1012 i != obj &&
1013 !codegen->IsCoreCalleeSaveRegister(i) &&
1014 !codegen->IsBlockedCoreRegister(i)) {
1015 return static_cast<Register>(i);
1016 }
1017 }
1018 // We shall never fail to find a free caller-save register, as
1019 // there are more than two core caller-save registers on MIPS
1020 // (meaning it is possible to find one which is different from
1021 // `ref` and `obj`).
1022 DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u);
1023 LOG(FATAL) << "Could not find a free caller-save register";
1024 UNREACHABLE();
1025 }
1026
1027 const Location out_;
1028 const Location ref_;
1029 const Location obj_;
1030 const uint32_t offset_;
1031 // An additional location containing an index to an array.
1032 // Only used for HArrayGet and the UnsafeGetObject &
1033 // UnsafeGetObjectVolatile intrinsics.
1034 const Location index_;
1035
1036 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS);
1037};
1038
1039// Slow path generating a read barrier for a GC root.
1040class ReadBarrierForRootSlowPathMIPS : public SlowPathCodeMIPS {
1041 public:
1042 ReadBarrierForRootSlowPathMIPS(HInstruction* instruction, Location out, Location root)
1043 : SlowPathCodeMIPS(instruction), out_(out), root_(root) {
1044 DCHECK(kEmitCompilerReadBarrier);
1045 }
1046
1047 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
1048 LocationSummary* locations = instruction_->GetLocations();
1049 Register reg_out = out_.AsRegister<Register>();
1050 DCHECK(locations->CanCall());
1051 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
1052 DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString())
1053 << "Unexpected instruction in read barrier for GC root slow path: "
1054 << instruction_->DebugName();
1055
1056 __ Bind(GetEntryLabel());
1057 SaveLiveRegisters(codegen, locations);
1058
1059 InvokeRuntimeCallingConvention calling_convention;
1060 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Lena Djokic8098da92017-06-28 12:07:50 +02001061 mips_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
1062 root_,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001063 DataType::Type::kReference);
Alexey Frunze15958152017-02-09 19:08:30 -08001064 mips_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow,
1065 instruction_,
1066 instruction_->GetDexPc(),
1067 this);
1068 CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>();
Lena Djokic8098da92017-06-28 12:07:50 +02001069 mips_codegen->MoveLocation(out_,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001070 calling_convention.GetReturnLocation(DataType::Type::kReference),
1071 DataType::Type::kReference);
Alexey Frunze15958152017-02-09 19:08:30 -08001072
1073 RestoreLiveRegisters(codegen, locations);
1074 __ B(GetExitLabel());
1075 }
1076
1077 const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS"; }
1078
1079 private:
1080 const Location out_;
1081 const Location root_;
1082
1083 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS);
1084};
1085
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001086CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph,
1087 const MipsInstructionSetFeatures& isa_features,
1088 const CompilerOptions& compiler_options,
1089 OptimizingCompilerStats* stats)
1090 : CodeGenerator(graph,
1091 kNumberOfCoreRegisters,
1092 kNumberOfFRegisters,
1093 kNumberOfRegisterPairs,
1094 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
1095 arraysize(kCoreCalleeSaves)),
1096 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
1097 arraysize(kFpuCalleeSaves)),
1098 compiler_options,
1099 stats),
1100 block_labels_(nullptr),
1101 location_builder_(graph, this),
1102 instruction_visitor_(graph, this),
Vladimir Markoca6fff82017-10-03 14:49:14 +01001103 move_resolver_(graph->GetAllocator(), this),
1104 assembler_(graph->GetAllocator(), &isa_features),
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001105 isa_features_(isa_features),
Alexey Frunze06a46c42016-07-19 15:00:40 -07001106 uint32_literals_(std::less<uint32_t>(),
Vladimir Markoca6fff82017-10-03 14:49:14 +01001107 graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1108 pc_relative_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1109 method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1110 pc_relative_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1111 type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1112 pc_relative_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1113 string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1114 jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
1115 jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze06a46c42016-07-19 15:00:40 -07001116 clobbered_ra_(false) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001117 // Save RA (containing the return address) to mimic Quick.
1118 AddAllocatedRegister(Location::RegisterLocation(RA));
1119}
1120
1121#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +01001122// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
1123#define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -07001124#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001125
1126void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) {
1127 // Ensure that we fix up branches.
1128 __ FinalizeCode();
1129
1130 // Adjust native pc offsets in stack maps.
1131 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
Mathieu Chartiera2f526f2017-01-19 14:48:48 -08001132 uint32_t old_position =
1133 stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kMips);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001134 uint32_t new_position = __ GetAdjustedPosition(old_position);
1135 DCHECK_GE(new_position, old_position);
1136 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
1137 }
1138
1139 // Adjust pc offsets for the disassembly information.
1140 if (disasm_info_ != nullptr) {
1141 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
1142 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
1143 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
1144 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
1145 it.second.start = __ GetAdjustedPosition(it.second.start);
1146 it.second.end = __ GetAdjustedPosition(it.second.end);
1147 }
1148 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
1149 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
1150 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
1151 }
1152 }
1153
1154 CodeGenerator::Finalize(allocator);
1155}
1156
1157MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const {
1158 return codegen_->GetAssembler();
1159}
1160
1161void ParallelMoveResolverMIPS::EmitMove(size_t index) {
1162 DCHECK_LT(index, moves_.size());
1163 MoveOperands* move = moves_[index];
1164 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
1165}
1166
1167void ParallelMoveResolverMIPS::EmitSwap(size_t index) {
1168 DCHECK_LT(index, moves_.size());
1169 MoveOperands* move = moves_[index];
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001170 DataType::Type type = move->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001171 Location loc1 = move->GetDestination();
1172 Location loc2 = move->GetSource();
1173
1174 DCHECK(!loc1.IsConstant());
1175 DCHECK(!loc2.IsConstant());
1176
1177 if (loc1.Equals(loc2)) {
1178 return;
1179 }
1180
1181 if (loc1.IsRegister() && loc2.IsRegister()) {
1182 // Swap 2 GPRs.
1183 Register r1 = loc1.AsRegister<Register>();
1184 Register r2 = loc2.AsRegister<Register>();
1185 __ Move(TMP, r2);
1186 __ Move(r2, r1);
1187 __ Move(r1, TMP);
1188 } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) {
1189 FRegister f1 = loc1.AsFpuRegister<FRegister>();
1190 FRegister f2 = loc2.AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001191 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001192 __ MovS(FTMP, f2);
1193 __ MovS(f2, f1);
1194 __ MovS(f1, FTMP);
1195 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001196 DCHECK_EQ(type, DataType::Type::kFloat64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001197 __ MovD(FTMP, f2);
1198 __ MovD(f2, f1);
1199 __ MovD(f1, FTMP);
1200 }
1201 } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) ||
1202 (loc1.IsFpuRegister() && loc2.IsRegister())) {
1203 // Swap FPR and GPR.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001204 DCHECK_EQ(type, DataType::Type::kFloat32); // Can only swap a float.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001205 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
1206 : loc2.AsFpuRegister<FRegister>();
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001207 Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001208 __ Move(TMP, r2);
1209 __ Mfc1(r2, f1);
1210 __ Mtc1(TMP, f1);
1211 } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) {
1212 // Swap 2 GPR register pairs.
1213 Register r1 = loc1.AsRegisterPairLow<Register>();
1214 Register r2 = loc2.AsRegisterPairLow<Register>();
1215 __ Move(TMP, r2);
1216 __ Move(r2, r1);
1217 __ Move(r1, TMP);
1218 r1 = loc1.AsRegisterPairHigh<Register>();
1219 r2 = loc2.AsRegisterPairHigh<Register>();
1220 __ Move(TMP, r2);
1221 __ Move(r2, r1);
1222 __ Move(r1, TMP);
1223 } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) ||
1224 (loc1.IsFpuRegister() && loc2.IsRegisterPair())) {
1225 // Swap FPR and GPR register pair.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001226 DCHECK_EQ(type, DataType::Type::kFloat64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001227 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
1228 : loc2.AsFpuRegister<FRegister>();
1229 Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
1230 : loc2.AsRegisterPairLow<Register>();
1231 Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
1232 : loc2.AsRegisterPairHigh<Register>();
1233 // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and
1234 // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR
1235 // unpredictable and the following mfch1 will fail.
1236 __ Mfc1(TMP, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -08001237 __ MoveFromFpuHigh(AT, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001238 __ Mtc1(r2_l, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -08001239 __ MoveToFpuHigh(r2_h, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001240 __ Move(r2_l, TMP);
1241 __ Move(r2_h, AT);
1242 } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) {
1243 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false);
1244 } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) {
1245 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true);
David Brazdilcc0f3112016-01-28 17:14:52 +00001246 } else if ((loc1.IsRegister() && loc2.IsStackSlot()) ||
1247 (loc1.IsStackSlot() && loc2.IsRegister())) {
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001248 Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>();
1249 intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex();
David Brazdilcc0f3112016-01-28 17:14:52 +00001250 __ Move(TMP, reg);
1251 __ LoadFromOffset(kLoadWord, reg, SP, offset);
1252 __ StoreToOffset(kStoreWord, TMP, SP, offset);
1253 } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) ||
1254 (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) {
1255 Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
1256 : loc2.AsRegisterPairLow<Register>();
1257 Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
1258 : loc2.AsRegisterPairHigh<Register>();
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001259 intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex();
David Brazdilcc0f3112016-01-28 17:14:52 +00001260 intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize)
1261 : loc2.GetHighStackIndex(kMipsWordSize);
1262 __ Move(TMP, reg_l);
David Brazdilcc0f3112016-01-28 17:14:52 +00001263 __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l);
David Brazdilcc0f3112016-01-28 17:14:52 +00001264 __ StoreToOffset(kStoreWord, TMP, SP, offset_l);
David Brazdil04d3e872016-01-29 09:50:09 +00001265 __ Move(TMP, reg_h);
1266 __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h);
1267 __ StoreToOffset(kStoreWord, TMP, SP, offset_h);
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001268 } else if (loc1.IsFpuRegister() || loc2.IsFpuRegister()) {
1269 FRegister reg = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
1270 : loc2.AsFpuRegister<FRegister>();
1271 intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001272 if (type == DataType::Type::kFloat32) {
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001273 __ MovS(FTMP, reg);
1274 __ LoadSFromOffset(reg, SP, offset);
1275 __ StoreSToOffset(FTMP, SP, offset);
1276 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001277 DCHECK_EQ(type, DataType::Type::kFloat64);
Goran Jakovljevic35dfcaa2016-09-22 09:26:01 +02001278 __ MovD(FTMP, reg);
1279 __ LoadDFromOffset(reg, SP, offset);
1280 __ StoreDToOffset(FTMP, SP, offset);
1281 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001282 } else {
1283 LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported";
1284 }
1285}
1286
1287void ParallelMoveResolverMIPS::RestoreScratch(int reg) {
1288 __ Pop(static_cast<Register>(reg));
1289}
1290
1291void ParallelMoveResolverMIPS::SpillScratch(int reg) {
1292 __ Push(static_cast<Register>(reg));
1293}
1294
1295void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) {
1296 // Allocate a scratch register other than TMP, if available.
1297 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
1298 // automatically unspilled when the scratch scope object is destroyed).
1299 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
1300 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
1301 int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0;
1302 for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) {
1303 __ LoadFromOffset(kLoadWord,
1304 Register(ensure_scratch.GetRegister()),
1305 SP,
1306 index1 + stack_offset);
1307 __ LoadFromOffset(kLoadWord,
1308 TMP,
1309 SP,
1310 index2 + stack_offset);
1311 __ StoreToOffset(kStoreWord,
1312 Register(ensure_scratch.GetRegister()),
1313 SP,
1314 index2 + stack_offset);
1315 __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset);
1316 }
1317}
1318
Alexey Frunze73296a72016-06-03 22:51:46 -07001319void CodeGeneratorMIPS::ComputeSpillMask() {
1320 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
1321 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
1322 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
1323 // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved
1324 // registers, include the ZERO register to force alignment of FPU callee-saved registers
1325 // within the stack frame.
1326 if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) {
1327 core_spill_mask_ |= (1 << ZERO);
1328 }
Alexey Frunze58320ce2016-08-30 21:40:46 -07001329}
1330
1331bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const {
Alexey Frunze06a46c42016-07-19 15:00:40 -07001332 // If RA is clobbered by PC-relative operations on R2 and it's the only spilled register
Alexey Frunze58320ce2016-08-30 21:40:46 -07001333 // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration()
1334 // into the path that creates a stack frame so that RA can be explicitly saved and restored.
1335 // RA can't otherwise be saved/restored when it's the only spilled register.
Alexey Frunze58320ce2016-08-30 21:40:46 -07001336 return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_;
Alexey Frunze73296a72016-06-03 22:51:46 -07001337}
1338
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001339static dwarf::Reg DWARFReg(Register reg) {
1340 return dwarf::Reg::MipsCore(static_cast<int>(reg));
1341}
1342
1343// TODO: mapping of floating-point registers to DWARF.
1344
1345void CodeGeneratorMIPS::GenerateFrameEntry() {
1346 __ Bind(&frame_entry_label_);
1347
1348 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod();
1349
1350 if (do_overflow_check) {
1351 __ LoadFromOffset(kLoadWord,
1352 ZERO,
1353 SP,
1354 -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips)));
1355 RecordPcInfo(nullptr, 0);
1356 }
1357
1358 if (HasEmptyFrame()) {
Alexey Frunze58320ce2016-08-30 21:40:46 -07001359 CHECK_EQ(fpu_spill_mask_, 0u);
1360 CHECK_EQ(core_spill_mask_, 1u << RA);
1361 CHECK(!clobbered_ra_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001362 return;
1363 }
1364
1365 // Make sure the frame size isn't unreasonably large.
1366 if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) {
1367 LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes";
1368 }
1369
1370 // Spill callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001371
Alexey Frunze73296a72016-06-03 22:51:46 -07001372 uint32_t ofs = GetFrameSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001373 __ IncreaseFrameSize(ofs);
1374
Alexey Frunze73296a72016-06-03 22:51:46 -07001375 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
1376 Register reg = static_cast<Register>(MostSignificantBit(mask));
1377 mask ^= 1u << reg;
1378 ofs -= kMipsWordSize;
1379 // The ZERO register is only included for alignment.
1380 if (reg != ZERO) {
1381 __ StoreToOffset(kStoreWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001382 __ cfi().RelOffset(DWARFReg(reg), ofs);
1383 }
1384 }
1385
Alexey Frunze73296a72016-06-03 22:51:46 -07001386 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
1387 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
1388 mask ^= 1u << reg;
1389 ofs -= kMipsDoublewordSize;
1390 __ StoreDToOffset(reg, SP, ofs);
1391 // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001392 }
1393
Nicolas Geoffray96eeb4e2016-10-12 22:03:31 +01001394 // Save the current method if we need it. Note that we do not
1395 // do this in HCurrentMethod, as the instruction might have been removed
1396 // in the SSA graph.
1397 if (RequiresCurrentMethod()) {
1398 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
1399 }
Goran Jakovljevicc6418422016-12-05 16:31:55 +01001400
1401 if (GetGraph()->HasShouldDeoptimizeFlag()) {
1402 // Initialize should deoptimize flag to 0.
1403 __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag());
1404 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001405}
1406
1407void CodeGeneratorMIPS::GenerateFrameExit() {
1408 __ cfi().RememberState();
1409
1410 if (!HasEmptyFrame()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001411 // Restore callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001412
Alexey Frunze73296a72016-06-03 22:51:46 -07001413 // For better instruction scheduling restore RA before other registers.
1414 uint32_t ofs = GetFrameSize();
1415 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
1416 Register reg = static_cast<Register>(MostSignificantBit(mask));
1417 mask ^= 1u << reg;
1418 ofs -= kMipsWordSize;
1419 // The ZERO register is only included for alignment.
1420 if (reg != ZERO) {
1421 __ LoadFromOffset(kLoadWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001422 __ cfi().Restore(DWARFReg(reg));
1423 }
1424 }
1425
Alexey Frunze73296a72016-06-03 22:51:46 -07001426 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
1427 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
1428 mask ^= 1u << reg;
1429 ofs -= kMipsDoublewordSize;
1430 __ LoadDFromOffset(reg, SP, ofs);
1431 // TODO: __ cfi().Restore(DWARFReg(reg));
1432 }
1433
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001434 size_t frame_size = GetFrameSize();
1435 // Adjust the stack pointer in the delay slot if doing so doesn't break CFI.
1436 bool exchange = IsInt<16>(static_cast<int32_t>(frame_size));
1437 bool reordering = __ SetReorder(false);
1438 if (exchange) {
1439 __ Jr(RA);
1440 __ DecreaseFrameSize(frame_size); // Single instruction in delay slot.
1441 } else {
1442 __ DecreaseFrameSize(frame_size);
1443 __ Jr(RA);
1444 __ Nop(); // In delay slot.
1445 }
1446 __ SetReorder(reordering);
1447 } else {
1448 __ Jr(RA);
1449 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001450 }
1451
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001452 __ cfi().RestoreState();
1453 __ cfi().DefCFAOffset(GetFrameSize());
1454}
1455
1456void CodeGeneratorMIPS::Bind(HBasicBlock* block) {
1457 __ Bind(GetLabelOf(block));
1458}
1459
Lena Djokicca8c2952017-05-29 11:31:46 +02001460VectorRegister VectorRegisterFrom(Location location) {
1461 DCHECK(location.IsFpuRegister());
1462 return static_cast<VectorRegister>(location.AsFpuRegister<FRegister>());
1463}
1464
Lena Djokic8098da92017-06-28 12:07:50 +02001465void CodeGeneratorMIPS::MoveLocation(Location destination,
1466 Location source,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001467 DataType::Type dst_type) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001468 if (source.Equals(destination)) {
1469 return;
1470 }
1471
Lena Djokic8098da92017-06-28 12:07:50 +02001472 if (source.IsConstant()) {
1473 MoveConstant(destination, source.GetConstant());
1474 } else {
1475 if (destination.IsRegister()) {
1476 if (source.IsRegister()) {
1477 __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>());
1478 } else if (source.IsFpuRegister()) {
1479 __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>());
1480 } else {
1481 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001482 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Lena Djokic8098da92017-06-28 12:07:50 +02001483 }
1484 } else if (destination.IsRegisterPair()) {
1485 if (source.IsRegisterPair()) {
1486 __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
1487 __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
1488 } else if (source.IsFpuRegister()) {
1489 Register dst_high = destination.AsRegisterPairHigh<Register>();
1490 Register dst_low = destination.AsRegisterPairLow<Register>();
1491 FRegister src = source.AsFpuRegister<FRegister>();
1492 __ Mfc1(dst_low, src);
1493 __ MoveFromFpuHigh(dst_high, src);
1494 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001495 DCHECK(source.IsDoubleStackSlot())
1496 << "Cannot move from " << source << " to " << destination;
Lena Djokic8098da92017-06-28 12:07:50 +02001497 int32_t off = source.GetStackIndex();
1498 Register r = destination.AsRegisterPairLow<Register>();
1499 __ LoadFromOffset(kLoadDoubleword, r, SP, off);
1500 }
1501 } else if (destination.IsFpuRegister()) {
1502 if (source.IsRegister()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001503 DCHECK(!DataType::Is64BitType(dst_type));
Lena Djokic8098da92017-06-28 12:07:50 +02001504 __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>());
1505 } else if (source.IsRegisterPair()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001506 DCHECK(DataType::Is64BitType(dst_type));
Lena Djokic8098da92017-06-28 12:07:50 +02001507 FRegister dst = destination.AsFpuRegister<FRegister>();
1508 Register src_high = source.AsRegisterPairHigh<Register>();
1509 Register src_low = source.AsRegisterPairLow<Register>();
1510 __ Mtc1(src_low, dst);
1511 __ MoveToFpuHigh(src_high, dst);
1512 } else if (source.IsFpuRegister()) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001513 if (GetGraph()->HasSIMD()) {
1514 __ MoveV(VectorRegisterFrom(destination),
1515 VectorRegisterFrom(source));
Lena Djokic8098da92017-06-28 12:07:50 +02001516 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001517 if (DataType::Is64BitType(dst_type)) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001518 __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
1519 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001520 DCHECK_EQ(dst_type, DataType::Type::kFloat32);
Lena Djokicca8c2952017-05-29 11:31:46 +02001521 __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
1522 }
Lena Djokic8098da92017-06-28 12:07:50 +02001523 }
Lena Djokicca8c2952017-05-29 11:31:46 +02001524 } else if (source.IsSIMDStackSlot()) {
1525 __ LoadQFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
Lena Djokic8098da92017-06-28 12:07:50 +02001526 } else if (source.IsDoubleStackSlot()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001527 DCHECK(DataType::Is64BitType(dst_type));
Lena Djokic8098da92017-06-28 12:07:50 +02001528 __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
1529 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01001530 DCHECK(!DataType::Is64BitType(dst_type));
Lena Djokic8098da92017-06-28 12:07:50 +02001531 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
1532 __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
1533 }
Lena Djokicca8c2952017-05-29 11:31:46 +02001534 } else if (destination.IsSIMDStackSlot()) {
1535 if (source.IsFpuRegister()) {
1536 __ StoreQToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex());
1537 } else {
1538 DCHECK(source.IsSIMDStackSlot());
1539 __ LoadQFromOffset(FTMP, SP, source.GetStackIndex());
1540 __ StoreQToOffset(FTMP, SP, destination.GetStackIndex());
1541 }
Lena Djokic8098da92017-06-28 12:07:50 +02001542 } else if (destination.IsDoubleStackSlot()) {
1543 int32_t dst_offset = destination.GetStackIndex();
1544 if (source.IsRegisterPair()) {
1545 __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, dst_offset);
1546 } else if (source.IsFpuRegister()) {
1547 __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset);
1548 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001549 DCHECK(source.IsDoubleStackSlot())
1550 << "Cannot move from " << source << " to " << destination;
Lena Djokic8098da92017-06-28 12:07:50 +02001551 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
1552 __ StoreToOffset(kStoreWord, TMP, SP, dst_offset);
1553 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4);
1554 __ StoreToOffset(kStoreWord, TMP, SP, dst_offset + 4);
1555 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001556 } else {
Lena Djokic8098da92017-06-28 12:07:50 +02001557 DCHECK(destination.IsStackSlot()) << destination;
1558 int32_t dst_offset = destination.GetStackIndex();
1559 if (source.IsRegister()) {
1560 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, dst_offset);
1561 } else if (source.IsFpuRegister()) {
1562 __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset);
1563 } else {
1564 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
1565 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
1566 __ StoreToOffset(kStoreWord, TMP, SP, dst_offset);
1567 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001568 }
1569 }
1570}
1571
1572void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) {
1573 if (c->IsIntConstant() || c->IsNullConstant()) {
1574 // Move 32 bit constant.
1575 int32_t value = GetInt32ValueOf(c);
1576 if (destination.IsRegister()) {
1577 Register dst = destination.AsRegister<Register>();
1578 __ LoadConst32(dst, value);
1579 } else {
1580 DCHECK(destination.IsStackSlot())
1581 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -07001582 __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001583 }
1584 } else if (c->IsLongConstant()) {
1585 // Move 64 bit constant.
1586 int64_t value = GetInt64ValueOf(c);
1587 if (destination.IsRegisterPair()) {
1588 Register r_h = destination.AsRegisterPairHigh<Register>();
1589 Register r_l = destination.AsRegisterPairLow<Register>();
1590 __ LoadConst64(r_h, r_l, value);
1591 } else {
1592 DCHECK(destination.IsDoubleStackSlot())
1593 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -07001594 __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001595 }
1596 } else if (c->IsFloatConstant()) {
1597 // Move 32 bit float constant.
1598 int32_t value = GetInt32ValueOf(c);
1599 if (destination.IsFpuRegister()) {
1600 __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP);
1601 } else {
1602 DCHECK(destination.IsStackSlot())
1603 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -07001604 __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001605 }
1606 } else {
1607 // Move 64 bit double constant.
1608 DCHECK(c->IsDoubleConstant()) << c->DebugName();
1609 int64_t value = GetInt64ValueOf(c);
1610 if (destination.IsFpuRegister()) {
1611 FRegister fd = destination.AsFpuRegister<FRegister>();
1612 __ LoadDConst64(fd, value, TMP);
1613 } else {
1614 DCHECK(destination.IsDoubleStackSlot())
1615 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -07001616 __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001617 }
1618 }
1619}
1620
1621void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) {
1622 DCHECK(destination.IsRegister());
1623 Register dst = destination.AsRegister<Register>();
1624 __ LoadConst32(dst, value);
1625}
1626
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001627void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) {
1628 if (location.IsRegister()) {
1629 locations->AddTemp(location);
Alexey Frunzec9e94f32015-10-26 16:11:39 -07001630 } else if (location.IsRegisterPair()) {
1631 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
1632 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001633 } else {
1634 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
1635 }
1636}
1637
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001638template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
Vladimir Markoaad75c62016-10-03 08:46:48 +00001639inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches(
1640 const ArenaDeque<PcRelativePatchInfo>& infos,
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001641 ArenaVector<linker::LinkerPatch>* linker_patches) {
Vladimir Markoaad75c62016-10-03 08:46:48 +00001642 for (const PcRelativePatchInfo& info : infos) {
1643 const DexFile& dex_file = info.target_dex_file;
1644 size_t offset_or_index = info.offset_or_index;
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001645 DCHECK(info.label.IsBound());
1646 uint32_t literal_offset = __ GetLabelLocation(&info.label);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001647 // On R2 we use HMipsComputeBaseMethodAddress and patch relative to
1648 // the assembler's base label used for PC-relative addressing.
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001649 const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info;
1650 uint32_t pc_rel_offset = info_high.pc_rel_label.IsBound()
1651 ? __ GetLabelLocation(&info_high.pc_rel_label)
Vladimir Markoaad75c62016-10-03 08:46:48 +00001652 : __ GetPcRelBaseLabelLocation();
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001653 linker_patches->push_back(Factory(literal_offset, &dex_file, pc_rel_offset, offset_or_index));
Vladimir Markoaad75c62016-10-03 08:46:48 +00001654 }
1655}
1656
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001657void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001658 DCHECK(linker_patches->empty());
1659 size_t size =
Vladimir Marko65979462017-05-19 17:25:12 +01001660 pc_relative_method_patches_.size() +
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001661 method_bss_entry_patches_.size() +
Alexey Frunze06a46c42016-07-19 15:00:40 -07001662 pc_relative_type_patches_.size() +
Vladimir Marko65979462017-05-19 17:25:12 +01001663 type_bss_entry_patches_.size() +
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01001664 pc_relative_string_patches_.size() +
1665 string_bss_entry_patches_.size();
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001666 linker_patches->reserve(size);
Vladimir Marko65979462017-05-19 17:25:12 +01001667 if (GetCompilerOptions().IsBootImage()) {
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001668 EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>(
1669 pc_relative_method_patches_, linker_patches);
1670 EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>(
1671 pc_relative_type_patches_, linker_patches);
1672 EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>(
1673 pc_relative_string_patches_, linker_patches);
Vladimir Marko65979462017-05-19 17:25:12 +01001674 } else {
1675 DCHECK(pc_relative_method_patches_.empty());
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001676 EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>(
1677 pc_relative_type_patches_, linker_patches);
1678 EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>(
1679 pc_relative_string_patches_, linker_patches);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001680 }
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01001681 EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>(
1682 method_bss_entry_patches_, linker_patches);
1683 EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>(
1684 type_bss_entry_patches_, linker_patches);
1685 EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>(
1686 string_bss_entry_patches_, linker_patches);
Vladimir Marko1998cd02017-01-13 13:02:58 +00001687 DCHECK_EQ(size, linker_patches->size());
Alexey Frunze06a46c42016-07-19 15:00:40 -07001688}
1689
Vladimir Marko65979462017-05-19 17:25:12 +01001690CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeMethodPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001691 MethodReference target_method,
1692 const PcRelativePatchInfo* info_high) {
Vladimir Marko65979462017-05-19 17:25:12 +01001693 return NewPcRelativePatch(*target_method.dex_file,
Mathieu Chartierfc8b4222017-09-17 13:44:24 -07001694 target_method.index,
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001695 info_high,
Vladimir Marko65979462017-05-19 17:25:12 +01001696 &pc_relative_method_patches_);
Alexey Frunze06a46c42016-07-19 15:00:40 -07001697}
1698
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001699CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewMethodBssEntryPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001700 MethodReference target_method,
1701 const PcRelativePatchInfo* info_high) {
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001702 return NewPcRelativePatch(*target_method.dex_file,
Mathieu Chartierfc8b4222017-09-17 13:44:24 -07001703 target_method.index,
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001704 info_high,
Vladimir Marko0eb882b2017-05-15 13:39:18 +01001705 &method_bss_entry_patches_);
1706}
1707
Alexey Frunze06a46c42016-07-19 15:00:40 -07001708CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001709 const DexFile& dex_file,
1710 dex::TypeIndex type_index,
1711 const PcRelativePatchInfo* info_high) {
1712 return NewPcRelativePatch(dex_file, type_index.index_, info_high, &pc_relative_type_patches_);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001713}
1714
Vladimir Marko1998cd02017-01-13 13:02:58 +00001715CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewTypeBssEntryPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001716 const DexFile& dex_file,
1717 dex::TypeIndex type_index,
1718 const PcRelativePatchInfo* info_high) {
1719 return NewPcRelativePatch(dex_file, type_index.index_, info_high, &type_bss_entry_patches_);
Vladimir Marko1998cd02017-01-13 13:02:58 +00001720}
1721
Vladimir Marko65979462017-05-19 17:25:12 +01001722CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001723 const DexFile& dex_file,
1724 dex::StringIndex string_index,
1725 const PcRelativePatchInfo* info_high) {
1726 return NewPcRelativePatch(dex_file, string_index.index_, info_high, &pc_relative_string_patches_);
Vladimir Marko65979462017-05-19 17:25:12 +01001727}
1728
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01001729CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewStringBssEntryPatch(
1730 const DexFile& dex_file,
1731 dex::StringIndex string_index,
1732 const PcRelativePatchInfo* info_high) {
1733 return NewPcRelativePatch(dex_file, string_index.index_, info_high, &string_bss_entry_patches_);
1734}
1735
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001736CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001737 const DexFile& dex_file,
1738 uint32_t offset_or_index,
1739 const PcRelativePatchInfo* info_high,
1740 ArenaDeque<PcRelativePatchInfo>* patches) {
1741 patches->emplace_back(dex_file, offset_or_index, info_high);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001742 return &patches->back();
1743}
1744
Alexey Frunze06a46c42016-07-19 15:00:40 -07001745Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
1746 return map->GetOrCreate(
1747 value,
1748 [this, value]() { return __ NewLiteral<uint32_t>(value); });
1749}
1750
Alexey Frunze06a46c42016-07-19 15:00:40 -07001751Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) {
Richard Uhlerc52f3032017-03-02 13:45:45 +00001752 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_);
Alexey Frunze06a46c42016-07-19 15:00:40 -07001753}
1754
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001755void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high,
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001756 Register out,
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001757 Register base) {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001758 DCHECK(!info_high->patch_info_high);
Alexey Frunze6079dca2017-05-28 19:10:28 -07001759 DCHECK_NE(out, base);
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001760 bool reordering = __ SetReorder(false);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001761 if (GetInstructionSetFeatures().IsR6()) {
1762 DCHECK_EQ(base, ZERO);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001763 __ Bind(&info_high->label);
1764 __ Bind(&info_high->pc_rel_label);
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001765 // Add the high half of a 32-bit offset to PC.
Vladimir Markoaad75c62016-10-03 08:46:48 +00001766 __ Auipc(out, /* placeholder */ 0x1234);
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001767 __ SetReorder(reordering);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001768 } else {
1769 // If base is ZERO, emit NAL to obtain the actual base.
1770 if (base == ZERO) {
1771 // Generate a dummy PC-relative call to obtain PC.
1772 __ Nal();
1773 }
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001774 __ Bind(&info_high->label);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001775 __ Lui(out, /* placeholder */ 0x1234);
1776 // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding
1777 // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler.
1778 if (base == ZERO) {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001779 __ Bind(&info_high->pc_rel_label);
Vladimir Markoaad75c62016-10-03 08:46:48 +00001780 }
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001781 __ SetReorder(reordering);
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001782 // Add the high half of a 32-bit offset to PC.
Vladimir Markoaad75c62016-10-03 08:46:48 +00001783 __ Addu(out, out, (base == ZERO) ? RA : base);
1784 }
Alexey Frunze5fa5c042017-06-01 21:07:52 -07001785 // A following instruction will add the sign-extended low half of the 32-bit
Alexey Frunze6b892cd2017-01-03 17:11:38 -08001786 // offset to `out` (e.g. lw, jialc, addiu).
Vladimir Markoaad75c62016-10-03 08:46:48 +00001787}
1788
Alexey Frunze627c1a02017-01-30 19:28:14 -08001789CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootStringPatch(
1790 const DexFile& dex_file,
1791 dex::StringIndex dex_index,
1792 Handle<mirror::String> handle) {
1793 jit_string_roots_.Overwrite(StringReference(&dex_file, dex_index),
1794 reinterpret_cast64<uint64_t>(handle.GetReference()));
1795 jit_string_patches_.emplace_back(dex_file, dex_index.index_);
1796 return &jit_string_patches_.back();
1797}
1798
1799CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootClassPatch(
1800 const DexFile& dex_file,
1801 dex::TypeIndex dex_index,
1802 Handle<mirror::Class> handle) {
1803 jit_class_roots_.Overwrite(TypeReference(&dex_file, dex_index),
1804 reinterpret_cast64<uint64_t>(handle.GetReference()));
1805 jit_class_patches_.emplace_back(dex_file, dex_index.index_);
1806 return &jit_class_patches_.back();
1807}
1808
1809void CodeGeneratorMIPS::PatchJitRootUse(uint8_t* code,
1810 const uint8_t* roots_data,
1811 const CodeGeneratorMIPS::JitPatchInfo& info,
1812 uint64_t index_in_table) const {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001813 uint32_t high_literal_offset = GetAssembler().GetLabelLocation(&info.high_label);
1814 uint32_t low_literal_offset = GetAssembler().GetLabelLocation(&info.low_label);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001815 uintptr_t address =
1816 reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>);
1817 uint32_t addr32 = dchecked_integral_cast<uint32_t>(address);
1818 // lui reg, addr32_high
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001819 DCHECK_EQ(code[high_literal_offset + 0], 0x34);
1820 DCHECK_EQ(code[high_literal_offset + 1], 0x12);
1821 DCHECK_EQ((code[high_literal_offset + 2] & 0xE0), 0x00);
1822 DCHECK_EQ(code[high_literal_offset + 3], 0x3C);
Alexey Frunzec61c0762017-04-10 13:54:23 -07001823 // instr reg, reg, addr32_low
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001824 DCHECK_EQ(code[low_literal_offset + 0], 0x78);
1825 DCHECK_EQ(code[low_literal_offset + 1], 0x56);
Alexey Frunzec61c0762017-04-10 13:54:23 -07001826 addr32 += (addr32 & 0x8000) << 1; // Account for sign extension in "instr reg, reg, addr32_low".
Alexey Frunze627c1a02017-01-30 19:28:14 -08001827 // lui reg, addr32_high
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001828 code[high_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 16);
1829 code[high_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 24);
Alexey Frunzec61c0762017-04-10 13:54:23 -07001830 // instr reg, reg, addr32_low
Alexey Frunze4147fcc2017-06-17 19:57:27 -07001831 code[low_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 0);
1832 code[low_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 8);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001833}
1834
1835void CodeGeneratorMIPS::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) {
1836 for (const JitPatchInfo& info : jit_string_patches_) {
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001837 const auto it = jit_string_roots_.find(StringReference(&info.target_dex_file,
1838 dex::StringIndex(info.index)));
Alexey Frunze627c1a02017-01-30 19:28:14 -08001839 DCHECK(it != jit_string_roots_.end());
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001840 uint64_t index_in_table = it->second;
1841 PatchJitRootUse(code, roots_data, info, index_in_table);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001842 }
1843 for (const JitPatchInfo& info : jit_class_patches_) {
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001844 const auto it = jit_class_roots_.find(TypeReference(&info.target_dex_file,
1845 dex::TypeIndex(info.index)));
Alexey Frunze627c1a02017-01-30 19:28:14 -08001846 DCHECK(it != jit_class_roots_.end());
Vladimir Marko7d157fc2017-05-10 16:29:23 +01001847 uint64_t index_in_table = it->second;
1848 PatchJitRootUse(code, roots_data, info, index_in_table);
Alexey Frunze627c1a02017-01-30 19:28:14 -08001849 }
1850}
1851
Goran Jakovljevice114da22016-12-26 14:21:43 +01001852void CodeGeneratorMIPS::MarkGCCard(Register object,
1853 Register value,
1854 bool value_can_be_null) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001855 MipsLabel done;
1856 Register card = AT;
1857 Register temp = TMP;
Goran Jakovljevice114da22016-12-26 14:21:43 +01001858 if (value_can_be_null) {
1859 __ Beqz(value, &done);
1860 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001861 __ LoadFromOffset(kLoadWord,
1862 card,
1863 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001864 Thread::CardTableOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001865 __ Srl(temp, object, gc::accounting::CardTable::kCardShift);
1866 __ Addu(temp, card, temp);
1867 __ Sb(card, temp, 0);
Goran Jakovljevice114da22016-12-26 14:21:43 +01001868 if (value_can_be_null) {
1869 __ Bind(&done);
1870 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001871}
1872
David Brazdil58282f42016-01-14 12:45:10 +00001873void CodeGeneratorMIPS::SetupBlockedRegisters() const {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001874 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
1875 blocked_core_registers_[ZERO] = true;
1876 blocked_core_registers_[K0] = true;
1877 blocked_core_registers_[K1] = true;
1878 blocked_core_registers_[GP] = true;
1879 blocked_core_registers_[SP] = true;
1880 blocked_core_registers_[RA] = true;
1881
1882 // AT and TMP(T8) are used as temporary/scratch registers
1883 // (similar to how AT is used by MIPS assemblers).
1884 blocked_core_registers_[AT] = true;
1885 blocked_core_registers_[TMP] = true;
1886 blocked_fpu_registers_[FTMP] = true;
1887
1888 // Reserve suspend and thread registers.
1889 blocked_core_registers_[S0] = true;
1890 blocked_core_registers_[TR] = true;
1891
1892 // Reserve T9 for function calls
1893 blocked_core_registers_[T9] = true;
1894
1895 // Reserve odd-numbered FPU registers.
1896 for (size_t i = 1; i < kNumberOfFRegisters; i += 2) {
1897 blocked_fpu_registers_[i] = true;
1898 }
1899
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02001900 if (GetGraph()->IsDebuggable()) {
1901 // Stubs do not save callee-save floating point registers. If the graph
1902 // is debuggable, we need to deal with these registers differently. For
1903 // now, just block them.
1904 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1905 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1906 }
1907 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001908}
1909
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001910size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1911 __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index);
1912 return kMipsWordSize;
1913}
1914
1915size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1916 __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index);
1917 return kMipsWordSize;
1918}
1919
1920size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001921 if (GetGraph()->HasSIMD()) {
1922 __ StoreQToOffset(FRegister(reg_id), SP, stack_index);
1923 } else {
1924 __ StoreDToOffset(FRegister(reg_id), SP, stack_index);
1925 }
1926 return GetFloatingPointSpillSlotSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001927}
1928
1929size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
Lena Djokicca8c2952017-05-29 11:31:46 +02001930 if (GetGraph()->HasSIMD()) {
1931 __ LoadQFromOffset(FRegister(reg_id), SP, stack_index);
1932 } else {
1933 __ LoadDFromOffset(FRegister(reg_id), SP, stack_index);
1934 }
1935 return GetFloatingPointSpillSlotSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001936}
1937
1938void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001939 stream << Register(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001940}
1941
1942void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001943 stream << FRegister(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001944}
1945
Serban Constantinescufca16662016-07-14 09:21:59 +01001946constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16;
1947
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001948void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint,
1949 HInstruction* instruction,
1950 uint32_t dex_pc,
1951 SlowPathCode* slow_path) {
Alexandre Rames91a65162016-09-19 13:54:30 +01001952 ValidateInvokeRuntime(entrypoint, instruction, slow_path);
Alexey Frunze15958152017-02-09 19:08:30 -08001953 GenerateInvokeRuntime(GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value(),
1954 IsDirectEntrypoint(entrypoint));
1955 if (EntrypointRequiresStackMap(entrypoint)) {
1956 RecordPcInfo(instruction, dex_pc, slow_path);
1957 }
1958}
1959
1960void CodeGeneratorMIPS::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
1961 HInstruction* instruction,
1962 SlowPathCode* slow_path,
1963 bool direct) {
1964 ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path);
1965 GenerateInvokeRuntime(entry_point_offset, direct);
1966}
1967
1968void CodeGeneratorMIPS::GenerateInvokeRuntime(int32_t entry_point_offset, bool direct) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001969 bool reordering = __ SetReorder(false);
Alexey Frunze15958152017-02-09 19:08:30 -08001970 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001971 __ Jalr(T9);
Alexey Frunze15958152017-02-09 19:08:30 -08001972 if (direct) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001973 // Reserve argument space on stack (for $a0-$a3) for
1974 // entrypoints that directly reference native implementations.
1975 // Called function may use this space to store $a0-$a3 regs.
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001976 __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001977 __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001978 } else {
1979 __ Nop(); // In delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001980 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001981 __ SetReorder(reordering);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001982}
1983
1984void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path,
1985 Register class_reg) {
1986 __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
1987 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
1988 __ Blt(TMP, AT, slow_path->GetEntryLabel());
1989 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
1990 __ Sync(0);
1991 __ Bind(slow_path->GetExitLabel());
1992}
1993
1994void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1995 __ Sync(0); // Only stype 0 is supported.
1996}
1997
1998void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction,
1999 HBasicBlock* successor) {
2000 SuspendCheckSlowPathMIPS* slow_path =
Vladimir Markoca6fff82017-10-03 14:49:14 +01002001 new (GetGraph()->GetAllocator()) SuspendCheckSlowPathMIPS(instruction, successor);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002002 codegen_->AddSlowPath(slow_path);
2003
2004 __ LoadFromOffset(kLoadUnsignedHalfword,
2005 TMP,
2006 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07002007 Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002008 if (successor == nullptr) {
2009 __ Bnez(TMP, slow_path->GetEntryLabel());
2010 __ Bind(slow_path->GetReturnLabel());
2011 } else {
2012 __ Beqz(TMP, codegen_->GetLabelOf(successor));
2013 __ B(slow_path->GetEntryLabel());
2014 // slow_path will return to GetLabelOf(successor).
2015 }
2016}
2017
2018InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph,
2019 CodeGeneratorMIPS* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08002020 : InstructionCodeGenerator(graph, codegen),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002021 assembler_(codegen->GetAssembler()),
2022 codegen_(codegen) {}
2023
2024void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
2025 DCHECK_EQ(instruction->InputCount(), 2U);
Vladimir Markoca6fff82017-10-03 14:49:14 +01002026 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002027 DataType::Type type = instruction->GetResultType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002028 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002029 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002030 locations->SetInAt(0, Location::RequiresRegister());
2031 HInstruction* right = instruction->InputAt(1);
2032 bool can_use_imm = false;
2033 if (right->IsConstant()) {
2034 int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant());
2035 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
2036 can_use_imm = IsUint<16>(imm);
2037 } else if (instruction->IsAdd()) {
2038 can_use_imm = IsInt<16>(imm);
2039 } else {
2040 DCHECK(instruction->IsSub());
2041 can_use_imm = IsInt<16>(-imm);
2042 }
2043 }
2044 if (can_use_imm)
2045 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
2046 else
2047 locations->SetInAt(1, Location::RequiresRegister());
2048 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2049 break;
2050 }
2051
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002052 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002053 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002054 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2055 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002056 break;
2057 }
2058
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002059 case DataType::Type::kFloat32:
2060 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002061 DCHECK(instruction->IsAdd() || instruction->IsSub());
2062 locations->SetInAt(0, Location::RequiresFpuRegister());
2063 locations->SetInAt(1, Location::RequiresFpuRegister());
2064 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2065 break;
2066
2067 default:
2068 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
2069 }
2070}
2071
2072void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002073 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002074 LocationSummary* locations = instruction->GetLocations();
2075
2076 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002077 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002078 Register dst = locations->Out().AsRegister<Register>();
2079 Register lhs = locations->InAt(0).AsRegister<Register>();
2080 Location rhs_location = locations->InAt(1);
2081
2082 Register rhs_reg = ZERO;
2083 int32_t rhs_imm = 0;
2084 bool use_imm = rhs_location.IsConstant();
2085 if (use_imm) {
2086 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2087 } else {
2088 rhs_reg = rhs_location.AsRegister<Register>();
2089 }
2090
2091 if (instruction->IsAnd()) {
2092 if (use_imm)
2093 __ Andi(dst, lhs, rhs_imm);
2094 else
2095 __ And(dst, lhs, rhs_reg);
2096 } else if (instruction->IsOr()) {
2097 if (use_imm)
2098 __ Ori(dst, lhs, rhs_imm);
2099 else
2100 __ Or(dst, lhs, rhs_reg);
2101 } else if (instruction->IsXor()) {
2102 if (use_imm)
2103 __ Xori(dst, lhs, rhs_imm);
2104 else
2105 __ Xor(dst, lhs, rhs_reg);
2106 } else if (instruction->IsAdd()) {
2107 if (use_imm)
2108 __ Addiu(dst, lhs, rhs_imm);
2109 else
2110 __ Addu(dst, lhs, rhs_reg);
2111 } else {
2112 DCHECK(instruction->IsSub());
2113 if (use_imm)
2114 __ Addiu(dst, lhs, -rhs_imm);
2115 else
2116 __ Subu(dst, lhs, rhs_reg);
2117 }
2118 break;
2119 }
2120
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002121 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002122 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
2123 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
2124 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2125 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002126 Location rhs_location = locations->InAt(1);
2127 bool use_imm = rhs_location.IsConstant();
2128 if (!use_imm) {
2129 Register rhs_high = rhs_location.AsRegisterPairHigh<Register>();
2130 Register rhs_low = rhs_location.AsRegisterPairLow<Register>();
2131 if (instruction->IsAnd()) {
2132 __ And(dst_low, lhs_low, rhs_low);
2133 __ And(dst_high, lhs_high, rhs_high);
2134 } else if (instruction->IsOr()) {
2135 __ Or(dst_low, lhs_low, rhs_low);
2136 __ Or(dst_high, lhs_high, rhs_high);
2137 } else if (instruction->IsXor()) {
2138 __ Xor(dst_low, lhs_low, rhs_low);
2139 __ Xor(dst_high, lhs_high, rhs_high);
2140 } else if (instruction->IsAdd()) {
2141 if (lhs_low == rhs_low) {
2142 // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs.
2143 __ Slt(TMP, lhs_low, ZERO);
2144 __ Addu(dst_low, lhs_low, rhs_low);
2145 } else {
2146 __ Addu(dst_low, lhs_low, rhs_low);
2147 // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged.
2148 __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low);
2149 }
2150 __ Addu(dst_high, lhs_high, rhs_high);
2151 __ Addu(dst_high, dst_high, TMP);
2152 } else {
2153 DCHECK(instruction->IsSub());
2154 __ Sltu(TMP, lhs_low, rhs_low);
2155 __ Subu(dst_low, lhs_low, rhs_low);
2156 __ Subu(dst_high, lhs_high, rhs_high);
2157 __ Subu(dst_high, dst_high, TMP);
2158 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002159 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002160 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
2161 if (instruction->IsOr()) {
2162 uint32_t low = Low32Bits(value);
2163 uint32_t high = High32Bits(value);
2164 if (IsUint<16>(low)) {
2165 if (dst_low != lhs_low || low != 0) {
2166 __ Ori(dst_low, lhs_low, low);
2167 }
2168 } else {
2169 __ LoadConst32(TMP, low);
2170 __ Or(dst_low, lhs_low, TMP);
2171 }
2172 if (IsUint<16>(high)) {
2173 if (dst_high != lhs_high || high != 0) {
2174 __ Ori(dst_high, lhs_high, high);
2175 }
2176 } else {
2177 if (high != low) {
2178 __ LoadConst32(TMP, high);
2179 }
2180 __ Or(dst_high, lhs_high, TMP);
2181 }
2182 } else if (instruction->IsXor()) {
2183 uint32_t low = Low32Bits(value);
2184 uint32_t high = High32Bits(value);
2185 if (IsUint<16>(low)) {
2186 if (dst_low != lhs_low || low != 0) {
2187 __ Xori(dst_low, lhs_low, low);
2188 }
2189 } else {
2190 __ LoadConst32(TMP, low);
2191 __ Xor(dst_low, lhs_low, TMP);
2192 }
2193 if (IsUint<16>(high)) {
2194 if (dst_high != lhs_high || high != 0) {
2195 __ Xori(dst_high, lhs_high, high);
2196 }
2197 } else {
2198 if (high != low) {
2199 __ LoadConst32(TMP, high);
2200 }
2201 __ Xor(dst_high, lhs_high, TMP);
2202 }
2203 } else if (instruction->IsAnd()) {
2204 uint32_t low = Low32Bits(value);
2205 uint32_t high = High32Bits(value);
2206 if (IsUint<16>(low)) {
2207 __ Andi(dst_low, lhs_low, low);
2208 } else if (low != 0xFFFFFFFF) {
2209 __ LoadConst32(TMP, low);
2210 __ And(dst_low, lhs_low, TMP);
2211 } else if (dst_low != lhs_low) {
2212 __ Move(dst_low, lhs_low);
2213 }
2214 if (IsUint<16>(high)) {
2215 __ Andi(dst_high, lhs_high, high);
2216 } else if (high != 0xFFFFFFFF) {
2217 if (high != low) {
2218 __ LoadConst32(TMP, high);
2219 }
2220 __ And(dst_high, lhs_high, TMP);
2221 } else if (dst_high != lhs_high) {
2222 __ Move(dst_high, lhs_high);
2223 }
2224 } else {
2225 if (instruction->IsSub()) {
2226 value = -value;
2227 } else {
2228 DCHECK(instruction->IsAdd());
2229 }
2230 int32_t low = Low32Bits(value);
2231 int32_t high = High32Bits(value);
2232 if (IsInt<16>(low)) {
2233 if (dst_low != lhs_low || low != 0) {
2234 __ Addiu(dst_low, lhs_low, low);
2235 }
2236 if (low != 0) {
2237 __ Sltiu(AT, dst_low, low);
2238 }
2239 } else {
2240 __ LoadConst32(TMP, low);
2241 __ Addu(dst_low, lhs_low, TMP);
2242 __ Sltu(AT, dst_low, TMP);
2243 }
2244 if (IsInt<16>(high)) {
2245 if (dst_high != lhs_high || high != 0) {
2246 __ Addiu(dst_high, lhs_high, high);
2247 }
2248 } else {
2249 if (high != low) {
2250 __ LoadConst32(TMP, high);
2251 }
2252 __ Addu(dst_high, lhs_high, TMP);
2253 }
2254 if (low != 0) {
2255 __ Addu(dst_high, dst_high, AT);
2256 }
2257 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002258 }
2259 break;
2260 }
2261
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002262 case DataType::Type::kFloat32:
2263 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002264 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
2265 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2266 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2267 if (instruction->IsAdd()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002268 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002269 __ AddS(dst, lhs, rhs);
2270 } else {
2271 __ AddD(dst, lhs, rhs);
2272 }
2273 } else {
2274 DCHECK(instruction->IsSub());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002275 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002276 __ SubS(dst, lhs, rhs);
2277 } else {
2278 __ SubD(dst, lhs, rhs);
2279 }
2280 }
2281 break;
2282 }
2283
2284 default:
2285 LOG(FATAL) << "Unexpected binary operation type " << type;
2286 }
2287}
2288
2289void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002290 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002291
Vladimir Markoca6fff82017-10-03 14:49:14 +01002292 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002293 DataType::Type type = instr->GetResultType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002294 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002295 case DataType::Type::kInt32:
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002296 locations->SetInAt(0, Location::RequiresRegister());
2297 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
2298 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2299 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002300 case DataType::Type::kInt64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002301 locations->SetInAt(0, Location::RequiresRegister());
2302 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
2303 locations->SetOut(Location::RequiresRegister());
2304 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002305 default:
2306 LOG(FATAL) << "Unexpected shift type " << type;
2307 }
2308}
2309
2310static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte;
2311
2312void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002313 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002314 LocationSummary* locations = instr->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002315 DataType::Type type = instr->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002316
2317 Location rhs_location = locations->InAt(1);
2318 bool use_imm = rhs_location.IsConstant();
2319 Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>();
2320 int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0;
Roland Levillain5b5b9312016-03-22 14:57:31 +00002321 const uint32_t shift_mask =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002322 (type == DataType::Type::kInt32) ? kMaxIntShiftDistance : kMaxLongShiftDistance;
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002323 const uint32_t shift_value = rhs_imm & shift_mask;
Alexey Frunze92d90602015-12-18 18:16:36 -08002324 // Are the INS (Insert Bit Field) and ROTR instructions supported?
2325 bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002326
2327 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002328 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002329 Register dst = locations->Out().AsRegister<Register>();
2330 Register lhs = locations->InAt(0).AsRegister<Register>();
2331 if (use_imm) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002332 if (shift_value == 0) {
2333 if (dst != lhs) {
2334 __ Move(dst, lhs);
2335 }
2336 } else if (instr->IsShl()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002337 __ Sll(dst, lhs, shift_value);
2338 } else if (instr->IsShr()) {
2339 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002340 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002341 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002342 } else {
2343 if (has_ins_rotr) {
2344 __ Rotr(dst, lhs, shift_value);
2345 } else {
2346 __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask);
2347 __ Srl(dst, lhs, shift_value);
2348 __ Or(dst, dst, TMP);
2349 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002350 }
2351 } else {
2352 if (instr->IsShl()) {
2353 __ Sllv(dst, lhs, rhs_reg);
2354 } else if (instr->IsShr()) {
2355 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002356 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002357 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08002358 } else {
2359 if (has_ins_rotr) {
2360 __ Rotrv(dst, lhs, rhs_reg);
2361 } else {
2362 __ Subu(TMP, ZERO, rhs_reg);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002363 // 32-bit shift instructions use the 5 least significant bits of the shift count, so
2364 // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case
2365 // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out
2366 // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`,
2367 // IOW, the OR'd values are equal.
Alexey Frunze92d90602015-12-18 18:16:36 -08002368 __ Sllv(TMP, lhs, TMP);
2369 __ Srlv(dst, lhs, rhs_reg);
2370 __ Or(dst, dst, TMP);
2371 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002372 }
2373 }
2374 break;
2375 }
2376
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002377 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002378 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
2379 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
2380 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2381 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
2382 if (use_imm) {
2383 if (shift_value == 0) {
Lena Djokic8098da92017-06-28 12:07:50 +02002384 codegen_->MoveLocation(locations->Out(), locations->InAt(0), type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002385 } else if (shift_value < kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002386 if (has_ins_rotr) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002387 if (instr->IsShl()) {
2388 __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
2389 __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value);
2390 __ Sll(dst_low, lhs_low, shift_value);
2391 } else if (instr->IsShr()) {
2392 __ Srl(dst_low, lhs_low, shift_value);
2393 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
2394 __ Sra(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002395 } else if (instr->IsUShr()) {
2396 __ Srl(dst_low, lhs_low, shift_value);
2397 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
2398 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002399 } else {
2400 __ Srl(dst_low, lhs_low, shift_value);
2401 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
2402 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08002403 __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002404 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002405 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002406 if (instr->IsShl()) {
2407 __ Sll(dst_low, lhs_low, shift_value);
2408 __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value);
2409 __ Sll(dst_high, lhs_high, shift_value);
2410 __ Or(dst_high, dst_high, TMP);
2411 } else if (instr->IsShr()) {
2412 __ Sra(dst_high, lhs_high, shift_value);
2413 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
2414 __ Srl(dst_low, lhs_low, shift_value);
2415 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08002416 } else if (instr->IsUShr()) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002417 __ Srl(dst_high, lhs_high, shift_value);
2418 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
2419 __ Srl(dst_low, lhs_low, shift_value);
2420 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08002421 } else {
2422 __ Srl(TMP, lhs_low, shift_value);
2423 __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value);
2424 __ Or(dst_low, dst_low, TMP);
2425 __ Srl(TMP, lhs_high, shift_value);
2426 __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
2427 __ Or(dst_high, dst_high, TMP);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002428 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002429 }
2430 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002431 const uint32_t shift_value_high = shift_value - kMipsBitsPerWord;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002432 if (instr->IsShl()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002433 __ Sll(dst_high, lhs_low, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002434 __ Move(dst_low, ZERO);
2435 } else if (instr->IsShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002436 __ Sra(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002437 __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1);
Alexey Frunze92d90602015-12-18 18:16:36 -08002438 } else if (instr->IsUShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002439 __ Srl(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002440 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08002441 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002442 if (shift_value == kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08002443 // 64-bit rotation by 32 is just a swap.
2444 __ Move(dst_low, lhs_high);
2445 __ Move(dst_high, lhs_low);
2446 } else {
2447 if (has_ins_rotr) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002448 __ Srl(dst_low, lhs_high, shift_value_high);
2449 __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high);
2450 __ Srl(dst_high, lhs_low, shift_value_high);
2451 __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08002452 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002453 __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high);
2454 __ Srl(dst_low, lhs_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08002455 __ Or(dst_low, dst_low, TMP);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08002456 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high);
2457 __ Srl(dst_high, lhs_low, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08002458 __ Or(dst_high, dst_high, TMP);
2459 }
2460 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002461 }
2462 }
2463 } else {
2464 MipsLabel done;
2465 if (instr->IsShl()) {
2466 __ Sllv(dst_low, lhs_low, rhs_reg);
2467 __ Nor(AT, ZERO, rhs_reg);
2468 __ Srl(TMP, lhs_low, 1);
2469 __ Srlv(TMP, TMP, AT);
2470 __ Sllv(dst_high, lhs_high, rhs_reg);
2471 __ Or(dst_high, dst_high, TMP);
2472 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
2473 __ Beqz(TMP, &done);
2474 __ Move(dst_high, dst_low);
2475 __ Move(dst_low, ZERO);
2476 } else if (instr->IsShr()) {
2477 __ Srav(dst_high, lhs_high, rhs_reg);
2478 __ Nor(AT, ZERO, rhs_reg);
2479 __ Sll(TMP, lhs_high, 1);
2480 __ Sllv(TMP, TMP, AT);
2481 __ Srlv(dst_low, lhs_low, rhs_reg);
2482 __ Or(dst_low, dst_low, TMP);
2483 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
2484 __ Beqz(TMP, &done);
2485 __ Move(dst_low, dst_high);
2486 __ Sra(dst_high, dst_high, 31);
Alexey Frunze92d90602015-12-18 18:16:36 -08002487 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002488 __ Srlv(dst_high, lhs_high, rhs_reg);
2489 __ Nor(AT, ZERO, rhs_reg);
2490 __ Sll(TMP, lhs_high, 1);
2491 __ Sllv(TMP, TMP, AT);
2492 __ Srlv(dst_low, lhs_low, rhs_reg);
2493 __ Or(dst_low, dst_low, TMP);
2494 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
2495 __ Beqz(TMP, &done);
2496 __ Move(dst_low, dst_high);
2497 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08002498 } else {
2499 __ Nor(AT, ZERO, rhs_reg);
2500 __ Srlv(TMP, lhs_low, rhs_reg);
2501 __ Sll(dst_low, lhs_high, 1);
2502 __ Sllv(dst_low, dst_low, AT);
2503 __ Or(dst_low, dst_low, TMP);
2504 __ Srlv(TMP, lhs_high, rhs_reg);
2505 __ Sll(dst_high, lhs_low, 1);
2506 __ Sllv(dst_high, dst_high, AT);
2507 __ Or(dst_high, dst_high, TMP);
2508 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
2509 __ Beqz(TMP, &done);
2510 __ Move(TMP, dst_high);
2511 __ Move(dst_high, dst_low);
2512 __ Move(dst_low, TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002513 }
2514 __ Bind(&done);
2515 }
2516 break;
2517 }
2518
2519 default:
2520 LOG(FATAL) << "Unexpected shift operation type " << type;
2521 }
2522}
2523
2524void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) {
2525 HandleBinaryOp(instruction);
2526}
2527
2528void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) {
2529 HandleBinaryOp(instruction);
2530}
2531
2532void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) {
2533 HandleBinaryOp(instruction);
2534}
2535
2536void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) {
2537 HandleBinaryOp(instruction);
2538}
2539
2540void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002541 DataType::Type type = instruction->GetType();
Alexey Frunze15958152017-02-09 19:08:30 -08002542 bool object_array_get_with_read_barrier =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002543 kEmitCompilerReadBarrier && (type == DataType::Type::kReference);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002544 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01002545 new (GetGraph()->GetAllocator()) LocationSummary(instruction,
2546 object_array_get_with_read_barrier
2547 ? LocationSummary::kCallOnSlowPath
2548 : LocationSummary::kNoCall);
Alexey Frunzec61c0762017-04-10 13:54:23 -07002549 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
2550 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
2551 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002552 locations->SetInAt(0, Location::RequiresRegister());
2553 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002554 if (DataType::IsFloatingPointType(type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002555 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2556 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08002557 // The output overlaps in the case of an object array get with
2558 // read barriers enabled: we do not want the move to overwrite the
2559 // array's location, as we need it to emit the read barrier.
2560 locations->SetOut(Location::RequiresRegister(),
2561 object_array_get_with_read_barrier
2562 ? Location::kOutputOverlap
2563 : Location::kNoOutputOverlap);
2564 }
2565 // We need a temporary register for the read barrier marking slow
2566 // path in CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier.
2567 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002568 bool temp_needed = instruction->GetIndex()->IsConstant()
2569 ? !kBakerReadBarrierThunksEnableForFields
2570 : !kBakerReadBarrierThunksEnableForArrays;
2571 if (temp_needed) {
2572 locations->AddTemp(Location::RequiresRegister());
2573 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002574 }
2575}
2576
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002577static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS* codegen) {
2578 auto null_checker = [codegen, instruction]() {
2579 codegen->MaybeRecordImplicitNullCheck(instruction);
Alexey Frunze2923db72016-08-20 01:55:47 -07002580 };
2581 return null_checker;
2582}
2583
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002584void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) {
2585 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08002586 Location obj_loc = locations->InAt(0);
2587 Register obj = obj_loc.AsRegister<Register>();
2588 Location out_loc = locations->Out();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002589 Location index = locations->InAt(1);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01002590 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002591 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002592
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002593 DataType::Type type = instruction->GetType();
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002594 const bool maybe_compressed_char_at = mirror::kUseStringCompression &&
2595 instruction->IsStringCharAt();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002596 switch (type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002597 case DataType::Type::kBool:
2598 case DataType::Type::kUint8: {
Alexey Frunze15958152017-02-09 19:08:30 -08002599 Register out = out_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002600 if (index.IsConstant()) {
2601 size_t offset =
2602 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002603 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002604 } else {
2605 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07002606 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002607 }
2608 break;
2609 }
2610
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002611 case DataType::Type::kInt8: {
Alexey Frunze15958152017-02-09 19:08:30 -08002612 Register out = out_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002613 if (index.IsConstant()) {
2614 size_t offset =
2615 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002616 __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002617 } else {
2618 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07002619 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002620 }
2621 break;
2622 }
2623
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002624 case DataType::Type::kUint16: {
Alexey Frunze15958152017-02-09 19:08:30 -08002625 Register out = out_loc.AsRegister<Register>();
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002626 if (maybe_compressed_char_at) {
2627 uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
2628 __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker);
2629 __ Sll(TMP, TMP, 31); // Extract compression flag into the most significant bit of TMP.
2630 static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u,
2631 "Expecting 0=compressed, 1=uncompressed");
2632 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002633 if (index.IsConstant()) {
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002634 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
2635 if (maybe_compressed_char_at) {
2636 MipsLabel uncompressed_load, done;
2637 __ Bnez(TMP, &uncompressed_load);
2638 __ LoadFromOffset(kLoadUnsignedByte,
2639 out,
2640 obj,
2641 data_offset + (const_index << TIMES_1));
2642 __ B(&done);
2643 __ Bind(&uncompressed_load);
2644 __ LoadFromOffset(kLoadUnsignedHalfword,
2645 out,
2646 obj,
2647 data_offset + (const_index << TIMES_2));
2648 __ Bind(&done);
2649 } else {
2650 __ LoadFromOffset(kLoadUnsignedHalfword,
2651 out,
2652 obj,
2653 data_offset + (const_index << TIMES_2),
2654 null_checker);
2655 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002656 } else {
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002657 Register index_reg = index.AsRegister<Register>();
2658 if (maybe_compressed_char_at) {
2659 MipsLabel uncompressed_load, done;
2660 __ Bnez(TMP, &uncompressed_load);
2661 __ Addu(TMP, obj, index_reg);
2662 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset);
2663 __ B(&done);
2664 __ Bind(&uncompressed_load);
Chris Larsencd0295d2017-03-31 15:26:54 -07002665 __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002666 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset);
2667 __ Bind(&done);
Lena Djokica2901602017-09-21 13:50:52 +02002668 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2669 __ Addu(TMP, index_reg, obj);
2670 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002671 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002672 __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002673 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker);
2674 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002675 }
2676 break;
2677 }
2678
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002679 case DataType::Type::kInt16: {
2680 Register out = out_loc.AsRegister<Register>();
2681 if (index.IsConstant()) {
2682 size_t offset =
2683 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2684 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker);
Lena Djokica2901602017-09-21 13:50:52 +02002685 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2686 __ Addu(TMP, index.AsRegister<Register>(), obj);
2687 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker);
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002688 } else {
2689 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_2, TMP);
2690 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker);
2691 }
2692 break;
2693 }
2694
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002695 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002696 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
Alexey Frunze15958152017-02-09 19:08:30 -08002697 Register out = out_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002698 if (index.IsConstant()) {
2699 size_t offset =
2700 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002701 __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker);
Lena Djokica2901602017-09-21 13:50:52 +02002702 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2703 __ Addu(TMP, index.AsRegister<Register>(), obj);
2704 __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002705 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002706 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002707 __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002708 }
2709 break;
2710 }
2711
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002712 case DataType::Type::kReference: {
Alexey Frunze15958152017-02-09 19:08:30 -08002713 static_assert(
2714 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
2715 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
2716 // /* HeapReference<Object> */ out =
2717 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
2718 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002719 bool temp_needed = index.IsConstant()
2720 ? !kBakerReadBarrierThunksEnableForFields
2721 : !kBakerReadBarrierThunksEnableForArrays;
2722 Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation();
Alexey Frunze15958152017-02-09 19:08:30 -08002723 // Note that a potential implicit null check is handled in this
2724 // CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier call.
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002725 DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0)));
2726 if (index.IsConstant()) {
2727 // Array load with a constant index can be treated as a field load.
2728 size_t offset =
2729 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2730 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
2731 out_loc,
2732 obj,
2733 offset,
2734 temp,
2735 /* needs_null_check */ false);
2736 } else {
2737 codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction,
2738 out_loc,
2739 obj,
2740 data_offset,
2741 index,
2742 temp,
2743 /* needs_null_check */ false);
2744 }
Alexey Frunze15958152017-02-09 19:08:30 -08002745 } else {
2746 Register out = out_loc.AsRegister<Register>();
2747 if (index.IsConstant()) {
2748 size_t offset =
2749 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2750 __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker);
2751 // If read barriers are enabled, emit read barriers other than
2752 // Baker's using a slow path (and also unpoison the loaded
2753 // reference, if heap poisoning is enabled).
2754 codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
2755 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002756 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP);
Alexey Frunze15958152017-02-09 19:08:30 -08002757 __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
2758 // If read barriers are enabled, emit read barriers other than
2759 // Baker's using a slow path (and also unpoison the loaded
2760 // reference, if heap poisoning is enabled).
2761 codegen_->MaybeGenerateReadBarrierSlow(instruction,
2762 out_loc,
2763 out_loc,
2764 obj_loc,
2765 data_offset,
2766 index);
2767 }
2768 }
2769 break;
2770 }
2771
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002772 case DataType::Type::kInt64: {
Alexey Frunze15958152017-02-09 19:08:30 -08002773 Register out = out_loc.AsRegisterPairLow<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002774 if (index.IsConstant()) {
2775 size_t offset =
2776 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002777 __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker);
Lena Djokica2901602017-09-21 13:50:52 +02002778 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2779 __ Addu(TMP, index.AsRegister<Register>(), obj);
2780 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002781 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002782 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002783 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002784 }
2785 break;
2786 }
2787
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002788 case DataType::Type::kFloat32: {
Alexey Frunze15958152017-02-09 19:08:30 -08002789 FRegister out = out_loc.AsFpuRegister<FRegister>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002790 if (index.IsConstant()) {
2791 size_t offset =
2792 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002793 __ LoadSFromOffset(out, obj, offset, null_checker);
Lena Djokica2901602017-09-21 13:50:52 +02002794 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2795 __ Addu(TMP, index.AsRegister<Register>(), obj);
2796 __ LoadSFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002797 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002798 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002799 __ LoadSFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002800 }
2801 break;
2802 }
2803
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002804 case DataType::Type::kFloat64: {
Alexey Frunze15958152017-02-09 19:08:30 -08002805 FRegister out = out_loc.AsFpuRegister<FRegister>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002806 if (index.IsConstant()) {
2807 size_t offset =
2808 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002809 __ LoadDFromOffset(out, obj, offset, null_checker);
Lena Djokica2901602017-09-21 13:50:52 +02002810 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2811 __ Addu(TMP, index.AsRegister<Register>(), obj);
2812 __ LoadDFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002813 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002814 __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002815 __ LoadDFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002816 }
2817 break;
2818 }
2819
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002820 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002821 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2822 UNREACHABLE();
2823 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002824}
2825
2826void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01002827 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002828 locations->SetInAt(0, Location::RequiresRegister());
2829 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2830}
2831
2832void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) {
2833 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01002834 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002835 Register obj = locations->InAt(0).AsRegister<Register>();
2836 Register out = locations->Out().AsRegister<Register>();
2837 __ LoadFromOffset(kLoadWord, out, obj, offset);
2838 codegen_->MaybeRecordImplicitNullCheck(instruction);
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002839 // Mask out compression flag from String's array length.
2840 if (mirror::kUseStringCompression && instruction->IsStringLength()) {
2841 __ Srl(out, out, 1u);
2842 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002843}
2844
Alexey Frunzef58b2482016-09-02 22:14:06 -07002845Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) {
2846 return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern())
2847 ? Location::ConstantLocation(instruction->AsConstant())
2848 : Location::RequiresRegister();
2849}
2850
2851Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) {
2852 // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register.
2853 // We can store a non-zero float or double constant without first loading it into the FPU,
2854 // but we should only prefer this if the constant has a single use.
2855 if (instruction->IsConstant() &&
2856 (instruction->AsConstant()->IsZeroBitPattern() ||
2857 instruction->GetUses().HasExactlyOneElement())) {
2858 return Location::ConstantLocation(instruction->AsConstant());
2859 // Otherwise fall through and require an FPU register for the constant.
2860 }
2861 return Location::RequiresFpuRegister();
2862}
2863
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002864void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002865 DataType::Type value_type = instruction->GetComponentType();
Alexey Frunze15958152017-02-09 19:08:30 -08002866
2867 bool needs_write_barrier =
2868 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
2869 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
2870
Vladimir Markoca6fff82017-10-03 14:49:14 +01002871 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002872 instruction,
Alexey Frunze15958152017-02-09 19:08:30 -08002873 may_need_runtime_call_for_type_check ?
2874 LocationSummary::kCallOnSlowPath :
2875 LocationSummary::kNoCall);
2876
2877 locations->SetInAt(0, Location::RequiresRegister());
2878 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002879 if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
Alexey Frunze15958152017-02-09 19:08:30 -08002880 locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002881 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08002882 locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2)));
2883 }
2884 if (needs_write_barrier) {
2885 // Temporary register for the write barrier.
2886 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002887 }
2888}
2889
2890void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) {
2891 LocationSummary* locations = instruction->GetLocations();
2892 Register obj = locations->InAt(0).AsRegister<Register>();
2893 Location index = locations->InAt(1);
Alexey Frunzef58b2482016-09-02 22:14:06 -07002894 Location value_location = locations->InAt(2);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002895 DataType::Type value_type = instruction->GetComponentType();
Alexey Frunze15958152017-02-09 19:08:30 -08002896 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002897 bool needs_write_barrier =
2898 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002899 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Alexey Frunzef58b2482016-09-02 22:14:06 -07002900 Register base_reg = index.IsConstant() ? obj : TMP;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002901
2902 switch (value_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002903 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002904 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002905 case DataType::Type::kInt8: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002906 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002907 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002908 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002909 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002910 __ Addu(base_reg, obj, index.AsRegister<Register>());
2911 }
2912 if (value_location.IsConstant()) {
2913 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2914 __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker);
2915 } else {
2916 Register value = value_location.AsRegister<Register>();
2917 __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002918 }
2919 break;
2920 }
2921
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01002922 case DataType::Type::kUint16:
2923 case DataType::Type::kInt16: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002924 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002925 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002926 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2;
Lena Djokica2901602017-09-21 13:50:52 +02002927 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2928 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002929 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002930 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_2, base_reg);
Alexey Frunzef58b2482016-09-02 22:14:06 -07002931 }
2932 if (value_location.IsConstant()) {
2933 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2934 __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker);
2935 } else {
2936 Register value = value_location.AsRegister<Register>();
2937 __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002938 }
2939 break;
2940 }
2941
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002942 case DataType::Type::kInt32: {
Alexey Frunze15958152017-02-09 19:08:30 -08002943 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2944 if (index.IsConstant()) {
2945 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Lena Djokica2901602017-09-21 13:50:52 +02002946 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2947 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Alexey Frunze15958152017-02-09 19:08:30 -08002948 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002949 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg);
Alexey Frunze15958152017-02-09 19:08:30 -08002950 }
2951 if (value_location.IsConstant()) {
2952 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2953 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2954 } else {
2955 Register value = value_location.AsRegister<Register>();
2956 __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
2957 }
2958 break;
2959 }
2960
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01002961 case DataType::Type::kReference: {
Alexey Frunze15958152017-02-09 19:08:30 -08002962 if (value_location.IsConstant()) {
2963 // Just setting null.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002964 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002965 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002966 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002967 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07002968 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002969 }
Alexey Frunze15958152017-02-09 19:08:30 -08002970 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2971 DCHECK_EQ(value, 0);
2972 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2973 DCHECK(!needs_write_barrier);
2974 DCHECK(!may_need_runtime_call_for_type_check);
2975 break;
2976 }
2977
2978 DCHECK(needs_write_barrier);
2979 Register value = value_location.AsRegister<Register>();
2980 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2981 Register temp2 = TMP; // Doesn't need to survive slow path.
2982 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2983 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
2984 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
2985 MipsLabel done;
2986 SlowPathCodeMIPS* slow_path = nullptr;
2987
2988 if (may_need_runtime_call_for_type_check) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01002989 slow_path = new (GetGraph()->GetAllocator()) ArraySetSlowPathMIPS(instruction);
Alexey Frunze15958152017-02-09 19:08:30 -08002990 codegen_->AddSlowPath(slow_path);
2991 if (instruction->GetValueCanBeNull()) {
2992 MipsLabel non_zero;
2993 __ Bnez(value, &non_zero);
2994 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2995 if (index.IsConstant()) {
2996 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Lena Djokica2901602017-09-21 13:50:52 +02002997 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
2998 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Alexey Frunzec061de12017-02-14 13:27:23 -08002999 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07003000 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg);
Alexey Frunzec061de12017-02-14 13:27:23 -08003001 }
Alexey Frunze15958152017-02-09 19:08:30 -08003002 __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
3003 __ B(&done);
3004 __ Bind(&non_zero);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003005 }
Alexey Frunze15958152017-02-09 19:08:30 -08003006
3007 // Note that when read barriers are enabled, the type checks
3008 // are performed without read barriers. This is fine, even in
3009 // the case where a class object is in the from-space after
3010 // the flip, as a comparison involving such a type would not
3011 // produce a false positive; it may of course produce a false
3012 // negative, in which case we would take the ArraySet slow
3013 // path.
3014
3015 // /* HeapReference<Class> */ temp1 = obj->klass_
3016 __ LoadFromOffset(kLoadWord, temp1, obj, class_offset, null_checker);
3017 __ MaybeUnpoisonHeapReference(temp1);
3018
3019 // /* HeapReference<Class> */ temp1 = temp1->component_type_
3020 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
3021 // /* HeapReference<Class> */ temp2 = value->klass_
3022 __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
3023 // If heap poisoning is enabled, no need to unpoison `temp1`
3024 // nor `temp2`, as we are comparing two poisoned references.
3025
3026 if (instruction->StaticTypeOfArrayIsObjectArray()) {
3027 MipsLabel do_put;
3028 __ Beq(temp1, temp2, &do_put);
3029 // If heap poisoning is enabled, the `temp1` reference has
3030 // not been unpoisoned yet; unpoison it now.
3031 __ MaybeUnpoisonHeapReference(temp1);
3032
3033 // /* HeapReference<Class> */ temp1 = temp1->super_class_
3034 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
3035 // If heap poisoning is enabled, no need to unpoison
3036 // `temp1`, as we are comparing against null below.
3037 __ Bnez(temp1, slow_path->GetEntryLabel());
3038 __ Bind(&do_put);
3039 } else {
3040 __ Bne(temp1, temp2, slow_path->GetEntryLabel());
3041 }
3042 }
3043
3044 Register source = value;
3045 if (kPoisonHeapReferences) {
3046 // Note that in the case where `value` is a null reference,
3047 // we do not enter this block, as a null reference does not
3048 // need poisoning.
3049 __ Move(temp1, value);
3050 __ PoisonHeapReference(temp1);
3051 source = temp1;
3052 }
3053
3054 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
3055 if (index.IsConstant()) {
3056 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003057 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07003058 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg);
Alexey Frunze15958152017-02-09 19:08:30 -08003059 }
3060 __ StoreToOffset(kStoreWord, source, base_reg, data_offset);
3061
3062 if (!may_need_runtime_call_for_type_check) {
3063 codegen_->MaybeRecordImplicitNullCheck(instruction);
3064 }
3065
3066 codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull());
3067
3068 if (done.IsLinked()) {
3069 __ Bind(&done);
3070 }
3071
3072 if (slow_path != nullptr) {
3073 __ Bind(slow_path->GetExitLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003074 }
3075 break;
3076 }
3077
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003078 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003079 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003080 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07003081 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Lena Djokica2901602017-09-21 13:50:52 +02003082 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
3083 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003084 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07003085 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg);
Alexey Frunzef58b2482016-09-02 22:14:06 -07003086 }
3087 if (value_location.IsConstant()) {
3088 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
3089 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
3090 } else {
3091 Register value = value_location.AsRegisterPairLow<Register>();
3092 __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003093 }
3094 break;
3095 }
3096
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003097 case DataType::Type::kFloat32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003098 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003099 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07003100 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Lena Djokica2901602017-09-21 13:50:52 +02003101 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
3102 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003103 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07003104 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg);
Alexey Frunzef58b2482016-09-02 22:14:06 -07003105 }
3106 if (value_location.IsConstant()) {
3107 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
3108 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
3109 } else {
3110 FRegister value = value_location.AsFpuRegister<FRegister>();
3111 __ StoreSToOffset(value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003112 }
3113 break;
3114 }
3115
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003116 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003117 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003118 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07003119 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Lena Djokica2901602017-09-21 13:50:52 +02003120 } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) {
3121 __ Addu(base_reg, index.AsRegister<Register>(), obj);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003122 } else {
Chris Larsencd0295d2017-03-31 15:26:54 -07003123 __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg);
Alexey Frunzef58b2482016-09-02 22:14:06 -07003124 }
3125 if (value_location.IsConstant()) {
3126 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
3127 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
3128 } else {
3129 FRegister value = value_location.AsFpuRegister<FRegister>();
3130 __ StoreDToOffset(value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003131 }
3132 break;
3133 }
3134
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003135 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003136 LOG(FATAL) << "Unreachable type " << instruction->GetType();
3137 UNREACHABLE();
3138 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003139}
3140
Lena Djokica2901602017-09-21 13:50:52 +02003141void LocationsBuilderMIPS::VisitIntermediateArrayAddressIndex(
3142 HIntermediateArrayAddressIndex* instruction) {
3143 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003144 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Lena Djokica2901602017-09-21 13:50:52 +02003145
3146 HIntConstant* shift = instruction->GetShift()->AsIntConstant();
3147
3148 locations->SetInAt(0, Location::RequiresRegister());
3149 locations->SetInAt(1, Location::ConstantLocation(shift));
3150 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3151}
3152
3153void InstructionCodeGeneratorMIPS::VisitIntermediateArrayAddressIndex(
3154 HIntermediateArrayAddressIndex* instruction) {
3155 LocationSummary* locations = instruction->GetLocations();
3156 Register index_reg = locations->InAt(0).AsRegister<Register>();
3157 uint32_t shift = instruction->GetShift()->AsIntConstant()->GetValue();
3158 __ Sll(locations->Out().AsRegister<Register>(), index_reg, shift);
3159}
3160
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003161void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01003162 RegisterSet caller_saves = RegisterSet::Empty();
3163 InvokeRuntimeCallingConvention calling_convention;
3164 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3165 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3166 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003167 locations->SetInAt(0, Location::RequiresRegister());
3168 locations->SetInAt(1, Location::RequiresRegister());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003169}
3170
3171void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
3172 LocationSummary* locations = instruction->GetLocations();
3173 BoundsCheckSlowPathMIPS* slow_path =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003174 new (GetGraph()->GetAllocator()) BoundsCheckSlowPathMIPS(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003175 codegen_->AddSlowPath(slow_path);
3176
3177 Register index = locations->InAt(0).AsRegister<Register>();
3178 Register length = locations->InAt(1).AsRegister<Register>();
3179
3180 // length is limited by the maximum positive signed 32-bit integer.
3181 // Unsigned comparison of length and index checks for index < 0
3182 // and for length <= index simultaneously.
3183 __ Bgeu(index, length, slow_path->GetEntryLabel());
3184}
3185
Alexey Frunze15958152017-02-09 19:08:30 -08003186// Temp is used for read barrier.
3187static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) {
3188 if (kEmitCompilerReadBarrier &&
Alexey Frunze4147fcc2017-06-17 19:57:27 -07003189 !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) &&
Alexey Frunze15958152017-02-09 19:08:30 -08003190 (kUseBakerReadBarrier ||
3191 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
3192 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
3193 type_check_kind == TypeCheckKind::kArrayObjectCheck)) {
3194 return 1;
3195 }
3196 return 0;
3197}
3198
3199// Extra temp is used for read barrier.
3200static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) {
3201 return 1 + NumberOfInstanceOfTemps(type_check_kind);
3202}
3203
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003204void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003205 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
3206 bool throws_into_catch = instruction->CanThrowIntoCatchBlock();
3207
3208 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
3209 switch (type_check_kind) {
3210 case TypeCheckKind::kExactCheck:
3211 case TypeCheckKind::kAbstractClassCheck:
3212 case TypeCheckKind::kClassHierarchyCheck:
3213 case TypeCheckKind::kArrayObjectCheck:
Alexey Frunze15958152017-02-09 19:08:30 -08003214 call_kind = (throws_into_catch || kEmitCompilerReadBarrier)
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003215 ? LocationSummary::kCallOnSlowPath
3216 : LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path.
3217 break;
3218 case TypeCheckKind::kArrayCheck:
3219 case TypeCheckKind::kUnresolvedCheck:
3220 case TypeCheckKind::kInterfaceCheck:
3221 call_kind = LocationSummary::kCallOnSlowPath;
3222 break;
3223 }
3224
Vladimir Markoca6fff82017-10-03 14:49:14 +01003225 LocationSummary* locations =
3226 new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003227 locations->SetInAt(0, Location::RequiresRegister());
3228 locations->SetInAt(1, Location::RequiresRegister());
Alexey Frunze15958152017-02-09 19:08:30 -08003229 locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003230}
3231
3232void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003233 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003234 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08003235 Location obj_loc = locations->InAt(0);
3236 Register obj = obj_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003237 Register cls = locations->InAt(1).AsRegister<Register>();
Alexey Frunze15958152017-02-09 19:08:30 -08003238 Location temp_loc = locations->GetTemp(0);
3239 Register temp = temp_loc.AsRegister<Register>();
3240 const size_t num_temps = NumberOfCheckCastTemps(type_check_kind);
3241 DCHECK_LE(num_temps, 2u);
3242 Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation();
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003243 const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3244 const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
3245 const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
3246 const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
3247 const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value();
3248 const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value();
3249 const uint32_t object_array_data_offset =
3250 mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value();
3251 MipsLabel done;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003252
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003253 // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases
3254 // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding
3255 // read barriers is done for performance and code size reasons.
3256 bool is_type_check_slow_path_fatal = false;
3257 if (!kEmitCompilerReadBarrier) {
3258 is_type_check_slow_path_fatal =
3259 (type_check_kind == TypeCheckKind::kExactCheck ||
3260 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
3261 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
3262 type_check_kind == TypeCheckKind::kArrayObjectCheck) &&
3263 !instruction->CanThrowIntoCatchBlock();
3264 }
3265 SlowPathCodeMIPS* slow_path =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003266 new (GetGraph()->GetAllocator()) TypeCheckSlowPathMIPS(instruction,
3267 is_type_check_slow_path_fatal);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003268 codegen_->AddSlowPath(slow_path);
3269
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003270 // Avoid this check if we know `obj` is not null.
3271 if (instruction->MustDoNullCheck()) {
3272 __ Beqz(obj, &done);
3273 }
3274
3275 switch (type_check_kind) {
3276 case TypeCheckKind::kExactCheck:
3277 case TypeCheckKind::kArrayCheck: {
3278 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003279 GenerateReferenceLoadTwoRegisters(instruction,
3280 temp_loc,
3281 obj_loc,
3282 class_offset,
3283 maybe_temp2_loc,
3284 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003285 // Jump to slow path for throwing the exception or doing a
3286 // more involved array check.
3287 __ Bne(temp, cls, slow_path->GetEntryLabel());
3288 break;
3289 }
3290
3291 case TypeCheckKind::kAbstractClassCheck: {
3292 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003293 GenerateReferenceLoadTwoRegisters(instruction,
3294 temp_loc,
3295 obj_loc,
3296 class_offset,
3297 maybe_temp2_loc,
3298 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003299 // If the class is abstract, we eagerly fetch the super class of the
3300 // object to avoid doing a comparison we know will fail.
3301 MipsLabel loop;
3302 __ Bind(&loop);
3303 // /* HeapReference<Class> */ temp = temp->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08003304 GenerateReferenceLoadOneRegister(instruction,
3305 temp_loc,
3306 super_offset,
3307 maybe_temp2_loc,
3308 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003309 // If the class reference currently in `temp` is null, jump to the slow path to throw the
3310 // exception.
3311 __ Beqz(temp, slow_path->GetEntryLabel());
3312 // Otherwise, compare the classes.
3313 __ Bne(temp, cls, &loop);
3314 break;
3315 }
3316
3317 case TypeCheckKind::kClassHierarchyCheck: {
3318 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003319 GenerateReferenceLoadTwoRegisters(instruction,
3320 temp_loc,
3321 obj_loc,
3322 class_offset,
3323 maybe_temp2_loc,
3324 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003325 // Walk over the class hierarchy to find a match.
3326 MipsLabel loop;
3327 __ Bind(&loop);
3328 __ Beq(temp, cls, &done);
3329 // /* HeapReference<Class> */ temp = temp->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08003330 GenerateReferenceLoadOneRegister(instruction,
3331 temp_loc,
3332 super_offset,
3333 maybe_temp2_loc,
3334 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003335 // If the class reference currently in `temp` is null, jump to the slow path to throw the
3336 // exception. Otherwise, jump to the beginning of the loop.
3337 __ Bnez(temp, &loop);
3338 __ B(slow_path->GetEntryLabel());
3339 break;
3340 }
3341
3342 case TypeCheckKind::kArrayObjectCheck: {
3343 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003344 GenerateReferenceLoadTwoRegisters(instruction,
3345 temp_loc,
3346 obj_loc,
3347 class_offset,
3348 maybe_temp2_loc,
3349 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003350 // Do an exact check.
3351 __ Beq(temp, cls, &done);
3352 // Otherwise, we need to check that the object's class is a non-primitive array.
3353 // /* HeapReference<Class> */ temp = temp->component_type_
Alexey Frunze15958152017-02-09 19:08:30 -08003354 GenerateReferenceLoadOneRegister(instruction,
3355 temp_loc,
3356 component_offset,
3357 maybe_temp2_loc,
3358 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003359 // If the component type is null, jump to the slow path to throw the exception.
3360 __ Beqz(temp, slow_path->GetEntryLabel());
3361 // Otherwise, the object is indeed an array, further check that this component
3362 // type is not a primitive type.
3363 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
3364 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
3365 __ Bnez(temp, slow_path->GetEntryLabel());
3366 break;
3367 }
3368
3369 case TypeCheckKind::kUnresolvedCheck:
3370 // We always go into the type check slow path for the unresolved check case.
3371 // We cannot directly call the CheckCast runtime entry point
3372 // without resorting to a type checking slow path here (i.e. by
3373 // calling InvokeRuntime directly), as it would require to
3374 // assign fixed registers for the inputs of this HInstanceOf
3375 // instruction (following the runtime calling convention), which
3376 // might be cluttered by the potential first read barrier
3377 // emission at the beginning of this method.
3378 __ B(slow_path->GetEntryLabel());
3379 break;
3380
3381 case TypeCheckKind::kInterfaceCheck: {
3382 // Avoid read barriers to improve performance of the fast path. We can not get false
3383 // positives by doing this.
3384 // /* HeapReference<Class> */ temp = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08003385 GenerateReferenceLoadTwoRegisters(instruction,
3386 temp_loc,
3387 obj_loc,
3388 class_offset,
3389 maybe_temp2_loc,
3390 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003391 // /* HeapReference<Class> */ temp = temp->iftable_
Alexey Frunze15958152017-02-09 19:08:30 -08003392 GenerateReferenceLoadTwoRegisters(instruction,
3393 temp_loc,
3394 temp_loc,
3395 iftable_offset,
3396 maybe_temp2_loc,
3397 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08003398 // Iftable is never null.
3399 __ Lw(TMP, temp, array_length_offset);
3400 // Loop through the iftable and check if any class matches.
3401 MipsLabel loop;
3402 __ Bind(&loop);
3403 __ Addiu(temp, temp, 2 * kHeapReferenceSize); // Possibly in delay slot on R2.
3404 __ Beqz(TMP, slow_path->GetEntryLabel());
3405 __ Lw(AT, temp, object_array_data_offset - 2 * kHeapReferenceSize);
3406 __ MaybeUnpoisonHeapReference(AT);
3407 // Go to next interface.
3408 __ Addiu(TMP, TMP, -2);
3409 // Compare the classes and continue the loop if they do not match.
3410 __ Bne(AT, cls, &loop);
3411 break;
3412 }
3413 }
3414
3415 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003416 __ Bind(slow_path->GetExitLabel());
3417}
3418
3419void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) {
3420 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003421 new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003422 locations->SetInAt(0, Location::RequiresRegister());
3423 if (check->HasUses()) {
3424 locations->SetOut(Location::SameAsFirstInput());
3425 }
3426}
3427
3428void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) {
3429 // We assume the class is not null.
Vladimir Markoca6fff82017-10-03 14:49:14 +01003430 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetAllocator()) LoadClassSlowPathMIPS(
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003431 check->GetLoadClass(),
3432 check,
3433 check->GetDexPc(),
3434 true);
3435 codegen_->AddSlowPath(slow_path);
3436 GenerateClassInitializationCheck(slow_path,
3437 check->GetLocations()->InAt(0).AsRegister<Register>());
3438}
3439
3440void LocationsBuilderMIPS::VisitCompare(HCompare* compare) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003441 DataType::Type in_type = compare->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003442
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003443 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003444 new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003445
3446 switch (in_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003447 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003448 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003449 case DataType::Type::kInt8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003450 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003451 case DataType::Type::kInt16:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003452 case DataType::Type::kInt32:
Alexey Frunzee7697712016-09-15 21:37:49 -07003453 locations->SetInAt(0, Location::RequiresRegister());
3454 locations->SetInAt(1, Location::RequiresRegister());
3455 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3456 break;
3457
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003458 case DataType::Type::kInt64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003459 locations->SetInAt(0, Location::RequiresRegister());
3460 locations->SetInAt(1, Location::RequiresRegister());
3461 // Output overlaps because it is written before doing the low comparison.
3462 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3463 break;
3464
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003465 case DataType::Type::kFloat32:
3466 case DataType::Type::kFloat64:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003467 locations->SetInAt(0, Location::RequiresFpuRegister());
3468 locations->SetInAt(1, Location::RequiresFpuRegister());
3469 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003470 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003471
3472 default:
3473 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
3474 }
3475}
3476
3477void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) {
3478 LocationSummary* locations = instruction->GetLocations();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003479 Register res = locations->Out().AsRegister<Register>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003480 DataType::Type in_type = instruction->InputAt(0)->GetType();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003481 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003482
3483 // 0 if: left == right
3484 // 1 if: left > right
3485 // -1 if: left < right
3486 switch (in_type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003487 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003488 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003489 case DataType::Type::kInt8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003490 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003491 case DataType::Type::kInt16:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003492 case DataType::Type::kInt32: {
Aart Bika19616e2016-02-01 18:57:58 -08003493 Register lhs = locations->InAt(0).AsRegister<Register>();
3494 Register rhs = locations->InAt(1).AsRegister<Register>();
3495 __ Slt(TMP, lhs, rhs);
3496 __ Slt(res, rhs, lhs);
3497 __ Subu(res, res, TMP);
3498 break;
3499 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003500 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003501 MipsLabel done;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003502 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
3503 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
3504 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
3505 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
3506 // TODO: more efficient (direct) comparison with a constant.
3507 __ Slt(TMP, lhs_high, rhs_high);
3508 __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt.
3509 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
3510 __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal.
3511 __ Sltu(TMP, lhs_low, rhs_low);
3512 __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt.
3513 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
3514 __ Bind(&done);
3515 break;
3516 }
3517
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003518 case DataType::Type::kFloat32: {
Roland Levillain32ca3752016-02-17 16:49:37 +00003519 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003520 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3521 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3522 MipsLabel done;
3523 if (isR6) {
3524 __ CmpEqS(FTMP, lhs, rhs);
3525 __ LoadConst32(res, 0);
3526 __ Bc1nez(FTMP, &done);
3527 if (gt_bias) {
3528 __ CmpLtS(FTMP, lhs, rhs);
3529 __ LoadConst32(res, -1);
3530 __ Bc1nez(FTMP, &done);
3531 __ LoadConst32(res, 1);
3532 } else {
3533 __ CmpLtS(FTMP, rhs, lhs);
3534 __ LoadConst32(res, 1);
3535 __ Bc1nez(FTMP, &done);
3536 __ LoadConst32(res, -1);
3537 }
3538 } else {
3539 if (gt_bias) {
3540 __ ColtS(0, lhs, rhs);
3541 __ LoadConst32(res, -1);
3542 __ Bc1t(0, &done);
3543 __ CeqS(0, lhs, rhs);
3544 __ LoadConst32(res, 1);
3545 __ Movt(res, ZERO, 0);
3546 } else {
3547 __ ColtS(0, rhs, lhs);
3548 __ LoadConst32(res, 1);
3549 __ Bc1t(0, &done);
3550 __ CeqS(0, lhs, rhs);
3551 __ LoadConst32(res, -1);
3552 __ Movt(res, ZERO, 0);
3553 }
3554 }
3555 __ Bind(&done);
3556 break;
3557 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003558 case DataType::Type::kFloat64: {
Roland Levillain32ca3752016-02-17 16:49:37 +00003559 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003560 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3561 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3562 MipsLabel done;
3563 if (isR6) {
3564 __ CmpEqD(FTMP, lhs, rhs);
3565 __ LoadConst32(res, 0);
3566 __ Bc1nez(FTMP, &done);
3567 if (gt_bias) {
3568 __ CmpLtD(FTMP, lhs, rhs);
3569 __ LoadConst32(res, -1);
3570 __ Bc1nez(FTMP, &done);
3571 __ LoadConst32(res, 1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003572 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003573 __ CmpLtD(FTMP, rhs, lhs);
3574 __ LoadConst32(res, 1);
3575 __ Bc1nez(FTMP, &done);
3576 __ LoadConst32(res, -1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003577 }
3578 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003579 if (gt_bias) {
3580 __ ColtD(0, lhs, rhs);
3581 __ LoadConst32(res, -1);
3582 __ Bc1t(0, &done);
3583 __ CeqD(0, lhs, rhs);
3584 __ LoadConst32(res, 1);
3585 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003586 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003587 __ ColtD(0, rhs, lhs);
3588 __ LoadConst32(res, 1);
3589 __ Bc1t(0, &done);
3590 __ CeqD(0, lhs, rhs);
3591 __ LoadConst32(res, -1);
3592 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003593 }
3594 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003595 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003596 break;
3597 }
3598
3599 default:
3600 LOG(FATAL) << "Unimplemented compare type " << in_type;
3601 }
3602}
3603
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00003604void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01003605 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003606 switch (instruction->InputAt(0)->GetType()) {
3607 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003608 case DataType::Type::kInt64:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003609 locations->SetInAt(0, Location::RequiresRegister());
3610 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3611 break;
3612
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003613 case DataType::Type::kFloat32:
3614 case DataType::Type::kFloat64:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003615 locations->SetInAt(0, Location::RequiresFpuRegister());
3616 locations->SetInAt(1, Location::RequiresFpuRegister());
3617 break;
3618 }
David Brazdilb3e773e2016-01-26 11:28:37 +00003619 if (!instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003620 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3621 }
3622}
3623
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00003624void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00003625 if (instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003626 return;
3627 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003628
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003629 DataType::Type type = instruction->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003630 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003631
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003632 switch (type) {
3633 default:
3634 // Integer case.
3635 GenerateIntCompare(instruction->GetCondition(), locations);
3636 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003637
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003638 case DataType::Type::kInt64:
Tijana Jakovljevic6d482aa2017-02-03 13:24:08 +01003639 GenerateLongCompare(instruction->GetCondition(), locations);
3640 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003641
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003642 case DataType::Type::kFloat32:
3643 case DataType::Type::kFloat64:
Alexey Frunze2ddb7172016-09-06 17:04:55 -07003644 GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations);
3645 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003646 }
3647}
3648
Alexey Frunze7e99e052015-11-24 19:28:01 -08003649void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
3650 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003651 DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32);
Alexey Frunze7e99e052015-11-24 19:28:01 -08003652
3653 LocationSummary* locations = instruction->GetLocations();
3654 Location second = locations->InAt(1);
3655 DCHECK(second.IsConstant());
3656
3657 Register out = locations->Out().AsRegister<Register>();
3658 Register dividend = locations->InAt(0).AsRegister<Register>();
3659 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
3660 DCHECK(imm == 1 || imm == -1);
3661
3662 if (instruction->IsRem()) {
3663 __ Move(out, ZERO);
3664 } else {
3665 if (imm == -1) {
3666 __ Subu(out, ZERO, dividend);
3667 } else if (out != dividend) {
3668 __ Move(out, dividend);
3669 }
3670 }
3671}
3672
3673void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
3674 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003675 DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32);
Alexey Frunze7e99e052015-11-24 19:28:01 -08003676
3677 LocationSummary* locations = instruction->GetLocations();
3678 Location second = locations->InAt(1);
3679 DCHECK(second.IsConstant());
3680
3681 Register out = locations->Out().AsRegister<Register>();
3682 Register dividend = locations->InAt(0).AsRegister<Register>();
3683 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003684 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Alexey Frunze7e99e052015-11-24 19:28:01 -08003685 int ctz_imm = CTZ(abs_imm);
3686
3687 if (instruction->IsDiv()) {
3688 if (ctz_imm == 1) {
3689 // Fast path for division by +/-2, which is very common.
3690 __ Srl(TMP, dividend, 31);
3691 } else {
3692 __ Sra(TMP, dividend, 31);
3693 __ Srl(TMP, TMP, 32 - ctz_imm);
3694 }
3695 __ Addu(out, dividend, TMP);
3696 __ Sra(out, out, ctz_imm);
3697 if (imm < 0) {
3698 __ Subu(out, ZERO, out);
3699 }
3700 } else {
3701 if (ctz_imm == 1) {
3702 // Fast path for modulo +/-2, which is very common.
3703 __ Sra(TMP, dividend, 31);
3704 __ Subu(out, dividend, TMP);
3705 __ Andi(out, out, 1);
3706 __ Addu(out, out, TMP);
3707 } else {
3708 __ Sra(TMP, dividend, 31);
3709 __ Srl(TMP, TMP, 32 - ctz_imm);
3710 __ Addu(out, dividend, TMP);
3711 if (IsUint<16>(abs_imm - 1)) {
3712 __ Andi(out, out, abs_imm - 1);
3713 } else {
3714 __ Sll(out, out, 32 - ctz_imm);
3715 __ Srl(out, out, 32 - ctz_imm);
3716 }
3717 __ Subu(out, out, TMP);
3718 }
3719 }
3720}
3721
3722void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
3723 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003724 DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32);
Alexey Frunze7e99e052015-11-24 19:28:01 -08003725
3726 LocationSummary* locations = instruction->GetLocations();
3727 Location second = locations->InAt(1);
3728 DCHECK(second.IsConstant());
3729
3730 Register out = locations->Out().AsRegister<Register>();
3731 Register dividend = locations->InAt(0).AsRegister<Register>();
3732 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
3733
3734 int64_t magic;
3735 int shift;
3736 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
3737
3738 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3739
3740 __ LoadConst32(TMP, magic);
3741 if (isR6) {
3742 __ MuhR6(TMP, dividend, TMP);
3743 } else {
3744 __ MultR2(dividend, TMP);
3745 __ Mfhi(TMP);
3746 }
3747 if (imm > 0 && magic < 0) {
3748 __ Addu(TMP, TMP, dividend);
3749 } else if (imm < 0 && magic > 0) {
3750 __ Subu(TMP, TMP, dividend);
3751 }
3752
3753 if (shift != 0) {
3754 __ Sra(TMP, TMP, shift);
3755 }
3756
3757 if (instruction->IsDiv()) {
3758 __ Sra(out, TMP, 31);
3759 __ Subu(out, TMP, out);
3760 } else {
3761 __ Sra(AT, TMP, 31);
3762 __ Subu(AT, TMP, AT);
3763 __ LoadConst32(TMP, imm);
3764 if (isR6) {
3765 __ MulR6(TMP, AT, TMP);
3766 } else {
3767 __ MulR2(TMP, AT, TMP);
3768 }
3769 __ Subu(out, dividend, TMP);
3770 }
3771}
3772
3773void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) {
3774 DCHECK(instruction->IsDiv() || instruction->IsRem());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003775 DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32);
Alexey Frunze7e99e052015-11-24 19:28:01 -08003776
3777 LocationSummary* locations = instruction->GetLocations();
3778 Register out = locations->Out().AsRegister<Register>();
3779 Location second = locations->InAt(1);
3780
3781 if (second.IsConstant()) {
3782 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
3783 if (imm == 0) {
3784 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
3785 } else if (imm == 1 || imm == -1) {
3786 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003787 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08003788 DivRemByPowerOfTwo(instruction);
3789 } else {
3790 DCHECK(imm <= -2 || imm >= 2);
3791 GenerateDivRemWithAnyConstant(instruction);
3792 }
3793 } else {
3794 Register dividend = locations->InAt(0).AsRegister<Register>();
3795 Register divisor = second.AsRegister<Register>();
3796 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3797 if (instruction->IsDiv()) {
3798 if (isR6) {
3799 __ DivR6(out, dividend, divisor);
3800 } else {
3801 __ DivR2(out, dividend, divisor);
3802 }
3803 } else {
3804 if (isR6) {
3805 __ ModR6(out, dividend, divisor);
3806 } else {
3807 __ ModR2(out, dividend, divisor);
3808 }
3809 }
3810 }
3811}
3812
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003813void LocationsBuilderMIPS::VisitDiv(HDiv* div) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003814 DataType::Type type = div->GetResultType();
3815 LocationSummary::CallKind call_kind = (type == DataType::Type::kInt64)
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003816 ? LocationSummary::kCallOnMainOnly
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003817 : LocationSummary::kNoCall;
3818
Vladimir Markoca6fff82017-10-03 14:49:14 +01003819 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003820
3821 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003822 case DataType::Type::kInt32:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003823 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08003824 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003825 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3826 break;
3827
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003828 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003829 InvokeRuntimeCallingConvention calling_convention;
3830 locations->SetInAt(0, Location::RegisterPairLocation(
3831 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
3832 locations->SetInAt(1, Location::RegisterPairLocation(
3833 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
3834 locations->SetOut(calling_convention.GetReturnLocation(type));
3835 break;
3836 }
3837
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003838 case DataType::Type::kFloat32:
3839 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003840 locations->SetInAt(0, Location::RequiresFpuRegister());
3841 locations->SetInAt(1, Location::RequiresFpuRegister());
3842 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3843 break;
3844
3845 default:
3846 LOG(FATAL) << "Unexpected div type " << type;
3847 }
3848}
3849
3850void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003851 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003852 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003853
3854 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003855 case DataType::Type::kInt32:
Alexey Frunze7e99e052015-11-24 19:28:01 -08003856 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003857 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003858 case DataType::Type::kInt64: {
Serban Constantinescufca16662016-07-14 09:21:59 +01003859 codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003860 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
3861 break;
3862 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003863 case DataType::Type::kFloat32:
3864 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003865 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
3866 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3867 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003868 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003869 __ DivS(dst, lhs, rhs);
3870 } else {
3871 __ DivD(dst, lhs, rhs);
3872 }
3873 break;
3874 }
3875 default:
3876 LOG(FATAL) << "Unexpected div type " << type;
3877 }
3878}
3879
3880void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01003881 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003882 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003883}
3884
3885void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01003886 SlowPathCodeMIPS* slow_path =
3887 new (GetGraph()->GetAllocator()) DivZeroCheckSlowPathMIPS(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003888 codegen_->AddSlowPath(slow_path);
3889 Location value = instruction->GetLocations()->InAt(0);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003890 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003891
3892 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003893 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01003894 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003895 case DataType::Type::kInt8:
3896 case DataType::Type::kUint16:
3897 case DataType::Type::kInt16:
3898 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003899 if (value.IsConstant()) {
3900 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
3901 __ B(slow_path->GetEntryLabel());
3902 } else {
3903 // A division by a non-null constant is valid. We don't need to perform
3904 // any check, so simply fall through.
3905 }
3906 } else {
3907 DCHECK(value.IsRegister()) << value;
3908 __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel());
3909 }
3910 break;
3911 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01003912 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003913 if (value.IsConstant()) {
3914 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
3915 __ B(slow_path->GetEntryLabel());
3916 } else {
3917 // A division by a non-null constant is valid. We don't need to perform
3918 // any check, so simply fall through.
3919 }
3920 } else {
3921 DCHECK(value.IsRegisterPair()) << value;
3922 __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>());
3923 __ Beqz(TMP, slow_path->GetEntryLabel());
3924 }
3925 break;
3926 }
3927 default:
3928 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
3929 }
3930}
3931
3932void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) {
3933 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003934 new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003935 locations->SetOut(Location::ConstantLocation(constant));
3936}
3937
3938void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
3939 // Will be generated at use site.
3940}
3941
3942void LocationsBuilderMIPS::VisitExit(HExit* exit) {
3943 exit->SetLocations(nullptr);
3944}
3945
3946void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
3947}
3948
3949void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) {
3950 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01003951 new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003952 locations->SetOut(Location::ConstantLocation(constant));
3953}
3954
3955void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
3956 // Will be generated at use site.
3957}
3958
3959void LocationsBuilderMIPS::VisitGoto(HGoto* got) {
3960 got->SetLocations(nullptr);
3961}
3962
3963void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) {
3964 DCHECK(!successor->IsExitBlock());
3965 HBasicBlock* block = got->GetBlock();
3966 HInstruction* previous = got->GetPrevious();
3967 HLoopInformation* info = block->GetLoopInformation();
3968
3969 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
3970 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
3971 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
3972 return;
3973 }
3974 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
3975 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
3976 }
3977 if (!codegen_->GoesToNextBlock(block, successor)) {
3978 __ B(codegen_->GetLabelOf(successor));
3979 }
3980}
3981
3982void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) {
3983 HandleGoto(got, got->GetSuccessor());
3984}
3985
3986void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
3987 try_boundary->SetLocations(nullptr);
3988}
3989
3990void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
3991 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
3992 if (!successor->IsExitBlock()) {
3993 HandleGoto(try_boundary, successor);
3994 }
3995}
3996
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003997void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond,
3998 LocationSummary* locations) {
3999 Register dst = locations->Out().AsRegister<Register>();
4000 Register lhs = locations->InAt(0).AsRegister<Register>();
4001 Location rhs_location = locations->InAt(1);
4002 Register rhs_reg = ZERO;
4003 int64_t rhs_imm = 0;
4004 bool use_imm = rhs_location.IsConstant();
4005 if (use_imm) {
4006 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
4007 } else {
4008 rhs_reg = rhs_location.AsRegister<Register>();
4009 }
4010
4011 switch (cond) {
4012 case kCondEQ:
4013 case kCondNE:
Alexey Frunzee7697712016-09-15 21:37:49 -07004014 if (use_imm && IsInt<16>(-rhs_imm)) {
4015 if (rhs_imm == 0) {
4016 if (cond == kCondEQ) {
4017 __ Sltiu(dst, lhs, 1);
4018 } else {
4019 __ Sltu(dst, ZERO, lhs);
4020 }
4021 } else {
4022 __ Addiu(dst, lhs, -rhs_imm);
4023 if (cond == kCondEQ) {
4024 __ Sltiu(dst, dst, 1);
4025 } else {
4026 __ Sltu(dst, ZERO, dst);
4027 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004028 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004029 } else {
Alexey Frunzee7697712016-09-15 21:37:49 -07004030 if (use_imm && IsUint<16>(rhs_imm)) {
4031 __ Xori(dst, lhs, rhs_imm);
4032 } else {
4033 if (use_imm) {
4034 rhs_reg = TMP;
4035 __ LoadConst32(rhs_reg, rhs_imm);
4036 }
4037 __ Xor(dst, lhs, rhs_reg);
4038 }
4039 if (cond == kCondEQ) {
4040 __ Sltiu(dst, dst, 1);
4041 } else {
4042 __ Sltu(dst, ZERO, dst);
4043 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004044 }
4045 break;
4046
4047 case kCondLT:
4048 case kCondGE:
4049 if (use_imm && IsInt<16>(rhs_imm)) {
4050 __ Slti(dst, lhs, rhs_imm);
4051 } else {
4052 if (use_imm) {
4053 rhs_reg = TMP;
4054 __ LoadConst32(rhs_reg, rhs_imm);
4055 }
4056 __ Slt(dst, lhs, rhs_reg);
4057 }
4058 if (cond == kCondGE) {
4059 // Simulate lhs >= rhs via !(lhs < rhs) since there's
4060 // only the slt instruction but no sge.
4061 __ Xori(dst, dst, 1);
4062 }
4063 break;
4064
4065 case kCondLE:
4066 case kCondGT:
4067 if (use_imm && IsInt<16>(rhs_imm + 1)) {
4068 // Simulate lhs <= rhs via lhs < rhs + 1.
4069 __ Slti(dst, lhs, rhs_imm + 1);
4070 if (cond == kCondGT) {
4071 // Simulate lhs > rhs via !(lhs <= rhs) since there's
4072 // only the slti instruction but no sgti.
4073 __ Xori(dst, dst, 1);
4074 }
4075 } else {
4076 if (use_imm) {
4077 rhs_reg = TMP;
4078 __ LoadConst32(rhs_reg, rhs_imm);
4079 }
4080 __ Slt(dst, rhs_reg, lhs);
4081 if (cond == kCondLE) {
4082 // Simulate lhs <= rhs via !(rhs < lhs) since there's
4083 // only the slt instruction but no sle.
4084 __ Xori(dst, dst, 1);
4085 }
4086 }
4087 break;
4088
4089 case kCondB:
4090 case kCondAE:
4091 if (use_imm && IsInt<16>(rhs_imm)) {
4092 // Sltiu sign-extends its 16-bit immediate operand before
4093 // the comparison and thus lets us compare directly with
4094 // unsigned values in the ranges [0, 0x7fff] and
4095 // [0xffff8000, 0xffffffff].
4096 __ Sltiu(dst, lhs, rhs_imm);
4097 } else {
4098 if (use_imm) {
4099 rhs_reg = TMP;
4100 __ LoadConst32(rhs_reg, rhs_imm);
4101 }
4102 __ Sltu(dst, lhs, rhs_reg);
4103 }
4104 if (cond == kCondAE) {
4105 // Simulate lhs >= rhs via !(lhs < rhs) since there's
4106 // only the sltu instruction but no sgeu.
4107 __ Xori(dst, dst, 1);
4108 }
4109 break;
4110
4111 case kCondBE:
4112 case kCondA:
4113 if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
4114 // Simulate lhs <= rhs via lhs < rhs + 1.
4115 // Note that this only works if rhs + 1 does not overflow
4116 // to 0, hence the check above.
4117 // Sltiu sign-extends its 16-bit immediate operand before
4118 // the comparison and thus lets us compare directly with
4119 // unsigned values in the ranges [0, 0x7fff] and
4120 // [0xffff8000, 0xffffffff].
4121 __ Sltiu(dst, lhs, rhs_imm + 1);
4122 if (cond == kCondA) {
4123 // Simulate lhs > rhs via !(lhs <= rhs) since there's
4124 // only the sltiu instruction but no sgtiu.
4125 __ Xori(dst, dst, 1);
4126 }
4127 } else {
4128 if (use_imm) {
4129 rhs_reg = TMP;
4130 __ LoadConst32(rhs_reg, rhs_imm);
4131 }
4132 __ Sltu(dst, rhs_reg, lhs);
4133 if (cond == kCondBE) {
4134 // Simulate lhs <= rhs via !(rhs < lhs) since there's
4135 // only the sltu instruction but no sleu.
4136 __ Xori(dst, dst, 1);
4137 }
4138 }
4139 break;
4140 }
4141}
4142
Alexey Frunze674b9ee2016-09-20 14:54:15 -07004143bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond,
4144 LocationSummary* input_locations,
4145 Register dst) {
4146 Register lhs = input_locations->InAt(0).AsRegister<Register>();
4147 Location rhs_location = input_locations->InAt(1);
4148 Register rhs_reg = ZERO;
4149 int64_t rhs_imm = 0;
4150 bool use_imm = rhs_location.IsConstant();
4151 if (use_imm) {
4152 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
4153 } else {
4154 rhs_reg = rhs_location.AsRegister<Register>();
4155 }
4156
4157 switch (cond) {
4158 case kCondEQ:
4159 case kCondNE:
4160 if (use_imm && IsInt<16>(-rhs_imm)) {
4161 __ Addiu(dst, lhs, -rhs_imm);
4162 } else if (use_imm && IsUint<16>(rhs_imm)) {
4163 __ Xori(dst, lhs, rhs_imm);
4164 } else {
4165 if (use_imm) {
4166 rhs_reg = TMP;
4167 __ LoadConst32(rhs_reg, rhs_imm);
4168 }
4169 __ Xor(dst, lhs, rhs_reg);
4170 }
4171 return (cond == kCondEQ);
4172
4173 case kCondLT:
4174 case kCondGE:
4175 if (use_imm && IsInt<16>(rhs_imm)) {
4176 __ Slti(dst, lhs, rhs_imm);
4177 } else {
4178 if (use_imm) {
4179 rhs_reg = TMP;
4180 __ LoadConst32(rhs_reg, rhs_imm);
4181 }
4182 __ Slt(dst, lhs, rhs_reg);
4183 }
4184 return (cond == kCondGE);
4185
4186 case kCondLE:
4187 case kCondGT:
4188 if (use_imm && IsInt<16>(rhs_imm + 1)) {
4189 // Simulate lhs <= rhs via lhs < rhs + 1.
4190 __ Slti(dst, lhs, rhs_imm + 1);
4191 return (cond == kCondGT);
4192 } else {
4193 if (use_imm) {
4194 rhs_reg = TMP;
4195 __ LoadConst32(rhs_reg, rhs_imm);
4196 }
4197 __ Slt(dst, rhs_reg, lhs);
4198 return (cond == kCondLE);
4199 }
4200
4201 case kCondB:
4202 case kCondAE:
4203 if (use_imm && IsInt<16>(rhs_imm)) {
4204 // Sltiu sign-extends its 16-bit immediate operand before
4205 // the comparison and thus lets us compare directly with
4206 // unsigned values in the ranges [0, 0x7fff] and
4207 // [0xffff8000, 0xffffffff].
4208 __ Sltiu(dst, lhs, rhs_imm);
4209 } else {
4210 if (use_imm) {
4211 rhs_reg = TMP;
4212 __ LoadConst32(rhs_reg, rhs_imm);
4213 }
4214 __ Sltu(dst, lhs, rhs_reg);
4215 }
4216 return (cond == kCondAE);
4217
4218 case kCondBE:
4219 case kCondA:
4220 if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
4221 // Simulate lhs <= rhs via lhs < rhs + 1.
4222 // Note that this only works if rhs + 1 does not overflow
4223 // to 0, hence the check above.
4224 // Sltiu sign-extends its 16-bit immediate operand before
4225 // the comparison and thus lets us compare directly with
4226 // unsigned values in the ranges [0, 0x7fff] and
4227 // [0xffff8000, 0xffffffff].
4228 __ Sltiu(dst, lhs, rhs_imm + 1);
4229 return (cond == kCondA);
4230 } else {
4231 if (use_imm) {
4232 rhs_reg = TMP;
4233 __ LoadConst32(rhs_reg, rhs_imm);
4234 }
4235 __ Sltu(dst, rhs_reg, lhs);
4236 return (cond == kCondBE);
4237 }
4238 }
4239}
4240
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004241void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond,
4242 LocationSummary* locations,
4243 MipsLabel* label) {
4244 Register lhs = locations->InAt(0).AsRegister<Register>();
4245 Location rhs_location = locations->InAt(1);
4246 Register rhs_reg = ZERO;
Alexey Frunzee7697712016-09-15 21:37:49 -07004247 int64_t rhs_imm = 0;
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004248 bool use_imm = rhs_location.IsConstant();
4249 if (use_imm) {
4250 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
4251 } else {
4252 rhs_reg = rhs_location.AsRegister<Register>();
4253 }
4254
4255 if (use_imm && rhs_imm == 0) {
4256 switch (cond) {
4257 case kCondEQ:
4258 case kCondBE: // <= 0 if zero
4259 __ Beqz(lhs, label);
4260 break;
4261 case kCondNE:
4262 case kCondA: // > 0 if non-zero
4263 __ Bnez(lhs, label);
4264 break;
4265 case kCondLT:
4266 __ Bltz(lhs, label);
4267 break;
4268 case kCondGE:
4269 __ Bgez(lhs, label);
4270 break;
4271 case kCondLE:
4272 __ Blez(lhs, label);
4273 break;
4274 case kCondGT:
4275 __ Bgtz(lhs, label);
4276 break;
4277 case kCondB: // always false
4278 break;
4279 case kCondAE: // always true
4280 __ B(label);
4281 break;
4282 }
4283 } else {
Alexey Frunzee7697712016-09-15 21:37:49 -07004284 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4285 if (isR6 || !use_imm) {
4286 if (use_imm) {
4287 rhs_reg = TMP;
4288 __ LoadConst32(rhs_reg, rhs_imm);
4289 }
4290 switch (cond) {
4291 case kCondEQ:
4292 __ Beq(lhs, rhs_reg, label);
4293 break;
4294 case kCondNE:
4295 __ Bne(lhs, rhs_reg, label);
4296 break;
4297 case kCondLT:
4298 __ Blt(lhs, rhs_reg, label);
4299 break;
4300 case kCondGE:
4301 __ Bge(lhs, rhs_reg, label);
4302 break;
4303 case kCondLE:
4304 __ Bge(rhs_reg, lhs, label);
4305 break;
4306 case kCondGT:
4307 __ Blt(rhs_reg, lhs, label);
4308 break;
4309 case kCondB:
4310 __ Bltu(lhs, rhs_reg, label);
4311 break;
4312 case kCondAE:
4313 __ Bgeu(lhs, rhs_reg, label);
4314 break;
4315 case kCondBE:
4316 __ Bgeu(rhs_reg, lhs, label);
4317 break;
4318 case kCondA:
4319 __ Bltu(rhs_reg, lhs, label);
4320 break;
4321 }
4322 } else {
4323 // Special cases for more efficient comparison with constants on R2.
4324 switch (cond) {
4325 case kCondEQ:
4326 __ LoadConst32(TMP, rhs_imm);
4327 __ Beq(lhs, TMP, label);
4328 break;
4329 case kCondNE:
4330 __ LoadConst32(TMP, rhs_imm);
4331 __ Bne(lhs, TMP, label);
4332 break;
4333 case kCondLT:
4334 if (IsInt<16>(rhs_imm)) {
4335 __ Slti(TMP, lhs, rhs_imm);
4336 __ Bnez(TMP, label);
4337 } else {
4338 __ LoadConst32(TMP, rhs_imm);
4339 __ Blt(lhs, TMP, label);
4340 }
4341 break;
4342 case kCondGE:
4343 if (IsInt<16>(rhs_imm)) {
4344 __ Slti(TMP, lhs, rhs_imm);
4345 __ Beqz(TMP, label);
4346 } else {
4347 __ LoadConst32(TMP, rhs_imm);
4348 __ Bge(lhs, TMP, label);
4349 }
4350 break;
4351 case kCondLE:
4352 if (IsInt<16>(rhs_imm + 1)) {
4353 // Simulate lhs <= rhs via lhs < rhs + 1.
4354 __ Slti(TMP, lhs, rhs_imm + 1);
4355 __ Bnez(TMP, label);
4356 } else {
4357 __ LoadConst32(TMP, rhs_imm);
4358 __ Bge(TMP, lhs, label);
4359 }
4360 break;
4361 case kCondGT:
4362 if (IsInt<16>(rhs_imm + 1)) {
4363 // Simulate lhs > rhs via !(lhs < rhs + 1).
4364 __ Slti(TMP, lhs, rhs_imm + 1);
4365 __ Beqz(TMP, label);
4366 } else {
4367 __ LoadConst32(TMP, rhs_imm);
4368 __ Blt(TMP, lhs, label);
4369 }
4370 break;
4371 case kCondB:
4372 if (IsInt<16>(rhs_imm)) {
4373 __ Sltiu(TMP, lhs, rhs_imm);
4374 __ Bnez(TMP, label);
4375 } else {
4376 __ LoadConst32(TMP, rhs_imm);
4377 __ Bltu(lhs, TMP, label);
4378 }
4379 break;
4380 case kCondAE:
4381 if (IsInt<16>(rhs_imm)) {
4382 __ Sltiu(TMP, lhs, rhs_imm);
4383 __ Beqz(TMP, label);
4384 } else {
4385 __ LoadConst32(TMP, rhs_imm);
4386 __ Bgeu(lhs, TMP, label);
4387 }
4388 break;
4389 case kCondBE:
4390 if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
4391 // Simulate lhs <= rhs via lhs < rhs + 1.
4392 // Note that this only works if rhs + 1 does not overflow
4393 // to 0, hence the check above.
4394 __ Sltiu(TMP, lhs, rhs_imm + 1);
4395 __ Bnez(TMP, label);
4396 } else {
4397 __ LoadConst32(TMP, rhs_imm);
4398 __ Bgeu(TMP, lhs, label);
4399 }
4400 break;
4401 case kCondA:
4402 if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
4403 // Simulate lhs > rhs via !(lhs < rhs + 1).
4404 // Note that this only works if rhs + 1 does not overflow
4405 // to 0, hence the check above.
4406 __ Sltiu(TMP, lhs, rhs_imm + 1);
4407 __ Beqz(TMP, label);
4408 } else {
4409 __ LoadConst32(TMP, rhs_imm);
4410 __ Bltu(TMP, lhs, label);
4411 }
4412 break;
4413 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004414 }
4415 }
4416}
4417
Tijana Jakovljevic6d482aa2017-02-03 13:24:08 +01004418void InstructionCodeGeneratorMIPS::GenerateLongCompare(IfCondition cond,
4419 LocationSummary* locations) {
4420 Register dst = locations->Out().AsRegister<Register>();
4421 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4422 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
4423 Location rhs_location = locations->InAt(1);
4424 Register rhs_high = ZERO;
4425 Register rhs_low = ZERO;
4426 int64_t imm = 0;
4427 uint32_t imm_high = 0;
4428 uint32_t imm_low = 0;
4429 bool use_imm = rhs_location.IsConstant();
4430 if (use_imm) {
4431 imm = rhs_location.GetConstant()->AsLongConstant()->GetValue();
4432 imm_high = High32Bits(imm);
4433 imm_low = Low32Bits(imm);
4434 } else {
4435 rhs_high = rhs_location.AsRegisterPairHigh<Register>();
4436 rhs_low = rhs_location.AsRegisterPairLow<Register>();
4437 }
4438 if (use_imm && imm == 0) {
4439 switch (cond) {
4440 case kCondEQ:
4441 case kCondBE: // <= 0 if zero
4442 __ Or(dst, lhs_high, lhs_low);
4443 __ Sltiu(dst, dst, 1);
4444 break;
4445 case kCondNE:
4446 case kCondA: // > 0 if non-zero
4447 __ Or(dst, lhs_high, lhs_low);
4448 __ Sltu(dst, ZERO, dst);
4449 break;
4450 case kCondLT:
4451 __ Slt(dst, lhs_high, ZERO);
4452 break;
4453 case kCondGE:
4454 __ Slt(dst, lhs_high, ZERO);
4455 __ Xori(dst, dst, 1);
4456 break;
4457 case kCondLE:
4458 __ Or(TMP, lhs_high, lhs_low);
4459 __ Sra(AT, lhs_high, 31);
4460 __ Sltu(dst, AT, TMP);
4461 __ Xori(dst, dst, 1);
4462 break;
4463 case kCondGT:
4464 __ Or(TMP, lhs_high, lhs_low);
4465 __ Sra(AT, lhs_high, 31);
4466 __ Sltu(dst, AT, TMP);
4467 break;
4468 case kCondB: // always false
4469 __ Andi(dst, dst, 0);
4470 break;
4471 case kCondAE: // always true
4472 __ Ori(dst, ZERO, 1);
4473 break;
4474 }
4475 } else if (use_imm) {
4476 // TODO: more efficient comparison with constants without loading them into TMP/AT.
4477 switch (cond) {
4478 case kCondEQ:
4479 __ LoadConst32(TMP, imm_high);
4480 __ Xor(TMP, TMP, lhs_high);
4481 __ LoadConst32(AT, imm_low);
4482 __ Xor(AT, AT, lhs_low);
4483 __ Or(dst, TMP, AT);
4484 __ Sltiu(dst, dst, 1);
4485 break;
4486 case kCondNE:
4487 __ LoadConst32(TMP, imm_high);
4488 __ Xor(TMP, TMP, lhs_high);
4489 __ LoadConst32(AT, imm_low);
4490 __ Xor(AT, AT, lhs_low);
4491 __ Or(dst, TMP, AT);
4492 __ Sltu(dst, ZERO, dst);
4493 break;
4494 case kCondLT:
4495 case kCondGE:
4496 if (dst == lhs_low) {
4497 __ LoadConst32(TMP, imm_low);
4498 __ Sltu(dst, lhs_low, TMP);
4499 }
4500 __ LoadConst32(TMP, imm_high);
4501 __ Slt(AT, lhs_high, TMP);
4502 __ Slt(TMP, TMP, lhs_high);
4503 if (dst != lhs_low) {
4504 __ LoadConst32(dst, imm_low);
4505 __ Sltu(dst, lhs_low, dst);
4506 }
4507 __ Slt(dst, TMP, dst);
4508 __ Or(dst, dst, AT);
4509 if (cond == kCondGE) {
4510 __ Xori(dst, dst, 1);
4511 }
4512 break;
4513 case kCondGT:
4514 case kCondLE:
4515 if (dst == lhs_low) {
4516 __ LoadConst32(TMP, imm_low);
4517 __ Sltu(dst, TMP, lhs_low);
4518 }
4519 __ LoadConst32(TMP, imm_high);
4520 __ Slt(AT, TMP, lhs_high);
4521 __ Slt(TMP, lhs_high, TMP);
4522 if (dst != lhs_low) {
4523 __ LoadConst32(dst, imm_low);
4524 __ Sltu(dst, dst, lhs_low);
4525 }
4526 __ Slt(dst, TMP, dst);
4527 __ Or(dst, dst, AT);
4528 if (cond == kCondLE) {
4529 __ Xori(dst, dst, 1);
4530 }
4531 break;
4532 case kCondB:
4533 case kCondAE:
4534 if (dst == lhs_low) {
4535 __ LoadConst32(TMP, imm_low);
4536 __ Sltu(dst, lhs_low, TMP);
4537 }
4538 __ LoadConst32(TMP, imm_high);
4539 __ Sltu(AT, lhs_high, TMP);
4540 __ Sltu(TMP, TMP, lhs_high);
4541 if (dst != lhs_low) {
4542 __ LoadConst32(dst, imm_low);
4543 __ Sltu(dst, lhs_low, dst);
4544 }
4545 __ Slt(dst, TMP, dst);
4546 __ Or(dst, dst, AT);
4547 if (cond == kCondAE) {
4548 __ Xori(dst, dst, 1);
4549 }
4550 break;
4551 case kCondA:
4552 case kCondBE:
4553 if (dst == lhs_low) {
4554 __ LoadConst32(TMP, imm_low);
4555 __ Sltu(dst, TMP, lhs_low);
4556 }
4557 __ LoadConst32(TMP, imm_high);
4558 __ Sltu(AT, TMP, lhs_high);
4559 __ Sltu(TMP, lhs_high, TMP);
4560 if (dst != lhs_low) {
4561 __ LoadConst32(dst, imm_low);
4562 __ Sltu(dst, dst, lhs_low);
4563 }
4564 __ Slt(dst, TMP, dst);
4565 __ Or(dst, dst, AT);
4566 if (cond == kCondBE) {
4567 __ Xori(dst, dst, 1);
4568 }
4569 break;
4570 }
4571 } else {
4572 switch (cond) {
4573 case kCondEQ:
4574 __ Xor(TMP, lhs_high, rhs_high);
4575 __ Xor(AT, lhs_low, rhs_low);
4576 __ Or(dst, TMP, AT);
4577 __ Sltiu(dst, dst, 1);
4578 break;
4579 case kCondNE:
4580 __ Xor(TMP, lhs_high, rhs_high);
4581 __ Xor(AT, lhs_low, rhs_low);
4582 __ Or(dst, TMP, AT);
4583 __ Sltu(dst, ZERO, dst);
4584 break;
4585 case kCondLT:
4586 case kCondGE:
4587 __ Slt(TMP, rhs_high, lhs_high);
4588 __ Sltu(AT, lhs_low, rhs_low);
4589 __ Slt(TMP, TMP, AT);
4590 __ Slt(AT, lhs_high, rhs_high);
4591 __ Or(dst, AT, TMP);
4592 if (cond == kCondGE) {
4593 __ Xori(dst, dst, 1);
4594 }
4595 break;
4596 case kCondGT:
4597 case kCondLE:
4598 __ Slt(TMP, lhs_high, rhs_high);
4599 __ Sltu(AT, rhs_low, lhs_low);
4600 __ Slt(TMP, TMP, AT);
4601 __ Slt(AT, rhs_high, lhs_high);
4602 __ Or(dst, AT, TMP);
4603 if (cond == kCondLE) {
4604 __ Xori(dst, dst, 1);
4605 }
4606 break;
4607 case kCondB:
4608 case kCondAE:
4609 __ Sltu(TMP, rhs_high, lhs_high);
4610 __ Sltu(AT, lhs_low, rhs_low);
4611 __ Slt(TMP, TMP, AT);
4612 __ Sltu(AT, lhs_high, rhs_high);
4613 __ Or(dst, AT, TMP);
4614 if (cond == kCondAE) {
4615 __ Xori(dst, dst, 1);
4616 }
4617 break;
4618 case kCondA:
4619 case kCondBE:
4620 __ Sltu(TMP, lhs_high, rhs_high);
4621 __ Sltu(AT, rhs_low, lhs_low);
4622 __ Slt(TMP, TMP, AT);
4623 __ Sltu(AT, rhs_high, lhs_high);
4624 __ Or(dst, AT, TMP);
4625 if (cond == kCondBE) {
4626 __ Xori(dst, dst, 1);
4627 }
4628 break;
4629 }
4630 }
4631}
4632
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004633void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond,
4634 LocationSummary* locations,
4635 MipsLabel* label) {
4636 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4637 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
4638 Location rhs_location = locations->InAt(1);
4639 Register rhs_high = ZERO;
4640 Register rhs_low = ZERO;
4641 int64_t imm = 0;
4642 uint32_t imm_high = 0;
4643 uint32_t imm_low = 0;
4644 bool use_imm = rhs_location.IsConstant();
4645 if (use_imm) {
4646 imm = rhs_location.GetConstant()->AsLongConstant()->GetValue();
4647 imm_high = High32Bits(imm);
4648 imm_low = Low32Bits(imm);
4649 } else {
4650 rhs_high = rhs_location.AsRegisterPairHigh<Register>();
4651 rhs_low = rhs_location.AsRegisterPairLow<Register>();
4652 }
4653
4654 if (use_imm && imm == 0) {
4655 switch (cond) {
4656 case kCondEQ:
4657 case kCondBE: // <= 0 if zero
4658 __ Or(TMP, lhs_high, lhs_low);
4659 __ Beqz(TMP, label);
4660 break;
4661 case kCondNE:
4662 case kCondA: // > 0 if non-zero
4663 __ Or(TMP, lhs_high, lhs_low);
4664 __ Bnez(TMP, label);
4665 break;
4666 case kCondLT:
4667 __ Bltz(lhs_high, label);
4668 break;
4669 case kCondGE:
4670 __ Bgez(lhs_high, label);
4671 break;
4672 case kCondLE:
4673 __ Or(TMP, lhs_high, lhs_low);
4674 __ Sra(AT, lhs_high, 31);
4675 __ Bgeu(AT, TMP, label);
4676 break;
4677 case kCondGT:
4678 __ Or(TMP, lhs_high, lhs_low);
4679 __ Sra(AT, lhs_high, 31);
4680 __ Bltu(AT, TMP, label);
4681 break;
4682 case kCondB: // always false
4683 break;
4684 case kCondAE: // always true
4685 __ B(label);
4686 break;
4687 }
4688 } else if (use_imm) {
4689 // TODO: more efficient comparison with constants without loading them into TMP/AT.
4690 switch (cond) {
4691 case kCondEQ:
4692 __ LoadConst32(TMP, imm_high);
4693 __ Xor(TMP, TMP, lhs_high);
4694 __ LoadConst32(AT, imm_low);
4695 __ Xor(AT, AT, lhs_low);
4696 __ Or(TMP, TMP, AT);
4697 __ Beqz(TMP, label);
4698 break;
4699 case kCondNE:
4700 __ LoadConst32(TMP, imm_high);
4701 __ Xor(TMP, TMP, lhs_high);
4702 __ LoadConst32(AT, imm_low);
4703 __ Xor(AT, AT, lhs_low);
4704 __ Or(TMP, TMP, AT);
4705 __ Bnez(TMP, label);
4706 break;
4707 case kCondLT:
4708 __ LoadConst32(TMP, imm_high);
4709 __ Blt(lhs_high, TMP, label);
4710 __ Slt(TMP, TMP, lhs_high);
4711 __ LoadConst32(AT, imm_low);
4712 __ Sltu(AT, lhs_low, AT);
4713 __ Blt(TMP, AT, label);
4714 break;
4715 case kCondGE:
4716 __ LoadConst32(TMP, imm_high);
4717 __ Blt(TMP, lhs_high, label);
4718 __ Slt(TMP, lhs_high, TMP);
4719 __ LoadConst32(AT, imm_low);
4720 __ Sltu(AT, lhs_low, AT);
4721 __ Or(TMP, TMP, AT);
4722 __ Beqz(TMP, label);
4723 break;
4724 case kCondLE:
4725 __ LoadConst32(TMP, imm_high);
4726 __ Blt(lhs_high, TMP, label);
4727 __ Slt(TMP, TMP, lhs_high);
4728 __ LoadConst32(AT, imm_low);
4729 __ Sltu(AT, AT, lhs_low);
4730 __ Or(TMP, TMP, AT);
4731 __ Beqz(TMP, label);
4732 break;
4733 case kCondGT:
4734 __ LoadConst32(TMP, imm_high);
4735 __ Blt(TMP, lhs_high, label);
4736 __ Slt(TMP, lhs_high, TMP);
4737 __ LoadConst32(AT, imm_low);
4738 __ Sltu(AT, AT, lhs_low);
4739 __ Blt(TMP, AT, label);
4740 break;
4741 case kCondB:
4742 __ LoadConst32(TMP, imm_high);
4743 __ Bltu(lhs_high, TMP, label);
4744 __ Sltu(TMP, TMP, lhs_high);
4745 __ LoadConst32(AT, imm_low);
4746 __ Sltu(AT, lhs_low, AT);
4747 __ Blt(TMP, AT, label);
4748 break;
4749 case kCondAE:
4750 __ LoadConst32(TMP, imm_high);
4751 __ Bltu(TMP, lhs_high, label);
4752 __ Sltu(TMP, lhs_high, TMP);
4753 __ LoadConst32(AT, imm_low);
4754 __ Sltu(AT, lhs_low, AT);
4755 __ Or(TMP, TMP, AT);
4756 __ Beqz(TMP, label);
4757 break;
4758 case kCondBE:
4759 __ LoadConst32(TMP, imm_high);
4760 __ Bltu(lhs_high, TMP, label);
4761 __ Sltu(TMP, TMP, lhs_high);
4762 __ LoadConst32(AT, imm_low);
4763 __ Sltu(AT, AT, lhs_low);
4764 __ Or(TMP, TMP, AT);
4765 __ Beqz(TMP, label);
4766 break;
4767 case kCondA:
4768 __ LoadConst32(TMP, imm_high);
4769 __ Bltu(TMP, lhs_high, label);
4770 __ Sltu(TMP, lhs_high, TMP);
4771 __ LoadConst32(AT, imm_low);
4772 __ Sltu(AT, AT, lhs_low);
4773 __ Blt(TMP, AT, label);
4774 break;
4775 }
4776 } else {
4777 switch (cond) {
4778 case kCondEQ:
4779 __ Xor(TMP, lhs_high, rhs_high);
4780 __ Xor(AT, lhs_low, rhs_low);
4781 __ Or(TMP, TMP, AT);
4782 __ Beqz(TMP, label);
4783 break;
4784 case kCondNE:
4785 __ Xor(TMP, lhs_high, rhs_high);
4786 __ Xor(AT, lhs_low, rhs_low);
4787 __ Or(TMP, TMP, AT);
4788 __ Bnez(TMP, label);
4789 break;
4790 case kCondLT:
4791 __ Blt(lhs_high, rhs_high, label);
4792 __ Slt(TMP, rhs_high, lhs_high);
4793 __ Sltu(AT, lhs_low, rhs_low);
4794 __ Blt(TMP, AT, label);
4795 break;
4796 case kCondGE:
4797 __ Blt(rhs_high, lhs_high, label);
4798 __ Slt(TMP, lhs_high, rhs_high);
4799 __ Sltu(AT, lhs_low, rhs_low);
4800 __ Or(TMP, TMP, AT);
4801 __ Beqz(TMP, label);
4802 break;
4803 case kCondLE:
4804 __ Blt(lhs_high, rhs_high, label);
4805 __ Slt(TMP, rhs_high, lhs_high);
4806 __ Sltu(AT, rhs_low, lhs_low);
4807 __ Or(TMP, TMP, AT);
4808 __ Beqz(TMP, label);
4809 break;
4810 case kCondGT:
4811 __ Blt(rhs_high, lhs_high, label);
4812 __ Slt(TMP, lhs_high, rhs_high);
4813 __ Sltu(AT, rhs_low, lhs_low);
4814 __ Blt(TMP, AT, label);
4815 break;
4816 case kCondB:
4817 __ Bltu(lhs_high, rhs_high, label);
4818 __ Sltu(TMP, rhs_high, lhs_high);
4819 __ Sltu(AT, lhs_low, rhs_low);
4820 __ Blt(TMP, AT, label);
4821 break;
4822 case kCondAE:
4823 __ Bltu(rhs_high, lhs_high, label);
4824 __ Sltu(TMP, lhs_high, rhs_high);
4825 __ Sltu(AT, lhs_low, rhs_low);
4826 __ Or(TMP, TMP, AT);
4827 __ Beqz(TMP, label);
4828 break;
4829 case kCondBE:
4830 __ Bltu(lhs_high, rhs_high, label);
4831 __ Sltu(TMP, rhs_high, lhs_high);
4832 __ Sltu(AT, rhs_low, lhs_low);
4833 __ Or(TMP, TMP, AT);
4834 __ Beqz(TMP, label);
4835 break;
4836 case kCondA:
4837 __ Bltu(rhs_high, lhs_high, label);
4838 __ Sltu(TMP, lhs_high, rhs_high);
4839 __ Sltu(AT, rhs_low, lhs_low);
4840 __ Blt(TMP, AT, label);
4841 break;
4842 }
4843 }
4844}
4845
Alexey Frunze2ddb7172016-09-06 17:04:55 -07004846void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond,
4847 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004848 DataType::Type type,
Alexey Frunze2ddb7172016-09-06 17:04:55 -07004849 LocationSummary* locations) {
4850 Register dst = locations->Out().AsRegister<Register>();
4851 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
4852 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
4853 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004854 if (type == DataType::Type::kFloat32) {
Alexey Frunze2ddb7172016-09-06 17:04:55 -07004855 if (isR6) {
4856 switch (cond) {
4857 case kCondEQ:
4858 __ CmpEqS(FTMP, lhs, rhs);
4859 __ Mfc1(dst, FTMP);
4860 __ Andi(dst, dst, 1);
4861 break;
4862 case kCondNE:
4863 __ CmpEqS(FTMP, lhs, rhs);
4864 __ Mfc1(dst, FTMP);
4865 __ Addiu(dst, dst, 1);
4866 break;
4867 case kCondLT:
4868 if (gt_bias) {
4869 __ CmpLtS(FTMP, lhs, rhs);
4870 } else {
4871 __ CmpUltS(FTMP, lhs, rhs);
4872 }
4873 __ Mfc1(dst, FTMP);
4874 __ Andi(dst, dst, 1);
4875 break;
4876 case kCondLE:
4877 if (gt_bias) {
4878 __ CmpLeS(FTMP, lhs, rhs);
4879 } else {
4880 __ CmpUleS(FTMP, lhs, rhs);
4881 }
4882 __ Mfc1(dst, FTMP);
4883 __ Andi(dst, dst, 1);
4884 break;
4885 case kCondGT:
4886 if (gt_bias) {
4887 __ CmpUltS(FTMP, rhs, lhs);
4888 } else {
4889 __ CmpLtS(FTMP, rhs, lhs);
4890 }
4891 __ Mfc1(dst, FTMP);
4892 __ Andi(dst, dst, 1);
4893 break;
4894 case kCondGE:
4895 if (gt_bias) {
4896 __ CmpUleS(FTMP, rhs, lhs);
4897 } else {
4898 __ CmpLeS(FTMP, rhs, lhs);
4899 }
4900 __ Mfc1(dst, FTMP);
4901 __ Andi(dst, dst, 1);
4902 break;
4903 default:
4904 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4905 UNREACHABLE();
4906 }
4907 } else {
4908 switch (cond) {
4909 case kCondEQ:
4910 __ CeqS(0, lhs, rhs);
4911 __ LoadConst32(dst, 1);
4912 __ Movf(dst, ZERO, 0);
4913 break;
4914 case kCondNE:
4915 __ CeqS(0, lhs, rhs);
4916 __ LoadConst32(dst, 1);
4917 __ Movt(dst, ZERO, 0);
4918 break;
4919 case kCondLT:
4920 if (gt_bias) {
4921 __ ColtS(0, lhs, rhs);
4922 } else {
4923 __ CultS(0, lhs, rhs);
4924 }
4925 __ LoadConst32(dst, 1);
4926 __ Movf(dst, ZERO, 0);
4927 break;
4928 case kCondLE:
4929 if (gt_bias) {
4930 __ ColeS(0, lhs, rhs);
4931 } else {
4932 __ CuleS(0, lhs, rhs);
4933 }
4934 __ LoadConst32(dst, 1);
4935 __ Movf(dst, ZERO, 0);
4936 break;
4937 case kCondGT:
4938 if (gt_bias) {
4939 __ CultS(0, rhs, lhs);
4940 } else {
4941 __ ColtS(0, rhs, lhs);
4942 }
4943 __ LoadConst32(dst, 1);
4944 __ Movf(dst, ZERO, 0);
4945 break;
4946 case kCondGE:
4947 if (gt_bias) {
4948 __ CuleS(0, rhs, lhs);
4949 } else {
4950 __ ColeS(0, rhs, lhs);
4951 }
4952 __ LoadConst32(dst, 1);
4953 __ Movf(dst, ZERO, 0);
4954 break;
4955 default:
4956 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
4957 UNREACHABLE();
4958 }
4959 }
4960 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01004961 DCHECK_EQ(type, DataType::Type::kFloat64);
Alexey Frunze2ddb7172016-09-06 17:04:55 -07004962 if (isR6) {
4963 switch (cond) {
4964 case kCondEQ:
4965 __ CmpEqD(FTMP, lhs, rhs);
4966 __ Mfc1(dst, FTMP);
4967 __ Andi(dst, dst, 1);
4968 break;
4969 case kCondNE:
4970 __ CmpEqD(FTMP, lhs, rhs);
4971 __ Mfc1(dst, FTMP);
4972 __ Addiu(dst, dst, 1);
4973 break;
4974 case kCondLT:
4975 if (gt_bias) {
4976 __ CmpLtD(FTMP, lhs, rhs);
4977 } else {
4978 __ CmpUltD(FTMP, lhs, rhs);
4979 }
4980 __ Mfc1(dst, FTMP);
4981 __ Andi(dst, dst, 1);
4982 break;
4983 case kCondLE:
4984 if (gt_bias) {
4985 __ CmpLeD(FTMP, lhs, rhs);
4986 } else {
4987 __ CmpUleD(FTMP, lhs, rhs);
4988 }
4989 __ Mfc1(dst, FTMP);
4990 __ Andi(dst, dst, 1);
4991 break;
4992 case kCondGT:
4993 if (gt_bias) {
4994 __ CmpUltD(FTMP, rhs, lhs);
4995 } else {
4996 __ CmpLtD(FTMP, rhs, lhs);
4997 }
4998 __ Mfc1(dst, FTMP);
4999 __ Andi(dst, dst, 1);
5000 break;
5001 case kCondGE:
5002 if (gt_bias) {
5003 __ CmpUleD(FTMP, rhs, lhs);
5004 } else {
5005 __ CmpLeD(FTMP, rhs, lhs);
5006 }
5007 __ Mfc1(dst, FTMP);
5008 __ Andi(dst, dst, 1);
5009 break;
5010 default:
5011 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
5012 UNREACHABLE();
5013 }
5014 } else {
5015 switch (cond) {
5016 case kCondEQ:
5017 __ CeqD(0, lhs, rhs);
5018 __ LoadConst32(dst, 1);
5019 __ Movf(dst, ZERO, 0);
5020 break;
5021 case kCondNE:
5022 __ CeqD(0, lhs, rhs);
5023 __ LoadConst32(dst, 1);
5024 __ Movt(dst, ZERO, 0);
5025 break;
5026 case kCondLT:
5027 if (gt_bias) {
5028 __ ColtD(0, lhs, rhs);
5029 } else {
5030 __ CultD(0, lhs, rhs);
5031 }
5032 __ LoadConst32(dst, 1);
5033 __ Movf(dst, ZERO, 0);
5034 break;
5035 case kCondLE:
5036 if (gt_bias) {
5037 __ ColeD(0, lhs, rhs);
5038 } else {
5039 __ CuleD(0, lhs, rhs);
5040 }
5041 __ LoadConst32(dst, 1);
5042 __ Movf(dst, ZERO, 0);
5043 break;
5044 case kCondGT:
5045 if (gt_bias) {
5046 __ CultD(0, rhs, lhs);
5047 } else {
5048 __ ColtD(0, rhs, lhs);
5049 }
5050 __ LoadConst32(dst, 1);
5051 __ Movf(dst, ZERO, 0);
5052 break;
5053 case kCondGE:
5054 if (gt_bias) {
5055 __ CuleD(0, rhs, lhs);
5056 } else {
5057 __ ColeD(0, rhs, lhs);
5058 }
5059 __ LoadConst32(dst, 1);
5060 __ Movf(dst, ZERO, 0);
5061 break;
5062 default:
5063 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
5064 UNREACHABLE();
5065 }
5066 }
5067 }
5068}
5069
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005070bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond,
5071 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005072 DataType::Type type,
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005073 LocationSummary* input_locations,
5074 int cc) {
5075 FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>();
5076 FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>();
5077 CHECK(!codegen_->GetInstructionSetFeatures().IsR6());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005078 if (type == DataType::Type::kFloat32) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005079 switch (cond) {
5080 case kCondEQ:
5081 __ CeqS(cc, lhs, rhs);
5082 return false;
5083 case kCondNE:
5084 __ CeqS(cc, lhs, rhs);
5085 return true;
5086 case kCondLT:
5087 if (gt_bias) {
5088 __ ColtS(cc, lhs, rhs);
5089 } else {
5090 __ CultS(cc, lhs, rhs);
5091 }
5092 return false;
5093 case kCondLE:
5094 if (gt_bias) {
5095 __ ColeS(cc, lhs, rhs);
5096 } else {
5097 __ CuleS(cc, lhs, rhs);
5098 }
5099 return false;
5100 case kCondGT:
5101 if (gt_bias) {
5102 __ CultS(cc, rhs, lhs);
5103 } else {
5104 __ ColtS(cc, rhs, lhs);
5105 }
5106 return false;
5107 case kCondGE:
5108 if (gt_bias) {
5109 __ CuleS(cc, rhs, lhs);
5110 } else {
5111 __ ColeS(cc, rhs, lhs);
5112 }
5113 return false;
5114 default:
5115 LOG(FATAL) << "Unexpected non-floating-point condition";
5116 UNREACHABLE();
5117 }
5118 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005119 DCHECK_EQ(type, DataType::Type::kFloat64);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005120 switch (cond) {
5121 case kCondEQ:
5122 __ CeqD(cc, lhs, rhs);
5123 return false;
5124 case kCondNE:
5125 __ CeqD(cc, lhs, rhs);
5126 return true;
5127 case kCondLT:
5128 if (gt_bias) {
5129 __ ColtD(cc, lhs, rhs);
5130 } else {
5131 __ CultD(cc, lhs, rhs);
5132 }
5133 return false;
5134 case kCondLE:
5135 if (gt_bias) {
5136 __ ColeD(cc, lhs, rhs);
5137 } else {
5138 __ CuleD(cc, lhs, rhs);
5139 }
5140 return false;
5141 case kCondGT:
5142 if (gt_bias) {
5143 __ CultD(cc, rhs, lhs);
5144 } else {
5145 __ ColtD(cc, rhs, lhs);
5146 }
5147 return false;
5148 case kCondGE:
5149 if (gt_bias) {
5150 __ CuleD(cc, rhs, lhs);
5151 } else {
5152 __ ColeD(cc, rhs, lhs);
5153 }
5154 return false;
5155 default:
5156 LOG(FATAL) << "Unexpected non-floating-point condition";
5157 UNREACHABLE();
5158 }
5159 }
5160}
5161
5162bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond,
5163 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005164 DataType::Type type,
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005165 LocationSummary* input_locations,
5166 FRegister dst) {
5167 FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>();
5168 FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>();
5169 CHECK(codegen_->GetInstructionSetFeatures().IsR6());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005170 if (type == DataType::Type::kFloat32) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005171 switch (cond) {
5172 case kCondEQ:
5173 __ CmpEqS(dst, lhs, rhs);
5174 return false;
5175 case kCondNE:
5176 __ CmpEqS(dst, lhs, rhs);
5177 return true;
5178 case kCondLT:
5179 if (gt_bias) {
5180 __ CmpLtS(dst, lhs, rhs);
5181 } else {
5182 __ CmpUltS(dst, lhs, rhs);
5183 }
5184 return false;
5185 case kCondLE:
5186 if (gt_bias) {
5187 __ CmpLeS(dst, lhs, rhs);
5188 } else {
5189 __ CmpUleS(dst, lhs, rhs);
5190 }
5191 return false;
5192 case kCondGT:
5193 if (gt_bias) {
5194 __ CmpUltS(dst, rhs, lhs);
5195 } else {
5196 __ CmpLtS(dst, rhs, lhs);
5197 }
5198 return false;
5199 case kCondGE:
5200 if (gt_bias) {
5201 __ CmpUleS(dst, rhs, lhs);
5202 } else {
5203 __ CmpLeS(dst, rhs, lhs);
5204 }
5205 return false;
5206 default:
5207 LOG(FATAL) << "Unexpected non-floating-point condition";
5208 UNREACHABLE();
5209 }
5210 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005211 DCHECK_EQ(type, DataType::Type::kFloat64);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005212 switch (cond) {
5213 case kCondEQ:
5214 __ CmpEqD(dst, lhs, rhs);
5215 return false;
5216 case kCondNE:
5217 __ CmpEqD(dst, lhs, rhs);
5218 return true;
5219 case kCondLT:
5220 if (gt_bias) {
5221 __ CmpLtD(dst, lhs, rhs);
5222 } else {
5223 __ CmpUltD(dst, lhs, rhs);
5224 }
5225 return false;
5226 case kCondLE:
5227 if (gt_bias) {
5228 __ CmpLeD(dst, lhs, rhs);
5229 } else {
5230 __ CmpUleD(dst, lhs, rhs);
5231 }
5232 return false;
5233 case kCondGT:
5234 if (gt_bias) {
5235 __ CmpUltD(dst, rhs, lhs);
5236 } else {
5237 __ CmpLtD(dst, rhs, lhs);
5238 }
5239 return false;
5240 case kCondGE:
5241 if (gt_bias) {
5242 __ CmpUleD(dst, rhs, lhs);
5243 } else {
5244 __ CmpLeD(dst, rhs, lhs);
5245 }
5246 return false;
5247 default:
5248 LOG(FATAL) << "Unexpected non-floating-point condition";
5249 UNREACHABLE();
5250 }
5251 }
5252}
5253
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005254void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond,
5255 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005256 DataType::Type type,
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005257 LocationSummary* locations,
5258 MipsLabel* label) {
5259 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
5260 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
5261 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005262 if (type == DataType::Type::kFloat32) {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005263 if (isR6) {
5264 switch (cond) {
5265 case kCondEQ:
5266 __ CmpEqS(FTMP, lhs, rhs);
5267 __ Bc1nez(FTMP, label);
5268 break;
5269 case kCondNE:
5270 __ CmpEqS(FTMP, lhs, rhs);
5271 __ Bc1eqz(FTMP, label);
5272 break;
5273 case kCondLT:
5274 if (gt_bias) {
5275 __ CmpLtS(FTMP, lhs, rhs);
5276 } else {
5277 __ CmpUltS(FTMP, lhs, rhs);
5278 }
5279 __ Bc1nez(FTMP, label);
5280 break;
5281 case kCondLE:
5282 if (gt_bias) {
5283 __ CmpLeS(FTMP, lhs, rhs);
5284 } else {
5285 __ CmpUleS(FTMP, lhs, rhs);
5286 }
5287 __ Bc1nez(FTMP, label);
5288 break;
5289 case kCondGT:
5290 if (gt_bias) {
5291 __ CmpUltS(FTMP, rhs, lhs);
5292 } else {
5293 __ CmpLtS(FTMP, rhs, lhs);
5294 }
5295 __ Bc1nez(FTMP, label);
5296 break;
5297 case kCondGE:
5298 if (gt_bias) {
5299 __ CmpUleS(FTMP, rhs, lhs);
5300 } else {
5301 __ CmpLeS(FTMP, rhs, lhs);
5302 }
5303 __ Bc1nez(FTMP, label);
5304 break;
5305 default:
5306 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005307 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005308 }
5309 } else {
5310 switch (cond) {
5311 case kCondEQ:
5312 __ CeqS(0, lhs, rhs);
5313 __ Bc1t(0, label);
5314 break;
5315 case kCondNE:
5316 __ CeqS(0, lhs, rhs);
5317 __ Bc1f(0, label);
5318 break;
5319 case kCondLT:
5320 if (gt_bias) {
5321 __ ColtS(0, lhs, rhs);
5322 } else {
5323 __ CultS(0, lhs, rhs);
5324 }
5325 __ Bc1t(0, label);
5326 break;
5327 case kCondLE:
5328 if (gt_bias) {
5329 __ ColeS(0, lhs, rhs);
5330 } else {
5331 __ CuleS(0, lhs, rhs);
5332 }
5333 __ Bc1t(0, label);
5334 break;
5335 case kCondGT:
5336 if (gt_bias) {
5337 __ CultS(0, rhs, lhs);
5338 } else {
5339 __ ColtS(0, rhs, lhs);
5340 }
5341 __ Bc1t(0, label);
5342 break;
5343 case kCondGE:
5344 if (gt_bias) {
5345 __ CuleS(0, rhs, lhs);
5346 } else {
5347 __ ColeS(0, rhs, lhs);
5348 }
5349 __ Bc1t(0, label);
5350 break;
5351 default:
5352 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005353 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005354 }
5355 }
5356 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005357 DCHECK_EQ(type, DataType::Type::kFloat64);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005358 if (isR6) {
5359 switch (cond) {
5360 case kCondEQ:
5361 __ CmpEqD(FTMP, lhs, rhs);
5362 __ Bc1nez(FTMP, label);
5363 break;
5364 case kCondNE:
5365 __ CmpEqD(FTMP, lhs, rhs);
5366 __ Bc1eqz(FTMP, label);
5367 break;
5368 case kCondLT:
5369 if (gt_bias) {
5370 __ CmpLtD(FTMP, lhs, rhs);
5371 } else {
5372 __ CmpUltD(FTMP, lhs, rhs);
5373 }
5374 __ Bc1nez(FTMP, label);
5375 break;
5376 case kCondLE:
5377 if (gt_bias) {
5378 __ CmpLeD(FTMP, lhs, rhs);
5379 } else {
5380 __ CmpUleD(FTMP, lhs, rhs);
5381 }
5382 __ Bc1nez(FTMP, label);
5383 break;
5384 case kCondGT:
5385 if (gt_bias) {
5386 __ CmpUltD(FTMP, rhs, lhs);
5387 } else {
5388 __ CmpLtD(FTMP, rhs, lhs);
5389 }
5390 __ Bc1nez(FTMP, label);
5391 break;
5392 case kCondGE:
5393 if (gt_bias) {
5394 __ CmpUleD(FTMP, rhs, lhs);
5395 } else {
5396 __ CmpLeD(FTMP, rhs, lhs);
5397 }
5398 __ Bc1nez(FTMP, label);
5399 break;
5400 default:
5401 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005402 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005403 }
5404 } else {
5405 switch (cond) {
5406 case kCondEQ:
5407 __ CeqD(0, lhs, rhs);
5408 __ Bc1t(0, label);
5409 break;
5410 case kCondNE:
5411 __ CeqD(0, lhs, rhs);
5412 __ Bc1f(0, label);
5413 break;
5414 case kCondLT:
5415 if (gt_bias) {
5416 __ ColtD(0, lhs, rhs);
5417 } else {
5418 __ CultD(0, lhs, rhs);
5419 }
5420 __ Bc1t(0, label);
5421 break;
5422 case kCondLE:
5423 if (gt_bias) {
5424 __ ColeD(0, lhs, rhs);
5425 } else {
5426 __ CuleD(0, lhs, rhs);
5427 }
5428 __ Bc1t(0, label);
5429 break;
5430 case kCondGT:
5431 if (gt_bias) {
5432 __ CultD(0, rhs, lhs);
5433 } else {
5434 __ ColtD(0, rhs, lhs);
5435 }
5436 __ Bc1t(0, label);
5437 break;
5438 case kCondGE:
5439 if (gt_bias) {
5440 __ CuleD(0, rhs, lhs);
5441 } else {
5442 __ ColeD(0, rhs, lhs);
5443 }
5444 __ Bc1t(0, label);
5445 break;
5446 default:
5447 LOG(FATAL) << "Unexpected non-floating-point condition";
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005448 UNREACHABLE();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005449 }
5450 }
5451 }
5452}
5453
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005454void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00005455 size_t condition_input_index,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005456 MipsLabel* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00005457 MipsLabel* false_target) {
5458 HInstruction* cond = instruction->InputAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005459
David Brazdil0debae72015-11-12 18:37:00 +00005460 if (true_target == nullptr && false_target == nullptr) {
5461 // Nothing to do. The code always falls through.
5462 return;
5463 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00005464 // Constant condition, statically compared against "true" (integer value 1).
5465 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00005466 if (true_target != nullptr) {
5467 __ B(true_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005468 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005469 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00005470 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00005471 if (false_target != nullptr) {
5472 __ B(false_target);
5473 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005474 }
David Brazdil0debae72015-11-12 18:37:00 +00005475 return;
5476 }
5477
5478 // The following code generates these patterns:
5479 // (1) true_target == nullptr && false_target != nullptr
5480 // - opposite condition true => branch to false_target
5481 // (2) true_target != nullptr && false_target == nullptr
5482 // - condition true => branch to true_target
5483 // (3) true_target != nullptr && false_target != nullptr
5484 // - condition true => branch to true_target
5485 // - branch to false_target
5486 if (IsBooleanValueOrMaterializedCondition(cond)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005487 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00005488 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005489 DCHECK(cond_val.IsRegister());
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005490 if (true_target == nullptr) {
David Brazdil0debae72015-11-12 18:37:00 +00005491 __ Beqz(cond_val.AsRegister<Register>(), false_target);
5492 } else {
5493 __ Bnez(cond_val.AsRegister<Register>(), true_target);
5494 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005495 } else {
5496 // The condition instruction has not been materialized, use its inputs as
5497 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00005498 HCondition* condition = cond->AsCondition();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005499 DataType::Type type = condition->InputAt(0)->GetType();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005500 LocationSummary* locations = cond->GetLocations();
5501 IfCondition if_cond = condition->GetCondition();
5502 MipsLabel* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00005503
David Brazdil0debae72015-11-12 18:37:00 +00005504 if (true_target == nullptr) {
5505 if_cond = condition->GetOppositeCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005506 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00005507 }
5508
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005509 switch (type) {
5510 default:
5511 GenerateIntCompareAndBranch(if_cond, locations, branch_target);
5512 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005513 case DataType::Type::kInt64:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005514 GenerateLongCompareAndBranch(if_cond, locations, branch_target);
5515 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005516 case DataType::Type::kFloat32:
5517 case DataType::Type::kFloat64:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08005518 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
5519 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005520 }
5521 }
David Brazdil0debae72015-11-12 18:37:00 +00005522
5523 // If neither branch falls through (case 3), the conditional branch to `true_target`
5524 // was already emitted (case 2) and we need to emit a jump to `false_target`.
5525 if (true_target != nullptr && false_target != nullptr) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005526 __ B(false_target);
5527 }
5528}
5529
5530void LocationsBuilderMIPS::VisitIf(HIf* if_instr) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01005531 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00005532 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005533 locations->SetInAt(0, Location::RequiresRegister());
5534 }
5535}
5536
5537void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00005538 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
5539 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
5540 MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
5541 nullptr : codegen_->GetLabelOf(true_successor);
5542 MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
5543 nullptr : codegen_->GetLabelOf(false_successor);
5544 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005545}
5546
5547void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01005548 LocationSummary* locations = new (GetGraph()->GetAllocator())
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005549 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01005550 InvokeRuntimeCallingConvention calling_convention;
5551 RegisterSet caller_saves = RegisterSet::Empty();
5552 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5553 locations->SetCustomSlowPathCallerSaves(caller_saves);
David Brazdil0debae72015-11-12 18:37:00 +00005554 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005555 locations->SetInAt(0, Location::RequiresRegister());
5556 }
5557}
5558
5559void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08005560 SlowPathCodeMIPS* slow_path =
5561 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00005562 GenerateTestAndBranch(deoptimize,
5563 /* condition_input_index */ 0,
5564 slow_path->GetEntryLabel(),
5565 /* false_target */ nullptr);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005566}
5567
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005568// This function returns true if a conditional move can be generated for HSelect.
5569// Otherwise it returns false and HSelect must be implemented in terms of conditonal
5570// branches and regular moves.
5571//
5572// If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect.
5573//
5574// While determining feasibility of a conditional move and setting inputs/outputs
5575// are two distinct tasks, this function does both because they share quite a bit
5576// of common logic.
5577static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) {
5578 bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition());
5579 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
5580 HCondition* condition = cond->AsCondition();
5581
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005582 DataType::Type cond_type =
5583 materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType();
5584 DataType::Type dst_type = select->GetType();
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005585
5586 HConstant* cst_true_value = select->GetTrueValue()->AsConstant();
5587 HConstant* cst_false_value = select->GetFalseValue()->AsConstant();
5588 bool is_true_value_zero_constant =
5589 (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern());
5590 bool is_false_value_zero_constant =
5591 (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern());
5592
5593 bool can_move_conditionally = false;
5594 bool use_const_for_false_in = false;
5595 bool use_const_for_true_in = false;
5596
5597 if (!cond->IsConstant()) {
5598 switch (cond_type) {
5599 default:
5600 switch (dst_type) {
5601 default:
5602 // Moving int on int condition.
5603 if (is_r6) {
5604 if (is_true_value_zero_constant) {
5605 // seleqz out_reg, false_reg, cond_reg
5606 can_move_conditionally = true;
5607 use_const_for_true_in = true;
5608 } else if (is_false_value_zero_constant) {
5609 // selnez out_reg, true_reg, cond_reg
5610 can_move_conditionally = true;
5611 use_const_for_false_in = true;
5612 } else if (materialized) {
5613 // Not materializing unmaterialized int conditions
5614 // to keep the instruction count low.
5615 // selnez AT, true_reg, cond_reg
5616 // seleqz TMP, false_reg, cond_reg
5617 // or out_reg, AT, TMP
5618 can_move_conditionally = true;
5619 }
5620 } else {
5621 // movn out_reg, true_reg/ZERO, cond_reg
5622 can_move_conditionally = true;
5623 use_const_for_true_in = is_true_value_zero_constant;
5624 }
5625 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005626 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005627 // Moving long on int condition.
5628 if (is_r6) {
5629 if (is_true_value_zero_constant) {
5630 // seleqz out_reg_lo, false_reg_lo, cond_reg
5631 // seleqz out_reg_hi, false_reg_hi, cond_reg
5632 can_move_conditionally = true;
5633 use_const_for_true_in = true;
5634 } else if (is_false_value_zero_constant) {
5635 // selnez out_reg_lo, true_reg_lo, cond_reg
5636 // selnez out_reg_hi, true_reg_hi, cond_reg
5637 can_move_conditionally = true;
5638 use_const_for_false_in = true;
5639 }
5640 // Other long conditional moves would generate 6+ instructions,
5641 // which is too many.
5642 } else {
5643 // movn out_reg_lo, true_reg_lo/ZERO, cond_reg
5644 // movn out_reg_hi, true_reg_hi/ZERO, cond_reg
5645 can_move_conditionally = true;
5646 use_const_for_true_in = is_true_value_zero_constant;
5647 }
5648 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005649 case DataType::Type::kFloat32:
5650 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005651 // Moving float/double on int condition.
5652 if (is_r6) {
5653 if (materialized) {
5654 // Not materializing unmaterialized int conditions
5655 // to keep the instruction count low.
5656 can_move_conditionally = true;
5657 if (is_true_value_zero_constant) {
5658 // sltu TMP, ZERO, cond_reg
5659 // mtc1 TMP, temp_cond_reg
5660 // seleqz.fmt out_reg, false_reg, temp_cond_reg
5661 use_const_for_true_in = true;
5662 } else if (is_false_value_zero_constant) {
5663 // sltu TMP, ZERO, cond_reg
5664 // mtc1 TMP, temp_cond_reg
5665 // selnez.fmt out_reg, true_reg, temp_cond_reg
5666 use_const_for_false_in = true;
5667 } else {
5668 // sltu TMP, ZERO, cond_reg
5669 // mtc1 TMP, temp_cond_reg
5670 // sel.fmt temp_cond_reg, false_reg, true_reg
5671 // mov.fmt out_reg, temp_cond_reg
5672 }
5673 }
5674 } else {
5675 // movn.fmt out_reg, true_reg, cond_reg
5676 can_move_conditionally = true;
5677 }
5678 break;
5679 }
5680 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005681 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005682 // We don't materialize long comparison now
5683 // and use conditional branches instead.
5684 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005685 case DataType::Type::kFloat32:
5686 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005687 switch (dst_type) {
5688 default:
5689 // Moving int on float/double condition.
5690 if (is_r6) {
5691 if (is_true_value_zero_constant) {
5692 // mfc1 TMP, temp_cond_reg
5693 // seleqz out_reg, false_reg, TMP
5694 can_move_conditionally = true;
5695 use_const_for_true_in = true;
5696 } else if (is_false_value_zero_constant) {
5697 // mfc1 TMP, temp_cond_reg
5698 // selnez out_reg, true_reg, TMP
5699 can_move_conditionally = true;
5700 use_const_for_false_in = true;
5701 } else {
5702 // mfc1 TMP, temp_cond_reg
5703 // selnez AT, true_reg, TMP
5704 // seleqz TMP, false_reg, TMP
5705 // or out_reg, AT, TMP
5706 can_move_conditionally = true;
5707 }
5708 } else {
5709 // movt out_reg, true_reg/ZERO, cc
5710 can_move_conditionally = true;
5711 use_const_for_true_in = is_true_value_zero_constant;
5712 }
5713 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005714 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005715 // Moving long on float/double condition.
5716 if (is_r6) {
5717 if (is_true_value_zero_constant) {
5718 // mfc1 TMP, temp_cond_reg
5719 // seleqz out_reg_lo, false_reg_lo, TMP
5720 // seleqz out_reg_hi, false_reg_hi, TMP
5721 can_move_conditionally = true;
5722 use_const_for_true_in = true;
5723 } else if (is_false_value_zero_constant) {
5724 // mfc1 TMP, temp_cond_reg
5725 // selnez out_reg_lo, true_reg_lo, TMP
5726 // selnez out_reg_hi, true_reg_hi, TMP
5727 can_move_conditionally = true;
5728 use_const_for_false_in = true;
5729 }
5730 // Other long conditional moves would generate 6+ instructions,
5731 // which is too many.
5732 } else {
5733 // movt out_reg_lo, true_reg_lo/ZERO, cc
5734 // movt out_reg_hi, true_reg_hi/ZERO, cc
5735 can_move_conditionally = true;
5736 use_const_for_true_in = is_true_value_zero_constant;
5737 }
5738 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005739 case DataType::Type::kFloat32:
5740 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005741 // Moving float/double on float/double condition.
5742 if (is_r6) {
5743 can_move_conditionally = true;
5744 if (is_true_value_zero_constant) {
5745 // seleqz.fmt out_reg, false_reg, temp_cond_reg
5746 use_const_for_true_in = true;
5747 } else if (is_false_value_zero_constant) {
5748 // selnez.fmt out_reg, true_reg, temp_cond_reg
5749 use_const_for_false_in = true;
5750 } else {
5751 // sel.fmt temp_cond_reg, false_reg, true_reg
5752 // mov.fmt out_reg, temp_cond_reg
5753 }
5754 } else {
5755 // movt.fmt out_reg, true_reg, cc
5756 can_move_conditionally = true;
5757 }
5758 break;
5759 }
5760 break;
5761 }
5762 }
5763
5764 if (can_move_conditionally) {
5765 DCHECK(!use_const_for_false_in || !use_const_for_true_in);
5766 } else {
5767 DCHECK(!use_const_for_false_in);
5768 DCHECK(!use_const_for_true_in);
5769 }
5770
5771 if (locations_to_set != nullptr) {
5772 if (use_const_for_false_in) {
5773 locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value));
5774 } else {
5775 locations_to_set->SetInAt(0,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005776 DataType::IsFloatingPointType(dst_type)
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005777 ? Location::RequiresFpuRegister()
5778 : Location::RequiresRegister());
5779 }
5780 if (use_const_for_true_in) {
5781 locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value));
5782 } else {
5783 locations_to_set->SetInAt(1,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005784 DataType::IsFloatingPointType(dst_type)
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005785 ? Location::RequiresFpuRegister()
5786 : Location::RequiresRegister());
5787 }
5788 if (materialized) {
5789 locations_to_set->SetInAt(2, Location::RequiresRegister());
5790 }
5791 // On R6 we don't require the output to be the same as the
5792 // first input for conditional moves unlike on R2.
5793 bool is_out_same_as_first_in = !can_move_conditionally || !is_r6;
5794 if (is_out_same_as_first_in) {
5795 locations_to_set->SetOut(Location::SameAsFirstInput());
5796 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005797 locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type)
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005798 ? Location::RequiresFpuRegister()
5799 : Location::RequiresRegister());
5800 }
5801 }
5802
5803 return can_move_conditionally;
5804}
5805
5806void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) {
5807 LocationSummary* locations = select->GetLocations();
5808 Location dst = locations->Out();
5809 Location src = locations->InAt(1);
5810 Register src_reg = ZERO;
5811 Register src_reg_high = ZERO;
5812 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
5813 Register cond_reg = TMP;
5814 int cond_cc = 0;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005815 DataType::Type cond_type = DataType::Type::kInt32;
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005816 bool cond_inverted = false;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005817 DataType::Type dst_type = select->GetType();
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005818
5819 if (IsBooleanValueOrMaterializedCondition(cond)) {
5820 cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>();
5821 } else {
5822 HCondition* condition = cond->AsCondition();
5823 LocationSummary* cond_locations = cond->GetLocations();
5824 IfCondition if_cond = condition->GetCondition();
5825 cond_type = condition->InputAt(0)->GetType();
5826 switch (cond_type) {
5827 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005828 DCHECK_NE(cond_type, DataType::Type::kInt64);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005829 cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg);
5830 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005831 case DataType::Type::kFloat32:
5832 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005833 cond_inverted = MaterializeFpCompareR2(if_cond,
5834 condition->IsGtBias(),
5835 cond_type,
5836 cond_locations,
5837 cond_cc);
5838 break;
5839 }
5840 }
5841
5842 DCHECK(dst.Equals(locations->InAt(0)));
5843 if (src.IsRegister()) {
5844 src_reg = src.AsRegister<Register>();
5845 } else if (src.IsRegisterPair()) {
5846 src_reg = src.AsRegisterPairLow<Register>();
5847 src_reg_high = src.AsRegisterPairHigh<Register>();
5848 } else if (src.IsConstant()) {
5849 DCHECK(src.GetConstant()->IsZeroBitPattern());
5850 }
5851
5852 switch (cond_type) {
5853 default:
5854 switch (dst_type) {
5855 default:
5856 if (cond_inverted) {
5857 __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg);
5858 } else {
5859 __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg);
5860 }
5861 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005862 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005863 if (cond_inverted) {
5864 __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg);
5865 __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg);
5866 } else {
5867 __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg);
5868 __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg);
5869 }
5870 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005871 case DataType::Type::kFloat32:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005872 if (cond_inverted) {
5873 __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
5874 } else {
5875 __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
5876 }
5877 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005878 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005879 if (cond_inverted) {
5880 __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
5881 } else {
5882 __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg);
5883 }
5884 break;
5885 }
5886 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005887 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005888 LOG(FATAL) << "Unreachable";
5889 UNREACHABLE();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005890 case DataType::Type::kFloat32:
5891 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005892 switch (dst_type) {
5893 default:
5894 if (cond_inverted) {
5895 __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc);
5896 } else {
5897 __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc);
5898 }
5899 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005900 case DataType::Type::kInt64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005901 if (cond_inverted) {
5902 __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc);
5903 __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc);
5904 } else {
5905 __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc);
5906 __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc);
5907 }
5908 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005909 case DataType::Type::kFloat32:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005910 if (cond_inverted) {
5911 __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
5912 } else {
5913 __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
5914 }
5915 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005916 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005917 if (cond_inverted) {
5918 __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
5919 } else {
5920 __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc);
5921 }
5922 break;
5923 }
5924 break;
5925 }
5926}
5927
5928void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) {
5929 LocationSummary* locations = select->GetLocations();
5930 Location dst = locations->Out();
5931 Location false_src = locations->InAt(0);
5932 Location true_src = locations->InAt(1);
5933 HInstruction* cond = select->InputAt(/* condition_input_index */ 2);
5934 Register cond_reg = TMP;
5935 FRegister fcond_reg = FTMP;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005936 DataType::Type cond_type = DataType::Type::kInt32;
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005937 bool cond_inverted = false;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005938 DataType::Type dst_type = select->GetType();
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005939
5940 if (IsBooleanValueOrMaterializedCondition(cond)) {
5941 cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>();
5942 } else {
5943 HCondition* condition = cond->AsCondition();
5944 LocationSummary* cond_locations = cond->GetLocations();
5945 IfCondition if_cond = condition->GetCondition();
5946 cond_type = condition->InputAt(0)->GetType();
5947 switch (cond_type) {
5948 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005949 DCHECK_NE(cond_type, DataType::Type::kInt64);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005950 cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg);
5951 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005952 case DataType::Type::kFloat32:
5953 case DataType::Type::kFloat64:
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005954 cond_inverted = MaterializeFpCompareR6(if_cond,
5955 condition->IsGtBias(),
5956 cond_type,
5957 cond_locations,
5958 fcond_reg);
5959 break;
5960 }
5961 }
5962
5963 if (true_src.IsConstant()) {
5964 DCHECK(true_src.GetConstant()->IsZeroBitPattern());
5965 }
5966 if (false_src.IsConstant()) {
5967 DCHECK(false_src.GetConstant()->IsZeroBitPattern());
5968 }
5969
5970 switch (dst_type) {
5971 default:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005972 if (DataType::IsFloatingPointType(cond_type)) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07005973 __ Mfc1(cond_reg, fcond_reg);
5974 }
5975 if (true_src.IsConstant()) {
5976 if (cond_inverted) {
5977 __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg);
5978 } else {
5979 __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg);
5980 }
5981 } else if (false_src.IsConstant()) {
5982 if (cond_inverted) {
5983 __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg);
5984 } else {
5985 __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg);
5986 }
5987 } else {
5988 DCHECK_NE(cond_reg, AT);
5989 if (cond_inverted) {
5990 __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg);
5991 __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg);
5992 } else {
5993 __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg);
5994 __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg);
5995 }
5996 __ Or(dst.AsRegister<Register>(), AT, TMP);
5997 }
5998 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01005999 case DataType::Type::kInt64: {
6000 if (DataType::IsFloatingPointType(cond_type)) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006001 __ Mfc1(cond_reg, fcond_reg);
6002 }
6003 Register dst_lo = dst.AsRegisterPairLow<Register>();
6004 Register dst_hi = dst.AsRegisterPairHigh<Register>();
6005 if (true_src.IsConstant()) {
6006 Register src_lo = false_src.AsRegisterPairLow<Register>();
6007 Register src_hi = false_src.AsRegisterPairHigh<Register>();
6008 if (cond_inverted) {
6009 __ Selnez(dst_lo, src_lo, cond_reg);
6010 __ Selnez(dst_hi, src_hi, cond_reg);
6011 } else {
6012 __ Seleqz(dst_lo, src_lo, cond_reg);
6013 __ Seleqz(dst_hi, src_hi, cond_reg);
6014 }
6015 } else {
6016 DCHECK(false_src.IsConstant());
6017 Register src_lo = true_src.AsRegisterPairLow<Register>();
6018 Register src_hi = true_src.AsRegisterPairHigh<Register>();
6019 if (cond_inverted) {
6020 __ Seleqz(dst_lo, src_lo, cond_reg);
6021 __ Seleqz(dst_hi, src_hi, cond_reg);
6022 } else {
6023 __ Selnez(dst_lo, src_lo, cond_reg);
6024 __ Selnez(dst_hi, src_hi, cond_reg);
6025 }
6026 }
6027 break;
6028 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006029 case DataType::Type::kFloat32: {
6030 if (!DataType::IsFloatingPointType(cond_type)) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006031 // sel*.fmt tests bit 0 of the condition register, account for that.
6032 __ Sltu(TMP, ZERO, cond_reg);
6033 __ Mtc1(TMP, fcond_reg);
6034 }
6035 FRegister dst_reg = dst.AsFpuRegister<FRegister>();
6036 if (true_src.IsConstant()) {
6037 FRegister src_reg = false_src.AsFpuRegister<FRegister>();
6038 if (cond_inverted) {
6039 __ SelnezS(dst_reg, src_reg, fcond_reg);
6040 } else {
6041 __ SeleqzS(dst_reg, src_reg, fcond_reg);
6042 }
6043 } else if (false_src.IsConstant()) {
6044 FRegister src_reg = true_src.AsFpuRegister<FRegister>();
6045 if (cond_inverted) {
6046 __ SeleqzS(dst_reg, src_reg, fcond_reg);
6047 } else {
6048 __ SelnezS(dst_reg, src_reg, fcond_reg);
6049 }
6050 } else {
6051 if (cond_inverted) {
6052 __ SelS(fcond_reg,
6053 true_src.AsFpuRegister<FRegister>(),
6054 false_src.AsFpuRegister<FRegister>());
6055 } else {
6056 __ SelS(fcond_reg,
6057 false_src.AsFpuRegister<FRegister>(),
6058 true_src.AsFpuRegister<FRegister>());
6059 }
6060 __ MovS(dst_reg, fcond_reg);
6061 }
6062 break;
6063 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006064 case DataType::Type::kFloat64: {
6065 if (!DataType::IsFloatingPointType(cond_type)) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006066 // sel*.fmt tests bit 0 of the condition register, account for that.
6067 __ Sltu(TMP, ZERO, cond_reg);
6068 __ Mtc1(TMP, fcond_reg);
6069 }
6070 FRegister dst_reg = dst.AsFpuRegister<FRegister>();
6071 if (true_src.IsConstant()) {
6072 FRegister src_reg = false_src.AsFpuRegister<FRegister>();
6073 if (cond_inverted) {
6074 __ SelnezD(dst_reg, src_reg, fcond_reg);
6075 } else {
6076 __ SeleqzD(dst_reg, src_reg, fcond_reg);
6077 }
6078 } else if (false_src.IsConstant()) {
6079 FRegister src_reg = true_src.AsFpuRegister<FRegister>();
6080 if (cond_inverted) {
6081 __ SeleqzD(dst_reg, src_reg, fcond_reg);
6082 } else {
6083 __ SelnezD(dst_reg, src_reg, fcond_reg);
6084 }
6085 } else {
6086 if (cond_inverted) {
6087 __ SelD(fcond_reg,
6088 true_src.AsFpuRegister<FRegister>(),
6089 false_src.AsFpuRegister<FRegister>());
6090 } else {
6091 __ SelD(fcond_reg,
6092 false_src.AsFpuRegister<FRegister>(),
6093 true_src.AsFpuRegister<FRegister>());
6094 }
6095 __ MovD(dst_reg, fcond_reg);
6096 }
6097 break;
6098 }
6099 }
6100}
6101
Goran Jakovljevicc6418422016-12-05 16:31:55 +01006102void LocationsBuilderMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006103 LocationSummary* locations = new (GetGraph()->GetAllocator())
Goran Jakovljevicc6418422016-12-05 16:31:55 +01006104 LocationSummary(flag, LocationSummary::kNoCall);
6105 locations->SetOut(Location::RequiresRegister());
Mingyao Yang063fc772016-08-02 11:02:54 -07006106}
6107
Goran Jakovljevicc6418422016-12-05 16:31:55 +01006108void InstructionCodeGeneratorMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
6109 __ LoadFromOffset(kLoadWord,
6110 flag->GetLocations()->Out().AsRegister<Register>(),
6111 SP,
6112 codegen_->GetStackOffsetOfShouldDeoptimizeFlag());
Mingyao Yang063fc772016-08-02 11:02:54 -07006113}
6114
David Brazdil74eb1b22015-12-14 11:44:01 +00006115void LocationsBuilderMIPS::VisitSelect(HSelect* select) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006116 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006117 CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations);
David Brazdil74eb1b22015-12-14 11:44:01 +00006118}
6119
6120void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) {
Alexey Frunze674b9ee2016-09-20 14:54:15 -07006121 bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6();
6122 if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) {
6123 if (is_r6) {
6124 GenConditionalMoveR6(select);
6125 } else {
6126 GenConditionalMoveR2(select);
6127 }
6128 } else {
6129 LocationSummary* locations = select->GetLocations();
6130 MipsLabel false_target;
6131 GenerateTestAndBranch(select,
6132 /* condition_input_index */ 2,
6133 /* true_target */ nullptr,
6134 &false_target);
6135 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
6136 __ Bind(&false_target);
6137 }
David Brazdil74eb1b22015-12-14 11:44:01 +00006138}
6139
David Srbecky0cf44932015-12-09 14:09:59 +00006140void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01006141 new (GetGraph()->GetAllocator()) LocationSummary(info);
David Srbecky0cf44932015-12-09 14:09:59 +00006142}
6143
David Srbeckyd28f4a02016-03-14 17:14:24 +00006144void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) {
6145 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00006146}
6147
6148void CodeGeneratorMIPS::GenerateNop() {
6149 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00006150}
6151
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006152void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006153 DataType::Type field_type = field_info.GetFieldType();
6154 bool is_wide = (field_type == DataType::Type::kInt64) || (field_type == DataType::Type::kFloat64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006155 bool generate_volatile = field_info.IsVolatile() && is_wide;
Alexey Frunze15958152017-02-09 19:08:30 -08006156 bool object_field_get_with_read_barrier =
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006157 kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference);
Vladimir Markoca6fff82017-10-03 14:49:14 +01006158 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
Alexey Frunze15958152017-02-09 19:08:30 -08006159 instruction,
6160 generate_volatile
6161 ? LocationSummary::kCallOnMainOnly
6162 : (object_field_get_with_read_barrier
6163 ? LocationSummary::kCallOnSlowPath
6164 : LocationSummary::kNoCall));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006165
Alexey Frunzec61c0762017-04-10 13:54:23 -07006166 if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
6167 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
6168 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006169 locations->SetInAt(0, Location::RequiresRegister());
6170 if (generate_volatile) {
6171 InvokeRuntimeCallingConvention calling_convention;
6172 // need A0 to hold base + offset
6173 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006174 if (field_type == DataType::Type::kInt64) {
6175 locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kInt64));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006176 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006177 // Use Location::Any() to prevent situations when running out of available fp registers.
6178 locations->SetOut(Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006179 // Need some temp core regs since FP results are returned in core registers
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006180 Location reg = calling_convention.GetReturnLocation(DataType::Type::kInt64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006181 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>()));
6182 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>()));
6183 }
6184 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006185 if (DataType::IsFloatingPointType(instruction->GetType())) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006186 locations->SetOut(Location::RequiresFpuRegister());
6187 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08006188 // The output overlaps in the case of an object field get with
6189 // read barriers enabled: we do not want the move to overwrite the
6190 // object's location, as we need it to emit the read barrier.
6191 locations->SetOut(Location::RequiresRegister(),
6192 object_field_get_with_read_barrier
6193 ? Location::kOutputOverlap
6194 : Location::kNoOutputOverlap);
6195 }
6196 if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
6197 // We need a temporary register for the read barrier marking slow
6198 // path in CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier.
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006199 if (!kBakerReadBarrierThunksEnableForFields) {
6200 locations->AddTemp(Location::RequiresRegister());
6201 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006202 }
6203 }
6204}
6205
6206void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction,
6207 const FieldInfo& field_info,
6208 uint32_t dex_pc) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006209 DataType::Type type = field_info.GetFieldType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006210 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08006211 Location obj_loc = locations->InAt(0);
6212 Register obj = obj_loc.AsRegister<Register>();
6213 Location dst_loc = locations->Out();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006214 LoadOperandType load_type = kLoadUnsignedByte;
6215 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01006216 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Tijana Jakovljevic57433862017-01-17 16:59:03 +01006217 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006218
6219 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006220 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006221 case DataType::Type::kUint8:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006222 load_type = kLoadUnsignedByte;
6223 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006224 case DataType::Type::kInt8:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006225 load_type = kLoadSignedByte;
6226 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006227 case DataType::Type::kUint16:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006228 load_type = kLoadUnsignedHalfword;
6229 break;
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006230 case DataType::Type::kInt16:
6231 load_type = kLoadSignedHalfword;
6232 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006233 case DataType::Type::kInt32:
6234 case DataType::Type::kFloat32:
6235 case DataType::Type::kReference:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006236 load_type = kLoadWord;
6237 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006238 case DataType::Type::kInt64:
6239 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006240 load_type = kLoadDoubleword;
6241 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006242 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006243 LOG(FATAL) << "Unreachable type " << type;
6244 UNREACHABLE();
6245 }
6246
6247 if (is_volatile && load_type == kLoadDoubleword) {
6248 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01006249 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006250 // Do implicit Null check
6251 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
6252 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Serban Constantinescufca16662016-07-14 09:21:59 +01006253 codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006254 CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006255 if (type == DataType::Type::kFloat64) {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006256 // FP results are returned in core registers. Need to move them.
Alexey Frunze15958152017-02-09 19:08:30 -08006257 if (dst_loc.IsFpuRegister()) {
6258 __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), dst_loc.AsFpuRegister<FRegister>());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006259 __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
Alexey Frunze15958152017-02-09 19:08:30 -08006260 dst_loc.AsFpuRegister<FRegister>());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006261 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08006262 DCHECK(dst_loc.IsDoubleStackSlot());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006263 __ StoreToOffset(kStoreWord,
6264 locations->GetTemp(1).AsRegister<Register>(),
6265 SP,
Alexey Frunze15958152017-02-09 19:08:30 -08006266 dst_loc.GetStackIndex());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006267 __ StoreToOffset(kStoreWord,
6268 locations->GetTemp(2).AsRegister<Register>(),
6269 SP,
Alexey Frunze15958152017-02-09 19:08:30 -08006270 dst_loc.GetStackIndex() + 4);
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006271 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006272 }
6273 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006274 if (type == DataType::Type::kReference) {
Alexey Frunze15958152017-02-09 19:08:30 -08006275 // /* HeapReference<Object> */ dst = *(obj + offset)
6276 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006277 Location temp_loc =
6278 kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0);
Alexey Frunze15958152017-02-09 19:08:30 -08006279 // Note that a potential implicit null check is handled in this
6280 // CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier call.
6281 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
6282 dst_loc,
6283 obj,
6284 offset,
6285 temp_loc,
6286 /* needs_null_check */ true);
6287 if (is_volatile) {
6288 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
6289 }
6290 } else {
6291 __ LoadFromOffset(kLoadWord, dst_loc.AsRegister<Register>(), obj, offset, null_checker);
6292 if (is_volatile) {
6293 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
6294 }
6295 // If read barriers are enabled, emit read barriers other than
6296 // Baker's using a slow path (and also unpoison the loaded
6297 // reference, if heap poisoning is enabled).
6298 codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset);
6299 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006300 } else if (!DataType::IsFloatingPointType(type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006301 Register dst;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006302 if (type == DataType::Type::kInt64) {
Alexey Frunze15958152017-02-09 19:08:30 -08006303 DCHECK(dst_loc.IsRegisterPair());
6304 dst = dst_loc.AsRegisterPairLow<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006305 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08006306 DCHECK(dst_loc.IsRegister());
6307 dst = dst_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006308 }
Alexey Frunze2923db72016-08-20 01:55:47 -07006309 __ LoadFromOffset(load_type, dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006310 } else {
Alexey Frunze15958152017-02-09 19:08:30 -08006311 DCHECK(dst_loc.IsFpuRegister());
6312 FRegister dst = dst_loc.AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006313 if (type == DataType::Type::kFloat32) {
Alexey Frunze2923db72016-08-20 01:55:47 -07006314 __ LoadSFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006315 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07006316 __ LoadDFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006317 }
6318 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006319 }
6320
Alexey Frunze15958152017-02-09 19:08:30 -08006321 // Memory barriers, in the case of references, are handled in the
6322 // previous switch statement.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006323 if (is_volatile && (type != DataType::Type::kReference)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006324 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
6325 }
6326}
6327
6328void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006329 DataType::Type field_type = field_info.GetFieldType();
6330 bool is_wide = (field_type == DataType::Type::kInt64) || (field_type == DataType::Type::kFloat64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006331 bool generate_volatile = field_info.IsVolatile() && is_wide;
Vladimir Markoca6fff82017-10-03 14:49:14 +01006332 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006333 instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006334
6335 locations->SetInAt(0, Location::RequiresRegister());
6336 if (generate_volatile) {
6337 InvokeRuntimeCallingConvention calling_convention;
6338 // need A0 to hold base + offset
6339 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006340 if (field_type == DataType::Type::kInt64) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006341 locations->SetInAt(1, Location::RegisterPairLocation(
6342 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
6343 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006344 // Use Location::Any() to prevent situations when running out of available fp registers.
6345 locations->SetInAt(1, Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006346 // Pass FP parameters in core registers.
6347 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
6348 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
6349 }
6350 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006351 if (DataType::IsFloatingPointType(field_type)) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006352 locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006353 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006354 locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006355 }
6356 }
6357}
6358
6359void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction,
6360 const FieldInfo& field_info,
Goran Jakovljevice114da22016-12-26 14:21:43 +01006361 uint32_t dex_pc,
6362 bool value_can_be_null) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006363 DataType::Type type = field_info.GetFieldType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006364 LocationSummary* locations = instruction->GetLocations();
6365 Register obj = locations->InAt(0).AsRegister<Register>();
Alexey Frunzef58b2482016-09-02 22:14:06 -07006366 Location value_location = locations->InAt(1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006367 StoreOperandType store_type = kStoreByte;
6368 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01006369 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Alexey Frunzec061de12017-02-14 13:27:23 -08006370 bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1));
Tijana Jakovljevic57433862017-01-17 16:59:03 +01006371 auto null_checker = GetImplicitNullChecker(instruction, codegen_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006372
6373 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006374 case DataType::Type::kBool:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006375 case DataType::Type::kUint8:
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006376 case DataType::Type::kInt8:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006377 store_type = kStoreByte;
6378 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006379 case DataType::Type::kUint16:
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01006380 case DataType::Type::kInt16:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006381 store_type = kStoreHalfword;
6382 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006383 case DataType::Type::kInt32:
6384 case DataType::Type::kFloat32:
6385 case DataType::Type::kReference:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006386 store_type = kStoreWord;
6387 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006388 case DataType::Type::kInt64:
6389 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006390 store_type = kStoreDoubleword;
6391 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006392 case DataType::Type::kVoid:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006393 LOG(FATAL) << "Unreachable type " << type;
6394 UNREACHABLE();
6395 }
6396
6397 if (is_volatile) {
6398 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
6399 }
6400
6401 if (is_volatile && store_type == kStoreDoubleword) {
6402 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01006403 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006404 // Do implicit Null check.
6405 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
6406 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006407 if (type == DataType::Type::kFloat64) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006408 // Pass FP parameters in core registers.
Alexey Frunzef58b2482016-09-02 22:14:06 -07006409 if (value_location.IsFpuRegister()) {
6410 __ Mfc1(locations->GetTemp(1).AsRegister<Register>(),
6411 value_location.AsFpuRegister<FRegister>());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006412 __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
Alexey Frunzef58b2482016-09-02 22:14:06 -07006413 value_location.AsFpuRegister<FRegister>());
6414 } else if (value_location.IsDoubleStackSlot()) {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006415 __ LoadFromOffset(kLoadWord,
6416 locations->GetTemp(1).AsRegister<Register>(),
6417 SP,
Alexey Frunzef58b2482016-09-02 22:14:06 -07006418 value_location.GetStackIndex());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006419 __ LoadFromOffset(kLoadWord,
6420 locations->GetTemp(2).AsRegister<Register>(),
6421 SP,
Alexey Frunzef58b2482016-09-02 22:14:06 -07006422 value_location.GetStackIndex() + 4);
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006423 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006424 DCHECK(value_location.IsConstant());
6425 DCHECK(value_location.GetConstant()->IsDoubleConstant());
6426 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02006427 __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(),
6428 locations->GetTemp(1).AsRegister<Register>(),
6429 value);
6430 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006431 }
Serban Constantinescufca16662016-07-14 09:21:59 +01006432 codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006433 CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>();
6434 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006435 if (value_location.IsConstant()) {
6436 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
6437 __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006438 } else if (!DataType::IsFloatingPointType(type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006439 Register src;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006440 if (type == DataType::Type::kInt64) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006441 src = value_location.AsRegisterPairLow<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006442 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006443 src = value_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006444 }
Alexey Frunzec061de12017-02-14 13:27:23 -08006445 if (kPoisonHeapReferences && needs_write_barrier) {
6446 // Note that in the case where `value` is a null reference,
6447 // we do not enter this block, as a null reference does not
6448 // need poisoning.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006449 DCHECK_EQ(type, DataType::Type::kReference);
Alexey Frunzec061de12017-02-14 13:27:23 -08006450 __ PoisonHeapReference(TMP, src);
6451 __ StoreToOffset(store_type, TMP, obj, offset, null_checker);
6452 } else {
6453 __ StoreToOffset(store_type, src, obj, offset, null_checker);
6454 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006455 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006456 FRegister src = value_location.AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01006457 if (type == DataType::Type::kFloat32) {
Alexey Frunze2923db72016-08-20 01:55:47 -07006458 __ StoreSToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006459 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07006460 __ StoreDToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006461 }
6462 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006463 }
6464
Alexey Frunzec061de12017-02-14 13:27:23 -08006465 if (needs_write_barrier) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07006466 Register src = value_location.AsRegister<Register>();
Goran Jakovljevice114da22016-12-26 14:21:43 +01006467 codegen_->MarkGCCard(obj, src, value_can_be_null);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006468 }
6469
6470 if (is_volatile) {
6471 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
6472 }
6473}
6474
6475void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
6476 HandleFieldGet(instruction, instruction->GetFieldInfo());
6477}
6478
6479void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
6480 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
6481}
6482
6483void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
6484 HandleFieldSet(instruction, instruction->GetFieldInfo());
6485}
6486
6487void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Goran Jakovljevice114da22016-12-26 14:21:43 +01006488 HandleFieldSet(instruction,
6489 instruction->GetFieldInfo(),
6490 instruction->GetDexPc(),
6491 instruction->GetValueCanBeNull());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006492}
6493
Alexey Frunze15958152017-02-09 19:08:30 -08006494void InstructionCodeGeneratorMIPS::GenerateReferenceLoadOneRegister(
6495 HInstruction* instruction,
6496 Location out,
6497 uint32_t offset,
6498 Location maybe_temp,
6499 ReadBarrierOption read_barrier_option) {
6500 Register out_reg = out.AsRegister<Register>();
6501 if (read_barrier_option == kWithReadBarrier) {
6502 CHECK(kEmitCompilerReadBarrier);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006503 if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) {
6504 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
6505 }
Alexey Frunze15958152017-02-09 19:08:30 -08006506 if (kUseBakerReadBarrier) {
6507 // Load with fast path based Baker's read barrier.
6508 // /* HeapReference<Object> */ out = *(out + offset)
6509 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
6510 out,
6511 out_reg,
6512 offset,
6513 maybe_temp,
6514 /* needs_null_check */ false);
6515 } else {
6516 // Load with slow path based read barrier.
6517 // Save the value of `out` into `maybe_temp` before overwriting it
6518 // in the following move operation, as we will need it for the
6519 // read barrier below.
6520 __ Move(maybe_temp.AsRegister<Register>(), out_reg);
6521 // /* HeapReference<Object> */ out = *(out + offset)
6522 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
6523 codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset);
6524 }
6525 } else {
6526 // Plain load with no read barrier.
6527 // /* HeapReference<Object> */ out = *(out + offset)
6528 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
6529 __ MaybeUnpoisonHeapReference(out_reg);
6530 }
6531}
6532
6533void InstructionCodeGeneratorMIPS::GenerateReferenceLoadTwoRegisters(
6534 HInstruction* instruction,
6535 Location out,
6536 Location obj,
6537 uint32_t offset,
6538 Location maybe_temp,
6539 ReadBarrierOption read_barrier_option) {
6540 Register out_reg = out.AsRegister<Register>();
6541 Register obj_reg = obj.AsRegister<Register>();
6542 if (read_barrier_option == kWithReadBarrier) {
6543 CHECK(kEmitCompilerReadBarrier);
6544 if (kUseBakerReadBarrier) {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006545 if (!kBakerReadBarrierThunksEnableForFields) {
6546 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
6547 }
Alexey Frunze15958152017-02-09 19:08:30 -08006548 // Load with fast path based Baker's read barrier.
6549 // /* HeapReference<Object> */ out = *(obj + offset)
6550 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
6551 out,
6552 obj_reg,
6553 offset,
6554 maybe_temp,
6555 /* needs_null_check */ false);
6556 } else {
6557 // Load with slow path based read barrier.
6558 // /* HeapReference<Object> */ out = *(obj + offset)
6559 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6560 codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset);
6561 }
6562 } else {
6563 // Plain load with no read barrier.
6564 // /* HeapReference<Object> */ out = *(obj + offset)
6565 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6566 __ MaybeUnpoisonHeapReference(out_reg);
6567 }
6568}
6569
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006570static inline int GetBakerMarkThunkNumber(Register reg) {
6571 static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 21, "Expecting equal");
6572 if (reg >= V0 && reg <= T7) { // 14 consequtive regs.
6573 return reg - V0;
6574 } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs.
6575 return 14 + (reg - S2);
6576 } else if (reg == FP) { // One more.
6577 return 20;
6578 }
6579 LOG(FATAL) << "Unexpected register " << reg;
6580 UNREACHABLE();
6581}
6582
6583static inline int GetBakerMarkFieldArrayThunkDisplacement(Register reg, bool short_offset) {
6584 int num = GetBakerMarkThunkNumber(reg) +
6585 (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0);
6586 return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE;
6587}
6588
6589static inline int GetBakerMarkGcRootThunkDisplacement(Register reg) {
6590 return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE +
6591 BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET;
6592}
6593
Alexey Frunze15958152017-02-09 19:08:30 -08006594void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(HInstruction* instruction,
6595 Location root,
6596 Register obj,
6597 uint32_t offset,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006598 ReadBarrierOption read_barrier_option,
6599 MipsLabel* label_low) {
6600 bool reordering;
6601 if (label_low != nullptr) {
6602 DCHECK_EQ(offset, 0x5678u);
6603 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07006604 Register root_reg = root.AsRegister<Register>();
Alexey Frunze15958152017-02-09 19:08:30 -08006605 if (read_barrier_option == kWithReadBarrier) {
6606 DCHECK(kEmitCompilerReadBarrier);
6607 if (kUseBakerReadBarrier) {
6608 // Fast path implementation of art::ReadBarrier::BarrierForRoot when
6609 // Baker's read barrier are used:
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006610 if (kBakerReadBarrierThunksEnableForGcRoots) {
6611 // Note that we do not actually check the value of `GetIsGcMarking()`
6612 // to decide whether to mark the loaded GC root or not. Instead, we
6613 // load into `temp` (T9) the read barrier mark introspection entrypoint.
6614 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
6615 // vice versa.
6616 //
6617 // We use thunks for the slow path. That thunk checks the reference
6618 // and jumps to the entrypoint if needed.
6619 //
6620 // temp = Thread::Current()->pReadBarrierMarkReg00
6621 // // AKA &art_quick_read_barrier_mark_introspection.
6622 // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load.
6623 // if (temp != nullptr) {
6624 // temp = &gc_root_thunk<root_reg>
6625 // root = temp(root)
6626 // }
Alexey Frunze15958152017-02-09 19:08:30 -08006627
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006628 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
6629 const int32_t entry_point_offset =
6630 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0);
6631 const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg);
6632 int16_t offset_low = Low16Bits(offset);
6633 int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign
6634 // extension in lw.
6635 bool short_offset = IsInt<16>(static_cast<int32_t>(offset));
6636 Register base = short_offset ? obj : TMP;
6637 // Loading the entrypoint does not require a load acquire since it is only changed when
6638 // threads are suspended or running a checkpoint.
6639 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
6640 reordering = __ SetReorder(false);
6641 if (!short_offset) {
6642 DCHECK(!label_low);
6643 __ AddUpper(base, obj, offset_high);
6644 }
Alexey Frunze0cab6562017-07-25 15:19:36 -07006645 MipsLabel skip_call;
6646 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006647 if (label_low != nullptr) {
6648 DCHECK(short_offset);
6649 __ Bind(label_low);
6650 }
6651 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6652 __ LoadFromOffset(kLoadWord, root_reg, base, offset_low); // Single instruction
6653 // in delay slot.
6654 if (isR6) {
6655 __ Jialc(T9, thunk_disp);
6656 } else {
6657 __ Addiu(T9, T9, thunk_disp);
6658 __ Jalr(T9);
6659 __ Nop();
6660 }
Alexey Frunze0cab6562017-07-25 15:19:36 -07006661 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006662 __ SetReorder(reordering);
6663 } else {
6664 // Note that we do not actually check the value of `GetIsGcMarking()`
6665 // to decide whether to mark the loaded GC root or not. Instead, we
6666 // load into `temp` (T9) the read barrier mark entry point corresponding
6667 // to register `root`. If `temp` is null, it means that `GetIsGcMarking()`
6668 // is false, and vice versa.
6669 //
6670 // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load.
6671 // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg()
6672 // if (temp != null) {
6673 // root = temp(root)
6674 // }
Alexey Frunze15958152017-02-09 19:08:30 -08006675
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006676 if (label_low != nullptr) {
6677 reordering = __ SetReorder(false);
6678 __ Bind(label_low);
6679 }
6680 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6681 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6682 if (label_low != nullptr) {
6683 __ SetReorder(reordering);
6684 }
6685 static_assert(
6686 sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>),
6687 "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> "
6688 "have different sizes.");
6689 static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t),
6690 "art::mirror::CompressedReference<mirror::Object> and int32_t "
6691 "have different sizes.");
Alexey Frunze15958152017-02-09 19:08:30 -08006692
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006693 // Slow path marking the GC root `root`.
6694 Location temp = Location::RegisterLocation(T9);
6695 SlowPathCodeMIPS* slow_path =
Vladimir Markoca6fff82017-10-03 14:49:14 +01006696 new (GetGraph()->GetAllocator()) ReadBarrierMarkSlowPathMIPS(
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006697 instruction,
6698 root,
6699 /*entrypoint*/ temp);
6700 codegen_->AddSlowPath(slow_path);
6701
6702 const int32_t entry_point_offset =
6703 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(root.reg() - 1);
6704 // Loading the entrypoint does not require a load acquire since it is only changed when
6705 // threads are suspended or running a checkpoint.
6706 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset);
6707 __ Bnez(temp.AsRegister<Register>(), slow_path->GetEntryLabel());
6708 __ Bind(slow_path->GetExitLabel());
6709 }
Alexey Frunze15958152017-02-09 19:08:30 -08006710 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006711 if (label_low != nullptr) {
6712 reordering = __ SetReorder(false);
6713 __ Bind(label_low);
6714 }
Alexey Frunze15958152017-02-09 19:08:30 -08006715 // GC root loaded through a slow path for read barriers other
6716 // than Baker's.
6717 // /* GcRoot<mirror::Object>* */ root = obj + offset
6718 __ Addiu32(root_reg, obj, offset);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006719 if (label_low != nullptr) {
6720 __ SetReorder(reordering);
6721 }
Alexey Frunze15958152017-02-09 19:08:30 -08006722 // /* mirror::Object* */ root = root->Read()
6723 codegen_->GenerateReadBarrierForRootSlow(instruction, root, root);
6724 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07006725 } else {
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006726 if (label_low != nullptr) {
6727 reordering = __ SetReorder(false);
6728 __ Bind(label_low);
6729 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07006730 // Plain GC root load with no read barrier.
6731 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6732 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6733 // Note that GC roots are not affected by heap poisoning, thus we
6734 // do not have to unpoison `root_reg` here.
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006735 if (label_low != nullptr) {
6736 __ SetReorder(reordering);
6737 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07006738 }
6739}
6740
Alexey Frunze15958152017-02-09 19:08:30 -08006741void CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
6742 Location ref,
6743 Register obj,
6744 uint32_t offset,
6745 Location temp,
6746 bool needs_null_check) {
6747 DCHECK(kEmitCompilerReadBarrier);
6748 DCHECK(kUseBakerReadBarrier);
6749
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006750 if (kBakerReadBarrierThunksEnableForFields) {
6751 // Note that we do not actually check the value of `GetIsGcMarking()`
6752 // to decide whether to mark the loaded reference or not. Instead, we
6753 // load into `temp` (T9) the read barrier mark introspection entrypoint.
6754 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
6755 // vice versa.
6756 //
6757 // We use thunks for the slow path. That thunk checks the reference
6758 // and jumps to the entrypoint if needed. If the holder is not gray,
6759 // it issues a load-load memory barrier and returns to the original
6760 // reference load.
6761 //
6762 // temp = Thread::Current()->pReadBarrierMarkReg00
6763 // // AKA &art_quick_read_barrier_mark_introspection.
6764 // if (temp != nullptr) {
6765 // temp = &field_array_thunk<holder_reg>
6766 // temp()
6767 // }
6768 // not_gray_return_address:
6769 // // If the offset is too large to fit into the lw instruction, we
6770 // // use an adjusted base register (TMP) here. This register
6771 // // receives bits 16 ... 31 of the offset before the thunk invocation
6772 // // and the thunk benefits from it.
6773 // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load.
6774 // gray_return_address:
6775
6776 DCHECK(temp.IsInvalid());
6777 bool isR6 = GetInstructionSetFeatures().IsR6();
6778 int16_t offset_low = Low16Bits(offset);
6779 int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lw.
6780 bool short_offset = IsInt<16>(static_cast<int32_t>(offset));
6781 bool reordering = __ SetReorder(false);
6782 const int32_t entry_point_offset =
6783 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0);
6784 // There may have or may have not been a null check if the field offset is smaller than
6785 // the page size.
6786 // There must've been a null check in case it's actually a load from an array.
6787 // We will, however, perform an explicit null check in the thunk as it's easier to
6788 // do it than not.
6789 if (instruction->IsArrayGet()) {
6790 DCHECK(!needs_null_check);
6791 }
6792 const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset);
6793 // Loading the entrypoint does not require a load acquire since it is only changed when
6794 // threads are suspended or running a checkpoint.
6795 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
6796 Register ref_reg = ref.AsRegister<Register>();
6797 Register base = short_offset ? obj : TMP;
Alexey Frunze0cab6562017-07-25 15:19:36 -07006798 MipsLabel skip_call;
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006799 if (short_offset) {
6800 if (isR6) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07006801 __ Beqzc(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006802 __ Nop(); // In forbidden slot.
6803 __ Jialc(T9, thunk_disp);
6804 } else {
Alexey Frunze0cab6562017-07-25 15:19:36 -07006805 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006806 __ Addiu(T9, T9, thunk_disp); // In delay slot.
6807 __ Jalr(T9);
6808 __ Nop(); // In delay slot.
6809 }
Alexey Frunze0cab6562017-07-25 15:19:36 -07006810 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006811 } else {
6812 if (isR6) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07006813 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006814 __ Aui(base, obj, offset_high); // In delay slot.
6815 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07006816 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006817 } else {
6818 __ Lui(base, offset_high);
Alexey Frunze0cab6562017-07-25 15:19:36 -07006819 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006820 __ Addiu(T9, T9, thunk_disp); // In delay slot.
6821 __ Jalr(T9);
Alexey Frunze0cab6562017-07-25 15:19:36 -07006822 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006823 __ Addu(base, base, obj); // In delay slot.
6824 }
6825 }
6826 // /* HeapReference<Object> */ ref = *(obj + offset)
6827 __ LoadFromOffset(kLoadWord, ref_reg, base, offset_low); // Single instruction.
6828 if (needs_null_check) {
6829 MaybeRecordImplicitNullCheck(instruction);
6830 }
6831 __ MaybeUnpoisonHeapReference(ref_reg);
6832 __ SetReorder(reordering);
6833 return;
6834 }
6835
Alexey Frunze15958152017-02-09 19:08:30 -08006836 // /* HeapReference<Object> */ ref = *(obj + offset)
6837 Location no_index = Location::NoLocation();
6838 ScaleFactor no_scale_factor = TIMES_1;
6839 GenerateReferenceLoadWithBakerReadBarrier(instruction,
6840 ref,
6841 obj,
6842 offset,
6843 no_index,
6844 no_scale_factor,
6845 temp,
6846 needs_null_check);
6847}
6848
6849void CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
6850 Location ref,
6851 Register obj,
6852 uint32_t data_offset,
6853 Location index,
6854 Location temp,
6855 bool needs_null_check) {
6856 DCHECK(kEmitCompilerReadBarrier);
6857 DCHECK(kUseBakerReadBarrier);
6858
6859 static_assert(
6860 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
6861 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006862 ScaleFactor scale_factor = TIMES_4;
6863
6864 if (kBakerReadBarrierThunksEnableForArrays) {
6865 // Note that we do not actually check the value of `GetIsGcMarking()`
6866 // to decide whether to mark the loaded reference or not. Instead, we
6867 // load into `temp` (T9) the read barrier mark introspection entrypoint.
6868 // If `temp` is null, it means that `GetIsGcMarking()` is false, and
6869 // vice versa.
6870 //
6871 // We use thunks for the slow path. That thunk checks the reference
6872 // and jumps to the entrypoint if needed. If the holder is not gray,
6873 // it issues a load-load memory barrier and returns to the original
6874 // reference load.
6875 //
6876 // temp = Thread::Current()->pReadBarrierMarkReg00
6877 // // AKA &art_quick_read_barrier_mark_introspection.
6878 // if (temp != nullptr) {
6879 // temp = &field_array_thunk<holder_reg>
6880 // temp()
6881 // }
6882 // not_gray_return_address:
6883 // // The element address is pre-calculated in the TMP register before the
6884 // // thunk invocation and the thunk benefits from it.
6885 // HeapReference<mirror::Object> reference = data[index]; // Original reference load.
6886 // gray_return_address:
6887
6888 DCHECK(temp.IsInvalid());
6889 DCHECK(index.IsValid());
6890 bool reordering = __ SetReorder(false);
6891 const int32_t entry_point_offset =
6892 Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0);
6893 // We will not do the explicit null check in the thunk as some form of a null check
6894 // must've been done earlier.
6895 DCHECK(!needs_null_check);
6896 const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false);
6897 // Loading the entrypoint does not require a load acquire since it is only changed when
6898 // threads are suspended or running a checkpoint.
6899 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
6900 Register ref_reg = ref.AsRegister<Register>();
6901 Register index_reg = index.IsRegisterPair()
6902 ? index.AsRegisterPairLow<Register>()
6903 : index.AsRegister<Register>();
Alexey Frunze0cab6562017-07-25 15:19:36 -07006904 MipsLabel skip_call;
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006905 if (GetInstructionSetFeatures().IsR6()) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07006906 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006907 __ Lsa(TMP, index_reg, obj, scale_factor); // In delay slot.
6908 __ Jialc(T9, thunk_disp);
Alexey Frunze0cab6562017-07-25 15:19:36 -07006909 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006910 } else {
6911 __ Sll(TMP, index_reg, scale_factor);
Alexey Frunze0cab6562017-07-25 15:19:36 -07006912 __ Beqz(T9, &skip_call, /* is_bare */ true);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006913 __ Addiu(T9, T9, thunk_disp); // In delay slot.
6914 __ Jalr(T9);
Alexey Frunze0cab6562017-07-25 15:19:36 -07006915 __ Bind(&skip_call);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07006916 __ Addu(TMP, TMP, obj); // In delay slot.
6917 }
6918 // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor))
6919 DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset;
6920 __ LoadFromOffset(kLoadWord, ref_reg, TMP, data_offset); // Single instruction.
6921 __ MaybeUnpoisonHeapReference(ref_reg);
6922 __ SetReorder(reordering);
6923 return;
6924 }
6925
Alexey Frunze15958152017-02-09 19:08:30 -08006926 // /* HeapReference<Object> */ ref =
6927 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
Alexey Frunze15958152017-02-09 19:08:30 -08006928 GenerateReferenceLoadWithBakerReadBarrier(instruction,
6929 ref,
6930 obj,
6931 data_offset,
6932 index,
6933 scale_factor,
6934 temp,
6935 needs_null_check);
6936}
6937
6938void CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
6939 Location ref,
6940 Register obj,
6941 uint32_t offset,
6942 Location index,
6943 ScaleFactor scale_factor,
6944 Location temp,
6945 bool needs_null_check,
6946 bool always_update_field) {
6947 DCHECK(kEmitCompilerReadBarrier);
6948 DCHECK(kUseBakerReadBarrier);
6949
6950 // In slow path based read barriers, the read barrier call is
6951 // inserted after the original load. However, in fast path based
6952 // Baker's read barriers, we need to perform the load of
6953 // mirror::Object::monitor_ *before* the original reference load.
6954 // This load-load ordering is required by the read barrier.
6955 // The fast path/slow path (for Baker's algorithm) should look like:
6956 //
6957 // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState();
6958 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
6959 // HeapReference<Object> ref = *src; // Original reference load.
6960 // bool is_gray = (rb_state == ReadBarrier::GrayState());
6961 // if (is_gray) {
6962 // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path.
6963 // }
6964 //
6965 // Note: the original implementation in ReadBarrier::Barrier is
6966 // slightly more complex as it performs additional checks that we do
6967 // not do here for performance reasons.
6968
6969 Register ref_reg = ref.AsRegister<Register>();
6970 Register temp_reg = temp.AsRegister<Register>();
6971 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
6972
6973 // /* int32_t */ monitor = obj->monitor_
6974 __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset);
6975 if (needs_null_check) {
6976 MaybeRecordImplicitNullCheck(instruction);
6977 }
6978 // /* LockWord */ lock_word = LockWord(monitor)
6979 static_assert(sizeof(LockWord) == sizeof(int32_t),
6980 "art::LockWord and int32_t have different sizes.");
6981
6982 __ Sync(0); // Barrier to prevent load-load reordering.
6983
6984 // The actual reference load.
6985 if (index.IsValid()) {
6986 // Load types involving an "index": ArrayGet,
6987 // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject
6988 // intrinsics.
6989 // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor))
6990 if (index.IsConstant()) {
6991 size_t computed_offset =
6992 (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset;
6993 __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset);
6994 } else {
6995 // Handle the special case of the
6996 // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject
6997 // intrinsics, which use a register pair as index ("long
6998 // offset"), of which only the low part contains data.
6999 Register index_reg = index.IsRegisterPair()
7000 ? index.AsRegisterPairLow<Register>()
7001 : index.AsRegister<Register>();
Chris Larsencd0295d2017-03-31 15:26:54 -07007002 __ ShiftAndAdd(TMP, index_reg, obj, scale_factor, TMP);
Alexey Frunze15958152017-02-09 19:08:30 -08007003 __ LoadFromOffset(kLoadWord, ref_reg, TMP, offset);
7004 }
7005 } else {
7006 // /* HeapReference<Object> */ ref = *(obj + offset)
7007 __ LoadFromOffset(kLoadWord, ref_reg, obj, offset);
7008 }
7009
7010 // Object* ref = ref_addr->AsMirrorPtr()
7011 __ MaybeUnpoisonHeapReference(ref_reg);
7012
7013 // Slow path marking the object `ref` when it is gray.
7014 SlowPathCodeMIPS* slow_path;
7015 if (always_update_field) {
7016 // ReadBarrierMarkAndUpdateFieldSlowPathMIPS only supports address
7017 // of the form `obj + field_offset`, where `obj` is a register and
7018 // `field_offset` is a register pair (of which only the lower half
7019 // is used). Thus `offset` and `scale_factor` above are expected
7020 // to be null in this code path.
7021 DCHECK_EQ(offset, 0u);
7022 DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1);
Vladimir Markoca6fff82017-10-03 14:49:14 +01007023 slow_path = new (GetGraph()->GetAllocator())
Alexey Frunze15958152017-02-09 19:08:30 -08007024 ReadBarrierMarkAndUpdateFieldSlowPathMIPS(instruction,
7025 ref,
7026 obj,
7027 /* field_offset */ index,
7028 temp_reg);
7029 } else {
Vladimir Markoca6fff82017-10-03 14:49:14 +01007030 slow_path = new (GetGraph()->GetAllocator()) ReadBarrierMarkSlowPathMIPS(instruction, ref);
Alexey Frunze15958152017-02-09 19:08:30 -08007031 }
7032 AddSlowPath(slow_path);
7033
7034 // if (rb_state == ReadBarrier::GrayState())
7035 // ref = ReadBarrier::Mark(ref);
7036 // Given the numeric representation, it's enough to check the low bit of the
7037 // rb_state. We do that by shifting the bit into the sign bit (31) and
7038 // performing a branch on less than zero.
7039 static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0");
7040 static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1");
7041 static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size");
7042 __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift);
7043 __ Bltz(temp_reg, slow_path->GetEntryLabel());
7044 __ Bind(slow_path->GetExitLabel());
7045}
7046
7047void CodeGeneratorMIPS::GenerateReadBarrierSlow(HInstruction* instruction,
7048 Location out,
7049 Location ref,
7050 Location obj,
7051 uint32_t offset,
7052 Location index) {
7053 DCHECK(kEmitCompilerReadBarrier);
7054
7055 // Insert a slow path based read barrier *after* the reference load.
7056 //
7057 // If heap poisoning is enabled, the unpoisoning of the loaded
7058 // reference will be carried out by the runtime within the slow
7059 // path.
7060 //
7061 // Note that `ref` currently does not get unpoisoned (when heap
7062 // poisoning is enabled), which is alright as the `ref` argument is
7063 // not used by the artReadBarrierSlow entry point.
7064 //
7065 // TODO: Unpoison `ref` when it is used by artReadBarrierSlow.
Vladimir Markoca6fff82017-10-03 14:49:14 +01007066 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetAllocator())
Alexey Frunze15958152017-02-09 19:08:30 -08007067 ReadBarrierForHeapReferenceSlowPathMIPS(instruction, out, ref, obj, offset, index);
7068 AddSlowPath(slow_path);
7069
7070 __ B(slow_path->GetEntryLabel());
7071 __ Bind(slow_path->GetExitLabel());
7072}
7073
7074void CodeGeneratorMIPS::MaybeGenerateReadBarrierSlow(HInstruction* instruction,
7075 Location out,
7076 Location ref,
7077 Location obj,
7078 uint32_t offset,
7079 Location index) {
7080 if (kEmitCompilerReadBarrier) {
7081 // Baker's read barriers shall be handled by the fast path
7082 // (CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier).
7083 DCHECK(!kUseBakerReadBarrier);
7084 // If heap poisoning is enabled, unpoisoning will be taken care of
7085 // by the runtime within the slow path.
7086 GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index);
7087 } else if (kPoisonHeapReferences) {
7088 __ UnpoisonHeapReference(out.AsRegister<Register>());
7089 }
7090}
7091
7092void CodeGeneratorMIPS::GenerateReadBarrierForRootSlow(HInstruction* instruction,
7093 Location out,
7094 Location root) {
7095 DCHECK(kEmitCompilerReadBarrier);
7096
7097 // Insert a slow path based read barrier *after* the GC root load.
7098 //
7099 // Note that GC roots are not affected by heap poisoning, so we do
7100 // not need to do anything special for this here.
7101 SlowPathCodeMIPS* slow_path =
Vladimir Markoca6fff82017-10-03 14:49:14 +01007102 new (GetGraph()->GetAllocator()) ReadBarrierForRootSlowPathMIPS(instruction, out, root);
Alexey Frunze15958152017-02-09 19:08:30 -08007103 AddSlowPath(slow_path);
7104
7105 __ B(slow_path->GetEntryLabel());
7106 __ Bind(slow_path->GetExitLabel());
7107}
7108
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007109void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007110 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
7111 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexey Frunzec61c0762017-04-10 13:54:23 -07007112 bool baker_read_barrier_slow_path = false;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007113 switch (type_check_kind) {
7114 case TypeCheckKind::kExactCheck:
7115 case TypeCheckKind::kAbstractClassCheck:
7116 case TypeCheckKind::kClassHierarchyCheck:
7117 case TypeCheckKind::kArrayObjectCheck:
Alexey Frunze15958152017-02-09 19:08:30 -08007118 call_kind =
7119 kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall;
Alexey Frunzec61c0762017-04-10 13:54:23 -07007120 baker_read_barrier_slow_path = kUseBakerReadBarrier;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007121 break;
7122 case TypeCheckKind::kArrayCheck:
7123 case TypeCheckKind::kUnresolvedCheck:
7124 case TypeCheckKind::kInterfaceCheck:
7125 call_kind = LocationSummary::kCallOnSlowPath;
7126 break;
7127 }
7128
Vladimir Markoca6fff82017-10-03 14:49:14 +01007129 LocationSummary* locations =
7130 new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind);
Alexey Frunzec61c0762017-04-10 13:54:23 -07007131 if (baker_read_barrier_slow_path) {
7132 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
7133 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007134 locations->SetInAt(0, Location::RequiresRegister());
7135 locations->SetInAt(1, Location::RequiresRegister());
7136 // The output does overlap inputs.
7137 // Note that TypeCheckSlowPathMIPS uses this register too.
7138 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexey Frunze15958152017-02-09 19:08:30 -08007139 locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007140}
7141
7142void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) {
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007143 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007144 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze15958152017-02-09 19:08:30 -08007145 Location obj_loc = locations->InAt(0);
7146 Register obj = obj_loc.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007147 Register cls = locations->InAt(1).AsRegister<Register>();
Alexey Frunze15958152017-02-09 19:08:30 -08007148 Location out_loc = locations->Out();
7149 Register out = out_loc.AsRegister<Register>();
7150 const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind);
7151 DCHECK_LE(num_temps, 1u);
7152 Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation();
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007153 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
7154 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
7155 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
7156 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007157 MipsLabel done;
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007158 SlowPathCodeMIPS* slow_path = nullptr;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007159
7160 // Return 0 if `obj` is null.
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007161 // Avoid this check if we know `obj` is not null.
7162 if (instruction->MustDoNullCheck()) {
7163 __ Move(out, ZERO);
7164 __ Beqz(obj, &done);
7165 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007166
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007167 switch (type_check_kind) {
7168 case TypeCheckKind::kExactCheck: {
7169 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08007170 GenerateReferenceLoadTwoRegisters(instruction,
7171 out_loc,
7172 obj_loc,
7173 class_offset,
7174 maybe_temp_loc,
7175 kCompilerReadBarrierOption);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007176 // Classes must be equal for the instanceof to succeed.
7177 __ Xor(out, out, cls);
7178 __ Sltiu(out, out, 1);
7179 break;
7180 }
7181
7182 case TypeCheckKind::kAbstractClassCheck: {
7183 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08007184 GenerateReferenceLoadTwoRegisters(instruction,
7185 out_loc,
7186 obj_loc,
7187 class_offset,
7188 maybe_temp_loc,
7189 kCompilerReadBarrierOption);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007190 // If the class is abstract, we eagerly fetch the super class of the
7191 // object to avoid doing a comparison we know will fail.
7192 MipsLabel loop;
7193 __ Bind(&loop);
7194 // /* HeapReference<Class> */ out = out->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08007195 GenerateReferenceLoadOneRegister(instruction,
7196 out_loc,
7197 super_offset,
7198 maybe_temp_loc,
7199 kCompilerReadBarrierOption);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007200 // If `out` is null, we use it for the result, and jump to `done`.
7201 __ Beqz(out, &done);
7202 __ Bne(out, cls, &loop);
7203 __ LoadConst32(out, 1);
7204 break;
7205 }
7206
7207 case TypeCheckKind::kClassHierarchyCheck: {
7208 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08007209 GenerateReferenceLoadTwoRegisters(instruction,
7210 out_loc,
7211 obj_loc,
7212 class_offset,
7213 maybe_temp_loc,
7214 kCompilerReadBarrierOption);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007215 // Walk over the class hierarchy to find a match.
7216 MipsLabel loop, success;
7217 __ Bind(&loop);
7218 __ Beq(out, cls, &success);
7219 // /* HeapReference<Class> */ out = out->super_class_
Alexey Frunze15958152017-02-09 19:08:30 -08007220 GenerateReferenceLoadOneRegister(instruction,
7221 out_loc,
7222 super_offset,
7223 maybe_temp_loc,
7224 kCompilerReadBarrierOption);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007225 __ Bnez(out, &loop);
7226 // If `out` is null, we use it for the result, and jump to `done`.
7227 __ B(&done);
7228 __ Bind(&success);
7229 __ LoadConst32(out, 1);
7230 break;
7231 }
7232
7233 case TypeCheckKind::kArrayObjectCheck: {
7234 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08007235 GenerateReferenceLoadTwoRegisters(instruction,
7236 out_loc,
7237 obj_loc,
7238 class_offset,
7239 maybe_temp_loc,
7240 kCompilerReadBarrierOption);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007241 // Do an exact check.
7242 MipsLabel success;
7243 __ Beq(out, cls, &success);
7244 // Otherwise, we need to check that the object's class is a non-primitive array.
7245 // /* HeapReference<Class> */ out = out->component_type_
Alexey Frunze15958152017-02-09 19:08:30 -08007246 GenerateReferenceLoadOneRegister(instruction,
7247 out_loc,
7248 component_offset,
7249 maybe_temp_loc,
7250 kCompilerReadBarrierOption);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007251 // If `out` is null, we use it for the result, and jump to `done`.
7252 __ Beqz(out, &done);
7253 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
7254 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
7255 __ Sltiu(out, out, 1);
7256 __ B(&done);
7257 __ Bind(&success);
7258 __ LoadConst32(out, 1);
7259 break;
7260 }
7261
7262 case TypeCheckKind::kArrayCheck: {
7263 // No read barrier since the slow path will retry upon failure.
7264 // /* HeapReference<Class> */ out = obj->klass_
Alexey Frunze15958152017-02-09 19:08:30 -08007265 GenerateReferenceLoadTwoRegisters(instruction,
7266 out_loc,
7267 obj_loc,
7268 class_offset,
7269 maybe_temp_loc,
7270 kWithoutReadBarrier);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007271 DCHECK(locations->OnlyCallsOnSlowPath());
Vladimir Markoca6fff82017-10-03 14:49:14 +01007272 slow_path = new (GetGraph()->GetAllocator()) TypeCheckSlowPathMIPS(instruction,
7273 /* is_fatal */ false);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007274 codegen_->AddSlowPath(slow_path);
7275 __ Bne(out, cls, slow_path->GetEntryLabel());
7276 __ LoadConst32(out, 1);
7277 break;
7278 }
7279
7280 case TypeCheckKind::kUnresolvedCheck:
7281 case TypeCheckKind::kInterfaceCheck: {
7282 // Note that we indeed only call on slow path, but we always go
7283 // into the slow path for the unresolved and interface check
7284 // cases.
7285 //
7286 // We cannot directly call the InstanceofNonTrivial runtime
7287 // entry point without resorting to a type checking slow path
7288 // here (i.e. by calling InvokeRuntime directly), as it would
7289 // require to assign fixed registers for the inputs of this
7290 // HInstanceOf instruction (following the runtime calling
7291 // convention), which might be cluttered by the potential first
7292 // read barrier emission at the beginning of this method.
7293 //
7294 // TODO: Introduce a new runtime entry point taking the object
7295 // to test (instead of its class) as argument, and let it deal
7296 // with the read barrier issues. This will let us refactor this
7297 // case of the `switch` code as it was previously (with a direct
7298 // call to the runtime not using a type checking slow path).
7299 // This should also be beneficial for the other cases above.
7300 DCHECK(locations->OnlyCallsOnSlowPath());
Vladimir Markoca6fff82017-10-03 14:49:14 +01007301 slow_path = new (GetGraph()->GetAllocator()) TypeCheckSlowPathMIPS(instruction,
7302 /* is_fatal */ false);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007303 codegen_->AddSlowPath(slow_path);
7304 __ B(slow_path->GetEntryLabel());
7305 break;
7306 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007307 }
7308
7309 __ Bind(&done);
Alexey Frunze66b69ad2017-02-24 00:51:44 -08007310
7311 if (slow_path != nullptr) {
7312 __ Bind(slow_path->GetExitLabel());
7313 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007314}
7315
7316void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01007317 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007318 locations->SetOut(Location::ConstantLocation(constant));
7319}
7320
7321void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
7322 // Will be generated at use site.
7323}
7324
7325void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01007326 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007327 locations->SetOut(Location::ConstantLocation(constant));
7328}
7329
7330void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
7331 // Will be generated at use site.
7332}
7333
7334void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) {
7335 InvokeDexCallingConventionVisitorMIPS calling_convention_visitor;
7336 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
7337}
7338
7339void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
7340 HandleInvoke(invoke);
Alexey Frunze1b8464d2016-11-12 17:22:05 -08007341 // The register T7 is required to be used for the hidden argument in
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007342 // art_quick_imt_conflict_trampoline, so add the hidden argument.
Alexey Frunze1b8464d2016-11-12 17:22:05 -08007343 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T7));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007344}
7345
7346void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
7347 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
7348 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007349 Location receiver = invoke->GetLocations()->InAt(0);
7350 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07007351 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007352
7353 // Set the hidden argument.
7354 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
7355 invoke->GetDexMethodIndex());
7356
7357 // temp = object->GetClass();
7358 if (receiver.IsStackSlot()) {
7359 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
7360 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
7361 } else {
7362 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
7363 }
7364 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexey Frunzec061de12017-02-14 13:27:23 -08007365 // Instead of simply (possibly) unpoisoning `temp` here, we should
7366 // emit a read barrier for the previous class reference load.
7367 // However this is not required in practice, as this is an
7368 // intermediate/temporary reference and because the current
7369 // concurrent copying collector keeps the from-space memory
7370 // intact/accessible until the end of the marking phase (the
7371 // concurrent copying collector may not in the future).
7372 __ MaybeUnpoisonHeapReference(temp);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00007373 __ LoadFromOffset(kLoadWord, temp, temp,
7374 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
7375 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00007376 invoke->GetImtIndex(), kMipsPointerSize));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007377 // temp = temp->GetImtEntryAt(method_offset);
7378 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
7379 // T9 = temp->GetEntryPoint();
7380 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
7381 // T9();
7382 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07007383 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007384 DCHECK(!codegen_->IsLeafMethod());
7385 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
7386}
7387
7388void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen701566a2015-10-27 15:29:13 -07007389 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
7390 if (intrinsic.TryDispatch(invoke)) {
7391 return;
7392 }
7393
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007394 HandleInvoke(invoke);
7395}
7396
7397void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00007398 // Explicit clinit checks triggered by static invokes must have been pruned by
7399 // art::PrepareForRegisterAllocation.
7400 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007401
Alexey Frunze6b892cd2017-01-03 17:11:38 -08007402 bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007403 bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops();
7404 bool has_extra_input = invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007405
Chris Larsen701566a2015-10-27 15:29:13 -07007406 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
7407 if (intrinsic.TryDispatch(invoke)) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007408 if (invoke->GetLocations()->CanCall() && has_extra_input) {
7409 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
7410 }
Chris Larsen701566a2015-10-27 15:29:13 -07007411 return;
7412 }
7413
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007414 HandleInvoke(invoke);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007415
7416 // Add the extra input register if either the dex cache array base register
7417 // or the PC-relative base register for accessing literals is needed.
7418 if (has_extra_input) {
7419 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
7420 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007421}
7422
Orion Hodsonac141392017-01-13 11:53:47 +00007423void LocationsBuilderMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
7424 HandleInvoke(invoke);
7425}
7426
7427void InstructionCodeGeneratorMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
7428 codegen_->GenerateInvokePolymorphicCall(invoke);
7429}
7430
Chris Larsen701566a2015-10-27 15:29:13 -07007431static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007432 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen701566a2015-10-27 15:29:13 -07007433 IntrinsicCodeGeneratorMIPS intrinsic(codegen);
7434 intrinsic.Dispatch(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007435 return true;
7436 }
7437 return false;
7438}
7439
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007440HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind(
Alexey Frunze06a46c42016-07-19 15:00:40 -07007441 HLoadString::LoadKind desired_string_load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007442 switch (desired_string_load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007443 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01007444 case HLoadString::LoadKind::kBootImageInternTable:
Vladimir Markoaad75c62016-10-03 08:46:48 +00007445 case HLoadString::LoadKind::kBssEntry:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007446 DCHECK(!Runtime::Current()->UseJitCompilation());
Alexey Frunze06a46c42016-07-19 15:00:40 -07007447 break;
Nicolas Geoffray132d8362016-11-16 09:19:42 +00007448 case HLoadString::LoadKind::kJitTableAddress:
7449 DCHECK(Runtime::Current()->UseJitCompilation());
Nicolas Geoffray132d8362016-11-16 09:19:42 +00007450 break;
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007451 case HLoadString::LoadKind::kBootImageAddress:
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007452 case HLoadString::LoadKind::kRuntimeCall:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007453 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007454 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007455 return desired_string_load_kind;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007456}
7457
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01007458HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind(
7459 HLoadClass::LoadKind desired_class_load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007460 switch (desired_class_load_kind) {
Nicolas Geoffray83c8e272017-01-31 14:36:37 +00007461 case HLoadClass::LoadKind::kInvalid:
7462 LOG(FATAL) << "UNREACHABLE";
7463 UNREACHABLE();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007464 case HLoadClass::LoadKind::kReferrersClass:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007465 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007466 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko94ec2db2017-09-06 17:21:03 +01007467 case HLoadClass::LoadKind::kBootImageClassTable:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007468 case HLoadClass::LoadKind::kBssEntry:
7469 DCHECK(!Runtime::Current()->UseJitCompilation());
7470 break;
Nicolas Geoffray22384ae2016-12-12 22:33:36 +00007471 case HLoadClass::LoadKind::kJitTableAddress:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007472 DCHECK(Runtime::Current()->UseJitCompilation());
Alexey Frunze06a46c42016-07-19 15:00:40 -07007473 break;
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007474 case HLoadClass::LoadKind::kBootImageAddress:
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007475 case HLoadClass::LoadKind::kRuntimeCall:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007476 break;
7477 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007478 return desired_class_load_kind;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01007479}
7480
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007481Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
7482 Register temp) {
Alexey Frunze6b892cd2017-01-03 17:11:38 -08007483 CHECK(!GetInstructionSetFeatures().IsR6());
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007484 CHECK(!GetGraph()->HasIrreducibleLoops());
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007485 CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
7486 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
7487 if (!invoke->GetLocations()->Intrinsified()) {
7488 return location.AsRegister<Register>();
7489 }
7490 // For intrinsics we allow any location, so it may be on the stack.
7491 if (!location.IsRegister()) {
7492 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
7493 return temp;
7494 }
7495 // For register locations, check if the register was saved. If so, get it from the stack.
7496 // Note: There is a chance that the register was saved but not overwritten, so we could
7497 // save one load. However, since this is just an intrinsic slow path we prefer this
7498 // simple and more robust approach rather that trying to determine if that's the case.
7499 SlowPathCode* slow_path = GetCurrentSlowPath();
7500 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
7501 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
7502 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
7503 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
7504 return temp;
7505 }
7506 return location.AsRegister<Register>();
7507}
7508
Vladimir Markodc151b22015-10-15 18:02:30 +01007509HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch(
7510 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +01007511 HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) {
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007512 return desired_dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01007513}
7514
Vladimir Markoe7197bf2017-06-02 17:00:23 +01007515void CodeGeneratorMIPS::GenerateStaticOrDirectCall(
7516 HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007517 // All registers are assumed to be correctly set up per the calling convention.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007518 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007519 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
7520 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
Alexey Frunze6b892cd2017-01-03 17:11:38 -08007521 bool is_r6 = GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007522 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
7523 Register base_reg = (invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops)
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007524 ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>())
7525 : ZERO;
7526
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007527 switch (method_load_kind) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01007528 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007529 // temp = thread->string_init_entrypoint
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01007530 uint32_t offset =
7531 GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007532 __ LoadFromOffset(kLoadWord,
7533 temp.AsRegister<Register>(),
7534 TR,
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01007535 offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007536 break;
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01007537 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007538 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00007539 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007540 break;
Vladimir Marko65979462017-05-19 17:25:12 +01007541 case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: {
7542 DCHECK(GetCompilerOptions().IsBootImage());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007543 PcRelativePatchInfo* info_high = NewPcRelativeMethodPatch(invoke->GetTargetMethod());
7544 PcRelativePatchInfo* info_low =
7545 NewPcRelativeMethodPatch(invoke->GetTargetMethod(), info_high);
Vladimir Marko65979462017-05-19 17:25:12 +01007546 Register temp_reg = temp.AsRegister<Register>();
Alexey Frunzea663d9d2017-07-31 18:43:18 -07007547 EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg);
7548 __ Addiu(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label);
Vladimir Marko65979462017-05-19 17:25:12 +01007549 break;
7550 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007551 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
7552 __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress());
7553 break;
Vladimir Marko0eb882b2017-05-15 13:39:18 +01007554 case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007555 PcRelativePatchInfo* info_high = NewMethodBssEntryPatch(
Vladimir Marko0eb882b2017-05-15 13:39:18 +01007556 MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()));
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007557 PcRelativePatchInfo* info_low = NewMethodBssEntryPatch(
7558 MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high);
Vladimir Marko0eb882b2017-05-15 13:39:18 +01007559 Register temp_reg = temp.AsRegister<Register>();
Alexey Frunzea663d9d2017-07-31 18:43:18 -07007560 EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg);
7561 __ Lw(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007562 break;
Vladimir Marko0eb882b2017-05-15 13:39:18 +01007563 }
Vladimir Markoe7197bf2017-06-02 17:00:23 +01007564 case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: {
7565 GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path);
7566 return; // No code pointer retrieval; the runtime performs the call directly.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007567 }
7568 }
7569
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007570 switch (code_ptr_location) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007571 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07007572 __ Bal(&frame_entry_label_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007573 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007574 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
7575 // T9 = callee_method->entry_point_from_quick_compiled_code_;
Goran Jakovljevic1a878372015-10-26 14:28:52 +01007576 __ LoadFromOffset(kLoadWord,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007577 T9,
7578 callee_method.AsRegister<Register>(),
7579 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07007580 kMipsPointerSize).Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007581 // T9()
7582 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07007583 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007584 break;
7585 }
Vladimir Markoe7197bf2017-06-02 17:00:23 +01007586 RecordPcInfo(invoke, invoke->GetDexPc(), slow_path);
7587
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007588 DCHECK(!IsLeafMethod());
7589}
7590
7591void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00007592 // Explicit clinit checks triggered by static invokes must have been pruned by
7593 // art::PrepareForRegisterAllocation.
7594 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007595
7596 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
7597 return;
7598 }
7599
7600 LocationSummary* locations = invoke->GetLocations();
7601 codegen_->GenerateStaticOrDirectCall(invoke,
7602 locations->HasTemps()
7603 ? locations->GetTemp(0)
7604 : Location::NoLocation());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007605}
7606
Vladimir Markoe7197bf2017-06-02 17:00:23 +01007607void CodeGeneratorMIPS::GenerateVirtualCall(
7608 HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) {
Goran Jakovljevice919b072016-10-04 10:17:34 +02007609 // Use the calling convention instead of the location of the receiver, as
7610 // intrinsics may have put the receiver in a different register. In the intrinsics
7611 // slow path, the arguments have been moved to the right place, so here we are
7612 // guaranteed that the receiver is the first register of the calling convention.
7613 InvokeDexCallingConvention calling_convention;
7614 Register receiver = calling_convention.GetRegisterAt(0);
7615
Chris Larsen3acee732015-11-18 13:31:08 -08007616 Register temp = temp_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007617 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
7618 invoke->GetVTableIndex(), kMipsPointerSize).SizeValue();
7619 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07007620 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007621
7622 // temp = object->GetClass();
Goran Jakovljevice919b072016-10-04 10:17:34 +02007623 __ LoadFromOffset(kLoadWord, temp, receiver, class_offset);
Chris Larsen3acee732015-11-18 13:31:08 -08007624 MaybeRecordImplicitNullCheck(invoke);
Alexey Frunzec061de12017-02-14 13:27:23 -08007625 // Instead of simply (possibly) unpoisoning `temp` here, we should
7626 // emit a read barrier for the previous class reference load.
7627 // However this is not required in practice, as this is an
7628 // intermediate/temporary reference and because the current
7629 // concurrent copying collector keeps the from-space memory
7630 // intact/accessible until the end of the marking phase (the
7631 // concurrent copying collector may not in the future).
7632 __ MaybeUnpoisonHeapReference(temp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007633 // temp = temp->GetMethodAt(method_offset);
7634 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
7635 // T9 = temp->GetEntryPoint();
7636 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
7637 // T9();
7638 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07007639 __ NopIfNoReordering();
Vladimir Markoe7197bf2017-06-02 17:00:23 +01007640 RecordPcInfo(invoke, invoke->GetDexPc(), slow_path);
Chris Larsen3acee732015-11-18 13:31:08 -08007641}
7642
7643void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
7644 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
7645 return;
7646 }
7647
7648 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007649 DCHECK(!codegen_->IsLeafMethod());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007650}
7651
7652void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) {
Vladimir Marko41559982017-01-06 14:04:23 +00007653 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007654 if (load_kind == HLoadClass::LoadKind::kRuntimeCall) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007655 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07007656 Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0));
7657 CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc);
Alexey Frunze06a46c42016-07-19 15:00:40 -07007658 return;
7659 }
Vladimir Marko41559982017-01-06 14:04:23 +00007660 DCHECK(!cls->NeedsAccessCheck());
Alexey Frunzec61c0762017-04-10 13:54:23 -07007661 const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007662 const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops();
Alexey Frunze15958152017-02-09 19:08:30 -08007663 const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage();
7664 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier)
Alexey Frunze06a46c42016-07-19 15:00:40 -07007665 ? LocationSummary::kCallOnSlowPath
7666 : LocationSummary::kNoCall;
Vladimir Markoca6fff82017-10-03 14:49:14 +01007667 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind);
Alexey Frunzec61c0762017-04-10 13:54:23 -07007668 if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) {
7669 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
7670 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007671 switch (load_kind) {
7672 // We need an extra register for PC-relative literals on R2.
Alexey Frunze06a46c42016-07-19 15:00:40 -07007673 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007674 case HLoadClass::LoadKind::kBootImageAddress:
Vladimir Marko94ec2db2017-09-06 17:21:03 +01007675 case HLoadClass::LoadKind::kBootImageClassTable:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007676 case HLoadClass::LoadKind::kBssEntry:
Alexey Frunzec61c0762017-04-10 13:54:23 -07007677 if (isR6) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007678 break;
7679 }
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007680 if (has_irreducible_loops) {
7681 codegen_->ClobberRA();
7682 break;
7683 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007684 FALLTHROUGH_INTENDED;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007685 case HLoadClass::LoadKind::kReferrersClass:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007686 locations->SetInAt(0, Location::RequiresRegister());
7687 break;
7688 default:
7689 break;
7690 }
7691 locations->SetOut(Location::RequiresRegister());
Alexey Frunzec61c0762017-04-10 13:54:23 -07007692 if (load_kind == HLoadClass::LoadKind::kBssEntry) {
7693 if (!kUseReadBarrier || kUseBakerReadBarrier) {
7694 // Rely on the type resolution or initialization and marking to save everything we need.
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007695 // Request a temp to hold the BSS entry location for the slow path.
7696 locations->AddTemp(Location::RequiresRegister());
Alexey Frunzec61c0762017-04-10 13:54:23 -07007697 RegisterSet caller_saves = RegisterSet::Empty();
7698 InvokeRuntimeCallingConvention calling_convention;
7699 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
7700 locations->SetCustomSlowPathCallerSaves(caller_saves);
7701 } else {
7702 // For non-Baker read barriers we have a temp-clobbering call.
7703 }
7704 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007705}
7706
Nicolas Geoffray5247c082017-01-13 14:17:29 +00007707// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
7708// move.
7709void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS {
Vladimir Marko41559982017-01-06 14:04:23 +00007710 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007711 if (load_kind == HLoadClass::LoadKind::kRuntimeCall) {
Vladimir Marko41559982017-01-06 14:04:23 +00007712 codegen_->GenerateLoadClassRuntimeCall(cls);
Pavle Batutae87a7182015-10-28 13:10:42 +01007713 return;
7714 }
Vladimir Marko41559982017-01-06 14:04:23 +00007715 DCHECK(!cls->NeedsAccessCheck());
Pavle Batutae87a7182015-10-28 13:10:42 +01007716
Vladimir Marko41559982017-01-06 14:04:23 +00007717 LocationSummary* locations = cls->GetLocations();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007718 Location out_loc = locations->Out();
7719 Register out = out_loc.AsRegister<Register>();
7720 Register base_or_current_method_reg;
7721 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007722 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007723 switch (load_kind) {
7724 // We need an extra register for PC-relative literals on R2.
Alexey Frunze06a46c42016-07-19 15:00:40 -07007725 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007726 case HLoadClass::LoadKind::kBootImageAddress:
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007727 case HLoadClass::LoadKind::kBootImageClassTable:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007728 case HLoadClass::LoadKind::kBssEntry:
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007729 base_or_current_method_reg =
7730 (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007731 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007732 case HLoadClass::LoadKind::kReferrersClass:
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007733 case HLoadClass::LoadKind::kRuntimeCall:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007734 base_or_current_method_reg = locations->InAt(0).AsRegister<Register>();
7735 break;
7736 default:
7737 base_or_current_method_reg = ZERO;
7738 break;
7739 }
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00007740
Alexey Frunze15958152017-02-09 19:08:30 -08007741 const ReadBarrierOption read_barrier_option = cls->IsInBootImage()
7742 ? kWithoutReadBarrier
7743 : kCompilerReadBarrierOption;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007744 bool generate_null_check = false;
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007745 CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high = nullptr;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007746 switch (load_kind) {
7747 case HLoadClass::LoadKind::kReferrersClass: {
7748 DCHECK(!cls->CanCallRuntime());
7749 DCHECK(!cls->MustGenerateClinitCheck());
7750 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
7751 GenerateGcRootFieldLoad(cls,
7752 out_loc,
7753 base_or_current_method_reg,
Alexey Frunze15958152017-02-09 19:08:30 -08007754 ArtMethod::DeclaringClassOffset().Int32Value(),
7755 read_barrier_option);
Alexey Frunze06a46c42016-07-19 15:00:40 -07007756 break;
7757 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007758 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007759 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze15958152017-02-09 19:08:30 -08007760 DCHECK_EQ(read_barrier_option, kWithoutReadBarrier);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007761 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
Alexey Frunze06a46c42016-07-19 15:00:40 -07007762 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007763 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
7764 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007765 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high,
7766 out,
Alexey Frunzea663d9d2017-07-31 18:43:18 -07007767 base_or_current_method_reg);
7768 __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label);
Alexey Frunze06a46c42016-07-19 15:00:40 -07007769 break;
7770 }
7771 case HLoadClass::LoadKind::kBootImageAddress: {
Alexey Frunze15958152017-02-09 19:08:30 -08007772 DCHECK_EQ(read_barrier_option, kWithoutReadBarrier);
Nicolas Geoffray5247c082017-01-13 14:17:29 +00007773 uint32_t address = dchecked_integral_cast<uint32_t>(
7774 reinterpret_cast<uintptr_t>(cls->GetClass().Get()));
7775 DCHECK_NE(address, 0u);
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007776 if (isR6 || !has_irreducible_loops) {
7777 __ LoadLiteral(out,
7778 base_or_current_method_reg,
7779 codegen_->DeduplicateBootImageAddressLiteral(address));
7780 } else {
7781 __ LoadConst32(out, address);
7782 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007783 break;
7784 }
Vladimir Marko94ec2db2017-09-06 17:21:03 +01007785 case HLoadClass::LoadKind::kBootImageClassTable: {
7786 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
7787 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
7788 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
7789 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
7790 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high);
7791 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high,
7792 out,
7793 base_or_current_method_reg);
7794 __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label);
7795 // Extract the reference from the slot data, i.e. clear the hash bits.
7796 int32_t masked_hash = ClassTable::TableSlot::MaskHash(
7797 ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex())));
7798 if (masked_hash != 0) {
7799 __ Addiu(out, out, -masked_hash);
7800 }
7801 break;
7802 }
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007803 case HLoadClass::LoadKind::kBssEntry: {
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007804 bss_info_high = codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex());
7805 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
7806 codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high);
Alexey Frunzec61c0762017-04-10 13:54:23 -07007807 constexpr bool non_baker_read_barrier = kUseReadBarrier && !kUseBakerReadBarrier;
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007808 Register temp = non_baker_read_barrier ? out : locations->GetTemp(0).AsRegister<Register>();
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007809 codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high,
7810 temp,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007811 base_or_current_method_reg);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007812 GenerateGcRootFieldLoad(cls,
7813 out_loc,
7814 temp,
7815 /* placeholder */ 0x5678,
7816 read_barrier_option,
7817 &info_low->label);
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007818 generate_null_check = true;
7819 break;
7820 }
Nicolas Geoffray22384ae2016-12-12 22:33:36 +00007821 case HLoadClass::LoadKind::kJitTableAddress: {
Alexey Frunze627c1a02017-01-30 19:28:14 -08007822 CodeGeneratorMIPS::JitPatchInfo* info = codegen_->NewJitRootClassPatch(cls->GetDexFile(),
7823 cls->GetTypeIndex(),
7824 cls->GetClass());
7825 bool reordering = __ SetReorder(false);
7826 __ Bind(&info->high_label);
7827 __ Lui(out, /* placeholder */ 0x1234);
Alexey Frunze627c1a02017-01-30 19:28:14 -08007828 __ SetReorder(reordering);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07007829 GenerateGcRootFieldLoad(cls,
7830 out_loc,
7831 out,
7832 /* placeholder */ 0x5678,
7833 read_barrier_option,
7834 &info->low_label);
Alexey Frunze06a46c42016-07-19 15:00:40 -07007835 break;
7836 }
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007837 case HLoadClass::LoadKind::kRuntimeCall:
Nicolas Geoffray83c8e272017-01-31 14:36:37 +00007838 case HLoadClass::LoadKind::kInvalid:
Vladimir Marko41559982017-01-06 14:04:23 +00007839 LOG(FATAL) << "UNREACHABLE";
7840 UNREACHABLE();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007841 }
7842
7843 if (generate_null_check || cls->MustGenerateClinitCheck()) {
7844 DCHECK(cls->CanCallRuntime());
Vladimir Markoca6fff82017-10-03 14:49:14 +01007845 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetAllocator()) LoadClassSlowPathMIPS(
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007846 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck(), bss_info_high);
Alexey Frunze06a46c42016-07-19 15:00:40 -07007847 codegen_->AddSlowPath(slow_path);
7848 if (generate_null_check) {
7849 __ Beqz(out, slow_path->GetEntryLabel());
7850 }
7851 if (cls->MustGenerateClinitCheck()) {
7852 GenerateClassInitializationCheck(slow_path, out);
7853 } else {
7854 __ Bind(slow_path->GetExitLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007855 }
7856 }
7857}
7858
7859static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07007860 return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007861}
7862
7863void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) {
7864 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01007865 new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007866 locations->SetOut(Location::RequiresRegister());
7867}
7868
7869void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) {
7870 Register out = load->GetLocations()->Out().AsRegister<Register>();
7871 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
7872}
7873
7874void LocationsBuilderMIPS::VisitClearException(HClearException* clear) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01007875 new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007876}
7877
7878void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
7879 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
7880}
7881
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007882void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08007883 LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load);
Vladimir Markoca6fff82017-10-03 14:49:14 +01007884 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind);
Alexey Frunze06a46c42016-07-19 15:00:40 -07007885 HLoadString::LoadKind load_kind = load->GetLoadKind();
Alexey Frunzec61c0762017-04-10 13:54:23 -07007886 const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007887 const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007888 switch (load_kind) {
7889 // We need an extra register for PC-relative literals on R2.
Alexey Frunze06a46c42016-07-19 15:00:40 -07007890 case HLoadString::LoadKind::kBootImageAddress:
7891 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01007892 case HLoadString::LoadKind::kBootImageInternTable:
Vladimir Markoaad75c62016-10-03 08:46:48 +00007893 case HLoadString::LoadKind::kBssEntry:
Alexey Frunzec61c0762017-04-10 13:54:23 -07007894 if (isR6) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007895 break;
7896 }
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007897 if (has_irreducible_loops) {
7898 codegen_->ClobberRA();
7899 break;
7900 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07007901 FALLTHROUGH_INTENDED;
7902 // We need an extra register for PC-relative dex cache accesses.
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007903 case HLoadString::LoadKind::kRuntimeCall:
Alexey Frunze06a46c42016-07-19 15:00:40 -07007904 locations->SetInAt(0, Location::RequiresRegister());
7905 break;
7906 default:
7907 break;
7908 }
Vladimir Marko847e6ce2017-06-02 13:55:07 +01007909 if (load_kind == HLoadString::LoadKind::kRuntimeCall) {
Alexey Frunzebb51df82016-11-01 16:07:32 -07007910 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07007911 locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Alexey Frunzebb51df82016-11-01 16:07:32 -07007912 } else {
7913 locations->SetOut(Location::RequiresRegister());
Alexey Frunzec61c0762017-04-10 13:54:23 -07007914 if (load_kind == HLoadString::LoadKind::kBssEntry) {
7915 if (!kUseReadBarrier || kUseBakerReadBarrier) {
7916 // Rely on the pResolveString and marking to save everything we need.
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007917 // Request a temp to hold the BSS entry location for the slow path.
7918 locations->AddTemp(Location::RequiresRegister());
Alexey Frunzec61c0762017-04-10 13:54:23 -07007919 RegisterSet caller_saves = RegisterSet::Empty();
7920 InvokeRuntimeCallingConvention calling_convention;
7921 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
7922 locations->SetCustomSlowPathCallerSaves(caller_saves);
7923 } else {
7924 // For non-Baker read barriers we have a temp-clobbering call.
7925 }
7926 }
Alexey Frunzebb51df82016-11-01 16:07:32 -07007927 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007928}
7929
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00007930// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
7931// move.
7932void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007933 HLoadString::LoadKind load_kind = load->GetLoadKind();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02007934 LocationSummary* locations = load->GetLocations();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007935 Location out_loc = locations->Out();
7936 Register out = out_loc.AsRegister<Register>();
7937 Register base_or_current_method_reg;
7938 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007939 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007940 switch (load_kind) {
7941 // We need an extra register for PC-relative literals on R2.
Alexey Frunze06a46c42016-07-19 15:00:40 -07007942 case HLoadString::LoadKind::kBootImageAddress:
7943 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01007944 case HLoadString::LoadKind::kBootImageInternTable:
Vladimir Markoaad75c62016-10-03 08:46:48 +00007945 case HLoadString::LoadKind::kBssEntry:
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007946 base_or_current_method_reg =
7947 (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>();
Alexey Frunze06a46c42016-07-19 15:00:40 -07007948 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007949 default:
7950 base_or_current_method_reg = ZERO;
7951 break;
7952 }
7953
7954 switch (load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07007955 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Markoaad75c62016-10-03 08:46:48 +00007956 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007957 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007958 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007959 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
7960 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007961 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high,
7962 out,
Alexey Frunzea663d9d2017-07-31 18:43:18 -07007963 base_or_current_method_reg);
7964 __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01007965 return;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007966 }
7967 case HLoadString::LoadKind::kBootImageAddress: {
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00007968 uint32_t address = dchecked_integral_cast<uint32_t>(
7969 reinterpret_cast<uintptr_t>(load->GetString().Get()));
7970 DCHECK_NE(address, 0u);
Goran Jakovljevicdebb5102017-09-21 14:24:06 +02007971 if (isR6 || !has_irreducible_loops) {
7972 __ LoadLiteral(out,
7973 base_or_current_method_reg,
7974 codegen_->DeduplicateBootImageAddressLiteral(address));
7975 } else {
7976 __ LoadConst32(out, address);
7977 }
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01007978 return;
Alexey Frunze06a46c42016-07-19 15:00:40 -07007979 }
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01007980 case HLoadString::LoadKind::kBootImageInternTable: {
Vladimir Markoaad75c62016-10-03 08:46:48 +00007981 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007982 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
Vladimir Marko6bec91c2017-01-09 15:03:12 +00007983 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007984 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
7985 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +01007986 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high,
7987 out,
7988 base_or_current_method_reg);
7989 __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label);
7990 return;
7991 }
7992 case HLoadString::LoadKind::kBssEntry: {
7993 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
7994 CodeGeneratorMIPS::PcRelativePatchInfo* info_high =
7995 codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex());
7996 CodeGeneratorMIPS::PcRelativePatchInfo* info_low =
7997 codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high);
Alexey Frunzec61c0762017-04-10 13:54:23 -07007998 constexpr bool non_baker_read_barrier = kUseReadBarrier && !kUseBakerReadBarrier;
Alexey Frunze5fa5c042017-06-01 21:07:52 -07007999 Register temp = non_baker_read_barrier ? out : locations->GetTemp(0).AsRegister<Register>();
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008000 codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high,
8001 temp,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008002 base_or_current_method_reg);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008003 GenerateGcRootFieldLoad(load,
8004 out_loc,
8005 temp,
8006 /* placeholder */ 0x5678,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008007 kCompilerReadBarrierOption,
8008 &info_low->label);
Alexey Frunze5fa5c042017-06-01 21:07:52 -07008009 SlowPathCodeMIPS* slow_path =
Vladimir Markoca6fff82017-10-03 14:49:14 +01008010 new (GetGraph()->GetAllocator()) LoadStringSlowPathMIPS(load, info_high);
Vladimir Markoaad75c62016-10-03 08:46:48 +00008011 codegen_->AddSlowPath(slow_path);
8012 __ Beqz(out, slow_path->GetEntryLabel());
8013 __ Bind(slow_path->GetExitLabel());
8014 return;
8015 }
Alexey Frunze627c1a02017-01-30 19:28:14 -08008016 case HLoadString::LoadKind::kJitTableAddress: {
8017 CodeGeneratorMIPS::JitPatchInfo* info =
8018 codegen_->NewJitRootStringPatch(load->GetDexFile(),
8019 load->GetStringIndex(),
8020 load->GetString());
8021 bool reordering = __ SetReorder(false);
8022 __ Bind(&info->high_label);
8023 __ Lui(out, /* placeholder */ 0x1234);
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008024 __ SetReorder(reordering);
Alexey Frunze15958152017-02-09 19:08:30 -08008025 GenerateGcRootFieldLoad(load,
8026 out_loc,
8027 out,
8028 /* placeholder */ 0x5678,
Alexey Frunze4147fcc2017-06-17 19:57:27 -07008029 kCompilerReadBarrierOption,
8030 &info->low_label);
Alexey Frunze627c1a02017-01-30 19:28:14 -08008031 return;
8032 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07008033 default:
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07008034 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07008035 }
Nicolas Geoffray917d0162015-11-24 18:25:35 +00008036
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07008037 // TODO: Re-add the compiler code to do string dex cache lookup again.
Vladimir Marko847e6ce2017-06-02 13:55:07 +01008038 DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall);
Vladimir Markoaad75c62016-10-03 08:46:48 +00008039 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzec61c0762017-04-10 13:54:23 -07008040 DCHECK_EQ(calling_convention.GetRegisterAt(0), out);
Andreas Gampe8a0128a2016-11-28 07:38:35 -08008041 __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_);
Vladimir Markoaad75c62016-10-03 08:46:48 +00008042 codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc());
8043 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008044}
8045
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008046void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008047 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008048 locations->SetOut(Location::ConstantLocation(constant));
8049}
8050
8051void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
8052 // Will be generated at use site.
8053}
8054
8055void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008056 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
8057 instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008058 InvokeRuntimeCallingConvention calling_convention;
8059 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
8060}
8061
8062void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
8063 if (instruction->IsEnter()) {
Serban Constantinescufca16662016-07-14 09:21:59 +01008064 codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008065 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
8066 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01008067 codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008068 }
8069 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
8070}
8071
8072void LocationsBuilderMIPS::VisitMul(HMul* mul) {
8073 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01008074 new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008075 switch (mul->GetResultType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008076 case DataType::Type::kInt32:
8077 case DataType::Type::kInt64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008078 locations->SetInAt(0, Location::RequiresRegister());
8079 locations->SetInAt(1, Location::RequiresRegister());
8080 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8081 break;
8082
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008083 case DataType::Type::kFloat32:
8084 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008085 locations->SetInAt(0, Location::RequiresFpuRegister());
8086 locations->SetInAt(1, Location::RequiresFpuRegister());
8087 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
8088 break;
8089
8090 default:
8091 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
8092 }
8093}
8094
8095void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008096 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008097 LocationSummary* locations = instruction->GetLocations();
8098 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
8099
8100 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008101 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008102 Register dst = locations->Out().AsRegister<Register>();
8103 Register lhs = locations->InAt(0).AsRegister<Register>();
8104 Register rhs = locations->InAt(1).AsRegister<Register>();
8105
8106 if (isR6) {
8107 __ MulR6(dst, lhs, rhs);
8108 } else {
8109 __ MulR2(dst, lhs, rhs);
8110 }
8111 break;
8112 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008113 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008114 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
8115 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
8116 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
8117 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
8118 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
8119 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
8120
8121 // Extra checks to protect caused by the existance of A1_A2.
8122 // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo:
8123 // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2).
8124 DCHECK_NE(dst_high, lhs_low);
8125 DCHECK_NE(dst_high, rhs_low);
8126
8127 // A_B * C_D
8128 // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ]
8129 // dst_lo: [ low(B*D) ]
8130 // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result.
8131
8132 if (isR6) {
8133 __ MulR6(TMP, lhs_high, rhs_low);
8134 __ MulR6(dst_high, lhs_low, rhs_high);
8135 __ Addu(dst_high, dst_high, TMP);
8136 __ MuhuR6(TMP, lhs_low, rhs_low);
8137 __ Addu(dst_high, dst_high, TMP);
8138 __ MulR6(dst_low, lhs_low, rhs_low);
8139 } else {
8140 __ MulR2(TMP, lhs_high, rhs_low);
8141 __ MulR2(dst_high, lhs_low, rhs_high);
8142 __ Addu(dst_high, dst_high, TMP);
8143 __ MultuR2(lhs_low, rhs_low);
8144 __ Mfhi(TMP);
8145 __ Addu(dst_high, dst_high, TMP);
8146 __ Mflo(dst_low);
8147 }
8148 break;
8149 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008150 case DataType::Type::kFloat32:
8151 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008152 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
8153 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
8154 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008155 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008156 __ MulS(dst, lhs, rhs);
8157 } else {
8158 __ MulD(dst, lhs, rhs);
8159 }
8160 break;
8161 }
8162 default:
8163 LOG(FATAL) << "Unexpected mul type " << type;
8164 }
8165}
8166
8167void LocationsBuilderMIPS::VisitNeg(HNeg* neg) {
8168 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01008169 new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008170 switch (neg->GetResultType()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008171 case DataType::Type::kInt32:
8172 case DataType::Type::kInt64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008173 locations->SetInAt(0, Location::RequiresRegister());
8174 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8175 break;
8176
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008177 case DataType::Type::kFloat32:
8178 case DataType::Type::kFloat64:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008179 locations->SetInAt(0, Location::RequiresFpuRegister());
8180 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
8181 break;
8182
8183 default:
8184 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
8185 }
8186}
8187
8188void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008189 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008190 LocationSummary* locations = instruction->GetLocations();
8191
8192 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008193 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008194 Register dst = locations->Out().AsRegister<Register>();
8195 Register src = locations->InAt(0).AsRegister<Register>();
8196 __ Subu(dst, ZERO, src);
8197 break;
8198 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008199 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008200 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
8201 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
8202 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
8203 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
8204 __ Subu(dst_low, ZERO, src_low);
8205 __ Sltu(TMP, ZERO, dst_low);
8206 __ Subu(dst_high, ZERO, src_high);
8207 __ Subu(dst_high, dst_high, TMP);
8208 break;
8209 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008210 case DataType::Type::kFloat32:
8211 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008212 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
8213 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008214 if (type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008215 __ NegS(dst, src);
8216 } else {
8217 __ NegD(dst, src);
8218 }
8219 break;
8220 }
8221 default:
8222 LOG(FATAL) << "Unexpected neg type " << type;
8223 }
8224}
8225
8226void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008227 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
8228 instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008229 InvokeRuntimeCallingConvention calling_convention;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008230 locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference));
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00008231 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
8232 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008233}
8234
8235void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) {
Alexey Frunzec061de12017-02-14 13:27:23 -08008236 // Note: if heap poisoning is enabled, the entry point takes care
8237 // of poisoning the reference.
Goran Jakovljevic854df412017-06-27 14:41:39 +02008238 QuickEntrypointEnum entrypoint =
8239 CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass());
8240 codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc());
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00008241 CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>();
Goran Jakovljevic854df412017-06-27 14:41:39 +02008242 DCHECK(!codegen_->IsLeafMethod());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008243}
8244
8245void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008246 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
8247 instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008248 InvokeRuntimeCallingConvention calling_convention;
David Brazdil6de19382016-01-08 17:37:10 +00008249 if (instruction->IsStringAlloc()) {
8250 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
8251 } else {
8252 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
David Brazdil6de19382016-01-08 17:37:10 +00008253 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008254 locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008255}
8256
8257void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) {
Alexey Frunzec061de12017-02-14 13:27:23 -08008258 // Note: if heap poisoning is enabled, the entry point takes care
8259 // of poisoning the reference.
David Brazdil6de19382016-01-08 17:37:10 +00008260 if (instruction->IsStringAlloc()) {
8261 // String is allocated through StringFactory. Call NewEmptyString entry point.
8262 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07008263 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00008264 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
8265 __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value());
8266 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07008267 __ NopIfNoReordering();
David Brazdil6de19382016-01-08 17:37:10 +00008268 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
8269 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01008270 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00008271 CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>();
David Brazdil6de19382016-01-08 17:37:10 +00008272 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008273}
8274
8275void LocationsBuilderMIPS::VisitNot(HNot* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008276 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008277 locations->SetInAt(0, Location::RequiresRegister());
8278 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8279}
8280
8281void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008282 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008283 LocationSummary* locations = instruction->GetLocations();
8284
8285 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008286 case DataType::Type::kInt32: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008287 Register dst = locations->Out().AsRegister<Register>();
8288 Register src = locations->InAt(0).AsRegister<Register>();
8289 __ Nor(dst, src, ZERO);
8290 break;
8291 }
8292
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008293 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008294 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
8295 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
8296 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
8297 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
8298 __ Nor(dst_high, src_high, ZERO);
8299 __ Nor(dst_low, src_low, ZERO);
8300 break;
8301 }
8302
8303 default:
8304 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
8305 }
8306}
8307
8308void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008309 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008310 locations->SetInAt(0, Location::RequiresRegister());
8311 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8312}
8313
8314void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) {
8315 LocationSummary* locations = instruction->GetLocations();
8316 __ Xori(locations->Out().AsRegister<Register>(),
8317 locations->InAt(0).AsRegister<Register>(),
8318 1);
8319}
8320
8321void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01008322 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
8323 locations->SetInAt(0, Location::RequiresRegister());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008324}
8325
Calin Juravle2ae48182016-03-16 14:05:09 +00008326void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) {
8327 if (CanMoveNullCheckToUser(instruction)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008328 return;
8329 }
8330 Location obj = instruction->GetLocations()->InAt(0);
8331
8332 __ Lw(ZERO, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00008333 RecordPcInfo(instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008334}
8335
Calin Juravle2ae48182016-03-16 14:05:09 +00008336void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008337 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetAllocator()) NullCheckSlowPathMIPS(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00008338 AddSlowPath(slow_path);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008339
8340 Location obj = instruction->GetLocations()->InAt(0);
8341
8342 __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
8343}
8344
8345void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00008346 codegen_->GenerateNullCheck(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008347}
8348
8349void LocationsBuilderMIPS::VisitOr(HOr* instruction) {
8350 HandleBinaryOp(instruction);
8351}
8352
8353void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) {
8354 HandleBinaryOp(instruction);
8355}
8356
8357void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
8358 LOG(FATAL) << "Unreachable";
8359}
8360
8361void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) {
8362 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
8363}
8364
8365void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008366 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008367 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
8368 if (location.IsStackSlot()) {
8369 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
8370 } else if (location.IsDoubleStackSlot()) {
8371 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
8372 }
8373 locations->SetOut(location);
8374}
8375
8376void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction
8377 ATTRIBUTE_UNUSED) {
8378 // Nothing to do, the parameter is already at its location.
8379}
8380
8381void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) {
8382 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01008383 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008384 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
8385}
8386
8387void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction
8388 ATTRIBUTE_UNUSED) {
8389 // Nothing to do, the method is already at its location.
8390}
8391
8392void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008393 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction);
Vladimir Marko372f10e2016-05-17 16:30:10 +01008394 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008395 locations->SetInAt(i, Location::Any());
8396 }
8397 locations->SetOut(Location::Any());
8398}
8399
8400void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
8401 LOG(FATAL) << "Unreachable";
8402}
8403
8404void LocationsBuilderMIPS::VisitRem(HRem* rem) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008405 DataType::Type type = rem->GetResultType();
8406 LocationSummary::CallKind call_kind = (type == DataType::Type::kInt32)
8407 ? LocationSummary::kNoCall
8408 : LocationSummary::kCallOnMainOnly;
Vladimir Markoca6fff82017-10-03 14:49:14 +01008409 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008410
8411 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008412 case DataType::Type::kInt32:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008413 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08008414 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008415 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8416 break;
8417
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008418 case DataType::Type::kInt64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008419 InvokeRuntimeCallingConvention calling_convention;
8420 locations->SetInAt(0, Location::RegisterPairLocation(
8421 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
8422 locations->SetInAt(1, Location::RegisterPairLocation(
8423 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
8424 locations->SetOut(calling_convention.GetReturnLocation(type));
8425 break;
8426 }
8427
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008428 case DataType::Type::kFloat32:
8429 case DataType::Type::kFloat64: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008430 InvokeRuntimeCallingConvention calling_convention;
8431 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
8432 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
8433 locations->SetOut(calling_convention.GetReturnLocation(type));
8434 break;
8435 }
8436
8437 default:
8438 LOG(FATAL) << "Unexpected rem type " << type;
8439 }
8440}
8441
8442void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008443 DataType::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008444
8445 switch (type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008446 case DataType::Type::kInt32:
Alexey Frunze7e99e052015-11-24 19:28:01 -08008447 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008448 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008449 case DataType::Type::kInt64: {
Serban Constantinescufca16662016-07-14 09:21:59 +01008450 codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008451 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
8452 break;
8453 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008454 case DataType::Type::kFloat32: {
Serban Constantinescufca16662016-07-14 09:21:59 +01008455 codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00008456 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008457 break;
8458 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008459 case DataType::Type::kFloat64: {
Serban Constantinescufca16662016-07-14 09:21:59 +01008460 codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00008461 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008462 break;
8463 }
8464 default:
8465 LOG(FATAL) << "Unexpected rem type " << type;
8466 }
8467}
8468
Igor Murashkind01745e2017-04-05 16:40:31 -07008469void LocationsBuilderMIPS::VisitConstructorFence(HConstructorFence* constructor_fence) {
8470 constructor_fence->SetLocations(nullptr);
8471}
8472
8473void InstructionCodeGeneratorMIPS::VisitConstructorFence(
8474 HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) {
8475 GenerateMemoryBarrier(MemBarrierKind::kStoreStore);
8476}
8477
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008478void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
8479 memory_barrier->SetLocations(nullptr);
8480}
8481
8482void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
8483 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
8484}
8485
8486void LocationsBuilderMIPS::VisitReturn(HReturn* ret) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008487 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008488 DataType::Type return_type = ret->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008489 locations->SetInAt(0, MipsReturnLocation(return_type));
8490}
8491
8492void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
8493 codegen_->GenerateFrameExit();
8494}
8495
8496void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) {
8497 ret->SetLocations(nullptr);
8498}
8499
8500void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
8501 codegen_->GenerateFrameExit();
8502}
8503
Alexey Frunze92d90602015-12-18 18:16:36 -08008504void LocationsBuilderMIPS::VisitRor(HRor* ror) {
8505 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00008506}
8507
Alexey Frunze92d90602015-12-18 18:16:36 -08008508void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) {
8509 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00008510}
8511
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008512void LocationsBuilderMIPS::VisitShl(HShl* shl) {
8513 HandleShift(shl);
8514}
8515
8516void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) {
8517 HandleShift(shl);
8518}
8519
8520void LocationsBuilderMIPS::VisitShr(HShr* shr) {
8521 HandleShift(shr);
8522}
8523
8524void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) {
8525 HandleShift(shr);
8526}
8527
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008528void LocationsBuilderMIPS::VisitSub(HSub* instruction) {
8529 HandleBinaryOp(instruction);
8530}
8531
8532void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) {
8533 HandleBinaryOp(instruction);
8534}
8535
8536void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
8537 HandleFieldGet(instruction, instruction->GetFieldInfo());
8538}
8539
8540void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
8541 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
8542}
8543
8544void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
8545 HandleFieldSet(instruction, instruction->GetFieldInfo());
8546}
8547
8548void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Goran Jakovljevice114da22016-12-26 14:21:43 +01008549 HandleFieldSet(instruction,
8550 instruction->GetFieldInfo(),
8551 instruction->GetDexPc(),
8552 instruction->GetValueCanBeNull());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008553}
8554
8555void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet(
8556 HUnresolvedInstanceFieldGet* instruction) {
8557 FieldAccessCallingConventionMIPS calling_convention;
8558 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
8559 instruction->GetFieldType(),
8560 calling_convention);
8561}
8562
8563void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet(
8564 HUnresolvedInstanceFieldGet* instruction) {
8565 FieldAccessCallingConventionMIPS calling_convention;
8566 codegen_->GenerateUnresolvedFieldAccess(instruction,
8567 instruction->GetFieldType(),
8568 instruction->GetFieldIndex(),
8569 instruction->GetDexPc(),
8570 calling_convention);
8571}
8572
8573void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet(
8574 HUnresolvedInstanceFieldSet* instruction) {
8575 FieldAccessCallingConventionMIPS calling_convention;
8576 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
8577 instruction->GetFieldType(),
8578 calling_convention);
8579}
8580
8581void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet(
8582 HUnresolvedInstanceFieldSet* instruction) {
8583 FieldAccessCallingConventionMIPS calling_convention;
8584 codegen_->GenerateUnresolvedFieldAccess(instruction,
8585 instruction->GetFieldType(),
8586 instruction->GetFieldIndex(),
8587 instruction->GetDexPc(),
8588 calling_convention);
8589}
8590
8591void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet(
8592 HUnresolvedStaticFieldGet* instruction) {
8593 FieldAccessCallingConventionMIPS calling_convention;
8594 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
8595 instruction->GetFieldType(),
8596 calling_convention);
8597}
8598
8599void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet(
8600 HUnresolvedStaticFieldGet* instruction) {
8601 FieldAccessCallingConventionMIPS calling_convention;
8602 codegen_->GenerateUnresolvedFieldAccess(instruction,
8603 instruction->GetFieldType(),
8604 instruction->GetFieldIndex(),
8605 instruction->GetDexPc(),
8606 calling_convention);
8607}
8608
8609void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet(
8610 HUnresolvedStaticFieldSet* instruction) {
8611 FieldAccessCallingConventionMIPS calling_convention;
8612 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
8613 instruction->GetFieldType(),
8614 calling_convention);
8615}
8616
8617void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet(
8618 HUnresolvedStaticFieldSet* instruction) {
8619 FieldAccessCallingConventionMIPS calling_convention;
8620 codegen_->GenerateUnresolvedFieldAccess(instruction,
8621 instruction->GetFieldType(),
8622 instruction->GetFieldIndex(),
8623 instruction->GetDexPc(),
8624 calling_convention);
8625}
8626
8627void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008628 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
8629 instruction, LocationSummary::kCallOnSlowPath);
Lena Djokicca8c2952017-05-29 11:31:46 +02008630 // In suspend check slow path, usually there are no caller-save registers at all.
8631 // If SIMD instructions are present, however, we force spilling all live SIMD
8632 // registers in full width (since the runtime only saves/restores lower part).
8633 locations->SetCustomSlowPathCallerSaves(
8634 GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008635}
8636
8637void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
8638 HBasicBlock* block = instruction->GetBlock();
8639 if (block->GetLoopInformation() != nullptr) {
8640 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
8641 // The back edge will generate the suspend check.
8642 return;
8643 }
8644 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
8645 // The goto will generate the suspend check.
8646 return;
8647 }
8648 GenerateSuspendCheck(instruction, nullptr);
8649}
8650
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008651void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) {
Vladimir Markoca6fff82017-10-03 14:49:14 +01008652 LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(
8653 instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008654 InvokeRuntimeCallingConvention calling_convention;
8655 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
8656}
8657
8658void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) {
Serban Constantinescufca16662016-07-14 09:21:59 +01008659 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008660 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
8661}
8662
8663void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008664 DataType::Type input_type = conversion->GetInputType();
8665 DataType::Type result_type = conversion->GetResultType();
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01008666 DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type))
8667 << input_type << " -> " << result_type;
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008668 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008669
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008670 if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) ||
8671 (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008672 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
8673 }
8674
8675 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008676 if (!isR6 &&
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008677 ((DataType::IsFloatingPointType(result_type) && input_type == DataType::Type::kInt64) ||
8678 (result_type == DataType::Type::kInt64 && DataType::IsFloatingPointType(input_type)))) {
Serban Constantinescu54ff4822016-07-07 18:03:19 +01008679 call_kind = LocationSummary::kCallOnMainOnly;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008680 }
8681
Vladimir Markoca6fff82017-10-03 14:49:14 +01008682 LocationSummary* locations =
8683 new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008684
8685 if (call_kind == LocationSummary::kNoCall) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008686 if (DataType::IsFloatingPointType(input_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008687 locations->SetInAt(0, Location::RequiresFpuRegister());
8688 } else {
8689 locations->SetInAt(0, Location::RequiresRegister());
8690 }
8691
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008692 if (DataType::IsFloatingPointType(result_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008693 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
8694 } else {
8695 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
8696 }
8697 } else {
8698 InvokeRuntimeCallingConvention calling_convention;
8699
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008700 if (DataType::IsFloatingPointType(input_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008701 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
8702 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008703 DCHECK_EQ(input_type, DataType::Type::kInt64);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008704 locations->SetInAt(0, Location::RegisterPairLocation(
8705 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
8706 }
8707
8708 locations->SetOut(calling_convention.GetReturnLocation(result_type));
8709 }
8710}
8711
8712void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) {
8713 LocationSummary* locations = conversion->GetLocations();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008714 DataType::Type result_type = conversion->GetResultType();
8715 DataType::Type input_type = conversion->GetInputType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008716 bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008717 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008718
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01008719 DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type))
8720 << input_type << " -> " << result_type;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008721
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008722 if (result_type == DataType::Type::kInt64 && DataType::IsIntegralType(input_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008723 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
8724 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
8725 Register src = locations->InAt(0).AsRegister<Register>();
8726
Alexey Frunzea871ef12016-06-27 15:20:11 -07008727 if (dst_low != src) {
8728 __ Move(dst_low, src);
8729 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008730 __ Sra(dst_high, src, 31);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008731 } else if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008732 Register dst = locations->Out().AsRegister<Register>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008733 Register src = (input_type == DataType::Type::kInt64)
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008734 ? locations->InAt(0).AsRegisterPairLow<Register>()
8735 : locations->InAt(0).AsRegister<Register>();
8736
8737 switch (result_type) {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01008738 case DataType::Type::kUint8:
8739 __ Andi(dst, src, 0xFF);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008740 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008741 case DataType::Type::kInt8:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008742 if (has_sign_extension) {
8743 __ Seb(dst, src);
8744 } else {
8745 __ Sll(dst, src, 24);
8746 __ Sra(dst, dst, 24);
8747 }
8748 break;
Vladimir Markod5d2f2c2017-09-26 12:37:26 +01008749 case DataType::Type::kUint16:
8750 __ Andi(dst, src, 0xFFFF);
8751 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008752 case DataType::Type::kInt16:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008753 if (has_sign_extension) {
8754 __ Seh(dst, src);
8755 } else {
8756 __ Sll(dst, src, 16);
8757 __ Sra(dst, dst, 16);
8758 }
8759 break;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008760 case DataType::Type::kInt32:
Alexey Frunzea871ef12016-06-27 15:20:11 -07008761 if (dst != src) {
8762 __ Move(dst, src);
8763 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008764 break;
8765
8766 default:
8767 LOG(FATAL) << "Unexpected type conversion from " << input_type
8768 << " to " << result_type;
8769 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008770 } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) {
8771 if (input_type == DataType::Type::kInt64) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008772 if (isR6) {
8773 // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
8774 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
8775 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
8776 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
8777 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
8778 __ Mtc1(src_low, FTMP);
8779 __ Mthc1(src_high, FTMP);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008780 if (result_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008781 __ Cvtsl(dst, FTMP);
8782 } else {
8783 __ Cvtdl(dst, FTMP);
8784 }
8785 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008786 QuickEntrypointEnum entrypoint =
8787 (result_type == DataType::Type::kFloat32) ? kQuickL2f : kQuickL2d;
Serban Constantinescufca16662016-07-14 09:21:59 +01008788 codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008789 if (result_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008790 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
8791 } else {
8792 CheckEntrypointTypes<kQuickL2d, double, int64_t>();
8793 }
8794 }
8795 } else {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008796 Register src = locations->InAt(0).AsRegister<Register>();
8797 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
8798 __ Mtc1(src, FTMP);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008799 if (result_type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008800 __ Cvtsw(dst, FTMP);
8801 } else {
8802 __ Cvtdw(dst, FTMP);
8803 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008804 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008805 } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) {
8806 CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64);
Lena Djokicf4e23a82017-05-09 15:43:45 +02008807
8808 // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum
8809 // value of the output type if the input is outside of the range after the truncation or
8810 // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct
8811 // results. This matches the desired float/double-to-int/long conversion exactly.
8812 //
8813 // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive
8814 // value when the input is either a NaN or is outside of the range of the output type
8815 // after the truncation. IOW, the three special cases (NaN, too small, too big) produce
8816 // the same result.
8817 //
8818 // The code takes care of the different behaviors by first comparing the input to the
8819 // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int).
8820 // If the input is greater than or equal to the minimum, it procedes to the truncate
8821 // instruction, which will handle such an input the same way irrespective of NAN2008.
8822 // Otherwise the input is compared to itself to determine whether it is a NaN or not
8823 // in order to return either zero or the minimum value.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008824 if (result_type == DataType::Type::kInt64) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008825 if (isR6) {
8826 // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
8827 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
8828 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
8829 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
8830 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008831
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008832 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008833 __ TruncLS(FTMP, src);
8834 } else {
8835 __ TruncLD(FTMP, src);
8836 }
8837 __ Mfc1(dst_low, FTMP);
8838 __ Mfhc1(dst_high, FTMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008839 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008840 QuickEntrypointEnum entrypoint =
8841 (input_type == DataType::Type::kFloat32) ? kQuickF2l : kQuickD2l;
Serban Constantinescufca16662016-07-14 09:21:59 +01008842 codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008843 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008844 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
8845 } else {
8846 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
8847 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008848 }
8849 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008850 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
8851 Register dst = locations->Out().AsRegister<Register>();
8852 MipsLabel truncate;
8853 MipsLabel done;
8854
Lena Djokicf4e23a82017-05-09 15:43:45 +02008855 if (!isR6) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008856 if (input_type == DataType::Type::kFloat32) {
Lena Djokicf4e23a82017-05-09 15:43:45 +02008857 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min());
8858 __ LoadConst32(TMP, min_val);
8859 __ Mtc1(TMP, FTMP);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008860 } else {
Lena Djokicf4e23a82017-05-09 15:43:45 +02008861 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min());
8862 __ LoadConst32(TMP, High32Bits(min_val));
8863 __ Mtc1(ZERO, FTMP);
8864 __ MoveToFpuHigh(TMP, FTMP);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008865 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008866
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008867 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008868 __ ColeS(0, FTMP, src);
8869 } else {
8870 __ ColeD(0, FTMP, src);
8871 }
8872 __ Bc1t(0, &truncate);
8873
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008874 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008875 __ CeqS(0, src, src);
8876 } else {
8877 __ CeqD(0, src, src);
8878 }
8879 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
8880 __ Movf(dst, ZERO, 0);
Lena Djokicf4e23a82017-05-09 15:43:45 +02008881
8882 __ B(&done);
8883
8884 __ Bind(&truncate);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008885 }
8886
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008887 if (input_type == DataType::Type::kFloat32) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08008888 __ TruncWS(FTMP, src);
8889 } else {
8890 __ TruncWD(FTMP, src);
8891 }
8892 __ Mfc1(dst, FTMP);
8893
Lena Djokicf4e23a82017-05-09 15:43:45 +02008894 if (!isR6) {
8895 __ Bind(&done);
8896 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008897 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008898 } else if (DataType::IsFloatingPointType(result_type) &&
8899 DataType::IsFloatingPointType(input_type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008900 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
8901 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +01008902 if (result_type == DataType::Type::kFloat32) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008903 __ Cvtsd(dst, src);
8904 } else {
8905 __ Cvtds(dst, src);
8906 }
8907 } else {
8908 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
8909 << " to " << result_type;
8910 }
8911}
8912
8913void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) {
8914 HandleShift(ushr);
8915}
8916
8917void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) {
8918 HandleShift(ushr);
8919}
8920
8921void LocationsBuilderMIPS::VisitXor(HXor* instruction) {
8922 HandleBinaryOp(instruction);
8923}
8924
8925void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) {
8926 HandleBinaryOp(instruction);
8927}
8928
8929void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
8930 // Nothing to do, this should be removed during prepare for register allocator.
8931 LOG(FATAL) << "Unreachable";
8932}
8933
8934void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
8935 // Nothing to do, this should be removed during prepare for register allocator.
8936 LOG(FATAL) << "Unreachable";
8937}
8938
8939void LocationsBuilderMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008940 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008941}
8942
8943void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008944 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008945}
8946
8947void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008948 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008949}
8950
8951void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008952 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008953}
8954
8955void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008956 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008957}
8958
8959void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008960 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008961}
8962
8963void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008964 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008965}
8966
8967void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008968 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008969}
8970
8971void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008972 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008973}
8974
8975void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008976 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008977}
8978
8979void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008980 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008981}
8982
8983void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008984 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008985}
8986
8987void LocationsBuilderMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008988 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008989}
8990
8991void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008992 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008993}
8994
8995void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00008996 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02008997}
8998
8999void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009000 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009001}
9002
9003void LocationsBuilderMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009004 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009005}
9006
9007void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009008 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009009}
9010
9011void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009012 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009013}
9014
9015void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00009016 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009017}
9018
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009019void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
9020 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01009021 new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009022 locations->SetInAt(0, Location::RequiresRegister());
9023}
9024
Alexey Frunze96b66822016-09-10 02:32:44 -07009025void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg,
9026 int32_t lower_bound,
9027 uint32_t num_entries,
9028 HBasicBlock* switch_block,
9029 HBasicBlock* default_block) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009030 // Create a set of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00009031 Register temp_reg = TMP;
9032 __ Addiu32(temp_reg, value_reg, -lower_bound);
9033 // Jump to default if index is negative
9034 // Note: We don't check the case that index is positive while value < lower_bound, because in
9035 // this case, index >= num_entries must be true. So that we can save one branch instruction.
9036 __ Bltz(temp_reg, codegen_->GetLabelOf(default_block));
9037
Alexey Frunze96b66822016-09-10 02:32:44 -07009038 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00009039 // Jump to successors[0] if value == lower_bound.
9040 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0]));
9041 int32_t last_index = 0;
9042 for (; num_entries - last_index > 2; last_index += 2) {
9043 __ Addiu(temp_reg, temp_reg, -2);
9044 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
9045 __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
9046 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
9047 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
9048 }
9049 if (num_entries - last_index == 2) {
9050 // The last missing case_value.
9051 __ Addiu(temp_reg, temp_reg, -1);
9052 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009053 }
9054
Vladimir Markof3e0ee22015-12-17 15:23:13 +00009055 // And the default for any other value.
Alexey Frunze96b66822016-09-10 02:32:44 -07009056 if (!codegen_->GoesToNextBlock(switch_block, default_block)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009057 __ B(codegen_->GetLabelOf(default_block));
9058 }
9059}
9060
Alexey Frunze96b66822016-09-10 02:32:44 -07009061void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg,
9062 Register constant_area,
9063 int32_t lower_bound,
9064 uint32_t num_entries,
9065 HBasicBlock* switch_block,
9066 HBasicBlock* default_block) {
9067 // Create a jump table.
9068 std::vector<MipsLabel*> labels(num_entries);
9069 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
9070 for (uint32_t i = 0; i < num_entries; i++) {
9071 labels[i] = codegen_->GetLabelOf(successors[i]);
9072 }
9073 JumpTable* table = __ CreateJumpTable(std::move(labels));
9074
9075 // Is the value in range?
9076 __ Addiu32(TMP, value_reg, -lower_bound);
9077 if (IsInt<16>(static_cast<int32_t>(num_entries))) {
9078 __ Sltiu(AT, TMP, num_entries);
9079 __ Beqz(AT, codegen_->GetLabelOf(default_block));
9080 } else {
9081 __ LoadConst32(AT, num_entries);
9082 __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block));
9083 }
9084
9085 // We are in the range of the table.
9086 // Load the target address from the jump table, indexing by the value.
9087 __ LoadLabelAddress(AT, constant_area, table->GetLabel());
Chris Larsencd0295d2017-03-31 15:26:54 -07009088 __ ShiftAndAdd(TMP, TMP, AT, 2, TMP);
Alexey Frunze96b66822016-09-10 02:32:44 -07009089 __ Lw(TMP, TMP, 0);
9090 // Compute the absolute target address by adding the table start address
9091 // (the table contains offsets to targets relative to its start).
9092 __ Addu(TMP, TMP, AT);
9093 // And jump.
9094 __ Jr(TMP);
9095 __ NopIfNoReordering();
9096}
9097
9098void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
9099 int32_t lower_bound = switch_instr->GetStartValue();
9100 uint32_t num_entries = switch_instr->GetNumEntries();
9101 LocationSummary* locations = switch_instr->GetLocations();
9102 Register value_reg = locations->InAt(0).AsRegister<Register>();
9103 HBasicBlock* switch_block = switch_instr->GetBlock();
9104 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
9105
9106 if (codegen_->GetInstructionSetFeatures().IsR6() &&
9107 num_entries > kPackedSwitchJumpTableThreshold) {
9108 // R6 uses PC-relative addressing to access the jump table.
9109 // R2, OTOH, requires an HMipsComputeBaseMethodAddress input to access
9110 // the jump table and it is implemented by changing HPackedSwitch to
9111 // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress.
9112 // See VisitMipsPackedSwitch() for the table-based implementation on R2.
9113 GenTableBasedPackedSwitch(value_reg,
9114 ZERO,
9115 lower_bound,
9116 num_entries,
9117 switch_block,
9118 default_block);
9119 } else {
9120 GenPackedSwitchWithCompares(value_reg,
9121 lower_bound,
9122 num_entries,
9123 switch_block,
9124 default_block);
9125 }
9126}
9127
9128void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) {
9129 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01009130 new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall);
Alexey Frunze96b66822016-09-10 02:32:44 -07009131 locations->SetInAt(0, Location::RequiresRegister());
9132 // Constant area pointer (HMipsComputeBaseMethodAddress).
9133 locations->SetInAt(1, Location::RequiresRegister());
9134}
9135
9136void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) {
9137 int32_t lower_bound = switch_instr->GetStartValue();
9138 uint32_t num_entries = switch_instr->GetNumEntries();
9139 LocationSummary* locations = switch_instr->GetLocations();
9140 Register value_reg = locations->InAt(0).AsRegister<Register>();
9141 Register constant_area = locations->InAt(1).AsRegister<Register>();
9142 HBasicBlock* switch_block = switch_instr->GetBlock();
9143 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
9144
9145 // This is an R2-only path. HPackedSwitch has been changed to
9146 // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress
9147 // required to address the jump table relative to PC.
9148 GenTableBasedPackedSwitch(value_reg,
9149 constant_area,
9150 lower_bound,
9151 num_entries,
9152 switch_block,
9153 default_block);
9154}
9155
Alexey Frunzee3fb2452016-05-10 16:08:05 -07009156void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress(
9157 HMipsComputeBaseMethodAddress* insn) {
9158 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01009159 new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07009160 locations->SetOut(Location::RequiresRegister());
9161}
9162
9163void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress(
9164 HMipsComputeBaseMethodAddress* insn) {
9165 LocationSummary* locations = insn->GetLocations();
9166 Register reg = locations->Out().AsRegister<Register>();
9167
9168 CHECK(!codegen_->GetInstructionSetFeatures().IsR6());
9169
9170 // Generate a dummy PC-relative call to obtain PC.
9171 __ Nal();
9172 // Grab the return address off RA.
9173 __ Move(reg, RA);
9174
9175 // Remember this offset (the obtained PC value) for later use with constant area.
9176 __ BindPcRelBaseLabel();
9177}
9178
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009179void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
9180 // The trampoline uses the same calling convention as dex calling conventions,
9181 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
9182 // the method_idx.
9183 HandleInvoke(invoke);
9184}
9185
9186void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
9187 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
9188}
9189
Roland Levillain2aba7cd2016-02-03 12:27:20 +00009190void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) {
9191 LocationSummary* locations =
Vladimir Markoca6fff82017-10-03 14:49:14 +01009192 new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00009193 locations->SetInAt(0, Location::RequiresRegister());
9194 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00009195}
9196
Roland Levillain2aba7cd2016-02-03 12:27:20 +00009197void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) {
9198 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00009199 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01009200 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Roland Levillain2aba7cd2016-02-03 12:27:20 +00009201 instruction->GetIndex(), kMipsPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01009202 __ LoadFromOffset(kLoadWord,
9203 locations->Out().AsRegister<Register>(),
9204 locations->InAt(0).AsRegister<Register>(),
9205 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00009206 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01009207 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00009208 instruction->GetIndex(), kMipsPointerSize));
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00009209 __ LoadFromOffset(kLoadWord,
9210 locations->Out().AsRegister<Register>(),
9211 locations->InAt(0).AsRegister<Register>(),
9212 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01009213 __ LoadFromOffset(kLoadWord,
9214 locations->Out().AsRegister<Register>(),
9215 locations->Out().AsRegister<Register>(),
9216 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00009217 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00009218}
9219
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02009220#undef __
9221#undef QUICK_ENTRY_POINT
9222
9223} // namespace mips
9224} // namespace art