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