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 | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 19 | #include "arch/mips64/asm_support_mips64.h" |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 21 | #include "class_table.h" |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 22 | #include "code_generator_utils.h" |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 23 | #include "compiled_method.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints.h" |
| 25 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| 26 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 27 | #include "heap_poisoning.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 28 | #include "intrinsics.h" |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 29 | #include "intrinsics_mips64.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 30 | #include "linker/linker_patch.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 31 | #include "mirror/array-inl.h" |
| 32 | #include "mirror/class-inl.h" |
| 33 | #include "offsets.h" |
| 34 | #include "thread.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 35 | #include "utils/assembler.h" |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 36 | #include "utils/mips64/assembler_mips64.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 37 | #include "utils/stack_checks.h" |
| 38 | |
| 39 | namespace art { |
| 40 | namespace mips64 { |
| 41 | |
| 42 | static constexpr int kCurrentMethodStackOffset = 0; |
| 43 | static constexpr GpuRegister kMethodRegisterArgument = A0; |
| 44 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 45 | // Flags controlling the use of thunks for Baker read barriers. |
| 46 | constexpr bool kBakerReadBarrierThunksEnableForFields = true; |
| 47 | constexpr bool kBakerReadBarrierThunksEnableForArrays = true; |
| 48 | constexpr bool kBakerReadBarrierThunksEnableForGcRoots = true; |
| 49 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 50 | Location Mips64ReturnLocation(DataType::Type return_type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 51 | switch (return_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 52 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 53 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 54 | case DataType::Type::kInt8: |
| 55 | case DataType::Type::kUint16: |
| 56 | case DataType::Type::kInt16: |
| 57 | case DataType::Type::kInt32: |
| 58 | case DataType::Type::kReference: |
| 59 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 60 | return Location::RegisterLocation(V0); |
| 61 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 62 | case DataType::Type::kFloat32: |
| 63 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 64 | return Location::FpuRegisterLocation(F0); |
| 65 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 66 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 67 | return Location(); |
| 68 | } |
| 69 | UNREACHABLE(); |
| 70 | } |
| 71 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 72 | Location InvokeDexCallingConventionVisitorMIPS64::GetReturnLocation(DataType::Type type) const { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 73 | return Mips64ReturnLocation(type); |
| 74 | } |
| 75 | |
| 76 | Location InvokeDexCallingConventionVisitorMIPS64::GetMethodLocation() const { |
| 77 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 78 | } |
| 79 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 80 | Location InvokeDexCallingConventionVisitorMIPS64::GetNextLocation(DataType::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 81 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 82 | if (type == DataType::Type::kVoid) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 83 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 84 | } |
| 85 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 86 | if (DataType::IsFloatingPointType(type) && |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 87 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 88 | next_location = Location::FpuRegisterLocation( |
| 89 | calling_convention.GetFpuRegisterAt(float_index_++)); |
| 90 | gp_index_++; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 91 | } else if (!DataType::IsFloatingPointType(type) && |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 92 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 93 | next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index_++)); |
| 94 | float_index_++; |
| 95 | } else { |
| 96 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 97 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 98 | : Location::StackSlot(stack_offset); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 102 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 103 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 104 | return next_location; |
| 105 | } |
| 106 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 107 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 108 | return Mips64ReturnLocation(type); |
| 109 | } |
| 110 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 111 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 112 | #define __ down_cast<CodeGeneratorMIPS64*>(codegen)->GetAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 113 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value() |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 114 | |
| 115 | class BoundsCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 116 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 117 | explicit BoundsCheckSlowPathMIPS64(HBoundsCheck* instruction) : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 118 | |
| 119 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 120 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 121 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 122 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 123 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 124 | // Live registers will be restored in the catch block if caught. |
| 125 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 126 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 127 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 128 | // move resolver. |
| 129 | InvokeRuntimeCallingConvention calling_convention; |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 130 | codegen->EmitParallelMoves(locations->InAt(0), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 131 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 132 | DataType::Type::kInt32, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 133 | locations->InAt(1), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 134 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 135 | DataType::Type::kInt32); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 136 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 137 | ? kQuickThrowStringBounds |
| 138 | : kQuickThrowArrayBounds; |
| 139 | mips64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 140 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 141 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 142 | } |
| 143 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 144 | bool IsFatal() const OVERRIDE { return true; } |
| 145 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 146 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS64"; } |
| 147 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 148 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 149 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS64); |
| 150 | }; |
| 151 | |
| 152 | class DivZeroCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 153 | public: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 154 | explicit DivZeroCheckSlowPathMIPS64(HDivZeroCheck* instruction) |
| 155 | : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 156 | |
| 157 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 158 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 159 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 160 | mips64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 161 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 162 | } |
| 163 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 164 | bool IsFatal() const OVERRIDE { return true; } |
| 165 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 166 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS64"; } |
| 167 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 168 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 169 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS64); |
| 170 | }; |
| 171 | |
| 172 | class LoadClassSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 173 | public: |
| 174 | LoadClassSlowPathMIPS64(HLoadClass* cls, |
| 175 | HInstruction* at, |
| 176 | uint32_t dex_pc, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 177 | bool do_clinit, |
| 178 | const CodeGeneratorMIPS64::PcRelativePatchInfo* bss_info_high = nullptr) |
| 179 | : SlowPathCodeMIPS64(at), |
| 180 | cls_(cls), |
| 181 | dex_pc_(dex_pc), |
| 182 | do_clinit_(do_clinit), |
| 183 | bss_info_high_(bss_info_high) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 184 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 185 | } |
| 186 | |
| 187 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 188 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 189 | Location out = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 190 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 191 | const bool baker_or_no_read_barriers = (!kUseReadBarrier || kUseBakerReadBarrier); |
| 192 | InvokeRuntimeCallingConvention calling_convention; |
| 193 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 194 | const bool is_load_class_bss_entry = |
| 195 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 196 | __ Bind(GetEntryLabel()); |
| 197 | SaveLiveRegisters(codegen, locations); |
| 198 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 199 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 200 | GpuRegister entry_address = kNoGpuRegister; |
| 201 | if (is_load_class_bss_entry && baker_or_no_read_barriers) { |
| 202 | GpuRegister temp = locations->GetTemp(0).AsRegister<GpuRegister>(); |
| 203 | bool temp_is_a0 = (temp == calling_convention.GetRegisterAt(0)); |
| 204 | // In the unlucky case that `temp` is A0, we preserve the address in `out` across the |
| 205 | // kSaveEverything call. |
| 206 | entry_address = temp_is_a0 ? out.AsRegister<GpuRegister>() : temp; |
| 207 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 208 | if (temp_is_a0) { |
| 209 | __ Move(entry_address, temp); |
| 210 | } |
| 211 | } |
| 212 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 213 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 214 | __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 215 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 216 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 217 | mips64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 218 | if (do_clinit_) { |
| 219 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 220 | } else { |
| 221 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 222 | } |
| 223 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 224 | // For HLoadClass/kBssEntry, store the resolved class to the BSS entry. |
| 225 | if (is_load_class_bss_entry && baker_or_no_read_barriers) { |
| 226 | // The class entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 227 | DCHECK(bss_info_high_); |
| 228 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 229 | mips64_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index, bss_info_high_); |
| 230 | __ Bind(&info_low->label); |
| 231 | __ StoreToOffset(kStoreWord, |
| 232 | calling_convention.GetRegisterAt(0), |
| 233 | entry_address, |
| 234 | /* placeholder */ 0x5678); |
| 235 | } |
| 236 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 237 | // Move the class to the desired location. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 238 | if (out.IsValid()) { |
| 239 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 240 | DataType::Type type = instruction_->GetType(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 241 | mips64_codegen->MoveLocation(out, |
| 242 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 243 | type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 244 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 245 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 246 | |
| 247 | // For HLoadClass/kBssEntry, store the resolved class to the BSS entry. |
| 248 | if (is_load_class_bss_entry && !baker_or_no_read_barriers) { |
| 249 | // For non-Baker read barriers we need to re-calculate the address of |
| 250 | // the class entry. |
| 251 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 252 | mips64_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 253 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 254 | mips64_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index, info_high); |
| 255 | mips64_codegen->EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, info_low); |
| 256 | __ StoreToOffset(kStoreWord, out.AsRegister<GpuRegister>(), TMP, /* placeholder */ 0x5678); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 257 | } |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 258 | __ Bc(GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 261 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS64"; } |
| 262 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 263 | private: |
| 264 | // The class this slow path will load. |
| 265 | HLoadClass* const cls_; |
| 266 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 267 | // The dex PC of `at_`. |
| 268 | const uint32_t dex_pc_; |
| 269 | |
| 270 | // Whether to initialize the class. |
| 271 | const bool do_clinit_; |
| 272 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 273 | // Pointer to the high half PC-relative patch info for HLoadClass/kBssEntry. |
| 274 | const CodeGeneratorMIPS64::PcRelativePatchInfo* bss_info_high_; |
| 275 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 276 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS64); |
| 277 | }; |
| 278 | |
| 279 | class LoadStringSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 280 | public: |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 281 | explicit LoadStringSlowPathMIPS64(HLoadString* instruction, |
| 282 | const CodeGeneratorMIPS64::PcRelativePatchInfo* bss_info_high) |
| 283 | : SlowPathCodeMIPS64(instruction), bss_info_high_(bss_info_high) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 284 | |
| 285 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 286 | DCHECK(instruction_->IsLoadString()); |
| 287 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 288 | LocationSummary* locations = instruction_->GetLocations(); |
| 289 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 290 | HLoadString* load = instruction_->AsLoadString(); |
| 291 | const dex::StringIndex string_index = load->GetStringIndex(); |
| 292 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 293 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 294 | const bool baker_or_no_read_barriers = (!kUseReadBarrier || kUseBakerReadBarrier); |
| 295 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 296 | __ Bind(GetEntryLabel()); |
| 297 | SaveLiveRegisters(codegen, locations); |
| 298 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 299 | // For HLoadString/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 300 | GpuRegister entry_address = kNoGpuRegister; |
| 301 | if (baker_or_no_read_barriers) { |
| 302 | GpuRegister temp = locations->GetTemp(0).AsRegister<GpuRegister>(); |
| 303 | bool temp_is_a0 = (temp == calling_convention.GetRegisterAt(0)); |
| 304 | // In the unlucky case that `temp` is A0, we preserve the address in `out` across the |
| 305 | // kSaveEverything call. |
| 306 | entry_address = temp_is_a0 ? out : temp; |
| 307 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 308 | if (temp_is_a0) { |
| 309 | __ Move(entry_address, temp); |
| 310 | } |
| 311 | } |
| 312 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 313 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 314 | mips64_codegen->InvokeRuntime(kQuickResolveString, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 315 | instruction_, |
| 316 | instruction_->GetDexPc(), |
| 317 | this); |
| 318 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 319 | |
| 320 | // Store the resolved string to the BSS entry. |
| 321 | if (baker_or_no_read_barriers) { |
| 322 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 323 | DCHECK(bss_info_high_); |
| 324 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 325 | mips64_codegen->NewStringBssEntryPatch(load->GetDexFile(), |
| 326 | string_index, |
| 327 | bss_info_high_); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 328 | __ Bind(&info_low->label); |
| 329 | __ StoreToOffset(kStoreWord, |
| 330 | calling_convention.GetRegisterAt(0), |
| 331 | entry_address, |
| 332 | /* placeholder */ 0x5678); |
| 333 | } |
| 334 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 335 | DataType::Type type = instruction_->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 336 | mips64_codegen->MoveLocation(locations->Out(), |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 337 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 338 | type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 339 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 340 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 341 | // Store the resolved string to the BSS entry. |
| 342 | if (!baker_or_no_read_barriers) { |
| 343 | // For non-Baker read barriers we need to re-calculate the address of |
| 344 | // the string entry. |
| 345 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 346 | mips64_codegen->NewStringBssEntryPatch(load->GetDexFile(), string_index); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 347 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 348 | mips64_codegen->NewStringBssEntryPatch(load->GetDexFile(), string_index, info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 349 | mips64_codegen->EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, info_low); |
| 350 | __ StoreToOffset(kStoreWord, out, TMP, /* placeholder */ 0x5678); |
| 351 | } |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 352 | __ Bc(GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 355 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS64"; } |
| 356 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 357 | private: |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 358 | // Pointer to the high half PC-relative patch info. |
| 359 | const CodeGeneratorMIPS64::PcRelativePatchInfo* bss_info_high_; |
| 360 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 361 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS64); |
| 362 | }; |
| 363 | |
| 364 | class NullCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 365 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 366 | explicit NullCheckSlowPathMIPS64(HNullCheck* instr) : SlowPathCodeMIPS64(instr) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 367 | |
| 368 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 369 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 370 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 371 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 372 | // Live registers will be restored in the catch block if caught. |
| 373 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 374 | } |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 375 | mips64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 376 | instruction_, |
| 377 | instruction_->GetDexPc(), |
| 378 | this); |
| 379 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 380 | } |
| 381 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 382 | bool IsFatal() const OVERRIDE { return true; } |
| 383 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 384 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS64"; } |
| 385 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 386 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 387 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS64); |
| 388 | }; |
| 389 | |
| 390 | class SuspendCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 391 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 392 | SuspendCheckSlowPathMIPS64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 393 | : SlowPathCodeMIPS64(instruction), successor_(successor) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 394 | |
| 395 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 396 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 397 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 398 | __ Bind(GetEntryLabel()); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 399 | SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD. |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 400 | mips64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 401 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 402 | RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 403 | if (successor_ == nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 404 | __ Bc(GetReturnLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 405 | } else { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 406 | __ Bc(mips64_codegen->GetLabelOf(successor_)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 410 | Mips64Label* GetReturnLabel() { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 411 | DCHECK(successor_ == nullptr); |
| 412 | return &return_label_; |
| 413 | } |
| 414 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 415 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS64"; } |
| 416 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 417 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 418 | // If not null, the block to branch to after the suspend check. |
| 419 | HBasicBlock* const successor_; |
| 420 | |
| 421 | // 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] | 422 | Mips64Label return_label_; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 423 | |
| 424 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS64); |
| 425 | }; |
| 426 | |
| 427 | class TypeCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 428 | public: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 429 | explicit TypeCheckSlowPathMIPS64(HInstruction* instruction, bool is_fatal) |
| 430 | : SlowPathCodeMIPS64(instruction), is_fatal_(is_fatal) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 431 | |
| 432 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 433 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 434 | |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 435 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 436 | DCHECK(instruction_->IsCheckCast() |
| 437 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 438 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 439 | |
| 440 | __ Bind(GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 441 | if (!is_fatal_) { |
| 442 | SaveLiveRegisters(codegen, locations); |
| 443 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 444 | |
| 445 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 446 | // move resolver. |
| 447 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 448 | codegen->EmitParallelMoves(locations->InAt(0), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 449 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 450 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 451 | locations->InAt(1), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 452 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 453 | DataType::Type::kReference); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 454 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 455 | mips64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 456 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 457 | DataType::Type ret_type = instruction_->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 458 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 459 | mips64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 460 | } else { |
| 461 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 462 | mips64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 463 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 466 | if (!is_fatal_) { |
| 467 | RestoreLiveRegisters(codegen, locations); |
| 468 | __ Bc(GetExitLabel()); |
| 469 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 472 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS64"; } |
| 473 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 474 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 475 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 476 | private: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 477 | const bool is_fatal_; |
| 478 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 479 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS64); |
| 480 | }; |
| 481 | |
| 482 | class DeoptimizationSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 483 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 484 | explicit DeoptimizationSlowPathMIPS64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 485 | : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 486 | |
| 487 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 488 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 489 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 490 | LocationSummary* locations = instruction_->GetLocations(); |
| 491 | SaveLiveRegisters(codegen, locations); |
| 492 | InvokeRuntimeCallingConvention calling_convention; |
| 493 | __ LoadConst32(calling_convention.GetRegisterAt(0), |
| 494 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 495 | mips64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 496 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 499 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS64"; } |
| 500 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 501 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 502 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64); |
| 503 | }; |
| 504 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 505 | class ArraySetSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 506 | public: |
| 507 | explicit ArraySetSlowPathMIPS64(HInstruction* instruction) : SlowPathCodeMIPS64(instruction) {} |
| 508 | |
| 509 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 510 | LocationSummary* locations = instruction_->GetLocations(); |
| 511 | __ Bind(GetEntryLabel()); |
| 512 | SaveLiveRegisters(codegen, locations); |
| 513 | |
| 514 | InvokeRuntimeCallingConvention calling_convention; |
| 515 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 516 | parallel_move.AddMove( |
| 517 | locations->InAt(0), |
| 518 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 519 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 520 | nullptr); |
| 521 | parallel_move.AddMove( |
| 522 | locations->InAt(1), |
| 523 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 524 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 525 | nullptr); |
| 526 | parallel_move.AddMove( |
| 527 | locations->InAt(2), |
| 528 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 529 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 530 | nullptr); |
| 531 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 532 | |
| 533 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 534 | mips64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 535 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 536 | RestoreLiveRegisters(codegen, locations); |
| 537 | __ Bc(GetExitLabel()); |
| 538 | } |
| 539 | |
| 540 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS64"; } |
| 541 | |
| 542 | private: |
| 543 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS64); |
| 544 | }; |
| 545 | |
| 546 | // Slow path marking an object reference `ref` during a read |
| 547 | // barrier. The field `obj.field` in the object `obj` holding this |
| 548 | // reference does not get updated by this slow path after marking (see |
| 549 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 below for that). |
| 550 | // |
| 551 | // This means that after the execution of this slow path, `ref` will |
| 552 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 553 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 554 | // probably still be a from-space reference (unless it gets updated by |
| 555 | // another thread, or if another thread installed another object |
| 556 | // reference (different from `ref`) in `obj.field`). |
| 557 | // |
| 558 | // If `entrypoint` is a valid location it is assumed to already be |
| 559 | // holding the entrypoint. The case where the entrypoint is passed in |
| 560 | // is for the GcRoot read barrier. |
| 561 | class ReadBarrierMarkSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 562 | public: |
| 563 | ReadBarrierMarkSlowPathMIPS64(HInstruction* instruction, |
| 564 | Location ref, |
| 565 | Location entrypoint = Location::NoLocation()) |
| 566 | : SlowPathCodeMIPS64(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 567 | DCHECK(kEmitCompilerReadBarrier); |
| 568 | } |
| 569 | |
| 570 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; } |
| 571 | |
| 572 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 573 | LocationSummary* locations = instruction_->GetLocations(); |
| 574 | GpuRegister ref_reg = ref_.AsRegister<GpuRegister>(); |
| 575 | DCHECK(locations->CanCall()); |
| 576 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 577 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 578 | instruction_->IsStaticFieldGet() || |
| 579 | instruction_->IsArrayGet() || |
| 580 | instruction_->IsArraySet() || |
| 581 | instruction_->IsLoadClass() || |
| 582 | instruction_->IsLoadString() || |
| 583 | instruction_->IsInstanceOf() || |
| 584 | instruction_->IsCheckCast() || |
| 585 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 586 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 587 | << "Unexpected instruction in read barrier marking slow path: " |
| 588 | << instruction_->DebugName(); |
| 589 | |
| 590 | __ Bind(GetEntryLabel()); |
| 591 | // No need to save live registers; it's taken care of by the |
| 592 | // entrypoint. Also, there is no need to update the stack mask, |
| 593 | // as this runtime call will not trigger a garbage collection. |
| 594 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 595 | DCHECK((V0 <= ref_reg && ref_reg <= T2) || |
| 596 | (S2 <= ref_reg && ref_reg <= S7) || |
| 597 | (ref_reg == S8)) << ref_reg; |
| 598 | // "Compact" slow path, saving two moves. |
| 599 | // |
| 600 | // Instead of using the standard runtime calling convention (input |
| 601 | // and output in A0 and V0 respectively): |
| 602 | // |
| 603 | // A0 <- ref |
| 604 | // V0 <- ReadBarrierMark(A0) |
| 605 | // ref <- V0 |
| 606 | // |
| 607 | // we just use rX (the register containing `ref`) as input and output |
| 608 | // of a dedicated entrypoint: |
| 609 | // |
| 610 | // rX <- ReadBarrierMarkRegX(rX) |
| 611 | // |
| 612 | if (entrypoint_.IsValid()) { |
| 613 | mips64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 614 | DCHECK_EQ(entrypoint_.AsRegister<GpuRegister>(), T9); |
| 615 | __ Jalr(entrypoint_.AsRegister<GpuRegister>()); |
| 616 | __ Nop(); |
| 617 | } else { |
| 618 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 619 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 620 | // This runtime call does not require a stack map. |
| 621 | mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 622 | instruction_, |
| 623 | this); |
| 624 | } |
| 625 | __ Bc(GetExitLabel()); |
| 626 | } |
| 627 | |
| 628 | private: |
| 629 | // The location (register) of the marked object reference. |
| 630 | const Location ref_; |
| 631 | |
| 632 | // The location of the entrypoint if already loaded. |
| 633 | const Location entrypoint_; |
| 634 | |
| 635 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS64); |
| 636 | }; |
| 637 | |
| 638 | // Slow path marking an object reference `ref` during a read barrier, |
| 639 | // and if needed, atomically updating the field `obj.field` in the |
| 640 | // object `obj` holding this reference after marking (contrary to |
| 641 | // ReadBarrierMarkSlowPathMIPS64 above, which never tries to update |
| 642 | // `obj.field`). |
| 643 | // |
| 644 | // This means that after the execution of this slow path, both `ref` |
| 645 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 646 | // hold the same to-space reference (unless another thread installed |
| 647 | // another object reference (different from `ref`) in `obj.field`). |
| 648 | class ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 649 | public: |
| 650 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(HInstruction* instruction, |
| 651 | Location ref, |
| 652 | GpuRegister obj, |
| 653 | Location field_offset, |
| 654 | GpuRegister temp1) |
| 655 | : SlowPathCodeMIPS64(instruction), |
| 656 | ref_(ref), |
| 657 | obj_(obj), |
| 658 | field_offset_(field_offset), |
| 659 | temp1_(temp1) { |
| 660 | DCHECK(kEmitCompilerReadBarrier); |
| 661 | } |
| 662 | |
| 663 | const char* GetDescription() const OVERRIDE { |
| 664 | return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS64"; |
| 665 | } |
| 666 | |
| 667 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 668 | LocationSummary* locations = instruction_->GetLocations(); |
| 669 | GpuRegister ref_reg = ref_.AsRegister<GpuRegister>(); |
| 670 | DCHECK(locations->CanCall()); |
| 671 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 672 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 673 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 674 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 675 | << instruction_->DebugName(); |
| 676 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 677 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 678 | DCHECK(field_offset_.IsRegister()) << field_offset_; |
| 679 | |
| 680 | __ Bind(GetEntryLabel()); |
| 681 | |
| 682 | // Save the old reference. |
| 683 | // Note that we cannot use AT or TMP to save the old reference, as those |
| 684 | // are used by the code that follows, but we need the old reference after |
| 685 | // the call to the ReadBarrierMarkRegX entry point. |
| 686 | DCHECK_NE(temp1_, AT); |
| 687 | DCHECK_NE(temp1_, TMP); |
| 688 | __ Move(temp1_, ref_reg); |
| 689 | |
| 690 | // No need to save live registers; it's taken care of by the |
| 691 | // entrypoint. Also, there is no need to update the stack mask, |
| 692 | // as this runtime call will not trigger a garbage collection. |
| 693 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 694 | DCHECK((V0 <= ref_reg && ref_reg <= T2) || |
| 695 | (S2 <= ref_reg && ref_reg <= S7) || |
| 696 | (ref_reg == S8)) << ref_reg; |
| 697 | // "Compact" slow path, saving two moves. |
| 698 | // |
| 699 | // Instead of using the standard runtime calling convention (input |
| 700 | // and output in A0 and V0 respectively): |
| 701 | // |
| 702 | // A0 <- ref |
| 703 | // V0 <- ReadBarrierMark(A0) |
| 704 | // ref <- V0 |
| 705 | // |
| 706 | // we just use rX (the register containing `ref`) as input and output |
| 707 | // of a dedicated entrypoint: |
| 708 | // |
| 709 | // rX <- ReadBarrierMarkRegX(rX) |
| 710 | // |
| 711 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 712 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 713 | // This runtime call does not require a stack map. |
| 714 | mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 715 | instruction_, |
| 716 | this); |
| 717 | |
| 718 | // If the new reference is different from the old reference, |
| 719 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 720 | // |
| 721 | // Note that this field could also hold a different object, if |
| 722 | // another thread had concurrently changed it. In that case, the |
| 723 | // the compare-and-set (CAS) loop below would abort, leaving the |
| 724 | // field as-is. |
| 725 | Mips64Label done; |
| 726 | __ Beqc(temp1_, ref_reg, &done); |
| 727 | |
| 728 | // Update the the holder's field atomically. This may fail if |
| 729 | // mutator updates before us, but it's OK. This is achieved |
| 730 | // using a strong compare-and-set (CAS) operation with relaxed |
| 731 | // memory synchronization ordering, where the expected value is |
| 732 | // the old reference and the desired value is the new reference. |
| 733 | |
| 734 | // Convenience aliases. |
| 735 | GpuRegister base = obj_; |
| 736 | GpuRegister offset = field_offset_.AsRegister<GpuRegister>(); |
| 737 | GpuRegister expected = temp1_; |
| 738 | GpuRegister value = ref_reg; |
| 739 | GpuRegister tmp_ptr = TMP; // Pointer to actual memory. |
| 740 | GpuRegister tmp = AT; // Value in memory. |
| 741 | |
| 742 | __ Daddu(tmp_ptr, base, offset); |
| 743 | |
| 744 | if (kPoisonHeapReferences) { |
| 745 | __ PoisonHeapReference(expected); |
| 746 | // Do not poison `value` if it is the same register as |
| 747 | // `expected`, which has just been poisoned. |
| 748 | if (value != expected) { |
| 749 | __ PoisonHeapReference(value); |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | // do { |
| 754 | // tmp = [r_ptr] - expected; |
| 755 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 756 | |
| 757 | Mips64Label loop_head, exit_loop; |
| 758 | __ Bind(&loop_head); |
| 759 | __ Ll(tmp, tmp_ptr); |
| 760 | // The LL instruction sign-extends the 32-bit value, but |
| 761 | // 32-bit references must be zero-extended. Zero-extend `tmp`. |
| 762 | __ Dext(tmp, tmp, 0, 32); |
| 763 | __ Bnec(tmp, expected, &exit_loop); |
| 764 | __ Move(tmp, value); |
| 765 | __ Sc(tmp, tmp_ptr); |
| 766 | __ Beqzc(tmp, &loop_head); |
| 767 | __ Bind(&exit_loop); |
| 768 | |
| 769 | if (kPoisonHeapReferences) { |
| 770 | __ UnpoisonHeapReference(expected); |
| 771 | // Do not unpoison `value` if it is the same register as |
| 772 | // `expected`, which has just been unpoisoned. |
| 773 | if (value != expected) { |
| 774 | __ UnpoisonHeapReference(value); |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | __ Bind(&done); |
| 779 | __ Bc(GetExitLabel()); |
| 780 | } |
| 781 | |
| 782 | private: |
| 783 | // The location (register) of the marked object reference. |
| 784 | const Location ref_; |
| 785 | // The register containing the object holding the marked object reference field. |
| 786 | const GpuRegister obj_; |
| 787 | // The location of the offset of the marked reference field within `obj_`. |
| 788 | Location field_offset_; |
| 789 | |
| 790 | const GpuRegister temp1_; |
| 791 | |
| 792 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS64); |
| 793 | }; |
| 794 | |
| 795 | // Slow path generating a read barrier for a heap reference. |
| 796 | class ReadBarrierForHeapReferenceSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 797 | public: |
| 798 | ReadBarrierForHeapReferenceSlowPathMIPS64(HInstruction* instruction, |
| 799 | Location out, |
| 800 | Location ref, |
| 801 | Location obj, |
| 802 | uint32_t offset, |
| 803 | Location index) |
| 804 | : SlowPathCodeMIPS64(instruction), |
| 805 | out_(out), |
| 806 | ref_(ref), |
| 807 | obj_(obj), |
| 808 | offset_(offset), |
| 809 | index_(index) { |
| 810 | DCHECK(kEmitCompilerReadBarrier); |
| 811 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 812 | // has been overwritten by (or after) the heap object reference load |
| 813 | // to be instrumented, e.g.: |
| 814 | // |
| 815 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 816 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 817 | // |
| 818 | // In that case, we have lost the information about the original |
| 819 | // object, and the emitted read barrier cannot work properly. |
| 820 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 821 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 822 | } |
| 823 | |
| 824 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 825 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 826 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 827 | DataType::Type type = DataType::Type::kReference; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 828 | GpuRegister reg_out = out_.AsRegister<GpuRegister>(); |
| 829 | DCHECK(locations->CanCall()); |
| 830 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 831 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 832 | instruction_->IsStaticFieldGet() || |
| 833 | instruction_->IsArrayGet() || |
| 834 | instruction_->IsInstanceOf() || |
| 835 | instruction_->IsCheckCast() || |
| 836 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 837 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 838 | << instruction_->DebugName(); |
| 839 | |
| 840 | __ Bind(GetEntryLabel()); |
| 841 | SaveLiveRegisters(codegen, locations); |
| 842 | |
| 843 | // We may have to change the index's value, but as `index_` is a |
| 844 | // constant member (like other "inputs" of this slow path), |
| 845 | // introduce a copy of it, `index`. |
| 846 | Location index = index_; |
| 847 | if (index_.IsValid()) { |
| 848 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 849 | if (instruction_->IsArrayGet()) { |
| 850 | // Compute the actual memory offset and store it in `index`. |
| 851 | GpuRegister index_reg = index_.AsRegister<GpuRegister>(); |
| 852 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 853 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 854 | // We are about to change the value of `index_reg` (see the |
| 855 | // calls to art::mips64::Mips64Assembler::Sll and |
| 856 | // art::mips64::MipsAssembler::Addiu32 below), but it has |
| 857 | // not been saved by the previous call to |
| 858 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 859 | // callee-save register -- |
| 860 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 861 | // callee-save registers, as it has been designed with the |
| 862 | // assumption that callee-save registers are supposed to be |
| 863 | // handled by the called function. So, as a callee-save |
| 864 | // register, `index_reg` _would_ eventually be saved onto |
| 865 | // the stack, but it would be too late: we would have |
| 866 | // changed its value earlier. Therefore, we manually save |
| 867 | // it here into another freely available register, |
| 868 | // `free_reg`, chosen of course among the caller-save |
| 869 | // registers (as a callee-save `free_reg` register would |
| 870 | // exhibit the same problem). |
| 871 | // |
| 872 | // Note we could have requested a temporary register from |
| 873 | // the register allocator instead; but we prefer not to, as |
| 874 | // this is a slow path, and we know we can find a |
| 875 | // caller-save register that is available. |
| 876 | GpuRegister free_reg = FindAvailableCallerSaveRegister(codegen); |
| 877 | __ Move(free_reg, index_reg); |
| 878 | index_reg = free_reg; |
| 879 | index = Location::RegisterLocation(index_reg); |
| 880 | } else { |
| 881 | // The initial register stored in `index_` has already been |
| 882 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 883 | // (as it is not a callee-save register), so we can freely |
| 884 | // use it. |
| 885 | } |
| 886 | // Shifting the index value contained in `index_reg` by the scale |
| 887 | // factor (2) cannot overflow in practice, as the runtime is |
| 888 | // unable to allocate object arrays with a size larger than |
| 889 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 890 | __ Sll(index_reg, index_reg, TIMES_4); |
| 891 | static_assert( |
| 892 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 893 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 894 | __ Addiu32(index_reg, index_reg, offset_); |
| 895 | } else { |
| 896 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 897 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 898 | // (as in the case of ArrayGet), as it is actually an offset |
| 899 | // to an object field within an object. |
| 900 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 901 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 902 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 903 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 904 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 905 | DCHECK_EQ(offset_, 0U); |
| 906 | DCHECK(index_.IsRegister()); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | // We're moving two or three locations to locations that could |
| 911 | // overlap, so we need a parallel move resolver. |
| 912 | InvokeRuntimeCallingConvention calling_convention; |
| 913 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 914 | parallel_move.AddMove(ref_, |
| 915 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 916 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 917 | nullptr); |
| 918 | parallel_move.AddMove(obj_, |
| 919 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 920 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 921 | nullptr); |
| 922 | if (index.IsValid()) { |
| 923 | parallel_move.AddMove(index, |
| 924 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 925 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 926 | nullptr); |
| 927 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 928 | } else { |
| 929 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 930 | __ LoadConst32(calling_convention.GetRegisterAt(2), offset_); |
| 931 | } |
| 932 | mips64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| 933 | instruction_, |
| 934 | instruction_->GetDexPc(), |
| 935 | this); |
| 936 | CheckEntrypointTypes< |
| 937 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 938 | mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 939 | |
| 940 | RestoreLiveRegisters(codegen, locations); |
| 941 | __ Bc(GetExitLabel()); |
| 942 | } |
| 943 | |
| 944 | const char* GetDescription() const OVERRIDE { |
| 945 | return "ReadBarrierForHeapReferenceSlowPathMIPS64"; |
| 946 | } |
| 947 | |
| 948 | private: |
| 949 | GpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 950 | size_t ref = static_cast<int>(ref_.AsRegister<GpuRegister>()); |
| 951 | size_t obj = static_cast<int>(obj_.AsRegister<GpuRegister>()); |
| 952 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 953 | if (i != ref && |
| 954 | i != obj && |
| 955 | !codegen->IsCoreCalleeSaveRegister(i) && |
| 956 | !codegen->IsBlockedCoreRegister(i)) { |
| 957 | return static_cast<GpuRegister>(i); |
| 958 | } |
| 959 | } |
| 960 | // We shall never fail to find a free caller-save register, as |
| 961 | // there are more than two core caller-save registers on MIPS64 |
| 962 | // (meaning it is possible to find one which is different from |
| 963 | // `ref` and `obj`). |
| 964 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 965 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 966 | UNREACHABLE(); |
| 967 | } |
| 968 | |
| 969 | const Location out_; |
| 970 | const Location ref_; |
| 971 | const Location obj_; |
| 972 | const uint32_t offset_; |
| 973 | // An additional location containing an index to an array. |
| 974 | // Only used for HArrayGet and the UnsafeGetObject & |
| 975 | // UnsafeGetObjectVolatile intrinsics. |
| 976 | const Location index_; |
| 977 | |
| 978 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS64); |
| 979 | }; |
| 980 | |
| 981 | // Slow path generating a read barrier for a GC root. |
| 982 | class ReadBarrierForRootSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 983 | public: |
| 984 | ReadBarrierForRootSlowPathMIPS64(HInstruction* instruction, Location out, Location root) |
| 985 | : SlowPathCodeMIPS64(instruction), out_(out), root_(root) { |
| 986 | DCHECK(kEmitCompilerReadBarrier); |
| 987 | } |
| 988 | |
| 989 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 990 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 991 | DataType::Type type = DataType::Type::kReference; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 992 | GpuRegister reg_out = out_.AsRegister<GpuRegister>(); |
| 993 | DCHECK(locations->CanCall()); |
| 994 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 995 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 996 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 997 | << instruction_->DebugName(); |
| 998 | |
| 999 | __ Bind(GetEntryLabel()); |
| 1000 | SaveLiveRegisters(codegen, locations); |
| 1001 | |
| 1002 | InvokeRuntimeCallingConvention calling_convention; |
| 1003 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 1004 | mips64_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 1005 | root_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1006 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1007 | mips64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 1008 | instruction_, |
| 1009 | instruction_->GetDexPc(), |
| 1010 | this); |
| 1011 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1012 | mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1013 | |
| 1014 | RestoreLiveRegisters(codegen, locations); |
| 1015 | __ Bc(GetExitLabel()); |
| 1016 | } |
| 1017 | |
| 1018 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS64"; } |
| 1019 | |
| 1020 | private: |
| 1021 | const Location out_; |
| 1022 | const Location root_; |
| 1023 | |
| 1024 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS64); |
| 1025 | }; |
| 1026 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1027 | CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph, |
| 1028 | const Mips64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1029 | const CompilerOptions& compiler_options, |
| 1030 | OptimizingCompilerStats* stats) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1031 | : CodeGenerator(graph, |
| 1032 | kNumberOfGpuRegisters, |
| 1033 | kNumberOfFpuRegisters, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1034 | /* number_of_register_pairs */ 0, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1035 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1036 | arraysize(kCoreCalleeSaves)), |
| 1037 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1038 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1039 | compiler_options, |
| 1040 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1041 | block_labels_(nullptr), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1042 | location_builder_(graph, this), |
| 1043 | instruction_visitor_(graph, this), |
| 1044 | move_resolver_(graph->GetArena(), this), |
Goran Jakovljevic | 19680d3 | 2017-05-11 10:38:36 +0200 | [diff] [blame] | 1045 | assembler_(graph->GetArena(), &isa_features), |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1046 | isa_features_(isa_features), |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1047 | uint32_literals_(std::less<uint32_t>(), |
| 1048 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1049 | uint64_literals_(std::less<uint64_t>(), |
| 1050 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1051 | pc_relative_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1052 | method_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1053 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1054 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1055 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1056 | string_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1057 | jit_string_patches_(StringReferenceValueComparator(), |
| 1058 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1059 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1060 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1061 | // Save RA (containing the return address) to mimic Quick. |
| 1062 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 1063 | } |
| 1064 | |
| 1065 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 1066 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1067 | #define __ down_cast<Mips64Assembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1068 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value() |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1069 | |
| 1070 | void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1071 | // Ensure that we fix up branches. |
| 1072 | __ FinalizeCode(); |
| 1073 | |
| 1074 | // Adjust native pc offsets in stack maps. |
| 1075 | 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] | 1076 | uint32_t old_position = |
| 1077 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kMips64); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1078 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1079 | DCHECK_GE(new_position, old_position); |
| 1080 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 1081 | } |
| 1082 | |
| 1083 | // Adjust pc offsets for the disassembly information. |
| 1084 | if (disasm_info_ != nullptr) { |
| 1085 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1086 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1087 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1088 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1089 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1090 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1091 | } |
| 1092 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1093 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1094 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1095 | } |
| 1096 | } |
| 1097 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1098 | CodeGenerator::Finalize(allocator); |
| 1099 | } |
| 1100 | |
| 1101 | Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const { |
| 1102 | return codegen_->GetAssembler(); |
| 1103 | } |
| 1104 | |
| 1105 | void ParallelMoveResolverMIPS64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1106 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1107 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1108 | } |
| 1109 | |
| 1110 | void ParallelMoveResolverMIPS64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1111 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1112 | codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1113 | } |
| 1114 | |
| 1115 | void ParallelMoveResolverMIPS64::RestoreScratch(int reg) { |
| 1116 | // Pop reg |
| 1117 | __ Ld(GpuRegister(reg), SP, 0); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1118 | __ DecreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | void ParallelMoveResolverMIPS64::SpillScratch(int reg) { |
| 1122 | // Push reg |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1123 | __ IncreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1124 | __ Sd(GpuRegister(reg), SP, 0); |
| 1125 | } |
| 1126 | |
| 1127 | void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) { |
| 1128 | LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord; |
| 1129 | StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord; |
| 1130 | // Allocate a scratch register other than TMP, if available. |
| 1131 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 1132 | // automatically unspilled when the scratch scope object is destroyed). |
| 1133 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 1134 | // 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] | 1135 | int stack_offset = ensure_scratch.IsSpilled() ? kMips64DoublewordSize : 0; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1136 | __ LoadFromOffset(load_type, |
| 1137 | GpuRegister(ensure_scratch.GetRegister()), |
| 1138 | SP, |
| 1139 | index1 + stack_offset); |
| 1140 | __ LoadFromOffset(load_type, |
| 1141 | TMP, |
| 1142 | SP, |
| 1143 | index2 + stack_offset); |
| 1144 | __ StoreToOffset(store_type, |
| 1145 | GpuRegister(ensure_scratch.GetRegister()), |
| 1146 | SP, |
| 1147 | index2 + stack_offset); |
| 1148 | __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset); |
| 1149 | } |
| 1150 | |
| 1151 | static dwarf::Reg DWARFReg(GpuRegister reg) { |
| 1152 | return dwarf::Reg::Mips64Core(static_cast<int>(reg)); |
| 1153 | } |
| 1154 | |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1155 | static dwarf::Reg DWARFReg(FpuRegister reg) { |
| 1156 | return dwarf::Reg::Mips64Fp(static_cast<int>(reg)); |
| 1157 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1158 | |
| 1159 | void CodeGeneratorMIPS64::GenerateFrameEntry() { |
| 1160 | __ Bind(&frame_entry_label_); |
| 1161 | |
| 1162 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips64) || !IsLeafMethod(); |
| 1163 | |
| 1164 | if (do_overflow_check) { |
| 1165 | __ LoadFromOffset(kLoadWord, |
| 1166 | ZERO, |
| 1167 | SP, |
| 1168 | -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips64))); |
| 1169 | RecordPcInfo(nullptr, 0); |
| 1170 | } |
| 1171 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1172 | if (HasEmptyFrame()) { |
| 1173 | return; |
| 1174 | } |
| 1175 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1176 | // Make sure the frame size isn't unreasonably large. |
| 1177 | if (GetFrameSize() > GetStackOverflowReservedBytes(kMips64)) { |
| 1178 | LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips64) << " bytes"; |
| 1179 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1180 | |
| 1181 | // Spill callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1182 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1183 | uint32_t ofs = GetFrameSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1184 | __ IncreaseFrameSize(ofs); |
| 1185 | |
| 1186 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1187 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1188 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1189 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1190 | __ StoreToOffset(kStoreDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1191 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1196 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1197 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1198 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1199 | __ StoreFpuToOffset(kStoreDoubleword, reg, SP, ofs); |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1200 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1201 | } |
| 1202 | } |
| 1203 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1204 | // Save the current method if we need it. Note that we do not |
| 1205 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1206 | // in the SSA graph. |
| 1207 | if (RequiresCurrentMethod()) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1208 | __ StoreToOffset(kStoreDoubleword, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1209 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 1210 | |
| 1211 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1212 | // Initialize should_deoptimize flag to 0. |
| 1213 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1214 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | void CodeGeneratorMIPS64::GenerateFrameExit() { |
| 1218 | __ cfi().RememberState(); |
| 1219 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1220 | if (!HasEmptyFrame()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1221 | // Restore callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1222 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1223 | // For better instruction scheduling restore RA before other registers. |
| 1224 | uint32_t ofs = GetFrameSize(); |
| 1225 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1226 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1227 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1228 | ofs -= kMips64DoublewordSize; |
| 1229 | __ LoadFromOffset(kLoadDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1230 | __ cfi().Restore(DWARFReg(reg)); |
| 1231 | } |
| 1232 | } |
| 1233 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1234 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1235 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1236 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
| 1237 | ofs -= kMips64DoublewordSize; |
| 1238 | __ LoadFpuFromOffset(kLoadDoubleword, reg, SP, ofs); |
| 1239 | __ cfi().Restore(DWARFReg(reg)); |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | __ DecreaseFrameSize(GetFrameSize()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1246 | __ Jic(RA, 0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1247 | |
| 1248 | __ cfi().RestoreState(); |
| 1249 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 1250 | } |
| 1251 | |
| 1252 | void CodeGeneratorMIPS64::Bind(HBasicBlock* block) { |
| 1253 | __ Bind(GetLabelOf(block)); |
| 1254 | } |
| 1255 | |
| 1256 | void CodeGeneratorMIPS64::MoveLocation(Location destination, |
| 1257 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1258 | DataType::Type dst_type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1259 | if (source.Equals(destination)) { |
| 1260 | return; |
| 1261 | } |
| 1262 | |
| 1263 | // A valid move can always be inferred from the destination and source |
| 1264 | // locations. When moving from and to a register, the argument type can be |
| 1265 | // used to generate 32bit instead of 64bit moves. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1266 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1267 | DCHECK_EQ(unspecified_type, false); |
| 1268 | |
| 1269 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1270 | if (unspecified_type) { |
| 1271 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1272 | if (source.IsStackSlot() || |
| 1273 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1274 | || src_cst->IsFloatConstant() |
| 1275 | || src_cst->IsNullConstant()))) { |
| 1276 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1277 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1278 | } else { |
| 1279 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1280 | // type is appropriate. Else the source is a register, and since the |
| 1281 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1282 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1283 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1284 | } |
| 1285 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1286 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1287 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1288 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1289 | // Move to GPR/FPR from stack |
| 1290 | LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1291 | if (DataType::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1292 | __ LoadFpuFromOffset(load_type, |
| 1293 | destination.AsFpuRegister<FpuRegister>(), |
| 1294 | SP, |
| 1295 | source.GetStackIndex()); |
| 1296 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1297 | // TODO: use load_type = kLoadUnsignedWord when type == DataType::Type::kReference. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1298 | __ LoadFromOffset(load_type, |
| 1299 | destination.AsRegister<GpuRegister>(), |
| 1300 | SP, |
| 1301 | source.GetStackIndex()); |
| 1302 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1303 | } else if (source.IsSIMDStackSlot()) { |
| 1304 | __ LoadFpuFromOffset(kLoadQuadword, |
| 1305 | destination.AsFpuRegister<FpuRegister>(), |
| 1306 | SP, |
| 1307 | source.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1308 | } else if (source.IsConstant()) { |
| 1309 | // Move to GPR/FPR from constant |
| 1310 | GpuRegister gpr = AT; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1311 | if (!DataType::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1312 | gpr = destination.AsRegister<GpuRegister>(); |
| 1313 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1314 | if (dst_type == DataType::Type::kInt32 || dst_type == DataType::Type::kFloat32) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1315 | int32_t value = GetInt32ValueOf(source.GetConstant()->AsConstant()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1316 | if (DataType::IsFloatingPointType(dst_type) && value == 0) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1317 | gpr = ZERO; |
| 1318 | } else { |
| 1319 | __ LoadConst32(gpr, value); |
| 1320 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1321 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1322 | int64_t value = GetInt64ValueOf(source.GetConstant()->AsConstant()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1323 | if (DataType::IsFloatingPointType(dst_type) && value == 0) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1324 | gpr = ZERO; |
| 1325 | } else { |
| 1326 | __ LoadConst64(gpr, value); |
| 1327 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1328 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1329 | if (dst_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1330 | __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1331 | } else if (dst_type == DataType::Type::kFloat64) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1332 | __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
| 1333 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1334 | } else if (source.IsRegister()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1335 | if (destination.IsRegister()) { |
| 1336 | // Move to GPR from GPR |
| 1337 | __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>()); |
| 1338 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1339 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1340 | if (DataType::Is64BitType(dst_type)) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1341 | __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1342 | } else { |
| 1343 | __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1344 | } |
| 1345 | } |
| 1346 | } else if (source.IsFpuRegister()) { |
| 1347 | if (destination.IsFpuRegister()) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1348 | if (GetGraph()->HasSIMD()) { |
| 1349 | __ MoveV(VectorRegisterFrom(destination), |
| 1350 | VectorRegisterFrom(source)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1351 | } else { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1352 | // Move to FPR from FPR |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1353 | if (dst_type == DataType::Type::kFloat32) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1354 | __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1355 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1356 | DCHECK_EQ(dst_type, DataType::Type::kFloat64); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1357 | __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1358 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1359 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1360 | } else { |
| 1361 | DCHECK(destination.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1362 | if (DataType::Is64BitType(dst_type)) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1363 | __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1364 | } else { |
| 1365 | __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1366 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1367 | } |
| 1368 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1369 | } else if (destination.IsSIMDStackSlot()) { |
| 1370 | if (source.IsFpuRegister()) { |
| 1371 | __ StoreFpuToOffset(kStoreQuadword, |
| 1372 | source.AsFpuRegister<FpuRegister>(), |
| 1373 | SP, |
| 1374 | destination.GetStackIndex()); |
| 1375 | } else { |
| 1376 | DCHECK(source.IsSIMDStackSlot()); |
| 1377 | __ LoadFpuFromOffset(kLoadQuadword, |
| 1378 | FTMP, |
| 1379 | SP, |
| 1380 | source.GetStackIndex()); |
| 1381 | __ StoreFpuToOffset(kStoreQuadword, |
| 1382 | FTMP, |
| 1383 | SP, |
| 1384 | destination.GetStackIndex()); |
| 1385 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1386 | } else { // The destination is not a register. It must be a stack slot. |
| 1387 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1388 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1389 | if (unspecified_type) { |
| 1390 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1391 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1392 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1393 | dst_type = |
| 1394 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1395 | } |
| 1396 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1397 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1398 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1399 | // Move to stack from GPR/FPR |
| 1400 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 1401 | if (source.IsRegister()) { |
| 1402 | __ StoreToOffset(store_type, |
| 1403 | source.AsRegister<GpuRegister>(), |
| 1404 | SP, |
| 1405 | destination.GetStackIndex()); |
| 1406 | } else { |
| 1407 | __ StoreFpuToOffset(store_type, |
| 1408 | source.AsFpuRegister<FpuRegister>(), |
| 1409 | SP, |
| 1410 | destination.GetStackIndex()); |
| 1411 | } |
| 1412 | } else if (source.IsConstant()) { |
| 1413 | // Move to stack from constant |
| 1414 | HConstant* src_cst = source.GetConstant(); |
| 1415 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1416 | GpuRegister gpr = ZERO; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1417 | if (destination.IsStackSlot()) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1418 | int32_t value = GetInt32ValueOf(src_cst->AsConstant()); |
| 1419 | if (value != 0) { |
| 1420 | gpr = TMP; |
| 1421 | __ LoadConst32(gpr, value); |
| 1422 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1423 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1424 | DCHECK(destination.IsDoubleStackSlot()); |
| 1425 | int64_t value = GetInt64ValueOf(src_cst->AsConstant()); |
| 1426 | if (value != 0) { |
| 1427 | gpr = TMP; |
| 1428 | __ LoadConst64(gpr, value); |
| 1429 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1430 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1431 | __ StoreToOffset(store_type, gpr, SP, destination.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1432 | } else { |
| 1433 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
| 1434 | DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot()); |
| 1435 | // Move to stack from stack |
| 1436 | if (destination.IsStackSlot()) { |
| 1437 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1438 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 1439 | } else { |
| 1440 | __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex()); |
| 1441 | __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex()); |
| 1442 | } |
| 1443 | } |
| 1444 | } |
| 1445 | } |
| 1446 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1447 | void CodeGeneratorMIPS64::SwapLocations(Location loc1, Location loc2, DataType::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1448 | DCHECK(!loc1.IsConstant()); |
| 1449 | DCHECK(!loc2.IsConstant()); |
| 1450 | |
| 1451 | if (loc1.Equals(loc2)) { |
| 1452 | return; |
| 1453 | } |
| 1454 | |
| 1455 | bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot(); |
| 1456 | bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot(); |
| 1457 | bool is_fp_reg1 = loc1.IsFpuRegister(); |
| 1458 | bool is_fp_reg2 = loc2.IsFpuRegister(); |
| 1459 | |
| 1460 | if (loc2.IsRegister() && loc1.IsRegister()) { |
| 1461 | // Swap 2 GPRs |
| 1462 | GpuRegister r1 = loc1.AsRegister<GpuRegister>(); |
| 1463 | GpuRegister r2 = loc2.AsRegister<GpuRegister>(); |
| 1464 | __ Move(TMP, r2); |
| 1465 | __ Move(r2, r1); |
| 1466 | __ Move(r1, TMP); |
| 1467 | } else if (is_fp_reg2 && is_fp_reg1) { |
| 1468 | // Swap 2 FPRs |
| 1469 | FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>(); |
| 1470 | FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1471 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1472 | __ MovS(FTMP, r1); |
| 1473 | __ MovS(r1, r2); |
| 1474 | __ MovS(r2, FTMP); |
| 1475 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1476 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1477 | __ MovD(FTMP, r1); |
| 1478 | __ MovD(r1, r2); |
| 1479 | __ MovD(r2, FTMP); |
| 1480 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1481 | } else if (is_slot1 != is_slot2) { |
| 1482 | // Swap GPR/FPR and stack slot |
| 1483 | Location reg_loc = is_slot1 ? loc2 : loc1; |
| 1484 | Location mem_loc = is_slot1 ? loc1 : loc2; |
| 1485 | LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
| 1486 | StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1487 | // TODO: use load_type = kLoadUnsignedWord when type == DataType::Type::kReference. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1488 | __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex()); |
| 1489 | if (reg_loc.IsFpuRegister()) { |
| 1490 | __ StoreFpuToOffset(store_type, |
| 1491 | reg_loc.AsFpuRegister<FpuRegister>(), |
| 1492 | SP, |
| 1493 | mem_loc.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1494 | if (mem_loc.IsStackSlot()) { |
| 1495 | __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1496 | } else { |
| 1497 | DCHECK(mem_loc.IsDoubleStackSlot()); |
| 1498 | __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1499 | } |
| 1500 | } else { |
| 1501 | __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex()); |
| 1502 | __ Move(reg_loc.AsRegister<GpuRegister>(), TMP); |
| 1503 | } |
| 1504 | } else if (is_slot1 && is_slot2) { |
| 1505 | move_resolver_.Exchange(loc1.GetStackIndex(), |
| 1506 | loc2.GetStackIndex(), |
| 1507 | loc1.IsDoubleStackSlot()); |
| 1508 | } else { |
| 1509 | LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2; |
| 1510 | } |
| 1511 | } |
| 1512 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1513 | void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) { |
| 1514 | DCHECK(location.IsRegister()); |
| 1515 | __ LoadConst32(location.AsRegister<GpuRegister>(), value); |
| 1516 | } |
| 1517 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1518 | void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1519 | if (location.IsRegister()) { |
| 1520 | locations->AddTemp(location); |
| 1521 | } else { |
| 1522 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1523 | } |
| 1524 | } |
| 1525 | |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1526 | void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object, |
| 1527 | GpuRegister value, |
| 1528 | bool value_can_be_null) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1529 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1530 | GpuRegister card = AT; |
| 1531 | GpuRegister temp = TMP; |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1532 | if (value_can_be_null) { |
| 1533 | __ Beqzc(value, &done); |
| 1534 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1535 | __ LoadFromOffset(kLoadDoubleword, |
| 1536 | card, |
| 1537 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1538 | Thread::CardTableOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1539 | __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1540 | __ Daddu(temp, card, temp); |
| 1541 | __ Sb(card, temp, 0); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1542 | if (value_can_be_null) { |
| 1543 | __ Bind(&done); |
| 1544 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1547 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1548 | inline void CodeGeneratorMIPS64::EmitPcRelativeLinkerPatches( |
| 1549 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1550 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1551 | for (const PcRelativePatchInfo& info : infos) { |
| 1552 | const DexFile& dex_file = info.target_dex_file; |
| 1553 | size_t offset_or_index = info.offset_or_index; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1554 | DCHECK(info.label.IsBound()); |
| 1555 | uint32_t literal_offset = __ GetLabelLocation(&info.label); |
| 1556 | const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info; |
| 1557 | uint32_t pc_rel_offset = __ GetLabelLocation(&info_high.label); |
| 1558 | linker_patches->push_back(Factory(literal_offset, &dex_file, pc_rel_offset, offset_or_index)); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1559 | } |
| 1560 | } |
| 1561 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1562 | void CodeGeneratorMIPS64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1563 | DCHECK(linker_patches->empty()); |
| 1564 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1565 | pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1566 | method_bss_entry_patches_.size() + |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1567 | pc_relative_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1568 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1569 | pc_relative_string_patches_.size() + |
| 1570 | string_bss_entry_patches_.size(); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1571 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1572 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1573 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 1574 | pc_relative_method_patches_, linker_patches); |
| 1575 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 1576 | pc_relative_type_patches_, linker_patches); |
| 1577 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 1578 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1579 | } else { |
| 1580 | DCHECK(pc_relative_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1581 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 1582 | pc_relative_type_patches_, linker_patches); |
| 1583 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 1584 | pc_relative_string_patches_, linker_patches); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1585 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1586 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1587 | method_bss_entry_patches_, linker_patches); |
| 1588 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1589 | type_bss_entry_patches_, linker_patches); |
| 1590 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1591 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1592 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1593 | } |
| 1594 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1595 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeMethodPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1596 | MethodReference target_method, |
| 1597 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1598 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1599 | target_method.index, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1600 | info_high, |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1601 | &pc_relative_method_patches_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1602 | } |
| 1603 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1604 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewMethodBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1605 | MethodReference target_method, |
| 1606 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1607 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1608 | target_method.index, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1609 | info_high, |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1610 | &method_bss_entry_patches_); |
| 1611 | } |
| 1612 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1613 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeTypePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1614 | const DexFile& dex_file, |
| 1615 | dex::TypeIndex type_index, |
| 1616 | const PcRelativePatchInfo* info_high) { |
| 1617 | return NewPcRelativePatch(dex_file, type_index.index_, info_high, &pc_relative_type_patches_); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1618 | } |
| 1619 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1620 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewTypeBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1621 | const DexFile& dex_file, |
| 1622 | dex::TypeIndex type_index, |
| 1623 | const PcRelativePatchInfo* info_high) { |
| 1624 | return NewPcRelativePatch(dex_file, type_index.index_, info_high, &type_bss_entry_patches_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1627 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeStringPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1628 | const DexFile& dex_file, |
| 1629 | dex::StringIndex string_index, |
| 1630 | const PcRelativePatchInfo* info_high) { |
| 1631 | return NewPcRelativePatch(dex_file, string_index.index_, info_high, &pc_relative_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1632 | } |
| 1633 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1634 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewStringBssEntryPatch( |
| 1635 | const DexFile& dex_file, |
| 1636 | dex::StringIndex string_index, |
| 1637 | const PcRelativePatchInfo* info_high) { |
| 1638 | return NewPcRelativePatch(dex_file, string_index.index_, info_high, &string_bss_entry_patches_); |
| 1639 | } |
| 1640 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1641 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1642 | const DexFile& dex_file, |
| 1643 | uint32_t offset_or_index, |
| 1644 | const PcRelativePatchInfo* info_high, |
| 1645 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1646 | patches->emplace_back(dex_file, offset_or_index, info_high); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1647 | return &patches->back(); |
| 1648 | } |
| 1649 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1650 | Literal* CodeGeneratorMIPS64::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1651 | return map->GetOrCreate( |
| 1652 | value, |
| 1653 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1654 | } |
| 1655 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1656 | Literal* CodeGeneratorMIPS64::DeduplicateUint64Literal(uint64_t value) { |
| 1657 | return uint64_literals_.GetOrCreate( |
| 1658 | value, |
| 1659 | [this, value]() { return __ NewLiteral<uint64_t>(value); }); |
| 1660 | } |
| 1661 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1662 | Literal* CodeGeneratorMIPS64::DeduplicateBootImageAddressLiteral(uint64_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1663 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1664 | } |
| 1665 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1666 | void CodeGeneratorMIPS64::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high, |
| 1667 | GpuRegister out, |
| 1668 | PcRelativePatchInfo* info_low) { |
| 1669 | DCHECK(!info_high->patch_info_high); |
| 1670 | __ Bind(&info_high->label); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1671 | // Add the high half of a 32-bit offset to PC. |
| 1672 | __ Auipc(out, /* placeholder */ 0x1234); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1673 | // A 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] | 1674 | // offset to `out` (e.g. ld, jialc, daddiu). |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1675 | if (info_low != nullptr) { |
| 1676 | DCHECK_EQ(info_low->patch_info_high, info_high); |
| 1677 | __ Bind(&info_low->label); |
| 1678 | } |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1679 | } |
| 1680 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1681 | Literal* CodeGeneratorMIPS64::DeduplicateJitStringLiteral(const DexFile& dex_file, |
| 1682 | dex::StringIndex string_index, |
| 1683 | Handle<mirror::String> handle) { |
| 1684 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 1685 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
| 1686 | return jit_string_patches_.GetOrCreate( |
| 1687 | StringReference(&dex_file, string_index), |
| 1688 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1689 | } |
| 1690 | |
| 1691 | Literal* CodeGeneratorMIPS64::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 1692 | dex::TypeIndex type_index, |
| 1693 | Handle<mirror::Class> handle) { |
| 1694 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 1695 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
| 1696 | return jit_class_patches_.GetOrCreate( |
| 1697 | TypeReference(&dex_file, type_index), |
| 1698 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1699 | } |
| 1700 | |
| 1701 | void CodeGeneratorMIPS64::PatchJitRootUse(uint8_t* code, |
| 1702 | const uint8_t* roots_data, |
| 1703 | const Literal* literal, |
| 1704 | uint64_t index_in_table) const { |
| 1705 | uint32_t literal_offset = GetAssembler().GetLabelLocation(literal->GetLabel()); |
| 1706 | uintptr_t address = |
| 1707 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1708 | reinterpret_cast<uint32_t*>(code + literal_offset)[0] = dchecked_integral_cast<uint32_t>(address); |
| 1709 | } |
| 1710 | |
| 1711 | void CodeGeneratorMIPS64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1712 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1713 | const StringReference& string_reference = entry.first; |
| 1714 | Literal* table_entry_literal = entry.second; |
| 1715 | const auto it = jit_string_roots_.find(string_reference); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1716 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1717 | uint64_t index_in_table = it->second; |
| 1718 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1719 | } |
| 1720 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1721 | const TypeReference& type_reference = entry.first; |
| 1722 | Literal* table_entry_literal = entry.second; |
| 1723 | const auto it = jit_class_roots_.find(type_reference); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1724 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1725 | uint64_t index_in_table = it->second; |
| 1726 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1727 | } |
| 1728 | } |
| 1729 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1730 | void CodeGeneratorMIPS64::SetupBlockedRegisters() const { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1731 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1732 | blocked_core_registers_[ZERO] = true; |
| 1733 | blocked_core_registers_[K0] = true; |
| 1734 | blocked_core_registers_[K1] = true; |
| 1735 | blocked_core_registers_[GP] = true; |
| 1736 | blocked_core_registers_[SP] = true; |
| 1737 | blocked_core_registers_[RA] = true; |
| 1738 | |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1739 | // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch |
| 1740 | // registers (similar to how AT is used by MIPS assemblers). |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1741 | blocked_core_registers_[AT] = true; |
| 1742 | blocked_core_registers_[TMP] = true; |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1743 | blocked_core_registers_[TMP2] = true; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1744 | blocked_fpu_registers_[FTMP] = true; |
| 1745 | |
| 1746 | // Reserve suspend and thread registers. |
| 1747 | blocked_core_registers_[S0] = true; |
| 1748 | blocked_core_registers_[TR] = true; |
| 1749 | |
| 1750 | // Reserve T9 for function calls |
| 1751 | blocked_core_registers_[T9] = true; |
| 1752 | |
Goran Jakovljevic | 782be11 | 2016-06-21 12:39:04 +0200 | [diff] [blame] | 1753 | if (GetGraph()->IsDebuggable()) { |
| 1754 | // Stubs do not save callee-save floating point registers. If the graph |
| 1755 | // is debuggable, we need to deal with these registers differently. For |
| 1756 | // now, just block them. |
| 1757 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1758 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1759 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1760 | } |
| 1761 | } |
| 1762 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1763 | size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1764 | __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1765 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1769 | __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1770 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1774 | __ StoreFpuToOffset(GetGraph()->HasSIMD() ? kStoreQuadword : kStoreDoubleword, |
| 1775 | FpuRegister(reg_id), |
| 1776 | SP, |
| 1777 | stack_index); |
| 1778 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1782 | __ LoadFpuFromOffset(GetGraph()->HasSIMD() ? kLoadQuadword : kLoadDoubleword, |
| 1783 | FpuRegister(reg_id), |
| 1784 | SP, |
| 1785 | stack_index); |
| 1786 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1790 | stream << GpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1794 | stream << FpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1797 | void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1798 | HInstruction* instruction, |
| 1799 | uint32_t dex_pc, |
| 1800 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1801 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1802 | GenerateInvokeRuntime(GetThreadOffset<kMips64PointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 1803 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1804 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1805 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1808 | void CodeGeneratorMIPS64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1809 | HInstruction* instruction, |
| 1810 | SlowPathCode* slow_path) { |
| 1811 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1812 | GenerateInvokeRuntime(entry_point_offset); |
| 1813 | } |
| 1814 | |
| 1815 | void CodeGeneratorMIPS64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| 1816 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 1817 | __ Jalr(T9); |
| 1818 | __ Nop(); |
| 1819 | } |
| 1820 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1821 | void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path, |
| 1822 | GpuRegister class_reg) { |
| 1823 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 1824 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 1825 | __ Bltc(TMP, AT, slow_path->GetEntryLabel()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1826 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1827 | __ Sync(0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1828 | __ Bind(slow_path->GetExitLabel()); |
| 1829 | } |
| 1830 | |
| 1831 | void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1832 | __ Sync(0); // only stype 0 is supported |
| 1833 | } |
| 1834 | |
| 1835 | void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1836 | HBasicBlock* successor) { |
| 1837 | SuspendCheckSlowPathMIPS64* slow_path = |
| 1838 | new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS64(instruction, successor); |
| 1839 | codegen_->AddSlowPath(slow_path); |
| 1840 | |
| 1841 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1842 | TMP, |
| 1843 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1844 | Thread::ThreadFlagsOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1845 | if (successor == nullptr) { |
| 1846 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 1847 | __ Bind(slow_path->GetReturnLabel()); |
| 1848 | } else { |
| 1849 | __ Beqzc(TMP, codegen_->GetLabelOf(successor)); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1850 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1851 | // slow_path will return to GetLabelOf(successor). |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph, |
| 1856 | CodeGeneratorMIPS64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1857 | : InstructionCodeGenerator(graph, codegen), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1858 | assembler_(codegen->GetAssembler()), |
| 1859 | codegen_(codegen) {} |
| 1860 | |
| 1861 | void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1862 | DCHECK_EQ(instruction->InputCount(), 2U); |
| 1863 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1864 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1865 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1866 | case DataType::Type::kInt32: |
| 1867 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1868 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1869 | HInstruction* right = instruction->InputAt(1); |
| 1870 | bool can_use_imm = false; |
| 1871 | if (right->IsConstant()) { |
| 1872 | int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant()); |
| 1873 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1874 | can_use_imm = IsUint<16>(imm); |
| 1875 | } else if (instruction->IsAdd()) { |
| 1876 | can_use_imm = IsInt<16>(imm); |
| 1877 | } else { |
| 1878 | DCHECK(instruction->IsSub()); |
| 1879 | can_use_imm = IsInt<16>(-imm); |
| 1880 | } |
| 1881 | } |
| 1882 | if (can_use_imm) |
| 1883 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1884 | else |
| 1885 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1886 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1887 | } |
| 1888 | break; |
| 1889 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1890 | case DataType::Type::kFloat32: |
| 1891 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1892 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1893 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1894 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1895 | break; |
| 1896 | |
| 1897 | default: |
| 1898 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1903 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1904 | LocationSummary* locations = instruction->GetLocations(); |
| 1905 | |
| 1906 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1907 | case DataType::Type::kInt32: |
| 1908 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1909 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1910 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1911 | Location rhs_location = locations->InAt(1); |
| 1912 | |
| 1913 | GpuRegister rhs_reg = ZERO; |
| 1914 | int64_t rhs_imm = 0; |
| 1915 | bool use_imm = rhs_location.IsConstant(); |
| 1916 | if (use_imm) { |
| 1917 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1918 | } else { |
| 1919 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1920 | } |
| 1921 | |
| 1922 | if (instruction->IsAnd()) { |
| 1923 | if (use_imm) |
| 1924 | __ Andi(dst, lhs, rhs_imm); |
| 1925 | else |
| 1926 | __ And(dst, lhs, rhs_reg); |
| 1927 | } else if (instruction->IsOr()) { |
| 1928 | if (use_imm) |
| 1929 | __ Ori(dst, lhs, rhs_imm); |
| 1930 | else |
| 1931 | __ Or(dst, lhs, rhs_reg); |
| 1932 | } else if (instruction->IsXor()) { |
| 1933 | if (use_imm) |
| 1934 | __ Xori(dst, lhs, rhs_imm); |
| 1935 | else |
| 1936 | __ Xor(dst, lhs, rhs_reg); |
| 1937 | } else if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1938 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1939 | if (use_imm) |
| 1940 | __ Addiu(dst, lhs, rhs_imm); |
| 1941 | else |
| 1942 | __ Addu(dst, lhs, rhs_reg); |
| 1943 | } else { |
| 1944 | if (use_imm) |
| 1945 | __ Daddiu(dst, lhs, rhs_imm); |
| 1946 | else |
| 1947 | __ Daddu(dst, lhs, rhs_reg); |
| 1948 | } |
| 1949 | } else { |
| 1950 | DCHECK(instruction->IsSub()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1951 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1952 | if (use_imm) |
| 1953 | __ Addiu(dst, lhs, -rhs_imm); |
| 1954 | else |
| 1955 | __ Subu(dst, lhs, rhs_reg); |
| 1956 | } else { |
| 1957 | if (use_imm) |
| 1958 | __ Daddiu(dst, lhs, -rhs_imm); |
| 1959 | else |
| 1960 | __ Dsubu(dst, lhs, rhs_reg); |
| 1961 | } |
| 1962 | } |
| 1963 | break; |
| 1964 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1965 | case DataType::Type::kFloat32: |
| 1966 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1967 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 1968 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 1969 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 1970 | if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1971 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1972 | __ AddS(dst, lhs, rhs); |
| 1973 | else |
| 1974 | __ AddD(dst, lhs, rhs); |
| 1975 | } else if (instruction->IsSub()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1976 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1977 | __ SubS(dst, lhs, rhs); |
| 1978 | else |
| 1979 | __ SubD(dst, lhs, rhs); |
| 1980 | } else { |
| 1981 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
| 1982 | } |
| 1983 | break; |
| 1984 | } |
| 1985 | default: |
| 1986 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 1987 | } |
| 1988 | } |
| 1989 | |
| 1990 | void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1991 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1992 | |
| 1993 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1994 | DataType::Type type = instr->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1995 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1996 | case DataType::Type::kInt32: |
| 1997 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1998 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1999 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2000 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2001 | break; |
| 2002 | } |
| 2003 | default: |
| 2004 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2005 | } |
| 2006 | } |
| 2007 | |
| 2008 | void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2009 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2010 | LocationSummary* locations = instr->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2011 | DataType::Type type = instr->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2012 | |
| 2013 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2014 | case DataType::Type::kInt32: |
| 2015 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2016 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 2017 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2018 | Location rhs_location = locations->InAt(1); |
| 2019 | |
| 2020 | GpuRegister rhs_reg = ZERO; |
| 2021 | int64_t rhs_imm = 0; |
| 2022 | bool use_imm = rhs_location.IsConstant(); |
| 2023 | if (use_imm) { |
| 2024 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 2025 | } else { |
| 2026 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 2027 | } |
| 2028 | |
| 2029 | if (use_imm) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2030 | uint32_t shift_value = rhs_imm & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2031 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2032 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2033 | if (shift_value == 0) { |
| 2034 | if (dst != lhs) { |
| 2035 | __ Move(dst, lhs); |
| 2036 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2037 | } else if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2038 | if (instr->IsShl()) { |
| 2039 | __ Sll(dst, lhs, shift_value); |
| 2040 | } else if (instr->IsShr()) { |
| 2041 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2042 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2043 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2044 | } else { |
| 2045 | __ Rotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2046 | } |
| 2047 | } else { |
| 2048 | if (shift_value < 32) { |
| 2049 | if (instr->IsShl()) { |
| 2050 | __ Dsll(dst, lhs, shift_value); |
| 2051 | } else if (instr->IsShr()) { |
| 2052 | __ Dsra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2053 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2054 | __ Dsrl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2055 | } else { |
| 2056 | __ Drotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2057 | } |
| 2058 | } else { |
| 2059 | shift_value -= 32; |
| 2060 | if (instr->IsShl()) { |
| 2061 | __ Dsll32(dst, lhs, shift_value); |
| 2062 | } else if (instr->IsShr()) { |
| 2063 | __ Dsra32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2064 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2065 | __ Dsrl32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2066 | } else { |
| 2067 | __ Drotr32(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2068 | } |
| 2069 | } |
| 2070 | } |
| 2071 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2072 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2073 | if (instr->IsShl()) { |
| 2074 | __ Sllv(dst, lhs, rhs_reg); |
| 2075 | } else if (instr->IsShr()) { |
| 2076 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2077 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2078 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2079 | } else { |
| 2080 | __ Rotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2081 | } |
| 2082 | } else { |
| 2083 | if (instr->IsShl()) { |
| 2084 | __ Dsllv(dst, lhs, rhs_reg); |
| 2085 | } else if (instr->IsShr()) { |
| 2086 | __ Dsrav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2087 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2088 | __ Dsrlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2089 | } else { |
| 2090 | __ Drotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2091 | } |
| 2092 | } |
| 2093 | } |
| 2094 | break; |
| 2095 | } |
| 2096 | default: |
| 2097 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2098 | } |
| 2099 | } |
| 2100 | |
| 2101 | void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) { |
| 2102 | HandleBinaryOp(instruction); |
| 2103 | } |
| 2104 | |
| 2105 | void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) { |
| 2106 | HandleBinaryOp(instruction); |
| 2107 | } |
| 2108 | |
| 2109 | void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) { |
| 2110 | HandleBinaryOp(instruction); |
| 2111 | } |
| 2112 | |
| 2113 | void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) { |
| 2114 | HandleBinaryOp(instruction); |
| 2115 | } |
| 2116 | |
| 2117 | void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2118 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2119 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2120 | kEmitCompilerReadBarrier && (type == DataType::Type::kReference); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2121 | LocationSummary* locations = |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2122 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2123 | object_array_get_with_read_barrier |
| 2124 | ? LocationSummary::kCallOnSlowPath |
| 2125 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 2126 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2127 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2128 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2129 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2130 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2131 | if (DataType::IsFloatingPointType(type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2132 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2133 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2134 | // The output overlaps in the case of an object array get with |
| 2135 | // read barriers enabled: we do not want the move to overwrite the |
| 2136 | // array's location, as we need it to emit the read barrier. |
| 2137 | locations->SetOut(Location::RequiresRegister(), |
| 2138 | object_array_get_with_read_barrier |
| 2139 | ? Location::kOutputOverlap |
| 2140 | : Location::kNoOutputOverlap); |
| 2141 | } |
| 2142 | // We need a temporary register for the read barrier marking slow |
| 2143 | // path in CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier. |
| 2144 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2145 | bool temp_needed = instruction->GetIndex()->IsConstant() |
| 2146 | ? !kBakerReadBarrierThunksEnableForFields |
| 2147 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2148 | if (temp_needed) { |
| 2149 | locations->AddTemp(Location::RequiresRegister()); |
| 2150 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2151 | } |
| 2152 | } |
| 2153 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2154 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS64* codegen) { |
| 2155 | auto null_checker = [codegen, instruction]() { |
| 2156 | codegen->MaybeRecordImplicitNullCheck(instruction); |
| 2157 | }; |
| 2158 | return null_checker; |
| 2159 | } |
| 2160 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2161 | void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) { |
| 2162 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2163 | Location obj_loc = locations->InAt(0); |
| 2164 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 2165 | Location out_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2166 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2167 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2168 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2169 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2170 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2171 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2172 | instruction->IsStringCharAt(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2173 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2174 | case DataType::Type::kBool: |
| 2175 | case DataType::Type::kUint8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2176 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2177 | if (index.IsConstant()) { |
| 2178 | size_t offset = |
| 2179 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2180 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2181 | } else { |
| 2182 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2183 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2184 | } |
| 2185 | break; |
| 2186 | } |
| 2187 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2188 | case DataType::Type::kInt8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2189 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2190 | if (index.IsConstant()) { |
| 2191 | size_t offset = |
| 2192 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2193 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2194 | } else { |
| 2195 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2196 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2197 | } |
| 2198 | break; |
| 2199 | } |
| 2200 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2201 | case DataType::Type::kUint16: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2202 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2203 | if (maybe_compressed_char_at) { |
| 2204 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2205 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2206 | __ Dext(TMP, TMP, 0, 1); |
| 2207 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2208 | "Expecting 0=compressed, 1=uncompressed"); |
| 2209 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2210 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2211 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2212 | if (maybe_compressed_char_at) { |
| 2213 | Mips64Label uncompressed_load, done; |
| 2214 | __ Bnezc(TMP, &uncompressed_load); |
| 2215 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2216 | out, |
| 2217 | obj, |
| 2218 | data_offset + (const_index << TIMES_1)); |
| 2219 | __ Bc(&done); |
| 2220 | __ Bind(&uncompressed_load); |
| 2221 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2222 | out, |
| 2223 | obj, |
| 2224 | data_offset + (const_index << TIMES_2)); |
| 2225 | __ Bind(&done); |
| 2226 | } else { |
| 2227 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2228 | out, |
| 2229 | obj, |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2230 | data_offset + (const_index << TIMES_2), |
| 2231 | null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2232 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2233 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2234 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
| 2235 | if (maybe_compressed_char_at) { |
| 2236 | Mips64Label uncompressed_load, done; |
| 2237 | __ Bnezc(TMP, &uncompressed_load); |
| 2238 | __ Daddu(TMP, obj, index_reg); |
| 2239 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2240 | __ Bc(&done); |
| 2241 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2242 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2243 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2244 | __ Bind(&done); |
| 2245 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2246 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2247 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2248 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2249 | } |
| 2250 | break; |
| 2251 | } |
| 2252 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2253 | case DataType::Type::kInt16: { |
| 2254 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 2255 | if (index.IsConstant()) { |
| 2256 | size_t offset = |
| 2257 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2258 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
| 2259 | } else { |
| 2260 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
| 2261 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
| 2262 | } |
| 2263 | break; |
| 2264 | } |
| 2265 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2266 | case DataType::Type::kInt32: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2267 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2268 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2269 | LoadOperandType load_type = |
| 2270 | (type == DataType::Type::kReference) ? kLoadUnsignedWord : kLoadWord; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2271 | if (index.IsConstant()) { |
| 2272 | size_t offset = |
| 2273 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2274 | __ LoadFromOffset(load_type, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2275 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2276 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2277 | __ LoadFromOffset(load_type, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2278 | } |
| 2279 | break; |
| 2280 | } |
| 2281 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2282 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2283 | static_assert( |
| 2284 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2285 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2286 | // /* HeapReference<Object> */ out = |
| 2287 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2288 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2289 | bool temp_needed = index.IsConstant() |
| 2290 | ? !kBakerReadBarrierThunksEnableForFields |
| 2291 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2292 | Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2293 | // Note that a potential implicit null check is handled in this |
| 2294 | // CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier call. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2295 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 2296 | if (index.IsConstant()) { |
| 2297 | // Array load with a constant index can be treated as a field load. |
| 2298 | size_t offset = |
| 2299 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2300 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2301 | out_loc, |
| 2302 | obj, |
| 2303 | offset, |
| 2304 | temp, |
| 2305 | /* needs_null_check */ false); |
| 2306 | } else { |
| 2307 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2308 | out_loc, |
| 2309 | obj, |
| 2310 | data_offset, |
| 2311 | index, |
| 2312 | temp, |
| 2313 | /* needs_null_check */ false); |
| 2314 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2315 | } else { |
| 2316 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 2317 | if (index.IsConstant()) { |
| 2318 | size_t offset = |
| 2319 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2320 | __ LoadFromOffset(kLoadUnsignedWord, out, obj, offset, null_checker); |
| 2321 | // If read barriers are enabled, emit read barriers other than |
| 2322 | // Baker's using a slow path (and also unpoison the loaded |
| 2323 | // reference, if heap poisoning is enabled). |
| 2324 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2325 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2326 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2327 | __ LoadFromOffset(kLoadUnsignedWord, out, TMP, data_offset, null_checker); |
| 2328 | // If read barriers are enabled, emit read barriers other than |
| 2329 | // Baker's using a slow path (and also unpoison the loaded |
| 2330 | // reference, if heap poisoning is enabled). |
| 2331 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2332 | out_loc, |
| 2333 | out_loc, |
| 2334 | obj_loc, |
| 2335 | data_offset, |
| 2336 | index); |
| 2337 | } |
| 2338 | } |
| 2339 | break; |
| 2340 | } |
| 2341 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2342 | case DataType::Type::kInt64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2343 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2344 | if (index.IsConstant()) { |
| 2345 | size_t offset = |
| 2346 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2347 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2348 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2349 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2350 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2351 | } |
| 2352 | break; |
| 2353 | } |
| 2354 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2355 | case DataType::Type::kFloat32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2356 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2357 | if (index.IsConstant()) { |
| 2358 | size_t offset = |
| 2359 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2360 | __ LoadFpuFromOffset(kLoadWord, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2361 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2362 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2363 | __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2364 | } |
| 2365 | break; |
| 2366 | } |
| 2367 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2368 | case DataType::Type::kFloat64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2369 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2370 | if (index.IsConstant()) { |
| 2371 | size_t offset = |
| 2372 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2373 | __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2374 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2375 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2376 | __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2377 | } |
| 2378 | break; |
| 2379 | } |
| 2380 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2381 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2382 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2383 | UNREACHABLE(); |
| 2384 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 2388 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2389 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2390 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2391 | } |
| 2392 | |
| 2393 | void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 2394 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2395 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2396 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2397 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2398 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2399 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2400 | // Mask out compression flag from String's array length. |
| 2401 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2402 | __ Srl(out, out, 1u); |
| 2403 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2404 | } |
| 2405 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2406 | Location LocationsBuilderMIPS64::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2407 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2408 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2409 | : Location::RequiresRegister(); |
| 2410 | } |
| 2411 | |
| 2412 | Location LocationsBuilderMIPS64::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2413 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2414 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2415 | // but we should only prefer this if the constant has a single use. |
| 2416 | if (instruction->IsConstant() && |
| 2417 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2418 | instruction->GetUses().HasExactlyOneElement())) { |
| 2419 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2420 | // Otherwise fall through and require an FPU register for the constant. |
| 2421 | } |
| 2422 | return Location::RequiresFpuRegister(); |
| 2423 | } |
| 2424 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2425 | void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2426 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2427 | |
| 2428 | bool needs_write_barrier = |
| 2429 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2430 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2431 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2432 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2433 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2434 | may_need_runtime_call_for_type_check ? |
| 2435 | LocationSummary::kCallOnSlowPath : |
| 2436 | LocationSummary::kNoCall); |
| 2437 | |
| 2438 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2439 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2440 | if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2441 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2442 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2443 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2444 | } |
| 2445 | if (needs_write_barrier) { |
| 2446 | // Temporary register for the write barrier. |
| 2447 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2448 | } |
| 2449 | } |
| 2450 | |
| 2451 | void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) { |
| 2452 | LocationSummary* locations = instruction->GetLocations(); |
| 2453 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2454 | Location index = locations->InAt(1); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2455 | Location value_location = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2456 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2457 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2458 | bool needs_write_barrier = |
| 2459 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2460 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2461 | GpuRegister base_reg = index.IsConstant() ? obj : TMP; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2462 | |
| 2463 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2464 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2465 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2466 | case DataType::Type::kInt8: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2467 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2468 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2469 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2470 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2471 | __ Daddu(base_reg, obj, index.AsRegister<GpuRegister>()); |
| 2472 | } |
| 2473 | if (value_location.IsConstant()) { |
| 2474 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2475 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2476 | } else { |
| 2477 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2478 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2479 | } |
| 2480 | break; |
| 2481 | } |
| 2482 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2483 | case DataType::Type::kUint16: |
| 2484 | case DataType::Type::kInt16: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2485 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2486 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2487 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2488 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2489 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2490 | } |
| 2491 | if (value_location.IsConstant()) { |
| 2492 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2493 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2494 | } else { |
| 2495 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2496 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2497 | } |
| 2498 | break; |
| 2499 | } |
| 2500 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2501 | case DataType::Type::kInt32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2502 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2503 | if (index.IsConstant()) { |
| 2504 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
| 2505 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2506 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2507 | } |
| 2508 | if (value_location.IsConstant()) { |
| 2509 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2510 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2511 | } else { |
| 2512 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2513 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2514 | } |
| 2515 | break; |
| 2516 | } |
| 2517 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2518 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2519 | if (value_location.IsConstant()) { |
| 2520 | // Just setting null. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2521 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2522 | if (index.IsConstant()) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2523 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2524 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2525 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2526 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2527 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2528 | DCHECK_EQ(value, 0); |
| 2529 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2530 | DCHECK(!needs_write_barrier); |
| 2531 | DCHECK(!may_need_runtime_call_for_type_check); |
| 2532 | break; |
| 2533 | } |
| 2534 | |
| 2535 | DCHECK(needs_write_barrier); |
| 2536 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2537 | GpuRegister temp1 = locations->GetTemp(0).AsRegister<GpuRegister>(); |
| 2538 | GpuRegister temp2 = TMP; // Doesn't need to survive slow path. |
| 2539 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2540 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2541 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2542 | Mips64Label done; |
| 2543 | SlowPathCodeMIPS64* slow_path = nullptr; |
| 2544 | |
| 2545 | if (may_need_runtime_call_for_type_check) { |
| 2546 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathMIPS64(instruction); |
| 2547 | codegen_->AddSlowPath(slow_path); |
| 2548 | if (instruction->GetValueCanBeNull()) { |
| 2549 | Mips64Label non_zero; |
| 2550 | __ Bnezc(value, &non_zero); |
| 2551 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2552 | if (index.IsConstant()) { |
| 2553 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2554 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2555 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2556 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2557 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2558 | __ Bc(&done); |
| 2559 | __ Bind(&non_zero); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2560 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2561 | |
| 2562 | // Note that when read barriers are enabled, the type checks |
| 2563 | // are performed without read barriers. This is fine, even in |
| 2564 | // the case where a class object is in the from-space after |
| 2565 | // the flip, as a comparison involving such a type would not |
| 2566 | // produce a false positive; it may of course produce a false |
| 2567 | // negative, in which case we would take the ArraySet slow |
| 2568 | // path. |
| 2569 | |
| 2570 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 2571 | __ LoadFromOffset(kLoadUnsignedWord, temp1, obj, class_offset, null_checker); |
| 2572 | __ MaybeUnpoisonHeapReference(temp1); |
| 2573 | |
| 2574 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2575 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, component_offset); |
| 2576 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2577 | __ LoadFromOffset(kLoadUnsignedWord, temp2, value, class_offset); |
| 2578 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 2579 | // nor `temp2`, as we are comparing two poisoned references. |
| 2580 | |
| 2581 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2582 | Mips64Label do_put; |
| 2583 | __ Beqc(temp1, temp2, &do_put); |
| 2584 | // If heap poisoning is enabled, the `temp1` reference has |
| 2585 | // not been unpoisoned yet; unpoison it now. |
| 2586 | __ MaybeUnpoisonHeapReference(temp1); |
| 2587 | |
| 2588 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 2589 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, super_offset); |
| 2590 | // If heap poisoning is enabled, no need to unpoison |
| 2591 | // `temp1`, as we are comparing against null below. |
| 2592 | __ Bnezc(temp1, slow_path->GetEntryLabel()); |
| 2593 | __ Bind(&do_put); |
| 2594 | } else { |
| 2595 | __ Bnec(temp1, temp2, slow_path->GetEntryLabel()); |
| 2596 | } |
| 2597 | } |
| 2598 | |
| 2599 | GpuRegister source = value; |
| 2600 | if (kPoisonHeapReferences) { |
| 2601 | // Note that in the case where `value` is a null reference, |
| 2602 | // we do not enter this block, as a null reference does not |
| 2603 | // need poisoning. |
| 2604 | __ Move(temp1, value); |
| 2605 | __ PoisonHeapReference(temp1); |
| 2606 | source = temp1; |
| 2607 | } |
| 2608 | |
| 2609 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2610 | if (index.IsConstant()) { |
| 2611 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2612 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2613 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2614 | } |
| 2615 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 2616 | |
| 2617 | if (!may_need_runtime_call_for_type_check) { |
| 2618 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2619 | } |
| 2620 | |
| 2621 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 2622 | |
| 2623 | if (done.IsLinked()) { |
| 2624 | __ Bind(&done); |
| 2625 | } |
| 2626 | |
| 2627 | if (slow_path != nullptr) { |
| 2628 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2629 | } |
| 2630 | break; |
| 2631 | } |
| 2632 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2633 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2634 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2635 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2636 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2637 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2638 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2639 | } |
| 2640 | if (value_location.IsConstant()) { |
| 2641 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2642 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2643 | } else { |
| 2644 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2645 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2646 | } |
| 2647 | break; |
| 2648 | } |
| 2649 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2650 | case DataType::Type::kFloat32: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2651 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2652 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2653 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2654 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2655 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2656 | } |
| 2657 | if (value_location.IsConstant()) { |
| 2658 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2659 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2660 | } else { |
| 2661 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2662 | __ StoreFpuToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2663 | } |
| 2664 | break; |
| 2665 | } |
| 2666 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2667 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2668 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2669 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2670 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2671 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2672 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2673 | } |
| 2674 | if (value_location.IsConstant()) { |
| 2675 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2676 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2677 | } else { |
| 2678 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2679 | __ StoreFpuToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2680 | } |
| 2681 | break; |
| 2682 | } |
| 2683 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2684 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2685 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2686 | UNREACHABLE(); |
| 2687 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2691 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2692 | InvokeRuntimeCallingConvention calling_convention; |
| 2693 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2694 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2695 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2696 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2697 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2701 | LocationSummary* locations = instruction->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2702 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2703 | new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS64(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2704 | codegen_->AddSlowPath(slow_path); |
| 2705 | |
| 2706 | GpuRegister index = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2707 | GpuRegister length = locations->InAt(1).AsRegister<GpuRegister>(); |
| 2708 | |
| 2709 | // length is limited by the maximum positive signed 32-bit integer. |
| 2710 | // Unsigned comparison of length and index checks for index < 0 |
| 2711 | // and for length <= index simultaneously. |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2712 | __ Bgeuc(index, length, slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2715 | // Temp is used for read barrier. |
| 2716 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 2717 | if (kEmitCompilerReadBarrier && |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2718 | !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) && |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2719 | (kUseBakerReadBarrier || |
| 2720 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2721 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2722 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 2723 | return 1; |
| 2724 | } |
| 2725 | return 0; |
| 2726 | } |
| 2727 | |
| 2728 | // Extra temp is used for read barrier. |
| 2729 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 2730 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 2731 | } |
| 2732 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2733 | void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2734 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2735 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 2736 | |
| 2737 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 2738 | switch (type_check_kind) { |
| 2739 | case TypeCheckKind::kExactCheck: |
| 2740 | case TypeCheckKind::kAbstractClassCheck: |
| 2741 | case TypeCheckKind::kClassHierarchyCheck: |
| 2742 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2743 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2744 | ? LocationSummary::kCallOnSlowPath |
| 2745 | : LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 2746 | break; |
| 2747 | case TypeCheckKind::kArrayCheck: |
| 2748 | case TypeCheckKind::kUnresolvedCheck: |
| 2749 | case TypeCheckKind::kInterfaceCheck: |
| 2750 | call_kind = LocationSummary::kCallOnSlowPath; |
| 2751 | break; |
| 2752 | } |
| 2753 | |
| 2754 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2755 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2756 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2757 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2758 | } |
| 2759 | |
| 2760 | void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2761 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2762 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2763 | Location obj_loc = locations->InAt(0); |
| 2764 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2765 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2766 | Location temp_loc = locations->GetTemp(0); |
| 2767 | GpuRegister temp = temp_loc.AsRegister<GpuRegister>(); |
| 2768 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 2769 | DCHECK_LE(num_temps, 2u); |
| 2770 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2771 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2772 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2773 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2774 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 2775 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 2776 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 2777 | const uint32_t object_array_data_offset = |
| 2778 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 2779 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2780 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2781 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 2782 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 2783 | // read barriers is done for performance and code size reasons. |
| 2784 | bool is_type_check_slow_path_fatal = false; |
| 2785 | if (!kEmitCompilerReadBarrier) { |
| 2786 | is_type_check_slow_path_fatal = |
| 2787 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 2788 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2789 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2790 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 2791 | !instruction->CanThrowIntoCatchBlock(); |
| 2792 | } |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2793 | SlowPathCodeMIPS64* slow_path = |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2794 | new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction, |
| 2795 | is_type_check_slow_path_fatal); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2796 | codegen_->AddSlowPath(slow_path); |
| 2797 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2798 | // Avoid this check if we know `obj` is not null. |
| 2799 | if (instruction->MustDoNullCheck()) { |
| 2800 | __ Beqzc(obj, &done); |
| 2801 | } |
| 2802 | |
| 2803 | switch (type_check_kind) { |
| 2804 | case TypeCheckKind::kExactCheck: |
| 2805 | case TypeCheckKind::kArrayCheck: { |
| 2806 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2807 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2808 | temp_loc, |
| 2809 | obj_loc, |
| 2810 | class_offset, |
| 2811 | maybe_temp2_loc, |
| 2812 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2813 | // Jump to slow path for throwing the exception or doing a |
| 2814 | // more involved array check. |
| 2815 | __ Bnec(temp, cls, slow_path->GetEntryLabel()); |
| 2816 | break; |
| 2817 | } |
| 2818 | |
| 2819 | case TypeCheckKind::kAbstractClassCheck: { |
| 2820 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2821 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2822 | temp_loc, |
| 2823 | obj_loc, |
| 2824 | class_offset, |
| 2825 | maybe_temp2_loc, |
| 2826 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2827 | // If the class is abstract, we eagerly fetch the super class of the |
| 2828 | // object to avoid doing a comparison we know will fail. |
| 2829 | Mips64Label loop; |
| 2830 | __ Bind(&loop); |
| 2831 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2832 | GenerateReferenceLoadOneRegister(instruction, |
| 2833 | temp_loc, |
| 2834 | super_offset, |
| 2835 | maybe_temp2_loc, |
| 2836 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2837 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2838 | // exception. |
| 2839 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2840 | // Otherwise, compare the classes. |
| 2841 | __ Bnec(temp, cls, &loop); |
| 2842 | break; |
| 2843 | } |
| 2844 | |
| 2845 | case TypeCheckKind::kClassHierarchyCheck: { |
| 2846 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2847 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2848 | temp_loc, |
| 2849 | obj_loc, |
| 2850 | class_offset, |
| 2851 | maybe_temp2_loc, |
| 2852 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2853 | // Walk over the class hierarchy to find a match. |
| 2854 | Mips64Label loop; |
| 2855 | __ Bind(&loop); |
| 2856 | __ Beqc(temp, cls, &done); |
| 2857 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2858 | GenerateReferenceLoadOneRegister(instruction, |
| 2859 | temp_loc, |
| 2860 | super_offset, |
| 2861 | maybe_temp2_loc, |
| 2862 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2863 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2864 | // exception. Otherwise, jump to the beginning of the loop. |
| 2865 | __ Bnezc(temp, &loop); |
| 2866 | __ Bc(slow_path->GetEntryLabel()); |
| 2867 | break; |
| 2868 | } |
| 2869 | |
| 2870 | case TypeCheckKind::kArrayObjectCheck: { |
| 2871 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2872 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2873 | temp_loc, |
| 2874 | obj_loc, |
| 2875 | class_offset, |
| 2876 | maybe_temp2_loc, |
| 2877 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2878 | // Do an exact check. |
| 2879 | __ Beqc(temp, cls, &done); |
| 2880 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 2881 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2882 | GenerateReferenceLoadOneRegister(instruction, |
| 2883 | temp_loc, |
| 2884 | component_offset, |
| 2885 | maybe_temp2_loc, |
| 2886 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2887 | // If the component type is null, jump to the slow path to throw the exception. |
| 2888 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2889 | // Otherwise, the object is indeed an array, further check that this component |
| 2890 | // type is not a primitive type. |
| 2891 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 2892 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 2893 | __ Bnezc(temp, slow_path->GetEntryLabel()); |
| 2894 | break; |
| 2895 | } |
| 2896 | |
| 2897 | case TypeCheckKind::kUnresolvedCheck: |
| 2898 | // We always go into the type check slow path for the unresolved check case. |
| 2899 | // We cannot directly call the CheckCast runtime entry point |
| 2900 | // without resorting to a type checking slow path here (i.e. by |
| 2901 | // calling InvokeRuntime directly), as it would require to |
| 2902 | // assign fixed registers for the inputs of this HInstanceOf |
| 2903 | // instruction (following the runtime calling convention), which |
| 2904 | // might be cluttered by the potential first read barrier |
| 2905 | // emission at the beginning of this method. |
| 2906 | __ Bc(slow_path->GetEntryLabel()); |
| 2907 | break; |
| 2908 | |
| 2909 | case TypeCheckKind::kInterfaceCheck: { |
| 2910 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 2911 | // positives by doing this. |
| 2912 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2913 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2914 | temp_loc, |
| 2915 | obj_loc, |
| 2916 | class_offset, |
| 2917 | maybe_temp2_loc, |
| 2918 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2919 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2920 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2921 | temp_loc, |
| 2922 | temp_loc, |
| 2923 | iftable_offset, |
| 2924 | maybe_temp2_loc, |
| 2925 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2926 | // Iftable is never null. |
| 2927 | __ Lw(TMP, temp, array_length_offset); |
| 2928 | // Loop through the iftable and check if any class matches. |
| 2929 | Mips64Label loop; |
| 2930 | __ Bind(&loop); |
| 2931 | __ Beqzc(TMP, slow_path->GetEntryLabel()); |
| 2932 | __ Lwu(AT, temp, object_array_data_offset); |
| 2933 | __ MaybeUnpoisonHeapReference(AT); |
| 2934 | // Go to next interface. |
| 2935 | __ Daddiu(temp, temp, 2 * kHeapReferenceSize); |
| 2936 | __ Addiu(TMP, TMP, -2); |
| 2937 | // Compare the classes and continue the loop if they do not match. |
| 2938 | __ Bnec(AT, cls, &loop); |
| 2939 | break; |
| 2940 | } |
| 2941 | } |
| 2942 | |
| 2943 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2944 | __ Bind(slow_path->GetExitLabel()); |
| 2945 | } |
| 2946 | |
| 2947 | void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 2948 | LocationSummary* locations = |
| 2949 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2950 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2951 | if (check->HasUses()) { |
| 2952 | locations->SetOut(Location::SameAsFirstInput()); |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 2957 | // We assume the class is not null. |
| 2958 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64( |
| 2959 | check->GetLoadClass(), |
| 2960 | check, |
| 2961 | check->GetDexPc(), |
| 2962 | true); |
| 2963 | codegen_->AddSlowPath(slow_path); |
| 2964 | GenerateClassInitializationCheck(slow_path, |
| 2965 | check->GetLocations()->InAt(0).AsRegister<GpuRegister>()); |
| 2966 | } |
| 2967 | |
| 2968 | void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2969 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2970 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2971 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(compare); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2972 | |
| 2973 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2974 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2975 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2976 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2977 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2978 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2979 | case DataType::Type::kInt32: |
| 2980 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2981 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2982 | locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2983 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2984 | break; |
| 2985 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2986 | case DataType::Type::kFloat32: |
| 2987 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2988 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2989 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2990 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2991 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2992 | |
| 2993 | default: |
| 2994 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2995 | } |
| 2996 | } |
| 2997 | |
| 2998 | void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) { |
| 2999 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3000 | GpuRegister res = locations->Out().AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3001 | DataType::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3002 | |
| 3003 | // 0 if: left == right |
| 3004 | // 1 if: left > right |
| 3005 | // -1 if: left < right |
| 3006 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3007 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3008 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3009 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3010 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3011 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3012 | case DataType::Type::kInt32: |
| 3013 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3014 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3015 | Location rhs_location = locations->InAt(1); |
| 3016 | bool use_imm = rhs_location.IsConstant(); |
| 3017 | GpuRegister rhs = ZERO; |
| 3018 | if (use_imm) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3019 | if (in_type == DataType::Type::kInt64) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3020 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 3021 | if (value != 0) { |
| 3022 | rhs = AT; |
| 3023 | __ LoadConst64(rhs, value); |
| 3024 | } |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3025 | } else { |
| 3026 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 3027 | if (value != 0) { |
| 3028 | rhs = AT; |
| 3029 | __ LoadConst32(rhs, value); |
| 3030 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3031 | } |
| 3032 | } else { |
| 3033 | rhs = rhs_location.AsRegister<GpuRegister>(); |
| 3034 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3035 | __ Slt(TMP, lhs, rhs); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3036 | __ Slt(res, rhs, lhs); |
| 3037 | __ Subu(res, res, TMP); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3038 | break; |
| 3039 | } |
| 3040 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3041 | case DataType::Type::kFloat32: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3042 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3043 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3044 | Mips64Label done; |
| 3045 | __ CmpEqS(FTMP, lhs, rhs); |
| 3046 | __ LoadConst32(res, 0); |
| 3047 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3048 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3049 | __ CmpLtS(FTMP, lhs, rhs); |
| 3050 | __ LoadConst32(res, -1); |
| 3051 | __ Bc1nez(FTMP, &done); |
| 3052 | __ LoadConst32(res, 1); |
| 3053 | } else { |
| 3054 | __ CmpLtS(FTMP, rhs, lhs); |
| 3055 | __ LoadConst32(res, 1); |
| 3056 | __ Bc1nez(FTMP, &done); |
| 3057 | __ LoadConst32(res, -1); |
| 3058 | } |
| 3059 | __ Bind(&done); |
| 3060 | break; |
| 3061 | } |
| 3062 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3063 | case DataType::Type::kFloat64: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3064 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3065 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3066 | Mips64Label done; |
| 3067 | __ CmpEqD(FTMP, lhs, rhs); |
| 3068 | __ LoadConst32(res, 0); |
| 3069 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3070 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3071 | __ CmpLtD(FTMP, lhs, rhs); |
| 3072 | __ LoadConst32(res, -1); |
| 3073 | __ Bc1nez(FTMP, &done); |
| 3074 | __ LoadConst32(res, 1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3075 | } else { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3076 | __ CmpLtD(FTMP, rhs, lhs); |
| 3077 | __ LoadConst32(res, 1); |
| 3078 | __ Bc1nez(FTMP, &done); |
| 3079 | __ LoadConst32(res, -1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3080 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3081 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3082 | break; |
| 3083 | } |
| 3084 | |
| 3085 | default: |
| 3086 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3087 | } |
| 3088 | } |
| 3089 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3090 | void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3091 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3092 | switch (instruction->InputAt(0)->GetType()) { |
| 3093 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3094 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3095 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3096 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3097 | break; |
| 3098 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3099 | case DataType::Type::kFloat32: |
| 3100 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3101 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3102 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3103 | break; |
| 3104 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3105 | if (!instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3106 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3107 | } |
| 3108 | } |
| 3109 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3110 | void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3111 | if (instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3112 | return; |
| 3113 | } |
| 3114 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3115 | DataType::Type type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3116 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3117 | switch (type) { |
| 3118 | default: |
| 3119 | // Integer case. |
| 3120 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations); |
| 3121 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3122 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3123 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations); |
| 3124 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3125 | case DataType::Type::kFloat32: |
| 3126 | case DataType::Type::kFloat64: |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3127 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 3128 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3129 | } |
| 3130 | } |
| 3131 | |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3132 | void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3133 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3134 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3135 | |
| 3136 | LocationSummary* locations = instruction->GetLocations(); |
| 3137 | Location second = locations->InAt(1); |
| 3138 | DCHECK(second.IsConstant()); |
| 3139 | |
| 3140 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3141 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3142 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3143 | DCHECK(imm == 1 || imm == -1); |
| 3144 | |
| 3145 | if (instruction->IsRem()) { |
| 3146 | __ Move(out, ZERO); |
| 3147 | } else { |
| 3148 | if (imm == -1) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3149 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3150 | __ Subu(out, ZERO, dividend); |
| 3151 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3152 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3153 | __ Dsubu(out, ZERO, dividend); |
| 3154 | } |
| 3155 | } else if (out != dividend) { |
| 3156 | __ Move(out, dividend); |
| 3157 | } |
| 3158 | } |
| 3159 | } |
| 3160 | |
| 3161 | void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3162 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3163 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3164 | |
| 3165 | LocationSummary* locations = instruction->GetLocations(); |
| 3166 | Location second = locations->InAt(1); |
| 3167 | DCHECK(second.IsConstant()); |
| 3168 | |
| 3169 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3170 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3171 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3172 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3173 | int ctz_imm = CTZ(abs_imm); |
| 3174 | |
| 3175 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3176 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3177 | if (ctz_imm == 1) { |
| 3178 | // Fast path for division by +/-2, which is very common. |
| 3179 | __ Srl(TMP, dividend, 31); |
| 3180 | } else { |
| 3181 | __ Sra(TMP, dividend, 31); |
| 3182 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3183 | } |
| 3184 | __ Addu(out, dividend, TMP); |
| 3185 | __ Sra(out, out, ctz_imm); |
| 3186 | if (imm < 0) { |
| 3187 | __ Subu(out, ZERO, out); |
| 3188 | } |
| 3189 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3190 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3191 | if (ctz_imm == 1) { |
| 3192 | // Fast path for division by +/-2, which is very common. |
| 3193 | __ Dsrl32(TMP, dividend, 31); |
| 3194 | } else { |
| 3195 | __ Dsra32(TMP, dividend, 31); |
| 3196 | if (ctz_imm > 32) { |
| 3197 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3198 | } else { |
| 3199 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3200 | } |
| 3201 | } |
| 3202 | __ Daddu(out, dividend, TMP); |
| 3203 | if (ctz_imm < 32) { |
| 3204 | __ Dsra(out, out, ctz_imm); |
| 3205 | } else { |
| 3206 | __ Dsra32(out, out, ctz_imm - 32); |
| 3207 | } |
| 3208 | if (imm < 0) { |
| 3209 | __ Dsubu(out, ZERO, out); |
| 3210 | } |
| 3211 | } |
| 3212 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3213 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3214 | if (ctz_imm == 1) { |
| 3215 | // Fast path for modulo +/-2, which is very common. |
| 3216 | __ Sra(TMP, dividend, 31); |
| 3217 | __ Subu(out, dividend, TMP); |
| 3218 | __ Andi(out, out, 1); |
| 3219 | __ Addu(out, out, TMP); |
| 3220 | } else { |
| 3221 | __ Sra(TMP, dividend, 31); |
| 3222 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3223 | __ Addu(out, dividend, TMP); |
| 3224 | if (IsUint<16>(abs_imm - 1)) { |
| 3225 | __ Andi(out, out, abs_imm - 1); |
| 3226 | } else { |
| 3227 | __ Sll(out, out, 32 - ctz_imm); |
| 3228 | __ Srl(out, out, 32 - ctz_imm); |
| 3229 | } |
| 3230 | __ Subu(out, out, TMP); |
| 3231 | } |
| 3232 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3233 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3234 | if (ctz_imm == 1) { |
| 3235 | // Fast path for modulo +/-2, which is very common. |
| 3236 | __ Dsra32(TMP, dividend, 31); |
| 3237 | __ Dsubu(out, dividend, TMP); |
| 3238 | __ Andi(out, out, 1); |
| 3239 | __ Daddu(out, out, TMP); |
| 3240 | } else { |
| 3241 | __ Dsra32(TMP, dividend, 31); |
| 3242 | if (ctz_imm > 32) { |
| 3243 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3244 | } else { |
| 3245 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3246 | } |
| 3247 | __ Daddu(out, dividend, TMP); |
| 3248 | if (IsUint<16>(abs_imm - 1)) { |
| 3249 | __ Andi(out, out, abs_imm - 1); |
| 3250 | } else { |
| 3251 | if (ctz_imm > 32) { |
| 3252 | __ Dsll(out, out, 64 - ctz_imm); |
| 3253 | __ Dsrl(out, out, 64 - ctz_imm); |
| 3254 | } else { |
| 3255 | __ Dsll32(out, out, 32 - ctz_imm); |
| 3256 | __ Dsrl32(out, out, 32 - ctz_imm); |
| 3257 | } |
| 3258 | } |
| 3259 | __ Dsubu(out, out, TMP); |
| 3260 | } |
| 3261 | } |
| 3262 | } |
| 3263 | } |
| 3264 | |
| 3265 | void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3266 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3267 | |
| 3268 | LocationSummary* locations = instruction->GetLocations(); |
| 3269 | Location second = locations->InAt(1); |
| 3270 | DCHECK(second.IsConstant()); |
| 3271 | |
| 3272 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3273 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3274 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3275 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3276 | DataType::Type type = instruction->GetResultType(); |
| 3277 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type; |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3278 | |
| 3279 | int64_t magic; |
| 3280 | int shift; |
| 3281 | CalculateMagicAndShiftForDivRem(imm, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3282 | (type == DataType::Type::kInt64), |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3283 | &magic, |
| 3284 | &shift); |
| 3285 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3286 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3287 | __ LoadConst32(TMP, magic); |
| 3288 | __ MuhR6(TMP, dividend, TMP); |
| 3289 | |
| 3290 | if (imm > 0 && magic < 0) { |
| 3291 | __ Addu(TMP, TMP, dividend); |
| 3292 | } else if (imm < 0 && magic > 0) { |
| 3293 | __ Subu(TMP, TMP, dividend); |
| 3294 | } |
| 3295 | |
| 3296 | if (shift != 0) { |
| 3297 | __ Sra(TMP, TMP, shift); |
| 3298 | } |
| 3299 | |
| 3300 | if (instruction->IsDiv()) { |
| 3301 | __ Sra(out, TMP, 31); |
| 3302 | __ Subu(out, TMP, out); |
| 3303 | } else { |
| 3304 | __ Sra(AT, TMP, 31); |
| 3305 | __ Subu(AT, TMP, AT); |
| 3306 | __ LoadConst32(TMP, imm); |
| 3307 | __ MulR6(TMP, AT, TMP); |
| 3308 | __ Subu(out, dividend, TMP); |
| 3309 | } |
| 3310 | } else { |
| 3311 | __ LoadConst64(TMP, magic); |
| 3312 | __ Dmuh(TMP, dividend, TMP); |
| 3313 | |
| 3314 | if (imm > 0 && magic < 0) { |
| 3315 | __ Daddu(TMP, TMP, dividend); |
| 3316 | } else if (imm < 0 && magic > 0) { |
| 3317 | __ Dsubu(TMP, TMP, dividend); |
| 3318 | } |
| 3319 | |
| 3320 | if (shift >= 32) { |
| 3321 | __ Dsra32(TMP, TMP, shift - 32); |
| 3322 | } else if (shift > 0) { |
| 3323 | __ Dsra(TMP, TMP, shift); |
| 3324 | } |
| 3325 | |
| 3326 | if (instruction->IsDiv()) { |
| 3327 | __ Dsra32(out, TMP, 31); |
| 3328 | __ Dsubu(out, TMP, out); |
| 3329 | } else { |
| 3330 | __ Dsra32(AT, TMP, 31); |
| 3331 | __ Dsubu(AT, TMP, AT); |
| 3332 | __ LoadConst64(TMP, imm); |
| 3333 | __ Dmul(TMP, AT, TMP); |
| 3334 | __ Dsubu(out, dividend, TMP); |
| 3335 | } |
| 3336 | } |
| 3337 | } |
| 3338 | |
| 3339 | void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3340 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3341 | DataType::Type type = instruction->GetResultType(); |
| 3342 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type; |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3343 | |
| 3344 | LocationSummary* locations = instruction->GetLocations(); |
| 3345 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3346 | Location second = locations->InAt(1); |
| 3347 | |
| 3348 | if (second.IsConstant()) { |
| 3349 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3350 | if (imm == 0) { |
| 3351 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3352 | } else if (imm == 1 || imm == -1) { |
| 3353 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3354 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3355 | DivRemByPowerOfTwo(instruction); |
| 3356 | } else { |
| 3357 | DCHECK(imm <= -2 || imm >= 2); |
| 3358 | GenerateDivRemWithAnyConstant(instruction); |
| 3359 | } |
| 3360 | } else { |
| 3361 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3362 | GpuRegister divisor = second.AsRegister<GpuRegister>(); |
| 3363 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3364 | if (type == DataType::Type::kInt32) |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3365 | __ DivR6(out, dividend, divisor); |
| 3366 | else |
| 3367 | __ Ddiv(out, dividend, divisor); |
| 3368 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3369 | if (type == DataType::Type::kInt32) |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3370 | __ ModR6(out, dividend, divisor); |
| 3371 | else |
| 3372 | __ Dmod(out, dividend, divisor); |
| 3373 | } |
| 3374 | } |
| 3375 | } |
| 3376 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3377 | void LocationsBuilderMIPS64::VisitDiv(HDiv* div) { |
| 3378 | LocationSummary* locations = |
| 3379 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3380 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3381 | case DataType::Type::kInt32: |
| 3382 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3383 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3384 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3385 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3386 | break; |
| 3387 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3388 | case DataType::Type::kFloat32: |
| 3389 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3390 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3391 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3392 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3393 | break; |
| 3394 | |
| 3395 | default: |
| 3396 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3397 | } |
| 3398 | } |
| 3399 | |
| 3400 | void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3401 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3402 | LocationSummary* locations = instruction->GetLocations(); |
| 3403 | |
| 3404 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3405 | case DataType::Type::kInt32: |
| 3406 | case DataType::Type::kInt64: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3407 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3408 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3409 | case DataType::Type::kFloat32: |
| 3410 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3411 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 3412 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3413 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3414 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3415 | __ DivS(dst, lhs, rhs); |
| 3416 | else |
| 3417 | __ DivD(dst, lhs, rhs); |
| 3418 | break; |
| 3419 | } |
| 3420 | default: |
| 3421 | LOG(FATAL) << "Unexpected div type " << type; |
| 3422 | } |
| 3423 | } |
| 3424 | |
| 3425 | void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3426 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3427 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3431 | SlowPathCodeMIPS64* slow_path = |
| 3432 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS64(instruction); |
| 3433 | codegen_->AddSlowPath(slow_path); |
| 3434 | Location value = instruction->GetLocations()->InAt(0); |
| 3435 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3436 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3437 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3438 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3439 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3440 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3441 | } |
| 3442 | |
| 3443 | if (value.IsConstant()) { |
| 3444 | int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant()); |
| 3445 | if (divisor == 0) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3446 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3447 | } else { |
| 3448 | // A division by a non-null constant is valid. We don't need to perform |
| 3449 | // any check, so simply fall through. |
| 3450 | } |
| 3451 | } else { |
| 3452 | __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 3453 | } |
| 3454 | } |
| 3455 | |
| 3456 | void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3457 | LocationSummary* locations = |
| 3458 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3459 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3460 | } |
| 3461 | |
| 3462 | void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 3463 | // Will be generated at use site. |
| 3464 | } |
| 3465 | |
| 3466 | void LocationsBuilderMIPS64::VisitExit(HExit* exit) { |
| 3467 | exit->SetLocations(nullptr); |
| 3468 | } |
| 3469 | |
| 3470 | void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 3471 | } |
| 3472 | |
| 3473 | void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) { |
| 3474 | LocationSummary* locations = |
| 3475 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3476 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3477 | } |
| 3478 | |
| 3479 | void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 3480 | // Will be generated at use site. |
| 3481 | } |
| 3482 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3483 | void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3484 | DCHECK(!successor->IsExitBlock()); |
| 3485 | HBasicBlock* block = got->GetBlock(); |
| 3486 | HInstruction* previous = got->GetPrevious(); |
| 3487 | HLoopInformation* info = block->GetLoopInformation(); |
| 3488 | |
| 3489 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 3490 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3491 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3492 | return; |
| 3493 | } |
| 3494 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3495 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3496 | } |
| 3497 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3498 | __ Bc(codegen_->GetLabelOf(successor)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3499 | } |
| 3500 | } |
| 3501 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3502 | void LocationsBuilderMIPS64::VisitGoto(HGoto* got) { |
| 3503 | got->SetLocations(nullptr); |
| 3504 | } |
| 3505 | |
| 3506 | void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) { |
| 3507 | HandleGoto(got, got->GetSuccessor()); |
| 3508 | } |
| 3509 | |
| 3510 | void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3511 | try_boundary->SetLocations(nullptr); |
| 3512 | } |
| 3513 | |
| 3514 | void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3515 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3516 | if (!successor->IsExitBlock()) { |
| 3517 | HandleGoto(try_boundary, successor); |
| 3518 | } |
| 3519 | } |
| 3520 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3521 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond, |
| 3522 | bool is64bit, |
| 3523 | LocationSummary* locations) { |
| 3524 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3525 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3526 | Location rhs_location = locations->InAt(1); |
| 3527 | GpuRegister rhs_reg = ZERO; |
| 3528 | int64_t rhs_imm = 0; |
| 3529 | bool use_imm = rhs_location.IsConstant(); |
| 3530 | if (use_imm) { |
| 3531 | if (is64bit) { |
| 3532 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3533 | } else { |
| 3534 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3535 | } |
| 3536 | } else { |
| 3537 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3538 | } |
| 3539 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 3540 | |
| 3541 | switch (cond) { |
| 3542 | case kCondEQ: |
| 3543 | case kCondNE: |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3544 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3545 | if (rhs_imm == 0) { |
| 3546 | if (cond == kCondEQ) { |
| 3547 | __ Sltiu(dst, lhs, 1); |
| 3548 | } else { |
| 3549 | __ Sltu(dst, ZERO, lhs); |
| 3550 | } |
| 3551 | } else { |
| 3552 | if (is64bit) { |
| 3553 | __ Daddiu(dst, lhs, -rhs_imm); |
| 3554 | } else { |
| 3555 | __ Addiu(dst, lhs, -rhs_imm); |
| 3556 | } |
| 3557 | if (cond == kCondEQ) { |
| 3558 | __ Sltiu(dst, dst, 1); |
| 3559 | } else { |
| 3560 | __ Sltu(dst, ZERO, dst); |
| 3561 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3562 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3563 | } else { |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3564 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 3565 | __ Xori(dst, lhs, rhs_imm); |
| 3566 | } else { |
| 3567 | if (use_imm) { |
| 3568 | rhs_reg = TMP; |
| 3569 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3570 | } |
| 3571 | __ Xor(dst, lhs, rhs_reg); |
| 3572 | } |
| 3573 | if (cond == kCondEQ) { |
| 3574 | __ Sltiu(dst, dst, 1); |
| 3575 | } else { |
| 3576 | __ Sltu(dst, ZERO, dst); |
| 3577 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3578 | } |
| 3579 | break; |
| 3580 | |
| 3581 | case kCondLT: |
| 3582 | case kCondGE: |
| 3583 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3584 | __ Slti(dst, lhs, rhs_imm); |
| 3585 | } else { |
| 3586 | if (use_imm) { |
| 3587 | rhs_reg = TMP; |
| 3588 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3589 | } |
| 3590 | __ Slt(dst, lhs, rhs_reg); |
| 3591 | } |
| 3592 | if (cond == kCondGE) { |
| 3593 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3594 | // only the slt instruction but no sge. |
| 3595 | __ Xori(dst, dst, 1); |
| 3596 | } |
| 3597 | break; |
| 3598 | |
| 3599 | case kCondLE: |
| 3600 | case kCondGT: |
| 3601 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 3602 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3603 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 3604 | if (cond == kCondGT) { |
| 3605 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3606 | // only the slti instruction but no sgti. |
| 3607 | __ Xori(dst, dst, 1); |
| 3608 | } |
| 3609 | } else { |
| 3610 | if (use_imm) { |
| 3611 | rhs_reg = TMP; |
| 3612 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3613 | } |
| 3614 | __ Slt(dst, rhs_reg, lhs); |
| 3615 | if (cond == kCondLE) { |
| 3616 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3617 | // only the slt instruction but no sle. |
| 3618 | __ Xori(dst, dst, 1); |
| 3619 | } |
| 3620 | } |
| 3621 | break; |
| 3622 | |
| 3623 | case kCondB: |
| 3624 | case kCondAE: |
| 3625 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3626 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3627 | // the comparison and thus lets us compare directly with |
| 3628 | // unsigned values in the ranges [0, 0x7fff] and |
| 3629 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3630 | __ Sltiu(dst, lhs, rhs_imm); |
| 3631 | } else { |
| 3632 | if (use_imm) { |
| 3633 | rhs_reg = TMP; |
| 3634 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3635 | } |
| 3636 | __ Sltu(dst, lhs, rhs_reg); |
| 3637 | } |
| 3638 | if (cond == kCondAE) { |
| 3639 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3640 | // only the sltu instruction but no sgeu. |
| 3641 | __ Xori(dst, dst, 1); |
| 3642 | } |
| 3643 | break; |
| 3644 | |
| 3645 | case kCondBE: |
| 3646 | case kCondA: |
| 3647 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 3648 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3649 | // Note that this only works if rhs + 1 does not overflow |
| 3650 | // to 0, hence the check above. |
| 3651 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3652 | // the comparison and thus lets us compare directly with |
| 3653 | // unsigned values in the ranges [0, 0x7fff] and |
| 3654 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3655 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 3656 | if (cond == kCondA) { |
| 3657 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3658 | // only the sltiu instruction but no sgtiu. |
| 3659 | __ Xori(dst, dst, 1); |
| 3660 | } |
| 3661 | } else { |
| 3662 | if (use_imm) { |
| 3663 | rhs_reg = TMP; |
| 3664 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3665 | } |
| 3666 | __ Sltu(dst, rhs_reg, lhs); |
| 3667 | if (cond == kCondBE) { |
| 3668 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3669 | // only the sltu instruction but no sleu. |
| 3670 | __ Xori(dst, dst, 1); |
| 3671 | } |
| 3672 | } |
| 3673 | break; |
| 3674 | } |
| 3675 | } |
| 3676 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 3677 | bool InstructionCodeGeneratorMIPS64::MaterializeIntLongCompare(IfCondition cond, |
| 3678 | bool is64bit, |
| 3679 | LocationSummary* input_locations, |
| 3680 | GpuRegister dst) { |
| 3681 | GpuRegister lhs = input_locations->InAt(0).AsRegister<GpuRegister>(); |
| 3682 | Location rhs_location = input_locations->InAt(1); |
| 3683 | GpuRegister rhs_reg = ZERO; |
| 3684 | int64_t rhs_imm = 0; |
| 3685 | bool use_imm = rhs_location.IsConstant(); |
| 3686 | if (use_imm) { |
| 3687 | if (is64bit) { |
| 3688 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3689 | } else { |
| 3690 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3691 | } |
| 3692 | } else { |
| 3693 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3694 | } |
| 3695 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 3696 | |
| 3697 | switch (cond) { |
| 3698 | case kCondEQ: |
| 3699 | case kCondNE: |
| 3700 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3701 | if (is64bit) { |
| 3702 | __ Daddiu(dst, lhs, -rhs_imm); |
| 3703 | } else { |
| 3704 | __ Addiu(dst, lhs, -rhs_imm); |
| 3705 | } |
| 3706 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 3707 | __ Xori(dst, lhs, rhs_imm); |
| 3708 | } else { |
| 3709 | if (use_imm) { |
| 3710 | rhs_reg = TMP; |
| 3711 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3712 | } |
| 3713 | __ Xor(dst, lhs, rhs_reg); |
| 3714 | } |
| 3715 | return (cond == kCondEQ); |
| 3716 | |
| 3717 | case kCondLT: |
| 3718 | case kCondGE: |
| 3719 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3720 | __ Slti(dst, lhs, rhs_imm); |
| 3721 | } else { |
| 3722 | if (use_imm) { |
| 3723 | rhs_reg = TMP; |
| 3724 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3725 | } |
| 3726 | __ Slt(dst, lhs, rhs_reg); |
| 3727 | } |
| 3728 | return (cond == kCondGE); |
| 3729 | |
| 3730 | case kCondLE: |
| 3731 | case kCondGT: |
| 3732 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 3733 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3734 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 3735 | return (cond == kCondGT); |
| 3736 | } else { |
| 3737 | if (use_imm) { |
| 3738 | rhs_reg = TMP; |
| 3739 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3740 | } |
| 3741 | __ Slt(dst, rhs_reg, lhs); |
| 3742 | return (cond == kCondLE); |
| 3743 | } |
| 3744 | |
| 3745 | case kCondB: |
| 3746 | case kCondAE: |
| 3747 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3748 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3749 | // the comparison and thus lets us compare directly with |
| 3750 | // unsigned values in the ranges [0, 0x7fff] and |
| 3751 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3752 | __ Sltiu(dst, lhs, rhs_imm); |
| 3753 | } else { |
| 3754 | if (use_imm) { |
| 3755 | rhs_reg = TMP; |
| 3756 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3757 | } |
| 3758 | __ Sltu(dst, lhs, rhs_reg); |
| 3759 | } |
| 3760 | return (cond == kCondAE); |
| 3761 | |
| 3762 | case kCondBE: |
| 3763 | case kCondA: |
| 3764 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 3765 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3766 | // Note that this only works if rhs + 1 does not overflow |
| 3767 | // to 0, hence the check above. |
| 3768 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3769 | // the comparison and thus lets us compare directly with |
| 3770 | // unsigned values in the ranges [0, 0x7fff] and |
| 3771 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3772 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 3773 | return (cond == kCondA); |
| 3774 | } else { |
| 3775 | if (use_imm) { |
| 3776 | rhs_reg = TMP; |
| 3777 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3778 | } |
| 3779 | __ Sltu(dst, rhs_reg, lhs); |
| 3780 | return (cond == kCondBE); |
| 3781 | } |
| 3782 | } |
| 3783 | } |
| 3784 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3785 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond, |
| 3786 | bool is64bit, |
| 3787 | LocationSummary* locations, |
| 3788 | Mips64Label* label) { |
| 3789 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3790 | Location rhs_location = locations->InAt(1); |
| 3791 | GpuRegister rhs_reg = ZERO; |
| 3792 | int64_t rhs_imm = 0; |
| 3793 | bool use_imm = rhs_location.IsConstant(); |
| 3794 | if (use_imm) { |
| 3795 | if (is64bit) { |
| 3796 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3797 | } else { |
| 3798 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3799 | } |
| 3800 | } else { |
| 3801 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3802 | } |
| 3803 | |
| 3804 | if (use_imm && rhs_imm == 0) { |
| 3805 | switch (cond) { |
| 3806 | case kCondEQ: |
| 3807 | case kCondBE: // <= 0 if zero |
| 3808 | __ Beqzc(lhs, label); |
| 3809 | break; |
| 3810 | case kCondNE: |
| 3811 | case kCondA: // > 0 if non-zero |
| 3812 | __ Bnezc(lhs, label); |
| 3813 | break; |
| 3814 | case kCondLT: |
| 3815 | __ Bltzc(lhs, label); |
| 3816 | break; |
| 3817 | case kCondGE: |
| 3818 | __ Bgezc(lhs, label); |
| 3819 | break; |
| 3820 | case kCondLE: |
| 3821 | __ Blezc(lhs, label); |
| 3822 | break; |
| 3823 | case kCondGT: |
| 3824 | __ Bgtzc(lhs, label); |
| 3825 | break; |
| 3826 | case kCondB: // always false |
| 3827 | break; |
| 3828 | case kCondAE: // always true |
| 3829 | __ Bc(label); |
| 3830 | break; |
| 3831 | } |
| 3832 | } else { |
| 3833 | if (use_imm) { |
| 3834 | rhs_reg = TMP; |
| 3835 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3836 | } |
| 3837 | switch (cond) { |
| 3838 | case kCondEQ: |
| 3839 | __ Beqc(lhs, rhs_reg, label); |
| 3840 | break; |
| 3841 | case kCondNE: |
| 3842 | __ Bnec(lhs, rhs_reg, label); |
| 3843 | break; |
| 3844 | case kCondLT: |
| 3845 | __ Bltc(lhs, rhs_reg, label); |
| 3846 | break; |
| 3847 | case kCondGE: |
| 3848 | __ Bgec(lhs, rhs_reg, label); |
| 3849 | break; |
| 3850 | case kCondLE: |
| 3851 | __ Bgec(rhs_reg, lhs, label); |
| 3852 | break; |
| 3853 | case kCondGT: |
| 3854 | __ Bltc(rhs_reg, lhs, label); |
| 3855 | break; |
| 3856 | case kCondB: |
| 3857 | __ Bltuc(lhs, rhs_reg, label); |
| 3858 | break; |
| 3859 | case kCondAE: |
| 3860 | __ Bgeuc(lhs, rhs_reg, label); |
| 3861 | break; |
| 3862 | case kCondBE: |
| 3863 | __ Bgeuc(rhs_reg, lhs, label); |
| 3864 | break; |
| 3865 | case kCondA: |
| 3866 | __ Bltuc(rhs_reg, lhs, label); |
| 3867 | break; |
| 3868 | } |
| 3869 | } |
| 3870 | } |
| 3871 | |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3872 | void InstructionCodeGeneratorMIPS64::GenerateFpCompare(IfCondition cond, |
| 3873 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3874 | DataType::Type type, |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3875 | LocationSummary* locations) { |
| 3876 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3877 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3878 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3879 | if (type == DataType::Type::kFloat32) { |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3880 | switch (cond) { |
| 3881 | case kCondEQ: |
| 3882 | __ CmpEqS(FTMP, lhs, rhs); |
| 3883 | __ Mfc1(dst, FTMP); |
| 3884 | __ Andi(dst, dst, 1); |
| 3885 | break; |
| 3886 | case kCondNE: |
| 3887 | __ CmpEqS(FTMP, lhs, rhs); |
| 3888 | __ Mfc1(dst, FTMP); |
| 3889 | __ Addiu(dst, dst, 1); |
| 3890 | break; |
| 3891 | case kCondLT: |
| 3892 | if (gt_bias) { |
| 3893 | __ CmpLtS(FTMP, lhs, rhs); |
| 3894 | } else { |
| 3895 | __ CmpUltS(FTMP, lhs, rhs); |
| 3896 | } |
| 3897 | __ Mfc1(dst, FTMP); |
| 3898 | __ Andi(dst, dst, 1); |
| 3899 | break; |
| 3900 | case kCondLE: |
| 3901 | if (gt_bias) { |
| 3902 | __ CmpLeS(FTMP, lhs, rhs); |
| 3903 | } else { |
| 3904 | __ CmpUleS(FTMP, lhs, rhs); |
| 3905 | } |
| 3906 | __ Mfc1(dst, FTMP); |
| 3907 | __ Andi(dst, dst, 1); |
| 3908 | break; |
| 3909 | case kCondGT: |
| 3910 | if (gt_bias) { |
| 3911 | __ CmpUltS(FTMP, rhs, lhs); |
| 3912 | } else { |
| 3913 | __ CmpLtS(FTMP, rhs, lhs); |
| 3914 | } |
| 3915 | __ Mfc1(dst, FTMP); |
| 3916 | __ Andi(dst, dst, 1); |
| 3917 | break; |
| 3918 | case kCondGE: |
| 3919 | if (gt_bias) { |
| 3920 | __ CmpUleS(FTMP, rhs, lhs); |
| 3921 | } else { |
| 3922 | __ CmpLeS(FTMP, rhs, lhs); |
| 3923 | } |
| 3924 | __ Mfc1(dst, FTMP); |
| 3925 | __ Andi(dst, dst, 1); |
| 3926 | break; |
| 3927 | default: |
| 3928 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3929 | UNREACHABLE(); |
| 3930 | } |
| 3931 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3932 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3933 | switch (cond) { |
| 3934 | case kCondEQ: |
| 3935 | __ CmpEqD(FTMP, lhs, rhs); |
| 3936 | __ Mfc1(dst, FTMP); |
| 3937 | __ Andi(dst, dst, 1); |
| 3938 | break; |
| 3939 | case kCondNE: |
| 3940 | __ CmpEqD(FTMP, lhs, rhs); |
| 3941 | __ Mfc1(dst, FTMP); |
| 3942 | __ Addiu(dst, dst, 1); |
| 3943 | break; |
| 3944 | case kCondLT: |
| 3945 | if (gt_bias) { |
| 3946 | __ CmpLtD(FTMP, lhs, rhs); |
| 3947 | } else { |
| 3948 | __ CmpUltD(FTMP, lhs, rhs); |
| 3949 | } |
| 3950 | __ Mfc1(dst, FTMP); |
| 3951 | __ Andi(dst, dst, 1); |
| 3952 | break; |
| 3953 | case kCondLE: |
| 3954 | if (gt_bias) { |
| 3955 | __ CmpLeD(FTMP, lhs, rhs); |
| 3956 | } else { |
| 3957 | __ CmpUleD(FTMP, lhs, rhs); |
| 3958 | } |
| 3959 | __ Mfc1(dst, FTMP); |
| 3960 | __ Andi(dst, dst, 1); |
| 3961 | break; |
| 3962 | case kCondGT: |
| 3963 | if (gt_bias) { |
| 3964 | __ CmpUltD(FTMP, rhs, lhs); |
| 3965 | } else { |
| 3966 | __ CmpLtD(FTMP, rhs, lhs); |
| 3967 | } |
| 3968 | __ Mfc1(dst, FTMP); |
| 3969 | __ Andi(dst, dst, 1); |
| 3970 | break; |
| 3971 | case kCondGE: |
| 3972 | if (gt_bias) { |
| 3973 | __ CmpUleD(FTMP, rhs, lhs); |
| 3974 | } else { |
| 3975 | __ CmpLeD(FTMP, rhs, lhs); |
| 3976 | } |
| 3977 | __ Mfc1(dst, FTMP); |
| 3978 | __ Andi(dst, dst, 1); |
| 3979 | break; |
| 3980 | default: |
| 3981 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3982 | UNREACHABLE(); |
| 3983 | } |
| 3984 | } |
| 3985 | } |
| 3986 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 3987 | bool InstructionCodeGeneratorMIPS64::MaterializeFpCompare(IfCondition cond, |
| 3988 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3989 | DataType::Type type, |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 3990 | LocationSummary* input_locations, |
| 3991 | FpuRegister dst) { |
| 3992 | FpuRegister lhs = input_locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3993 | FpuRegister rhs = input_locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3994 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 3995 | switch (cond) { |
| 3996 | case kCondEQ: |
| 3997 | __ CmpEqS(dst, lhs, rhs); |
| 3998 | return false; |
| 3999 | case kCondNE: |
| 4000 | __ CmpEqS(dst, lhs, rhs); |
| 4001 | return true; |
| 4002 | case kCondLT: |
| 4003 | if (gt_bias) { |
| 4004 | __ CmpLtS(dst, lhs, rhs); |
| 4005 | } else { |
| 4006 | __ CmpUltS(dst, lhs, rhs); |
| 4007 | } |
| 4008 | return false; |
| 4009 | case kCondLE: |
| 4010 | if (gt_bias) { |
| 4011 | __ CmpLeS(dst, lhs, rhs); |
| 4012 | } else { |
| 4013 | __ CmpUleS(dst, lhs, rhs); |
| 4014 | } |
| 4015 | return false; |
| 4016 | case kCondGT: |
| 4017 | if (gt_bias) { |
| 4018 | __ CmpUltS(dst, rhs, lhs); |
| 4019 | } else { |
| 4020 | __ CmpLtS(dst, rhs, lhs); |
| 4021 | } |
| 4022 | return false; |
| 4023 | case kCondGE: |
| 4024 | if (gt_bias) { |
| 4025 | __ CmpUleS(dst, rhs, lhs); |
| 4026 | } else { |
| 4027 | __ CmpLeS(dst, rhs, lhs); |
| 4028 | } |
| 4029 | return false; |
| 4030 | default: |
| 4031 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4032 | UNREACHABLE(); |
| 4033 | } |
| 4034 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4035 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4036 | switch (cond) { |
| 4037 | case kCondEQ: |
| 4038 | __ CmpEqD(dst, lhs, rhs); |
| 4039 | return false; |
| 4040 | case kCondNE: |
| 4041 | __ CmpEqD(dst, lhs, rhs); |
| 4042 | return true; |
| 4043 | case kCondLT: |
| 4044 | if (gt_bias) { |
| 4045 | __ CmpLtD(dst, lhs, rhs); |
| 4046 | } else { |
| 4047 | __ CmpUltD(dst, lhs, rhs); |
| 4048 | } |
| 4049 | return false; |
| 4050 | case kCondLE: |
| 4051 | if (gt_bias) { |
| 4052 | __ CmpLeD(dst, lhs, rhs); |
| 4053 | } else { |
| 4054 | __ CmpUleD(dst, lhs, rhs); |
| 4055 | } |
| 4056 | return false; |
| 4057 | case kCondGT: |
| 4058 | if (gt_bias) { |
| 4059 | __ CmpUltD(dst, rhs, lhs); |
| 4060 | } else { |
| 4061 | __ CmpLtD(dst, rhs, lhs); |
| 4062 | } |
| 4063 | return false; |
| 4064 | case kCondGE: |
| 4065 | if (gt_bias) { |
| 4066 | __ CmpUleD(dst, rhs, lhs); |
| 4067 | } else { |
| 4068 | __ CmpLeD(dst, rhs, lhs); |
| 4069 | } |
| 4070 | return false; |
| 4071 | default: |
| 4072 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4073 | UNREACHABLE(); |
| 4074 | } |
| 4075 | } |
| 4076 | } |
| 4077 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4078 | void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond, |
| 4079 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4080 | DataType::Type type, |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4081 | LocationSummary* locations, |
| 4082 | Mips64Label* label) { |
| 4083 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 4084 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4085 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4086 | switch (cond) { |
| 4087 | case kCondEQ: |
| 4088 | __ CmpEqS(FTMP, lhs, rhs); |
| 4089 | __ Bc1nez(FTMP, label); |
| 4090 | break; |
| 4091 | case kCondNE: |
| 4092 | __ CmpEqS(FTMP, lhs, rhs); |
| 4093 | __ Bc1eqz(FTMP, label); |
| 4094 | break; |
| 4095 | case kCondLT: |
| 4096 | if (gt_bias) { |
| 4097 | __ CmpLtS(FTMP, lhs, rhs); |
| 4098 | } else { |
| 4099 | __ CmpUltS(FTMP, lhs, rhs); |
| 4100 | } |
| 4101 | __ Bc1nez(FTMP, label); |
| 4102 | break; |
| 4103 | case kCondLE: |
| 4104 | if (gt_bias) { |
| 4105 | __ CmpLeS(FTMP, lhs, rhs); |
| 4106 | } else { |
| 4107 | __ CmpUleS(FTMP, lhs, rhs); |
| 4108 | } |
| 4109 | __ Bc1nez(FTMP, label); |
| 4110 | break; |
| 4111 | case kCondGT: |
| 4112 | if (gt_bias) { |
| 4113 | __ CmpUltS(FTMP, rhs, lhs); |
| 4114 | } else { |
| 4115 | __ CmpLtS(FTMP, rhs, lhs); |
| 4116 | } |
| 4117 | __ Bc1nez(FTMP, label); |
| 4118 | break; |
| 4119 | case kCondGE: |
| 4120 | if (gt_bias) { |
| 4121 | __ CmpUleS(FTMP, rhs, lhs); |
| 4122 | } else { |
| 4123 | __ CmpLeS(FTMP, rhs, lhs); |
| 4124 | } |
| 4125 | __ Bc1nez(FTMP, label); |
| 4126 | break; |
| 4127 | default: |
| 4128 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4129 | UNREACHABLE(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4130 | } |
| 4131 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4132 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4133 | switch (cond) { |
| 4134 | case kCondEQ: |
| 4135 | __ CmpEqD(FTMP, lhs, rhs); |
| 4136 | __ Bc1nez(FTMP, label); |
| 4137 | break; |
| 4138 | case kCondNE: |
| 4139 | __ CmpEqD(FTMP, lhs, rhs); |
| 4140 | __ Bc1eqz(FTMP, label); |
| 4141 | break; |
| 4142 | case kCondLT: |
| 4143 | if (gt_bias) { |
| 4144 | __ CmpLtD(FTMP, lhs, rhs); |
| 4145 | } else { |
| 4146 | __ CmpUltD(FTMP, lhs, rhs); |
| 4147 | } |
| 4148 | __ Bc1nez(FTMP, label); |
| 4149 | break; |
| 4150 | case kCondLE: |
| 4151 | if (gt_bias) { |
| 4152 | __ CmpLeD(FTMP, lhs, rhs); |
| 4153 | } else { |
| 4154 | __ CmpUleD(FTMP, lhs, rhs); |
| 4155 | } |
| 4156 | __ Bc1nez(FTMP, label); |
| 4157 | break; |
| 4158 | case kCondGT: |
| 4159 | if (gt_bias) { |
| 4160 | __ CmpUltD(FTMP, rhs, lhs); |
| 4161 | } else { |
| 4162 | __ CmpLtD(FTMP, rhs, lhs); |
| 4163 | } |
| 4164 | __ Bc1nez(FTMP, label); |
| 4165 | break; |
| 4166 | case kCondGE: |
| 4167 | if (gt_bias) { |
| 4168 | __ CmpUleD(FTMP, rhs, lhs); |
| 4169 | } else { |
| 4170 | __ CmpLeD(FTMP, rhs, lhs); |
| 4171 | } |
| 4172 | __ Bc1nez(FTMP, label); |
| 4173 | break; |
| 4174 | default: |
| 4175 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4176 | UNREACHABLE(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4177 | } |
| 4178 | } |
| 4179 | } |
| 4180 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4181 | void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4182 | size_t condition_input_index, |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4183 | Mips64Label* true_target, |
| 4184 | Mips64Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4185 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4186 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4187 | if (true_target == nullptr && false_target == nullptr) { |
| 4188 | // Nothing to do. The code always falls through. |
| 4189 | return; |
| 4190 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4191 | // Constant condition, statically compared against "true" (integer value 1). |
| 4192 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4193 | if (true_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4194 | __ Bc(true_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4195 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4196 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4197 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4198 | if (false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4199 | __ Bc(false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4200 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4201 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4202 | return; |
| 4203 | } |
| 4204 | |
| 4205 | // The following code generates these patterns: |
| 4206 | // (1) true_target == nullptr && false_target != nullptr |
| 4207 | // - opposite condition true => branch to false_target |
| 4208 | // (2) true_target != nullptr && false_target == nullptr |
| 4209 | // - condition true => branch to true_target |
| 4210 | // (3) true_target != nullptr && false_target != nullptr |
| 4211 | // - condition true => branch to true_target |
| 4212 | // - branch to false_target |
| 4213 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4214 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4215 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4216 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4217 | if (true_target == nullptr) { |
| 4218 | __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target); |
| 4219 | } else { |
| 4220 | __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target); |
| 4221 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4222 | } else { |
| 4223 | // The condition instruction has not been materialized, use its inputs as |
| 4224 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4225 | HCondition* condition = cond->AsCondition(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4226 | DataType::Type type = condition->InputAt(0)->GetType(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4227 | LocationSummary* locations = cond->GetLocations(); |
| 4228 | IfCondition if_cond = condition->GetCondition(); |
| 4229 | Mips64Label* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4230 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4231 | if (true_target == nullptr) { |
| 4232 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4233 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4234 | } |
| 4235 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4236 | switch (type) { |
| 4237 | default: |
| 4238 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target); |
| 4239 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4240 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4241 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target); |
| 4242 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4243 | case DataType::Type::kFloat32: |
| 4244 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4245 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 4246 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4247 | } |
| 4248 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4249 | |
| 4250 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 4251 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 4252 | if (true_target != nullptr && false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4253 | __ Bc(false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4254 | } |
| 4255 | } |
| 4256 | |
| 4257 | void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) { |
| 4258 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4259 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4260 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4261 | } |
| 4262 | } |
| 4263 | |
| 4264 | void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4265 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 4266 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4267 | Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4268 | nullptr : codegen_->GetLabelOf(true_successor); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4269 | Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4270 | nullptr : codegen_->GetLabelOf(false_successor); |
| 4271 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 4275 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 4276 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 4277 | InvokeRuntimeCallingConvention calling_convention; |
| 4278 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4279 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4280 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4281 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4282 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4283 | } |
| 4284 | } |
| 4285 | |
| 4286 | void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 4287 | SlowPathCodeMIPS64* slow_path = |
| 4288 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4289 | GenerateTestAndBranch(deoptimize, |
| 4290 | /* condition_input_index */ 0, |
| 4291 | slow_path->GetEntryLabel(), |
| 4292 | /* false_target */ nullptr); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4293 | } |
| 4294 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4295 | // This function returns true if a conditional move can be generated for HSelect. |
| 4296 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 4297 | // branches and regular moves. |
| 4298 | // |
| 4299 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 4300 | // |
| 4301 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 4302 | // are two distinct tasks, this function does both because they share quite a bit |
| 4303 | // of common logic. |
| 4304 | static bool CanMoveConditionally(HSelect* select, LocationSummary* locations_to_set) { |
| 4305 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 4306 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4307 | HCondition* condition = cond->AsCondition(); |
| 4308 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4309 | DataType::Type cond_type = |
| 4310 | materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType(); |
| 4311 | DataType::Type dst_type = select->GetType(); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4312 | |
| 4313 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 4314 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 4315 | bool is_true_value_zero_constant = |
| 4316 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 4317 | bool is_false_value_zero_constant = |
| 4318 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 4319 | |
| 4320 | bool can_move_conditionally = false; |
| 4321 | bool use_const_for_false_in = false; |
| 4322 | bool use_const_for_true_in = false; |
| 4323 | |
| 4324 | if (!cond->IsConstant()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4325 | if (!DataType::IsFloatingPointType(cond_type)) { |
| 4326 | if (!DataType::IsFloatingPointType(dst_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4327 | // Moving int/long on int/long condition. |
| 4328 | if (is_true_value_zero_constant) { |
| 4329 | // seleqz out_reg, false_reg, cond_reg |
| 4330 | can_move_conditionally = true; |
| 4331 | use_const_for_true_in = true; |
| 4332 | } else if (is_false_value_zero_constant) { |
| 4333 | // selnez out_reg, true_reg, cond_reg |
| 4334 | can_move_conditionally = true; |
| 4335 | use_const_for_false_in = true; |
| 4336 | } else if (materialized) { |
| 4337 | // Not materializing unmaterialized int conditions |
| 4338 | // to keep the instruction count low. |
| 4339 | // selnez AT, true_reg, cond_reg |
| 4340 | // seleqz TMP, false_reg, cond_reg |
| 4341 | // or out_reg, AT, TMP |
| 4342 | can_move_conditionally = true; |
| 4343 | } |
| 4344 | } else { |
| 4345 | // Moving float/double on int/long condition. |
| 4346 | if (materialized) { |
| 4347 | // Not materializing unmaterialized int conditions |
| 4348 | // to keep the instruction count low. |
| 4349 | can_move_conditionally = true; |
| 4350 | if (is_true_value_zero_constant) { |
| 4351 | // sltu TMP, ZERO, cond_reg |
| 4352 | // mtc1 TMP, temp_cond_reg |
| 4353 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4354 | use_const_for_true_in = true; |
| 4355 | } else if (is_false_value_zero_constant) { |
| 4356 | // sltu TMP, ZERO, cond_reg |
| 4357 | // mtc1 TMP, temp_cond_reg |
| 4358 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4359 | use_const_for_false_in = true; |
| 4360 | } else { |
| 4361 | // sltu TMP, ZERO, cond_reg |
| 4362 | // mtc1 TMP, temp_cond_reg |
| 4363 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4364 | // mov.fmt out_reg, temp_cond_reg |
| 4365 | } |
| 4366 | } |
| 4367 | } |
| 4368 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4369 | if (!DataType::IsFloatingPointType(dst_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4370 | // Moving int/long on float/double condition. |
| 4371 | can_move_conditionally = true; |
| 4372 | if (is_true_value_zero_constant) { |
| 4373 | // mfc1 TMP, temp_cond_reg |
| 4374 | // seleqz out_reg, false_reg, TMP |
| 4375 | use_const_for_true_in = true; |
| 4376 | } else if (is_false_value_zero_constant) { |
| 4377 | // mfc1 TMP, temp_cond_reg |
| 4378 | // selnez out_reg, true_reg, TMP |
| 4379 | use_const_for_false_in = true; |
| 4380 | } else { |
| 4381 | // mfc1 TMP, temp_cond_reg |
| 4382 | // selnez AT, true_reg, TMP |
| 4383 | // seleqz TMP, false_reg, TMP |
| 4384 | // or out_reg, AT, TMP |
| 4385 | } |
| 4386 | } else { |
| 4387 | // Moving float/double on float/double condition. |
| 4388 | can_move_conditionally = true; |
| 4389 | if (is_true_value_zero_constant) { |
| 4390 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4391 | use_const_for_true_in = true; |
| 4392 | } else if (is_false_value_zero_constant) { |
| 4393 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4394 | use_const_for_false_in = true; |
| 4395 | } else { |
| 4396 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4397 | // mov.fmt out_reg, temp_cond_reg |
| 4398 | } |
| 4399 | } |
| 4400 | } |
| 4401 | } |
| 4402 | |
| 4403 | if (can_move_conditionally) { |
| 4404 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 4405 | } else { |
| 4406 | DCHECK(!use_const_for_false_in); |
| 4407 | DCHECK(!use_const_for_true_in); |
| 4408 | } |
| 4409 | |
| 4410 | if (locations_to_set != nullptr) { |
| 4411 | if (use_const_for_false_in) { |
| 4412 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 4413 | } else { |
| 4414 | locations_to_set->SetInAt(0, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4415 | DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4416 | ? Location::RequiresFpuRegister() |
| 4417 | : Location::RequiresRegister()); |
| 4418 | } |
| 4419 | if (use_const_for_true_in) { |
| 4420 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 4421 | } else { |
| 4422 | locations_to_set->SetInAt(1, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4423 | DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4424 | ? Location::RequiresFpuRegister() |
| 4425 | : Location::RequiresRegister()); |
| 4426 | } |
| 4427 | if (materialized) { |
| 4428 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 4429 | } |
| 4430 | |
| 4431 | if (can_move_conditionally) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4432 | locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4433 | ? Location::RequiresFpuRegister() |
| 4434 | : Location::RequiresRegister()); |
| 4435 | } else { |
| 4436 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 4437 | } |
| 4438 | } |
| 4439 | |
| 4440 | return can_move_conditionally; |
| 4441 | } |
| 4442 | |
| 4443 | |
| 4444 | void InstructionCodeGeneratorMIPS64::GenConditionalMove(HSelect* select) { |
| 4445 | LocationSummary* locations = select->GetLocations(); |
| 4446 | Location dst = locations->Out(); |
| 4447 | Location false_src = locations->InAt(0); |
| 4448 | Location true_src = locations->InAt(1); |
| 4449 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4450 | GpuRegister cond_reg = TMP; |
| 4451 | FpuRegister fcond_reg = FTMP; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4452 | DataType::Type cond_type = DataType::Type::kInt32; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4453 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4454 | DataType::Type dst_type = select->GetType(); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4455 | |
| 4456 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 4457 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<GpuRegister>(); |
| 4458 | } else { |
| 4459 | HCondition* condition = cond->AsCondition(); |
| 4460 | LocationSummary* cond_locations = cond->GetLocations(); |
| 4461 | IfCondition if_cond = condition->GetCondition(); |
| 4462 | cond_type = condition->InputAt(0)->GetType(); |
| 4463 | switch (cond_type) { |
| 4464 | default: |
| 4465 | cond_inverted = MaterializeIntLongCompare(if_cond, |
| 4466 | /* is64bit */ false, |
| 4467 | cond_locations, |
| 4468 | cond_reg); |
| 4469 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4470 | case DataType::Type::kInt64: |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4471 | cond_inverted = MaterializeIntLongCompare(if_cond, |
| 4472 | /* is64bit */ true, |
| 4473 | cond_locations, |
| 4474 | cond_reg); |
| 4475 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4476 | case DataType::Type::kFloat32: |
| 4477 | case DataType::Type::kFloat64: |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4478 | cond_inverted = MaterializeFpCompare(if_cond, |
| 4479 | condition->IsGtBias(), |
| 4480 | cond_type, |
| 4481 | cond_locations, |
| 4482 | fcond_reg); |
| 4483 | break; |
| 4484 | } |
| 4485 | } |
| 4486 | |
| 4487 | if (true_src.IsConstant()) { |
| 4488 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 4489 | } |
| 4490 | if (false_src.IsConstant()) { |
| 4491 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 4492 | } |
| 4493 | |
| 4494 | switch (dst_type) { |
| 4495 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4496 | if (DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4497 | __ Mfc1(cond_reg, fcond_reg); |
| 4498 | } |
| 4499 | if (true_src.IsConstant()) { |
| 4500 | if (cond_inverted) { |
| 4501 | __ Selnez(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4502 | } else { |
| 4503 | __ Seleqz(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4504 | } |
| 4505 | } else if (false_src.IsConstant()) { |
| 4506 | if (cond_inverted) { |
| 4507 | __ Seleqz(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4508 | } else { |
| 4509 | __ Selnez(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4510 | } |
| 4511 | } else { |
| 4512 | DCHECK_NE(cond_reg, AT); |
| 4513 | if (cond_inverted) { |
| 4514 | __ Seleqz(AT, true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4515 | __ Selnez(TMP, false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4516 | } else { |
| 4517 | __ Selnez(AT, true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4518 | __ Seleqz(TMP, false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4519 | } |
| 4520 | __ Or(dst.AsRegister<GpuRegister>(), AT, TMP); |
| 4521 | } |
| 4522 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4523 | case DataType::Type::kFloat32: { |
| 4524 | if (!DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4525 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4526 | __ Sltu(TMP, ZERO, cond_reg); |
| 4527 | __ Mtc1(TMP, fcond_reg); |
| 4528 | } |
| 4529 | FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>(); |
| 4530 | if (true_src.IsConstant()) { |
| 4531 | FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>(); |
| 4532 | if (cond_inverted) { |
| 4533 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4534 | } else { |
| 4535 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4536 | } |
| 4537 | } else if (false_src.IsConstant()) { |
| 4538 | FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>(); |
| 4539 | if (cond_inverted) { |
| 4540 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4541 | } else { |
| 4542 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4543 | } |
| 4544 | } else { |
| 4545 | if (cond_inverted) { |
| 4546 | __ SelS(fcond_reg, |
| 4547 | true_src.AsFpuRegister<FpuRegister>(), |
| 4548 | false_src.AsFpuRegister<FpuRegister>()); |
| 4549 | } else { |
| 4550 | __ SelS(fcond_reg, |
| 4551 | false_src.AsFpuRegister<FpuRegister>(), |
| 4552 | true_src.AsFpuRegister<FpuRegister>()); |
| 4553 | } |
| 4554 | __ MovS(dst_reg, fcond_reg); |
| 4555 | } |
| 4556 | break; |
| 4557 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4558 | case DataType::Type::kFloat64: { |
| 4559 | if (!DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4560 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4561 | __ Sltu(TMP, ZERO, cond_reg); |
| 4562 | __ Mtc1(TMP, fcond_reg); |
| 4563 | } |
| 4564 | FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>(); |
| 4565 | if (true_src.IsConstant()) { |
| 4566 | FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>(); |
| 4567 | if (cond_inverted) { |
| 4568 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4569 | } else { |
| 4570 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4571 | } |
| 4572 | } else if (false_src.IsConstant()) { |
| 4573 | FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>(); |
| 4574 | if (cond_inverted) { |
| 4575 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4576 | } else { |
| 4577 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4578 | } |
| 4579 | } else { |
| 4580 | if (cond_inverted) { |
| 4581 | __ SelD(fcond_reg, |
| 4582 | true_src.AsFpuRegister<FpuRegister>(), |
| 4583 | false_src.AsFpuRegister<FpuRegister>()); |
| 4584 | } else { |
| 4585 | __ SelD(fcond_reg, |
| 4586 | false_src.AsFpuRegister<FpuRegister>(), |
| 4587 | true_src.AsFpuRegister<FpuRegister>()); |
| 4588 | } |
| 4589 | __ MovD(dst_reg, fcond_reg); |
| 4590 | } |
| 4591 | break; |
| 4592 | } |
| 4593 | } |
| 4594 | } |
| 4595 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4596 | void LocationsBuilderMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 4597 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 4598 | LocationSummary(flag, LocationSummary::kNoCall); |
| 4599 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4600 | } |
| 4601 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4602 | void InstructionCodeGeneratorMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 4603 | __ LoadFromOffset(kLoadWord, |
| 4604 | flag->GetLocations()->Out().AsRegister<GpuRegister>(), |
| 4605 | SP, |
| 4606 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4607 | } |
| 4608 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4609 | void LocationsBuilderMIPS64::VisitSelect(HSelect* select) { |
| 4610 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4611 | CanMoveConditionally(select, locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4612 | } |
| 4613 | |
| 4614 | void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4615 | if (CanMoveConditionally(select, /* locations_to_set */ nullptr)) { |
| 4616 | GenConditionalMove(select); |
| 4617 | } else { |
| 4618 | LocationSummary* locations = select->GetLocations(); |
| 4619 | Mips64Label false_target; |
| 4620 | GenerateTestAndBranch(select, |
| 4621 | /* condition_input_index */ 2, |
| 4622 | /* true_target */ nullptr, |
| 4623 | &false_target); |
| 4624 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 4625 | __ Bind(&false_target); |
| 4626 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4627 | } |
| 4628 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4629 | void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 4630 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 4631 | } |
| 4632 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 4633 | void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 4634 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 4635 | } |
| 4636 | |
| 4637 | void CodeGeneratorMIPS64::GenerateNop() { |
| 4638 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4639 | } |
| 4640 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4641 | void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4642 | const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4643 | DataType::Type field_type = field_info.GetFieldType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4644 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4645 | kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4646 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4647 | instruction, |
| 4648 | object_field_get_with_read_barrier |
| 4649 | ? LocationSummary::kCallOnSlowPath |
| 4650 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 4651 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4652 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 4653 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4654 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4655 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4656 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4657 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4658 | // The output overlaps in the case of an object field get with |
| 4659 | // read barriers enabled: we do not want the move to overwrite the |
| 4660 | // object's location, as we need it to emit the read barrier. |
| 4661 | locations->SetOut(Location::RequiresRegister(), |
| 4662 | object_field_get_with_read_barrier |
| 4663 | ? Location::kOutputOverlap |
| 4664 | : Location::kNoOutputOverlap); |
| 4665 | } |
| 4666 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4667 | // We need a temporary register for the read barrier marking slow |
| 4668 | // path in CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4669 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 4670 | locations->AddTemp(Location::RequiresRegister()); |
| 4671 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4672 | } |
| 4673 | } |
| 4674 | |
| 4675 | void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction, |
| 4676 | const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4677 | DataType::Type type = field_info.GetFieldType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4678 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4679 | Location obj_loc = locations->InAt(0); |
| 4680 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 4681 | Location dst_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4682 | LoadOperandType load_type = kLoadUnsignedByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4683 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4684 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4685 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4686 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4687 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4688 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4689 | case DataType::Type::kUint8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4690 | load_type = kLoadUnsignedByte; |
| 4691 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4692 | case DataType::Type::kInt8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4693 | load_type = kLoadSignedByte; |
| 4694 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4695 | case DataType::Type::kUint16: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4696 | load_type = kLoadUnsignedHalfword; |
| 4697 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4698 | case DataType::Type::kInt16: |
| 4699 | load_type = kLoadSignedHalfword; |
| 4700 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4701 | case DataType::Type::kInt32: |
| 4702 | case DataType::Type::kFloat32: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4703 | load_type = kLoadWord; |
| 4704 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4705 | case DataType::Type::kInt64: |
| 4706 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4707 | load_type = kLoadDoubleword; |
| 4708 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4709 | case DataType::Type::kReference: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4710 | load_type = kLoadUnsignedWord; |
| 4711 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4712 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4713 | LOG(FATAL) << "Unreachable type " << type; |
| 4714 | UNREACHABLE(); |
| 4715 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4716 | if (!DataType::IsFloatingPointType(type)) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4717 | DCHECK(dst_loc.IsRegister()); |
| 4718 | GpuRegister dst = dst_loc.AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4719 | if (type == DataType::Type::kReference) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4720 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 4721 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4722 | Location temp_loc = |
| 4723 | kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4724 | // Note that a potential implicit null check is handled in this |
| 4725 | // CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier call. |
| 4726 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4727 | dst_loc, |
| 4728 | obj, |
| 4729 | offset, |
| 4730 | temp_loc, |
| 4731 | /* needs_null_check */ true); |
| 4732 | if (is_volatile) { |
| 4733 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4734 | } |
| 4735 | } else { |
| 4736 | __ LoadFromOffset(kLoadUnsignedWord, dst, obj, offset, null_checker); |
| 4737 | if (is_volatile) { |
| 4738 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4739 | } |
| 4740 | // If read barriers are enabled, emit read barriers other than |
| 4741 | // Baker's using a slow path (and also unpoison the loaded |
| 4742 | // reference, if heap poisoning is enabled). |
| 4743 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 4744 | } |
| 4745 | } else { |
| 4746 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
| 4747 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4748 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4749 | DCHECK(dst_loc.IsFpuRegister()); |
| 4750 | FpuRegister dst = dst_loc.AsFpuRegister<FpuRegister>(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4751 | __ LoadFpuFromOffset(load_type, dst, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4752 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4753 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4754 | // Memory barriers, in the case of references, are handled in the |
| 4755 | // previous switch statement. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4756 | if (is_volatile && (type != DataType::Type::kReference)) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4757 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4758 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4759 | } |
| 4760 | |
| 4761 | void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction, |
| 4762 | const FieldInfo& field_info ATTRIBUTE_UNUSED) { |
| 4763 | LocationSummary* locations = |
| 4764 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4765 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4766 | if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4767 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4768 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4769 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4770 | } |
| 4771 | } |
| 4772 | |
| 4773 | void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction, |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4774 | const FieldInfo& field_info, |
| 4775 | bool value_can_be_null) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4776 | DataType::Type type = field_info.GetFieldType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4777 | LocationSummary* locations = instruction->GetLocations(); |
| 4778 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4779 | Location value_location = locations->InAt(1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4780 | StoreOperandType store_type = kStoreByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4781 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4782 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4783 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4784 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4785 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4786 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4787 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4788 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4789 | case DataType::Type::kInt8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4790 | store_type = kStoreByte; |
| 4791 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4792 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4793 | case DataType::Type::kInt16: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4794 | store_type = kStoreHalfword; |
| 4795 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4796 | case DataType::Type::kInt32: |
| 4797 | case DataType::Type::kFloat32: |
| 4798 | case DataType::Type::kReference: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4799 | store_type = kStoreWord; |
| 4800 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4801 | case DataType::Type::kInt64: |
| 4802 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4803 | store_type = kStoreDoubleword; |
| 4804 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4805 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4806 | LOG(FATAL) << "Unreachable type " << type; |
| 4807 | UNREACHABLE(); |
| 4808 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4809 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4810 | if (is_volatile) { |
| 4811 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4812 | } |
| 4813 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4814 | if (value_location.IsConstant()) { |
| 4815 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 4816 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
| 4817 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4818 | if (!DataType::IsFloatingPointType(type)) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4819 | DCHECK(value_location.IsRegister()); |
| 4820 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
| 4821 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4822 | // Note that in the case where `value` is a null reference, |
| 4823 | // we do not enter this block, as a null reference does not |
| 4824 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4825 | DCHECK_EQ(type, DataType::Type::kReference); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4826 | __ PoisonHeapReference(TMP, src); |
| 4827 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 4828 | } else { |
| 4829 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 4830 | } |
| 4831 | } else { |
| 4832 | DCHECK(value_location.IsFpuRegister()); |
| 4833 | FpuRegister src = value_location.AsFpuRegister<FpuRegister>(); |
| 4834 | __ StoreFpuToOffset(store_type, src, obj, offset, null_checker); |
| 4835 | } |
| 4836 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4837 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4838 | if (needs_write_barrier) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4839 | DCHECK(value_location.IsRegister()); |
| 4840 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4841 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4842 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4843 | |
| 4844 | if (is_volatile) { |
| 4845 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4846 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4850 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4851 | } |
| 4852 | |
| 4853 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4854 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4855 | } |
| 4856 | |
| 4857 | void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4858 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4859 | } |
| 4860 | |
| 4861 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4862 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4863 | } |
| 4864 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4865 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadOneRegister( |
| 4866 | HInstruction* instruction, |
| 4867 | Location out, |
| 4868 | uint32_t offset, |
| 4869 | Location maybe_temp, |
| 4870 | ReadBarrierOption read_barrier_option) { |
| 4871 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 4872 | if (read_barrier_option == kWithReadBarrier) { |
| 4873 | CHECK(kEmitCompilerReadBarrier); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4874 | if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) { |
| 4875 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 4876 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4877 | if (kUseBakerReadBarrier) { |
| 4878 | // Load with fast path based Baker's read barrier. |
| 4879 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4880 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4881 | out, |
| 4882 | out_reg, |
| 4883 | offset, |
| 4884 | maybe_temp, |
| 4885 | /* needs_null_check */ false); |
| 4886 | } else { |
| 4887 | // Load with slow path based read barrier. |
| 4888 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 4889 | // in the following move operation, as we will need it for the |
| 4890 | // read barrier below. |
| 4891 | __ Move(maybe_temp.AsRegister<GpuRegister>(), out_reg); |
| 4892 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4893 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4894 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 4895 | } |
| 4896 | } else { |
| 4897 | // Plain load with no read barrier. |
| 4898 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4899 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4900 | __ MaybeUnpoisonHeapReference(out_reg); |
| 4901 | } |
| 4902 | } |
| 4903 | |
| 4904 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadTwoRegisters( |
| 4905 | HInstruction* instruction, |
| 4906 | Location out, |
| 4907 | Location obj, |
| 4908 | uint32_t offset, |
| 4909 | Location maybe_temp, |
| 4910 | ReadBarrierOption read_barrier_option) { |
| 4911 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 4912 | GpuRegister obj_reg = obj.AsRegister<GpuRegister>(); |
| 4913 | if (read_barrier_option == kWithReadBarrier) { |
| 4914 | CHECK(kEmitCompilerReadBarrier); |
| 4915 | if (kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4916 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 4917 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 4918 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4919 | // Load with fast path based Baker's read barrier. |
| 4920 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4921 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4922 | out, |
| 4923 | obj_reg, |
| 4924 | offset, |
| 4925 | maybe_temp, |
| 4926 | /* needs_null_check */ false); |
| 4927 | } else { |
| 4928 | // Load with slow path based read barrier. |
| 4929 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4930 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 4931 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 4932 | } |
| 4933 | } else { |
| 4934 | // Plain load with no read barrier. |
| 4935 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4936 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 4937 | __ MaybeUnpoisonHeapReference(out_reg); |
| 4938 | } |
| 4939 | } |
| 4940 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4941 | static inline int GetBakerMarkThunkNumber(GpuRegister reg) { |
| 4942 | static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 20, "Expecting equal"); |
| 4943 | if (reg >= V0 && reg <= T2) { // 13 consequtive regs. |
| 4944 | return reg - V0; |
| 4945 | } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs. |
| 4946 | return 13 + (reg - S2); |
| 4947 | } else if (reg == S8) { // One more. |
| 4948 | return 19; |
| 4949 | } |
| 4950 | LOG(FATAL) << "Unexpected register " << reg; |
| 4951 | UNREACHABLE(); |
| 4952 | } |
| 4953 | |
| 4954 | static inline int GetBakerMarkFieldArrayThunkDisplacement(GpuRegister reg, bool short_offset) { |
| 4955 | int num = GetBakerMarkThunkNumber(reg) + |
| 4956 | (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0); |
| 4957 | return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE; |
| 4958 | } |
| 4959 | |
| 4960 | static inline int GetBakerMarkGcRootThunkDisplacement(GpuRegister reg) { |
| 4961 | return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE + |
| 4962 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET; |
| 4963 | } |
| 4964 | |
| 4965 | void InstructionCodeGeneratorMIPS64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 4966 | Location root, |
| 4967 | GpuRegister obj, |
| 4968 | uint32_t offset, |
| 4969 | ReadBarrierOption read_barrier_option, |
| 4970 | Mips64Label* label_low) { |
| 4971 | if (label_low != nullptr) { |
| 4972 | DCHECK_EQ(offset, 0x5678u); |
| 4973 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4974 | GpuRegister root_reg = root.AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4975 | if (read_barrier_option == kWithReadBarrier) { |
| 4976 | DCHECK(kEmitCompilerReadBarrier); |
| 4977 | if (kUseBakerReadBarrier) { |
| 4978 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 4979 | // Baker's read barrier are used: |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4980 | if (kBakerReadBarrierThunksEnableForGcRoots) { |
| 4981 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 4982 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 4983 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 4984 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 4985 | // vice versa. |
| 4986 | // |
| 4987 | // We use thunks for the slow path. That thunk checks the reference |
| 4988 | // and jumps to the entrypoint if needed. |
| 4989 | // |
| 4990 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 4991 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 4992 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 4993 | // if (temp != nullptr) { |
| 4994 | // temp = &gc_root_thunk<root_reg> |
| 4995 | // root = temp(root) |
| 4996 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4997 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4998 | const int32_t entry_point_offset = |
| 4999 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5000 | const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg); |
| 5001 | int16_t offset_low = Low16Bits(offset); |
| 5002 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign |
| 5003 | // extension in lwu. |
| 5004 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 5005 | GpuRegister base = short_offset ? obj : TMP; |
| 5006 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5007 | // threads are suspended or running a checkpoint. |
| 5008 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 5009 | if (!short_offset) { |
| 5010 | DCHECK(!label_low); |
| 5011 | __ Daui(base, obj, offset_high); |
| 5012 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5013 | Mips64Label skip_call; |
| 5014 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5015 | if (label_low != nullptr) { |
| 5016 | DCHECK(short_offset); |
| 5017 | __ Bind(label_low); |
| 5018 | } |
| 5019 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5020 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, base, offset_low); // Single instruction |
| 5021 | // in delay slot. |
| 5022 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5023 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5024 | } else { |
| 5025 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5026 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 5027 | // load into `temp` (T9) the read barrier mark entry point corresponding |
| 5028 | // to register `root`. If `temp` is null, it means that `GetIsGcMarking()` |
| 5029 | // is false, and vice versa. |
| 5030 | // |
| 5031 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5032 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5033 | // if (temp != null) { |
| 5034 | // root = temp(root) |
| 5035 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5036 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5037 | if (label_low != nullptr) { |
| 5038 | __ Bind(label_low); |
| 5039 | } |
| 5040 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5041 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 5042 | static_assert( |
| 5043 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5044 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5045 | "have different sizes."); |
| 5046 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5047 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5048 | "have different sizes."); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5049 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5050 | // Slow path marking the GC root `root`. |
| 5051 | Location temp = Location::RegisterLocation(T9); |
| 5052 | SlowPathCodeMIPS64* slow_path = |
| 5053 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathMIPS64( |
| 5054 | instruction, |
| 5055 | root, |
| 5056 | /*entrypoint*/ temp); |
| 5057 | codegen_->AddSlowPath(slow_path); |
| 5058 | |
| 5059 | const int32_t entry_point_offset = |
| 5060 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(root.reg() - 1); |
| 5061 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5062 | // threads are suspended or running a checkpoint. |
| 5063 | __ LoadFromOffset(kLoadDoubleword, temp.AsRegister<GpuRegister>(), TR, entry_point_offset); |
| 5064 | __ Bnezc(temp.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 5065 | __ Bind(slow_path->GetExitLabel()); |
| 5066 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5067 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5068 | if (label_low != nullptr) { |
| 5069 | __ Bind(label_low); |
| 5070 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5071 | // GC root loaded through a slow path for read barriers other |
| 5072 | // than Baker's. |
| 5073 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 5074 | __ Daddiu64(root_reg, obj, static_cast<int32_t>(offset)); |
| 5075 | // /* mirror::Object* */ root = root->Read() |
| 5076 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5077 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5078 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5079 | if (label_low != nullptr) { |
| 5080 | __ Bind(label_low); |
| 5081 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5082 | // Plain GC root load with no read barrier. |
| 5083 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5084 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 5085 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5086 | // do not have to unpoison `root_reg` here. |
| 5087 | } |
| 5088 | } |
| 5089 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5090 | void CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5091 | Location ref, |
| 5092 | GpuRegister obj, |
| 5093 | uint32_t offset, |
| 5094 | Location temp, |
| 5095 | bool needs_null_check) { |
| 5096 | DCHECK(kEmitCompilerReadBarrier); |
| 5097 | DCHECK(kUseBakerReadBarrier); |
| 5098 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5099 | if (kBakerReadBarrierThunksEnableForFields) { |
| 5100 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5101 | // to decide whether to mark the loaded reference or not. Instead, we |
| 5102 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5103 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5104 | // vice versa. |
| 5105 | // |
| 5106 | // We use thunks for the slow path. That thunk checks the reference |
| 5107 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 5108 | // it issues a load-load memory barrier and returns to the original |
| 5109 | // reference load. |
| 5110 | // |
| 5111 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5112 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5113 | // if (temp != nullptr) { |
| 5114 | // temp = &field_array_thunk<holder_reg> |
| 5115 | // temp() |
| 5116 | // } |
| 5117 | // not_gray_return_address: |
| 5118 | // // If the offset is too large to fit into the lw instruction, we |
| 5119 | // // use an adjusted base register (TMP) here. This register |
| 5120 | // // receives bits 16 ... 31 of the offset before the thunk invocation |
| 5121 | // // and the thunk benefits from it. |
| 5122 | // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load. |
| 5123 | // gray_return_address: |
| 5124 | |
| 5125 | DCHECK(temp.IsInvalid()); |
| 5126 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 5127 | const int32_t entry_point_offset = |
| 5128 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5129 | // There may have or may have not been a null check if the field offset is smaller than |
| 5130 | // the page size. |
| 5131 | // There must've been a null check in case it's actually a load from an array. |
| 5132 | // We will, however, perform an explicit null check in the thunk as it's easier to |
| 5133 | // do it than not. |
| 5134 | if (instruction->IsArrayGet()) { |
| 5135 | DCHECK(!needs_null_check); |
| 5136 | } |
| 5137 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset); |
| 5138 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5139 | // threads are suspended or running a checkpoint. |
| 5140 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 5141 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5142 | Mips64Label skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5143 | if (short_offset) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5144 | __ Beqzc(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5145 | __ Nop(); // In forbidden slot. |
| 5146 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5147 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5148 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5149 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); // Single instruction. |
| 5150 | } else { |
| 5151 | int16_t offset_low = Low16Bits(offset); |
| 5152 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lwu. |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5153 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5154 | __ Daui(TMP, obj, offset_high); // In delay slot. |
| 5155 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5156 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5157 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5158 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset_low); // Single instruction. |
| 5159 | } |
| 5160 | if (needs_null_check) { |
| 5161 | MaybeRecordImplicitNullCheck(instruction); |
| 5162 | } |
| 5163 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5164 | return; |
| 5165 | } |
| 5166 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5167 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5168 | Location no_index = Location::NoLocation(); |
| 5169 | ScaleFactor no_scale_factor = TIMES_1; |
| 5170 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5171 | ref, |
| 5172 | obj, |
| 5173 | offset, |
| 5174 | no_index, |
| 5175 | no_scale_factor, |
| 5176 | temp, |
| 5177 | needs_null_check); |
| 5178 | } |
| 5179 | |
| 5180 | void CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5181 | Location ref, |
| 5182 | GpuRegister obj, |
| 5183 | uint32_t data_offset, |
| 5184 | Location index, |
| 5185 | Location temp, |
| 5186 | bool needs_null_check) { |
| 5187 | DCHECK(kEmitCompilerReadBarrier); |
| 5188 | DCHECK(kUseBakerReadBarrier); |
| 5189 | |
| 5190 | static_assert( |
| 5191 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5192 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5193 | ScaleFactor scale_factor = TIMES_4; |
| 5194 | |
| 5195 | if (kBakerReadBarrierThunksEnableForArrays) { |
| 5196 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5197 | // to decide whether to mark the loaded reference or not. Instead, we |
| 5198 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5199 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5200 | // vice versa. |
| 5201 | // |
| 5202 | // We use thunks for the slow path. That thunk checks the reference |
| 5203 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 5204 | // it issues a load-load memory barrier and returns to the original |
| 5205 | // reference load. |
| 5206 | // |
| 5207 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5208 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5209 | // if (temp != nullptr) { |
| 5210 | // temp = &field_array_thunk<holder_reg> |
| 5211 | // temp() |
| 5212 | // } |
| 5213 | // not_gray_return_address: |
| 5214 | // // The element address is pre-calculated in the TMP register before the |
| 5215 | // // thunk invocation and the thunk benefits from it. |
| 5216 | // HeapReference<mirror::Object> reference = data[index]; // Original reference load. |
| 5217 | // gray_return_address: |
| 5218 | |
| 5219 | DCHECK(temp.IsInvalid()); |
| 5220 | DCHECK(index.IsValid()); |
| 5221 | const int32_t entry_point_offset = |
| 5222 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5223 | // We will not do the explicit null check in the thunk as some form of a null check |
| 5224 | // must've been done earlier. |
| 5225 | DCHECK(!needs_null_check); |
| 5226 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false); |
| 5227 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5228 | // threads are suspended or running a checkpoint. |
| 5229 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5230 | Mips64Label skip_call; |
| 5231 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5232 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
| 5233 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
| 5234 | __ Dlsa(TMP, index_reg, obj, scale_factor); // In delay slot. |
| 5235 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5236 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5237 | // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor)) |
| 5238 | DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset; |
| 5239 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, data_offset); // Single instruction. |
| 5240 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5241 | return; |
| 5242 | } |
| 5243 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5244 | // /* HeapReference<Object> */ ref = |
| 5245 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5246 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5247 | ref, |
| 5248 | obj, |
| 5249 | data_offset, |
| 5250 | index, |
| 5251 | scale_factor, |
| 5252 | temp, |
| 5253 | needs_null_check); |
| 5254 | } |
| 5255 | |
| 5256 | void CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5257 | Location ref, |
| 5258 | GpuRegister obj, |
| 5259 | uint32_t offset, |
| 5260 | Location index, |
| 5261 | ScaleFactor scale_factor, |
| 5262 | Location temp, |
| 5263 | bool needs_null_check, |
| 5264 | bool always_update_field) { |
| 5265 | DCHECK(kEmitCompilerReadBarrier); |
| 5266 | DCHECK(kUseBakerReadBarrier); |
| 5267 | |
| 5268 | // In slow path based read barriers, the read barrier call is |
| 5269 | // inserted after the original load. However, in fast path based |
| 5270 | // Baker's read barriers, we need to perform the load of |
| 5271 | // mirror::Object::monitor_ *before* the original reference load. |
| 5272 | // This load-load ordering is required by the read barrier. |
| 5273 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 5274 | // |
| 5275 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 5276 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 5277 | // HeapReference<Object> ref = *src; // Original reference load. |
| 5278 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 5279 | // if (is_gray) { |
| 5280 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 5281 | // } |
| 5282 | // |
| 5283 | // Note: the original implementation in ReadBarrier::Barrier is |
| 5284 | // slightly more complex as it performs additional checks that we do |
| 5285 | // not do here for performance reasons. |
| 5286 | |
| 5287 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
| 5288 | GpuRegister temp_reg = temp.AsRegister<GpuRegister>(); |
| 5289 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 5290 | |
| 5291 | // /* int32_t */ monitor = obj->monitor_ |
| 5292 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 5293 | if (needs_null_check) { |
| 5294 | MaybeRecordImplicitNullCheck(instruction); |
| 5295 | } |
| 5296 | // /* LockWord */ lock_word = LockWord(monitor) |
| 5297 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 5298 | "art::LockWord and int32_t have different sizes."); |
| 5299 | |
| 5300 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 5301 | |
| 5302 | // The actual reference load. |
| 5303 | if (index.IsValid()) { |
| 5304 | // Load types involving an "index": ArrayGet, |
| 5305 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 5306 | // intrinsics. |
| 5307 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 5308 | if (index.IsConstant()) { |
| 5309 | size_t computed_offset = |
| 5310 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 5311 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, computed_offset); |
| 5312 | } else { |
| 5313 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 5314 | if (scale_factor == TIMES_1) { |
| 5315 | __ Daddu(TMP, index_reg, obj); |
| 5316 | } else { |
| 5317 | __ Dlsa(TMP, index_reg, obj, scale_factor); |
| 5318 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5319 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset); |
| 5320 | } |
| 5321 | } else { |
| 5322 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5323 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); |
| 5324 | } |
| 5325 | |
| 5326 | // Object* ref = ref_addr->AsMirrorPtr() |
| 5327 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5328 | |
| 5329 | // Slow path marking the object `ref` when it is gray. |
| 5330 | SlowPathCodeMIPS64* slow_path; |
| 5331 | if (always_update_field) { |
| 5332 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 only supports address |
| 5333 | // of the form `obj + field_offset`, where `obj` is a register and |
| 5334 | // `field_offset` is a register. Thus `offset` and `scale_factor` |
| 5335 | // above are expected to be null in this code path. |
| 5336 | DCHECK_EQ(offset, 0u); |
| 5337 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
| 5338 | slow_path = new (GetGraph()->GetArena()) |
| 5339 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(instruction, |
| 5340 | ref, |
| 5341 | obj, |
| 5342 | /* field_offset */ index, |
| 5343 | temp_reg); |
| 5344 | } else { |
| 5345 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathMIPS64(instruction, ref); |
| 5346 | } |
| 5347 | AddSlowPath(slow_path); |
| 5348 | |
| 5349 | // if (rb_state == ReadBarrier::GrayState()) |
| 5350 | // ref = ReadBarrier::Mark(ref); |
| 5351 | // Given the numeric representation, it's enough to check the low bit of the |
| 5352 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 5353 | // performing a branch on less than zero. |
| 5354 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 5355 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 5356 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 5357 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 5358 | __ Bltzc(temp_reg, slow_path->GetEntryLabel()); |
| 5359 | __ Bind(slow_path->GetExitLabel()); |
| 5360 | } |
| 5361 | |
| 5362 | void CodeGeneratorMIPS64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 5363 | Location out, |
| 5364 | Location ref, |
| 5365 | Location obj, |
| 5366 | uint32_t offset, |
| 5367 | Location index) { |
| 5368 | DCHECK(kEmitCompilerReadBarrier); |
| 5369 | |
| 5370 | // Insert a slow path based read barrier *after* the reference load. |
| 5371 | // |
| 5372 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5373 | // reference will be carried out by the runtime within the slow |
| 5374 | // path. |
| 5375 | // |
| 5376 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5377 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5378 | // not used by the artReadBarrierSlow entry point. |
| 5379 | // |
| 5380 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 5381 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) |
| 5382 | ReadBarrierForHeapReferenceSlowPathMIPS64(instruction, out, ref, obj, offset, index); |
| 5383 | AddSlowPath(slow_path); |
| 5384 | |
| 5385 | __ Bc(slow_path->GetEntryLabel()); |
| 5386 | __ Bind(slow_path->GetExitLabel()); |
| 5387 | } |
| 5388 | |
| 5389 | void CodeGeneratorMIPS64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 5390 | Location out, |
| 5391 | Location ref, |
| 5392 | Location obj, |
| 5393 | uint32_t offset, |
| 5394 | Location index) { |
| 5395 | if (kEmitCompilerReadBarrier) { |
| 5396 | // Baker's read barriers shall be handled by the fast path |
| 5397 | // (CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier). |
| 5398 | DCHECK(!kUseBakerReadBarrier); |
| 5399 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5400 | // by the runtime within the slow path. |
| 5401 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 5402 | } else if (kPoisonHeapReferences) { |
| 5403 | __ UnpoisonHeapReference(out.AsRegister<GpuRegister>()); |
| 5404 | } |
| 5405 | } |
| 5406 | |
| 5407 | void CodeGeneratorMIPS64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 5408 | Location out, |
| 5409 | Location root) { |
| 5410 | DCHECK(kEmitCompilerReadBarrier); |
| 5411 | |
| 5412 | // Insert a slow path based read barrier *after* the GC root load. |
| 5413 | // |
| 5414 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5415 | // not need to do anything special for this here. |
| 5416 | SlowPathCodeMIPS64* slow_path = |
| 5417 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathMIPS64(instruction, out, root); |
| 5418 | AddSlowPath(slow_path); |
| 5419 | |
| 5420 | __ Bc(slow_path->GetEntryLabel()); |
| 5421 | __ Bind(slow_path->GetExitLabel()); |
| 5422 | } |
| 5423 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5424 | void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5425 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5426 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5427 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5428 | switch (type_check_kind) { |
| 5429 | case TypeCheckKind::kExactCheck: |
| 5430 | case TypeCheckKind::kAbstractClassCheck: |
| 5431 | case TypeCheckKind::kClassHierarchyCheck: |
| 5432 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5433 | call_kind = |
| 5434 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5435 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5436 | break; |
| 5437 | case TypeCheckKind::kArrayCheck: |
| 5438 | case TypeCheckKind::kUnresolvedCheck: |
| 5439 | case TypeCheckKind::kInterfaceCheck: |
| 5440 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5441 | break; |
| 5442 | } |
| 5443 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5444 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5445 | if (baker_read_barrier_slow_path) { |
| 5446 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5447 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5448 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5449 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5450 | // The output does overlap inputs. |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5451 | // Note that TypeCheckSlowPathMIPS64 uses this register too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5452 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5453 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5454 | } |
| 5455 | |
| 5456 | void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5457 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5458 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5459 | Location obj_loc = locations->InAt(0); |
| 5460 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5461 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5462 | Location out_loc = locations->Out(); |
| 5463 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 5464 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 5465 | DCHECK_LE(num_temps, 1u); |
| 5466 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5467 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5468 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5469 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5470 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5471 | Mips64Label done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5472 | SlowPathCodeMIPS64* slow_path = nullptr; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5473 | |
| 5474 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5475 | // Avoid this check if we know `obj` is not null. |
| 5476 | if (instruction->MustDoNullCheck()) { |
| 5477 | __ Move(out, ZERO); |
| 5478 | __ Beqzc(obj, &done); |
| 5479 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5480 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5481 | switch (type_check_kind) { |
| 5482 | case TypeCheckKind::kExactCheck: { |
| 5483 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5484 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5485 | out_loc, |
| 5486 | obj_loc, |
| 5487 | class_offset, |
| 5488 | maybe_temp_loc, |
| 5489 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5490 | // Classes must be equal for the instanceof to succeed. |
| 5491 | __ Xor(out, out, cls); |
| 5492 | __ Sltiu(out, out, 1); |
| 5493 | break; |
| 5494 | } |
| 5495 | |
| 5496 | case TypeCheckKind::kAbstractClassCheck: { |
| 5497 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5498 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5499 | out_loc, |
| 5500 | obj_loc, |
| 5501 | class_offset, |
| 5502 | maybe_temp_loc, |
| 5503 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5504 | // If the class is abstract, we eagerly fetch the super class of the |
| 5505 | // object to avoid doing a comparison we know will fail. |
| 5506 | Mips64Label loop; |
| 5507 | __ Bind(&loop); |
| 5508 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5509 | GenerateReferenceLoadOneRegister(instruction, |
| 5510 | out_loc, |
| 5511 | super_offset, |
| 5512 | maybe_temp_loc, |
| 5513 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5514 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5515 | __ Beqzc(out, &done); |
| 5516 | __ Bnec(out, cls, &loop); |
| 5517 | __ LoadConst32(out, 1); |
| 5518 | break; |
| 5519 | } |
| 5520 | |
| 5521 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5522 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5523 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5524 | out_loc, |
| 5525 | obj_loc, |
| 5526 | class_offset, |
| 5527 | maybe_temp_loc, |
| 5528 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5529 | // Walk over the class hierarchy to find a match. |
| 5530 | Mips64Label loop, success; |
| 5531 | __ Bind(&loop); |
| 5532 | __ Beqc(out, cls, &success); |
| 5533 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5534 | GenerateReferenceLoadOneRegister(instruction, |
| 5535 | out_loc, |
| 5536 | super_offset, |
| 5537 | maybe_temp_loc, |
| 5538 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5539 | __ Bnezc(out, &loop); |
| 5540 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5541 | __ Bc(&done); |
| 5542 | __ Bind(&success); |
| 5543 | __ LoadConst32(out, 1); |
| 5544 | break; |
| 5545 | } |
| 5546 | |
| 5547 | case TypeCheckKind::kArrayObjectCheck: { |
| 5548 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5549 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5550 | out_loc, |
| 5551 | obj_loc, |
| 5552 | class_offset, |
| 5553 | maybe_temp_loc, |
| 5554 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5555 | // Do an exact check. |
| 5556 | Mips64Label success; |
| 5557 | __ Beqc(out, cls, &success); |
| 5558 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 5559 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5560 | GenerateReferenceLoadOneRegister(instruction, |
| 5561 | out_loc, |
| 5562 | component_offset, |
| 5563 | maybe_temp_loc, |
| 5564 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5565 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5566 | __ Beqzc(out, &done); |
| 5567 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5568 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5569 | __ Sltiu(out, out, 1); |
| 5570 | __ Bc(&done); |
| 5571 | __ Bind(&success); |
| 5572 | __ LoadConst32(out, 1); |
| 5573 | break; |
| 5574 | } |
| 5575 | |
| 5576 | case TypeCheckKind::kArrayCheck: { |
| 5577 | // No read barrier since the slow path will retry upon failure. |
| 5578 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5579 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5580 | out_loc, |
| 5581 | obj_loc, |
| 5582 | class_offset, |
| 5583 | maybe_temp_loc, |
| 5584 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5585 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5586 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction, |
| 5587 | /* is_fatal */ false); |
| 5588 | codegen_->AddSlowPath(slow_path); |
| 5589 | __ Bnec(out, cls, slow_path->GetEntryLabel()); |
| 5590 | __ LoadConst32(out, 1); |
| 5591 | break; |
| 5592 | } |
| 5593 | |
| 5594 | case TypeCheckKind::kUnresolvedCheck: |
| 5595 | case TypeCheckKind::kInterfaceCheck: { |
| 5596 | // Note that we indeed only call on slow path, but we always go |
| 5597 | // into the slow path for the unresolved and interface check |
| 5598 | // cases. |
| 5599 | // |
| 5600 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5601 | // entry point without resorting to a type checking slow path |
| 5602 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5603 | // require to assign fixed registers for the inputs of this |
| 5604 | // HInstanceOf instruction (following the runtime calling |
| 5605 | // convention), which might be cluttered by the potential first |
| 5606 | // read barrier emission at the beginning of this method. |
| 5607 | // |
| 5608 | // TODO: Introduce a new runtime entry point taking the object |
| 5609 | // to test (instead of its class) as argument, and let it deal |
| 5610 | // with the read barrier issues. This will let us refactor this |
| 5611 | // case of the `switch` code as it was previously (with a direct |
| 5612 | // call to the runtime not using a type checking slow path). |
| 5613 | // This should also be beneficial for the other cases above. |
| 5614 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5615 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction, |
| 5616 | /* is_fatal */ false); |
| 5617 | codegen_->AddSlowPath(slow_path); |
| 5618 | __ Bc(slow_path->GetEntryLabel()); |
| 5619 | break; |
| 5620 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5621 | } |
| 5622 | |
| 5623 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5624 | |
| 5625 | if (slow_path != nullptr) { |
| 5626 | __ Bind(slow_path->GetExitLabel()); |
| 5627 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5628 | } |
| 5629 | |
| 5630 | void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) { |
| 5631 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5632 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5633 | } |
| 5634 | |
| 5635 | void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 5636 | // Will be generated at use site. |
| 5637 | } |
| 5638 | |
| 5639 | void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) { |
| 5640 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5641 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5642 | } |
| 5643 | |
| 5644 | void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 5645 | // Will be generated at use site. |
| 5646 | } |
| 5647 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 5648 | void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 5649 | // The trampoline uses the same calling convention as dex calling conventions, |
| 5650 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 5651 | // the method_idx. |
| 5652 | HandleInvoke(invoke); |
| 5653 | } |
| 5654 | |
| 5655 | void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 5656 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 5657 | } |
| 5658 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5659 | void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) { |
| 5660 | InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor; |
| 5661 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 5662 | } |
| 5663 | |
| 5664 | void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5665 | HandleInvoke(invoke); |
| 5666 | // The register T0 is required to be used for the hidden argument in |
| 5667 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
| 5668 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); |
| 5669 | } |
| 5670 | |
| 5671 | void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5672 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 5673 | GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5674 | Location receiver = invoke->GetLocations()->InAt(0); |
| 5675 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5676 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5677 | |
| 5678 | // Set the hidden argument. |
| 5679 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(), |
| 5680 | invoke->GetDexMethodIndex()); |
| 5681 | |
| 5682 | // temp = object->GetClass(); |
| 5683 | if (receiver.IsStackSlot()) { |
| 5684 | __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex()); |
| 5685 | __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset); |
| 5686 | } else { |
| 5687 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset); |
| 5688 | } |
| 5689 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5690 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5691 | // emit a read barrier for the previous class reference load. |
| 5692 | // However this is not required in practice, as this is an |
| 5693 | // intermediate/temporary reference and because the current |
| 5694 | // concurrent copying collector keeps the from-space memory |
| 5695 | // intact/accessible until the end of the marking phase (the |
| 5696 | // concurrent copying collector may not in the future). |
| 5697 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5698 | __ LoadFromOffset(kLoadDoubleword, temp, temp, |
| 5699 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 5700 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5701 | invoke->GetImtIndex(), kMips64PointerSize)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5702 | // temp = temp->GetImtEntryAt(method_offset); |
| 5703 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 5704 | // T9 = temp->GetEntryPoint(); |
| 5705 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 5706 | // T9(); |
| 5707 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5708 | __ Nop(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5709 | DCHECK(!codegen_->IsLeafMethod()); |
| 5710 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5711 | } |
| 5712 | |
| 5713 | void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5714 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 5715 | if (intrinsic.TryDispatch(invoke)) { |
| 5716 | return; |
| 5717 | } |
| 5718 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5719 | HandleInvoke(invoke); |
| 5720 | } |
| 5721 | |
| 5722 | void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5723 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5724 | // art::PrepareForRegisterAllocation. |
| 5725 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5726 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5727 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 5728 | if (intrinsic.TryDispatch(invoke)) { |
| 5729 | return; |
| 5730 | } |
| 5731 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5732 | HandleInvoke(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5733 | } |
| 5734 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 5735 | void LocationsBuilderMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5736 | HandleInvoke(invoke); |
| 5737 | } |
| 5738 | |
| 5739 | void InstructionCodeGeneratorMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5740 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 5741 | } |
| 5742 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5743 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5744 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5745 | IntrinsicCodeGeneratorMIPS64 intrinsic(codegen); |
| 5746 | intrinsic.Dispatch(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5747 | return true; |
| 5748 | } |
| 5749 | return false; |
| 5750 | } |
| 5751 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5752 | HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind( |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5753 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5754 | bool fallback_load = false; |
| 5755 | switch (desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5756 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5757 | case HLoadString::LoadKind::kBootImageInternTable: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5758 | case HLoadString::LoadKind::kBssEntry: |
| 5759 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5760 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5761 | case HLoadString::LoadKind::kJitTableAddress: |
| 5762 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5763 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5764 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5765 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5766 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5767 | } |
| 5768 | if (fallback_load) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5769 | desired_string_load_kind = HLoadString::LoadKind::kRuntimeCall; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5770 | } |
| 5771 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5772 | } |
| 5773 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5774 | HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind( |
| 5775 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5776 | bool fallback_load = false; |
| 5777 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5778 | case HLoadClass::LoadKind::kInvalid: |
| 5779 | LOG(FATAL) << "UNREACHABLE"; |
| 5780 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5781 | case HLoadClass::LoadKind::kReferrersClass: |
| 5782 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5783 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5784 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5785 | case HLoadClass::LoadKind::kBssEntry: |
| 5786 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5787 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5788 | case HLoadClass::LoadKind::kJitTableAddress: |
| 5789 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5790 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5791 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5792 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5793 | break; |
| 5794 | } |
| 5795 | if (fallback_load) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5796 | desired_class_load_kind = HLoadClass::LoadKind::kRuntimeCall; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5797 | } |
| 5798 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5799 | } |
| 5800 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5801 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch( |
| 5802 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5803 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5804 | // On MIPS64 we support all dispatch types. |
| 5805 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5806 | } |
| 5807 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5808 | void CodeGeneratorMIPS64::GenerateStaticOrDirectCall( |
| 5809 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5810 | // 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] | 5811 | 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] | 5812 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 5813 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
| 5814 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5815 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5816 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5817 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5818 | uint32_t offset = |
| 5819 | GetThreadOffset<kMips64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5820 | __ LoadFromOffset(kLoadDoubleword, |
| 5821 | temp.AsRegister<GpuRegister>(), |
| 5822 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5823 | offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5824 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5825 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5826 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5827 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5828 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5829 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 5830 | DCHECK(GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5831 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5832 | NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5833 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 5834 | NewPcRelativeMethodPatch(invoke->GetTargetMethod(), info_high); |
| 5835 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5836 | __ Daddiu(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 5837 | break; |
| 5838 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5839 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5840 | __ LoadLiteral(temp.AsRegister<GpuRegister>(), |
| 5841 | kLoadDoubleword, |
| 5842 | DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5843 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5844 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5845 | PcRelativePatchInfo* info_high = NewMethodBssEntryPatch( |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5846 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5847 | PcRelativePatchInfo* info_low = NewMethodBssEntryPatch( |
| 5848 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high); |
| 5849 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5850 | __ Ld(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 5851 | break; |
| 5852 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5853 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 5854 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 5855 | return; // No code pointer retrieval; the runtime performs the call directly. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5856 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5857 | } |
| 5858 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5859 | switch (code_ptr_location) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5860 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5861 | __ Balc(&frame_entry_label_); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5862 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5863 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 5864 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
| 5865 | __ LoadFromOffset(kLoadDoubleword, |
| 5866 | T9, |
| 5867 | callee_method.AsRegister<GpuRegister>(), |
| 5868 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5869 | kMips64PointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5870 | // T9() |
| 5871 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5872 | __ Nop(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5873 | break; |
| 5874 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5875 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 5876 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5877 | DCHECK(!IsLeafMethod()); |
| 5878 | } |
| 5879 | |
| 5880 | void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5881 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5882 | // art::PrepareForRegisterAllocation. |
| 5883 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5884 | |
| 5885 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5886 | return; |
| 5887 | } |
| 5888 | |
| 5889 | LocationSummary* locations = invoke->GetLocations(); |
| 5890 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 5891 | locations->HasTemps() |
| 5892 | ? locations->GetTemp(0) |
| 5893 | : Location::NoLocation()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5894 | } |
| 5895 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5896 | void CodeGeneratorMIPS64::GenerateVirtualCall( |
| 5897 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5898 | // Use the calling convention instead of the location of the receiver, as |
| 5899 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5900 | // slow path, the arguments have been moved to the right place, so here we are |
| 5901 | // guaranteed that the receiver is the first register of the calling convention. |
| 5902 | InvokeDexCallingConvention calling_convention; |
| 5903 | GpuRegister receiver = calling_convention.GetRegisterAt(0); |
| 5904 | |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5905 | GpuRegister temp = temp_location.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5906 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5907 | invoke->GetVTableIndex(), kMips64PointerSize).SizeValue(); |
| 5908 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5909 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5910 | |
| 5911 | // temp = object->GetClass(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5912 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5913 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5914 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5915 | // emit a read barrier for the previous class reference load. |
| 5916 | // However this is not required in practice, as this is an |
| 5917 | // intermediate/temporary reference and because the current |
| 5918 | // concurrent copying collector keeps the from-space memory |
| 5919 | // intact/accessible until the end of the marking phase (the |
| 5920 | // concurrent copying collector may not in the future). |
| 5921 | __ MaybeUnpoisonHeapReference(temp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5922 | // temp = temp->GetMethodAt(method_offset); |
| 5923 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 5924 | // T9 = temp->GetEntryPoint(); |
| 5925 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 5926 | // T9(); |
| 5927 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5928 | __ Nop(); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5929 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5930 | } |
| 5931 | |
| 5932 | void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 5933 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5934 | return; |
| 5935 | } |
| 5936 | |
| 5937 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5938 | DCHECK(!codegen_->IsLeafMethod()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5939 | } |
| 5940 | |
| 5941 | void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5942 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5943 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5944 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5945 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 5946 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5947 | return; |
| 5948 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5949 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5950 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5951 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5952 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5953 | ? LocationSummary::kCallOnSlowPath |
| 5954 | : LocationSummary::kNoCall; |
| 5955 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5956 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 5957 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5958 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5959 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5960 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5961 | } |
| 5962 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5963 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5964 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5965 | // Rely on the type resolution or initialization and marking to save everything we need. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5966 | // Request a temp to hold the BSS entry location for the slow path. |
| 5967 | locations->AddTemp(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5968 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5969 | InvokeRuntimeCallingConvention calling_convention; |
| 5970 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5971 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5972 | } else { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5973 | // For non-Baker read barriers we have a temp-clobbering call. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5974 | } |
| 5975 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5976 | } |
| 5977 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5978 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5979 | // move. |
| 5980 | void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5981 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5982 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5983 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5984 | return; |
| 5985 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5986 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5987 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5988 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5989 | Location out_loc = locations->Out(); |
| 5990 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 5991 | GpuRegister current_method_reg = ZERO; |
| 5992 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5993 | load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5994 | current_method_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 5995 | } |
| 5996 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5997 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5998 | ? kWithoutReadBarrier |
| 5999 | : kCompilerReadBarrierOption; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6000 | bool generate_null_check = false; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6001 | CodeGeneratorMIPS64::PcRelativePatchInfo* bss_info_high = nullptr; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6002 | switch (load_kind) { |
| 6003 | case HLoadClass::LoadKind::kReferrersClass: |
| 6004 | DCHECK(!cls->CanCallRuntime()); |
| 6005 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6006 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6007 | GenerateGcRootFieldLoad(cls, |
| 6008 | out_loc, |
| 6009 | current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6010 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 6011 | read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6012 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6013 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6014 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6015 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6016 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6017 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6018 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6019 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
| 6020 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6021 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
| 6022 | break; |
| 6023 | } |
| 6024 | case HLoadClass::LoadKind::kBootImageAddress: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6025 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6026 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6027 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6028 | DCHECK_NE(address, 0u); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6029 | __ LoadLiteral(out, |
| 6030 | kLoadUnsignedWord, |
| 6031 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6032 | break; |
| 6033 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6034 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 6035 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6036 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
| 6037 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 6038 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6039 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
| 6040 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 6041 | __ Lwu(out, AT, /* placeholder */ 0x5678); |
| 6042 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 6043 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 6044 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 6045 | if (masked_hash != 0) { |
| 6046 | __ Daddiu(out, out, -masked_hash); |
| 6047 | } |
| 6048 | break; |
| 6049 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6050 | case HLoadClass::LoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6051 | bss_info_high = codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 6052 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6053 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high); |
| 6054 | constexpr bool non_baker_read_barrier = kUseReadBarrier && !kUseBakerReadBarrier; |
| 6055 | GpuRegister temp = non_baker_read_barrier |
| 6056 | ? out |
| 6057 | : locations->GetTemp(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6058 | codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, temp); |
| 6059 | GenerateGcRootFieldLoad(cls, |
| 6060 | out_loc, |
| 6061 | temp, |
| 6062 | /* placeholder */ 0x5678, |
| 6063 | read_barrier_option, |
| 6064 | &info_low->label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6065 | generate_null_check = true; |
| 6066 | break; |
| 6067 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6068 | case HLoadClass::LoadKind::kJitTableAddress: |
| 6069 | __ LoadLiteral(out, |
| 6070 | kLoadUnsignedWord, |
| 6071 | codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6072 | cls->GetTypeIndex(), |
| 6073 | cls->GetClass())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6074 | GenerateGcRootFieldLoad(cls, out_loc, out, 0, read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6075 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6076 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6077 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6078 | LOG(FATAL) << "UNREACHABLE"; |
| 6079 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6080 | } |
| 6081 | |
| 6082 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6083 | DCHECK(cls->CanCallRuntime()); |
| 6084 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6085 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck(), bss_info_high); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6086 | codegen_->AddSlowPath(slow_path); |
| 6087 | if (generate_null_check) { |
| 6088 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 6089 | } |
| 6090 | if (cls->MustGenerateClinitCheck()) { |
| 6091 | GenerateClassInitializationCheck(slow_path, out); |
| 6092 | } else { |
| 6093 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6094 | } |
| 6095 | } |
| 6096 | } |
| 6097 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6098 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6099 | return Thread::ExceptionOffset<kMips64PointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6100 | } |
| 6101 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6102 | void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) { |
| 6103 | LocationSummary* locations = |
| 6104 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6105 | locations->SetOut(Location::RequiresRegister()); |
| 6106 | } |
| 6107 | |
| 6108 | void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) { |
| 6109 | GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6110 | __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset()); |
| 6111 | } |
| 6112 | |
| 6113 | void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) { |
| 6114 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6115 | } |
| 6116 | |
| 6117 | void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6118 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6119 | } |
| 6120 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6121 | void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6122 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6123 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6124 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6125 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6126 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6127 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6128 | } else { |
| 6129 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6130 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6131 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6132 | // Rely on the pResolveString and marking to save everything we need. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6133 | // Request a temp to hold the BSS entry location for the slow path. |
| 6134 | locations->AddTemp(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6135 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6136 | InvokeRuntimeCallingConvention calling_convention; |
| 6137 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6138 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6139 | } else { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6140 | // For non-Baker read barriers we have a temp-clobbering call. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6141 | } |
| 6142 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6143 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6144 | } |
| 6145 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6146 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6147 | // move. |
| 6148 | void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6149 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6150 | LocationSummary* locations = load->GetLocations(); |
| 6151 | Location out_loc = locations->Out(); |
| 6152 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 6153 | |
| 6154 | switch (load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6155 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6156 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6157 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6158 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6159 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6160 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
| 6161 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6162 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6163 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6164 | } |
| 6165 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6166 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6167 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6168 | DCHECK_NE(address, 0u); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6169 | __ LoadLiteral(out, |
| 6170 | kLoadUnsignedWord, |
| 6171 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6172 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6173 | } |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6174 | case HLoadString::LoadKind::kBootImageInternTable: { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6175 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6176 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6177 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6178 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6179 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6180 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 6181 | __ Lwu(out, AT, /* placeholder */ 0x5678); |
| 6182 | return; |
| 6183 | } |
| 6184 | case HLoadString::LoadKind::kBssEntry: { |
| 6185 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6186 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
| 6187 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| 6188 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6189 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6190 | constexpr bool non_baker_read_barrier = kUseReadBarrier && !kUseBakerReadBarrier; |
| 6191 | GpuRegister temp = non_baker_read_barrier |
| 6192 | ? out |
| 6193 | : locations->GetTemp(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6194 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, temp); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6195 | GenerateGcRootFieldLoad(load, |
| 6196 | out_loc, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6197 | temp, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6198 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6199 | kCompilerReadBarrierOption, |
| 6200 | &info_low->label); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6201 | SlowPathCodeMIPS64* slow_path = |
| 6202 | new (GetGraph()->GetArena()) LoadStringSlowPathMIPS64(load, info_high); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6203 | codegen_->AddSlowPath(slow_path); |
| 6204 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 6205 | __ Bind(slow_path->GetExitLabel()); |
| 6206 | return; |
| 6207 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6208 | case HLoadString::LoadKind::kJitTableAddress: |
| 6209 | __ LoadLiteral(out, |
| 6210 | kLoadUnsignedWord, |
| 6211 | codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
| 6212 | load->GetStringIndex(), |
| 6213 | load->GetString())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6214 | GenerateGcRootFieldLoad(load, out_loc, out, 0, kCompilerReadBarrierOption); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6215 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6216 | default: |
| 6217 | break; |
| 6218 | } |
| 6219 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6220 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6221 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6222 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6223 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6224 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
| 6225 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6226 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6227 | } |
| 6228 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6229 | void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) { |
| 6230 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 6231 | locations->SetOut(Location::ConstantLocation(constant)); |
| 6232 | } |
| 6233 | |
| 6234 | void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 6235 | // Will be generated at use site. |
| 6236 | } |
| 6237 | |
| 6238 | void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6239 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6240 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6241 | InvokeRuntimeCallingConvention calling_convention; |
| 6242 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6243 | } |
| 6244 | |
| 6245 | void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6246 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6247 | instruction, |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6248 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6249 | if (instruction->IsEnter()) { |
| 6250 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6251 | } else { |
| 6252 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6253 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6254 | } |
| 6255 | |
| 6256 | void LocationsBuilderMIPS64::VisitMul(HMul* mul) { |
| 6257 | LocationSummary* locations = |
| 6258 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 6259 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6260 | case DataType::Type::kInt32: |
| 6261 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6262 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6263 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6264 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6265 | break; |
| 6266 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6267 | case DataType::Type::kFloat32: |
| 6268 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6269 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6270 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 6271 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6272 | break; |
| 6273 | |
| 6274 | default: |
| 6275 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 6276 | } |
| 6277 | } |
| 6278 | |
| 6279 | void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6280 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6281 | LocationSummary* locations = instruction->GetLocations(); |
| 6282 | |
| 6283 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6284 | case DataType::Type::kInt32: |
| 6285 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6286 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6287 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6288 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6289 | if (type == DataType::Type::kInt32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6290 | __ MulR6(dst, lhs, rhs); |
| 6291 | else |
| 6292 | __ Dmul(dst, lhs, rhs); |
| 6293 | break; |
| 6294 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6295 | case DataType::Type::kFloat32: |
| 6296 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6297 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6298 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 6299 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6300 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6301 | __ MulS(dst, lhs, rhs); |
| 6302 | else |
| 6303 | __ MulD(dst, lhs, rhs); |
| 6304 | break; |
| 6305 | } |
| 6306 | default: |
| 6307 | LOG(FATAL) << "Unexpected mul type " << type; |
| 6308 | } |
| 6309 | } |
| 6310 | |
| 6311 | void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) { |
| 6312 | LocationSummary* locations = |
| 6313 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 6314 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6315 | case DataType::Type::kInt32: |
| 6316 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6317 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6318 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6319 | break; |
| 6320 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6321 | case DataType::Type::kFloat32: |
| 6322 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6323 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6324 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6325 | break; |
| 6326 | |
| 6327 | default: |
| 6328 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 6329 | } |
| 6330 | } |
| 6331 | |
| 6332 | void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6333 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6334 | LocationSummary* locations = instruction->GetLocations(); |
| 6335 | |
| 6336 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6337 | case DataType::Type::kInt32: |
| 6338 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6339 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6340 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6341 | if (type == DataType::Type::kInt32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6342 | __ Subu(dst, ZERO, src); |
| 6343 | else |
| 6344 | __ Dsubu(dst, ZERO, src); |
| 6345 | break; |
| 6346 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6347 | case DataType::Type::kFloat32: |
| 6348 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6349 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6350 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6351 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6352 | __ NegS(dst, src); |
| 6353 | else |
| 6354 | __ NegD(dst, src); |
| 6355 | break; |
| 6356 | } |
| 6357 | default: |
| 6358 | LOG(FATAL) << "Unexpected neg type " << type; |
| 6359 | } |
| 6360 | } |
| 6361 | |
| 6362 | void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) { |
| 6363 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6364 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6365 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6366 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6367 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6368 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6369 | } |
| 6370 | |
| 6371 | void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6372 | // Note: if heap poisoning is enabled, the entry point takes care |
| 6373 | // of poisoning the reference. |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 6374 | QuickEntrypointEnum entrypoint = |
| 6375 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 6376 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6377 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 6378 | DCHECK(!codegen_->IsLeafMethod()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6379 | } |
| 6380 | |
| 6381 | void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) { |
| 6382 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6383 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6384 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6385 | if (instruction->IsStringAlloc()) { |
| 6386 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6387 | } else { |
| 6388 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6389 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6390 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6391 | } |
| 6392 | |
| 6393 | void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6394 | // Note: if heap poisoning is enabled, the entry point takes care |
| 6395 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6396 | if (instruction->IsStringAlloc()) { |
| 6397 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 6398 | GpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 6399 | MemberOffset code_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6400 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6401 | __ LoadFromOffset(kLoadDoubleword, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 6402 | __ LoadFromOffset(kLoadDoubleword, T9, temp, code_offset.Int32Value()); |
| 6403 | __ Jalr(T9); |
| 6404 | __ Nop(); |
| 6405 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 6406 | } else { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6407 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 6408 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6409 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6410 | } |
| 6411 | |
| 6412 | void LocationsBuilderMIPS64::VisitNot(HNot* instruction) { |
| 6413 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 6414 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6415 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6416 | } |
| 6417 | |
| 6418 | void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6419 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6420 | LocationSummary* locations = instruction->GetLocations(); |
| 6421 | |
| 6422 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6423 | case DataType::Type::kInt32: |
| 6424 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6425 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6426 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6427 | __ Nor(dst, src, ZERO); |
| 6428 | break; |
| 6429 | } |
| 6430 | |
| 6431 | default: |
| 6432 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 6433 | } |
| 6434 | } |
| 6435 | |
| 6436 | void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
| 6437 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 6438 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6439 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6440 | } |
| 6441 | |
| 6442 | void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
| 6443 | LocationSummary* locations = instruction->GetLocations(); |
| 6444 | __ Xori(locations->Out().AsRegister<GpuRegister>(), |
| 6445 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 6446 | 1); |
| 6447 | } |
| 6448 | |
| 6449 | void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6450 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 6451 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6452 | } |
| 6453 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6454 | void CodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6455 | if (CanMoveNullCheckToUser(instruction)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6456 | return; |
| 6457 | } |
| 6458 | Location obj = instruction->GetLocations()->InAt(0); |
| 6459 | |
| 6460 | __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6461 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6462 | } |
| 6463 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6464 | void CodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6465 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6466 | AddSlowPath(slow_path); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6467 | |
| 6468 | Location obj = instruction->GetLocations()->InAt(0); |
| 6469 | |
| 6470 | __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 6471 | } |
| 6472 | |
| 6473 | void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6474 | codegen_->GenerateNullCheck(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6475 | } |
| 6476 | |
| 6477 | void LocationsBuilderMIPS64::VisitOr(HOr* instruction) { |
| 6478 | HandleBinaryOp(instruction); |
| 6479 | } |
| 6480 | |
| 6481 | void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) { |
| 6482 | HandleBinaryOp(instruction); |
| 6483 | } |
| 6484 | |
| 6485 | void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6486 | LOG(FATAL) << "Unreachable"; |
| 6487 | } |
| 6488 | |
| 6489 | void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) { |
| 6490 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6491 | } |
| 6492 | |
| 6493 | void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) { |
| 6494 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 6495 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 6496 | if (location.IsStackSlot()) { |
| 6497 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6498 | } else if (location.IsDoubleStackSlot()) { |
| 6499 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6500 | } |
| 6501 | locations->SetOut(location); |
| 6502 | } |
| 6503 | |
| 6504 | void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction |
| 6505 | ATTRIBUTE_UNUSED) { |
| 6506 | // Nothing to do, the parameter is already at its location. |
| 6507 | } |
| 6508 | |
| 6509 | void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 6510 | LocationSummary* locations = |
| 6511 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6512 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6513 | } |
| 6514 | |
| 6515 | void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction |
| 6516 | ATTRIBUTE_UNUSED) { |
| 6517 | // Nothing to do, the method is already at its location. |
| 6518 | } |
| 6519 | |
| 6520 | void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) { |
| 6521 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6522 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6523 | locations->SetInAt(i, Location::Any()); |
| 6524 | } |
| 6525 | locations->SetOut(Location::Any()); |
| 6526 | } |
| 6527 | |
| 6528 | void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 6529 | LOG(FATAL) << "Unreachable"; |
| 6530 | } |
| 6531 | |
| 6532 | void LocationsBuilderMIPS64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6533 | DataType::Type type = rem->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6534 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6535 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 6536 | : LocationSummary::kNoCall; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6537 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 6538 | |
| 6539 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6540 | case DataType::Type::kInt32: |
| 6541 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6542 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 6543 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6544 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6545 | break; |
| 6546 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6547 | case DataType::Type::kFloat32: |
| 6548 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6549 | InvokeRuntimeCallingConvention calling_convention; |
| 6550 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 6551 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 6552 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 6553 | break; |
| 6554 | } |
| 6555 | |
| 6556 | default: |
| 6557 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6558 | } |
| 6559 | } |
| 6560 | |
| 6561 | void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6562 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6563 | |
| 6564 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6565 | case DataType::Type::kInt32: |
| 6566 | case DataType::Type::kInt64: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 6567 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6568 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6569 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6570 | case DataType::Type::kFloat32: |
| 6571 | case DataType::Type::kFloat64: { |
| 6572 | QuickEntrypointEnum entrypoint = |
| 6573 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6574 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6575 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6576 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 6577 | } else { |
| 6578 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 6579 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6580 | break; |
| 6581 | } |
| 6582 | default: |
| 6583 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6584 | } |
| 6585 | } |
| 6586 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6587 | void LocationsBuilderMIPS64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 6588 | constructor_fence->SetLocations(nullptr); |
| 6589 | } |
| 6590 | |
| 6591 | void InstructionCodeGeneratorMIPS64::VisitConstructorFence( |
| 6592 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 6593 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 6594 | } |
| 6595 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6596 | void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6597 | memory_barrier->SetLocations(nullptr); |
| 6598 | } |
| 6599 | |
| 6600 | void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6601 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 6602 | } |
| 6603 | |
| 6604 | void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) { |
| 6605 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6606 | DataType::Type return_type = ret->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6607 | locations->SetInAt(0, Mips64ReturnLocation(return_type)); |
| 6608 | } |
| 6609 | |
| 6610 | void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 6611 | codegen_->GenerateFrameExit(); |
| 6612 | } |
| 6613 | |
| 6614 | void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) { |
| 6615 | ret->SetLocations(nullptr); |
| 6616 | } |
| 6617 | |
| 6618 | void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 6619 | codegen_->GenerateFrameExit(); |
| 6620 | } |
| 6621 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6622 | void LocationsBuilderMIPS64::VisitRor(HRor* ror) { |
| 6623 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6624 | } |
| 6625 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6626 | void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) { |
| 6627 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6628 | } |
| 6629 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6630 | void LocationsBuilderMIPS64::VisitShl(HShl* shl) { |
| 6631 | HandleShift(shl); |
| 6632 | } |
| 6633 | |
| 6634 | void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) { |
| 6635 | HandleShift(shl); |
| 6636 | } |
| 6637 | |
| 6638 | void LocationsBuilderMIPS64::VisitShr(HShr* shr) { |
| 6639 | HandleShift(shr); |
| 6640 | } |
| 6641 | |
| 6642 | void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) { |
| 6643 | HandleShift(shr); |
| 6644 | } |
| 6645 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6646 | void LocationsBuilderMIPS64::VisitSub(HSub* instruction) { |
| 6647 | HandleBinaryOp(instruction); |
| 6648 | } |
| 6649 | |
| 6650 | void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) { |
| 6651 | HandleBinaryOp(instruction); |
| 6652 | } |
| 6653 | |
| 6654 | void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6655 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6656 | } |
| 6657 | |
| 6658 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6659 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6660 | } |
| 6661 | |
| 6662 | void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6663 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6664 | } |
| 6665 | |
| 6666 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 6667 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6668 | } |
| 6669 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6670 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet( |
| 6671 | HUnresolvedInstanceFieldGet* instruction) { |
| 6672 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6673 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6674 | instruction, instruction->GetFieldType(), calling_convention); |
| 6675 | } |
| 6676 | |
| 6677 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet( |
| 6678 | HUnresolvedInstanceFieldGet* instruction) { |
| 6679 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6680 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6681 | instruction->GetFieldType(), |
| 6682 | instruction->GetFieldIndex(), |
| 6683 | instruction->GetDexPc(), |
| 6684 | calling_convention); |
| 6685 | } |
| 6686 | |
| 6687 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet( |
| 6688 | HUnresolvedInstanceFieldSet* instruction) { |
| 6689 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6690 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6691 | instruction, instruction->GetFieldType(), calling_convention); |
| 6692 | } |
| 6693 | |
| 6694 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet( |
| 6695 | HUnresolvedInstanceFieldSet* instruction) { |
| 6696 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6697 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6698 | instruction->GetFieldType(), |
| 6699 | instruction->GetFieldIndex(), |
| 6700 | instruction->GetDexPc(), |
| 6701 | calling_convention); |
| 6702 | } |
| 6703 | |
| 6704 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet( |
| 6705 | HUnresolvedStaticFieldGet* instruction) { |
| 6706 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6707 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6708 | instruction, instruction->GetFieldType(), calling_convention); |
| 6709 | } |
| 6710 | |
| 6711 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet( |
| 6712 | HUnresolvedStaticFieldGet* instruction) { |
| 6713 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6714 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6715 | instruction->GetFieldType(), |
| 6716 | instruction->GetFieldIndex(), |
| 6717 | instruction->GetDexPc(), |
| 6718 | calling_convention); |
| 6719 | } |
| 6720 | |
| 6721 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet( |
| 6722 | HUnresolvedStaticFieldSet* instruction) { |
| 6723 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6724 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6725 | instruction, instruction->GetFieldType(), calling_convention); |
| 6726 | } |
| 6727 | |
| 6728 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet( |
| 6729 | HUnresolvedStaticFieldSet* instruction) { |
| 6730 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6731 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6732 | instruction->GetFieldType(), |
| 6733 | instruction->GetFieldIndex(), |
| 6734 | instruction->GetDexPc(), |
| 6735 | calling_convention); |
| 6736 | } |
| 6737 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6738 | void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6739 | LocationSummary* locations = |
| 6740 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 6741 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6742 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6743 | // registers in full width (since the runtime only saves/restores lower part). |
| 6744 | locations->SetCustomSlowPathCallerSaves( |
| 6745 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6746 | } |
| 6747 | |
| 6748 | void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6749 | HBasicBlock* block = instruction->GetBlock(); |
| 6750 | if (block->GetLoopInformation() != nullptr) { |
| 6751 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6752 | // The back edge will generate the suspend check. |
| 6753 | return; |
| 6754 | } |
| 6755 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6756 | // The goto will generate the suspend check. |
| 6757 | return; |
| 6758 | } |
| 6759 | GenerateSuspendCheck(instruction, nullptr); |
| 6760 | } |
| 6761 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6762 | void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) { |
| 6763 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6764 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6765 | InvokeRuntimeCallingConvention calling_convention; |
| 6766 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6767 | } |
| 6768 | |
| 6769 | void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6770 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6771 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 6772 | } |
| 6773 | |
| 6774 | void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6775 | DataType::Type input_type = conversion->GetInputType(); |
| 6776 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6777 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6778 | << input_type << " -> " << result_type; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6779 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6780 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 6781 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6782 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 6783 | } |
| 6784 | |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6785 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion); |
| 6786 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6787 | if (DataType::IsFloatingPointType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6788 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6789 | } else { |
| 6790 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6791 | } |
| 6792 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6793 | if (DataType::IsFloatingPointType(result_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6794 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6795 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6796 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6797 | } |
| 6798 | } |
| 6799 | |
| 6800 | void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
| 6801 | LocationSummary* locations = conversion->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6802 | DataType::Type result_type = conversion->GetResultType(); |
| 6803 | DataType::Type input_type = conversion->GetInputType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6804 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6805 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6806 | << input_type << " -> " << result_type; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6807 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6808 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6809 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6810 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6811 | |
| 6812 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6813 | case DataType::Type::kUint8: |
| 6814 | __ Andi(dst, src, 0xFF); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6815 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6816 | case DataType::Type::kInt8: |
| 6817 | if (input_type == DataType::Type::kInt64) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 6818 | // Type conversion from long to types narrower than int is a result of code |
| 6819 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 6820 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 6821 | __ Sll(dst, src, 0); |
| 6822 | __ Seb(dst, dst); |
| 6823 | } else { |
| 6824 | __ Seb(dst, src); |
| 6825 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6826 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6827 | case DataType::Type::kUint16: |
| 6828 | __ Andi(dst, src, 0xFFFF); |
| 6829 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6830 | case DataType::Type::kInt16: |
| 6831 | if (input_type == DataType::Type::kInt64) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 6832 | // Type conversion from long to types narrower than int is a result of code |
| 6833 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 6834 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 6835 | __ Sll(dst, src, 0); |
| 6836 | __ Seh(dst, dst); |
| 6837 | } else { |
| 6838 | __ Seh(dst, src); |
| 6839 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6840 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6841 | case DataType::Type::kInt32: |
| 6842 | case DataType::Type::kInt64: |
Goran Jakovljevic | 992bdb9 | 2016-12-28 16:21:48 +0100 | [diff] [blame] | 6843 | // Sign-extend 32-bit int into bits 32 through 63 for int-to-long and long-to-int |
| 6844 | // conversions, except when the input and output registers are the same and we are not |
| 6845 | // converting longs to shorter types. In these cases, do nothing. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6846 | if ((input_type == DataType::Type::kInt64) || (dst != src)) { |
Goran Jakovljevic | 992bdb9 | 2016-12-28 16:21:48 +0100 | [diff] [blame] | 6847 | __ Sll(dst, src, 0); |
| 6848 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6849 | break; |
| 6850 | |
| 6851 | default: |
| 6852 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 6853 | << " to " << result_type; |
| 6854 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6855 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6856 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6857 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6858 | if (input_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6859 | __ Dmtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6860 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6861 | __ Cvtsl(dst, FTMP); |
| 6862 | } else { |
| 6863 | __ Cvtdl(dst, FTMP); |
| 6864 | } |
| 6865 | } else { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6866 | __ Mtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6867 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6868 | __ Cvtsw(dst, FTMP); |
| 6869 | } else { |
| 6870 | __ Cvtdw(dst, FTMP); |
| 6871 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6872 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6873 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 6874 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6875 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6876 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6877 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6878 | if (result_type == DataType::Type::kInt64) { |
| 6879 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6880 | __ TruncLS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6881 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6882 | __ TruncLD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6883 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6884 | __ Dmfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6885 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6886 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6887 | __ TruncWS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6888 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6889 | __ TruncWD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6890 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6891 | __ Mfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6892 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6893 | } else if (DataType::IsFloatingPointType(result_type) && |
| 6894 | DataType::IsFloatingPointType(input_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6895 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6896 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6897 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6898 | __ Cvtsd(dst, src); |
| 6899 | } else { |
| 6900 | __ Cvtds(dst, src); |
| 6901 | } |
| 6902 | } else { |
| 6903 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6904 | << " to " << result_type; |
| 6905 | } |
| 6906 | } |
| 6907 | |
| 6908 | void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) { |
| 6909 | HandleShift(ushr); |
| 6910 | } |
| 6911 | |
| 6912 | void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) { |
| 6913 | HandleShift(ushr); |
| 6914 | } |
| 6915 | |
| 6916 | void LocationsBuilderMIPS64::VisitXor(HXor* instruction) { |
| 6917 | HandleBinaryOp(instruction); |
| 6918 | } |
| 6919 | |
| 6920 | void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) { |
| 6921 | HandleBinaryOp(instruction); |
| 6922 | } |
| 6923 | |
| 6924 | void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 6925 | // Nothing to do, this should be removed during prepare for register allocator. |
| 6926 | LOG(FATAL) << "Unreachable"; |
| 6927 | } |
| 6928 | |
| 6929 | void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 6930 | // Nothing to do, this should be removed during prepare for register allocator. |
| 6931 | LOG(FATAL) << "Unreachable"; |
| 6932 | } |
| 6933 | |
| 6934 | void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6935 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6936 | } |
| 6937 | |
| 6938 | void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6939 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6940 | } |
| 6941 | |
| 6942 | void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6943 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6944 | } |
| 6945 | |
| 6946 | void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6947 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6948 | } |
| 6949 | |
| 6950 | void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6951 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6952 | } |
| 6953 | |
| 6954 | void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6955 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6956 | } |
| 6957 | |
| 6958 | void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6959 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6960 | } |
| 6961 | |
| 6962 | void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6963 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6964 | } |
| 6965 | |
| 6966 | void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6967 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6968 | } |
| 6969 | |
| 6970 | void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6971 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6972 | } |
| 6973 | |
| 6974 | void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6975 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6976 | } |
| 6977 | |
| 6978 | void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6979 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6980 | } |
| 6981 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6982 | void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6983 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6984 | } |
| 6985 | |
| 6986 | void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6987 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6988 | } |
| 6989 | |
| 6990 | void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6991 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6992 | } |
| 6993 | |
| 6994 | void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6995 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6996 | } |
| 6997 | |
| 6998 | void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6999 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7000 | } |
| 7001 | |
| 7002 | void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7003 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7004 | } |
| 7005 | |
| 7006 | void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7007 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7008 | } |
| 7009 | |
| 7010 | void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7011 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7012 | } |
| 7013 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7014 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7015 | void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7016 | LocationSummary* locations = |
| 7017 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7018 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7019 | } |
| 7020 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7021 | void InstructionCodeGeneratorMIPS64::GenPackedSwitchWithCompares(GpuRegister value_reg, |
| 7022 | int32_t lower_bound, |
| 7023 | uint32_t num_entries, |
| 7024 | HBasicBlock* switch_block, |
| 7025 | HBasicBlock* default_block) { |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7026 | // Create a set of compare/jumps. |
| 7027 | GpuRegister temp_reg = TMP; |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7028 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7029 | // Jump to default if index is negative |
| 7030 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 7031 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 7032 | __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block)); |
| 7033 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7034 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7035 | // Jump to successors[0] if value == lower_bound. |
| 7036 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 7037 | int32_t last_index = 0; |
| 7038 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7039 | __ Addiu(temp_reg, temp_reg, -2); |
| 7040 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7041 | __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 7042 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7043 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 7044 | } |
| 7045 | if (num_entries - last_index == 2) { |
| 7046 | // The last missing case_value. |
| 7047 | __ Addiu(temp_reg, temp_reg, -1); |
| 7048 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7049 | } |
| 7050 | |
| 7051 | // And the default for any other value. |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7052 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 7053 | __ Bc(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7054 | } |
| 7055 | } |
| 7056 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7057 | void InstructionCodeGeneratorMIPS64::GenTableBasedPackedSwitch(GpuRegister value_reg, |
| 7058 | int32_t lower_bound, |
| 7059 | uint32_t num_entries, |
| 7060 | HBasicBlock* switch_block, |
| 7061 | HBasicBlock* default_block) { |
| 7062 | // Create a jump table. |
| 7063 | std::vector<Mips64Label*> labels(num_entries); |
| 7064 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7065 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7066 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7067 | } |
| 7068 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 7069 | |
| 7070 | // Is the value in range? |
| 7071 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 7072 | __ LoadConst32(AT, num_entries); |
| 7073 | __ Bgeuc(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 7074 | |
| 7075 | // We are in the range of the table. |
| 7076 | // Load the target address from the jump table, indexing by the value. |
| 7077 | __ LoadLabelAddress(AT, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 7078 | __ Dlsa(TMP, TMP, AT, 2); |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7079 | __ Lw(TMP, TMP, 0); |
| 7080 | // Compute the absolute target address by adding the table start address |
| 7081 | // (the table contains offsets to targets relative to its start). |
| 7082 | __ Daddu(TMP, TMP, AT); |
| 7083 | // And jump. |
| 7084 | __ Jr(TMP); |
| 7085 | __ Nop(); |
| 7086 | } |
| 7087 | |
| 7088 | void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7089 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7090 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7091 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7092 | GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 7093 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 7094 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7095 | |
| 7096 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
| 7097 | GenTableBasedPackedSwitch(value_reg, |
| 7098 | lower_bound, |
| 7099 | num_entries, |
| 7100 | switch_block, |
| 7101 | default_block); |
| 7102 | } else { |
| 7103 | GenPackedSwitchWithCompares(value_reg, |
| 7104 | lower_bound, |
| 7105 | num_entries, |
| 7106 | switch_block, |
| 7107 | default_block); |
| 7108 | } |
| 7109 | } |
| 7110 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7111 | void LocationsBuilderMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 7112 | LocationSummary* locations = |
| 7113 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7114 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7115 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7116 | } |
| 7117 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7118 | void InstructionCodeGeneratorMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 7119 | LocationSummary* locations = instruction->GetLocations(); |
| 7120 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 7121 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7122 | instruction->GetIndex(), kMips64PointerSize).SizeValue(); |
| 7123 | __ LoadFromOffset(kLoadDoubleword, |
| 7124 | locations->Out().AsRegister<GpuRegister>(), |
| 7125 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 7126 | method_offset); |
| 7127 | } else { |
| 7128 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 7129 | instruction->GetIndex(), kMips64PointerSize)); |
| 7130 | __ LoadFromOffset(kLoadDoubleword, |
| 7131 | locations->Out().AsRegister<GpuRegister>(), |
| 7132 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 7133 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 7134 | __ LoadFromOffset(kLoadDoubleword, |
| 7135 | locations->Out().AsRegister<GpuRegister>(), |
| 7136 | locations->Out().AsRegister<GpuRegister>(), |
| 7137 | method_offset); |
| 7138 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7139 | } |
| 7140 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7141 | } // namespace mips64 |
| 7142 | } // namespace art |