blob: abfaae4b500caaf1d8da1fb142bc08c55b1a655f [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 Frunze4dda3372015-06-01 18:31:49 -070021#include "entrypoints/quick/quick_entrypoints.h"
22#include "entrypoints/quick/quick_entrypoints_enum.h"
23#include "gc/accounting/card_table.h"
24#include "intrinsics.h"
Chris Larsen3039e382015-08-26 07:54:08 -070025#include "intrinsics_mips64.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070026#include "mirror/array-inl.h"
27#include "mirror/class-inl.h"
28#include "offsets.h"
29#include "thread.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070030#include "utils/assembler.h"
Alexey Frunzea0e87b02015-09-24 22:57:20 -070031#include "utils/mips64/assembler_mips64.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070032#include "utils/stack_checks.h"
33
34namespace art {
35namespace mips64 {
36
37static constexpr int kCurrentMethodStackOffset = 0;
38static constexpr GpuRegister kMethodRegisterArgument = A0;
39
40// We need extra temporary/scratch registers (in addition to AT) in some cases.
Alexey Frunze4dda3372015-06-01 18:31:49 -070041static constexpr FpuRegister FTMP = F8;
42
Alexey Frunze4dda3372015-06-01 18:31:49 -070043Location Mips64ReturnLocation(Primitive::Type return_type) {
44 switch (return_type) {
45 case Primitive::kPrimBoolean:
46 case Primitive::kPrimByte:
47 case Primitive::kPrimChar:
48 case Primitive::kPrimShort:
49 case Primitive::kPrimInt:
50 case Primitive::kPrimNot:
51 case Primitive::kPrimLong:
52 return Location::RegisterLocation(V0);
53
54 case Primitive::kPrimFloat:
55 case Primitive::kPrimDouble:
56 return Location::FpuRegisterLocation(F0);
57
58 case Primitive::kPrimVoid:
59 return Location();
60 }
61 UNREACHABLE();
62}
63
64Location InvokeDexCallingConventionVisitorMIPS64::GetReturnLocation(Primitive::Type type) const {
65 return Mips64ReturnLocation(type);
66}
67
68Location InvokeDexCallingConventionVisitorMIPS64::GetMethodLocation() const {
69 return Location::RegisterLocation(kMethodRegisterArgument);
70}
71
72Location InvokeDexCallingConventionVisitorMIPS64::GetNextLocation(Primitive::Type type) {
73 Location next_location;
74 if (type == Primitive::kPrimVoid) {
75 LOG(FATAL) << "Unexpected parameter type " << type;
76 }
77
78 if (Primitive::IsFloatingPointType(type) &&
79 (float_index_ < calling_convention.GetNumberOfFpuRegisters())) {
80 next_location = Location::FpuRegisterLocation(
81 calling_convention.GetFpuRegisterAt(float_index_++));
82 gp_index_++;
83 } else if (!Primitive::IsFloatingPointType(type) &&
84 (gp_index_ < calling_convention.GetNumberOfRegisters())) {
85 next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index_++));
86 float_index_++;
87 } else {
88 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
89 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
90 : Location::StackSlot(stack_offset);
91 }
92
93 // Space on the stack is reserved for all arguments.
94 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
95
96 // TODO: review
97
98 // TODO: shouldn't we use a whole machine word per argument on the stack?
99 // Implicit 4-byte method pointer (and such) will cause misalignment.
100
101 return next_location;
102}
103
104Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type type) {
105 return Mips64ReturnLocation(type);
106}
107
108#define __ down_cast<CodeGeneratorMIPS64*>(codegen)->GetAssembler()->
109#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, x).Int32Value()
110
111class BoundsCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
112 public:
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100113 explicit BoundsCheckSlowPathMIPS64(HBoundsCheck* instruction) : instruction_(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700114
115 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100116 LocationSummary* locations = instruction_->GetLocations();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700117 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
118 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000119 if (instruction_->CanThrowIntoCatchBlock()) {
120 // Live registers will be restored in the catch block if caught.
121 SaveLiveRegisters(codegen, instruction_->GetLocations());
122 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700123 // We're moving two locations to locations that could overlap, so we need a parallel
124 // move resolver.
125 InvokeRuntimeCallingConvention calling_convention;
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100126 codegen->EmitParallelMoves(locations->InAt(0),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700127 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
128 Primitive::kPrimInt,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100129 locations->InAt(1),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700130 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
131 Primitive::kPrimInt);
132 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds),
133 instruction_,
134 instruction_->GetDexPc(),
135 this);
136 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
137 }
138
Alexandre Rames8158f282015-08-07 10:26:17 +0100139 bool IsFatal() const OVERRIDE { return true; }
140
Roland Levillain46648892015-06-19 16:07:18 +0100141 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS64"; }
142
Alexey Frunze4dda3372015-06-01 18:31:49 -0700143 private:
144 HBoundsCheck* const instruction_;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700145
146 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS64);
147};
148
149class DivZeroCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
150 public:
151 explicit DivZeroCheckSlowPathMIPS64(HDivZeroCheck* instruction) : instruction_(instruction) {}
152
153 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
154 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
155 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000156 if (instruction_->CanThrowIntoCatchBlock()) {
157 // Live registers will be restored in the catch block if caught.
158 SaveLiveRegisters(codegen, instruction_->GetLocations());
159 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700160 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero),
161 instruction_,
162 instruction_->GetDexPc(),
163 this);
164 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
165 }
166
Alexandre Rames8158f282015-08-07 10:26:17 +0100167 bool IsFatal() const OVERRIDE { return true; }
168
Roland Levillain46648892015-06-19 16:07:18 +0100169 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS64"; }
170
Alexey Frunze4dda3372015-06-01 18:31:49 -0700171 private:
172 HDivZeroCheck* const instruction_;
173 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS64);
174};
175
176class LoadClassSlowPathMIPS64 : public SlowPathCodeMIPS64 {
177 public:
178 LoadClassSlowPathMIPS64(HLoadClass* cls,
179 HInstruction* at,
180 uint32_t dex_pc,
181 bool do_clinit)
182 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
183 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
184 }
185
186 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
187 LocationSummary* locations = at_->GetLocations();
188 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
189
190 __ Bind(GetEntryLabel());
191 SaveLiveRegisters(codegen, locations);
192
193 InvokeRuntimeCallingConvention calling_convention;
194 __ LoadConst32(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
195 int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
196 : QUICK_ENTRY_POINT(pInitializeType);
197 mips64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
198 if (do_clinit_) {
199 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
200 } else {
201 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
202 }
203
204 // Move the class to the desired location.
205 Location out = locations->Out();
206 if (out.IsValid()) {
207 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
208 Primitive::Type type = at_->GetType();
209 mips64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
210 }
211
212 RestoreLiveRegisters(codegen, locations);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700213 __ Bc(GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700214 }
215
Roland Levillain46648892015-06-19 16:07:18 +0100216 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS64"; }
217
Alexey Frunze4dda3372015-06-01 18:31:49 -0700218 private:
219 // The class this slow path will load.
220 HLoadClass* const cls_;
221
222 // The instruction where this slow path is happening.
223 // (Might be the load class or an initialization check).
224 HInstruction* const at_;
225
226 // The dex PC of `at_`.
227 const uint32_t dex_pc_;
228
229 // Whether to initialize the class.
230 const bool do_clinit_;
231
232 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS64);
233};
234
235class LoadStringSlowPathMIPS64 : public SlowPathCodeMIPS64 {
236 public:
237 explicit LoadStringSlowPathMIPS64(HLoadString* instruction) : instruction_(instruction) {}
238
239 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
240 LocationSummary* locations = instruction_->GetLocations();
241 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
242 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
243
244 __ Bind(GetEntryLabel());
245 SaveLiveRegisters(codegen, locations);
246
247 InvokeRuntimeCallingConvention calling_convention;
248 __ LoadConst32(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
249 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString),
250 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 Frunzea0e87b02015-09-24 22:57:20 -0700260 __ Bc(GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700261 }
262
Roland Levillain46648892015-06-19 16:07:18 +0100263 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS64"; }
264
Alexey Frunze4dda3372015-06-01 18:31:49 -0700265 private:
266 HLoadString* const instruction_;
267
268 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS64);
269};
270
271class NullCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
272 public:
273 explicit NullCheckSlowPathMIPS64(HNullCheck* instr) : instruction_(instr) {}
274
275 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
276 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
277 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000278 if (instruction_->CanThrowIntoCatchBlock()) {
279 // Live registers will be restored in the catch block if caught.
280 SaveLiveRegisters(codegen, instruction_->GetLocations());
281 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700282 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer),
283 instruction_,
284 instruction_->GetDexPc(),
285 this);
286 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
287 }
288
Alexandre Rames8158f282015-08-07 10:26:17 +0100289 bool IsFatal() const OVERRIDE { return true; }
290
Roland Levillain46648892015-06-19 16:07:18 +0100291 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS64"; }
292
Alexey Frunze4dda3372015-06-01 18:31:49 -0700293 private:
294 HNullCheck* const instruction_;
295
296 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS64);
297};
298
299class SuspendCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
300 public:
Roland Levillain3887c462015-08-12 18:15:42 +0100301 SuspendCheckSlowPathMIPS64(HSuspendCheck* instruction, HBasicBlock* successor)
Alexey Frunze4dda3372015-06-01 18:31:49 -0700302 : instruction_(instruction), successor_(successor) {}
303
304 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
305 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
306 __ Bind(GetEntryLabel());
307 SaveLiveRegisters(codegen, instruction_->GetLocations());
308 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend),
309 instruction_,
310 instruction_->GetDexPc(),
311 this);
312 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
313 RestoreLiveRegisters(codegen, instruction_->GetLocations());
314 if (successor_ == nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700315 __ Bc(GetReturnLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700316 } else {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700317 __ Bc(mips64_codegen->GetLabelOf(successor_));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700318 }
319 }
320
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700321 Mips64Label* GetReturnLabel() {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700322 DCHECK(successor_ == nullptr);
323 return &return_label_;
324 }
325
Roland Levillain46648892015-06-19 16:07:18 +0100326 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS64"; }
327
Alexey Frunze4dda3372015-06-01 18:31:49 -0700328 private:
329 HSuspendCheck* const instruction_;
330 // If not null, the block to branch to after the suspend check.
331 HBasicBlock* const successor_;
332
333 // If `successor_` is null, the label to branch to after the suspend check.
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700334 Mips64Label return_label_;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700335
336 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS64);
337};
338
339class TypeCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
340 public:
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100341 explicit TypeCheckSlowPathMIPS64(HInstruction* instruction) : instruction_(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700342
343 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
344 LocationSummary* locations = instruction_->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200345 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) : locations->Out();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100346 uint32_t dex_pc = instruction_->GetDexPc();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700347 DCHECK(instruction_->IsCheckCast()
348 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
349 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
350
351 __ Bind(GetEntryLabel());
352 SaveLiveRegisters(codegen, locations);
353
354 // We're moving two locations to locations that could overlap, so we need a parallel
355 // move resolver.
356 InvokeRuntimeCallingConvention calling_convention;
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100357 codegen->EmitParallelMoves(locations->InAt(1),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700358 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
359 Primitive::kPrimNot,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100360 object_class,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700361 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
362 Primitive::kPrimNot);
363
364 if (instruction_->IsInstanceOf()) {
365 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
366 instruction_,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100367 dex_pc,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700368 this);
Roland Levillain888d0672015-11-23 18:53:50 +0000369 CheckEntrypointTypes<
370 kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700371 Primitive::Type ret_type = instruction_->GetType();
372 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
373 mips64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700374 } else {
375 DCHECK(instruction_->IsCheckCast());
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100376 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc, this);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700377 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
378 }
379
380 RestoreLiveRegisters(codegen, locations);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700381 __ Bc(GetExitLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700382 }
383
Roland Levillain46648892015-06-19 16:07:18 +0100384 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS64"; }
385
Alexey Frunze4dda3372015-06-01 18:31:49 -0700386 private:
387 HInstruction* const instruction_;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700388
389 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS64);
390};
391
392class DeoptimizationSlowPathMIPS64 : public SlowPathCodeMIPS64 {
393 public:
Aart Bik42249c32016-01-07 15:33:50 -0800394 explicit DeoptimizationSlowPathMIPS64(HDeoptimize* instruction)
Alexey Frunze4dda3372015-06-01 18:31:49 -0700395 : instruction_(instruction) {}
396
397 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800398 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700399 __ Bind(GetEntryLabel());
400 SaveLiveRegisters(codegen, instruction_->GetLocations());
Aart Bik42249c32016-01-07 15:33:50 -0800401 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize),
402 instruction_,
403 instruction_->GetDexPc(),
404 this);
Roland Levillain888d0672015-11-23 18:53:50 +0000405 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700406 }
407
Roland Levillain46648892015-06-19 16:07:18 +0100408 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS64"; }
409
Alexey Frunze4dda3372015-06-01 18:31:49 -0700410 private:
Aart Bik42249c32016-01-07 15:33:50 -0800411 HDeoptimize* const instruction_;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700412 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64);
413};
414
415CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph,
416 const Mips64InstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100417 const CompilerOptions& compiler_options,
418 OptimizingCompilerStats* stats)
Alexey Frunze4dda3372015-06-01 18:31:49 -0700419 : CodeGenerator(graph,
420 kNumberOfGpuRegisters,
421 kNumberOfFpuRegisters,
Roland Levillain0d5a2812015-11-13 10:07:31 +0000422 /* number_of_register_pairs */ 0,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700423 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
424 arraysize(kCoreCalleeSaves)),
425 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
426 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +0100427 compiler_options,
428 stats),
Vladimir Marko225b6462015-09-28 12:17:40 +0100429 block_labels_(nullptr),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700430 location_builder_(graph, this),
431 instruction_visitor_(graph, this),
432 move_resolver_(graph->GetArena(), this),
433 isa_features_(isa_features) {
434 // Save RA (containing the return address) to mimic Quick.
435 AddAllocatedRegister(Location::RegisterLocation(RA));
436}
437
438#undef __
439#define __ down_cast<Mips64Assembler*>(GetAssembler())->
440#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, x).Int32Value()
441
442void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700443 // Ensure that we fix up branches.
444 __ FinalizeCode();
445
446 // Adjust native pc offsets in stack maps.
447 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
448 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
449 uint32_t new_position = __ GetAdjustedPosition(old_position);
450 DCHECK_GE(new_position, old_position);
451 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
452 }
453
454 // Adjust pc offsets for the disassembly information.
455 if (disasm_info_ != nullptr) {
456 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
457 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
458 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
459 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
460 it.second.start = __ GetAdjustedPosition(it.second.start);
461 it.second.end = __ GetAdjustedPosition(it.second.end);
462 }
463 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
464 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
465 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
466 }
467 }
468
Alexey Frunze4dda3372015-06-01 18:31:49 -0700469 CodeGenerator::Finalize(allocator);
470}
471
472Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const {
473 return codegen_->GetAssembler();
474}
475
476void ParallelMoveResolverMIPS64::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +0100477 MoveOperands* move = moves_[index];
Alexey Frunze4dda3372015-06-01 18:31:49 -0700478 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
479}
480
481void ParallelMoveResolverMIPS64::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +0100482 MoveOperands* move = moves_[index];
Alexey Frunze4dda3372015-06-01 18:31:49 -0700483 codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType());
484}
485
486void ParallelMoveResolverMIPS64::RestoreScratch(int reg) {
487 // Pop reg
488 __ Ld(GpuRegister(reg), SP, 0);
489 __ DecreaseFrameSize(kMips64WordSize);
490}
491
492void ParallelMoveResolverMIPS64::SpillScratch(int reg) {
493 // Push reg
494 __ IncreaseFrameSize(kMips64WordSize);
495 __ Sd(GpuRegister(reg), SP, 0);
496}
497
498void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) {
499 LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord;
500 StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord;
501 // Allocate a scratch register other than TMP, if available.
502 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
503 // automatically unspilled when the scratch scope object is destroyed).
504 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
505 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
506 int stack_offset = ensure_scratch.IsSpilled() ? kMips64WordSize : 0;
507 __ LoadFromOffset(load_type,
508 GpuRegister(ensure_scratch.GetRegister()),
509 SP,
510 index1 + stack_offset);
511 __ LoadFromOffset(load_type,
512 TMP,
513 SP,
514 index2 + stack_offset);
515 __ StoreToOffset(store_type,
516 GpuRegister(ensure_scratch.GetRegister()),
517 SP,
518 index2 + stack_offset);
519 __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset);
520}
521
522static dwarf::Reg DWARFReg(GpuRegister reg) {
523 return dwarf::Reg::Mips64Core(static_cast<int>(reg));
524}
525
526// TODO: mapping of floating-point registers to DWARF
527
528void CodeGeneratorMIPS64::GenerateFrameEntry() {
529 __ Bind(&frame_entry_label_);
530
531 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips64) || !IsLeafMethod();
532
533 if (do_overflow_check) {
534 __ LoadFromOffset(kLoadWord,
535 ZERO,
536 SP,
537 -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips64)));
538 RecordPcInfo(nullptr, 0);
539 }
540
541 // TODO: anything related to T9/GP/GOT/PIC/.so's?
542
543 if (HasEmptyFrame()) {
544 return;
545 }
546
547 // Make sure the frame size isn't unreasonably large. Per the various APIs
548 // it looks like it should always be less than 2GB in size, which allows
549 // us using 32-bit signed offsets from the stack pointer.
550 if (GetFrameSize() > 0x7FFFFFFF)
551 LOG(FATAL) << "Stack frame larger than 2GB";
552
553 // Spill callee-saved registers.
554 // Note that their cumulative size is small and they can be indexed using
555 // 16-bit offsets.
556
557 // TODO: increment/decrement SP in one step instead of two or remove this comment.
558
559 uint32_t ofs = FrameEntrySpillSize();
560 __ IncreaseFrameSize(ofs);
561
562 for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) {
563 GpuRegister reg = kCoreCalleeSaves[i];
564 if (allocated_registers_.ContainsCoreRegister(reg)) {
565 ofs -= kMips64WordSize;
566 __ Sd(reg, SP, ofs);
567 __ cfi().RelOffset(DWARFReg(reg), ofs);
568 }
569 }
570
571 for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) {
572 FpuRegister reg = kFpuCalleeSaves[i];
573 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
574 ofs -= kMips64WordSize;
575 __ Sdc1(reg, SP, ofs);
576 // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs);
577 }
578 }
579
580 // Allocate the rest of the frame and store the current method pointer
581 // at its end.
582
583 __ IncreaseFrameSize(GetFrameSize() - FrameEntrySpillSize());
584
585 static_assert(IsInt<16>(kCurrentMethodStackOffset),
586 "kCurrentMethodStackOffset must fit into int16_t");
587 __ Sd(kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
588}
589
590void CodeGeneratorMIPS64::GenerateFrameExit() {
591 __ cfi().RememberState();
592
593 // TODO: anything related to T9/GP/GOT/PIC/.so's?
594
595 if (!HasEmptyFrame()) {
596 // Deallocate the rest of the frame.
597
598 __ DecreaseFrameSize(GetFrameSize() - FrameEntrySpillSize());
599
600 // Restore callee-saved registers.
601 // Note that their cumulative size is small and they can be indexed using
602 // 16-bit offsets.
603
604 // TODO: increment/decrement SP in one step instead of two or remove this comment.
605
606 uint32_t ofs = 0;
607
608 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
609 FpuRegister reg = kFpuCalleeSaves[i];
610 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
611 __ Ldc1(reg, SP, ofs);
612 ofs += kMips64WordSize;
613 // TODO: __ cfi().Restore(DWARFReg(reg));
614 }
615 }
616
617 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
618 GpuRegister reg = kCoreCalleeSaves[i];
619 if (allocated_registers_.ContainsCoreRegister(reg)) {
620 __ Ld(reg, SP, ofs);
621 ofs += kMips64WordSize;
622 __ cfi().Restore(DWARFReg(reg));
623 }
624 }
625
626 DCHECK_EQ(ofs, FrameEntrySpillSize());
627 __ DecreaseFrameSize(ofs);
628 }
629
630 __ Jr(RA);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700631 __ Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700632
633 __ cfi().RestoreState();
634 __ cfi().DefCFAOffset(GetFrameSize());
635}
636
637void CodeGeneratorMIPS64::Bind(HBasicBlock* block) {
638 __ Bind(GetLabelOf(block));
639}
640
641void CodeGeneratorMIPS64::MoveLocation(Location destination,
642 Location source,
Calin Juravlee460d1d2015-09-29 04:52:17 +0100643 Primitive::Type dst_type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700644 if (source.Equals(destination)) {
645 return;
646 }
647
648 // A valid move can always be inferred from the destination and source
649 // locations. When moving from and to a register, the argument type can be
650 // used to generate 32bit instead of 64bit moves.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100651 bool unspecified_type = (dst_type == Primitive::kPrimVoid);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700652 DCHECK_EQ(unspecified_type, false);
653
654 if (destination.IsRegister() || destination.IsFpuRegister()) {
655 if (unspecified_type) {
656 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
657 if (source.IsStackSlot() ||
658 (src_cst != nullptr && (src_cst->IsIntConstant()
659 || src_cst->IsFloatConstant()
660 || src_cst->IsNullConstant()))) {
661 // For stack slots and 32bit constants, a 64bit type is appropriate.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100662 dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700663 } else {
664 // If the source is a double stack slot or a 64bit constant, a 64bit
665 // type is appropriate. Else the source is a register, and since the
666 // type has not been specified, we chose a 64bit type to force a 64bit
667 // move.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100668 dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700669 }
670 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100671 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) ||
672 (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type)));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700673 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
674 // Move to GPR/FPR from stack
675 LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword;
Calin Juravlee460d1d2015-09-29 04:52:17 +0100676 if (Primitive::IsFloatingPointType(dst_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700677 __ LoadFpuFromOffset(load_type,
678 destination.AsFpuRegister<FpuRegister>(),
679 SP,
680 source.GetStackIndex());
681 } else {
682 // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot.
683 __ LoadFromOffset(load_type,
684 destination.AsRegister<GpuRegister>(),
685 SP,
686 source.GetStackIndex());
687 }
688 } else if (source.IsConstant()) {
689 // Move to GPR/FPR from constant
690 GpuRegister gpr = AT;
Calin Juravlee460d1d2015-09-29 04:52:17 +0100691 if (!Primitive::IsFloatingPointType(dst_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700692 gpr = destination.AsRegister<GpuRegister>();
693 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100694 if (dst_type == Primitive::kPrimInt || dst_type == Primitive::kPrimFloat) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700695 int32_t value = GetInt32ValueOf(source.GetConstant()->AsConstant());
696 if (Primitive::IsFloatingPointType(dst_type) && value == 0) {
697 gpr = ZERO;
698 } else {
699 __ LoadConst32(gpr, value);
700 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700701 } else {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700702 int64_t value = GetInt64ValueOf(source.GetConstant()->AsConstant());
703 if (Primitive::IsFloatingPointType(dst_type) && value == 0) {
704 gpr = ZERO;
705 } else {
706 __ LoadConst64(gpr, value);
707 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700708 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100709 if (dst_type == Primitive::kPrimFloat) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700710 __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>());
Calin Juravlee460d1d2015-09-29 04:52:17 +0100711 } else if (dst_type == Primitive::kPrimDouble) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700712 __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>());
713 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100714 } else if (source.IsRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700715 if (destination.IsRegister()) {
716 // Move to GPR from GPR
717 __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>());
718 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100719 DCHECK(destination.IsFpuRegister());
720 if (Primitive::Is64BitType(dst_type)) {
721 __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>());
722 } else {
723 __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>());
724 }
725 }
726 } else if (source.IsFpuRegister()) {
727 if (destination.IsFpuRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700728 // Move to FPR from FPR
Calin Juravlee460d1d2015-09-29 04:52:17 +0100729 if (dst_type == Primitive::kPrimFloat) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700730 __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
731 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100732 DCHECK_EQ(dst_type, Primitive::kPrimDouble);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700733 __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
734 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100735 } else {
736 DCHECK(destination.IsRegister());
737 if (Primitive::Is64BitType(dst_type)) {
738 __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>());
739 } else {
740 __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>());
741 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700742 }
743 }
744 } else { // The destination is not a register. It must be a stack slot.
745 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
746 if (source.IsRegister() || source.IsFpuRegister()) {
747 if (unspecified_type) {
748 if (source.IsRegister()) {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100749 dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700750 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100751 dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700752 }
753 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100754 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) &&
755 (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type)));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700756 // Move to stack from GPR/FPR
757 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
758 if (source.IsRegister()) {
759 __ StoreToOffset(store_type,
760 source.AsRegister<GpuRegister>(),
761 SP,
762 destination.GetStackIndex());
763 } else {
764 __ StoreFpuToOffset(store_type,
765 source.AsFpuRegister<FpuRegister>(),
766 SP,
767 destination.GetStackIndex());
768 }
769 } else if (source.IsConstant()) {
770 // Move to stack from constant
771 HConstant* src_cst = source.GetConstant();
772 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700773 GpuRegister gpr = ZERO;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700774 if (destination.IsStackSlot()) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700775 int32_t value = GetInt32ValueOf(src_cst->AsConstant());
776 if (value != 0) {
777 gpr = TMP;
778 __ LoadConst32(gpr, value);
779 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700780 } else {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700781 DCHECK(destination.IsDoubleStackSlot());
782 int64_t value = GetInt64ValueOf(src_cst->AsConstant());
783 if (value != 0) {
784 gpr = TMP;
785 __ LoadConst64(gpr, value);
786 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700787 }
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700788 __ StoreToOffset(store_type, gpr, SP, destination.GetStackIndex());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700789 } else {
790 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
791 DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot());
792 // Move to stack from stack
793 if (destination.IsStackSlot()) {
794 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
795 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
796 } else {
797 __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex());
798 __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex());
799 }
800 }
801 }
802}
803
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700804void CodeGeneratorMIPS64::SwapLocations(Location loc1, Location loc2, Primitive::Type type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700805 DCHECK(!loc1.IsConstant());
806 DCHECK(!loc2.IsConstant());
807
808 if (loc1.Equals(loc2)) {
809 return;
810 }
811
812 bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot();
813 bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot();
814 bool is_fp_reg1 = loc1.IsFpuRegister();
815 bool is_fp_reg2 = loc2.IsFpuRegister();
816
817 if (loc2.IsRegister() && loc1.IsRegister()) {
818 // Swap 2 GPRs
819 GpuRegister r1 = loc1.AsRegister<GpuRegister>();
820 GpuRegister r2 = loc2.AsRegister<GpuRegister>();
821 __ Move(TMP, r2);
822 __ Move(r2, r1);
823 __ Move(r1, TMP);
824 } else if (is_fp_reg2 && is_fp_reg1) {
825 // Swap 2 FPRs
826 FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>();
827 FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>();
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700828 if (type == Primitive::kPrimFloat) {
829 __ MovS(FTMP, r1);
830 __ MovS(r1, r2);
831 __ MovS(r2, FTMP);
832 } else {
833 DCHECK_EQ(type, Primitive::kPrimDouble);
834 __ MovD(FTMP, r1);
835 __ MovD(r1, r2);
836 __ MovD(r2, FTMP);
837 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700838 } else if (is_slot1 != is_slot2) {
839 // Swap GPR/FPR and stack slot
840 Location reg_loc = is_slot1 ? loc2 : loc1;
841 Location mem_loc = is_slot1 ? loc1 : loc2;
842 LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword;
843 StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword;
844 // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot.
845 __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex());
846 if (reg_loc.IsFpuRegister()) {
847 __ StoreFpuToOffset(store_type,
848 reg_loc.AsFpuRegister<FpuRegister>(),
849 SP,
850 mem_loc.GetStackIndex());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700851 if (mem_loc.IsStackSlot()) {
852 __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
853 } else {
854 DCHECK(mem_loc.IsDoubleStackSlot());
855 __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
856 }
857 } else {
858 __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex());
859 __ Move(reg_loc.AsRegister<GpuRegister>(), TMP);
860 }
861 } else if (is_slot1 && is_slot2) {
862 move_resolver_.Exchange(loc1.GetStackIndex(),
863 loc2.GetStackIndex(),
864 loc1.IsDoubleStackSlot());
865 } else {
866 LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2;
867 }
868}
869
870void CodeGeneratorMIPS64::Move(HInstruction* instruction,
871 Location location,
872 HInstruction* move_for) {
873 LocationSummary* locations = instruction->GetLocations();
874 Primitive::Type type = instruction->GetType();
875 DCHECK_NE(type, Primitive::kPrimVoid);
876
877 if (instruction->IsCurrentMethod()) {
878 MoveLocation(location, Location::DoubleStackSlot(kCurrentMethodStackOffset), type);
879 } else if (locations != nullptr && locations->Out().Equals(location)) {
880 return;
881 } else if (instruction->IsIntConstant()
882 || instruction->IsLongConstant()
883 || instruction->IsNullConstant()) {
884 if (location.IsRegister()) {
885 // Move to GPR from constant
886 GpuRegister dst = location.AsRegister<GpuRegister>();
887 if (instruction->IsNullConstant() || instruction->IsIntConstant()) {
888 __ LoadConst32(dst, GetInt32ValueOf(instruction->AsConstant()));
889 } else {
890 __ LoadConst64(dst, instruction->AsLongConstant()->GetValue());
891 }
892 } else {
893 DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot());
894 // Move to stack from constant
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700895 GpuRegister gpr = ZERO;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700896 if (location.IsStackSlot()) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700897 int32_t value = GetInt32ValueOf(instruction->AsConstant());
898 if (value != 0) {
899 gpr = TMP;
900 __ LoadConst32(gpr, value);
901 }
902 __ StoreToOffset(kStoreWord, gpr, SP, location.GetStackIndex());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700903 } else {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700904 DCHECK(location.IsDoubleStackSlot());
905 int64_t value = instruction->AsLongConstant()->GetValue();
906 if (value != 0) {
907 gpr = TMP;
908 __ LoadConst64(gpr, value);
909 }
910 __ StoreToOffset(kStoreDoubleword, gpr, SP, location.GetStackIndex());
Alexey Frunze4dda3372015-06-01 18:31:49 -0700911 }
912 }
913 } else if (instruction->IsTemporary()) {
914 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
915 MoveLocation(location, temp_location, type);
916 } else if (instruction->IsLoadLocal()) {
917 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
918 if (Primitive::Is64BitType(type)) {
919 MoveLocation(location, Location::DoubleStackSlot(stack_slot), type);
920 } else {
921 MoveLocation(location, Location::StackSlot(stack_slot), type);
922 }
923 } else {
924 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
925 MoveLocation(location, locations->Out(), type);
926 }
927}
928
Calin Juravle175dc732015-08-25 15:42:32 +0100929void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) {
930 DCHECK(location.IsRegister());
931 __ LoadConst32(location.AsRegister<GpuRegister>(), value);
932}
933
Calin Juravlee460d1d2015-09-29 04:52:17 +0100934void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) {
935 if (location.IsRegister()) {
936 locations->AddTemp(location);
937 } else {
938 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
939 }
940}
941
Alexey Frunze4dda3372015-06-01 18:31:49 -0700942Location CodeGeneratorMIPS64::GetStackLocation(HLoadLocal* load) const {
943 Primitive::Type type = load->GetType();
944
945 switch (type) {
946 case Primitive::kPrimNot:
947 case Primitive::kPrimInt:
948 case Primitive::kPrimFloat:
949 return Location::StackSlot(GetStackSlot(load->GetLocal()));
950
951 case Primitive::kPrimLong:
952 case Primitive::kPrimDouble:
953 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
954
955 case Primitive::kPrimBoolean:
956 case Primitive::kPrimByte:
957 case Primitive::kPrimChar:
958 case Primitive::kPrimShort:
959 case Primitive::kPrimVoid:
960 LOG(FATAL) << "Unexpected type " << type;
961 }
962
963 LOG(FATAL) << "Unreachable";
964 return Location::NoLocation();
965}
966
967void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object, GpuRegister value) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700968 Mips64Label done;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700969 GpuRegister card = AT;
970 GpuRegister temp = TMP;
971 __ Beqzc(value, &done);
972 __ LoadFromOffset(kLoadDoubleword,
973 card,
974 TR,
975 Thread::CardTableOffset<kMips64WordSize>().Int32Value());
976 __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift);
977 __ Daddu(temp, card, temp);
978 __ Sb(card, temp, 0);
979 __ Bind(&done);
980}
981
982void CodeGeneratorMIPS64::SetupBlockedRegisters(bool is_baseline ATTRIBUTE_UNUSED) const {
983 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
984 blocked_core_registers_[ZERO] = true;
985 blocked_core_registers_[K0] = true;
986 blocked_core_registers_[K1] = true;
987 blocked_core_registers_[GP] = true;
988 blocked_core_registers_[SP] = true;
989 blocked_core_registers_[RA] = true;
990
991 // AT and TMP(T8) are used as temporary/scratch registers
992 // (similar to how AT is used by MIPS assemblers).
993 blocked_core_registers_[AT] = true;
994 blocked_core_registers_[TMP] = true;
995 blocked_fpu_registers_[FTMP] = true;
996
997 // Reserve suspend and thread registers.
998 blocked_core_registers_[S0] = true;
999 blocked_core_registers_[TR] = true;
1000
1001 // Reserve T9 for function calls
1002 blocked_core_registers_[T9] = true;
1003
1004 // TODO: review; anything else?
1005
1006 // TODO: make these two for's conditional on is_baseline once
1007 // all the issues with register saving/restoring are sorted out.
1008 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
1009 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
1010 }
1011
1012 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1013 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1014 }
1015}
1016
1017Location CodeGeneratorMIPS64::AllocateFreeRegister(Primitive::Type type) const {
1018 if (type == Primitive::kPrimVoid) {
1019 LOG(FATAL) << "Unreachable type " << type;
1020 }
1021
1022 if (Primitive::IsFloatingPointType(type)) {
1023 size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFpuRegisters);
1024 return Location::FpuRegisterLocation(reg);
1025 } else {
1026 size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfGpuRegisters);
1027 return Location::RegisterLocation(reg);
1028 }
1029}
1030
1031size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1032 __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index);
1033 return kMips64WordSize;
1034}
1035
1036size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1037 __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index);
1038 return kMips64WordSize;
1039}
1040
1041size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1042 __ StoreFpuToOffset(kStoreDoubleword, FpuRegister(reg_id), SP, stack_index);
1043 return kMips64WordSize;
1044}
1045
1046size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1047 __ LoadFpuFromOffset(kLoadDoubleword, FpuRegister(reg_id), SP, stack_index);
1048 return kMips64WordSize;
1049}
1050
1051void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdil9f0dece2015-09-21 18:20:26 +01001052 stream << GpuRegister(reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001053}
1054
1055void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdil9f0dece2015-09-21 18:20:26 +01001056 stream << FpuRegister(reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001057}
1058
Calin Juravle175dc732015-08-25 15:42:32 +01001059void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint,
1060 HInstruction* instruction,
1061 uint32_t dex_pc,
1062 SlowPathCode* slow_path) {
1063 InvokeRuntime(GetThreadOffset<kMips64WordSize>(entrypoint).Int32Value(),
1064 instruction,
1065 dex_pc,
1066 slow_path);
1067}
1068
Alexey Frunze4dda3372015-06-01 18:31:49 -07001069void CodeGeneratorMIPS64::InvokeRuntime(int32_t entry_point_offset,
1070 HInstruction* instruction,
1071 uint32_t dex_pc,
1072 SlowPathCode* slow_path) {
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001073 ValidateInvokeRuntime(instruction, slow_path);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001074 // TODO: anything related to T9/GP/GOT/PIC/.so's?
1075 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
1076 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001077 __ Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001078 RecordPcInfo(instruction, dex_pc, slow_path);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001079}
1080
1081void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path,
1082 GpuRegister class_reg) {
1083 __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
1084 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
1085 __ Bltc(TMP, AT, slow_path->GetEntryLabel());
1086 // TODO: barrier needed?
1087 __ Bind(slow_path->GetExitLabel());
1088}
1089
1090void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1091 __ Sync(0); // only stype 0 is supported
1092}
1093
1094void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction,
1095 HBasicBlock* successor) {
1096 SuspendCheckSlowPathMIPS64* slow_path =
1097 new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS64(instruction, successor);
1098 codegen_->AddSlowPath(slow_path);
1099
1100 __ LoadFromOffset(kLoadUnsignedHalfword,
1101 TMP,
1102 TR,
1103 Thread::ThreadFlagsOffset<kMips64WordSize>().Int32Value());
1104 if (successor == nullptr) {
1105 __ Bnezc(TMP, slow_path->GetEntryLabel());
1106 __ Bind(slow_path->GetReturnLabel());
1107 } else {
1108 __ Beqzc(TMP, codegen_->GetLabelOf(successor));
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001109 __ Bc(slow_path->GetEntryLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001110 // slow_path will return to GetLabelOf(successor).
1111 }
1112}
1113
1114InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph,
1115 CodeGeneratorMIPS64* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001116 : InstructionCodeGenerator(graph, codegen),
Alexey Frunze4dda3372015-06-01 18:31:49 -07001117 assembler_(codegen->GetAssembler()),
1118 codegen_(codegen) {}
1119
1120void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
1121 DCHECK_EQ(instruction->InputCount(), 2U);
1122 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1123 Primitive::Type type = instruction->GetResultType();
1124 switch (type) {
1125 case Primitive::kPrimInt:
1126 case Primitive::kPrimLong: {
1127 locations->SetInAt(0, Location::RequiresRegister());
1128 HInstruction* right = instruction->InputAt(1);
1129 bool can_use_imm = false;
1130 if (right->IsConstant()) {
1131 int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant());
1132 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1133 can_use_imm = IsUint<16>(imm);
1134 } else if (instruction->IsAdd()) {
1135 can_use_imm = IsInt<16>(imm);
1136 } else {
1137 DCHECK(instruction->IsSub());
1138 can_use_imm = IsInt<16>(-imm);
1139 }
1140 }
1141 if (can_use_imm)
1142 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1143 else
1144 locations->SetInAt(1, Location::RequiresRegister());
1145 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1146 }
1147 break;
1148
1149 case Primitive::kPrimFloat:
1150 case Primitive::kPrimDouble:
1151 locations->SetInAt(0, Location::RequiresFpuRegister());
1152 locations->SetInAt(1, Location::RequiresFpuRegister());
1153 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1154 break;
1155
1156 default:
1157 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1158 }
1159}
1160
1161void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
1162 Primitive::Type type = instruction->GetType();
1163 LocationSummary* locations = instruction->GetLocations();
1164
1165 switch (type) {
1166 case Primitive::kPrimInt:
1167 case Primitive::kPrimLong: {
1168 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1169 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1170 Location rhs_location = locations->InAt(1);
1171
1172 GpuRegister rhs_reg = ZERO;
1173 int64_t rhs_imm = 0;
1174 bool use_imm = rhs_location.IsConstant();
1175 if (use_imm) {
1176 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
1177 } else {
1178 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1179 }
1180
1181 if (instruction->IsAnd()) {
1182 if (use_imm)
1183 __ Andi(dst, lhs, rhs_imm);
1184 else
1185 __ And(dst, lhs, rhs_reg);
1186 } else if (instruction->IsOr()) {
1187 if (use_imm)
1188 __ Ori(dst, lhs, rhs_imm);
1189 else
1190 __ Or(dst, lhs, rhs_reg);
1191 } else if (instruction->IsXor()) {
1192 if (use_imm)
1193 __ Xori(dst, lhs, rhs_imm);
1194 else
1195 __ Xor(dst, lhs, rhs_reg);
1196 } else if (instruction->IsAdd()) {
1197 if (type == Primitive::kPrimInt) {
1198 if (use_imm)
1199 __ Addiu(dst, lhs, rhs_imm);
1200 else
1201 __ Addu(dst, lhs, rhs_reg);
1202 } else {
1203 if (use_imm)
1204 __ Daddiu(dst, lhs, rhs_imm);
1205 else
1206 __ Daddu(dst, lhs, rhs_reg);
1207 }
1208 } else {
1209 DCHECK(instruction->IsSub());
1210 if (type == Primitive::kPrimInt) {
1211 if (use_imm)
1212 __ Addiu(dst, lhs, -rhs_imm);
1213 else
1214 __ Subu(dst, lhs, rhs_reg);
1215 } else {
1216 if (use_imm)
1217 __ Daddiu(dst, lhs, -rhs_imm);
1218 else
1219 __ Dsubu(dst, lhs, rhs_reg);
1220 }
1221 }
1222 break;
1223 }
1224 case Primitive::kPrimFloat:
1225 case Primitive::kPrimDouble: {
1226 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
1227 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1228 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1229 if (instruction->IsAdd()) {
1230 if (type == Primitive::kPrimFloat)
1231 __ AddS(dst, lhs, rhs);
1232 else
1233 __ AddD(dst, lhs, rhs);
1234 } else if (instruction->IsSub()) {
1235 if (type == Primitive::kPrimFloat)
1236 __ SubS(dst, lhs, rhs);
1237 else
1238 __ SubD(dst, lhs, rhs);
1239 } else {
1240 LOG(FATAL) << "Unexpected floating-point binary operation";
1241 }
1242 break;
1243 }
1244 default:
1245 LOG(FATAL) << "Unexpected binary operation type " << type;
1246 }
1247}
1248
1249void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001250 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001251
1252 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1253 Primitive::Type type = instr->GetResultType();
1254 switch (type) {
1255 case Primitive::kPrimInt:
1256 case Primitive::kPrimLong: {
1257 locations->SetInAt(0, Location::RequiresRegister());
1258 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001259 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001260 break;
1261 }
1262 default:
1263 LOG(FATAL) << "Unexpected shift type " << type;
1264 }
1265}
1266
1267void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001268 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001269 LocationSummary* locations = instr->GetLocations();
1270 Primitive::Type type = instr->GetType();
1271
1272 switch (type) {
1273 case Primitive::kPrimInt:
1274 case Primitive::kPrimLong: {
1275 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1276 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1277 Location rhs_location = locations->InAt(1);
1278
1279 GpuRegister rhs_reg = ZERO;
1280 int64_t rhs_imm = 0;
1281 bool use_imm = rhs_location.IsConstant();
1282 if (use_imm) {
1283 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
1284 } else {
1285 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1286 }
1287
1288 if (use_imm) {
1289 uint32_t shift_value = (type == Primitive::kPrimInt)
1290 ? static_cast<uint32_t>(rhs_imm & kMaxIntShiftValue)
1291 : static_cast<uint32_t>(rhs_imm & kMaxLongShiftValue);
1292
Alexey Frunze92d90602015-12-18 18:16:36 -08001293 if (shift_value == 0) {
1294 if (dst != lhs) {
1295 __ Move(dst, lhs);
1296 }
1297 } else if (type == Primitive::kPrimInt) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001298 if (instr->IsShl()) {
1299 __ Sll(dst, lhs, shift_value);
1300 } else if (instr->IsShr()) {
1301 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001302 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001303 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001304 } else {
1305 __ Rotr(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001306 }
1307 } else {
1308 if (shift_value < 32) {
1309 if (instr->IsShl()) {
1310 __ Dsll(dst, lhs, shift_value);
1311 } else if (instr->IsShr()) {
1312 __ Dsra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001313 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001314 __ Dsrl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001315 } else {
1316 __ Drotr(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001317 }
1318 } else {
1319 shift_value -= 32;
1320 if (instr->IsShl()) {
1321 __ Dsll32(dst, lhs, shift_value);
1322 } else if (instr->IsShr()) {
1323 __ Dsra32(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001324 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001325 __ Dsrl32(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001326 } else {
1327 __ Drotr32(dst, lhs, shift_value);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001328 }
1329 }
1330 }
1331 } else {
1332 if (type == Primitive::kPrimInt) {
1333 if (instr->IsShl()) {
1334 __ Sllv(dst, lhs, rhs_reg);
1335 } else if (instr->IsShr()) {
1336 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001337 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001338 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001339 } else {
1340 __ Rotrv(dst, lhs, rhs_reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001341 }
1342 } else {
1343 if (instr->IsShl()) {
1344 __ Dsllv(dst, lhs, rhs_reg);
1345 } else if (instr->IsShr()) {
1346 __ Dsrav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001347 } else if (instr->IsUShr()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001348 __ Dsrlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001349 } else {
1350 __ Drotrv(dst, lhs, rhs_reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001351 }
1352 }
1353 }
1354 break;
1355 }
1356 default:
1357 LOG(FATAL) << "Unexpected shift operation type " << type;
1358 }
1359}
1360
1361void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) {
1362 HandleBinaryOp(instruction);
1363}
1364
1365void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) {
1366 HandleBinaryOp(instruction);
1367}
1368
1369void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) {
1370 HandleBinaryOp(instruction);
1371}
1372
1373void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) {
1374 HandleBinaryOp(instruction);
1375}
1376
1377void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) {
1378 LocationSummary* locations =
1379 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1380 locations->SetInAt(0, Location::RequiresRegister());
1381 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1382 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1383 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1384 } else {
1385 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1386 }
1387}
1388
1389void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) {
1390 LocationSummary* locations = instruction->GetLocations();
1391 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1392 Location index = locations->InAt(1);
1393 Primitive::Type type = instruction->GetType();
1394
1395 switch (type) {
1396 case Primitive::kPrimBoolean: {
1397 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1398 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1399 if (index.IsConstant()) {
1400 size_t offset =
1401 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1402 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1403 } else {
1404 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1405 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset);
1406 }
1407 break;
1408 }
1409
1410 case Primitive::kPrimByte: {
1411 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
1412 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1413 if (index.IsConstant()) {
1414 size_t offset =
1415 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1416 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1417 } else {
1418 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1419 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset);
1420 }
1421 break;
1422 }
1423
1424 case Primitive::kPrimShort: {
1425 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
1426 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1427 if (index.IsConstant()) {
1428 size_t offset =
1429 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1430 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1431 } else {
1432 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1433 __ Daddu(TMP, obj, TMP);
1434 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset);
1435 }
1436 break;
1437 }
1438
1439 case Primitive::kPrimChar: {
1440 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
1441 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1442 if (index.IsConstant()) {
1443 size_t offset =
1444 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1445 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1446 } else {
1447 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1448 __ Daddu(TMP, obj, TMP);
1449 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset);
1450 }
1451 break;
1452 }
1453
1454 case Primitive::kPrimInt:
1455 case Primitive::kPrimNot: {
1456 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1457 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
1458 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1459 LoadOperandType load_type = (type == Primitive::kPrimNot) ? kLoadUnsignedWord : kLoadWord;
1460 if (index.IsConstant()) {
1461 size_t offset =
1462 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1463 __ LoadFromOffset(load_type, out, obj, offset);
1464 } else {
1465 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1466 __ Daddu(TMP, obj, TMP);
1467 __ LoadFromOffset(load_type, out, TMP, data_offset);
1468 }
1469 break;
1470 }
1471
1472 case Primitive::kPrimLong: {
1473 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
1474 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1475 if (index.IsConstant()) {
1476 size_t offset =
1477 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1478 __ LoadFromOffset(kLoadDoubleword, out, obj, offset);
1479 } else {
1480 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1481 __ Daddu(TMP, obj, TMP);
1482 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset);
1483 }
1484 break;
1485 }
1486
1487 case Primitive::kPrimFloat: {
1488 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
1489 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
1490 if (index.IsConstant()) {
1491 size_t offset =
1492 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1493 __ LoadFpuFromOffset(kLoadWord, out, obj, offset);
1494 } else {
1495 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1496 __ Daddu(TMP, obj, TMP);
1497 __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset);
1498 }
1499 break;
1500 }
1501
1502 case Primitive::kPrimDouble: {
1503 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
1504 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
1505 if (index.IsConstant()) {
1506 size_t offset =
1507 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1508 __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset);
1509 } else {
1510 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1511 __ Daddu(TMP, obj, TMP);
1512 __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset);
1513 }
1514 break;
1515 }
1516
1517 case Primitive::kPrimVoid:
1518 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1519 UNREACHABLE();
1520 }
1521 codegen_->MaybeRecordImplicitNullCheck(instruction);
1522}
1523
1524void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) {
1525 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1526 locations->SetInAt(0, Location::RequiresRegister());
1527 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1528}
1529
1530void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) {
1531 LocationSummary* locations = instruction->GetLocations();
1532 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
1533 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1534 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1535 __ LoadFromOffset(kLoadWord, out, obj, offset);
1536 codegen_->MaybeRecordImplicitNullCheck(instruction);
1537}
1538
1539void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) {
David Brazdilbb3d5052015-09-21 18:39:16 +01001540 bool needs_runtime_call = instruction->NeedsTypeCheck();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001541 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1542 instruction,
David Brazdilbb3d5052015-09-21 18:39:16 +01001543 needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
1544 if (needs_runtime_call) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001545 InvokeRuntimeCallingConvention calling_convention;
1546 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1547 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1548 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1549 } else {
1550 locations->SetInAt(0, Location::RequiresRegister());
1551 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1552 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
1553 locations->SetInAt(2, Location::RequiresFpuRegister());
1554 } else {
1555 locations->SetInAt(2, Location::RequiresRegister());
1556 }
1557 }
1558}
1559
1560void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) {
1561 LocationSummary* locations = instruction->GetLocations();
1562 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1563 Location index = locations->InAt(1);
1564 Primitive::Type value_type = instruction->GetComponentType();
1565 bool needs_runtime_call = locations->WillCall();
1566 bool needs_write_barrier =
1567 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
1568
1569 switch (value_type) {
1570 case Primitive::kPrimBoolean:
1571 case Primitive::kPrimByte: {
1572 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1573 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1574 if (index.IsConstant()) {
1575 size_t offset =
1576 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1577 __ StoreToOffset(kStoreByte, value, obj, offset);
1578 } else {
1579 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1580 __ StoreToOffset(kStoreByte, value, TMP, data_offset);
1581 }
1582 break;
1583 }
1584
1585 case Primitive::kPrimShort:
1586 case Primitive::kPrimChar: {
1587 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
1588 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1589 if (index.IsConstant()) {
1590 size_t offset =
1591 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1592 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1593 } else {
1594 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1595 __ Daddu(TMP, obj, TMP);
1596 __ StoreToOffset(kStoreHalfword, value, TMP, data_offset);
1597 }
1598 break;
1599 }
1600
1601 case Primitive::kPrimInt:
1602 case Primitive::kPrimNot: {
1603 if (!needs_runtime_call) {
1604 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
1605 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1606 if (index.IsConstant()) {
1607 size_t offset =
1608 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1609 __ StoreToOffset(kStoreWord, value, obj, offset);
1610 } else {
1611 DCHECK(index.IsRegister()) << index;
1612 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1613 __ Daddu(TMP, obj, TMP);
1614 __ StoreToOffset(kStoreWord, value, TMP, data_offset);
1615 }
1616 codegen_->MaybeRecordImplicitNullCheck(instruction);
1617 if (needs_write_barrier) {
1618 DCHECK_EQ(value_type, Primitive::kPrimNot);
1619 codegen_->MarkGCCard(obj, value);
1620 }
1621 } else {
1622 DCHECK_EQ(value_type, Primitive::kPrimNot);
1623 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
1624 instruction,
1625 instruction->GetDexPc(),
1626 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00001627 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001628 }
1629 break;
1630 }
1631
1632 case Primitive::kPrimLong: {
1633 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
1634 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1635 if (index.IsConstant()) {
1636 size_t offset =
1637 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1638 __ StoreToOffset(kStoreDoubleword, value, obj, offset);
1639 } else {
1640 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1641 __ Daddu(TMP, obj, TMP);
1642 __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset);
1643 }
1644 break;
1645 }
1646
1647 case Primitive::kPrimFloat: {
1648 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
1649 FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>();
1650 DCHECK(locations->InAt(2).IsFpuRegister());
1651 if (index.IsConstant()) {
1652 size_t offset =
1653 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1654 __ StoreFpuToOffset(kStoreWord, value, obj, offset);
1655 } else {
1656 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1657 __ Daddu(TMP, obj, TMP);
1658 __ StoreFpuToOffset(kStoreWord, value, TMP, data_offset);
1659 }
1660 break;
1661 }
1662
1663 case Primitive::kPrimDouble: {
1664 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
1665 FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>();
1666 DCHECK(locations->InAt(2).IsFpuRegister());
1667 if (index.IsConstant()) {
1668 size_t offset =
1669 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1670 __ StoreFpuToOffset(kStoreDoubleword, value, obj, offset);
1671 } else {
1672 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1673 __ Daddu(TMP, obj, TMP);
1674 __ StoreFpuToOffset(kStoreDoubleword, value, TMP, data_offset);
1675 }
1676 break;
1677 }
1678
1679 case Primitive::kPrimVoid:
1680 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1681 UNREACHABLE();
1682 }
1683
1684 // Ints and objects are handled in the switch.
1685 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
1686 codegen_->MaybeRecordImplicitNullCheck(instruction);
1687 }
1688}
1689
1690void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00001691 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
1692 ? LocationSummary::kCallOnSlowPath
1693 : LocationSummary::kNoCall;
1694 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001695 locations->SetInAt(0, Location::RequiresRegister());
1696 locations->SetInAt(1, Location::RequiresRegister());
1697 if (instruction->HasUses()) {
1698 locations->SetOut(Location::SameAsFirstInput());
1699 }
1700}
1701
1702void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
1703 LocationSummary* locations = instruction->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01001704 BoundsCheckSlowPathMIPS64* slow_path =
1705 new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001706 codegen_->AddSlowPath(slow_path);
1707
1708 GpuRegister index = locations->InAt(0).AsRegister<GpuRegister>();
1709 GpuRegister length = locations->InAt(1).AsRegister<GpuRegister>();
1710
1711 // length is limited by the maximum positive signed 32-bit integer.
1712 // Unsigned comparison of length and index checks for index < 0
1713 // and for length <= index simultaneously.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001714 __ Bgeuc(index, length, slow_path->GetEntryLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001715}
1716
1717void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) {
1718 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1719 instruction,
1720 LocationSummary::kCallOnSlowPath);
1721 locations->SetInAt(0, Location::RequiresRegister());
1722 locations->SetInAt(1, Location::RequiresRegister());
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01001723 // Note that TypeCheckSlowPathMIPS64 uses this register too.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001724 locations->AddTemp(Location::RequiresRegister());
1725}
1726
1727void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) {
1728 LocationSummary* locations = instruction->GetLocations();
1729 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1730 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
1731 GpuRegister obj_cls = locations->GetTemp(0).AsRegister<GpuRegister>();
1732
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01001733 SlowPathCodeMIPS64* slow_path =
1734 new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001735 codegen_->AddSlowPath(slow_path);
1736
1737 // TODO: avoid this check if we know obj is not null.
1738 __ Beqzc(obj, slow_path->GetExitLabel());
1739 // Compare the class of `obj` with `cls`.
1740 __ LoadFromOffset(kLoadUnsignedWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value());
1741 __ Bnec(obj_cls, cls, slow_path->GetEntryLabel());
1742 __ Bind(slow_path->GetExitLabel());
1743}
1744
1745void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) {
1746 LocationSummary* locations =
1747 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1748 locations->SetInAt(0, Location::RequiresRegister());
1749 if (check->HasUses()) {
1750 locations->SetOut(Location::SameAsFirstInput());
1751 }
1752}
1753
1754void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) {
1755 // We assume the class is not null.
1756 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64(
1757 check->GetLoadClass(),
1758 check,
1759 check->GetDexPc(),
1760 true);
1761 codegen_->AddSlowPath(slow_path);
1762 GenerateClassInitializationCheck(slow_path,
1763 check->GetLocations()->InAt(0).AsRegister<GpuRegister>());
1764}
1765
1766void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) {
1767 Primitive::Type in_type = compare->InputAt(0)->GetType();
1768
Alexey Frunze299a9392015-12-08 16:08:02 -08001769 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(compare);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001770
1771 switch (in_type) {
1772 case Primitive::kPrimLong:
1773 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001774 locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07001775 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1776 break;
1777
1778 case Primitive::kPrimFloat:
Alexey Frunze299a9392015-12-08 16:08:02 -08001779 case Primitive::kPrimDouble:
1780 locations->SetInAt(0, Location::RequiresFpuRegister());
1781 locations->SetInAt(1, Location::RequiresFpuRegister());
1782 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001783 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001784
1785 default:
1786 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1787 }
1788}
1789
1790void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) {
1791 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze299a9392015-12-08 16:08:02 -08001792 GpuRegister res = locations->Out().AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001793 Primitive::Type in_type = instruction->InputAt(0)->GetType();
Alexey Frunze299a9392015-12-08 16:08:02 -08001794 bool gt_bias = instruction->IsGtBias();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001795
1796 // 0 if: left == right
1797 // 1 if: left > right
1798 // -1 if: left < right
1799 switch (in_type) {
1800 case Primitive::kPrimLong: {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001801 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
Alexey Frunze5c75ffa2015-09-24 14:41:59 -07001802 Location rhs_location = locations->InAt(1);
1803 bool use_imm = rhs_location.IsConstant();
1804 GpuRegister rhs = ZERO;
1805 if (use_imm) {
1806 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
1807 if (value != 0) {
1808 rhs = AT;
1809 __ LoadConst64(rhs, value);
1810 }
1811 } else {
1812 rhs = rhs_location.AsRegister<GpuRegister>();
1813 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001814 __ Slt(TMP, lhs, rhs);
Alexey Frunze299a9392015-12-08 16:08:02 -08001815 __ Slt(res, rhs, lhs);
1816 __ Subu(res, res, TMP);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001817 break;
1818 }
1819
Alexey Frunze299a9392015-12-08 16:08:02 -08001820 case Primitive::kPrimFloat: {
1821 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1822 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1823 Mips64Label done;
1824 __ CmpEqS(FTMP, lhs, rhs);
1825 __ LoadConst32(res, 0);
1826 __ Bc1nez(FTMP, &done);
1827 if (gt_bias) {
1828 __ CmpLtS(FTMP, lhs, rhs);
1829 __ LoadConst32(res, -1);
1830 __ Bc1nez(FTMP, &done);
1831 __ LoadConst32(res, 1);
1832 } else {
1833 __ CmpLtS(FTMP, rhs, lhs);
1834 __ LoadConst32(res, 1);
1835 __ Bc1nez(FTMP, &done);
1836 __ LoadConst32(res, -1);
1837 }
1838 __ Bind(&done);
1839 break;
1840 }
1841
Alexey Frunze4dda3372015-06-01 18:31:49 -07001842 case Primitive::kPrimDouble: {
Alexey Frunze299a9392015-12-08 16:08:02 -08001843 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1844 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1845 Mips64Label done;
1846 __ CmpEqD(FTMP, lhs, rhs);
1847 __ LoadConst32(res, 0);
1848 __ Bc1nez(FTMP, &done);
1849 if (gt_bias) {
1850 __ CmpLtD(FTMP, lhs, rhs);
1851 __ LoadConst32(res, -1);
1852 __ Bc1nez(FTMP, &done);
1853 __ LoadConst32(res, 1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001854 } else {
Alexey Frunze299a9392015-12-08 16:08:02 -08001855 __ CmpLtD(FTMP, rhs, lhs);
1856 __ LoadConst32(res, 1);
1857 __ Bc1nez(FTMP, &done);
1858 __ LoadConst32(res, -1);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001859 }
Alexey Frunze299a9392015-12-08 16:08:02 -08001860 __ Bind(&done);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001861 break;
1862 }
1863
1864 default:
1865 LOG(FATAL) << "Unimplemented compare type " << in_type;
1866 }
1867}
1868
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001869void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001870 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexey Frunze299a9392015-12-08 16:08:02 -08001871 switch (instruction->InputAt(0)->GetType()) {
1872 default:
1873 case Primitive::kPrimLong:
1874 locations->SetInAt(0, Location::RequiresRegister());
1875 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1876 break;
1877
1878 case Primitive::kPrimFloat:
1879 case Primitive::kPrimDouble:
1880 locations->SetInAt(0, Location::RequiresFpuRegister());
1881 locations->SetInAt(1, Location::RequiresFpuRegister());
1882 break;
1883 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001884 if (instruction->NeedsMaterialization()) {
1885 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1886 }
1887}
1888
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001889void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001890 if (!instruction->NeedsMaterialization()) {
1891 return;
1892 }
1893
Alexey Frunze299a9392015-12-08 16:08:02 -08001894 Primitive::Type type = instruction->InputAt(0)->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001895 LocationSummary* locations = instruction->GetLocations();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001896 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
Alexey Frunze299a9392015-12-08 16:08:02 -08001897 Mips64Label true_label;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001898
Alexey Frunze299a9392015-12-08 16:08:02 -08001899 switch (type) {
1900 default:
1901 // Integer case.
1902 GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations);
1903 return;
1904 case Primitive::kPrimLong:
1905 GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations);
1906 return;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001907
Alexey Frunze299a9392015-12-08 16:08:02 -08001908 case Primitive::kPrimFloat:
1909 case Primitive::kPrimDouble:
1910 // TODO: don't use branches.
1911 GenerateFpCompareAndBranch(instruction->GetCondition(),
1912 instruction->IsGtBias(),
1913 type,
1914 locations,
1915 &true_label);
Aart Bike9f37602015-10-09 11:15:55 -07001916 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001917 }
Alexey Frunze299a9392015-12-08 16:08:02 -08001918
1919 // Convert the branches into the result.
1920 Mips64Label done;
1921
1922 // False case: result = 0.
1923 __ LoadConst32(dst, 0);
1924 __ Bc(&done);
1925
1926 // True case: result = 1.
1927 __ Bind(&true_label);
1928 __ LoadConst32(dst, 1);
1929 __ Bind(&done);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001930}
1931
Alexey Frunzec857c742015-09-23 15:12:39 -07001932void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
1933 DCHECK(instruction->IsDiv() || instruction->IsRem());
1934 Primitive::Type type = instruction->GetResultType();
1935
1936 LocationSummary* locations = instruction->GetLocations();
1937 Location second = locations->InAt(1);
1938 DCHECK(second.IsConstant());
1939
1940 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1941 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
1942 int64_t imm = Int64FromConstant(second.GetConstant());
1943 DCHECK(imm == 1 || imm == -1);
1944
1945 if (instruction->IsRem()) {
1946 __ Move(out, ZERO);
1947 } else {
1948 if (imm == -1) {
1949 if (type == Primitive::kPrimInt) {
1950 __ Subu(out, ZERO, dividend);
1951 } else {
1952 DCHECK_EQ(type, Primitive::kPrimLong);
1953 __ Dsubu(out, ZERO, dividend);
1954 }
1955 } else if (out != dividend) {
1956 __ Move(out, dividend);
1957 }
1958 }
1959}
1960
1961void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
1962 DCHECK(instruction->IsDiv() || instruction->IsRem());
1963 Primitive::Type type = instruction->GetResultType();
1964
1965 LocationSummary* locations = instruction->GetLocations();
1966 Location second = locations->InAt(1);
1967 DCHECK(second.IsConstant());
1968
1969 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1970 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
1971 int64_t imm = Int64FromConstant(second.GetConstant());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00001972 uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm));
Alexey Frunzec857c742015-09-23 15:12:39 -07001973 int ctz_imm = CTZ(abs_imm);
1974
1975 if (instruction->IsDiv()) {
1976 if (type == Primitive::kPrimInt) {
1977 if (ctz_imm == 1) {
1978 // Fast path for division by +/-2, which is very common.
1979 __ Srl(TMP, dividend, 31);
1980 } else {
1981 __ Sra(TMP, dividend, 31);
1982 __ Srl(TMP, TMP, 32 - ctz_imm);
1983 }
1984 __ Addu(out, dividend, TMP);
1985 __ Sra(out, out, ctz_imm);
1986 if (imm < 0) {
1987 __ Subu(out, ZERO, out);
1988 }
1989 } else {
1990 DCHECK_EQ(type, Primitive::kPrimLong);
1991 if (ctz_imm == 1) {
1992 // Fast path for division by +/-2, which is very common.
1993 __ Dsrl32(TMP, dividend, 31);
1994 } else {
1995 __ Dsra32(TMP, dividend, 31);
1996 if (ctz_imm > 32) {
1997 __ Dsrl(TMP, TMP, 64 - ctz_imm);
1998 } else {
1999 __ Dsrl32(TMP, TMP, 32 - ctz_imm);
2000 }
2001 }
2002 __ Daddu(out, dividend, TMP);
2003 if (ctz_imm < 32) {
2004 __ Dsra(out, out, ctz_imm);
2005 } else {
2006 __ Dsra32(out, out, ctz_imm - 32);
2007 }
2008 if (imm < 0) {
2009 __ Dsubu(out, ZERO, out);
2010 }
2011 }
2012 } else {
2013 if (type == Primitive::kPrimInt) {
2014 if (ctz_imm == 1) {
2015 // Fast path for modulo +/-2, which is very common.
2016 __ Sra(TMP, dividend, 31);
2017 __ Subu(out, dividend, TMP);
2018 __ Andi(out, out, 1);
2019 __ Addu(out, out, TMP);
2020 } else {
2021 __ Sra(TMP, dividend, 31);
2022 __ Srl(TMP, TMP, 32 - ctz_imm);
2023 __ Addu(out, dividend, TMP);
2024 if (IsUint<16>(abs_imm - 1)) {
2025 __ Andi(out, out, abs_imm - 1);
2026 } else {
2027 __ Sll(out, out, 32 - ctz_imm);
2028 __ Srl(out, out, 32 - ctz_imm);
2029 }
2030 __ Subu(out, out, TMP);
2031 }
2032 } else {
2033 DCHECK_EQ(type, Primitive::kPrimLong);
2034 if (ctz_imm == 1) {
2035 // Fast path for modulo +/-2, which is very common.
2036 __ Dsra32(TMP, dividend, 31);
2037 __ Dsubu(out, dividend, TMP);
2038 __ Andi(out, out, 1);
2039 __ Daddu(out, out, TMP);
2040 } else {
2041 __ Dsra32(TMP, dividend, 31);
2042 if (ctz_imm > 32) {
2043 __ Dsrl(TMP, TMP, 64 - ctz_imm);
2044 } else {
2045 __ Dsrl32(TMP, TMP, 32 - ctz_imm);
2046 }
2047 __ Daddu(out, dividend, TMP);
2048 if (IsUint<16>(abs_imm - 1)) {
2049 __ Andi(out, out, abs_imm - 1);
2050 } else {
2051 if (ctz_imm > 32) {
2052 __ Dsll(out, out, 64 - ctz_imm);
2053 __ Dsrl(out, out, 64 - ctz_imm);
2054 } else {
2055 __ Dsll32(out, out, 32 - ctz_imm);
2056 __ Dsrl32(out, out, 32 - ctz_imm);
2057 }
2058 }
2059 __ Dsubu(out, out, TMP);
2060 }
2061 }
2062 }
2063}
2064
2065void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2066 DCHECK(instruction->IsDiv() || instruction->IsRem());
2067
2068 LocationSummary* locations = instruction->GetLocations();
2069 Location second = locations->InAt(1);
2070 DCHECK(second.IsConstant());
2071
2072 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2073 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
2074 int64_t imm = Int64FromConstant(second.GetConstant());
2075
2076 Primitive::Type type = instruction->GetResultType();
2077 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type;
2078
2079 int64_t magic;
2080 int shift;
2081 CalculateMagicAndShiftForDivRem(imm,
2082 (type == Primitive::kPrimLong),
2083 &magic,
2084 &shift);
2085
2086 if (type == Primitive::kPrimInt) {
2087 __ LoadConst32(TMP, magic);
2088 __ MuhR6(TMP, dividend, TMP);
2089
2090 if (imm > 0 && magic < 0) {
2091 __ Addu(TMP, TMP, dividend);
2092 } else if (imm < 0 && magic > 0) {
2093 __ Subu(TMP, TMP, dividend);
2094 }
2095
2096 if (shift != 0) {
2097 __ Sra(TMP, TMP, shift);
2098 }
2099
2100 if (instruction->IsDiv()) {
2101 __ Sra(out, TMP, 31);
2102 __ Subu(out, TMP, out);
2103 } else {
2104 __ Sra(AT, TMP, 31);
2105 __ Subu(AT, TMP, AT);
2106 __ LoadConst32(TMP, imm);
2107 __ MulR6(TMP, AT, TMP);
2108 __ Subu(out, dividend, TMP);
2109 }
2110 } else {
2111 __ LoadConst64(TMP, magic);
2112 __ Dmuh(TMP, dividend, TMP);
2113
2114 if (imm > 0 && magic < 0) {
2115 __ Daddu(TMP, TMP, dividend);
2116 } else if (imm < 0 && magic > 0) {
2117 __ Dsubu(TMP, TMP, dividend);
2118 }
2119
2120 if (shift >= 32) {
2121 __ Dsra32(TMP, TMP, shift - 32);
2122 } else if (shift > 0) {
2123 __ Dsra(TMP, TMP, shift);
2124 }
2125
2126 if (instruction->IsDiv()) {
2127 __ Dsra32(out, TMP, 31);
2128 __ Dsubu(out, TMP, out);
2129 } else {
2130 __ Dsra32(AT, TMP, 31);
2131 __ Dsubu(AT, TMP, AT);
2132 __ LoadConst64(TMP, imm);
2133 __ Dmul(TMP, AT, TMP);
2134 __ Dsubu(out, dividend, TMP);
2135 }
2136 }
2137}
2138
2139void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) {
2140 DCHECK(instruction->IsDiv() || instruction->IsRem());
2141 Primitive::Type type = instruction->GetResultType();
2142 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type;
2143
2144 LocationSummary* locations = instruction->GetLocations();
2145 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2146 Location second = locations->InAt(1);
2147
2148 if (second.IsConstant()) {
2149 int64_t imm = Int64FromConstant(second.GetConstant());
2150 if (imm == 0) {
2151 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2152 } else if (imm == 1 || imm == -1) {
2153 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002154 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunzec857c742015-09-23 15:12:39 -07002155 DivRemByPowerOfTwo(instruction);
2156 } else {
2157 DCHECK(imm <= -2 || imm >= 2);
2158 GenerateDivRemWithAnyConstant(instruction);
2159 }
2160 } else {
2161 GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>();
2162 GpuRegister divisor = second.AsRegister<GpuRegister>();
2163 if (instruction->IsDiv()) {
2164 if (type == Primitive::kPrimInt)
2165 __ DivR6(out, dividend, divisor);
2166 else
2167 __ Ddiv(out, dividend, divisor);
2168 } else {
2169 if (type == Primitive::kPrimInt)
2170 __ ModR6(out, dividend, divisor);
2171 else
2172 __ Dmod(out, dividend, divisor);
2173 }
2174 }
2175}
2176
Alexey Frunze4dda3372015-06-01 18:31:49 -07002177void LocationsBuilderMIPS64::VisitDiv(HDiv* div) {
2178 LocationSummary* locations =
2179 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
2180 switch (div->GetResultType()) {
2181 case Primitive::kPrimInt:
2182 case Primitive::kPrimLong:
2183 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunzec857c742015-09-23 15:12:39 -07002184 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002185 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2186 break;
2187
2188 case Primitive::kPrimFloat:
2189 case Primitive::kPrimDouble:
2190 locations->SetInAt(0, Location::RequiresFpuRegister());
2191 locations->SetInAt(1, Location::RequiresFpuRegister());
2192 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2193 break;
2194
2195 default:
2196 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2197 }
2198}
2199
2200void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) {
2201 Primitive::Type type = instruction->GetType();
2202 LocationSummary* locations = instruction->GetLocations();
2203
2204 switch (type) {
2205 case Primitive::kPrimInt:
Alexey Frunzec857c742015-09-23 15:12:39 -07002206 case Primitive::kPrimLong:
2207 GenerateDivRemIntegral(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002208 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002209 case Primitive::kPrimFloat:
2210 case Primitive::kPrimDouble: {
2211 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2212 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
2213 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
2214 if (type == Primitive::kPrimFloat)
2215 __ DivS(dst, lhs, rhs);
2216 else
2217 __ DivD(dst, lhs, rhs);
2218 break;
2219 }
2220 default:
2221 LOG(FATAL) << "Unexpected div type " << type;
2222 }
2223}
2224
2225void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00002226 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2227 ? LocationSummary::kCallOnSlowPath
2228 : LocationSummary::kNoCall;
2229 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002230 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
2231 if (instruction->HasUses()) {
2232 locations->SetOut(Location::SameAsFirstInput());
2233 }
2234}
2235
2236void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2237 SlowPathCodeMIPS64* slow_path =
2238 new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS64(instruction);
2239 codegen_->AddSlowPath(slow_path);
2240 Location value = instruction->GetLocations()->InAt(0);
2241
2242 Primitive::Type type = instruction->GetType();
2243
Serguei Katkov8c0676c2015-08-03 13:55:33 +06002244 if ((type == Primitive::kPrimBoolean) || !Primitive::IsIntegralType(type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002245 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
Serguei Katkov8c0676c2015-08-03 13:55:33 +06002246 return;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002247 }
2248
2249 if (value.IsConstant()) {
2250 int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant());
2251 if (divisor == 0) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002252 __ Bc(slow_path->GetEntryLabel());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002253 } else {
2254 // A division by a non-null constant is valid. We don't need to perform
2255 // any check, so simply fall through.
2256 }
2257 } else {
2258 __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
2259 }
2260}
2261
2262void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) {
2263 LocationSummary* locations =
2264 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2265 locations->SetOut(Location::ConstantLocation(constant));
2266}
2267
2268void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
2269 // Will be generated at use site.
2270}
2271
2272void LocationsBuilderMIPS64::VisitExit(HExit* exit) {
2273 exit->SetLocations(nullptr);
2274}
2275
2276void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
2277}
2278
2279void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) {
2280 LocationSummary* locations =
2281 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2282 locations->SetOut(Location::ConstantLocation(constant));
2283}
2284
2285void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
2286 // Will be generated at use site.
2287}
2288
David Brazdilfc6a86a2015-06-26 10:33:45 +00002289void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002290 DCHECK(!successor->IsExitBlock());
2291 HBasicBlock* block = got->GetBlock();
2292 HInstruction* previous = got->GetPrevious();
2293 HLoopInformation* info = block->GetLoopInformation();
2294
2295 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
2296 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
2297 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
2298 return;
2299 }
2300 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
2301 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
2302 }
2303 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002304 __ Bc(codegen_->GetLabelOf(successor));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002305 }
2306}
2307
David Brazdilfc6a86a2015-06-26 10:33:45 +00002308void LocationsBuilderMIPS64::VisitGoto(HGoto* got) {
2309 got->SetLocations(nullptr);
2310}
2311
2312void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) {
2313 HandleGoto(got, got->GetSuccessor());
2314}
2315
2316void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
2317 try_boundary->SetLocations(nullptr);
2318}
2319
2320void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
2321 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
2322 if (!successor->IsExitBlock()) {
2323 HandleGoto(try_boundary, successor);
2324 }
2325}
2326
Alexey Frunze299a9392015-12-08 16:08:02 -08002327void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond,
2328 bool is64bit,
2329 LocationSummary* locations) {
2330 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2331 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2332 Location rhs_location = locations->InAt(1);
2333 GpuRegister rhs_reg = ZERO;
2334 int64_t rhs_imm = 0;
2335 bool use_imm = rhs_location.IsConstant();
2336 if (use_imm) {
2337 if (is64bit) {
2338 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
2339 } else {
2340 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2341 }
2342 } else {
2343 rhs_reg = rhs_location.AsRegister<GpuRegister>();
2344 }
2345 int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1);
2346
2347 switch (cond) {
2348 case kCondEQ:
2349 case kCondNE:
2350 if (use_imm && IsUint<16>(rhs_imm)) {
2351 __ Xori(dst, lhs, rhs_imm);
2352 } else {
2353 if (use_imm) {
2354 rhs_reg = TMP;
2355 __ LoadConst64(rhs_reg, rhs_imm);
2356 }
2357 __ Xor(dst, lhs, rhs_reg);
2358 }
2359 if (cond == kCondEQ) {
2360 __ Sltiu(dst, dst, 1);
2361 } else {
2362 __ Sltu(dst, ZERO, dst);
2363 }
2364 break;
2365
2366 case kCondLT:
2367 case kCondGE:
2368 if (use_imm && IsInt<16>(rhs_imm)) {
2369 __ Slti(dst, lhs, rhs_imm);
2370 } else {
2371 if (use_imm) {
2372 rhs_reg = TMP;
2373 __ LoadConst64(rhs_reg, rhs_imm);
2374 }
2375 __ Slt(dst, lhs, rhs_reg);
2376 }
2377 if (cond == kCondGE) {
2378 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2379 // only the slt instruction but no sge.
2380 __ Xori(dst, dst, 1);
2381 }
2382 break;
2383
2384 case kCondLE:
2385 case kCondGT:
2386 if (use_imm && IsInt<16>(rhs_imm_plus_one)) {
2387 // Simulate lhs <= rhs via lhs < rhs + 1.
2388 __ Slti(dst, lhs, rhs_imm_plus_one);
2389 if (cond == kCondGT) {
2390 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2391 // only the slti instruction but no sgti.
2392 __ Xori(dst, dst, 1);
2393 }
2394 } else {
2395 if (use_imm) {
2396 rhs_reg = TMP;
2397 __ LoadConst64(rhs_reg, rhs_imm);
2398 }
2399 __ Slt(dst, rhs_reg, lhs);
2400 if (cond == kCondLE) {
2401 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2402 // only the slt instruction but no sle.
2403 __ Xori(dst, dst, 1);
2404 }
2405 }
2406 break;
2407
2408 case kCondB:
2409 case kCondAE:
2410 if (use_imm && IsInt<16>(rhs_imm)) {
2411 // Sltiu sign-extends its 16-bit immediate operand before
2412 // the comparison and thus lets us compare directly with
2413 // unsigned values in the ranges [0, 0x7fff] and
2414 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
2415 __ Sltiu(dst, lhs, rhs_imm);
2416 } else {
2417 if (use_imm) {
2418 rhs_reg = TMP;
2419 __ LoadConst64(rhs_reg, rhs_imm);
2420 }
2421 __ Sltu(dst, lhs, rhs_reg);
2422 }
2423 if (cond == kCondAE) {
2424 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2425 // only the sltu instruction but no sgeu.
2426 __ Xori(dst, dst, 1);
2427 }
2428 break;
2429
2430 case kCondBE:
2431 case kCondA:
2432 if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) {
2433 // Simulate lhs <= rhs via lhs < rhs + 1.
2434 // Note that this only works if rhs + 1 does not overflow
2435 // to 0, hence the check above.
2436 // Sltiu sign-extends its 16-bit immediate operand before
2437 // the comparison and thus lets us compare directly with
2438 // unsigned values in the ranges [0, 0x7fff] and
2439 // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff].
2440 __ Sltiu(dst, lhs, rhs_imm_plus_one);
2441 if (cond == kCondA) {
2442 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2443 // only the sltiu instruction but no sgtiu.
2444 __ Xori(dst, dst, 1);
2445 }
2446 } else {
2447 if (use_imm) {
2448 rhs_reg = TMP;
2449 __ LoadConst64(rhs_reg, rhs_imm);
2450 }
2451 __ Sltu(dst, rhs_reg, lhs);
2452 if (cond == kCondBE) {
2453 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2454 // only the sltu instruction but no sleu.
2455 __ Xori(dst, dst, 1);
2456 }
2457 }
2458 break;
2459 }
2460}
2461
2462void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond,
2463 bool is64bit,
2464 LocationSummary* locations,
2465 Mips64Label* label) {
2466 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2467 Location rhs_location = locations->InAt(1);
2468 GpuRegister rhs_reg = ZERO;
2469 int64_t rhs_imm = 0;
2470 bool use_imm = rhs_location.IsConstant();
2471 if (use_imm) {
2472 if (is64bit) {
2473 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
2474 } else {
2475 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2476 }
2477 } else {
2478 rhs_reg = rhs_location.AsRegister<GpuRegister>();
2479 }
2480
2481 if (use_imm && rhs_imm == 0) {
2482 switch (cond) {
2483 case kCondEQ:
2484 case kCondBE: // <= 0 if zero
2485 __ Beqzc(lhs, label);
2486 break;
2487 case kCondNE:
2488 case kCondA: // > 0 if non-zero
2489 __ Bnezc(lhs, label);
2490 break;
2491 case kCondLT:
2492 __ Bltzc(lhs, label);
2493 break;
2494 case kCondGE:
2495 __ Bgezc(lhs, label);
2496 break;
2497 case kCondLE:
2498 __ Blezc(lhs, label);
2499 break;
2500 case kCondGT:
2501 __ Bgtzc(lhs, label);
2502 break;
2503 case kCondB: // always false
2504 break;
2505 case kCondAE: // always true
2506 __ Bc(label);
2507 break;
2508 }
2509 } else {
2510 if (use_imm) {
2511 rhs_reg = TMP;
2512 __ LoadConst64(rhs_reg, rhs_imm);
2513 }
2514 switch (cond) {
2515 case kCondEQ:
2516 __ Beqc(lhs, rhs_reg, label);
2517 break;
2518 case kCondNE:
2519 __ Bnec(lhs, rhs_reg, label);
2520 break;
2521 case kCondLT:
2522 __ Bltc(lhs, rhs_reg, label);
2523 break;
2524 case kCondGE:
2525 __ Bgec(lhs, rhs_reg, label);
2526 break;
2527 case kCondLE:
2528 __ Bgec(rhs_reg, lhs, label);
2529 break;
2530 case kCondGT:
2531 __ Bltc(rhs_reg, lhs, label);
2532 break;
2533 case kCondB:
2534 __ Bltuc(lhs, rhs_reg, label);
2535 break;
2536 case kCondAE:
2537 __ Bgeuc(lhs, rhs_reg, label);
2538 break;
2539 case kCondBE:
2540 __ Bgeuc(rhs_reg, lhs, label);
2541 break;
2542 case kCondA:
2543 __ Bltuc(rhs_reg, lhs, label);
2544 break;
2545 }
2546 }
2547}
2548
2549void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond,
2550 bool gt_bias,
2551 Primitive::Type type,
2552 LocationSummary* locations,
2553 Mips64Label* label) {
2554 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
2555 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
2556 if (type == Primitive::kPrimFloat) {
2557 switch (cond) {
2558 case kCondEQ:
2559 __ CmpEqS(FTMP, lhs, rhs);
2560 __ Bc1nez(FTMP, label);
2561 break;
2562 case kCondNE:
2563 __ CmpEqS(FTMP, lhs, rhs);
2564 __ Bc1eqz(FTMP, label);
2565 break;
2566 case kCondLT:
2567 if (gt_bias) {
2568 __ CmpLtS(FTMP, lhs, rhs);
2569 } else {
2570 __ CmpUltS(FTMP, lhs, rhs);
2571 }
2572 __ Bc1nez(FTMP, label);
2573 break;
2574 case kCondLE:
2575 if (gt_bias) {
2576 __ CmpLeS(FTMP, lhs, rhs);
2577 } else {
2578 __ CmpUleS(FTMP, lhs, rhs);
2579 }
2580 __ Bc1nez(FTMP, label);
2581 break;
2582 case kCondGT:
2583 if (gt_bias) {
2584 __ CmpUltS(FTMP, rhs, lhs);
2585 } else {
2586 __ CmpLtS(FTMP, rhs, lhs);
2587 }
2588 __ Bc1nez(FTMP, label);
2589 break;
2590 case kCondGE:
2591 if (gt_bias) {
2592 __ CmpUleS(FTMP, rhs, lhs);
2593 } else {
2594 __ CmpLeS(FTMP, rhs, lhs);
2595 }
2596 __ Bc1nez(FTMP, label);
2597 break;
2598 default:
2599 LOG(FATAL) << "Unexpected non-floating-point condition";
2600 }
2601 } else {
2602 DCHECK_EQ(type, Primitive::kPrimDouble);
2603 switch (cond) {
2604 case kCondEQ:
2605 __ CmpEqD(FTMP, lhs, rhs);
2606 __ Bc1nez(FTMP, label);
2607 break;
2608 case kCondNE:
2609 __ CmpEqD(FTMP, lhs, rhs);
2610 __ Bc1eqz(FTMP, label);
2611 break;
2612 case kCondLT:
2613 if (gt_bias) {
2614 __ CmpLtD(FTMP, lhs, rhs);
2615 } else {
2616 __ CmpUltD(FTMP, lhs, rhs);
2617 }
2618 __ Bc1nez(FTMP, label);
2619 break;
2620 case kCondLE:
2621 if (gt_bias) {
2622 __ CmpLeD(FTMP, lhs, rhs);
2623 } else {
2624 __ CmpUleD(FTMP, lhs, rhs);
2625 }
2626 __ Bc1nez(FTMP, label);
2627 break;
2628 case kCondGT:
2629 if (gt_bias) {
2630 __ CmpUltD(FTMP, rhs, lhs);
2631 } else {
2632 __ CmpLtD(FTMP, rhs, lhs);
2633 }
2634 __ Bc1nez(FTMP, label);
2635 break;
2636 case kCondGE:
2637 if (gt_bias) {
2638 __ CmpUleD(FTMP, rhs, lhs);
2639 } else {
2640 __ CmpLeD(FTMP, rhs, lhs);
2641 }
2642 __ Bc1nez(FTMP, label);
2643 break;
2644 default:
2645 LOG(FATAL) << "Unexpected non-floating-point condition";
2646 }
2647 }
2648}
2649
Alexey Frunze4dda3372015-06-01 18:31:49 -07002650void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00002651 size_t condition_input_index,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002652 Mips64Label* true_target,
2653 Mips64Label* false_target) {
David Brazdil0debae72015-11-12 18:37:00 +00002654 HInstruction* cond = instruction->InputAt(condition_input_index);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002655
David Brazdil0debae72015-11-12 18:37:00 +00002656 if (true_target == nullptr && false_target == nullptr) {
2657 // Nothing to do. The code always falls through.
2658 return;
2659 } else if (cond->IsIntConstant()) {
2660 // Constant condition, statically compared against 1.
2661 if (cond->AsIntConstant()->IsOne()) {
2662 if (true_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002663 __ Bc(true_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002664 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002665 } else {
David Brazdil0debae72015-11-12 18:37:00 +00002666 DCHECK(cond->AsIntConstant()->IsZero());
2667 if (false_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002668 __ Bc(false_target);
David Brazdil0debae72015-11-12 18:37:00 +00002669 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002670 }
David Brazdil0debae72015-11-12 18:37:00 +00002671 return;
2672 }
2673
2674 // The following code generates these patterns:
2675 // (1) true_target == nullptr && false_target != nullptr
2676 // - opposite condition true => branch to false_target
2677 // (2) true_target != nullptr && false_target == nullptr
2678 // - condition true => branch to true_target
2679 // (3) true_target != nullptr && false_target != nullptr
2680 // - condition true => branch to true_target
2681 // - branch to false_target
2682 if (IsBooleanValueOrMaterializedCondition(cond)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002683 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00002684 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002685 DCHECK(cond_val.IsRegister());
David Brazdil0debae72015-11-12 18:37:00 +00002686 if (true_target == nullptr) {
2687 __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target);
2688 } else {
2689 __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target);
2690 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002691 } else {
2692 // The condition instruction has not been materialized, use its inputs as
2693 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00002694 HCondition* condition = cond->AsCondition();
Alexey Frunze299a9392015-12-08 16:08:02 -08002695 Primitive::Type type = condition->InputAt(0)->GetType();
2696 LocationSummary* locations = cond->GetLocations();
2697 IfCondition if_cond = condition->GetCondition();
2698 Mips64Label* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00002699
David Brazdil0debae72015-11-12 18:37:00 +00002700 if (true_target == nullptr) {
2701 if_cond = condition->GetOppositeCondition();
Alexey Frunze299a9392015-12-08 16:08:02 -08002702 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00002703 }
2704
Alexey Frunze299a9392015-12-08 16:08:02 -08002705 switch (type) {
2706 default:
2707 GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target);
2708 break;
2709 case Primitive::kPrimLong:
2710 GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target);
2711 break;
2712 case Primitive::kPrimFloat:
2713 case Primitive::kPrimDouble:
2714 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
2715 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002716 }
2717 }
David Brazdil0debae72015-11-12 18:37:00 +00002718
2719 // If neither branch falls through (case 3), the conditional branch to `true_target`
2720 // was already emitted (case 2) and we need to emit a jump to `false_target`.
2721 if (true_target != nullptr && false_target != nullptr) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002722 __ Bc(false_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002723 }
2724}
2725
2726void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) {
2727 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00002728 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002729 locations->SetInAt(0, Location::RequiresRegister());
2730 }
2731}
2732
2733void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00002734 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
2735 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002736 Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
David Brazdil0debae72015-11-12 18:37:00 +00002737 nullptr : codegen_->GetLabelOf(true_successor);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002738 Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
David Brazdil0debae72015-11-12 18:37:00 +00002739 nullptr : codegen_->GetLabelOf(false_successor);
2740 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002741}
2742
2743void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
2744 LocationSummary* locations = new (GetGraph()->GetArena())
2745 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
David Brazdil0debae72015-11-12 18:37:00 +00002746 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002747 locations->SetInAt(0, Location::RequiresRegister());
2748 }
2749}
2750
2751void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08002752 SlowPathCodeMIPS64* slow_path =
2753 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00002754 GenerateTestAndBranch(deoptimize,
2755 /* condition_input_index */ 0,
2756 slow_path->GetEntryLabel(),
2757 /* false_target */ nullptr);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002758}
2759
David Srbecky0cf44932015-12-09 14:09:59 +00002760void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) {
2761 new (GetGraph()->GetArena()) LocationSummary(info);
2762}
2763
2764void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) {
David Srbeckyb7070a22016-01-08 18:13:53 +00002765 if (codegen_->HasStackMapAtCurrentPc()) {
2766 // Ensure that we do not collide with the stack map of the previous instruction.
2767 __ Nop();
2768 }
David Srbecky0cf44932015-12-09 14:09:59 +00002769 codegen_->RecordPcInfo(info, info->GetDexPc());
2770}
2771
Alexey Frunze4dda3372015-06-01 18:31:49 -07002772void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction,
2773 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
2774 LocationSummary* locations =
2775 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2776 locations->SetInAt(0, Location::RequiresRegister());
2777 if (Primitive::IsFloatingPointType(instruction->GetType())) {
2778 locations->SetOut(Location::RequiresFpuRegister());
2779 } else {
2780 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2781 }
2782}
2783
2784void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction,
2785 const FieldInfo& field_info) {
2786 Primitive::Type type = field_info.GetFieldType();
2787 LocationSummary* locations = instruction->GetLocations();
2788 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2789 LoadOperandType load_type = kLoadUnsignedByte;
2790 switch (type) {
2791 case Primitive::kPrimBoolean:
2792 load_type = kLoadUnsignedByte;
2793 break;
2794 case Primitive::kPrimByte:
2795 load_type = kLoadSignedByte;
2796 break;
2797 case Primitive::kPrimShort:
2798 load_type = kLoadSignedHalfword;
2799 break;
2800 case Primitive::kPrimChar:
2801 load_type = kLoadUnsignedHalfword;
2802 break;
2803 case Primitive::kPrimInt:
2804 case Primitive::kPrimFloat:
2805 load_type = kLoadWord;
2806 break;
2807 case Primitive::kPrimLong:
2808 case Primitive::kPrimDouble:
2809 load_type = kLoadDoubleword;
2810 break;
2811 case Primitive::kPrimNot:
2812 load_type = kLoadUnsignedWord;
2813 break;
2814 case Primitive::kPrimVoid:
2815 LOG(FATAL) << "Unreachable type " << type;
2816 UNREACHABLE();
2817 }
2818 if (!Primitive::IsFloatingPointType(type)) {
2819 DCHECK(locations->Out().IsRegister());
2820 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2821 __ LoadFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value());
2822 } else {
2823 DCHECK(locations->Out().IsFpuRegister());
2824 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2825 __ LoadFpuFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value());
2826 }
2827
2828 codegen_->MaybeRecordImplicitNullCheck(instruction);
2829 // TODO: memory barrier?
2830}
2831
2832void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction,
2833 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
2834 LocationSummary* locations =
2835 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2836 locations->SetInAt(0, Location::RequiresRegister());
2837 if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
2838 locations->SetInAt(1, Location::RequiresFpuRegister());
2839 } else {
2840 locations->SetInAt(1, Location::RequiresRegister());
2841 }
2842}
2843
2844void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction,
2845 const FieldInfo& field_info) {
2846 Primitive::Type type = field_info.GetFieldType();
2847 LocationSummary* locations = instruction->GetLocations();
2848 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2849 StoreOperandType store_type = kStoreByte;
2850 switch (type) {
2851 case Primitive::kPrimBoolean:
2852 case Primitive::kPrimByte:
2853 store_type = kStoreByte;
2854 break;
2855 case Primitive::kPrimShort:
2856 case Primitive::kPrimChar:
2857 store_type = kStoreHalfword;
2858 break;
2859 case Primitive::kPrimInt:
2860 case Primitive::kPrimFloat:
2861 case Primitive::kPrimNot:
2862 store_type = kStoreWord;
2863 break;
2864 case Primitive::kPrimLong:
2865 case Primitive::kPrimDouble:
2866 store_type = kStoreDoubleword;
2867 break;
2868 case Primitive::kPrimVoid:
2869 LOG(FATAL) << "Unreachable type " << type;
2870 UNREACHABLE();
2871 }
2872 if (!Primitive::IsFloatingPointType(type)) {
2873 DCHECK(locations->InAt(1).IsRegister());
2874 GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>();
2875 __ StoreToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value());
2876 } else {
2877 DCHECK(locations->InAt(1).IsFpuRegister());
2878 FpuRegister src = locations->InAt(1).AsFpuRegister<FpuRegister>();
2879 __ StoreFpuToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value());
2880 }
2881
2882 codegen_->MaybeRecordImplicitNullCheck(instruction);
2883 // TODO: memory barriers?
2884 if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) {
2885 DCHECK(locations->InAt(1).IsRegister());
2886 GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>();
2887 codegen_->MarkGCCard(obj, src);
2888 }
2889}
2890
2891void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2892 HandleFieldGet(instruction, instruction->GetFieldInfo());
2893}
2894
2895void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2896 HandleFieldGet(instruction, instruction->GetFieldInfo());
2897}
2898
2899void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2900 HandleFieldSet(instruction, instruction->GetFieldInfo());
2901}
2902
2903void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2904 HandleFieldSet(instruction, instruction->GetFieldInfo());
2905}
2906
2907void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
2908 LocationSummary::CallKind call_kind =
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00002909 instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002910 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2911 locations->SetInAt(0, Location::RequiresRegister());
2912 locations->SetInAt(1, Location::RequiresRegister());
2913 // The output does overlap inputs.
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01002914 // Note that TypeCheckSlowPathMIPS64 uses this register too.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002915 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2916}
2917
2918void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
2919 LocationSummary* locations = instruction->GetLocations();
2920 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2921 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
2922 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2923
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002924 Mips64Label done;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002925
2926 // Return 0 if `obj` is null.
2927 // TODO: Avoid this check if we know `obj` is not null.
2928 __ Move(out, ZERO);
2929 __ Beqzc(obj, &done);
2930
2931 // Compare the class of `obj` with `cls`.
2932 __ LoadFromOffset(kLoadUnsignedWord, out, obj, mirror::Object::ClassOffset().Int32Value());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00002933 if (instruction->IsExactCheck()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002934 // Classes must be equal for the instanceof to succeed.
2935 __ Xor(out, out, cls);
2936 __ Sltiu(out, out, 1);
2937 } else {
2938 // If the classes are not equal, we go into a slow path.
2939 DCHECK(locations->OnlyCallsOnSlowPath());
2940 SlowPathCodeMIPS64* slow_path =
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01002941 new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002942 codegen_->AddSlowPath(slow_path);
2943 __ Bnec(out, cls, slow_path->GetEntryLabel());
2944 __ LoadConst32(out, 1);
2945 __ Bind(slow_path->GetExitLabel());
2946 }
2947
2948 __ Bind(&done);
2949}
2950
2951void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) {
2952 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2953 locations->SetOut(Location::ConstantLocation(constant));
2954}
2955
2956void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
2957 // Will be generated at use site.
2958}
2959
2960void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) {
2961 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2962 locations->SetOut(Location::ConstantLocation(constant));
2963}
2964
2965void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
2966 // Will be generated at use site.
2967}
2968
Calin Juravle175dc732015-08-25 15:42:32 +01002969void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
2970 // The trampoline uses the same calling convention as dex calling conventions,
2971 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
2972 // the method_idx.
2973 HandleInvoke(invoke);
2974}
2975
2976void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
2977 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
2978}
2979
Alexey Frunze4dda3372015-06-01 18:31:49 -07002980void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) {
2981 InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor;
2982 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
2983}
2984
2985void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
2986 HandleInvoke(invoke);
2987 // The register T0 is required to be used for the hidden argument in
2988 // art_quick_imt_conflict_trampoline, so add the hidden argument.
2989 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
2990}
2991
2992void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
2993 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
2994 GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
2995 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
2996 invoke->GetImtIndex() % mirror::Class::kImtSize, kMips64PointerSize).Uint32Value();
2997 Location receiver = invoke->GetLocations()->InAt(0);
2998 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2999 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64WordSize);
3000
3001 // Set the hidden argument.
3002 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(),
3003 invoke->GetDexMethodIndex());
3004
3005 // temp = object->GetClass();
3006 if (receiver.IsStackSlot()) {
3007 __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex());
3008 __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset);
3009 } else {
3010 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset);
3011 }
3012 codegen_->MaybeRecordImplicitNullCheck(invoke);
3013 // temp = temp->GetImtEntryAt(method_offset);
3014 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
3015 // T9 = temp->GetEntryPoint();
3016 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
3017 // T9();
3018 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003019 __ Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003020 DCHECK(!codegen_->IsLeafMethod());
3021 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3022}
3023
3024void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen3039e382015-08-26 07:54:08 -07003025 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
3026 if (intrinsic.TryDispatch(invoke)) {
3027 return;
3028 }
3029
Alexey Frunze4dda3372015-06-01 18:31:49 -07003030 HandleInvoke(invoke);
3031}
3032
3033void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
3034 // When we do not run baseline, explicit clinit checks triggered by static
3035 // invokes must have been pruned by art::PrepareForRegisterAllocation.
3036 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
3037
Chris Larsen3039e382015-08-26 07:54:08 -07003038 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
3039 if (intrinsic.TryDispatch(invoke)) {
3040 return;
3041 }
3042
Alexey Frunze4dda3372015-06-01 18:31:49 -07003043 HandleInvoke(invoke);
3044
3045 // While SetupBlockedRegisters() blocks registers S2-S8 due to their
3046 // clobbering somewhere else, reduce further register pressure by avoiding
3047 // allocation of a register for the current method pointer like on x86 baseline.
3048 // TODO: remove this once all the issues with register saving/restoring are
3049 // sorted out.
Vladimir Marko6f6f3592015-11-09 12:54:16 +00003050 if (invoke->HasCurrentMethodInput()) {
3051 LocationSummary* locations = invoke->GetLocations();
Vladimir Markoc53c0792015-11-19 15:48:33 +00003052 Location location = locations->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko6f6f3592015-11-09 12:54:16 +00003053 if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) {
Vladimir Markoc53c0792015-11-19 15:48:33 +00003054 locations->SetInAt(invoke->GetSpecialInputIndex(), Location::NoLocation());
Vladimir Marko6f6f3592015-11-09 12:54:16 +00003055 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003056 }
3057}
3058
Chris Larsen3039e382015-08-26 07:54:08 -07003059static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003060 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen3039e382015-08-26 07:54:08 -07003061 IntrinsicCodeGeneratorMIPS64 intrinsic(codegen);
3062 intrinsic.Dispatch(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003063 return true;
3064 }
3065 return false;
3066}
3067
Vladimir Markodc151b22015-10-15 18:02:30 +01003068HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch(
3069 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
3070 MethodReference target_method ATTRIBUTE_UNUSED) {
3071 switch (desired_dispatch_info.method_load_kind) {
3072 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
3073 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
3074 // TODO: Implement these types. For the moment, we fall back to kDexCacheViaMethod.
3075 return HInvokeStaticOrDirect::DispatchInfo {
3076 HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod,
3077 HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod,
3078 0u,
3079 0u
3080 };
3081 default:
3082 break;
3083 }
3084 switch (desired_dispatch_info.code_ptr_location) {
3085 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
3086 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
3087 // TODO: Implement these types. For the moment, we fall back to kCallArtMethod.
3088 return HInvokeStaticOrDirect::DispatchInfo {
3089 desired_dispatch_info.method_load_kind,
3090 HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod,
3091 desired_dispatch_info.method_load_data,
3092 0u
3093 };
3094 default:
3095 return desired_dispatch_info;
3096 }
3097}
3098
Alexey Frunze4dda3372015-06-01 18:31:49 -07003099void CodeGeneratorMIPS64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
3100 // All registers are assumed to be correctly set up per the calling convention.
3101
Vladimir Marko58155012015-08-19 12:49:41 +00003102 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
3103 switch (invoke->GetMethodLoadKind()) {
3104 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
3105 // temp = thread->string_init_entrypoint
3106 __ LoadFromOffset(kLoadDoubleword,
3107 temp.AsRegister<GpuRegister>(),
3108 TR,
3109 invoke->GetStringInitOffset());
3110 break;
3111 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00003112 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00003113 break;
3114 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
3115 __ LoadConst64(temp.AsRegister<GpuRegister>(), invoke->GetMethodAddress());
3116 break;
3117 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
Vladimir Marko58155012015-08-19 12:49:41 +00003118 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
Vladimir Markodc151b22015-10-15 18:02:30 +01003119 // TODO: Implement these types.
3120 // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch().
3121 LOG(FATAL) << "Unsupported";
3122 UNREACHABLE();
Vladimir Marko58155012015-08-19 12:49:41 +00003123 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00003124 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00003125 GpuRegister reg = temp.AsRegister<GpuRegister>();
3126 GpuRegister method_reg;
3127 if (current_method.IsRegister()) {
3128 method_reg = current_method.AsRegister<GpuRegister>();
3129 } else {
3130 // TODO: use the appropriate DCHECK() here if possible.
3131 // DCHECK(invoke->GetLocations()->Intrinsified());
3132 DCHECK(!current_method.IsValid());
3133 method_reg = reg;
3134 __ Ld(reg, SP, kCurrentMethodStackOffset);
3135 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003136
Vladimir Marko58155012015-08-19 12:49:41 +00003137 // temp = temp->dex_cache_resolved_methods_;
Vladimir Marko05792b92015-08-03 11:56:49 +01003138 __ LoadFromOffset(kLoadDoubleword,
Vladimir Marko58155012015-08-19 12:49:41 +00003139 reg,
3140 method_reg,
Vladimir Marko05792b92015-08-03 11:56:49 +01003141 ArtMethod::DexCacheResolvedMethodsOffset(kMips64PointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00003142 // temp = temp[index_in_cache]
3143 uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index;
3144 __ LoadFromOffset(kLoadDoubleword,
3145 reg,
3146 reg,
3147 CodeGenerator::GetCachePointerOffset(index_in_cache));
3148 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003149 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003150 }
3151
Vladimir Marko58155012015-08-19 12:49:41 +00003152 switch (invoke->GetCodePtrLocation()) {
3153 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003154 __ Jialc(&frame_entry_label_, T9);
Vladimir Marko58155012015-08-19 12:49:41 +00003155 break;
3156 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
3157 // LR = invoke->GetDirectCodePtr();
3158 __ LoadConst64(T9, invoke->GetDirectCodePtr());
3159 // LR()
3160 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003161 __ Nop();
Vladimir Marko58155012015-08-19 12:49:41 +00003162 break;
Vladimir Marko58155012015-08-19 12:49:41 +00003163 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
Vladimir Markodc151b22015-10-15 18:02:30 +01003164 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
3165 // TODO: Implement these types.
3166 // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch().
3167 LOG(FATAL) << "Unsupported";
3168 UNREACHABLE();
Vladimir Marko58155012015-08-19 12:49:41 +00003169 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
3170 // T9 = callee_method->entry_point_from_quick_compiled_code_;
3171 __ LoadFromOffset(kLoadDoubleword,
3172 T9,
3173 callee_method.AsRegister<GpuRegister>(),
3174 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
3175 kMips64WordSize).Int32Value());
3176 // T9()
3177 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003178 __ Nop();
Vladimir Marko58155012015-08-19 12:49:41 +00003179 break;
3180 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003181 DCHECK(!IsLeafMethod());
3182}
3183
3184void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
3185 // When we do not run baseline, explicit clinit checks triggered by static
3186 // invokes must have been pruned by art::PrepareForRegisterAllocation.
3187 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
3188
3189 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
3190 return;
3191 }
3192
3193 LocationSummary* locations = invoke->GetLocations();
3194 codegen_->GenerateStaticOrDirectCall(invoke,
3195 locations->HasTemps()
3196 ? locations->GetTemp(0)
3197 : Location::NoLocation());
3198 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3199}
3200
Alexey Frunze53afca12015-11-05 16:34:23 -08003201void CodeGeneratorMIPS64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
Nicolas Geoffraye5234232015-12-02 09:06:11 +00003202 // Use the calling convention instead of the location of the receiver, as
3203 // intrinsics may have put the receiver in a different register. In the intrinsics
3204 // slow path, the arguments have been moved to the right place, so here we are
3205 // guaranteed that the receiver is the first register of the calling convention.
3206 InvokeDexCallingConvention calling_convention;
3207 GpuRegister receiver = calling_convention.GetRegisterAt(0);
3208
Alexey Frunze53afca12015-11-05 16:34:23 -08003209 GpuRegister temp = temp_location.AsRegister<GpuRegister>();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003210 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
3211 invoke->GetVTableIndex(), kMips64PointerSize).SizeValue();
3212 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3213 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64WordSize);
3214
3215 // temp = object->GetClass();
Nicolas Geoffraye5234232015-12-02 09:06:11 +00003216 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset);
Alexey Frunze53afca12015-11-05 16:34:23 -08003217 MaybeRecordImplicitNullCheck(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003218 // temp = temp->GetMethodAt(method_offset);
3219 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
3220 // T9 = temp->GetEntryPoint();
3221 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
3222 // T9();
3223 __ Jalr(T9);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003224 __ Nop();
Alexey Frunze53afca12015-11-05 16:34:23 -08003225}
3226
3227void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
3228 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
3229 return;
3230 }
3231
3232 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003233 DCHECK(!codegen_->IsLeafMethod());
3234 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3235}
3236
3237void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) {
Calin Juravle98893e12015-10-02 21:05:03 +01003238 InvokeRuntimeCallingConvention calling_convention;
3239 CodeGenerator::CreateLoadClassLocationSummary(
3240 cls,
3241 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Alexey Frunze00580bd2015-11-11 13:31:12 -08003242 calling_convention.GetReturnLocation(cls->GetType()));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003243}
3244
3245void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) {
3246 LocationSummary* locations = cls->GetLocations();
Calin Juravle98893e12015-10-02 21:05:03 +01003247 if (cls->NeedsAccessCheck()) {
3248 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
3249 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess),
3250 cls,
3251 cls->GetDexPc(),
3252 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003253 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Calin Juravle580b6092015-10-06 17:35:58 +01003254 return;
3255 }
3256
3257 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3258 GpuRegister current_method = locations->InAt(0).AsRegister<GpuRegister>();
3259 if (cls->IsReferrersClass()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003260 DCHECK(!cls->CanCallRuntime());
3261 DCHECK(!cls->MustGenerateClinitCheck());
3262 __ LoadFromOffset(kLoadUnsignedWord, out, current_method,
3263 ArtMethod::DeclaringClassOffset().Int32Value());
3264 } else {
Vladimir Marko05792b92015-08-03 11:56:49 +01003265 __ LoadFromOffset(kLoadDoubleword, out, current_method,
3266 ArtMethod::DexCacheResolvedTypesOffset(kMips64PointerSize).Int32Value());
Roland Levillain698fa972015-12-16 17:06:47 +00003267 __ LoadFromOffset(
3268 kLoadUnsignedWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Vladimir Marko05792b92015-08-03 11:56:49 +01003269 // TODO: We will need a read barrier here.
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00003270 if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) {
3271 DCHECK(cls->CanCallRuntime());
3272 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64(
3273 cls,
3274 cls,
3275 cls->GetDexPc(),
3276 cls->MustGenerateClinitCheck());
3277 codegen_->AddSlowPath(slow_path);
3278 if (!cls->IsInDexCache()) {
3279 __ Beqzc(out, slow_path->GetEntryLabel());
3280 }
3281 if (cls->MustGenerateClinitCheck()) {
3282 GenerateClassInitializationCheck(slow_path, out);
3283 } else {
3284 __ Bind(slow_path->GetExitLabel());
3285 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003286 }
3287 }
3288}
3289
David Brazdilcb1c0552015-08-04 16:22:25 +01003290static int32_t GetExceptionTlsOffset() {
3291 return Thread::ExceptionOffset<kMips64WordSize>().Int32Value();
3292}
3293
Alexey Frunze4dda3372015-06-01 18:31:49 -07003294void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) {
3295 LocationSummary* locations =
3296 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3297 locations->SetOut(Location::RequiresRegister());
3298}
3299
3300void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) {
3301 GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>();
David Brazdilcb1c0552015-08-04 16:22:25 +01003302 __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset());
3303}
3304
3305void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) {
3306 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
3307}
3308
3309void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
3310 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
Alexey Frunze4dda3372015-06-01 18:31:49 -07003311}
3312
3313void LocationsBuilderMIPS64::VisitLoadLocal(HLoadLocal* load) {
3314 load->SetLocations(nullptr);
3315}
3316
3317void InstructionCodeGeneratorMIPS64::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) {
3318 // Nothing to do, this is driven by the code generator.
3319}
3320
3321void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) {
Roland Levillain698fa972015-12-16 17:06:47 +00003322 LocationSummary::CallKind call_kind = load->IsInDexCache()
3323 ? LocationSummary::kNoCall
3324 : LocationSummary::kCallOnSlowPath;
Nicolas Geoffray917d0162015-11-24 18:25:35 +00003325 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003326 locations->SetInAt(0, Location::RequiresRegister());
3327 locations->SetOut(Location::RequiresRegister());
3328}
3329
3330void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003331 LocationSummary* locations = load->GetLocations();
3332 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
3333 GpuRegister current_method = locations->InAt(0).AsRegister<GpuRegister>();
3334 __ LoadFromOffset(kLoadUnsignedWord, out, current_method,
3335 ArtMethod::DeclaringClassOffset().Int32Value());
Vladimir Marko05792b92015-08-03 11:56:49 +01003336 __ LoadFromOffset(kLoadDoubleword, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Roland Levillain698fa972015-12-16 17:06:47 +00003337 __ LoadFromOffset(
3338 kLoadUnsignedWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
Vladimir Marko05792b92015-08-03 11:56:49 +01003339 // TODO: We will need a read barrier here.
Nicolas Geoffray917d0162015-11-24 18:25:35 +00003340
3341 if (!load->IsInDexCache()) {
3342 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS64(load);
3343 codegen_->AddSlowPath(slow_path);
3344 __ Beqzc(out, slow_path->GetEntryLabel());
3345 __ Bind(slow_path->GetExitLabel());
3346 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003347}
3348
3349void LocationsBuilderMIPS64::VisitLocal(HLocal* local) {
3350 local->SetLocations(nullptr);
3351}
3352
3353void InstructionCodeGeneratorMIPS64::VisitLocal(HLocal* local) {
3354 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
3355}
3356
3357void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) {
3358 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3359 locations->SetOut(Location::ConstantLocation(constant));
3360}
3361
3362void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
3363 // Will be generated at use site.
3364}
3365
3366void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
3367 LocationSummary* locations =
3368 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3369 InvokeRuntimeCallingConvention calling_convention;
3370 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3371}
3372
3373void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
3374 codegen_->InvokeRuntime(instruction->IsEnter()
3375 ? QUICK_ENTRY_POINT(pLockObject)
3376 : QUICK_ENTRY_POINT(pUnlockObject),
3377 instruction,
3378 instruction->GetDexPc(),
3379 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003380 if (instruction->IsEnter()) {
3381 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
3382 } else {
3383 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
3384 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003385}
3386
3387void LocationsBuilderMIPS64::VisitMul(HMul* mul) {
3388 LocationSummary* locations =
3389 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
3390 switch (mul->GetResultType()) {
3391 case Primitive::kPrimInt:
3392 case Primitive::kPrimLong:
3393 locations->SetInAt(0, Location::RequiresRegister());
3394 locations->SetInAt(1, Location::RequiresRegister());
3395 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3396 break;
3397
3398 case Primitive::kPrimFloat:
3399 case Primitive::kPrimDouble:
3400 locations->SetInAt(0, Location::RequiresFpuRegister());
3401 locations->SetInAt(1, Location::RequiresFpuRegister());
3402 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3403 break;
3404
3405 default:
3406 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
3407 }
3408}
3409
3410void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) {
3411 Primitive::Type type = instruction->GetType();
3412 LocationSummary* locations = instruction->GetLocations();
3413
3414 switch (type) {
3415 case Primitive::kPrimInt:
3416 case Primitive::kPrimLong: {
3417 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3418 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
3419 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
3420 if (type == Primitive::kPrimInt)
3421 __ MulR6(dst, lhs, rhs);
3422 else
3423 __ Dmul(dst, lhs, rhs);
3424 break;
3425 }
3426 case Primitive::kPrimFloat:
3427 case Primitive::kPrimDouble: {
3428 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3429 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
3430 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
3431 if (type == Primitive::kPrimFloat)
3432 __ MulS(dst, lhs, rhs);
3433 else
3434 __ MulD(dst, lhs, rhs);
3435 break;
3436 }
3437 default:
3438 LOG(FATAL) << "Unexpected mul type " << type;
3439 }
3440}
3441
3442void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) {
3443 LocationSummary* locations =
3444 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
3445 switch (neg->GetResultType()) {
3446 case Primitive::kPrimInt:
3447 case Primitive::kPrimLong:
3448 locations->SetInAt(0, Location::RequiresRegister());
3449 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3450 break;
3451
3452 case Primitive::kPrimFloat:
3453 case Primitive::kPrimDouble:
3454 locations->SetInAt(0, Location::RequiresFpuRegister());
3455 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3456 break;
3457
3458 default:
3459 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
3460 }
3461}
3462
3463void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) {
3464 Primitive::Type type = instruction->GetType();
3465 LocationSummary* locations = instruction->GetLocations();
3466
3467 switch (type) {
3468 case Primitive::kPrimInt:
3469 case Primitive::kPrimLong: {
3470 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3471 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
3472 if (type == Primitive::kPrimInt)
3473 __ Subu(dst, ZERO, src);
3474 else
3475 __ Dsubu(dst, ZERO, src);
3476 break;
3477 }
3478 case Primitive::kPrimFloat:
3479 case Primitive::kPrimDouble: {
3480 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3481 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
3482 if (type == Primitive::kPrimFloat)
3483 __ NegS(dst, src);
3484 else
3485 __ NegD(dst, src);
3486 break;
3487 }
3488 default:
3489 LOG(FATAL) << "Unexpected neg type " << type;
3490 }
3491}
3492
3493void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) {
3494 LocationSummary* locations =
3495 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3496 InvokeRuntimeCallingConvention calling_convention;
3497 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3498 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
3499 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3500 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
3501}
3502
3503void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) {
3504 LocationSummary* locations = instruction->GetLocations();
3505 // Move an uint16_t value to a register.
3506 __ LoadConst32(locations->GetTemp(0).AsRegister<GpuRegister>(), instruction->GetTypeIndex());
Calin Juravle175dc732015-08-25 15:42:32 +01003507 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
3508 instruction,
3509 instruction->GetDexPc(),
3510 nullptr);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003511 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
3512}
3513
3514void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) {
3515 LocationSummary* locations =
3516 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3517 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray729645a2015-11-19 13:29:02 +00003518 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3519 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003520 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
3521}
3522
3523void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) {
Calin Juravle175dc732015-08-25 15:42:32 +01003524 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
3525 instruction,
3526 instruction->GetDexPc(),
3527 nullptr);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003528 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
3529}
3530
3531void LocationsBuilderMIPS64::VisitNot(HNot* instruction) {
3532 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
3533 locations->SetInAt(0, Location::RequiresRegister());
3534 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3535}
3536
3537void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) {
3538 Primitive::Type type = instruction->GetType();
3539 LocationSummary* locations = instruction->GetLocations();
3540
3541 switch (type) {
3542 case Primitive::kPrimInt:
3543 case Primitive::kPrimLong: {
3544 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3545 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
3546 __ Nor(dst, src, ZERO);
3547 break;
3548 }
3549
3550 default:
3551 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
3552 }
3553}
3554
3555void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
3556 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
3557 locations->SetInAt(0, Location::RequiresRegister());
3558 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3559}
3560
3561void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
3562 LocationSummary* locations = instruction->GetLocations();
3563 __ Xori(locations->Out().AsRegister<GpuRegister>(),
3564 locations->InAt(0).AsRegister<GpuRegister>(),
3565 1);
3566}
3567
3568void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003569 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
3570 ? LocationSummary::kCallOnSlowPath
3571 : LocationSummary::kNoCall;
3572 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003573 locations->SetInAt(0, Location::RequiresRegister());
3574 if (instruction->HasUses()) {
3575 locations->SetOut(Location::SameAsFirstInput());
3576 }
3577}
3578
3579void InstructionCodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) {
3580 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3581 return;
3582 }
3583 Location obj = instruction->GetLocations()->InAt(0);
3584
3585 __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0);
3586 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3587}
3588
3589void InstructionCodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) {
3590 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS64(instruction);
3591 codegen_->AddSlowPath(slow_path);
3592
3593 Location obj = instruction->GetLocations()->InAt(0);
3594
3595 __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
3596}
3597
3598void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003599 if (codegen_->IsImplicitNullCheckAllowed(instruction)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003600 GenerateImplicitNullCheck(instruction);
3601 } else {
3602 GenerateExplicitNullCheck(instruction);
3603 }
3604}
3605
3606void LocationsBuilderMIPS64::VisitOr(HOr* instruction) {
3607 HandleBinaryOp(instruction);
3608}
3609
3610void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) {
3611 HandleBinaryOp(instruction);
3612}
3613
3614void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
3615 LOG(FATAL) << "Unreachable";
3616}
3617
3618void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) {
3619 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3620}
3621
3622void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) {
3623 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
3624 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3625 if (location.IsStackSlot()) {
3626 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3627 } else if (location.IsDoubleStackSlot()) {
3628 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3629 }
3630 locations->SetOut(location);
3631}
3632
3633void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction
3634 ATTRIBUTE_UNUSED) {
3635 // Nothing to do, the parameter is already at its location.
3636}
3637
3638void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) {
3639 LocationSummary* locations =
3640 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3641 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3642}
3643
3644void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction
3645 ATTRIBUTE_UNUSED) {
3646 // Nothing to do, the method is already at its location.
3647}
3648
3649void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) {
3650 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
3651 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
3652 locations->SetInAt(i, Location::Any());
3653 }
3654 locations->SetOut(Location::Any());
3655}
3656
3657void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
3658 LOG(FATAL) << "Unreachable";
3659}
3660
3661void LocationsBuilderMIPS64::VisitRem(HRem* rem) {
3662 Primitive::Type type = rem->GetResultType();
3663 LocationSummary::CallKind call_kind =
3664 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
3665 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
3666
3667 switch (type) {
3668 case Primitive::kPrimInt:
3669 case Primitive::kPrimLong:
3670 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunzec857c742015-09-23 15:12:39 -07003671 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Alexey Frunze4dda3372015-06-01 18:31:49 -07003672 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3673 break;
3674
3675 case Primitive::kPrimFloat:
3676 case Primitive::kPrimDouble: {
3677 InvokeRuntimeCallingConvention calling_convention;
3678 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3679 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
3680 locations->SetOut(calling_convention.GetReturnLocation(type));
3681 break;
3682 }
3683
3684 default:
3685 LOG(FATAL) << "Unexpected rem type " << type;
3686 }
3687}
3688
3689void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) {
3690 Primitive::Type type = instruction->GetType();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003691
3692 switch (type) {
3693 case Primitive::kPrimInt:
Alexey Frunzec857c742015-09-23 15:12:39 -07003694 case Primitive::kPrimLong:
3695 GenerateDivRemIntegral(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003696 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003697
3698 case Primitive::kPrimFloat:
3699 case Primitive::kPrimDouble: {
3700 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
3701 : QUICK_ENTRY_POINT(pFmod);
3702 codegen_->InvokeRuntime(entry_offset, instruction, instruction->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003703 if (type == Primitive::kPrimFloat) {
3704 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
3705 } else {
3706 CheckEntrypointTypes<kQuickFmod, double, double, double>();
3707 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003708 break;
3709 }
3710 default:
3711 LOG(FATAL) << "Unexpected rem type " << type;
3712 }
3713}
3714
3715void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
3716 memory_barrier->SetLocations(nullptr);
3717}
3718
3719void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
3720 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
3721}
3722
3723void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) {
3724 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret);
3725 Primitive::Type return_type = ret->InputAt(0)->GetType();
3726 locations->SetInAt(0, Mips64ReturnLocation(return_type));
3727}
3728
3729void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
3730 codegen_->GenerateFrameExit();
3731}
3732
3733void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) {
3734 ret->SetLocations(nullptr);
3735}
3736
3737void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
3738 codegen_->GenerateFrameExit();
3739}
3740
Alexey Frunze92d90602015-12-18 18:16:36 -08003741void LocationsBuilderMIPS64::VisitRor(HRor* ror) {
3742 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003743}
3744
Alexey Frunze92d90602015-12-18 18:16:36 -08003745void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) {
3746 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003747}
3748
Alexey Frunze4dda3372015-06-01 18:31:49 -07003749void LocationsBuilderMIPS64::VisitShl(HShl* shl) {
3750 HandleShift(shl);
3751}
3752
3753void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) {
3754 HandleShift(shl);
3755}
3756
3757void LocationsBuilderMIPS64::VisitShr(HShr* shr) {
3758 HandleShift(shr);
3759}
3760
3761void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) {
3762 HandleShift(shr);
3763}
3764
3765void LocationsBuilderMIPS64::VisitStoreLocal(HStoreLocal* store) {
3766 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
3767 Primitive::Type field_type = store->InputAt(1)->GetType();
3768 switch (field_type) {
3769 case Primitive::kPrimNot:
3770 case Primitive::kPrimBoolean:
3771 case Primitive::kPrimByte:
3772 case Primitive::kPrimChar:
3773 case Primitive::kPrimShort:
3774 case Primitive::kPrimInt:
3775 case Primitive::kPrimFloat:
3776 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
3777 break;
3778
3779 case Primitive::kPrimLong:
3780 case Primitive::kPrimDouble:
3781 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
3782 break;
3783
3784 default:
3785 LOG(FATAL) << "Unimplemented local type " << field_type;
3786 }
3787}
3788
3789void InstructionCodeGeneratorMIPS64::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) {
3790}
3791
3792void LocationsBuilderMIPS64::VisitSub(HSub* instruction) {
3793 HandleBinaryOp(instruction);
3794}
3795
3796void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) {
3797 HandleBinaryOp(instruction);
3798}
3799
3800void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3801 HandleFieldGet(instruction, instruction->GetFieldInfo());
3802}
3803
3804void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3805 HandleFieldGet(instruction, instruction->GetFieldInfo());
3806}
3807
3808void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3809 HandleFieldSet(instruction, instruction->GetFieldInfo());
3810}
3811
3812void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3813 HandleFieldSet(instruction, instruction->GetFieldInfo());
3814}
3815
Calin Juravlee460d1d2015-09-29 04:52:17 +01003816void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet(
3817 HUnresolvedInstanceFieldGet* instruction) {
3818 FieldAccessCallingConventionMIPS64 calling_convention;
3819 codegen_->CreateUnresolvedFieldLocationSummary(
3820 instruction, instruction->GetFieldType(), calling_convention);
3821}
3822
3823void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet(
3824 HUnresolvedInstanceFieldGet* instruction) {
3825 FieldAccessCallingConventionMIPS64 calling_convention;
3826 codegen_->GenerateUnresolvedFieldAccess(instruction,
3827 instruction->GetFieldType(),
3828 instruction->GetFieldIndex(),
3829 instruction->GetDexPc(),
3830 calling_convention);
3831}
3832
3833void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet(
3834 HUnresolvedInstanceFieldSet* instruction) {
3835 FieldAccessCallingConventionMIPS64 calling_convention;
3836 codegen_->CreateUnresolvedFieldLocationSummary(
3837 instruction, instruction->GetFieldType(), calling_convention);
3838}
3839
3840void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet(
3841 HUnresolvedInstanceFieldSet* instruction) {
3842 FieldAccessCallingConventionMIPS64 calling_convention;
3843 codegen_->GenerateUnresolvedFieldAccess(instruction,
3844 instruction->GetFieldType(),
3845 instruction->GetFieldIndex(),
3846 instruction->GetDexPc(),
3847 calling_convention);
3848}
3849
3850void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet(
3851 HUnresolvedStaticFieldGet* instruction) {
3852 FieldAccessCallingConventionMIPS64 calling_convention;
3853 codegen_->CreateUnresolvedFieldLocationSummary(
3854 instruction, instruction->GetFieldType(), calling_convention);
3855}
3856
3857void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet(
3858 HUnresolvedStaticFieldGet* instruction) {
3859 FieldAccessCallingConventionMIPS64 calling_convention;
3860 codegen_->GenerateUnresolvedFieldAccess(instruction,
3861 instruction->GetFieldType(),
3862 instruction->GetFieldIndex(),
3863 instruction->GetDexPc(),
3864 calling_convention);
3865}
3866
3867void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet(
3868 HUnresolvedStaticFieldSet* instruction) {
3869 FieldAccessCallingConventionMIPS64 calling_convention;
3870 codegen_->CreateUnresolvedFieldLocationSummary(
3871 instruction, instruction->GetFieldType(), calling_convention);
3872}
3873
3874void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet(
3875 HUnresolvedStaticFieldSet* instruction) {
3876 FieldAccessCallingConventionMIPS64 calling_convention;
3877 codegen_->GenerateUnresolvedFieldAccess(instruction,
3878 instruction->GetFieldType(),
3879 instruction->GetFieldIndex(),
3880 instruction->GetDexPc(),
3881 calling_convention);
3882}
3883
Alexey Frunze4dda3372015-06-01 18:31:49 -07003884void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
3885 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3886}
3887
3888void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
3889 HBasicBlock* block = instruction->GetBlock();
3890 if (block->GetLoopInformation() != nullptr) {
3891 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3892 // The back edge will generate the suspend check.
3893 return;
3894 }
3895 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3896 // The goto will generate the suspend check.
3897 return;
3898 }
3899 GenerateSuspendCheck(instruction, nullptr);
3900}
3901
3902void LocationsBuilderMIPS64::VisitTemporary(HTemporary* temp) {
3903 temp->SetLocations(nullptr);
3904}
3905
3906void InstructionCodeGeneratorMIPS64::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) {
3907 // Nothing to do, this is driven by the code generator.
3908}
3909
3910void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) {
3911 LocationSummary* locations =
3912 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3913 InvokeRuntimeCallingConvention calling_convention;
3914 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3915}
3916
3917void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) {
3918 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException),
3919 instruction,
3920 instruction->GetDexPc(),
3921 nullptr);
3922 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
3923}
3924
3925void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
3926 Primitive::Type input_type = conversion->GetInputType();
3927 Primitive::Type result_type = conversion->GetResultType();
3928 DCHECK_NE(input_type, result_type);
3929
3930 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
3931 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
3932 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
3933 }
3934
3935 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
3936 if ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) ||
3937 (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type))) {
3938 call_kind = LocationSummary::kCall;
3939 }
3940
3941 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
3942
3943 if (call_kind == LocationSummary::kNoCall) {
3944 if (Primitive::IsFloatingPointType(input_type)) {
3945 locations->SetInAt(0, Location::RequiresFpuRegister());
3946 } else {
3947 locations->SetInAt(0, Location::RequiresRegister());
3948 }
3949
3950 if (Primitive::IsFloatingPointType(result_type)) {
3951 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3952 } else {
3953 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3954 }
3955 } else {
3956 InvokeRuntimeCallingConvention calling_convention;
3957
3958 if (Primitive::IsFloatingPointType(input_type)) {
3959 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3960 } else {
3961 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3962 }
3963
3964 locations->SetOut(calling_convention.GetReturnLocation(result_type));
3965 }
3966}
3967
3968void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
3969 LocationSummary* locations = conversion->GetLocations();
3970 Primitive::Type result_type = conversion->GetResultType();
3971 Primitive::Type input_type = conversion->GetInputType();
3972
3973 DCHECK_NE(input_type, result_type);
3974
3975 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
3976 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3977 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
3978
3979 switch (result_type) {
3980 case Primitive::kPrimChar:
3981 __ Andi(dst, src, 0xFFFF);
3982 break;
3983 case Primitive::kPrimByte:
3984 // long is never converted into types narrower than int directly,
3985 // so SEB and SEH can be used without ever causing unpredictable results
3986 // on 64-bit inputs
3987 DCHECK(input_type != Primitive::kPrimLong);
3988 __ Seb(dst, src);
3989 break;
3990 case Primitive::kPrimShort:
3991 // long is never converted into types narrower than int directly,
3992 // so SEB and SEH can be used without ever causing unpredictable results
3993 // on 64-bit inputs
3994 DCHECK(input_type != Primitive::kPrimLong);
3995 __ Seh(dst, src);
3996 break;
3997 case Primitive::kPrimInt:
3998 case Primitive::kPrimLong:
3999 // Sign-extend 32-bit int into bits 32 through 63 for
4000 // int-to-long and long-to-int conversions
4001 __ Sll(dst, src, 0);
4002 break;
4003
4004 default:
4005 LOG(FATAL) << "Unexpected type conversion from " << input_type
4006 << " to " << result_type;
4007 }
4008 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
4009 if (input_type != Primitive::kPrimLong) {
4010 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
4011 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
4012 __ Mtc1(src, FTMP);
4013 if (result_type == Primitive::kPrimFloat) {
4014 __ Cvtsw(dst, FTMP);
4015 } else {
4016 __ Cvtdw(dst, FTMP);
4017 }
4018 } else {
4019 int32_t entry_offset = (result_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pL2f)
4020 : QUICK_ENTRY_POINT(pL2d);
4021 codegen_->InvokeRuntime(entry_offset,
4022 conversion,
4023 conversion->GetDexPc(),
4024 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00004025 if (result_type == Primitive::kPrimFloat) {
4026 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
4027 } else {
4028 CheckEntrypointTypes<kQuickL2d, double, int64_t>();
4029 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004030 }
4031 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
4032 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
4033 int32_t entry_offset;
4034 if (result_type != Primitive::kPrimLong) {
4035 entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2iz)
4036 : QUICK_ENTRY_POINT(pD2iz);
4037 } else {
4038 entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2l)
4039 : QUICK_ENTRY_POINT(pD2l);
4040 }
4041 codegen_->InvokeRuntime(entry_offset,
4042 conversion,
4043 conversion->GetDexPc(),
4044 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00004045 if (result_type != Primitive::kPrimLong) {
4046 if (input_type == Primitive::kPrimFloat) {
4047 CheckEntrypointTypes<kQuickF2iz, int32_t, float>();
4048 } else {
4049 CheckEntrypointTypes<kQuickD2iz, int32_t, double>();
4050 }
4051 } else {
4052 if (input_type == Primitive::kPrimFloat) {
4053 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
4054 } else {
4055 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
4056 }
4057 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07004058 } else if (Primitive::IsFloatingPointType(result_type) &&
4059 Primitive::IsFloatingPointType(input_type)) {
4060 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
4061 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
4062 if (result_type == Primitive::kPrimFloat) {
4063 __ Cvtsd(dst, src);
4064 } else {
4065 __ Cvtds(dst, src);
4066 }
4067 } else {
4068 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
4069 << " to " << result_type;
4070 }
4071}
4072
4073void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) {
4074 HandleShift(ushr);
4075}
4076
4077void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) {
4078 HandleShift(ushr);
4079}
4080
4081void LocationsBuilderMIPS64::VisitXor(HXor* instruction) {
4082 HandleBinaryOp(instruction);
4083}
4084
4085void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) {
4086 HandleBinaryOp(instruction);
4087}
4088
4089void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
4090 // Nothing to do, this should be removed during prepare for register allocator.
4091 LOG(FATAL) << "Unreachable";
4092}
4093
4094void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
4095 // Nothing to do, this should be removed during prepare for register allocator.
4096 LOG(FATAL) << "Unreachable";
4097}
4098
4099void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004100 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004101}
4102
4103void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004104 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004105}
4106
4107void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004108 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004109}
4110
4111void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004112 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004113}
4114
4115void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004116 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004117}
4118
4119void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004120 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004121}
4122
4123void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004124 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004125}
4126
4127void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004128 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004129}
4130
4131void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004132 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004133}
4134
4135void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004136 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004137}
4138
4139void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004140 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004141}
4142
4143void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004144 HandleCondition(comp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07004145}
4146
Aart Bike9f37602015-10-09 11:15:55 -07004147void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004148 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004149}
4150
4151void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004152 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004153}
4154
4155void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004156 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004157}
4158
4159void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004160 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004161}
4162
4163void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004164 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004165}
4166
4167void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004168 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004169}
4170
4171void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004172 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004173}
4174
4175void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00004176 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07004177}
4178
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01004179void LocationsBuilderMIPS64::VisitFakeString(HFakeString* instruction) {
4180 DCHECK(codegen_->IsBaseline());
4181 LocationSummary* locations =
4182 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4183 locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
4184}
4185
4186void InstructionCodeGeneratorMIPS64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
4187 DCHECK(codegen_->IsBaseline());
4188 // Will be generated at use site.
4189}
4190
Mark Mendellfe57faa2015-09-18 09:26:15 -04004191// Simple implementation of packed switch - generate cascaded compare/jumps.
4192void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
4193 LocationSummary* locations =
4194 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
4195 locations->SetInAt(0, Location::RequiresRegister());
4196}
4197
4198void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
4199 int32_t lower_bound = switch_instr->GetStartValue();
4200 int32_t num_entries = switch_instr->GetNumEntries();
4201 LocationSummary* locations = switch_instr->GetLocations();
4202 GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>();
4203 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
4204
Vladimir Markof3e0ee22015-12-17 15:23:13 +00004205 // Create a set of compare/jumps.
4206 GpuRegister temp_reg = TMP;
4207 if (IsInt<16>(-lower_bound)) {
4208 __ Addiu(temp_reg, value_reg, -lower_bound);
4209 } else {
4210 __ LoadConst32(AT, -lower_bound);
4211 __ Addu(temp_reg, value_reg, AT);
4212 }
4213 // Jump to default if index is negative
4214 // Note: We don't check the case that index is positive while value < lower_bound, because in
4215 // this case, index >= num_entries must be true. So that we can save one branch instruction.
4216 __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block));
4217
Mark Mendellfe57faa2015-09-18 09:26:15 -04004218 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00004219 // Jump to successors[0] if value == lower_bound.
4220 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0]));
4221 int32_t last_index = 0;
4222 for (; num_entries - last_index > 2; last_index += 2) {
4223 __ Addiu(temp_reg, temp_reg, -2);
4224 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
4225 __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
4226 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
4227 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
4228 }
4229 if (num_entries - last_index == 2) {
4230 // The last missing case_value.
4231 __ Addiu(temp_reg, temp_reg, -1);
4232 __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Mark Mendellfe57faa2015-09-18 09:26:15 -04004233 }
4234
4235 // And the default for any other value.
4236 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07004237 __ Bc(codegen_->GetLabelOf(default_block));
Mark Mendellfe57faa2015-09-18 09:26:15 -04004238 }
4239}
4240
Alexey Frunze4dda3372015-06-01 18:31:49 -07004241} // namespace mips64
4242} // namespace art