blob: 446dea659eaf017d89b2cf0abdf506f2b08d634a [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) {
453 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
454 uint32_t new_position = __ GetAdjustedPosition(old_position);
455 DCHECK_GE(new_position, old_position);
456 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
457 }
458
459 // Adjust pc offsets for the disassembly information.
460 if (disasm_info_ != nullptr) {
461 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
462 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
463 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
464 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
465 it.second.start = __ GetAdjustedPosition(it.second.start);
466 it.second.end = __ GetAdjustedPosition(it.second.end);
467 }
468 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
469 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
470 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
471 }
472 }
473
Alexey Frunze4dda3372015-06-01 18:31:49 -0700474 CodeGenerator::Finalize(allocator);
475}
476
477Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const {
478 return codegen_->GetAssembler();
479}
480
481void ParallelMoveResolverMIPS64::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +0100482 MoveOperands* move = moves_[index];
Alexey Frunze4dda3372015-06-01 18:31:49 -0700483 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
484}
485
486void ParallelMoveResolverMIPS64::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +0100487 MoveOperands* move = moves_[index];
Alexey Frunze4dda3372015-06-01 18:31:49 -0700488 codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType());
489}
490
491void ParallelMoveResolverMIPS64::RestoreScratch(int reg) {
492 // Pop reg
493 __ Ld(GpuRegister(reg), SP, 0);
Lazar Trsicd9672662015-09-03 17:33:01 +0200494 __ DecreaseFrameSize(kMips64DoublewordSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700495}
496
497void ParallelMoveResolverMIPS64::SpillScratch(int reg) {
498 // Push reg
Lazar Trsicd9672662015-09-03 17:33:01 +0200499 __ IncreaseFrameSize(kMips64DoublewordSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700500 __ Sd(GpuRegister(reg), SP, 0);
501}
502
503void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) {
504 LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord;
505 StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord;
506 // Allocate a scratch register other than TMP, if available.
507 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
508 // automatically unspilled when the scratch scope object is destroyed).
509 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
510 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
Lazar Trsicd9672662015-09-03 17:33:01 +0200511 int stack_offset = ensure_scratch.IsSpilled() ? kMips64DoublewordSize : 0;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700512 __ LoadFromOffset(load_type,
513 GpuRegister(ensure_scratch.GetRegister()),
514 SP,
515 index1 + stack_offset);
516 __ LoadFromOffset(load_type,
517 TMP,
518 SP,
519 index2 + stack_offset);
520 __ StoreToOffset(store_type,
521 GpuRegister(ensure_scratch.GetRegister()),
522 SP,
523 index2 + stack_offset);
524 __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset);
525}
526
527static dwarf::Reg DWARFReg(GpuRegister reg) {
528 return dwarf::Reg::Mips64Core(static_cast<int>(reg));
529}
530
David Srbeckyba702002016-02-01 18:15:29 +0000531static dwarf::Reg DWARFReg(FpuRegister reg) {
532 return dwarf::Reg::Mips64Fp(static_cast<int>(reg));
533}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700534
535void CodeGeneratorMIPS64::GenerateFrameEntry() {
536 __ Bind(&frame_entry_label_);
537
538 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips64) || !IsLeafMethod();
539
540 if (do_overflow_check) {
541 __ LoadFromOffset(kLoadWord,
542 ZERO,
543 SP,
544 -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips64)));
545 RecordPcInfo(nullptr, 0);
546 }
547
Alexey Frunze4dda3372015-06-01 18:31:49 -0700548 if (HasEmptyFrame()) {
549 return;
550 }
551
552 // Make sure the frame size isn't unreasonably large. Per the various APIs
553 // it looks like it should always be less than 2GB in size, which allows
554 // us using 32-bit signed offsets from the stack pointer.
555 if (GetFrameSize() > 0x7FFFFFFF)
556 LOG(FATAL) << "Stack frame larger than 2GB";
557
558 // Spill callee-saved registers.
559 // Note that their cumulative size is small and they can be indexed using
560 // 16-bit offsets.
561
562 // TODO: increment/decrement SP in one step instead of two or remove this comment.
563
564 uint32_t ofs = FrameEntrySpillSize();
565 __ IncreaseFrameSize(ofs);
566
567 for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) {
568 GpuRegister reg = kCoreCalleeSaves[i];
569 if (allocated_registers_.ContainsCoreRegister(reg)) {
Lazar Trsicd9672662015-09-03 17:33:01 +0200570 ofs -= kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700571 __ Sd(reg, SP, ofs);
572 __ cfi().RelOffset(DWARFReg(reg), ofs);
573 }
574 }
575
576 for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) {
577 FpuRegister reg = kFpuCalleeSaves[i];
578 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
Lazar Trsicd9672662015-09-03 17:33:01 +0200579 ofs -= kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700580 __ Sdc1(reg, SP, ofs);
David Srbeckyba702002016-02-01 18:15:29 +0000581 __ cfi().RelOffset(DWARFReg(reg), ofs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700582 }
583 }
584
585 // Allocate the rest of the frame and store the current method pointer
586 // at its end.
587
588 __ IncreaseFrameSize(GetFrameSize() - FrameEntrySpillSize());
589
Nicolas Geoffray96eeb4e2016-10-12 22:03:31 +0100590 // Save the current method if we need it. Note that we do not
591 // do this in HCurrentMethod, as the instruction might have been removed
592 // in the SSA graph.
593 if (RequiresCurrentMethod()) {
594 static_assert(IsInt<16>(kCurrentMethodStackOffset),
595 "kCurrentMethodStackOffset must fit into int16_t");
596 __ Sd(kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
597 }
Goran Jakovljevicc6418422016-12-05 16:31:55 +0100598
599 if (GetGraph()->HasShouldDeoptimizeFlag()) {
600 // Initialize should_deoptimize flag to 0.
601 __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag());
602 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700603}
604
605void CodeGeneratorMIPS64::GenerateFrameExit() {
606 __ cfi().RememberState();
607
Alexey Frunze4dda3372015-06-01 18:31:49 -0700608 if (!HasEmptyFrame()) {
609 // Deallocate the rest of the frame.
610
611 __ DecreaseFrameSize(GetFrameSize() - FrameEntrySpillSize());
612
613 // Restore callee-saved registers.
614 // Note that their cumulative size is small and they can be indexed using
615 // 16-bit offsets.
616
617 // TODO: increment/decrement SP in one step instead of two or remove this comment.
618
619 uint32_t ofs = 0;
620
621 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
622 FpuRegister reg = kFpuCalleeSaves[i];
623 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
624 __ Ldc1(reg, SP, ofs);
Lazar Trsicd9672662015-09-03 17:33:01 +0200625 ofs += kMips64DoublewordSize;
David Srbeckyba702002016-02-01 18:15:29 +0000626 __ cfi().Restore(DWARFReg(reg));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700627 }
628 }
629
630 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
631 GpuRegister reg = kCoreCalleeSaves[i];
632 if (allocated_registers_.ContainsCoreRegister(reg)) {
633 __ Ld(reg, SP, ofs);
Lazar Trsicd9672662015-09-03 17:33:01 +0200634 ofs += kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700635 __ cfi().Restore(DWARFReg(reg));
636 }
637 }
638
639 DCHECK_EQ(ofs, FrameEntrySpillSize());
640 __ DecreaseFrameSize(ofs);
641 }
642
643 __ Jr(RA);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700644 __ Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700645
646 __ cfi().RestoreState();
647 __ cfi().DefCFAOffset(GetFrameSize());
648}
649
650void CodeGeneratorMIPS64::Bind(HBasicBlock* block) {
651 __ Bind(GetLabelOf(block));
652}
653
654void CodeGeneratorMIPS64::MoveLocation(Location destination,
655 Location source,
Calin Juravlee460d1d2015-09-29 04:52:17 +0100656 Primitive::Type dst_type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700657 if (source.Equals(destination)) {
658 return;
659 }
660
661 // A valid move can always be inferred from the destination and source
662 // locations. When moving from and to a register, the argument type can be
663 // used to generate 32bit instead of 64bit moves.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100664 bool unspecified_type = (dst_type == Primitive::kPrimVoid);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700665 DCHECK_EQ(unspecified_type, false);
666
667 if (destination.IsRegister() || destination.IsFpuRegister()) {
668 if (unspecified_type) {
669 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
670 if (source.IsStackSlot() ||
671 (src_cst != nullptr && (src_cst->IsIntConstant()
672 || src_cst->IsFloatConstant()
673 || src_cst->IsNullConstant()))) {
674 // For stack slots and 32bit constants, a 64bit type is appropriate.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100675 dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700676 } else {
677 // If the source is a double stack slot or a 64bit constant, a 64bit
678 // type is appropriate. Else the source is a register, and since the
679 // type has not been specified, we chose a 64bit type to force a 64bit
680 // move.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100681 dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700682 }
683 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100684 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) ||
685 (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type)));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700686 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
687 // Move to GPR/FPR from stack
688 LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword;
Calin Juravlee460d1d2015-09-29 04:52:17 +0100689 if (Primitive::IsFloatingPointType(dst_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700690 __ LoadFpuFromOffset(load_type,
691 destination.AsFpuRegister<FpuRegister>(),
692 SP,
693 source.GetStackIndex());
694 } else {
695 // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot.
696 __ LoadFromOffset(load_type,
697 destination.AsRegister<GpuRegister>(),
698 SP,
699 source.GetStackIndex());
700 }
701 } else if (source.IsConstant()) {
702 // Move to GPR/FPR from constant
703 GpuRegister gpr = AT;
Calin Juravlee460d1d2015-09-29 04:52:17 +0100704 if (!Primitive::IsFloatingPointType(dst_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700705 gpr = destination.AsRegister<GpuRegister>();
706 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100707 if (dst_type == Primitive::kPrimInt || dst_type == Primitive::kPrimFloat) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700708 int32_t value = GetInt32ValueOf(source.GetConstant()->AsConstant());
709 if (Primitive::IsFloatingPointType(dst_type) && value == 0) {
710 gpr = ZERO;
711 } else {
712 __ LoadConst32(gpr, value);
713 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700714 } else {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700715 int64_t value = GetInt64ValueOf(source.GetConstant()->AsConstant());
716 if (Primitive::IsFloatingPointType(dst_type) && value == 0) {
717 gpr = ZERO;
718 } else {
719 __ LoadConst64(gpr, value);
720 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700721 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100722 if (dst_type == Primitive::kPrimFloat) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700723 __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>());
Calin Juravlee460d1d2015-09-29 04:52:17 +0100724 } else if (dst_type == Primitive::kPrimDouble) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700725 __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>());
726 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100727 } else if (source.IsRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700728 if (destination.IsRegister()) {
729 // Move to GPR from GPR
730 __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>());
731 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100732 DCHECK(destination.IsFpuRegister());
733 if (Primitive::Is64BitType(dst_type)) {
734 __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>());
735 } else {
736 __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>());
737 }
738 }
739 } else if (source.IsFpuRegister()) {
740 if (destination.IsFpuRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700741 // Move to FPR from FPR
Calin Juravlee460d1d2015-09-29 04:52:17 +0100742 if (dst_type == Primitive::kPrimFloat) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700743 __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
744 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100745 DCHECK_EQ(dst_type, Primitive::kPrimDouble);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700746 __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
747 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100748 } else {
749 DCHECK(destination.IsRegister());
750 if (Primitive::Is64BitType(dst_type)) {
751 __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>());
752 } else {
753 __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>());
754 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700755 }
756 }
757 } else { // The destination is not a register. It must be a stack slot.
758 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
759 if (source.IsRegister() || source.IsFpuRegister()) {
760 if (unspecified_type) {
761 if (source.IsRegister()) {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100762 dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700763 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100764 dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700765 }
766 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100767 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) &&
768 (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type)));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700769 // Move to stack from GPR/FPR
770 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
771 if (source.IsRegister()) {
772 __ StoreToOffset(store_type,
773 source.AsRegister<GpuRegister>(),
774 SP,
775 destination.GetStackIndex());
776 } else {
777 __ StoreFpuToOffset(store_type,
778 source.AsFpuRegister<FpuRegister>(),
779 SP,
780 destination.GetStackIndex());
781 }
782 } else if (source.IsConstant()) {
783 // Move to stack from constant
784 HConstant* src_cst = source.GetConstant();
785 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700786 GpuRegister gpr = ZERO;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700787 if (destination.IsStackSlot()) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700788 int32_t value = GetInt32ValueOf(src_cst->AsConstant());
789 if (value != 0) {
790 gpr = TMP;
791 __ LoadConst32(gpr, value);
792 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700793 } else {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700794 DCHECK(destination.IsDoubleStackSlot());
795 int64_t value = GetInt64ValueOf(src_cst->AsConstant());
796 if (value != 0) {
797 gpr = TMP;
798 __ LoadConst64(gpr, value);
799 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700800 }
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700801 __ StoreToOffset(store_type, gpr, SP, destination.GetStackIndex());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700802 } else {
803 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
804 DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot());
805 // Move to stack from stack
806 if (destination.IsStackSlot()) {
807 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
808 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
809 } else {
810 __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex());
811 __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex());
812 }
813 }
814 }
815}
816
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700817void CodeGeneratorMIPS64::SwapLocations(Location loc1, Location loc2, Primitive::Type type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700818 DCHECK(!loc1.IsConstant());
819 DCHECK(!loc2.IsConstant());
820
821 if (loc1.Equals(loc2)) {
822 return;
823 }
824
825 bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot();
826 bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot();
827 bool is_fp_reg1 = loc1.IsFpuRegister();
828 bool is_fp_reg2 = loc2.IsFpuRegister();
829
830 if (loc2.IsRegister() && loc1.IsRegister()) {
831 // Swap 2 GPRs
832 GpuRegister r1 = loc1.AsRegister<GpuRegister>();
833 GpuRegister r2 = loc2.AsRegister<GpuRegister>();
834 __ Move(TMP, r2);
835 __ Move(r2, r1);
836 __ Move(r1, TMP);
837 } else if (is_fp_reg2 && is_fp_reg1) {
838 // Swap 2 FPRs
839 FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>();
840 FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>();
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700841 if (type == Primitive::kPrimFloat) {
842 __ MovS(FTMP, r1);
843 __ MovS(r1, r2);
844 __ MovS(r2, FTMP);
845 } else {
846 DCHECK_EQ(type, Primitive::kPrimDouble);
847 __ MovD(FTMP, r1);
848 __ MovD(r1, r2);
849 __ MovD(r2, FTMP);
850 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700851 } else if (is_slot1 != is_slot2) {
852 // Swap GPR/FPR and stack slot
853 Location reg_loc = is_slot1 ? loc2 : loc1;
854 Location mem_loc = is_slot1 ? loc1 : loc2;
855 LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword;
856 StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword;
857 // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot.
858 __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex());
859 if (reg_loc.IsFpuRegister()) {
860 __ StoreFpuToOffset(store_type,
861 reg_loc.AsFpuRegister<FpuRegister>(),
862 SP,
863 mem_loc.GetStackIndex());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700864 if (mem_loc.IsStackSlot()) {
865 __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
866 } else {
867 DCHECK(mem_loc.IsDoubleStackSlot());
868 __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
869 }
870 } else {
871 __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex());
872 __ Move(reg_loc.AsRegister<GpuRegister>(), TMP);
873 }
874 } else if (is_slot1 && is_slot2) {
875 move_resolver_.Exchange(loc1.GetStackIndex(),
876 loc2.GetStackIndex(),
877 loc1.IsDoubleStackSlot());
878 } else {
879 LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2;
880 }
881}
882
Calin Juravle175dc732015-08-25 15:42:32 +0100883void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) {
884 DCHECK(location.IsRegister());
885 __ LoadConst32(location.AsRegister<GpuRegister>(), value);
886}
887
Calin Juravlee460d1d2015-09-29 04:52:17 +0100888void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) {
889 if (location.IsRegister()) {
890 locations->AddTemp(location);
891 } else {
892 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
893 }
894}
895
Goran Jakovljevic8ed18262016-01-22 13:01:00 +0100896void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object,
897 GpuRegister value,
898 bool value_can_be_null) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700899 Mips64Label done;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700900 GpuRegister card = AT;
901 GpuRegister temp = TMP;
Goran Jakovljevic8ed18262016-01-22 13:01:00 +0100902 if (value_can_be_null) {
903 __ Beqzc(value, &done);
904 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700905 __ LoadFromOffset(kLoadDoubleword,
906 card,
907 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -0700908 Thread::CardTableOffset<kMips64PointerSize>().Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700909 __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift);
910 __ Daddu(temp, card, temp);
911 __ Sb(card, temp, 0);
Goran Jakovljevic8ed18262016-01-22 13:01:00 +0100912 if (value_can_be_null) {
913 __ Bind(&done);
914 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700915}
916
Alexey Frunze19f6c692016-11-30 19:19:55 -0800917template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
918inline void CodeGeneratorMIPS64::EmitPcRelativeLinkerPatches(
919 const ArenaDeque<PcRelativePatchInfo>& infos,
920 ArenaVector<LinkerPatch>* linker_patches) {
921 for (const PcRelativePatchInfo& info : infos) {
922 const DexFile& dex_file = info.target_dex_file;
923 size_t offset_or_index = info.offset_or_index;
924 DCHECK(info.pc_rel_label.IsBound());
925 uint32_t pc_rel_offset = __ GetLabelLocation(&info.pc_rel_label);
926 linker_patches->push_back(Factory(pc_rel_offset, &dex_file, pc_rel_offset, offset_or_index));
927 }
928}
929
930void CodeGeneratorMIPS64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
931 DCHECK(linker_patches->empty());
932 size_t size =
Alexey Frunze19f6c692016-11-30 19:19:55 -0800933 pc_relative_dex_cache_patches_.size() +
Alexey Frunzef63f5692016-12-13 17:43:11 -0800934 pc_relative_string_patches_.size() +
935 pc_relative_type_patches_.size() +
Vladimir Marko1998cd02017-01-13 13:02:58 +0000936 type_bss_entry_patches_.size() +
Alexey Frunzef63f5692016-12-13 17:43:11 -0800937 boot_image_string_patches_.size() +
938 boot_image_type_patches_.size() +
939 boot_image_address_patches_.size();
Alexey Frunze19f6c692016-11-30 19:19:55 -0800940 linker_patches->reserve(size);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800941 EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_,
942 linker_patches);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800943 if (!GetCompilerOptions().IsBootImage()) {
Vladimir Marko1998cd02017-01-13 13:02:58 +0000944 DCHECK(pc_relative_type_patches_.empty());
Alexey Frunzef63f5692016-12-13 17:43:11 -0800945 EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_,
946 linker_patches);
947 } else {
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000948 EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_,
949 linker_patches);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800950 EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_,
951 linker_patches);
952 }
Vladimir Marko1998cd02017-01-13 13:02:58 +0000953 EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_,
954 linker_patches);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800955 for (const auto& entry : boot_image_string_patches_) {
956 const StringReference& target_string = entry.first;
957 Literal* literal = entry.second;
958 DCHECK(literal->GetLabel()->IsBound());
959 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
960 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
961 target_string.dex_file,
962 target_string.string_index.index_));
963 }
964 for (const auto& entry : boot_image_type_patches_) {
965 const TypeReference& target_type = entry.first;
966 Literal* literal = entry.second;
967 DCHECK(literal->GetLabel()->IsBound());
968 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
969 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
970 target_type.dex_file,
971 target_type.type_index.index_));
972 }
973 for (const auto& entry : boot_image_address_patches_) {
974 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
975 Literal* literal = entry.second;
976 DCHECK(literal->GetLabel()->IsBound());
977 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
978 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
979 }
Vladimir Marko1998cd02017-01-13 13:02:58 +0000980 DCHECK_EQ(size, linker_patches->size());
Alexey Frunzef63f5692016-12-13 17:43:11 -0800981}
982
983CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeStringPatch(
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000984 const DexFile& dex_file, dex::StringIndex string_index) {
985 return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800986}
987
988CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeTypePatch(
989 const DexFile& dex_file, dex::TypeIndex type_index) {
990 return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800991}
992
Vladimir Marko1998cd02017-01-13 13:02:58 +0000993CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewTypeBssEntryPatch(
994 const DexFile& dex_file, dex::TypeIndex type_index) {
995 return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_);
996}
997
Alexey Frunze19f6c692016-11-30 19:19:55 -0800998CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeDexCacheArrayPatch(
999 const DexFile& dex_file, uint32_t element_offset) {
1000 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
1001}
1002
Alexey Frunze19f6c692016-11-30 19:19:55 -08001003CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativePatch(
1004 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
1005 patches->emplace_back(dex_file, offset_or_index);
1006 return &patches->back();
1007}
1008
Alexey Frunzef63f5692016-12-13 17:43:11 -08001009Literal* CodeGeneratorMIPS64::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
1010 return map->GetOrCreate(
1011 value,
1012 [this, value]() { return __ NewLiteral<uint32_t>(value); });
1013}
1014
Alexey Frunze19f6c692016-11-30 19:19:55 -08001015Literal* CodeGeneratorMIPS64::DeduplicateUint64Literal(uint64_t value) {
1016 return uint64_literals_.GetOrCreate(
1017 value,
1018 [this, value]() { return __ NewLiteral<uint64_t>(value); });
1019}
1020
1021Literal* CodeGeneratorMIPS64::DeduplicateMethodLiteral(MethodReference target_method,
1022 MethodToLiteralMap* map) {
1023 return map->GetOrCreate(
1024 target_method,
1025 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1026}
1027
Alexey Frunzef63f5692016-12-13 17:43:11 -08001028Literal* CodeGeneratorMIPS64::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
1029 dex::StringIndex string_index) {
1030 return boot_image_string_patches_.GetOrCreate(
1031 StringReference(&dex_file, string_index),
1032 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1033}
1034
1035Literal* CodeGeneratorMIPS64::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
1036 dex::TypeIndex type_index) {
1037 return boot_image_type_patches_.GetOrCreate(
1038 TypeReference(&dex_file, type_index),
1039 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1040}
1041
1042Literal* CodeGeneratorMIPS64::DeduplicateBootImageAddressLiteral(uint64_t address) {
1043 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
1044 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
1045 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
1046}
1047
Alexey Frunze19f6c692016-11-30 19:19:55 -08001048void CodeGeneratorMIPS64::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info,
1049 GpuRegister out) {
1050 __ Bind(&info->pc_rel_label);
1051 // Add the high half of a 32-bit offset to PC.
1052 __ Auipc(out, /* placeholder */ 0x1234);
1053 // The immediately following instruction will add the sign-extended low half of the 32-bit
Alexey Frunzef63f5692016-12-13 17:43:11 -08001054 // offset to `out` (e.g. ld, jialc, daddiu).
Alexey Frunze19f6c692016-11-30 19:19:55 -08001055}
1056
David Brazdil58282f42016-01-14 12:45:10 +00001057void CodeGeneratorMIPS64::SetupBlockedRegisters() const {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001058 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
1059 blocked_core_registers_[ZERO] = true;
1060 blocked_core_registers_[K0] = true;
1061 blocked_core_registers_[K1] = true;
1062 blocked_core_registers_[GP] = true;
1063 blocked_core_registers_[SP] = true;
1064 blocked_core_registers_[RA] = true;
1065
Lazar Trsicd9672662015-09-03 17:33:01 +02001066 // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch
1067 // registers (similar to how AT is used by MIPS assemblers).
Alexey Frunze4dda3372015-06-01 18:31:49 -07001068 blocked_core_registers_[AT] = true;
1069 blocked_core_registers_[TMP] = true;
Lazar Trsicd9672662015-09-03 17:33:01 +02001070 blocked_core_registers_[TMP2] = true;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001071 blocked_fpu_registers_[FTMP] = true;
1072
1073 // Reserve suspend and thread registers.
1074 blocked_core_registers_[S0] = true;
1075 blocked_core_registers_[TR] = true;
1076
1077 // Reserve T9 for function calls
1078 blocked_core_registers_[T9] = true;
1079
Goran Jakovljevic782be112016-06-21 12:39:04 +02001080 if (GetGraph()->IsDebuggable()) {
1081 // Stubs do not save callee-save floating point registers. If the graph
1082 // is debuggable, we need to deal with these registers differently. For
1083 // now, just block them.
1084 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1085 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1086 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001087 }
1088}
1089
Alexey Frunze4dda3372015-06-01 18:31:49 -07001090size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1091 __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index);
Lazar Trsicd9672662015-09-03 17:33:01 +02001092 return kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001093}
1094
1095size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1096 __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index);
Lazar Trsicd9672662015-09-03 17:33:01 +02001097 return kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001098}
1099
1100size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1101 __ StoreFpuToOffset(kStoreDoubleword, FpuRegister(reg_id), SP, stack_index);
Lazar Trsicd9672662015-09-03 17:33:01 +02001102 return kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001103}
1104
1105size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1106 __ LoadFpuFromOffset(kLoadDoubleword, FpuRegister(reg_id), SP, stack_index);
Lazar Trsicd9672662015-09-03 17:33:01 +02001107 return kMips64DoublewordSize;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001108}
1109
1110void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdil9f0dece2015-09-21 18:20:26 +01001111 stream << GpuRegister(reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001112}
1113
1114void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdil9f0dece2015-09-21 18:20:26 +01001115 stream << FpuRegister(reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001116}
1117
Calin Juravle175dc732015-08-25 15:42:32 +01001118void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint,
Alexey Frunze4dda3372015-06-01 18:31:49 -07001119 HInstruction* instruction,
1120 uint32_t dex_pc,
1121 SlowPathCode* slow_path) {
Alexandre Rames91a65162016-09-19 13:54:30 +01001122 ValidateInvokeRuntime(entrypoint, instruction, slow_path);
Serban Constantinescufc734082016-07-19 17:18:07 +01001123 __ LoadFromOffset(kLoadDoubleword,
1124 T9,
1125 TR,
1126 GetThreadOffset<kMips64PointerSize>(entrypoint).Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001127 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001128 __ Nop();
Serban Constantinescufc734082016-07-19 17:18:07 +01001129 if (EntrypointRequiresStackMap(entrypoint)) {
1130 RecordPcInfo(instruction, dex_pc, slow_path);
1131 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001132}
1133
1134void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path,
1135 GpuRegister class_reg) {
1136 __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
1137 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
1138 __ Bltc(TMP, AT, slow_path->GetEntryLabel());
1139 // TODO: barrier needed?
1140 __ Bind(slow_path->GetExitLabel());
1141}
1142
1143void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1144 __ Sync(0); // only stype 0 is supported
1145}
1146
1147void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction,
1148 HBasicBlock* successor) {
1149 SuspendCheckSlowPathMIPS64* slow_path =
1150 new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS64(instruction, successor);
1151 codegen_->AddSlowPath(slow_path);
1152
1153 __ LoadFromOffset(kLoadUnsignedHalfword,
1154 TMP,
1155 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001156 Thread::ThreadFlagsOffset<kMips64PointerSize>().Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001157 if (successor == nullptr) {
1158 __ Bnezc(TMP, slow_path->GetEntryLabel());
1159 __ Bind(slow_path->GetReturnLabel());
1160 } else {
1161 __ Beqzc(TMP, codegen_->GetLabelOf(successor));
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001162 __ Bc(slow_path->GetEntryLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001163 // slow_path will return to GetLabelOf(successor).
1164 }
1165}
1166
1167InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph,
1168 CodeGeneratorMIPS64* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001169 : InstructionCodeGenerator(graph, codegen),
Alexey Frunze4dda3372015-06-01 18:31:49 -07001170 assembler_(codegen->GetAssembler()),
1171 codegen_(codegen) {}
1172
1173void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
1174 DCHECK_EQ(instruction->InputCount(), 2U);
1175 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1176 Primitive::Type type = instruction->GetResultType();
1177 switch (type) {
1178 case Primitive::kPrimInt:
1179 case Primitive::kPrimLong: {
1180 locations->SetInAt(0, Location::RequiresRegister());
1181 HInstruction* right = instruction->InputAt(1);
1182 bool can_use_imm = false;
1183 if (right->IsConstant()) {
1184 int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant());
1185 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1186 can_use_imm = IsUint<16>(imm);
1187 } else if (instruction->IsAdd()) {
1188 can_use_imm = IsInt<16>(imm);
1189 } else {
1190 DCHECK(instruction->IsSub());
1191 can_use_imm = IsInt<16>(-imm);
1192 }
1193 }
1194 if (can_use_imm)
1195 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1196 else
1197 locations->SetInAt(1, Location::RequiresRegister());
1198 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1199 }
1200 break;
1201
1202 case Primitive::kPrimFloat:
1203 case Primitive::kPrimDouble:
1204 locations->SetInAt(0, Location::RequiresFpuRegister());
1205 locations->SetInAt(1, Location::RequiresFpuRegister());
1206 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1207 break;
1208
1209 default:
1210 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1211 }
1212}
1213
1214void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
1215 Primitive::Type type = instruction->GetType();
1216 LocationSummary* locations = instruction->GetLocations();
1217
1218 switch (type) {
1219 case Primitive::kPrimInt:
1220 case Primitive::kPrimLong: {
1221 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1222 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1223 Location rhs_location = locations->InAt(1);
1224
1225 GpuRegister rhs_reg = ZERO;
1226 int64_t rhs_imm = 0;
1227 bool use_imm = rhs_location.IsConstant();
1228 if (use_imm) {
1229 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
1230 } else {
1231 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1232 }
1233
1234 if (instruction->IsAnd()) {
1235 if (use_imm)
1236 __ Andi(dst, lhs, rhs_imm);
1237 else
1238 __ And(dst, lhs, rhs_reg);
1239 } else if (instruction->IsOr()) {
1240 if (use_imm)
1241 __ Ori(dst, lhs, rhs_imm);
1242 else
1243 __ Or(dst, lhs, rhs_reg);
1244 } else if (instruction->IsXor()) {
1245 if (use_imm)
1246 __ Xori(dst, lhs, rhs_imm);
1247 else
1248 __ Xor(dst, lhs, rhs_reg);
1249 } else if (instruction->IsAdd()) {
1250 if (type == Primitive::kPrimInt) {
1251 if (use_imm)
1252 __ Addiu(dst, lhs, rhs_imm);
1253 else
1254 __ Addu(dst, lhs, rhs_reg);
1255 } else {
1256 if (use_imm)
1257 __ Daddiu(dst, lhs, rhs_imm);
1258 else
1259 __ Daddu(dst, lhs, rhs_reg);
1260 }
1261 } else {
1262 DCHECK(instruction->IsSub());
1263 if (type == Primitive::kPrimInt) {
1264 if (use_imm)
1265 __ Addiu(dst, lhs, -rhs_imm);
1266 else
1267 __ Subu(dst, lhs, rhs_reg);
1268 } else {
1269 if (use_imm)
1270 __ Daddiu(dst, lhs, -rhs_imm);
1271 else
1272 __ Dsubu(dst, lhs, rhs_reg);
1273 }
1274 }
1275 break;
1276 }
1277 case Primitive::kPrimFloat:
1278 case Primitive::kPrimDouble: {
1279 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
1280 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1281 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1282 if (instruction->IsAdd()) {
1283 if (type == Primitive::kPrimFloat)
1284 __ AddS(dst, lhs, rhs);
1285 else
1286 __ AddD(dst, lhs, rhs);
1287 } else if (instruction->IsSub()) {
1288 if (type == Primitive::kPrimFloat)
1289 __ SubS(dst, lhs, rhs);
1290 else
1291 __ SubD(dst, lhs, rhs);
1292 } else {
1293 LOG(FATAL) << "Unexpected floating-point binary operation";
1294 }
1295 break;
1296 }
1297 default:
1298 LOG(FATAL) << "Unexpected binary operation type " << type;
1299 }
1300}
1301
1302void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001303 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001304
1305 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1306 Primitive::Type type = instr->GetResultType();
1307 switch (type) {
1308 case Primitive::kPrimInt:
1309 case Primitive::kPrimLong: {
1310 locations->SetInAt(0, Location::RequiresRegister());
1311 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001312 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001313 break;
1314 }
1315 default:
1316 LOG(FATAL) << "Unexpected shift type " << type;
1317 }
1318}
1319
1320void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001321 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001322 LocationSummary* locations = instr->GetLocations();
1323 Primitive::Type type = instr->GetType();
1324
1325 switch (type) {
1326 case Primitive::kPrimInt:
1327 case Primitive::kPrimLong: {
1328 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1329 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1330 Location rhs_location = locations->InAt(1);
1331
1332 GpuRegister rhs_reg = ZERO;
1333 int64_t rhs_imm = 0;
1334 bool use_imm = rhs_location.IsConstant();
1335 if (use_imm) {
1336 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
1337 } else {
1338 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1339 }
1340
1341 if (use_imm) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00001342 uint32_t shift_value = rhs_imm &
1343 (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001344
Alexey Frunze92d90602015-12-18 18:16:36 -08001345 if (shift_value == 0) {
1346 if (dst != lhs) {
1347 __ Move(dst, lhs);
1348 }
1349 } else if (type == Primitive::kPrimInt) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001350 if (instr->IsShl()) {
1351 __ Sll(dst, lhs, shift_value);
1352 } else if (instr->IsShr()) {
1353 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001354 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001355 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001356 } else {
1357 __ Rotr(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001358 }
1359 } else {
1360 if (shift_value < 32) {
1361 if (instr->IsShl()) {
1362 __ Dsll(dst, lhs, shift_value);
1363 } else if (instr->IsShr()) {
1364 __ Dsra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001365 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001366 __ Dsrl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001367 } else {
1368 __ Drotr(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001369 }
1370 } else {
1371 shift_value -= 32;
1372 if (instr->IsShl()) {
1373 __ Dsll32(dst, lhs, shift_value);
1374 } else if (instr->IsShr()) {
1375 __ Dsra32(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001376 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001377 __ Dsrl32(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001378 } else {
1379 __ Drotr32(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001380 }
1381 }
1382 }
1383 } else {
1384 if (type == Primitive::kPrimInt) {
1385 if (instr->IsShl()) {
1386 __ Sllv(dst, lhs, rhs_reg);
1387 } else if (instr->IsShr()) {
1388 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001389 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001390 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001391 } else {
1392 __ Rotrv(dst, lhs, rhs_reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001393 }
1394 } else {
1395 if (instr->IsShl()) {
1396 __ Dsllv(dst, lhs, rhs_reg);
1397 } else if (instr->IsShr()) {
1398 __ Dsrav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001399 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001400 __ Dsrlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001401 } else {
1402 __ Drotrv(dst, lhs, rhs_reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001403 }
1404 }
1405 }
1406 break;
1407 }
1408 default:
1409 LOG(FATAL) << "Unexpected shift operation type " << type;
1410 }
1411}
1412
1413void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) {
1414 HandleBinaryOp(instruction);
1415}
1416
1417void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) {
1418 HandleBinaryOp(instruction);
1419}
1420
1421void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) {
1422 HandleBinaryOp(instruction);
1423}
1424
1425void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) {
1426 HandleBinaryOp(instruction);
1427}
1428
1429void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) {
1430 LocationSummary* locations =
1431 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1432 locations->SetInAt(0, Location::RequiresRegister());
1433 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1434 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1435 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1436 } else {
1437 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1438 }
1439}
1440
1441void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) {
1442 LocationSummary* locations = instruction->GetLocations();
1443 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1444 Location index = locations->InAt(1);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001445 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001446
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001447 Primitive::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001448 switch (type) {
1449 case Primitive::kPrimBoolean: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001450 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1451 if (index.IsConstant()) {
1452 size_t offset =
1453 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1454 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1455 } else {
1456 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1457 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset);
1458 }
1459 break;
1460 }
1461
1462 case Primitive::kPrimByte: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001463 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1464 if (index.IsConstant()) {
1465 size_t offset =
1466 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1467 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1468 } else {
1469 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1470 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset);
1471 }
1472 break;
1473 }
1474
1475 case Primitive::kPrimShort: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001476 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1477 if (index.IsConstant()) {
1478 size_t offset =
1479 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1480 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1481 } else {
1482 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1483 __ Daddu(TMP, obj, TMP);
1484 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset);
1485 }
1486 break;
1487 }
1488
1489 case Primitive::kPrimChar: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001490 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1491 if (index.IsConstant()) {
1492 size_t offset =
1493 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1494 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1495 } else {
1496 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1497 __ Daddu(TMP, obj, TMP);
1498 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset);
1499 }
1500 break;
1501 }
1502
1503 case Primitive::kPrimInt:
1504 case Primitive::kPrimNot: {
1505 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
Alexey Frunze4dda3372015-06-01 18:31:49 -07001506 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1507 LoadOperandType load_type = (type == Primitive::kPrimNot) ? kLoadUnsignedWord : kLoadWord;
1508 if (index.IsConstant()) {
1509 size_t offset =
1510 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1511 __ LoadFromOffset(load_type, out, obj, offset);
1512 } else {
1513 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1514 __ Daddu(TMP, obj, TMP);
1515 __ LoadFromOffset(load_type, out, TMP, data_offset);
1516 }
1517 break;
1518 }
1519
1520 case Primitive::kPrimLong: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001521 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1522 if (index.IsConstant()) {
1523 size_t offset =
1524 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1525 __ LoadFromOffset(kLoadDoubleword, out, obj, offset);
1526 } else {
1527 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1528 __ Daddu(TMP, obj, TMP);
1529 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset);
1530 }
1531 break;
1532 }
1533
1534 case Primitive::kPrimFloat: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001535 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
1536 if (index.IsConstant()) {
1537 size_t offset =
1538 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1539 __ LoadFpuFromOffset(kLoadWord, out, obj, offset);
1540 } else {
1541 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1542 __ Daddu(TMP, obj, TMP);
1543 __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset);
1544 }
1545 break;
1546 }
1547
1548 case Primitive::kPrimDouble: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001549 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
1550 if (index.IsConstant()) {
1551 size_t offset =
1552 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1553 __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset);
1554 } else {
1555 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1556 __ Daddu(TMP, obj, TMP);
1557 __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset);
1558 }
1559 break;
1560 }
1561
1562 case Primitive::kPrimVoid:
1563 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1564 UNREACHABLE();
1565 }
1566 codegen_->MaybeRecordImplicitNullCheck(instruction);
1567}
1568
1569void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) {
1570 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1571 locations->SetInAt(0, Location::RequiresRegister());
1572 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1573}
1574
1575void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) {
1576 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01001577 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001578 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1579 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1580 __ LoadFromOffset(kLoadWord, out, obj, offset);
1581 codegen_->MaybeRecordImplicitNullCheck(instruction);
1582}
1583
1584void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) {
David Brazdilbb3d5052015-09-21 18:39:16 +01001585 bool needs_runtime_call = instruction->NeedsTypeCheck();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001586 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1587 instruction,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001588 needs_runtime_call ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
David Brazdilbb3d5052015-09-21 18:39:16 +01001589 if (needs_runtime_call) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001590 InvokeRuntimeCallingConvention calling_convention;
1591 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1592 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1593 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1594 } else {
1595 locations->SetInAt(0, Location::RequiresRegister());
1596 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1597 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
1598 locations->SetInAt(2, Location::RequiresFpuRegister());
1599 } else {
1600 locations->SetInAt(2, Location::RequiresRegister());
1601 }
1602 }
1603}
1604
1605void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) {
1606 LocationSummary* locations = instruction->GetLocations();
1607 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1608 Location index = locations->InAt(1);
1609 Primitive::Type value_type = instruction->GetComponentType();
1610 bool needs_runtime_call = locations->WillCall();
1611 bool needs_write_barrier =
1612 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
1613
1614 switch (value_type) {
1615 case Primitive::kPrimBoolean:
1616 case Primitive::kPrimByte: {
1617 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1618 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1619 if (index.IsConstant()) {
1620 size_t offset =
1621 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1622 __ StoreToOffset(kStoreByte, value, obj, offset);
1623 } else {
1624 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1625 __ StoreToOffset(kStoreByte, value, TMP, data_offset);
1626 }
1627 break;
1628 }
1629
1630 case Primitive::kPrimShort:
1631 case Primitive::kPrimChar: {
1632 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
1633 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1634 if (index.IsConstant()) {
1635 size_t offset =
1636 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1637 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1638 } else {
1639 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1640 __ Daddu(TMP, obj, TMP);
1641 __ StoreToOffset(kStoreHalfword, value, TMP, data_offset);
1642 }
1643 break;
1644 }
1645
1646 case Primitive::kPrimInt:
1647 case Primitive::kPrimNot: {
1648 if (!needs_runtime_call) {
1649 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
1650 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1651 if (index.IsConstant()) {
1652 size_t offset =
1653 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1654 __ StoreToOffset(kStoreWord, value, obj, offset);
1655 } else {
1656 DCHECK(index.IsRegister()) << index;
1657 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1658 __ Daddu(TMP, obj, TMP);
1659 __ StoreToOffset(kStoreWord, value, TMP, data_offset);
1660 }
1661 codegen_->MaybeRecordImplicitNullCheck(instruction);
1662 if (needs_write_barrier) {
1663 DCHECK_EQ(value_type, Primitive::kPrimNot);
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01001664 codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001665 }
1666 } else {
1667 DCHECK_EQ(value_type, Primitive::kPrimNot);
Serban Constantinescufc734082016-07-19 17:18:07 +01001668 codegen_->InvokeRuntime(kQuickAputObject, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00001669 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001670 }
1671 break;
1672 }
1673
1674 case Primitive::kPrimLong: {
1675 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
1676 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1677 if (index.IsConstant()) {
1678 size_t offset =
1679 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1680 __ StoreToOffset(kStoreDoubleword, value, obj, offset);
1681 } else {
1682 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1683 __ Daddu(TMP, obj, TMP);
1684 __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset);
1685 }
1686 break;
1687 }
1688
1689 case Primitive::kPrimFloat: {
1690 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
1691 FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>();
1692 DCHECK(locations->InAt(2).IsFpuRegister());
1693 if (index.IsConstant()) {
1694 size_t offset =
1695 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1696 __ StoreFpuToOffset(kStoreWord, value, obj, offset);
1697 } else {
1698 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1699 __ Daddu(TMP, obj, TMP);
1700 __ StoreFpuToOffset(kStoreWord, value, TMP, data_offset);
1701 }
1702 break;
1703 }
1704
1705 case Primitive::kPrimDouble: {
1706 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
1707 FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>();
1708 DCHECK(locations->InAt(2).IsFpuRegister());
1709 if (index.IsConstant()) {
1710 size_t offset =
1711 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1712 __ StoreFpuToOffset(kStoreDoubleword, value, obj, offset);
1713 } else {
1714 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1715 __ Daddu(TMP, obj, TMP);
1716 __ StoreFpuToOffset(kStoreDoubleword, value, TMP, data_offset);
1717 }
1718 break;
1719 }
1720
1721 case Primitive::kPrimVoid:
1722 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1723 UNREACHABLE();
1724 }
1725
1726 // Ints and objects are handled in the switch.
1727 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
1728 codegen_->MaybeRecordImplicitNullCheck(instruction);
1729 }
1730}
1731
1732void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01001733 RegisterSet caller_saves = RegisterSet::Empty();
1734 InvokeRuntimeCallingConvention calling_convention;
1735 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1736 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1737 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001738 locations->SetInAt(0, Location::RequiresRegister());
1739 locations->SetInAt(1, Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001740}
1741
1742void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
1743 LocationSummary* locations = instruction->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01001744 BoundsCheckSlowPathMIPS64* slow_path =
1745 new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001746 codegen_->AddSlowPath(slow_path);
1747
1748 GpuRegister index = locations->InAt(0).AsRegister<GpuRegister>();
1749 GpuRegister length = locations->InAt(1).AsRegister<GpuRegister>();
1750
1751 // length is limited by the maximum positive signed 32-bit integer.
1752 // Unsigned comparison of length and index checks for index < 0
1753 // and for length <= index simultaneously.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001754 __ Bgeuc(index, length, slow_path->GetEntryLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001755}
1756
1757void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) {
1758 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1759 instruction,
1760 LocationSummary::kCallOnSlowPath);
1761 locations->SetInAt(0, Location::RequiresRegister());
1762 locations->SetInAt(1, Location::RequiresRegister());
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01001763 // Note that TypeCheckSlowPathMIPS64 uses this register too.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001764 locations->AddTemp(Location::RequiresRegister());
1765}
1766
1767void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) {
1768 LocationSummary* locations = instruction->GetLocations();
1769 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1770 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
1771 GpuRegister obj_cls = locations->GetTemp(0).AsRegister<GpuRegister>();
1772
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01001773 SlowPathCodeMIPS64* slow_path =
1774 new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001775 codegen_->AddSlowPath(slow_path);
1776
1777 // TODO: avoid this check if we know obj is not null.
1778 __ Beqzc(obj, slow_path->GetExitLabel());
1779 // Compare the class of `obj` with `cls`.
1780 __ LoadFromOffset(kLoadUnsignedWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value());
1781 __ Bnec(obj_cls, cls, slow_path->GetEntryLabel());
1782 __ Bind(slow_path->GetExitLabel());
1783}
1784
1785void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) {
1786 LocationSummary* locations =
1787 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1788 locations->SetInAt(0, Location::RequiresRegister());
1789 if (check->HasUses()) {
1790 locations->SetOut(Location::SameAsFirstInput());
1791 }
1792}
1793
1794void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) {
1795 // We assume the class is not null.
1796 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64(
1797 check->GetLoadClass(),
1798 check,
1799 check->GetDexPc(),
1800 true);
1801 codegen_->AddSlowPath(slow_path);
1802 GenerateClassInitializationCheck(slow_path,
1803 check->GetLocations()->InAt(0).AsRegister<GpuRegister>());
1804}
1805
1806void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) {
1807 Primitive::Type in_type = compare->InputAt(0)->GetType();
1808
Alexey Frunze299a9392015-12-08 16:08:02 -08001809 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(compare);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001810
1811 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00001812 case Primitive::kPrimBoolean:
1813 case Primitive::kPrimByte:
1814 case Primitive::kPrimShort:
1815 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08001816 case Primitive::kPrimInt:
Alexey Frunze4dda3372015-06-01 18:31:49 -07001817 case Primitive::kPrimLong:
1818 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001819 locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07001820 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1821 break;
1822
1823 case Primitive::kPrimFloat:
Alexey Frunze299a9392015-12-08 16:08:02 -08001824 case Primitive::kPrimDouble:
1825 locations->SetInAt(0, Location::RequiresFpuRegister());
1826 locations->SetInAt(1, Location::RequiresFpuRegister());
1827 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001828 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001829
1830 default:
1831 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1832 }
1833}
1834
1835void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) {
1836 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze299a9392015-12-08 16:08:02 -08001837 GpuRegister res = locations->Out().AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001838 Primitive::Type in_type = instruction->InputAt(0)->GetType();
1839
1840 // 0 if: left == right
1841 // 1 if: left > right
1842 // -1 if: left < right
1843 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00001844 case Primitive::kPrimBoolean:
1845 case Primitive::kPrimByte:
1846 case Primitive::kPrimShort:
1847 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08001848 case Primitive::kPrimInt:
Alexey Frunze4dda3372015-06-01 18:31:49 -07001849 case Primitive::kPrimLong: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001850 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001851 Location rhs_location = locations->InAt(1);
1852 bool use_imm = rhs_location.IsConstant();
1853 GpuRegister rhs = ZERO;
1854 if (use_imm) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00001855 if (in_type == Primitive::kPrimLong) {
Aart Bika19616e2016-02-01 18:57:58 -08001856 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
1857 if (value != 0) {
1858 rhs = AT;
1859 __ LoadConst64(rhs, value);
1860 }
Roland Levillaina5c4a402016-03-15 15:02:50 +00001861 } else {
1862 int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant());
1863 if (value != 0) {
1864 rhs = AT;
1865 __ LoadConst32(rhs, value);
1866 }
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001867 }
1868 } else {
1869 rhs = rhs_location.AsRegister<GpuRegister>();
1870 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001871 __ Slt(TMP, lhs, rhs);
Alexey Frunze299a9392015-12-08 16:08:02 -08001872 __ Slt(res, rhs, lhs);
1873 __ Subu(res, res, TMP);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001874 break;
1875 }
1876
Alexey Frunze299a9392015-12-08 16:08:02 -08001877 case Primitive::kPrimFloat: {
1878 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1879 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1880 Mips64Label done;
1881 __ CmpEqS(FTMP, lhs, rhs);
1882 __ LoadConst32(res, 0);
1883 __ Bc1nez(FTMP, &done);
Roland Levillain32ca3752016-02-17 16:49:37 +00001884 if (instruction->IsGtBias()) {
Alexey Frunze299a9392015-12-08 16:08:02 -08001885 __ CmpLtS(FTMP, lhs, rhs);
1886 __ LoadConst32(res, -1);
1887 __ Bc1nez(FTMP, &done);
1888 __ LoadConst32(res, 1);
1889 } else {
1890 __ CmpLtS(FTMP, rhs, lhs);
1891 __ LoadConst32(res, 1);
1892 __ Bc1nez(FTMP, &done);
1893 __ LoadConst32(res, -1);
1894 }
1895 __ Bind(&done);
1896 break;
1897 }
1898
Alexey Frunze4dda3372015-06-01 18:31:49 -07001899 case Primitive::kPrimDouble: {
Alexey Frunze299a9392015-12-08 16:08:02 -08001900 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1901 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1902 Mips64Label done;
1903 __ CmpEqD(FTMP, lhs, rhs);
1904 __ LoadConst32(res, 0);
1905 __ Bc1nez(FTMP, &done);
Roland Levillain32ca3752016-02-17 16:49:37 +00001906 if (instruction->IsGtBias()) {
Alexey Frunze299a9392015-12-08 16:08:02 -08001907 __ CmpLtD(FTMP, lhs, rhs);
1908 __ LoadConst32(res, -1);
1909 __ Bc1nez(FTMP, &done);
1910 __ LoadConst32(res, 1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001911 } else {
Alexey Frunze299a9392015-12-08 16:08:02 -08001912 __ CmpLtD(FTMP, rhs, lhs);
1913 __ LoadConst32(res, 1);
1914 __ Bc1nez(FTMP, &done);
1915 __ LoadConst32(res, -1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001916 }
Alexey Frunze299a9392015-12-08 16:08:02 -08001917 __ Bind(&done);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001918 break;
1919 }
1920
1921 default:
1922 LOG(FATAL) << "Unimplemented compare type " << in_type;
1923 }
1924}
1925
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001926void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001927 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexey Frunze299a9392015-12-08 16:08:02 -08001928 switch (instruction->InputAt(0)->GetType()) {
1929 default:
1930 case Primitive::kPrimLong:
1931 locations->SetInAt(0, Location::RequiresRegister());
1932 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1933 break;
1934
1935 case Primitive::kPrimFloat:
1936 case Primitive::kPrimDouble:
1937 locations->SetInAt(0, Location::RequiresFpuRegister());
1938 locations->SetInAt(1, Location::RequiresFpuRegister());
1939 break;
1940 }
David Brazdilb3e773e2016-01-26 11:28:37 +00001941 if (!instruction->IsEmittedAtUseSite()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001942 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1943 }
1944}
1945
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001946void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00001947 if (instruction->IsEmittedAtUseSite()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001948 return;
1949 }
1950
Alexey Frunze299a9392015-12-08 16:08:02 -08001951 Primitive::Type type = instruction->InputAt(0)->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001952 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze299a9392015-12-08 16:08:02 -08001953 switch (type) {
1954 default:
1955 // Integer case.
1956 GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations);
1957 return;
1958 case Primitive::kPrimLong:
1959 GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations);
1960 return;
Alexey Frunze299a9392015-12-08 16:08:02 -08001961 case Primitive::kPrimFloat:
1962 case Primitive::kPrimDouble:
Tijana Jakovljevic43758192016-12-30 09:23:01 +01001963 GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations);
1964 return;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001965 }
1966}
1967
Alexey Frunzec857c742015-09-23 15:12:39 -07001968void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
1969 DCHECK(instruction->IsDiv() || instruction->IsRem());
1970 Primitive::Type type = instruction->GetResultType();
1971
1972 LocationSummary* locations = instruction->GetLocations();
1973 Location second = locations->InAt(1);
1974 DCHECK(second.IsConstant());
1975
1976 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1977 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
1978 int64_t imm = Int64FromConstant(second.GetConstant());
1979 DCHECK(imm == 1 || imm == -1);
1980
1981 if (instruction->IsRem()) {
1982 __ Move(out, ZERO);
1983 } else {
1984 if (imm == -1) {
1985 if (type == Primitive::kPrimInt) {
1986 __ Subu(out, ZERO, dividend);
1987 } else {
1988 DCHECK_EQ(type, Primitive::kPrimLong);
1989 __ Dsubu(out, ZERO, dividend);
1990 }
1991 } else if (out != dividend) {
1992 __ Move(out, dividend);
1993 }
1994 }
1995}
1996
1997void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
1998 DCHECK(instruction->IsDiv() || instruction->IsRem());
1999 Primitive::Type type = instruction->GetResultType();
2000
2001 LocationSummary* locations = instruction->GetLocations();
2002 Location second = locations->InAt(1);
2003 DCHECK(second.IsConstant());
2004
2005 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2006 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
2007 int64_t imm = Int64FromConstant(second.GetConstant());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002008 uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm));
Alexey Frunzec857c742015-09-23 15:12:39 -07002009 int ctz_imm = CTZ(abs_imm);
2010
2011 if (instruction->IsDiv()) {
2012 if (type == Primitive::kPrimInt) {
2013 if (ctz_imm == 1) {
2014 // Fast path for division by +/-2, which is very common.
2015 __ Srl(TMP, dividend, 31);
2016 } else {
2017 __ Sra(TMP, dividend, 31);
2018 __ Srl(TMP, TMP, 32 - ctz_imm);
2019 }
2020 __ Addu(out, dividend, TMP);
2021 __ Sra(out, out, ctz_imm);
2022 if (imm < 0) {
2023 __ Subu(out, ZERO, out);
2024 }
2025 } else {
2026 DCHECK_EQ(type, Primitive::kPrimLong);
2027 if (ctz_imm == 1) {
2028 // Fast path for division by +/-2, which is very common.
2029 __ Dsrl32(TMP, dividend, 31);
2030 } else {
2031 __ Dsra32(TMP, dividend, 31);
2032 if (ctz_imm > 32) {
2033 __ Dsrl(TMP, TMP, 64 - ctz_imm);
2034 } else {
2035 __ Dsrl32(TMP, TMP, 32 - ctz_imm);
2036 }
2037 }
2038 __ Daddu(out, dividend, TMP);
2039 if (ctz_imm < 32) {
2040 __ Dsra(out, out, ctz_imm);
2041 } else {
2042 __ Dsra32(out, out, ctz_imm - 32);
2043 }
2044 if (imm < 0) {
2045 __ Dsubu(out, ZERO, out);
2046 }
2047 }
2048 } else {
2049 if (type == Primitive::kPrimInt) {
2050 if (ctz_imm == 1) {
2051 // Fast path for modulo +/-2, which is very common.
2052 __ Sra(TMP, dividend, 31);
2053 __ Subu(out, dividend, TMP);
2054 __ Andi(out, out, 1);
2055 __ Addu(out, out, TMP);
2056 } else {
2057 __ Sra(TMP, dividend, 31);
2058 __ Srl(TMP, TMP, 32 - ctz_imm);
2059 __ Addu(out, dividend, TMP);
2060 if (IsUint<16>(abs_imm - 1)) {
2061 __ Andi(out, out, abs_imm - 1);
2062 } else {
2063 __ Sll(out, out, 32 - ctz_imm);
2064 __ Srl(out, out, 32 - ctz_imm);
2065 }
2066 __ Subu(out, out, TMP);
2067 }
2068 } else {
2069 DCHECK_EQ(type, Primitive::kPrimLong);
2070 if (ctz_imm == 1) {
2071 // Fast path for modulo +/-2, which is very common.
2072 __ Dsra32(TMP, dividend, 31);
2073 __ Dsubu(out, dividend, TMP);
2074 __ Andi(out, out, 1);
2075 __ Daddu(out, out, TMP);
2076 } else {
2077 __ Dsra32(TMP, dividend, 31);
2078 if (ctz_imm > 32) {
2079 __ Dsrl(TMP, TMP, 64 - ctz_imm);
2080 } else {
2081 __ Dsrl32(TMP, TMP, 32 - ctz_imm);
2082 }
2083 __ Daddu(out, dividend, TMP);
2084 if (IsUint<16>(abs_imm - 1)) {
2085 __ Andi(out, out, abs_imm - 1);
2086 } else {
2087 if (ctz_imm > 32) {
2088 __ Dsll(out, out, 64 - ctz_imm);
2089 __ Dsrl(out, out, 64 - ctz_imm);
2090 } else {
2091 __ Dsll32(out, out, 32 - ctz_imm);
2092 __ Dsrl32(out, out, 32 - ctz_imm);
2093 }
2094 }
2095 __ Dsubu(out, out, TMP);
2096 }
2097 }
2098 }
2099}
2100
2101void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2102 DCHECK(instruction->IsDiv() || instruction->IsRem());
2103
2104 LocationSummary* locations = instruction->GetLocations();
2105 Location second = locations->InAt(1);
2106 DCHECK(second.IsConstant());
2107
2108 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2109 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
2110 int64_t imm = Int64FromConstant(second.GetConstant());
2111
2112 Primitive::Type type = instruction->GetResultType();
2113 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type;
2114
2115 int64_t magic;
2116 int shift;
2117 CalculateMagicAndShiftForDivRem(imm,
2118 (type == Primitive::kPrimLong),
2119 &magic,
2120 &shift);
2121
2122 if (type == Primitive::kPrimInt) {
2123 __ LoadConst32(TMP, magic);
2124 __ MuhR6(TMP, dividend, TMP);
2125
2126 if (imm > 0 && magic < 0) {
2127 __ Addu(TMP, TMP, dividend);
2128 } else if (imm < 0 && magic > 0) {
2129 __ Subu(TMP, TMP, dividend);
2130 }
2131
2132 if (shift != 0) {
2133 __ Sra(TMP, TMP, shift);
2134 }
2135
2136 if (instruction->IsDiv()) {
2137 __ Sra(out, TMP, 31);
2138 __ Subu(out, TMP, out);
2139 } else {
2140 __ Sra(AT, TMP, 31);
2141 __ Subu(AT, TMP, AT);
2142 __ LoadConst32(TMP, imm);
2143 __ MulR6(TMP, AT, TMP);
2144 __ Subu(out, dividend, TMP);
2145 }
2146 } else {
2147 __ LoadConst64(TMP, magic);
2148 __ Dmuh(TMP, dividend, TMP);
2149
2150 if (imm > 0 && magic < 0) {
2151 __ Daddu(TMP, TMP, dividend);
2152 } else if (imm < 0 && magic > 0) {
2153 __ Dsubu(TMP, TMP, dividend);
2154 }
2155
2156 if (shift >= 32) {
2157 __ Dsra32(TMP, TMP, shift - 32);
2158 } else if (shift > 0) {
2159 __ Dsra(TMP, TMP, shift);
2160 }
2161
2162 if (instruction->IsDiv()) {
2163 __ Dsra32(out, TMP, 31);
2164 __ Dsubu(out, TMP, out);
2165 } else {
2166 __ Dsra32(AT, TMP, 31);
2167 __ Dsubu(AT, TMP, AT);
2168 __ LoadConst64(TMP, imm);
2169 __ Dmul(TMP, AT, TMP);
2170 __ Dsubu(out, dividend, TMP);
2171 }
2172 }
2173}
2174
2175void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) {
2176 DCHECK(instruction->IsDiv() || instruction->IsRem());
2177 Primitive::Type type = instruction->GetResultType();
2178 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type;
2179
2180 LocationSummary* locations = instruction->GetLocations();
2181 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2182 Location second = locations->InAt(1);
2183
2184 if (second.IsConstant()) {
2185 int64_t imm = Int64FromConstant(second.GetConstant());
2186 if (imm == 0) {
2187 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2188 } else if (imm == 1 || imm == -1) {
2189 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002190 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunzec857c742015-09-23 15:12:39 -07002191 DivRemByPowerOfTwo(instruction);
2192 } else {
2193 DCHECK(imm <= -2 || imm >= 2);
2194 GenerateDivRemWithAnyConstant(instruction);
2195 }
2196 } else {
2197 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
2198 GpuRegister divisor = second.AsRegister<GpuRegister>();
2199 if (instruction->IsDiv()) {
2200 if (type == Primitive::kPrimInt)
2201 __ DivR6(out, dividend, divisor);
2202 else
2203 __ Ddiv(out, dividend, divisor);
2204 } else {
2205 if (type == Primitive::kPrimInt)
2206 __ ModR6(out, dividend, divisor);
2207 else
2208 __ Dmod(out, dividend, divisor);
2209 }
2210 }
2211}
2212
Alexey Frunze4dda3372015-06-01 18:31:49 -07002213void LocationsBuilderMIPS64::VisitDiv(HDiv* div) {
2214 LocationSummary* locations =
2215 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
2216 switch (div->GetResultType()) {
2217 case Primitive::kPrimInt:
2218 case Primitive::kPrimLong:
2219 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunzec857c742015-09-23 15:12:39 -07002220 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002221 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2222 break;
2223
2224 case Primitive::kPrimFloat:
2225 case Primitive::kPrimDouble:
2226 locations->SetInAt(0, Location::RequiresFpuRegister());
2227 locations->SetInAt(1, Location::RequiresFpuRegister());
2228 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2229 break;
2230
2231 default:
2232 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2233 }
2234}
2235
2236void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) {
2237 Primitive::Type type = instruction->GetType();
2238 LocationSummary* locations = instruction->GetLocations();
2239
2240 switch (type) {
2241 case Primitive::kPrimInt:
Alexey Frunzec857c742015-09-23 15:12:39 -07002242 case Primitive::kPrimLong:
2243 GenerateDivRemIntegral(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002244 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002245 case Primitive::kPrimFloat:
2246 case Primitive::kPrimDouble: {
2247 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2248 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
2249 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
2250 if (type == Primitive::kPrimFloat)
2251 __ DivS(dst, lhs, rhs);
2252 else
2253 __ DivD(dst, lhs, rhs);
2254 break;
2255 }
2256 default:
2257 LOG(FATAL) << "Unexpected div type " << type;
2258 }
2259}
2260
2261void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01002262 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002263 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002264}
2265
2266void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2267 SlowPathCodeMIPS64* slow_path =
2268 new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS64(instruction);
2269 codegen_->AddSlowPath(slow_path);
2270 Location value = instruction->GetLocations()->InAt(0);
2271
2272 Primitive::Type type = instruction->GetType();
2273
Nicolas Geoffraye5671612016-03-16 11:03:54 +00002274 if (!Primitive::IsIntegralType(type)) {
2275 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
Serguei Katkov8c0676c2015-08-03 13:55:33 +06002276 return;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002277 }
2278
2279 if (value.IsConstant()) {
2280 int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant());
2281 if (divisor == 0) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002282 __ Bc(slow_path->GetEntryLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002283 } else {
2284 // A division by a non-null constant is valid. We don't need to perform
2285 // any check, so simply fall through.
2286 }
2287 } else {
2288 __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
2289 }
2290}
2291
2292void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) {
2293 LocationSummary* locations =
2294 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2295 locations->SetOut(Location::ConstantLocation(constant));
2296}
2297
2298void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
2299 // Will be generated at use site.
2300}
2301
2302void LocationsBuilderMIPS64::VisitExit(HExit* exit) {
2303 exit->SetLocations(nullptr);
2304}
2305
2306void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
2307}
2308
2309void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) {
2310 LocationSummary* locations =
2311 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2312 locations->SetOut(Location::ConstantLocation(constant));
2313}
2314
2315void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
2316 // Will be generated at use site.
2317}
2318
David Brazdilfc6a86a2015-06-26 10:33:45 +00002319void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002320 DCHECK(!successor->IsExitBlock());
2321 HBasicBlock* block = got->GetBlock();
2322 HInstruction* previous = got->GetPrevious();
2323 HLoopInformation* info = block->GetLoopInformation();
2324
2325 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
2326 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
2327 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
2328 return;
2329 }
2330 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
2331 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
2332 }
2333 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002334 __ Bc(codegen_->GetLabelOf(successor));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002335 }
2336}
2337
David Brazdilfc6a86a2015-06-26 10:33:45 +00002338void LocationsBuilderMIPS64::VisitGoto(HGoto* got) {
2339 got->SetLocations(nullptr);
2340}
2341
2342void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) {
2343 HandleGoto(got, got->GetSuccessor());
2344}
2345
2346void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
2347 try_boundary->SetLocations(nullptr);
2348}
2349
2350void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
2351 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
2352 if (!successor->IsExitBlock()) {
2353 HandleGoto(try_boundary, successor);
2354 }
2355}
2356
Alexey Frunze299a9392015-12-08 16:08:02 -08002357void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond,
2358 bool is64bit,
2359 LocationSummary* locations) {
2360 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2361 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2362 Location rhs_location = locations->InAt(1);
2363 GpuRegister rhs_reg = ZERO;
2364 int64_t rhs_imm = 0;
2365 bool use_imm = rhs_location.IsConstant();
2366 if (use_imm) {
2367 if (is64bit) {
2368 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
2369 } else {
2370 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2371 }
2372 } else {
2373 rhs_reg = rhs_location.AsRegister<GpuRegister>();
2374 }
2375 int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1);
2376
2377 switch (cond) {
2378 case kCondEQ:
2379 case kCondNE:
Goran Jakovljevicdb3deee2016-12-28 14:33:21 +01002380 if (use_imm && IsInt<16>(-rhs_imm)) {
2381 if (rhs_imm == 0) {
2382 if (cond == kCondEQ) {
2383 __ Sltiu(dst, lhs, 1);
2384 } else {
2385 __ Sltu(dst, ZERO, lhs);
2386 }
2387 } else {
2388 if (is64bit) {
2389 __ Daddiu(dst, lhs, -rhs_imm);
2390 } else {
2391 __ Addiu(dst, lhs, -rhs_imm);
2392 }
2393 if (cond == kCondEQ) {
2394 __ Sltiu(dst, dst, 1);
2395 } else {
2396 __ Sltu(dst, ZERO, dst);
2397 }
Alexey Frunze299a9392015-12-08 16:08:02 -08002398 }
Alexey Frunze299a9392015-12-08 16:08:02 -08002399 } else {
Goran Jakovljevicdb3deee2016-12-28 14:33:21 +01002400 if (use_imm && IsUint<16>(rhs_imm)) {
2401 __ Xori(dst, lhs, rhs_imm);
2402 } else {
2403 if (use_imm) {
2404 rhs_reg = TMP;
2405 __ LoadConst64(rhs_reg, rhs_imm);
2406 }
2407 __ Xor(dst, lhs, rhs_reg);
2408 }
2409 if (cond == kCondEQ) {
2410 __ Sltiu(dst, dst, 1);
2411 } else {
2412 __ Sltu(dst, ZERO, dst);
2413 }
Alexey Frunze299a9392015-12-08 16:08:02 -08002414 }
2415 break;
2416
2417 case kCondLT:
2418 case kCondGE:
2419 if (use_imm && IsInt<16>(rhs_imm)) {
2420 __ Slti(dst, lhs, rhs_imm);
2421 } else {
2422 if (use_imm) {
2423 rhs_reg = TMP;
2424 __ LoadConst64(rhs_reg, rhs_imm);
2425 }
2426 __ Slt(dst, lhs, rhs_reg);
2427 }
2428 if (cond == kCondGE) {
2429 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2430 // only the slt instruction but no sge.
2431 __ Xori(dst, dst, 1);
2432 }
2433 break;
2434
2435 case kCondLE:
2436 case kCondGT:
2437 if (use_imm && IsInt<16>(rhs_imm_plus_one)) {
2438 // Simulate lhs <= rhs via lhs < rhs + 1.
2439 __ Slti(dst, lhs, rhs_imm_plus_one);
2440 if (cond == kCondGT) {
2441 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2442 // only the slti instruction but no sgti.
2443 __ Xori(dst, dst, 1);
2444 }
2445 } else {
2446 if (use_imm) {
2447 rhs_reg = TMP;
2448 __ LoadConst64(rhs_reg, rhs_imm);
2449 }
2450 __ Slt(dst, rhs_reg, lhs);
2451 if (cond == kCondLE) {
2452 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2453 // only the slt instruction but no sle.
2454 __ Xori(dst, dst, 1);
2455 }
2456 }
2457 break;
2458
2459 case kCondB:
2460 case kCondAE:
2461 if (use_imm && IsInt<16>(rhs_imm)) {
2462 // Sltiu sign-extends its 16-bit immediate operand before
2463 // the comparison and thus lets us compare directly with
2464 // unsigned values in the ranges [0, 0x7fff] and
2465 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
2466 __ Sltiu(dst, lhs, rhs_imm);
2467 } else {
2468 if (use_imm) {
2469 rhs_reg = TMP;
2470 __ LoadConst64(rhs_reg, rhs_imm);
2471 }
2472 __ Sltu(dst, lhs, rhs_reg);
2473 }
2474 if (cond == kCondAE) {
2475 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2476 // only the sltu instruction but no sgeu.
2477 __ Xori(dst, dst, 1);
2478 }
2479 break;
2480
2481 case kCondBE:
2482 case kCondA:
2483 if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) {
2484 // Simulate lhs <= rhs via lhs < rhs + 1.
2485 // Note that this only works if rhs + 1 does not overflow
2486 // to 0, hence the check above.
2487 // Sltiu sign-extends its 16-bit immediate operand before
2488 // the comparison and thus lets us compare directly with
2489 // unsigned values in the ranges [0, 0x7fff] and
2490 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
2491 __ Sltiu(dst, lhs, rhs_imm_plus_one);
2492 if (cond == kCondA) {
2493 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2494 // only the sltiu instruction but no sgtiu.
2495 __ Xori(dst, dst, 1);
2496 }
2497 } else {
2498 if (use_imm) {
2499 rhs_reg = TMP;
2500 __ LoadConst64(rhs_reg, rhs_imm);
2501 }
2502 __ Sltu(dst, rhs_reg, lhs);
2503 if (cond == kCondBE) {
2504 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2505 // only the sltu instruction but no sleu.
2506 __ Xori(dst, dst, 1);
2507 }
2508 }
2509 break;
2510 }
2511}
2512
2513void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond,
2514 bool is64bit,
2515 LocationSummary* locations,
2516 Mips64Label* label) {
2517 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2518 Location rhs_location = locations->InAt(1);
2519 GpuRegister rhs_reg = ZERO;
2520 int64_t rhs_imm = 0;
2521 bool use_imm = rhs_location.IsConstant();
2522 if (use_imm) {
2523 if (is64bit) {
2524 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
2525 } else {
2526 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2527 }
2528 } else {
2529 rhs_reg = rhs_location.AsRegister<GpuRegister>();
2530 }
2531
2532 if (use_imm && rhs_imm == 0) {
2533 switch (cond) {
2534 case kCondEQ:
2535 case kCondBE: // <= 0 if zero
2536 __ Beqzc(lhs, label);
2537 break;
2538 case kCondNE:
2539 case kCondA: // > 0 if non-zero
2540 __ Bnezc(lhs, label);
2541 break;
2542 case kCondLT:
2543 __ Bltzc(lhs, label);
2544 break;
2545 case kCondGE:
2546 __ Bgezc(lhs, label);
2547 break;
2548 case kCondLE:
2549 __ Blezc(lhs, label);
2550 break;
2551 case kCondGT:
2552 __ Bgtzc(lhs, label);
2553 break;
2554 case kCondB: // always false
2555 break;
2556 case kCondAE: // always true
2557 __ Bc(label);
2558 break;
2559 }
2560 } else {
2561 if (use_imm) {
2562 rhs_reg = TMP;
2563 __ LoadConst64(rhs_reg, rhs_imm);
2564 }
2565 switch (cond) {
2566 case kCondEQ:
2567 __ Beqc(lhs, rhs_reg, label);
2568 break;
2569 case kCondNE:
2570 __ Bnec(lhs, rhs_reg, label);
2571 break;
2572 case kCondLT:
2573 __ Bltc(lhs, rhs_reg, label);
2574 break;
2575 case kCondGE:
2576 __ Bgec(lhs, rhs_reg, label);
2577 break;
2578 case kCondLE:
2579 __ Bgec(rhs_reg, lhs, label);
2580 break;
2581 case kCondGT:
2582 __ Bltc(rhs_reg, lhs, label);
2583 break;
2584 case kCondB:
2585 __ Bltuc(lhs, rhs_reg, label);
2586 break;
2587 case kCondAE:
2588 __ Bgeuc(lhs, rhs_reg, label);
2589 break;
2590 case kCondBE:
2591 __ Bgeuc(rhs_reg, lhs, label);
2592 break;
2593 case kCondA:
2594 __ Bltuc(rhs_reg, lhs, label);
2595 break;
2596 }
2597 }
2598}
2599
Tijana Jakovljevic43758192016-12-30 09:23:01 +01002600void InstructionCodeGeneratorMIPS64::GenerateFpCompare(IfCondition cond,
2601 bool gt_bias,
2602 Primitive::Type type,
2603 LocationSummary* locations) {
2604 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2605 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
2606 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
2607 if (type == Primitive::kPrimFloat) {
2608 switch (cond) {
2609 case kCondEQ:
2610 __ CmpEqS(FTMP, lhs, rhs);
2611 __ Mfc1(dst, FTMP);
2612 __ Andi(dst, dst, 1);
2613 break;
2614 case kCondNE:
2615 __ CmpEqS(FTMP, lhs, rhs);
2616 __ Mfc1(dst, FTMP);
2617 __ Addiu(dst, dst, 1);
2618 break;
2619 case kCondLT:
2620 if (gt_bias) {
2621 __ CmpLtS(FTMP, lhs, rhs);
2622 } else {
2623 __ CmpUltS(FTMP, lhs, rhs);
2624 }
2625 __ Mfc1(dst, FTMP);
2626 __ Andi(dst, dst, 1);
2627 break;
2628 case kCondLE:
2629 if (gt_bias) {
2630 __ CmpLeS(FTMP, lhs, rhs);
2631 } else {
2632 __ CmpUleS(FTMP, lhs, rhs);
2633 }
2634 __ Mfc1(dst, FTMP);
2635 __ Andi(dst, dst, 1);
2636 break;
2637 case kCondGT:
2638 if (gt_bias) {
2639 __ CmpUltS(FTMP, rhs, lhs);
2640 } else {
2641 __ CmpLtS(FTMP, rhs, lhs);
2642 }
2643 __ Mfc1(dst, FTMP);
2644 __ Andi(dst, dst, 1);
2645 break;
2646 case kCondGE:
2647 if (gt_bias) {
2648 __ CmpUleS(FTMP, rhs, lhs);
2649 } else {
2650 __ CmpLeS(FTMP, rhs, lhs);
2651 }
2652 __ Mfc1(dst, FTMP);
2653 __ Andi(dst, dst, 1);
2654 break;
2655 default:
2656 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
2657 UNREACHABLE();
2658 }
2659 } else {
2660 DCHECK_EQ(type, Primitive::kPrimDouble);
2661 switch (cond) {
2662 case kCondEQ:
2663 __ CmpEqD(FTMP, lhs, rhs);
2664 __ Mfc1(dst, FTMP);
2665 __ Andi(dst, dst, 1);
2666 break;
2667 case kCondNE:
2668 __ CmpEqD(FTMP, lhs, rhs);
2669 __ Mfc1(dst, FTMP);
2670 __ Addiu(dst, dst, 1);
2671 break;
2672 case kCondLT:
2673 if (gt_bias) {
2674 __ CmpLtD(FTMP, lhs, rhs);
2675 } else {
2676 __ CmpUltD(FTMP, lhs, rhs);
2677 }
2678 __ Mfc1(dst, FTMP);
2679 __ Andi(dst, dst, 1);
2680 break;
2681 case kCondLE:
2682 if (gt_bias) {
2683 __ CmpLeD(FTMP, lhs, rhs);
2684 } else {
2685 __ CmpUleD(FTMP, lhs, rhs);
2686 }
2687 __ Mfc1(dst, FTMP);
2688 __ Andi(dst, dst, 1);
2689 break;
2690 case kCondGT:
2691 if (gt_bias) {
2692 __ CmpUltD(FTMP, rhs, lhs);
2693 } else {
2694 __ CmpLtD(FTMP, rhs, lhs);
2695 }
2696 __ Mfc1(dst, FTMP);
2697 __ Andi(dst, dst, 1);
2698 break;
2699 case kCondGE:
2700 if (gt_bias) {
2701 __ CmpUleD(FTMP, rhs, lhs);
2702 } else {
2703 __ CmpLeD(FTMP, rhs, lhs);
2704 }
2705 __ Mfc1(dst, FTMP);
2706 __ Andi(dst, dst, 1);
2707 break;
2708 default:
2709 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
2710 UNREACHABLE();
2711 }
2712 }
2713}
2714
Alexey Frunze299a9392015-12-08 16:08:02 -08002715void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond,
2716 bool gt_bias,
2717 Primitive::Type type,
2718 LocationSummary* locations,
2719 Mips64Label* label) {
2720 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
2721 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
2722 if (type == Primitive::kPrimFloat) {
2723 switch (cond) {
2724 case kCondEQ:
2725 __ CmpEqS(FTMP, lhs, rhs);
2726 __ Bc1nez(FTMP, label);
2727 break;
2728 case kCondNE:
2729 __ CmpEqS(FTMP, lhs, rhs);
2730 __ Bc1eqz(FTMP, label);
2731 break;
2732 case kCondLT:
2733 if (gt_bias) {
2734 __ CmpLtS(FTMP, lhs, rhs);
2735 } else {
2736 __ CmpUltS(FTMP, lhs, rhs);
2737 }
2738 __ Bc1nez(FTMP, label);
2739 break;
2740 case kCondLE:
2741 if (gt_bias) {
2742 __ CmpLeS(FTMP, lhs, rhs);
2743 } else {
2744 __ CmpUleS(FTMP, lhs, rhs);
2745 }
2746 __ Bc1nez(FTMP, label);
2747 break;
2748 case kCondGT:
2749 if (gt_bias) {
2750 __ CmpUltS(FTMP, rhs, lhs);
2751 } else {
2752 __ CmpLtS(FTMP, rhs, lhs);
2753 }
2754 __ Bc1nez(FTMP, label);
2755 break;
2756 case kCondGE:
2757 if (gt_bias) {
2758 __ CmpUleS(FTMP, rhs, lhs);
2759 } else {
2760 __ CmpLeS(FTMP, rhs, lhs);
2761 }
2762 __ Bc1nez(FTMP, label);
2763 break;
2764 default:
2765 LOG(FATAL) << "Unexpected non-floating-point condition";
2766 }
2767 } else {
2768 DCHECK_EQ(type, Primitive::kPrimDouble);
2769 switch (cond) {
2770 case kCondEQ:
2771 __ CmpEqD(FTMP, lhs, rhs);
2772 __ Bc1nez(FTMP, label);
2773 break;
2774 case kCondNE:
2775 __ CmpEqD(FTMP, lhs, rhs);
2776 __ Bc1eqz(FTMP, label);
2777 break;
2778 case kCondLT:
2779 if (gt_bias) {
2780 __ CmpLtD(FTMP, lhs, rhs);
2781 } else {
2782 __ CmpUltD(FTMP, lhs, rhs);
2783 }
2784 __ Bc1nez(FTMP, label);
2785 break;
2786 case kCondLE:
2787 if (gt_bias) {
2788 __ CmpLeD(FTMP, lhs, rhs);
2789 } else {
2790 __ CmpUleD(FTMP, lhs, rhs);
2791 }
2792 __ Bc1nez(FTMP, label);
2793 break;
2794 case kCondGT:
2795 if (gt_bias) {
2796 __ CmpUltD(FTMP, rhs, lhs);
2797 } else {
2798 __ CmpLtD(FTMP, rhs, lhs);
2799 }
2800 __ Bc1nez(FTMP, label);
2801 break;
2802 case kCondGE:
2803 if (gt_bias) {
2804 __ CmpUleD(FTMP, rhs, lhs);
2805 } else {
2806 __ CmpLeD(FTMP, rhs, lhs);
2807 }
2808 __ Bc1nez(FTMP, label);
2809 break;
2810 default:
2811 LOG(FATAL) << "Unexpected non-floating-point condition";
2812 }
2813 }
2814}
2815
Alexey Frunze4dda3372015-06-01 18:31:49 -07002816void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00002817 size_t condition_input_index,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002818 Mips64Label* true_target,
2819 Mips64Label* false_target) {
David Brazdil0debae72015-11-12 18:37:00 +00002820 HInstruction* cond = instruction->InputAt(condition_input_index);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002821
David Brazdil0debae72015-11-12 18:37:00 +00002822 if (true_target == nullptr && false_target == nullptr) {
2823 // Nothing to do. The code always falls through.
2824 return;
2825 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00002826 // Constant condition, statically compared against "true" (integer value 1).
2827 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00002828 if (true_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002829 __ Bc(true_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002830 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002831 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00002832 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00002833 if (false_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002834 __ Bc(false_target);
David Brazdil0debae72015-11-12 18:37:00 +00002835 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002836 }
David Brazdil0debae72015-11-12 18:37:00 +00002837 return;
2838 }
2839
2840 // The following code generates these patterns:
2841 // (1) true_target == nullptr && false_target != nullptr
2842 // - opposite condition true => branch to false_target
2843 // (2) true_target != nullptr && false_target == nullptr
2844 // - condition true => branch to true_target
2845 // (3) true_target != nullptr && false_target != nullptr
2846 // - condition true => branch to true_target
2847 // - branch to false_target
2848 if (IsBooleanValueOrMaterializedCondition(cond)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002849 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00002850 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002851 DCHECK(cond_val.IsRegister());
David Brazdil0debae72015-11-12 18:37:00 +00002852 if (true_target == nullptr) {
2853 __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target);
2854 } else {
2855 __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target);
2856 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002857 } else {
2858 // The condition instruction has not been materialized, use its inputs as
2859 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00002860 HCondition* condition = cond->AsCondition();
Alexey Frunze299a9392015-12-08 16:08:02 -08002861 Primitive::Type type = condition->InputAt(0)->GetType();
2862 LocationSummary* locations = cond->GetLocations();
2863 IfCondition if_cond = condition->GetCondition();
2864 Mips64Label* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00002865
David Brazdil0debae72015-11-12 18:37:00 +00002866 if (true_target == nullptr) {
2867 if_cond = condition->GetOppositeCondition();
Alexey Frunze299a9392015-12-08 16:08:02 -08002868 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00002869 }
2870
Alexey Frunze299a9392015-12-08 16:08:02 -08002871 switch (type) {
2872 default:
2873 GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target);
2874 break;
2875 case Primitive::kPrimLong:
2876 GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target);
2877 break;
2878 case Primitive::kPrimFloat:
2879 case Primitive::kPrimDouble:
2880 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
2881 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002882 }
2883 }
David Brazdil0debae72015-11-12 18:37:00 +00002884
2885 // If neither branch falls through (case 3), the conditional branch to `true_target`
2886 // was already emitted (case 2) and we need to emit a jump to `false_target`.
2887 if (true_target != nullptr && false_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002888 __ Bc(false_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002889 }
2890}
2891
2892void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) {
2893 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00002894 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002895 locations->SetInAt(0, Location::RequiresRegister());
2896 }
2897}
2898
2899void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00002900 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
2901 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002902 Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
David Brazdil0debae72015-11-12 18:37:00 +00002903 nullptr : codegen_->GetLabelOf(true_successor);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002904 Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
David Brazdil0debae72015-11-12 18:37:00 +00002905 nullptr : codegen_->GetLabelOf(false_successor);
2906 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002907}
2908
2909void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
2910 LocationSummary* locations = new (GetGraph()->GetArena())
2911 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
Vladimir Marko804b03f2016-09-14 16:26:36 +01002912 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
David Brazdil0debae72015-11-12 18:37:00 +00002913 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002914 locations->SetInAt(0, Location::RequiresRegister());
2915 }
2916}
2917
2918void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08002919 SlowPathCodeMIPS64* slow_path =
2920 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00002921 GenerateTestAndBranch(deoptimize,
2922 /* condition_input_index */ 0,
2923 slow_path->GetEntryLabel(),
2924 /* false_target */ nullptr);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002925}
2926
Goran Jakovljevicc6418422016-12-05 16:31:55 +01002927void LocationsBuilderMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
2928 LocationSummary* locations = new (GetGraph()->GetArena())
2929 LocationSummary(flag, LocationSummary::kNoCall);
2930 locations->SetOut(Location::RequiresRegister());
Mingyao Yang063fc772016-08-02 11:02:54 -07002931}
2932
Goran Jakovljevicc6418422016-12-05 16:31:55 +01002933void InstructionCodeGeneratorMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) {
2934 __ LoadFromOffset(kLoadWord,
2935 flag->GetLocations()->Out().AsRegister<GpuRegister>(),
2936 SP,
2937 codegen_->GetStackOffsetOfShouldDeoptimizeFlag());
Mingyao Yang063fc772016-08-02 11:02:54 -07002938}
2939
David Brazdil74eb1b22015-12-14 11:44:01 +00002940void LocationsBuilderMIPS64::VisitSelect(HSelect* select) {
2941 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
2942 if (Primitive::IsFloatingPointType(select->GetType())) {
2943 locations->SetInAt(0, Location::RequiresFpuRegister());
2944 locations->SetInAt(1, Location::RequiresFpuRegister());
2945 } else {
2946 locations->SetInAt(0, Location::RequiresRegister());
2947 locations->SetInAt(1, Location::RequiresRegister());
2948 }
2949 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
2950 locations->SetInAt(2, Location::RequiresRegister());
2951 }
2952 locations->SetOut(Location::SameAsFirstInput());
2953}
2954
2955void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) {
2956 LocationSummary* locations = select->GetLocations();
2957 Mips64Label false_target;
2958 GenerateTestAndBranch(select,
2959 /* condition_input_index */ 2,
2960 /* true_target */ nullptr,
2961 &false_target);
2962 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
2963 __ Bind(&false_target);
2964}
2965
David Srbecky0cf44932015-12-09 14:09:59 +00002966void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) {
2967 new (GetGraph()->GetArena()) LocationSummary(info);
2968}
2969
David Srbeckyd28f4a02016-03-14 17:14:24 +00002970void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) {
2971 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00002972}
2973
2974void CodeGeneratorMIPS64::GenerateNop() {
2975 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00002976}
2977
Alexey Frunze4dda3372015-06-01 18:31:49 -07002978void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction,
2979 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
2980 LocationSummary* locations =
2981 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2982 locations->SetInAt(0, Location::RequiresRegister());
2983 if (Primitive::IsFloatingPointType(instruction->GetType())) {
2984 locations->SetOut(Location::RequiresFpuRegister());
2985 } else {
2986 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2987 }
2988}
2989
2990void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction,
2991 const FieldInfo& field_info) {
2992 Primitive::Type type = field_info.GetFieldType();
2993 LocationSummary* locations = instruction->GetLocations();
2994 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2995 LoadOperandType load_type = kLoadUnsignedByte;
2996 switch (type) {
2997 case Primitive::kPrimBoolean:
2998 load_type = kLoadUnsignedByte;
2999 break;
3000 case Primitive::kPrimByte:
3001 load_type = kLoadSignedByte;
3002 break;
3003 case Primitive::kPrimShort:
3004 load_type = kLoadSignedHalfword;
3005 break;
3006 case Primitive::kPrimChar:
3007 load_type = kLoadUnsignedHalfword;
3008 break;
3009 case Primitive::kPrimInt:
3010 case Primitive::kPrimFloat:
3011 load_type = kLoadWord;
3012 break;
3013 case Primitive::kPrimLong:
3014 case Primitive::kPrimDouble:
3015 load_type = kLoadDoubleword;
3016 break;
3017 case Primitive::kPrimNot:
3018 load_type = kLoadUnsignedWord;
3019 break;
3020 case Primitive::kPrimVoid:
3021 LOG(FATAL) << "Unreachable type " << type;
3022 UNREACHABLE();
3023 }
3024 if (!Primitive::IsFloatingPointType(type)) {
3025 DCHECK(locations->Out().IsRegister());
3026 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3027 __ LoadFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value());
3028 } else {
3029 DCHECK(locations->Out().IsFpuRegister());
3030 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3031 __ LoadFpuFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value());
3032 }
3033
3034 codegen_->MaybeRecordImplicitNullCheck(instruction);
3035 // TODO: memory barrier?
3036}
3037
3038void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction,
3039 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
3040 LocationSummary* locations =
3041 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3042 locations->SetInAt(0, Location::RequiresRegister());
3043 if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
3044 locations->SetInAt(1, Location::RequiresFpuRegister());
3045 } else {
3046 locations->SetInAt(1, Location::RequiresRegister());
3047 }
3048}
3049
3050void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction,
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01003051 const FieldInfo& field_info,
3052 bool value_can_be_null) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003053 Primitive::Type type = field_info.GetFieldType();
3054 LocationSummary* locations = instruction->GetLocations();
3055 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
3056 StoreOperandType store_type = kStoreByte;
3057 switch (type) {
3058 case Primitive::kPrimBoolean:
3059 case Primitive::kPrimByte:
3060 store_type = kStoreByte;
3061 break;
3062 case Primitive::kPrimShort:
3063 case Primitive::kPrimChar:
3064 store_type = kStoreHalfword;
3065 break;
3066 case Primitive::kPrimInt:
3067 case Primitive::kPrimFloat:
3068 case Primitive::kPrimNot:
3069 store_type = kStoreWord;
3070 break;
3071 case Primitive::kPrimLong:
3072 case Primitive::kPrimDouble:
3073 store_type = kStoreDoubleword;
3074 break;
3075 case Primitive::kPrimVoid:
3076 LOG(FATAL) << "Unreachable type " << type;
3077 UNREACHABLE();
3078 }
3079 if (!Primitive::IsFloatingPointType(type)) {
3080 DCHECK(locations->InAt(1).IsRegister());
3081 GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>();
3082 __ StoreToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value());
3083 } else {
3084 DCHECK(locations->InAt(1).IsFpuRegister());
3085 FpuRegister src = locations->InAt(1).AsFpuRegister<FpuRegister>();
3086 __ StoreFpuToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value());
3087 }
3088
3089 codegen_->MaybeRecordImplicitNullCheck(instruction);
3090 // TODO: memory barriers?
3091 if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) {
3092 DCHECK(locations->InAt(1).IsRegister());
3093 GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>();
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01003094 codegen_->MarkGCCard(obj, src, value_can_be_null);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003095 }
3096}
3097
3098void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3099 HandleFieldGet(instruction, instruction->GetFieldInfo());
3100}
3101
3102void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3103 HandleFieldGet(instruction, instruction->GetFieldInfo());
3104}
3105
3106void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3107 HandleFieldSet(instruction, instruction->GetFieldInfo());
3108}
3109
3110void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01003111 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003112}
3113
Alexey Frunzef63f5692016-12-13 17:43:11 -08003114void InstructionCodeGeneratorMIPS64::GenerateGcRootFieldLoad(
3115 HInstruction* instruction ATTRIBUTE_UNUSED,
3116 Location root,
3117 GpuRegister obj,
3118 uint32_t offset) {
Vladimir Marko48886c22017-01-06 11:45:47 +00003119 // When handling PC-relative loads, the caller calls
Alexey Frunzef63f5692016-12-13 17:43:11 -08003120 // EmitPcRelativeAddressPlaceholderHigh() and then GenerateGcRootFieldLoad().
3121 // The relative patcher expects the two methods to emit the following patchable
3122 // sequence of instructions in this case:
3123 // auipc reg1, 0x1234 // 0x1234 is a placeholder for offset_high.
3124 // lwu reg2, 0x5678(reg1) // 0x5678 is a placeholder for offset_low.
3125 // TODO: Adjust GenerateGcRootFieldLoad() and its caller when this method is
3126 // extended (e.g. for read barriers) so as not to break the relative patcher.
3127 GpuRegister root_reg = root.AsRegister<GpuRegister>();
3128 if (kEmitCompilerReadBarrier) {
3129 UNIMPLEMENTED(FATAL) << "for read barrier";
3130 } else {
3131 // Plain GC root load with no read barrier.
3132 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
3133 __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset);
3134 // Note that GC roots are not affected by heap poisoning, thus we
3135 // do not have to unpoison `root_reg` here.
3136 }
3137}
3138
Alexey Frunze4dda3372015-06-01 18:31:49 -07003139void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
3140 LocationSummary::CallKind call_kind =
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003141 instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003142 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3143 locations->SetInAt(0, Location::RequiresRegister());
3144 locations->SetInAt(1, Location::RequiresRegister());
3145 // The output does overlap inputs.
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01003146 // Note that TypeCheckSlowPathMIPS64 uses this register too.
Alexey Frunze4dda3372015-06-01 18:31:49 -07003147 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3148}
3149
3150void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
3151 LocationSummary* locations = instruction->GetLocations();
3152 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
3153 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
3154 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3155
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003156 Mips64Label done;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003157
3158 // Return 0 if `obj` is null.
3159 // TODO: Avoid this check if we know `obj` is not null.
3160 __ Move(out, ZERO);
3161 __ Beqzc(obj, &done);
3162
3163 // Compare the class of `obj` with `cls`.
3164 __ LoadFromOffset(kLoadUnsignedWord, out, obj, mirror::Object::ClassOffset().Int32Value());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003165 if (instruction->IsExactCheck()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003166 // Classes must be equal for the instanceof to succeed.
3167 __ Xor(out, out, cls);
3168 __ Sltiu(out, out, 1);
3169 } else {
3170 // If the classes are not equal, we go into a slow path.
3171 DCHECK(locations->OnlyCallsOnSlowPath());
3172 SlowPathCodeMIPS64* slow_path =
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01003173 new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003174 codegen_->AddSlowPath(slow_path);
3175 __ Bnec(out, cls, slow_path->GetEntryLabel());
3176 __ LoadConst32(out, 1);
3177 __ Bind(slow_path->GetExitLabel());
3178 }
3179
3180 __ Bind(&done);
3181}
3182
3183void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) {
3184 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3185 locations->SetOut(Location::ConstantLocation(constant));
3186}
3187
3188void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
3189 // Will be generated at use site.
3190}
3191
3192void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) {
3193 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3194 locations->SetOut(Location::ConstantLocation(constant));
3195}
3196
3197void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
3198 // Will be generated at use site.
3199}
3200
Calin Juravle175dc732015-08-25 15:42:32 +01003201void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
3202 // The trampoline uses the same calling convention as dex calling conventions,
3203 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
3204 // the method_idx.
3205 HandleInvoke(invoke);
3206}
3207
3208void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
3209 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
3210}
3211
Alexey Frunze4dda3372015-06-01 18:31:49 -07003212void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) {
3213 InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor;
3214 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
3215}
3216
3217void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
3218 HandleInvoke(invoke);
3219 // The register T0 is required to be used for the hidden argument in
3220 // art_quick_imt_conflict_trampoline, so add the hidden argument.
3221 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
3222}
3223
3224void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
3225 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
3226 GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003227 Location receiver = invoke->GetLocations()->InAt(0);
3228 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07003229 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003230
3231 // Set the hidden argument.
3232 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(),
3233 invoke->GetDexMethodIndex());
3234
3235 // temp = object->GetClass();
3236 if (receiver.IsStackSlot()) {
3237 __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex());
3238 __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset);
3239 } else {
3240 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset);
3241 }
3242 codegen_->MaybeRecordImplicitNullCheck(invoke);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00003243 __ LoadFromOffset(kLoadDoubleword, temp, temp,
3244 mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value());
3245 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00003246 invoke->GetImtIndex(), kMips64PointerSize));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003247 // temp = temp->GetImtEntryAt(method_offset);
3248 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
3249 // T9 = temp->GetEntryPoint();
3250 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
3251 // T9();
3252 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003253 __ Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003254 DCHECK(!codegen_->IsLeafMethod());
3255 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3256}
3257
3258void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen3039e382015-08-26 07:54:08 -07003259 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
3260 if (intrinsic.TryDispatch(invoke)) {
3261 return;
3262 }
3263
Alexey Frunze4dda3372015-06-01 18:31:49 -07003264 HandleInvoke(invoke);
3265}
3266
3267void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00003268 // Explicit clinit checks triggered by static invokes must have been pruned by
3269 // art::PrepareForRegisterAllocation.
3270 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003271
Chris Larsen3039e382015-08-26 07:54:08 -07003272 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
3273 if (intrinsic.TryDispatch(invoke)) {
3274 return;
3275 }
3276
Alexey Frunze4dda3372015-06-01 18:31:49 -07003277 HandleInvoke(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003278}
3279
Orion Hodsonac141392017-01-13 11:53:47 +00003280void LocationsBuilderMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
3281 HandleInvoke(invoke);
3282}
3283
3284void InstructionCodeGeneratorMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) {
3285 codegen_->GenerateInvokePolymorphicCall(invoke);
3286}
3287
Chris Larsen3039e382015-08-26 07:54:08 -07003288static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003289 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen3039e382015-08-26 07:54:08 -07003290 IntrinsicCodeGeneratorMIPS64 intrinsic(codegen);
3291 intrinsic.Dispatch(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003292 return true;
3293 }
3294 return false;
3295}
3296
Vladimir Markocac5a7e2016-02-22 10:39:50 +00003297HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind(
Alexey Frunzef63f5692016-12-13 17:43:11 -08003298 HLoadString::LoadKind desired_string_load_kind) {
3299 if (kEmitCompilerReadBarrier) {
3300 UNIMPLEMENTED(FATAL) << "for read barrier";
3301 }
3302 bool fallback_load = false;
3303 switch (desired_string_load_kind) {
3304 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
3305 DCHECK(!GetCompilerOptions().GetCompilePic());
3306 break;
3307 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
3308 DCHECK(GetCompilerOptions().GetCompilePic());
3309 break;
3310 case HLoadString::LoadKind::kBootImageAddress:
3311 break;
3312 case HLoadString::LoadKind::kBssEntry:
3313 DCHECK(!Runtime::Current()->UseJitCompilation());
3314 break;
3315 case HLoadString::LoadKind::kDexCacheViaMethod:
3316 break;
3317 case HLoadString::LoadKind::kJitTableAddress:
3318 DCHECK(Runtime::Current()->UseJitCompilation());
3319 // TODO: implement.
3320 fallback_load = true;
3321 break;
3322 }
3323 if (fallback_load) {
3324 desired_string_load_kind = HLoadString::LoadKind::kDexCacheViaMethod;
3325 }
3326 return desired_string_load_kind;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00003327}
3328
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01003329HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind(
3330 HLoadClass::LoadKind desired_class_load_kind) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08003331 if (kEmitCompilerReadBarrier) {
3332 UNIMPLEMENTED(FATAL) << "for read barrier";
3333 }
3334 bool fallback_load = false;
3335 switch (desired_class_load_kind) {
3336 case HLoadClass::LoadKind::kReferrersClass:
3337 break;
3338 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
3339 DCHECK(!GetCompilerOptions().GetCompilePic());
3340 break;
3341 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
3342 DCHECK(GetCompilerOptions().GetCompilePic());
3343 break;
3344 case HLoadClass::LoadKind::kBootImageAddress:
3345 break;
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003346 case HLoadClass::LoadKind::kBssEntry:
3347 DCHECK(!Runtime::Current()->UseJitCompilation());
3348 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08003349 case HLoadClass::LoadKind::kJitTableAddress:
3350 DCHECK(Runtime::Current()->UseJitCompilation());
3351 // TODO: implement.
3352 fallback_load = true;
3353 break;
Alexey Frunzef63f5692016-12-13 17:43:11 -08003354 case HLoadClass::LoadKind::kDexCacheViaMethod:
3355 break;
3356 }
3357 if (fallback_load) {
3358 desired_class_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod;
3359 }
3360 return desired_class_load_kind;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01003361}
3362
Vladimir Markodc151b22015-10-15 18:02:30 +01003363HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch(
3364 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +01003365 HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) {
Alexey Frunze19f6c692016-11-30 19:19:55 -08003366 // On MIPS64 we support all dispatch types.
3367 return desired_dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01003368}
3369
Alexey Frunze4dda3372015-06-01 18:31:49 -07003370void CodeGeneratorMIPS64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
3371 // All registers are assumed to be correctly set up per the calling convention.
Vladimir Marko58155012015-08-19 12:49:41 +00003372 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
Alexey Frunze19f6c692016-11-30 19:19:55 -08003373 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
3374 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
3375
Alexey Frunze19f6c692016-11-30 19:19:55 -08003376 switch (method_load_kind) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01003377 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
Vladimir Marko58155012015-08-19 12:49:41 +00003378 // temp = thread->string_init_entrypoint
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01003379 uint32_t offset =
3380 GetThreadOffset<kMips64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
Vladimir Marko58155012015-08-19 12:49:41 +00003381 __ LoadFromOffset(kLoadDoubleword,
3382 temp.AsRegister<GpuRegister>(),
3383 TR,
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01003384 offset);
Vladimir Marko58155012015-08-19 12:49:41 +00003385 break;
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01003386 }
Vladimir Marko58155012015-08-19 12:49:41 +00003387 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00003388 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00003389 break;
3390 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
Alexey Frunze19f6c692016-11-30 19:19:55 -08003391 __ LoadLiteral(temp.AsRegister<GpuRegister>(),
3392 kLoadDoubleword,
3393 DeduplicateUint64Literal(invoke->GetMethodAddress()));
Vladimir Marko58155012015-08-19 12:49:41 +00003394 break;
Alexey Frunze19f6c692016-11-30 19:19:55 -08003395 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: {
3396 uint32_t offset = invoke->GetDexCacheArrayOffset();
3397 CodeGeneratorMIPS64::PcRelativePatchInfo* info =
Nicolas Geoffray5d37c152017-01-12 13:25:19 +00003398 NewPcRelativeDexCacheArrayPatch(invoke->GetDexFileForPcRelativeDexCache(), offset);
Alexey Frunze19f6c692016-11-30 19:19:55 -08003399 EmitPcRelativeAddressPlaceholderHigh(info, AT);
3400 __ Ld(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678);
3401 break;
3402 }
Vladimir Marko58155012015-08-19 12:49:41 +00003403 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00003404 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00003405 GpuRegister reg = temp.AsRegister<GpuRegister>();
3406 GpuRegister method_reg;
3407 if (current_method.IsRegister()) {
3408 method_reg = current_method.AsRegister<GpuRegister>();
3409 } else {
3410 // TODO: use the appropriate DCHECK() here if possible.
3411 // DCHECK(invoke->GetLocations()->Intrinsified());
3412 DCHECK(!current_method.IsValid());
3413 method_reg = reg;
3414 __ Ld(reg, SP, kCurrentMethodStackOffset);
3415 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003416
Vladimir Marko58155012015-08-19 12:49:41 +00003417 // temp = temp->dex_cache_resolved_methods_;
Vladimir Marko05792b92015-08-03 11:56:49 +01003418 __ LoadFromOffset(kLoadDoubleword,
Vladimir Marko58155012015-08-19 12:49:41 +00003419 reg,
3420 method_reg,
Vladimir Marko05792b92015-08-03 11:56:49 +01003421 ArtMethod::DexCacheResolvedMethodsOffset(kMips64PointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01003422 // temp = temp[index_in_cache];
3423 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
3424 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Vladimir Marko58155012015-08-19 12:49:41 +00003425 __ LoadFromOffset(kLoadDoubleword,
3426 reg,
3427 reg,
3428 CodeGenerator::GetCachePointerOffset(index_in_cache));
3429 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003430 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003431 }
3432
Alexey Frunze19f6c692016-11-30 19:19:55 -08003433 switch (code_ptr_location) {
Vladimir Marko58155012015-08-19 12:49:41 +00003434 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
Alexey Frunze19f6c692016-11-30 19:19:55 -08003435 __ Balc(&frame_entry_label_);
Vladimir Marko58155012015-08-19 12:49:41 +00003436 break;
Vladimir Marko58155012015-08-19 12:49:41 +00003437 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
3438 // T9 = callee_method->entry_point_from_quick_compiled_code_;
3439 __ LoadFromOffset(kLoadDoubleword,
3440 T9,
3441 callee_method.AsRegister<GpuRegister>(),
3442 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07003443 kMips64PointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00003444 // T9()
3445 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003446 __ Nop();
Vladimir Marko58155012015-08-19 12:49:41 +00003447 break;
3448 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003449 DCHECK(!IsLeafMethod());
3450}
3451
3452void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00003453 // Explicit clinit checks triggered by static invokes must have been pruned by
3454 // art::PrepareForRegisterAllocation.
3455 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003456
3457 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
3458 return;
3459 }
3460
3461 LocationSummary* locations = invoke->GetLocations();
3462 codegen_->GenerateStaticOrDirectCall(invoke,
3463 locations->HasTemps()
3464 ? locations->GetTemp(0)
3465 : Location::NoLocation());
3466 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3467}
3468
Alexey Frunze53afca12015-11-05 16:34:23 -08003469void CodeGeneratorMIPS64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
Nicolas Geoffraye5234232015-12-02 09:06:11 +00003470 // Use the calling convention instead of the location of the receiver, as
3471 // intrinsics may have put the receiver in a different register. In the intrinsics
3472 // slow path, the arguments have been moved to the right place, so here we are
3473 // guaranteed that the receiver is the first register of the calling convention.
3474 InvokeDexCallingConvention calling_convention;
3475 GpuRegister receiver = calling_convention.GetRegisterAt(0);
3476
Alexey Frunze53afca12015-11-05 16:34:23 -08003477 GpuRegister temp = temp_location.AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003478 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
3479 invoke->GetVTableIndex(), kMips64PointerSize).SizeValue();
3480 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07003481 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003482
3483 // temp = object->GetClass();
Nicolas Geoffraye5234232015-12-02 09:06:11 +00003484 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset);
Alexey Frunze53afca12015-11-05 16:34:23 -08003485 MaybeRecordImplicitNullCheck(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003486 // temp = temp->GetMethodAt(method_offset);
3487 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
3488 // T9 = temp->GetEntryPoint();
3489 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
3490 // T9();
3491 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003492 __ Nop();
Alexey Frunze53afca12015-11-05 16:34:23 -08003493}
3494
3495void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
3496 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
3497 return;
3498 }
3499
3500 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003501 DCHECK(!codegen_->IsLeafMethod());
3502 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3503}
3504
3505void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) {
Vladimir Marko41559982017-01-06 14:04:23 +00003506 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
3507 if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08003508 InvokeRuntimeCallingConvention calling_convention;
Vladimir Marko41559982017-01-06 14:04:23 +00003509 CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(
Alexey Frunzef63f5692016-12-13 17:43:11 -08003510 cls,
3511 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Vladimir Marko41559982017-01-06 14:04:23 +00003512 calling_convention.GetReturnLocation(Primitive::kPrimNot));
Alexey Frunzef63f5692016-12-13 17:43:11 -08003513 return;
3514 }
Vladimir Marko41559982017-01-06 14:04:23 +00003515 DCHECK(!cls->NeedsAccessCheck());
Alexey Frunzef63f5692016-12-13 17:43:11 -08003516
3517 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier)
3518 ? LocationSummary::kCallOnSlowPath
3519 : LocationSummary::kNoCall;
3520 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Vladimir Marko41559982017-01-06 14:04:23 +00003521 if (load_kind == HLoadClass::LoadKind::kReferrersClass) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08003522 locations->SetInAt(0, Location::RequiresRegister());
3523 }
3524 locations->SetOut(Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003525}
3526
Nicolas Geoffray5247c082017-01-13 14:17:29 +00003527// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
3528// move.
3529void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS {
Vladimir Marko41559982017-01-06 14:04:23 +00003530 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
3531 if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) {
3532 codegen_->GenerateLoadClassRuntimeCall(cls);
Calin Juravle580b6092015-10-06 17:35:58 +01003533 return;
3534 }
Vladimir Marko41559982017-01-06 14:04:23 +00003535 DCHECK(!cls->NeedsAccessCheck());
Calin Juravle580b6092015-10-06 17:35:58 +01003536
Vladimir Marko41559982017-01-06 14:04:23 +00003537 LocationSummary* locations = cls->GetLocations();
Alexey Frunzef63f5692016-12-13 17:43:11 -08003538 Location out_loc = locations->Out();
3539 GpuRegister out = out_loc.AsRegister<GpuRegister>();
3540 GpuRegister current_method_reg = ZERO;
3541 if (load_kind == HLoadClass::LoadKind::kReferrersClass ||
3542 load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) {
3543 current_method_reg = locations->InAt(0).AsRegister<GpuRegister>();
3544 }
3545
3546 bool generate_null_check = false;
3547 switch (load_kind) {
3548 case HLoadClass::LoadKind::kReferrersClass:
3549 DCHECK(!cls->CanCallRuntime());
3550 DCHECK(!cls->MustGenerateClinitCheck());
3551 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
3552 GenerateGcRootFieldLoad(cls,
3553 out_loc,
3554 current_method_reg,
3555 ArtMethod::DeclaringClassOffset().Int32Value());
3556 break;
3557 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003558 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunzef63f5692016-12-13 17:43:11 -08003559 __ LoadLiteral(out,
3560 kLoadUnsignedWord,
3561 codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
3562 cls->GetTypeIndex()));
3563 break;
3564 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003565 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunzef63f5692016-12-13 17:43:11 -08003566 CodeGeneratorMIPS64::PcRelativePatchInfo* info =
3567 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
3568 codegen_->EmitPcRelativeAddressPlaceholderHigh(info, AT);
3569 __ Daddiu(out, AT, /* placeholder */ 0x5678);
3570 break;
3571 }
3572 case HLoadClass::LoadKind::kBootImageAddress: {
3573 DCHECK(!kEmitCompilerReadBarrier);
Nicolas Geoffray5247c082017-01-13 14:17:29 +00003574 uint32_t address = dchecked_integral_cast<uint32_t>(
3575 reinterpret_cast<uintptr_t>(cls->GetClass().Get()));
3576 DCHECK_NE(address, 0u);
Alexey Frunzef63f5692016-12-13 17:43:11 -08003577 __ LoadLiteral(out,
3578 kLoadUnsignedWord,
3579 codegen_->DeduplicateBootImageAddressLiteral(address));
3580 break;
3581 }
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003582 case HLoadClass::LoadKind::kBssEntry: {
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003583 CodeGeneratorMIPS64::PcRelativePatchInfo* info =
Vladimir Marko1998cd02017-01-13 13:02:58 +00003584 codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex());
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003585 codegen_->EmitPcRelativeAddressPlaceholderHigh(info, AT);
3586 __ Lwu(out, AT, /* placeholder */ 0x5678);
3587 generate_null_check = true;
3588 break;
3589 }
Alexey Frunzef63f5692016-12-13 17:43:11 -08003590 case HLoadClass::LoadKind::kJitTableAddress: {
3591 LOG(FATAL) << "Unimplemented";
3592 break;
3593 }
Vladimir Marko41559982017-01-06 14:04:23 +00003594 case HLoadClass::LoadKind::kDexCacheViaMethod:
3595 LOG(FATAL) << "UNREACHABLE";
3596 UNREACHABLE();
Alexey Frunzef63f5692016-12-13 17:43:11 -08003597 }
3598
3599 if (generate_null_check || cls->MustGenerateClinitCheck()) {
3600 DCHECK(cls->CanCallRuntime());
3601 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64(
3602 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3603 codegen_->AddSlowPath(slow_path);
3604 if (generate_null_check) {
3605 __ Beqzc(out, slow_path->GetEntryLabel());
3606 }
3607 if (cls->MustGenerateClinitCheck()) {
3608 GenerateClassInitializationCheck(slow_path, out);
3609 } else {
3610 __ Bind(slow_path->GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003611 }
3612 }
3613}
3614
David Brazdilcb1c0552015-08-04 16:22:25 +01003615static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07003616 return Thread::ExceptionOffset<kMips64PointerSize>().Int32Value();
David Brazdilcb1c0552015-08-04 16:22:25 +01003617}
3618
Alexey Frunze4dda3372015-06-01 18:31:49 -07003619void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) {
3620 LocationSummary* locations =
3621 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3622 locations->SetOut(Location::RequiresRegister());
3623}
3624
3625void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) {
3626 GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>();
David Brazdilcb1c0552015-08-04 16:22:25 +01003627 __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset());
3628}
3629
3630void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) {
3631 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
3632}
3633
3634void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
3635 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003636}
3637
Alexey Frunze4dda3372015-06-01 18:31:49 -07003638void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) {
Alexey Frunzef63f5692016-12-13 17:43:11 -08003639 HLoadString::LoadKind load_kind = load->GetLoadKind();
3640 LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load);
Nicolas Geoffray917d0162015-11-24 18:25:35 +00003641 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Alexey Frunzef63f5692016-12-13 17:43:11 -08003642 if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) {
3643 InvokeRuntimeCallingConvention calling_convention;
3644 locations->SetOut(calling_convention.GetReturnLocation(load->GetType()));
3645 } else {
3646 locations->SetOut(Location::RequiresRegister());
3647 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003648}
3649
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00003650// NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not
3651// move.
3652void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS {
Alexey Frunzef63f5692016-12-13 17:43:11 -08003653 HLoadString::LoadKind load_kind = load->GetLoadKind();
3654 LocationSummary* locations = load->GetLocations();
3655 Location out_loc = locations->Out();
3656 GpuRegister out = out_loc.AsRegister<GpuRegister>();
3657
3658 switch (load_kind) {
3659 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003660 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunzef63f5692016-12-13 17:43:11 -08003661 __ LoadLiteral(out,
3662 kLoadUnsignedWord,
3663 codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
3664 load->GetStringIndex()));
3665 return; // No dex cache slow path.
3666 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
3667 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
3668 CodeGeneratorMIPS64::PcRelativePatchInfo* info =
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003669 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunzef63f5692016-12-13 17:43:11 -08003670 codegen_->EmitPcRelativeAddressPlaceholderHigh(info, AT);
3671 __ Daddiu(out, AT, /* placeholder */ 0x5678);
3672 return; // No dex cache slow path.
3673 }
3674 case HLoadString::LoadKind::kBootImageAddress: {
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +00003675 uint32_t address = dchecked_integral_cast<uint32_t>(
3676 reinterpret_cast<uintptr_t>(load->GetString().Get()));
3677 DCHECK_NE(address, 0u);
Alexey Frunzef63f5692016-12-13 17:43:11 -08003678 __ LoadLiteral(out,
3679 kLoadUnsignedWord,
3680 codegen_->DeduplicateBootImageAddressLiteral(address));
3681 return; // No dex cache slow path.
3682 }
3683 case HLoadString::LoadKind::kBssEntry: {
3684 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
3685 CodeGeneratorMIPS64::PcRelativePatchInfo* info =
Vladimir Marko6bec91c2017-01-09 15:03:12 +00003686 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunzef63f5692016-12-13 17:43:11 -08003687 codegen_->EmitPcRelativeAddressPlaceholderHigh(info, AT);
3688 __ Lwu(out, AT, /* placeholder */ 0x5678);
3689 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS64(load);
3690 codegen_->AddSlowPath(slow_path);
3691 __ Beqzc(out, slow_path->GetEntryLabel());
3692 __ Bind(slow_path->GetExitLabel());
3693 return;
3694 }
3695 default:
3696 break;
3697 }
3698
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07003699 // TODO: Re-add the compiler code to do string dex cache lookup again.
Alexey Frunzef63f5692016-12-13 17:43:11 -08003700 DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod);
3701 InvokeRuntimeCallingConvention calling_convention;
3702 __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_);
3703 codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc());
3704 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003705}
3706
Alexey Frunze4dda3372015-06-01 18:31:49 -07003707void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) {
3708 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3709 locations->SetOut(Location::ConstantLocation(constant));
3710}
3711
3712void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
3713 // Will be generated at use site.
3714}
3715
3716void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
3717 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003718 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003719 InvokeRuntimeCallingConvention calling_convention;
3720 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3721}
3722
3723void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
Serban Constantinescufc734082016-07-19 17:18:07 +01003724 codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003725 instruction,
Serban Constantinescufc734082016-07-19 17:18:07 +01003726 instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003727 if (instruction->IsEnter()) {
3728 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
3729 } else {
3730 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
3731 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003732}
3733
3734void LocationsBuilderMIPS64::VisitMul(HMul* mul) {
3735 LocationSummary* locations =
3736 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
3737 switch (mul->GetResultType()) {
3738 case Primitive::kPrimInt:
3739 case Primitive::kPrimLong:
3740 locations->SetInAt(0, Location::RequiresRegister());
3741 locations->SetInAt(1, Location::RequiresRegister());
3742 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3743 break;
3744
3745 case Primitive::kPrimFloat:
3746 case Primitive::kPrimDouble:
3747 locations->SetInAt(0, Location::RequiresFpuRegister());
3748 locations->SetInAt(1, Location::RequiresFpuRegister());
3749 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3750 break;
3751
3752 default:
3753 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
3754 }
3755}
3756
3757void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) {
3758 Primitive::Type type = instruction->GetType();
3759 LocationSummary* locations = instruction->GetLocations();
3760
3761 switch (type) {
3762 case Primitive::kPrimInt:
3763 case Primitive::kPrimLong: {
3764 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3765 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
3766 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
3767 if (type == Primitive::kPrimInt)
3768 __ MulR6(dst, lhs, rhs);
3769 else
3770 __ Dmul(dst, lhs, rhs);
3771 break;
3772 }
3773 case Primitive::kPrimFloat:
3774 case Primitive::kPrimDouble: {
3775 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3776 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
3777 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
3778 if (type == Primitive::kPrimFloat)
3779 __ MulS(dst, lhs, rhs);
3780 else
3781 __ MulD(dst, lhs, rhs);
3782 break;
3783 }
3784 default:
3785 LOG(FATAL) << "Unexpected mul type " << type;
3786 }
3787}
3788
3789void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) {
3790 LocationSummary* locations =
3791 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
3792 switch (neg->GetResultType()) {
3793 case Primitive::kPrimInt:
3794 case Primitive::kPrimLong:
3795 locations->SetInAt(0, Location::RequiresRegister());
3796 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3797 break;
3798
3799 case Primitive::kPrimFloat:
3800 case Primitive::kPrimDouble:
3801 locations->SetInAt(0, Location::RequiresFpuRegister());
3802 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3803 break;
3804
3805 default:
3806 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
3807 }
3808}
3809
3810void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) {
3811 Primitive::Type type = instruction->GetType();
3812 LocationSummary* locations = instruction->GetLocations();
3813
3814 switch (type) {
3815 case Primitive::kPrimInt:
3816 case Primitive::kPrimLong: {
3817 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3818 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
3819 if (type == Primitive::kPrimInt)
3820 __ Subu(dst, ZERO, src);
3821 else
3822 __ Dsubu(dst, ZERO, src);
3823 break;
3824 }
3825 case Primitive::kPrimFloat:
3826 case Primitive::kPrimDouble: {
3827 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3828 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
3829 if (type == Primitive::kPrimFloat)
3830 __ NegS(dst, src);
3831 else
3832 __ NegD(dst, src);
3833 break;
3834 }
3835 default:
3836 LOG(FATAL) << "Unexpected neg type " << type;
3837 }
3838}
3839
3840void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) {
3841 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003842 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003843 InvokeRuntimeCallingConvention calling_convention;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003844 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00003845 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3846 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003847}
3848
3849void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) {
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00003850 codegen_->InvokeRuntime(kQuickAllocArrayResolved, instruction, instruction->GetDexPc());
3851 CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003852}
3853
3854void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) {
3855 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003856 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003857 InvokeRuntimeCallingConvention calling_convention;
David Brazdil6de19382016-01-08 17:37:10 +00003858 if (instruction->IsStringAlloc()) {
3859 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
3860 } else {
3861 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
David Brazdil6de19382016-01-08 17:37:10 +00003862 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003863 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
3864}
3865
3866void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) {
David Brazdil6de19382016-01-08 17:37:10 +00003867 if (instruction->IsStringAlloc()) {
3868 // String is allocated through StringFactory. Call NewEmptyString entry point.
3869 GpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
Lazar Trsicd9672662015-09-03 17:33:01 +02003870 MemberOffset code_offset =
Andreas Gampe542451c2016-07-26 09:02:02 -07003871 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00003872 __ LoadFromOffset(kLoadDoubleword, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
3873 __ LoadFromOffset(kLoadDoubleword, T9, temp, code_offset.Int32Value());
3874 __ Jalr(T9);
3875 __ Nop();
3876 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3877 } else {
Serban Constantinescufc734082016-07-19 17:18:07 +01003878 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00003879 CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>();
David Brazdil6de19382016-01-08 17:37:10 +00003880 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003881}
3882
3883void LocationsBuilderMIPS64::VisitNot(HNot* instruction) {
3884 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
3885 locations->SetInAt(0, Location::RequiresRegister());
3886 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3887}
3888
3889void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) {
3890 Primitive::Type type = instruction->GetType();
3891 LocationSummary* locations = instruction->GetLocations();
3892
3893 switch (type) {
3894 case Primitive::kPrimInt:
3895 case Primitive::kPrimLong: {
3896 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3897 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
3898 __ Nor(dst, src, ZERO);
3899 break;
3900 }
3901
3902 default:
3903 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
3904 }
3905}
3906
3907void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
3908 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
3909 locations->SetInAt(0, Location::RequiresRegister());
3910 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3911}
3912
3913void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
3914 LocationSummary* locations = instruction->GetLocations();
3915 __ Xori(locations->Out().AsRegister<GpuRegister>(),
3916 locations->InAt(0).AsRegister<GpuRegister>(),
3917 1);
3918}
3919
3920void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01003921 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
3922 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003923}
3924
Calin Juravle2ae48182016-03-16 14:05:09 +00003925void CodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) {
3926 if (CanMoveNullCheckToUser(instruction)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003927 return;
3928 }
3929 Location obj = instruction->GetLocations()->InAt(0);
3930
3931 __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00003932 RecordPcInfo(instruction, instruction->GetDexPc());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003933}
3934
Calin Juravle2ae48182016-03-16 14:05:09 +00003935void CodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003936 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS64(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00003937 AddSlowPath(slow_path);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003938
3939 Location obj = instruction->GetLocations()->InAt(0);
3940
3941 __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
3942}
3943
3944void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00003945 codegen_->GenerateNullCheck(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003946}
3947
3948void LocationsBuilderMIPS64::VisitOr(HOr* instruction) {
3949 HandleBinaryOp(instruction);
3950}
3951
3952void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) {
3953 HandleBinaryOp(instruction);
3954}
3955
3956void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
3957 LOG(FATAL) << "Unreachable";
3958}
3959
3960void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) {
3961 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3962}
3963
3964void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) {
3965 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
3966 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3967 if (location.IsStackSlot()) {
3968 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3969 } else if (location.IsDoubleStackSlot()) {
3970 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3971 }
3972 locations->SetOut(location);
3973}
3974
3975void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction
3976 ATTRIBUTE_UNUSED) {
3977 // Nothing to do, the parameter is already at its location.
3978}
3979
3980void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) {
3981 LocationSummary* locations =
3982 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3983 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3984}
3985
3986void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction
3987 ATTRIBUTE_UNUSED) {
3988 // Nothing to do, the method is already at its location.
3989}
3990
3991void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) {
3992 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Vladimir Marko372f10e2016-05-17 16:30:10 +01003993 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003994 locations->SetInAt(i, Location::Any());
3995 }
3996 locations->SetOut(Location::Any());
3997}
3998
3999void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
4000 LOG(FATAL) << "Unreachable";
4001}
4002
4003void LocationsBuilderMIPS64::VisitRem(HRem* rem) {
4004 Primitive::Type type = rem->GetResultType();
4005 LocationSummary::CallKind call_kind =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004006 Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly
4007 : LocationSummary::kNoCall;
Alexey Frunze4dda3372015-06-01 18:31:49 -07004008 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
4009
4010 switch (type) {
4011 case Primitive::kPrimInt:
4012 case Primitive::kPrimLong:
4013 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunzec857c742015-09-23 15:12:39 -07004014 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07004015 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4016 break;
4017
4018 case Primitive::kPrimFloat:
4019 case Primitive::kPrimDouble: {
4020 InvokeRuntimeCallingConvention calling_convention;
4021 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
4022 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
4023 locations->SetOut(calling_convention.GetReturnLocation(type));
4024 break;
4025 }
4026
4027 default:
4028 LOG(FATAL) << "Unexpected rem type " << type;
4029 }
4030}
4031
4032void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) {
4033 Primitive::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07004034
4035 switch (type) {
4036 case Primitive::kPrimInt:
Alexey Frunzec857c742015-09-23 15:12:39 -07004037 case Primitive::kPrimLong:
4038 GenerateDivRemIntegral(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004039 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07004040
4041 case Primitive::kPrimFloat:
4042 case Primitive::kPrimDouble: {
Serban Constantinescufc734082016-07-19 17:18:07 +01004043 QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod;
4044 codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00004045 if (type == Primitive::kPrimFloat) {
4046 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
4047 } else {
4048 CheckEntrypointTypes<kQuickFmod, double, double, double>();
4049 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004050 break;
4051 }
4052 default:
4053 LOG(FATAL) << "Unexpected rem type " << type;
4054 }
4055}
4056
4057void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
4058 memory_barrier->SetLocations(nullptr);
4059}
4060
4061void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
4062 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
4063}
4064
4065void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) {
4066 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret);
4067 Primitive::Type return_type = ret->InputAt(0)->GetType();
4068 locations->SetInAt(0, Mips64ReturnLocation(return_type));
4069}
4070
4071void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
4072 codegen_->GenerateFrameExit();
4073}
4074
4075void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) {
4076 ret->SetLocations(nullptr);
4077}
4078
4079void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
4080 codegen_->GenerateFrameExit();
4081}
4082
Alexey Frunze92d90602015-12-18 18:16:36 -08004083void LocationsBuilderMIPS64::VisitRor(HRor* ror) {
4084 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00004085}
4086
Alexey Frunze92d90602015-12-18 18:16:36 -08004087void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) {
4088 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00004089}
4090
Alexey Frunze4dda3372015-06-01 18:31:49 -07004091void LocationsBuilderMIPS64::VisitShl(HShl* shl) {
4092 HandleShift(shl);
4093}
4094
4095void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) {
4096 HandleShift(shl);
4097}
4098
4099void LocationsBuilderMIPS64::VisitShr(HShr* shr) {
4100 HandleShift(shr);
4101}
4102
4103void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) {
4104 HandleShift(shr);
4105}
4106
Alexey Frunze4dda3372015-06-01 18:31:49 -07004107void LocationsBuilderMIPS64::VisitSub(HSub* instruction) {
4108 HandleBinaryOp(instruction);
4109}
4110
4111void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) {
4112 HandleBinaryOp(instruction);
4113}
4114
4115void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4116 HandleFieldGet(instruction, instruction->GetFieldInfo());
4117}
4118
4119void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4120 HandleFieldGet(instruction, instruction->GetFieldInfo());
4121}
4122
4123void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
4124 HandleFieldSet(instruction, instruction->GetFieldInfo());
4125}
4126
4127void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Goran Jakovljevic8ed18262016-01-22 13:01:00 +01004128 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Alexey Frunze4dda3372015-06-01 18:31:49 -07004129}
4130
Calin Juravlee460d1d2015-09-29 04:52:17 +01004131void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet(
4132 HUnresolvedInstanceFieldGet* instruction) {
4133 FieldAccessCallingConventionMIPS64 calling_convention;
4134 codegen_->CreateUnresolvedFieldLocationSummary(
4135 instruction, instruction->GetFieldType(), calling_convention);
4136}
4137
4138void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet(
4139 HUnresolvedInstanceFieldGet* instruction) {
4140 FieldAccessCallingConventionMIPS64 calling_convention;
4141 codegen_->GenerateUnresolvedFieldAccess(instruction,
4142 instruction->GetFieldType(),
4143 instruction->GetFieldIndex(),
4144 instruction->GetDexPc(),
4145 calling_convention);
4146}
4147
4148void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet(
4149 HUnresolvedInstanceFieldSet* instruction) {
4150 FieldAccessCallingConventionMIPS64 calling_convention;
4151 codegen_->CreateUnresolvedFieldLocationSummary(
4152 instruction, instruction->GetFieldType(), calling_convention);
4153}
4154
4155void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet(
4156 HUnresolvedInstanceFieldSet* instruction) {
4157 FieldAccessCallingConventionMIPS64 calling_convention;
4158 codegen_->GenerateUnresolvedFieldAccess(instruction,
4159 instruction->GetFieldType(),
4160 instruction->GetFieldIndex(),
4161 instruction->GetDexPc(),
4162 calling_convention);
4163}
4164
4165void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet(
4166 HUnresolvedStaticFieldGet* instruction) {
4167 FieldAccessCallingConventionMIPS64 calling_convention;
4168 codegen_->CreateUnresolvedFieldLocationSummary(
4169 instruction, instruction->GetFieldType(), calling_convention);
4170}
4171
4172void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet(
4173 HUnresolvedStaticFieldGet* instruction) {
4174 FieldAccessCallingConventionMIPS64 calling_convention;
4175 codegen_->GenerateUnresolvedFieldAccess(instruction,
4176 instruction->GetFieldType(),
4177 instruction->GetFieldIndex(),
4178 instruction->GetDexPc(),
4179 calling_convention);
4180}
4181
4182void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet(
4183 HUnresolvedStaticFieldSet* instruction) {
4184 FieldAccessCallingConventionMIPS64 calling_convention;
4185 codegen_->CreateUnresolvedFieldLocationSummary(
4186 instruction, instruction->GetFieldType(), calling_convention);
4187}
4188
4189void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet(
4190 HUnresolvedStaticFieldSet* instruction) {
4191 FieldAccessCallingConventionMIPS64 calling_convention;
4192 codegen_->GenerateUnresolvedFieldAccess(instruction,
4193 instruction->GetFieldType(),
4194 instruction->GetFieldIndex(),
4195 instruction->GetDexPc(),
4196 calling_convention);
4197}
4198
Alexey Frunze4dda3372015-06-01 18:31:49 -07004199void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
Vladimir Marko70e97462016-08-09 11:04:26 +01004200 LocationSummary* locations =
4201 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
Vladimir Marko804b03f2016-09-14 16:26:36 +01004202 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
Alexey Frunze4dda3372015-06-01 18:31:49 -07004203}
4204
4205void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
4206 HBasicBlock* block = instruction->GetBlock();
4207 if (block->GetLoopInformation() != nullptr) {
4208 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
4209 // The back edge will generate the suspend check.
4210 return;
4211 }
4212 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
4213 // The goto will generate the suspend check.
4214 return;
4215 }
4216 GenerateSuspendCheck(instruction, nullptr);
4217}
4218
Alexey Frunze4dda3372015-06-01 18:31:49 -07004219void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) {
4220 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004221 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004222 InvokeRuntimeCallingConvention calling_convention;
4223 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4224}
4225
4226void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) {
Serban Constantinescufc734082016-07-19 17:18:07 +01004227 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Alexey Frunze4dda3372015-06-01 18:31:49 -07004228 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
4229}
4230
4231void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
4232 Primitive::Type input_type = conversion->GetInputType();
4233 Primitive::Type result_type = conversion->GetResultType();
4234 DCHECK_NE(input_type, result_type);
4235
4236 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
4237 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
4238 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
4239 }
4240
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004241 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion);
4242
4243 if (Primitive::IsFloatingPointType(input_type)) {
4244 locations->SetInAt(0, Location::RequiresFpuRegister());
4245 } else {
4246 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze4dda3372015-06-01 18:31:49 -07004247 }
4248
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004249 if (Primitive::IsFloatingPointType(result_type)) {
4250 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004251 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004252 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004253 }
4254}
4255
4256void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
4257 LocationSummary* locations = conversion->GetLocations();
4258 Primitive::Type result_type = conversion->GetResultType();
4259 Primitive::Type input_type = conversion->GetInputType();
4260
4261 DCHECK_NE(input_type, result_type);
4262
4263 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
4264 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
4265 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
4266
4267 switch (result_type) {
4268 case Primitive::kPrimChar:
4269 __ Andi(dst, src, 0xFFFF);
4270 break;
4271 case Primitive::kPrimByte:
Vladimir Markob52bbde2016-02-12 12:06:05 +00004272 if (input_type == Primitive::kPrimLong) {
4273 // Type conversion from long to types narrower than int is a result of code
4274 // transformations. To avoid unpredictable results for SEB and SEH, we first
4275 // need to sign-extend the low 32-bit value into bits 32 through 63.
4276 __ Sll(dst, src, 0);
4277 __ Seb(dst, dst);
4278 } else {
4279 __ Seb(dst, src);
4280 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004281 break;
4282 case Primitive::kPrimShort:
Vladimir Markob52bbde2016-02-12 12:06:05 +00004283 if (input_type == Primitive::kPrimLong) {
4284 // Type conversion from long to types narrower than int is a result of code
4285 // transformations. To avoid unpredictable results for SEB and SEH, we first
4286 // need to sign-extend the low 32-bit value into bits 32 through 63.
4287 __ Sll(dst, src, 0);
4288 __ Seh(dst, dst);
4289 } else {
4290 __ Seh(dst, src);
4291 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004292 break;
4293 case Primitive::kPrimInt:
4294 case Primitive::kPrimLong:
Goran Jakovljevic992bdb92016-12-28 16:21:48 +01004295 // Sign-extend 32-bit int into bits 32 through 63 for int-to-long and long-to-int
4296 // conversions, except when the input and output registers are the same and we are not
4297 // converting longs to shorter types. In these cases, do nothing.
4298 if ((input_type == Primitive::kPrimLong) || (dst != src)) {
4299 __ Sll(dst, src, 0);
4300 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004301 break;
4302
4303 default:
4304 LOG(FATAL) << "Unexpected type conversion from " << input_type
4305 << " to " << result_type;
4306 }
4307 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004308 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
4309 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
4310 if (input_type == Primitive::kPrimLong) {
4311 __ Dmtc1(src, FTMP);
4312 if (result_type == Primitive::kPrimFloat) {
4313 __ Cvtsl(dst, FTMP);
4314 } else {
4315 __ Cvtdl(dst, FTMP);
4316 }
4317 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -07004318 __ Mtc1(src, FTMP);
4319 if (result_type == Primitive::kPrimFloat) {
4320 __ Cvtsw(dst, FTMP);
4321 } else {
4322 __ Cvtdw(dst, FTMP);
4323 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004324 }
4325 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
4326 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004327 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
4328 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
4329 Mips64Label truncate;
4330 Mips64Label done;
4331
4332 // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive
4333 // value when the input is either a NaN or is outside of the range of the output type
4334 // after the truncation. IOW, the three special cases (NaN, too small, too big) produce
4335 // the same result.
4336 //
4337 // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum
4338 // value of the output type if the input is outside of the range after the truncation or
4339 // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct
4340 // results. This matches the desired float/double-to-int/long conversion exactly.
4341 //
4342 // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction.
4343 //
4344 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
4345 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
4346 // even though it must be NAN2008=1 on R6.
4347 //
4348 // The code takes care of the different behaviors by first comparing the input to the
4349 // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int).
4350 // If the input is greater than or equal to the minimum, it procedes to the truncate
4351 // instruction, which will handle such an input the same way irrespective of NAN2008.
4352 // Otherwise the input is compared to itself to determine whether it is a NaN or not
4353 // in order to return either zero or the minimum value.
4354 //
4355 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
4356 // truncate instruction for MIPS64R6.
4357 if (input_type == Primitive::kPrimFloat) {
4358 uint32_t min_val = (result_type == Primitive::kPrimLong)
4359 ? bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min())
4360 : bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min());
4361 __ LoadConst32(TMP, min_val);
4362 __ Mtc1(TMP, FTMP);
4363 __ CmpLeS(FTMP, FTMP, src);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004364 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004365 uint64_t min_val = (result_type == Primitive::kPrimLong)
4366 ? bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min())
4367 : bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min());
4368 __ LoadConst64(TMP, min_val);
4369 __ Dmtc1(TMP, FTMP);
4370 __ CmpLeD(FTMP, FTMP, src);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004371 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004372
4373 __ Bc1nez(FTMP, &truncate);
4374
4375 if (input_type == Primitive::kPrimFloat) {
4376 __ CmpEqS(FTMP, src, src);
4377 } else {
4378 __ CmpEqD(FTMP, src, src);
4379 }
4380 if (result_type == Primitive::kPrimLong) {
4381 __ LoadConst64(dst, std::numeric_limits<int64_t>::min());
4382 } else {
4383 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
4384 }
4385 __ Mfc1(TMP, FTMP);
4386 __ And(dst, dst, TMP);
4387
4388 __ Bc(&done);
4389
4390 __ Bind(&truncate);
4391
4392 if (result_type == Primitive::kPrimLong) {
Roland Levillain888d0672015-11-23 18:53:50 +00004393 if (input_type == Primitive::kPrimFloat) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004394 __ TruncLS(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00004395 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004396 __ TruncLD(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00004397 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004398 __ Dmfc1(dst, FTMP);
Roland Levillain888d0672015-11-23 18:53:50 +00004399 } else {
4400 if (input_type == Primitive::kPrimFloat) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004401 __ TruncWS(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00004402 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004403 __ TruncWD(FTMP, src);
Roland Levillain888d0672015-11-23 18:53:50 +00004404 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004405 __ Mfc1(dst, FTMP);
Roland Levillain888d0672015-11-23 18:53:50 +00004406 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004407
4408 __ Bind(&done);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004409 } else if (Primitive::IsFloatingPointType(result_type) &&
4410 Primitive::IsFloatingPointType(input_type)) {
4411 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
4412 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
4413 if (result_type == Primitive::kPrimFloat) {
4414 __ Cvtsd(dst, src);
4415 } else {
4416 __ Cvtds(dst, src);
4417 }
4418 } else {
4419 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
4420 << " to " << result_type;
4421 }
4422}
4423
4424void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) {
4425 HandleShift(ushr);
4426}
4427
4428void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) {
4429 HandleShift(ushr);
4430}
4431
4432void LocationsBuilderMIPS64::VisitXor(HXor* instruction) {
4433 HandleBinaryOp(instruction);
4434}
4435
4436void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) {
4437 HandleBinaryOp(instruction);
4438}
4439
4440void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
4441 // Nothing to do, this should be removed during prepare for register allocator.
4442 LOG(FATAL) << "Unreachable";
4443}
4444
4445void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
4446 // Nothing to do, this should be removed during prepare for register allocator.
4447 LOG(FATAL) << "Unreachable";
4448}
4449
4450void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004451 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004452}
4453
4454void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004455 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004456}
4457
4458void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004459 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004460}
4461
4462void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004463 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004464}
4465
4466void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004467 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004468}
4469
4470void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004471 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004472}
4473
4474void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004475 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004476}
4477
4478void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004479 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004480}
4481
4482void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004483 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004484}
4485
4486void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004487 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004488}
4489
4490void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004491 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004492}
4493
4494void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004495 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004496}
4497
Aart Bike9f37602015-10-09 11:15:55 -07004498void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004499 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004500}
4501
4502void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004503 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004504}
4505
4506void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004507 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004508}
4509
4510void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004511 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004512}
4513
4514void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004515 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004516}
4517
4518void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004519 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004520}
4521
4522void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004523 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004524}
4525
4526void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004527 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004528}
4529
Mark Mendellfe57faa2015-09-18 09:26:15 -04004530// Simple implementation of packed switch - generate cascaded compare/jumps.
4531void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
4532 LocationSummary* locations =
4533 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
4534 locations->SetInAt(0, Location::RequiresRegister());
4535}
4536
Alexey Frunze0960ac52016-12-20 17:24:59 -08004537void InstructionCodeGeneratorMIPS64::GenPackedSwitchWithCompares(GpuRegister value_reg,
4538 int32_t lower_bound,
4539 uint32_t num_entries,
4540 HBasicBlock* switch_block,
4541 HBasicBlock* default_block) {
Vladimir Markof3e0ee22015-12-17 15:23:13 +00004542 // Create a set of compare/jumps.
4543 GpuRegister temp_reg = TMP;
Alexey Frunze0960ac52016-12-20 17:24:59 -08004544 __ Addiu32(temp_reg, value_reg, -lower_bound);
Vladimir Markof3e0ee22015-12-17 15:23:13 +00004545 // Jump to default if index is negative
4546 // Note: We don't check the case that index is positive while value < lower_bound, because in
4547 // this case, index >= num_entries must be true. So that we can save one branch instruction.
4548 __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block));
4549
Alexey Frunze0960ac52016-12-20 17:24:59 -08004550 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00004551 // Jump to successors[0] if value == lower_bound.
4552 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0]));
4553 int32_t last_index = 0;
4554 for (; num_entries - last_index > 2; last_index += 2) {
4555 __ Addiu(temp_reg, temp_reg, -2);
4556 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
4557 __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
4558 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
4559 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
4560 }
4561 if (num_entries - last_index == 2) {
4562 // The last missing case_value.
4563 __ Addiu(temp_reg, temp_reg, -1);
4564 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Mark Mendellfe57faa2015-09-18 09:26:15 -04004565 }
4566
4567 // And the default for any other value.
Alexey Frunze0960ac52016-12-20 17:24:59 -08004568 if (!codegen_->GoesToNextBlock(switch_block, default_block)) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004569 __ Bc(codegen_->GetLabelOf(default_block));
Mark Mendellfe57faa2015-09-18 09:26:15 -04004570 }
4571}
4572
Alexey Frunze0960ac52016-12-20 17:24:59 -08004573void InstructionCodeGeneratorMIPS64::GenTableBasedPackedSwitch(GpuRegister value_reg,
4574 int32_t lower_bound,
4575 uint32_t num_entries,
4576 HBasicBlock* switch_block,
4577 HBasicBlock* default_block) {
4578 // Create a jump table.
4579 std::vector<Mips64Label*> labels(num_entries);
4580 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
4581 for (uint32_t i = 0; i < num_entries; i++) {
4582 labels[i] = codegen_->GetLabelOf(successors[i]);
4583 }
4584 JumpTable* table = __ CreateJumpTable(std::move(labels));
4585
4586 // Is the value in range?
4587 __ Addiu32(TMP, value_reg, -lower_bound);
4588 __ LoadConst32(AT, num_entries);
4589 __ Bgeuc(TMP, AT, codegen_->GetLabelOf(default_block));
4590
4591 // We are in the range of the table.
4592 // Load the target address from the jump table, indexing by the value.
4593 __ LoadLabelAddress(AT, table->GetLabel());
4594 __ Sll(TMP, TMP, 2);
4595 __ Daddu(TMP, TMP, AT);
4596 __ Lw(TMP, TMP, 0);
4597 // Compute the absolute target address by adding the table start address
4598 // (the table contains offsets to targets relative to its start).
4599 __ Daddu(TMP, TMP, AT);
4600 // And jump.
4601 __ Jr(TMP);
4602 __ Nop();
4603}
4604
4605void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
4606 int32_t lower_bound = switch_instr->GetStartValue();
4607 uint32_t num_entries = switch_instr->GetNumEntries();
4608 LocationSummary* locations = switch_instr->GetLocations();
4609 GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>();
4610 HBasicBlock* switch_block = switch_instr->GetBlock();
4611 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
4612
4613 if (num_entries > kPackedSwitchJumpTableThreshold) {
4614 GenTableBasedPackedSwitch(value_reg,
4615 lower_bound,
4616 num_entries,
4617 switch_block,
4618 default_block);
4619 } else {
4620 GenPackedSwitchWithCompares(value_reg,
4621 lower_bound,
4622 num_entries,
4623 switch_block,
4624 default_block);
4625 }
4626}
4627
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00004628void LocationsBuilderMIPS64::VisitClassTableGet(HClassTableGet*) {
4629 UNIMPLEMENTED(FATAL) << "ClassTableGet is unimplemented on mips64";
4630}
4631
4632void InstructionCodeGeneratorMIPS64::VisitClassTableGet(HClassTableGet*) {
4633 UNIMPLEMENTED(FATAL) << "ClassTableGet is unimplemented on mips64";
4634}
4635
Alexey Frunze4dda3372015-06-01 18:31:49 -07004636} // namespace mips64
4637} // namespace art