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