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