Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1 | /* |
| 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 Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
| 20 | #include "code_generator_utils.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 21 | #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 Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 25 | #include "intrinsics_mips64.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 26 | #include "mirror/array-inl.h" |
| 27 | #include "mirror/class-inl.h" |
| 28 | #include "offsets.h" |
| 29 | #include "thread.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 30 | #include "utils/assembler.h" |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 31 | #include "utils/mips64/assembler_mips64.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 32 | #include "utils/stack_checks.h" |
| 33 | |
| 34 | namespace art { |
| 35 | namespace mips64 { |
| 36 | |
| 37 | static constexpr int kCurrentMethodStackOffset = 0; |
| 38 | static constexpr GpuRegister kMethodRegisterArgument = A0; |
| 39 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 40 | Location Mips64ReturnLocation(Primitive::Type return_type) { |
| 41 | switch (return_type) { |
| 42 | case Primitive::kPrimBoolean: |
| 43 | case Primitive::kPrimByte: |
| 44 | case Primitive::kPrimChar: |
| 45 | case Primitive::kPrimShort: |
| 46 | case Primitive::kPrimInt: |
| 47 | case Primitive::kPrimNot: |
| 48 | case Primitive::kPrimLong: |
| 49 | return Location::RegisterLocation(V0); |
| 50 | |
| 51 | case Primitive::kPrimFloat: |
| 52 | case Primitive::kPrimDouble: |
| 53 | return Location::FpuRegisterLocation(F0); |
| 54 | |
| 55 | case Primitive::kPrimVoid: |
| 56 | return Location(); |
| 57 | } |
| 58 | UNREACHABLE(); |
| 59 | } |
| 60 | |
| 61 | Location InvokeDexCallingConventionVisitorMIPS64::GetReturnLocation(Primitive::Type type) const { |
| 62 | return Mips64ReturnLocation(type); |
| 63 | } |
| 64 | |
| 65 | Location InvokeDexCallingConventionVisitorMIPS64::GetMethodLocation() const { |
| 66 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 67 | } |
| 68 | |
| 69 | Location InvokeDexCallingConventionVisitorMIPS64::GetNextLocation(Primitive::Type type) { |
| 70 | Location next_location; |
| 71 | if (type == Primitive::kPrimVoid) { |
| 72 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 73 | } |
| 74 | |
| 75 | if (Primitive::IsFloatingPointType(type) && |
| 76 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 77 | next_location = Location::FpuRegisterLocation( |
| 78 | calling_convention.GetFpuRegisterAt(float_index_++)); |
| 79 | gp_index_++; |
| 80 | } else if (!Primitive::IsFloatingPointType(type) && |
| 81 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 82 | next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index_++)); |
| 83 | float_index_++; |
| 84 | } else { |
| 85 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 86 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 87 | : Location::StackSlot(stack_offset); |
| 88 | } |
| 89 | |
| 90 | // Space on the stack is reserved for all arguments. |
| 91 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
| 92 | |
| 93 | // TODO: review |
| 94 | |
| 95 | // TODO: shouldn't we use a whole machine word per argument on the stack? |
| 96 | // Implicit 4-byte method pointer (and such) will cause misalignment. |
| 97 | |
| 98 | return next_location; |
| 99 | } |
| 100 | |
| 101 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type type) { |
| 102 | return Mips64ReturnLocation(type); |
| 103 | } |
| 104 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 105 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 106 | #define __ down_cast<CodeGeneratorMIPS64*>(codegen)->GetAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 107 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value() |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 108 | |
| 109 | class BoundsCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 110 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 111 | explicit BoundsCheckSlowPathMIPS64(HBoundsCheck* instruction) : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 112 | |
| 113 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 114 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 115 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 116 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 117 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 118 | // Live registers will be restored in the catch block if caught. |
| 119 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 120 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 121 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 122 | // move resolver. |
| 123 | InvokeRuntimeCallingConvention calling_convention; |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 124 | codegen->EmitParallelMoves(locations->InAt(0), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 125 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 126 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 127 | locations->InAt(1), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 128 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 129 | Primitive::kPrimInt); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 130 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 131 | ? kQuickThrowStringBounds |
| 132 | : kQuickThrowArrayBounds; |
| 133 | mips64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 134 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 135 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 136 | } |
| 137 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 138 | bool IsFatal() const OVERRIDE { return true; } |
| 139 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 140 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS64"; } |
| 141 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 142 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 143 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS64); |
| 144 | }; |
| 145 | |
| 146 | class DivZeroCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 147 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 148 | explicit DivZeroCheckSlowPathMIPS64(HDivZeroCheck* instruction) : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 149 | |
| 150 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 151 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 152 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 153 | mips64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 154 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 155 | } |
| 156 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 157 | bool IsFatal() const OVERRIDE { return true; } |
| 158 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 159 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS64"; } |
| 160 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 161 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 162 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS64); |
| 163 | }; |
| 164 | |
| 165 | class LoadClassSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 166 | public: |
| 167 | LoadClassSlowPathMIPS64(HLoadClass* cls, |
| 168 | HInstruction* at, |
| 169 | uint32_t dex_pc, |
| 170 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 171 | : SlowPathCodeMIPS64(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 172 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 173 | } |
| 174 | |
| 175 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 176 | LocationSummary* locations = at_->GetLocations(); |
| 177 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 178 | |
| 179 | __ Bind(GetEntryLabel()); |
| 180 | SaveLiveRegisters(codegen, locations); |
| 181 | |
| 182 | InvokeRuntimeCallingConvention calling_convention; |
| 183 | __ LoadConst32(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 184 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 185 | : kQuickInitializeType; |
| 186 | mips64_codegen->InvokeRuntime(entrypoint, at_, dex_pc_, this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 187 | if (do_clinit_) { |
| 188 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 189 | } else { |
| 190 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 191 | } |
| 192 | |
| 193 | // Move the class to the desired location. |
| 194 | Location out = locations->Out(); |
| 195 | if (out.IsValid()) { |
| 196 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 197 | Primitive::Type type = at_->GetType(); |
| 198 | mips64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
| 199 | } |
| 200 | |
| 201 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 202 | __ Bc(GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 205 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS64"; } |
| 206 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 207 | private: |
| 208 | // The class this slow path will load. |
| 209 | HLoadClass* const cls_; |
| 210 | |
| 211 | // The instruction where this slow path is happening. |
| 212 | // (Might be the load class or an initialization check). |
| 213 | HInstruction* const at_; |
| 214 | |
| 215 | // The dex PC of `at_`. |
| 216 | const uint32_t dex_pc_; |
| 217 | |
| 218 | // Whether to initialize the class. |
| 219 | const bool do_clinit_; |
| 220 | |
| 221 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS64); |
| 222 | }; |
| 223 | |
| 224 | class LoadStringSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 225 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 226 | explicit LoadStringSlowPathMIPS64(HLoadString* instruction) : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 227 | |
| 228 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 229 | LocationSummary* locations = instruction_->GetLocations(); |
| 230 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 231 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 232 | |
| 233 | __ Bind(GetEntryLabel()); |
| 234 | SaveLiveRegisters(codegen, locations); |
| 235 | |
| 236 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 237 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 238 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 239 | mips64_codegen->InvokeRuntime(kQuickResolveString, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 240 | instruction_, |
| 241 | instruction_->GetDexPc(), |
| 242 | this); |
| 243 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 244 | Primitive::Type type = instruction_->GetType(); |
| 245 | mips64_codegen->MoveLocation(locations->Out(), |
| 246 | calling_convention.GetReturnLocation(type), |
| 247 | type); |
| 248 | |
| 249 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 250 | __ Bc(GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 253 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS64"; } |
| 254 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 255 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 256 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS64); |
| 257 | }; |
| 258 | |
| 259 | class NullCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 260 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 261 | explicit NullCheckSlowPathMIPS64(HNullCheck* instr) : SlowPathCodeMIPS64(instr) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 262 | |
| 263 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 264 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 265 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 266 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 267 | // Live registers will be restored in the catch block if caught. |
| 268 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 269 | } |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 270 | mips64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 271 | instruction_, |
| 272 | instruction_->GetDexPc(), |
| 273 | this); |
| 274 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 275 | } |
| 276 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 277 | bool IsFatal() const OVERRIDE { return true; } |
| 278 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 279 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS64"; } |
| 280 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 281 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 282 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS64); |
| 283 | }; |
| 284 | |
| 285 | class SuspendCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 286 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 287 | SuspendCheckSlowPathMIPS64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 288 | : SlowPathCodeMIPS64(instruction), successor_(successor) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 289 | |
| 290 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 291 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 292 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 293 | mips64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 294 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 295 | if (successor_ == nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 296 | __ Bc(GetReturnLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 297 | } else { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 298 | __ Bc(mips64_codegen->GetLabelOf(successor_)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 302 | Mips64Label* GetReturnLabel() { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 303 | DCHECK(successor_ == nullptr); |
| 304 | return &return_label_; |
| 305 | } |
| 306 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 307 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS64"; } |
| 308 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 309 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 310 | // If not null, the block to branch to after the suspend check. |
| 311 | HBasicBlock* const successor_; |
| 312 | |
| 313 | // If `successor_` is null, the label to branch to after the suspend check. |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 314 | Mips64Label return_label_; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 315 | |
| 316 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS64); |
| 317 | }; |
| 318 | |
| 319 | class TypeCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 320 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 321 | explicit TypeCheckSlowPathMIPS64(HInstruction* instruction) : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 322 | |
| 323 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 324 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 325 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) : locations->Out(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 326 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 327 | DCHECK(instruction_->IsCheckCast() |
| 328 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 329 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 330 | |
| 331 | __ Bind(GetEntryLabel()); |
| 332 | SaveLiveRegisters(codegen, locations); |
| 333 | |
| 334 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 335 | // move resolver. |
| 336 | InvokeRuntimeCallingConvention calling_convention; |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 337 | codegen->EmitParallelMoves(locations->InAt(1), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 338 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 339 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 340 | object_class, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 341 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 342 | Primitive::kPrimNot); |
| 343 | |
| 344 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 345 | mips64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 346 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 347 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 348 | Primitive::Type ret_type = instruction_->GetType(); |
| 349 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 350 | mips64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 351 | } else { |
| 352 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 353 | mips64_codegen->InvokeRuntime(kQuickCheckCast, instruction_, dex_pc, this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 354 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
| 355 | } |
| 356 | |
| 357 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 358 | __ Bc(GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 361 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS64"; } |
| 362 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 363 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 364 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS64); |
| 365 | }; |
| 366 | |
| 367 | class DeoptimizationSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 368 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 369 | explicit DeoptimizationSlowPathMIPS64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 370 | : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 371 | |
| 372 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 373 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 374 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 375 | mips64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 376 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 379 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS64"; } |
| 380 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 381 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 382 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64); |
| 383 | }; |
| 384 | |
| 385 | CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph, |
| 386 | const Mips64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 387 | const CompilerOptions& compiler_options, |
| 388 | OptimizingCompilerStats* stats) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 389 | : CodeGenerator(graph, |
| 390 | kNumberOfGpuRegisters, |
| 391 | kNumberOfFpuRegisters, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 392 | /* number_of_register_pairs */ 0, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 393 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 394 | arraysize(kCoreCalleeSaves)), |
| 395 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 396 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 397 | compiler_options, |
| 398 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 399 | block_labels_(nullptr), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 400 | location_builder_(graph, this), |
| 401 | instruction_visitor_(graph, this), |
| 402 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 403 | assembler_(graph->GetArena()), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 404 | isa_features_(isa_features) { |
| 405 | // Save RA (containing the return address) to mimic Quick. |
| 406 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 407 | } |
| 408 | |
| 409 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 410 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 411 | #define __ down_cast<Mips64Assembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 412 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value() |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 413 | |
| 414 | void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 415 | // Ensure that we fix up branches. |
| 416 | __ FinalizeCode(); |
| 417 | |
| 418 | // Adjust native pc offsets in stack maps. |
| 419 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 420 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 421 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 422 | DCHECK_GE(new_position, old_position); |
| 423 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 424 | } |
| 425 | |
| 426 | // Adjust pc offsets for the disassembly information. |
| 427 | if (disasm_info_ != nullptr) { |
| 428 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 429 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 430 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 431 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 432 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 433 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 434 | } |
| 435 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 436 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 437 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 438 | } |
| 439 | } |
| 440 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 441 | CodeGenerator::Finalize(allocator); |
| 442 | } |
| 443 | |
| 444 | Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const { |
| 445 | return codegen_->GetAssembler(); |
| 446 | } |
| 447 | |
| 448 | void ParallelMoveResolverMIPS64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 449 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 450 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 451 | } |
| 452 | |
| 453 | void ParallelMoveResolverMIPS64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 454 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 455 | codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType()); |
| 456 | } |
| 457 | |
| 458 | void ParallelMoveResolverMIPS64::RestoreScratch(int reg) { |
| 459 | // Pop reg |
| 460 | __ Ld(GpuRegister(reg), SP, 0); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 461 | __ DecreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | void ParallelMoveResolverMIPS64::SpillScratch(int reg) { |
| 465 | // Push reg |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 466 | __ IncreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 467 | __ Sd(GpuRegister(reg), SP, 0); |
| 468 | } |
| 469 | |
| 470 | void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) { |
| 471 | LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord; |
| 472 | StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord; |
| 473 | // Allocate a scratch register other than TMP, if available. |
| 474 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 475 | // automatically unspilled when the scratch scope object is destroyed). |
| 476 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 477 | // If V0 spills onto the stack, SP-relative offsets need to be adjusted. |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 478 | int stack_offset = ensure_scratch.IsSpilled() ? kMips64DoublewordSize : 0; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 479 | __ LoadFromOffset(load_type, |
| 480 | GpuRegister(ensure_scratch.GetRegister()), |
| 481 | SP, |
| 482 | index1 + stack_offset); |
| 483 | __ LoadFromOffset(load_type, |
| 484 | TMP, |
| 485 | SP, |
| 486 | index2 + stack_offset); |
| 487 | __ StoreToOffset(store_type, |
| 488 | GpuRegister(ensure_scratch.GetRegister()), |
| 489 | SP, |
| 490 | index2 + stack_offset); |
| 491 | __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset); |
| 492 | } |
| 493 | |
| 494 | static dwarf::Reg DWARFReg(GpuRegister reg) { |
| 495 | return dwarf::Reg::Mips64Core(static_cast<int>(reg)); |
| 496 | } |
| 497 | |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 498 | static dwarf::Reg DWARFReg(FpuRegister reg) { |
| 499 | return dwarf::Reg::Mips64Fp(static_cast<int>(reg)); |
| 500 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 501 | |
| 502 | void CodeGeneratorMIPS64::GenerateFrameEntry() { |
| 503 | __ Bind(&frame_entry_label_); |
| 504 | |
| 505 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips64) || !IsLeafMethod(); |
| 506 | |
| 507 | if (do_overflow_check) { |
| 508 | __ LoadFromOffset(kLoadWord, |
| 509 | ZERO, |
| 510 | SP, |
| 511 | -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips64))); |
| 512 | RecordPcInfo(nullptr, 0); |
| 513 | } |
| 514 | |
| 515 | // TODO: anything related to T9/GP/GOT/PIC/.so's? |
| 516 | |
| 517 | if (HasEmptyFrame()) { |
| 518 | return; |
| 519 | } |
| 520 | |
| 521 | // Make sure the frame size isn't unreasonably large. Per the various APIs |
| 522 | // it looks like it should always be less than 2GB in size, which allows |
| 523 | // us using 32-bit signed offsets from the stack pointer. |
| 524 | if (GetFrameSize() > 0x7FFFFFFF) |
| 525 | LOG(FATAL) << "Stack frame larger than 2GB"; |
| 526 | |
| 527 | // Spill callee-saved registers. |
| 528 | // Note that their cumulative size is small and they can be indexed using |
| 529 | // 16-bit offsets. |
| 530 | |
| 531 | // TODO: increment/decrement SP in one step instead of two or remove this comment. |
| 532 | |
| 533 | uint32_t ofs = FrameEntrySpillSize(); |
| 534 | __ IncreaseFrameSize(ofs); |
| 535 | |
| 536 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 537 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 538 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 539 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 540 | __ Sd(reg, SP, ofs); |
| 541 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 546 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 547 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 548 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 549 | __ Sdc1(reg, SP, ofs); |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 550 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
| 554 | // Allocate the rest of the frame and store the current method pointer |
| 555 | // at its end. |
| 556 | |
| 557 | __ IncreaseFrameSize(GetFrameSize() - FrameEntrySpillSize()); |
| 558 | |
| 559 | static_assert(IsInt<16>(kCurrentMethodStackOffset), |
| 560 | "kCurrentMethodStackOffset must fit into int16_t"); |
| 561 | __ Sd(kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
| 562 | } |
| 563 | |
| 564 | void CodeGeneratorMIPS64::GenerateFrameExit() { |
| 565 | __ cfi().RememberState(); |
| 566 | |
| 567 | // TODO: anything related to T9/GP/GOT/PIC/.so's? |
| 568 | |
| 569 | if (!HasEmptyFrame()) { |
| 570 | // Deallocate the rest of the frame. |
| 571 | |
| 572 | __ DecreaseFrameSize(GetFrameSize() - FrameEntrySpillSize()); |
| 573 | |
| 574 | // Restore callee-saved registers. |
| 575 | // Note that their cumulative size is small and they can be indexed using |
| 576 | // 16-bit offsets. |
| 577 | |
| 578 | // TODO: increment/decrement SP in one step instead of two or remove this comment. |
| 579 | |
| 580 | uint32_t ofs = 0; |
| 581 | |
| 582 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 583 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 584 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
| 585 | __ Ldc1(reg, SP, ofs); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 586 | ofs += kMips64DoublewordSize; |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 587 | __ cfi().Restore(DWARFReg(reg)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
| 591 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 592 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 593 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 594 | __ Ld(reg, SP, ofs); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 595 | ofs += kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 596 | __ cfi().Restore(DWARFReg(reg)); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | DCHECK_EQ(ofs, FrameEntrySpillSize()); |
| 601 | __ DecreaseFrameSize(ofs); |
| 602 | } |
| 603 | |
| 604 | __ Jr(RA); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 605 | __ Nop(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 606 | |
| 607 | __ cfi().RestoreState(); |
| 608 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 609 | } |
| 610 | |
| 611 | void CodeGeneratorMIPS64::Bind(HBasicBlock* block) { |
| 612 | __ Bind(GetLabelOf(block)); |
| 613 | } |
| 614 | |
| 615 | void CodeGeneratorMIPS64::MoveLocation(Location destination, |
| 616 | Location source, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 617 | Primitive::Type dst_type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 618 | if (source.Equals(destination)) { |
| 619 | return; |
| 620 | } |
| 621 | |
| 622 | // A valid move can always be inferred from the destination and source |
| 623 | // locations. When moving from and to a register, the argument type can be |
| 624 | // used to generate 32bit instead of 64bit moves. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 625 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 626 | DCHECK_EQ(unspecified_type, false); |
| 627 | |
| 628 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 629 | if (unspecified_type) { |
| 630 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 631 | if (source.IsStackSlot() || |
| 632 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 633 | || src_cst->IsFloatConstant() |
| 634 | || src_cst->IsNullConstant()))) { |
| 635 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 636 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 637 | } else { |
| 638 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 639 | // type is appropriate. Else the source is a register, and since the |
| 640 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 641 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 642 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 643 | } |
| 644 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 645 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 646 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 647 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 648 | // Move to GPR/FPR from stack |
| 649 | LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 650 | if (Primitive::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 651 | __ LoadFpuFromOffset(load_type, |
| 652 | destination.AsFpuRegister<FpuRegister>(), |
| 653 | SP, |
| 654 | source.GetStackIndex()); |
| 655 | } else { |
| 656 | // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot. |
| 657 | __ LoadFromOffset(load_type, |
| 658 | destination.AsRegister<GpuRegister>(), |
| 659 | SP, |
| 660 | source.GetStackIndex()); |
| 661 | } |
| 662 | } else if (source.IsConstant()) { |
| 663 | // Move to GPR/FPR from constant |
| 664 | GpuRegister gpr = AT; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 665 | if (!Primitive::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 666 | gpr = destination.AsRegister<GpuRegister>(); |
| 667 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 668 | if (dst_type == Primitive::kPrimInt || dst_type == Primitive::kPrimFloat) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 669 | int32_t value = GetInt32ValueOf(source.GetConstant()->AsConstant()); |
| 670 | if (Primitive::IsFloatingPointType(dst_type) && value == 0) { |
| 671 | gpr = ZERO; |
| 672 | } else { |
| 673 | __ LoadConst32(gpr, value); |
| 674 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 675 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 676 | int64_t value = GetInt64ValueOf(source.GetConstant()->AsConstant()); |
| 677 | if (Primitive::IsFloatingPointType(dst_type) && value == 0) { |
| 678 | gpr = ZERO; |
| 679 | } else { |
| 680 | __ LoadConst64(gpr, value); |
| 681 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 682 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 683 | if (dst_type == Primitive::kPrimFloat) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 684 | __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 685 | } else if (dst_type == Primitive::kPrimDouble) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 686 | __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
| 687 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 688 | } else if (source.IsRegister()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 689 | if (destination.IsRegister()) { |
| 690 | // Move to GPR from GPR |
| 691 | __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>()); |
| 692 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 693 | DCHECK(destination.IsFpuRegister()); |
| 694 | if (Primitive::Is64BitType(dst_type)) { |
| 695 | __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 696 | } else { |
| 697 | __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 698 | } |
| 699 | } |
| 700 | } else if (source.IsFpuRegister()) { |
| 701 | if (destination.IsFpuRegister()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 702 | // Move to FPR from FPR |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 703 | if (dst_type == Primitive::kPrimFloat) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 704 | __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 705 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 706 | DCHECK_EQ(dst_type, Primitive::kPrimDouble); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 707 | __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 708 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 709 | } else { |
| 710 | DCHECK(destination.IsRegister()); |
| 711 | if (Primitive::Is64BitType(dst_type)) { |
| 712 | __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 713 | } else { |
| 714 | __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 715 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | } else { // The destination is not a register. It must be a stack slot. |
| 719 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 720 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 721 | if (unspecified_type) { |
| 722 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 723 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 724 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 725 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 726 | } |
| 727 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 728 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 729 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 730 | // Move to stack from GPR/FPR |
| 731 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 732 | if (source.IsRegister()) { |
| 733 | __ StoreToOffset(store_type, |
| 734 | source.AsRegister<GpuRegister>(), |
| 735 | SP, |
| 736 | destination.GetStackIndex()); |
| 737 | } else { |
| 738 | __ StoreFpuToOffset(store_type, |
| 739 | source.AsFpuRegister<FpuRegister>(), |
| 740 | SP, |
| 741 | destination.GetStackIndex()); |
| 742 | } |
| 743 | } else if (source.IsConstant()) { |
| 744 | // Move to stack from constant |
| 745 | HConstant* src_cst = source.GetConstant(); |
| 746 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 747 | GpuRegister gpr = ZERO; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 748 | if (destination.IsStackSlot()) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 749 | int32_t value = GetInt32ValueOf(src_cst->AsConstant()); |
| 750 | if (value != 0) { |
| 751 | gpr = TMP; |
| 752 | __ LoadConst32(gpr, value); |
| 753 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 754 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 755 | DCHECK(destination.IsDoubleStackSlot()); |
| 756 | int64_t value = GetInt64ValueOf(src_cst->AsConstant()); |
| 757 | if (value != 0) { |
| 758 | gpr = TMP; |
| 759 | __ LoadConst64(gpr, value); |
| 760 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 761 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 762 | __ StoreToOffset(store_type, gpr, SP, destination.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 763 | } else { |
| 764 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
| 765 | DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot()); |
| 766 | // Move to stack from stack |
| 767 | if (destination.IsStackSlot()) { |
| 768 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 769 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 770 | } else { |
| 771 | __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex()); |
| 772 | __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex()); |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 778 | void CodeGeneratorMIPS64::SwapLocations(Location loc1, Location loc2, Primitive::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 779 | DCHECK(!loc1.IsConstant()); |
| 780 | DCHECK(!loc2.IsConstant()); |
| 781 | |
| 782 | if (loc1.Equals(loc2)) { |
| 783 | return; |
| 784 | } |
| 785 | |
| 786 | bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot(); |
| 787 | bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot(); |
| 788 | bool is_fp_reg1 = loc1.IsFpuRegister(); |
| 789 | bool is_fp_reg2 = loc2.IsFpuRegister(); |
| 790 | |
| 791 | if (loc2.IsRegister() && loc1.IsRegister()) { |
| 792 | // Swap 2 GPRs |
| 793 | GpuRegister r1 = loc1.AsRegister<GpuRegister>(); |
| 794 | GpuRegister r2 = loc2.AsRegister<GpuRegister>(); |
| 795 | __ Move(TMP, r2); |
| 796 | __ Move(r2, r1); |
| 797 | __ Move(r1, TMP); |
| 798 | } else if (is_fp_reg2 && is_fp_reg1) { |
| 799 | // Swap 2 FPRs |
| 800 | FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>(); |
| 801 | FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 802 | if (type == Primitive::kPrimFloat) { |
| 803 | __ MovS(FTMP, r1); |
| 804 | __ MovS(r1, r2); |
| 805 | __ MovS(r2, FTMP); |
| 806 | } else { |
| 807 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 808 | __ MovD(FTMP, r1); |
| 809 | __ MovD(r1, r2); |
| 810 | __ MovD(r2, FTMP); |
| 811 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 812 | } else if (is_slot1 != is_slot2) { |
| 813 | // Swap GPR/FPR and stack slot |
| 814 | Location reg_loc = is_slot1 ? loc2 : loc1; |
| 815 | Location mem_loc = is_slot1 ? loc1 : loc2; |
| 816 | LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
| 817 | StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 818 | // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot. |
| 819 | __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex()); |
| 820 | if (reg_loc.IsFpuRegister()) { |
| 821 | __ StoreFpuToOffset(store_type, |
| 822 | reg_loc.AsFpuRegister<FpuRegister>(), |
| 823 | SP, |
| 824 | mem_loc.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 825 | if (mem_loc.IsStackSlot()) { |
| 826 | __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 827 | } else { |
| 828 | DCHECK(mem_loc.IsDoubleStackSlot()); |
| 829 | __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 830 | } |
| 831 | } else { |
| 832 | __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex()); |
| 833 | __ Move(reg_loc.AsRegister<GpuRegister>(), TMP); |
| 834 | } |
| 835 | } else if (is_slot1 && is_slot2) { |
| 836 | move_resolver_.Exchange(loc1.GetStackIndex(), |
| 837 | loc2.GetStackIndex(), |
| 838 | loc1.IsDoubleStackSlot()); |
| 839 | } else { |
| 840 | LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2; |
| 841 | } |
| 842 | } |
| 843 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 844 | void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) { |
| 845 | DCHECK(location.IsRegister()); |
| 846 | __ LoadConst32(location.AsRegister<GpuRegister>(), value); |
| 847 | } |
| 848 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 849 | void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 850 | if (location.IsRegister()) { |
| 851 | locations->AddTemp(location); |
| 852 | } else { |
| 853 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 854 | } |
| 855 | } |
| 856 | |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 857 | void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object, |
| 858 | GpuRegister value, |
| 859 | bool value_can_be_null) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 860 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 861 | GpuRegister card = AT; |
| 862 | GpuRegister temp = TMP; |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 863 | if (value_can_be_null) { |
| 864 | __ Beqzc(value, &done); |
| 865 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 866 | __ LoadFromOffset(kLoadDoubleword, |
| 867 | card, |
| 868 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 869 | Thread::CardTableOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 870 | __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift); |
| 871 | __ Daddu(temp, card, temp); |
| 872 | __ Sb(card, temp, 0); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 873 | if (value_can_be_null) { |
| 874 | __ Bind(&done); |
| 875 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 876 | } |
| 877 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 878 | void CodeGeneratorMIPS64::SetupBlockedRegisters() const { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 879 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 880 | blocked_core_registers_[ZERO] = true; |
| 881 | blocked_core_registers_[K0] = true; |
| 882 | blocked_core_registers_[K1] = true; |
| 883 | blocked_core_registers_[GP] = true; |
| 884 | blocked_core_registers_[SP] = true; |
| 885 | blocked_core_registers_[RA] = true; |
| 886 | |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 887 | // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch |
| 888 | // registers (similar to how AT is used by MIPS assemblers). |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 889 | blocked_core_registers_[AT] = true; |
| 890 | blocked_core_registers_[TMP] = true; |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 891 | blocked_core_registers_[TMP2] = true; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 892 | blocked_fpu_registers_[FTMP] = true; |
| 893 | |
| 894 | // Reserve suspend and thread registers. |
| 895 | blocked_core_registers_[S0] = true; |
| 896 | blocked_core_registers_[TR] = true; |
| 897 | |
| 898 | // Reserve T9 for function calls |
| 899 | blocked_core_registers_[T9] = true; |
| 900 | |
| 901 | // TODO: review; anything else? |
| 902 | |
Goran Jakovljevic | 782be11 | 2016-06-21 12:39:04 +0200 | [diff] [blame] | 903 | if (GetGraph()->IsDebuggable()) { |
| 904 | // Stubs do not save callee-save floating point registers. If the graph |
| 905 | // is debuggable, we need to deal with these registers differently. For |
| 906 | // now, just block them. |
| 907 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 908 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 909 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 913 | size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 914 | __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 915 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 919 | __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 920 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 924 | __ StoreFpuToOffset(kStoreDoubleword, FpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 925 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 929 | __ LoadFpuFromOffset(kLoadDoubleword, FpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 930 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 934 | stream << GpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 938 | stream << FpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 939 | } |
| 940 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 941 | void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 942 | HInstruction* instruction, |
| 943 | uint32_t dex_pc, |
| 944 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 945 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 946 | // TODO: anything related to T9/GP/GOT/PIC/.so's? |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 947 | __ LoadFromOffset(kLoadDoubleword, |
| 948 | T9, |
| 949 | TR, |
| 950 | GetThreadOffset<kMips64PointerSize>(entrypoint).Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 951 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 952 | __ Nop(); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 953 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 954 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 955 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path, |
| 959 | GpuRegister class_reg) { |
| 960 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 961 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 962 | __ Bltc(TMP, AT, slow_path->GetEntryLabel()); |
| 963 | // TODO: barrier needed? |
| 964 | __ Bind(slow_path->GetExitLabel()); |
| 965 | } |
| 966 | |
| 967 | void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 968 | __ Sync(0); // only stype 0 is supported |
| 969 | } |
| 970 | |
| 971 | void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 972 | HBasicBlock* successor) { |
| 973 | SuspendCheckSlowPathMIPS64* slow_path = |
| 974 | new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS64(instruction, successor); |
| 975 | codegen_->AddSlowPath(slow_path); |
| 976 | |
| 977 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 978 | TMP, |
| 979 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 980 | Thread::ThreadFlagsOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 981 | if (successor == nullptr) { |
| 982 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 983 | __ Bind(slow_path->GetReturnLabel()); |
| 984 | } else { |
| 985 | __ Beqzc(TMP, codegen_->GetLabelOf(successor)); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 986 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 987 | // slow_path will return to GetLabelOf(successor). |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph, |
| 992 | CodeGeneratorMIPS64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 993 | : InstructionCodeGenerator(graph, codegen), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 994 | assembler_(codegen->GetAssembler()), |
| 995 | codegen_(codegen) {} |
| 996 | |
| 997 | void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 998 | DCHECK_EQ(instruction->InputCount(), 2U); |
| 999 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1000 | Primitive::Type type = instruction->GetResultType(); |
| 1001 | switch (type) { |
| 1002 | case Primitive::kPrimInt: |
| 1003 | case Primitive::kPrimLong: { |
| 1004 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1005 | HInstruction* right = instruction->InputAt(1); |
| 1006 | bool can_use_imm = false; |
| 1007 | if (right->IsConstant()) { |
| 1008 | int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant()); |
| 1009 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1010 | can_use_imm = IsUint<16>(imm); |
| 1011 | } else if (instruction->IsAdd()) { |
| 1012 | can_use_imm = IsInt<16>(imm); |
| 1013 | } else { |
| 1014 | DCHECK(instruction->IsSub()); |
| 1015 | can_use_imm = IsInt<16>(-imm); |
| 1016 | } |
| 1017 | } |
| 1018 | if (can_use_imm) |
| 1019 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1020 | else |
| 1021 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1022 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1023 | } |
| 1024 | break; |
| 1025 | |
| 1026 | case Primitive::kPrimFloat: |
| 1027 | case Primitive::kPrimDouble: |
| 1028 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1029 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1030 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1031 | break; |
| 1032 | |
| 1033 | default: |
| 1034 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1039 | Primitive::Type type = instruction->GetType(); |
| 1040 | LocationSummary* locations = instruction->GetLocations(); |
| 1041 | |
| 1042 | switch (type) { |
| 1043 | case Primitive::kPrimInt: |
| 1044 | case Primitive::kPrimLong: { |
| 1045 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1046 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1047 | Location rhs_location = locations->InAt(1); |
| 1048 | |
| 1049 | GpuRegister rhs_reg = ZERO; |
| 1050 | int64_t rhs_imm = 0; |
| 1051 | bool use_imm = rhs_location.IsConstant(); |
| 1052 | if (use_imm) { |
| 1053 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1054 | } else { |
| 1055 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1056 | } |
| 1057 | |
| 1058 | if (instruction->IsAnd()) { |
| 1059 | if (use_imm) |
| 1060 | __ Andi(dst, lhs, rhs_imm); |
| 1061 | else |
| 1062 | __ And(dst, lhs, rhs_reg); |
| 1063 | } else if (instruction->IsOr()) { |
| 1064 | if (use_imm) |
| 1065 | __ Ori(dst, lhs, rhs_imm); |
| 1066 | else |
| 1067 | __ Or(dst, lhs, rhs_reg); |
| 1068 | } else if (instruction->IsXor()) { |
| 1069 | if (use_imm) |
| 1070 | __ Xori(dst, lhs, rhs_imm); |
| 1071 | else |
| 1072 | __ Xor(dst, lhs, rhs_reg); |
| 1073 | } else if (instruction->IsAdd()) { |
| 1074 | if (type == Primitive::kPrimInt) { |
| 1075 | if (use_imm) |
| 1076 | __ Addiu(dst, lhs, rhs_imm); |
| 1077 | else |
| 1078 | __ Addu(dst, lhs, rhs_reg); |
| 1079 | } else { |
| 1080 | if (use_imm) |
| 1081 | __ Daddiu(dst, lhs, rhs_imm); |
| 1082 | else |
| 1083 | __ Daddu(dst, lhs, rhs_reg); |
| 1084 | } |
| 1085 | } else { |
| 1086 | DCHECK(instruction->IsSub()); |
| 1087 | if (type == Primitive::kPrimInt) { |
| 1088 | if (use_imm) |
| 1089 | __ Addiu(dst, lhs, -rhs_imm); |
| 1090 | else |
| 1091 | __ Subu(dst, lhs, rhs_reg); |
| 1092 | } else { |
| 1093 | if (use_imm) |
| 1094 | __ Daddiu(dst, lhs, -rhs_imm); |
| 1095 | else |
| 1096 | __ Dsubu(dst, lhs, rhs_reg); |
| 1097 | } |
| 1098 | } |
| 1099 | break; |
| 1100 | } |
| 1101 | case Primitive::kPrimFloat: |
| 1102 | case Primitive::kPrimDouble: { |
| 1103 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 1104 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 1105 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 1106 | if (instruction->IsAdd()) { |
| 1107 | if (type == Primitive::kPrimFloat) |
| 1108 | __ AddS(dst, lhs, rhs); |
| 1109 | else |
| 1110 | __ AddD(dst, lhs, rhs); |
| 1111 | } else if (instruction->IsSub()) { |
| 1112 | if (type == Primitive::kPrimFloat) |
| 1113 | __ SubS(dst, lhs, rhs); |
| 1114 | else |
| 1115 | __ SubD(dst, lhs, rhs); |
| 1116 | } else { |
| 1117 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
| 1118 | } |
| 1119 | break; |
| 1120 | } |
| 1121 | default: |
| 1122 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1127 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1128 | |
| 1129 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1130 | Primitive::Type type = instr->GetResultType(); |
| 1131 | switch (type) { |
| 1132 | case Primitive::kPrimInt: |
| 1133 | case Primitive::kPrimLong: { |
| 1134 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1135 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1136 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1137 | break; |
| 1138 | } |
| 1139 | default: |
| 1140 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1145 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1146 | LocationSummary* locations = instr->GetLocations(); |
| 1147 | Primitive::Type type = instr->GetType(); |
| 1148 | |
| 1149 | switch (type) { |
| 1150 | case Primitive::kPrimInt: |
| 1151 | case Primitive::kPrimLong: { |
| 1152 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1153 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1154 | Location rhs_location = locations->InAt(1); |
| 1155 | |
| 1156 | GpuRegister rhs_reg = ZERO; |
| 1157 | int64_t rhs_imm = 0; |
| 1158 | bool use_imm = rhs_location.IsConstant(); |
| 1159 | if (use_imm) { |
| 1160 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1161 | } else { |
| 1162 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1163 | } |
| 1164 | |
| 1165 | if (use_imm) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1166 | uint32_t shift_value = rhs_imm & |
| 1167 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1168 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1169 | if (shift_value == 0) { |
| 1170 | if (dst != lhs) { |
| 1171 | __ Move(dst, lhs); |
| 1172 | } |
| 1173 | } else if (type == Primitive::kPrimInt) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1174 | if (instr->IsShl()) { |
| 1175 | __ Sll(dst, lhs, shift_value); |
| 1176 | } else if (instr->IsShr()) { |
| 1177 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1178 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1179 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1180 | } else { |
| 1181 | __ Rotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1182 | } |
| 1183 | } else { |
| 1184 | if (shift_value < 32) { |
| 1185 | if (instr->IsShl()) { |
| 1186 | __ Dsll(dst, lhs, shift_value); |
| 1187 | } else if (instr->IsShr()) { |
| 1188 | __ Dsra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1189 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1190 | __ Dsrl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1191 | } else { |
| 1192 | __ Drotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1193 | } |
| 1194 | } else { |
| 1195 | shift_value -= 32; |
| 1196 | if (instr->IsShl()) { |
| 1197 | __ Dsll32(dst, lhs, shift_value); |
| 1198 | } else if (instr->IsShr()) { |
| 1199 | __ Dsra32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1200 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1201 | __ Dsrl32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1202 | } else { |
| 1203 | __ Drotr32(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | } |
| 1207 | } else { |
| 1208 | if (type == Primitive::kPrimInt) { |
| 1209 | if (instr->IsShl()) { |
| 1210 | __ Sllv(dst, lhs, rhs_reg); |
| 1211 | } else if (instr->IsShr()) { |
| 1212 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1213 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1214 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1215 | } else { |
| 1216 | __ Rotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1217 | } |
| 1218 | } else { |
| 1219 | if (instr->IsShl()) { |
| 1220 | __ Dsllv(dst, lhs, rhs_reg); |
| 1221 | } else if (instr->IsShr()) { |
| 1222 | __ Dsrav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1223 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1224 | __ Dsrlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1225 | } else { |
| 1226 | __ Drotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | } |
| 1230 | break; |
| 1231 | } |
| 1232 | default: |
| 1233 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) { |
| 1238 | HandleBinaryOp(instruction); |
| 1239 | } |
| 1240 | |
| 1241 | void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) { |
| 1242 | HandleBinaryOp(instruction); |
| 1243 | } |
| 1244 | |
| 1245 | void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) { |
| 1246 | HandleBinaryOp(instruction); |
| 1247 | } |
| 1248 | |
| 1249 | void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) { |
| 1250 | HandleBinaryOp(instruction); |
| 1251 | } |
| 1252 | |
| 1253 | void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) { |
| 1254 | LocationSummary* locations = |
| 1255 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1256 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1257 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1258 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1259 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1260 | } else { |
| 1261 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) { |
| 1266 | LocationSummary* locations = instruction->GetLocations(); |
| 1267 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1268 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1269 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1270 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1271 | Primitive::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1272 | switch (type) { |
| 1273 | case Primitive::kPrimBoolean: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1274 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1275 | if (index.IsConstant()) { |
| 1276 | size_t offset = |
| 1277 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 1278 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 1279 | } else { |
| 1280 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
| 1281 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 1282 | } |
| 1283 | break; |
| 1284 | } |
| 1285 | |
| 1286 | case Primitive::kPrimByte: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1287 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1288 | if (index.IsConstant()) { |
| 1289 | size_t offset = |
| 1290 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 1291 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 1292 | } else { |
| 1293 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
| 1294 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset); |
| 1295 | } |
| 1296 | break; |
| 1297 | } |
| 1298 | |
| 1299 | case Primitive::kPrimShort: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1300 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1301 | if (index.IsConstant()) { |
| 1302 | size_t offset = |
| 1303 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 1304 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 1305 | } else { |
| 1306 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2); |
| 1307 | __ Daddu(TMP, obj, TMP); |
| 1308 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset); |
| 1309 | } |
| 1310 | break; |
| 1311 | } |
| 1312 | |
| 1313 | case Primitive::kPrimChar: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1314 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1315 | if (index.IsConstant()) { |
| 1316 | size_t offset = |
| 1317 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 1318 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 1319 | } else { |
| 1320 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2); |
| 1321 | __ Daddu(TMP, obj, TMP); |
| 1322 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 1323 | } |
| 1324 | break; |
| 1325 | } |
| 1326 | |
| 1327 | case Primitive::kPrimInt: |
| 1328 | case Primitive::kPrimNot: { |
| 1329 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1330 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1331 | LoadOperandType load_type = (type == Primitive::kPrimNot) ? kLoadUnsignedWord : kLoadWord; |
| 1332 | if (index.IsConstant()) { |
| 1333 | size_t offset = |
| 1334 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1335 | __ LoadFromOffset(load_type, out, obj, offset); |
| 1336 | } else { |
| 1337 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4); |
| 1338 | __ Daddu(TMP, obj, TMP); |
| 1339 | __ LoadFromOffset(load_type, out, TMP, data_offset); |
| 1340 | } |
| 1341 | break; |
| 1342 | } |
| 1343 | |
| 1344 | case Primitive::kPrimLong: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1345 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1346 | if (index.IsConstant()) { |
| 1347 | size_t offset = |
| 1348 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1349 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset); |
| 1350 | } else { |
| 1351 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8); |
| 1352 | __ Daddu(TMP, obj, TMP); |
| 1353 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset); |
| 1354 | } |
| 1355 | break; |
| 1356 | } |
| 1357 | |
| 1358 | case Primitive::kPrimFloat: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1359 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 1360 | if (index.IsConstant()) { |
| 1361 | size_t offset = |
| 1362 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1363 | __ LoadFpuFromOffset(kLoadWord, out, obj, offset); |
| 1364 | } else { |
| 1365 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4); |
| 1366 | __ Daddu(TMP, obj, TMP); |
| 1367 | __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset); |
| 1368 | } |
| 1369 | break; |
| 1370 | } |
| 1371 | |
| 1372 | case Primitive::kPrimDouble: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1373 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 1374 | if (index.IsConstant()) { |
| 1375 | size_t offset = |
| 1376 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1377 | __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset); |
| 1378 | } else { |
| 1379 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8); |
| 1380 | __ Daddu(TMP, obj, TMP); |
| 1381 | __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset); |
| 1382 | } |
| 1383 | break; |
| 1384 | } |
| 1385 | |
| 1386 | case Primitive::kPrimVoid: |
| 1387 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1388 | UNREACHABLE(); |
| 1389 | } |
| 1390 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1391 | } |
| 1392 | |
| 1393 | void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 1394 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1395 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1396 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1397 | } |
| 1398 | |
| 1399 | void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 1400 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 1401 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1402 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1403 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1404 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 1405 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1406 | } |
| 1407 | |
| 1408 | void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) { |
David Brazdil | bb3d505 | 2015-09-21 18:39:16 +0100 | [diff] [blame] | 1409 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1410 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1411 | instruction, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1412 | needs_runtime_call ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
David Brazdil | bb3d505 | 2015-09-21 18:39:16 +0100 | [diff] [blame] | 1413 | if (needs_runtime_call) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1414 | InvokeRuntimeCallingConvention calling_convention; |
| 1415 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1416 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1417 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1418 | } else { |
| 1419 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1420 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1421 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
| 1422 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 1423 | } else { |
| 1424 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) { |
| 1430 | LocationSummary* locations = instruction->GetLocations(); |
| 1431 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1432 | Location index = locations->InAt(1); |
| 1433 | Primitive::Type value_type = instruction->GetComponentType(); |
| 1434 | bool needs_runtime_call = locations->WillCall(); |
| 1435 | bool needs_write_barrier = |
| 1436 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 1437 | |
| 1438 | switch (value_type) { |
| 1439 | case Primitive::kPrimBoolean: |
| 1440 | case Primitive::kPrimByte: { |
| 1441 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 1442 | GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>(); |
| 1443 | if (index.IsConstant()) { |
| 1444 | size_t offset = |
| 1445 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 1446 | __ StoreToOffset(kStoreByte, value, obj, offset); |
| 1447 | } else { |
| 1448 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
| 1449 | __ StoreToOffset(kStoreByte, value, TMP, data_offset); |
| 1450 | } |
| 1451 | break; |
| 1452 | } |
| 1453 | |
| 1454 | case Primitive::kPrimShort: |
| 1455 | case Primitive::kPrimChar: { |
| 1456 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 1457 | GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>(); |
| 1458 | if (index.IsConstant()) { |
| 1459 | size_t offset = |
| 1460 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 1461 | __ StoreToOffset(kStoreHalfword, value, obj, offset); |
| 1462 | } else { |
| 1463 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2); |
| 1464 | __ Daddu(TMP, obj, TMP); |
| 1465 | __ StoreToOffset(kStoreHalfword, value, TMP, data_offset); |
| 1466 | } |
| 1467 | break; |
| 1468 | } |
| 1469 | |
| 1470 | case Primitive::kPrimInt: |
| 1471 | case Primitive::kPrimNot: { |
| 1472 | if (!needs_runtime_call) { |
| 1473 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 1474 | GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>(); |
| 1475 | if (index.IsConstant()) { |
| 1476 | size_t offset = |
| 1477 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1478 | __ StoreToOffset(kStoreWord, value, obj, offset); |
| 1479 | } else { |
| 1480 | DCHECK(index.IsRegister()) << index; |
| 1481 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4); |
| 1482 | __ Daddu(TMP, obj, TMP); |
| 1483 | __ StoreToOffset(kStoreWord, value, TMP, data_offset); |
| 1484 | } |
| 1485 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1486 | if (needs_write_barrier) { |
| 1487 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1488 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1489 | } |
| 1490 | } else { |
| 1491 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 1492 | codegen_->InvokeRuntime(kQuickAputObject, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 1493 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1494 | } |
| 1495 | break; |
| 1496 | } |
| 1497 | |
| 1498 | case Primitive::kPrimLong: { |
| 1499 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 1500 | GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>(); |
| 1501 | if (index.IsConstant()) { |
| 1502 | size_t offset = |
| 1503 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1504 | __ StoreToOffset(kStoreDoubleword, value, obj, offset); |
| 1505 | } else { |
| 1506 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8); |
| 1507 | __ Daddu(TMP, obj, TMP); |
| 1508 | __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset); |
| 1509 | } |
| 1510 | break; |
| 1511 | } |
| 1512 | |
| 1513 | case Primitive::kPrimFloat: { |
| 1514 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 1515 | FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>(); |
| 1516 | DCHECK(locations->InAt(2).IsFpuRegister()); |
| 1517 | if (index.IsConstant()) { |
| 1518 | size_t offset = |
| 1519 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1520 | __ StoreFpuToOffset(kStoreWord, value, obj, offset); |
| 1521 | } else { |
| 1522 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4); |
| 1523 | __ Daddu(TMP, obj, TMP); |
| 1524 | __ StoreFpuToOffset(kStoreWord, value, TMP, data_offset); |
| 1525 | } |
| 1526 | break; |
| 1527 | } |
| 1528 | |
| 1529 | case Primitive::kPrimDouble: { |
| 1530 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 1531 | FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>(); |
| 1532 | DCHECK(locations->InAt(2).IsFpuRegister()); |
| 1533 | if (index.IsConstant()) { |
| 1534 | size_t offset = |
| 1535 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1536 | __ StoreFpuToOffset(kStoreDoubleword, value, obj, offset); |
| 1537 | } else { |
| 1538 | __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8); |
| 1539 | __ Daddu(TMP, obj, TMP); |
| 1540 | __ StoreFpuToOffset(kStoreDoubleword, value, TMP, data_offset); |
| 1541 | } |
| 1542 | break; |
| 1543 | } |
| 1544 | |
| 1545 | case Primitive::kPrimVoid: |
| 1546 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1547 | UNREACHABLE(); |
| 1548 | } |
| 1549 | |
| 1550 | // Ints and objects are handled in the switch. |
| 1551 | if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) { |
| 1552 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1557 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1558 | InvokeRuntimeCallingConvention calling_convention; |
| 1559 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1560 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1561 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1562 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1563 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 1567 | LocationSummary* locations = instruction->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 1568 | BoundsCheckSlowPathMIPS64* slow_path = |
| 1569 | new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS64(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1570 | codegen_->AddSlowPath(slow_path); |
| 1571 | |
| 1572 | GpuRegister index = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1573 | GpuRegister length = locations->InAt(1).AsRegister<GpuRegister>(); |
| 1574 | |
| 1575 | // length is limited by the maximum positive signed 32-bit integer. |
| 1576 | // Unsigned comparison of length and index checks for index < 0 |
| 1577 | // and for length <= index simultaneously. |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1578 | __ Bgeuc(index, length, slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) { |
| 1582 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1583 | instruction, |
| 1584 | LocationSummary::kCallOnSlowPath); |
| 1585 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1586 | locations->SetInAt(1, Location::RequiresRegister()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 1587 | // Note that TypeCheckSlowPathMIPS64 uses this register too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1588 | locations->AddTemp(Location::RequiresRegister()); |
| 1589 | } |
| 1590 | |
| 1591 | void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) { |
| 1592 | LocationSummary* locations = instruction->GetLocations(); |
| 1593 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1594 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
| 1595 | GpuRegister obj_cls = locations->GetTemp(0).AsRegister<GpuRegister>(); |
| 1596 | |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 1597 | SlowPathCodeMIPS64* slow_path = |
| 1598 | new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1599 | codegen_->AddSlowPath(slow_path); |
| 1600 | |
| 1601 | // TODO: avoid this check if we know obj is not null. |
| 1602 | __ Beqzc(obj, slow_path->GetExitLabel()); |
| 1603 | // Compare the class of `obj` with `cls`. |
| 1604 | __ LoadFromOffset(kLoadUnsignedWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value()); |
| 1605 | __ Bnec(obj_cls, cls, slow_path->GetEntryLabel()); |
| 1606 | __ Bind(slow_path->GetExitLabel()); |
| 1607 | } |
| 1608 | |
| 1609 | void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 1610 | LocationSummary* locations = |
| 1611 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 1612 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1613 | if (check->HasUses()) { |
| 1614 | locations->SetOut(Location::SameAsFirstInput()); |
| 1615 | } |
| 1616 | } |
| 1617 | |
| 1618 | void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 1619 | // We assume the class is not null. |
| 1620 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64( |
| 1621 | check->GetLoadClass(), |
| 1622 | check, |
| 1623 | check->GetDexPc(), |
| 1624 | true); |
| 1625 | codegen_->AddSlowPath(slow_path); |
| 1626 | GenerateClassInitializationCheck(slow_path, |
| 1627 | check->GetLocations()->InAt(0).AsRegister<GpuRegister>()); |
| 1628 | } |
| 1629 | |
| 1630 | void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) { |
| 1631 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 1632 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1633 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(compare); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1634 | |
| 1635 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1636 | case Primitive::kPrimBoolean: |
| 1637 | case Primitive::kPrimByte: |
| 1638 | case Primitive::kPrimShort: |
| 1639 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1640 | case Primitive::kPrimInt: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1641 | case Primitive::kPrimLong: |
| 1642 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1643 | locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1644 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1645 | break; |
| 1646 | |
| 1647 | case Primitive::kPrimFloat: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1648 | case Primitive::kPrimDouble: |
| 1649 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1650 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1651 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1652 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1653 | |
| 1654 | default: |
| 1655 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) { |
| 1660 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1661 | GpuRegister res = locations->Out().AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1662 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); |
| 1663 | |
| 1664 | // 0 if: left == right |
| 1665 | // 1 if: left > right |
| 1666 | // -1 if: left < right |
| 1667 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1668 | case Primitive::kPrimBoolean: |
| 1669 | case Primitive::kPrimByte: |
| 1670 | case Primitive::kPrimShort: |
| 1671 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1672 | case Primitive::kPrimInt: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1673 | case Primitive::kPrimLong: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1674 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1675 | Location rhs_location = locations->InAt(1); |
| 1676 | bool use_imm = rhs_location.IsConstant(); |
| 1677 | GpuRegister rhs = ZERO; |
| 1678 | if (use_imm) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1679 | if (in_type == Primitive::kPrimLong) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1680 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 1681 | if (value != 0) { |
| 1682 | rhs = AT; |
| 1683 | __ LoadConst64(rhs, value); |
| 1684 | } |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1685 | } else { |
| 1686 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 1687 | if (value != 0) { |
| 1688 | rhs = AT; |
| 1689 | __ LoadConst32(rhs, value); |
| 1690 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1691 | } |
| 1692 | } else { |
| 1693 | rhs = rhs_location.AsRegister<GpuRegister>(); |
| 1694 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1695 | __ Slt(TMP, lhs, rhs); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1696 | __ Slt(res, rhs, lhs); |
| 1697 | __ Subu(res, res, TMP); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1698 | break; |
| 1699 | } |
| 1700 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1701 | case Primitive::kPrimFloat: { |
| 1702 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 1703 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 1704 | Mips64Label done; |
| 1705 | __ CmpEqS(FTMP, lhs, rhs); |
| 1706 | __ LoadConst32(res, 0); |
| 1707 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 1708 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1709 | __ CmpLtS(FTMP, lhs, rhs); |
| 1710 | __ LoadConst32(res, -1); |
| 1711 | __ Bc1nez(FTMP, &done); |
| 1712 | __ LoadConst32(res, 1); |
| 1713 | } else { |
| 1714 | __ CmpLtS(FTMP, rhs, lhs); |
| 1715 | __ LoadConst32(res, 1); |
| 1716 | __ Bc1nez(FTMP, &done); |
| 1717 | __ LoadConst32(res, -1); |
| 1718 | } |
| 1719 | __ Bind(&done); |
| 1720 | break; |
| 1721 | } |
| 1722 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1723 | case Primitive::kPrimDouble: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1724 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 1725 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 1726 | Mips64Label done; |
| 1727 | __ CmpEqD(FTMP, lhs, rhs); |
| 1728 | __ LoadConst32(res, 0); |
| 1729 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 1730 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1731 | __ CmpLtD(FTMP, lhs, rhs); |
| 1732 | __ LoadConst32(res, -1); |
| 1733 | __ Bc1nez(FTMP, &done); |
| 1734 | __ LoadConst32(res, 1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1735 | } else { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1736 | __ CmpLtD(FTMP, rhs, lhs); |
| 1737 | __ LoadConst32(res, 1); |
| 1738 | __ Bc1nez(FTMP, &done); |
| 1739 | __ LoadConst32(res, -1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1740 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1741 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1742 | break; |
| 1743 | } |
| 1744 | |
| 1745 | default: |
| 1746 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 1747 | } |
| 1748 | } |
| 1749 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1750 | void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1751 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1752 | switch (instruction->InputAt(0)->GetType()) { |
| 1753 | default: |
| 1754 | case Primitive::kPrimLong: |
| 1755 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1756 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1757 | break; |
| 1758 | |
| 1759 | case Primitive::kPrimFloat: |
| 1760 | case Primitive::kPrimDouble: |
| 1761 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1762 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1763 | break; |
| 1764 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1765 | if (!instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1766 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1767 | } |
| 1768 | } |
| 1769 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1770 | void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1771 | if (instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1772 | return; |
| 1773 | } |
| 1774 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1775 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1776 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1777 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1778 | Mips64Label true_label; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1779 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1780 | switch (type) { |
| 1781 | default: |
| 1782 | // Integer case. |
| 1783 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations); |
| 1784 | return; |
| 1785 | case Primitive::kPrimLong: |
| 1786 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations); |
| 1787 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1788 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1789 | case Primitive::kPrimFloat: |
| 1790 | case Primitive::kPrimDouble: |
| 1791 | // TODO: don't use branches. |
| 1792 | GenerateFpCompareAndBranch(instruction->GetCondition(), |
| 1793 | instruction->IsGtBias(), |
| 1794 | type, |
| 1795 | locations, |
| 1796 | &true_label); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1797 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1798 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1799 | |
| 1800 | // Convert the branches into the result. |
| 1801 | Mips64Label done; |
| 1802 | |
| 1803 | // False case: result = 0. |
| 1804 | __ LoadConst32(dst, 0); |
| 1805 | __ Bc(&done); |
| 1806 | |
| 1807 | // True case: result = 1. |
| 1808 | __ Bind(&true_label); |
| 1809 | __ LoadConst32(dst, 1); |
| 1810 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 1813 | void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 1814 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 1815 | Primitive::Type type = instruction->GetResultType(); |
| 1816 | |
| 1817 | LocationSummary* locations = instruction->GetLocations(); |
| 1818 | Location second = locations->InAt(1); |
| 1819 | DCHECK(second.IsConstant()); |
| 1820 | |
| 1821 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1822 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1823 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 1824 | DCHECK(imm == 1 || imm == -1); |
| 1825 | |
| 1826 | if (instruction->IsRem()) { |
| 1827 | __ Move(out, ZERO); |
| 1828 | } else { |
| 1829 | if (imm == -1) { |
| 1830 | if (type == Primitive::kPrimInt) { |
| 1831 | __ Subu(out, ZERO, dividend); |
| 1832 | } else { |
| 1833 | DCHECK_EQ(type, Primitive::kPrimLong); |
| 1834 | __ Dsubu(out, ZERO, dividend); |
| 1835 | } |
| 1836 | } else if (out != dividend) { |
| 1837 | __ Move(out, dividend); |
| 1838 | } |
| 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 1843 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 1844 | Primitive::Type type = instruction->GetResultType(); |
| 1845 | |
| 1846 | LocationSummary* locations = instruction->GetLocations(); |
| 1847 | Location second = locations->InAt(1); |
| 1848 | DCHECK(second.IsConstant()); |
| 1849 | |
| 1850 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1851 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1852 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 1853 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 1854 | int ctz_imm = CTZ(abs_imm); |
| 1855 | |
| 1856 | if (instruction->IsDiv()) { |
| 1857 | if (type == Primitive::kPrimInt) { |
| 1858 | if (ctz_imm == 1) { |
| 1859 | // Fast path for division by +/-2, which is very common. |
| 1860 | __ Srl(TMP, dividend, 31); |
| 1861 | } else { |
| 1862 | __ Sra(TMP, dividend, 31); |
| 1863 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 1864 | } |
| 1865 | __ Addu(out, dividend, TMP); |
| 1866 | __ Sra(out, out, ctz_imm); |
| 1867 | if (imm < 0) { |
| 1868 | __ Subu(out, ZERO, out); |
| 1869 | } |
| 1870 | } else { |
| 1871 | DCHECK_EQ(type, Primitive::kPrimLong); |
| 1872 | if (ctz_imm == 1) { |
| 1873 | // Fast path for division by +/-2, which is very common. |
| 1874 | __ Dsrl32(TMP, dividend, 31); |
| 1875 | } else { |
| 1876 | __ Dsra32(TMP, dividend, 31); |
| 1877 | if (ctz_imm > 32) { |
| 1878 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 1879 | } else { |
| 1880 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 1881 | } |
| 1882 | } |
| 1883 | __ Daddu(out, dividend, TMP); |
| 1884 | if (ctz_imm < 32) { |
| 1885 | __ Dsra(out, out, ctz_imm); |
| 1886 | } else { |
| 1887 | __ Dsra32(out, out, ctz_imm - 32); |
| 1888 | } |
| 1889 | if (imm < 0) { |
| 1890 | __ Dsubu(out, ZERO, out); |
| 1891 | } |
| 1892 | } |
| 1893 | } else { |
| 1894 | if (type == Primitive::kPrimInt) { |
| 1895 | if (ctz_imm == 1) { |
| 1896 | // Fast path for modulo +/-2, which is very common. |
| 1897 | __ Sra(TMP, dividend, 31); |
| 1898 | __ Subu(out, dividend, TMP); |
| 1899 | __ Andi(out, out, 1); |
| 1900 | __ Addu(out, out, TMP); |
| 1901 | } else { |
| 1902 | __ Sra(TMP, dividend, 31); |
| 1903 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 1904 | __ Addu(out, dividend, TMP); |
| 1905 | if (IsUint<16>(abs_imm - 1)) { |
| 1906 | __ Andi(out, out, abs_imm - 1); |
| 1907 | } else { |
| 1908 | __ Sll(out, out, 32 - ctz_imm); |
| 1909 | __ Srl(out, out, 32 - ctz_imm); |
| 1910 | } |
| 1911 | __ Subu(out, out, TMP); |
| 1912 | } |
| 1913 | } else { |
| 1914 | DCHECK_EQ(type, Primitive::kPrimLong); |
| 1915 | if (ctz_imm == 1) { |
| 1916 | // Fast path for modulo +/-2, which is very common. |
| 1917 | __ Dsra32(TMP, dividend, 31); |
| 1918 | __ Dsubu(out, dividend, TMP); |
| 1919 | __ Andi(out, out, 1); |
| 1920 | __ Daddu(out, out, TMP); |
| 1921 | } else { |
| 1922 | __ Dsra32(TMP, dividend, 31); |
| 1923 | if (ctz_imm > 32) { |
| 1924 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 1925 | } else { |
| 1926 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 1927 | } |
| 1928 | __ Daddu(out, dividend, TMP); |
| 1929 | if (IsUint<16>(abs_imm - 1)) { |
| 1930 | __ Andi(out, out, abs_imm - 1); |
| 1931 | } else { |
| 1932 | if (ctz_imm > 32) { |
| 1933 | __ Dsll(out, out, 64 - ctz_imm); |
| 1934 | __ Dsrl(out, out, 64 - ctz_imm); |
| 1935 | } else { |
| 1936 | __ Dsll32(out, out, 32 - ctz_imm); |
| 1937 | __ Dsrl32(out, out, 32 - ctz_imm); |
| 1938 | } |
| 1939 | } |
| 1940 | __ Dsubu(out, out, TMP); |
| 1941 | } |
| 1942 | } |
| 1943 | } |
| 1944 | } |
| 1945 | |
| 1946 | void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 1947 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 1948 | |
| 1949 | LocationSummary* locations = instruction->GetLocations(); |
| 1950 | Location second = locations->InAt(1); |
| 1951 | DCHECK(second.IsConstant()); |
| 1952 | |
| 1953 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 1954 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1955 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 1956 | |
| 1957 | Primitive::Type type = instruction->GetResultType(); |
| 1958 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type; |
| 1959 | |
| 1960 | int64_t magic; |
| 1961 | int shift; |
| 1962 | CalculateMagicAndShiftForDivRem(imm, |
| 1963 | (type == Primitive::kPrimLong), |
| 1964 | &magic, |
| 1965 | &shift); |
| 1966 | |
| 1967 | if (type == Primitive::kPrimInt) { |
| 1968 | __ LoadConst32(TMP, magic); |
| 1969 | __ MuhR6(TMP, dividend, TMP); |
| 1970 | |
| 1971 | if (imm > 0 && magic < 0) { |
| 1972 | __ Addu(TMP, TMP, dividend); |
| 1973 | } else if (imm < 0 && magic > 0) { |
| 1974 | __ Subu(TMP, TMP, dividend); |
| 1975 | } |
| 1976 | |
| 1977 | if (shift != 0) { |
| 1978 | __ Sra(TMP, TMP, shift); |
| 1979 | } |
| 1980 | |
| 1981 | if (instruction->IsDiv()) { |
| 1982 | __ Sra(out, TMP, 31); |
| 1983 | __ Subu(out, TMP, out); |
| 1984 | } else { |
| 1985 | __ Sra(AT, TMP, 31); |
| 1986 | __ Subu(AT, TMP, AT); |
| 1987 | __ LoadConst32(TMP, imm); |
| 1988 | __ MulR6(TMP, AT, TMP); |
| 1989 | __ Subu(out, dividend, TMP); |
| 1990 | } |
| 1991 | } else { |
| 1992 | __ LoadConst64(TMP, magic); |
| 1993 | __ Dmuh(TMP, dividend, TMP); |
| 1994 | |
| 1995 | if (imm > 0 && magic < 0) { |
| 1996 | __ Daddu(TMP, TMP, dividend); |
| 1997 | } else if (imm < 0 && magic > 0) { |
| 1998 | __ Dsubu(TMP, TMP, dividend); |
| 1999 | } |
| 2000 | |
| 2001 | if (shift >= 32) { |
| 2002 | __ Dsra32(TMP, TMP, shift - 32); |
| 2003 | } else if (shift > 0) { |
| 2004 | __ Dsra(TMP, TMP, shift); |
| 2005 | } |
| 2006 | |
| 2007 | if (instruction->IsDiv()) { |
| 2008 | __ Dsra32(out, TMP, 31); |
| 2009 | __ Dsubu(out, TMP, out); |
| 2010 | } else { |
| 2011 | __ Dsra32(AT, TMP, 31); |
| 2012 | __ Dsubu(AT, TMP, AT); |
| 2013 | __ LoadConst64(TMP, imm); |
| 2014 | __ Dmul(TMP, AT, TMP); |
| 2015 | __ Dsubu(out, dividend, TMP); |
| 2016 | } |
| 2017 | } |
| 2018 | } |
| 2019 | |
| 2020 | void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2021 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2022 | Primitive::Type type = instruction->GetResultType(); |
| 2023 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type; |
| 2024 | |
| 2025 | LocationSummary* locations = instruction->GetLocations(); |
| 2026 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2027 | Location second = locations->InAt(1); |
| 2028 | |
| 2029 | if (second.IsConstant()) { |
| 2030 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2031 | if (imm == 0) { |
| 2032 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2033 | } else if (imm == 1 || imm == -1) { |
| 2034 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2035 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 2036 | DivRemByPowerOfTwo(instruction); |
| 2037 | } else { |
| 2038 | DCHECK(imm <= -2 || imm >= 2); |
| 2039 | GenerateDivRemWithAnyConstant(instruction); |
| 2040 | } |
| 2041 | } else { |
| 2042 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2043 | GpuRegister divisor = second.AsRegister<GpuRegister>(); |
| 2044 | if (instruction->IsDiv()) { |
| 2045 | if (type == Primitive::kPrimInt) |
| 2046 | __ DivR6(out, dividend, divisor); |
| 2047 | else |
| 2048 | __ Ddiv(out, dividend, divisor); |
| 2049 | } else { |
| 2050 | if (type == Primitive::kPrimInt) |
| 2051 | __ ModR6(out, dividend, divisor); |
| 2052 | else |
| 2053 | __ Dmod(out, dividend, divisor); |
| 2054 | } |
| 2055 | } |
| 2056 | } |
| 2057 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2058 | void LocationsBuilderMIPS64::VisitDiv(HDiv* div) { |
| 2059 | LocationSummary* locations = |
| 2060 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 2061 | switch (div->GetResultType()) { |
| 2062 | case Primitive::kPrimInt: |
| 2063 | case Primitive::kPrimLong: |
| 2064 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 2065 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2066 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2067 | break; |
| 2068 | |
| 2069 | case Primitive::kPrimFloat: |
| 2070 | case Primitive::kPrimDouble: |
| 2071 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2072 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2073 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2074 | break; |
| 2075 | |
| 2076 | default: |
| 2077 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) { |
| 2082 | Primitive::Type type = instruction->GetType(); |
| 2083 | LocationSummary* locations = instruction->GetLocations(); |
| 2084 | |
| 2085 | switch (type) { |
| 2086 | case Primitive::kPrimInt: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 2087 | case Primitive::kPrimLong: |
| 2088 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2089 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2090 | case Primitive::kPrimFloat: |
| 2091 | case Primitive::kPrimDouble: { |
| 2092 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 2093 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 2094 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 2095 | if (type == Primitive::kPrimFloat) |
| 2096 | __ DivS(dst, lhs, rhs); |
| 2097 | else |
| 2098 | __ DivD(dst, lhs, rhs); |
| 2099 | break; |
| 2100 | } |
| 2101 | default: |
| 2102 | LOG(FATAL) << "Unexpected div type " << type; |
| 2103 | } |
| 2104 | } |
| 2105 | |
| 2106 | void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2107 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2108 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2112 | SlowPathCodeMIPS64* slow_path = |
| 2113 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS64(instruction); |
| 2114 | codegen_->AddSlowPath(slow_path); |
| 2115 | Location value = instruction->GetLocations()->InAt(0); |
| 2116 | |
| 2117 | Primitive::Type type = instruction->GetType(); |
| 2118 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 2119 | if (!Primitive::IsIntegralType(type)) { |
| 2120 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 2121 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | if (value.IsConstant()) { |
| 2125 | int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant()); |
| 2126 | if (divisor == 0) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2127 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2128 | } else { |
| 2129 | // A division by a non-null constant is valid. We don't need to perform |
| 2130 | // any check, so simply fall through. |
| 2131 | } |
| 2132 | } else { |
| 2133 | __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2138 | LocationSummary* locations = |
| 2139 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2140 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2141 | } |
| 2142 | |
| 2143 | void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 2144 | // Will be generated at use site. |
| 2145 | } |
| 2146 | |
| 2147 | void LocationsBuilderMIPS64::VisitExit(HExit* exit) { |
| 2148 | exit->SetLocations(nullptr); |
| 2149 | } |
| 2150 | |
| 2151 | void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2152 | } |
| 2153 | |
| 2154 | void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) { |
| 2155 | LocationSummary* locations = |
| 2156 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2157 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2158 | } |
| 2159 | |
| 2160 | void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 2161 | // Will be generated at use site. |
| 2162 | } |
| 2163 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2164 | void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2165 | DCHECK(!successor->IsExitBlock()); |
| 2166 | HBasicBlock* block = got->GetBlock(); |
| 2167 | HInstruction* previous = got->GetPrevious(); |
| 2168 | HLoopInformation* info = block->GetLoopInformation(); |
| 2169 | |
| 2170 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 2171 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2172 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2173 | return; |
| 2174 | } |
| 2175 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2176 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2177 | } |
| 2178 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2179 | __ Bc(codegen_->GetLabelOf(successor)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2180 | } |
| 2181 | } |
| 2182 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2183 | void LocationsBuilderMIPS64::VisitGoto(HGoto* got) { |
| 2184 | got->SetLocations(nullptr); |
| 2185 | } |
| 2186 | |
| 2187 | void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) { |
| 2188 | HandleGoto(got, got->GetSuccessor()); |
| 2189 | } |
| 2190 | |
| 2191 | void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2192 | try_boundary->SetLocations(nullptr); |
| 2193 | } |
| 2194 | |
| 2195 | void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2196 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2197 | if (!successor->IsExitBlock()) { |
| 2198 | HandleGoto(try_boundary, successor); |
| 2199 | } |
| 2200 | } |
| 2201 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2202 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond, |
| 2203 | bool is64bit, |
| 2204 | LocationSummary* locations) { |
| 2205 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 2206 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2207 | Location rhs_location = locations->InAt(1); |
| 2208 | GpuRegister rhs_reg = ZERO; |
| 2209 | int64_t rhs_imm = 0; |
| 2210 | bool use_imm = rhs_location.IsConstant(); |
| 2211 | if (use_imm) { |
| 2212 | if (is64bit) { |
| 2213 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 2214 | } else { |
| 2215 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2216 | } |
| 2217 | } else { |
| 2218 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 2219 | } |
| 2220 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 2221 | |
| 2222 | switch (cond) { |
| 2223 | case kCondEQ: |
| 2224 | case kCondNE: |
| 2225 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 2226 | __ Xori(dst, lhs, rhs_imm); |
| 2227 | } else { |
| 2228 | if (use_imm) { |
| 2229 | rhs_reg = TMP; |
| 2230 | __ LoadConst64(rhs_reg, rhs_imm); |
| 2231 | } |
| 2232 | __ Xor(dst, lhs, rhs_reg); |
| 2233 | } |
| 2234 | if (cond == kCondEQ) { |
| 2235 | __ Sltiu(dst, dst, 1); |
| 2236 | } else { |
| 2237 | __ Sltu(dst, ZERO, dst); |
| 2238 | } |
| 2239 | break; |
| 2240 | |
| 2241 | case kCondLT: |
| 2242 | case kCondGE: |
| 2243 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 2244 | __ Slti(dst, lhs, rhs_imm); |
| 2245 | } else { |
| 2246 | if (use_imm) { |
| 2247 | rhs_reg = TMP; |
| 2248 | __ LoadConst64(rhs_reg, rhs_imm); |
| 2249 | } |
| 2250 | __ Slt(dst, lhs, rhs_reg); |
| 2251 | } |
| 2252 | if (cond == kCondGE) { |
| 2253 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 2254 | // only the slt instruction but no sge. |
| 2255 | __ Xori(dst, dst, 1); |
| 2256 | } |
| 2257 | break; |
| 2258 | |
| 2259 | case kCondLE: |
| 2260 | case kCondGT: |
| 2261 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 2262 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 2263 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 2264 | if (cond == kCondGT) { |
| 2265 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 2266 | // only the slti instruction but no sgti. |
| 2267 | __ Xori(dst, dst, 1); |
| 2268 | } |
| 2269 | } else { |
| 2270 | if (use_imm) { |
| 2271 | rhs_reg = TMP; |
| 2272 | __ LoadConst64(rhs_reg, rhs_imm); |
| 2273 | } |
| 2274 | __ Slt(dst, rhs_reg, lhs); |
| 2275 | if (cond == kCondLE) { |
| 2276 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 2277 | // only the slt instruction but no sle. |
| 2278 | __ Xori(dst, dst, 1); |
| 2279 | } |
| 2280 | } |
| 2281 | break; |
| 2282 | |
| 2283 | case kCondB: |
| 2284 | case kCondAE: |
| 2285 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 2286 | // Sltiu sign-extends its 16-bit immediate operand before |
| 2287 | // the comparison and thus lets us compare directly with |
| 2288 | // unsigned values in the ranges [0, 0x7fff] and |
| 2289 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 2290 | __ Sltiu(dst, lhs, rhs_imm); |
| 2291 | } else { |
| 2292 | if (use_imm) { |
| 2293 | rhs_reg = TMP; |
| 2294 | __ LoadConst64(rhs_reg, rhs_imm); |
| 2295 | } |
| 2296 | __ Sltu(dst, lhs, rhs_reg); |
| 2297 | } |
| 2298 | if (cond == kCondAE) { |
| 2299 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 2300 | // only the sltu instruction but no sgeu. |
| 2301 | __ Xori(dst, dst, 1); |
| 2302 | } |
| 2303 | break; |
| 2304 | |
| 2305 | case kCondBE: |
| 2306 | case kCondA: |
| 2307 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 2308 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 2309 | // Note that this only works if rhs + 1 does not overflow |
| 2310 | // to 0, hence the check above. |
| 2311 | // Sltiu sign-extends its 16-bit immediate operand before |
| 2312 | // the comparison and thus lets us compare directly with |
| 2313 | // unsigned values in the ranges [0, 0x7fff] and |
| 2314 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 2315 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 2316 | if (cond == kCondA) { |
| 2317 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 2318 | // only the sltiu instruction but no sgtiu. |
| 2319 | __ Xori(dst, dst, 1); |
| 2320 | } |
| 2321 | } else { |
| 2322 | if (use_imm) { |
| 2323 | rhs_reg = TMP; |
| 2324 | __ LoadConst64(rhs_reg, rhs_imm); |
| 2325 | } |
| 2326 | __ Sltu(dst, rhs_reg, lhs); |
| 2327 | if (cond == kCondBE) { |
| 2328 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 2329 | // only the sltu instruction but no sleu. |
| 2330 | __ Xori(dst, dst, 1); |
| 2331 | } |
| 2332 | } |
| 2333 | break; |
| 2334 | } |
| 2335 | } |
| 2336 | |
| 2337 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond, |
| 2338 | bool is64bit, |
| 2339 | LocationSummary* locations, |
| 2340 | Mips64Label* label) { |
| 2341 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2342 | Location rhs_location = locations->InAt(1); |
| 2343 | GpuRegister rhs_reg = ZERO; |
| 2344 | int64_t rhs_imm = 0; |
| 2345 | bool use_imm = rhs_location.IsConstant(); |
| 2346 | if (use_imm) { |
| 2347 | if (is64bit) { |
| 2348 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 2349 | } else { |
| 2350 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2351 | } |
| 2352 | } else { |
| 2353 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 2354 | } |
| 2355 | |
| 2356 | if (use_imm && rhs_imm == 0) { |
| 2357 | switch (cond) { |
| 2358 | case kCondEQ: |
| 2359 | case kCondBE: // <= 0 if zero |
| 2360 | __ Beqzc(lhs, label); |
| 2361 | break; |
| 2362 | case kCondNE: |
| 2363 | case kCondA: // > 0 if non-zero |
| 2364 | __ Bnezc(lhs, label); |
| 2365 | break; |
| 2366 | case kCondLT: |
| 2367 | __ Bltzc(lhs, label); |
| 2368 | break; |
| 2369 | case kCondGE: |
| 2370 | __ Bgezc(lhs, label); |
| 2371 | break; |
| 2372 | case kCondLE: |
| 2373 | __ Blezc(lhs, label); |
| 2374 | break; |
| 2375 | case kCondGT: |
| 2376 | __ Bgtzc(lhs, label); |
| 2377 | break; |
| 2378 | case kCondB: // always false |
| 2379 | break; |
| 2380 | case kCondAE: // always true |
| 2381 | __ Bc(label); |
| 2382 | break; |
| 2383 | } |
| 2384 | } else { |
| 2385 | if (use_imm) { |
| 2386 | rhs_reg = TMP; |
| 2387 | __ LoadConst64(rhs_reg, rhs_imm); |
| 2388 | } |
| 2389 | switch (cond) { |
| 2390 | case kCondEQ: |
| 2391 | __ Beqc(lhs, rhs_reg, label); |
| 2392 | break; |
| 2393 | case kCondNE: |
| 2394 | __ Bnec(lhs, rhs_reg, label); |
| 2395 | break; |
| 2396 | case kCondLT: |
| 2397 | __ Bltc(lhs, rhs_reg, label); |
| 2398 | break; |
| 2399 | case kCondGE: |
| 2400 | __ Bgec(lhs, rhs_reg, label); |
| 2401 | break; |
| 2402 | case kCondLE: |
| 2403 | __ Bgec(rhs_reg, lhs, label); |
| 2404 | break; |
| 2405 | case kCondGT: |
| 2406 | __ Bltc(rhs_reg, lhs, label); |
| 2407 | break; |
| 2408 | case kCondB: |
| 2409 | __ Bltuc(lhs, rhs_reg, label); |
| 2410 | break; |
| 2411 | case kCondAE: |
| 2412 | __ Bgeuc(lhs, rhs_reg, label); |
| 2413 | break; |
| 2414 | case kCondBE: |
| 2415 | __ Bgeuc(rhs_reg, lhs, label); |
| 2416 | break; |
| 2417 | case kCondA: |
| 2418 | __ Bltuc(rhs_reg, lhs, label); |
| 2419 | break; |
| 2420 | } |
| 2421 | } |
| 2422 | } |
| 2423 | |
| 2424 | void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond, |
| 2425 | bool gt_bias, |
| 2426 | Primitive::Type type, |
| 2427 | LocationSummary* locations, |
| 2428 | Mips64Label* label) { |
| 2429 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 2430 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 2431 | if (type == Primitive::kPrimFloat) { |
| 2432 | switch (cond) { |
| 2433 | case kCondEQ: |
| 2434 | __ CmpEqS(FTMP, lhs, rhs); |
| 2435 | __ Bc1nez(FTMP, label); |
| 2436 | break; |
| 2437 | case kCondNE: |
| 2438 | __ CmpEqS(FTMP, lhs, rhs); |
| 2439 | __ Bc1eqz(FTMP, label); |
| 2440 | break; |
| 2441 | case kCondLT: |
| 2442 | if (gt_bias) { |
| 2443 | __ CmpLtS(FTMP, lhs, rhs); |
| 2444 | } else { |
| 2445 | __ CmpUltS(FTMP, lhs, rhs); |
| 2446 | } |
| 2447 | __ Bc1nez(FTMP, label); |
| 2448 | break; |
| 2449 | case kCondLE: |
| 2450 | if (gt_bias) { |
| 2451 | __ CmpLeS(FTMP, lhs, rhs); |
| 2452 | } else { |
| 2453 | __ CmpUleS(FTMP, lhs, rhs); |
| 2454 | } |
| 2455 | __ Bc1nez(FTMP, label); |
| 2456 | break; |
| 2457 | case kCondGT: |
| 2458 | if (gt_bias) { |
| 2459 | __ CmpUltS(FTMP, rhs, lhs); |
| 2460 | } else { |
| 2461 | __ CmpLtS(FTMP, rhs, lhs); |
| 2462 | } |
| 2463 | __ Bc1nez(FTMP, label); |
| 2464 | break; |
| 2465 | case kCondGE: |
| 2466 | if (gt_bias) { |
| 2467 | __ CmpUleS(FTMP, rhs, lhs); |
| 2468 | } else { |
| 2469 | __ CmpLeS(FTMP, rhs, lhs); |
| 2470 | } |
| 2471 | __ Bc1nez(FTMP, label); |
| 2472 | break; |
| 2473 | default: |
| 2474 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 2475 | } |
| 2476 | } else { |
| 2477 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 2478 | switch (cond) { |
| 2479 | case kCondEQ: |
| 2480 | __ CmpEqD(FTMP, lhs, rhs); |
| 2481 | __ Bc1nez(FTMP, label); |
| 2482 | break; |
| 2483 | case kCondNE: |
| 2484 | __ CmpEqD(FTMP, lhs, rhs); |
| 2485 | __ Bc1eqz(FTMP, label); |
| 2486 | break; |
| 2487 | case kCondLT: |
| 2488 | if (gt_bias) { |
| 2489 | __ CmpLtD(FTMP, lhs, rhs); |
| 2490 | } else { |
| 2491 | __ CmpUltD(FTMP, lhs, rhs); |
| 2492 | } |
| 2493 | __ Bc1nez(FTMP, label); |
| 2494 | break; |
| 2495 | case kCondLE: |
| 2496 | if (gt_bias) { |
| 2497 | __ CmpLeD(FTMP, lhs, rhs); |
| 2498 | } else { |
| 2499 | __ CmpUleD(FTMP, lhs, rhs); |
| 2500 | } |
| 2501 | __ Bc1nez(FTMP, label); |
| 2502 | break; |
| 2503 | case kCondGT: |
| 2504 | if (gt_bias) { |
| 2505 | __ CmpUltD(FTMP, rhs, lhs); |
| 2506 | } else { |
| 2507 | __ CmpLtD(FTMP, rhs, lhs); |
| 2508 | } |
| 2509 | __ Bc1nez(FTMP, label); |
| 2510 | break; |
| 2511 | case kCondGE: |
| 2512 | if (gt_bias) { |
| 2513 | __ CmpUleD(FTMP, rhs, lhs); |
| 2514 | } else { |
| 2515 | __ CmpLeD(FTMP, rhs, lhs); |
| 2516 | } |
| 2517 | __ Bc1nez(FTMP, label); |
| 2518 | break; |
| 2519 | default: |
| 2520 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 2521 | } |
| 2522 | } |
| 2523 | } |
| 2524 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2525 | void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2526 | size_t condition_input_index, |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2527 | Mips64Label* true_target, |
| 2528 | Mips64Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2529 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2530 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2531 | if (true_target == nullptr && false_target == nullptr) { |
| 2532 | // Nothing to do. The code always falls through. |
| 2533 | return; |
| 2534 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2535 | // Constant condition, statically compared against "true" (integer value 1). |
| 2536 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2537 | if (true_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2538 | __ Bc(true_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2539 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2540 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2541 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2542 | if (false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2543 | __ Bc(false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2544 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2545 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2546 | return; |
| 2547 | } |
| 2548 | |
| 2549 | // The following code generates these patterns: |
| 2550 | // (1) true_target == nullptr && false_target != nullptr |
| 2551 | // - opposite condition true => branch to false_target |
| 2552 | // (2) true_target != nullptr && false_target == nullptr |
| 2553 | // - condition true => branch to true_target |
| 2554 | // (3) true_target != nullptr && false_target != nullptr |
| 2555 | // - condition true => branch to true_target |
| 2556 | // - branch to false_target |
| 2557 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2558 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2559 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2560 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2561 | if (true_target == nullptr) { |
| 2562 | __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target); |
| 2563 | } else { |
| 2564 | __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target); |
| 2565 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2566 | } else { |
| 2567 | // The condition instruction has not been materialized, use its inputs as |
| 2568 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2569 | HCondition* condition = cond->AsCondition(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2570 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2571 | LocationSummary* locations = cond->GetLocations(); |
| 2572 | IfCondition if_cond = condition->GetCondition(); |
| 2573 | Mips64Label* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2574 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2575 | if (true_target == nullptr) { |
| 2576 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2577 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2578 | } |
| 2579 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2580 | switch (type) { |
| 2581 | default: |
| 2582 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target); |
| 2583 | break; |
| 2584 | case Primitive::kPrimLong: |
| 2585 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target); |
| 2586 | break; |
| 2587 | case Primitive::kPrimFloat: |
| 2588 | case Primitive::kPrimDouble: |
| 2589 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 2590 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2591 | } |
| 2592 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2593 | |
| 2594 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2595 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2596 | if (true_target != nullptr && false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2597 | __ Bc(false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2598 | } |
| 2599 | } |
| 2600 | |
| 2601 | void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) { |
| 2602 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2603 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2604 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2605 | } |
| 2606 | } |
| 2607 | |
| 2608 | void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2609 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2610 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2611 | Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2612 | nullptr : codegen_->GetLabelOf(true_successor); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2613 | Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2614 | nullptr : codegen_->GetLabelOf(false_successor); |
| 2615 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2616 | } |
| 2617 | |
| 2618 | void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2619 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2620 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2621 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2622 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2623 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2628 | SlowPathCodeMIPS64* slow_path = |
| 2629 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2630 | GenerateTestAndBranch(deoptimize, |
| 2631 | /* condition_input_index */ 0, |
| 2632 | slow_path->GetEntryLabel(), |
| 2633 | /* false_target */ nullptr); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2634 | } |
| 2635 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2636 | void LocationsBuilderMIPS64::VisitSelect(HSelect* select) { |
| 2637 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 2638 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 2639 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2640 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2641 | } else { |
| 2642 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2643 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2644 | } |
| 2645 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 2646 | locations->SetInAt(2, Location::RequiresRegister()); |
| 2647 | } |
| 2648 | locations->SetOut(Location::SameAsFirstInput()); |
| 2649 | } |
| 2650 | |
| 2651 | void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) { |
| 2652 | LocationSummary* locations = select->GetLocations(); |
| 2653 | Mips64Label false_target; |
| 2654 | GenerateTestAndBranch(select, |
| 2655 | /* condition_input_index */ 2, |
| 2656 | /* true_target */ nullptr, |
| 2657 | &false_target); |
| 2658 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 2659 | __ Bind(&false_target); |
| 2660 | } |
| 2661 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2662 | void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2663 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2664 | } |
| 2665 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2666 | void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2667 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2668 | } |
| 2669 | |
| 2670 | void CodeGeneratorMIPS64::GenerateNop() { |
| 2671 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2672 | } |
| 2673 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2674 | void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction, |
| 2675 | const FieldInfo& field_info ATTRIBUTE_UNUSED) { |
| 2676 | LocationSummary* locations = |
| 2677 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2678 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2679 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2680 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2681 | } else { |
| 2682 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction, |
| 2687 | const FieldInfo& field_info) { |
| 2688 | Primitive::Type type = field_info.GetFieldType(); |
| 2689 | LocationSummary* locations = instruction->GetLocations(); |
| 2690 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2691 | LoadOperandType load_type = kLoadUnsignedByte; |
| 2692 | switch (type) { |
| 2693 | case Primitive::kPrimBoolean: |
| 2694 | load_type = kLoadUnsignedByte; |
| 2695 | break; |
| 2696 | case Primitive::kPrimByte: |
| 2697 | load_type = kLoadSignedByte; |
| 2698 | break; |
| 2699 | case Primitive::kPrimShort: |
| 2700 | load_type = kLoadSignedHalfword; |
| 2701 | break; |
| 2702 | case Primitive::kPrimChar: |
| 2703 | load_type = kLoadUnsignedHalfword; |
| 2704 | break; |
| 2705 | case Primitive::kPrimInt: |
| 2706 | case Primitive::kPrimFloat: |
| 2707 | load_type = kLoadWord; |
| 2708 | break; |
| 2709 | case Primitive::kPrimLong: |
| 2710 | case Primitive::kPrimDouble: |
| 2711 | load_type = kLoadDoubleword; |
| 2712 | break; |
| 2713 | case Primitive::kPrimNot: |
| 2714 | load_type = kLoadUnsignedWord; |
| 2715 | break; |
| 2716 | case Primitive::kPrimVoid: |
| 2717 | LOG(FATAL) << "Unreachable type " << type; |
| 2718 | UNREACHABLE(); |
| 2719 | } |
| 2720 | if (!Primitive::IsFloatingPointType(type)) { |
| 2721 | DCHECK(locations->Out().IsRegister()); |
| 2722 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 2723 | __ LoadFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value()); |
| 2724 | } else { |
| 2725 | DCHECK(locations->Out().IsFpuRegister()); |
| 2726 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 2727 | __ LoadFpuFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value()); |
| 2728 | } |
| 2729 | |
| 2730 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2731 | // TODO: memory barrier? |
| 2732 | } |
| 2733 | |
| 2734 | void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction, |
| 2735 | const FieldInfo& field_info ATTRIBUTE_UNUSED) { |
| 2736 | LocationSummary* locations = |
| 2737 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2738 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2739 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 2740 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2741 | } else { |
| 2742 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2743 | } |
| 2744 | } |
| 2745 | |
| 2746 | void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction, |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 2747 | const FieldInfo& field_info, |
| 2748 | bool value_can_be_null) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2749 | Primitive::Type type = field_info.GetFieldType(); |
| 2750 | LocationSummary* locations = instruction->GetLocations(); |
| 2751 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2752 | StoreOperandType store_type = kStoreByte; |
| 2753 | switch (type) { |
| 2754 | case Primitive::kPrimBoolean: |
| 2755 | case Primitive::kPrimByte: |
| 2756 | store_type = kStoreByte; |
| 2757 | break; |
| 2758 | case Primitive::kPrimShort: |
| 2759 | case Primitive::kPrimChar: |
| 2760 | store_type = kStoreHalfword; |
| 2761 | break; |
| 2762 | case Primitive::kPrimInt: |
| 2763 | case Primitive::kPrimFloat: |
| 2764 | case Primitive::kPrimNot: |
| 2765 | store_type = kStoreWord; |
| 2766 | break; |
| 2767 | case Primitive::kPrimLong: |
| 2768 | case Primitive::kPrimDouble: |
| 2769 | store_type = kStoreDoubleword; |
| 2770 | break; |
| 2771 | case Primitive::kPrimVoid: |
| 2772 | LOG(FATAL) << "Unreachable type " << type; |
| 2773 | UNREACHABLE(); |
| 2774 | } |
| 2775 | if (!Primitive::IsFloatingPointType(type)) { |
| 2776 | DCHECK(locations->InAt(1).IsRegister()); |
| 2777 | GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>(); |
| 2778 | __ StoreToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value()); |
| 2779 | } else { |
| 2780 | DCHECK(locations->InAt(1).IsFpuRegister()); |
| 2781 | FpuRegister src = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 2782 | __ StoreFpuToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value()); |
| 2783 | } |
| 2784 | |
| 2785 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2786 | // TODO: memory barriers? |
| 2787 | if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) { |
| 2788 | DCHECK(locations->InAt(1).IsRegister()); |
| 2789 | GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>(); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 2790 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2791 | } |
| 2792 | } |
| 2793 | |
| 2794 | void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 2795 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 2796 | } |
| 2797 | |
| 2798 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 2799 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 2800 | } |
| 2801 | |
| 2802 | void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 2803 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 2804 | } |
| 2805 | |
| 2806 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 2807 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
| 2811 | LocationSummary::CallKind call_kind = |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2812 | instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2813 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 2814 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2815 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2816 | // The output does overlap inputs. |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2817 | // Note that TypeCheckSlowPathMIPS64 uses this register too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2818 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2819 | } |
| 2820 | |
| 2821 | void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
| 2822 | LocationSummary* locations = instruction->GetLocations(); |
| 2823 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2824 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
| 2825 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2826 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2827 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2828 | |
| 2829 | // Return 0 if `obj` is null. |
| 2830 | // TODO: Avoid this check if we know `obj` is not null. |
| 2831 | __ Move(out, ZERO); |
| 2832 | __ Beqzc(obj, &done); |
| 2833 | |
| 2834 | // Compare the class of `obj` with `cls`. |
| 2835 | __ LoadFromOffset(kLoadUnsignedWord, out, obj, mirror::Object::ClassOffset().Int32Value()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2836 | if (instruction->IsExactCheck()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2837 | // Classes must be equal for the instanceof to succeed. |
| 2838 | __ Xor(out, out, cls); |
| 2839 | __ Sltiu(out, out, 1); |
| 2840 | } else { |
| 2841 | // If the classes are not equal, we go into a slow path. |
| 2842 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 2843 | SlowPathCodeMIPS64* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2844 | new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2845 | codegen_->AddSlowPath(slow_path); |
| 2846 | __ Bnec(out, cls, slow_path->GetEntryLabel()); |
| 2847 | __ LoadConst32(out, 1); |
| 2848 | __ Bind(slow_path->GetExitLabel()); |
| 2849 | } |
| 2850 | |
| 2851 | __ Bind(&done); |
| 2852 | } |
| 2853 | |
| 2854 | void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) { |
| 2855 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 2856 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2857 | } |
| 2858 | |
| 2859 | void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 2860 | // Will be generated at use site. |
| 2861 | } |
| 2862 | |
| 2863 | void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) { |
| 2864 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 2865 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2866 | } |
| 2867 | |
| 2868 | void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 2869 | // Will be generated at use site. |
| 2870 | } |
| 2871 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2872 | void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2873 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2874 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2875 | // the method_idx. |
| 2876 | HandleInvoke(invoke); |
| 2877 | } |
| 2878 | |
| 2879 | void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2880 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2881 | } |
| 2882 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2883 | void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) { |
| 2884 | InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor; |
| 2885 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 2886 | } |
| 2887 | |
| 2888 | void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2889 | HandleInvoke(invoke); |
| 2890 | // The register T0 is required to be used for the hidden argument in |
| 2891 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
| 2892 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); |
| 2893 | } |
| 2894 | |
| 2895 | void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2896 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 2897 | GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2898 | Location receiver = invoke->GetLocations()->InAt(0); |
| 2899 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2900 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2901 | |
| 2902 | // Set the hidden argument. |
| 2903 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(), |
| 2904 | invoke->GetDexMethodIndex()); |
| 2905 | |
| 2906 | // temp = object->GetClass(); |
| 2907 | if (receiver.IsStackSlot()) { |
| 2908 | __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex()); |
| 2909 | __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset); |
| 2910 | } else { |
| 2911 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset); |
| 2912 | } |
| 2913 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2914 | __ LoadFromOffset(kLoadDoubleword, temp, temp, |
| 2915 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 2916 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2917 | invoke->GetImtIndex(), kMips64PointerSize)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2918 | // temp = temp->GetImtEntryAt(method_offset); |
| 2919 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 2920 | // T9 = temp->GetEntryPoint(); |
| 2921 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 2922 | // T9(); |
| 2923 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2924 | __ Nop(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2925 | DCHECK(!codegen_->IsLeafMethod()); |
| 2926 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2927 | } |
| 2928 | |
| 2929 | void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 2930 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 2931 | if (intrinsic.TryDispatch(invoke)) { |
| 2932 | return; |
| 2933 | } |
| 2934 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2935 | HandleInvoke(invoke); |
| 2936 | } |
| 2937 | |
| 2938 | void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2939 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2940 | // art::PrepareForRegisterAllocation. |
| 2941 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2942 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 2943 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 2944 | if (intrinsic.TryDispatch(invoke)) { |
| 2945 | return; |
| 2946 | } |
| 2947 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2948 | HandleInvoke(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2949 | } |
| 2950 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 2951 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2952 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 2953 | IntrinsicCodeGeneratorMIPS64 intrinsic(codegen); |
| 2954 | intrinsic.Dispatch(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2955 | return true; |
| 2956 | } |
| 2957 | return false; |
| 2958 | } |
| 2959 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2960 | HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind( |
| 2961 | HLoadString::LoadKind desired_string_load_kind ATTRIBUTE_UNUSED) { |
| 2962 | // TODO: Implement other kinds. |
| 2963 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 2964 | } |
| 2965 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 2966 | HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind( |
| 2967 | HLoadClass::LoadKind desired_class_load_kind) { |
| 2968 | DCHECK_NE(desired_class_load_kind, HLoadClass::LoadKind::kReferrersClass); |
| 2969 | // TODO: Implement other kinds. |
| 2970 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 2971 | } |
| 2972 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2973 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch( |
| 2974 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame^] | 2975 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2976 | switch (desired_dispatch_info.method_load_kind) { |
| 2977 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 2978 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 2979 | // TODO: Implement these types. For the moment, we fall back to kDexCacheViaMethod. |
| 2980 | return HInvokeStaticOrDirect::DispatchInfo { |
| 2981 | HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod, |
| 2982 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 2983 | 0u, |
| 2984 | 0u |
| 2985 | }; |
| 2986 | default: |
| 2987 | break; |
| 2988 | } |
| 2989 | switch (desired_dispatch_info.code_ptr_location) { |
| 2990 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 2991 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
| 2992 | // TODO: Implement these types. For the moment, we fall back to kCallArtMethod. |
| 2993 | return HInvokeStaticOrDirect::DispatchInfo { |
| 2994 | desired_dispatch_info.method_load_kind, |
| 2995 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 2996 | desired_dispatch_info.method_load_data, |
| 2997 | 0u |
| 2998 | }; |
| 2999 | default: |
| 3000 | return desired_dispatch_info; |
| 3001 | } |
| 3002 | } |
| 3003 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3004 | void CodeGeneratorMIPS64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 3005 | // All registers are assumed to be correctly set up per the calling convention. |
| 3006 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3007 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3008 | switch (invoke->GetMethodLoadKind()) { |
| 3009 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 3010 | // temp = thread->string_init_entrypoint |
| 3011 | __ LoadFromOffset(kLoadDoubleword, |
| 3012 | temp.AsRegister<GpuRegister>(), |
| 3013 | TR, |
| 3014 | invoke->GetStringInitOffset()); |
| 3015 | break; |
| 3016 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3017 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3018 | break; |
| 3019 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3020 | __ LoadConst64(temp.AsRegister<GpuRegister>(), invoke->GetMethodAddress()); |
| 3021 | break; |
| 3022 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3023 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3024 | // TODO: Implement these types. |
| 3025 | // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 3026 | LOG(FATAL) << "Unsupported"; |
| 3027 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3028 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3029 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3030 | GpuRegister reg = temp.AsRegister<GpuRegister>(); |
| 3031 | GpuRegister method_reg; |
| 3032 | if (current_method.IsRegister()) { |
| 3033 | method_reg = current_method.AsRegister<GpuRegister>(); |
| 3034 | } else { |
| 3035 | // TODO: use the appropriate DCHECK() here if possible. |
| 3036 | // DCHECK(invoke->GetLocations()->Intrinsified()); |
| 3037 | DCHECK(!current_method.IsValid()); |
| 3038 | method_reg = reg; |
| 3039 | __ Ld(reg, SP, kCurrentMethodStackOffset); |
| 3040 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3041 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3042 | // temp = temp->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3043 | __ LoadFromOffset(kLoadDoubleword, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3044 | reg, |
| 3045 | method_reg, |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3046 | ArtMethod::DexCacheResolvedMethodsOffset(kMips64PointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 3047 | // temp = temp[index_in_cache]; |
| 3048 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 3049 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3050 | __ LoadFromOffset(kLoadDoubleword, |
| 3051 | reg, |
| 3052 | reg, |
| 3053 | CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 3054 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3055 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3056 | } |
| 3057 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3058 | switch (invoke->GetCodePtrLocation()) { |
| 3059 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3060 | __ Jialc(&frame_entry_label_, T9); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3061 | break; |
| 3062 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3063 | // LR = invoke->GetDirectCodePtr(); |
| 3064 | __ LoadConst64(T9, invoke->GetDirectCodePtr()); |
| 3065 | // LR() |
| 3066 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3067 | __ Nop(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3068 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3069 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3070 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
| 3071 | // TODO: Implement these types. |
| 3072 | // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 3073 | LOG(FATAL) << "Unsupported"; |
| 3074 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3075 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3076 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
| 3077 | __ LoadFromOffset(kLoadDoubleword, |
| 3078 | T9, |
| 3079 | callee_method.AsRegister<GpuRegister>(), |
| 3080 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3081 | kMips64PointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3082 | // T9() |
| 3083 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3084 | __ Nop(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3085 | break; |
| 3086 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3087 | DCHECK(!IsLeafMethod()); |
| 3088 | } |
| 3089 | |
| 3090 | void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3091 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3092 | // art::PrepareForRegisterAllocation. |
| 3093 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3094 | |
| 3095 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3096 | return; |
| 3097 | } |
| 3098 | |
| 3099 | LocationSummary* locations = invoke->GetLocations(); |
| 3100 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 3101 | locations->HasTemps() |
| 3102 | ? locations->GetTemp(0) |
| 3103 | : Location::NoLocation()); |
| 3104 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3105 | } |
| 3106 | |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 3107 | void CodeGeneratorMIPS64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3108 | // Use the calling convention instead of the location of the receiver, as |
| 3109 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 3110 | // slow path, the arguments have been moved to the right place, so here we are |
| 3111 | // guaranteed that the receiver is the first register of the calling convention. |
| 3112 | InvokeDexCallingConvention calling_convention; |
| 3113 | GpuRegister receiver = calling_convention.GetRegisterAt(0); |
| 3114 | |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 3115 | GpuRegister temp = temp_location.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3116 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3117 | invoke->GetVTableIndex(), kMips64PointerSize).SizeValue(); |
| 3118 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3119 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3120 | |
| 3121 | // temp = object->GetClass(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3122 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 3123 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3124 | // temp = temp->GetMethodAt(method_offset); |
| 3125 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 3126 | // T9 = temp->GetEntryPoint(); |
| 3127 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 3128 | // T9(); |
| 3129 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3130 | __ Nop(); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 3131 | } |
| 3132 | |
| 3133 | void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 3134 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3135 | return; |
| 3136 | } |
| 3137 | |
| 3138 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3139 | DCHECK(!codegen_->IsLeafMethod()); |
| 3140 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3141 | } |
| 3142 | |
| 3143 | void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3144 | InvokeRuntimeCallingConvention calling_convention; |
| 3145 | CodeGenerator::CreateLoadClassLocationSummary( |
| 3146 | cls, |
| 3147 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Alexey Frunze | 00580bd | 2015-11-11 13:31:12 -0800 | [diff] [blame] | 3148 | calling_convention.GetReturnLocation(cls->GetType())); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3149 | } |
| 3150 | |
| 3151 | void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) { |
| 3152 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3153 | if (cls->NeedsAccessCheck()) { |
| 3154 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 3155 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3156 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 3157 | return; |
| 3158 | } |
| 3159 | |
| 3160 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3161 | GpuRegister current_method = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3162 | if (cls->IsReferrersClass()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3163 | DCHECK(!cls->CanCallRuntime()); |
| 3164 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 3165 | __ LoadFromOffset(kLoadUnsignedWord, out, current_method, |
| 3166 | ArtMethod::DeclaringClassOffset().Int32Value()); |
| 3167 | } else { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3168 | __ LoadFromOffset(kLoadDoubleword, out, current_method, |
| 3169 | ArtMethod::DexCacheResolvedTypesOffset(kMips64PointerSize).Int32Value()); |
Roland Levillain | 698fa97 | 2015-12-16 17:06:47 +0000 | [diff] [blame] | 3170 | __ LoadFromOffset( |
| 3171 | kLoadUnsignedWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3172 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 3173 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 3174 | DCHECK(cls->CanCallRuntime()); |
| 3175 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64( |
| 3176 | cls, |
| 3177 | cls, |
| 3178 | cls->GetDexPc(), |
| 3179 | cls->MustGenerateClinitCheck()); |
| 3180 | codegen_->AddSlowPath(slow_path); |
| 3181 | if (!cls->IsInDexCache()) { |
| 3182 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 3183 | } |
| 3184 | if (cls->MustGenerateClinitCheck()) { |
| 3185 | GenerateClassInitializationCheck(slow_path, out); |
| 3186 | } else { |
| 3187 | __ Bind(slow_path->GetExitLabel()); |
| 3188 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3189 | } |
| 3190 | } |
| 3191 | } |
| 3192 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3193 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3194 | return Thread::ExceptionOffset<kMips64PointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3195 | } |
| 3196 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3197 | void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) { |
| 3198 | LocationSummary* locations = |
| 3199 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 3200 | locations->SetOut(Location::RequiresRegister()); |
| 3201 | } |
| 3202 | |
| 3203 | void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) { |
| 3204 | GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3205 | __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset()); |
| 3206 | } |
| 3207 | |
| 3208 | void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) { |
| 3209 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 3210 | } |
| 3211 | |
| 3212 | void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 3213 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3216 | void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3217 | LocationSummary::CallKind call_kind = load->NeedsEnvironment() |
| 3218 | ? LocationSummary::kCallOnSlowPath |
| 3219 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 3220 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3221 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3222 | locations->SetOut(Location::RequiresRegister()); |
| 3223 | } |
| 3224 | |
| 3225 | void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) { |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 3226 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
| 3227 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS64(load); |
| 3228 | codegen_->AddSlowPath(slow_path); |
| 3229 | __ Bc(slow_path->GetEntryLabel()); |
| 3230 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3231 | } |
| 3232 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3233 | void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) { |
| 3234 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3235 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3236 | } |
| 3237 | |
| 3238 | void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 3239 | // Will be generated at use site. |
| 3240 | } |
| 3241 | |
| 3242 | void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3243 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3244 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3245 | InvokeRuntimeCallingConvention calling_convention; |
| 3246 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3247 | } |
| 3248 | |
| 3249 | void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 3250 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3251 | instruction, |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 3252 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3253 | if (instruction->IsEnter()) { |
| 3254 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 3255 | } else { |
| 3256 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 3257 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3258 | } |
| 3259 | |
| 3260 | void LocationsBuilderMIPS64::VisitMul(HMul* mul) { |
| 3261 | LocationSummary* locations = |
| 3262 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3263 | switch (mul->GetResultType()) { |
| 3264 | case Primitive::kPrimInt: |
| 3265 | case Primitive::kPrimLong: |
| 3266 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3267 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3268 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3269 | break; |
| 3270 | |
| 3271 | case Primitive::kPrimFloat: |
| 3272 | case Primitive::kPrimDouble: |
| 3273 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3274 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3275 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3276 | break; |
| 3277 | |
| 3278 | default: |
| 3279 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 3280 | } |
| 3281 | } |
| 3282 | |
| 3283 | void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) { |
| 3284 | Primitive::Type type = instruction->GetType(); |
| 3285 | LocationSummary* locations = instruction->GetLocations(); |
| 3286 | |
| 3287 | switch (type) { |
| 3288 | case Primitive::kPrimInt: |
| 3289 | case Primitive::kPrimLong: { |
| 3290 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3291 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3292 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
| 3293 | if (type == Primitive::kPrimInt) |
| 3294 | __ MulR6(dst, lhs, rhs); |
| 3295 | else |
| 3296 | __ Dmul(dst, lhs, rhs); |
| 3297 | break; |
| 3298 | } |
| 3299 | case Primitive::kPrimFloat: |
| 3300 | case Primitive::kPrimDouble: { |
| 3301 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 3302 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3303 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3304 | if (type == Primitive::kPrimFloat) |
| 3305 | __ MulS(dst, lhs, rhs); |
| 3306 | else |
| 3307 | __ MulD(dst, lhs, rhs); |
| 3308 | break; |
| 3309 | } |
| 3310 | default: |
| 3311 | LOG(FATAL) << "Unexpected mul type " << type; |
| 3312 | } |
| 3313 | } |
| 3314 | |
| 3315 | void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) { |
| 3316 | LocationSummary* locations = |
| 3317 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 3318 | switch (neg->GetResultType()) { |
| 3319 | case Primitive::kPrimInt: |
| 3320 | case Primitive::kPrimLong: |
| 3321 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3322 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3323 | break; |
| 3324 | |
| 3325 | case Primitive::kPrimFloat: |
| 3326 | case Primitive::kPrimDouble: |
| 3327 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3328 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3329 | break; |
| 3330 | |
| 3331 | default: |
| 3332 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3333 | } |
| 3334 | } |
| 3335 | |
| 3336 | void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) { |
| 3337 | Primitive::Type type = instruction->GetType(); |
| 3338 | LocationSummary* locations = instruction->GetLocations(); |
| 3339 | |
| 3340 | switch (type) { |
| 3341 | case Primitive::kPrimInt: |
| 3342 | case Primitive::kPrimLong: { |
| 3343 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3344 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3345 | if (type == Primitive::kPrimInt) |
| 3346 | __ Subu(dst, ZERO, src); |
| 3347 | else |
| 3348 | __ Dsubu(dst, ZERO, src); |
| 3349 | break; |
| 3350 | } |
| 3351 | case Primitive::kPrimFloat: |
| 3352 | case Primitive::kPrimDouble: { |
| 3353 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 3354 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3355 | if (type == Primitive::kPrimFloat) |
| 3356 | __ NegS(dst, src); |
| 3357 | else |
| 3358 | __ NegD(dst, src); |
| 3359 | break; |
| 3360 | } |
| 3361 | default: |
| 3362 | LOG(FATAL) << "Unexpected neg type " << type; |
| 3363 | } |
| 3364 | } |
| 3365 | |
| 3366 | void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) { |
| 3367 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3368 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3369 | InvokeRuntimeCallingConvention calling_convention; |
| 3370 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3371 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 3372 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3373 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 3374 | } |
| 3375 | |
| 3376 | void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) { |
| 3377 | LocationSummary* locations = instruction->GetLocations(); |
| 3378 | // Move an uint16_t value to a register. |
| 3379 | __ LoadConst32(locations->GetTemp(0).AsRegister<GpuRegister>(), instruction->GetTypeIndex()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 3380 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3381 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
| 3382 | } |
| 3383 | |
| 3384 | void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) { |
| 3385 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3386 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3387 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3388 | if (instruction->IsStringAlloc()) { |
| 3389 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3390 | } else { |
| 3391 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3392 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3393 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3394 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 3395 | } |
| 3396 | |
| 3397 | void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3398 | if (instruction->IsStringAlloc()) { |
| 3399 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3400 | GpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 3401 | MemberOffset code_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3402 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3403 | __ LoadFromOffset(kLoadDoubleword, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 3404 | __ LoadFromOffset(kLoadDoubleword, T9, temp, code_offset.Int32Value()); |
| 3405 | __ Jalr(T9); |
| 3406 | __ Nop(); |
| 3407 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3408 | } else { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 3409 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3410 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3411 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3412 | } |
| 3413 | |
| 3414 | void LocationsBuilderMIPS64::VisitNot(HNot* instruction) { |
| 3415 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 3416 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3417 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3418 | } |
| 3419 | |
| 3420 | void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) { |
| 3421 | Primitive::Type type = instruction->GetType(); |
| 3422 | LocationSummary* locations = instruction->GetLocations(); |
| 3423 | |
| 3424 | switch (type) { |
| 3425 | case Primitive::kPrimInt: |
| 3426 | case Primitive::kPrimLong: { |
| 3427 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3428 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3429 | __ Nor(dst, src, ZERO); |
| 3430 | break; |
| 3431 | } |
| 3432 | |
| 3433 | default: |
| 3434 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 3435 | } |
| 3436 | } |
| 3437 | |
| 3438 | void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
| 3439 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 3440 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3441 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3442 | } |
| 3443 | |
| 3444 | void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
| 3445 | LocationSummary* locations = instruction->GetLocations(); |
| 3446 | __ Xori(locations->Out().AsRegister<GpuRegister>(), |
| 3447 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 3448 | 1); |
| 3449 | } |
| 3450 | |
| 3451 | void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3452 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 3453 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3454 | } |
| 3455 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 3456 | void CodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 3457 | if (CanMoveNullCheckToUser(instruction)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3458 | return; |
| 3459 | } |
| 3460 | Location obj = instruction->GetLocations()->InAt(0); |
| 3461 | |
| 3462 | __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 3463 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3464 | } |
| 3465 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 3466 | void CodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3467 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 3468 | AddSlowPath(slow_path); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3469 | |
| 3470 | Location obj = instruction->GetLocations()->InAt(0); |
| 3471 | |
| 3472 | __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 3473 | } |
| 3474 | |
| 3475 | void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 3476 | codegen_->GenerateNullCheck(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | void LocationsBuilderMIPS64::VisitOr(HOr* instruction) { |
| 3480 | HandleBinaryOp(instruction); |
| 3481 | } |
| 3482 | |
| 3483 | void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) { |
| 3484 | HandleBinaryOp(instruction); |
| 3485 | } |
| 3486 | |
| 3487 | void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 3488 | LOG(FATAL) << "Unreachable"; |
| 3489 | } |
| 3490 | |
| 3491 | void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) { |
| 3492 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 3493 | } |
| 3494 | |
| 3495 | void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) { |
| 3496 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 3497 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3498 | if (location.IsStackSlot()) { |
| 3499 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3500 | } else if (location.IsDoubleStackSlot()) { |
| 3501 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3502 | } |
| 3503 | locations->SetOut(location); |
| 3504 | } |
| 3505 | |
| 3506 | void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction |
| 3507 | ATTRIBUTE_UNUSED) { |
| 3508 | // Nothing to do, the parameter is already at its location. |
| 3509 | } |
| 3510 | |
| 3511 | void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3512 | LocationSummary* locations = |
| 3513 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3514 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3515 | } |
| 3516 | |
| 3517 | void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction |
| 3518 | ATTRIBUTE_UNUSED) { |
| 3519 | // Nothing to do, the method is already at its location. |
| 3520 | } |
| 3521 | |
| 3522 | void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) { |
| 3523 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3524 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3525 | locations->SetInAt(i, Location::Any()); |
| 3526 | } |
| 3527 | locations->SetOut(Location::Any()); |
| 3528 | } |
| 3529 | |
| 3530 | void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 3531 | LOG(FATAL) << "Unreachable"; |
| 3532 | } |
| 3533 | |
| 3534 | void LocationsBuilderMIPS64::VisitRem(HRem* rem) { |
| 3535 | Primitive::Type type = rem->GetResultType(); |
| 3536 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3537 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 3538 | : LocationSummary::kNoCall; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3539 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3540 | |
| 3541 | switch (type) { |
| 3542 | case Primitive::kPrimInt: |
| 3543 | case Primitive::kPrimLong: |
| 3544 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3545 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3546 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3547 | break; |
| 3548 | |
| 3549 | case Primitive::kPrimFloat: |
| 3550 | case Primitive::kPrimDouble: { |
| 3551 | InvokeRuntimeCallingConvention calling_convention; |
| 3552 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3553 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3554 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 3555 | break; |
| 3556 | } |
| 3557 | |
| 3558 | default: |
| 3559 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3560 | } |
| 3561 | } |
| 3562 | |
| 3563 | void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) { |
| 3564 | Primitive::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3565 | |
| 3566 | switch (type) { |
| 3567 | case Primitive::kPrimInt: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3568 | case Primitive::kPrimLong: |
| 3569 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3570 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3571 | |
| 3572 | case Primitive::kPrimFloat: |
| 3573 | case Primitive::kPrimDouble: { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 3574 | QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod; |
| 3575 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3576 | if (type == Primitive::kPrimFloat) { |
| 3577 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 3578 | } else { |
| 3579 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 3580 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3581 | break; |
| 3582 | } |
| 3583 | default: |
| 3584 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3585 | } |
| 3586 | } |
| 3587 | |
| 3588 | void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3589 | memory_barrier->SetLocations(nullptr); |
| 3590 | } |
| 3591 | |
| 3592 | void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3593 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3594 | } |
| 3595 | |
| 3596 | void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) { |
| 3597 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
| 3598 | Primitive::Type return_type = ret->InputAt(0)->GetType(); |
| 3599 | locations->SetInAt(0, Mips64ReturnLocation(return_type)); |
| 3600 | } |
| 3601 | |
| 3602 | void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 3603 | codegen_->GenerateFrameExit(); |
| 3604 | } |
| 3605 | |
| 3606 | void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) { |
| 3607 | ret->SetLocations(nullptr); |
| 3608 | } |
| 3609 | |
| 3610 | void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 3611 | codegen_->GenerateFrameExit(); |
| 3612 | } |
| 3613 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 3614 | void LocationsBuilderMIPS64::VisitRor(HRor* ror) { |
| 3615 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3616 | } |
| 3617 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 3618 | void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) { |
| 3619 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3620 | } |
| 3621 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3622 | void LocationsBuilderMIPS64::VisitShl(HShl* shl) { |
| 3623 | HandleShift(shl); |
| 3624 | } |
| 3625 | |
| 3626 | void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) { |
| 3627 | HandleShift(shl); |
| 3628 | } |
| 3629 | |
| 3630 | void LocationsBuilderMIPS64::VisitShr(HShr* shr) { |
| 3631 | HandleShift(shr); |
| 3632 | } |
| 3633 | |
| 3634 | void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) { |
| 3635 | HandleShift(shr); |
| 3636 | } |
| 3637 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3638 | void LocationsBuilderMIPS64::VisitSub(HSub* instruction) { |
| 3639 | HandleBinaryOp(instruction); |
| 3640 | } |
| 3641 | |
| 3642 | void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) { |
| 3643 | HandleBinaryOp(instruction); |
| 3644 | } |
| 3645 | |
| 3646 | void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3647 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3648 | } |
| 3649 | |
| 3650 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3651 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3652 | } |
| 3653 | |
| 3654 | void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3655 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3656 | } |
| 3657 | |
| 3658 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 3659 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 3662 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet( |
| 3663 | HUnresolvedInstanceFieldGet* instruction) { |
| 3664 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 3665 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3666 | instruction, instruction->GetFieldType(), calling_convention); |
| 3667 | } |
| 3668 | |
| 3669 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet( |
| 3670 | HUnresolvedInstanceFieldGet* instruction) { |
| 3671 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 3672 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3673 | instruction->GetFieldType(), |
| 3674 | instruction->GetFieldIndex(), |
| 3675 | instruction->GetDexPc(), |
| 3676 | calling_convention); |
| 3677 | } |
| 3678 | |
| 3679 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet( |
| 3680 | HUnresolvedInstanceFieldSet* instruction) { |
| 3681 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 3682 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3683 | instruction, instruction->GetFieldType(), calling_convention); |
| 3684 | } |
| 3685 | |
| 3686 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet( |
| 3687 | HUnresolvedInstanceFieldSet* instruction) { |
| 3688 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 3689 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3690 | instruction->GetFieldType(), |
| 3691 | instruction->GetFieldIndex(), |
| 3692 | instruction->GetDexPc(), |
| 3693 | calling_convention); |
| 3694 | } |
| 3695 | |
| 3696 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet( |
| 3697 | HUnresolvedStaticFieldGet* instruction) { |
| 3698 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 3699 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3700 | instruction, instruction->GetFieldType(), calling_convention); |
| 3701 | } |
| 3702 | |
| 3703 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet( |
| 3704 | HUnresolvedStaticFieldGet* instruction) { |
| 3705 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 3706 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3707 | instruction->GetFieldType(), |
| 3708 | instruction->GetFieldIndex(), |
| 3709 | instruction->GetDexPc(), |
| 3710 | calling_convention); |
| 3711 | } |
| 3712 | |
| 3713 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet( |
| 3714 | HUnresolvedStaticFieldSet* instruction) { |
| 3715 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 3716 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3717 | instruction, instruction->GetFieldType(), calling_convention); |
| 3718 | } |
| 3719 | |
| 3720 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet( |
| 3721 | HUnresolvedStaticFieldSet* instruction) { |
| 3722 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 3723 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3724 | instruction->GetFieldType(), |
| 3725 | instruction->GetFieldIndex(), |
| 3726 | instruction->GetDexPc(), |
| 3727 | calling_convention); |
| 3728 | } |
| 3729 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3730 | void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3731 | LocationSummary* locations = |
| 3732 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3733 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3734 | } |
| 3735 | |
| 3736 | void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 3737 | HBasicBlock* block = instruction->GetBlock(); |
| 3738 | if (block->GetLoopInformation() != nullptr) { |
| 3739 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 3740 | // The back edge will generate the suspend check. |
| 3741 | return; |
| 3742 | } |
| 3743 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 3744 | // The goto will generate the suspend check. |
| 3745 | return; |
| 3746 | } |
| 3747 | GenerateSuspendCheck(instruction, nullptr); |
| 3748 | } |
| 3749 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3750 | void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) { |
| 3751 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3752 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3753 | InvokeRuntimeCallingConvention calling_convention; |
| 3754 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3755 | } |
| 3756 | |
| 3757 | void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 3758 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3759 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 3760 | } |
| 3761 | |
| 3762 | void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
| 3763 | Primitive::Type input_type = conversion->GetInputType(); |
| 3764 | Primitive::Type result_type = conversion->GetResultType(); |
| 3765 | DCHECK_NE(input_type, result_type); |
| 3766 | |
| 3767 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 3768 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 3769 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 3770 | } |
| 3771 | |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3772 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion); |
| 3773 | |
| 3774 | if (Primitive::IsFloatingPointType(input_type)) { |
| 3775 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3776 | } else { |
| 3777 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3778 | } |
| 3779 | |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3780 | if (Primitive::IsFloatingPointType(result_type)) { |
| 3781 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3782 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3783 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3784 | } |
| 3785 | } |
| 3786 | |
| 3787 | void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
| 3788 | LocationSummary* locations = conversion->GetLocations(); |
| 3789 | Primitive::Type result_type = conversion->GetResultType(); |
| 3790 | Primitive::Type input_type = conversion->GetInputType(); |
| 3791 | |
| 3792 | DCHECK_NE(input_type, result_type); |
| 3793 | |
| 3794 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
| 3795 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3796 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3797 | |
| 3798 | switch (result_type) { |
| 3799 | case Primitive::kPrimChar: |
| 3800 | __ Andi(dst, src, 0xFFFF); |
| 3801 | break; |
| 3802 | case Primitive::kPrimByte: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3803 | if (input_type == Primitive::kPrimLong) { |
| 3804 | // Type conversion from long to types narrower than int is a result of code |
| 3805 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 3806 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 3807 | __ Sll(dst, src, 0); |
| 3808 | __ Seb(dst, dst); |
| 3809 | } else { |
| 3810 | __ Seb(dst, src); |
| 3811 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3812 | break; |
| 3813 | case Primitive::kPrimShort: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3814 | if (input_type == Primitive::kPrimLong) { |
| 3815 | // Type conversion from long to types narrower than int is a result of code |
| 3816 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 3817 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 3818 | __ Sll(dst, src, 0); |
| 3819 | __ Seh(dst, dst); |
| 3820 | } else { |
| 3821 | __ Seh(dst, src); |
| 3822 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3823 | break; |
| 3824 | case Primitive::kPrimInt: |
| 3825 | case Primitive::kPrimLong: |
| 3826 | // Sign-extend 32-bit int into bits 32 through 63 for |
| 3827 | // int-to-long and long-to-int conversions |
| 3828 | __ Sll(dst, src, 0); |
| 3829 | break; |
| 3830 | |
| 3831 | default: |
| 3832 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3833 | << " to " << result_type; |
| 3834 | } |
| 3835 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3836 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 3837 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3838 | if (input_type == Primitive::kPrimLong) { |
| 3839 | __ Dmtc1(src, FTMP); |
| 3840 | if (result_type == Primitive::kPrimFloat) { |
| 3841 | __ Cvtsl(dst, FTMP); |
| 3842 | } else { |
| 3843 | __ Cvtdl(dst, FTMP); |
| 3844 | } |
| 3845 | } else { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3846 | __ Mtc1(src, FTMP); |
| 3847 | if (result_type == Primitive::kPrimFloat) { |
| 3848 | __ Cvtsw(dst, FTMP); |
| 3849 | } else { |
| 3850 | __ Cvtdw(dst, FTMP); |
| 3851 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3852 | } |
| 3853 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
| 3854 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3855 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3856 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3857 | Mips64Label truncate; |
| 3858 | Mips64Label done; |
| 3859 | |
| 3860 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive |
| 3861 | // value when the input is either a NaN or is outside of the range of the output type |
| 3862 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce |
| 3863 | // the same result. |
| 3864 | // |
| 3865 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum |
| 3866 | // value of the output type if the input is outside of the range after the truncation or |
| 3867 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct |
| 3868 | // results. This matches the desired float/double-to-int/long conversion exactly. |
| 3869 | // |
| 3870 | // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction. |
| 3871 | // |
| 3872 | // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate |
| 3873 | // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6, |
| 3874 | // even though it must be NAN2008=1 on R6. |
| 3875 | // |
| 3876 | // The code takes care of the different behaviors by first comparing the input to the |
| 3877 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). |
| 3878 | // If the input is greater than or equal to the minimum, it procedes to the truncate |
| 3879 | // instruction, which will handle such an input the same way irrespective of NAN2008. |
| 3880 | // Otherwise the input is compared to itself to determine whether it is a NaN or not |
| 3881 | // in order to return either zero or the minimum value. |
| 3882 | // |
| 3883 | // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the |
| 3884 | // truncate instruction for MIPS64R6. |
| 3885 | if (input_type == Primitive::kPrimFloat) { |
| 3886 | uint32_t min_val = (result_type == Primitive::kPrimLong) |
| 3887 | ? bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min()) |
| 3888 | : bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); |
| 3889 | __ LoadConst32(TMP, min_val); |
| 3890 | __ Mtc1(TMP, FTMP); |
| 3891 | __ CmpLeS(FTMP, FTMP, src); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3892 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3893 | uint64_t min_val = (result_type == Primitive::kPrimLong) |
| 3894 | ? bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min()) |
| 3895 | : bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); |
| 3896 | __ LoadConst64(TMP, min_val); |
| 3897 | __ Dmtc1(TMP, FTMP); |
| 3898 | __ CmpLeD(FTMP, FTMP, src); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3899 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3900 | |
| 3901 | __ Bc1nez(FTMP, &truncate); |
| 3902 | |
| 3903 | if (input_type == Primitive::kPrimFloat) { |
| 3904 | __ CmpEqS(FTMP, src, src); |
| 3905 | } else { |
| 3906 | __ CmpEqD(FTMP, src, src); |
| 3907 | } |
| 3908 | if (result_type == Primitive::kPrimLong) { |
| 3909 | __ LoadConst64(dst, std::numeric_limits<int64_t>::min()); |
| 3910 | } else { |
| 3911 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 3912 | } |
| 3913 | __ Mfc1(TMP, FTMP); |
| 3914 | __ And(dst, dst, TMP); |
| 3915 | |
| 3916 | __ Bc(&done); |
| 3917 | |
| 3918 | __ Bind(&truncate); |
| 3919 | |
| 3920 | if (result_type == Primitive::kPrimLong) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3921 | if (input_type == Primitive::kPrimFloat) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3922 | __ TruncLS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3923 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3924 | __ TruncLD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3925 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3926 | __ Dmfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3927 | } else { |
| 3928 | if (input_type == Primitive::kPrimFloat) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3929 | __ TruncWS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3930 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3931 | __ TruncWD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3932 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3933 | __ Mfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3934 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 3935 | |
| 3936 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3937 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 3938 | Primitive::IsFloatingPointType(input_type)) { |
| 3939 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 3940 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3941 | if (result_type == Primitive::kPrimFloat) { |
| 3942 | __ Cvtsd(dst, src); |
| 3943 | } else { |
| 3944 | __ Cvtds(dst, src); |
| 3945 | } |
| 3946 | } else { |
| 3947 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 3948 | << " to " << result_type; |
| 3949 | } |
| 3950 | } |
| 3951 | |
| 3952 | void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) { |
| 3953 | HandleShift(ushr); |
| 3954 | } |
| 3955 | |
| 3956 | void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) { |
| 3957 | HandleShift(ushr); |
| 3958 | } |
| 3959 | |
| 3960 | void LocationsBuilderMIPS64::VisitXor(HXor* instruction) { |
| 3961 | HandleBinaryOp(instruction); |
| 3962 | } |
| 3963 | |
| 3964 | void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) { |
| 3965 | HandleBinaryOp(instruction); |
| 3966 | } |
| 3967 | |
| 3968 | void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 3969 | // Nothing to do, this should be removed during prepare for register allocator. |
| 3970 | LOG(FATAL) << "Unreachable"; |
| 3971 | } |
| 3972 | |
| 3973 | void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 3974 | // Nothing to do, this should be removed during prepare for register allocator. |
| 3975 | LOG(FATAL) << "Unreachable"; |
| 3976 | } |
| 3977 | |
| 3978 | void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3979 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3980 | } |
| 3981 | |
| 3982 | void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3983 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3984 | } |
| 3985 | |
| 3986 | void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3987 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3988 | } |
| 3989 | |
| 3990 | void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3991 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3992 | } |
| 3993 | |
| 3994 | void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3995 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3999 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4003 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4004 | } |
| 4005 | |
| 4006 | void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4007 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4011 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4015 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4016 | } |
| 4017 | |
| 4018 | void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4019 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4020 | } |
| 4021 | |
| 4022 | void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4023 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4024 | } |
| 4025 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4026 | void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4027 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4028 | } |
| 4029 | |
| 4030 | void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4031 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4035 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4036 | } |
| 4037 | |
| 4038 | void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4039 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4040 | } |
| 4041 | |
| 4042 | void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4043 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4047 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4048 | } |
| 4049 | |
| 4050 | void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4051 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4052 | } |
| 4053 | |
| 4054 | void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4055 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4056 | } |
| 4057 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4058 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 4059 | void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4060 | LocationSummary* locations = |
| 4061 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 4062 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4063 | } |
| 4064 | |
| 4065 | void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4066 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 4067 | int32_t num_entries = switch_instr->GetNumEntries(); |
| 4068 | LocationSummary* locations = switch_instr->GetLocations(); |
| 4069 | GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 4070 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 4071 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4072 | // Create a set of compare/jumps. |
| 4073 | GpuRegister temp_reg = TMP; |
| 4074 | if (IsInt<16>(-lower_bound)) { |
| 4075 | __ Addiu(temp_reg, value_reg, -lower_bound); |
| 4076 | } else { |
| 4077 | __ LoadConst32(AT, -lower_bound); |
| 4078 | __ Addu(temp_reg, value_reg, AT); |
| 4079 | } |
| 4080 | // Jump to default if index is negative |
| 4081 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 4082 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 4083 | __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block)); |
| 4084 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4085 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4086 | // Jump to successors[0] if value == lower_bound. |
| 4087 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 4088 | int32_t last_index = 0; |
| 4089 | for (; num_entries - last_index > 2; last_index += 2) { |
| 4090 | __ Addiu(temp_reg, temp_reg, -2); |
| 4091 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 4092 | __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 4093 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 4094 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 4095 | } |
| 4096 | if (num_entries - last_index == 2) { |
| 4097 | // The last missing case_value. |
| 4098 | __ Addiu(temp_reg, temp_reg, -1); |
| 4099 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4100 | } |
| 4101 | |
| 4102 | // And the default for any other value. |
| 4103 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4104 | __ Bc(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4105 | } |
| 4106 | } |
| 4107 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4108 | void LocationsBuilderMIPS64::VisitClassTableGet(HClassTableGet*) { |
| 4109 | UNIMPLEMENTED(FATAL) << "ClassTableGet is unimplemented on mips64"; |
| 4110 | } |
| 4111 | |
| 4112 | void InstructionCodeGeneratorMIPS64::VisitClassTableGet(HClassTableGet*) { |
| 4113 | UNIMPLEMENTED(FATAL) << "ClassTableGet is unimplemented on mips64"; |
| 4114 | } |
| 4115 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4116 | } // namespace mips64 |
| 4117 | } // namespace art |