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