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" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 27 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 28 | #include "heap_poisoning.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 29 | #include "intrinsics.h" |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 30 | #include "intrinsics_mips64.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 31 | #include "linker/linker_patch.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 32 | #include "mirror/array-inl.h" |
| 33 | #include "mirror/class-inl.h" |
| 34 | #include "offsets.h" |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 35 | #include "stack_map_stream.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 36 | #include "thread.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 37 | #include "utils/assembler.h" |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 38 | #include "utils/mips64/assembler_mips64.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 39 | #include "utils/stack_checks.h" |
| 40 | |
| 41 | namespace art { |
| 42 | namespace mips64 { |
| 43 | |
| 44 | static constexpr int kCurrentMethodStackOffset = 0; |
| 45 | static constexpr GpuRegister kMethodRegisterArgument = A0; |
| 46 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 47 | // Flags controlling the use of thunks for Baker read barriers. |
| 48 | constexpr bool kBakerReadBarrierThunksEnableForFields = true; |
| 49 | constexpr bool kBakerReadBarrierThunksEnableForArrays = true; |
| 50 | constexpr bool kBakerReadBarrierThunksEnableForGcRoots = true; |
| 51 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 52 | Location Mips64ReturnLocation(DataType::Type return_type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 53 | switch (return_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 54 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 55 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 56 | case DataType::Type::kInt8: |
| 57 | case DataType::Type::kUint16: |
| 58 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 59 | case DataType::Type::kUint32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 60 | case DataType::Type::kInt32: |
| 61 | case DataType::Type::kReference: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 62 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 63 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 64 | return Location::RegisterLocation(V0); |
| 65 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 66 | case DataType::Type::kFloat32: |
| 67 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 68 | return Location::FpuRegisterLocation(F0); |
| 69 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 70 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 71 | return Location(); |
| 72 | } |
| 73 | UNREACHABLE(); |
| 74 | } |
| 75 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 76 | Location InvokeDexCallingConventionVisitorMIPS64::GetReturnLocation(DataType::Type type) const { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 77 | return Mips64ReturnLocation(type); |
| 78 | } |
| 79 | |
| 80 | Location InvokeDexCallingConventionVisitorMIPS64::GetMethodLocation() const { |
| 81 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 82 | } |
| 83 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 84 | Location InvokeDexCallingConventionVisitorMIPS64::GetNextLocation(DataType::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 85 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 86 | if (type == DataType::Type::kVoid) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 87 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 88 | } |
| 89 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 90 | if (DataType::IsFloatingPointType(type) && |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 91 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 92 | next_location = Location::FpuRegisterLocation( |
| 93 | calling_convention.GetFpuRegisterAt(float_index_++)); |
| 94 | gp_index_++; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 95 | } else if (!DataType::IsFloatingPointType(type) && |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 96 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 97 | next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index_++)); |
| 98 | float_index_++; |
| 99 | } else { |
| 100 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 101 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 102 | : Location::StackSlot(stack_offset); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 106 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 107 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 108 | return next_location; |
| 109 | } |
| 110 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 111 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 112 | return Mips64ReturnLocation(type); |
| 113 | } |
| 114 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame^] | 115 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 116 | InvokeRuntimeCallingConvention calling_convention; |
| 117 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 118 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 119 | // The reference is returned in the same register. This differs from the standard return location. |
| 120 | return caller_saves; |
| 121 | } |
| 122 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 123 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 124 | #define __ down_cast<CodeGeneratorMIPS64*>(codegen)->GetAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 125 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value() |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 126 | |
| 127 | class BoundsCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 128 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 129 | explicit BoundsCheckSlowPathMIPS64(HBoundsCheck* instruction) : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 130 | |
| 131 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 132 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 133 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 134 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 135 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 136 | // Live registers will be restored in the catch block if caught. |
| 137 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 138 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 139 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 140 | // move resolver. |
| 141 | InvokeRuntimeCallingConvention calling_convention; |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 142 | codegen->EmitParallelMoves(locations->InAt(0), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 143 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 144 | DataType::Type::kInt32, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 145 | locations->InAt(1), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 146 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 147 | DataType::Type::kInt32); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 148 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 149 | ? kQuickThrowStringBounds |
| 150 | : kQuickThrowArrayBounds; |
| 151 | mips64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 152 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 153 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 154 | } |
| 155 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 156 | bool IsFatal() const OVERRIDE { return true; } |
| 157 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 158 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS64"; } |
| 159 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 160 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 161 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS64); |
| 162 | }; |
| 163 | |
| 164 | class DivZeroCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 165 | public: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 166 | explicit DivZeroCheckSlowPathMIPS64(HDivZeroCheck* instruction) |
| 167 | : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 168 | |
| 169 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 170 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 171 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 172 | mips64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 173 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 174 | } |
| 175 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 176 | bool IsFatal() const OVERRIDE { return true; } |
| 177 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 178 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS64"; } |
| 179 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 180 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 181 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS64); |
| 182 | }; |
| 183 | |
| 184 | class LoadClassSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 185 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 186 | LoadClassSlowPathMIPS64(HLoadClass* cls, HInstruction* at) |
| 187 | : SlowPathCodeMIPS64(at), cls_(cls) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 188 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 189 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 193 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 194 | Location out = locations->Out(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 195 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 196 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 197 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| 198 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 199 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 200 | __ Bind(GetEntryLabel()); |
| 201 | SaveLiveRegisters(codegen, locations); |
| 202 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 203 | InvokeRuntimeCallingConvention calling_convention; |
| 204 | if (must_resolve_type) { |
| 205 | DCHECK(IsSameDexFile(cls_->GetDexFile(), mips64_codegen->GetGraph()->GetDexFile())); |
| 206 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 207 | __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_); |
| 208 | mips64_codegen->InvokeRuntime(kQuickInitializeType, instruction_, dex_pc, this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 209 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 210 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 211 | } else { |
| 212 | DCHECK(must_do_clinit); |
| 213 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 214 | mips64_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 215 | source, |
| 216 | cls_->GetType()); |
| 217 | } |
| 218 | if (must_do_clinit) { |
| 219 | mips64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 220 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | // Move the class to the desired location. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 224 | if (out.IsValid()) { |
| 225 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 226 | DataType::Type type = instruction_->GetType(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 227 | mips64_codegen->MoveLocation(out, |
| 228 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 229 | type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 230 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 231 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 232 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 233 | __ Bc(GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 236 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS64"; } |
| 237 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 238 | private: |
| 239 | // The class this slow path will load. |
| 240 | HLoadClass* const cls_; |
| 241 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 242 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS64); |
| 243 | }; |
| 244 | |
| 245 | class LoadStringSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 246 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 247 | explicit LoadStringSlowPathMIPS64(HLoadString* instruction) |
| 248 | : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 249 | |
| 250 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 251 | DCHECK(instruction_->IsLoadString()); |
| 252 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 253 | LocationSummary* locations = instruction_->GetLocations(); |
| 254 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 255 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 256 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 257 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 258 | __ Bind(GetEntryLabel()); |
| 259 | SaveLiveRegisters(codegen, locations); |
| 260 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 261 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 262 | mips64_codegen->InvokeRuntime(kQuickResolveString, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 263 | instruction_, |
| 264 | instruction_->GetDexPc(), |
| 265 | this); |
| 266 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 267 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 268 | DataType::Type type = instruction_->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 269 | mips64_codegen->MoveLocation(locations->Out(), |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 270 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 271 | type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 272 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 273 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 274 | __ Bc(GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 277 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS64"; } |
| 278 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 279 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 280 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS64); |
| 281 | }; |
| 282 | |
| 283 | class NullCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 284 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 285 | explicit NullCheckSlowPathMIPS64(HNullCheck* instr) : SlowPathCodeMIPS64(instr) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 286 | |
| 287 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 288 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 289 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 290 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 291 | // Live registers will be restored in the catch block if caught. |
| 292 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 293 | } |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 294 | mips64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 295 | instruction_, |
| 296 | instruction_->GetDexPc(), |
| 297 | this); |
| 298 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 299 | } |
| 300 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 301 | bool IsFatal() const OVERRIDE { return true; } |
| 302 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 303 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS64"; } |
| 304 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 305 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 306 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS64); |
| 307 | }; |
| 308 | |
| 309 | class SuspendCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 310 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 311 | SuspendCheckSlowPathMIPS64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 312 | : SlowPathCodeMIPS64(instruction), successor_(successor) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 313 | |
| 314 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 315 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 316 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 317 | __ Bind(GetEntryLabel()); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 318 | SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD. |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 319 | mips64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 320 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 321 | RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 322 | if (successor_ == nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 323 | __ Bc(GetReturnLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 324 | } else { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 325 | __ Bc(mips64_codegen->GetLabelOf(successor_)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 329 | Mips64Label* GetReturnLabel() { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 330 | DCHECK(successor_ == nullptr); |
| 331 | return &return_label_; |
| 332 | } |
| 333 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 334 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS64"; } |
| 335 | |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 336 | HBasicBlock* GetSuccessor() const { |
| 337 | return successor_; |
| 338 | } |
| 339 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 340 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 341 | // If not null, the block to branch to after the suspend check. |
| 342 | HBasicBlock* const successor_; |
| 343 | |
| 344 | // 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] | 345 | Mips64Label return_label_; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 346 | |
| 347 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS64); |
| 348 | }; |
| 349 | |
| 350 | class TypeCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 351 | public: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 352 | explicit TypeCheckSlowPathMIPS64(HInstruction* instruction, bool is_fatal) |
| 353 | : SlowPathCodeMIPS64(instruction), is_fatal_(is_fatal) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 354 | |
| 355 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 356 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 357 | |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 358 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 359 | DCHECK(instruction_->IsCheckCast() |
| 360 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 361 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 362 | |
| 363 | __ Bind(GetEntryLabel()); |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 364 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 365 | SaveLiveRegisters(codegen, locations); |
| 366 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 367 | |
| 368 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 369 | // move resolver. |
| 370 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 371 | codegen->EmitParallelMoves(locations->InAt(0), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 372 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 373 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 374 | locations->InAt(1), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 375 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 376 | DataType::Type::kReference); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 377 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 378 | mips64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 379 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 380 | DataType::Type ret_type = instruction_->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 381 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 382 | mips64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 383 | } else { |
| 384 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 385 | mips64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 386 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 389 | if (!is_fatal_) { |
| 390 | RestoreLiveRegisters(codegen, locations); |
| 391 | __ Bc(GetExitLabel()); |
| 392 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 395 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS64"; } |
| 396 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 397 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 398 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 399 | private: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 400 | const bool is_fatal_; |
| 401 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 402 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS64); |
| 403 | }; |
| 404 | |
| 405 | class DeoptimizationSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 406 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 407 | explicit DeoptimizationSlowPathMIPS64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 408 | : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 409 | |
| 410 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 411 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 412 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 413 | LocationSummary* locations = instruction_->GetLocations(); |
| 414 | SaveLiveRegisters(codegen, locations); |
| 415 | InvokeRuntimeCallingConvention calling_convention; |
| 416 | __ LoadConst32(calling_convention.GetRegisterAt(0), |
| 417 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 418 | mips64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 419 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 422 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS64"; } |
| 423 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 424 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 425 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64); |
| 426 | }; |
| 427 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 428 | class ArraySetSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 429 | public: |
| 430 | explicit ArraySetSlowPathMIPS64(HInstruction* instruction) : SlowPathCodeMIPS64(instruction) {} |
| 431 | |
| 432 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 433 | LocationSummary* locations = instruction_->GetLocations(); |
| 434 | __ Bind(GetEntryLabel()); |
| 435 | SaveLiveRegisters(codegen, locations); |
| 436 | |
| 437 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 438 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 439 | parallel_move.AddMove( |
| 440 | locations->InAt(0), |
| 441 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 442 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 443 | nullptr); |
| 444 | parallel_move.AddMove( |
| 445 | locations->InAt(1), |
| 446 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 447 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 448 | nullptr); |
| 449 | parallel_move.AddMove( |
| 450 | locations->InAt(2), |
| 451 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 452 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 453 | nullptr); |
| 454 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 455 | |
| 456 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 457 | mips64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 458 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 459 | RestoreLiveRegisters(codegen, locations); |
| 460 | __ Bc(GetExitLabel()); |
| 461 | } |
| 462 | |
| 463 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS64"; } |
| 464 | |
| 465 | private: |
| 466 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS64); |
| 467 | }; |
| 468 | |
| 469 | // Slow path marking an object reference `ref` during a read |
| 470 | // barrier. The field `obj.field` in the object `obj` holding this |
| 471 | // reference does not get updated by this slow path after marking (see |
| 472 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 below for that). |
| 473 | // |
| 474 | // This means that after the execution of this slow path, `ref` will |
| 475 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 476 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 477 | // probably still be a from-space reference (unless it gets updated by |
| 478 | // another thread, or if another thread installed another object |
| 479 | // reference (different from `ref`) in `obj.field`). |
| 480 | // |
| 481 | // If `entrypoint` is a valid location it is assumed to already be |
| 482 | // holding the entrypoint. The case where the entrypoint is passed in |
| 483 | // is for the GcRoot read barrier. |
| 484 | class ReadBarrierMarkSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 485 | public: |
| 486 | ReadBarrierMarkSlowPathMIPS64(HInstruction* instruction, |
| 487 | Location ref, |
| 488 | Location entrypoint = Location::NoLocation()) |
| 489 | : SlowPathCodeMIPS64(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 490 | DCHECK(kEmitCompilerReadBarrier); |
| 491 | } |
| 492 | |
| 493 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; } |
| 494 | |
| 495 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 496 | LocationSummary* locations = instruction_->GetLocations(); |
| 497 | GpuRegister ref_reg = ref_.AsRegister<GpuRegister>(); |
| 498 | DCHECK(locations->CanCall()); |
| 499 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 500 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 501 | instruction_->IsStaticFieldGet() || |
| 502 | instruction_->IsArrayGet() || |
| 503 | instruction_->IsArraySet() || |
| 504 | instruction_->IsLoadClass() || |
| 505 | instruction_->IsLoadString() || |
| 506 | instruction_->IsInstanceOf() || |
| 507 | instruction_->IsCheckCast() || |
| 508 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 509 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 510 | << "Unexpected instruction in read barrier marking slow path: " |
| 511 | << instruction_->DebugName(); |
| 512 | |
| 513 | __ Bind(GetEntryLabel()); |
| 514 | // No need to save live registers; it's taken care of by the |
| 515 | // entrypoint. Also, there is no need to update the stack mask, |
| 516 | // as this runtime call will not trigger a garbage collection. |
| 517 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 518 | DCHECK((V0 <= ref_reg && ref_reg <= T2) || |
| 519 | (S2 <= ref_reg && ref_reg <= S7) || |
| 520 | (ref_reg == S8)) << ref_reg; |
| 521 | // "Compact" slow path, saving two moves. |
| 522 | // |
| 523 | // Instead of using the standard runtime calling convention (input |
| 524 | // and output in A0 and V0 respectively): |
| 525 | // |
| 526 | // A0 <- ref |
| 527 | // V0 <- ReadBarrierMark(A0) |
| 528 | // ref <- V0 |
| 529 | // |
| 530 | // we just use rX (the register containing `ref`) as input and output |
| 531 | // of a dedicated entrypoint: |
| 532 | // |
| 533 | // rX <- ReadBarrierMarkRegX(rX) |
| 534 | // |
| 535 | if (entrypoint_.IsValid()) { |
| 536 | mips64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 537 | DCHECK_EQ(entrypoint_.AsRegister<GpuRegister>(), T9); |
| 538 | __ Jalr(entrypoint_.AsRegister<GpuRegister>()); |
| 539 | __ Nop(); |
| 540 | } else { |
| 541 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 542 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 543 | // This runtime call does not require a stack map. |
| 544 | mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 545 | instruction_, |
| 546 | this); |
| 547 | } |
| 548 | __ Bc(GetExitLabel()); |
| 549 | } |
| 550 | |
| 551 | private: |
| 552 | // The location (register) of the marked object reference. |
| 553 | const Location ref_; |
| 554 | |
| 555 | // The location of the entrypoint if already loaded. |
| 556 | const Location entrypoint_; |
| 557 | |
| 558 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS64); |
| 559 | }; |
| 560 | |
| 561 | // Slow path marking an object reference `ref` during a read barrier, |
| 562 | // and if needed, atomically updating the field `obj.field` in the |
| 563 | // object `obj` holding this reference after marking (contrary to |
| 564 | // ReadBarrierMarkSlowPathMIPS64 above, which never tries to update |
| 565 | // `obj.field`). |
| 566 | // |
| 567 | // This means that after the execution of this slow path, both `ref` |
| 568 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 569 | // hold the same to-space reference (unless another thread installed |
| 570 | // another object reference (different from `ref`) in `obj.field`). |
| 571 | class ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 572 | public: |
| 573 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(HInstruction* instruction, |
| 574 | Location ref, |
| 575 | GpuRegister obj, |
| 576 | Location field_offset, |
| 577 | GpuRegister temp1) |
| 578 | : SlowPathCodeMIPS64(instruction), |
| 579 | ref_(ref), |
| 580 | obj_(obj), |
| 581 | field_offset_(field_offset), |
| 582 | temp1_(temp1) { |
| 583 | DCHECK(kEmitCompilerReadBarrier); |
| 584 | } |
| 585 | |
| 586 | const char* GetDescription() const OVERRIDE { |
| 587 | return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS64"; |
| 588 | } |
| 589 | |
| 590 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 591 | LocationSummary* locations = instruction_->GetLocations(); |
| 592 | GpuRegister ref_reg = ref_.AsRegister<GpuRegister>(); |
| 593 | DCHECK(locations->CanCall()); |
| 594 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 595 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 596 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 597 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 598 | << instruction_->DebugName(); |
| 599 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 600 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 601 | DCHECK(field_offset_.IsRegister()) << field_offset_; |
| 602 | |
| 603 | __ Bind(GetEntryLabel()); |
| 604 | |
| 605 | // Save the old reference. |
| 606 | // Note that we cannot use AT or TMP to save the old reference, as those |
| 607 | // are used by the code that follows, but we need the old reference after |
| 608 | // the call to the ReadBarrierMarkRegX entry point. |
| 609 | DCHECK_NE(temp1_, AT); |
| 610 | DCHECK_NE(temp1_, TMP); |
| 611 | __ Move(temp1_, ref_reg); |
| 612 | |
| 613 | // No need to save live registers; it's taken care of by the |
| 614 | // entrypoint. Also, there is no need to update the stack mask, |
| 615 | // as this runtime call will not trigger a garbage collection. |
| 616 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 617 | DCHECK((V0 <= ref_reg && ref_reg <= T2) || |
| 618 | (S2 <= ref_reg && ref_reg <= S7) || |
| 619 | (ref_reg == S8)) << ref_reg; |
| 620 | // "Compact" slow path, saving two moves. |
| 621 | // |
| 622 | // Instead of using the standard runtime calling convention (input |
| 623 | // and output in A0 and V0 respectively): |
| 624 | // |
| 625 | // A0 <- ref |
| 626 | // V0 <- ReadBarrierMark(A0) |
| 627 | // ref <- V0 |
| 628 | // |
| 629 | // we just use rX (the register containing `ref`) as input and output |
| 630 | // of a dedicated entrypoint: |
| 631 | // |
| 632 | // rX <- ReadBarrierMarkRegX(rX) |
| 633 | // |
| 634 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 635 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 636 | // This runtime call does not require a stack map. |
| 637 | mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 638 | instruction_, |
| 639 | this); |
| 640 | |
| 641 | // If the new reference is different from the old reference, |
| 642 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 643 | // |
| 644 | // Note that this field could also hold a different object, if |
| 645 | // another thread had concurrently changed it. In that case, the |
| 646 | // the compare-and-set (CAS) loop below would abort, leaving the |
| 647 | // field as-is. |
| 648 | Mips64Label done; |
| 649 | __ Beqc(temp1_, ref_reg, &done); |
| 650 | |
| 651 | // Update the the holder's field atomically. This may fail if |
| 652 | // mutator updates before us, but it's OK. This is achieved |
| 653 | // using a strong compare-and-set (CAS) operation with relaxed |
| 654 | // memory synchronization ordering, where the expected value is |
| 655 | // the old reference and the desired value is the new reference. |
| 656 | |
| 657 | // Convenience aliases. |
| 658 | GpuRegister base = obj_; |
| 659 | GpuRegister offset = field_offset_.AsRegister<GpuRegister>(); |
| 660 | GpuRegister expected = temp1_; |
| 661 | GpuRegister value = ref_reg; |
| 662 | GpuRegister tmp_ptr = TMP; // Pointer to actual memory. |
| 663 | GpuRegister tmp = AT; // Value in memory. |
| 664 | |
| 665 | __ Daddu(tmp_ptr, base, offset); |
| 666 | |
| 667 | if (kPoisonHeapReferences) { |
| 668 | __ PoisonHeapReference(expected); |
| 669 | // Do not poison `value` if it is the same register as |
| 670 | // `expected`, which has just been poisoned. |
| 671 | if (value != expected) { |
| 672 | __ PoisonHeapReference(value); |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | // do { |
| 677 | // tmp = [r_ptr] - expected; |
| 678 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 679 | |
| 680 | Mips64Label loop_head, exit_loop; |
| 681 | __ Bind(&loop_head); |
| 682 | __ Ll(tmp, tmp_ptr); |
| 683 | // The LL instruction sign-extends the 32-bit value, but |
| 684 | // 32-bit references must be zero-extended. Zero-extend `tmp`. |
| 685 | __ Dext(tmp, tmp, 0, 32); |
| 686 | __ Bnec(tmp, expected, &exit_loop); |
| 687 | __ Move(tmp, value); |
| 688 | __ Sc(tmp, tmp_ptr); |
| 689 | __ Beqzc(tmp, &loop_head); |
| 690 | __ Bind(&exit_loop); |
| 691 | |
| 692 | if (kPoisonHeapReferences) { |
| 693 | __ UnpoisonHeapReference(expected); |
| 694 | // Do not unpoison `value` if it is the same register as |
| 695 | // `expected`, which has just been unpoisoned. |
| 696 | if (value != expected) { |
| 697 | __ UnpoisonHeapReference(value); |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | __ Bind(&done); |
| 702 | __ Bc(GetExitLabel()); |
| 703 | } |
| 704 | |
| 705 | private: |
| 706 | // The location (register) of the marked object reference. |
| 707 | const Location ref_; |
| 708 | // The register containing the object holding the marked object reference field. |
| 709 | const GpuRegister obj_; |
| 710 | // The location of the offset of the marked reference field within `obj_`. |
| 711 | Location field_offset_; |
| 712 | |
| 713 | const GpuRegister temp1_; |
| 714 | |
| 715 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS64); |
| 716 | }; |
| 717 | |
| 718 | // Slow path generating a read barrier for a heap reference. |
| 719 | class ReadBarrierForHeapReferenceSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 720 | public: |
| 721 | ReadBarrierForHeapReferenceSlowPathMIPS64(HInstruction* instruction, |
| 722 | Location out, |
| 723 | Location ref, |
| 724 | Location obj, |
| 725 | uint32_t offset, |
| 726 | Location index) |
| 727 | : SlowPathCodeMIPS64(instruction), |
| 728 | out_(out), |
| 729 | ref_(ref), |
| 730 | obj_(obj), |
| 731 | offset_(offset), |
| 732 | index_(index) { |
| 733 | DCHECK(kEmitCompilerReadBarrier); |
| 734 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 735 | // has been overwritten by (or after) the heap object reference load |
| 736 | // to be instrumented, e.g.: |
| 737 | // |
| 738 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 739 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 740 | // |
| 741 | // In that case, we have lost the information about the original |
| 742 | // object, and the emitted read barrier cannot work properly. |
| 743 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 744 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 745 | } |
| 746 | |
| 747 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 748 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 749 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 750 | DataType::Type type = DataType::Type::kReference; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 751 | GpuRegister reg_out = out_.AsRegister<GpuRegister>(); |
| 752 | DCHECK(locations->CanCall()); |
| 753 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 754 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 755 | instruction_->IsStaticFieldGet() || |
| 756 | instruction_->IsArrayGet() || |
| 757 | instruction_->IsInstanceOf() || |
| 758 | instruction_->IsCheckCast() || |
| 759 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 760 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 761 | << instruction_->DebugName(); |
| 762 | |
| 763 | __ Bind(GetEntryLabel()); |
| 764 | SaveLiveRegisters(codegen, locations); |
| 765 | |
| 766 | // We may have to change the index's value, but as `index_` is a |
| 767 | // constant member (like other "inputs" of this slow path), |
| 768 | // introduce a copy of it, `index`. |
| 769 | Location index = index_; |
| 770 | if (index_.IsValid()) { |
| 771 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 772 | if (instruction_->IsArrayGet()) { |
| 773 | // Compute the actual memory offset and store it in `index`. |
| 774 | GpuRegister index_reg = index_.AsRegister<GpuRegister>(); |
| 775 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 776 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 777 | // We are about to change the value of `index_reg` (see the |
| 778 | // calls to art::mips64::Mips64Assembler::Sll and |
| 779 | // art::mips64::MipsAssembler::Addiu32 below), but it has |
| 780 | // not been saved by the previous call to |
| 781 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 782 | // callee-save register -- |
| 783 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 784 | // callee-save registers, as it has been designed with the |
| 785 | // assumption that callee-save registers are supposed to be |
| 786 | // handled by the called function. So, as a callee-save |
| 787 | // register, `index_reg` _would_ eventually be saved onto |
| 788 | // the stack, but it would be too late: we would have |
| 789 | // changed its value earlier. Therefore, we manually save |
| 790 | // it here into another freely available register, |
| 791 | // `free_reg`, chosen of course among the caller-save |
| 792 | // registers (as a callee-save `free_reg` register would |
| 793 | // exhibit the same problem). |
| 794 | // |
| 795 | // Note we could have requested a temporary register from |
| 796 | // the register allocator instead; but we prefer not to, as |
| 797 | // this is a slow path, and we know we can find a |
| 798 | // caller-save register that is available. |
| 799 | GpuRegister free_reg = FindAvailableCallerSaveRegister(codegen); |
| 800 | __ Move(free_reg, index_reg); |
| 801 | index_reg = free_reg; |
| 802 | index = Location::RegisterLocation(index_reg); |
| 803 | } else { |
| 804 | // The initial register stored in `index_` has already been |
| 805 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 806 | // (as it is not a callee-save register), so we can freely |
| 807 | // use it. |
| 808 | } |
| 809 | // Shifting the index value contained in `index_reg` by the scale |
| 810 | // factor (2) cannot overflow in practice, as the runtime is |
| 811 | // unable to allocate object arrays with a size larger than |
| 812 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 813 | __ Sll(index_reg, index_reg, TIMES_4); |
| 814 | static_assert( |
| 815 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 816 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 817 | __ Addiu32(index_reg, index_reg, offset_); |
| 818 | } else { |
| 819 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 820 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 821 | // (as in the case of ArrayGet), as it is actually an offset |
| 822 | // to an object field within an object. |
| 823 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 824 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 825 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 826 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 827 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 828 | DCHECK_EQ(offset_, 0U); |
| 829 | DCHECK(index_.IsRegister()); |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | // We're moving two or three locations to locations that could |
| 834 | // overlap, so we need a parallel move resolver. |
| 835 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 836 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 837 | parallel_move.AddMove(ref_, |
| 838 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 839 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 840 | nullptr); |
| 841 | parallel_move.AddMove(obj_, |
| 842 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 843 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 844 | nullptr); |
| 845 | if (index.IsValid()) { |
| 846 | parallel_move.AddMove(index, |
| 847 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 848 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 849 | nullptr); |
| 850 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 851 | } else { |
| 852 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 853 | __ LoadConst32(calling_convention.GetRegisterAt(2), offset_); |
| 854 | } |
| 855 | mips64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| 856 | instruction_, |
| 857 | instruction_->GetDexPc(), |
| 858 | this); |
| 859 | CheckEntrypointTypes< |
| 860 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 861 | mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 862 | |
| 863 | RestoreLiveRegisters(codegen, locations); |
| 864 | __ Bc(GetExitLabel()); |
| 865 | } |
| 866 | |
| 867 | const char* GetDescription() const OVERRIDE { |
| 868 | return "ReadBarrierForHeapReferenceSlowPathMIPS64"; |
| 869 | } |
| 870 | |
| 871 | private: |
| 872 | GpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 873 | size_t ref = static_cast<int>(ref_.AsRegister<GpuRegister>()); |
| 874 | size_t obj = static_cast<int>(obj_.AsRegister<GpuRegister>()); |
| 875 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 876 | if (i != ref && |
| 877 | i != obj && |
| 878 | !codegen->IsCoreCalleeSaveRegister(i) && |
| 879 | !codegen->IsBlockedCoreRegister(i)) { |
| 880 | return static_cast<GpuRegister>(i); |
| 881 | } |
| 882 | } |
| 883 | // We shall never fail to find a free caller-save register, as |
| 884 | // there are more than two core caller-save registers on MIPS64 |
| 885 | // (meaning it is possible to find one which is different from |
| 886 | // `ref` and `obj`). |
| 887 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 888 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 889 | UNREACHABLE(); |
| 890 | } |
| 891 | |
| 892 | const Location out_; |
| 893 | const Location ref_; |
| 894 | const Location obj_; |
| 895 | const uint32_t offset_; |
| 896 | // An additional location containing an index to an array. |
| 897 | // Only used for HArrayGet and the UnsafeGetObject & |
| 898 | // UnsafeGetObjectVolatile intrinsics. |
| 899 | const Location index_; |
| 900 | |
| 901 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS64); |
| 902 | }; |
| 903 | |
| 904 | // Slow path generating a read barrier for a GC root. |
| 905 | class ReadBarrierForRootSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 906 | public: |
| 907 | ReadBarrierForRootSlowPathMIPS64(HInstruction* instruction, Location out, Location root) |
| 908 | : SlowPathCodeMIPS64(instruction), out_(out), root_(root) { |
| 909 | DCHECK(kEmitCompilerReadBarrier); |
| 910 | } |
| 911 | |
| 912 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 913 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 914 | DataType::Type type = DataType::Type::kReference; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 915 | GpuRegister reg_out = out_.AsRegister<GpuRegister>(); |
| 916 | DCHECK(locations->CanCall()); |
| 917 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 918 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 919 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 920 | << instruction_->DebugName(); |
| 921 | |
| 922 | __ Bind(GetEntryLabel()); |
| 923 | SaveLiveRegisters(codegen, locations); |
| 924 | |
| 925 | InvokeRuntimeCallingConvention calling_convention; |
| 926 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 927 | mips64_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 928 | root_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 929 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 930 | mips64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 931 | instruction_, |
| 932 | instruction_->GetDexPc(), |
| 933 | this); |
| 934 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 935 | mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 936 | |
| 937 | RestoreLiveRegisters(codegen, locations); |
| 938 | __ Bc(GetExitLabel()); |
| 939 | } |
| 940 | |
| 941 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS64"; } |
| 942 | |
| 943 | private: |
| 944 | const Location out_; |
| 945 | const Location root_; |
| 946 | |
| 947 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS64); |
| 948 | }; |
| 949 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 950 | CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 951 | const CompilerOptions& compiler_options, |
| 952 | OptimizingCompilerStats* stats) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 953 | : CodeGenerator(graph, |
| 954 | kNumberOfGpuRegisters, |
| 955 | kNumberOfFpuRegisters, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 956 | /* number_of_register_pairs */ 0, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 957 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 958 | arraysize(kCoreCalleeSaves)), |
| 959 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 960 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 961 | compiler_options, |
| 962 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 963 | block_labels_(nullptr), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 964 | location_builder_(graph, this), |
| 965 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 966 | move_resolver_(graph->GetAllocator(), this), |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 967 | assembler_(graph->GetAllocator(), |
| 968 | compiler_options.GetInstructionSetFeatures()->AsMips64InstructionSetFeatures()), |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 969 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 970 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 971 | uint64_literals_(std::less<uint64_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 972 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 973 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 974 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 975 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 976 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 977 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 978 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 979 | boot_image_intrinsic_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 980 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 981 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 982 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 983 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 984 | // Save RA (containing the return address) to mimic Quick. |
| 985 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 986 | } |
| 987 | |
| 988 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 989 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 990 | #define __ down_cast<Mips64Assembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 991 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value() |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 992 | |
| 993 | void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 994 | // Ensure that we fix up branches. |
| 995 | __ FinalizeCode(); |
| 996 | |
| 997 | // Adjust native pc offsets in stack maps. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 998 | StackMapStream* stack_map_stream = GetStackMapStream(); |
| 999 | for (size_t i = 0, num = stack_map_stream->GetNumberOfStackMaps(); i != num; ++i) { |
David Srbecky | d02b23f | 2018-05-29 23:27:22 +0100 | [diff] [blame] | 1000 | uint32_t old_position = stack_map_stream->GetStackMapNativePcOffset(i); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1001 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1002 | DCHECK_GE(new_position, old_position); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1003 | stack_map_stream->SetStackMapNativePcOffset(i, new_position); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | // Adjust pc offsets for the disassembly information. |
| 1007 | if (disasm_info_ != nullptr) { |
| 1008 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1009 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1010 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1011 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1012 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1013 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1014 | } |
| 1015 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1016 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1017 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1018 | } |
| 1019 | } |
| 1020 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1021 | CodeGenerator::Finalize(allocator); |
| 1022 | } |
| 1023 | |
| 1024 | Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const { |
| 1025 | return codegen_->GetAssembler(); |
| 1026 | } |
| 1027 | |
| 1028 | void ParallelMoveResolverMIPS64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1029 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1030 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1031 | } |
| 1032 | |
| 1033 | void ParallelMoveResolverMIPS64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1034 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1035 | codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1036 | } |
| 1037 | |
| 1038 | void ParallelMoveResolverMIPS64::RestoreScratch(int reg) { |
| 1039 | // Pop reg |
| 1040 | __ Ld(GpuRegister(reg), SP, 0); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1041 | __ DecreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | void ParallelMoveResolverMIPS64::SpillScratch(int reg) { |
| 1045 | // Push reg |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1046 | __ IncreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1047 | __ Sd(GpuRegister(reg), SP, 0); |
| 1048 | } |
| 1049 | |
| 1050 | void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) { |
| 1051 | LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord; |
| 1052 | StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord; |
| 1053 | // Allocate a scratch register other than TMP, if available. |
| 1054 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 1055 | // automatically unspilled when the scratch scope object is destroyed). |
| 1056 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 1057 | // 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] | 1058 | int stack_offset = ensure_scratch.IsSpilled() ? kMips64DoublewordSize : 0; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1059 | __ LoadFromOffset(load_type, |
| 1060 | GpuRegister(ensure_scratch.GetRegister()), |
| 1061 | SP, |
| 1062 | index1 + stack_offset); |
| 1063 | __ LoadFromOffset(load_type, |
| 1064 | TMP, |
| 1065 | SP, |
| 1066 | index2 + stack_offset); |
| 1067 | __ StoreToOffset(store_type, |
| 1068 | GpuRegister(ensure_scratch.GetRegister()), |
| 1069 | SP, |
| 1070 | index2 + stack_offset); |
| 1071 | __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset); |
| 1072 | } |
| 1073 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1074 | void ParallelMoveResolverMIPS64::ExchangeQuadSlots(int index1, int index2) { |
| 1075 | __ LoadFpuFromOffset(kLoadQuadword, FTMP, SP, index1); |
| 1076 | __ LoadFpuFromOffset(kLoadQuadword, FTMP2, SP, index2); |
| 1077 | __ StoreFpuToOffset(kStoreQuadword, FTMP, SP, index2); |
| 1078 | __ StoreFpuToOffset(kStoreQuadword, FTMP2, SP, index1); |
| 1079 | } |
| 1080 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1081 | static dwarf::Reg DWARFReg(GpuRegister reg) { |
| 1082 | return dwarf::Reg::Mips64Core(static_cast<int>(reg)); |
| 1083 | } |
| 1084 | |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1085 | static dwarf::Reg DWARFReg(FpuRegister reg) { |
| 1086 | return dwarf::Reg::Mips64Fp(static_cast<int>(reg)); |
| 1087 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1088 | |
| 1089 | void CodeGeneratorMIPS64::GenerateFrameEntry() { |
| 1090 | __ Bind(&frame_entry_label_); |
| 1091 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1092 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
Goran Jakovljevic | feec167 | 2018-02-08 10:20:14 +0100 | [diff] [blame] | 1093 | __ Lhu(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()); |
| 1094 | __ Addiu(TMP, TMP, 1); |
| 1095 | __ Sh(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()); |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1098 | bool do_overflow_check = |
| 1099 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips64) || !IsLeafMethod(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1100 | |
| 1101 | if (do_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1102 | __ LoadFromOffset( |
| 1103 | kLoadWord, |
| 1104 | ZERO, |
| 1105 | SP, |
| 1106 | -static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kMips64))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1107 | RecordPcInfo(nullptr, 0); |
| 1108 | } |
| 1109 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1110 | if (HasEmptyFrame()) { |
| 1111 | return; |
| 1112 | } |
| 1113 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1114 | // Make sure the frame size isn't unreasonably large. |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1115 | if (GetFrameSize() > GetStackOverflowReservedBytes(InstructionSet::kMips64)) { |
| 1116 | LOG(FATAL) << "Stack frame larger than " |
| 1117 | << GetStackOverflowReservedBytes(InstructionSet::kMips64) << " bytes"; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1118 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1119 | |
| 1120 | // Spill callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1121 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1122 | uint32_t ofs = GetFrameSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1123 | __ IncreaseFrameSize(ofs); |
| 1124 | |
| 1125 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1126 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1127 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1128 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1129 | __ StoreToOffset(kStoreDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1130 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1135 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1136 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1137 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1138 | __ StoreFpuToOffset(kStoreDoubleword, reg, SP, ofs); |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1139 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1140 | } |
| 1141 | } |
| 1142 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1143 | // Save the current method if we need it. Note that we do not |
| 1144 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1145 | // in the SSA graph. |
| 1146 | if (RequiresCurrentMethod()) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1147 | __ StoreToOffset(kStoreDoubleword, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1148 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 1149 | |
| 1150 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1151 | // Initialize should_deoptimize flag to 0. |
| 1152 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1153 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | void CodeGeneratorMIPS64::GenerateFrameExit() { |
| 1157 | __ cfi().RememberState(); |
| 1158 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1159 | if (!HasEmptyFrame()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1160 | // Restore callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1161 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1162 | // For better instruction scheduling restore RA before other registers. |
| 1163 | uint32_t ofs = GetFrameSize(); |
| 1164 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1165 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1166 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1167 | ofs -= kMips64DoublewordSize; |
| 1168 | __ LoadFromOffset(kLoadDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1169 | __ cfi().Restore(DWARFReg(reg)); |
| 1170 | } |
| 1171 | } |
| 1172 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1173 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1174 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1175 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
| 1176 | ofs -= kMips64DoublewordSize; |
| 1177 | __ LoadFpuFromOffset(kLoadDoubleword, reg, SP, ofs); |
| 1178 | __ cfi().Restore(DWARFReg(reg)); |
| 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | __ DecreaseFrameSize(GetFrameSize()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1185 | __ Jic(RA, 0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1186 | |
| 1187 | __ cfi().RestoreState(); |
| 1188 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 1189 | } |
| 1190 | |
| 1191 | void CodeGeneratorMIPS64::Bind(HBasicBlock* block) { |
| 1192 | __ Bind(GetLabelOf(block)); |
| 1193 | } |
| 1194 | |
| 1195 | void CodeGeneratorMIPS64::MoveLocation(Location destination, |
| 1196 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1197 | DataType::Type dst_type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1198 | if (source.Equals(destination)) { |
| 1199 | return; |
| 1200 | } |
| 1201 | |
| 1202 | // A valid move can always be inferred from the destination and source |
| 1203 | // locations. When moving from and to a register, the argument type can be |
| 1204 | // used to generate 32bit instead of 64bit moves. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1205 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1206 | DCHECK_EQ(unspecified_type, false); |
| 1207 | |
| 1208 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1209 | if (unspecified_type) { |
| 1210 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1211 | if (source.IsStackSlot() || |
| 1212 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1213 | || src_cst->IsFloatConstant() |
| 1214 | || src_cst->IsNullConstant()))) { |
| 1215 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1216 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1217 | } else { |
| 1218 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1219 | // type is appropriate. Else the source is a register, and since the |
| 1220 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1221 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1222 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1223 | } |
| 1224 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1225 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1226 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1227 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1228 | // Move to GPR/FPR from stack |
| 1229 | LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1230 | if (DataType::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1231 | __ LoadFpuFromOffset(load_type, |
| 1232 | destination.AsFpuRegister<FpuRegister>(), |
| 1233 | SP, |
| 1234 | source.GetStackIndex()); |
| 1235 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1236 | // TODO: use load_type = kLoadUnsignedWord when type == DataType::Type::kReference. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1237 | __ LoadFromOffset(load_type, |
| 1238 | destination.AsRegister<GpuRegister>(), |
| 1239 | SP, |
| 1240 | source.GetStackIndex()); |
| 1241 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1242 | } else if (source.IsSIMDStackSlot()) { |
| 1243 | __ LoadFpuFromOffset(kLoadQuadword, |
| 1244 | destination.AsFpuRegister<FpuRegister>(), |
| 1245 | SP, |
| 1246 | source.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1247 | } else if (source.IsConstant()) { |
| 1248 | // Move to GPR/FPR from constant |
| 1249 | GpuRegister gpr = AT; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1250 | if (!DataType::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1251 | gpr = destination.AsRegister<GpuRegister>(); |
| 1252 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1253 | if (dst_type == DataType::Type::kInt32 || dst_type == DataType::Type::kFloat32) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1254 | int32_t value = GetInt32ValueOf(source.GetConstant()->AsConstant()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1255 | if (DataType::IsFloatingPointType(dst_type) && value == 0) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1256 | gpr = ZERO; |
| 1257 | } else { |
| 1258 | __ LoadConst32(gpr, value); |
| 1259 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1260 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1261 | int64_t value = GetInt64ValueOf(source.GetConstant()->AsConstant()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1262 | if (DataType::IsFloatingPointType(dst_type) && value == 0) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1263 | gpr = ZERO; |
| 1264 | } else { |
| 1265 | __ LoadConst64(gpr, value); |
| 1266 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1267 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1268 | if (dst_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1269 | __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1270 | } else if (dst_type == DataType::Type::kFloat64) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1271 | __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
| 1272 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1273 | } else if (source.IsRegister()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1274 | if (destination.IsRegister()) { |
| 1275 | // Move to GPR from GPR |
| 1276 | __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>()); |
| 1277 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1278 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1279 | if (DataType::Is64BitType(dst_type)) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1280 | __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1281 | } else { |
| 1282 | __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1283 | } |
| 1284 | } |
| 1285 | } else if (source.IsFpuRegister()) { |
| 1286 | if (destination.IsFpuRegister()) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1287 | if (GetGraph()->HasSIMD()) { |
| 1288 | __ MoveV(VectorRegisterFrom(destination), |
| 1289 | VectorRegisterFrom(source)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1290 | } else { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1291 | // Move to FPR from FPR |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1292 | if (dst_type == DataType::Type::kFloat32) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1293 | __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1294 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1295 | DCHECK_EQ(dst_type, DataType::Type::kFloat64); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1296 | __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1297 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1298 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1299 | } else { |
| 1300 | DCHECK(destination.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1301 | if (DataType::Is64BitType(dst_type)) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1302 | __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1303 | } else { |
| 1304 | __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1305 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1306 | } |
| 1307 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1308 | } else if (destination.IsSIMDStackSlot()) { |
| 1309 | if (source.IsFpuRegister()) { |
| 1310 | __ StoreFpuToOffset(kStoreQuadword, |
| 1311 | source.AsFpuRegister<FpuRegister>(), |
| 1312 | SP, |
| 1313 | destination.GetStackIndex()); |
| 1314 | } else { |
| 1315 | DCHECK(source.IsSIMDStackSlot()); |
| 1316 | __ LoadFpuFromOffset(kLoadQuadword, |
| 1317 | FTMP, |
| 1318 | SP, |
| 1319 | source.GetStackIndex()); |
| 1320 | __ StoreFpuToOffset(kStoreQuadword, |
| 1321 | FTMP, |
| 1322 | SP, |
| 1323 | destination.GetStackIndex()); |
| 1324 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1325 | } else { // The destination is not a register. It must be a stack slot. |
| 1326 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1327 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1328 | if (unspecified_type) { |
| 1329 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1330 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1331 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1332 | dst_type = |
| 1333 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1334 | } |
| 1335 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1336 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1337 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1338 | // Move to stack from GPR/FPR |
| 1339 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 1340 | if (source.IsRegister()) { |
| 1341 | __ StoreToOffset(store_type, |
| 1342 | source.AsRegister<GpuRegister>(), |
| 1343 | SP, |
| 1344 | destination.GetStackIndex()); |
| 1345 | } else { |
| 1346 | __ StoreFpuToOffset(store_type, |
| 1347 | source.AsFpuRegister<FpuRegister>(), |
| 1348 | SP, |
| 1349 | destination.GetStackIndex()); |
| 1350 | } |
| 1351 | } else if (source.IsConstant()) { |
| 1352 | // Move to stack from constant |
| 1353 | HConstant* src_cst = source.GetConstant(); |
| 1354 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1355 | GpuRegister gpr = ZERO; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1356 | if (destination.IsStackSlot()) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1357 | int32_t value = GetInt32ValueOf(src_cst->AsConstant()); |
| 1358 | if (value != 0) { |
| 1359 | gpr = TMP; |
| 1360 | __ LoadConst32(gpr, value); |
| 1361 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1362 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1363 | DCHECK(destination.IsDoubleStackSlot()); |
| 1364 | int64_t value = GetInt64ValueOf(src_cst->AsConstant()); |
| 1365 | if (value != 0) { |
| 1366 | gpr = TMP; |
| 1367 | __ LoadConst64(gpr, value); |
| 1368 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1369 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1370 | __ StoreToOffset(store_type, gpr, SP, destination.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1371 | } else { |
| 1372 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
| 1373 | DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot()); |
| 1374 | // Move to stack from stack |
| 1375 | if (destination.IsStackSlot()) { |
| 1376 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1377 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 1378 | } else { |
| 1379 | __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex()); |
| 1380 | __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex()); |
| 1381 | } |
| 1382 | } |
| 1383 | } |
| 1384 | } |
| 1385 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1386 | void CodeGeneratorMIPS64::SwapLocations(Location loc1, Location loc2, DataType::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1387 | DCHECK(!loc1.IsConstant()); |
| 1388 | DCHECK(!loc2.IsConstant()); |
| 1389 | |
| 1390 | if (loc1.Equals(loc2)) { |
| 1391 | return; |
| 1392 | } |
| 1393 | |
| 1394 | bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot(); |
| 1395 | bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot(); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1396 | bool is_simd1 = loc1.IsSIMDStackSlot(); |
| 1397 | bool is_simd2 = loc2.IsSIMDStackSlot(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1398 | bool is_fp_reg1 = loc1.IsFpuRegister(); |
| 1399 | bool is_fp_reg2 = loc2.IsFpuRegister(); |
| 1400 | |
| 1401 | if (loc2.IsRegister() && loc1.IsRegister()) { |
| 1402 | // Swap 2 GPRs |
| 1403 | GpuRegister r1 = loc1.AsRegister<GpuRegister>(); |
| 1404 | GpuRegister r2 = loc2.AsRegister<GpuRegister>(); |
| 1405 | __ Move(TMP, r2); |
| 1406 | __ Move(r2, r1); |
| 1407 | __ Move(r1, TMP); |
| 1408 | } else if (is_fp_reg2 && is_fp_reg1) { |
| 1409 | // Swap 2 FPRs |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1410 | if (GetGraph()->HasSIMD()) { |
| 1411 | __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(loc1)); |
| 1412 | __ MoveV(VectorRegisterFrom(loc1), VectorRegisterFrom(loc2)); |
| 1413 | __ MoveV(VectorRegisterFrom(loc2), static_cast<VectorRegister>(FTMP)); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1414 | } else { |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1415 | FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>(); |
| 1416 | FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>(); |
| 1417 | if (type == DataType::Type::kFloat32) { |
| 1418 | __ MovS(FTMP, r1); |
| 1419 | __ MovS(r1, r2); |
| 1420 | __ MovS(r2, FTMP); |
| 1421 | } else { |
| 1422 | DCHECK_EQ(type, DataType::Type::kFloat64); |
| 1423 | __ MovD(FTMP, r1); |
| 1424 | __ MovD(r1, r2); |
| 1425 | __ MovD(r2, FTMP); |
| 1426 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1427 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1428 | } else if (is_slot1 != is_slot2) { |
| 1429 | // Swap GPR/FPR and stack slot |
| 1430 | Location reg_loc = is_slot1 ? loc2 : loc1; |
| 1431 | Location mem_loc = is_slot1 ? loc1 : loc2; |
| 1432 | LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
| 1433 | StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1434 | // TODO: use load_type = kLoadUnsignedWord when type == DataType::Type::kReference. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1435 | __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex()); |
| 1436 | if (reg_loc.IsFpuRegister()) { |
| 1437 | __ StoreFpuToOffset(store_type, |
| 1438 | reg_loc.AsFpuRegister<FpuRegister>(), |
| 1439 | SP, |
| 1440 | mem_loc.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1441 | if (mem_loc.IsStackSlot()) { |
| 1442 | __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1443 | } else { |
| 1444 | DCHECK(mem_loc.IsDoubleStackSlot()); |
| 1445 | __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1446 | } |
| 1447 | } else { |
| 1448 | __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex()); |
| 1449 | __ Move(reg_loc.AsRegister<GpuRegister>(), TMP); |
| 1450 | } |
| 1451 | } else if (is_slot1 && is_slot2) { |
| 1452 | move_resolver_.Exchange(loc1.GetStackIndex(), |
| 1453 | loc2.GetStackIndex(), |
| 1454 | loc1.IsDoubleStackSlot()); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1455 | } else if (is_simd1 && is_simd2) { |
| 1456 | move_resolver_.ExchangeQuadSlots(loc1.GetStackIndex(), loc2.GetStackIndex()); |
| 1457 | } else if ((is_fp_reg1 && is_simd2) || (is_fp_reg2 && is_simd1)) { |
| 1458 | Location fp_reg_loc = is_fp_reg1 ? loc1 : loc2; |
| 1459 | Location mem_loc = is_fp_reg1 ? loc2 : loc1; |
| 1460 | __ LoadFpuFromOffset(kLoadQuadword, FTMP, SP, mem_loc.GetStackIndex()); |
| 1461 | __ StoreFpuToOffset(kStoreQuadword, |
| 1462 | fp_reg_loc.AsFpuRegister<FpuRegister>(), |
| 1463 | SP, |
| 1464 | mem_loc.GetStackIndex()); |
| 1465 | __ MoveV(VectorRegisterFrom(fp_reg_loc), static_cast<VectorRegister>(FTMP)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1466 | } else { |
| 1467 | LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2; |
| 1468 | } |
| 1469 | } |
| 1470 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1471 | void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) { |
| 1472 | DCHECK(location.IsRegister()); |
| 1473 | __ LoadConst32(location.AsRegister<GpuRegister>(), value); |
| 1474 | } |
| 1475 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1476 | void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1477 | if (location.IsRegister()) { |
| 1478 | locations->AddTemp(location); |
| 1479 | } else { |
| 1480 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1481 | } |
| 1482 | } |
| 1483 | |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1484 | void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object, |
| 1485 | GpuRegister value, |
| 1486 | bool value_can_be_null) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1487 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1488 | GpuRegister card = AT; |
| 1489 | GpuRegister temp = TMP; |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1490 | if (value_can_be_null) { |
| 1491 | __ Beqzc(value, &done); |
| 1492 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1493 | __ LoadFromOffset(kLoadDoubleword, |
| 1494 | card, |
| 1495 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1496 | Thread::CardTableOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1497 | __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1498 | __ Daddu(temp, card, temp); |
| 1499 | __ Sb(card, temp, 0); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1500 | if (value_can_be_null) { |
| 1501 | __ Bind(&done); |
| 1502 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1505 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1506 | inline void CodeGeneratorMIPS64::EmitPcRelativeLinkerPatches( |
| 1507 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1508 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1509 | for (const PcRelativePatchInfo& info : infos) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1510 | const DexFile* dex_file = info.target_dex_file; |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1511 | size_t offset_or_index = info.offset_or_index; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1512 | DCHECK(info.label.IsBound()); |
| 1513 | uint32_t literal_offset = __ GetLabelLocation(&info.label); |
| 1514 | const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info; |
| 1515 | uint32_t pc_rel_offset = __ GetLabelLocation(&info_high.label); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1516 | 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] | 1517 | } |
| 1518 | } |
| 1519 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1520 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 1521 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 1522 | const DexFile* target_dex_file, |
| 1523 | uint32_t pc_insn_offset, |
| 1524 | uint32_t boot_image_offset) { |
| 1525 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 1526 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1527 | } |
| 1528 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1529 | void CodeGeneratorMIPS64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1530 | DCHECK(linker_patches->empty()); |
| 1531 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1532 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1533 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1534 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1535 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1536 | boot_image_string_patches_.size() + |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1537 | string_bss_entry_patches_.size() + |
| 1538 | boot_image_intrinsic_patches_.size(); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1539 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1540 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1541 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1542 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1543 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1544 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1545 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1546 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1547 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 1548 | boot_image_intrinsic_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1549 | } else { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1550 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1551 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1552 | DCHECK(boot_image_type_patches_.empty()); |
| 1553 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1554 | DCHECK(boot_image_intrinsic_patches_.empty()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1555 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1556 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1557 | method_bss_entry_patches_, linker_patches); |
| 1558 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1559 | type_bss_entry_patches_, linker_patches); |
| 1560 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1561 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1562 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1563 | } |
| 1564 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1565 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageIntrinsicPatch( |
| 1566 | uint32_t intrinsic_data, |
| 1567 | const PcRelativePatchInfo* info_high) { |
| 1568 | return NewPcRelativePatch( |
| 1569 | /* dex_file */ nullptr, intrinsic_data, info_high, &boot_image_intrinsic_patches_); |
| 1570 | } |
| 1571 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1572 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageRelRoPatch( |
| 1573 | uint32_t boot_image_offset, |
| 1574 | const PcRelativePatchInfo* info_high) { |
| 1575 | return NewPcRelativePatch( |
| 1576 | /* dex_file */ nullptr, boot_image_offset, info_high, &boot_image_method_patches_); |
| 1577 | } |
| 1578 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1579 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageMethodPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1580 | MethodReference target_method, |
| 1581 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1582 | return NewPcRelativePatch( |
| 1583 | target_method.dex_file, target_method.index, info_high, &boot_image_method_patches_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1584 | } |
| 1585 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1586 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewMethodBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1587 | MethodReference target_method, |
| 1588 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1589 | return NewPcRelativePatch( |
| 1590 | target_method.dex_file, target_method.index, info_high, &method_bss_entry_patches_); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1591 | } |
| 1592 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1593 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageTypePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1594 | const DexFile& dex_file, |
| 1595 | dex::TypeIndex type_index, |
| 1596 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1597 | return NewPcRelativePatch(&dex_file, type_index.index_, info_high, &boot_image_type_patches_); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1598 | } |
| 1599 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1600 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewTypeBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1601 | const DexFile& dex_file, |
| 1602 | dex::TypeIndex type_index, |
| 1603 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1604 | 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] | 1605 | } |
| 1606 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1607 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageStringPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1608 | const DexFile& dex_file, |
| 1609 | dex::StringIndex string_index, |
| 1610 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1611 | return NewPcRelativePatch( |
| 1612 | &dex_file, string_index.index_, info_high, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1613 | } |
| 1614 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1615 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewStringBssEntryPatch( |
| 1616 | const DexFile& dex_file, |
| 1617 | dex::StringIndex string_index, |
| 1618 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1619 | return NewPcRelativePatch(&dex_file, string_index.index_, info_high, &string_bss_entry_patches_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1620 | } |
| 1621 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1622 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1623 | const DexFile* dex_file, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1624 | uint32_t offset_or_index, |
| 1625 | const PcRelativePatchInfo* info_high, |
| 1626 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1627 | patches->emplace_back(dex_file, offset_or_index, info_high); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1628 | return &patches->back(); |
| 1629 | } |
| 1630 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1631 | Literal* CodeGeneratorMIPS64::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1632 | return map->GetOrCreate( |
| 1633 | value, |
| 1634 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1635 | } |
| 1636 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1637 | Literal* CodeGeneratorMIPS64::DeduplicateUint64Literal(uint64_t value) { |
| 1638 | return uint64_literals_.GetOrCreate( |
| 1639 | value, |
| 1640 | [this, value]() { return __ NewLiteral<uint64_t>(value); }); |
| 1641 | } |
| 1642 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1643 | Literal* CodeGeneratorMIPS64::DeduplicateBootImageAddressLiteral(uint64_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1644 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1645 | } |
| 1646 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1647 | void CodeGeneratorMIPS64::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high, |
| 1648 | GpuRegister out, |
| 1649 | PcRelativePatchInfo* info_low) { |
| 1650 | DCHECK(!info_high->patch_info_high); |
| 1651 | __ Bind(&info_high->label); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1652 | // Add the high half of a 32-bit offset to PC. |
| 1653 | __ Auipc(out, /* placeholder */ 0x1234); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1654 | // 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] | 1655 | // offset to `out` (e.g. ld, jialc, daddiu). |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1656 | if (info_low != nullptr) { |
| 1657 | DCHECK_EQ(info_low->patch_info_high, info_high); |
| 1658 | __ Bind(&info_low->label); |
| 1659 | } |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1660 | } |
| 1661 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1662 | void CodeGeneratorMIPS64::LoadBootImageAddress(GpuRegister reg, uint32_t boot_image_reference) { |
| 1663 | if (GetCompilerOptions().IsBootImage()) { |
| 1664 | PcRelativePatchInfo* info_high = NewBootImageIntrinsicPatch(boot_image_reference); |
| 1665 | PcRelativePatchInfo* info_low = NewBootImageIntrinsicPatch(boot_image_reference, info_high); |
| 1666 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 1667 | __ Daddiu(reg, AT, /* placeholder */ 0x5678); |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 1668 | } else if (Runtime::Current()->IsAotCompiler()) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1669 | PcRelativePatchInfo* info_high = NewBootImageRelRoPatch(boot_image_reference); |
| 1670 | PcRelativePatchInfo* info_low = NewBootImageRelRoPatch(boot_image_reference, info_high); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1671 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 1672 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 1673 | __ Lwu(reg, AT, /* placeholder */ 0x5678); |
| 1674 | } else { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 1675 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1676 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1677 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| 1678 | uintptr_t address = |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1679 | reinterpret_cast<uintptr_t>(heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1680 | __ LoadLiteral(reg, kLoadDoubleword, DeduplicateBootImageAddressLiteral(address)); |
| 1681 | } |
| 1682 | } |
| 1683 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1684 | void CodeGeneratorMIPS64::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 1685 | uint32_t boot_image_offset) { |
| 1686 | DCHECK(invoke->IsStatic()); |
| 1687 | InvokeRuntimeCallingConvention calling_convention; |
| 1688 | GpuRegister argument = calling_convention.GetRegisterAt(0); |
| 1689 | if (GetCompilerOptions().IsBootImage()) { |
| 1690 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 1691 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 1692 | MethodReference target_method = invoke->GetTargetMethod(); |
| 1693 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 1694 | PcRelativePatchInfo* info_high = NewBootImageTypePatch(*target_method.dex_file, type_idx); |
| 1695 | PcRelativePatchInfo* info_low = |
| 1696 | NewBootImageTypePatch(*target_method.dex_file, type_idx, info_high); |
| 1697 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 1698 | __ Daddiu(argument, AT, /* placeholder */ 0x5678); |
| 1699 | } else { |
| 1700 | LoadBootImageAddress(argument, boot_image_offset); |
| 1701 | } |
| 1702 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 1703 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 1704 | } |
| 1705 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1706 | Literal* CodeGeneratorMIPS64::DeduplicateJitStringLiteral(const DexFile& dex_file, |
| 1707 | dex::StringIndex string_index, |
| 1708 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1709 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1710 | return jit_string_patches_.GetOrCreate( |
| 1711 | StringReference(&dex_file, string_index), |
| 1712 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1713 | } |
| 1714 | |
| 1715 | Literal* CodeGeneratorMIPS64::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 1716 | dex::TypeIndex type_index, |
| 1717 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1718 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1719 | return jit_class_patches_.GetOrCreate( |
| 1720 | TypeReference(&dex_file, type_index), |
| 1721 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1722 | } |
| 1723 | |
| 1724 | void CodeGeneratorMIPS64::PatchJitRootUse(uint8_t* code, |
| 1725 | const uint8_t* roots_data, |
| 1726 | const Literal* literal, |
| 1727 | uint64_t index_in_table) const { |
| 1728 | uint32_t literal_offset = GetAssembler().GetLabelLocation(literal->GetLabel()); |
| 1729 | uintptr_t address = |
| 1730 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1731 | reinterpret_cast<uint32_t*>(code + literal_offset)[0] = dchecked_integral_cast<uint32_t>(address); |
| 1732 | } |
| 1733 | |
| 1734 | void CodeGeneratorMIPS64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1735 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1736 | const StringReference& string_reference = entry.first; |
| 1737 | Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1738 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1739 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1740 | } |
| 1741 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1742 | const TypeReference& type_reference = entry.first; |
| 1743 | Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1744 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1745 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1746 | } |
| 1747 | } |
| 1748 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1749 | void CodeGeneratorMIPS64::SetupBlockedRegisters() const { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1750 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1751 | blocked_core_registers_[ZERO] = true; |
| 1752 | blocked_core_registers_[K0] = true; |
| 1753 | blocked_core_registers_[K1] = true; |
| 1754 | blocked_core_registers_[GP] = true; |
| 1755 | blocked_core_registers_[SP] = true; |
| 1756 | blocked_core_registers_[RA] = true; |
| 1757 | |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1758 | // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch |
| 1759 | // registers (similar to how AT is used by MIPS assemblers). |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1760 | blocked_core_registers_[AT] = true; |
| 1761 | blocked_core_registers_[TMP] = true; |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1762 | blocked_core_registers_[TMP2] = true; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1763 | blocked_fpu_registers_[FTMP] = true; |
| 1764 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1765 | if (GetInstructionSetFeatures().HasMsa()) { |
| 1766 | // To be used just for MSA instructions. |
| 1767 | blocked_fpu_registers_[FTMP2] = true; |
| 1768 | } |
| 1769 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1770 | // Reserve suspend and thread registers. |
| 1771 | blocked_core_registers_[S0] = true; |
| 1772 | blocked_core_registers_[TR] = true; |
| 1773 | |
| 1774 | // Reserve T9 for function calls |
| 1775 | blocked_core_registers_[T9] = true; |
| 1776 | |
Goran Jakovljevic | 782be11 | 2016-06-21 12:39:04 +0200 | [diff] [blame] | 1777 | if (GetGraph()->IsDebuggable()) { |
| 1778 | // Stubs do not save callee-save floating point registers. If the graph |
| 1779 | // is debuggable, we need to deal with these registers differently. For |
| 1780 | // now, just block them. |
| 1781 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1782 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1783 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1784 | } |
| 1785 | } |
| 1786 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1787 | size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1788 | __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1789 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1793 | __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1794 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1798 | __ StoreFpuToOffset(GetGraph()->HasSIMD() ? kStoreQuadword : kStoreDoubleword, |
| 1799 | FpuRegister(reg_id), |
| 1800 | SP, |
| 1801 | stack_index); |
| 1802 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1806 | __ LoadFpuFromOffset(GetGraph()->HasSIMD() ? kLoadQuadword : kLoadDoubleword, |
| 1807 | FpuRegister(reg_id), |
| 1808 | SP, |
| 1809 | stack_index); |
| 1810 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1814 | stream << GpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1818 | stream << FpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1821 | const Mips64InstructionSetFeatures& CodeGeneratorMIPS64::GetInstructionSetFeatures() const { |
| 1822 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsMips64InstructionSetFeatures(); |
| 1823 | } |
| 1824 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1825 | void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1826 | HInstruction* instruction, |
| 1827 | uint32_t dex_pc, |
| 1828 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1829 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1830 | GenerateInvokeRuntime(GetThreadOffset<kMips64PointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 1831 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1832 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1833 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1834 | } |
| 1835 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1836 | void CodeGeneratorMIPS64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1837 | HInstruction* instruction, |
| 1838 | SlowPathCode* slow_path) { |
| 1839 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1840 | GenerateInvokeRuntime(entry_point_offset); |
| 1841 | } |
| 1842 | |
| 1843 | void CodeGeneratorMIPS64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| 1844 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 1845 | __ Jalr(T9); |
| 1846 | __ Nop(); |
| 1847 | } |
| 1848 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1849 | void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path, |
| 1850 | GpuRegister class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1851 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 1852 | const size_t status_byte_offset = |
| 1853 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 1854 | constexpr uint32_t shifted_initialized_value = |
| 1855 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 1856 | |
| 1857 | __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, status_byte_offset); |
Lena Djokic | 3177e10 | 2018-02-28 11:32:40 +0100 | [diff] [blame] | 1858 | __ Sltiu(TMP, TMP, shifted_initialized_value); |
| 1859 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1860 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1861 | __ Sync(0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1862 | __ Bind(slow_path->GetExitLabel()); |
| 1863 | } |
| 1864 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 1865 | void InstructionCodeGeneratorMIPS64::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 1866 | GpuRegister temp) { |
| 1867 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 1868 | uint32_t mask = check->GetBitstringMask(); |
| 1869 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 1870 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 1871 | |
| 1872 | if (mask_bits == 16u) { |
| 1873 | // Load only the bitstring part of the status word. |
| 1874 | __ LoadFromOffset( |
| 1875 | kLoadUnsignedHalfword, temp, temp, mirror::Class::StatusOffset().Int32Value()); |
| 1876 | // Compare the bitstring bits using XOR. |
| 1877 | __ Xori(temp, temp, dchecked_integral_cast<uint16_t>(path_to_root)); |
| 1878 | } else { |
| 1879 | // /* uint32_t */ temp = temp->status_ |
| 1880 | __ LoadFromOffset(kLoadWord, temp, temp, mirror::Class::StatusOffset().Int32Value()); |
| 1881 | // Compare the bitstring bits using XOR. |
| 1882 | if (IsUint<16>(path_to_root)) { |
| 1883 | __ Xori(temp, temp, dchecked_integral_cast<uint16_t>(path_to_root)); |
| 1884 | } else { |
| 1885 | __ LoadConst32(TMP, path_to_root); |
| 1886 | __ Xor(temp, temp, TMP); |
| 1887 | } |
| 1888 | // Shift out bits that do not contribute to the comparison. |
| 1889 | __ Sll(temp, temp, 32 - mask_bits); |
| 1890 | } |
| 1891 | } |
| 1892 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1893 | void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1894 | __ Sync(0); // only stype 0 is supported |
| 1895 | } |
| 1896 | |
| 1897 | void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1898 | HBasicBlock* successor) { |
| 1899 | SuspendCheckSlowPathMIPS64* slow_path = |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 1900 | down_cast<SuspendCheckSlowPathMIPS64*>(instruction->GetSlowPath()); |
| 1901 | |
| 1902 | if (slow_path == nullptr) { |
| 1903 | slow_path = |
| 1904 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS64(instruction, successor); |
| 1905 | instruction->SetSlowPath(slow_path); |
| 1906 | codegen_->AddSlowPath(slow_path); |
| 1907 | if (successor != nullptr) { |
| 1908 | DCHECK(successor->IsLoopHeader()); |
| 1909 | } |
| 1910 | } else { |
| 1911 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1912 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1913 | |
| 1914 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1915 | TMP, |
| 1916 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1917 | Thread::ThreadFlagsOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1918 | if (successor == nullptr) { |
| 1919 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 1920 | __ Bind(slow_path->GetReturnLabel()); |
| 1921 | } else { |
| 1922 | __ Beqzc(TMP, codegen_->GetLabelOf(successor)); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1923 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1924 | // slow_path will return to GetLabelOf(successor). |
| 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph, |
| 1929 | CodeGeneratorMIPS64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1930 | : InstructionCodeGenerator(graph, codegen), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1931 | assembler_(codegen->GetAssembler()), |
| 1932 | codegen_(codegen) {} |
| 1933 | |
| 1934 | void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1935 | DCHECK_EQ(instruction->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1936 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1937 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1938 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1939 | case DataType::Type::kInt32: |
| 1940 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1941 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1942 | HInstruction* right = instruction->InputAt(1); |
| 1943 | bool can_use_imm = false; |
| 1944 | if (right->IsConstant()) { |
| 1945 | int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant()); |
| 1946 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1947 | can_use_imm = IsUint<16>(imm); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1948 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1949 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 1950 | bool single_use = right->GetUses().HasExactlyOneElement(); |
| 1951 | if (instruction->IsSub()) { |
| 1952 | if (!(type == DataType::Type::kInt32 && imm == INT32_MIN)) { |
| 1953 | imm = -imm; |
| 1954 | } |
| 1955 | } |
| 1956 | if (type == DataType::Type::kInt32) { |
| 1957 | can_use_imm = IsInt<16>(imm) || (Low16Bits(imm) == 0) || single_use; |
| 1958 | } else { |
| 1959 | can_use_imm = IsInt<16>(imm) || (IsInt<32>(imm) && (Low16Bits(imm) == 0)) || single_use; |
| 1960 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1961 | } |
| 1962 | } |
| 1963 | if (can_use_imm) |
| 1964 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1965 | else |
| 1966 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1967 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1968 | } |
| 1969 | break; |
| 1970 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1971 | case DataType::Type::kFloat32: |
| 1972 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1973 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1974 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1975 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1976 | break; |
| 1977 | |
| 1978 | default: |
| 1979 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1980 | } |
| 1981 | } |
| 1982 | |
| 1983 | void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1984 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1985 | LocationSummary* locations = instruction->GetLocations(); |
| 1986 | |
| 1987 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1988 | case DataType::Type::kInt32: |
| 1989 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1990 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1991 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1992 | Location rhs_location = locations->InAt(1); |
| 1993 | |
| 1994 | GpuRegister rhs_reg = ZERO; |
| 1995 | int64_t rhs_imm = 0; |
| 1996 | bool use_imm = rhs_location.IsConstant(); |
| 1997 | if (use_imm) { |
| 1998 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1999 | } else { |
| 2000 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 2001 | } |
| 2002 | |
| 2003 | if (instruction->IsAnd()) { |
| 2004 | if (use_imm) |
| 2005 | __ Andi(dst, lhs, rhs_imm); |
| 2006 | else |
| 2007 | __ And(dst, lhs, rhs_reg); |
| 2008 | } else if (instruction->IsOr()) { |
| 2009 | if (use_imm) |
| 2010 | __ Ori(dst, lhs, rhs_imm); |
| 2011 | else |
| 2012 | __ Or(dst, lhs, rhs_reg); |
| 2013 | } else if (instruction->IsXor()) { |
| 2014 | if (use_imm) |
| 2015 | __ Xori(dst, lhs, rhs_imm); |
| 2016 | else |
| 2017 | __ Xor(dst, lhs, rhs_reg); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2018 | } else if (instruction->IsAdd() || instruction->IsSub()) { |
| 2019 | if (instruction->IsSub()) { |
| 2020 | rhs_imm = -rhs_imm; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2021 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2022 | if (type == DataType::Type::kInt32) { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2023 | if (use_imm) { |
| 2024 | if (IsInt<16>(rhs_imm)) { |
| 2025 | __ Addiu(dst, lhs, rhs_imm); |
| 2026 | } else { |
| 2027 | int16_t rhs_imm_high = High16Bits(rhs_imm); |
| 2028 | int16_t rhs_imm_low = Low16Bits(rhs_imm); |
| 2029 | if (rhs_imm_low < 0) { |
| 2030 | rhs_imm_high += 1; |
| 2031 | } |
| 2032 | __ Aui(dst, lhs, rhs_imm_high); |
| 2033 | if (rhs_imm_low != 0) { |
| 2034 | __ Addiu(dst, dst, rhs_imm_low); |
| 2035 | } |
| 2036 | } |
| 2037 | } else { |
| 2038 | if (instruction->IsAdd()) { |
| 2039 | __ Addu(dst, lhs, rhs_reg); |
| 2040 | } else { |
| 2041 | DCHECK(instruction->IsSub()); |
| 2042 | __ Subu(dst, lhs, rhs_reg); |
| 2043 | } |
| 2044 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2045 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2046 | if (use_imm) { |
| 2047 | if (IsInt<16>(rhs_imm)) { |
| 2048 | __ Daddiu(dst, lhs, rhs_imm); |
| 2049 | } else if (IsInt<32>(rhs_imm)) { |
| 2050 | int16_t rhs_imm_high = High16Bits(rhs_imm); |
| 2051 | int16_t rhs_imm_low = Low16Bits(rhs_imm); |
| 2052 | bool overflow_hi16 = false; |
| 2053 | if (rhs_imm_low < 0) { |
| 2054 | rhs_imm_high += 1; |
| 2055 | overflow_hi16 = (rhs_imm_high == -32768); |
| 2056 | } |
| 2057 | __ Daui(dst, lhs, rhs_imm_high); |
| 2058 | if (rhs_imm_low != 0) { |
| 2059 | __ Daddiu(dst, dst, rhs_imm_low); |
| 2060 | } |
| 2061 | if (overflow_hi16) { |
| 2062 | __ Dahi(dst, 1); |
| 2063 | } |
| 2064 | } else { |
| 2065 | int16_t rhs_imm_low = Low16Bits(Low32Bits(rhs_imm)); |
| 2066 | if (rhs_imm_low < 0) { |
| 2067 | rhs_imm += (INT64_C(1) << 16); |
| 2068 | } |
| 2069 | int16_t rhs_imm_upper = High16Bits(Low32Bits(rhs_imm)); |
| 2070 | if (rhs_imm_upper < 0) { |
| 2071 | rhs_imm += (INT64_C(1) << 32); |
| 2072 | } |
| 2073 | int16_t rhs_imm_high = Low16Bits(High32Bits(rhs_imm)); |
| 2074 | if (rhs_imm_high < 0) { |
| 2075 | rhs_imm += (INT64_C(1) << 48); |
| 2076 | } |
| 2077 | int16_t rhs_imm_top = High16Bits(High32Bits(rhs_imm)); |
| 2078 | GpuRegister tmp = lhs; |
| 2079 | if (rhs_imm_low != 0) { |
| 2080 | __ Daddiu(dst, tmp, rhs_imm_low); |
| 2081 | tmp = dst; |
| 2082 | } |
| 2083 | // Dahi and Dati must use the same input and output register, so we have to initialize |
| 2084 | // the dst register using Daddiu or Daui, even when the intermediate value is zero: |
| 2085 | // Daui(dst, lhs, 0). |
| 2086 | if ((rhs_imm_upper != 0) || (rhs_imm_low == 0)) { |
| 2087 | __ Daui(dst, tmp, rhs_imm_upper); |
| 2088 | } |
| 2089 | if (rhs_imm_high != 0) { |
| 2090 | __ Dahi(dst, rhs_imm_high); |
| 2091 | } |
| 2092 | if (rhs_imm_top != 0) { |
| 2093 | __ Dati(dst, rhs_imm_top); |
| 2094 | } |
| 2095 | } |
| 2096 | } else if (instruction->IsAdd()) { |
| 2097 | __ Daddu(dst, lhs, rhs_reg); |
| 2098 | } else { |
| 2099 | DCHECK(instruction->IsSub()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2100 | __ Dsubu(dst, lhs, rhs_reg); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2101 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2102 | } |
| 2103 | } |
| 2104 | break; |
| 2105 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2106 | case DataType::Type::kFloat32: |
| 2107 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2108 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 2109 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 2110 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 2111 | if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2112 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2113 | __ AddS(dst, lhs, rhs); |
| 2114 | else |
| 2115 | __ AddD(dst, lhs, rhs); |
| 2116 | } else if (instruction->IsSub()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2117 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2118 | __ SubS(dst, lhs, rhs); |
| 2119 | else |
| 2120 | __ SubD(dst, lhs, rhs); |
| 2121 | } else { |
| 2122 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
| 2123 | } |
| 2124 | break; |
| 2125 | } |
| 2126 | default: |
| 2127 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 2128 | } |
| 2129 | } |
| 2130 | |
| 2131 | void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2132 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2133 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2134 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2135 | DataType::Type type = instr->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2136 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2137 | case DataType::Type::kInt32: |
| 2138 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2139 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2140 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2141 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2142 | break; |
| 2143 | } |
| 2144 | default: |
| 2145 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2146 | } |
| 2147 | } |
| 2148 | |
| 2149 | void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2150 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2151 | LocationSummary* locations = instr->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2152 | DataType::Type type = instr->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2153 | |
| 2154 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2155 | case DataType::Type::kInt32: |
| 2156 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2157 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 2158 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2159 | Location rhs_location = locations->InAt(1); |
| 2160 | |
| 2161 | GpuRegister rhs_reg = ZERO; |
| 2162 | int64_t rhs_imm = 0; |
| 2163 | bool use_imm = rhs_location.IsConstant(); |
| 2164 | if (use_imm) { |
| 2165 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 2166 | } else { |
| 2167 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 2168 | } |
| 2169 | |
| 2170 | if (use_imm) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2171 | uint32_t shift_value = rhs_imm & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2172 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2173 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2174 | if (shift_value == 0) { |
| 2175 | if (dst != lhs) { |
| 2176 | __ Move(dst, lhs); |
| 2177 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2178 | } else if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2179 | if (instr->IsShl()) { |
| 2180 | __ Sll(dst, lhs, shift_value); |
| 2181 | } else if (instr->IsShr()) { |
| 2182 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2183 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2184 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2185 | } else { |
| 2186 | __ Rotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2187 | } |
| 2188 | } else { |
| 2189 | if (shift_value < 32) { |
| 2190 | if (instr->IsShl()) { |
| 2191 | __ Dsll(dst, lhs, shift_value); |
| 2192 | } else if (instr->IsShr()) { |
| 2193 | __ Dsra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2194 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2195 | __ Dsrl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2196 | } else { |
| 2197 | __ Drotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2198 | } |
| 2199 | } else { |
| 2200 | shift_value -= 32; |
| 2201 | if (instr->IsShl()) { |
| 2202 | __ Dsll32(dst, lhs, shift_value); |
| 2203 | } else if (instr->IsShr()) { |
| 2204 | __ Dsra32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2205 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2206 | __ Dsrl32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2207 | } else { |
| 2208 | __ Drotr32(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2209 | } |
| 2210 | } |
| 2211 | } |
| 2212 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2213 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2214 | if (instr->IsShl()) { |
| 2215 | __ Sllv(dst, lhs, rhs_reg); |
| 2216 | } else if (instr->IsShr()) { |
| 2217 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2218 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2219 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2220 | } else { |
| 2221 | __ Rotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2222 | } |
| 2223 | } else { |
| 2224 | if (instr->IsShl()) { |
| 2225 | __ Dsllv(dst, lhs, rhs_reg); |
| 2226 | } else if (instr->IsShr()) { |
| 2227 | __ Dsrav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2228 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2229 | __ Dsrlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2230 | } else { |
| 2231 | __ Drotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2232 | } |
| 2233 | } |
| 2234 | } |
| 2235 | break; |
| 2236 | } |
| 2237 | default: |
| 2238 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2239 | } |
| 2240 | } |
| 2241 | |
| 2242 | void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) { |
| 2243 | HandleBinaryOp(instruction); |
| 2244 | } |
| 2245 | |
| 2246 | void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) { |
| 2247 | HandleBinaryOp(instruction); |
| 2248 | } |
| 2249 | |
| 2250 | void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) { |
| 2251 | HandleBinaryOp(instruction); |
| 2252 | } |
| 2253 | |
| 2254 | void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) { |
| 2255 | HandleBinaryOp(instruction); |
| 2256 | } |
| 2257 | |
| 2258 | void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2259 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2260 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2261 | kEmitCompilerReadBarrier && (type == DataType::Type::kReference); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2262 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2263 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2264 | object_array_get_with_read_barrier |
| 2265 | ? LocationSummary::kCallOnSlowPath |
| 2266 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 2267 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2268 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2269 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2270 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2271 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2272 | if (DataType::IsFloatingPointType(type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2273 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2274 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2275 | // The output overlaps in the case of an object array get with |
| 2276 | // read barriers enabled: we do not want the move to overwrite the |
| 2277 | // array's location, as we need it to emit the read barrier. |
| 2278 | locations->SetOut(Location::RequiresRegister(), |
| 2279 | object_array_get_with_read_barrier |
| 2280 | ? Location::kOutputOverlap |
| 2281 | : Location::kNoOutputOverlap); |
| 2282 | } |
| 2283 | // We need a temporary register for the read barrier marking slow |
| 2284 | // path in CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier. |
| 2285 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2286 | bool temp_needed = instruction->GetIndex()->IsConstant() |
| 2287 | ? !kBakerReadBarrierThunksEnableForFields |
| 2288 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2289 | if (temp_needed) { |
| 2290 | locations->AddTemp(Location::RequiresRegister()); |
| 2291 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2292 | } |
| 2293 | } |
| 2294 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2295 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS64* codegen) { |
| 2296 | auto null_checker = [codegen, instruction]() { |
| 2297 | codegen->MaybeRecordImplicitNullCheck(instruction); |
| 2298 | }; |
| 2299 | return null_checker; |
| 2300 | } |
| 2301 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2302 | void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) { |
| 2303 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2304 | Location obj_loc = locations->InAt(0); |
| 2305 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 2306 | Location out_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2307 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2308 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2309 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2310 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2311 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2312 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2313 | instruction->IsStringCharAt(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2314 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2315 | case DataType::Type::kBool: |
| 2316 | case DataType::Type::kUint8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2317 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2318 | if (index.IsConstant()) { |
| 2319 | size_t offset = |
| 2320 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2321 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2322 | } else { |
| 2323 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2324 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2325 | } |
| 2326 | break; |
| 2327 | } |
| 2328 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2329 | case DataType::Type::kInt8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2330 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2331 | if (index.IsConstant()) { |
| 2332 | size_t offset = |
| 2333 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2334 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2335 | } else { |
| 2336 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2337 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2338 | } |
| 2339 | break; |
| 2340 | } |
| 2341 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2342 | case DataType::Type::kUint16: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2343 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2344 | if (maybe_compressed_char_at) { |
| 2345 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2346 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2347 | __ Dext(TMP, TMP, 0, 1); |
| 2348 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2349 | "Expecting 0=compressed, 1=uncompressed"); |
| 2350 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2351 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2352 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2353 | if (maybe_compressed_char_at) { |
| 2354 | Mips64Label uncompressed_load, done; |
| 2355 | __ Bnezc(TMP, &uncompressed_load); |
| 2356 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2357 | out, |
| 2358 | obj, |
| 2359 | data_offset + (const_index << TIMES_1)); |
| 2360 | __ Bc(&done); |
| 2361 | __ Bind(&uncompressed_load); |
| 2362 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2363 | out, |
| 2364 | obj, |
| 2365 | data_offset + (const_index << TIMES_2)); |
| 2366 | __ Bind(&done); |
| 2367 | } else { |
| 2368 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2369 | out, |
| 2370 | obj, |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2371 | data_offset + (const_index << TIMES_2), |
| 2372 | null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2373 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2374 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2375 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
| 2376 | if (maybe_compressed_char_at) { |
| 2377 | Mips64Label uncompressed_load, done; |
| 2378 | __ Bnezc(TMP, &uncompressed_load); |
| 2379 | __ Daddu(TMP, obj, index_reg); |
| 2380 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2381 | __ Bc(&done); |
| 2382 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2383 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2384 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2385 | __ Bind(&done); |
| 2386 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2387 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2388 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2389 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2390 | } |
| 2391 | break; |
| 2392 | } |
| 2393 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2394 | case DataType::Type::kInt16: { |
| 2395 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 2396 | if (index.IsConstant()) { |
| 2397 | size_t offset = |
| 2398 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2399 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
| 2400 | } else { |
| 2401 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
| 2402 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
| 2403 | } |
| 2404 | break; |
| 2405 | } |
| 2406 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2407 | case DataType::Type::kInt32: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2408 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2409 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2410 | LoadOperandType load_type = |
| 2411 | (type == DataType::Type::kReference) ? kLoadUnsignedWord : kLoadWord; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2412 | if (index.IsConstant()) { |
| 2413 | size_t offset = |
| 2414 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2415 | __ LoadFromOffset(load_type, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2416 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2417 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2418 | __ LoadFromOffset(load_type, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2419 | } |
| 2420 | break; |
| 2421 | } |
| 2422 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2423 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2424 | static_assert( |
| 2425 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2426 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2427 | // /* HeapReference<Object> */ out = |
| 2428 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2429 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2430 | bool temp_needed = index.IsConstant() |
| 2431 | ? !kBakerReadBarrierThunksEnableForFields |
| 2432 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2433 | Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2434 | // Note that a potential implicit null check is handled in this |
| 2435 | // CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier call. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2436 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 2437 | if (index.IsConstant()) { |
| 2438 | // Array load with a constant index can be treated as a field load. |
| 2439 | size_t offset = |
| 2440 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2441 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2442 | out_loc, |
| 2443 | obj, |
| 2444 | offset, |
| 2445 | temp, |
| 2446 | /* needs_null_check */ false); |
| 2447 | } else { |
| 2448 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2449 | out_loc, |
| 2450 | obj, |
| 2451 | data_offset, |
| 2452 | index, |
| 2453 | temp, |
| 2454 | /* needs_null_check */ false); |
| 2455 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2456 | } else { |
| 2457 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 2458 | if (index.IsConstant()) { |
| 2459 | size_t offset = |
| 2460 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2461 | __ LoadFromOffset(kLoadUnsignedWord, out, obj, offset, null_checker); |
| 2462 | // If read barriers are enabled, emit read barriers other than |
| 2463 | // Baker's using a slow path (and also unpoison the loaded |
| 2464 | // reference, if heap poisoning is enabled). |
| 2465 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2466 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2467 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2468 | __ LoadFromOffset(kLoadUnsignedWord, out, TMP, data_offset, null_checker); |
| 2469 | // If read barriers are enabled, emit read barriers other than |
| 2470 | // Baker's using a slow path (and also unpoison the loaded |
| 2471 | // reference, if heap poisoning is enabled). |
| 2472 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2473 | out_loc, |
| 2474 | out_loc, |
| 2475 | obj_loc, |
| 2476 | data_offset, |
| 2477 | index); |
| 2478 | } |
| 2479 | } |
| 2480 | break; |
| 2481 | } |
| 2482 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2483 | case DataType::Type::kInt64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2484 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2485 | if (index.IsConstant()) { |
| 2486 | size_t offset = |
| 2487 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2488 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2489 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2490 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2491 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2492 | } |
| 2493 | break; |
| 2494 | } |
| 2495 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2496 | case DataType::Type::kFloat32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2497 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2498 | if (index.IsConstant()) { |
| 2499 | size_t offset = |
| 2500 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2501 | __ LoadFpuFromOffset(kLoadWord, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2502 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2503 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2504 | __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2505 | } |
| 2506 | break; |
| 2507 | } |
| 2508 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2509 | case DataType::Type::kFloat64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2510 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2511 | if (index.IsConstant()) { |
| 2512 | size_t offset = |
| 2513 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2514 | __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2515 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2516 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2517 | __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2518 | } |
| 2519 | break; |
| 2520 | } |
| 2521 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2522 | case DataType::Type::kUint32: |
| 2523 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2524 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2525 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2526 | UNREACHABLE(); |
| 2527 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2531 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2532 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2533 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2534 | } |
| 2535 | |
| 2536 | void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 2537 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2538 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2539 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2540 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2541 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2542 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2543 | // Mask out compression flag from String's array length. |
| 2544 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2545 | __ Srl(out, out, 1u); |
| 2546 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2547 | } |
| 2548 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2549 | Location LocationsBuilderMIPS64::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2550 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2551 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2552 | : Location::RequiresRegister(); |
| 2553 | } |
| 2554 | |
| 2555 | Location LocationsBuilderMIPS64::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2556 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2557 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2558 | // but we should only prefer this if the constant has a single use. |
| 2559 | if (instruction->IsConstant() && |
| 2560 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2561 | instruction->GetUses().HasExactlyOneElement())) { |
| 2562 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2563 | // Otherwise fall through and require an FPU register for the constant. |
| 2564 | } |
| 2565 | return Location::RequiresFpuRegister(); |
| 2566 | } |
| 2567 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2568 | void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2569 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2570 | |
| 2571 | bool needs_write_barrier = |
| 2572 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2573 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2574 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2575 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2576 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2577 | may_need_runtime_call_for_type_check ? |
| 2578 | LocationSummary::kCallOnSlowPath : |
| 2579 | LocationSummary::kNoCall); |
| 2580 | |
| 2581 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2582 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2583 | if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2584 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2585 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2586 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2587 | } |
| 2588 | if (needs_write_barrier) { |
| 2589 | // Temporary register for the write barrier. |
| 2590 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2591 | } |
| 2592 | } |
| 2593 | |
| 2594 | void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) { |
| 2595 | LocationSummary* locations = instruction->GetLocations(); |
| 2596 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2597 | Location index = locations->InAt(1); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2598 | Location value_location = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2599 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2600 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2601 | bool needs_write_barrier = |
| 2602 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2603 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2604 | GpuRegister base_reg = index.IsConstant() ? obj : TMP; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2605 | |
| 2606 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2607 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2608 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2609 | case DataType::Type::kInt8: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2610 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2611 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2612 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2613 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2614 | __ Daddu(base_reg, obj, index.AsRegister<GpuRegister>()); |
| 2615 | } |
| 2616 | if (value_location.IsConstant()) { |
| 2617 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2618 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2619 | } else { |
| 2620 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2621 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2622 | } |
| 2623 | break; |
| 2624 | } |
| 2625 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2626 | case DataType::Type::kUint16: |
| 2627 | case DataType::Type::kInt16: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2628 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2629 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2630 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2631 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2632 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2633 | } |
| 2634 | if (value_location.IsConstant()) { |
| 2635 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2636 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2637 | } else { |
| 2638 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2639 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2640 | } |
| 2641 | break; |
| 2642 | } |
| 2643 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2644 | case DataType::Type::kInt32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2645 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2646 | if (index.IsConstant()) { |
| 2647 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
| 2648 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2649 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2650 | } |
| 2651 | if (value_location.IsConstant()) { |
| 2652 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2653 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2654 | } else { |
| 2655 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2656 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2657 | } |
| 2658 | break; |
| 2659 | } |
| 2660 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2661 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2662 | if (value_location.IsConstant()) { |
| 2663 | // Just setting null. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2664 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2665 | if (index.IsConstant()) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2666 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2667 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2668 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2669 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2670 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2671 | DCHECK_EQ(value, 0); |
| 2672 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2673 | DCHECK(!needs_write_barrier); |
| 2674 | DCHECK(!may_need_runtime_call_for_type_check); |
| 2675 | break; |
| 2676 | } |
| 2677 | |
| 2678 | DCHECK(needs_write_barrier); |
| 2679 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2680 | GpuRegister temp1 = locations->GetTemp(0).AsRegister<GpuRegister>(); |
| 2681 | GpuRegister temp2 = TMP; // Doesn't need to survive slow path. |
| 2682 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2683 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2684 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2685 | Mips64Label done; |
| 2686 | SlowPathCodeMIPS64* slow_path = nullptr; |
| 2687 | |
| 2688 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2689 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS64(instruction); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2690 | codegen_->AddSlowPath(slow_path); |
| 2691 | if (instruction->GetValueCanBeNull()) { |
| 2692 | Mips64Label non_zero; |
| 2693 | __ Bnezc(value, &non_zero); |
| 2694 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2695 | if (index.IsConstant()) { |
| 2696 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2697 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2698 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2699 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2700 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2701 | __ Bc(&done); |
| 2702 | __ Bind(&non_zero); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2703 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2704 | |
| 2705 | // Note that when read barriers are enabled, the type checks |
| 2706 | // are performed without read barriers. This is fine, even in |
| 2707 | // the case where a class object is in the from-space after |
| 2708 | // the flip, as a comparison involving such a type would not |
| 2709 | // produce a false positive; it may of course produce a false |
| 2710 | // negative, in which case we would take the ArraySet slow |
| 2711 | // path. |
| 2712 | |
| 2713 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 2714 | __ LoadFromOffset(kLoadUnsignedWord, temp1, obj, class_offset, null_checker); |
| 2715 | __ MaybeUnpoisonHeapReference(temp1); |
| 2716 | |
| 2717 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2718 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, component_offset); |
| 2719 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2720 | __ LoadFromOffset(kLoadUnsignedWord, temp2, value, class_offset); |
| 2721 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 2722 | // nor `temp2`, as we are comparing two poisoned references. |
| 2723 | |
| 2724 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2725 | Mips64Label do_put; |
| 2726 | __ Beqc(temp1, temp2, &do_put); |
| 2727 | // If heap poisoning is enabled, the `temp1` reference has |
| 2728 | // not been unpoisoned yet; unpoison it now. |
| 2729 | __ MaybeUnpoisonHeapReference(temp1); |
| 2730 | |
| 2731 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 2732 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, super_offset); |
| 2733 | // If heap poisoning is enabled, no need to unpoison |
| 2734 | // `temp1`, as we are comparing against null below. |
| 2735 | __ Bnezc(temp1, slow_path->GetEntryLabel()); |
| 2736 | __ Bind(&do_put); |
| 2737 | } else { |
| 2738 | __ Bnec(temp1, temp2, slow_path->GetEntryLabel()); |
| 2739 | } |
| 2740 | } |
| 2741 | |
| 2742 | GpuRegister source = value; |
| 2743 | if (kPoisonHeapReferences) { |
| 2744 | // Note that in the case where `value` is a null reference, |
| 2745 | // we do not enter this block, as a null reference does not |
| 2746 | // need poisoning. |
| 2747 | __ Move(temp1, value); |
| 2748 | __ PoisonHeapReference(temp1); |
| 2749 | source = temp1; |
| 2750 | } |
| 2751 | |
| 2752 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2753 | if (index.IsConstant()) { |
| 2754 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2755 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2756 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2757 | } |
| 2758 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 2759 | |
| 2760 | if (!may_need_runtime_call_for_type_check) { |
| 2761 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2762 | } |
| 2763 | |
| 2764 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 2765 | |
| 2766 | if (done.IsLinked()) { |
| 2767 | __ Bind(&done); |
| 2768 | } |
| 2769 | |
| 2770 | if (slow_path != nullptr) { |
| 2771 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2772 | } |
| 2773 | break; |
| 2774 | } |
| 2775 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2776 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2777 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2778 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2779 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2780 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2781 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2782 | } |
| 2783 | if (value_location.IsConstant()) { |
| 2784 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2785 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2786 | } else { |
| 2787 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2788 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2789 | } |
| 2790 | break; |
| 2791 | } |
| 2792 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2793 | case DataType::Type::kFloat32: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2794 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2795 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2796 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2797 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2798 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2799 | } |
| 2800 | if (value_location.IsConstant()) { |
| 2801 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2802 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2803 | } else { |
| 2804 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2805 | __ StoreFpuToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2806 | } |
| 2807 | break; |
| 2808 | } |
| 2809 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2810 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2811 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2812 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2813 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2814 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2815 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2816 | } |
| 2817 | if (value_location.IsConstant()) { |
| 2818 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2819 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2820 | } else { |
| 2821 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2822 | __ StoreFpuToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2823 | } |
| 2824 | break; |
| 2825 | } |
| 2826 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2827 | case DataType::Type::kUint32: |
| 2828 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2829 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2830 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2831 | UNREACHABLE(); |
| 2832 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2836 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2837 | InvokeRuntimeCallingConvention calling_convention; |
| 2838 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2839 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2840 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2841 | |
| 2842 | HInstruction* index = instruction->InputAt(0); |
| 2843 | HInstruction* length = instruction->InputAt(1); |
| 2844 | |
| 2845 | bool const_index = false; |
| 2846 | bool const_length = false; |
| 2847 | |
| 2848 | if (index->IsConstant()) { |
| 2849 | if (length->IsConstant()) { |
| 2850 | const_index = true; |
| 2851 | const_length = true; |
| 2852 | } else { |
| 2853 | int32_t index_value = index->AsIntConstant()->GetValue(); |
| 2854 | if (index_value < 0 || IsInt<16>(index_value + 1)) { |
| 2855 | const_index = true; |
| 2856 | } |
| 2857 | } |
| 2858 | } else if (length->IsConstant()) { |
| 2859 | int32_t length_value = length->AsIntConstant()->GetValue(); |
| 2860 | if (IsUint<15>(length_value)) { |
| 2861 | const_length = true; |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | locations->SetInAt(0, const_index |
| 2866 | ? Location::ConstantLocation(index->AsConstant()) |
| 2867 | : Location::RequiresRegister()); |
| 2868 | locations->SetInAt(1, const_length |
| 2869 | ? Location::ConstantLocation(length->AsConstant()) |
| 2870 | : Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2874 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2875 | Location index_loc = locations->InAt(0); |
| 2876 | Location length_loc = locations->InAt(1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2877 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2878 | if (length_loc.IsConstant()) { |
| 2879 | int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 2880 | if (index_loc.IsConstant()) { |
| 2881 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 2882 | if (index < 0 || index >= length) { |
| 2883 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2884 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction); |
| 2885 | codegen_->AddSlowPath(slow_path); |
| 2886 | __ Bc(slow_path->GetEntryLabel()); |
| 2887 | } else { |
| 2888 | // Nothing to be done. |
| 2889 | } |
| 2890 | return; |
| 2891 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2892 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2893 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2894 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction); |
| 2895 | codegen_->AddSlowPath(slow_path); |
| 2896 | GpuRegister index = index_loc.AsRegister<GpuRegister>(); |
| 2897 | if (length == 0) { |
| 2898 | __ Bc(slow_path->GetEntryLabel()); |
| 2899 | } else if (length == 1) { |
| 2900 | __ Bnezc(index, slow_path->GetEntryLabel()); |
| 2901 | } else { |
| 2902 | DCHECK(IsUint<15>(length)) << length; |
| 2903 | __ Sltiu(TMP, index, length); |
| 2904 | __ Beqzc(TMP, slow_path->GetEntryLabel()); |
| 2905 | } |
| 2906 | } else { |
| 2907 | GpuRegister length = length_loc.AsRegister<GpuRegister>(); |
| 2908 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2909 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction); |
| 2910 | codegen_->AddSlowPath(slow_path); |
| 2911 | if (index_loc.IsConstant()) { |
| 2912 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 2913 | if (index < 0) { |
| 2914 | __ Bc(slow_path->GetEntryLabel()); |
| 2915 | } else if (index == 0) { |
| 2916 | __ Blezc(length, slow_path->GetEntryLabel()); |
| 2917 | } else { |
| 2918 | DCHECK(IsInt<16>(index + 1)) << index; |
| 2919 | __ Sltiu(TMP, length, index + 1); |
| 2920 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 2921 | } |
| 2922 | } else { |
| 2923 | GpuRegister index = index_loc.AsRegister<GpuRegister>(); |
| 2924 | __ Bgeuc(index, length, slow_path->GetEntryLabel()); |
| 2925 | } |
| 2926 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2929 | // Temp is used for read barrier. |
| 2930 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 2931 | if (kEmitCompilerReadBarrier && |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2932 | !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) && |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2933 | (kUseBakerReadBarrier || |
| 2934 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2935 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2936 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 2937 | return 1; |
| 2938 | } |
| 2939 | return 0; |
| 2940 | } |
| 2941 | |
| 2942 | // Extra temp is used for read barrier. |
| 2943 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 2944 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 2945 | } |
| 2946 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2947 | void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2948 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 2949 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2950 | LocationSummary* locations = |
| 2951 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2952 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2953 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 2954 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 2955 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 2956 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 2957 | } else { |
| 2958 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2959 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2960 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2964 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2965 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2966 | Location obj_loc = locations->InAt(0); |
| 2967 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2968 | Location cls = locations->InAt(1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2969 | Location temp_loc = locations->GetTemp(0); |
| 2970 | GpuRegister temp = temp_loc.AsRegister<GpuRegister>(); |
| 2971 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 2972 | DCHECK_LE(num_temps, 2u); |
| 2973 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2974 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2975 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2976 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2977 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 2978 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 2979 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 2980 | const uint32_t object_array_data_offset = |
| 2981 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 2982 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2983 | |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 2984 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2985 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2986 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( |
| 2987 | instruction, is_type_check_slow_path_fatal); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2988 | codegen_->AddSlowPath(slow_path); |
| 2989 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2990 | // Avoid this check if we know `obj` is not null. |
| 2991 | if (instruction->MustDoNullCheck()) { |
| 2992 | __ Beqzc(obj, &done); |
| 2993 | } |
| 2994 | |
| 2995 | switch (type_check_kind) { |
| 2996 | case TypeCheckKind::kExactCheck: |
| 2997 | case TypeCheckKind::kArrayCheck: { |
| 2998 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2999 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3000 | temp_loc, |
| 3001 | obj_loc, |
| 3002 | class_offset, |
| 3003 | maybe_temp2_loc, |
| 3004 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3005 | // Jump to slow path for throwing the exception or doing a |
| 3006 | // more involved array check. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3007 | __ Bnec(temp, cls.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3008 | break; |
| 3009 | } |
| 3010 | |
| 3011 | case TypeCheckKind::kAbstractClassCheck: { |
| 3012 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3013 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3014 | temp_loc, |
| 3015 | obj_loc, |
| 3016 | class_offset, |
| 3017 | maybe_temp2_loc, |
| 3018 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3019 | // If the class is abstract, we eagerly fetch the super class of the |
| 3020 | // object to avoid doing a comparison we know will fail. |
| 3021 | Mips64Label loop; |
| 3022 | __ Bind(&loop); |
| 3023 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3024 | GenerateReferenceLoadOneRegister(instruction, |
| 3025 | temp_loc, |
| 3026 | super_offset, |
| 3027 | maybe_temp2_loc, |
| 3028 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3029 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3030 | // exception. |
| 3031 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 3032 | // Otherwise, compare the classes. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3033 | __ Bnec(temp, cls.AsRegister<GpuRegister>(), &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3034 | break; |
| 3035 | } |
| 3036 | |
| 3037 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3038 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3039 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3040 | temp_loc, |
| 3041 | obj_loc, |
| 3042 | class_offset, |
| 3043 | maybe_temp2_loc, |
| 3044 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3045 | // Walk over the class hierarchy to find a match. |
| 3046 | Mips64Label loop; |
| 3047 | __ Bind(&loop); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3048 | __ Beqc(temp, cls.AsRegister<GpuRegister>(), &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3049 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3050 | GenerateReferenceLoadOneRegister(instruction, |
| 3051 | temp_loc, |
| 3052 | super_offset, |
| 3053 | maybe_temp2_loc, |
| 3054 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3055 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3056 | // exception. Otherwise, jump to the beginning of the loop. |
| 3057 | __ Bnezc(temp, &loop); |
| 3058 | __ Bc(slow_path->GetEntryLabel()); |
| 3059 | break; |
| 3060 | } |
| 3061 | |
| 3062 | case TypeCheckKind::kArrayObjectCheck: { |
| 3063 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3064 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3065 | temp_loc, |
| 3066 | obj_loc, |
| 3067 | class_offset, |
| 3068 | maybe_temp2_loc, |
| 3069 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3070 | // Do an exact check. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3071 | __ Beqc(temp, cls.AsRegister<GpuRegister>(), &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3072 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 3073 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3074 | GenerateReferenceLoadOneRegister(instruction, |
| 3075 | temp_loc, |
| 3076 | component_offset, |
| 3077 | maybe_temp2_loc, |
| 3078 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3079 | // If the component type is null, jump to the slow path to throw the exception. |
| 3080 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 3081 | // Otherwise, the object is indeed an array, further check that this component |
| 3082 | // type is not a primitive type. |
| 3083 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 3084 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3085 | __ Bnezc(temp, slow_path->GetEntryLabel()); |
| 3086 | break; |
| 3087 | } |
| 3088 | |
| 3089 | case TypeCheckKind::kUnresolvedCheck: |
| 3090 | // We always go into the type check slow path for the unresolved check case. |
| 3091 | // We cannot directly call the CheckCast runtime entry point |
| 3092 | // without resorting to a type checking slow path here (i.e. by |
| 3093 | // calling InvokeRuntime directly), as it would require to |
| 3094 | // assign fixed registers for the inputs of this HInstanceOf |
| 3095 | // instruction (following the runtime calling convention), which |
| 3096 | // might be cluttered by the potential first read barrier |
| 3097 | // emission at the beginning of this method. |
| 3098 | __ Bc(slow_path->GetEntryLabel()); |
| 3099 | break; |
| 3100 | |
| 3101 | case TypeCheckKind::kInterfaceCheck: { |
| 3102 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 3103 | // positives by doing this. |
| 3104 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3105 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3106 | temp_loc, |
| 3107 | obj_loc, |
| 3108 | class_offset, |
| 3109 | maybe_temp2_loc, |
| 3110 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3111 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3112 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3113 | temp_loc, |
| 3114 | temp_loc, |
| 3115 | iftable_offset, |
| 3116 | maybe_temp2_loc, |
| 3117 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3118 | // Iftable is never null. |
| 3119 | __ Lw(TMP, temp, array_length_offset); |
| 3120 | // Loop through the iftable and check if any class matches. |
| 3121 | Mips64Label loop; |
| 3122 | __ Bind(&loop); |
| 3123 | __ Beqzc(TMP, slow_path->GetEntryLabel()); |
| 3124 | __ Lwu(AT, temp, object_array_data_offset); |
| 3125 | __ MaybeUnpoisonHeapReference(AT); |
| 3126 | // Go to next interface. |
| 3127 | __ Daddiu(temp, temp, 2 * kHeapReferenceSize); |
| 3128 | __ Addiu(TMP, TMP, -2); |
| 3129 | // Compare the classes and continue the loop if they do not match. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3130 | __ Bnec(AT, cls.AsRegister<GpuRegister>(), &loop); |
| 3131 | break; |
| 3132 | } |
| 3133 | |
| 3134 | case TypeCheckKind::kBitstringCheck: { |
| 3135 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3136 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3137 | temp_loc, |
| 3138 | obj_loc, |
| 3139 | class_offset, |
| 3140 | maybe_temp2_loc, |
| 3141 | kWithoutReadBarrier); |
| 3142 | |
| 3143 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 3144 | __ Bnezc(temp, slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3145 | break; |
| 3146 | } |
| 3147 | } |
| 3148 | |
| 3149 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3150 | __ Bind(slow_path->GetExitLabel()); |
| 3151 | } |
| 3152 | |
| 3153 | void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 3154 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3155 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3156 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3157 | if (check->HasUses()) { |
| 3158 | locations->SetOut(Location::SameAsFirstInput()); |
| 3159 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame^] | 3160 | // Rely on the type initialization to save everything we need. |
| 3161 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 3165 | // We assume the class is not null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 3166 | SlowPathCodeMIPS64* slow_path = |
| 3167 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64(check->GetLoadClass(), check); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3168 | codegen_->AddSlowPath(slow_path); |
| 3169 | GenerateClassInitializationCheck(slow_path, |
| 3170 | check->GetLocations()->InAt(0).AsRegister<GpuRegister>()); |
| 3171 | } |
| 3172 | |
| 3173 | void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3174 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3175 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3176 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(compare); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3177 | |
| 3178 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3179 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3180 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3181 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3182 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3183 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3184 | case DataType::Type::kInt32: |
| 3185 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3186 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3187 | locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3188 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3189 | break; |
| 3190 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3191 | case DataType::Type::kFloat32: |
| 3192 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3193 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3194 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3195 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3196 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3197 | |
| 3198 | default: |
| 3199 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) { |
| 3204 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3205 | GpuRegister res = locations->Out().AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3206 | DataType::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3207 | |
| 3208 | // 0 if: left == right |
| 3209 | // 1 if: left > right |
| 3210 | // -1 if: left < right |
| 3211 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3212 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3213 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3214 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3215 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3216 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3217 | case DataType::Type::kInt32: |
| 3218 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3219 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3220 | Location rhs_location = locations->InAt(1); |
| 3221 | bool use_imm = rhs_location.IsConstant(); |
| 3222 | GpuRegister rhs = ZERO; |
| 3223 | if (use_imm) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3224 | if (in_type == DataType::Type::kInt64) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3225 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 3226 | if (value != 0) { |
| 3227 | rhs = AT; |
| 3228 | __ LoadConst64(rhs, value); |
| 3229 | } |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3230 | } else { |
| 3231 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 3232 | if (value != 0) { |
| 3233 | rhs = AT; |
| 3234 | __ LoadConst32(rhs, value); |
| 3235 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3236 | } |
| 3237 | } else { |
| 3238 | rhs = rhs_location.AsRegister<GpuRegister>(); |
| 3239 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3240 | __ Slt(TMP, lhs, rhs); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3241 | __ Slt(res, rhs, lhs); |
| 3242 | __ Subu(res, res, TMP); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3243 | break; |
| 3244 | } |
| 3245 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3246 | case DataType::Type::kFloat32: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3247 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3248 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3249 | Mips64Label done; |
| 3250 | __ CmpEqS(FTMP, lhs, rhs); |
| 3251 | __ LoadConst32(res, 0); |
| 3252 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3253 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3254 | __ CmpLtS(FTMP, lhs, rhs); |
| 3255 | __ LoadConst32(res, -1); |
| 3256 | __ Bc1nez(FTMP, &done); |
| 3257 | __ LoadConst32(res, 1); |
| 3258 | } else { |
| 3259 | __ CmpLtS(FTMP, rhs, lhs); |
| 3260 | __ LoadConst32(res, 1); |
| 3261 | __ Bc1nez(FTMP, &done); |
| 3262 | __ LoadConst32(res, -1); |
| 3263 | } |
| 3264 | __ Bind(&done); |
| 3265 | break; |
| 3266 | } |
| 3267 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3268 | case DataType::Type::kFloat64: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3269 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3270 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3271 | Mips64Label done; |
| 3272 | __ CmpEqD(FTMP, lhs, rhs); |
| 3273 | __ LoadConst32(res, 0); |
| 3274 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3275 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3276 | __ CmpLtD(FTMP, lhs, rhs); |
| 3277 | __ LoadConst32(res, -1); |
| 3278 | __ Bc1nez(FTMP, &done); |
| 3279 | __ LoadConst32(res, 1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3280 | } else { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3281 | __ CmpLtD(FTMP, rhs, lhs); |
| 3282 | __ LoadConst32(res, 1); |
| 3283 | __ Bc1nez(FTMP, &done); |
| 3284 | __ LoadConst32(res, -1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3285 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3286 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3287 | break; |
| 3288 | } |
| 3289 | |
| 3290 | default: |
| 3291 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3292 | } |
| 3293 | } |
| 3294 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3295 | void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3296 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3297 | switch (instruction->InputAt(0)->GetType()) { |
| 3298 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3299 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3300 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3301 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3302 | break; |
| 3303 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3304 | case DataType::Type::kFloat32: |
| 3305 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3306 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3307 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3308 | break; |
| 3309 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3310 | if (!instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3311 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3312 | } |
| 3313 | } |
| 3314 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3315 | void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3316 | if (instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3317 | return; |
| 3318 | } |
| 3319 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3320 | DataType::Type type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3321 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3322 | switch (type) { |
| 3323 | default: |
| 3324 | // Integer case. |
| 3325 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations); |
| 3326 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3327 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3328 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations); |
| 3329 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3330 | case DataType::Type::kFloat32: |
| 3331 | case DataType::Type::kFloat64: |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3332 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 3333 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3334 | } |
| 3335 | } |
| 3336 | |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3337 | void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3338 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3339 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3340 | |
| 3341 | LocationSummary* locations = instruction->GetLocations(); |
| 3342 | Location second = locations->InAt(1); |
| 3343 | DCHECK(second.IsConstant()); |
| 3344 | |
| 3345 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3346 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3347 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3348 | DCHECK(imm == 1 || imm == -1); |
| 3349 | |
| 3350 | if (instruction->IsRem()) { |
| 3351 | __ Move(out, ZERO); |
| 3352 | } else { |
| 3353 | if (imm == -1) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3354 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3355 | __ Subu(out, ZERO, dividend); |
| 3356 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3357 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3358 | __ Dsubu(out, ZERO, dividend); |
| 3359 | } |
| 3360 | } else if (out != dividend) { |
| 3361 | __ Move(out, dividend); |
| 3362 | } |
| 3363 | } |
| 3364 | } |
| 3365 | |
| 3366 | void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3367 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3368 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3369 | |
| 3370 | LocationSummary* locations = instruction->GetLocations(); |
| 3371 | Location second = locations->InAt(1); |
| 3372 | DCHECK(second.IsConstant()); |
| 3373 | |
| 3374 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3375 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3376 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3377 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3378 | int ctz_imm = CTZ(abs_imm); |
| 3379 | |
| 3380 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3381 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3382 | if (ctz_imm == 1) { |
| 3383 | // Fast path for division by +/-2, which is very common. |
| 3384 | __ Srl(TMP, dividend, 31); |
| 3385 | } else { |
| 3386 | __ Sra(TMP, dividend, 31); |
| 3387 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3388 | } |
| 3389 | __ Addu(out, dividend, TMP); |
| 3390 | __ Sra(out, out, ctz_imm); |
| 3391 | if (imm < 0) { |
| 3392 | __ Subu(out, ZERO, out); |
| 3393 | } |
| 3394 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3395 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3396 | if (ctz_imm == 1) { |
| 3397 | // Fast path for division by +/-2, which is very common. |
| 3398 | __ Dsrl32(TMP, dividend, 31); |
| 3399 | } else { |
| 3400 | __ Dsra32(TMP, dividend, 31); |
| 3401 | if (ctz_imm > 32) { |
| 3402 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3403 | } else { |
| 3404 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3405 | } |
| 3406 | } |
| 3407 | __ Daddu(out, dividend, TMP); |
| 3408 | if (ctz_imm < 32) { |
| 3409 | __ Dsra(out, out, ctz_imm); |
| 3410 | } else { |
| 3411 | __ Dsra32(out, out, ctz_imm - 32); |
| 3412 | } |
| 3413 | if (imm < 0) { |
| 3414 | __ Dsubu(out, ZERO, out); |
| 3415 | } |
| 3416 | } |
| 3417 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3418 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3419 | if (ctz_imm == 1) { |
| 3420 | // Fast path for modulo +/-2, which is very common. |
| 3421 | __ Sra(TMP, dividend, 31); |
| 3422 | __ Subu(out, dividend, TMP); |
| 3423 | __ Andi(out, out, 1); |
| 3424 | __ Addu(out, out, TMP); |
| 3425 | } else { |
| 3426 | __ Sra(TMP, dividend, 31); |
| 3427 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3428 | __ Addu(out, dividend, TMP); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3429 | __ Ins(out, ZERO, ctz_imm, 32 - ctz_imm); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3430 | __ Subu(out, out, TMP); |
| 3431 | } |
| 3432 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3433 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3434 | if (ctz_imm == 1) { |
| 3435 | // Fast path for modulo +/-2, which is very common. |
| 3436 | __ Dsra32(TMP, dividend, 31); |
| 3437 | __ Dsubu(out, dividend, TMP); |
| 3438 | __ Andi(out, out, 1); |
| 3439 | __ Daddu(out, out, TMP); |
| 3440 | } else { |
| 3441 | __ Dsra32(TMP, dividend, 31); |
| 3442 | if (ctz_imm > 32) { |
| 3443 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3444 | } else { |
| 3445 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3446 | } |
| 3447 | __ Daddu(out, dividend, TMP); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3448 | __ DblIns(out, ZERO, ctz_imm, 64 - ctz_imm); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3449 | __ Dsubu(out, out, TMP); |
| 3450 | } |
| 3451 | } |
| 3452 | } |
| 3453 | } |
| 3454 | |
| 3455 | void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3456 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3457 | |
| 3458 | LocationSummary* locations = instruction->GetLocations(); |
| 3459 | Location second = locations->InAt(1); |
| 3460 | DCHECK(second.IsConstant()); |
| 3461 | |
| 3462 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3463 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3464 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3465 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3466 | DataType::Type type = instruction->GetResultType(); |
| 3467 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type; |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3468 | |
| 3469 | int64_t magic; |
| 3470 | int shift; |
| 3471 | CalculateMagicAndShiftForDivRem(imm, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3472 | (type == DataType::Type::kInt64), |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3473 | &magic, |
| 3474 | &shift); |
| 3475 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3476 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3477 | __ LoadConst32(TMP, magic); |
| 3478 | __ MuhR6(TMP, dividend, TMP); |
| 3479 | |
| 3480 | if (imm > 0 && magic < 0) { |
| 3481 | __ Addu(TMP, TMP, dividend); |
| 3482 | } else if (imm < 0 && magic > 0) { |
| 3483 | __ Subu(TMP, TMP, dividend); |
| 3484 | } |
| 3485 | |
| 3486 | if (shift != 0) { |
| 3487 | __ Sra(TMP, TMP, shift); |
| 3488 | } |
| 3489 | |
| 3490 | if (instruction->IsDiv()) { |
| 3491 | __ Sra(out, TMP, 31); |
| 3492 | __ Subu(out, TMP, out); |
| 3493 | } else { |
| 3494 | __ Sra(AT, TMP, 31); |
| 3495 | __ Subu(AT, TMP, AT); |
| 3496 | __ LoadConst32(TMP, imm); |
| 3497 | __ MulR6(TMP, AT, TMP); |
| 3498 | __ Subu(out, dividend, TMP); |
| 3499 | } |
| 3500 | } else { |
| 3501 | __ LoadConst64(TMP, magic); |
| 3502 | __ Dmuh(TMP, dividend, TMP); |
| 3503 | |
| 3504 | if (imm > 0 && magic < 0) { |
| 3505 | __ Daddu(TMP, TMP, dividend); |
| 3506 | } else if (imm < 0 && magic > 0) { |
| 3507 | __ Dsubu(TMP, TMP, dividend); |
| 3508 | } |
| 3509 | |
| 3510 | if (shift >= 32) { |
| 3511 | __ Dsra32(TMP, TMP, shift - 32); |
| 3512 | } else if (shift > 0) { |
| 3513 | __ Dsra(TMP, TMP, shift); |
| 3514 | } |
| 3515 | |
| 3516 | if (instruction->IsDiv()) { |
| 3517 | __ Dsra32(out, TMP, 31); |
| 3518 | __ Dsubu(out, TMP, out); |
| 3519 | } else { |
| 3520 | __ Dsra32(AT, TMP, 31); |
| 3521 | __ Dsubu(AT, TMP, AT); |
| 3522 | __ LoadConst64(TMP, imm); |
| 3523 | __ Dmul(TMP, AT, TMP); |
| 3524 | __ Dsubu(out, dividend, TMP); |
| 3525 | } |
| 3526 | } |
| 3527 | } |
| 3528 | |
| 3529 | void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3530 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3531 | DataType::Type type = instruction->GetResultType(); |
| 3532 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type; |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3533 | |
| 3534 | LocationSummary* locations = instruction->GetLocations(); |
| 3535 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3536 | Location second = locations->InAt(1); |
| 3537 | |
| 3538 | if (second.IsConstant()) { |
| 3539 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3540 | if (imm == 0) { |
| 3541 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3542 | } else if (imm == 1 || imm == -1) { |
| 3543 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3544 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3545 | DivRemByPowerOfTwo(instruction); |
| 3546 | } else { |
| 3547 | DCHECK(imm <= -2 || imm >= 2); |
| 3548 | GenerateDivRemWithAnyConstant(instruction); |
| 3549 | } |
| 3550 | } else { |
| 3551 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3552 | GpuRegister divisor = second.AsRegister<GpuRegister>(); |
| 3553 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3554 | if (type == DataType::Type::kInt32) |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3555 | __ DivR6(out, dividend, divisor); |
| 3556 | else |
| 3557 | __ Ddiv(out, dividend, divisor); |
| 3558 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3559 | if (type == DataType::Type::kInt32) |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3560 | __ ModR6(out, dividend, divisor); |
| 3561 | else |
| 3562 | __ Dmod(out, dividend, divisor); |
| 3563 | } |
| 3564 | } |
| 3565 | } |
| 3566 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3567 | void LocationsBuilderMIPS64::VisitDiv(HDiv* div) { |
| 3568 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3569 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3570 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3571 | case DataType::Type::kInt32: |
| 3572 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3573 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3574 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3575 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3576 | break; |
| 3577 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3578 | case DataType::Type::kFloat32: |
| 3579 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3580 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3581 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3582 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3583 | break; |
| 3584 | |
| 3585 | default: |
| 3586 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3587 | } |
| 3588 | } |
| 3589 | |
| 3590 | void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3591 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3592 | LocationSummary* locations = instruction->GetLocations(); |
| 3593 | |
| 3594 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3595 | case DataType::Type::kInt32: |
| 3596 | case DataType::Type::kInt64: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3597 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3598 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3599 | case DataType::Type::kFloat32: |
| 3600 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3601 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 3602 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3603 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3604 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3605 | __ DivS(dst, lhs, rhs); |
| 3606 | else |
| 3607 | __ DivD(dst, lhs, rhs); |
| 3608 | break; |
| 3609 | } |
| 3610 | default: |
| 3611 | LOG(FATAL) << "Unexpected div type " << type; |
| 3612 | } |
| 3613 | } |
| 3614 | |
| 3615 | void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3616 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3617 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3618 | } |
| 3619 | |
| 3620 | void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3621 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3622 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS64(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3623 | codegen_->AddSlowPath(slow_path); |
| 3624 | Location value = instruction->GetLocations()->InAt(0); |
| 3625 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3626 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3627 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3628 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3629 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3630 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3631 | } |
| 3632 | |
| 3633 | if (value.IsConstant()) { |
| 3634 | int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant()); |
| 3635 | if (divisor == 0) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3636 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3637 | } else { |
| 3638 | // A division by a non-null constant is valid. We don't need to perform |
| 3639 | // any check, so simply fall through. |
| 3640 | } |
| 3641 | } else { |
| 3642 | __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 3643 | } |
| 3644 | } |
| 3645 | |
| 3646 | void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3647 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3648 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3649 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3650 | } |
| 3651 | |
| 3652 | void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 3653 | // Will be generated at use site. |
| 3654 | } |
| 3655 | |
| 3656 | void LocationsBuilderMIPS64::VisitExit(HExit* exit) { |
| 3657 | exit->SetLocations(nullptr); |
| 3658 | } |
| 3659 | |
| 3660 | void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 3661 | } |
| 3662 | |
| 3663 | void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) { |
| 3664 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3665 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3666 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3667 | } |
| 3668 | |
| 3669 | void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 3670 | // Will be generated at use site. |
| 3671 | } |
| 3672 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3673 | void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3674 | if (successor->IsExitBlock()) { |
| 3675 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3676 | return; // no code needed |
| 3677 | } |
| 3678 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3679 | HBasicBlock* block = got->GetBlock(); |
| 3680 | HInstruction* previous = got->GetPrevious(); |
| 3681 | HLoopInformation* info = block->GetLoopInformation(); |
| 3682 | |
| 3683 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Goran Jakovljevic | feec167 | 2018-02-08 10:20:14 +0100 | [diff] [blame] | 3684 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 3685 | __ Ld(AT, SP, kCurrentMethodStackOffset); |
| 3686 | __ Lhu(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value()); |
| 3687 | __ Addiu(TMP, TMP, 1); |
| 3688 | __ Sh(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value()); |
| 3689 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3690 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3691 | return; |
| 3692 | } |
| 3693 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3694 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3695 | } |
| 3696 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3697 | __ Bc(codegen_->GetLabelOf(successor)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3698 | } |
| 3699 | } |
| 3700 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3701 | void LocationsBuilderMIPS64::VisitGoto(HGoto* got) { |
| 3702 | got->SetLocations(nullptr); |
| 3703 | } |
| 3704 | |
| 3705 | void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) { |
| 3706 | HandleGoto(got, got->GetSuccessor()); |
| 3707 | } |
| 3708 | |
| 3709 | void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3710 | try_boundary->SetLocations(nullptr); |
| 3711 | } |
| 3712 | |
| 3713 | void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3714 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3715 | if (!successor->IsExitBlock()) { |
| 3716 | HandleGoto(try_boundary, successor); |
| 3717 | } |
| 3718 | } |
| 3719 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3720 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond, |
| 3721 | bool is64bit, |
| 3722 | LocationSummary* locations) { |
| 3723 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3724 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3725 | Location rhs_location = locations->InAt(1); |
| 3726 | GpuRegister rhs_reg = ZERO; |
| 3727 | int64_t rhs_imm = 0; |
| 3728 | bool use_imm = rhs_location.IsConstant(); |
| 3729 | if (use_imm) { |
| 3730 | if (is64bit) { |
| 3731 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3732 | } else { |
| 3733 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3734 | } |
| 3735 | } else { |
| 3736 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3737 | } |
| 3738 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 3739 | |
| 3740 | switch (cond) { |
| 3741 | case kCondEQ: |
| 3742 | case kCondNE: |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3743 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3744 | if (rhs_imm == 0) { |
| 3745 | if (cond == kCondEQ) { |
| 3746 | __ Sltiu(dst, lhs, 1); |
| 3747 | } else { |
| 3748 | __ Sltu(dst, ZERO, lhs); |
| 3749 | } |
| 3750 | } else { |
| 3751 | if (is64bit) { |
| 3752 | __ Daddiu(dst, lhs, -rhs_imm); |
| 3753 | } else { |
| 3754 | __ Addiu(dst, lhs, -rhs_imm); |
| 3755 | } |
| 3756 | if (cond == kCondEQ) { |
| 3757 | __ Sltiu(dst, dst, 1); |
| 3758 | } else { |
| 3759 | __ Sltu(dst, ZERO, dst); |
| 3760 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3761 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3762 | } else { |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3763 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 3764 | __ Xori(dst, lhs, rhs_imm); |
| 3765 | } else { |
| 3766 | if (use_imm) { |
| 3767 | rhs_reg = TMP; |
| 3768 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3769 | } |
| 3770 | __ Xor(dst, lhs, rhs_reg); |
| 3771 | } |
| 3772 | if (cond == kCondEQ) { |
| 3773 | __ Sltiu(dst, dst, 1); |
| 3774 | } else { |
| 3775 | __ Sltu(dst, ZERO, dst); |
| 3776 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3777 | } |
| 3778 | break; |
| 3779 | |
| 3780 | case kCondLT: |
| 3781 | case kCondGE: |
| 3782 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3783 | __ Slti(dst, lhs, rhs_imm); |
| 3784 | } else { |
| 3785 | if (use_imm) { |
| 3786 | rhs_reg = TMP; |
| 3787 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3788 | } |
| 3789 | __ Slt(dst, lhs, rhs_reg); |
| 3790 | } |
| 3791 | if (cond == kCondGE) { |
| 3792 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3793 | // only the slt instruction but no sge. |
| 3794 | __ Xori(dst, dst, 1); |
| 3795 | } |
| 3796 | break; |
| 3797 | |
| 3798 | case kCondLE: |
| 3799 | case kCondGT: |
| 3800 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 3801 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3802 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 3803 | if (cond == kCondGT) { |
| 3804 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3805 | // only the slti instruction but no sgti. |
| 3806 | __ Xori(dst, dst, 1); |
| 3807 | } |
| 3808 | } else { |
| 3809 | if (use_imm) { |
| 3810 | rhs_reg = TMP; |
| 3811 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3812 | } |
| 3813 | __ Slt(dst, rhs_reg, lhs); |
| 3814 | if (cond == kCondLE) { |
| 3815 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3816 | // only the slt instruction but no sle. |
| 3817 | __ Xori(dst, dst, 1); |
| 3818 | } |
| 3819 | } |
| 3820 | break; |
| 3821 | |
| 3822 | case kCondB: |
| 3823 | case kCondAE: |
| 3824 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3825 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3826 | // the comparison and thus lets us compare directly with |
| 3827 | // unsigned values in the ranges [0, 0x7fff] and |
| 3828 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3829 | __ Sltiu(dst, lhs, rhs_imm); |
| 3830 | } else { |
| 3831 | if (use_imm) { |
| 3832 | rhs_reg = TMP; |
| 3833 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3834 | } |
| 3835 | __ Sltu(dst, lhs, rhs_reg); |
| 3836 | } |
| 3837 | if (cond == kCondAE) { |
| 3838 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3839 | // only the sltu instruction but no sgeu. |
| 3840 | __ Xori(dst, dst, 1); |
| 3841 | } |
| 3842 | break; |
| 3843 | |
| 3844 | case kCondBE: |
| 3845 | case kCondA: |
| 3846 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 3847 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3848 | // Note that this only works if rhs + 1 does not overflow |
| 3849 | // to 0, hence the check above. |
| 3850 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3851 | // the comparison and thus lets us compare directly with |
| 3852 | // unsigned values in the ranges [0, 0x7fff] and |
| 3853 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3854 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 3855 | if (cond == kCondA) { |
| 3856 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3857 | // only the sltiu instruction but no sgtiu. |
| 3858 | __ Xori(dst, dst, 1); |
| 3859 | } |
| 3860 | } else { |
| 3861 | if (use_imm) { |
| 3862 | rhs_reg = TMP; |
| 3863 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3864 | } |
| 3865 | __ Sltu(dst, rhs_reg, lhs); |
| 3866 | if (cond == kCondBE) { |
| 3867 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3868 | // only the sltu instruction but no sleu. |
| 3869 | __ Xori(dst, dst, 1); |
| 3870 | } |
| 3871 | } |
| 3872 | break; |
| 3873 | } |
| 3874 | } |
| 3875 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 3876 | bool InstructionCodeGeneratorMIPS64::MaterializeIntLongCompare(IfCondition cond, |
| 3877 | bool is64bit, |
| 3878 | LocationSummary* input_locations, |
| 3879 | GpuRegister dst) { |
| 3880 | GpuRegister lhs = input_locations->InAt(0).AsRegister<GpuRegister>(); |
| 3881 | Location rhs_location = input_locations->InAt(1); |
| 3882 | GpuRegister rhs_reg = ZERO; |
| 3883 | int64_t rhs_imm = 0; |
| 3884 | bool use_imm = rhs_location.IsConstant(); |
| 3885 | if (use_imm) { |
| 3886 | if (is64bit) { |
| 3887 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3888 | } else { |
| 3889 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3890 | } |
| 3891 | } else { |
| 3892 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3893 | } |
| 3894 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 3895 | |
| 3896 | switch (cond) { |
| 3897 | case kCondEQ: |
| 3898 | case kCondNE: |
| 3899 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3900 | if (is64bit) { |
| 3901 | __ Daddiu(dst, lhs, -rhs_imm); |
| 3902 | } else { |
| 3903 | __ Addiu(dst, lhs, -rhs_imm); |
| 3904 | } |
| 3905 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 3906 | __ Xori(dst, lhs, rhs_imm); |
| 3907 | } else { |
| 3908 | if (use_imm) { |
| 3909 | rhs_reg = TMP; |
| 3910 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3911 | } |
| 3912 | __ Xor(dst, lhs, rhs_reg); |
| 3913 | } |
| 3914 | return (cond == kCondEQ); |
| 3915 | |
| 3916 | case kCondLT: |
| 3917 | case kCondGE: |
| 3918 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3919 | __ Slti(dst, lhs, rhs_imm); |
| 3920 | } else { |
| 3921 | if (use_imm) { |
| 3922 | rhs_reg = TMP; |
| 3923 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3924 | } |
| 3925 | __ Slt(dst, lhs, rhs_reg); |
| 3926 | } |
| 3927 | return (cond == kCondGE); |
| 3928 | |
| 3929 | case kCondLE: |
| 3930 | case kCondGT: |
| 3931 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 3932 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3933 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 3934 | return (cond == kCondGT); |
| 3935 | } else { |
| 3936 | if (use_imm) { |
| 3937 | rhs_reg = TMP; |
| 3938 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3939 | } |
| 3940 | __ Slt(dst, rhs_reg, lhs); |
| 3941 | return (cond == kCondLE); |
| 3942 | } |
| 3943 | |
| 3944 | case kCondB: |
| 3945 | case kCondAE: |
| 3946 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3947 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3948 | // the comparison and thus lets us compare directly with |
| 3949 | // unsigned values in the ranges [0, 0x7fff] and |
| 3950 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3951 | __ Sltiu(dst, lhs, rhs_imm); |
| 3952 | } else { |
| 3953 | if (use_imm) { |
| 3954 | rhs_reg = TMP; |
| 3955 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3956 | } |
| 3957 | __ Sltu(dst, lhs, rhs_reg); |
| 3958 | } |
| 3959 | return (cond == kCondAE); |
| 3960 | |
| 3961 | case kCondBE: |
| 3962 | case kCondA: |
| 3963 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 3964 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3965 | // Note that this only works if rhs + 1 does not overflow |
| 3966 | // to 0, hence the check above. |
| 3967 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3968 | // the comparison and thus lets us compare directly with |
| 3969 | // unsigned values in the ranges [0, 0x7fff] and |
| 3970 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3971 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 3972 | return (cond == kCondA); |
| 3973 | } else { |
| 3974 | if (use_imm) { |
| 3975 | rhs_reg = TMP; |
| 3976 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3977 | } |
| 3978 | __ Sltu(dst, rhs_reg, lhs); |
| 3979 | return (cond == kCondBE); |
| 3980 | } |
| 3981 | } |
| 3982 | } |
| 3983 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3984 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond, |
| 3985 | bool is64bit, |
| 3986 | LocationSummary* locations, |
| 3987 | Mips64Label* label) { |
| 3988 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3989 | Location rhs_location = locations->InAt(1); |
| 3990 | GpuRegister rhs_reg = ZERO; |
| 3991 | int64_t rhs_imm = 0; |
| 3992 | bool use_imm = rhs_location.IsConstant(); |
| 3993 | if (use_imm) { |
| 3994 | if (is64bit) { |
| 3995 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3996 | } else { |
| 3997 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3998 | } |
| 3999 | } else { |
| 4000 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 4001 | } |
| 4002 | |
| 4003 | if (use_imm && rhs_imm == 0) { |
| 4004 | switch (cond) { |
| 4005 | case kCondEQ: |
| 4006 | case kCondBE: // <= 0 if zero |
| 4007 | __ Beqzc(lhs, label); |
| 4008 | break; |
| 4009 | case kCondNE: |
| 4010 | case kCondA: // > 0 if non-zero |
| 4011 | __ Bnezc(lhs, label); |
| 4012 | break; |
| 4013 | case kCondLT: |
| 4014 | __ Bltzc(lhs, label); |
| 4015 | break; |
| 4016 | case kCondGE: |
| 4017 | __ Bgezc(lhs, label); |
| 4018 | break; |
| 4019 | case kCondLE: |
| 4020 | __ Blezc(lhs, label); |
| 4021 | break; |
| 4022 | case kCondGT: |
| 4023 | __ Bgtzc(lhs, label); |
| 4024 | break; |
| 4025 | case kCondB: // always false |
| 4026 | break; |
| 4027 | case kCondAE: // always true |
| 4028 | __ Bc(label); |
| 4029 | break; |
| 4030 | } |
| 4031 | } else { |
| 4032 | if (use_imm) { |
| 4033 | rhs_reg = TMP; |
| 4034 | __ LoadConst64(rhs_reg, rhs_imm); |
| 4035 | } |
| 4036 | switch (cond) { |
| 4037 | case kCondEQ: |
| 4038 | __ Beqc(lhs, rhs_reg, label); |
| 4039 | break; |
| 4040 | case kCondNE: |
| 4041 | __ Bnec(lhs, rhs_reg, label); |
| 4042 | break; |
| 4043 | case kCondLT: |
| 4044 | __ Bltc(lhs, rhs_reg, label); |
| 4045 | break; |
| 4046 | case kCondGE: |
| 4047 | __ Bgec(lhs, rhs_reg, label); |
| 4048 | break; |
| 4049 | case kCondLE: |
| 4050 | __ Bgec(rhs_reg, lhs, label); |
| 4051 | break; |
| 4052 | case kCondGT: |
| 4053 | __ Bltc(rhs_reg, lhs, label); |
| 4054 | break; |
| 4055 | case kCondB: |
| 4056 | __ Bltuc(lhs, rhs_reg, label); |
| 4057 | break; |
| 4058 | case kCondAE: |
| 4059 | __ Bgeuc(lhs, rhs_reg, label); |
| 4060 | break; |
| 4061 | case kCondBE: |
| 4062 | __ Bgeuc(rhs_reg, lhs, label); |
| 4063 | break; |
| 4064 | case kCondA: |
| 4065 | __ Bltuc(rhs_reg, lhs, label); |
| 4066 | break; |
| 4067 | } |
| 4068 | } |
| 4069 | } |
| 4070 | |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 4071 | void InstructionCodeGeneratorMIPS64::GenerateFpCompare(IfCondition cond, |
| 4072 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4073 | DataType::Type type, |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 4074 | LocationSummary* locations) { |
| 4075 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 4076 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 4077 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4078 | if (type == DataType::Type::kFloat32) { |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 4079 | switch (cond) { |
| 4080 | case kCondEQ: |
| 4081 | __ CmpEqS(FTMP, lhs, rhs); |
| 4082 | __ Mfc1(dst, FTMP); |
| 4083 | __ Andi(dst, dst, 1); |
| 4084 | break; |
| 4085 | case kCondNE: |
| 4086 | __ CmpEqS(FTMP, lhs, rhs); |
| 4087 | __ Mfc1(dst, FTMP); |
| 4088 | __ Addiu(dst, dst, 1); |
| 4089 | break; |
| 4090 | case kCondLT: |
| 4091 | if (gt_bias) { |
| 4092 | __ CmpLtS(FTMP, lhs, rhs); |
| 4093 | } else { |
| 4094 | __ CmpUltS(FTMP, lhs, rhs); |
| 4095 | } |
| 4096 | __ Mfc1(dst, FTMP); |
| 4097 | __ Andi(dst, dst, 1); |
| 4098 | break; |
| 4099 | case kCondLE: |
| 4100 | if (gt_bias) { |
| 4101 | __ CmpLeS(FTMP, lhs, rhs); |
| 4102 | } else { |
| 4103 | __ CmpUleS(FTMP, lhs, rhs); |
| 4104 | } |
| 4105 | __ Mfc1(dst, FTMP); |
| 4106 | __ Andi(dst, dst, 1); |
| 4107 | break; |
| 4108 | case kCondGT: |
| 4109 | if (gt_bias) { |
| 4110 | __ CmpUltS(FTMP, rhs, lhs); |
| 4111 | } else { |
| 4112 | __ CmpLtS(FTMP, rhs, lhs); |
| 4113 | } |
| 4114 | __ Mfc1(dst, FTMP); |
| 4115 | __ Andi(dst, dst, 1); |
| 4116 | break; |
| 4117 | case kCondGE: |
| 4118 | if (gt_bias) { |
| 4119 | __ CmpUleS(FTMP, rhs, lhs); |
| 4120 | } else { |
| 4121 | __ CmpLeS(FTMP, rhs, lhs); |
| 4122 | } |
| 4123 | __ Mfc1(dst, FTMP); |
| 4124 | __ Andi(dst, dst, 1); |
| 4125 | break; |
| 4126 | default: |
| 4127 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4128 | UNREACHABLE(); |
| 4129 | } |
| 4130 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4131 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 4132 | switch (cond) { |
| 4133 | case kCondEQ: |
| 4134 | __ CmpEqD(FTMP, lhs, rhs); |
| 4135 | __ Mfc1(dst, FTMP); |
| 4136 | __ Andi(dst, dst, 1); |
| 4137 | break; |
| 4138 | case kCondNE: |
| 4139 | __ CmpEqD(FTMP, lhs, rhs); |
| 4140 | __ Mfc1(dst, FTMP); |
| 4141 | __ Addiu(dst, dst, 1); |
| 4142 | break; |
| 4143 | case kCondLT: |
| 4144 | if (gt_bias) { |
| 4145 | __ CmpLtD(FTMP, lhs, rhs); |
| 4146 | } else { |
| 4147 | __ CmpUltD(FTMP, lhs, rhs); |
| 4148 | } |
| 4149 | __ Mfc1(dst, FTMP); |
| 4150 | __ Andi(dst, dst, 1); |
| 4151 | break; |
| 4152 | case kCondLE: |
| 4153 | if (gt_bias) { |
| 4154 | __ CmpLeD(FTMP, lhs, rhs); |
| 4155 | } else { |
| 4156 | __ CmpUleD(FTMP, lhs, rhs); |
| 4157 | } |
| 4158 | __ Mfc1(dst, FTMP); |
| 4159 | __ Andi(dst, dst, 1); |
| 4160 | break; |
| 4161 | case kCondGT: |
| 4162 | if (gt_bias) { |
| 4163 | __ CmpUltD(FTMP, rhs, lhs); |
| 4164 | } else { |
| 4165 | __ CmpLtD(FTMP, rhs, lhs); |
| 4166 | } |
| 4167 | __ Mfc1(dst, FTMP); |
| 4168 | __ Andi(dst, dst, 1); |
| 4169 | break; |
| 4170 | case kCondGE: |
| 4171 | if (gt_bias) { |
| 4172 | __ CmpUleD(FTMP, rhs, lhs); |
| 4173 | } else { |
| 4174 | __ CmpLeD(FTMP, rhs, lhs); |
| 4175 | } |
| 4176 | __ Mfc1(dst, FTMP); |
| 4177 | __ Andi(dst, dst, 1); |
| 4178 | break; |
| 4179 | default: |
| 4180 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4181 | UNREACHABLE(); |
| 4182 | } |
| 4183 | } |
| 4184 | } |
| 4185 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4186 | bool InstructionCodeGeneratorMIPS64::MaterializeFpCompare(IfCondition cond, |
| 4187 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4188 | DataType::Type type, |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4189 | LocationSummary* input_locations, |
| 4190 | FpuRegister dst) { |
| 4191 | FpuRegister lhs = input_locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 4192 | FpuRegister rhs = input_locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4193 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4194 | switch (cond) { |
| 4195 | case kCondEQ: |
| 4196 | __ CmpEqS(dst, lhs, rhs); |
| 4197 | return false; |
| 4198 | case kCondNE: |
| 4199 | __ CmpEqS(dst, lhs, rhs); |
| 4200 | return true; |
| 4201 | case kCondLT: |
| 4202 | if (gt_bias) { |
| 4203 | __ CmpLtS(dst, lhs, rhs); |
| 4204 | } else { |
| 4205 | __ CmpUltS(dst, lhs, rhs); |
| 4206 | } |
| 4207 | return false; |
| 4208 | case kCondLE: |
| 4209 | if (gt_bias) { |
| 4210 | __ CmpLeS(dst, lhs, rhs); |
| 4211 | } else { |
| 4212 | __ CmpUleS(dst, lhs, rhs); |
| 4213 | } |
| 4214 | return false; |
| 4215 | case kCondGT: |
| 4216 | if (gt_bias) { |
| 4217 | __ CmpUltS(dst, rhs, lhs); |
| 4218 | } else { |
| 4219 | __ CmpLtS(dst, rhs, lhs); |
| 4220 | } |
| 4221 | return false; |
| 4222 | case kCondGE: |
| 4223 | if (gt_bias) { |
| 4224 | __ CmpUleS(dst, rhs, lhs); |
| 4225 | } else { |
| 4226 | __ CmpLeS(dst, rhs, lhs); |
| 4227 | } |
| 4228 | return false; |
| 4229 | default: |
| 4230 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4231 | UNREACHABLE(); |
| 4232 | } |
| 4233 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4234 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4235 | switch (cond) { |
| 4236 | case kCondEQ: |
| 4237 | __ CmpEqD(dst, lhs, rhs); |
| 4238 | return false; |
| 4239 | case kCondNE: |
| 4240 | __ CmpEqD(dst, lhs, rhs); |
| 4241 | return true; |
| 4242 | case kCondLT: |
| 4243 | if (gt_bias) { |
| 4244 | __ CmpLtD(dst, lhs, rhs); |
| 4245 | } else { |
| 4246 | __ CmpUltD(dst, lhs, rhs); |
| 4247 | } |
| 4248 | return false; |
| 4249 | case kCondLE: |
| 4250 | if (gt_bias) { |
| 4251 | __ CmpLeD(dst, lhs, rhs); |
| 4252 | } else { |
| 4253 | __ CmpUleD(dst, lhs, rhs); |
| 4254 | } |
| 4255 | return false; |
| 4256 | case kCondGT: |
| 4257 | if (gt_bias) { |
| 4258 | __ CmpUltD(dst, rhs, lhs); |
| 4259 | } else { |
| 4260 | __ CmpLtD(dst, rhs, lhs); |
| 4261 | } |
| 4262 | return false; |
| 4263 | case kCondGE: |
| 4264 | if (gt_bias) { |
| 4265 | __ CmpUleD(dst, rhs, lhs); |
| 4266 | } else { |
| 4267 | __ CmpLeD(dst, rhs, lhs); |
| 4268 | } |
| 4269 | return false; |
| 4270 | default: |
| 4271 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4272 | UNREACHABLE(); |
| 4273 | } |
| 4274 | } |
| 4275 | } |
| 4276 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4277 | void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond, |
| 4278 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4279 | DataType::Type type, |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4280 | LocationSummary* locations, |
| 4281 | Mips64Label* label) { |
| 4282 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 4283 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4284 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4285 | switch (cond) { |
| 4286 | case kCondEQ: |
| 4287 | __ CmpEqS(FTMP, lhs, rhs); |
| 4288 | __ Bc1nez(FTMP, label); |
| 4289 | break; |
| 4290 | case kCondNE: |
| 4291 | __ CmpEqS(FTMP, lhs, rhs); |
| 4292 | __ Bc1eqz(FTMP, label); |
| 4293 | break; |
| 4294 | case kCondLT: |
| 4295 | if (gt_bias) { |
| 4296 | __ CmpLtS(FTMP, lhs, rhs); |
| 4297 | } else { |
| 4298 | __ CmpUltS(FTMP, lhs, rhs); |
| 4299 | } |
| 4300 | __ Bc1nez(FTMP, label); |
| 4301 | break; |
| 4302 | case kCondLE: |
| 4303 | if (gt_bias) { |
| 4304 | __ CmpLeS(FTMP, lhs, rhs); |
| 4305 | } else { |
| 4306 | __ CmpUleS(FTMP, lhs, rhs); |
| 4307 | } |
| 4308 | __ Bc1nez(FTMP, label); |
| 4309 | break; |
| 4310 | case kCondGT: |
| 4311 | if (gt_bias) { |
| 4312 | __ CmpUltS(FTMP, rhs, lhs); |
| 4313 | } else { |
| 4314 | __ CmpLtS(FTMP, rhs, lhs); |
| 4315 | } |
| 4316 | __ Bc1nez(FTMP, label); |
| 4317 | break; |
| 4318 | case kCondGE: |
| 4319 | if (gt_bias) { |
| 4320 | __ CmpUleS(FTMP, rhs, lhs); |
| 4321 | } else { |
| 4322 | __ CmpLeS(FTMP, rhs, lhs); |
| 4323 | } |
| 4324 | __ Bc1nez(FTMP, label); |
| 4325 | break; |
| 4326 | default: |
| 4327 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4328 | UNREACHABLE(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4329 | } |
| 4330 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4331 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4332 | switch (cond) { |
| 4333 | case kCondEQ: |
| 4334 | __ CmpEqD(FTMP, lhs, rhs); |
| 4335 | __ Bc1nez(FTMP, label); |
| 4336 | break; |
| 4337 | case kCondNE: |
| 4338 | __ CmpEqD(FTMP, lhs, rhs); |
| 4339 | __ Bc1eqz(FTMP, label); |
| 4340 | break; |
| 4341 | case kCondLT: |
| 4342 | if (gt_bias) { |
| 4343 | __ CmpLtD(FTMP, lhs, rhs); |
| 4344 | } else { |
| 4345 | __ CmpUltD(FTMP, lhs, rhs); |
| 4346 | } |
| 4347 | __ Bc1nez(FTMP, label); |
| 4348 | break; |
| 4349 | case kCondLE: |
| 4350 | if (gt_bias) { |
| 4351 | __ CmpLeD(FTMP, lhs, rhs); |
| 4352 | } else { |
| 4353 | __ CmpUleD(FTMP, lhs, rhs); |
| 4354 | } |
| 4355 | __ Bc1nez(FTMP, label); |
| 4356 | break; |
| 4357 | case kCondGT: |
| 4358 | if (gt_bias) { |
| 4359 | __ CmpUltD(FTMP, rhs, lhs); |
| 4360 | } else { |
| 4361 | __ CmpLtD(FTMP, rhs, lhs); |
| 4362 | } |
| 4363 | __ Bc1nez(FTMP, label); |
| 4364 | break; |
| 4365 | case kCondGE: |
| 4366 | if (gt_bias) { |
| 4367 | __ CmpUleD(FTMP, rhs, lhs); |
| 4368 | } else { |
| 4369 | __ CmpLeD(FTMP, rhs, lhs); |
| 4370 | } |
| 4371 | __ Bc1nez(FTMP, label); |
| 4372 | break; |
| 4373 | default: |
| 4374 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4375 | UNREACHABLE(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4376 | } |
| 4377 | } |
| 4378 | } |
| 4379 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4380 | void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4381 | size_t condition_input_index, |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4382 | Mips64Label* true_target, |
| 4383 | Mips64Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4384 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4385 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4386 | if (true_target == nullptr && false_target == nullptr) { |
| 4387 | // Nothing to do. The code always falls through. |
| 4388 | return; |
| 4389 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4390 | // Constant condition, statically compared against "true" (integer value 1). |
| 4391 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4392 | if (true_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4393 | __ Bc(true_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4394 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4395 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4396 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4397 | if (false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4398 | __ Bc(false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4399 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4400 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4401 | return; |
| 4402 | } |
| 4403 | |
| 4404 | // The following code generates these patterns: |
| 4405 | // (1) true_target == nullptr && false_target != nullptr |
| 4406 | // - opposite condition true => branch to false_target |
| 4407 | // (2) true_target != nullptr && false_target == nullptr |
| 4408 | // - condition true => branch to true_target |
| 4409 | // (3) true_target != nullptr && false_target != nullptr |
| 4410 | // - condition true => branch to true_target |
| 4411 | // - branch to false_target |
| 4412 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4413 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4414 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4415 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4416 | if (true_target == nullptr) { |
| 4417 | __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target); |
| 4418 | } else { |
| 4419 | __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target); |
| 4420 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4421 | } else { |
| 4422 | // The condition instruction has not been materialized, use its inputs as |
| 4423 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4424 | HCondition* condition = cond->AsCondition(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4425 | DataType::Type type = condition->InputAt(0)->GetType(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4426 | LocationSummary* locations = cond->GetLocations(); |
| 4427 | IfCondition if_cond = condition->GetCondition(); |
| 4428 | Mips64Label* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4429 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4430 | if (true_target == nullptr) { |
| 4431 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4432 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4433 | } |
| 4434 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4435 | switch (type) { |
| 4436 | default: |
| 4437 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target); |
| 4438 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4439 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4440 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target); |
| 4441 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4442 | case DataType::Type::kFloat32: |
| 4443 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4444 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 4445 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4446 | } |
| 4447 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4448 | |
| 4449 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 4450 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 4451 | if (true_target != nullptr && false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4452 | __ Bc(false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4453 | } |
| 4454 | } |
| 4455 | |
| 4456 | void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4457 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4458 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4459 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4460 | } |
| 4461 | } |
| 4462 | |
| 4463 | void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4464 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 4465 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4466 | Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4467 | nullptr : codegen_->GetLabelOf(true_successor); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4468 | Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4469 | nullptr : codegen_->GetLabelOf(false_successor); |
| 4470 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4474 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4475 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 4476 | InvokeRuntimeCallingConvention calling_convention; |
| 4477 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4478 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4479 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4480 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4481 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4482 | } |
| 4483 | } |
| 4484 | |
| 4485 | void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 4486 | SlowPathCodeMIPS64* slow_path = |
| 4487 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4488 | GenerateTestAndBranch(deoptimize, |
| 4489 | /* condition_input_index */ 0, |
| 4490 | slow_path->GetEntryLabel(), |
| 4491 | /* false_target */ nullptr); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4492 | } |
| 4493 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4494 | // This function returns true if a conditional move can be generated for HSelect. |
| 4495 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 4496 | // branches and regular moves. |
| 4497 | // |
| 4498 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 4499 | // |
| 4500 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 4501 | // are two distinct tasks, this function does both because they share quite a bit |
| 4502 | // of common logic. |
| 4503 | static bool CanMoveConditionally(HSelect* select, LocationSummary* locations_to_set) { |
| 4504 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 4505 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4506 | HCondition* condition = cond->AsCondition(); |
| 4507 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4508 | DataType::Type cond_type = |
| 4509 | materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType(); |
| 4510 | DataType::Type dst_type = select->GetType(); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4511 | |
| 4512 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 4513 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 4514 | bool is_true_value_zero_constant = |
| 4515 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 4516 | bool is_false_value_zero_constant = |
| 4517 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 4518 | |
| 4519 | bool can_move_conditionally = false; |
| 4520 | bool use_const_for_false_in = false; |
| 4521 | bool use_const_for_true_in = false; |
| 4522 | |
| 4523 | if (!cond->IsConstant()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4524 | if (!DataType::IsFloatingPointType(cond_type)) { |
| 4525 | if (!DataType::IsFloatingPointType(dst_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4526 | // Moving int/long on int/long condition. |
| 4527 | if (is_true_value_zero_constant) { |
| 4528 | // seleqz out_reg, false_reg, cond_reg |
| 4529 | can_move_conditionally = true; |
| 4530 | use_const_for_true_in = true; |
| 4531 | } else if (is_false_value_zero_constant) { |
| 4532 | // selnez out_reg, true_reg, cond_reg |
| 4533 | can_move_conditionally = true; |
| 4534 | use_const_for_false_in = true; |
| 4535 | } else if (materialized) { |
| 4536 | // Not materializing unmaterialized int conditions |
| 4537 | // to keep the instruction count low. |
| 4538 | // selnez AT, true_reg, cond_reg |
| 4539 | // seleqz TMP, false_reg, cond_reg |
| 4540 | // or out_reg, AT, TMP |
| 4541 | can_move_conditionally = true; |
| 4542 | } |
| 4543 | } else { |
| 4544 | // Moving float/double on int/long condition. |
| 4545 | if (materialized) { |
| 4546 | // Not materializing unmaterialized int conditions |
| 4547 | // to keep the instruction count low. |
| 4548 | can_move_conditionally = true; |
| 4549 | if (is_true_value_zero_constant) { |
| 4550 | // sltu TMP, ZERO, cond_reg |
| 4551 | // mtc1 TMP, temp_cond_reg |
| 4552 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4553 | use_const_for_true_in = true; |
| 4554 | } else if (is_false_value_zero_constant) { |
| 4555 | // sltu TMP, ZERO, cond_reg |
| 4556 | // mtc1 TMP, temp_cond_reg |
| 4557 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4558 | use_const_for_false_in = true; |
| 4559 | } else { |
| 4560 | // sltu TMP, ZERO, cond_reg |
| 4561 | // mtc1 TMP, temp_cond_reg |
| 4562 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4563 | // mov.fmt out_reg, temp_cond_reg |
| 4564 | } |
| 4565 | } |
| 4566 | } |
| 4567 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4568 | if (!DataType::IsFloatingPointType(dst_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4569 | // Moving int/long on float/double condition. |
| 4570 | can_move_conditionally = true; |
| 4571 | if (is_true_value_zero_constant) { |
| 4572 | // mfc1 TMP, temp_cond_reg |
| 4573 | // seleqz out_reg, false_reg, TMP |
| 4574 | use_const_for_true_in = true; |
| 4575 | } else if (is_false_value_zero_constant) { |
| 4576 | // mfc1 TMP, temp_cond_reg |
| 4577 | // selnez out_reg, true_reg, TMP |
| 4578 | use_const_for_false_in = true; |
| 4579 | } else { |
| 4580 | // mfc1 TMP, temp_cond_reg |
| 4581 | // selnez AT, true_reg, TMP |
| 4582 | // seleqz TMP, false_reg, TMP |
| 4583 | // or out_reg, AT, TMP |
| 4584 | } |
| 4585 | } else { |
| 4586 | // Moving float/double on float/double condition. |
| 4587 | can_move_conditionally = true; |
| 4588 | if (is_true_value_zero_constant) { |
| 4589 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4590 | use_const_for_true_in = true; |
| 4591 | } else if (is_false_value_zero_constant) { |
| 4592 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4593 | use_const_for_false_in = true; |
| 4594 | } else { |
| 4595 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4596 | // mov.fmt out_reg, temp_cond_reg |
| 4597 | } |
| 4598 | } |
| 4599 | } |
| 4600 | } |
| 4601 | |
| 4602 | if (can_move_conditionally) { |
| 4603 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 4604 | } else { |
| 4605 | DCHECK(!use_const_for_false_in); |
| 4606 | DCHECK(!use_const_for_true_in); |
| 4607 | } |
| 4608 | |
| 4609 | if (locations_to_set != nullptr) { |
| 4610 | if (use_const_for_false_in) { |
| 4611 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 4612 | } else { |
| 4613 | locations_to_set->SetInAt(0, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4614 | DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4615 | ? Location::RequiresFpuRegister() |
| 4616 | : Location::RequiresRegister()); |
| 4617 | } |
| 4618 | if (use_const_for_true_in) { |
| 4619 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 4620 | } else { |
| 4621 | locations_to_set->SetInAt(1, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4622 | DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4623 | ? Location::RequiresFpuRegister() |
| 4624 | : Location::RequiresRegister()); |
| 4625 | } |
| 4626 | if (materialized) { |
| 4627 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 4628 | } |
| 4629 | |
| 4630 | if (can_move_conditionally) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4631 | locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4632 | ? Location::RequiresFpuRegister() |
| 4633 | : Location::RequiresRegister()); |
| 4634 | } else { |
| 4635 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 4636 | } |
| 4637 | } |
| 4638 | |
| 4639 | return can_move_conditionally; |
| 4640 | } |
| 4641 | |
| 4642 | |
| 4643 | void InstructionCodeGeneratorMIPS64::GenConditionalMove(HSelect* select) { |
| 4644 | LocationSummary* locations = select->GetLocations(); |
| 4645 | Location dst = locations->Out(); |
| 4646 | Location false_src = locations->InAt(0); |
| 4647 | Location true_src = locations->InAt(1); |
| 4648 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4649 | GpuRegister cond_reg = TMP; |
| 4650 | FpuRegister fcond_reg = FTMP; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4651 | DataType::Type cond_type = DataType::Type::kInt32; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4652 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4653 | DataType::Type dst_type = select->GetType(); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4654 | |
| 4655 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 4656 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<GpuRegister>(); |
| 4657 | } else { |
| 4658 | HCondition* condition = cond->AsCondition(); |
| 4659 | LocationSummary* cond_locations = cond->GetLocations(); |
| 4660 | IfCondition if_cond = condition->GetCondition(); |
| 4661 | cond_type = condition->InputAt(0)->GetType(); |
| 4662 | switch (cond_type) { |
| 4663 | default: |
| 4664 | cond_inverted = MaterializeIntLongCompare(if_cond, |
| 4665 | /* is64bit */ false, |
| 4666 | cond_locations, |
| 4667 | cond_reg); |
| 4668 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4669 | case DataType::Type::kInt64: |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4670 | cond_inverted = MaterializeIntLongCompare(if_cond, |
| 4671 | /* is64bit */ true, |
| 4672 | cond_locations, |
| 4673 | cond_reg); |
| 4674 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4675 | case DataType::Type::kFloat32: |
| 4676 | case DataType::Type::kFloat64: |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4677 | cond_inverted = MaterializeFpCompare(if_cond, |
| 4678 | condition->IsGtBias(), |
| 4679 | cond_type, |
| 4680 | cond_locations, |
| 4681 | fcond_reg); |
| 4682 | break; |
| 4683 | } |
| 4684 | } |
| 4685 | |
| 4686 | if (true_src.IsConstant()) { |
| 4687 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 4688 | } |
| 4689 | if (false_src.IsConstant()) { |
| 4690 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 4691 | } |
| 4692 | |
| 4693 | switch (dst_type) { |
| 4694 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4695 | if (DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4696 | __ Mfc1(cond_reg, fcond_reg); |
| 4697 | } |
| 4698 | if (true_src.IsConstant()) { |
| 4699 | if (cond_inverted) { |
| 4700 | __ Selnez(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4701 | } else { |
| 4702 | __ Seleqz(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4703 | } |
| 4704 | } else if (false_src.IsConstant()) { |
| 4705 | if (cond_inverted) { |
| 4706 | __ Seleqz(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4707 | } else { |
| 4708 | __ Selnez(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4709 | } |
| 4710 | } else { |
| 4711 | DCHECK_NE(cond_reg, AT); |
| 4712 | if (cond_inverted) { |
| 4713 | __ Seleqz(AT, true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4714 | __ Selnez(TMP, false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4715 | } else { |
| 4716 | __ Selnez(AT, true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4717 | __ Seleqz(TMP, false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4718 | } |
| 4719 | __ Or(dst.AsRegister<GpuRegister>(), AT, TMP); |
| 4720 | } |
| 4721 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4722 | case DataType::Type::kFloat32: { |
| 4723 | if (!DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4724 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4725 | __ Sltu(TMP, ZERO, cond_reg); |
| 4726 | __ Mtc1(TMP, fcond_reg); |
| 4727 | } |
| 4728 | FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>(); |
| 4729 | if (true_src.IsConstant()) { |
| 4730 | FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>(); |
| 4731 | if (cond_inverted) { |
| 4732 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4733 | } else { |
| 4734 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4735 | } |
| 4736 | } else if (false_src.IsConstant()) { |
| 4737 | FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>(); |
| 4738 | if (cond_inverted) { |
| 4739 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4740 | } else { |
| 4741 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4742 | } |
| 4743 | } else { |
| 4744 | if (cond_inverted) { |
| 4745 | __ SelS(fcond_reg, |
| 4746 | true_src.AsFpuRegister<FpuRegister>(), |
| 4747 | false_src.AsFpuRegister<FpuRegister>()); |
| 4748 | } else { |
| 4749 | __ SelS(fcond_reg, |
| 4750 | false_src.AsFpuRegister<FpuRegister>(), |
| 4751 | true_src.AsFpuRegister<FpuRegister>()); |
| 4752 | } |
| 4753 | __ MovS(dst_reg, fcond_reg); |
| 4754 | } |
| 4755 | break; |
| 4756 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4757 | case DataType::Type::kFloat64: { |
| 4758 | if (!DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4759 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4760 | __ Sltu(TMP, ZERO, cond_reg); |
| 4761 | __ Mtc1(TMP, fcond_reg); |
| 4762 | } |
| 4763 | FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>(); |
| 4764 | if (true_src.IsConstant()) { |
| 4765 | FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>(); |
| 4766 | if (cond_inverted) { |
| 4767 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4768 | } else { |
| 4769 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4770 | } |
| 4771 | } else if (false_src.IsConstant()) { |
| 4772 | FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>(); |
| 4773 | if (cond_inverted) { |
| 4774 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4775 | } else { |
| 4776 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4777 | } |
| 4778 | } else { |
| 4779 | if (cond_inverted) { |
| 4780 | __ SelD(fcond_reg, |
| 4781 | true_src.AsFpuRegister<FpuRegister>(), |
| 4782 | false_src.AsFpuRegister<FpuRegister>()); |
| 4783 | } else { |
| 4784 | __ SelD(fcond_reg, |
| 4785 | false_src.AsFpuRegister<FpuRegister>(), |
| 4786 | true_src.AsFpuRegister<FpuRegister>()); |
| 4787 | } |
| 4788 | __ MovD(dst_reg, fcond_reg); |
| 4789 | } |
| 4790 | break; |
| 4791 | } |
| 4792 | } |
| 4793 | } |
| 4794 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4795 | void LocationsBuilderMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4796 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4797 | LocationSummary(flag, LocationSummary::kNoCall); |
| 4798 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4799 | } |
| 4800 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4801 | void InstructionCodeGeneratorMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 4802 | __ LoadFromOffset(kLoadWord, |
| 4803 | flag->GetLocations()->Out().AsRegister<GpuRegister>(), |
| 4804 | SP, |
| 4805 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4806 | } |
| 4807 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4808 | void LocationsBuilderMIPS64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4809 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4810 | CanMoveConditionally(select, locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4811 | } |
| 4812 | |
| 4813 | void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4814 | if (CanMoveConditionally(select, /* locations_to_set */ nullptr)) { |
| 4815 | GenConditionalMove(select); |
| 4816 | } else { |
| 4817 | LocationSummary* locations = select->GetLocations(); |
| 4818 | Mips64Label false_target; |
| 4819 | GenerateTestAndBranch(select, |
| 4820 | /* condition_input_index */ 2, |
| 4821 | /* true_target */ nullptr, |
| 4822 | &false_target); |
| 4823 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 4824 | __ Bind(&false_target); |
| 4825 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4826 | } |
| 4827 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4828 | void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4829 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4830 | } |
| 4831 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 4832 | void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 4833 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | void CodeGeneratorMIPS64::GenerateNop() { |
| 4837 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4838 | } |
| 4839 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4840 | void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4841 | const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4842 | DataType::Type field_type = field_info.GetFieldType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4843 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4844 | kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4845 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4846 | instruction, |
| 4847 | object_field_get_with_read_barrier |
| 4848 | ? LocationSummary::kCallOnSlowPath |
| 4849 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 4850 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4851 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 4852 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4853 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4854 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4855 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4856 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4857 | // The output overlaps in the case of an object field get with |
| 4858 | // read barriers enabled: we do not want the move to overwrite the |
| 4859 | // object's location, as we need it to emit the read barrier. |
| 4860 | locations->SetOut(Location::RequiresRegister(), |
| 4861 | object_field_get_with_read_barrier |
| 4862 | ? Location::kOutputOverlap |
| 4863 | : Location::kNoOutputOverlap); |
| 4864 | } |
| 4865 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4866 | // We need a temporary register for the read barrier marking slow |
| 4867 | // path in CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4868 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 4869 | locations->AddTemp(Location::RequiresRegister()); |
| 4870 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4871 | } |
| 4872 | } |
| 4873 | |
| 4874 | void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction, |
| 4875 | const FieldInfo& field_info) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4876 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4877 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4878 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4879 | Location obj_loc = locations->InAt(0); |
| 4880 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 4881 | Location dst_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4882 | LoadOperandType load_type = kLoadUnsignedByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4883 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4884 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4885 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4886 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4887 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4888 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4889 | case DataType::Type::kUint8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4890 | load_type = kLoadUnsignedByte; |
| 4891 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4892 | case DataType::Type::kInt8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4893 | load_type = kLoadSignedByte; |
| 4894 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4895 | case DataType::Type::kUint16: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4896 | load_type = kLoadUnsignedHalfword; |
| 4897 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4898 | case DataType::Type::kInt16: |
| 4899 | load_type = kLoadSignedHalfword; |
| 4900 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4901 | case DataType::Type::kInt32: |
| 4902 | case DataType::Type::kFloat32: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4903 | load_type = kLoadWord; |
| 4904 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4905 | case DataType::Type::kInt64: |
| 4906 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4907 | load_type = kLoadDoubleword; |
| 4908 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4909 | case DataType::Type::kReference: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4910 | load_type = kLoadUnsignedWord; |
| 4911 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4912 | case DataType::Type::kUint32: |
| 4913 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4914 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4915 | LOG(FATAL) << "Unreachable type " << type; |
| 4916 | UNREACHABLE(); |
| 4917 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4918 | if (!DataType::IsFloatingPointType(type)) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4919 | DCHECK(dst_loc.IsRegister()); |
| 4920 | GpuRegister dst = dst_loc.AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4921 | if (type == DataType::Type::kReference) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4922 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 4923 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4924 | Location temp_loc = |
| 4925 | kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4926 | // Note that a potential implicit null check is handled in this |
| 4927 | // CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier call. |
| 4928 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4929 | dst_loc, |
| 4930 | obj, |
| 4931 | offset, |
| 4932 | temp_loc, |
| 4933 | /* needs_null_check */ true); |
| 4934 | if (is_volatile) { |
| 4935 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4936 | } |
| 4937 | } else { |
| 4938 | __ LoadFromOffset(kLoadUnsignedWord, dst, obj, offset, null_checker); |
| 4939 | if (is_volatile) { |
| 4940 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4941 | } |
| 4942 | // If read barriers are enabled, emit read barriers other than |
| 4943 | // Baker's using a slow path (and also unpoison the loaded |
| 4944 | // reference, if heap poisoning is enabled). |
| 4945 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 4946 | } |
| 4947 | } else { |
| 4948 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
| 4949 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4950 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4951 | DCHECK(dst_loc.IsFpuRegister()); |
| 4952 | FpuRegister dst = dst_loc.AsFpuRegister<FpuRegister>(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4953 | __ LoadFpuFromOffset(load_type, dst, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4954 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4955 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4956 | // Memory barriers, in the case of references, are handled in the |
| 4957 | // previous switch statement. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4958 | if (is_volatile && (type != DataType::Type::kReference)) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4959 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4960 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4961 | } |
| 4962 | |
| 4963 | void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction, |
| 4964 | const FieldInfo& field_info ATTRIBUTE_UNUSED) { |
| 4965 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4966 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4967 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4968 | if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4969 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4970 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4971 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4972 | } |
| 4973 | } |
| 4974 | |
| 4975 | void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction, |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4976 | const FieldInfo& field_info, |
| 4977 | bool value_can_be_null) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4978 | DataType::Type type = field_info.GetFieldType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4979 | LocationSummary* locations = instruction->GetLocations(); |
| 4980 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4981 | Location value_location = locations->InAt(1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4982 | StoreOperandType store_type = kStoreByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4983 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4984 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4985 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4986 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4987 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4988 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4989 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4990 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4991 | case DataType::Type::kInt8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4992 | store_type = kStoreByte; |
| 4993 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4994 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4995 | case DataType::Type::kInt16: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4996 | store_type = kStoreHalfword; |
| 4997 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4998 | case DataType::Type::kInt32: |
| 4999 | case DataType::Type::kFloat32: |
| 5000 | case DataType::Type::kReference: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5001 | store_type = kStoreWord; |
| 5002 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5003 | case DataType::Type::kInt64: |
| 5004 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5005 | store_type = kStoreDoubleword; |
| 5006 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5007 | case DataType::Type::kUint32: |
| 5008 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5009 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5010 | LOG(FATAL) << "Unreachable type " << type; |
| 5011 | UNREACHABLE(); |
| 5012 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5013 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5014 | if (is_volatile) { |
| 5015 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5016 | } |
| 5017 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 5018 | if (value_location.IsConstant()) { |
| 5019 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 5020 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
| 5021 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5022 | if (!DataType::IsFloatingPointType(type)) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 5023 | DCHECK(value_location.IsRegister()); |
| 5024 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
| 5025 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5026 | // Note that in the case where `value` is a null reference, |
| 5027 | // we do not enter this block, as a null reference does not |
| 5028 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5029 | DCHECK_EQ(type, DataType::Type::kReference); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 5030 | __ PoisonHeapReference(TMP, src); |
| 5031 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 5032 | } else { |
| 5033 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 5034 | } |
| 5035 | } else { |
| 5036 | DCHECK(value_location.IsFpuRegister()); |
| 5037 | FpuRegister src = value_location.AsFpuRegister<FpuRegister>(); |
| 5038 | __ StoreFpuToOffset(store_type, src, obj, offset, null_checker); |
| 5039 | } |
| 5040 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5041 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5042 | if (needs_write_barrier) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 5043 | DCHECK(value_location.IsRegister()); |
| 5044 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 5045 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5046 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5047 | |
| 5048 | if (is_volatile) { |
| 5049 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5050 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5051 | } |
| 5052 | |
| 5053 | void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5054 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5055 | } |
| 5056 | |
| 5057 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5058 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5059 | } |
| 5060 | |
| 5061 | void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5062 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5063 | } |
| 5064 | |
| 5065 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 5066 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5067 | } |
| 5068 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5069 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadOneRegister( |
| 5070 | HInstruction* instruction, |
| 5071 | Location out, |
| 5072 | uint32_t offset, |
| 5073 | Location maybe_temp, |
| 5074 | ReadBarrierOption read_barrier_option) { |
| 5075 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 5076 | if (read_barrier_option == kWithReadBarrier) { |
| 5077 | CHECK(kEmitCompilerReadBarrier); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5078 | if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) { |
| 5079 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 5080 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5081 | if (kUseBakerReadBarrier) { |
| 5082 | // Load with fast path based Baker's read barrier. |
| 5083 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5084 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5085 | out, |
| 5086 | out_reg, |
| 5087 | offset, |
| 5088 | maybe_temp, |
| 5089 | /* needs_null_check */ false); |
| 5090 | } else { |
| 5091 | // Load with slow path based read barrier. |
| 5092 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5093 | // in the following move operation, as we will need it for the |
| 5094 | // read barrier below. |
| 5095 | __ Move(maybe_temp.AsRegister<GpuRegister>(), out_reg); |
| 5096 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5097 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 5098 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5099 | } |
| 5100 | } else { |
| 5101 | // Plain load with no read barrier. |
| 5102 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5103 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 5104 | __ MaybeUnpoisonHeapReference(out_reg); |
| 5105 | } |
| 5106 | } |
| 5107 | |
| 5108 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadTwoRegisters( |
| 5109 | HInstruction* instruction, |
| 5110 | Location out, |
| 5111 | Location obj, |
| 5112 | uint32_t offset, |
| 5113 | Location maybe_temp, |
| 5114 | ReadBarrierOption read_barrier_option) { |
| 5115 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 5116 | GpuRegister obj_reg = obj.AsRegister<GpuRegister>(); |
| 5117 | if (read_barrier_option == kWithReadBarrier) { |
| 5118 | CHECK(kEmitCompilerReadBarrier); |
| 5119 | if (kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5120 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 5121 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 5122 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5123 | // Load with fast path based Baker's read barrier. |
| 5124 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5125 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5126 | out, |
| 5127 | obj_reg, |
| 5128 | offset, |
| 5129 | maybe_temp, |
| 5130 | /* needs_null_check */ false); |
| 5131 | } else { |
| 5132 | // Load with slow path based read barrier. |
| 5133 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5134 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 5135 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5136 | } |
| 5137 | } else { |
| 5138 | // Plain load with no read barrier. |
| 5139 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5140 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 5141 | __ MaybeUnpoisonHeapReference(out_reg); |
| 5142 | } |
| 5143 | } |
| 5144 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5145 | static inline int GetBakerMarkThunkNumber(GpuRegister reg) { |
| 5146 | static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 20, "Expecting equal"); |
| 5147 | if (reg >= V0 && reg <= T2) { // 13 consequtive regs. |
| 5148 | return reg - V0; |
| 5149 | } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs. |
| 5150 | return 13 + (reg - S2); |
| 5151 | } else if (reg == S8) { // One more. |
| 5152 | return 19; |
| 5153 | } |
| 5154 | LOG(FATAL) << "Unexpected register " << reg; |
| 5155 | UNREACHABLE(); |
| 5156 | } |
| 5157 | |
| 5158 | static inline int GetBakerMarkFieldArrayThunkDisplacement(GpuRegister reg, bool short_offset) { |
| 5159 | int num = GetBakerMarkThunkNumber(reg) + |
| 5160 | (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0); |
| 5161 | return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE; |
| 5162 | } |
| 5163 | |
| 5164 | static inline int GetBakerMarkGcRootThunkDisplacement(GpuRegister reg) { |
| 5165 | return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE + |
| 5166 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET; |
| 5167 | } |
| 5168 | |
| 5169 | void InstructionCodeGeneratorMIPS64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 5170 | Location root, |
| 5171 | GpuRegister obj, |
| 5172 | uint32_t offset, |
| 5173 | ReadBarrierOption read_barrier_option, |
| 5174 | Mips64Label* label_low) { |
| 5175 | if (label_low != nullptr) { |
| 5176 | DCHECK_EQ(offset, 0x5678u); |
| 5177 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5178 | GpuRegister root_reg = root.AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5179 | if (read_barrier_option == kWithReadBarrier) { |
| 5180 | DCHECK(kEmitCompilerReadBarrier); |
| 5181 | if (kUseBakerReadBarrier) { |
| 5182 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 5183 | // Baker's read barrier are used: |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5184 | if (kBakerReadBarrierThunksEnableForGcRoots) { |
| 5185 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5186 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 5187 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5188 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5189 | // vice versa. |
| 5190 | // |
| 5191 | // We use thunks for the slow path. That thunk checks the reference |
| 5192 | // and jumps to the entrypoint if needed. |
| 5193 | // |
| 5194 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5195 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5196 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5197 | // if (temp != nullptr) { |
| 5198 | // temp = &gc_root_thunk<root_reg> |
| 5199 | // root = temp(root) |
| 5200 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5201 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5202 | const int32_t entry_point_offset = |
| 5203 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5204 | const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg); |
| 5205 | int16_t offset_low = Low16Bits(offset); |
| 5206 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign |
| 5207 | // extension in lwu. |
| 5208 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 5209 | GpuRegister base = short_offset ? obj : TMP; |
| 5210 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5211 | // threads are suspended or running a checkpoint. |
| 5212 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 5213 | if (!short_offset) { |
| 5214 | DCHECK(!label_low); |
| 5215 | __ Daui(base, obj, offset_high); |
| 5216 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5217 | Mips64Label skip_call; |
| 5218 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5219 | if (label_low != nullptr) { |
| 5220 | DCHECK(short_offset); |
| 5221 | __ Bind(label_low); |
| 5222 | } |
| 5223 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5224 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, base, offset_low); // Single instruction |
| 5225 | // in delay slot. |
| 5226 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5227 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5228 | } else { |
| 5229 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5230 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 5231 | // load into `temp` (T9) the read barrier mark entry point corresponding |
| 5232 | // to register `root`. If `temp` is null, it means that `GetIsGcMarking()` |
| 5233 | // is false, and vice versa. |
| 5234 | // |
| 5235 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5236 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5237 | // if (temp != null) { |
| 5238 | // root = temp(root) |
| 5239 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5240 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5241 | if (label_low != nullptr) { |
| 5242 | __ Bind(label_low); |
| 5243 | } |
| 5244 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5245 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 5246 | static_assert( |
| 5247 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5248 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5249 | "have different sizes."); |
| 5250 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5251 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5252 | "have different sizes."); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5253 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5254 | // Slow path marking the GC root `root`. |
| 5255 | Location temp = Location::RegisterLocation(T9); |
| 5256 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5257 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64( |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5258 | instruction, |
| 5259 | root, |
| 5260 | /*entrypoint*/ temp); |
| 5261 | codegen_->AddSlowPath(slow_path); |
| 5262 | |
| 5263 | const int32_t entry_point_offset = |
| 5264 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(root.reg() - 1); |
| 5265 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5266 | // threads are suspended or running a checkpoint. |
| 5267 | __ LoadFromOffset(kLoadDoubleword, temp.AsRegister<GpuRegister>(), TR, entry_point_offset); |
| 5268 | __ Bnezc(temp.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 5269 | __ Bind(slow_path->GetExitLabel()); |
| 5270 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5271 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5272 | if (label_low != nullptr) { |
| 5273 | __ Bind(label_low); |
| 5274 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5275 | // GC root loaded through a slow path for read barriers other |
| 5276 | // than Baker's. |
| 5277 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 5278 | __ Daddiu64(root_reg, obj, static_cast<int32_t>(offset)); |
| 5279 | // /* mirror::Object* */ root = root->Read() |
| 5280 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5281 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5282 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5283 | if (label_low != nullptr) { |
| 5284 | __ Bind(label_low); |
| 5285 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5286 | // Plain GC root load with no read barrier. |
| 5287 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5288 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 5289 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5290 | // do not have to unpoison `root_reg` here. |
| 5291 | } |
| 5292 | } |
| 5293 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5294 | void CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5295 | Location ref, |
| 5296 | GpuRegister obj, |
| 5297 | uint32_t offset, |
| 5298 | Location temp, |
| 5299 | bool needs_null_check) { |
| 5300 | DCHECK(kEmitCompilerReadBarrier); |
| 5301 | DCHECK(kUseBakerReadBarrier); |
| 5302 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5303 | if (kBakerReadBarrierThunksEnableForFields) { |
| 5304 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5305 | // to decide whether to mark the loaded reference or not. Instead, we |
| 5306 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5307 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5308 | // vice versa. |
| 5309 | // |
| 5310 | // We use thunks for the slow path. That thunk checks the reference |
| 5311 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 5312 | // it issues a load-load memory barrier and returns to the original |
| 5313 | // reference load. |
| 5314 | // |
| 5315 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5316 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5317 | // if (temp != nullptr) { |
| 5318 | // temp = &field_array_thunk<holder_reg> |
| 5319 | // temp() |
| 5320 | // } |
| 5321 | // not_gray_return_address: |
| 5322 | // // If the offset is too large to fit into the lw instruction, we |
| 5323 | // // use an adjusted base register (TMP) here. This register |
| 5324 | // // receives bits 16 ... 31 of the offset before the thunk invocation |
| 5325 | // // and the thunk benefits from it. |
| 5326 | // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load. |
| 5327 | // gray_return_address: |
| 5328 | |
| 5329 | DCHECK(temp.IsInvalid()); |
| 5330 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 5331 | const int32_t entry_point_offset = |
| 5332 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5333 | // There may have or may have not been a null check if the field offset is smaller than |
| 5334 | // the page size. |
| 5335 | // There must've been a null check in case it's actually a load from an array. |
| 5336 | // We will, however, perform an explicit null check in the thunk as it's easier to |
| 5337 | // do it than not. |
| 5338 | if (instruction->IsArrayGet()) { |
| 5339 | DCHECK(!needs_null_check); |
| 5340 | } |
| 5341 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset); |
| 5342 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5343 | // threads are suspended or running a checkpoint. |
| 5344 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 5345 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5346 | Mips64Label skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5347 | if (short_offset) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5348 | __ Beqzc(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5349 | __ Nop(); // In forbidden slot. |
| 5350 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5351 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5352 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5353 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); // Single instruction. |
| 5354 | } else { |
| 5355 | int16_t offset_low = Low16Bits(offset); |
| 5356 | 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] | 5357 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5358 | __ Daui(TMP, obj, offset_high); // In delay slot. |
| 5359 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5360 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5361 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5362 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset_low); // Single instruction. |
| 5363 | } |
| 5364 | if (needs_null_check) { |
| 5365 | MaybeRecordImplicitNullCheck(instruction); |
| 5366 | } |
| 5367 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5368 | return; |
| 5369 | } |
| 5370 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5371 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5372 | Location no_index = Location::NoLocation(); |
| 5373 | ScaleFactor no_scale_factor = TIMES_1; |
| 5374 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5375 | ref, |
| 5376 | obj, |
| 5377 | offset, |
| 5378 | no_index, |
| 5379 | no_scale_factor, |
| 5380 | temp, |
| 5381 | needs_null_check); |
| 5382 | } |
| 5383 | |
| 5384 | void CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5385 | Location ref, |
| 5386 | GpuRegister obj, |
| 5387 | uint32_t data_offset, |
| 5388 | Location index, |
| 5389 | Location temp, |
| 5390 | bool needs_null_check) { |
| 5391 | DCHECK(kEmitCompilerReadBarrier); |
| 5392 | DCHECK(kUseBakerReadBarrier); |
| 5393 | |
| 5394 | static_assert( |
| 5395 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5396 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5397 | ScaleFactor scale_factor = TIMES_4; |
| 5398 | |
| 5399 | if (kBakerReadBarrierThunksEnableForArrays) { |
| 5400 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5401 | // to decide whether to mark the loaded reference or not. Instead, we |
| 5402 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5403 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5404 | // vice versa. |
| 5405 | // |
| 5406 | // We use thunks for the slow path. That thunk checks the reference |
| 5407 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 5408 | // it issues a load-load memory barrier and returns to the original |
| 5409 | // reference load. |
| 5410 | // |
| 5411 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5412 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5413 | // if (temp != nullptr) { |
| 5414 | // temp = &field_array_thunk<holder_reg> |
| 5415 | // temp() |
| 5416 | // } |
| 5417 | // not_gray_return_address: |
| 5418 | // // The element address is pre-calculated in the TMP register before the |
| 5419 | // // thunk invocation and the thunk benefits from it. |
| 5420 | // HeapReference<mirror::Object> reference = data[index]; // Original reference load. |
| 5421 | // gray_return_address: |
| 5422 | |
| 5423 | DCHECK(temp.IsInvalid()); |
| 5424 | DCHECK(index.IsValid()); |
| 5425 | const int32_t entry_point_offset = |
| 5426 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5427 | // We will not do the explicit null check in the thunk as some form of a null check |
| 5428 | // must've been done earlier. |
| 5429 | DCHECK(!needs_null_check); |
| 5430 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false); |
| 5431 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5432 | // threads are suspended or running a checkpoint. |
| 5433 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5434 | Mips64Label skip_call; |
| 5435 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5436 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
| 5437 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
| 5438 | __ Dlsa(TMP, index_reg, obj, scale_factor); // In delay slot. |
| 5439 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5440 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5441 | // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor)) |
| 5442 | DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset; |
| 5443 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, data_offset); // Single instruction. |
| 5444 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5445 | return; |
| 5446 | } |
| 5447 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5448 | // /* HeapReference<Object> */ ref = |
| 5449 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5450 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5451 | ref, |
| 5452 | obj, |
| 5453 | data_offset, |
| 5454 | index, |
| 5455 | scale_factor, |
| 5456 | temp, |
| 5457 | needs_null_check); |
| 5458 | } |
| 5459 | |
| 5460 | void CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5461 | Location ref, |
| 5462 | GpuRegister obj, |
| 5463 | uint32_t offset, |
| 5464 | Location index, |
| 5465 | ScaleFactor scale_factor, |
| 5466 | Location temp, |
| 5467 | bool needs_null_check, |
| 5468 | bool always_update_field) { |
| 5469 | DCHECK(kEmitCompilerReadBarrier); |
| 5470 | DCHECK(kUseBakerReadBarrier); |
| 5471 | |
| 5472 | // In slow path based read barriers, the read barrier call is |
| 5473 | // inserted after the original load. However, in fast path based |
| 5474 | // Baker's read barriers, we need to perform the load of |
| 5475 | // mirror::Object::monitor_ *before* the original reference load. |
| 5476 | // This load-load ordering is required by the read barrier. |
| 5477 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 5478 | // |
| 5479 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 5480 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 5481 | // HeapReference<Object> ref = *src; // Original reference load. |
| 5482 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 5483 | // if (is_gray) { |
| 5484 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 5485 | // } |
| 5486 | // |
| 5487 | // Note: the original implementation in ReadBarrier::Barrier is |
| 5488 | // slightly more complex as it performs additional checks that we do |
| 5489 | // not do here for performance reasons. |
| 5490 | |
| 5491 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
| 5492 | GpuRegister temp_reg = temp.AsRegister<GpuRegister>(); |
| 5493 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 5494 | |
| 5495 | // /* int32_t */ monitor = obj->monitor_ |
| 5496 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 5497 | if (needs_null_check) { |
| 5498 | MaybeRecordImplicitNullCheck(instruction); |
| 5499 | } |
| 5500 | // /* LockWord */ lock_word = LockWord(monitor) |
| 5501 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 5502 | "art::LockWord and int32_t have different sizes."); |
| 5503 | |
| 5504 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 5505 | |
| 5506 | // The actual reference load. |
| 5507 | if (index.IsValid()) { |
| 5508 | // Load types involving an "index": ArrayGet, |
| 5509 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 5510 | // intrinsics. |
| 5511 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 5512 | if (index.IsConstant()) { |
| 5513 | size_t computed_offset = |
| 5514 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 5515 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, computed_offset); |
| 5516 | } else { |
| 5517 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 5518 | if (scale_factor == TIMES_1) { |
| 5519 | __ Daddu(TMP, index_reg, obj); |
| 5520 | } else { |
| 5521 | __ Dlsa(TMP, index_reg, obj, scale_factor); |
| 5522 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5523 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset); |
| 5524 | } |
| 5525 | } else { |
| 5526 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5527 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); |
| 5528 | } |
| 5529 | |
| 5530 | // Object* ref = ref_addr->AsMirrorPtr() |
| 5531 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5532 | |
| 5533 | // Slow path marking the object `ref` when it is gray. |
| 5534 | SlowPathCodeMIPS64* slow_path; |
| 5535 | if (always_update_field) { |
| 5536 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 only supports address |
| 5537 | // of the form `obj + field_offset`, where `obj` is a register and |
| 5538 | // `field_offset` is a register. Thus `offset` and `scale_factor` |
| 5539 | // above are expected to be null in this code path. |
| 5540 | DCHECK_EQ(offset, 0u); |
| 5541 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5542 | slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5543 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(instruction, |
| 5544 | ref, |
| 5545 | obj, |
| 5546 | /* field_offset */ index, |
| 5547 | temp_reg); |
| 5548 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5549 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64(instruction, ref); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5550 | } |
| 5551 | AddSlowPath(slow_path); |
| 5552 | |
| 5553 | // if (rb_state == ReadBarrier::GrayState()) |
| 5554 | // ref = ReadBarrier::Mark(ref); |
| 5555 | // Given the numeric representation, it's enough to check the low bit of the |
| 5556 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 5557 | // performing a branch on less than zero. |
| 5558 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 5559 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 5560 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 5561 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 5562 | __ Bltzc(temp_reg, slow_path->GetEntryLabel()); |
| 5563 | __ Bind(slow_path->GetExitLabel()); |
| 5564 | } |
| 5565 | |
| 5566 | void CodeGeneratorMIPS64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 5567 | Location out, |
| 5568 | Location ref, |
| 5569 | Location obj, |
| 5570 | uint32_t offset, |
| 5571 | Location index) { |
| 5572 | DCHECK(kEmitCompilerReadBarrier); |
| 5573 | |
| 5574 | // Insert a slow path based read barrier *after* the reference load. |
| 5575 | // |
| 5576 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5577 | // reference will be carried out by the runtime within the slow |
| 5578 | // path. |
| 5579 | // |
| 5580 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5581 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5582 | // not used by the artReadBarrierSlow entry point. |
| 5583 | // |
| 5584 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5585 | SlowPathCodeMIPS64* slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5586 | ReadBarrierForHeapReferenceSlowPathMIPS64(instruction, out, ref, obj, offset, index); |
| 5587 | AddSlowPath(slow_path); |
| 5588 | |
| 5589 | __ Bc(slow_path->GetEntryLabel()); |
| 5590 | __ Bind(slow_path->GetExitLabel()); |
| 5591 | } |
| 5592 | |
| 5593 | void CodeGeneratorMIPS64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 5594 | Location out, |
| 5595 | Location ref, |
| 5596 | Location obj, |
| 5597 | uint32_t offset, |
| 5598 | Location index) { |
| 5599 | if (kEmitCompilerReadBarrier) { |
| 5600 | // Baker's read barriers shall be handled by the fast path |
| 5601 | // (CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier). |
| 5602 | DCHECK(!kUseBakerReadBarrier); |
| 5603 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5604 | // by the runtime within the slow path. |
| 5605 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 5606 | } else if (kPoisonHeapReferences) { |
| 5607 | __ UnpoisonHeapReference(out.AsRegister<GpuRegister>()); |
| 5608 | } |
| 5609 | } |
| 5610 | |
| 5611 | void CodeGeneratorMIPS64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 5612 | Location out, |
| 5613 | Location root) { |
| 5614 | DCHECK(kEmitCompilerReadBarrier); |
| 5615 | |
| 5616 | // Insert a slow path based read barrier *after* the GC root load. |
| 5617 | // |
| 5618 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5619 | // not need to do anything special for this here. |
| 5620 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5621 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS64(instruction, out, root); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5622 | AddSlowPath(slow_path); |
| 5623 | |
| 5624 | __ Bc(slow_path->GetEntryLabel()); |
| 5625 | __ Bind(slow_path->GetExitLabel()); |
| 5626 | } |
| 5627 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5628 | void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5629 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5630 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5631 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5632 | switch (type_check_kind) { |
| 5633 | case TypeCheckKind::kExactCheck: |
| 5634 | case TypeCheckKind::kAbstractClassCheck: |
| 5635 | case TypeCheckKind::kClassHierarchyCheck: |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5636 | case TypeCheckKind::kArrayObjectCheck: { |
| 5637 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 5638 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 5639 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5640 | break; |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5641 | } |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5642 | case TypeCheckKind::kArrayCheck: |
| 5643 | case TypeCheckKind::kUnresolvedCheck: |
| 5644 | case TypeCheckKind::kInterfaceCheck: |
| 5645 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5646 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 5647 | case TypeCheckKind::kBitstringCheck: |
| 5648 | break; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5649 | } |
| 5650 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5651 | LocationSummary* locations = |
| 5652 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5653 | if (baker_read_barrier_slow_path) { |
| 5654 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5655 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5656 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 5657 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 5658 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 5659 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 5660 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 5661 | } else { |
| 5662 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5663 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5664 | // The output does overlap inputs. |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5665 | // Note that TypeCheckSlowPathMIPS64 uses this register too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5666 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5667 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5668 | } |
| 5669 | |
| 5670 | void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5671 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5672 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5673 | Location obj_loc = locations->InAt(0); |
| 5674 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 5675 | Location cls = locations->InAt(1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5676 | Location out_loc = locations->Out(); |
| 5677 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 5678 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 5679 | DCHECK_LE(num_temps, 1u); |
| 5680 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5681 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5682 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5683 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5684 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5685 | Mips64Label done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5686 | SlowPathCodeMIPS64* slow_path = nullptr; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5687 | |
| 5688 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5689 | // Avoid this check if we know `obj` is not null. |
| 5690 | if (instruction->MustDoNullCheck()) { |
| 5691 | __ Move(out, ZERO); |
| 5692 | __ Beqzc(obj, &done); |
| 5693 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5694 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5695 | switch (type_check_kind) { |
| 5696 | case TypeCheckKind::kExactCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5697 | ReadBarrierOption read_barrier_option = |
| 5698 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5699 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5700 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5701 | out_loc, |
| 5702 | obj_loc, |
| 5703 | class_offset, |
| 5704 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5705 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5706 | // Classes must be equal for the instanceof to succeed. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 5707 | __ Xor(out, out, cls.AsRegister<GpuRegister>()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5708 | __ Sltiu(out, out, 1); |
| 5709 | break; |
| 5710 | } |
| 5711 | |
| 5712 | case TypeCheckKind::kAbstractClassCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5713 | ReadBarrierOption read_barrier_option = |
| 5714 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5715 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5716 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5717 | out_loc, |
| 5718 | obj_loc, |
| 5719 | class_offset, |
| 5720 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5721 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5722 | // If the class is abstract, we eagerly fetch the super class of the |
| 5723 | // object to avoid doing a comparison we know will fail. |
| 5724 | Mips64Label loop; |
| 5725 | __ Bind(&loop); |
| 5726 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5727 | GenerateReferenceLoadOneRegister(instruction, |
| 5728 | out_loc, |
| 5729 | super_offset, |
| 5730 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5731 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5732 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5733 | __ Beqzc(out, &done); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 5734 | __ Bnec(out, cls.AsRegister<GpuRegister>(), &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5735 | __ LoadConst32(out, 1); |
| 5736 | break; |
| 5737 | } |
| 5738 | |
| 5739 | case TypeCheckKind::kClassHierarchyCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5740 | ReadBarrierOption read_barrier_option = |
| 5741 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5742 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5743 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5744 | out_loc, |
| 5745 | obj_loc, |
| 5746 | class_offset, |
| 5747 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5748 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5749 | // Walk over the class hierarchy to find a match. |
| 5750 | Mips64Label loop, success; |
| 5751 | __ Bind(&loop); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 5752 | __ Beqc(out, cls.AsRegister<GpuRegister>(), &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5753 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5754 | GenerateReferenceLoadOneRegister(instruction, |
| 5755 | out_loc, |
| 5756 | super_offset, |
| 5757 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5758 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5759 | __ Bnezc(out, &loop); |
| 5760 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5761 | __ Bc(&done); |
| 5762 | __ Bind(&success); |
| 5763 | __ LoadConst32(out, 1); |
| 5764 | break; |
| 5765 | } |
| 5766 | |
| 5767 | case TypeCheckKind::kArrayObjectCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5768 | ReadBarrierOption read_barrier_option = |
| 5769 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5770 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5771 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5772 | out_loc, |
| 5773 | obj_loc, |
| 5774 | class_offset, |
| 5775 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5776 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5777 | // Do an exact check. |
| 5778 | Mips64Label success; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 5779 | __ Beqc(out, cls.AsRegister<GpuRegister>(), &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5780 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 5781 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5782 | GenerateReferenceLoadOneRegister(instruction, |
| 5783 | out_loc, |
| 5784 | component_offset, |
| 5785 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5786 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5787 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5788 | __ Beqzc(out, &done); |
| 5789 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5790 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5791 | __ Sltiu(out, out, 1); |
| 5792 | __ Bc(&done); |
| 5793 | __ Bind(&success); |
| 5794 | __ LoadConst32(out, 1); |
| 5795 | break; |
| 5796 | } |
| 5797 | |
| 5798 | case TypeCheckKind::kArrayCheck: { |
| 5799 | // No read barrier since the slow path will retry upon failure. |
| 5800 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5801 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5802 | out_loc, |
| 5803 | obj_loc, |
| 5804 | class_offset, |
| 5805 | maybe_temp_loc, |
| 5806 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5807 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5808 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( |
| 5809 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5810 | codegen_->AddSlowPath(slow_path); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 5811 | __ Bnec(out, cls.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5812 | __ LoadConst32(out, 1); |
| 5813 | break; |
| 5814 | } |
| 5815 | |
| 5816 | case TypeCheckKind::kUnresolvedCheck: |
| 5817 | case TypeCheckKind::kInterfaceCheck: { |
| 5818 | // Note that we indeed only call on slow path, but we always go |
| 5819 | // into the slow path for the unresolved and interface check |
| 5820 | // cases. |
| 5821 | // |
| 5822 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5823 | // entry point without resorting to a type checking slow path |
| 5824 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5825 | // require to assign fixed registers for the inputs of this |
| 5826 | // HInstanceOf instruction (following the runtime calling |
| 5827 | // convention), which might be cluttered by the potential first |
| 5828 | // read barrier emission at the beginning of this method. |
| 5829 | // |
| 5830 | // TODO: Introduce a new runtime entry point taking the object |
| 5831 | // to test (instead of its class) as argument, and let it deal |
| 5832 | // with the read barrier issues. This will let us refactor this |
| 5833 | // case of the `switch` code as it was previously (with a direct |
| 5834 | // call to the runtime not using a type checking slow path). |
| 5835 | // This should also be beneficial for the other cases above. |
| 5836 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5837 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( |
| 5838 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5839 | codegen_->AddSlowPath(slow_path); |
| 5840 | __ Bc(slow_path->GetEntryLabel()); |
| 5841 | break; |
| 5842 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 5843 | |
| 5844 | case TypeCheckKind::kBitstringCheck: { |
| 5845 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5846 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5847 | out_loc, |
| 5848 | obj_loc, |
| 5849 | class_offset, |
| 5850 | maybe_temp_loc, |
| 5851 | kWithoutReadBarrier); |
| 5852 | |
| 5853 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 5854 | __ Sltiu(out, out, 1); |
| 5855 | break; |
| 5856 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5857 | } |
| 5858 | |
| 5859 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5860 | |
| 5861 | if (slow_path != nullptr) { |
| 5862 | __ Bind(slow_path->GetExitLabel()); |
| 5863 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5864 | } |
| 5865 | |
| 5866 | void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5867 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5868 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5869 | } |
| 5870 | |
| 5871 | void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 5872 | // Will be generated at use site. |
| 5873 | } |
| 5874 | |
| 5875 | void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5876 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5877 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5878 | } |
| 5879 | |
| 5880 | void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 5881 | // Will be generated at use site. |
| 5882 | } |
| 5883 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 5884 | void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 5885 | // The trampoline uses the same calling convention as dex calling conventions, |
| 5886 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 5887 | // the method_idx. |
| 5888 | HandleInvoke(invoke); |
| 5889 | } |
| 5890 | |
| 5891 | void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 5892 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 5893 | } |
| 5894 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5895 | void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) { |
| 5896 | InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor; |
| 5897 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 5898 | } |
| 5899 | |
| 5900 | void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5901 | HandleInvoke(invoke); |
| 5902 | // The register T0 is required to be used for the hidden argument in |
| 5903 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
| 5904 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); |
| 5905 | } |
| 5906 | |
| 5907 | void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5908 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 5909 | GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5910 | Location receiver = invoke->GetLocations()->InAt(0); |
| 5911 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5912 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5913 | |
| 5914 | // Set the hidden argument. |
| 5915 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(), |
| 5916 | invoke->GetDexMethodIndex()); |
| 5917 | |
| 5918 | // temp = object->GetClass(); |
| 5919 | if (receiver.IsStackSlot()) { |
| 5920 | __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex()); |
| 5921 | __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset); |
| 5922 | } else { |
| 5923 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset); |
| 5924 | } |
| 5925 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5926 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5927 | // emit a read barrier for the previous class reference load. |
| 5928 | // However this is not required in practice, as this is an |
| 5929 | // intermediate/temporary reference and because the current |
| 5930 | // concurrent copying collector keeps the from-space memory |
| 5931 | // intact/accessible until the end of the marking phase (the |
| 5932 | // concurrent copying collector may not in the future). |
| 5933 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5934 | __ LoadFromOffset(kLoadDoubleword, temp, temp, |
| 5935 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 5936 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5937 | invoke->GetImtIndex(), kMips64PointerSize)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5938 | // temp = temp->GetImtEntryAt(method_offset); |
| 5939 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 5940 | // T9 = temp->GetEntryPoint(); |
| 5941 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 5942 | // T9(); |
| 5943 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5944 | __ Nop(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5945 | DCHECK(!codegen_->IsLeafMethod()); |
| 5946 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5947 | } |
| 5948 | |
| 5949 | void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5950 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 5951 | if (intrinsic.TryDispatch(invoke)) { |
| 5952 | return; |
| 5953 | } |
| 5954 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5955 | HandleInvoke(invoke); |
| 5956 | } |
| 5957 | |
| 5958 | void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5959 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5960 | // art::PrepareForRegisterAllocation. |
| 5961 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5962 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5963 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 5964 | if (intrinsic.TryDispatch(invoke)) { |
| 5965 | return; |
| 5966 | } |
| 5967 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5968 | HandleInvoke(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5969 | } |
| 5970 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 5971 | void LocationsBuilderMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5972 | HandleInvoke(invoke); |
| 5973 | } |
| 5974 | |
| 5975 | void InstructionCodeGeneratorMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5976 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 5977 | } |
| 5978 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 5979 | void LocationsBuilderMIPS64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 5980 | HandleInvoke(invoke); |
| 5981 | } |
| 5982 | |
| 5983 | void InstructionCodeGeneratorMIPS64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 5984 | codegen_->GenerateInvokeCustomCall(invoke); |
| 5985 | } |
| 5986 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5987 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5988 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5989 | IntrinsicCodeGeneratorMIPS64 intrinsic(codegen); |
| 5990 | intrinsic.Dispatch(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5991 | return true; |
| 5992 | } |
| 5993 | return false; |
| 5994 | } |
| 5995 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5996 | HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind( |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5997 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5998 | bool fallback_load = false; |
| 5999 | switch (desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6000 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6001 | case HLoadString::LoadKind::kBootImageRelRo: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6002 | case HLoadString::LoadKind::kBssEntry: |
| 6003 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6004 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6005 | case HLoadString::LoadKind::kJitBootImageAddress: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6006 | case HLoadString::LoadKind::kJitTableAddress: |
| 6007 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6008 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6009 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6010 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6011 | } |
| 6012 | if (fallback_load) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6013 | desired_string_load_kind = HLoadString::LoadKind::kRuntimeCall; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6014 | } |
| 6015 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6016 | } |
| 6017 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6018 | HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind( |
| 6019 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6020 | bool fallback_load = false; |
| 6021 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6022 | case HLoadClass::LoadKind::kInvalid: |
| 6023 | LOG(FATAL) << "UNREACHABLE"; |
| 6024 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6025 | case HLoadClass::LoadKind::kReferrersClass: |
| 6026 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6027 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6028 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6029 | case HLoadClass::LoadKind::kBssEntry: |
| 6030 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6031 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6032 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6033 | case HLoadClass::LoadKind::kJitTableAddress: |
| 6034 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6035 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6036 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6037 | break; |
| 6038 | } |
| 6039 | if (fallback_load) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6040 | desired_class_load_kind = HLoadClass::LoadKind::kRuntimeCall; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6041 | } |
| 6042 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6043 | } |
| 6044 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6045 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch( |
| 6046 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 6047 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 6048 | // On MIPS64 we support all dispatch types. |
| 6049 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6050 | } |
| 6051 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 6052 | void CodeGeneratorMIPS64::GenerateStaticOrDirectCall( |
| 6053 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6054 | // 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] | 6055 | 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] | 6056 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 6057 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
| 6058 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 6059 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 6060 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6061 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 6062 | uint32_t offset = |
| 6063 | GetThreadOffset<kMips64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6064 | __ LoadFromOffset(kLoadDoubleword, |
| 6065 | temp.AsRegister<GpuRegister>(), |
| 6066 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 6067 | offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6068 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 6069 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6070 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6071 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6072 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 6073 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 6074 | DCHECK(GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6075 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6076 | NewBootImageMethodPatch(invoke->GetTargetMethod()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6077 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6078 | NewBootImageMethodPatch(invoke->GetTargetMethod(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6079 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 6080 | __ Daddiu(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 6081 | break; |
| 6082 | } |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 6083 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6084 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 6085 | PcRelativePatchInfo* info_high = NewBootImageRelRoPatch(boot_image_offset); |
| 6086 | PcRelativePatchInfo* info_low = NewBootImageRelRoPatch(boot_image_offset, info_high); |
| 6087 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 6088 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 6089 | __ Lwu(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 6090 | break; |
| 6091 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 6092 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6093 | PcRelativePatchInfo* info_high = NewMethodBssEntryPatch( |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 6094 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6095 | PcRelativePatchInfo* info_low = NewMethodBssEntryPatch( |
| 6096 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high); |
| 6097 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 6098 | __ Ld(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 6099 | break; |
| 6100 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6101 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 6102 | __ LoadLiteral(temp.AsRegister<GpuRegister>(), |
| 6103 | kLoadDoubleword, |
| 6104 | DeduplicateUint64Literal(invoke->GetMethodAddress())); |
| 6105 | break; |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 6106 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 6107 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 6108 | return; // No code pointer retrieval; the runtime performs the call directly. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6109 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6110 | } |
| 6111 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 6112 | switch (code_ptr_location) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6113 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 6114 | __ Balc(&frame_entry_label_); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6115 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6116 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 6117 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
| 6118 | __ LoadFromOffset(kLoadDoubleword, |
| 6119 | T9, |
| 6120 | callee_method.AsRegister<GpuRegister>(), |
| 6121 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6122 | kMips64PointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6123 | // T9() |
| 6124 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 6125 | __ Nop(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6126 | break; |
| 6127 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 6128 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 6129 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6130 | DCHECK(!IsLeafMethod()); |
| 6131 | } |
| 6132 | |
| 6133 | void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 6134 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 6135 | // art::PrepareForRegisterAllocation. |
| 6136 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6137 | |
| 6138 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 6139 | return; |
| 6140 | } |
| 6141 | |
| 6142 | LocationSummary* locations = invoke->GetLocations(); |
| 6143 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 6144 | locations->HasTemps() |
| 6145 | ? locations->GetTemp(0) |
| 6146 | : Location::NoLocation()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6147 | } |
| 6148 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 6149 | void CodeGeneratorMIPS64::GenerateVirtualCall( |
| 6150 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6151 | // Use the calling convention instead of the location of the receiver, as |
| 6152 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 6153 | // slow path, the arguments have been moved to the right place, so here we are |
| 6154 | // guaranteed that the receiver is the first register of the calling convention. |
| 6155 | InvokeDexCallingConvention calling_convention; |
| 6156 | GpuRegister receiver = calling_convention.GetRegisterAt(0); |
| 6157 | |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 6158 | GpuRegister temp = temp_location.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6159 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 6160 | invoke->GetVTableIndex(), kMips64PointerSize).SizeValue(); |
| 6161 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6162 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6163 | |
| 6164 | // temp = object->GetClass(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6165 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 6166 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6167 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 6168 | // emit a read barrier for the previous class reference load. |
| 6169 | // However this is not required in practice, as this is an |
| 6170 | // intermediate/temporary reference and because the current |
| 6171 | // concurrent copying collector keeps the from-space memory |
| 6172 | // intact/accessible until the end of the marking phase (the |
| 6173 | // concurrent copying collector may not in the future). |
| 6174 | __ MaybeUnpoisonHeapReference(temp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6175 | // temp = temp->GetMethodAt(method_offset); |
| 6176 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 6177 | // T9 = temp->GetEntryPoint(); |
| 6178 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 6179 | // T9(); |
| 6180 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 6181 | __ Nop(); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 6182 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 6183 | } |
| 6184 | |
| 6185 | void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 6186 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 6187 | return; |
| 6188 | } |
| 6189 | |
| 6190 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6191 | DCHECK(!codegen_->IsLeafMethod()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6192 | } |
| 6193 | |
| 6194 | void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6195 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6196 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6197 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6198 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6199 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6200 | return; |
| 6201 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6202 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6203 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6204 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6205 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6206 | ? LocationSummary::kCallOnSlowPath |
| 6207 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6208 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6209 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 6210 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 6211 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6212 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6213 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6214 | } |
| 6215 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6216 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6217 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6218 | // Rely on the type resolution or initialization and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame^] | 6219 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6220 | } else { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6221 | // For non-Baker read barriers we have a temp-clobbering call. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6222 | } |
| 6223 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6224 | } |
| 6225 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6226 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6227 | // move. |
| 6228 | void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6229 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6230 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6231 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6232 | return; |
| 6233 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6234 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6235 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6236 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6237 | Location out_loc = locations->Out(); |
| 6238 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 6239 | GpuRegister current_method_reg = ZERO; |
| 6240 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6241 | load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6242 | current_method_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6243 | } |
| 6244 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6245 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6246 | ? kWithoutReadBarrier |
| 6247 | : kCompilerReadBarrierOption; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6248 | bool generate_null_check = false; |
| 6249 | switch (load_kind) { |
| 6250 | case HLoadClass::LoadKind::kReferrersClass: |
| 6251 | DCHECK(!cls->CanCallRuntime()); |
| 6252 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6253 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6254 | GenerateGcRootFieldLoad(cls, |
| 6255 | out_loc, |
| 6256 | current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6257 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 6258 | read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6259 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6260 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6261 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6262 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6263 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6264 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6265 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6266 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6267 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6268 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
| 6269 | break; |
| 6270 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6271 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6272 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6273 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6274 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6275 | codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6276 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6277 | codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6278 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 6279 | __ Lwu(out, AT, /* placeholder */ 0x5678); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6280 | break; |
| 6281 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6282 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6283 | CodeGeneratorMIPS64::PcRelativePatchInfo* bss_info_high = |
| 6284 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6285 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6286 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6287 | codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, out); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6288 | GenerateGcRootFieldLoad(cls, |
| 6289 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6290 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6291 | /* placeholder */ 0x5678, |
| 6292 | read_barrier_option, |
| 6293 | &info_low->label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6294 | generate_null_check = true; |
| 6295 | break; |
| 6296 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6297 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 6298 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6299 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 6300 | DCHECK_NE(address, 0u); |
| 6301 | __ LoadLiteral(out, |
| 6302 | kLoadUnsignedWord, |
| 6303 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6304 | break; |
| 6305 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6306 | case HLoadClass::LoadKind::kJitTableAddress: |
| 6307 | __ LoadLiteral(out, |
| 6308 | kLoadUnsignedWord, |
| 6309 | codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6310 | cls->GetTypeIndex(), |
| 6311 | cls->GetClass())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6312 | GenerateGcRootFieldLoad(cls, out_loc, out, 0, read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6313 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6314 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6315 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6316 | LOG(FATAL) << "UNREACHABLE"; |
| 6317 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6318 | } |
| 6319 | |
| 6320 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6321 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6322 | SlowPathCodeMIPS64* slow_path = |
| 6323 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64(cls, cls); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6324 | codegen_->AddSlowPath(slow_path); |
| 6325 | if (generate_null_check) { |
| 6326 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 6327 | } |
| 6328 | if (cls->MustGenerateClinitCheck()) { |
| 6329 | GenerateClassInitializationCheck(slow_path, out); |
| 6330 | } else { |
| 6331 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6332 | } |
| 6333 | } |
| 6334 | } |
| 6335 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6336 | void LocationsBuilderMIPS64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6337 | InvokeRuntimeCallingConvention calling_convention; |
| 6338 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6339 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, loc, loc); |
| 6340 | } |
| 6341 | |
| 6342 | void InstructionCodeGeneratorMIPS64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6343 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 6344 | } |
| 6345 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6346 | void LocationsBuilderMIPS64::VisitLoadMethodType(HLoadMethodType* load) { |
| 6347 | InvokeRuntimeCallingConvention calling_convention; |
| 6348 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6349 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, loc, loc); |
| 6350 | } |
| 6351 | |
| 6352 | void InstructionCodeGeneratorMIPS64::VisitLoadMethodType(HLoadMethodType* load) { |
| 6353 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 6354 | } |
| 6355 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6356 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6357 | return Thread::ExceptionOffset<kMips64PointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6358 | } |
| 6359 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6360 | void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) { |
| 6361 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6362 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6363 | locations->SetOut(Location::RequiresRegister()); |
| 6364 | } |
| 6365 | |
| 6366 | void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) { |
| 6367 | GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6368 | __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset()); |
| 6369 | } |
| 6370 | |
| 6371 | void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6372 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6373 | } |
| 6374 | |
| 6375 | void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6376 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6377 | } |
| 6378 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6379 | void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6380 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6381 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6382 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6383 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6384 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6385 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6386 | } else { |
| 6387 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6388 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6389 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6390 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame^] | 6391 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6392 | } else { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6393 | // For non-Baker read barriers we have a temp-clobbering call. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6394 | } |
| 6395 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6396 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6397 | } |
| 6398 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6399 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6400 | // move. |
| 6401 | void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6402 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6403 | LocationSummary* locations = load->GetLocations(); |
| 6404 | Location out_loc = locations->Out(); |
| 6405 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 6406 | |
| 6407 | switch (load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6408 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6409 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6410 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6411 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6412 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6413 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6414 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6415 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6416 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6417 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6418 | case HLoadString::LoadKind::kBootImageRelRo: { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6419 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6420 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(load); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6421 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6422 | codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6423 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6424 | codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6425 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 6426 | __ Lwu(out, AT, /* placeholder */ 0x5678); |
| 6427 | return; |
| 6428 | } |
| 6429 | case HLoadString::LoadKind::kBssEntry: { |
| 6430 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6431 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
| 6432 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| 6433 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6434 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6435 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, out); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6436 | GenerateGcRootFieldLoad(load, |
| 6437 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6438 | out, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6439 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6440 | kCompilerReadBarrierOption, |
| 6441 | &info_low->label); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6442 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6443 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS64(load); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6444 | codegen_->AddSlowPath(slow_path); |
| 6445 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 6446 | __ Bind(slow_path->GetExitLabel()); |
| 6447 | return; |
| 6448 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6449 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 6450 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 6451 | DCHECK_NE(address, 0u); |
| 6452 | __ LoadLiteral(out, |
| 6453 | kLoadUnsignedWord, |
| 6454 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6455 | return; |
| 6456 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6457 | case HLoadString::LoadKind::kJitTableAddress: |
| 6458 | __ LoadLiteral(out, |
| 6459 | kLoadUnsignedWord, |
| 6460 | codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
| 6461 | load->GetStringIndex(), |
| 6462 | load->GetString())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6463 | GenerateGcRootFieldLoad(load, out_loc, out, 0, kCompilerReadBarrierOption); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6464 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6465 | default: |
| 6466 | break; |
| 6467 | } |
| 6468 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6469 | // 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] | 6470 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6471 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6472 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6473 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
| 6474 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6475 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6476 | } |
| 6477 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6478 | void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6479 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6480 | locations->SetOut(Location::ConstantLocation(constant)); |
| 6481 | } |
| 6482 | |
| 6483 | void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 6484 | // Will be generated at use site. |
| 6485 | } |
| 6486 | |
| 6487 | void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6488 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6489 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6490 | InvokeRuntimeCallingConvention calling_convention; |
| 6491 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6492 | } |
| 6493 | |
| 6494 | void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6495 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6496 | instruction, |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6497 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6498 | if (instruction->IsEnter()) { |
| 6499 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6500 | } else { |
| 6501 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6502 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6503 | } |
| 6504 | |
| 6505 | void LocationsBuilderMIPS64::VisitMul(HMul* mul) { |
| 6506 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6507 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6508 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6509 | case DataType::Type::kInt32: |
| 6510 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6511 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6512 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6513 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6514 | break; |
| 6515 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6516 | case DataType::Type::kFloat32: |
| 6517 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6518 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6519 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 6520 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6521 | break; |
| 6522 | |
| 6523 | default: |
| 6524 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 6525 | } |
| 6526 | } |
| 6527 | |
| 6528 | void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6529 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6530 | LocationSummary* locations = instruction->GetLocations(); |
| 6531 | |
| 6532 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6533 | case DataType::Type::kInt32: |
| 6534 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6535 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6536 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6537 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6538 | if (type == DataType::Type::kInt32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6539 | __ MulR6(dst, lhs, rhs); |
| 6540 | else |
| 6541 | __ Dmul(dst, lhs, rhs); |
| 6542 | break; |
| 6543 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6544 | case DataType::Type::kFloat32: |
| 6545 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6546 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6547 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 6548 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6549 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6550 | __ MulS(dst, lhs, rhs); |
| 6551 | else |
| 6552 | __ MulD(dst, lhs, rhs); |
| 6553 | break; |
| 6554 | } |
| 6555 | default: |
| 6556 | LOG(FATAL) << "Unexpected mul type " << type; |
| 6557 | } |
| 6558 | } |
| 6559 | |
| 6560 | void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) { |
| 6561 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6562 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6563 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6564 | case DataType::Type::kInt32: |
| 6565 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6566 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6567 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6568 | break; |
| 6569 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6570 | case DataType::Type::kFloat32: |
| 6571 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6572 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6573 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6574 | break; |
| 6575 | |
| 6576 | default: |
| 6577 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 6578 | } |
| 6579 | } |
| 6580 | |
| 6581 | void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6582 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6583 | LocationSummary* locations = instruction->GetLocations(); |
| 6584 | |
| 6585 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6586 | case DataType::Type::kInt32: |
| 6587 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6588 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6589 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6590 | if (type == DataType::Type::kInt32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6591 | __ Subu(dst, ZERO, src); |
| 6592 | else |
| 6593 | __ Dsubu(dst, ZERO, src); |
| 6594 | break; |
| 6595 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6596 | case DataType::Type::kFloat32: |
| 6597 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6598 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6599 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6600 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6601 | __ NegS(dst, src); |
| 6602 | else |
| 6603 | __ NegD(dst, src); |
| 6604 | break; |
| 6605 | } |
| 6606 | default: |
| 6607 | LOG(FATAL) << "Unexpected neg type " << type; |
| 6608 | } |
| 6609 | } |
| 6610 | |
| 6611 | void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6612 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6613 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6614 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6615 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6616 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6617 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6618 | } |
| 6619 | |
| 6620 | void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6621 | // Note: if heap poisoning is enabled, the entry point takes care |
| 6622 | // of poisoning the reference. |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 6623 | QuickEntrypointEnum entrypoint = |
| 6624 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 6625 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6626 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 6627 | DCHECK(!codegen_->IsLeafMethod()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6628 | } |
| 6629 | |
| 6630 | void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6631 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6632 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6633 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 6634 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6635 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6636 | } |
| 6637 | |
| 6638 | void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 6639 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 6640 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6641 | } |
| 6642 | |
| 6643 | void LocationsBuilderMIPS64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6644 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6645 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6646 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6647 | } |
| 6648 | |
| 6649 | void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6650 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6651 | LocationSummary* locations = instruction->GetLocations(); |
| 6652 | |
| 6653 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6654 | case DataType::Type::kInt32: |
| 6655 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6656 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6657 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6658 | __ Nor(dst, src, ZERO); |
| 6659 | break; |
| 6660 | } |
| 6661 | |
| 6662 | default: |
| 6663 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 6664 | } |
| 6665 | } |
| 6666 | |
| 6667 | void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6668 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6669 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6670 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6671 | } |
| 6672 | |
| 6673 | void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
| 6674 | LocationSummary* locations = instruction->GetLocations(); |
| 6675 | __ Xori(locations->Out().AsRegister<GpuRegister>(), |
| 6676 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 6677 | 1); |
| 6678 | } |
| 6679 | |
| 6680 | void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6681 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 6682 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6683 | } |
| 6684 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6685 | void CodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6686 | if (CanMoveNullCheckToUser(instruction)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6687 | return; |
| 6688 | } |
| 6689 | Location obj = instruction->GetLocations()->InAt(0); |
| 6690 | |
| 6691 | __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6692 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6693 | } |
| 6694 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6695 | void CodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6696 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6697 | new (GetScopedAllocator()) NullCheckSlowPathMIPS64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6698 | AddSlowPath(slow_path); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6699 | |
| 6700 | Location obj = instruction->GetLocations()->InAt(0); |
| 6701 | |
| 6702 | __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 6703 | } |
| 6704 | |
| 6705 | void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6706 | codegen_->GenerateNullCheck(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6707 | } |
| 6708 | |
| 6709 | void LocationsBuilderMIPS64::VisitOr(HOr* instruction) { |
| 6710 | HandleBinaryOp(instruction); |
| 6711 | } |
| 6712 | |
| 6713 | void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) { |
| 6714 | HandleBinaryOp(instruction); |
| 6715 | } |
| 6716 | |
| 6717 | void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6718 | LOG(FATAL) << "Unreachable"; |
| 6719 | } |
| 6720 | |
| 6721 | void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6722 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6723 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6724 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6725 | // The back edge will generate the suspend check. |
| 6726 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6727 | } |
| 6728 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6729 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6730 | } |
| 6731 | |
| 6732 | void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6733 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6734 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 6735 | if (location.IsStackSlot()) { |
| 6736 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6737 | } else if (location.IsDoubleStackSlot()) { |
| 6738 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6739 | } |
| 6740 | locations->SetOut(location); |
| 6741 | } |
| 6742 | |
| 6743 | void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction |
| 6744 | ATTRIBUTE_UNUSED) { |
| 6745 | // Nothing to do, the parameter is already at its location. |
| 6746 | } |
| 6747 | |
| 6748 | void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 6749 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6750 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6751 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6752 | } |
| 6753 | |
| 6754 | void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction |
| 6755 | ATTRIBUTE_UNUSED) { |
| 6756 | // Nothing to do, the method is already at its location. |
| 6757 | } |
| 6758 | |
| 6759 | void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6760 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6761 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6762 | locations->SetInAt(i, Location::Any()); |
| 6763 | } |
| 6764 | locations->SetOut(Location::Any()); |
| 6765 | } |
| 6766 | |
| 6767 | void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 6768 | LOG(FATAL) << "Unreachable"; |
| 6769 | } |
| 6770 | |
| 6771 | void LocationsBuilderMIPS64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6772 | DataType::Type type = rem->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6773 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6774 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 6775 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6776 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6777 | |
| 6778 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6779 | case DataType::Type::kInt32: |
| 6780 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6781 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 6782 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6783 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6784 | break; |
| 6785 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6786 | case DataType::Type::kFloat32: |
| 6787 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6788 | InvokeRuntimeCallingConvention calling_convention; |
| 6789 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 6790 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 6791 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 6792 | break; |
| 6793 | } |
| 6794 | |
| 6795 | default: |
| 6796 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6797 | } |
| 6798 | } |
| 6799 | |
| 6800 | void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6801 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6802 | |
| 6803 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6804 | case DataType::Type::kInt32: |
| 6805 | case DataType::Type::kInt64: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 6806 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6807 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6808 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6809 | case DataType::Type::kFloat32: |
| 6810 | case DataType::Type::kFloat64: { |
| 6811 | QuickEntrypointEnum entrypoint = |
| 6812 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6813 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6814 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6815 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 6816 | } else { |
| 6817 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 6818 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6819 | break; |
| 6820 | } |
| 6821 | default: |
| 6822 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6823 | } |
| 6824 | } |
| 6825 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6826 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 6827 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 6828 | switch (minmax->GetResultType()) { |
| 6829 | case DataType::Type::kInt32: |
| 6830 | case DataType::Type::kInt64: |
| 6831 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6832 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6833 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6834 | break; |
| 6835 | case DataType::Type::kFloat32: |
| 6836 | case DataType::Type::kFloat64: |
| 6837 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6838 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 6839 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6840 | break; |
| 6841 | default: |
| 6842 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 6843 | } |
| 6844 | } |
| 6845 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 6846 | void InstructionCodeGeneratorMIPS64::GenerateMinMaxInt(LocationSummary* locations, bool is_min) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6847 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6848 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
| 6849 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 6850 | |
| 6851 | if (lhs == rhs) { |
| 6852 | if (out != lhs) { |
| 6853 | __ Move(out, lhs); |
| 6854 | } |
| 6855 | } else { |
| 6856 | // Some architectures, such as ARM and MIPS (prior to r6), have a |
| 6857 | // conditional move instruction which only changes the target |
| 6858 | // (output) register if the condition is true (MIPS prior to r6 had |
| 6859 | // MOVF, MOVT, and MOVZ). The SELEQZ and SELNEZ instructions always |
| 6860 | // change the target (output) register. If the condition is true the |
| 6861 | // output register gets the contents of the "rs" register; otherwise, |
| 6862 | // the output register is set to zero. One consequence of this is |
| 6863 | // that to implement something like "rd = c==0 ? rs : rt" MIPS64r6 |
| 6864 | // needs to use a pair of SELEQZ/SELNEZ instructions. After |
| 6865 | // executing this pair of instructions one of the output registers |
| 6866 | // from the pair will necessarily contain zero. Then the code ORs the |
| 6867 | // output registers from the SELEQZ/SELNEZ instructions to get the |
| 6868 | // final result. |
| 6869 | // |
| 6870 | // The initial test to see if the output register is same as the |
| 6871 | // first input register is needed to make sure that value in the |
| 6872 | // first input register isn't clobbered before we've finished |
| 6873 | // computing the output value. The logic in the corresponding else |
| 6874 | // clause performs the same task but makes sure the second input |
| 6875 | // register isn't clobbered in the event that it's the same register |
| 6876 | // as the output register; the else clause also handles the case |
| 6877 | // where the output register is distinct from both the first, and the |
| 6878 | // second input registers. |
| 6879 | if (out == lhs) { |
| 6880 | __ Slt(AT, rhs, lhs); |
| 6881 | if (is_min) { |
| 6882 | __ Seleqz(out, lhs, AT); |
| 6883 | __ Selnez(AT, rhs, AT); |
| 6884 | } else { |
| 6885 | __ Selnez(out, lhs, AT); |
| 6886 | __ Seleqz(AT, rhs, AT); |
| 6887 | } |
| 6888 | } else { |
| 6889 | __ Slt(AT, lhs, rhs); |
| 6890 | if (is_min) { |
| 6891 | __ Seleqz(out, rhs, AT); |
| 6892 | __ Selnez(AT, lhs, AT); |
| 6893 | } else { |
| 6894 | __ Selnez(out, rhs, AT); |
| 6895 | __ Seleqz(AT, lhs, AT); |
| 6896 | } |
| 6897 | } |
| 6898 | __ Or(out, out, AT); |
| 6899 | } |
| 6900 | } |
| 6901 | |
| 6902 | void InstructionCodeGeneratorMIPS64::GenerateMinMaxFP(LocationSummary* locations, |
| 6903 | bool is_min, |
| 6904 | DataType::Type type) { |
| 6905 | FpuRegister a = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 6906 | FpuRegister b = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 6907 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6908 | |
| 6909 | Mips64Label noNaNs; |
| 6910 | Mips64Label done; |
| 6911 | FpuRegister ftmp = ((out != a) && (out != b)) ? out : FTMP; |
| 6912 | |
| 6913 | // When Java computes min/max it prefers a NaN to a number; the |
| 6914 | // behavior of MIPSR6 is to prefer numbers to NaNs, i.e., if one of |
| 6915 | // the inputs is a NaN and the other is a valid number, the MIPS |
| 6916 | // instruction will return the number; Java wants the NaN value |
| 6917 | // returned. This is why there is extra logic preceding the use of |
| 6918 | // the MIPS min.fmt/max.fmt instructions. If either a, or b holds a |
| 6919 | // NaN, return the NaN, otherwise return the min/max. |
| 6920 | if (type == DataType::Type::kFloat64) { |
| 6921 | __ CmpUnD(FTMP, a, b); |
| 6922 | __ Bc1eqz(FTMP, &noNaNs); |
| 6923 | |
| 6924 | // One of the inputs is a NaN |
| 6925 | __ CmpEqD(ftmp, a, a); |
| 6926 | // If a == a then b is the NaN, otherwise a is the NaN. |
| 6927 | __ SelD(ftmp, a, b); |
| 6928 | |
| 6929 | if (ftmp != out) { |
| 6930 | __ MovD(out, ftmp); |
| 6931 | } |
| 6932 | |
| 6933 | __ Bc(&done); |
| 6934 | |
| 6935 | __ Bind(&noNaNs); |
| 6936 | |
| 6937 | if (is_min) { |
| 6938 | __ MinD(out, a, b); |
| 6939 | } else { |
| 6940 | __ MaxD(out, a, b); |
| 6941 | } |
| 6942 | } else { |
| 6943 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 6944 | __ CmpUnS(FTMP, a, b); |
| 6945 | __ Bc1eqz(FTMP, &noNaNs); |
| 6946 | |
| 6947 | // One of the inputs is a NaN |
| 6948 | __ CmpEqS(ftmp, a, a); |
| 6949 | // If a == a then b is the NaN, otherwise a is the NaN. |
| 6950 | __ SelS(ftmp, a, b); |
| 6951 | |
| 6952 | if (ftmp != out) { |
| 6953 | __ MovS(out, ftmp); |
| 6954 | } |
| 6955 | |
| 6956 | __ Bc(&done); |
| 6957 | |
| 6958 | __ Bind(&noNaNs); |
| 6959 | |
| 6960 | if (is_min) { |
| 6961 | __ MinS(out, a, b); |
| 6962 | } else { |
| 6963 | __ MaxS(out, a, b); |
| 6964 | } |
| 6965 | } |
| 6966 | |
| 6967 | __ Bind(&done); |
| 6968 | } |
| 6969 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 6970 | void InstructionCodeGeneratorMIPS64::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 6971 | DataType::Type type = minmax->GetResultType(); |
| 6972 | switch (type) { |
| 6973 | case DataType::Type::kInt32: |
| 6974 | case DataType::Type::kInt64: |
| 6975 | GenerateMinMaxInt(minmax->GetLocations(), is_min); |
| 6976 | break; |
| 6977 | case DataType::Type::kFloat32: |
| 6978 | case DataType::Type::kFloat64: |
| 6979 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 6980 | break; |
| 6981 | default: |
| 6982 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 6983 | } |
| 6984 | } |
| 6985 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6986 | void LocationsBuilderMIPS64::VisitMin(HMin* min) { |
| 6987 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 6988 | } |
| 6989 | |
| 6990 | void InstructionCodeGeneratorMIPS64::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 6991 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6992 | } |
| 6993 | |
| 6994 | void LocationsBuilderMIPS64::VisitMax(HMax* max) { |
| 6995 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 6996 | } |
| 6997 | |
| 6998 | void InstructionCodeGeneratorMIPS64::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 6999 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 7000 | } |
| 7001 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 7002 | void LocationsBuilderMIPS64::VisitAbs(HAbs* abs) { |
| 7003 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 7004 | switch (abs->GetResultType()) { |
| 7005 | case DataType::Type::kInt32: |
| 7006 | case DataType::Type::kInt64: |
| 7007 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7008 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7009 | break; |
| 7010 | case DataType::Type::kFloat32: |
| 7011 | case DataType::Type::kFloat64: |
| 7012 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 7013 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 7014 | break; |
| 7015 | default: |
| 7016 | LOG(FATAL) << "Unexpected abs type " << abs->GetResultType(); |
| 7017 | } |
| 7018 | } |
| 7019 | |
| 7020 | void InstructionCodeGeneratorMIPS64::VisitAbs(HAbs* abs) { |
| 7021 | LocationSummary* locations = abs->GetLocations(); |
| 7022 | switch (abs->GetResultType()) { |
| 7023 | case DataType::Type::kInt32: { |
| 7024 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 7025 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 7026 | __ Sra(AT, in, 31); |
| 7027 | __ Xor(out, in, AT); |
| 7028 | __ Subu(out, out, AT); |
| 7029 | break; |
| 7030 | } |
| 7031 | case DataType::Type::kInt64: { |
| 7032 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 7033 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 7034 | __ Dsra32(AT, in, 31); |
| 7035 | __ Xor(out, in, AT); |
| 7036 | __ Dsubu(out, out, AT); |
| 7037 | break; |
| 7038 | } |
| 7039 | case DataType::Type::kFloat32: { |
| 7040 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 7041 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 7042 | __ AbsS(out, in); |
| 7043 | break; |
| 7044 | } |
| 7045 | case DataType::Type::kFloat64: { |
| 7046 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 7047 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 7048 | __ AbsD(out, in); |
| 7049 | break; |
| 7050 | } |
| 7051 | default: |
| 7052 | LOG(FATAL) << "Unexpected abs type " << abs->GetResultType(); |
| 7053 | } |
| 7054 | } |
| 7055 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7056 | void LocationsBuilderMIPS64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 7057 | constructor_fence->SetLocations(nullptr); |
| 7058 | } |
| 7059 | |
| 7060 | void InstructionCodeGeneratorMIPS64::VisitConstructorFence( |
| 7061 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 7062 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 7063 | } |
| 7064 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7065 | void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 7066 | memory_barrier->SetLocations(nullptr); |
| 7067 | } |
| 7068 | |
| 7069 | void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 7070 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 7071 | } |
| 7072 | |
| 7073 | void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7074 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7075 | DataType::Type return_type = ret->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7076 | locations->SetInAt(0, Mips64ReturnLocation(return_type)); |
| 7077 | } |
| 7078 | |
| 7079 | void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 7080 | codegen_->GenerateFrameExit(); |
| 7081 | } |
| 7082 | |
| 7083 | void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) { |
| 7084 | ret->SetLocations(nullptr); |
| 7085 | } |
| 7086 | |
| 7087 | void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 7088 | codegen_->GenerateFrameExit(); |
| 7089 | } |
| 7090 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 7091 | void LocationsBuilderMIPS64::VisitRor(HRor* ror) { |
| 7092 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 7093 | } |
| 7094 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 7095 | void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) { |
| 7096 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 7097 | } |
| 7098 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7099 | void LocationsBuilderMIPS64::VisitShl(HShl* shl) { |
| 7100 | HandleShift(shl); |
| 7101 | } |
| 7102 | |
| 7103 | void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) { |
| 7104 | HandleShift(shl); |
| 7105 | } |
| 7106 | |
| 7107 | void LocationsBuilderMIPS64::VisitShr(HShr* shr) { |
| 7108 | HandleShift(shr); |
| 7109 | } |
| 7110 | |
| 7111 | void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) { |
| 7112 | HandleShift(shr); |
| 7113 | } |
| 7114 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7115 | void LocationsBuilderMIPS64::VisitSub(HSub* instruction) { |
| 7116 | HandleBinaryOp(instruction); |
| 7117 | } |
| 7118 | |
| 7119 | void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) { |
| 7120 | HandleBinaryOp(instruction); |
| 7121 | } |
| 7122 | |
| 7123 | void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 7124 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 7125 | } |
| 7126 | |
| 7127 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 7128 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 7129 | } |
| 7130 | |
| 7131 | void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 7132 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 7133 | } |
| 7134 | |
| 7135 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 7136 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7137 | } |
| 7138 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7139 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet( |
| 7140 | HUnresolvedInstanceFieldGet* instruction) { |
| 7141 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 7142 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 7143 | instruction, instruction->GetFieldType(), calling_convention); |
| 7144 | } |
| 7145 | |
| 7146 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet( |
| 7147 | HUnresolvedInstanceFieldGet* instruction) { |
| 7148 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 7149 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 7150 | instruction->GetFieldType(), |
| 7151 | instruction->GetFieldIndex(), |
| 7152 | instruction->GetDexPc(), |
| 7153 | calling_convention); |
| 7154 | } |
| 7155 | |
| 7156 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet( |
| 7157 | HUnresolvedInstanceFieldSet* instruction) { |
| 7158 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 7159 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 7160 | instruction, instruction->GetFieldType(), calling_convention); |
| 7161 | } |
| 7162 | |
| 7163 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet( |
| 7164 | HUnresolvedInstanceFieldSet* instruction) { |
| 7165 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 7166 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 7167 | instruction->GetFieldType(), |
| 7168 | instruction->GetFieldIndex(), |
| 7169 | instruction->GetDexPc(), |
| 7170 | calling_convention); |
| 7171 | } |
| 7172 | |
| 7173 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet( |
| 7174 | HUnresolvedStaticFieldGet* instruction) { |
| 7175 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 7176 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 7177 | instruction, instruction->GetFieldType(), calling_convention); |
| 7178 | } |
| 7179 | |
| 7180 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet( |
| 7181 | HUnresolvedStaticFieldGet* instruction) { |
| 7182 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 7183 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 7184 | instruction->GetFieldType(), |
| 7185 | instruction->GetFieldIndex(), |
| 7186 | instruction->GetDexPc(), |
| 7187 | calling_convention); |
| 7188 | } |
| 7189 | |
| 7190 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet( |
| 7191 | HUnresolvedStaticFieldSet* instruction) { |
| 7192 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 7193 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 7194 | instruction, instruction->GetFieldType(), calling_convention); |
| 7195 | } |
| 7196 | |
| 7197 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet( |
| 7198 | HUnresolvedStaticFieldSet* instruction) { |
| 7199 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 7200 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 7201 | instruction->GetFieldType(), |
| 7202 | instruction->GetFieldIndex(), |
| 7203 | instruction->GetDexPc(), |
| 7204 | calling_convention); |
| 7205 | } |
| 7206 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7207 | void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7208 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7209 | instruction, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 7210 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 7211 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 7212 | // registers in full width (since the runtime only saves/restores lower part). |
| 7213 | locations->SetCustomSlowPathCallerSaves( |
| 7214 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7215 | } |
| 7216 | |
| 7217 | void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 7218 | HBasicBlock* block = instruction->GetBlock(); |
| 7219 | if (block->GetLoopInformation() != nullptr) { |
| 7220 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 7221 | // The back edge will generate the suspend check. |
| 7222 | return; |
| 7223 | } |
| 7224 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 7225 | // The goto will generate the suspend check. |
| 7226 | return; |
| 7227 | } |
| 7228 | GenerateSuspendCheck(instruction, nullptr); |
| 7229 | } |
| 7230 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7231 | void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7232 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7233 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7234 | InvokeRuntimeCallingConvention calling_convention; |
| 7235 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7236 | } |
| 7237 | |
| 7238 | void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 7239 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7240 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 7241 | } |
| 7242 | |
| 7243 | void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7244 | DataType::Type input_type = conversion->GetInputType(); |
| 7245 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 7246 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 7247 | << input_type << " -> " << result_type; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7248 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7249 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 7250 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7251 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 7252 | } |
| 7253 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7254 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(conversion); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7255 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7256 | if (DataType::IsFloatingPointType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7257 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 7258 | } else { |
| 7259 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7260 | } |
| 7261 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7262 | if (DataType::IsFloatingPointType(result_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7263 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7264 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7265 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7266 | } |
| 7267 | } |
| 7268 | |
| 7269 | void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
| 7270 | LocationSummary* locations = conversion->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7271 | DataType::Type result_type = conversion->GetResultType(); |
| 7272 | DataType::Type input_type = conversion->GetInputType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7273 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 7274 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 7275 | << input_type << " -> " << result_type; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7276 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7277 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7278 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 7279 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 7280 | |
| 7281 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 7282 | case DataType::Type::kUint8: |
| 7283 | __ Andi(dst, src, 0xFF); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7284 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7285 | case DataType::Type::kInt8: |
| 7286 | if (input_type == DataType::Type::kInt64) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 7287 | // Type conversion from long to types narrower than int is a result of code |
| 7288 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 7289 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 7290 | __ Sll(dst, src, 0); |
| 7291 | __ Seb(dst, dst); |
| 7292 | } else { |
| 7293 | __ Seb(dst, src); |
| 7294 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7295 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 7296 | case DataType::Type::kUint16: |
| 7297 | __ Andi(dst, src, 0xFFFF); |
| 7298 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7299 | case DataType::Type::kInt16: |
| 7300 | if (input_type == DataType::Type::kInt64) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 7301 | // Type conversion from long to types narrower than int is a result of code |
| 7302 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 7303 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 7304 | __ Sll(dst, src, 0); |
| 7305 | __ Seh(dst, dst); |
| 7306 | } else { |
| 7307 | __ Seh(dst, src); |
| 7308 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7309 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7310 | case DataType::Type::kInt32: |
| 7311 | case DataType::Type::kInt64: |
Goran Jakovljevic | 992bdb9 | 2016-12-28 16:21:48 +0100 | [diff] [blame] | 7312 | // Sign-extend 32-bit int into bits 32 through 63 for int-to-long and long-to-int |
| 7313 | // conversions, except when the input and output registers are the same and we are not |
| 7314 | // converting longs to shorter types. In these cases, do nothing. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7315 | if ((input_type == DataType::Type::kInt64) || (dst != src)) { |
Goran Jakovljevic | 992bdb9 | 2016-12-28 16:21:48 +0100 | [diff] [blame] | 7316 | __ Sll(dst, src, 0); |
| 7317 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7318 | break; |
| 7319 | |
| 7320 | default: |
| 7321 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 7322 | << " to " << result_type; |
| 7323 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7324 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7325 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 7326 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7327 | if (input_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7328 | __ Dmtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7329 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7330 | __ Cvtsl(dst, FTMP); |
| 7331 | } else { |
| 7332 | __ Cvtdl(dst, FTMP); |
| 7333 | } |
| 7334 | } else { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7335 | __ Mtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7336 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7337 | __ Cvtsw(dst, FTMP); |
| 7338 | } else { |
| 7339 | __ Cvtdw(dst, FTMP); |
| 7340 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7341 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7342 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 7343 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7344 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 7345 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7346 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7347 | if (result_type == DataType::Type::kInt64) { |
| 7348 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7349 | __ TruncLS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7350 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7351 | __ TruncLD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7352 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7353 | __ Dmfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7354 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7355 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7356 | __ TruncWS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7357 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7358 | __ TruncWD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7359 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7360 | __ Mfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7361 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7362 | } else if (DataType::IsFloatingPointType(result_type) && |
| 7363 | DataType::IsFloatingPointType(input_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7364 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 7365 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7366 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7367 | __ Cvtsd(dst, src); |
| 7368 | } else { |
| 7369 | __ Cvtds(dst, src); |
| 7370 | } |
| 7371 | } else { |
| 7372 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 7373 | << " to " << result_type; |
| 7374 | } |
| 7375 | } |
| 7376 | |
| 7377 | void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) { |
| 7378 | HandleShift(ushr); |
| 7379 | } |
| 7380 | |
| 7381 | void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) { |
| 7382 | HandleShift(ushr); |
| 7383 | } |
| 7384 | |
| 7385 | void LocationsBuilderMIPS64::VisitXor(HXor* instruction) { |
| 7386 | HandleBinaryOp(instruction); |
| 7387 | } |
| 7388 | |
| 7389 | void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) { |
| 7390 | HandleBinaryOp(instruction); |
| 7391 | } |
| 7392 | |
| 7393 | void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 7394 | // Nothing to do, this should be removed during prepare for register allocator. |
| 7395 | LOG(FATAL) << "Unreachable"; |
| 7396 | } |
| 7397 | |
| 7398 | void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 7399 | // Nothing to do, this should be removed during prepare for register allocator. |
| 7400 | LOG(FATAL) << "Unreachable"; |
| 7401 | } |
| 7402 | |
| 7403 | void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7404 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7405 | } |
| 7406 | |
| 7407 | void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7408 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7409 | } |
| 7410 | |
| 7411 | void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7412 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7413 | } |
| 7414 | |
| 7415 | void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7416 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7417 | } |
| 7418 | |
| 7419 | void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7420 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7421 | } |
| 7422 | |
| 7423 | void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7424 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7425 | } |
| 7426 | |
| 7427 | void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7428 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7429 | } |
| 7430 | |
| 7431 | void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7432 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7433 | } |
| 7434 | |
| 7435 | void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7436 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7437 | } |
| 7438 | |
| 7439 | void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7440 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7441 | } |
| 7442 | |
| 7443 | void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7444 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7445 | } |
| 7446 | |
| 7447 | void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7448 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7449 | } |
| 7450 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7451 | void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7452 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7453 | } |
| 7454 | |
| 7455 | void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7456 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7457 | } |
| 7458 | |
| 7459 | void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7460 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7461 | } |
| 7462 | |
| 7463 | void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7464 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7465 | } |
| 7466 | |
| 7467 | void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7468 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7469 | } |
| 7470 | |
| 7471 | void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7472 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7473 | } |
| 7474 | |
| 7475 | void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7476 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7477 | } |
| 7478 | |
| 7479 | void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7480 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7481 | } |
| 7482 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7483 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7484 | void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7485 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7486 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7487 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7488 | } |
| 7489 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7490 | void InstructionCodeGeneratorMIPS64::GenPackedSwitchWithCompares(GpuRegister value_reg, |
| 7491 | int32_t lower_bound, |
| 7492 | uint32_t num_entries, |
| 7493 | HBasicBlock* switch_block, |
| 7494 | HBasicBlock* default_block) { |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7495 | // Create a set of compare/jumps. |
| 7496 | GpuRegister temp_reg = TMP; |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7497 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7498 | // Jump to default if index is negative |
| 7499 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 7500 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 7501 | __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block)); |
| 7502 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7503 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7504 | // Jump to successors[0] if value == lower_bound. |
| 7505 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 7506 | int32_t last_index = 0; |
| 7507 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7508 | __ Addiu(temp_reg, temp_reg, -2); |
| 7509 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7510 | __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 7511 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7512 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 7513 | } |
| 7514 | if (num_entries - last_index == 2) { |
| 7515 | // The last missing case_value. |
| 7516 | __ Addiu(temp_reg, temp_reg, -1); |
| 7517 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7518 | } |
| 7519 | |
| 7520 | // And the default for any other value. |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7521 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 7522 | __ Bc(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7523 | } |
| 7524 | } |
| 7525 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7526 | void InstructionCodeGeneratorMIPS64::GenTableBasedPackedSwitch(GpuRegister value_reg, |
| 7527 | int32_t lower_bound, |
| 7528 | uint32_t num_entries, |
| 7529 | HBasicBlock* switch_block, |
| 7530 | HBasicBlock* default_block) { |
| 7531 | // Create a jump table. |
| 7532 | std::vector<Mips64Label*> labels(num_entries); |
| 7533 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7534 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7535 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7536 | } |
| 7537 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 7538 | |
| 7539 | // Is the value in range? |
| 7540 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 7541 | __ LoadConst32(AT, num_entries); |
| 7542 | __ Bgeuc(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 7543 | |
| 7544 | // We are in the range of the table. |
| 7545 | // Load the target address from the jump table, indexing by the value. |
| 7546 | __ LoadLabelAddress(AT, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 7547 | __ Dlsa(TMP, TMP, AT, 2); |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7548 | __ Lw(TMP, TMP, 0); |
| 7549 | // Compute the absolute target address by adding the table start address |
| 7550 | // (the table contains offsets to targets relative to its start). |
| 7551 | __ Daddu(TMP, TMP, AT); |
| 7552 | // And jump. |
| 7553 | __ Jr(TMP); |
| 7554 | __ Nop(); |
| 7555 | } |
| 7556 | |
| 7557 | void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7558 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7559 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7560 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7561 | GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 7562 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 7563 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7564 | |
| 7565 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
| 7566 | GenTableBasedPackedSwitch(value_reg, |
| 7567 | lower_bound, |
| 7568 | num_entries, |
| 7569 | switch_block, |
| 7570 | default_block); |
| 7571 | } else { |
| 7572 | GenPackedSwitchWithCompares(value_reg, |
| 7573 | lower_bound, |
| 7574 | num_entries, |
| 7575 | switch_block, |
| 7576 | default_block); |
| 7577 | } |
| 7578 | } |
| 7579 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7580 | void LocationsBuilderMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 7581 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7582 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7583 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7584 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7585 | } |
| 7586 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7587 | void InstructionCodeGeneratorMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 7588 | LocationSummary* locations = instruction->GetLocations(); |
| 7589 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 7590 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7591 | instruction->GetIndex(), kMips64PointerSize).SizeValue(); |
| 7592 | __ LoadFromOffset(kLoadDoubleword, |
| 7593 | locations->Out().AsRegister<GpuRegister>(), |
| 7594 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 7595 | method_offset); |
| 7596 | } else { |
| 7597 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 7598 | instruction->GetIndex(), kMips64PointerSize)); |
| 7599 | __ LoadFromOffset(kLoadDoubleword, |
| 7600 | locations->Out().AsRegister<GpuRegister>(), |
| 7601 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 7602 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 7603 | __ LoadFromOffset(kLoadDoubleword, |
| 7604 | locations->Out().AsRegister<GpuRegister>(), |
| 7605 | locations->Out().AsRegister<GpuRegister>(), |
| 7606 | method_offset); |
| 7607 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7608 | } |
| 7609 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7610 | void LocationsBuilderMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7611 | ATTRIBUTE_UNUSED) { |
| 7612 | LOG(FATAL) << "Unreachable"; |
| 7613 | } |
| 7614 | |
| 7615 | void InstructionCodeGeneratorMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7616 | ATTRIBUTE_UNUSED) { |
| 7617 | LOG(FATAL) << "Unreachable"; |
| 7618 | } |
| 7619 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7620 | } // namespace mips64 |
| 7621 | } // namespace art |