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