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