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