blob: 192b4a5050a7b8746a83d28c79b5bc990d44ecca [file] [log] [blame]
Alexey Frunze4dda3372015-06-01 18:31:49 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "code_generator_mips64.h"
18
Alexey Frunzec857c742015-09-23 15:12:39 -070019#include "art_method.h"
20#include "code_generator_utils.h"
Alexey Frunze19f6c692016-11-30 19:19:55 -080021#include "compiled_method.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070022#include "entrypoints/quick/quick_entrypoints.h"
23#include "entrypoints/quick/quick_entrypoints_enum.h"
24#include "gc/accounting/card_table.h"
25#include "intrinsics.h"
Chris Larsen3039e382015-08-26 07:54:08 -070026#include "intrinsics_mips64.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070027#include "mirror/array-inl.h"
28#include "mirror/class-inl.h"
29#include "offsets.h"
30#include "thread.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070031#include "utils/assembler.h"
Alexey Frunzea0e87b02015-09-24 22:57:20 -070032#include "utils/mips64/assembler_mips64.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070033#include "utils/stack_checks.h"
34
35namespace art {
36namespace mips64 {
37
38static constexpr int kCurrentMethodStackOffset = 0;
39static constexpr GpuRegister kMethodRegisterArgument = A0;
40
Alexey Frunze4dda3372015-06-01 18:31:49 -070041Location Mips64ReturnLocation(Primitive::Type return_type) {
42 switch (return_type) {
43 case Primitive::kPrimBoolean:
44 case Primitive::kPrimByte:
45 case Primitive::kPrimChar:
46 case Primitive::kPrimShort:
47 case Primitive::kPrimInt:
48 case Primitive::kPrimNot:
49 case Primitive::kPrimLong:
50 return Location::RegisterLocation(V0);
51
52 case Primitive::kPrimFloat:
53 case Primitive::kPrimDouble:
54 return Location::FpuRegisterLocation(F0);
55
56 case Primitive::kPrimVoid:
57 return Location();
58 }
59 UNREACHABLE();
60}
61
62Location InvokeDexCallingConventionVisitorMIPS64::GetReturnLocation(Primitive::Type type) const {
63 return Mips64ReturnLocation(type);
64}
65
66Location InvokeDexCallingConventionVisitorMIPS64::GetMethodLocation() const {
67 return Location::RegisterLocation(kMethodRegisterArgument);
68}
69
70Location InvokeDexCallingConventionVisitorMIPS64::GetNextLocation(Primitive::Type type) {
71 Location next_location;
72 if (type == Primitive::kPrimVoid) {
73 LOG(FATAL) << "Unexpected parameter type " << type;
74 }
75
76 if (Primitive::IsFloatingPointType(type) &&
77 (float_index_ < calling_convention.GetNumberOfFpuRegisters())) {
78 next_location = Location::FpuRegisterLocation(
79 calling_convention.GetFpuRegisterAt(float_index_++));
80 gp_index_++;
81 } else if (!Primitive::IsFloatingPointType(type) &&
82 (gp_index_ < calling_convention.GetNumberOfRegisters())) {
83 next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index_++));
84 float_index_++;
85 } else {
86 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
87 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
88 : Location::StackSlot(stack_offset);
89 }
90
91 // Space on the stack is reserved for all arguments.
92 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
93
Alexey Frunze4dda3372015-06-01 18:31:49 -070094 // TODO: shouldn't we use a whole machine word per argument on the stack?
95 // Implicit 4-byte method pointer (and such) will cause misalignment.
96
97 return next_location;
98}
99
100Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type type) {
101 return Mips64ReturnLocation(type);
102}
103
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100104// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
105#define __ down_cast<CodeGeneratorMIPS64*>(codegen)->GetAssembler()-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700106#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value()
Alexey Frunze4dda3372015-06-01 18:31:49 -0700107
108class BoundsCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
109 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000110 explicit BoundsCheckSlowPathMIPS64(HBoundsCheck* instruction) : SlowPathCodeMIPS64(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700111
112 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100113 LocationSummary* locations = instruction_->GetLocations();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700114 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
115 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000116 if (instruction_->CanThrowIntoCatchBlock()) {
117 // Live registers will be restored in the catch block if caught.
118 SaveLiveRegisters(codegen, instruction_->GetLocations());
119 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700120 // We're moving two locations to locations that could overlap, so we need a parallel
121 // move resolver.
122 InvokeRuntimeCallingConvention calling_convention;
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100123 codegen->EmitParallelMoves(locations->InAt(0),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700124 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
125 Primitive::kPrimInt,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100126 locations->InAt(1),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700127 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
128 Primitive::kPrimInt);
Serban Constantinescufc734082016-07-19 17:18:07 +0100129 QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt()
130 ? kQuickThrowStringBounds
131 : kQuickThrowArrayBounds;
132 mips64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100133 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700134 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
135 }
136
Alexandre Rames8158f282015-08-07 10:26:17 +0100137 bool IsFatal() const OVERRIDE { return true; }
138
Roland Levillain46648892015-06-19 16:07:18 +0100139 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS64"; }
140
Alexey Frunze4dda3372015-06-01 18:31:49 -0700141 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700142 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS64);
143};
144
145class DivZeroCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
146 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000147 explicit DivZeroCheckSlowPathMIPS64(HDivZeroCheck* instruction) : SlowPathCodeMIPS64(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700148
149 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
150 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
151 __ Bind(GetEntryLabel());
Serban Constantinescufc734082016-07-19 17:18:07 +0100152 mips64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700153 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
154 }
155
Alexandre Rames8158f282015-08-07 10:26:17 +0100156 bool IsFatal() const OVERRIDE { return true; }
157
Roland Levillain46648892015-06-19 16:07:18 +0100158 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS64"; }
159
Alexey Frunze4dda3372015-06-01 18:31:49 -0700160 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700161 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS64);
162};
163
164class LoadClassSlowPathMIPS64 : public SlowPathCodeMIPS64 {
165 public:
166 LoadClassSlowPathMIPS64(HLoadClass* cls,
167 HInstruction* at,
168 uint32_t dex_pc,
169 bool do_clinit)
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000170 : SlowPathCodeMIPS64(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700171 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
172 }
173
174 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000175 LocationSummary* locations = instruction_->GetLocations();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700176 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
177
178 __ Bind(GetEntryLabel());
179 SaveLiveRegisters(codegen, locations);
180
181 InvokeRuntimeCallingConvention calling_convention;
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000182 dex::TypeIndex type_index = cls_->GetTypeIndex();
183 __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_);
Serban Constantinescufc734082016-07-19 17:18:07 +0100184 QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage
185 : kQuickInitializeType;
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000186 mips64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700187 if (do_clinit_) {
188 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
189 } else {
190 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
191 }
192
193 // Move the class to the desired location.
194 Location out = locations->Out();
195 if (out.IsValid()) {
196 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000197 Primitive::Type type = instruction_->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700198 mips64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
199 }
200
201 RestoreLiveRegisters(codegen, locations);
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000202 // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry.
203 DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_);
204 if (cls_ == instruction_ && cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) {
205 DCHECK(out.IsValid());
206 // TODO: Change art_quick_initialize_type/art_quick_initialize_static_storage to
207 // kSaveEverything and use a temporary for the .bss entry address in the fast path,
208 // so that we can avoid another calculation here.
209 DCHECK_NE(out.AsRegister<GpuRegister>(), AT);
210 CodeGeneratorMIPS64::PcRelativePatchInfo* info =
Vladimir Marko1998cd02017-01-13 13:02:58 +0000211 mips64_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index);
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000212 mips64_codegen->EmitPcRelativeAddressPlaceholderHigh(info, AT);
213 __ Sw(out.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678);
214 }
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700215 __ Bc(GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700216 }
217
Roland Levillain46648892015-06-19 16:07:18 +0100218 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS64"; }
219
Alexey Frunze4dda3372015-06-01 18:31:49 -0700220 private:
221 // The class this slow path will load.
222 HLoadClass* const cls_;
223
Alexey Frunze4dda3372015-06-01 18:31:49 -0700224 // The dex PC of `at_`.
225 const uint32_t dex_pc_;
226
227 // Whether to initialize the class.
228 const bool do_clinit_;
229
230 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS64);
231};
232
233class LoadStringSlowPathMIPS64 : public SlowPathCodeMIPS64 {
234 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000235 explicit LoadStringSlowPathMIPS64(HLoadString* instruction) : SlowPathCodeMIPS64(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700236
237 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
238 LocationSummary* locations = instruction_->GetLocations();
239 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
240 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
241
242 __ Bind(GetEntryLabel());
243 SaveLiveRegisters(codegen, locations);
244
245 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunzef63f5692016-12-13 17:43:11 -0800246 HLoadString* load = instruction_->AsLoadString();
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000247 const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex();
248 __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_);
Serban Constantinescufc734082016-07-19 17:18:07 +0100249 mips64_codegen->InvokeRuntime(kQuickResolveString,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700250 instruction_,
251 instruction_->GetDexPc(),
252 this);
253 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
254 Primitive::Type type = instruction_->GetType();
255 mips64_codegen->MoveLocation(locations->Out(),
256 calling_convention.GetReturnLocation(type),
257 type);
258
259 RestoreLiveRegisters(codegen, locations);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800260
261 // Store the resolved String to the BSS entry.
262 // TODO: Change art_quick_resolve_string to kSaveEverything and use a temporary for the
263 // .bss entry address in the fast path, so that we can avoid another calculation here.
264 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
265 DCHECK_NE(out, AT);
266 CodeGeneratorMIPS64::PcRelativePatchInfo* info =
267 mips64_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index);
268 mips64_codegen->EmitPcRelativeAddressPlaceholderHigh(info, AT);
269 __ Sw(out, AT, /* placeholder */ 0x5678);
270
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700271 __ Bc(GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700272 }
273
Roland Levillain46648892015-06-19 16:07:18 +0100274 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS64"; }
275
Alexey Frunze4dda3372015-06-01 18:31:49 -0700276 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700277 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS64);
278};
279
280class NullCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
281 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000282 explicit NullCheckSlowPathMIPS64(HNullCheck* instr) : SlowPathCodeMIPS64(instr) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700283
284 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
285 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
286 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000287 if (instruction_->CanThrowIntoCatchBlock()) {
288 // Live registers will be restored in the catch block if caught.
289 SaveLiveRegisters(codegen, instruction_->GetLocations());
290 }
Serban Constantinescufc734082016-07-19 17:18:07 +0100291 mips64_codegen->InvokeRuntime(kQuickThrowNullPointer,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700292 instruction_,
293 instruction_->GetDexPc(),
294 this);
295 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
296 }
297
Alexandre Rames8158f282015-08-07 10:26:17 +0100298 bool IsFatal() const OVERRIDE { return true; }
299
Roland Levillain46648892015-06-19 16:07:18 +0100300 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS64"; }
301
Alexey Frunze4dda3372015-06-01 18:31:49 -0700302 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700303 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS64);
304};
305
306class SuspendCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
307 public:
Roland Levillain3887c462015-08-12 18:15:42 +0100308 SuspendCheckSlowPathMIPS64(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000309 : SlowPathCodeMIPS64(instruction), successor_(successor) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700310
311 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
312 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
313 __ Bind(GetEntryLabel());
Serban Constantinescufc734082016-07-19 17:18:07 +0100314 mips64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700315 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700316 if (successor_ == nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700317 __ Bc(GetReturnLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700318 } else {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700319 __ Bc(mips64_codegen->GetLabelOf(successor_));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700320 }
321 }
322
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700323 Mips64Label* GetReturnLabel() {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700324 DCHECK(successor_ == nullptr);
325 return &return_label_;
326 }
327
Roland Levillain46648892015-06-19 16:07:18 +0100328 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS64"; }
329
Alexey Frunze4dda3372015-06-01 18:31:49 -0700330 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700331 // If not null, the block to branch to after the suspend check.
332 HBasicBlock* const successor_;
333
334 // If `successor_` is null, the label to branch to after the suspend check.
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700335 Mips64Label return_label_;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700336
337 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS64);
338};
339
340class TypeCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
341 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000342 explicit TypeCheckSlowPathMIPS64(HInstruction* instruction) : SlowPathCodeMIPS64(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700343
344 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
345 LocationSummary* locations = instruction_->GetLocations();
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800346
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100347 uint32_t dex_pc = instruction_->GetDexPc();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700348 DCHECK(instruction_->IsCheckCast()
349 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
350 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
351
352 __ Bind(GetEntryLabel());
353 SaveLiveRegisters(codegen, locations);
354
355 // We're moving two locations to locations that could overlap, so we need a parallel
356 // move resolver.
357 InvokeRuntimeCallingConvention calling_convention;
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800358 codegen->EmitParallelMoves(locations->InAt(0),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700359 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
360 Primitive::kPrimNot,
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800361 locations->InAt(1),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700362 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
363 Primitive::kPrimNot);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700364 if (instruction_->IsInstanceOf()) {
Serban Constantinescufc734082016-07-19 17:18:07 +0100365 mips64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this);
Mathieu Chartier9fd8c602016-11-14 14:38:53 -0800366 CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700367 Primitive::Type ret_type = instruction_->GetType();
368 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
369 mips64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700370 } else {
371 DCHECK(instruction_->IsCheckCast());
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800372 mips64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this);
373 CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700374 }
375
376 RestoreLiveRegisters(codegen, locations);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700377 __ Bc(GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700378 }
379
Roland Levillain46648892015-06-19 16:07:18 +0100380 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS64"; }
381
Alexey Frunze4dda3372015-06-01 18:31:49 -0700382 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700383 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS64);
384};
385
386class DeoptimizationSlowPathMIPS64 : public SlowPathCodeMIPS64 {
387 public:
Aart Bik42249c32016-01-07 15:33:50 -0800388 explicit DeoptimizationSlowPathMIPS64(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000389 : SlowPathCodeMIPS64(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700390
391 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800392 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700393 __ Bind(GetEntryLabel());
Serban Constantinescufc734082016-07-19 17:18:07 +0100394 mips64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000395 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700396 }
397
Roland Levillain46648892015-06-19 16:07:18 +0100398 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS64"; }
399
Alexey Frunze4dda3372015-06-01 18:31:49 -0700400 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700401 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64);
402};
403
404CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph,
405 const Mips64InstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100406 const CompilerOptions& compiler_options,
407 OptimizingCompilerStats* stats)
Alexey Frunze4dda3372015-06-01 18:31:49 -0700408 : CodeGenerator(graph,
409 kNumberOfGpuRegisters,
410 kNumberOfFpuRegisters,
Roland Levillain0d5a2812015-11-13 10:07:31 +0000411 /* number_of_register_pairs */ 0,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700412 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
413 arraysize(kCoreCalleeSaves)),
414 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
415 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +0100416 compiler_options,
417 stats),
Vladimir Marko225b6462015-09-28 12:17:40 +0100418 block_labels_(nullptr),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700419 location_builder_(graph, this),
420 instruction_visitor_(graph, this),
421 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +0100422 assembler_(graph->GetArena()),
Alexey Frunze19f6c692016-11-30 19:19:55 -0800423 isa_features_(isa_features),
Alexey Frunzef63f5692016-12-13 17:43:11 -0800424 uint32_literals_(std::less<uint32_t>(),
425 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze19f6c692016-11-30 19:19:55 -0800426 uint64_literals_(std::less<uint64_t>(),
427 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze19f6c692016-11-30 19:19:55 -0800428 pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunzef63f5692016-12-13 17:43:11 -0800429 boot_image_string_patches_(StringReferenceValueComparator(),
430 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
431 pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
432 boot_image_type_patches_(TypeReferenceValueComparator(),
433 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
434 pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko1998cd02017-01-13 13:02:58 +0000435 type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunzef63f5692016-12-13 17:43:11 -0800436 boot_image_address_patches_(std::less<uint32_t>(),
437 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700438 // Save RA (containing the return address) to mimic Quick.
439 AddAllocatedRegister(Location::RegisterLocation(RA));
440}
441
442#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100443// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
444#define __ down_cast<Mips64Assembler*>(GetAssembler())-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700445#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value()
Alexey Frunze4dda3372015-06-01 18:31:49 -0700446
447void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700448 // Ensure that we fix up branches.
449 __ FinalizeCode();
450
451 // Adjust native pc offsets in stack maps.
452 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800453 uint32_t old_position =
454 stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kMips64);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700455 uint32_t new_position = __ GetAdjustedPosition(old_position);
456 DCHECK_GE(new_position, old_position);
457 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
458 }
459
460 // Adjust pc offsets for the disassembly information.
461 if (disasm_info_ != nullptr) {
462 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
463 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
464 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
465 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
466 it.second.start = __ GetAdjustedPosition(it.second.start);
467 it.second.end = __ GetAdjustedPosition(it.second.end);
468 }
469 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
470 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
471 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
472 }
473 }
474
Alexey Frunze4dda3372015-06-01 18:31:49 -0700475 CodeGenerator::Finalize(allocator);
476}
477
478Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const {
479 return codegen_->GetAssembler();
480}
481
482void ParallelMoveResolverMIPS64::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +0100483 MoveOperands* move = moves_[index];
Alexey Frunze4dda3372015-06-01 18:31:49 -0700484 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
485}
486
487void ParallelMoveResolverMIPS64::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +0100488 MoveOperands* move = moves_[index];
Alexey Frunze4dda3372015-06-01 18:31:49 -0700489 codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType());
490}
491
492void ParallelMoveResolverMIPS64::RestoreScratch(int reg) {
493 // Pop reg
494 __ Ld(GpuRegister(reg), SP, 0);
Lazar Trsicd9672662015-09-03 17:33:01 +0200495 __ DecreaseFrameSize(kMips64DoublewordSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700496}
497
498void ParallelMoveResolverMIPS64::SpillScratch(int reg) {
499 // Push reg
Lazar Trsicd9672662015-09-03 17:33:01 +0200500 __ IncreaseFrameSize(kMips64DoublewordSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700501 __ Sd(GpuRegister(reg), SP, 0);
502}
503
504void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) {
505 LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord;
506 StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord;
507 // Allocate a scratch register other than TMP, if available.
508 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
509 // automatically unspilled when the scratch scope object is destroyed).
510 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
511 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
Lazar Trsicd9672662015-09-03 17:33:01 +0200512 int stack_offset = ensure_scratch.IsSpilled() ? kMips64DoublewordSize : 0;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700513 __ LoadFromOffset(load_type,
514 GpuRegister(ensure_scratch.GetRegister()),
515 SP,
516 index1 + stack_offset);
517 __ LoadFromOffset(load_type,
518 TMP,
519 SP,
520 index2 + stack_offset);
521 __ StoreToOffset(store_type,
522 GpuRegister(ensure_scratch.GetRegister()),
523 SP,
524 index2 + stack_offset);
525 __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset);
526}
527
528static dwarf::Reg DWARFReg(GpuRegister reg) {
529 return dwarf::Reg::Mips64Core(static_cast<int>(reg));
530}
531
David Srbeckyba702002016-02-01 18:15:29 +0000532static dwarf::Reg DWARFReg(FpuRegister reg) {
533 return dwarf::Reg::Mips64Fp(static_cast<int>(reg));
534}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700535
536void CodeGeneratorMIPS64::GenerateFrameEntry() {
537 __ Bind(&frame_entry_label_);
538
539 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips64) || !IsLeafMethod();
540
541 if (do_overflow_check) {
542 __ LoadFromOffset(kLoadWord,
543 ZERO,
544 SP,
545 -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips64)));
546 RecordPcInfo(nullptr, 0);
547 }
548
Alexey Frunze4dda3372015-06-01 18:31:49 -0700549 if (HasEmptyFrame()) {
550 return;
551 }
552
553 // Make sure the frame size isn't unreasonably large. Per the various APIs
554 // it looks like it should always be less than 2GB in size, which allows
555 // us using 32-bit signed offsets from the stack pointer.
556 if (GetFrameSize() > 0x7FFFFFFF)
557 LOG(FATAL) << "Stack frame larger than 2GB";
558
559 // Spill callee-saved registers.
560 // Note that their cumulative size is small and they can be indexed using
561 // 16-bit offsets.
562
563 // TODO: increment/decrement SP in one step instead of two or remove this comment.
564
565 uint32_t ofs = FrameEntrySpillSize();
566 __ IncreaseFrameSize(ofs);
567
568 for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) {
569 GpuRegister reg = kCoreCalleeSaves[i];
570 if (allocated_registers_.ContainsCoreRegister(reg)) {
Lazar Trsicd9672662015-09-03 17:33:01 +0200571 ofs -= kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700572 __ Sd(reg, SP, ofs);
573 __ cfi().RelOffset(DWARFReg(reg), ofs);
574 }
575 }
576
577 for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) {
578 FpuRegister reg = kFpuCalleeSaves[i];
579 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
Lazar Trsicd9672662015-09-03 17:33:01 +0200580 ofs -= kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700581 __ Sdc1(reg, SP, ofs);
David Srbeckyba702002016-02-01 18:15:29 +0000582 __ cfi().RelOffset(DWARFReg(reg), ofs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700583 }
584 }
585
586 // Allocate the rest of the frame and store the current method pointer
587 // at its end.
588
589 __ IncreaseFrameSize(GetFrameSize() - FrameEntrySpillSize());
590
Nicolas Geoffray96eeb4e2016-10-12 22:03:31 +0100591 // Save the current method if we need it. Note that we do not
592 // do this in HCurrentMethod, as the instruction might have been removed
593 // in the SSA graph.
594 if (RequiresCurrentMethod()) {
595 static_assert(IsInt<16>(kCurrentMethodStackOffset),
596 "kCurrentMethodStackOffset must fit into int16_t");
597 __ Sd(kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
598 }
Goran Jakovljevicc6418422016-12-05 16:31:55 +0100599
600 if (GetGraph()->HasShouldDeoptimizeFlag()) {
601 // Initialize should_deoptimize flag to 0.
602 __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag());
603 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700604}
605
606void CodeGeneratorMIPS64::GenerateFrameExit() {
607 __ cfi().RememberState();
608
Alexey Frunze4dda3372015-06-01 18:31:49 -0700609 if (!HasEmptyFrame()) {
610 // Deallocate the rest of the frame.
611
612 __ DecreaseFrameSize(GetFrameSize() - FrameEntrySpillSize());
613
614 // Restore callee-saved registers.
615 // Note that their cumulative size is small and they can be indexed using
616 // 16-bit offsets.
617
618 // TODO: increment/decrement SP in one step instead of two or remove this comment.
619
620 uint32_t ofs = 0;
621
622 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
623 FpuRegister reg = kFpuCalleeSaves[i];
624 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
625 __ Ldc1(reg, SP, ofs);
Lazar Trsicd9672662015-09-03 17:33:01 +0200626 ofs += kMips64DoublewordSize;
David Srbeckyba702002016-02-01 18:15:29 +0000627 __ cfi().Restore(DWARFReg(reg));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700628 }
629 }
630
631 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
632 GpuRegister reg = kCoreCalleeSaves[i];
633 if (allocated_registers_.ContainsCoreRegister(reg)) {
634 __ Ld(reg, SP, ofs);
Lazar Trsicd9672662015-09-03 17:33:01 +0200635 ofs += kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700636 __ cfi().Restore(DWARFReg(reg));
637 }
638 }
639
640 DCHECK_EQ(ofs, FrameEntrySpillSize());
641 __ DecreaseFrameSize(ofs);
642 }
643
644 __ Jr(RA);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700645 __ Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700646
647 __ cfi().RestoreState();
648 __ cfi().DefCFAOffset(GetFrameSize());
649}
650
651void CodeGeneratorMIPS64::Bind(HBasicBlock* block) {
652 __ Bind(GetLabelOf(block));
653}
654
655void CodeGeneratorMIPS64::MoveLocation(Location destination,
656 Location source,
Calin Juravlee460d1d2015-09-29 04:52:17 +0100657 Primitive::Type dst_type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700658 if (source.Equals(destination)) {
659 return;
660 }
661
662 // A valid move can always be inferred from the destination and source
663 // locations. When moving from and to a register, the argument type can be
664 // used to generate 32bit instead of 64bit moves.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100665 bool unspecified_type = (dst_type == Primitive::kPrimVoid);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700666 DCHECK_EQ(unspecified_type, false);
667
668 if (destination.IsRegister() || destination.IsFpuRegister()) {
669 if (unspecified_type) {
670 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
671 if (source.IsStackSlot() ||
672 (src_cst != nullptr && (src_cst->IsIntConstant()
673 || src_cst->IsFloatConstant()
674 || src_cst->IsNullConstant()))) {
675 // For stack slots and 32bit constants, a 64bit type is appropriate.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100676 dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700677 } else {
678 // If the source is a double stack slot or a 64bit constant, a 64bit
679 // type is appropriate. Else the source is a register, and since the
680 // type has not been specified, we chose a 64bit type to force a 64bit
681 // move.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100682 dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700683 }
684 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100685 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) ||
686 (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type)));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700687 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
688 // Move to GPR/FPR from stack
689 LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword;
Calin Juravlee460d1d2015-09-29 04:52:17 +0100690 if (Primitive::IsFloatingPointType(dst_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700691 __ LoadFpuFromOffset(load_type,
692 destination.AsFpuRegister<FpuRegister>(),
693 SP,
694 source.GetStackIndex());
695 } else {
696 // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot.
697 __ LoadFromOffset(load_type,
698 destination.AsRegister<GpuRegister>(),
699 SP,
700 source.GetStackIndex());
701 }
702 } else if (source.IsConstant()) {
703 // Move to GPR/FPR from constant
704 GpuRegister gpr = AT;
Calin Juravlee460d1d2015-09-29 04:52:17 +0100705 if (!Primitive::IsFloatingPointType(dst_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700706 gpr = destination.AsRegister<GpuRegister>();
707 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100708 if (dst_type == Primitive::kPrimInt || dst_type == Primitive::kPrimFloat) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700709 int32_t value = GetInt32ValueOf(source.GetConstant()->AsConstant());
710 if (Primitive::IsFloatingPointType(dst_type) && value == 0) {
711 gpr = ZERO;
712 } else {
713 __ LoadConst32(gpr, value);
714 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700715 } else {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700716 int64_t value = GetInt64ValueOf(source.GetConstant()->AsConstant());
717 if (Primitive::IsFloatingPointType(dst_type) && value == 0) {
718 gpr = ZERO;
719 } else {
720 __ LoadConst64(gpr, value);
721 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700722 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100723 if (dst_type == Primitive::kPrimFloat) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700724 __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>());
Calin Juravlee460d1d2015-09-29 04:52:17 +0100725 } else if (dst_type == Primitive::kPrimDouble) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700726 __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>());
727 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100728 } else if (source.IsRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700729 if (destination.IsRegister()) {
730 // Move to GPR from GPR
731 __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>());
732 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100733 DCHECK(destination.IsFpuRegister());
734 if (Primitive::Is64BitType(dst_type)) {
735 __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>());
736 } else {
737 __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>());
738 }
739 }
740 } else if (source.IsFpuRegister()) {
741 if (destination.IsFpuRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700742 // Move to FPR from FPR
Calin Juravlee460d1d2015-09-29 04:52:17 +0100743 if (dst_type == Primitive::kPrimFloat) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700744 __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
745 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100746 DCHECK_EQ(dst_type, Primitive::kPrimDouble);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700747 __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
748 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100749 } else {
750 DCHECK(destination.IsRegister());
751 if (Primitive::Is64BitType(dst_type)) {
752 __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>());
753 } else {
754 __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>());
755 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700756 }
757 }
758 } else { // The destination is not a register. It must be a stack slot.
759 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
760 if (source.IsRegister() || source.IsFpuRegister()) {
761 if (unspecified_type) {
762 if (source.IsRegister()) {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100763 dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700764 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100765 dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700766 }
767 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100768 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) &&
769 (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type)));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700770 // Move to stack from GPR/FPR
771 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
772 if (source.IsRegister()) {
773 __ StoreToOffset(store_type,
774 source.AsRegister<GpuRegister>(),
775 SP,
776 destination.GetStackIndex());
777 } else {
778 __ StoreFpuToOffset(store_type,
779 source.AsFpuRegister<FpuRegister>(),
780 SP,
781 destination.GetStackIndex());
782 }
783 } else if (source.IsConstant()) {
784 // Move to stack from constant
785 HConstant* src_cst = source.GetConstant();
786 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700787 GpuRegister gpr = ZERO;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700788 if (destination.IsStackSlot()) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700789 int32_t value = GetInt32ValueOf(src_cst->AsConstant());
790 if (value != 0) {
791 gpr = TMP;
792 __ LoadConst32(gpr, value);
793 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700794 } else {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700795 DCHECK(destination.IsDoubleStackSlot());
796 int64_t value = GetInt64ValueOf(src_cst->AsConstant());
797 if (value != 0) {
798 gpr = TMP;
799 __ LoadConst64(gpr, value);
800 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700801 }
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700802 __ StoreToOffset(store_type, gpr, SP, destination.GetStackIndex());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700803 } else {
804 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
805 DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot());
806 // Move to stack from stack
807 if (destination.IsStackSlot()) {
808 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
809 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
810 } else {
811 __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex());
812 __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex());
813 }
814 }
815 }
816}
817
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700818void CodeGeneratorMIPS64::SwapLocations(Location loc1, Location loc2, Primitive::Type type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700819 DCHECK(!loc1.IsConstant());
820 DCHECK(!loc2.IsConstant());
821
822 if (loc1.Equals(loc2)) {
823 return;
824 }
825
826 bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot();
827 bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot();
828 bool is_fp_reg1 = loc1.IsFpuRegister();
829 bool is_fp_reg2 = loc2.IsFpuRegister();
830
831 if (loc2.IsRegister() && loc1.IsRegister()) {
832 // Swap 2 GPRs
833 GpuRegister r1 = loc1.AsRegister<GpuRegister>();
834 GpuRegister r2 = loc2.AsRegister<GpuRegister>();
835 __ Move(TMP, r2);
836 __ Move(r2, r1);
837 __ Move(r1, TMP);
838 } else if (is_fp_reg2 && is_fp_reg1) {
839 // Swap 2 FPRs
840 FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>();
841 FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>();
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700842 if (type == Primitive::kPrimFloat) {
843 __ MovS(FTMP, r1);
844 __ MovS(r1, r2);
845 __ MovS(r2, FTMP);
846 } else {
847 DCHECK_EQ(type, Primitive::kPrimDouble);
848 __ MovD(FTMP, r1);
849 __ MovD(r1, r2);
850 __ MovD(r2, FTMP);
851 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700852 } else if (is_slot1 != is_slot2) {
853 // Swap GPR/FPR and stack slot
854 Location reg_loc = is_slot1 ? loc2 : loc1;
855 Location mem_loc = is_slot1 ? loc1 : loc2;
856 LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword;
857 StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword;
858 // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot.
859 __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex());
860 if (reg_loc.IsFpuRegister()) {
861 __ StoreFpuToOffset(store_type,
862 reg_loc.AsFpuRegister<FpuRegister>(),
863 SP,
864 mem_loc.GetStackIndex());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700865 if (mem_loc.IsStackSlot()) {
866 __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
867 } else {
868 DCHECK(mem_loc.IsDoubleStackSlot());
869 __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
870 }
871 } else {
872 __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex());
873 __ Move(reg_loc.AsRegister<GpuRegister>(), TMP);
874 }
875 } else if (is_slot1 && is_slot2) {
876 move_resolver_.Exchange(loc1.GetStackIndex(),
877 loc2.GetStackIndex(),
878 loc1.IsDoubleStackSlot());
879 } else {
880 LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2;
881 }
882}
883
Calin Juravle175dc732015-08-25 15:42:32 +0100884void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) {
885 DCHECK(location.IsRegister());
886 __ LoadConst32(location.AsRegister<GpuRegister>(), value);
887}
888
Calin Juravlee460d1d2015-09-29 04:52:17 +0100889void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) {
890 if (location.IsRegister()) {
891 locations->AddTemp(location);
892 } else {
893 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
894 }
895}
896
Goran Jakovljevic8ed18262016-01-22 13:01:00 +0100897void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object,
898 GpuRegister value,
899 bool value_can_be_null) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700900 Mips64Label done;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700901 GpuRegister card = AT;
902 GpuRegister temp = TMP;
Goran Jakovljevic8ed18262016-01-22 13:01:00 +0100903 if (value_can_be_null) {
904 __ Beqzc(value, &done);
905 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700906 __ LoadFromOffset(kLoadDoubleword,
907 card,
908 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -0700909 Thread::CardTableOffset<kMips64PointerSize>().Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700910 __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift);
911 __ Daddu(temp, card, temp);
912 __ Sb(card, temp, 0);
Goran Jakovljevic8ed18262016-01-22 13:01:00 +0100913 if (value_can_be_null) {
914 __ Bind(&done);
915 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700916}
917
Alexey Frunze19f6c692016-11-30 19:19:55 -0800918template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
919inline void CodeGeneratorMIPS64::EmitPcRelativeLinkerPatches(
920 const ArenaDeque<PcRelativePatchInfo>& infos,
921 ArenaVector<LinkerPatch>* linker_patches) {
922 for (const PcRelativePatchInfo& info : infos) {
923 const DexFile& dex_file = info.target_dex_file;
924 size_t offset_or_index = info.offset_or_index;
925 DCHECK(info.pc_rel_label.IsBound());
926 uint32_t pc_rel_offset = __ GetLabelLocation(&info.pc_rel_label);
927 linker_patches->push_back(Factory(pc_rel_offset, &dex_file, pc_rel_offset, offset_or_index));
928 }
929}
930
931void CodeGeneratorMIPS64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
932 DCHECK(linker_patches->empty());
933 size_t size =
Alexey Frunze19f6c692016-11-30 19:19:55 -0800934 pc_relative_dex_cache_patches_.size() +
Alexey Frunzef63f5692016-12-13 17:43:11 -0800935 pc_relative_string_patches_.size() +
936 pc_relative_type_patches_.size() +
Vladimir Marko1998cd02017-01-13 13:02:58 +0000937 type_bss_entry_patches_.size() +
Alexey Frunzef63f5692016-12-13 17:43:11 -0800938 boot_image_string_patches_.size() +
939 boot_image_type_patches_.size() +
940 boot_image_address_patches_.size();
Alexey Frunze19f6c692016-11-30 19:19:55 -0800941 linker_patches->reserve(size);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800942 EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_,
943 linker_patches);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800944 if (!GetCompilerOptions().IsBootImage()) {
Vladimir Marko1998cd02017-01-13 13:02:58 +0000945 DCHECK(pc_relative_type_patches_.empty());
Alexey Frunzef63f5692016-12-13 17:43:11 -0800946 EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_,
947 linker_patches);
948 } else {
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000949 EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_,
950 linker_patches);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800951 EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_,
952 linker_patches);
953 }
Vladimir Marko1998cd02017-01-13 13:02:58 +0000954 EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_,
955 linker_patches);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800956 for (const auto& entry : boot_image_string_patches_) {
957 const StringReference& target_string = entry.first;
958 Literal* literal = entry.second;
959 DCHECK(literal->GetLabel()->IsBound());
960 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
961 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
962 target_string.dex_file,
963 target_string.string_index.index_));
964 }
965 for (const auto& entry : boot_image_type_patches_) {
966 const TypeReference& target_type = entry.first;
967 Literal* literal = entry.second;
968 DCHECK(literal->GetLabel()->IsBound());
969 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
970 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
971 target_type.dex_file,
972 target_type.type_index.index_));
973 }
974 for (const auto& entry : boot_image_address_patches_) {
975 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
976 Literal* literal = entry.second;
977 DCHECK(literal->GetLabel()->IsBound());
978 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
979 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
980 }
Vladimir Marko1998cd02017-01-13 13:02:58 +0000981 DCHECK_EQ(size, linker_patches->size());
Alexey Frunzef63f5692016-12-13 17:43:11 -0800982}
983
984CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeStringPatch(
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000985 const DexFile& dex_file, dex::StringIndex string_index) {
986 return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800987}
988
989CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeTypePatch(
990 const DexFile& dex_file, dex::TypeIndex type_index) {
991 return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800992}
993
Vladimir Marko1998cd02017-01-13 13:02:58 +0000994CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewTypeBssEntryPatch(
995 const DexFile& dex_file, dex::TypeIndex type_index) {
996 return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_);
997}
998
Alexey Frunze19f6c692016-11-30 19:19:55 -0800999CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeDexCacheArrayPatch(
1000 const DexFile& dex_file, uint32_t element_offset) {
1001 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
1002}
1003
Alexey Frunze19f6c692016-11-30 19:19:55 -08001004CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativePatch(
1005 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
1006 patches->emplace_back(dex_file, offset_or_index);
1007 return &patches->back();
1008}
1009
Alexey Frunzef63f5692016-12-13 17:43:11 -08001010Literal* CodeGeneratorMIPS64::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
1011 return map->GetOrCreate(
1012 value,
1013 [this, value]() { return __ NewLiteral<uint32_t>(value); });
1014}
1015
Alexey Frunze19f6c692016-11-30 19:19:55 -08001016Literal* CodeGeneratorMIPS64::DeduplicateUint64Literal(uint64_t value) {
1017 return uint64_literals_.GetOrCreate(
1018 value,
1019 [this, value]() { return __ NewLiteral<uint64_t>(value); });
1020}
1021
1022Literal* CodeGeneratorMIPS64::DeduplicateMethodLiteral(MethodReference target_method,
1023 MethodToLiteralMap* map) {
1024 return map->GetOrCreate(
1025 target_method,
1026 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1027}
1028
Alexey Frunzef63f5692016-12-13 17:43:11 -08001029Literal* CodeGeneratorMIPS64::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
1030 dex::StringIndex string_index) {
1031 return boot_image_string_patches_.GetOrCreate(
1032 StringReference(&dex_file, string_index),
1033 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1034}
1035
1036Literal* CodeGeneratorMIPS64::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
1037 dex::TypeIndex type_index) {
1038 return boot_image_type_patches_.GetOrCreate(
1039 TypeReference(&dex_file, type_index),
1040 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1041}
1042
1043Literal* CodeGeneratorMIPS64::DeduplicateBootImageAddressLiteral(uint64_t address) {
1044 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
1045 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
1046 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
1047}
1048
Alexey Frunze19f6c692016-11-30 19:19:55 -08001049void CodeGeneratorMIPS64::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info,
1050 GpuRegister out) {
1051 __ Bind(&info->pc_rel_label);
1052 // Add the high half of a 32-bit offset to PC.
1053 __ Auipc(out, /* placeholder */ 0x1234);
1054 // The immediately following instruction will add the sign-extended low half of the 32-bit
Alexey Frunzef63f5692016-12-13 17:43:11 -08001055 // offset to `out` (e.g. ld, jialc, daddiu).
Alexey Frunze19f6c692016-11-30 19:19:55 -08001056}
1057
David Brazdil58282f42016-01-14 12:45:10 +00001058void CodeGeneratorMIPS64::SetupBlockedRegisters() const {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001059 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
1060 blocked_core_registers_[ZERO] = true;
1061 blocked_core_registers_[K0] = true;
1062 blocked_core_registers_[K1] = true;
1063 blocked_core_registers_[GP] = true;
1064 blocked_core_registers_[SP] = true;
1065 blocked_core_registers_[RA] = true;
1066
Lazar Trsicd9672662015-09-03 17:33:01 +02001067 // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch
1068 // registers (similar to how AT is used by MIPS assemblers).
Alexey Frunze4dda3372015-06-01 18:31:49 -07001069 blocked_core_registers_[AT] = true;
1070 blocked_core_registers_[TMP] = true;
Lazar Trsicd9672662015-09-03 17:33:01 +02001071 blocked_core_registers_[TMP2] = true;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001072 blocked_fpu_registers_[FTMP] = true;
1073
1074 // Reserve suspend and thread registers.
1075 blocked_core_registers_[S0] = true;
1076 blocked_core_registers_[TR] = true;
1077
1078 // Reserve T9 for function calls
1079 blocked_core_registers_[T9] = true;
1080
Goran Jakovljevic782be112016-06-21 12:39:04 +02001081 if (GetGraph()->IsDebuggable()) {
1082 // Stubs do not save callee-save floating point registers. If the graph
1083 // is debuggable, we need to deal with these registers differently. For
1084 // now, just block them.
1085 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1086 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1087 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001088 }
1089}
1090
Alexey Frunze4dda3372015-06-01 18:31:49 -07001091size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1092 __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index);
Lazar Trsicd9672662015-09-03 17:33:01 +02001093 return kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001094}
1095
1096size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1097 __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index);
Lazar Trsicd9672662015-09-03 17:33:01 +02001098 return kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001099}
1100
1101size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1102 __ StoreFpuToOffset(kStoreDoubleword, FpuRegister(reg_id), SP, stack_index);
Lazar Trsicd9672662015-09-03 17:33:01 +02001103 return kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001104}
1105
1106size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1107 __ LoadFpuFromOffset(kLoadDoubleword, FpuRegister(reg_id), SP, stack_index);
Lazar Trsicd9672662015-09-03 17:33:01 +02001108 return kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001109}
1110
1111void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdil9f0dece2015-09-21 18:20:26 +01001112 stream << GpuRegister(reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001113}
1114
1115void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdil9f0dece2015-09-21 18:20:26 +01001116 stream << FpuRegister(reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001117}
1118
Calin Juravle175dc732015-08-25 15:42:32 +01001119void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint,
Alexey Frunze4dda3372015-06-01 18:31:49 -07001120 HInstruction* instruction,
1121 uint32_t dex_pc,
1122 SlowPathCode* slow_path) {
Alexandre Rames91a65162016-09-19 13:54:30 +01001123 ValidateInvokeRuntime(entrypoint, instruction, slow_path);
Serban Constantinescufc734082016-07-19 17:18:07 +01001124 __ LoadFromOffset(kLoadDoubleword,
1125 T9,
1126 TR,
1127 GetThreadOffset<kMips64PointerSize>(entrypoint).Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001128 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001129 __ Nop();
Serban Constantinescufc734082016-07-19 17:18:07 +01001130 if (EntrypointRequiresStackMap(entrypoint)) {
1131 RecordPcInfo(instruction, dex_pc, slow_path);
1132 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001133}
1134
1135void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path,
1136 GpuRegister class_reg) {
1137 __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
1138 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
1139 __ Bltc(TMP, AT, slow_path->GetEntryLabel());
1140 // TODO: barrier needed?
1141 __ Bind(slow_path->GetExitLabel());
1142}
1143
1144void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1145 __ Sync(0); // only stype 0 is supported
1146}
1147
1148void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction,
1149 HBasicBlock* successor) {
1150 SuspendCheckSlowPathMIPS64* slow_path =
1151 new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS64(instruction, successor);
1152 codegen_->AddSlowPath(slow_path);
1153
1154 __ LoadFromOffset(kLoadUnsignedHalfword,
1155 TMP,
1156 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001157 Thread::ThreadFlagsOffset<kMips64PointerSize>().Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001158 if (successor == nullptr) {
1159 __ Bnezc(TMP, slow_path->GetEntryLabel());
1160 __ Bind(slow_path->GetReturnLabel());
1161 } else {
1162 __ Beqzc(TMP, codegen_->GetLabelOf(successor));
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001163 __ Bc(slow_path->GetEntryLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001164 // slow_path will return to GetLabelOf(successor).
1165 }
1166}
1167
1168InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph,
1169 CodeGeneratorMIPS64* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001170 : InstructionCodeGenerator(graph, codegen),
Alexey Frunze4dda3372015-06-01 18:31:49 -07001171 assembler_(codegen->GetAssembler()),
1172 codegen_(codegen) {}
1173
1174void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
1175 DCHECK_EQ(instruction->InputCount(), 2U);
1176 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1177 Primitive::Type type = instruction->GetResultType();
1178 switch (type) {
1179 case Primitive::kPrimInt:
1180 case Primitive::kPrimLong: {
1181 locations->SetInAt(0, Location::RequiresRegister());
1182 HInstruction* right = instruction->InputAt(1);
1183 bool can_use_imm = false;
1184 if (right->IsConstant()) {
1185 int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant());
1186 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1187 can_use_imm = IsUint<16>(imm);
1188 } else if (instruction->IsAdd()) {
1189 can_use_imm = IsInt<16>(imm);
1190 } else {
1191 DCHECK(instruction->IsSub());
1192 can_use_imm = IsInt<16>(-imm);
1193 }
1194 }
1195 if (can_use_imm)
1196 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1197 else
1198 locations->SetInAt(1, Location::RequiresRegister());
1199 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1200 }
1201 break;
1202
1203 case Primitive::kPrimFloat:
1204 case Primitive::kPrimDouble:
1205 locations->SetInAt(0, Location::RequiresFpuRegister());
1206 locations->SetInAt(1, Location::RequiresFpuRegister());
1207 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1208 break;
1209
1210 default:
1211 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1212 }
1213}
1214
1215void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
1216 Primitive::Type type = instruction->GetType();
1217 LocationSummary* locations = instruction->GetLocations();
1218
1219 switch (type) {
1220 case Primitive::kPrimInt:
1221 case Primitive::kPrimLong: {
1222 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1223 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1224 Location rhs_location = locations->InAt(1);
1225
1226 GpuRegister rhs_reg = ZERO;
1227 int64_t rhs_imm = 0;
1228 bool use_imm = rhs_location.IsConstant();
1229 if (use_imm) {
1230 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
1231 } else {
1232 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1233 }
1234
1235 if (instruction->IsAnd()) {
1236 if (use_imm)
1237 __ Andi(dst, lhs, rhs_imm);
1238 else
1239 __ And(dst, lhs, rhs_reg);
1240 } else if (instruction->IsOr()) {
1241 if (use_imm)
1242 __ Ori(dst, lhs, rhs_imm);
1243 else
1244 __ Or(dst, lhs, rhs_reg);
1245 } else if (instruction->IsXor()) {
1246 if (use_imm)
1247 __ Xori(dst, lhs, rhs_imm);
1248 else
1249 __ Xor(dst, lhs, rhs_reg);
1250 } else if (instruction->IsAdd()) {
1251 if (type == Primitive::kPrimInt) {
1252 if (use_imm)
1253 __ Addiu(dst, lhs, rhs_imm);
1254 else
1255 __ Addu(dst, lhs, rhs_reg);
1256 } else {
1257 if (use_imm)
1258 __ Daddiu(dst, lhs, rhs_imm);
1259 else
1260 __ Daddu(dst, lhs, rhs_reg);
1261 }
1262 } else {
1263 DCHECK(instruction->IsSub());
1264 if (type == Primitive::kPrimInt) {
1265 if (use_imm)
1266 __ Addiu(dst, lhs, -rhs_imm);
1267 else
1268 __ Subu(dst, lhs, rhs_reg);
1269 } else {
1270 if (use_imm)
1271 __ Daddiu(dst, lhs, -rhs_imm);
1272 else
1273 __ Dsubu(dst, lhs, rhs_reg);
1274 }
1275 }
1276 break;
1277 }
1278 case Primitive::kPrimFloat:
1279 case Primitive::kPrimDouble: {
1280 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
1281 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1282 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1283 if (instruction->IsAdd()) {
1284 if (type == Primitive::kPrimFloat)
1285 __ AddS(dst, lhs, rhs);
1286 else
1287 __ AddD(dst, lhs, rhs);
1288 } else if (instruction->IsSub()) {
1289 if (type == Primitive::kPrimFloat)
1290 __ SubS(dst, lhs, rhs);
1291 else
1292 __ SubD(dst, lhs, rhs);
1293 } else {
1294 LOG(FATAL) << "Unexpected floating-point binary operation";
1295 }
1296 break;
1297 }
1298 default:
1299 LOG(FATAL) << "Unexpected binary operation type " << type;
1300 }
1301}
1302
1303void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001304 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001305
1306 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1307 Primitive::Type type = instr->GetResultType();
1308 switch (type) {
1309 case Primitive::kPrimInt:
1310 case Primitive::kPrimLong: {
1311 locations->SetInAt(0, Location::RequiresRegister());
1312 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001313 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001314 break;
1315 }
1316 default:
1317 LOG(FATAL) << "Unexpected shift type " << type;
1318 }
1319}
1320
1321void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001322 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001323 LocationSummary* locations = instr->GetLocations();
1324 Primitive::Type type = instr->GetType();
1325
1326 switch (type) {
1327 case Primitive::kPrimInt:
1328 case Primitive::kPrimLong: {
1329 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1330 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1331 Location rhs_location = locations->InAt(1);
1332
1333 GpuRegister rhs_reg = ZERO;
1334 int64_t rhs_imm = 0;
1335 bool use_imm = rhs_location.IsConstant();
1336 if (use_imm) {
1337 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
1338 } else {
1339 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1340 }
1341
1342 if (use_imm) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00001343 uint32_t shift_value = rhs_imm &
1344 (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001345
Alexey Frunze92d90602015-12-18 18:16:36 -08001346 if (shift_value == 0) {
1347 if (dst != lhs) {
1348 __ Move(dst, lhs);
1349 }
1350 } else if (type == Primitive::kPrimInt) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001351 if (instr->IsShl()) {
1352 __ Sll(dst, lhs, shift_value);
1353 } else if (instr->IsShr()) {
1354 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001355 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001356 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001357 } else {
1358 __ Rotr(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001359 }
1360 } else {
1361 if (shift_value < 32) {
1362 if (instr->IsShl()) {
1363 __ Dsll(dst, lhs, shift_value);
1364 } else if (instr->IsShr()) {
1365 __ Dsra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001366 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001367 __ Dsrl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001368 } else {
1369 __ Drotr(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001370 }
1371 } else {
1372 shift_value -= 32;
1373 if (instr->IsShl()) {
1374 __ Dsll32(dst, lhs, shift_value);
1375 } else if (instr->IsShr()) {
1376 __ Dsra32(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001377 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001378 __ Dsrl32(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001379 } else {
1380 __ Drotr32(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001381 }
1382 }
1383 }
1384 } else {
1385 if (type == Primitive::kPrimInt) {
1386 if (instr->IsShl()) {
1387 __ Sllv(dst, lhs, rhs_reg);
1388 } else if (instr->IsShr()) {
1389 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001390 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001391 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001392 } else {
1393 __ Rotrv(dst, lhs, rhs_reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001394 }
1395 } else {
1396 if (instr->IsShl()) {
1397 __ Dsllv(dst, lhs, rhs_reg);
1398 } else if (instr->IsShr()) {
1399 __ Dsrav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001400 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001401 __ Dsrlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001402 } else {
1403 __ Drotrv(dst, lhs, rhs_reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001404 }
1405 }
1406 }
1407 break;
1408 }
1409 default:
1410 LOG(FATAL) << "Unexpected shift operation type " << type;
1411 }
1412}
1413
1414void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) {
1415 HandleBinaryOp(instruction);
1416}
1417
1418void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) {
1419 HandleBinaryOp(instruction);
1420}
1421
1422void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) {
1423 HandleBinaryOp(instruction);
1424}
1425
1426void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) {
1427 HandleBinaryOp(instruction);
1428}
1429
1430void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) {
1431 LocationSummary* locations =
1432 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1433 locations->SetInAt(0, Location::RequiresRegister());
1434 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1435 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1436 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1437 } else {
1438 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1439 }
1440}
1441
1442void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) {
1443 LocationSummary* locations = instruction->GetLocations();
1444 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1445 Location index = locations->InAt(1);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001446 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001447
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001448 Primitive::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001449 switch (type) {
1450 case Primitive::kPrimBoolean: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001451 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1452 if (index.IsConstant()) {
1453 size_t offset =
1454 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1455 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1456 } else {
1457 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1458 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset);
1459 }
1460 break;
1461 }
1462
1463 case Primitive::kPrimByte: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001464 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1465 if (index.IsConstant()) {
1466 size_t offset =
1467 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1468 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1469 } else {
1470 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1471 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset);
1472 }
1473 break;
1474 }
1475
1476 case Primitive::kPrimShort: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001477 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1478 if (index.IsConstant()) {
1479 size_t offset =
1480 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1481 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1482 } else {
1483 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1484 __ Daddu(TMP, obj, TMP);
1485 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset);
1486 }
1487 break;
1488 }
1489
1490 case Primitive::kPrimChar: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001491 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1492 if (index.IsConstant()) {
1493 size_t offset =
1494 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1495 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1496 } else {
1497 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1498 __ Daddu(TMP, obj, TMP);
1499 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset);
1500 }
1501 break;
1502 }
1503
1504 case Primitive::kPrimInt:
1505 case Primitive::kPrimNot: {
1506 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
Alexey Frunze4dda3372015-06-01 18:31:49 -07001507 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1508 LoadOperandType load_type = (type == Primitive::kPrimNot) ? kLoadUnsignedWord : kLoadWord;
1509 if (index.IsConstant()) {
1510 size_t offset =
1511 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1512 __ LoadFromOffset(load_type, out, obj, offset);
1513 } else {
1514 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1515 __ Daddu(TMP, obj, TMP);
1516 __ LoadFromOffset(load_type, out, TMP, data_offset);
1517 }
1518 break;
1519 }
1520
1521 case Primitive::kPrimLong: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001522 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1523 if (index.IsConstant()) {
1524 size_t offset =
1525 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1526 __ LoadFromOffset(kLoadDoubleword, out, obj, offset);
1527 } else {
1528 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1529 __ Daddu(TMP, obj, TMP);
1530 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset);
1531 }
1532 break;
1533 }
1534
1535 case Primitive::kPrimFloat: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001536 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
1537 if (index.IsConstant()) {
1538 size_t offset =
1539 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1540 __ LoadFpuFromOffset(kLoadWord, out, obj, offset);
1541 } else {
1542 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1543 __ Daddu(TMP, obj, TMP);
1544 __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset);
1545 }
1546 break;
1547 }
1548
1549 case Primitive::kPrimDouble: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001550 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
1551 if (index.IsConstant()) {
1552 size_t offset =
1553 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1554 __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset);
1555 } else {
1556 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1557 __ Daddu(TMP, obj, TMP);
1558 __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset);
1559 }
1560 break;
1561 }
1562
1563 case Primitive::kPrimVoid:
1564 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1565 UNREACHABLE();
1566 }
1567 codegen_->MaybeRecordImplicitNullCheck(instruction);
1568}
1569
1570void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) {
1571 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1572 locations->SetInAt(0, Location::RequiresRegister());
1573 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1574}
1575
1576void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) {
1577 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01001578 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001579 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1580 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1581 __ LoadFromOffset(kLoadWord, out, obj, offset);
1582 codegen_->MaybeRecordImplicitNullCheck(instruction);
1583}
1584
1585void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) {
David Brazdilbb3d5052015-09-21 18:39:16 +01001586 bool needs_runtime_call = instruction->NeedsTypeCheck();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001587 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1588 instruction,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001589 needs_runtime_call ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
David Brazdilbb3d5052015-09-21 18:39:16 +01001590 if (needs_runtime_call) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001591 InvokeRuntimeCallingConvention calling_convention;
1592 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1593 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1594 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1595 } else {
1596 locations->SetInAt(0, Location::RequiresRegister());
1597 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1598 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
1599 locations->SetInAt(2, Location::RequiresFpuRegister());
1600 } else {
1601 locations->SetInAt(2, Location::RequiresRegister());
1602 }
1603 }
1604}
1605
1606void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) {
1607 LocationSummary* locations = instruction->GetLocations();
1608 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1609 Location index = locations->InAt(1);
1610 Primitive::Type value_type = instruction->GetComponentType();
1611 bool needs_runtime_call = locations->WillCall();
1612 bool needs_write_barrier =
1613 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
1614
1615 switch (value_type) {
1616 case Primitive::kPrimBoolean:
1617 case Primitive::kPrimByte: {
1618 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1619 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1620 if (index.IsConstant()) {
1621 size_t offset =
1622 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1623 __ StoreToOffset(kStoreByte, value, obj, offset);
1624 } else {
1625 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1626 __ StoreToOffset(kStoreByte, value, TMP, data_offset);
1627 }
1628 break;
1629 }
1630
1631 case Primitive::kPrimShort:
1632 case Primitive::kPrimChar: {
1633 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
1634 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1635 if (index.IsConstant()) {
1636 size_t offset =
1637 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1638 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1639 } else {
1640 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1641 __ Daddu(TMP, obj, TMP);
1642 __ StoreToOffset(kStoreHalfword, value, TMP, data_offset);
1643 }
1644 break;
1645 }
1646
1647 case Primitive::kPrimInt:
1648 case Primitive::kPrimNot: {
1649 if (!needs_runtime_call) {
1650 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
1651 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1652 if (index.IsConstant()) {
1653 size_t offset =
1654 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1655 __ StoreToOffset(kStoreWord, value, obj, offset);
1656 } else {
1657 DCHECK(index.IsRegister()) << index;
1658 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1659 __ Daddu(TMP, obj, TMP);
1660 __ StoreToOffset(kStoreWord, value, TMP, data_offset);
1661 }
1662 codegen_->MaybeRecordImplicitNullCheck(instruction);
1663 if (needs_write_barrier) {
1664 DCHECK_EQ(value_type, Primitive::kPrimNot);
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01001665 codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001666 }
1667 } else {
1668 DCHECK_EQ(value_type, Primitive::kPrimNot);
Serban Constantinescufc734082016-07-19 17:18:07 +01001669 codegen_->InvokeRuntime(kQuickAputObject, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00001670 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001671 }
1672 break;
1673 }
1674
1675 case Primitive::kPrimLong: {
1676 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
1677 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1678 if (index.IsConstant()) {
1679 size_t offset =
1680 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1681 __ StoreToOffset(kStoreDoubleword, value, obj, offset);
1682 } else {
1683 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1684 __ Daddu(TMP, obj, TMP);
1685 __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset);
1686 }
1687 break;
1688 }
1689
1690 case Primitive::kPrimFloat: {
1691 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
1692 FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>();
1693 DCHECK(locations->InAt(2).IsFpuRegister());
1694 if (index.IsConstant()) {
1695 size_t offset =
1696 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1697 __ StoreFpuToOffset(kStoreWord, value, obj, offset);
1698 } else {
1699 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1700 __ Daddu(TMP, obj, TMP);
1701 __ StoreFpuToOffset(kStoreWord, value, TMP, data_offset);
1702 }
1703 break;
1704 }
1705
1706 case Primitive::kPrimDouble: {
1707 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
1708 FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>();
1709 DCHECK(locations->InAt(2).IsFpuRegister());
1710 if (index.IsConstant()) {
1711 size_t offset =
1712 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1713 __ StoreFpuToOffset(kStoreDoubleword, value, obj, offset);
1714 } else {
1715 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1716 __ Daddu(TMP, obj, TMP);
1717 __ StoreFpuToOffset(kStoreDoubleword, value, TMP, data_offset);
1718 }
1719 break;
1720 }
1721
1722 case Primitive::kPrimVoid:
1723 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1724 UNREACHABLE();
1725 }
1726
1727 // Ints and objects are handled in the switch.
1728 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
1729 codegen_->MaybeRecordImplicitNullCheck(instruction);
1730 }
1731}
1732
1733void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01001734 RegisterSet caller_saves = RegisterSet::Empty();
1735 InvokeRuntimeCallingConvention calling_convention;
1736 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1737 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1738 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001739 locations->SetInAt(0, Location::RequiresRegister());
1740 locations->SetInAt(1, Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001741}
1742
1743void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
1744 LocationSummary* locations = instruction->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01001745 BoundsCheckSlowPathMIPS64* slow_path =
1746 new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001747 codegen_->AddSlowPath(slow_path);
1748
1749 GpuRegister index = locations->InAt(0).AsRegister<GpuRegister>();
1750 GpuRegister length = locations->InAt(1).AsRegister<GpuRegister>();
1751
1752 // length is limited by the maximum positive signed 32-bit integer.
1753 // Unsigned comparison of length and index checks for index < 0
1754 // and for length <= index simultaneously.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001755 __ Bgeuc(index, length, slow_path->GetEntryLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001756}
1757
1758void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) {
1759 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1760 instruction,
1761 LocationSummary::kCallOnSlowPath);
1762 locations->SetInAt(0, Location::RequiresRegister());
1763 locations->SetInAt(1, Location::RequiresRegister());
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01001764 // Note that TypeCheckSlowPathMIPS64 uses this register too.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001765 locations->AddTemp(Location::RequiresRegister());
1766}
1767
1768void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) {
1769 LocationSummary* locations = instruction->GetLocations();
1770 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1771 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
1772 GpuRegister obj_cls = locations->GetTemp(0).AsRegister<GpuRegister>();
1773
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01001774 SlowPathCodeMIPS64* slow_path =
1775 new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001776 codegen_->AddSlowPath(slow_path);
1777
1778 // TODO: avoid this check if we know obj is not null.
1779 __ Beqzc(obj, slow_path->GetExitLabel());
1780 // Compare the class of `obj` with `cls`.
1781 __ LoadFromOffset(kLoadUnsignedWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value());
1782 __ Bnec(obj_cls, cls, slow_path->GetEntryLabel());
1783 __ Bind(slow_path->GetExitLabel());
1784}
1785
1786void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) {
1787 LocationSummary* locations =
1788 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1789 locations->SetInAt(0, Location::RequiresRegister());
1790 if (check->HasUses()) {
1791 locations->SetOut(Location::SameAsFirstInput());
1792 }
1793}
1794
1795void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) {
1796 // We assume the class is not null.
1797 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64(
1798 check->GetLoadClass(),
1799 check,
1800 check->GetDexPc(),
1801 true);
1802 codegen_->AddSlowPath(slow_path);
1803 GenerateClassInitializationCheck(slow_path,
1804 check->GetLocations()->InAt(0).AsRegister<GpuRegister>());
1805}
1806
1807void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) {
1808 Primitive::Type in_type = compare->InputAt(0)->GetType();
1809
Alexey Frunze299a9392015-12-08 16:08:02 -08001810 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(compare);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001811
1812 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00001813 case Primitive::kPrimBoolean:
1814 case Primitive::kPrimByte:
1815 case Primitive::kPrimShort:
1816 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08001817 case Primitive::kPrimInt:
Alexey Frunze4dda3372015-06-01 18:31:49 -07001818 case Primitive::kPrimLong:
1819 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001820 locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07001821 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1822 break;
1823
1824 case Primitive::kPrimFloat:
Alexey Frunze299a9392015-12-08 16:08:02 -08001825 case Primitive::kPrimDouble:
1826 locations->SetInAt(0, Location::RequiresFpuRegister());
1827 locations->SetInAt(1, Location::RequiresFpuRegister());
1828 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001829 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001830
1831 default:
1832 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1833 }
1834}
1835
1836void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) {
1837 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze299a9392015-12-08 16:08:02 -08001838 GpuRegister res = locations->Out().AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001839 Primitive::Type in_type = instruction->InputAt(0)->GetType();
1840
1841 // 0 if: left == right
1842 // 1 if: left > right
1843 // -1 if: left < right
1844 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00001845 case Primitive::kPrimBoolean:
1846 case Primitive::kPrimByte:
1847 case Primitive::kPrimShort:
1848 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08001849 case Primitive::kPrimInt:
Alexey Frunze4dda3372015-06-01 18:31:49 -07001850 case Primitive::kPrimLong: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001851 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001852 Location rhs_location = locations->InAt(1);
1853 bool use_imm = rhs_location.IsConstant();
1854 GpuRegister rhs = ZERO;
1855 if (use_imm) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00001856 if (in_type == Primitive::kPrimLong) {
Aart Bika19616e2016-02-01 18:57:58 -08001857 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
1858 if (value != 0) {
1859 rhs = AT;
1860 __ LoadConst64(rhs, value);
1861 }
Roland Levillaina5c4a402016-03-15 15:02:50 +00001862 } else {
1863 int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant());
1864 if (value != 0) {
1865 rhs = AT;
1866 __ LoadConst32(rhs, value);
1867 }
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001868 }
1869 } else {
1870 rhs = rhs_location.AsRegister<GpuRegister>();
1871 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001872 __ Slt(TMP, lhs, rhs);
Alexey Frunze299a9392015-12-08 16:08:02 -08001873 __ Slt(res, rhs, lhs);
1874 __ Subu(res, res, TMP);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001875 break;
1876 }
1877
Alexey Frunze299a9392015-12-08 16:08:02 -08001878 case Primitive::kPrimFloat: {
1879 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1880 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1881 Mips64Label done;
1882 __ CmpEqS(FTMP, lhs, rhs);
1883 __ LoadConst32(res, 0);
1884 __ Bc1nez(FTMP, &done);
Roland Levillain32ca3752016-02-17 16:49:37 +00001885 if (instruction->IsGtBias()) {
Alexey Frunze299a9392015-12-08 16:08:02 -08001886 __ CmpLtS(FTMP, lhs, rhs);
1887 __ LoadConst32(res, -1);
1888 __ Bc1nez(FTMP, &done);
1889 __ LoadConst32(res, 1);
1890 } else {
1891 __ CmpLtS(FTMP, rhs, lhs);
1892 __ LoadConst32(res, 1);
1893 __ Bc1nez(FTMP, &done);
1894 __ LoadConst32(res, -1);
1895 }
1896 __ Bind(&done);
1897 break;
1898 }
1899
Alexey Frunze4dda3372015-06-01 18:31:49 -07001900 case Primitive::kPrimDouble: {
Alexey Frunze299a9392015-12-08 16:08:02 -08001901 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1902 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1903 Mips64Label done;
1904 __ CmpEqD(FTMP, lhs, rhs);
1905 __ LoadConst32(res, 0);
1906 __ Bc1nez(FTMP, &done);
Roland Levillain32ca3752016-02-17 16:49:37 +00001907 if (instruction->IsGtBias()) {
Alexey Frunze299a9392015-12-08 16:08:02 -08001908 __ CmpLtD(FTMP, lhs, rhs);
1909 __ LoadConst32(res, -1);
1910 __ Bc1nez(FTMP, &done);
1911 __ LoadConst32(res, 1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001912 } else {
Alexey Frunze299a9392015-12-08 16:08:02 -08001913 __ CmpLtD(FTMP, rhs, lhs);
1914 __ LoadConst32(res, 1);
1915 __ Bc1nez(FTMP, &done);
1916 __ LoadConst32(res, -1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001917 }
Alexey Frunze299a9392015-12-08 16:08:02 -08001918 __ Bind(&done);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001919 break;
1920 }
1921
1922 default:
1923 LOG(FATAL) << "Unimplemented compare type " << in_type;
1924 }
1925}
1926
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001927void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001928 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexey Frunze299a9392015-12-08 16:08:02 -08001929 switch (instruction->InputAt(0)->GetType()) {
1930 default:
1931 case Primitive::kPrimLong:
1932 locations->SetInAt(0, Location::RequiresRegister());
1933 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1934 break;
1935
1936 case Primitive::kPrimFloat:
1937 case Primitive::kPrimDouble:
1938 locations->SetInAt(0, Location::RequiresFpuRegister());
1939 locations->SetInAt(1, Location::RequiresFpuRegister());
1940 break;
1941 }
David Brazdilb3e773e2016-01-26 11:28:37 +00001942 if (!instruction->IsEmittedAtUseSite()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001943 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1944 }
1945}
1946
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001947void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00001948 if (instruction->IsEmittedAtUseSite()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001949 return;
1950 }
1951
Alexey Frunze299a9392015-12-08 16:08:02 -08001952 Primitive::Type type = instruction->InputAt(0)->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001953 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze299a9392015-12-08 16:08:02 -08001954 switch (type) {
1955 default:
1956 // Integer case.
1957 GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations);
1958 return;
1959 case Primitive::kPrimLong:
1960 GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations);
1961 return;
Alexey Frunze299a9392015-12-08 16:08:02 -08001962 case Primitive::kPrimFloat:
1963 case Primitive::kPrimDouble:
Tijana Jakovljevic43758192016-12-30 09:23:01 +01001964 GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations);
1965 return;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001966 }
1967}
1968
Alexey Frunzec857c742015-09-23 15:12:39 -07001969void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
1970 DCHECK(instruction->IsDiv() || instruction->IsRem());
1971 Primitive::Type type = instruction->GetResultType();
1972
1973 LocationSummary* locations = instruction->GetLocations();
1974 Location second = locations->InAt(1);
1975 DCHECK(second.IsConstant());
1976
1977 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1978 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
1979 int64_t imm = Int64FromConstant(second.GetConstant());
1980 DCHECK(imm == 1 || imm == -1);
1981
1982 if (instruction->IsRem()) {
1983 __ Move(out, ZERO);
1984 } else {
1985 if (imm == -1) {
1986 if (type == Primitive::kPrimInt) {
1987 __ Subu(out, ZERO, dividend);
1988 } else {
1989 DCHECK_EQ(type, Primitive::kPrimLong);
1990 __ Dsubu(out, ZERO, dividend);
1991 }
1992 } else if (out != dividend) {
1993 __ Move(out, dividend);
1994 }
1995 }
1996}
1997
1998void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
1999 DCHECK(instruction->IsDiv() || instruction->IsRem());
2000 Primitive::Type type = instruction->GetResultType();
2001
2002 LocationSummary* locations = instruction->GetLocations();
2003 Location second = locations->InAt(1);
2004 DCHECK(second.IsConstant());
2005
2006 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2007 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
2008 int64_t imm = Int64FromConstant(second.GetConstant());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002009 uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm));
Alexey Frunzec857c742015-09-23 15:12:39 -07002010 int ctz_imm = CTZ(abs_imm);
2011
2012 if (instruction->IsDiv()) {
2013 if (type == Primitive::kPrimInt) {
2014 if (ctz_imm == 1) {
2015 // Fast path for division by +/-2, which is very common.
2016 __ Srl(TMP, dividend, 31);
2017 } else {
2018 __ Sra(TMP, dividend, 31);
2019 __ Srl(TMP, TMP, 32 - ctz_imm);
2020 }
2021 __ Addu(out, dividend, TMP);
2022 __ Sra(out, out, ctz_imm);
2023 if (imm < 0) {
2024 __ Subu(out, ZERO, out);
2025 }
2026 } else {
2027 DCHECK_EQ(type, Primitive::kPrimLong);
2028 if (ctz_imm == 1) {
2029 // Fast path for division by +/-2, which is very common.
2030 __ Dsrl32(TMP, dividend, 31);
2031 } else {
2032 __ Dsra32(TMP, dividend, 31);
2033 if (ctz_imm > 32) {
2034 __ Dsrl(TMP, TMP, 64 - ctz_imm);
2035 } else {
2036 __ Dsrl32(TMP, TMP, 32 - ctz_imm);
2037 }
2038 }
2039 __ Daddu(out, dividend, TMP);
2040 if (ctz_imm < 32) {
2041 __ Dsra(out, out, ctz_imm);
2042 } else {
2043 __ Dsra32(out, out, ctz_imm - 32);
2044 }
2045 if (imm < 0) {
2046 __ Dsubu(out, ZERO, out);
2047 }
2048 }
2049 } else {
2050 if (type == Primitive::kPrimInt) {
2051 if (ctz_imm == 1) {
2052 // Fast path for modulo +/-2, which is very common.
2053 __ Sra(TMP, dividend, 31);
2054 __ Subu(out, dividend, TMP);
2055 __ Andi(out, out, 1);
2056 __ Addu(out, out, TMP);
2057 } else {
2058 __ Sra(TMP, dividend, 31);
2059 __ Srl(TMP, TMP, 32 - ctz_imm);
2060 __ Addu(out, dividend, TMP);
2061 if (IsUint<16>(abs_imm - 1)) {
2062 __ Andi(out, out, abs_imm - 1);
2063 } else {
2064 __ Sll(out, out, 32 - ctz_imm);
2065 __ Srl(out, out, 32 - ctz_imm);
2066 }
2067 __ Subu(out, out, TMP);
2068 }
2069 } else {
2070 DCHECK_EQ(type, Primitive::kPrimLong);
2071 if (ctz_imm == 1) {
2072 // Fast path for modulo +/-2, which is very common.
2073 __ Dsra32(TMP, dividend, 31);
2074 __ Dsubu(out, dividend, TMP);
2075 __ Andi(out, out, 1);
2076 __ Daddu(out, out, TMP);
2077 } else {
2078 __ Dsra32(TMP, dividend, 31);
2079 if (ctz_imm > 32) {
2080 __ Dsrl(TMP, TMP, 64 - ctz_imm);
2081 } else {
2082 __ Dsrl32(TMP, TMP, 32 - ctz_imm);
2083 }
2084 __ Daddu(out, dividend, TMP);
2085 if (IsUint<16>(abs_imm - 1)) {
2086 __ Andi(out, out, abs_imm - 1);
2087 } else {
2088 if (ctz_imm > 32) {
2089 __ Dsll(out, out, 64 - ctz_imm);
2090 __ Dsrl(out, out, 64 - ctz_imm);
2091 } else {
2092 __ Dsll32(out, out, 32 - ctz_imm);
2093 __ Dsrl32(out, out, 32 - ctz_imm);
2094 }
2095 }
2096 __ Dsubu(out, out, TMP);
2097 }
2098 }
2099 }
2100}
2101
2102void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2103 DCHECK(instruction->IsDiv() || instruction->IsRem());
2104
2105 LocationSummary* locations = instruction->GetLocations();
2106 Location second = locations->InAt(1);
2107 DCHECK(second.IsConstant());
2108
2109 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2110 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
2111 int64_t imm = Int64FromConstant(second.GetConstant());
2112
2113 Primitive::Type type = instruction->GetResultType();
2114 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type;
2115
2116 int64_t magic;
2117 int shift;
2118 CalculateMagicAndShiftForDivRem(imm,
2119 (type == Primitive::kPrimLong),
2120 &magic,
2121 &shift);
2122
2123 if (type == Primitive::kPrimInt) {
2124 __ LoadConst32(TMP, magic);
2125 __ MuhR6(TMP, dividend, TMP);
2126
2127 if (imm > 0 && magic < 0) {
2128 __ Addu(TMP, TMP, dividend);
2129 } else if (imm < 0 && magic > 0) {
2130 __ Subu(TMP, TMP, dividend);
2131 }
2132
2133 if (shift != 0) {
2134 __ Sra(TMP, TMP, shift);
2135 }
2136
2137 if (instruction->IsDiv()) {
2138 __ Sra(out, TMP, 31);
2139 __ Subu(out, TMP, out);
2140 } else {
2141 __ Sra(AT, TMP, 31);
2142 __ Subu(AT, TMP, AT);
2143 __ LoadConst32(TMP, imm);
2144 __ MulR6(TMP, AT, TMP);
2145 __ Subu(out, dividend, TMP);
2146 }
2147 } else {
2148 __ LoadConst64(TMP, magic);
2149 __ Dmuh(TMP, dividend, TMP);
2150
2151 if (imm > 0 && magic < 0) {
2152 __ Daddu(TMP, TMP, dividend);
2153 } else if (imm < 0 && magic > 0) {
2154 __ Dsubu(TMP, TMP, dividend);
2155 }
2156
2157 if (shift >= 32) {
2158 __ Dsra32(TMP, TMP, shift - 32);
2159 } else if (shift > 0) {
2160 __ Dsra(TMP, TMP, shift);
2161 }
2162
2163 if (instruction->IsDiv()) {
2164 __ Dsra32(out, TMP, 31);
2165 __ Dsubu(out, TMP, out);
2166 } else {
2167 __ Dsra32(AT, TMP, 31);
2168 __ Dsubu(AT, TMP, AT);
2169 __ LoadConst64(TMP, imm);
2170 __ Dmul(TMP, AT, TMP);
2171 __ Dsubu(out, dividend, TMP);
2172 }
2173 }
2174}
2175
2176void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) {
2177 DCHECK(instruction->IsDiv() || instruction->IsRem());
2178 Primitive::Type type = instruction->GetResultType();
2179 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type;
2180
2181 LocationSummary* locations = instruction->GetLocations();
2182 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2183 Location second = locations->InAt(1);
2184
2185 if (second.IsConstant()) {
2186 int64_t imm = Int64FromConstant(second.GetConstant());
2187 if (imm == 0) {
2188 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2189 } else if (imm == 1 || imm == -1) {
2190 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002191 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunzec857c742015-09-23 15:12:39 -07002192 DivRemByPowerOfTwo(instruction);
2193 } else {
2194 DCHECK(imm <= -2 || imm >= 2);
2195 GenerateDivRemWithAnyConstant(instruction);
2196 }
2197 } else {
2198 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
2199 GpuRegister divisor = second.AsRegister<GpuRegister>();
2200 if (instruction->IsDiv()) {
2201 if (type == Primitive::kPrimInt)
2202 __ DivR6(out, dividend, divisor);
2203 else
2204 __ Ddiv(out, dividend, divisor);
2205 } else {
2206 if (type == Primitive::kPrimInt)
2207 __ ModR6(out, dividend, divisor);
2208 else
2209 __ Dmod(out, dividend, divisor);
2210 }
2211 }
2212}
2213
Alexey Frunze4dda3372015-06-01 18:31:49 -07002214void LocationsBuilderMIPS64::VisitDiv(HDiv* div) {
2215 LocationSummary* locations =
2216 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
2217 switch (div->GetResultType()) {
2218 case Primitive::kPrimInt:
2219 case Primitive::kPrimLong:
2220 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunzec857c742015-09-23 15:12:39 -07002221 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002222 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2223 break;
2224
2225 case Primitive::kPrimFloat:
2226 case Primitive::kPrimDouble:
2227 locations->SetInAt(0, Location::RequiresFpuRegister());
2228 locations->SetInAt(1, Location::RequiresFpuRegister());
2229 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2230 break;
2231
2232 default:
2233 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2234 }
2235}
2236
2237void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) {
2238 Primitive::Type type = instruction->GetType();
2239 LocationSummary* locations = instruction->GetLocations();
2240
2241 switch (type) {
2242 case Primitive::kPrimInt:
Alexey Frunzec857c742015-09-23 15:12:39 -07002243 case Primitive::kPrimLong:
2244 GenerateDivRemIntegral(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002245 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002246 case Primitive::kPrimFloat:
2247 case Primitive::kPrimDouble: {
2248 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2249 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
2250 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
2251 if (type == Primitive::kPrimFloat)
2252 __ DivS(dst, lhs, rhs);
2253 else
2254 __ DivD(dst, lhs, rhs);
2255 break;
2256 }
2257 default:
2258 LOG(FATAL) << "Unexpected div type " << type;
2259 }
2260}
2261
2262void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01002263 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002264 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002265}
2266
2267void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2268 SlowPathCodeMIPS64* slow_path =
2269 new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS64(instruction);
2270 codegen_->AddSlowPath(slow_path);
2271 Location value = instruction->GetLocations()->InAt(0);
2272
2273 Primitive::Type type = instruction->GetType();
2274
Nicolas Geoffraye5671612016-03-16 11:03:54 +00002275 if (!Primitive::IsIntegralType(type)) {
2276 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
Serguei Katkov8c0676c2015-08-03 13:55:33 +06002277 return;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002278 }
2279
2280 if (value.IsConstant()) {
2281 int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant());
2282 if (divisor == 0) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002283 __ Bc(slow_path->GetEntryLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002284 } else {
2285 // A division by a non-null constant is valid. We don't need to perform
2286 // any check, so simply fall through.
2287 }
2288 } else {
2289 __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
2290 }
2291}
2292
2293void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) {
2294 LocationSummary* locations =
2295 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2296 locations->SetOut(Location::ConstantLocation(constant));
2297}
2298
2299void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
2300 // Will be generated at use site.
2301}
2302
2303void LocationsBuilderMIPS64::VisitExit(HExit* exit) {
2304 exit->SetLocations(nullptr);
2305}
2306
2307void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
2308}
2309
2310void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) {
2311 LocationSummary* locations =
2312 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2313 locations->SetOut(Location::ConstantLocation(constant));
2314}
2315
2316void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
2317 // Will be generated at use site.
2318}
2319
David Brazdilfc6a86a2015-06-26 10:33:45 +00002320void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002321 DCHECK(!successor->IsExitBlock());
2322 HBasicBlock* block = got->GetBlock();
2323 HInstruction* previous = got->GetPrevious();
2324 HLoopInformation* info = block->GetLoopInformation();
2325
2326 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
2327 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
2328 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
2329 return;
2330 }
2331 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
2332 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
2333 }
2334 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002335 __ Bc(codegen_->GetLabelOf(successor));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002336 }
2337}
2338
David Brazdilfc6a86a2015-06-26 10:33:45 +00002339void LocationsBuilderMIPS64::VisitGoto(HGoto* got) {
2340 got->SetLocations(nullptr);
2341}
2342
2343void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) {
2344 HandleGoto(got, got->GetSuccessor());
2345}
2346
2347void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
2348 try_boundary->SetLocations(nullptr);
2349}
2350
2351void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
2352 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
2353 if (!successor->IsExitBlock()) {
2354 HandleGoto(try_boundary, successor);
2355 }
2356}
2357
Alexey Frunze299a9392015-12-08 16:08:02 -08002358void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond,
2359 bool is64bit,
2360 LocationSummary* locations) {
2361 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2362 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2363 Location rhs_location = locations->InAt(1);
2364 GpuRegister rhs_reg = ZERO;
2365 int64_t rhs_imm = 0;
2366 bool use_imm = rhs_location.IsConstant();
2367 if (use_imm) {
2368 if (is64bit) {
2369 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
2370 } else {
2371 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2372 }
2373 } else {
2374 rhs_reg = rhs_location.AsRegister<GpuRegister>();
2375 }
2376 int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1);
2377
2378 switch (cond) {
2379 case kCondEQ:
2380 case kCondNE:
Goran Jakovljevicdb3deee2016-12-28 14:33:21 +01002381 if (use_imm && IsInt<16>(-rhs_imm)) {
2382 if (rhs_imm == 0) {
2383 if (cond == kCondEQ) {
2384 __ Sltiu(dst, lhs, 1);
2385 } else {
2386 __ Sltu(dst, ZERO, lhs);
2387 }
2388 } else {
2389 if (is64bit) {
2390 __ Daddiu(dst, lhs, -rhs_imm);
2391 } else {
2392 __ Addiu(dst, lhs, -rhs_imm);
2393 }
2394 if (cond == kCondEQ) {
2395 __ Sltiu(dst, dst, 1);
2396 } else {
2397 __ Sltu(dst, ZERO, dst);
2398 }
Alexey Frunze299a9392015-12-08 16:08:02 -08002399 }
Alexey Frunze299a9392015-12-08 16:08:02 -08002400 } else {
Goran Jakovljevicdb3deee2016-12-28 14:33:21 +01002401 if (use_imm && IsUint<16>(rhs_imm)) {
2402 __ Xori(dst, lhs, rhs_imm);
2403 } else {
2404 if (use_imm) {
2405 rhs_reg = TMP;
2406 __ LoadConst64(rhs_reg, rhs_imm);
2407 }
2408 __ Xor(dst, lhs, rhs_reg);
2409 }
2410 if (cond == kCondEQ) {
2411 __ Sltiu(dst, dst, 1);
2412 } else {
2413 __ Sltu(dst, ZERO, dst);
2414 }
Alexey Frunze299a9392015-12-08 16:08:02 -08002415 }
2416 break;
2417
2418 case kCondLT:
2419 case kCondGE:
2420 if (use_imm && IsInt<16>(rhs_imm)) {
2421 __ Slti(dst, lhs, rhs_imm);
2422 } else {
2423 if (use_imm) {
2424 rhs_reg = TMP;
2425 __ LoadConst64(rhs_reg, rhs_imm);
2426 }
2427 __ Slt(dst, lhs, rhs_reg);
2428 }
2429 if (cond == kCondGE) {
2430 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2431 // only the slt instruction but no sge.
2432 __ Xori(dst, dst, 1);
2433 }
2434 break;
2435
2436 case kCondLE:
2437 case kCondGT:
2438 if (use_imm && IsInt<16>(rhs_imm_plus_one)) {
2439 // Simulate lhs <= rhs via lhs < rhs + 1.
2440 __ Slti(dst, lhs, rhs_imm_plus_one);
2441 if (cond == kCondGT) {
2442 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2443 // only the slti instruction but no sgti.
2444 __ Xori(dst, dst, 1);
2445 }
2446 } else {
2447 if (use_imm) {
2448 rhs_reg = TMP;
2449 __ LoadConst64(rhs_reg, rhs_imm);
2450 }
2451 __ Slt(dst, rhs_reg, lhs);
2452 if (cond == kCondLE) {
2453 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2454 // only the slt instruction but no sle.
2455 __ Xori(dst, dst, 1);
2456 }
2457 }
2458 break;
2459
2460 case kCondB:
2461 case kCondAE:
2462 if (use_imm && IsInt<16>(rhs_imm)) {
2463 // Sltiu sign-extends its 16-bit immediate operand before
2464 // the comparison and thus lets us compare directly with
2465 // unsigned values in the ranges [0, 0x7fff] and
2466 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
2467 __ Sltiu(dst, lhs, rhs_imm);
2468 } else {
2469 if (use_imm) {
2470 rhs_reg = TMP;
2471 __ LoadConst64(rhs_reg, rhs_imm);
2472 }
2473 __ Sltu(dst, lhs, rhs_reg);
2474 }
2475 if (cond == kCondAE) {
2476 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2477 // only the sltu instruction but no sgeu.
2478 __ Xori(dst, dst, 1);
2479 }
2480 break;
2481
2482 case kCondBE:
2483 case kCondA:
2484 if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) {
2485 // Simulate lhs <= rhs via lhs < rhs + 1.
2486 // Note that this only works if rhs + 1 does not overflow
2487 // to 0, hence the check above.
2488 // Sltiu sign-extends its 16-bit immediate operand before
2489 // the comparison and thus lets us compare directly with
2490 // unsigned values in the ranges [0, 0x7fff] and
2491 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
2492 __ Sltiu(dst, lhs, rhs_imm_plus_one);
2493 if (cond == kCondA) {
2494 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2495 // only the sltiu instruction but no sgtiu.
2496 __ Xori(dst, dst, 1);
2497 }
2498 } else {
2499 if (use_imm) {
2500 rhs_reg = TMP;
2501 __ LoadConst64(rhs_reg, rhs_imm);
2502 }
2503 __ Sltu(dst, rhs_reg, lhs);
2504 if (cond == kCondBE) {
2505 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2506 // only the sltu instruction but no sleu.
2507 __ Xori(dst, dst, 1);
2508 }
2509 }
2510 break;
2511 }
2512}
2513
2514void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond,
2515 bool is64bit,
2516 LocationSummary* locations,
2517 Mips64Label* label) {
2518 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2519 Location rhs_location = locations->InAt(1);
2520 GpuRegister rhs_reg = ZERO;
2521 int64_t rhs_imm = 0;
2522 bool use_imm = rhs_location.IsConstant();
2523 if (use_imm) {
2524 if (is64bit) {
2525 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
2526 } else {
2527 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2528 }
2529 } else {
2530 rhs_reg = rhs_location.AsRegister<GpuRegister>();
2531 }
2532
2533 if (use_imm && rhs_imm == 0) {
2534 switch (cond) {
2535 case kCondEQ:
2536 case kCondBE: // <= 0 if zero
2537 __ Beqzc(lhs, label);
2538 break;
2539 case kCondNE:
2540 case kCondA: // > 0 if non-zero
2541 __ Bnezc(lhs, label);
2542 break;
2543 case kCondLT:
2544 __ Bltzc(lhs, label);
2545 break;
2546 case kCondGE:
2547 __ Bgezc(lhs, label);
2548 break;
2549 case kCondLE:
2550 __ Blezc(lhs, label);
2551 break;
2552 case kCondGT:
2553 __ Bgtzc(lhs, label);
2554 break;
2555 case kCondB: // always false
2556 break;
2557 case kCondAE: // always true
2558 __ Bc(label);
2559 break;
2560 }
2561 } else {
2562 if (use_imm) {
2563 rhs_reg = TMP;
2564 __ LoadConst64(rhs_reg, rhs_imm);
2565 }
2566 switch (cond) {
2567 case kCondEQ:
2568 __ Beqc(lhs, rhs_reg, label);
2569 break;
2570 case kCondNE:
2571 __ Bnec(lhs, rhs_reg, label);
2572 break;
2573 case kCondLT:
2574 __ Bltc(lhs, rhs_reg, label);
2575 break;
2576 case kCondGE:
2577 __ Bgec(lhs, rhs_reg, label);
2578 break;
2579 case kCondLE:
2580 __ Bgec(rhs_reg, lhs, label);
2581 break;
2582 case kCondGT:
2583 __ Bltc(rhs_reg, lhs, label);
2584 break;
2585 case kCondB:
2586 __ Bltuc(lhs, rhs_reg, label);
2587 break;
2588 case kCondAE:
2589 __ Bgeuc(lhs, rhs_reg, label);
2590 break;
2591 case kCondBE:
2592 __ Bgeuc(rhs_reg, lhs, label);
2593 break;
2594 case kCondA:
2595 __ Bltuc(rhs_reg, lhs, label);
2596 break;
2597 }
2598 }
2599}
2600
Tijana Jakovljevic43758192016-12-30 09:23:01 +01002601void InstructionCodeGeneratorMIPS64::GenerateFpCompare(IfCondition cond,
2602 bool gt_bias,
2603 Primitive::Type type,
2604 LocationSummary* locations) {
2605 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2606 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
2607 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
2608 if (type == Primitive::kPrimFloat) {
2609 switch (cond) {
2610 case kCondEQ:
2611 __ CmpEqS(FTMP, lhs, rhs);
2612 __ Mfc1(dst, FTMP);
2613 __ Andi(dst, dst, 1);
2614 break;
2615 case kCondNE:
2616 __ CmpEqS(FTMP, lhs, rhs);
2617 __ Mfc1(dst, FTMP);
2618 __ Addiu(dst, dst, 1);
2619 break;
2620 case kCondLT:
2621 if (gt_bias) {
2622 __ CmpLtS(FTMP, lhs, rhs);
2623 } else {
2624 __ CmpUltS(FTMP, lhs, rhs);
2625 }
2626 __ Mfc1(dst, FTMP);
2627 __ Andi(dst, dst, 1);
2628 break;
2629 case kCondLE:
2630 if (gt_bias) {
2631 __ CmpLeS(FTMP, lhs, rhs);
2632 } else {
2633 __ CmpUleS(FTMP, lhs, rhs);
2634 }
2635 __ Mfc1(dst, FTMP);
2636 __ Andi(dst, dst, 1);
2637 break;
2638 case kCondGT:
2639 if (gt_bias) {
2640 __ CmpUltS(FTMP, rhs, lhs);
2641 } else {
2642 __ CmpLtS(FTMP, rhs, lhs);
2643 }
2644 __ Mfc1(dst, FTMP);
2645 __ Andi(dst, dst, 1);
2646 break;
2647 case kCondGE:
2648 if (gt_bias) {
2649 __ CmpUleS(FTMP, rhs, lhs);
2650 } else {
2651 __ CmpLeS(FTMP, rhs, lhs);
2652 }
2653 __ Mfc1(dst, FTMP);
2654 __ Andi(dst, dst, 1);
2655 break;
2656 default:
2657 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
2658 UNREACHABLE();
2659 }
2660 } else {
2661 DCHECK_EQ(type, Primitive::kPrimDouble);
2662 switch (cond) {
2663 case kCondEQ:
2664 __ CmpEqD(FTMP, lhs, rhs);
2665 __ Mfc1(dst, FTMP);
2666 __ Andi(dst, dst, 1);
2667 break;
2668 case kCondNE:
2669 __ CmpEqD(FTMP, lhs, rhs);
2670 __ Mfc1(dst, FTMP);
2671 __ Addiu(dst, dst, 1);
2672 break;
2673 case kCondLT:
2674 if (gt_bias) {
2675 __ CmpLtD(FTMP, lhs, rhs);
2676 } else {
2677 __ CmpUltD(FTMP, lhs, rhs);
2678 }
2679 __ Mfc1(dst, FTMP);
2680 __ Andi(dst, dst, 1);
2681 break;
2682 case kCondLE:
2683 if (gt_bias) {
2684 __ CmpLeD(FTMP, lhs, rhs);
2685 } else {
2686 __ CmpUleD(FTMP, lhs, rhs);
2687 }
2688 __ Mfc1(dst, FTMP);
2689 __ Andi(dst, dst, 1);
2690 break;
2691 case kCondGT:
2692 if (gt_bias) {
2693 __ CmpUltD(FTMP, rhs, lhs);
2694 } else {
2695 __ CmpLtD(FTMP, rhs, lhs);
2696 }
2697 __ Mfc1(dst, FTMP);
2698 __ Andi(dst, dst, 1);
2699 break;
2700 case kCondGE:
2701 if (gt_bias) {
2702 __ CmpUleD(FTMP, rhs, lhs);
2703 } else {
2704 __ CmpLeD(FTMP, rhs, lhs);
2705 }
2706 __ Mfc1(dst, FTMP);
2707 __ Andi(dst, dst, 1);
2708 break;
2709 default:
2710 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
2711 UNREACHABLE();
2712 }
2713 }
2714}
2715
Alexey Frunze299a9392015-12-08 16:08:02 -08002716void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond,
2717 bool gt_bias,
2718 Primitive::Type type,
2719 LocationSummary* locations,
2720 Mips64Label* label) {
2721 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
2722 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
2723 if (type == Primitive::kPrimFloat) {
2724 switch (cond) {
2725 case kCondEQ:
2726 __ CmpEqS(FTMP, lhs, rhs);
2727 __ Bc1nez(FTMP, label);
2728 break;
2729 case kCondNE:
2730 __ CmpEqS(FTMP, lhs, rhs);
2731 __ Bc1eqz(FTMP, label);
2732 break;
2733 case kCondLT:
2734 if (gt_bias) {
2735 __ CmpLtS(FTMP, lhs, rhs);
2736 } else {
2737 __ CmpUltS(FTMP, lhs, rhs);
2738 }
2739 __ Bc1nez(FTMP, label);
2740 break;
2741 case kCondLE:
2742 if (gt_bias) {
2743 __ CmpLeS(FTMP, lhs, rhs);
2744 } else {
2745 __ CmpUleS(FTMP, lhs, rhs);
2746 }
2747 __ Bc1nez(FTMP, label);
2748 break;
2749 case kCondGT:
2750 if (gt_bias) {
2751 __ CmpUltS(FTMP, rhs, lhs);
2752 } else {
2753 __ CmpLtS(FTMP, rhs, lhs);
2754 }
2755 __ Bc1nez(FTMP, label);
2756 break;
2757 case kCondGE:
2758 if (gt_bias) {
2759 __ CmpUleS(FTMP, rhs, lhs);
2760 } else {
2761 __ CmpLeS(FTMP, rhs, lhs);
2762 }
2763 __ Bc1nez(FTMP, label);
2764 break;
2765 default:
2766 LOG(FATAL) << "Unexpected non-floating-point condition";
2767 }
2768 } else {
2769 DCHECK_EQ(type, Primitive::kPrimDouble);
2770 switch (cond) {
2771 case kCondEQ:
2772 __ CmpEqD(FTMP, lhs, rhs);
2773 __ Bc1nez(FTMP, label);
2774 break;
2775 case kCondNE:
2776 __ CmpEqD(FTMP, lhs, rhs);
2777 __ Bc1eqz(FTMP, label);
2778 break;
2779 case kCondLT:
2780 if (gt_bias) {
2781 __ CmpLtD(FTMP, lhs, rhs);
2782 } else {
2783 __ CmpUltD(FTMP, lhs, rhs);
2784 }
2785 __ Bc1nez(FTMP, label);
2786 break;
2787 case kCondLE:
2788 if (gt_bias) {
2789 __ CmpLeD(FTMP, lhs, rhs);
2790 } else {
2791 __ CmpUleD(FTMP, lhs, rhs);
2792 }
2793 __ Bc1nez(FTMP, label);
2794 break;
2795 case kCondGT:
2796 if (gt_bias) {
2797 __ CmpUltD(FTMP, rhs, lhs);
2798 } else {
2799 __ CmpLtD(FTMP, rhs, lhs);
2800 }
2801 __ Bc1nez(FTMP, label);
2802 break;
2803 case kCondGE:
2804 if (gt_bias) {
2805 __ CmpUleD(FTMP, rhs, lhs);
2806 } else {
2807 __ CmpLeD(FTMP, rhs, lhs);
2808 }
2809 __ Bc1nez(FTMP, label);
2810 break;
2811 default:
2812 LOG(FATAL) << "Unexpected non-floating-point condition";
2813 }
2814 }
2815}
2816
Alexey Frunze4dda3372015-06-01 18:31:49 -07002817void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00002818 size_t condition_input_index,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002819 Mips64Label* true_target,
2820 Mips64Label* false_target) {
David Brazdil0debae72015-11-12 18:37:00 +00002821 HInstruction* cond = instruction->InputAt(condition_input_index);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002822
David Brazdil0debae72015-11-12 18:37:00 +00002823 if (true_target == nullptr && false_target == nullptr) {
2824 // Nothing to do. The code always falls through.
2825 return;
2826 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00002827 // Constant condition, statically compared against "true" (integer value 1).
2828 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00002829 if (true_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002830 __ Bc(true_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002831 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002832 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00002833 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00002834 if (false_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002835 __ Bc(false_target);
David Brazdil0debae72015-11-12 18:37:00 +00002836 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002837 }
David Brazdil0debae72015-11-12 18:37:00 +00002838 return;
2839 }
2840
2841 // The following code generates these patterns:
2842 // (1) true_target == nullptr && false_target != nullptr
2843 // - opposite condition true => branch to false_target
2844 // (2) true_target != nullptr && false_target == nullptr
2845 // - condition true => branch to true_target
2846 // (3) true_target != nullptr && false_target != nullptr
2847 // - condition true => branch to true_target
2848 // - branch to false_target
2849 if (IsBooleanValueOrMaterializedCondition(cond)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002850 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00002851 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002852 DCHECK(cond_val.IsRegister());
David Brazdil0debae72015-11-12 18:37:00 +00002853 if (true_target == nullptr) {
2854 __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target);
2855 } else {
2856 __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target);
2857 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002858 } else {
2859 // The condition instruction has not been materialized, use its inputs as
2860 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00002861 HCondition* condition = cond->AsCondition();
Alexey Frunze299a9392015-12-08 16:08:02 -08002862 Primitive::Type type = condition->InputAt(0)->GetType();
2863 LocationSummary* locations = cond->GetLocations();
2864 IfCondition if_cond = condition->GetCondition();
2865 Mips64Label* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00002866
David Brazdil0debae72015-11-12 18:37:00 +00002867 if (true_target == nullptr) {
2868 if_cond = condition->GetOppositeCondition();
Alexey Frunze299a9392015-12-08 16:08:02 -08002869 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00002870 }
2871
Alexey Frunze299a9392015-12-08 16:08:02 -08002872 switch (type) {
2873 default:
2874 GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target);
2875 break;
2876 case Primitive::kPrimLong:
2877 GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target);
2878 break;
2879 case Primitive::kPrimFloat:
2880 case Primitive::kPrimDouble:
2881 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
2882 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002883 }
2884 }
David Brazdil0debae72015-11-12 18:37:00 +00002885
2886 // If neither branch falls through (case 3), the conditional branch to `true_target`
2887 // was already emitted (case 2) and we need to emit a jump to `false_target`.
2888 if (true_target != nullptr && false_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002889 __ Bc(false_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002890 }
2891}
2892
2893void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) {
2894 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00002895 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002896 locations->SetInAt(0, Location::RequiresRegister());
2897 }
2898}
2899
2900void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00002901 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
2902 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002903 Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
David Brazdil0debae72015-11-12 18:37:00 +00002904 nullptr : codegen_->GetLabelOf(true_successor);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002905 Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
David Brazdil0debae72015-11-12 18:37:00 +00002906 nullptr : codegen_->GetLabelOf(false_successor);
2907 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002908}
2909
2910void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
2911 LocationSummary* locations = new (GetGraph()->GetArena())
2912 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
Vladimir Marko804b03f2016-09-14 16:26:36 +01002913 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
David Brazdil0debae72015-11-12 18:37:00 +00002914 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002915 locations->SetInAt(0, Location::RequiresRegister());
2916 }
2917}
2918
2919void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08002920 SlowPathCodeMIPS64* slow_path =
2921 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00002922 GenerateTestAndBranch(deoptimize,
2923 /* condition_input_index */ 0,
2924 slow_path->GetEntryLabel(),
2925 /* false_target */ nullptr);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002926}
2927
Goran Jakovljevicc6418422016-12-05 16:31:55 +01002928void LocationsBuilderMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
2929 LocationSummary* locations = new (GetGraph()->GetArena())
2930 LocationSummary(flag, LocationSummary::kNoCall);
2931 locations->SetOut(Location::RequiresRegister());
Mingyao Yang063fc772016-08-02 11:02:54 -07002932}
2933
Goran Jakovljevicc6418422016-12-05 16:31:55 +01002934void InstructionCodeGeneratorMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
2935 __ LoadFromOffset(kLoadWord,
2936 flag->GetLocations()->Out().AsRegister<GpuRegister>(),
2937 SP,
2938 codegen_->GetStackOffsetOfShouldDeoptimizeFlag());
Mingyao Yang063fc772016-08-02 11:02:54 -07002939}
2940
David Brazdil74eb1b22015-12-14 11:44:01 +00002941void LocationsBuilderMIPS64::VisitSelect(HSelect* select) {
2942 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
2943 if (Primitive::IsFloatingPointType(select->GetType())) {
2944 locations->SetInAt(0, Location::RequiresFpuRegister());
2945 locations->SetInAt(1, Location::RequiresFpuRegister());
2946 } else {
2947 locations->SetInAt(0, Location::RequiresRegister());
2948 locations->SetInAt(1, Location::RequiresRegister());
2949 }
2950 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
2951 locations->SetInAt(2, Location::RequiresRegister());
2952 }
2953 locations->SetOut(Location::SameAsFirstInput());
2954}
2955
2956void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) {
2957 LocationSummary* locations = select->GetLocations();
2958 Mips64Label false_target;
2959 GenerateTestAndBranch(select,
2960 /* condition_input_index */ 2,
2961 /* true_target */ nullptr,
2962 &false_target);
2963 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
2964 __ Bind(&false_target);
2965}
2966
David Srbecky0cf44932015-12-09 14:09:59 +00002967void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) {
2968 new (GetGraph()->GetArena()) LocationSummary(info);
2969}
2970
David Srbeckyd28f4a02016-03-14 17:14:24 +00002971void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) {
2972 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00002973}
2974
2975void CodeGeneratorMIPS64::GenerateNop() {
2976 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00002977}
2978
Alexey Frunze4dda3372015-06-01 18:31:49 -07002979void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction,
2980 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
2981 LocationSummary* locations =
2982 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2983 locations->SetInAt(0, Location::RequiresRegister());
2984 if (Primitive::IsFloatingPointType(instruction->GetType())) {
2985 locations->SetOut(Location::RequiresFpuRegister());
2986 } else {
2987 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2988 }
2989}
2990
2991void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction,
2992 const FieldInfo& field_info) {
2993 Primitive::Type type = field_info.GetFieldType();
2994 LocationSummary* locations = instruction->GetLocations();
2995 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2996 LoadOperandType load_type = kLoadUnsignedByte;
2997 switch (type) {
2998 case Primitive::kPrimBoolean:
2999 load_type = kLoadUnsignedByte;
3000 break;
3001 case Primitive::kPrimByte:
3002 load_type = kLoadSignedByte;
3003 break;
3004 case Primitive::kPrimShort:
3005 load_type = kLoadSignedHalfword;
3006 break;
3007 case Primitive::kPrimChar:
3008 load_type = kLoadUnsignedHalfword;
3009 break;
3010 case Primitive::kPrimInt:
3011 case Primitive::kPrimFloat:
3012 load_type = kLoadWord;
3013 break;
3014 case Primitive::kPrimLong:
3015 case Primitive::kPrimDouble:
3016 load_type = kLoadDoubleword;
3017 break;
3018 case Primitive::kPrimNot:
3019 load_type = kLoadUnsignedWord;
3020 break;
3021 case Primitive::kPrimVoid:
3022 LOG(FATAL) << "Unreachable type " << type;
3023 UNREACHABLE();
3024 }
3025 if (!Primitive::IsFloatingPointType(type)) {
3026 DCHECK(locations->Out().IsRegister());
3027 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3028 __ LoadFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value());
3029 } else {
3030 DCHECK(locations->Out().IsFpuRegister());
3031 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3032 __ LoadFpuFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value());
3033 }
3034
3035 codegen_->MaybeRecordImplicitNullCheck(instruction);
3036 // TODO: memory barrier?
3037}
3038
3039void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction,
3040 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
3041 LocationSummary* locations =
3042 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3043 locations->SetInAt(0, Location::RequiresRegister());
3044 if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
3045 locations->SetInAt(1, Location::RequiresFpuRegister());
3046 } else {
3047 locations->SetInAt(1, Location::RequiresRegister());
3048 }
3049}
3050
3051void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction,
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01003052 const FieldInfo& field_info,
3053 bool value_can_be_null) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003054 Primitive::Type type = field_info.GetFieldType();
3055 LocationSummary* locations = instruction->GetLocations();
3056 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
3057 StoreOperandType store_type = kStoreByte;
3058 switch (type) {
3059 case Primitive::kPrimBoolean:
3060 case Primitive::kPrimByte:
3061 store_type = kStoreByte;
3062 break;
3063 case Primitive::kPrimShort:
3064 case Primitive::kPrimChar:
3065 store_type = kStoreHalfword;
3066 break;
3067 case Primitive::kPrimInt:
3068 case Primitive::kPrimFloat:
3069 case Primitive::kPrimNot:
3070 store_type = kStoreWord;
3071 break;
3072 case Primitive::kPrimLong:
3073 case Primitive::kPrimDouble:
3074 store_type = kStoreDoubleword;
3075 break;
3076 case Primitive::kPrimVoid:
3077 LOG(FATAL) << "Unreachable type " << type;
3078 UNREACHABLE();
3079 }
3080 if (!Primitive::IsFloatingPointType(type)) {
3081 DCHECK(locations->InAt(1).IsRegister());
3082 GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>();
3083 __ StoreToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value());
3084 } else {
3085 DCHECK(locations->InAt(1).IsFpuRegister());
3086 FpuRegister src = locations->InAt(1).AsFpuRegister<FpuRegister>();
3087 __ StoreFpuToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value());
3088 }
3089
3090 codegen_->MaybeRecordImplicitNullCheck(instruction);
3091 // TODO: memory barriers?
3092 if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) {
3093 DCHECK(locations->InAt(1).IsRegister());
3094 GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>();
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01003095 codegen_->MarkGCCard(obj, src, value_can_be_null);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003096 }
3097}
3098
3099void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3100 HandleFieldGet(instruction, instruction->GetFieldInfo());
3101}
3102
3103void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3104 HandleFieldGet(instruction, instruction->GetFieldInfo());
3105}
3106
3107void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3108 HandleFieldSet(instruction, instruction->GetFieldInfo());
3109}
3110
3111void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01003112 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003113}
3114
Alexey Frunzef63f5692016-12-13 17:43:11 -08003115void InstructionCodeGeneratorMIPS64::GenerateGcRootFieldLoad(
3116 HInstruction* instruction ATTRIBUTE_UNUSED,
3117 Location root,
3118 GpuRegister obj,
3119 uint32_t offset) {
Vladimir Marko48886c22017-01-06 11:45:47 +00003120 // When handling PC-relative loads, the caller calls
Alexey Frunzef63f5692016-12-13 17:43:11 -08003121 // EmitPcRelativeAddressPlaceholderHigh() and then GenerateGcRootFieldLoad().
3122 // The relative patcher expects the two methods to emit the following patchable
3123 // sequence of instructions in this case:
3124 // auipc reg1, 0x1234 // 0x1234 is a placeholder for offset_high.
3125 // lwu reg2, 0x5678(reg1) // 0x5678 is a placeholder for offset_low.
3126 // TODO: Adjust GenerateGcRootFieldLoad() and its caller when this method is
3127 // extended (e.g. for read barriers) so as not to break the relative patcher.
3128 GpuRegister root_reg = root.AsRegister<GpuRegister>();
3129 if (kEmitCompilerReadBarrier) {
3130 UNIMPLEMENTED(FATAL) << "for read barrier";
3131 } else {
3132 // Plain GC root load with no read barrier.
3133 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
3134 __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset);
3135 // Note that GC roots are not affected by heap poisoning, thus we
3136 // do not have to unpoison `root_reg` here.
3137 }
3138}
3139
Alexey Frunze4dda3372015-06-01 18:31:49 -07003140void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
3141 LocationSummary::CallKind call_kind =
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003142 instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003143 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3144 locations->SetInAt(0, Location::RequiresRegister());
3145 locations->SetInAt(1, Location::RequiresRegister());
3146 // The output does overlap inputs.
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01003147 // Note that TypeCheckSlowPathMIPS64 uses this register too.
Alexey Frunze4dda3372015-06-01 18:31:49 -07003148 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3149}
3150
3151void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
3152 LocationSummary* locations = instruction->GetLocations();
3153 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
3154 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
3155 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3156
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003157 Mips64Label done;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003158
3159 // Return 0 if `obj` is null.
3160 // TODO: Avoid this check if we know `obj` is not null.
3161 __ Move(out, ZERO);
3162 __ Beqzc(obj, &done);
3163
3164 // Compare the class of `obj` with `cls`.
3165 __ LoadFromOffset(kLoadUnsignedWord, out, obj, mirror::Object::ClassOffset().Int32Value());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003166 if (instruction->IsExactCheck()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003167 // Classes must be equal for the instanceof to succeed.
3168 __ Xor(out, out, cls);
3169 __ Sltiu(out, out, 1);
3170 } else {
3171 // If the classes are not equal, we go into a slow path.
3172 DCHECK(locations->OnlyCallsOnSlowPath());
3173 SlowPathCodeMIPS64* slow_path =
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01003174 new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003175 codegen_->AddSlowPath(slow_path);
3176 __ Bnec(out, cls, slow_path->GetEntryLabel());
3177 __ LoadConst32(out, 1);
3178 __ Bind(slow_path->GetExitLabel());
3179 }
3180
3181 __ Bind(&done);
3182}
3183
3184void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) {
3185 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3186 locations->SetOut(Location::ConstantLocation(constant));
3187}
3188
3189void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
3190 // Will be generated at use site.
3191}
3192
3193void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) {
3194 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3195 locations->SetOut(Location::ConstantLocation(constant));
3196}
3197
3198void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
3199 // Will be generated at use site.
3200}
3201
Calin Juravle175dc732015-08-25 15:42:32 +01003202void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
3203 // The trampoline uses the same calling convention as dex calling conventions,
3204 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
3205 // the method_idx.
3206 HandleInvoke(invoke);
3207}
3208
3209void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
3210 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
3211}
3212
Alexey Frunze4dda3372015-06-01 18:31:49 -07003213void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) {
3214 InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor;
3215 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
3216}
3217
3218void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
3219 HandleInvoke(invoke);
3220 // The register T0 is required to be used for the hidden argument in
3221 // art_quick_imt_conflict_trampoline, so add the hidden argument.
3222 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
3223}
3224
3225void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
3226 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
3227 GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003228 Location receiver = invoke->GetLocations()->InAt(0);
3229 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07003230 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003231
3232 // Set the hidden argument.
3233 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(),
3234 invoke->GetDexMethodIndex());
3235
3236 // temp = object->GetClass();
3237 if (receiver.IsStackSlot()) {
3238 __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex());
3239 __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset);
3240 } else {
3241 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset);
3242 }
3243 codegen_->MaybeRecordImplicitNullCheck(invoke);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00003244 __ LoadFromOffset(kLoadDoubleword, temp, temp,
3245 mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value());
3246 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00003247 invoke->GetImtIndex(), kMips64PointerSize));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003248 // temp = temp->GetImtEntryAt(method_offset);
3249 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
3250 // T9 = temp->GetEntryPoint();
3251 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
3252 // T9();
3253 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003254 __ Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003255 DCHECK(!codegen_->IsLeafMethod());
3256 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3257}
3258
3259void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen3039e382015-08-26 07:54:08 -07003260 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
3261 if (intrinsic.TryDispatch(invoke)) {
3262 return;
3263 }
3264
Alexey Frunze4dda3372015-06-01 18:31:49 -07003265 HandleInvoke(invoke);
3266}
3267
3268void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00003269 // Explicit clinit checks triggered by static invokes must have been pruned by
3270 // art::PrepareForRegisterAllocation.
3271 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003272
Chris Larsen3039e382015-08-26 07:54:08 -07003273 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
3274 if (intrinsic.TryDispatch(invoke)) {
3275 return;
3276 }
3277
Alexey Frunze4dda3372015-06-01 18:31:49 -07003278 HandleInvoke(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003279}
3280
Orion Hodsonac141392017-01-13 11:53:47 +00003281void LocationsBuilderMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
3282 HandleInvoke(invoke);
3283}
3284
3285void InstructionCodeGeneratorMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
3286 codegen_->GenerateInvokePolymorphicCall(invoke);
3287}
3288
Chris Larsen3039e382015-08-26 07:54:08 -07003289static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003290 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen3039e382015-08-26 07:54:08 -07003291 IntrinsicCodeGeneratorMIPS64 intrinsic(codegen);
3292 intrinsic.Dispatch(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003293 return true;
3294 }
3295 return false;
3296}
3297
Vladimir Markocac5a7e2016-02-22 10:39:50 +00003298HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind(
Alexey Frunzef63f5692016-12-13 17:43:11 -08003299 HLoadString::LoadKind desired_string_load_kind) {
3300 if (kEmitCompilerReadBarrier) {
3301 UNIMPLEMENTED(FATAL) << "for read barrier";
3302 }
3303 bool fallback_load = false;
3304 switch (desired_string_load_kind) {
3305 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
3306 DCHECK(!GetCompilerOptions().GetCompilePic());
3307 break;
3308 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
3309 DCHECK(GetCompilerOptions().GetCompilePic());
3310 break;
3311 case HLoadString::LoadKind::kBootImageAddress:
3312 break;
3313 case HLoadString::LoadKind::kBssEntry:
3314 DCHECK(!Runtime::Current()->UseJitCompilation());
3315 break;
3316 case HLoadString::LoadKind::kDexCacheViaMethod:
3317 break;
3318 case HLoadString::LoadKind::kJitTableAddress:
3319 DCHECK(Runtime::Current()->UseJitCompilation());
3320 // TODO: implement.
3321 fallback_load = true;
3322 break;
3323 }
3324 if (fallback_load) {
3325 desired_string_load_kind = HLoadString::LoadKind::kDexCacheViaMethod;
3326 }
3327 return desired_string_load_kind;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00003328}
3329
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01003330HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind(
3331 HLoadClass::LoadKind desired_class_load_kind) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08003332 if (kEmitCompilerReadBarrier) {
3333 UNIMPLEMENTED(FATAL) << "for read barrier";
3334 }
3335 bool fallback_load = false;
3336 switch (desired_class_load_kind) {
3337 case HLoadClass::LoadKind::kReferrersClass:
3338 break;
3339 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
3340 DCHECK(!GetCompilerOptions().GetCompilePic());
3341 break;
3342 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
3343 DCHECK(GetCompilerOptions().GetCompilePic());
3344 break;
3345 case HLoadClass::LoadKind::kBootImageAddress:
3346 break;
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003347 case HLoadClass::LoadKind::kBssEntry:
3348 DCHECK(!Runtime::Current()->UseJitCompilation());
3349 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08003350 case HLoadClass::LoadKind::kJitTableAddress:
3351 DCHECK(Runtime::Current()->UseJitCompilation());
3352 // TODO: implement.
3353 fallback_load = true;
3354 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08003355 case HLoadClass::LoadKind::kDexCacheViaMethod:
3356 break;
3357 }
3358 if (fallback_load) {
3359 desired_class_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod;
3360 }
3361 return desired_class_load_kind;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01003362}
3363
Vladimir Markodc151b22015-10-15 18:02:30 +01003364HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch(
3365 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +01003366 HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) {
Alexey Frunze19f6c692016-11-30 19:19:55 -08003367 // On MIPS64 we support all dispatch types.
3368 return desired_dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01003369}
3370
Alexey Frunze4dda3372015-06-01 18:31:49 -07003371void CodeGeneratorMIPS64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
3372 // All registers are assumed to be correctly set up per the calling convention.
Vladimir Marko58155012015-08-19 12:49:41 +00003373 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
Alexey Frunze19f6c692016-11-30 19:19:55 -08003374 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
3375 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
3376
Alexey Frunze19f6c692016-11-30 19:19:55 -08003377 switch (method_load_kind) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01003378 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
Vladimir Marko58155012015-08-19 12:49:41 +00003379 // temp = thread->string_init_entrypoint
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01003380 uint32_t offset =
3381 GetThreadOffset<kMips64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
Vladimir Marko58155012015-08-19 12:49:41 +00003382 __ LoadFromOffset(kLoadDoubleword,
3383 temp.AsRegister<GpuRegister>(),
3384 TR,
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01003385 offset);
Vladimir Marko58155012015-08-19 12:49:41 +00003386 break;
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01003387 }
Vladimir Marko58155012015-08-19 12:49:41 +00003388 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00003389 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00003390 break;
3391 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
Alexey Frunze19f6c692016-11-30 19:19:55 -08003392 __ LoadLiteral(temp.AsRegister<GpuRegister>(),
3393 kLoadDoubleword,
3394 DeduplicateUint64Literal(invoke->GetMethodAddress()));
Vladimir Marko58155012015-08-19 12:49:41 +00003395 break;
Alexey Frunze19f6c692016-11-30 19:19:55 -08003396 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: {
3397 uint32_t offset = invoke->GetDexCacheArrayOffset();
3398 CodeGeneratorMIPS64::PcRelativePatchInfo* info =
Nicolas Geoffray5d37c152017-01-12 13:25:19 +00003399 NewPcRelativeDexCacheArrayPatch(invoke->GetDexFileForPcRelativeDexCache(), offset);
Alexey Frunze19f6c692016-11-30 19:19:55 -08003400 EmitPcRelativeAddressPlaceholderHigh(info, AT);
3401 __ Ld(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678);
3402 break;
3403 }
Vladimir Marko58155012015-08-19 12:49:41 +00003404 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00003405 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00003406 GpuRegister reg = temp.AsRegister<GpuRegister>();
3407 GpuRegister method_reg;
3408 if (current_method.IsRegister()) {
3409 method_reg = current_method.AsRegister<GpuRegister>();
3410 } else {
3411 // TODO: use the appropriate DCHECK() here if possible.
3412 // DCHECK(invoke->GetLocations()->Intrinsified());
3413 DCHECK(!current_method.IsValid());
3414 method_reg = reg;
3415 __ Ld(reg, SP, kCurrentMethodStackOffset);
3416 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003417
Vladimir Marko58155012015-08-19 12:49:41 +00003418 // temp = temp->dex_cache_resolved_methods_;
Vladimir Marko05792b92015-08-03 11:56:49 +01003419 __ LoadFromOffset(kLoadDoubleword,
Vladimir Marko58155012015-08-19 12:49:41 +00003420 reg,
3421 method_reg,
Vladimir Marko05792b92015-08-03 11:56:49 +01003422 ArtMethod::DexCacheResolvedMethodsOffset(kMips64PointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01003423 // temp = temp[index_in_cache];
3424 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
3425 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Vladimir Marko58155012015-08-19 12:49:41 +00003426 __ LoadFromOffset(kLoadDoubleword,
3427 reg,
3428 reg,
3429 CodeGenerator::GetCachePointerOffset(index_in_cache));
3430 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003431 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003432 }
3433
Alexey Frunze19f6c692016-11-30 19:19:55 -08003434 switch (code_ptr_location) {
Vladimir Marko58155012015-08-19 12:49:41 +00003435 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
Alexey Frunze19f6c692016-11-30 19:19:55 -08003436 __ Balc(&frame_entry_label_);
Vladimir Marko58155012015-08-19 12:49:41 +00003437 break;
Vladimir Marko58155012015-08-19 12:49:41 +00003438 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
3439 // T9 = callee_method->entry_point_from_quick_compiled_code_;
3440 __ LoadFromOffset(kLoadDoubleword,
3441 T9,
3442 callee_method.AsRegister<GpuRegister>(),
3443 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07003444 kMips64PointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00003445 // T9()
3446 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003447 __ Nop();
Vladimir Marko58155012015-08-19 12:49:41 +00003448 break;
3449 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003450 DCHECK(!IsLeafMethod());
3451}
3452
3453void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00003454 // Explicit clinit checks triggered by static invokes must have been pruned by
3455 // art::PrepareForRegisterAllocation.
3456 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003457
3458 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
3459 return;
3460 }
3461
3462 LocationSummary* locations = invoke->GetLocations();
3463 codegen_->GenerateStaticOrDirectCall(invoke,
3464 locations->HasTemps()
3465 ? locations->GetTemp(0)
3466 : Location::NoLocation());
3467 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3468}
3469
Alexey Frunze53afca12015-11-05 16:34:23 -08003470void CodeGeneratorMIPS64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
Nicolas Geoffraye5234232015-12-02 09:06:11 +00003471 // Use the calling convention instead of the location of the receiver, as
3472 // intrinsics may have put the receiver in a different register. In the intrinsics
3473 // slow path, the arguments have been moved to the right place, so here we are
3474 // guaranteed that the receiver is the first register of the calling convention.
3475 InvokeDexCallingConvention calling_convention;
3476 GpuRegister receiver = calling_convention.GetRegisterAt(0);
3477
Alexey Frunze53afca12015-11-05 16:34:23 -08003478 GpuRegister temp = temp_location.AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003479 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
3480 invoke->GetVTableIndex(), kMips64PointerSize).SizeValue();
3481 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07003482 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003483
3484 // temp = object->GetClass();
Nicolas Geoffraye5234232015-12-02 09:06:11 +00003485 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset);
Alexey Frunze53afca12015-11-05 16:34:23 -08003486 MaybeRecordImplicitNullCheck(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003487 // temp = temp->GetMethodAt(method_offset);
3488 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
3489 // T9 = temp->GetEntryPoint();
3490 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
3491 // T9();
3492 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003493 __ Nop();
Alexey Frunze53afca12015-11-05 16:34:23 -08003494}
3495
3496void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
3497 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
3498 return;
3499 }
3500
3501 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003502 DCHECK(!codegen_->IsLeafMethod());
3503 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3504}
3505
3506void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) {
Vladimir Marko41559982017-01-06 14:04:23 +00003507 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
3508 if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08003509 InvokeRuntimeCallingConvention calling_convention;
Vladimir Marko41559982017-01-06 14:04:23 +00003510 CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(
Alexey Frunzef63f5692016-12-13 17:43:11 -08003511 cls,
3512 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko41559982017-01-06 14:04:23 +00003513 calling_convention.GetReturnLocation(Primitive::kPrimNot));
Alexey Frunzef63f5692016-12-13 17:43:11 -08003514 return;
3515 }
Vladimir Marko41559982017-01-06 14:04:23 +00003516 DCHECK(!cls->NeedsAccessCheck());
Alexey Frunzef63f5692016-12-13 17:43:11 -08003517
3518 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier)
3519 ? LocationSummary::kCallOnSlowPath
3520 : LocationSummary::kNoCall;
3521 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Vladimir Marko41559982017-01-06 14:04:23 +00003522 if (load_kind == HLoadClass::LoadKind::kReferrersClass) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08003523 locations->SetInAt(0, Location::RequiresRegister());
3524 }
3525 locations->SetOut(Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003526}
3527
Nicolas Geoffray5247c082017-01-13 14:17:29 +00003528// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
3529// move.
3530void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS {
Vladimir Marko41559982017-01-06 14:04:23 +00003531 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
3532 if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) {
3533 codegen_->GenerateLoadClassRuntimeCall(cls);
Calin Juravle580b6092015-10-06 17:35:58 +01003534 return;
3535 }
Vladimir Marko41559982017-01-06 14:04:23 +00003536 DCHECK(!cls->NeedsAccessCheck());
Calin Juravle580b6092015-10-06 17:35:58 +01003537
Vladimir Marko41559982017-01-06 14:04:23 +00003538 LocationSummary* locations = cls->GetLocations();
Alexey Frunzef63f5692016-12-13 17:43:11 -08003539 Location out_loc = locations->Out();
3540 GpuRegister out = out_loc.AsRegister<GpuRegister>();
3541 GpuRegister current_method_reg = ZERO;
3542 if (load_kind == HLoadClass::LoadKind::kReferrersClass ||
3543 load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) {
3544 current_method_reg = locations->InAt(0).AsRegister<GpuRegister>();
3545 }
3546
3547 bool generate_null_check = false;
3548 switch (load_kind) {
3549 case HLoadClass::LoadKind::kReferrersClass:
3550 DCHECK(!cls->CanCallRuntime());
3551 DCHECK(!cls->MustGenerateClinitCheck());
3552 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
3553 GenerateGcRootFieldLoad(cls,
3554 out_loc,
3555 current_method_reg,
3556 ArtMethod::DeclaringClassOffset().Int32Value());
3557 break;
3558 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003559 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunzef63f5692016-12-13 17:43:11 -08003560 __ LoadLiteral(out,
3561 kLoadUnsignedWord,
3562 codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
3563 cls->GetTypeIndex()));
3564 break;
3565 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003566 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunzef63f5692016-12-13 17:43:11 -08003567 CodeGeneratorMIPS64::PcRelativePatchInfo* info =
3568 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
3569 codegen_->EmitPcRelativeAddressPlaceholderHigh(info, AT);
3570 __ Daddiu(out, AT, /* placeholder */ 0x5678);
3571 break;
3572 }
3573 case HLoadClass::LoadKind::kBootImageAddress: {
3574 DCHECK(!kEmitCompilerReadBarrier);
Nicolas Geoffray5247c082017-01-13 14:17:29 +00003575 uint32_t address = dchecked_integral_cast<uint32_t>(
3576 reinterpret_cast<uintptr_t>(cls->GetClass().Get()));
3577 DCHECK_NE(address, 0u);
Alexey Frunzef63f5692016-12-13 17:43:11 -08003578 __ LoadLiteral(out,
3579 kLoadUnsignedWord,
3580 codegen_->DeduplicateBootImageAddressLiteral(address));
3581 break;
3582 }
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003583 case HLoadClass::LoadKind::kBssEntry: {
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003584 CodeGeneratorMIPS64::PcRelativePatchInfo* info =
Vladimir Marko1998cd02017-01-13 13:02:58 +00003585 codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex());
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003586 codegen_->EmitPcRelativeAddressPlaceholderHigh(info, AT);
3587 __ Lwu(out, AT, /* placeholder */ 0x5678);
3588 generate_null_check = true;
3589 break;
3590 }
Alexey Frunzef63f5692016-12-13 17:43:11 -08003591 case HLoadClass::LoadKind::kJitTableAddress: {
3592 LOG(FATAL) << "Unimplemented";
3593 break;
3594 }
Vladimir Marko41559982017-01-06 14:04:23 +00003595 case HLoadClass::LoadKind::kDexCacheViaMethod:
3596 LOG(FATAL) << "UNREACHABLE";
3597 UNREACHABLE();
Alexey Frunzef63f5692016-12-13 17:43:11 -08003598 }
3599
3600 if (generate_null_check || cls->MustGenerateClinitCheck()) {
3601 DCHECK(cls->CanCallRuntime());
3602 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64(
3603 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3604 codegen_->AddSlowPath(slow_path);
3605 if (generate_null_check) {
3606 __ Beqzc(out, slow_path->GetEntryLabel());
3607 }
3608 if (cls->MustGenerateClinitCheck()) {
3609 GenerateClassInitializationCheck(slow_path, out);
3610 } else {
3611 __ Bind(slow_path->GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003612 }
3613 }
3614}
3615
David Brazdilcb1c0552015-08-04 16:22:25 +01003616static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07003617 return Thread::ExceptionOffset<kMips64PointerSize>().Int32Value();
David Brazdilcb1c0552015-08-04 16:22:25 +01003618}
3619
Alexey Frunze4dda3372015-06-01 18:31:49 -07003620void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) {
3621 LocationSummary* locations =
3622 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3623 locations->SetOut(Location::RequiresRegister());
3624}
3625
3626void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) {
3627 GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>();
David Brazdilcb1c0552015-08-04 16:22:25 +01003628 __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset());
3629}
3630
3631void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) {
3632 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
3633}
3634
3635void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
3636 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003637}
3638
Alexey Frunze4dda3372015-06-01 18:31:49 -07003639void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08003640 HLoadString::LoadKind load_kind = load->GetLoadKind();
3641 LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load);
Nicolas Geoffray917d0162015-11-24 18:25:35 +00003642 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Alexey Frunzef63f5692016-12-13 17:43:11 -08003643 if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) {
3644 InvokeRuntimeCallingConvention calling_convention;
3645 locations->SetOut(calling_convention.GetReturnLocation(load->GetType()));
3646 } else {
3647 locations->SetOut(Location::RequiresRegister());
3648 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003649}
3650
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00003651// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
3652// move.
3653void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS {
Alexey Frunzef63f5692016-12-13 17:43:11 -08003654 HLoadString::LoadKind load_kind = load->GetLoadKind();
3655 LocationSummary* locations = load->GetLocations();
3656 Location out_loc = locations->Out();
3657 GpuRegister out = out_loc.AsRegister<GpuRegister>();
3658
3659 switch (load_kind) {
3660 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003661 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunzef63f5692016-12-13 17:43:11 -08003662 __ LoadLiteral(out,
3663 kLoadUnsignedWord,
3664 codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
3665 load->GetStringIndex()));
3666 return; // No dex cache slow path.
3667 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
3668 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
3669 CodeGeneratorMIPS64::PcRelativePatchInfo* info =
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003670 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunzef63f5692016-12-13 17:43:11 -08003671 codegen_->EmitPcRelativeAddressPlaceholderHigh(info, AT);
3672 __ Daddiu(out, AT, /* placeholder */ 0x5678);
3673 return; // No dex cache slow path.
3674 }
3675 case HLoadString::LoadKind::kBootImageAddress: {
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00003676 uint32_t address = dchecked_integral_cast<uint32_t>(
3677 reinterpret_cast<uintptr_t>(load->GetString().Get()));
3678 DCHECK_NE(address, 0u);
Alexey Frunzef63f5692016-12-13 17:43:11 -08003679 __ LoadLiteral(out,
3680 kLoadUnsignedWord,
3681 codegen_->DeduplicateBootImageAddressLiteral(address));
3682 return; // No dex cache slow path.
3683 }
3684 case HLoadString::LoadKind::kBssEntry: {
3685 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
3686 CodeGeneratorMIPS64::PcRelativePatchInfo* info =
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003687 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunzef63f5692016-12-13 17:43:11 -08003688 codegen_->EmitPcRelativeAddressPlaceholderHigh(info, AT);
3689 __ Lwu(out, AT, /* placeholder */ 0x5678);
3690 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS64(load);
3691 codegen_->AddSlowPath(slow_path);
3692 __ Beqzc(out, slow_path->GetEntryLabel());
3693 __ Bind(slow_path->GetExitLabel());
3694 return;
3695 }
3696 default:
3697 break;
3698 }
3699
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07003700 // TODO: Re-add the compiler code to do string dex cache lookup again.
Alexey Frunzef63f5692016-12-13 17:43:11 -08003701 DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod);
3702 InvokeRuntimeCallingConvention calling_convention;
3703 __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_);
3704 codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc());
3705 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003706}
3707
Alexey Frunze4dda3372015-06-01 18:31:49 -07003708void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) {
3709 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3710 locations->SetOut(Location::ConstantLocation(constant));
3711}
3712
3713void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
3714 // Will be generated at use site.
3715}
3716
3717void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
3718 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003719 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003720 InvokeRuntimeCallingConvention calling_convention;
3721 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3722}
3723
3724void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
Serban Constantinescufc734082016-07-19 17:18:07 +01003725 codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003726 instruction,
Serban Constantinescufc734082016-07-19 17:18:07 +01003727 instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003728 if (instruction->IsEnter()) {
3729 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
3730 } else {
3731 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
3732 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003733}
3734
3735void LocationsBuilderMIPS64::VisitMul(HMul* mul) {
3736 LocationSummary* locations =
3737 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
3738 switch (mul->GetResultType()) {
3739 case Primitive::kPrimInt:
3740 case Primitive::kPrimLong:
3741 locations->SetInAt(0, Location::RequiresRegister());
3742 locations->SetInAt(1, Location::RequiresRegister());
3743 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3744 break;
3745
3746 case Primitive::kPrimFloat:
3747 case Primitive::kPrimDouble:
3748 locations->SetInAt(0, Location::RequiresFpuRegister());
3749 locations->SetInAt(1, Location::RequiresFpuRegister());
3750 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3751 break;
3752
3753 default:
3754 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
3755 }
3756}
3757
3758void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) {
3759 Primitive::Type type = instruction->GetType();
3760 LocationSummary* locations = instruction->GetLocations();
3761
3762 switch (type) {
3763 case Primitive::kPrimInt:
3764 case Primitive::kPrimLong: {
3765 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3766 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
3767 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
3768 if (type == Primitive::kPrimInt)
3769 __ MulR6(dst, lhs, rhs);
3770 else
3771 __ Dmul(dst, lhs, rhs);
3772 break;
3773 }
3774 case Primitive::kPrimFloat:
3775 case Primitive::kPrimDouble: {
3776 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3777 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
3778 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
3779 if (type == Primitive::kPrimFloat)
3780 __ MulS(dst, lhs, rhs);
3781 else
3782 __ MulD(dst, lhs, rhs);
3783 break;
3784 }
3785 default:
3786 LOG(FATAL) << "Unexpected mul type " << type;
3787 }
3788}
3789
3790void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) {
3791 LocationSummary* locations =
3792 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
3793 switch (neg->GetResultType()) {
3794 case Primitive::kPrimInt:
3795 case Primitive::kPrimLong:
3796 locations->SetInAt(0, Location::RequiresRegister());
3797 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3798 break;
3799
3800 case Primitive::kPrimFloat:
3801 case Primitive::kPrimDouble:
3802 locations->SetInAt(0, Location::RequiresFpuRegister());
3803 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3804 break;
3805
3806 default:
3807 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
3808 }
3809}
3810
3811void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) {
3812 Primitive::Type type = instruction->GetType();
3813 LocationSummary* locations = instruction->GetLocations();
3814
3815 switch (type) {
3816 case Primitive::kPrimInt:
3817 case Primitive::kPrimLong: {
3818 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3819 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
3820 if (type == Primitive::kPrimInt)
3821 __ Subu(dst, ZERO, src);
3822 else
3823 __ Dsubu(dst, ZERO, src);
3824 break;
3825 }
3826 case Primitive::kPrimFloat:
3827 case Primitive::kPrimDouble: {
3828 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3829 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
3830 if (type == Primitive::kPrimFloat)
3831 __ NegS(dst, src);
3832 else
3833 __ NegD(dst, src);
3834 break;
3835 }
3836 default:
3837 LOG(FATAL) << "Unexpected neg type " << type;
3838 }
3839}
3840
3841void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) {
3842 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003843 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003844 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003845 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00003846 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3847 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003848}
3849
3850void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) {
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00003851 codegen_->InvokeRuntime(kQuickAllocArrayResolved, instruction, instruction->GetDexPc());
3852 CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003853}
3854
3855void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) {
3856 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003857 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003858 InvokeRuntimeCallingConvention calling_convention;
David Brazdil6de19382016-01-08 17:37:10 +00003859 if (instruction->IsStringAlloc()) {
3860 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
3861 } else {
3862 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
David Brazdil6de19382016-01-08 17:37:10 +00003863 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003864 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
3865}
3866
3867void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) {
David Brazdil6de19382016-01-08 17:37:10 +00003868 if (instruction->IsStringAlloc()) {
3869 // String is allocated through StringFactory. Call NewEmptyString entry point.
3870 GpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
Lazar Trsicd9672662015-09-03 17:33:01 +02003871 MemberOffset code_offset =
Andreas Gampe542451c2016-07-26 09:02:02 -07003872 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00003873 __ LoadFromOffset(kLoadDoubleword, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
3874 __ LoadFromOffset(kLoadDoubleword, T9, temp, code_offset.Int32Value());
3875 __ Jalr(T9);
3876 __ Nop();
3877 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3878 } else {
Serban Constantinescufc734082016-07-19 17:18:07 +01003879 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00003880 CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>();
David Brazdil6de19382016-01-08 17:37:10 +00003881 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003882}
3883
3884void LocationsBuilderMIPS64::VisitNot(HNot* instruction) {
3885 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
3886 locations->SetInAt(0, Location::RequiresRegister());
3887 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3888}
3889
3890void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) {
3891 Primitive::Type type = instruction->GetType();
3892 LocationSummary* locations = instruction->GetLocations();
3893
3894 switch (type) {
3895 case Primitive::kPrimInt:
3896 case Primitive::kPrimLong: {
3897 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3898 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
3899 __ Nor(dst, src, ZERO);
3900 break;
3901 }
3902
3903 default:
3904 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
3905 }
3906}
3907
3908void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
3909 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
3910 locations->SetInAt(0, Location::RequiresRegister());
3911 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3912}
3913
3914void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
3915 LocationSummary* locations = instruction->GetLocations();
3916 __ Xori(locations->Out().AsRegister<GpuRegister>(),
3917 locations->InAt(0).AsRegister<GpuRegister>(),
3918 1);
3919}
3920
3921void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01003922 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
3923 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003924}
3925
Calin Juravle2ae48182016-03-16 14:05:09 +00003926void CodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) {
3927 if (CanMoveNullCheckToUser(instruction)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003928 return;
3929 }
3930 Location obj = instruction->GetLocations()->InAt(0);
3931
3932 __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00003933 RecordPcInfo(instruction, instruction->GetDexPc());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003934}
3935
Calin Juravle2ae48182016-03-16 14:05:09 +00003936void CodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003937 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS64(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00003938 AddSlowPath(slow_path);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003939
3940 Location obj = instruction->GetLocations()->InAt(0);
3941
3942 __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
3943}
3944
3945void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00003946 codegen_->GenerateNullCheck(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003947}
3948
3949void LocationsBuilderMIPS64::VisitOr(HOr* instruction) {
3950 HandleBinaryOp(instruction);
3951}
3952
3953void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) {
3954 HandleBinaryOp(instruction);
3955}
3956
3957void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
3958 LOG(FATAL) << "Unreachable";
3959}
3960
3961void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) {
3962 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3963}
3964
3965void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) {
3966 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
3967 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3968 if (location.IsStackSlot()) {
3969 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3970 } else if (location.IsDoubleStackSlot()) {
3971 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3972 }
3973 locations->SetOut(location);
3974}
3975
3976void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction
3977 ATTRIBUTE_UNUSED) {
3978 // Nothing to do, the parameter is already at its location.
3979}
3980
3981void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) {
3982 LocationSummary* locations =
3983 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3984 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3985}
3986
3987void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction
3988 ATTRIBUTE_UNUSED) {
3989 // Nothing to do, the method is already at its location.
3990}
3991
3992void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) {
3993 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Vladimir Marko372f10e2016-05-17 16:30:10 +01003994 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003995 locations->SetInAt(i, Location::Any());
3996 }
3997 locations->SetOut(Location::Any());
3998}
3999
4000void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
4001 LOG(FATAL) << "Unreachable";
4002}
4003
4004void LocationsBuilderMIPS64::VisitRem(HRem* rem) {
4005 Primitive::Type type = rem->GetResultType();
4006 LocationSummary::CallKind call_kind =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004007 Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly
4008 : LocationSummary::kNoCall;
Alexey Frunze4dda3372015-06-01 18:31:49 -07004009 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
4010
4011 switch (type) {
4012 case Primitive::kPrimInt:
4013 case Primitive::kPrimLong:
4014 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunzec857c742015-09-23 15:12:39 -07004015 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07004016 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4017 break;
4018
4019 case Primitive::kPrimFloat:
4020 case Primitive::kPrimDouble: {
4021 InvokeRuntimeCallingConvention calling_convention;
4022 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
4023 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
4024 locations->SetOut(calling_convention.GetReturnLocation(type));
4025 break;
4026 }
4027
4028 default:
4029 LOG(FATAL) << "Unexpected rem type " << type;
4030 }
4031}
4032
4033void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) {
4034 Primitive::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07004035
4036 switch (type) {
4037 case Primitive::kPrimInt:
Alexey Frunzec857c742015-09-23 15:12:39 -07004038 case Primitive::kPrimLong:
4039 GenerateDivRemIntegral(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004040 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07004041
4042 case Primitive::kPrimFloat:
4043 case Primitive::kPrimDouble: {
Serban Constantinescufc734082016-07-19 17:18:07 +01004044 QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod;
4045 codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00004046 if (type == Primitive::kPrimFloat) {
4047 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
4048 } else {
4049 CheckEntrypointTypes<kQuickFmod, double, double, double>();
4050 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004051 break;
4052 }
4053 default:
4054 LOG(FATAL) << "Unexpected rem type " << type;
4055 }
4056}
4057
4058void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
4059 memory_barrier->SetLocations(nullptr);
4060}
4061
4062void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
4063 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
4064}
4065
4066void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) {
4067 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret);
4068 Primitive::Type return_type = ret->InputAt(0)->GetType();
4069 locations->SetInAt(0, Mips64ReturnLocation(return_type));
4070}
4071
4072void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
4073 codegen_->GenerateFrameExit();
4074}
4075
4076void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) {
4077 ret->SetLocations(nullptr);
4078}
4079
4080void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
4081 codegen_->GenerateFrameExit();
4082}
4083
Alexey Frunze92d90602015-12-18 18:16:36 -08004084void LocationsBuilderMIPS64::VisitRor(HRor* ror) {
4085 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00004086}
4087
Alexey Frunze92d90602015-12-18 18:16:36 -08004088void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) {
4089 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00004090}
4091
Alexey Frunze4dda3372015-06-01 18:31:49 -07004092void LocationsBuilderMIPS64::VisitShl(HShl* shl) {
4093 HandleShift(shl);
4094}
4095
4096void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) {
4097 HandleShift(shl);
4098}
4099
4100void LocationsBuilderMIPS64::VisitShr(HShr* shr) {
4101 HandleShift(shr);
4102}
4103
4104void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) {
4105 HandleShift(shr);
4106}
4107
Alexey Frunze4dda3372015-06-01 18:31:49 -07004108void LocationsBuilderMIPS64::VisitSub(HSub* instruction) {
4109 HandleBinaryOp(instruction);
4110}
4111
4112void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) {
4113 HandleBinaryOp(instruction);
4114}
4115
4116void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4117 HandleFieldGet(instruction, instruction->GetFieldInfo());
4118}
4119
4120void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4121 HandleFieldGet(instruction, instruction->GetFieldInfo());
4122}
4123
4124void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
4125 HandleFieldSet(instruction, instruction->GetFieldInfo());
4126}
4127
4128void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01004129 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Alexey Frunze4dda3372015-06-01 18:31:49 -07004130}
4131
Calin Juravlee460d1d2015-09-29 04:52:17 +01004132void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet(
4133 HUnresolvedInstanceFieldGet* instruction) {
4134 FieldAccessCallingConventionMIPS64 calling_convention;
4135 codegen_->CreateUnresolvedFieldLocationSummary(
4136 instruction, instruction->GetFieldType(), calling_convention);
4137}
4138
4139void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet(
4140 HUnresolvedInstanceFieldGet* instruction) {
4141 FieldAccessCallingConventionMIPS64 calling_convention;
4142 codegen_->GenerateUnresolvedFieldAccess(instruction,
4143 instruction->GetFieldType(),
4144 instruction->GetFieldIndex(),
4145 instruction->GetDexPc(),
4146 calling_convention);
4147}
4148
4149void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet(
4150 HUnresolvedInstanceFieldSet* instruction) {
4151 FieldAccessCallingConventionMIPS64 calling_convention;
4152 codegen_->CreateUnresolvedFieldLocationSummary(
4153 instruction, instruction->GetFieldType(), calling_convention);
4154}
4155
4156void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet(
4157 HUnresolvedInstanceFieldSet* instruction) {
4158 FieldAccessCallingConventionMIPS64 calling_convention;
4159 codegen_->GenerateUnresolvedFieldAccess(instruction,
4160 instruction->GetFieldType(),
4161 instruction->GetFieldIndex(),
4162 instruction->GetDexPc(),
4163 calling_convention);
4164}
4165
4166void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet(
4167 HUnresolvedStaticFieldGet* instruction) {
4168 FieldAccessCallingConventionMIPS64 calling_convention;
4169 codegen_->CreateUnresolvedFieldLocationSummary(
4170 instruction, instruction->GetFieldType(), calling_convention);
4171}
4172
4173void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet(
4174 HUnresolvedStaticFieldGet* instruction) {
4175 FieldAccessCallingConventionMIPS64 calling_convention;
4176 codegen_->GenerateUnresolvedFieldAccess(instruction,
4177 instruction->GetFieldType(),
4178 instruction->GetFieldIndex(),
4179 instruction->GetDexPc(),
4180 calling_convention);
4181}
4182
4183void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet(
4184 HUnresolvedStaticFieldSet* instruction) {
4185 FieldAccessCallingConventionMIPS64 calling_convention;
4186 codegen_->CreateUnresolvedFieldLocationSummary(
4187 instruction, instruction->GetFieldType(), calling_convention);
4188}
4189
4190void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet(
4191 HUnresolvedStaticFieldSet* instruction) {
4192 FieldAccessCallingConventionMIPS64 calling_convention;
4193 codegen_->GenerateUnresolvedFieldAccess(instruction,
4194 instruction->GetFieldType(),
4195 instruction->GetFieldIndex(),
4196 instruction->GetDexPc(),
4197 calling_convention);
4198}
4199
Alexey Frunze4dda3372015-06-01 18:31:49 -07004200void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
Vladimir Marko70e97462016-08-09 11:04:26 +01004201 LocationSummary* locations =
4202 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
Vladimir Marko804b03f2016-09-14 16:26:36 +01004203 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
Alexey Frunze4dda3372015-06-01 18:31:49 -07004204}
4205
4206void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
4207 HBasicBlock* block = instruction->GetBlock();
4208 if (block->GetLoopInformation() != nullptr) {
4209 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
4210 // The back edge will generate the suspend check.
4211 return;
4212 }
4213 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
4214 // The goto will generate the suspend check.
4215 return;
4216 }
4217 GenerateSuspendCheck(instruction, nullptr);
4218}
4219
Alexey Frunze4dda3372015-06-01 18:31:49 -07004220void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) {
4221 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004222 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004223 InvokeRuntimeCallingConvention calling_convention;
4224 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4225}
4226
4227void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) {
Serban Constantinescufc734082016-07-19 17:18:07 +01004228 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Alexey Frunze4dda3372015-06-01 18:31:49 -07004229 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
4230}
4231
4232void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
4233 Primitive::Type input_type = conversion->GetInputType();
4234 Primitive::Type result_type = conversion->GetResultType();
4235 DCHECK_NE(input_type, result_type);
4236
4237 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
4238 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
4239 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
4240 }
4241
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004242 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion);
4243
4244 if (Primitive::IsFloatingPointType(input_type)) {
4245 locations->SetInAt(0, Location::RequiresFpuRegister());
4246 } else {
4247 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07004248 }
4249
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004250 if (Primitive::IsFloatingPointType(result_type)) {
4251 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004252 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004253 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004254 }
4255}
4256
4257void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
4258 LocationSummary* locations = conversion->GetLocations();
4259 Primitive::Type result_type = conversion->GetResultType();
4260 Primitive::Type input_type = conversion->GetInputType();
4261
4262 DCHECK_NE(input_type, result_type);
4263
4264 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
4265 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
4266 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
4267
4268 switch (result_type) {
4269 case Primitive::kPrimChar:
4270 __ Andi(dst, src, 0xFFFF);
4271 break;
4272 case Primitive::kPrimByte:
Vladimir Markob52bbde2016-02-12 12:06:05 +00004273 if (input_type == Primitive::kPrimLong) {
4274 // Type conversion from long to types narrower than int is a result of code
4275 // transformations. To avoid unpredictable results for SEB and SEH, we first
4276 // need to sign-extend the low 32-bit value into bits 32 through 63.
4277 __ Sll(dst, src, 0);
4278 __ Seb(dst, dst);
4279 } else {
4280 __ Seb(dst, src);
4281 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004282 break;
4283 case Primitive::kPrimShort:
Vladimir Markob52bbde2016-02-12 12:06:05 +00004284 if (input_type == Primitive::kPrimLong) {
4285 // Type conversion from long to types narrower than int is a result of code
4286 // transformations. To avoid unpredictable results for SEB and SEH, we first
4287 // need to sign-extend the low 32-bit value into bits 32 through 63.
4288 __ Sll(dst, src, 0);
4289 __ Seh(dst, dst);
4290 } else {
4291 __ Seh(dst, src);
4292 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004293 break;
4294 case Primitive::kPrimInt:
4295 case Primitive::kPrimLong:
Goran Jakovljevic992bdb92016-12-28 16:21:48 +01004296 // Sign-extend 32-bit int into bits 32 through 63 for int-to-long and long-to-int
4297 // conversions, except when the input and output registers are the same and we are not
4298 // converting longs to shorter types. In these cases, do nothing.
4299 if ((input_type == Primitive::kPrimLong) || (dst != src)) {
4300 __ Sll(dst, src, 0);
4301 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004302 break;
4303
4304 default:
4305 LOG(FATAL) << "Unexpected type conversion from " << input_type
4306 << " to " << result_type;
4307 }
4308 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004309 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
4310 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
4311 if (input_type == Primitive::kPrimLong) {
4312 __ Dmtc1(src, FTMP);
4313 if (result_type == Primitive::kPrimFloat) {
4314 __ Cvtsl(dst, FTMP);
4315 } else {
4316 __ Cvtdl(dst, FTMP);
4317 }
4318 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -07004319 __ Mtc1(src, FTMP);
4320 if (result_type == Primitive::kPrimFloat) {
4321 __ Cvtsw(dst, FTMP);
4322 } else {
4323 __ Cvtdw(dst, FTMP);
4324 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004325 }
4326 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
4327 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004328 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
4329 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
4330 Mips64Label truncate;
4331 Mips64Label done;
4332
4333 // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive
4334 // value when the input is either a NaN or is outside of the range of the output type
4335 // after the truncation. IOW, the three special cases (NaN, too small, too big) produce
4336 // the same result.
4337 //
4338 // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum
4339 // value of the output type if the input is outside of the range after the truncation or
4340 // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct
4341 // results. This matches the desired float/double-to-int/long conversion exactly.
4342 //
4343 // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction.
4344 //
4345 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
4346 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
4347 // even though it must be NAN2008=1 on R6.
4348 //
4349 // The code takes care of the different behaviors by first comparing the input to the
4350 // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int).
4351 // If the input is greater than or equal to the minimum, it procedes to the truncate
4352 // instruction, which will handle such an input the same way irrespective of NAN2008.
4353 // Otherwise the input is compared to itself to determine whether it is a NaN or not
4354 // in order to return either zero or the minimum value.
4355 //
4356 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
4357 // truncate instruction for MIPS64R6.
4358 if (input_type == Primitive::kPrimFloat) {
4359 uint32_t min_val = (result_type == Primitive::kPrimLong)
4360 ? bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min())
4361 : bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min());
4362 __ LoadConst32(TMP, min_val);
4363 __ Mtc1(TMP, FTMP);
4364 __ CmpLeS(FTMP, FTMP, src);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004365 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004366 uint64_t min_val = (result_type == Primitive::kPrimLong)
4367 ? bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min())
4368 : bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min());
4369 __ LoadConst64(TMP, min_val);
4370 __ Dmtc1(TMP, FTMP);
4371 __ CmpLeD(FTMP, FTMP, src);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004372 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004373
4374 __ Bc1nez(FTMP, &truncate);
4375
4376 if (input_type == Primitive::kPrimFloat) {
4377 __ CmpEqS(FTMP, src, src);
4378 } else {
4379 __ CmpEqD(FTMP, src, src);
4380 }
4381 if (result_type == Primitive::kPrimLong) {
4382 __ LoadConst64(dst, std::numeric_limits<int64_t>::min());
4383 } else {
4384 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
4385 }
4386 __ Mfc1(TMP, FTMP);
4387 __ And(dst, dst, TMP);
4388
4389 __ Bc(&done);
4390
4391 __ Bind(&truncate);
4392
4393 if (result_type == Primitive::kPrimLong) {
Roland Levillain888d0672015-11-23 18:53:50 +00004394 if (input_type == Primitive::kPrimFloat) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004395 __ TruncLS(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00004396 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004397 __ TruncLD(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00004398 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004399 __ Dmfc1(dst, FTMP);
Roland Levillain888d0672015-11-23 18:53:50 +00004400 } else {
4401 if (input_type == Primitive::kPrimFloat) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004402 __ TruncWS(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00004403 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004404 __ TruncWD(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00004405 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004406 __ Mfc1(dst, FTMP);
Roland Levillain888d0672015-11-23 18:53:50 +00004407 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004408
4409 __ Bind(&done);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004410 } else if (Primitive::IsFloatingPointType(result_type) &&
4411 Primitive::IsFloatingPointType(input_type)) {
4412 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
4413 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
4414 if (result_type == Primitive::kPrimFloat) {
4415 __ Cvtsd(dst, src);
4416 } else {
4417 __ Cvtds(dst, src);
4418 }
4419 } else {
4420 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
4421 << " to " << result_type;
4422 }
4423}
4424
4425void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) {
4426 HandleShift(ushr);
4427}
4428
4429void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) {
4430 HandleShift(ushr);
4431}
4432
4433void LocationsBuilderMIPS64::VisitXor(HXor* instruction) {
4434 HandleBinaryOp(instruction);
4435}
4436
4437void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) {
4438 HandleBinaryOp(instruction);
4439}
4440
4441void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
4442 // Nothing to do, this should be removed during prepare for register allocator.
4443 LOG(FATAL) << "Unreachable";
4444}
4445
4446void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
4447 // Nothing to do, this should be removed during prepare for register allocator.
4448 LOG(FATAL) << "Unreachable";
4449}
4450
4451void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004452 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004453}
4454
4455void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004456 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004457}
4458
4459void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004460 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004461}
4462
4463void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004464 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004465}
4466
4467void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004468 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004469}
4470
4471void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004472 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004473}
4474
4475void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004476 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004477}
4478
4479void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004480 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004481}
4482
4483void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004484 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004485}
4486
4487void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004488 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004489}
4490
4491void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004492 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004493}
4494
4495void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004496 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004497}
4498
Aart Bike9f37602015-10-09 11:15:55 -07004499void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004500 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004501}
4502
4503void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004504 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004505}
4506
4507void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004508 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004509}
4510
4511void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004512 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004513}
4514
4515void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004516 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004517}
4518
4519void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004520 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004521}
4522
4523void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004524 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004525}
4526
4527void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004528 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004529}
4530
Mark Mendellfe57faa2015-09-18 09:26:15 -04004531// Simple implementation of packed switch - generate cascaded compare/jumps.
4532void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
4533 LocationSummary* locations =
4534 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
4535 locations->SetInAt(0, Location::RequiresRegister());
4536}
4537
Alexey Frunze0960ac52016-12-20 17:24:59 -08004538void InstructionCodeGeneratorMIPS64::GenPackedSwitchWithCompares(GpuRegister value_reg,
4539 int32_t lower_bound,
4540 uint32_t num_entries,
4541 HBasicBlock* switch_block,
4542 HBasicBlock* default_block) {
Vladimir Markof3e0ee22015-12-17 15:23:13 +00004543 // Create a set of compare/jumps.
4544 GpuRegister temp_reg = TMP;
Alexey Frunze0960ac52016-12-20 17:24:59 -08004545 __ Addiu32(temp_reg, value_reg, -lower_bound);
Vladimir Markof3e0ee22015-12-17 15:23:13 +00004546 // Jump to default if index is negative
4547 // Note: We don't check the case that index is positive while value < lower_bound, because in
4548 // this case, index >= num_entries must be true. So that we can save one branch instruction.
4549 __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block));
4550
Alexey Frunze0960ac52016-12-20 17:24:59 -08004551 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00004552 // Jump to successors[0] if value == lower_bound.
4553 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0]));
4554 int32_t last_index = 0;
4555 for (; num_entries - last_index > 2; last_index += 2) {
4556 __ Addiu(temp_reg, temp_reg, -2);
4557 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
4558 __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
4559 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
4560 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
4561 }
4562 if (num_entries - last_index == 2) {
4563 // The last missing case_value.
4564 __ Addiu(temp_reg, temp_reg, -1);
4565 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Mark Mendellfe57faa2015-09-18 09:26:15 -04004566 }
4567
4568 // And the default for any other value.
Alexey Frunze0960ac52016-12-20 17:24:59 -08004569 if (!codegen_->GoesToNextBlock(switch_block, default_block)) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004570 __ Bc(codegen_->GetLabelOf(default_block));
Mark Mendellfe57faa2015-09-18 09:26:15 -04004571 }
4572}
4573
Alexey Frunze0960ac52016-12-20 17:24:59 -08004574void InstructionCodeGeneratorMIPS64::GenTableBasedPackedSwitch(GpuRegister value_reg,
4575 int32_t lower_bound,
4576 uint32_t num_entries,
4577 HBasicBlock* switch_block,
4578 HBasicBlock* default_block) {
4579 // Create a jump table.
4580 std::vector<Mips64Label*> labels(num_entries);
4581 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
4582 for (uint32_t i = 0; i < num_entries; i++) {
4583 labels[i] = codegen_->GetLabelOf(successors[i]);
4584 }
4585 JumpTable* table = __ CreateJumpTable(std::move(labels));
4586
4587 // Is the value in range?
4588 __ Addiu32(TMP, value_reg, -lower_bound);
4589 __ LoadConst32(AT, num_entries);
4590 __ Bgeuc(TMP, AT, codegen_->GetLabelOf(default_block));
4591
4592 // We are in the range of the table.
4593 // Load the target address from the jump table, indexing by the value.
4594 __ LoadLabelAddress(AT, table->GetLabel());
4595 __ Sll(TMP, TMP, 2);
4596 __ Daddu(TMP, TMP, AT);
4597 __ Lw(TMP, TMP, 0);
4598 // Compute the absolute target address by adding the table start address
4599 // (the table contains offsets to targets relative to its start).
4600 __ Daddu(TMP, TMP, AT);
4601 // And jump.
4602 __ Jr(TMP);
4603 __ Nop();
4604}
4605
4606void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
4607 int32_t lower_bound = switch_instr->GetStartValue();
4608 uint32_t num_entries = switch_instr->GetNumEntries();
4609 LocationSummary* locations = switch_instr->GetLocations();
4610 GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>();
4611 HBasicBlock* switch_block = switch_instr->GetBlock();
4612 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
4613
4614 if (num_entries > kPackedSwitchJumpTableThreshold) {
4615 GenTableBasedPackedSwitch(value_reg,
4616 lower_bound,
4617 num_entries,
4618 switch_block,
4619 default_block);
4620 } else {
4621 GenPackedSwitchWithCompares(value_reg,
4622 lower_bound,
4623 num_entries,
4624 switch_block,
4625 default_block);
4626 }
4627}
4628
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00004629void LocationsBuilderMIPS64::VisitClassTableGet(HClassTableGet*) {
4630 UNIMPLEMENTED(FATAL) << "ClassTableGet is unimplemented on mips64";
4631}
4632
4633void InstructionCodeGeneratorMIPS64::VisitClassTableGet(HClassTableGet*) {
4634 UNIMPLEMENTED(FATAL) << "ClassTableGet is unimplemented on mips64";
4635}
4636
Alexey Frunze4dda3372015-06-01 18:31:49 -07004637} // namespace mips64
4638} // namespace art