Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_mips64.h" |
| 18 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 19 | #include "arch/mips64/asm_support_mips64.h" |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 21 | #include "class_table.h" |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 22 | #include "code_generator_utils.h" |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 23 | #include "compiled_method.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints.h" |
| 25 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| 26 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 27 | #include "heap_poisoning.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 28 | #include "intrinsics.h" |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 29 | #include "intrinsics_mips64.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 30 | #include "linker/linker_patch.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 31 | #include "mirror/array-inl.h" |
| 32 | #include "mirror/class-inl.h" |
| 33 | #include "offsets.h" |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 34 | #include "stack_map_stream.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 35 | #include "thread.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 36 | #include "utils/assembler.h" |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 37 | #include "utils/mips64/assembler_mips64.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 38 | #include "utils/stack_checks.h" |
| 39 | |
| 40 | namespace art { |
| 41 | namespace mips64 { |
| 42 | |
| 43 | static constexpr int kCurrentMethodStackOffset = 0; |
| 44 | static constexpr GpuRegister kMethodRegisterArgument = A0; |
| 45 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 46 | // Flags controlling the use of thunks for Baker read barriers. |
| 47 | constexpr bool kBakerReadBarrierThunksEnableForFields = true; |
| 48 | constexpr bool kBakerReadBarrierThunksEnableForArrays = true; |
| 49 | constexpr bool kBakerReadBarrierThunksEnableForGcRoots = true; |
| 50 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 51 | Location Mips64ReturnLocation(DataType::Type return_type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 52 | switch (return_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 53 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 54 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 55 | case DataType::Type::kInt8: |
| 56 | case DataType::Type::kUint16: |
| 57 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 58 | case DataType::Type::kUint32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 59 | case DataType::Type::kInt32: |
| 60 | case DataType::Type::kReference: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 61 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 62 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 63 | return Location::RegisterLocation(V0); |
| 64 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 65 | case DataType::Type::kFloat32: |
| 66 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 67 | return Location::FpuRegisterLocation(F0); |
| 68 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 69 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 70 | return Location(); |
| 71 | } |
| 72 | UNREACHABLE(); |
| 73 | } |
| 74 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 75 | Location InvokeDexCallingConventionVisitorMIPS64::GetReturnLocation(DataType::Type type) const { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 76 | return Mips64ReturnLocation(type); |
| 77 | } |
| 78 | |
| 79 | Location InvokeDexCallingConventionVisitorMIPS64::GetMethodLocation() const { |
| 80 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 81 | } |
| 82 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 83 | Location InvokeDexCallingConventionVisitorMIPS64::GetNextLocation(DataType::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 84 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 85 | if (type == DataType::Type::kVoid) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 86 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 87 | } |
| 88 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 89 | if (DataType::IsFloatingPointType(type) && |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 90 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 91 | next_location = Location::FpuRegisterLocation( |
| 92 | calling_convention.GetFpuRegisterAt(float_index_++)); |
| 93 | gp_index_++; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 94 | } else if (!DataType::IsFloatingPointType(type) && |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 95 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 96 | next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index_++)); |
| 97 | float_index_++; |
| 98 | } else { |
| 99 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 100 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 101 | : Location::StackSlot(stack_offset); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 105 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 106 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 107 | return next_location; |
| 108 | } |
| 109 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 110 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 111 | return Mips64ReturnLocation(type); |
| 112 | } |
| 113 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 114 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 115 | #define __ down_cast<CodeGeneratorMIPS64*>(codegen)->GetAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 116 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value() |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 117 | |
| 118 | class BoundsCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 119 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 120 | explicit BoundsCheckSlowPathMIPS64(HBoundsCheck* instruction) : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 121 | |
| 122 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 123 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 124 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 125 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 126 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 127 | // Live registers will be restored in the catch block if caught. |
| 128 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 129 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 130 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 131 | // move resolver. |
| 132 | InvokeRuntimeCallingConvention calling_convention; |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 133 | codegen->EmitParallelMoves(locations->InAt(0), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 134 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 135 | DataType::Type::kInt32, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 136 | locations->InAt(1), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 137 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 138 | DataType::Type::kInt32); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 139 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 140 | ? kQuickThrowStringBounds |
| 141 | : kQuickThrowArrayBounds; |
| 142 | mips64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 143 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 144 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 145 | } |
| 146 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 147 | bool IsFatal() const OVERRIDE { return true; } |
| 148 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 149 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS64"; } |
| 150 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 151 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 152 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS64); |
| 153 | }; |
| 154 | |
| 155 | class DivZeroCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 156 | public: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 157 | explicit DivZeroCheckSlowPathMIPS64(HDivZeroCheck* instruction) |
| 158 | : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 159 | |
| 160 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 161 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 162 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 163 | mips64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 164 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 165 | } |
| 166 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 167 | bool IsFatal() const OVERRIDE { return true; } |
| 168 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 169 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS64"; } |
| 170 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 171 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 172 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS64); |
| 173 | }; |
| 174 | |
| 175 | class LoadClassSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 176 | public: |
| 177 | LoadClassSlowPathMIPS64(HLoadClass* cls, |
| 178 | HInstruction* at, |
| 179 | uint32_t dex_pc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 180 | bool do_clinit) |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 181 | : SlowPathCodeMIPS64(at), |
| 182 | cls_(cls), |
| 183 | dex_pc_(dex_pc), |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 184 | do_clinit_(do_clinit) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 185 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 186 | } |
| 187 | |
| 188 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 189 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 190 | Location out = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 191 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 192 | InvokeRuntimeCallingConvention calling_convention; |
| 193 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 194 | __ Bind(GetEntryLabel()); |
| 195 | SaveLiveRegisters(codegen, locations); |
| 196 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 197 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 198 | __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 199 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 200 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 201 | mips64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 202 | if (do_clinit_) { |
| 203 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 204 | } else { |
| 205 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 206 | } |
| 207 | |
| 208 | // Move the class to the desired location. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 209 | if (out.IsValid()) { |
| 210 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 211 | DataType::Type type = instruction_->GetType(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 212 | mips64_codegen->MoveLocation(out, |
| 213 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 214 | type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 215 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 216 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 217 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 218 | __ Bc(GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 221 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS64"; } |
| 222 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 223 | private: |
| 224 | // The class this slow path will load. |
| 225 | HLoadClass* const cls_; |
| 226 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 227 | // The dex PC of `at_`. |
| 228 | const uint32_t dex_pc_; |
| 229 | |
| 230 | // Whether to initialize the class. |
| 231 | const bool do_clinit_; |
| 232 | |
| 233 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS64); |
| 234 | }; |
| 235 | |
| 236 | class LoadStringSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 237 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 238 | explicit LoadStringSlowPathMIPS64(HLoadString* instruction) |
| 239 | : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 240 | |
| 241 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 242 | DCHECK(instruction_->IsLoadString()); |
| 243 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 244 | LocationSummary* locations = instruction_->GetLocations(); |
| 245 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 246 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 247 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 248 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 249 | __ Bind(GetEntryLabel()); |
| 250 | SaveLiveRegisters(codegen, locations); |
| 251 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 252 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 253 | mips64_codegen->InvokeRuntime(kQuickResolveString, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 254 | instruction_, |
| 255 | instruction_->GetDexPc(), |
| 256 | this); |
| 257 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 258 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 259 | DataType::Type type = instruction_->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 260 | mips64_codegen->MoveLocation(locations->Out(), |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 261 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 262 | type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 263 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 264 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 265 | __ Bc(GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 268 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS64"; } |
| 269 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 270 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 271 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS64); |
| 272 | }; |
| 273 | |
| 274 | class NullCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 275 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 276 | explicit NullCheckSlowPathMIPS64(HNullCheck* instr) : SlowPathCodeMIPS64(instr) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 277 | |
| 278 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 279 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 280 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 281 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 282 | // Live registers will be restored in the catch block if caught. |
| 283 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 284 | } |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 285 | mips64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 286 | instruction_, |
| 287 | instruction_->GetDexPc(), |
| 288 | this); |
| 289 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 290 | } |
| 291 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 292 | bool IsFatal() const OVERRIDE { return true; } |
| 293 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 294 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS64"; } |
| 295 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 296 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 297 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS64); |
| 298 | }; |
| 299 | |
| 300 | class SuspendCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 301 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 302 | SuspendCheckSlowPathMIPS64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 303 | : SlowPathCodeMIPS64(instruction), successor_(successor) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 304 | |
| 305 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 306 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 307 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 308 | __ Bind(GetEntryLabel()); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 309 | SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD. |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 310 | mips64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 311 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 312 | RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 313 | if (successor_ == nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 314 | __ Bc(GetReturnLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 315 | } else { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 316 | __ Bc(mips64_codegen->GetLabelOf(successor_)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 320 | Mips64Label* GetReturnLabel() { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 321 | DCHECK(successor_ == nullptr); |
| 322 | return &return_label_; |
| 323 | } |
| 324 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 325 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS64"; } |
| 326 | |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 327 | HBasicBlock* GetSuccessor() const { |
| 328 | return successor_; |
| 329 | } |
| 330 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 331 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 332 | // If not null, the block to branch to after the suspend check. |
| 333 | HBasicBlock* const successor_; |
| 334 | |
| 335 | // 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] | 336 | Mips64Label return_label_; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 337 | |
| 338 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS64); |
| 339 | }; |
| 340 | |
| 341 | class TypeCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 342 | public: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 343 | explicit TypeCheckSlowPathMIPS64(HInstruction* instruction, bool is_fatal) |
| 344 | : SlowPathCodeMIPS64(instruction), is_fatal_(is_fatal) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 345 | |
| 346 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 347 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 348 | |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 349 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 350 | DCHECK(instruction_->IsCheckCast() |
| 351 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 352 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 353 | |
| 354 | __ Bind(GetEntryLabel()); |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 355 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 356 | SaveLiveRegisters(codegen, locations); |
| 357 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 358 | |
| 359 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 360 | // move resolver. |
| 361 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 362 | codegen->EmitParallelMoves(locations->InAt(0), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 363 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 364 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 365 | locations->InAt(1), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 366 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 367 | DataType::Type::kReference); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 368 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 369 | mips64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 370 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 371 | DataType::Type ret_type = instruction_->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 372 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 373 | mips64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 374 | } else { |
| 375 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 376 | mips64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 377 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 380 | if (!is_fatal_) { |
| 381 | RestoreLiveRegisters(codegen, locations); |
| 382 | __ Bc(GetExitLabel()); |
| 383 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 386 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS64"; } |
| 387 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 388 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 389 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 390 | private: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 391 | const bool is_fatal_; |
| 392 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 393 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS64); |
| 394 | }; |
| 395 | |
| 396 | class DeoptimizationSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 397 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 398 | explicit DeoptimizationSlowPathMIPS64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 399 | : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 400 | |
| 401 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 402 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 403 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 404 | LocationSummary* locations = instruction_->GetLocations(); |
| 405 | SaveLiveRegisters(codegen, locations); |
| 406 | InvokeRuntimeCallingConvention calling_convention; |
| 407 | __ LoadConst32(calling_convention.GetRegisterAt(0), |
| 408 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 409 | mips64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 410 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 413 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS64"; } |
| 414 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 415 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 416 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64); |
| 417 | }; |
| 418 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 419 | class ArraySetSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 420 | public: |
| 421 | explicit ArraySetSlowPathMIPS64(HInstruction* instruction) : SlowPathCodeMIPS64(instruction) {} |
| 422 | |
| 423 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 424 | LocationSummary* locations = instruction_->GetLocations(); |
| 425 | __ Bind(GetEntryLabel()); |
| 426 | SaveLiveRegisters(codegen, locations); |
| 427 | |
| 428 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 429 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 430 | parallel_move.AddMove( |
| 431 | locations->InAt(0), |
| 432 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 433 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 434 | nullptr); |
| 435 | parallel_move.AddMove( |
| 436 | locations->InAt(1), |
| 437 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 438 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 439 | nullptr); |
| 440 | parallel_move.AddMove( |
| 441 | locations->InAt(2), |
| 442 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 443 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 444 | nullptr); |
| 445 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 446 | |
| 447 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 448 | mips64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 449 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 450 | RestoreLiveRegisters(codegen, locations); |
| 451 | __ Bc(GetExitLabel()); |
| 452 | } |
| 453 | |
| 454 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS64"; } |
| 455 | |
| 456 | private: |
| 457 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS64); |
| 458 | }; |
| 459 | |
| 460 | // Slow path marking an object reference `ref` during a read |
| 461 | // barrier. The field `obj.field` in the object `obj` holding this |
| 462 | // reference does not get updated by this slow path after marking (see |
| 463 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 below for that). |
| 464 | // |
| 465 | // This means that after the execution of this slow path, `ref` will |
| 466 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 467 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 468 | // probably still be a from-space reference (unless it gets updated by |
| 469 | // another thread, or if another thread installed another object |
| 470 | // reference (different from `ref`) in `obj.field`). |
| 471 | // |
| 472 | // If `entrypoint` is a valid location it is assumed to already be |
| 473 | // holding the entrypoint. The case where the entrypoint is passed in |
| 474 | // is for the GcRoot read barrier. |
| 475 | class ReadBarrierMarkSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 476 | public: |
| 477 | ReadBarrierMarkSlowPathMIPS64(HInstruction* instruction, |
| 478 | Location ref, |
| 479 | Location entrypoint = Location::NoLocation()) |
| 480 | : SlowPathCodeMIPS64(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 481 | DCHECK(kEmitCompilerReadBarrier); |
| 482 | } |
| 483 | |
| 484 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; } |
| 485 | |
| 486 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 487 | LocationSummary* locations = instruction_->GetLocations(); |
| 488 | GpuRegister ref_reg = ref_.AsRegister<GpuRegister>(); |
| 489 | DCHECK(locations->CanCall()); |
| 490 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 491 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 492 | instruction_->IsStaticFieldGet() || |
| 493 | instruction_->IsArrayGet() || |
| 494 | instruction_->IsArraySet() || |
| 495 | instruction_->IsLoadClass() || |
| 496 | instruction_->IsLoadString() || |
| 497 | instruction_->IsInstanceOf() || |
| 498 | instruction_->IsCheckCast() || |
| 499 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 500 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 501 | << "Unexpected instruction in read barrier marking slow path: " |
| 502 | << instruction_->DebugName(); |
| 503 | |
| 504 | __ Bind(GetEntryLabel()); |
| 505 | // No need to save live registers; it's taken care of by the |
| 506 | // entrypoint. Also, there is no need to update the stack mask, |
| 507 | // as this runtime call will not trigger a garbage collection. |
| 508 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 509 | DCHECK((V0 <= ref_reg && ref_reg <= T2) || |
| 510 | (S2 <= ref_reg && ref_reg <= S7) || |
| 511 | (ref_reg == S8)) << ref_reg; |
| 512 | // "Compact" slow path, saving two moves. |
| 513 | // |
| 514 | // Instead of using the standard runtime calling convention (input |
| 515 | // and output in A0 and V0 respectively): |
| 516 | // |
| 517 | // A0 <- ref |
| 518 | // V0 <- ReadBarrierMark(A0) |
| 519 | // ref <- V0 |
| 520 | // |
| 521 | // we just use rX (the register containing `ref`) as input and output |
| 522 | // of a dedicated entrypoint: |
| 523 | // |
| 524 | // rX <- ReadBarrierMarkRegX(rX) |
| 525 | // |
| 526 | if (entrypoint_.IsValid()) { |
| 527 | mips64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 528 | DCHECK_EQ(entrypoint_.AsRegister<GpuRegister>(), T9); |
| 529 | __ Jalr(entrypoint_.AsRegister<GpuRegister>()); |
| 530 | __ Nop(); |
| 531 | } else { |
| 532 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 533 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 534 | // This runtime call does not require a stack map. |
| 535 | mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 536 | instruction_, |
| 537 | this); |
| 538 | } |
| 539 | __ Bc(GetExitLabel()); |
| 540 | } |
| 541 | |
| 542 | private: |
| 543 | // The location (register) of the marked object reference. |
| 544 | const Location ref_; |
| 545 | |
| 546 | // The location of the entrypoint if already loaded. |
| 547 | const Location entrypoint_; |
| 548 | |
| 549 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS64); |
| 550 | }; |
| 551 | |
| 552 | // Slow path marking an object reference `ref` during a read barrier, |
| 553 | // and if needed, atomically updating the field `obj.field` in the |
| 554 | // object `obj` holding this reference after marking (contrary to |
| 555 | // ReadBarrierMarkSlowPathMIPS64 above, which never tries to update |
| 556 | // `obj.field`). |
| 557 | // |
| 558 | // This means that after the execution of this slow path, both `ref` |
| 559 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 560 | // hold the same to-space reference (unless another thread installed |
| 561 | // another object reference (different from `ref`) in `obj.field`). |
| 562 | class ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 563 | public: |
| 564 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(HInstruction* instruction, |
| 565 | Location ref, |
| 566 | GpuRegister obj, |
| 567 | Location field_offset, |
| 568 | GpuRegister temp1) |
| 569 | : SlowPathCodeMIPS64(instruction), |
| 570 | ref_(ref), |
| 571 | obj_(obj), |
| 572 | field_offset_(field_offset), |
| 573 | temp1_(temp1) { |
| 574 | DCHECK(kEmitCompilerReadBarrier); |
| 575 | } |
| 576 | |
| 577 | const char* GetDescription() const OVERRIDE { |
| 578 | return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS64"; |
| 579 | } |
| 580 | |
| 581 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 582 | LocationSummary* locations = instruction_->GetLocations(); |
| 583 | GpuRegister ref_reg = ref_.AsRegister<GpuRegister>(); |
| 584 | DCHECK(locations->CanCall()); |
| 585 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 586 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 587 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 588 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 589 | << instruction_->DebugName(); |
| 590 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 591 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 592 | DCHECK(field_offset_.IsRegister()) << field_offset_; |
| 593 | |
| 594 | __ Bind(GetEntryLabel()); |
| 595 | |
| 596 | // Save the old reference. |
| 597 | // Note that we cannot use AT or TMP to save the old reference, as those |
| 598 | // are used by the code that follows, but we need the old reference after |
| 599 | // the call to the ReadBarrierMarkRegX entry point. |
| 600 | DCHECK_NE(temp1_, AT); |
| 601 | DCHECK_NE(temp1_, TMP); |
| 602 | __ Move(temp1_, ref_reg); |
| 603 | |
| 604 | // No need to save live registers; it's taken care of by the |
| 605 | // entrypoint. Also, there is no need to update the stack mask, |
| 606 | // as this runtime call will not trigger a garbage collection. |
| 607 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 608 | DCHECK((V0 <= ref_reg && ref_reg <= T2) || |
| 609 | (S2 <= ref_reg && ref_reg <= S7) || |
| 610 | (ref_reg == S8)) << ref_reg; |
| 611 | // "Compact" slow path, saving two moves. |
| 612 | // |
| 613 | // Instead of using the standard runtime calling convention (input |
| 614 | // and output in A0 and V0 respectively): |
| 615 | // |
| 616 | // A0 <- ref |
| 617 | // V0 <- ReadBarrierMark(A0) |
| 618 | // ref <- V0 |
| 619 | // |
| 620 | // we just use rX (the register containing `ref`) as input and output |
| 621 | // of a dedicated entrypoint: |
| 622 | // |
| 623 | // rX <- ReadBarrierMarkRegX(rX) |
| 624 | // |
| 625 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 626 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 627 | // This runtime call does not require a stack map. |
| 628 | mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 629 | instruction_, |
| 630 | this); |
| 631 | |
| 632 | // If the new reference is different from the old reference, |
| 633 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 634 | // |
| 635 | // Note that this field could also hold a different object, if |
| 636 | // another thread had concurrently changed it. In that case, the |
| 637 | // the compare-and-set (CAS) loop below would abort, leaving the |
| 638 | // field as-is. |
| 639 | Mips64Label done; |
| 640 | __ Beqc(temp1_, ref_reg, &done); |
| 641 | |
| 642 | // Update the the holder's field atomically. This may fail if |
| 643 | // mutator updates before us, but it's OK. This is achieved |
| 644 | // using a strong compare-and-set (CAS) operation with relaxed |
| 645 | // memory synchronization ordering, where the expected value is |
| 646 | // the old reference and the desired value is the new reference. |
| 647 | |
| 648 | // Convenience aliases. |
| 649 | GpuRegister base = obj_; |
| 650 | GpuRegister offset = field_offset_.AsRegister<GpuRegister>(); |
| 651 | GpuRegister expected = temp1_; |
| 652 | GpuRegister value = ref_reg; |
| 653 | GpuRegister tmp_ptr = TMP; // Pointer to actual memory. |
| 654 | GpuRegister tmp = AT; // Value in memory. |
| 655 | |
| 656 | __ Daddu(tmp_ptr, base, offset); |
| 657 | |
| 658 | if (kPoisonHeapReferences) { |
| 659 | __ PoisonHeapReference(expected); |
| 660 | // Do not poison `value` if it is the same register as |
| 661 | // `expected`, which has just been poisoned. |
| 662 | if (value != expected) { |
| 663 | __ PoisonHeapReference(value); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | // do { |
| 668 | // tmp = [r_ptr] - expected; |
| 669 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 670 | |
| 671 | Mips64Label loop_head, exit_loop; |
| 672 | __ Bind(&loop_head); |
| 673 | __ Ll(tmp, tmp_ptr); |
| 674 | // The LL instruction sign-extends the 32-bit value, but |
| 675 | // 32-bit references must be zero-extended. Zero-extend `tmp`. |
| 676 | __ Dext(tmp, tmp, 0, 32); |
| 677 | __ Bnec(tmp, expected, &exit_loop); |
| 678 | __ Move(tmp, value); |
| 679 | __ Sc(tmp, tmp_ptr); |
| 680 | __ Beqzc(tmp, &loop_head); |
| 681 | __ Bind(&exit_loop); |
| 682 | |
| 683 | if (kPoisonHeapReferences) { |
| 684 | __ UnpoisonHeapReference(expected); |
| 685 | // Do not unpoison `value` if it is the same register as |
| 686 | // `expected`, which has just been unpoisoned. |
| 687 | if (value != expected) { |
| 688 | __ UnpoisonHeapReference(value); |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | __ Bind(&done); |
| 693 | __ Bc(GetExitLabel()); |
| 694 | } |
| 695 | |
| 696 | private: |
| 697 | // The location (register) of the marked object reference. |
| 698 | const Location ref_; |
| 699 | // The register containing the object holding the marked object reference field. |
| 700 | const GpuRegister obj_; |
| 701 | // The location of the offset of the marked reference field within `obj_`. |
| 702 | Location field_offset_; |
| 703 | |
| 704 | const GpuRegister temp1_; |
| 705 | |
| 706 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS64); |
| 707 | }; |
| 708 | |
| 709 | // Slow path generating a read barrier for a heap reference. |
| 710 | class ReadBarrierForHeapReferenceSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 711 | public: |
| 712 | ReadBarrierForHeapReferenceSlowPathMIPS64(HInstruction* instruction, |
| 713 | Location out, |
| 714 | Location ref, |
| 715 | Location obj, |
| 716 | uint32_t offset, |
| 717 | Location index) |
| 718 | : SlowPathCodeMIPS64(instruction), |
| 719 | out_(out), |
| 720 | ref_(ref), |
| 721 | obj_(obj), |
| 722 | offset_(offset), |
| 723 | index_(index) { |
| 724 | DCHECK(kEmitCompilerReadBarrier); |
| 725 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 726 | // has been overwritten by (or after) the heap object reference load |
| 727 | // to be instrumented, e.g.: |
| 728 | // |
| 729 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 730 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 731 | // |
| 732 | // In that case, we have lost the information about the original |
| 733 | // object, and the emitted read barrier cannot work properly. |
| 734 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 735 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 736 | } |
| 737 | |
| 738 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 739 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 740 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 741 | DataType::Type type = DataType::Type::kReference; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 742 | GpuRegister reg_out = out_.AsRegister<GpuRegister>(); |
| 743 | DCHECK(locations->CanCall()); |
| 744 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 745 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 746 | instruction_->IsStaticFieldGet() || |
| 747 | instruction_->IsArrayGet() || |
| 748 | instruction_->IsInstanceOf() || |
| 749 | instruction_->IsCheckCast() || |
| 750 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 751 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 752 | << instruction_->DebugName(); |
| 753 | |
| 754 | __ Bind(GetEntryLabel()); |
| 755 | SaveLiveRegisters(codegen, locations); |
| 756 | |
| 757 | // We may have to change the index's value, but as `index_` is a |
| 758 | // constant member (like other "inputs" of this slow path), |
| 759 | // introduce a copy of it, `index`. |
| 760 | Location index = index_; |
| 761 | if (index_.IsValid()) { |
| 762 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 763 | if (instruction_->IsArrayGet()) { |
| 764 | // Compute the actual memory offset and store it in `index`. |
| 765 | GpuRegister index_reg = index_.AsRegister<GpuRegister>(); |
| 766 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 767 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 768 | // We are about to change the value of `index_reg` (see the |
| 769 | // calls to art::mips64::Mips64Assembler::Sll and |
| 770 | // art::mips64::MipsAssembler::Addiu32 below), but it has |
| 771 | // not been saved by the previous call to |
| 772 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 773 | // callee-save register -- |
| 774 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 775 | // callee-save registers, as it has been designed with the |
| 776 | // assumption that callee-save registers are supposed to be |
| 777 | // handled by the called function. So, as a callee-save |
| 778 | // register, `index_reg` _would_ eventually be saved onto |
| 779 | // the stack, but it would be too late: we would have |
| 780 | // changed its value earlier. Therefore, we manually save |
| 781 | // it here into another freely available register, |
| 782 | // `free_reg`, chosen of course among the caller-save |
| 783 | // registers (as a callee-save `free_reg` register would |
| 784 | // exhibit the same problem). |
| 785 | // |
| 786 | // Note we could have requested a temporary register from |
| 787 | // the register allocator instead; but we prefer not to, as |
| 788 | // this is a slow path, and we know we can find a |
| 789 | // caller-save register that is available. |
| 790 | GpuRegister free_reg = FindAvailableCallerSaveRegister(codegen); |
| 791 | __ Move(free_reg, index_reg); |
| 792 | index_reg = free_reg; |
| 793 | index = Location::RegisterLocation(index_reg); |
| 794 | } else { |
| 795 | // The initial register stored in `index_` has already been |
| 796 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 797 | // (as it is not a callee-save register), so we can freely |
| 798 | // use it. |
| 799 | } |
| 800 | // Shifting the index value contained in `index_reg` by the scale |
| 801 | // factor (2) cannot overflow in practice, as the runtime is |
| 802 | // unable to allocate object arrays with a size larger than |
| 803 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 804 | __ Sll(index_reg, index_reg, TIMES_4); |
| 805 | static_assert( |
| 806 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 807 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 808 | __ Addiu32(index_reg, index_reg, offset_); |
| 809 | } else { |
| 810 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 811 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 812 | // (as in the case of ArrayGet), as it is actually an offset |
| 813 | // to an object field within an object. |
| 814 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 815 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 816 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 817 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 818 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 819 | DCHECK_EQ(offset_, 0U); |
| 820 | DCHECK(index_.IsRegister()); |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | // We're moving two or three locations to locations that could |
| 825 | // overlap, so we need a parallel move resolver. |
| 826 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 827 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 828 | parallel_move.AddMove(ref_, |
| 829 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 830 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 831 | nullptr); |
| 832 | parallel_move.AddMove(obj_, |
| 833 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 834 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 835 | nullptr); |
| 836 | if (index.IsValid()) { |
| 837 | parallel_move.AddMove(index, |
| 838 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 839 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 840 | nullptr); |
| 841 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 842 | } else { |
| 843 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 844 | __ LoadConst32(calling_convention.GetRegisterAt(2), offset_); |
| 845 | } |
| 846 | mips64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| 847 | instruction_, |
| 848 | instruction_->GetDexPc(), |
| 849 | this); |
| 850 | CheckEntrypointTypes< |
| 851 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 852 | mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 853 | |
| 854 | RestoreLiveRegisters(codegen, locations); |
| 855 | __ Bc(GetExitLabel()); |
| 856 | } |
| 857 | |
| 858 | const char* GetDescription() const OVERRIDE { |
| 859 | return "ReadBarrierForHeapReferenceSlowPathMIPS64"; |
| 860 | } |
| 861 | |
| 862 | private: |
| 863 | GpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 864 | size_t ref = static_cast<int>(ref_.AsRegister<GpuRegister>()); |
| 865 | size_t obj = static_cast<int>(obj_.AsRegister<GpuRegister>()); |
| 866 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 867 | if (i != ref && |
| 868 | i != obj && |
| 869 | !codegen->IsCoreCalleeSaveRegister(i) && |
| 870 | !codegen->IsBlockedCoreRegister(i)) { |
| 871 | return static_cast<GpuRegister>(i); |
| 872 | } |
| 873 | } |
| 874 | // We shall never fail to find a free caller-save register, as |
| 875 | // there are more than two core caller-save registers on MIPS64 |
| 876 | // (meaning it is possible to find one which is different from |
| 877 | // `ref` and `obj`). |
| 878 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 879 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 880 | UNREACHABLE(); |
| 881 | } |
| 882 | |
| 883 | const Location out_; |
| 884 | const Location ref_; |
| 885 | const Location obj_; |
| 886 | const uint32_t offset_; |
| 887 | // An additional location containing an index to an array. |
| 888 | // Only used for HArrayGet and the UnsafeGetObject & |
| 889 | // UnsafeGetObjectVolatile intrinsics. |
| 890 | const Location index_; |
| 891 | |
| 892 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS64); |
| 893 | }; |
| 894 | |
| 895 | // Slow path generating a read barrier for a GC root. |
| 896 | class ReadBarrierForRootSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 897 | public: |
| 898 | ReadBarrierForRootSlowPathMIPS64(HInstruction* instruction, Location out, Location root) |
| 899 | : SlowPathCodeMIPS64(instruction), out_(out), root_(root) { |
| 900 | DCHECK(kEmitCompilerReadBarrier); |
| 901 | } |
| 902 | |
| 903 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 904 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 905 | DataType::Type type = DataType::Type::kReference; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 906 | GpuRegister reg_out = out_.AsRegister<GpuRegister>(); |
| 907 | DCHECK(locations->CanCall()); |
| 908 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 909 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 910 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 911 | << instruction_->DebugName(); |
| 912 | |
| 913 | __ Bind(GetEntryLabel()); |
| 914 | SaveLiveRegisters(codegen, locations); |
| 915 | |
| 916 | InvokeRuntimeCallingConvention calling_convention; |
| 917 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 918 | mips64_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 919 | root_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 920 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 921 | mips64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 922 | instruction_, |
| 923 | instruction_->GetDexPc(), |
| 924 | this); |
| 925 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 926 | mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 927 | |
| 928 | RestoreLiveRegisters(codegen, locations); |
| 929 | __ Bc(GetExitLabel()); |
| 930 | } |
| 931 | |
| 932 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS64"; } |
| 933 | |
| 934 | private: |
| 935 | const Location out_; |
| 936 | const Location root_; |
| 937 | |
| 938 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS64); |
| 939 | }; |
| 940 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 941 | CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph, |
| 942 | const Mips64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 943 | const CompilerOptions& compiler_options, |
| 944 | OptimizingCompilerStats* stats) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 945 | : CodeGenerator(graph, |
| 946 | kNumberOfGpuRegisters, |
| 947 | kNumberOfFpuRegisters, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 948 | /* number_of_register_pairs */ 0, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 949 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 950 | arraysize(kCoreCalleeSaves)), |
| 951 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 952 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 953 | compiler_options, |
| 954 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 955 | block_labels_(nullptr), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 956 | location_builder_(graph, this), |
| 957 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 958 | move_resolver_(graph->GetAllocator(), this), |
| 959 | assembler_(graph->GetAllocator(), &isa_features), |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 960 | isa_features_(isa_features), |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 961 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 962 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 963 | uint64_literals_(std::less<uint64_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 964 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 965 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 966 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 967 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 968 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 969 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 970 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 971 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 972 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 973 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 974 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 975 | // Save RA (containing the return address) to mimic Quick. |
| 976 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 977 | } |
| 978 | |
| 979 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 980 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 981 | #define __ down_cast<Mips64Assembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 982 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value() |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 983 | |
| 984 | void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 985 | // Ensure that we fix up branches. |
| 986 | __ FinalizeCode(); |
| 987 | |
| 988 | // Adjust native pc offsets in stack maps. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 989 | StackMapStream* stack_map_stream = GetStackMapStream(); |
| 990 | for (size_t i = 0, num = stack_map_stream->GetNumberOfStackMaps(); i != num; ++i) { |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 991 | uint32_t old_position = |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 992 | stack_map_stream->GetStackMap(i).native_pc_code_offset.Uint32Value(InstructionSet::kMips64); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 993 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 994 | DCHECK_GE(new_position, old_position); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 995 | stack_map_stream->SetStackMapNativePcOffset(i, new_position); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | // Adjust pc offsets for the disassembly information. |
| 999 | if (disasm_info_ != nullptr) { |
| 1000 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1001 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1002 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1003 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1004 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1005 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1006 | } |
| 1007 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1008 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1009 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1010 | } |
| 1011 | } |
| 1012 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1013 | CodeGenerator::Finalize(allocator); |
| 1014 | } |
| 1015 | |
| 1016 | Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const { |
| 1017 | return codegen_->GetAssembler(); |
| 1018 | } |
| 1019 | |
| 1020 | void ParallelMoveResolverMIPS64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1021 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1022 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1023 | } |
| 1024 | |
| 1025 | void ParallelMoveResolverMIPS64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1026 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1027 | codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1028 | } |
| 1029 | |
| 1030 | void ParallelMoveResolverMIPS64::RestoreScratch(int reg) { |
| 1031 | // Pop reg |
| 1032 | __ Ld(GpuRegister(reg), SP, 0); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1033 | __ DecreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | void ParallelMoveResolverMIPS64::SpillScratch(int reg) { |
| 1037 | // Push reg |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1038 | __ IncreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1039 | __ Sd(GpuRegister(reg), SP, 0); |
| 1040 | } |
| 1041 | |
| 1042 | void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) { |
| 1043 | LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord; |
| 1044 | StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord; |
| 1045 | // Allocate a scratch register other than TMP, if available. |
| 1046 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 1047 | // automatically unspilled when the scratch scope object is destroyed). |
| 1048 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 1049 | // 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] | 1050 | int stack_offset = ensure_scratch.IsSpilled() ? kMips64DoublewordSize : 0; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1051 | __ LoadFromOffset(load_type, |
| 1052 | GpuRegister(ensure_scratch.GetRegister()), |
| 1053 | SP, |
| 1054 | index1 + stack_offset); |
| 1055 | __ LoadFromOffset(load_type, |
| 1056 | TMP, |
| 1057 | SP, |
| 1058 | index2 + stack_offset); |
| 1059 | __ StoreToOffset(store_type, |
| 1060 | GpuRegister(ensure_scratch.GetRegister()), |
| 1061 | SP, |
| 1062 | index2 + stack_offset); |
| 1063 | __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset); |
| 1064 | } |
| 1065 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1066 | void ParallelMoveResolverMIPS64::ExchangeQuadSlots(int index1, int index2) { |
| 1067 | __ LoadFpuFromOffset(kLoadQuadword, FTMP, SP, index1); |
| 1068 | __ LoadFpuFromOffset(kLoadQuadword, FTMP2, SP, index2); |
| 1069 | __ StoreFpuToOffset(kStoreQuadword, FTMP, SP, index2); |
| 1070 | __ StoreFpuToOffset(kStoreQuadword, FTMP2, SP, index1); |
| 1071 | } |
| 1072 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1073 | static dwarf::Reg DWARFReg(GpuRegister reg) { |
| 1074 | return dwarf::Reg::Mips64Core(static_cast<int>(reg)); |
| 1075 | } |
| 1076 | |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1077 | static dwarf::Reg DWARFReg(FpuRegister reg) { |
| 1078 | return dwarf::Reg::Mips64Fp(static_cast<int>(reg)); |
| 1079 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1080 | |
| 1081 | void CodeGeneratorMIPS64::GenerateFrameEntry() { |
| 1082 | __ Bind(&frame_entry_label_); |
| 1083 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1084 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
Goran Jakovljevic | feec167 | 2018-02-08 10:20:14 +0100 | [diff] [blame] | 1085 | __ Lhu(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()); |
| 1086 | __ Addiu(TMP, TMP, 1); |
| 1087 | __ Sh(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()); |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1090 | bool do_overflow_check = |
| 1091 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips64) || !IsLeafMethod(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1092 | |
| 1093 | if (do_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1094 | __ LoadFromOffset( |
| 1095 | kLoadWord, |
| 1096 | ZERO, |
| 1097 | SP, |
| 1098 | -static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kMips64))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1099 | RecordPcInfo(nullptr, 0); |
| 1100 | } |
| 1101 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1102 | if (HasEmptyFrame()) { |
| 1103 | return; |
| 1104 | } |
| 1105 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1106 | // Make sure the frame size isn't unreasonably large. |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1107 | if (GetFrameSize() > GetStackOverflowReservedBytes(InstructionSet::kMips64)) { |
| 1108 | LOG(FATAL) << "Stack frame larger than " |
| 1109 | << GetStackOverflowReservedBytes(InstructionSet::kMips64) << " bytes"; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1110 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1111 | |
| 1112 | // Spill callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1113 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1114 | uint32_t ofs = GetFrameSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1115 | __ IncreaseFrameSize(ofs); |
| 1116 | |
| 1117 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1118 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1119 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1120 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1121 | __ StoreToOffset(kStoreDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1122 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1127 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1128 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1129 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1130 | __ StoreFpuToOffset(kStoreDoubleword, reg, SP, ofs); |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1131 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1132 | } |
| 1133 | } |
| 1134 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1135 | // Save the current method if we need it. Note that we do not |
| 1136 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1137 | // in the SSA graph. |
| 1138 | if (RequiresCurrentMethod()) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1139 | __ StoreToOffset(kStoreDoubleword, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1140 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 1141 | |
| 1142 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1143 | // Initialize should_deoptimize flag to 0. |
| 1144 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1145 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | void CodeGeneratorMIPS64::GenerateFrameExit() { |
| 1149 | __ cfi().RememberState(); |
| 1150 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1151 | if (!HasEmptyFrame()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1152 | // Restore callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1153 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1154 | // For better instruction scheduling restore RA before other registers. |
| 1155 | uint32_t ofs = GetFrameSize(); |
| 1156 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1157 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1158 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1159 | ofs -= kMips64DoublewordSize; |
| 1160 | __ LoadFromOffset(kLoadDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1161 | __ cfi().Restore(DWARFReg(reg)); |
| 1162 | } |
| 1163 | } |
| 1164 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1165 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1166 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1167 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
| 1168 | ofs -= kMips64DoublewordSize; |
| 1169 | __ LoadFpuFromOffset(kLoadDoubleword, reg, SP, ofs); |
| 1170 | __ cfi().Restore(DWARFReg(reg)); |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | __ DecreaseFrameSize(GetFrameSize()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1177 | __ Jic(RA, 0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1178 | |
| 1179 | __ cfi().RestoreState(); |
| 1180 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 1181 | } |
| 1182 | |
| 1183 | void CodeGeneratorMIPS64::Bind(HBasicBlock* block) { |
| 1184 | __ Bind(GetLabelOf(block)); |
| 1185 | } |
| 1186 | |
| 1187 | void CodeGeneratorMIPS64::MoveLocation(Location destination, |
| 1188 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1189 | DataType::Type dst_type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1190 | if (source.Equals(destination)) { |
| 1191 | return; |
| 1192 | } |
| 1193 | |
| 1194 | // A valid move can always be inferred from the destination and source |
| 1195 | // locations. When moving from and to a register, the argument type can be |
| 1196 | // used to generate 32bit instead of 64bit moves. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1197 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1198 | DCHECK_EQ(unspecified_type, false); |
| 1199 | |
| 1200 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1201 | if (unspecified_type) { |
| 1202 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1203 | if (source.IsStackSlot() || |
| 1204 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1205 | || src_cst->IsFloatConstant() |
| 1206 | || src_cst->IsNullConstant()))) { |
| 1207 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1208 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1209 | } else { |
| 1210 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1211 | // type is appropriate. Else the source is a register, and since the |
| 1212 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1213 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1214 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1215 | } |
| 1216 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1217 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1218 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1219 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1220 | // Move to GPR/FPR from stack |
| 1221 | LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1222 | if (DataType::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1223 | __ LoadFpuFromOffset(load_type, |
| 1224 | destination.AsFpuRegister<FpuRegister>(), |
| 1225 | SP, |
| 1226 | source.GetStackIndex()); |
| 1227 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1228 | // TODO: use load_type = kLoadUnsignedWord when type == DataType::Type::kReference. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1229 | __ LoadFromOffset(load_type, |
| 1230 | destination.AsRegister<GpuRegister>(), |
| 1231 | SP, |
| 1232 | source.GetStackIndex()); |
| 1233 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1234 | } else if (source.IsSIMDStackSlot()) { |
| 1235 | __ LoadFpuFromOffset(kLoadQuadword, |
| 1236 | destination.AsFpuRegister<FpuRegister>(), |
| 1237 | SP, |
| 1238 | source.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1239 | } else if (source.IsConstant()) { |
| 1240 | // Move to GPR/FPR from constant |
| 1241 | GpuRegister gpr = AT; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1242 | if (!DataType::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1243 | gpr = destination.AsRegister<GpuRegister>(); |
| 1244 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1245 | if (dst_type == DataType::Type::kInt32 || dst_type == DataType::Type::kFloat32) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1246 | int32_t value = GetInt32ValueOf(source.GetConstant()->AsConstant()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1247 | if (DataType::IsFloatingPointType(dst_type) && value == 0) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1248 | gpr = ZERO; |
| 1249 | } else { |
| 1250 | __ LoadConst32(gpr, value); |
| 1251 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1252 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1253 | int64_t value = GetInt64ValueOf(source.GetConstant()->AsConstant()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1254 | if (DataType::IsFloatingPointType(dst_type) && value == 0) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1255 | gpr = ZERO; |
| 1256 | } else { |
| 1257 | __ LoadConst64(gpr, value); |
| 1258 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1259 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1260 | if (dst_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1261 | __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1262 | } else if (dst_type == DataType::Type::kFloat64) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1263 | __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
| 1264 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1265 | } else if (source.IsRegister()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1266 | if (destination.IsRegister()) { |
| 1267 | // Move to GPR from GPR |
| 1268 | __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>()); |
| 1269 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1270 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1271 | if (DataType::Is64BitType(dst_type)) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1272 | __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1273 | } else { |
| 1274 | __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1275 | } |
| 1276 | } |
| 1277 | } else if (source.IsFpuRegister()) { |
| 1278 | if (destination.IsFpuRegister()) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1279 | if (GetGraph()->HasSIMD()) { |
| 1280 | __ MoveV(VectorRegisterFrom(destination), |
| 1281 | VectorRegisterFrom(source)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1282 | } else { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1283 | // Move to FPR from FPR |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1284 | if (dst_type == DataType::Type::kFloat32) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1285 | __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1286 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1287 | DCHECK_EQ(dst_type, DataType::Type::kFloat64); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1288 | __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1289 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1290 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1291 | } else { |
| 1292 | DCHECK(destination.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1293 | if (DataType::Is64BitType(dst_type)) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1294 | __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1295 | } else { |
| 1296 | __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1297 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1298 | } |
| 1299 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1300 | } else if (destination.IsSIMDStackSlot()) { |
| 1301 | if (source.IsFpuRegister()) { |
| 1302 | __ StoreFpuToOffset(kStoreQuadword, |
| 1303 | source.AsFpuRegister<FpuRegister>(), |
| 1304 | SP, |
| 1305 | destination.GetStackIndex()); |
| 1306 | } else { |
| 1307 | DCHECK(source.IsSIMDStackSlot()); |
| 1308 | __ LoadFpuFromOffset(kLoadQuadword, |
| 1309 | FTMP, |
| 1310 | SP, |
| 1311 | source.GetStackIndex()); |
| 1312 | __ StoreFpuToOffset(kStoreQuadword, |
| 1313 | FTMP, |
| 1314 | SP, |
| 1315 | destination.GetStackIndex()); |
| 1316 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1317 | } else { // The destination is not a register. It must be a stack slot. |
| 1318 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1319 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1320 | if (unspecified_type) { |
| 1321 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1322 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1323 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1324 | dst_type = |
| 1325 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1326 | } |
| 1327 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1328 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1329 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1330 | // Move to stack from GPR/FPR |
| 1331 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 1332 | if (source.IsRegister()) { |
| 1333 | __ StoreToOffset(store_type, |
| 1334 | source.AsRegister<GpuRegister>(), |
| 1335 | SP, |
| 1336 | destination.GetStackIndex()); |
| 1337 | } else { |
| 1338 | __ StoreFpuToOffset(store_type, |
| 1339 | source.AsFpuRegister<FpuRegister>(), |
| 1340 | SP, |
| 1341 | destination.GetStackIndex()); |
| 1342 | } |
| 1343 | } else if (source.IsConstant()) { |
| 1344 | // Move to stack from constant |
| 1345 | HConstant* src_cst = source.GetConstant(); |
| 1346 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1347 | GpuRegister gpr = ZERO; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1348 | if (destination.IsStackSlot()) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1349 | int32_t value = GetInt32ValueOf(src_cst->AsConstant()); |
| 1350 | if (value != 0) { |
| 1351 | gpr = TMP; |
| 1352 | __ LoadConst32(gpr, value); |
| 1353 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1354 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1355 | DCHECK(destination.IsDoubleStackSlot()); |
| 1356 | int64_t value = GetInt64ValueOf(src_cst->AsConstant()); |
| 1357 | if (value != 0) { |
| 1358 | gpr = TMP; |
| 1359 | __ LoadConst64(gpr, value); |
| 1360 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1361 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1362 | __ StoreToOffset(store_type, gpr, SP, destination.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1363 | } else { |
| 1364 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
| 1365 | DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot()); |
| 1366 | // Move to stack from stack |
| 1367 | if (destination.IsStackSlot()) { |
| 1368 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1369 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 1370 | } else { |
| 1371 | __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex()); |
| 1372 | __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex()); |
| 1373 | } |
| 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1378 | void CodeGeneratorMIPS64::SwapLocations(Location loc1, Location loc2, DataType::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1379 | DCHECK(!loc1.IsConstant()); |
| 1380 | DCHECK(!loc2.IsConstant()); |
| 1381 | |
| 1382 | if (loc1.Equals(loc2)) { |
| 1383 | return; |
| 1384 | } |
| 1385 | |
| 1386 | bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot(); |
| 1387 | bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot(); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1388 | bool is_simd1 = loc1.IsSIMDStackSlot(); |
| 1389 | bool is_simd2 = loc2.IsSIMDStackSlot(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1390 | bool is_fp_reg1 = loc1.IsFpuRegister(); |
| 1391 | bool is_fp_reg2 = loc2.IsFpuRegister(); |
| 1392 | |
| 1393 | if (loc2.IsRegister() && loc1.IsRegister()) { |
| 1394 | // Swap 2 GPRs |
| 1395 | GpuRegister r1 = loc1.AsRegister<GpuRegister>(); |
| 1396 | GpuRegister r2 = loc2.AsRegister<GpuRegister>(); |
| 1397 | __ Move(TMP, r2); |
| 1398 | __ Move(r2, r1); |
| 1399 | __ Move(r1, TMP); |
| 1400 | } else if (is_fp_reg2 && is_fp_reg1) { |
| 1401 | // Swap 2 FPRs |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1402 | if (GetGraph()->HasSIMD()) { |
| 1403 | __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(loc1)); |
| 1404 | __ MoveV(VectorRegisterFrom(loc1), VectorRegisterFrom(loc2)); |
| 1405 | __ MoveV(VectorRegisterFrom(loc2), static_cast<VectorRegister>(FTMP)); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1406 | } else { |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1407 | FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>(); |
| 1408 | FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>(); |
| 1409 | if (type == DataType::Type::kFloat32) { |
| 1410 | __ MovS(FTMP, r1); |
| 1411 | __ MovS(r1, r2); |
| 1412 | __ MovS(r2, FTMP); |
| 1413 | } else { |
| 1414 | DCHECK_EQ(type, DataType::Type::kFloat64); |
| 1415 | __ MovD(FTMP, r1); |
| 1416 | __ MovD(r1, r2); |
| 1417 | __ MovD(r2, FTMP); |
| 1418 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1419 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1420 | } else if (is_slot1 != is_slot2) { |
| 1421 | // Swap GPR/FPR and stack slot |
| 1422 | Location reg_loc = is_slot1 ? loc2 : loc1; |
| 1423 | Location mem_loc = is_slot1 ? loc1 : loc2; |
| 1424 | LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
| 1425 | StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1426 | // TODO: use load_type = kLoadUnsignedWord when type == DataType::Type::kReference. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1427 | __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex()); |
| 1428 | if (reg_loc.IsFpuRegister()) { |
| 1429 | __ StoreFpuToOffset(store_type, |
| 1430 | reg_loc.AsFpuRegister<FpuRegister>(), |
| 1431 | SP, |
| 1432 | mem_loc.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1433 | if (mem_loc.IsStackSlot()) { |
| 1434 | __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1435 | } else { |
| 1436 | DCHECK(mem_loc.IsDoubleStackSlot()); |
| 1437 | __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1438 | } |
| 1439 | } else { |
| 1440 | __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex()); |
| 1441 | __ Move(reg_loc.AsRegister<GpuRegister>(), TMP); |
| 1442 | } |
| 1443 | } else if (is_slot1 && is_slot2) { |
| 1444 | move_resolver_.Exchange(loc1.GetStackIndex(), |
| 1445 | loc2.GetStackIndex(), |
| 1446 | loc1.IsDoubleStackSlot()); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1447 | } else if (is_simd1 && is_simd2) { |
| 1448 | move_resolver_.ExchangeQuadSlots(loc1.GetStackIndex(), loc2.GetStackIndex()); |
| 1449 | } else if ((is_fp_reg1 && is_simd2) || (is_fp_reg2 && is_simd1)) { |
| 1450 | Location fp_reg_loc = is_fp_reg1 ? loc1 : loc2; |
| 1451 | Location mem_loc = is_fp_reg1 ? loc2 : loc1; |
| 1452 | __ LoadFpuFromOffset(kLoadQuadword, FTMP, SP, mem_loc.GetStackIndex()); |
| 1453 | __ StoreFpuToOffset(kStoreQuadword, |
| 1454 | fp_reg_loc.AsFpuRegister<FpuRegister>(), |
| 1455 | SP, |
| 1456 | mem_loc.GetStackIndex()); |
| 1457 | __ MoveV(VectorRegisterFrom(fp_reg_loc), static_cast<VectorRegister>(FTMP)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1458 | } else { |
| 1459 | LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2; |
| 1460 | } |
| 1461 | } |
| 1462 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1463 | void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) { |
| 1464 | DCHECK(location.IsRegister()); |
| 1465 | __ LoadConst32(location.AsRegister<GpuRegister>(), value); |
| 1466 | } |
| 1467 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1468 | void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1469 | if (location.IsRegister()) { |
| 1470 | locations->AddTemp(location); |
| 1471 | } else { |
| 1472 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1473 | } |
| 1474 | } |
| 1475 | |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1476 | void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object, |
| 1477 | GpuRegister value, |
| 1478 | bool value_can_be_null) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1479 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1480 | GpuRegister card = AT; |
| 1481 | GpuRegister temp = TMP; |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1482 | if (value_can_be_null) { |
| 1483 | __ Beqzc(value, &done); |
| 1484 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1485 | __ LoadFromOffset(kLoadDoubleword, |
| 1486 | card, |
| 1487 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1488 | Thread::CardTableOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1489 | __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1490 | __ Daddu(temp, card, temp); |
| 1491 | __ Sb(card, temp, 0); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1492 | if (value_can_be_null) { |
| 1493 | __ Bind(&done); |
| 1494 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1497 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1498 | inline void CodeGeneratorMIPS64::EmitPcRelativeLinkerPatches( |
| 1499 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1500 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1501 | for (const PcRelativePatchInfo& info : infos) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1502 | const DexFile* dex_file = info.target_dex_file; |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1503 | size_t offset_or_index = info.offset_or_index; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1504 | DCHECK(info.label.IsBound()); |
| 1505 | uint32_t literal_offset = __ GetLabelLocation(&info.label); |
| 1506 | const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info; |
| 1507 | uint32_t pc_rel_offset = __ GetLabelLocation(&info_high.label); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1508 | 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] | 1509 | } |
| 1510 | } |
| 1511 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1512 | linker::LinkerPatch DataBimgRelRoPatchAdapter(size_t literal_offset, |
| 1513 | const DexFile* target_dex_file, |
| 1514 | uint32_t pc_insn_offset, |
| 1515 | uint32_t boot_image_offset) { |
| 1516 | DCHECK(target_dex_file == nullptr); // Unused for DataBimgRelRoPatch(), should be null. |
| 1517 | return linker::LinkerPatch::DataBimgRelRoPatch(literal_offset, pc_insn_offset, boot_image_offset); |
| 1518 | } |
| 1519 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1520 | void CodeGeneratorMIPS64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1521 | DCHECK(linker_patches->empty()); |
| 1522 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1523 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1524 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1525 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1526 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1527 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1528 | string_bss_entry_patches_.size(); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1529 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1530 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1531 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1532 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1533 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1534 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1535 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1536 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1537 | } else { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1538 | EmitPcRelativeLinkerPatches<DataBimgRelRoPatchAdapter>( |
| 1539 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame^] | 1540 | DCHECK(boot_image_type_patches_.empty()); |
| 1541 | DCHECK(boot_image_string_patches_.empty()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1542 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1543 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1544 | method_bss_entry_patches_, linker_patches); |
| 1545 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1546 | type_bss_entry_patches_, linker_patches); |
| 1547 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1548 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1549 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1550 | } |
| 1551 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1552 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageRelRoPatch( |
| 1553 | uint32_t boot_image_offset, |
| 1554 | const PcRelativePatchInfo* info_high) { |
| 1555 | return NewPcRelativePatch( |
| 1556 | /* dex_file */ nullptr, boot_image_offset, info_high, &boot_image_method_patches_); |
| 1557 | } |
| 1558 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1559 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageMethodPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1560 | MethodReference target_method, |
| 1561 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1562 | return NewPcRelativePatch( |
| 1563 | 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] | 1564 | } |
| 1565 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1566 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewMethodBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1567 | MethodReference target_method, |
| 1568 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1569 | return NewPcRelativePatch( |
| 1570 | 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] | 1571 | } |
| 1572 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1573 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageTypePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1574 | const DexFile& dex_file, |
| 1575 | dex::TypeIndex type_index, |
| 1576 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1577 | 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] | 1578 | } |
| 1579 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1580 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewTypeBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1581 | const DexFile& dex_file, |
| 1582 | dex::TypeIndex type_index, |
| 1583 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1584 | 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] | 1585 | } |
| 1586 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1587 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageStringPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1588 | const DexFile& dex_file, |
| 1589 | dex::StringIndex string_index, |
| 1590 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1591 | return NewPcRelativePatch( |
| 1592 | &dex_file, string_index.index_, info_high, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1593 | } |
| 1594 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1595 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewStringBssEntryPatch( |
| 1596 | const DexFile& dex_file, |
| 1597 | dex::StringIndex string_index, |
| 1598 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1599 | 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] | 1600 | } |
| 1601 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1602 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1603 | const DexFile* dex_file, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1604 | uint32_t offset_or_index, |
| 1605 | const PcRelativePatchInfo* info_high, |
| 1606 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1607 | patches->emplace_back(dex_file, offset_or_index, info_high); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1608 | return &patches->back(); |
| 1609 | } |
| 1610 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1611 | Literal* CodeGeneratorMIPS64::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1612 | return map->GetOrCreate( |
| 1613 | value, |
| 1614 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1615 | } |
| 1616 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1617 | Literal* CodeGeneratorMIPS64::DeduplicateUint64Literal(uint64_t value) { |
| 1618 | return uint64_literals_.GetOrCreate( |
| 1619 | value, |
| 1620 | [this, value]() { return __ NewLiteral<uint64_t>(value); }); |
| 1621 | } |
| 1622 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1623 | Literal* CodeGeneratorMIPS64::DeduplicateBootImageAddressLiteral(uint64_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1624 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1625 | } |
| 1626 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1627 | void CodeGeneratorMIPS64::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high, |
| 1628 | GpuRegister out, |
| 1629 | PcRelativePatchInfo* info_low) { |
| 1630 | DCHECK(!info_high->patch_info_high); |
| 1631 | __ Bind(&info_high->label); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1632 | // Add the high half of a 32-bit offset to PC. |
| 1633 | __ Auipc(out, /* placeholder */ 0x1234); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1634 | // 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] | 1635 | // offset to `out` (e.g. ld, jialc, daddiu). |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1636 | if (info_low != nullptr) { |
| 1637 | DCHECK_EQ(info_low->patch_info_high, info_high); |
| 1638 | __ Bind(&info_low->label); |
| 1639 | } |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1640 | } |
| 1641 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1642 | Literal* CodeGeneratorMIPS64::DeduplicateJitStringLiteral(const DexFile& dex_file, |
| 1643 | dex::StringIndex string_index, |
| 1644 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1645 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1646 | return jit_string_patches_.GetOrCreate( |
| 1647 | StringReference(&dex_file, string_index), |
| 1648 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1649 | } |
| 1650 | |
| 1651 | Literal* CodeGeneratorMIPS64::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 1652 | dex::TypeIndex type_index, |
| 1653 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1654 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1655 | return jit_class_patches_.GetOrCreate( |
| 1656 | TypeReference(&dex_file, type_index), |
| 1657 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1658 | } |
| 1659 | |
| 1660 | void CodeGeneratorMIPS64::PatchJitRootUse(uint8_t* code, |
| 1661 | const uint8_t* roots_data, |
| 1662 | const Literal* literal, |
| 1663 | uint64_t index_in_table) const { |
| 1664 | uint32_t literal_offset = GetAssembler().GetLabelLocation(literal->GetLabel()); |
| 1665 | uintptr_t address = |
| 1666 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1667 | reinterpret_cast<uint32_t*>(code + literal_offset)[0] = dchecked_integral_cast<uint32_t>(address); |
| 1668 | } |
| 1669 | |
| 1670 | void CodeGeneratorMIPS64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1671 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1672 | const StringReference& string_reference = entry.first; |
| 1673 | Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1674 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1675 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1676 | } |
| 1677 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1678 | const TypeReference& type_reference = entry.first; |
| 1679 | Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1680 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1681 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1682 | } |
| 1683 | } |
| 1684 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1685 | void CodeGeneratorMIPS64::SetupBlockedRegisters() const { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1686 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1687 | blocked_core_registers_[ZERO] = true; |
| 1688 | blocked_core_registers_[K0] = true; |
| 1689 | blocked_core_registers_[K1] = true; |
| 1690 | blocked_core_registers_[GP] = true; |
| 1691 | blocked_core_registers_[SP] = true; |
| 1692 | blocked_core_registers_[RA] = true; |
| 1693 | |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1694 | // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch |
| 1695 | // registers (similar to how AT is used by MIPS assemblers). |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1696 | blocked_core_registers_[AT] = true; |
| 1697 | blocked_core_registers_[TMP] = true; |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1698 | blocked_core_registers_[TMP2] = true; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1699 | blocked_fpu_registers_[FTMP] = true; |
| 1700 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1701 | if (GetInstructionSetFeatures().HasMsa()) { |
| 1702 | // To be used just for MSA instructions. |
| 1703 | blocked_fpu_registers_[FTMP2] = true; |
| 1704 | } |
| 1705 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1706 | // Reserve suspend and thread registers. |
| 1707 | blocked_core_registers_[S0] = true; |
| 1708 | blocked_core_registers_[TR] = true; |
| 1709 | |
| 1710 | // Reserve T9 for function calls |
| 1711 | blocked_core_registers_[T9] = true; |
| 1712 | |
Goran Jakovljevic | 782be11 | 2016-06-21 12:39:04 +0200 | [diff] [blame] | 1713 | if (GetGraph()->IsDebuggable()) { |
| 1714 | // Stubs do not save callee-save floating point registers. If the graph |
| 1715 | // is debuggable, we need to deal with these registers differently. For |
| 1716 | // now, just block them. |
| 1717 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1718 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1719 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1720 | } |
| 1721 | } |
| 1722 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1723 | size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1724 | __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1725 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1729 | __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1730 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1734 | __ StoreFpuToOffset(GetGraph()->HasSIMD() ? kStoreQuadword : kStoreDoubleword, |
| 1735 | FpuRegister(reg_id), |
| 1736 | SP, |
| 1737 | stack_index); |
| 1738 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1742 | __ LoadFpuFromOffset(GetGraph()->HasSIMD() ? kLoadQuadword : kLoadDoubleword, |
| 1743 | FpuRegister(reg_id), |
| 1744 | SP, |
| 1745 | stack_index); |
| 1746 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1750 | stream << GpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1754 | stream << FpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1757 | void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1758 | HInstruction* instruction, |
| 1759 | uint32_t dex_pc, |
| 1760 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1761 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1762 | GenerateInvokeRuntime(GetThreadOffset<kMips64PointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 1763 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1764 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1765 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1768 | void CodeGeneratorMIPS64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1769 | HInstruction* instruction, |
| 1770 | SlowPathCode* slow_path) { |
| 1771 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1772 | GenerateInvokeRuntime(entry_point_offset); |
| 1773 | } |
| 1774 | |
| 1775 | void CodeGeneratorMIPS64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| 1776 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 1777 | __ Jalr(T9); |
| 1778 | __ Nop(); |
| 1779 | } |
| 1780 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1781 | void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path, |
| 1782 | GpuRegister class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1783 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 1784 | const size_t status_byte_offset = |
| 1785 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 1786 | constexpr uint32_t shifted_initialized_value = |
| 1787 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 1788 | |
| 1789 | __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, status_byte_offset); |
Lena Djokic | 3177e10 | 2018-02-28 11:32:40 +0100 | [diff] [blame] | 1790 | __ Sltiu(TMP, TMP, shifted_initialized_value); |
| 1791 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1792 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1793 | __ Sync(0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1794 | __ Bind(slow_path->GetExitLabel()); |
| 1795 | } |
| 1796 | |
| 1797 | void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1798 | __ Sync(0); // only stype 0 is supported |
| 1799 | } |
| 1800 | |
| 1801 | void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1802 | HBasicBlock* successor) { |
| 1803 | SuspendCheckSlowPathMIPS64* slow_path = |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 1804 | down_cast<SuspendCheckSlowPathMIPS64*>(instruction->GetSlowPath()); |
| 1805 | |
| 1806 | if (slow_path == nullptr) { |
| 1807 | slow_path = |
| 1808 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS64(instruction, successor); |
| 1809 | instruction->SetSlowPath(slow_path); |
| 1810 | codegen_->AddSlowPath(slow_path); |
| 1811 | if (successor != nullptr) { |
| 1812 | DCHECK(successor->IsLoopHeader()); |
| 1813 | } |
| 1814 | } else { |
| 1815 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1816 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1817 | |
| 1818 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1819 | TMP, |
| 1820 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1821 | Thread::ThreadFlagsOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1822 | if (successor == nullptr) { |
| 1823 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 1824 | __ Bind(slow_path->GetReturnLabel()); |
| 1825 | } else { |
| 1826 | __ Beqzc(TMP, codegen_->GetLabelOf(successor)); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1827 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1828 | // slow_path will return to GetLabelOf(successor). |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph, |
| 1833 | CodeGeneratorMIPS64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1834 | : InstructionCodeGenerator(graph, codegen), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1835 | assembler_(codegen->GetAssembler()), |
| 1836 | codegen_(codegen) {} |
| 1837 | |
| 1838 | void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1839 | DCHECK_EQ(instruction->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1840 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1841 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1842 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1843 | case DataType::Type::kInt32: |
| 1844 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1845 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1846 | HInstruction* right = instruction->InputAt(1); |
| 1847 | bool can_use_imm = false; |
| 1848 | if (right->IsConstant()) { |
| 1849 | int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant()); |
| 1850 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1851 | can_use_imm = IsUint<16>(imm); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1852 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1853 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 1854 | bool single_use = right->GetUses().HasExactlyOneElement(); |
| 1855 | if (instruction->IsSub()) { |
| 1856 | if (!(type == DataType::Type::kInt32 && imm == INT32_MIN)) { |
| 1857 | imm = -imm; |
| 1858 | } |
| 1859 | } |
| 1860 | if (type == DataType::Type::kInt32) { |
| 1861 | can_use_imm = IsInt<16>(imm) || (Low16Bits(imm) == 0) || single_use; |
| 1862 | } else { |
| 1863 | can_use_imm = IsInt<16>(imm) || (IsInt<32>(imm) && (Low16Bits(imm) == 0)) || single_use; |
| 1864 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1865 | } |
| 1866 | } |
| 1867 | if (can_use_imm) |
| 1868 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1869 | else |
| 1870 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1871 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1872 | } |
| 1873 | break; |
| 1874 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1875 | case DataType::Type::kFloat32: |
| 1876 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1877 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1878 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1879 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1880 | break; |
| 1881 | |
| 1882 | default: |
| 1883 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1888 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1889 | LocationSummary* locations = instruction->GetLocations(); |
| 1890 | |
| 1891 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1892 | case DataType::Type::kInt32: |
| 1893 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1894 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1895 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1896 | Location rhs_location = locations->InAt(1); |
| 1897 | |
| 1898 | GpuRegister rhs_reg = ZERO; |
| 1899 | int64_t rhs_imm = 0; |
| 1900 | bool use_imm = rhs_location.IsConstant(); |
| 1901 | if (use_imm) { |
| 1902 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1903 | } else { |
| 1904 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1905 | } |
| 1906 | |
| 1907 | if (instruction->IsAnd()) { |
| 1908 | if (use_imm) |
| 1909 | __ Andi(dst, lhs, rhs_imm); |
| 1910 | else |
| 1911 | __ And(dst, lhs, rhs_reg); |
| 1912 | } else if (instruction->IsOr()) { |
| 1913 | if (use_imm) |
| 1914 | __ Ori(dst, lhs, rhs_imm); |
| 1915 | else |
| 1916 | __ Or(dst, lhs, rhs_reg); |
| 1917 | } else if (instruction->IsXor()) { |
| 1918 | if (use_imm) |
| 1919 | __ Xori(dst, lhs, rhs_imm); |
| 1920 | else |
| 1921 | __ Xor(dst, lhs, rhs_reg); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1922 | } else if (instruction->IsAdd() || instruction->IsSub()) { |
| 1923 | if (instruction->IsSub()) { |
| 1924 | rhs_imm = -rhs_imm; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1925 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1926 | if (type == DataType::Type::kInt32) { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1927 | if (use_imm) { |
| 1928 | if (IsInt<16>(rhs_imm)) { |
| 1929 | __ Addiu(dst, lhs, rhs_imm); |
| 1930 | } else { |
| 1931 | int16_t rhs_imm_high = High16Bits(rhs_imm); |
| 1932 | int16_t rhs_imm_low = Low16Bits(rhs_imm); |
| 1933 | if (rhs_imm_low < 0) { |
| 1934 | rhs_imm_high += 1; |
| 1935 | } |
| 1936 | __ Aui(dst, lhs, rhs_imm_high); |
| 1937 | if (rhs_imm_low != 0) { |
| 1938 | __ Addiu(dst, dst, rhs_imm_low); |
| 1939 | } |
| 1940 | } |
| 1941 | } else { |
| 1942 | if (instruction->IsAdd()) { |
| 1943 | __ Addu(dst, lhs, rhs_reg); |
| 1944 | } else { |
| 1945 | DCHECK(instruction->IsSub()); |
| 1946 | __ Subu(dst, lhs, rhs_reg); |
| 1947 | } |
| 1948 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1949 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1950 | if (use_imm) { |
| 1951 | if (IsInt<16>(rhs_imm)) { |
| 1952 | __ Daddiu(dst, lhs, rhs_imm); |
| 1953 | } else if (IsInt<32>(rhs_imm)) { |
| 1954 | int16_t rhs_imm_high = High16Bits(rhs_imm); |
| 1955 | int16_t rhs_imm_low = Low16Bits(rhs_imm); |
| 1956 | bool overflow_hi16 = false; |
| 1957 | if (rhs_imm_low < 0) { |
| 1958 | rhs_imm_high += 1; |
| 1959 | overflow_hi16 = (rhs_imm_high == -32768); |
| 1960 | } |
| 1961 | __ Daui(dst, lhs, rhs_imm_high); |
| 1962 | if (rhs_imm_low != 0) { |
| 1963 | __ Daddiu(dst, dst, rhs_imm_low); |
| 1964 | } |
| 1965 | if (overflow_hi16) { |
| 1966 | __ Dahi(dst, 1); |
| 1967 | } |
| 1968 | } else { |
| 1969 | int16_t rhs_imm_low = Low16Bits(Low32Bits(rhs_imm)); |
| 1970 | if (rhs_imm_low < 0) { |
| 1971 | rhs_imm += (INT64_C(1) << 16); |
| 1972 | } |
| 1973 | int16_t rhs_imm_upper = High16Bits(Low32Bits(rhs_imm)); |
| 1974 | if (rhs_imm_upper < 0) { |
| 1975 | rhs_imm += (INT64_C(1) << 32); |
| 1976 | } |
| 1977 | int16_t rhs_imm_high = Low16Bits(High32Bits(rhs_imm)); |
| 1978 | if (rhs_imm_high < 0) { |
| 1979 | rhs_imm += (INT64_C(1) << 48); |
| 1980 | } |
| 1981 | int16_t rhs_imm_top = High16Bits(High32Bits(rhs_imm)); |
| 1982 | GpuRegister tmp = lhs; |
| 1983 | if (rhs_imm_low != 0) { |
| 1984 | __ Daddiu(dst, tmp, rhs_imm_low); |
| 1985 | tmp = dst; |
| 1986 | } |
| 1987 | // Dahi and Dati must use the same input and output register, so we have to initialize |
| 1988 | // the dst register using Daddiu or Daui, even when the intermediate value is zero: |
| 1989 | // Daui(dst, lhs, 0). |
| 1990 | if ((rhs_imm_upper != 0) || (rhs_imm_low == 0)) { |
| 1991 | __ Daui(dst, tmp, rhs_imm_upper); |
| 1992 | } |
| 1993 | if (rhs_imm_high != 0) { |
| 1994 | __ Dahi(dst, rhs_imm_high); |
| 1995 | } |
| 1996 | if (rhs_imm_top != 0) { |
| 1997 | __ Dati(dst, rhs_imm_top); |
| 1998 | } |
| 1999 | } |
| 2000 | } else if (instruction->IsAdd()) { |
| 2001 | __ Daddu(dst, lhs, rhs_reg); |
| 2002 | } else { |
| 2003 | DCHECK(instruction->IsSub()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2004 | __ Dsubu(dst, lhs, rhs_reg); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2005 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2006 | } |
| 2007 | } |
| 2008 | break; |
| 2009 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2010 | case DataType::Type::kFloat32: |
| 2011 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2012 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 2013 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 2014 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 2015 | if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2016 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2017 | __ AddS(dst, lhs, rhs); |
| 2018 | else |
| 2019 | __ AddD(dst, lhs, rhs); |
| 2020 | } else if (instruction->IsSub()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2021 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2022 | __ SubS(dst, lhs, rhs); |
| 2023 | else |
| 2024 | __ SubD(dst, lhs, rhs); |
| 2025 | } else { |
| 2026 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
| 2027 | } |
| 2028 | break; |
| 2029 | } |
| 2030 | default: |
| 2031 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 2032 | } |
| 2033 | } |
| 2034 | |
| 2035 | void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2036 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2037 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2038 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2039 | DataType::Type type = instr->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2040 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2041 | case DataType::Type::kInt32: |
| 2042 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2043 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2044 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2045 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2046 | break; |
| 2047 | } |
| 2048 | default: |
| 2049 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2050 | } |
| 2051 | } |
| 2052 | |
| 2053 | void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2054 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2055 | LocationSummary* locations = instr->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2056 | DataType::Type type = instr->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2057 | |
| 2058 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2059 | case DataType::Type::kInt32: |
| 2060 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2061 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 2062 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2063 | Location rhs_location = locations->InAt(1); |
| 2064 | |
| 2065 | GpuRegister rhs_reg = ZERO; |
| 2066 | int64_t rhs_imm = 0; |
| 2067 | bool use_imm = rhs_location.IsConstant(); |
| 2068 | if (use_imm) { |
| 2069 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 2070 | } else { |
| 2071 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 2072 | } |
| 2073 | |
| 2074 | if (use_imm) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2075 | uint32_t shift_value = rhs_imm & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2076 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2077 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2078 | if (shift_value == 0) { |
| 2079 | if (dst != lhs) { |
| 2080 | __ Move(dst, lhs); |
| 2081 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2082 | } else if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2083 | if (instr->IsShl()) { |
| 2084 | __ Sll(dst, lhs, shift_value); |
| 2085 | } else if (instr->IsShr()) { |
| 2086 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2087 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2088 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2089 | } else { |
| 2090 | __ Rotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2091 | } |
| 2092 | } else { |
| 2093 | if (shift_value < 32) { |
| 2094 | if (instr->IsShl()) { |
| 2095 | __ Dsll(dst, lhs, shift_value); |
| 2096 | } else if (instr->IsShr()) { |
| 2097 | __ Dsra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2098 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2099 | __ Dsrl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2100 | } else { |
| 2101 | __ Drotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2102 | } |
| 2103 | } else { |
| 2104 | shift_value -= 32; |
| 2105 | if (instr->IsShl()) { |
| 2106 | __ Dsll32(dst, lhs, shift_value); |
| 2107 | } else if (instr->IsShr()) { |
| 2108 | __ Dsra32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2109 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2110 | __ Dsrl32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2111 | } else { |
| 2112 | __ Drotr32(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2113 | } |
| 2114 | } |
| 2115 | } |
| 2116 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2117 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2118 | if (instr->IsShl()) { |
| 2119 | __ Sllv(dst, lhs, rhs_reg); |
| 2120 | } else if (instr->IsShr()) { |
| 2121 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2122 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2123 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2124 | } else { |
| 2125 | __ Rotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2126 | } |
| 2127 | } else { |
| 2128 | if (instr->IsShl()) { |
| 2129 | __ Dsllv(dst, lhs, rhs_reg); |
| 2130 | } else if (instr->IsShr()) { |
| 2131 | __ Dsrav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2132 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2133 | __ Dsrlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2134 | } else { |
| 2135 | __ Drotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2136 | } |
| 2137 | } |
| 2138 | } |
| 2139 | break; |
| 2140 | } |
| 2141 | default: |
| 2142 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2143 | } |
| 2144 | } |
| 2145 | |
| 2146 | void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) { |
| 2147 | HandleBinaryOp(instruction); |
| 2148 | } |
| 2149 | |
| 2150 | void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) { |
| 2151 | HandleBinaryOp(instruction); |
| 2152 | } |
| 2153 | |
| 2154 | void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) { |
| 2155 | HandleBinaryOp(instruction); |
| 2156 | } |
| 2157 | |
| 2158 | void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) { |
| 2159 | HandleBinaryOp(instruction); |
| 2160 | } |
| 2161 | |
| 2162 | void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2163 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2164 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2165 | kEmitCompilerReadBarrier && (type == DataType::Type::kReference); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2166 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2167 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2168 | object_array_get_with_read_barrier |
| 2169 | ? LocationSummary::kCallOnSlowPath |
| 2170 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 2171 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2172 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2173 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2174 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2175 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2176 | if (DataType::IsFloatingPointType(type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2177 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2178 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2179 | // The output overlaps in the case of an object array get with |
| 2180 | // read barriers enabled: we do not want the move to overwrite the |
| 2181 | // array's location, as we need it to emit the read barrier. |
| 2182 | locations->SetOut(Location::RequiresRegister(), |
| 2183 | object_array_get_with_read_barrier |
| 2184 | ? Location::kOutputOverlap |
| 2185 | : Location::kNoOutputOverlap); |
| 2186 | } |
| 2187 | // We need a temporary register for the read barrier marking slow |
| 2188 | // path in CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier. |
| 2189 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2190 | bool temp_needed = instruction->GetIndex()->IsConstant() |
| 2191 | ? !kBakerReadBarrierThunksEnableForFields |
| 2192 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2193 | if (temp_needed) { |
| 2194 | locations->AddTemp(Location::RequiresRegister()); |
| 2195 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2196 | } |
| 2197 | } |
| 2198 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2199 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS64* codegen) { |
| 2200 | auto null_checker = [codegen, instruction]() { |
| 2201 | codegen->MaybeRecordImplicitNullCheck(instruction); |
| 2202 | }; |
| 2203 | return null_checker; |
| 2204 | } |
| 2205 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2206 | void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) { |
| 2207 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2208 | Location obj_loc = locations->InAt(0); |
| 2209 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 2210 | Location out_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2211 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2212 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2213 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2214 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2215 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2216 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2217 | instruction->IsStringCharAt(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2218 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2219 | case DataType::Type::kBool: |
| 2220 | case DataType::Type::kUint8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2221 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2222 | if (index.IsConstant()) { |
| 2223 | size_t offset = |
| 2224 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2225 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2226 | } else { |
| 2227 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2228 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2229 | } |
| 2230 | break; |
| 2231 | } |
| 2232 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2233 | case DataType::Type::kInt8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2234 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2235 | if (index.IsConstant()) { |
| 2236 | size_t offset = |
| 2237 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2238 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2239 | } else { |
| 2240 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2241 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2242 | } |
| 2243 | break; |
| 2244 | } |
| 2245 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2246 | case DataType::Type::kUint16: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2247 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2248 | if (maybe_compressed_char_at) { |
| 2249 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2250 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2251 | __ Dext(TMP, TMP, 0, 1); |
| 2252 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2253 | "Expecting 0=compressed, 1=uncompressed"); |
| 2254 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2255 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2256 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2257 | if (maybe_compressed_char_at) { |
| 2258 | Mips64Label uncompressed_load, done; |
| 2259 | __ Bnezc(TMP, &uncompressed_load); |
| 2260 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2261 | out, |
| 2262 | obj, |
| 2263 | data_offset + (const_index << TIMES_1)); |
| 2264 | __ Bc(&done); |
| 2265 | __ Bind(&uncompressed_load); |
| 2266 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2267 | out, |
| 2268 | obj, |
| 2269 | data_offset + (const_index << TIMES_2)); |
| 2270 | __ Bind(&done); |
| 2271 | } else { |
| 2272 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2273 | out, |
| 2274 | obj, |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2275 | data_offset + (const_index << TIMES_2), |
| 2276 | null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2277 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2278 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2279 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
| 2280 | if (maybe_compressed_char_at) { |
| 2281 | Mips64Label uncompressed_load, done; |
| 2282 | __ Bnezc(TMP, &uncompressed_load); |
| 2283 | __ Daddu(TMP, obj, index_reg); |
| 2284 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2285 | __ Bc(&done); |
| 2286 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2287 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2288 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2289 | __ Bind(&done); |
| 2290 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2291 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2292 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2293 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2294 | } |
| 2295 | break; |
| 2296 | } |
| 2297 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2298 | case DataType::Type::kInt16: { |
| 2299 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 2300 | if (index.IsConstant()) { |
| 2301 | size_t offset = |
| 2302 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2303 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
| 2304 | } else { |
| 2305 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
| 2306 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
| 2307 | } |
| 2308 | break; |
| 2309 | } |
| 2310 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2311 | case DataType::Type::kInt32: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2312 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2313 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2314 | LoadOperandType load_type = |
| 2315 | (type == DataType::Type::kReference) ? kLoadUnsignedWord : kLoadWord; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2316 | if (index.IsConstant()) { |
| 2317 | size_t offset = |
| 2318 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2319 | __ LoadFromOffset(load_type, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2320 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2321 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2322 | __ LoadFromOffset(load_type, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2323 | } |
| 2324 | break; |
| 2325 | } |
| 2326 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2327 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2328 | static_assert( |
| 2329 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2330 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2331 | // /* HeapReference<Object> */ out = |
| 2332 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2333 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2334 | bool temp_needed = index.IsConstant() |
| 2335 | ? !kBakerReadBarrierThunksEnableForFields |
| 2336 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2337 | Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2338 | // Note that a potential implicit null check is handled in this |
| 2339 | // CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier call. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2340 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 2341 | if (index.IsConstant()) { |
| 2342 | // Array load with a constant index can be treated as a field load. |
| 2343 | size_t offset = |
| 2344 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2345 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2346 | out_loc, |
| 2347 | obj, |
| 2348 | offset, |
| 2349 | temp, |
| 2350 | /* needs_null_check */ false); |
| 2351 | } else { |
| 2352 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2353 | out_loc, |
| 2354 | obj, |
| 2355 | data_offset, |
| 2356 | index, |
| 2357 | temp, |
| 2358 | /* needs_null_check */ false); |
| 2359 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2360 | } else { |
| 2361 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 2362 | if (index.IsConstant()) { |
| 2363 | size_t offset = |
| 2364 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2365 | __ LoadFromOffset(kLoadUnsignedWord, out, obj, offset, null_checker); |
| 2366 | // If read barriers are enabled, emit read barriers other than |
| 2367 | // Baker's using a slow path (and also unpoison the loaded |
| 2368 | // reference, if heap poisoning is enabled). |
| 2369 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2370 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2371 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2372 | __ LoadFromOffset(kLoadUnsignedWord, out, TMP, data_offset, null_checker); |
| 2373 | // If read barriers are enabled, emit read barriers other than |
| 2374 | // Baker's using a slow path (and also unpoison the loaded |
| 2375 | // reference, if heap poisoning is enabled). |
| 2376 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2377 | out_loc, |
| 2378 | out_loc, |
| 2379 | obj_loc, |
| 2380 | data_offset, |
| 2381 | index); |
| 2382 | } |
| 2383 | } |
| 2384 | break; |
| 2385 | } |
| 2386 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2387 | case DataType::Type::kInt64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2388 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2389 | if (index.IsConstant()) { |
| 2390 | size_t offset = |
| 2391 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2392 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2393 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2394 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2395 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2396 | } |
| 2397 | break; |
| 2398 | } |
| 2399 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2400 | case DataType::Type::kFloat32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2401 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2402 | if (index.IsConstant()) { |
| 2403 | size_t offset = |
| 2404 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2405 | __ LoadFpuFromOffset(kLoadWord, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2406 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2407 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2408 | __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2409 | } |
| 2410 | break; |
| 2411 | } |
| 2412 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2413 | case DataType::Type::kFloat64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2414 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2415 | if (index.IsConstant()) { |
| 2416 | size_t offset = |
| 2417 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2418 | __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2419 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2420 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2421 | __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2422 | } |
| 2423 | break; |
| 2424 | } |
| 2425 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2426 | case DataType::Type::kUint32: |
| 2427 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2428 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2429 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2430 | UNREACHABLE(); |
| 2431 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2432 | } |
| 2433 | |
| 2434 | void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2435 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2436 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2437 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2438 | } |
| 2439 | |
| 2440 | void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 2441 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2442 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2443 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2444 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2445 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2446 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2447 | // Mask out compression flag from String's array length. |
| 2448 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2449 | __ Srl(out, out, 1u); |
| 2450 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2451 | } |
| 2452 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2453 | Location LocationsBuilderMIPS64::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2454 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2455 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2456 | : Location::RequiresRegister(); |
| 2457 | } |
| 2458 | |
| 2459 | Location LocationsBuilderMIPS64::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2460 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2461 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2462 | // but we should only prefer this if the constant has a single use. |
| 2463 | if (instruction->IsConstant() && |
| 2464 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2465 | instruction->GetUses().HasExactlyOneElement())) { |
| 2466 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2467 | // Otherwise fall through and require an FPU register for the constant. |
| 2468 | } |
| 2469 | return Location::RequiresFpuRegister(); |
| 2470 | } |
| 2471 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2472 | void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2473 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2474 | |
| 2475 | bool needs_write_barrier = |
| 2476 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2477 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2478 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2479 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2480 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2481 | may_need_runtime_call_for_type_check ? |
| 2482 | LocationSummary::kCallOnSlowPath : |
| 2483 | LocationSummary::kNoCall); |
| 2484 | |
| 2485 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2486 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2487 | if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2488 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2489 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2490 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2491 | } |
| 2492 | if (needs_write_barrier) { |
| 2493 | // Temporary register for the write barrier. |
| 2494 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) { |
| 2499 | LocationSummary* locations = instruction->GetLocations(); |
| 2500 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2501 | Location index = locations->InAt(1); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2502 | Location value_location = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2503 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2504 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2505 | bool needs_write_barrier = |
| 2506 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2507 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2508 | GpuRegister base_reg = index.IsConstant() ? obj : TMP; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2509 | |
| 2510 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2511 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2512 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2513 | case DataType::Type::kInt8: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2514 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2515 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2516 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2517 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2518 | __ Daddu(base_reg, obj, index.AsRegister<GpuRegister>()); |
| 2519 | } |
| 2520 | if (value_location.IsConstant()) { |
| 2521 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2522 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2523 | } else { |
| 2524 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2525 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2526 | } |
| 2527 | break; |
| 2528 | } |
| 2529 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2530 | case DataType::Type::kUint16: |
| 2531 | case DataType::Type::kInt16: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2532 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2533 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2534 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2535 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2536 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2537 | } |
| 2538 | if (value_location.IsConstant()) { |
| 2539 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2540 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2541 | } else { |
| 2542 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2543 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2544 | } |
| 2545 | break; |
| 2546 | } |
| 2547 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2548 | case DataType::Type::kInt32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2549 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2550 | if (index.IsConstant()) { |
| 2551 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
| 2552 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2553 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2554 | } |
| 2555 | if (value_location.IsConstant()) { |
| 2556 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2557 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2558 | } else { |
| 2559 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2560 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2561 | } |
| 2562 | break; |
| 2563 | } |
| 2564 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2565 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2566 | if (value_location.IsConstant()) { |
| 2567 | // Just setting null. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2568 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2569 | if (index.IsConstant()) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2570 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2571 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2572 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2573 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2574 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2575 | DCHECK_EQ(value, 0); |
| 2576 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2577 | DCHECK(!needs_write_barrier); |
| 2578 | DCHECK(!may_need_runtime_call_for_type_check); |
| 2579 | break; |
| 2580 | } |
| 2581 | |
| 2582 | DCHECK(needs_write_barrier); |
| 2583 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2584 | GpuRegister temp1 = locations->GetTemp(0).AsRegister<GpuRegister>(); |
| 2585 | GpuRegister temp2 = TMP; // Doesn't need to survive slow path. |
| 2586 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2587 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2588 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2589 | Mips64Label done; |
| 2590 | SlowPathCodeMIPS64* slow_path = nullptr; |
| 2591 | |
| 2592 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2593 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS64(instruction); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2594 | codegen_->AddSlowPath(slow_path); |
| 2595 | if (instruction->GetValueCanBeNull()) { |
| 2596 | Mips64Label non_zero; |
| 2597 | __ Bnezc(value, &non_zero); |
| 2598 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2599 | if (index.IsConstant()) { |
| 2600 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2601 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2602 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2603 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2604 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2605 | __ Bc(&done); |
| 2606 | __ Bind(&non_zero); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2607 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2608 | |
| 2609 | // Note that when read barriers are enabled, the type checks |
| 2610 | // are performed without read barriers. This is fine, even in |
| 2611 | // the case where a class object is in the from-space after |
| 2612 | // the flip, as a comparison involving such a type would not |
| 2613 | // produce a false positive; it may of course produce a false |
| 2614 | // negative, in which case we would take the ArraySet slow |
| 2615 | // path. |
| 2616 | |
| 2617 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 2618 | __ LoadFromOffset(kLoadUnsignedWord, temp1, obj, class_offset, null_checker); |
| 2619 | __ MaybeUnpoisonHeapReference(temp1); |
| 2620 | |
| 2621 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2622 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, component_offset); |
| 2623 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2624 | __ LoadFromOffset(kLoadUnsignedWord, temp2, value, class_offset); |
| 2625 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 2626 | // nor `temp2`, as we are comparing two poisoned references. |
| 2627 | |
| 2628 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2629 | Mips64Label do_put; |
| 2630 | __ Beqc(temp1, temp2, &do_put); |
| 2631 | // If heap poisoning is enabled, the `temp1` reference has |
| 2632 | // not been unpoisoned yet; unpoison it now. |
| 2633 | __ MaybeUnpoisonHeapReference(temp1); |
| 2634 | |
| 2635 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 2636 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, super_offset); |
| 2637 | // If heap poisoning is enabled, no need to unpoison |
| 2638 | // `temp1`, as we are comparing against null below. |
| 2639 | __ Bnezc(temp1, slow_path->GetEntryLabel()); |
| 2640 | __ Bind(&do_put); |
| 2641 | } else { |
| 2642 | __ Bnec(temp1, temp2, slow_path->GetEntryLabel()); |
| 2643 | } |
| 2644 | } |
| 2645 | |
| 2646 | GpuRegister source = value; |
| 2647 | if (kPoisonHeapReferences) { |
| 2648 | // Note that in the case where `value` is a null reference, |
| 2649 | // we do not enter this block, as a null reference does not |
| 2650 | // need poisoning. |
| 2651 | __ Move(temp1, value); |
| 2652 | __ PoisonHeapReference(temp1); |
| 2653 | source = temp1; |
| 2654 | } |
| 2655 | |
| 2656 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2657 | if (index.IsConstant()) { |
| 2658 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2659 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2660 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2661 | } |
| 2662 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 2663 | |
| 2664 | if (!may_need_runtime_call_for_type_check) { |
| 2665 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2666 | } |
| 2667 | |
| 2668 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 2669 | |
| 2670 | if (done.IsLinked()) { |
| 2671 | __ Bind(&done); |
| 2672 | } |
| 2673 | |
| 2674 | if (slow_path != nullptr) { |
| 2675 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2676 | } |
| 2677 | break; |
| 2678 | } |
| 2679 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2680 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2681 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2682 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2683 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2684 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2685 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2686 | } |
| 2687 | if (value_location.IsConstant()) { |
| 2688 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2689 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2690 | } else { |
| 2691 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2692 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2693 | } |
| 2694 | break; |
| 2695 | } |
| 2696 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2697 | case DataType::Type::kFloat32: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2698 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2699 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2700 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2701 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2702 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2703 | } |
| 2704 | if (value_location.IsConstant()) { |
| 2705 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2706 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2707 | } else { |
| 2708 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2709 | __ StoreFpuToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2710 | } |
| 2711 | break; |
| 2712 | } |
| 2713 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2714 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2715 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2716 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2717 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2718 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2719 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2720 | } |
| 2721 | if (value_location.IsConstant()) { |
| 2722 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2723 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2724 | } else { |
| 2725 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2726 | __ StoreFpuToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2727 | } |
| 2728 | break; |
| 2729 | } |
| 2730 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2731 | case DataType::Type::kUint32: |
| 2732 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2733 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2734 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2735 | UNREACHABLE(); |
| 2736 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2740 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2741 | InvokeRuntimeCallingConvention calling_convention; |
| 2742 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2743 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2744 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2745 | |
| 2746 | HInstruction* index = instruction->InputAt(0); |
| 2747 | HInstruction* length = instruction->InputAt(1); |
| 2748 | |
| 2749 | bool const_index = false; |
| 2750 | bool const_length = false; |
| 2751 | |
| 2752 | if (index->IsConstant()) { |
| 2753 | if (length->IsConstant()) { |
| 2754 | const_index = true; |
| 2755 | const_length = true; |
| 2756 | } else { |
| 2757 | int32_t index_value = index->AsIntConstant()->GetValue(); |
| 2758 | if (index_value < 0 || IsInt<16>(index_value + 1)) { |
| 2759 | const_index = true; |
| 2760 | } |
| 2761 | } |
| 2762 | } else if (length->IsConstant()) { |
| 2763 | int32_t length_value = length->AsIntConstant()->GetValue(); |
| 2764 | if (IsUint<15>(length_value)) { |
| 2765 | const_length = true; |
| 2766 | } |
| 2767 | } |
| 2768 | |
| 2769 | locations->SetInAt(0, const_index |
| 2770 | ? Location::ConstantLocation(index->AsConstant()) |
| 2771 | : Location::RequiresRegister()); |
| 2772 | locations->SetInAt(1, const_length |
| 2773 | ? Location::ConstantLocation(length->AsConstant()) |
| 2774 | : Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2775 | } |
| 2776 | |
| 2777 | void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2778 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2779 | Location index_loc = locations->InAt(0); |
| 2780 | Location length_loc = locations->InAt(1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2781 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2782 | if (length_loc.IsConstant()) { |
| 2783 | int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 2784 | if (index_loc.IsConstant()) { |
| 2785 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 2786 | if (index < 0 || index >= length) { |
| 2787 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2788 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction); |
| 2789 | codegen_->AddSlowPath(slow_path); |
| 2790 | __ Bc(slow_path->GetEntryLabel()); |
| 2791 | } else { |
| 2792 | // Nothing to be done. |
| 2793 | } |
| 2794 | return; |
| 2795 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2796 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2797 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2798 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction); |
| 2799 | codegen_->AddSlowPath(slow_path); |
| 2800 | GpuRegister index = index_loc.AsRegister<GpuRegister>(); |
| 2801 | if (length == 0) { |
| 2802 | __ Bc(slow_path->GetEntryLabel()); |
| 2803 | } else if (length == 1) { |
| 2804 | __ Bnezc(index, slow_path->GetEntryLabel()); |
| 2805 | } else { |
| 2806 | DCHECK(IsUint<15>(length)) << length; |
| 2807 | __ Sltiu(TMP, index, length); |
| 2808 | __ Beqzc(TMP, slow_path->GetEntryLabel()); |
| 2809 | } |
| 2810 | } else { |
| 2811 | GpuRegister length = length_loc.AsRegister<GpuRegister>(); |
| 2812 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2813 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction); |
| 2814 | codegen_->AddSlowPath(slow_path); |
| 2815 | if (index_loc.IsConstant()) { |
| 2816 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 2817 | if (index < 0) { |
| 2818 | __ Bc(slow_path->GetEntryLabel()); |
| 2819 | } else if (index == 0) { |
| 2820 | __ Blezc(length, slow_path->GetEntryLabel()); |
| 2821 | } else { |
| 2822 | DCHECK(IsInt<16>(index + 1)) << index; |
| 2823 | __ Sltiu(TMP, length, index + 1); |
| 2824 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 2825 | } |
| 2826 | } else { |
| 2827 | GpuRegister index = index_loc.AsRegister<GpuRegister>(); |
| 2828 | __ Bgeuc(index, length, slow_path->GetEntryLabel()); |
| 2829 | } |
| 2830 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2833 | // Temp is used for read barrier. |
| 2834 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 2835 | if (kEmitCompilerReadBarrier && |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2836 | !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) && |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2837 | (kUseBakerReadBarrier || |
| 2838 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2839 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2840 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 2841 | return 1; |
| 2842 | } |
| 2843 | return 0; |
| 2844 | } |
| 2845 | |
| 2846 | // Extra temp is used for read barrier. |
| 2847 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 2848 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 2849 | } |
| 2850 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2851 | void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2852 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 2853 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2854 | LocationSummary* locations = |
| 2855 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2856 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 2857 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2858 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2862 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2863 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2864 | Location obj_loc = locations->InAt(0); |
| 2865 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 2866 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2867 | Location temp_loc = locations->GetTemp(0); |
| 2868 | GpuRegister temp = temp_loc.AsRegister<GpuRegister>(); |
| 2869 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 2870 | DCHECK_LE(num_temps, 2u); |
| 2871 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2872 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2873 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2874 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2875 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 2876 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 2877 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 2878 | const uint32_t object_array_data_offset = |
| 2879 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 2880 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2881 | |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 2882 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2883 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2884 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( |
| 2885 | instruction, is_type_check_slow_path_fatal); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2886 | codegen_->AddSlowPath(slow_path); |
| 2887 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2888 | // Avoid this check if we know `obj` is not null. |
| 2889 | if (instruction->MustDoNullCheck()) { |
| 2890 | __ Beqzc(obj, &done); |
| 2891 | } |
| 2892 | |
| 2893 | switch (type_check_kind) { |
| 2894 | case TypeCheckKind::kExactCheck: |
| 2895 | case TypeCheckKind::kArrayCheck: { |
| 2896 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2897 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2898 | temp_loc, |
| 2899 | obj_loc, |
| 2900 | class_offset, |
| 2901 | maybe_temp2_loc, |
| 2902 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2903 | // Jump to slow path for throwing the exception or doing a |
| 2904 | // more involved array check. |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 2905 | __ Bnec(temp, cls, slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2906 | break; |
| 2907 | } |
| 2908 | |
| 2909 | case TypeCheckKind::kAbstractClassCheck: { |
| 2910 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2911 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2912 | temp_loc, |
| 2913 | obj_loc, |
| 2914 | class_offset, |
| 2915 | maybe_temp2_loc, |
| 2916 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2917 | // If the class is abstract, we eagerly fetch the super class of the |
| 2918 | // object to avoid doing a comparison we know will fail. |
| 2919 | Mips64Label loop; |
| 2920 | __ Bind(&loop); |
| 2921 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2922 | GenerateReferenceLoadOneRegister(instruction, |
| 2923 | temp_loc, |
| 2924 | super_offset, |
| 2925 | maybe_temp2_loc, |
| 2926 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2927 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2928 | // exception. |
| 2929 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2930 | // Otherwise, compare the classes. |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 2931 | __ Bnec(temp, cls, &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2932 | break; |
| 2933 | } |
| 2934 | |
| 2935 | case TypeCheckKind::kClassHierarchyCheck: { |
| 2936 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2937 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2938 | temp_loc, |
| 2939 | obj_loc, |
| 2940 | class_offset, |
| 2941 | maybe_temp2_loc, |
| 2942 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2943 | // Walk over the class hierarchy to find a match. |
| 2944 | Mips64Label loop; |
| 2945 | __ Bind(&loop); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 2946 | __ Beqc(temp, cls, &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2947 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2948 | GenerateReferenceLoadOneRegister(instruction, |
| 2949 | temp_loc, |
| 2950 | super_offset, |
| 2951 | maybe_temp2_loc, |
| 2952 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2953 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2954 | // exception. Otherwise, jump to the beginning of the loop. |
| 2955 | __ Bnezc(temp, &loop); |
| 2956 | __ Bc(slow_path->GetEntryLabel()); |
| 2957 | break; |
| 2958 | } |
| 2959 | |
| 2960 | case TypeCheckKind::kArrayObjectCheck: { |
| 2961 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2962 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2963 | temp_loc, |
| 2964 | obj_loc, |
| 2965 | class_offset, |
| 2966 | maybe_temp2_loc, |
| 2967 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2968 | // Do an exact check. |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 2969 | __ Beqc(temp, cls, &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2970 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 2971 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2972 | GenerateReferenceLoadOneRegister(instruction, |
| 2973 | temp_loc, |
| 2974 | component_offset, |
| 2975 | maybe_temp2_loc, |
| 2976 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2977 | // If the component type is null, jump to the slow path to throw the exception. |
| 2978 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2979 | // Otherwise, the object is indeed an array, further check that this component |
| 2980 | // type is not a primitive type. |
| 2981 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 2982 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 2983 | __ Bnezc(temp, slow_path->GetEntryLabel()); |
| 2984 | break; |
| 2985 | } |
| 2986 | |
| 2987 | case TypeCheckKind::kUnresolvedCheck: |
| 2988 | // We always go into the type check slow path for the unresolved check case. |
| 2989 | // We cannot directly call the CheckCast runtime entry point |
| 2990 | // without resorting to a type checking slow path here (i.e. by |
| 2991 | // calling InvokeRuntime directly), as it would require to |
| 2992 | // assign fixed registers for the inputs of this HInstanceOf |
| 2993 | // instruction (following the runtime calling convention), which |
| 2994 | // might be cluttered by the potential first read barrier |
| 2995 | // emission at the beginning of this method. |
| 2996 | __ Bc(slow_path->GetEntryLabel()); |
| 2997 | break; |
| 2998 | |
| 2999 | case TypeCheckKind::kInterfaceCheck: { |
| 3000 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 3001 | // positives by doing this. |
| 3002 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3003 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3004 | temp_loc, |
| 3005 | obj_loc, |
| 3006 | class_offset, |
| 3007 | maybe_temp2_loc, |
| 3008 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3009 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3010 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3011 | temp_loc, |
| 3012 | temp_loc, |
| 3013 | iftable_offset, |
| 3014 | maybe_temp2_loc, |
| 3015 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3016 | // Iftable is never null. |
| 3017 | __ Lw(TMP, temp, array_length_offset); |
| 3018 | // Loop through the iftable and check if any class matches. |
| 3019 | Mips64Label loop; |
| 3020 | __ Bind(&loop); |
| 3021 | __ Beqzc(TMP, slow_path->GetEntryLabel()); |
| 3022 | __ Lwu(AT, temp, object_array_data_offset); |
| 3023 | __ MaybeUnpoisonHeapReference(AT); |
| 3024 | // Go to next interface. |
| 3025 | __ Daddiu(temp, temp, 2 * kHeapReferenceSize); |
| 3026 | __ Addiu(TMP, TMP, -2); |
| 3027 | // Compare the classes and continue the loop if they do not match. |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 3028 | __ Bnec(AT, cls, &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3029 | break; |
| 3030 | } |
| 3031 | } |
| 3032 | |
| 3033 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3034 | __ Bind(slow_path->GetExitLabel()); |
| 3035 | } |
| 3036 | |
| 3037 | void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 3038 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3039 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3040 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3041 | if (check->HasUses()) { |
| 3042 | locations->SetOut(Location::SameAsFirstInput()); |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 3047 | // We assume the class is not null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3048 | SlowPathCodeMIPS64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64( |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3049 | check->GetLoadClass(), |
| 3050 | check, |
| 3051 | check->GetDexPc(), |
| 3052 | true); |
| 3053 | codegen_->AddSlowPath(slow_path); |
| 3054 | GenerateClassInitializationCheck(slow_path, |
| 3055 | check->GetLocations()->InAt(0).AsRegister<GpuRegister>()); |
| 3056 | } |
| 3057 | |
| 3058 | void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3059 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3060 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3061 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(compare); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3062 | |
| 3063 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3064 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3065 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3066 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3067 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3068 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3069 | case DataType::Type::kInt32: |
| 3070 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3071 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3072 | locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3073 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3074 | break; |
| 3075 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3076 | case DataType::Type::kFloat32: |
| 3077 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3078 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3079 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3080 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3081 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3082 | |
| 3083 | default: |
| 3084 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3085 | } |
| 3086 | } |
| 3087 | |
| 3088 | void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) { |
| 3089 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3090 | GpuRegister res = locations->Out().AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3091 | DataType::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3092 | |
| 3093 | // 0 if: left == right |
| 3094 | // 1 if: left > right |
| 3095 | // -1 if: left < right |
| 3096 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3097 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3098 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3099 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3100 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3101 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3102 | case DataType::Type::kInt32: |
| 3103 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3104 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3105 | Location rhs_location = locations->InAt(1); |
| 3106 | bool use_imm = rhs_location.IsConstant(); |
| 3107 | GpuRegister rhs = ZERO; |
| 3108 | if (use_imm) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3109 | if (in_type == DataType::Type::kInt64) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3110 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 3111 | if (value != 0) { |
| 3112 | rhs = AT; |
| 3113 | __ LoadConst64(rhs, value); |
| 3114 | } |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3115 | } else { |
| 3116 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 3117 | if (value != 0) { |
| 3118 | rhs = AT; |
| 3119 | __ LoadConst32(rhs, value); |
| 3120 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3121 | } |
| 3122 | } else { |
| 3123 | rhs = rhs_location.AsRegister<GpuRegister>(); |
| 3124 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3125 | __ Slt(TMP, lhs, rhs); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3126 | __ Slt(res, rhs, lhs); |
| 3127 | __ Subu(res, res, TMP); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3128 | break; |
| 3129 | } |
| 3130 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3131 | case DataType::Type::kFloat32: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3132 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3133 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3134 | Mips64Label done; |
| 3135 | __ CmpEqS(FTMP, lhs, rhs); |
| 3136 | __ LoadConst32(res, 0); |
| 3137 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3138 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3139 | __ CmpLtS(FTMP, lhs, rhs); |
| 3140 | __ LoadConst32(res, -1); |
| 3141 | __ Bc1nez(FTMP, &done); |
| 3142 | __ LoadConst32(res, 1); |
| 3143 | } else { |
| 3144 | __ CmpLtS(FTMP, rhs, lhs); |
| 3145 | __ LoadConst32(res, 1); |
| 3146 | __ Bc1nez(FTMP, &done); |
| 3147 | __ LoadConst32(res, -1); |
| 3148 | } |
| 3149 | __ Bind(&done); |
| 3150 | break; |
| 3151 | } |
| 3152 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3153 | case DataType::Type::kFloat64: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3154 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3155 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3156 | Mips64Label done; |
| 3157 | __ CmpEqD(FTMP, lhs, rhs); |
| 3158 | __ LoadConst32(res, 0); |
| 3159 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3160 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3161 | __ CmpLtD(FTMP, lhs, rhs); |
| 3162 | __ LoadConst32(res, -1); |
| 3163 | __ Bc1nez(FTMP, &done); |
| 3164 | __ LoadConst32(res, 1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3165 | } else { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3166 | __ CmpLtD(FTMP, rhs, lhs); |
| 3167 | __ LoadConst32(res, 1); |
| 3168 | __ Bc1nez(FTMP, &done); |
| 3169 | __ LoadConst32(res, -1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3170 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3171 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3172 | break; |
| 3173 | } |
| 3174 | |
| 3175 | default: |
| 3176 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3177 | } |
| 3178 | } |
| 3179 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3180 | void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3181 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3182 | switch (instruction->InputAt(0)->GetType()) { |
| 3183 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3184 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3185 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3186 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3187 | break; |
| 3188 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3189 | case DataType::Type::kFloat32: |
| 3190 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3191 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3192 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3193 | break; |
| 3194 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3195 | if (!instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3196 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3197 | } |
| 3198 | } |
| 3199 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3200 | void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3201 | if (instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3202 | return; |
| 3203 | } |
| 3204 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3205 | DataType::Type type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3206 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3207 | switch (type) { |
| 3208 | default: |
| 3209 | // Integer case. |
| 3210 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations); |
| 3211 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3212 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3213 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations); |
| 3214 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3215 | case DataType::Type::kFloat32: |
| 3216 | case DataType::Type::kFloat64: |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3217 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 3218 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3219 | } |
| 3220 | } |
| 3221 | |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3222 | void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3223 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3224 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3225 | |
| 3226 | LocationSummary* locations = instruction->GetLocations(); |
| 3227 | Location second = locations->InAt(1); |
| 3228 | DCHECK(second.IsConstant()); |
| 3229 | |
| 3230 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3231 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3232 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3233 | DCHECK(imm == 1 || imm == -1); |
| 3234 | |
| 3235 | if (instruction->IsRem()) { |
| 3236 | __ Move(out, ZERO); |
| 3237 | } else { |
| 3238 | if (imm == -1) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3239 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3240 | __ Subu(out, ZERO, dividend); |
| 3241 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3242 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3243 | __ Dsubu(out, ZERO, dividend); |
| 3244 | } |
| 3245 | } else if (out != dividend) { |
| 3246 | __ Move(out, dividend); |
| 3247 | } |
| 3248 | } |
| 3249 | } |
| 3250 | |
| 3251 | void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3252 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3253 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3254 | |
| 3255 | LocationSummary* locations = instruction->GetLocations(); |
| 3256 | Location second = locations->InAt(1); |
| 3257 | DCHECK(second.IsConstant()); |
| 3258 | |
| 3259 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3260 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3261 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3262 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3263 | int ctz_imm = CTZ(abs_imm); |
| 3264 | |
| 3265 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3266 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3267 | if (ctz_imm == 1) { |
| 3268 | // Fast path for division by +/-2, which is very common. |
| 3269 | __ Srl(TMP, dividend, 31); |
| 3270 | } else { |
| 3271 | __ Sra(TMP, dividend, 31); |
| 3272 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3273 | } |
| 3274 | __ Addu(out, dividend, TMP); |
| 3275 | __ Sra(out, out, ctz_imm); |
| 3276 | if (imm < 0) { |
| 3277 | __ Subu(out, ZERO, out); |
| 3278 | } |
| 3279 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3280 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3281 | if (ctz_imm == 1) { |
| 3282 | // Fast path for division by +/-2, which is very common. |
| 3283 | __ Dsrl32(TMP, dividend, 31); |
| 3284 | } else { |
| 3285 | __ Dsra32(TMP, dividend, 31); |
| 3286 | if (ctz_imm > 32) { |
| 3287 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3288 | } else { |
| 3289 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3290 | } |
| 3291 | } |
| 3292 | __ Daddu(out, dividend, TMP); |
| 3293 | if (ctz_imm < 32) { |
| 3294 | __ Dsra(out, out, ctz_imm); |
| 3295 | } else { |
| 3296 | __ Dsra32(out, out, ctz_imm - 32); |
| 3297 | } |
| 3298 | if (imm < 0) { |
| 3299 | __ Dsubu(out, ZERO, out); |
| 3300 | } |
| 3301 | } |
| 3302 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3303 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3304 | if (ctz_imm == 1) { |
| 3305 | // Fast path for modulo +/-2, which is very common. |
| 3306 | __ Sra(TMP, dividend, 31); |
| 3307 | __ Subu(out, dividend, TMP); |
| 3308 | __ Andi(out, out, 1); |
| 3309 | __ Addu(out, out, TMP); |
| 3310 | } else { |
| 3311 | __ Sra(TMP, dividend, 31); |
| 3312 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3313 | __ Addu(out, dividend, TMP); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3314 | __ Ins(out, ZERO, ctz_imm, 32 - ctz_imm); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3315 | __ Subu(out, out, TMP); |
| 3316 | } |
| 3317 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3318 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3319 | if (ctz_imm == 1) { |
| 3320 | // Fast path for modulo +/-2, which is very common. |
| 3321 | __ Dsra32(TMP, dividend, 31); |
| 3322 | __ Dsubu(out, dividend, TMP); |
| 3323 | __ Andi(out, out, 1); |
| 3324 | __ Daddu(out, out, TMP); |
| 3325 | } else { |
| 3326 | __ Dsra32(TMP, dividend, 31); |
| 3327 | if (ctz_imm > 32) { |
| 3328 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3329 | } else { |
| 3330 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3331 | } |
| 3332 | __ Daddu(out, dividend, TMP); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3333 | __ DblIns(out, ZERO, ctz_imm, 64 - ctz_imm); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3334 | __ Dsubu(out, out, TMP); |
| 3335 | } |
| 3336 | } |
| 3337 | } |
| 3338 | } |
| 3339 | |
| 3340 | void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3341 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3342 | |
| 3343 | LocationSummary* locations = instruction->GetLocations(); |
| 3344 | Location second = locations->InAt(1); |
| 3345 | DCHECK(second.IsConstant()); |
| 3346 | |
| 3347 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3348 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3349 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3350 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3351 | DataType::Type type = instruction->GetResultType(); |
| 3352 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type; |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3353 | |
| 3354 | int64_t magic; |
| 3355 | int shift; |
| 3356 | CalculateMagicAndShiftForDivRem(imm, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3357 | (type == DataType::Type::kInt64), |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3358 | &magic, |
| 3359 | &shift); |
| 3360 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3361 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3362 | __ LoadConst32(TMP, magic); |
| 3363 | __ MuhR6(TMP, dividend, TMP); |
| 3364 | |
| 3365 | if (imm > 0 && magic < 0) { |
| 3366 | __ Addu(TMP, TMP, dividend); |
| 3367 | } else if (imm < 0 && magic > 0) { |
| 3368 | __ Subu(TMP, TMP, dividend); |
| 3369 | } |
| 3370 | |
| 3371 | if (shift != 0) { |
| 3372 | __ Sra(TMP, TMP, shift); |
| 3373 | } |
| 3374 | |
| 3375 | if (instruction->IsDiv()) { |
| 3376 | __ Sra(out, TMP, 31); |
| 3377 | __ Subu(out, TMP, out); |
| 3378 | } else { |
| 3379 | __ Sra(AT, TMP, 31); |
| 3380 | __ Subu(AT, TMP, AT); |
| 3381 | __ LoadConst32(TMP, imm); |
| 3382 | __ MulR6(TMP, AT, TMP); |
| 3383 | __ Subu(out, dividend, TMP); |
| 3384 | } |
| 3385 | } else { |
| 3386 | __ LoadConst64(TMP, magic); |
| 3387 | __ Dmuh(TMP, dividend, TMP); |
| 3388 | |
| 3389 | if (imm > 0 && magic < 0) { |
| 3390 | __ Daddu(TMP, TMP, dividend); |
| 3391 | } else if (imm < 0 && magic > 0) { |
| 3392 | __ Dsubu(TMP, TMP, dividend); |
| 3393 | } |
| 3394 | |
| 3395 | if (shift >= 32) { |
| 3396 | __ Dsra32(TMP, TMP, shift - 32); |
| 3397 | } else if (shift > 0) { |
| 3398 | __ Dsra(TMP, TMP, shift); |
| 3399 | } |
| 3400 | |
| 3401 | if (instruction->IsDiv()) { |
| 3402 | __ Dsra32(out, TMP, 31); |
| 3403 | __ Dsubu(out, TMP, out); |
| 3404 | } else { |
| 3405 | __ Dsra32(AT, TMP, 31); |
| 3406 | __ Dsubu(AT, TMP, AT); |
| 3407 | __ LoadConst64(TMP, imm); |
| 3408 | __ Dmul(TMP, AT, TMP); |
| 3409 | __ Dsubu(out, dividend, TMP); |
| 3410 | } |
| 3411 | } |
| 3412 | } |
| 3413 | |
| 3414 | void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3415 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3416 | DataType::Type type = instruction->GetResultType(); |
| 3417 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type; |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3418 | |
| 3419 | LocationSummary* locations = instruction->GetLocations(); |
| 3420 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3421 | Location second = locations->InAt(1); |
| 3422 | |
| 3423 | if (second.IsConstant()) { |
| 3424 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3425 | if (imm == 0) { |
| 3426 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3427 | } else if (imm == 1 || imm == -1) { |
| 3428 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3429 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3430 | DivRemByPowerOfTwo(instruction); |
| 3431 | } else { |
| 3432 | DCHECK(imm <= -2 || imm >= 2); |
| 3433 | GenerateDivRemWithAnyConstant(instruction); |
| 3434 | } |
| 3435 | } else { |
| 3436 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3437 | GpuRegister divisor = second.AsRegister<GpuRegister>(); |
| 3438 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3439 | if (type == DataType::Type::kInt32) |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3440 | __ DivR6(out, dividend, divisor); |
| 3441 | else |
| 3442 | __ Ddiv(out, dividend, divisor); |
| 3443 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3444 | if (type == DataType::Type::kInt32) |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3445 | __ ModR6(out, dividend, divisor); |
| 3446 | else |
| 3447 | __ Dmod(out, dividend, divisor); |
| 3448 | } |
| 3449 | } |
| 3450 | } |
| 3451 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3452 | void LocationsBuilderMIPS64::VisitDiv(HDiv* div) { |
| 3453 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3454 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3455 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3456 | case DataType::Type::kInt32: |
| 3457 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3458 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3459 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3460 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3461 | break; |
| 3462 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3463 | case DataType::Type::kFloat32: |
| 3464 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3465 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3466 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3467 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3468 | break; |
| 3469 | |
| 3470 | default: |
| 3471 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3472 | } |
| 3473 | } |
| 3474 | |
| 3475 | void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3476 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3477 | LocationSummary* locations = instruction->GetLocations(); |
| 3478 | |
| 3479 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3480 | case DataType::Type::kInt32: |
| 3481 | case DataType::Type::kInt64: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3482 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3483 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3484 | case DataType::Type::kFloat32: |
| 3485 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3486 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 3487 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3488 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3489 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3490 | __ DivS(dst, lhs, rhs); |
| 3491 | else |
| 3492 | __ DivD(dst, lhs, rhs); |
| 3493 | break; |
| 3494 | } |
| 3495 | default: |
| 3496 | LOG(FATAL) << "Unexpected div type " << type; |
| 3497 | } |
| 3498 | } |
| 3499 | |
| 3500 | void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3501 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3502 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3506 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3507 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS64(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3508 | codegen_->AddSlowPath(slow_path); |
| 3509 | Location value = instruction->GetLocations()->InAt(0); |
| 3510 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3511 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3512 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3513 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3514 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3515 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | if (value.IsConstant()) { |
| 3519 | int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant()); |
| 3520 | if (divisor == 0) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3521 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3522 | } else { |
| 3523 | // A division by a non-null constant is valid. We don't need to perform |
| 3524 | // any check, so simply fall through. |
| 3525 | } |
| 3526 | } else { |
| 3527 | __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 3528 | } |
| 3529 | } |
| 3530 | |
| 3531 | void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3532 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3533 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3534 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3535 | } |
| 3536 | |
| 3537 | void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 3538 | // Will be generated at use site. |
| 3539 | } |
| 3540 | |
| 3541 | void LocationsBuilderMIPS64::VisitExit(HExit* exit) { |
| 3542 | exit->SetLocations(nullptr); |
| 3543 | } |
| 3544 | |
| 3545 | void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 3546 | } |
| 3547 | |
| 3548 | void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) { |
| 3549 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3550 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3551 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3552 | } |
| 3553 | |
| 3554 | void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 3555 | // Will be generated at use site. |
| 3556 | } |
| 3557 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3558 | void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3559 | if (successor->IsExitBlock()) { |
| 3560 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3561 | return; // no code needed |
| 3562 | } |
| 3563 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3564 | HBasicBlock* block = got->GetBlock(); |
| 3565 | HInstruction* previous = got->GetPrevious(); |
| 3566 | HLoopInformation* info = block->GetLoopInformation(); |
| 3567 | |
| 3568 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Goran Jakovljevic | feec167 | 2018-02-08 10:20:14 +0100 | [diff] [blame] | 3569 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 3570 | __ Ld(AT, SP, kCurrentMethodStackOffset); |
| 3571 | __ Lhu(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value()); |
| 3572 | __ Addiu(TMP, TMP, 1); |
| 3573 | __ Sh(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value()); |
| 3574 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3575 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3576 | return; |
| 3577 | } |
| 3578 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3579 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3580 | } |
| 3581 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3582 | __ Bc(codegen_->GetLabelOf(successor)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3583 | } |
| 3584 | } |
| 3585 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3586 | void LocationsBuilderMIPS64::VisitGoto(HGoto* got) { |
| 3587 | got->SetLocations(nullptr); |
| 3588 | } |
| 3589 | |
| 3590 | void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) { |
| 3591 | HandleGoto(got, got->GetSuccessor()); |
| 3592 | } |
| 3593 | |
| 3594 | void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3595 | try_boundary->SetLocations(nullptr); |
| 3596 | } |
| 3597 | |
| 3598 | void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3599 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3600 | if (!successor->IsExitBlock()) { |
| 3601 | HandleGoto(try_boundary, successor); |
| 3602 | } |
| 3603 | } |
| 3604 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3605 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond, |
| 3606 | bool is64bit, |
| 3607 | LocationSummary* locations) { |
| 3608 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3609 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3610 | Location rhs_location = locations->InAt(1); |
| 3611 | GpuRegister rhs_reg = ZERO; |
| 3612 | int64_t rhs_imm = 0; |
| 3613 | bool use_imm = rhs_location.IsConstant(); |
| 3614 | if (use_imm) { |
| 3615 | if (is64bit) { |
| 3616 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3617 | } else { |
| 3618 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3619 | } |
| 3620 | } else { |
| 3621 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3622 | } |
| 3623 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 3624 | |
| 3625 | switch (cond) { |
| 3626 | case kCondEQ: |
| 3627 | case kCondNE: |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3628 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3629 | if (rhs_imm == 0) { |
| 3630 | if (cond == kCondEQ) { |
| 3631 | __ Sltiu(dst, lhs, 1); |
| 3632 | } else { |
| 3633 | __ Sltu(dst, ZERO, lhs); |
| 3634 | } |
| 3635 | } else { |
| 3636 | if (is64bit) { |
| 3637 | __ Daddiu(dst, lhs, -rhs_imm); |
| 3638 | } else { |
| 3639 | __ Addiu(dst, lhs, -rhs_imm); |
| 3640 | } |
| 3641 | if (cond == kCondEQ) { |
| 3642 | __ Sltiu(dst, dst, 1); |
| 3643 | } else { |
| 3644 | __ Sltu(dst, ZERO, dst); |
| 3645 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3646 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3647 | } else { |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3648 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 3649 | __ Xori(dst, lhs, rhs_imm); |
| 3650 | } else { |
| 3651 | if (use_imm) { |
| 3652 | rhs_reg = TMP; |
| 3653 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3654 | } |
| 3655 | __ Xor(dst, lhs, rhs_reg); |
| 3656 | } |
| 3657 | if (cond == kCondEQ) { |
| 3658 | __ Sltiu(dst, dst, 1); |
| 3659 | } else { |
| 3660 | __ Sltu(dst, ZERO, dst); |
| 3661 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3662 | } |
| 3663 | break; |
| 3664 | |
| 3665 | case kCondLT: |
| 3666 | case kCondGE: |
| 3667 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3668 | __ Slti(dst, lhs, rhs_imm); |
| 3669 | } else { |
| 3670 | if (use_imm) { |
| 3671 | rhs_reg = TMP; |
| 3672 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3673 | } |
| 3674 | __ Slt(dst, lhs, rhs_reg); |
| 3675 | } |
| 3676 | if (cond == kCondGE) { |
| 3677 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3678 | // only the slt instruction but no sge. |
| 3679 | __ Xori(dst, dst, 1); |
| 3680 | } |
| 3681 | break; |
| 3682 | |
| 3683 | case kCondLE: |
| 3684 | case kCondGT: |
| 3685 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 3686 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3687 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 3688 | if (cond == kCondGT) { |
| 3689 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3690 | // only the slti instruction but no sgti. |
| 3691 | __ Xori(dst, dst, 1); |
| 3692 | } |
| 3693 | } else { |
| 3694 | if (use_imm) { |
| 3695 | rhs_reg = TMP; |
| 3696 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3697 | } |
| 3698 | __ Slt(dst, rhs_reg, lhs); |
| 3699 | if (cond == kCondLE) { |
| 3700 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3701 | // only the slt instruction but no sle. |
| 3702 | __ Xori(dst, dst, 1); |
| 3703 | } |
| 3704 | } |
| 3705 | break; |
| 3706 | |
| 3707 | case kCondB: |
| 3708 | case kCondAE: |
| 3709 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3710 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3711 | // the comparison and thus lets us compare directly with |
| 3712 | // unsigned values in the ranges [0, 0x7fff] and |
| 3713 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3714 | __ Sltiu(dst, lhs, rhs_imm); |
| 3715 | } else { |
| 3716 | if (use_imm) { |
| 3717 | rhs_reg = TMP; |
| 3718 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3719 | } |
| 3720 | __ Sltu(dst, lhs, rhs_reg); |
| 3721 | } |
| 3722 | if (cond == kCondAE) { |
| 3723 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3724 | // only the sltu instruction but no sgeu. |
| 3725 | __ Xori(dst, dst, 1); |
| 3726 | } |
| 3727 | break; |
| 3728 | |
| 3729 | case kCondBE: |
| 3730 | case kCondA: |
| 3731 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 3732 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3733 | // Note that this only works if rhs + 1 does not overflow |
| 3734 | // to 0, hence the check above. |
| 3735 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3736 | // the comparison and thus lets us compare directly with |
| 3737 | // unsigned values in the ranges [0, 0x7fff] and |
| 3738 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3739 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 3740 | if (cond == kCondA) { |
| 3741 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3742 | // only the sltiu instruction but no sgtiu. |
| 3743 | __ Xori(dst, dst, 1); |
| 3744 | } |
| 3745 | } else { |
| 3746 | if (use_imm) { |
| 3747 | rhs_reg = TMP; |
| 3748 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3749 | } |
| 3750 | __ Sltu(dst, rhs_reg, lhs); |
| 3751 | if (cond == kCondBE) { |
| 3752 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3753 | // only the sltu instruction but no sleu. |
| 3754 | __ Xori(dst, dst, 1); |
| 3755 | } |
| 3756 | } |
| 3757 | break; |
| 3758 | } |
| 3759 | } |
| 3760 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 3761 | bool InstructionCodeGeneratorMIPS64::MaterializeIntLongCompare(IfCondition cond, |
| 3762 | bool is64bit, |
| 3763 | LocationSummary* input_locations, |
| 3764 | GpuRegister dst) { |
| 3765 | GpuRegister lhs = input_locations->InAt(0).AsRegister<GpuRegister>(); |
| 3766 | Location rhs_location = input_locations->InAt(1); |
| 3767 | GpuRegister rhs_reg = ZERO; |
| 3768 | int64_t rhs_imm = 0; |
| 3769 | bool use_imm = rhs_location.IsConstant(); |
| 3770 | if (use_imm) { |
| 3771 | if (is64bit) { |
| 3772 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3773 | } else { |
| 3774 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3775 | } |
| 3776 | } else { |
| 3777 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3778 | } |
| 3779 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 3780 | |
| 3781 | switch (cond) { |
| 3782 | case kCondEQ: |
| 3783 | case kCondNE: |
| 3784 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3785 | if (is64bit) { |
| 3786 | __ Daddiu(dst, lhs, -rhs_imm); |
| 3787 | } else { |
| 3788 | __ Addiu(dst, lhs, -rhs_imm); |
| 3789 | } |
| 3790 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 3791 | __ Xori(dst, lhs, rhs_imm); |
| 3792 | } else { |
| 3793 | if (use_imm) { |
| 3794 | rhs_reg = TMP; |
| 3795 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3796 | } |
| 3797 | __ Xor(dst, lhs, rhs_reg); |
| 3798 | } |
| 3799 | return (cond == kCondEQ); |
| 3800 | |
| 3801 | case kCondLT: |
| 3802 | case kCondGE: |
| 3803 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3804 | __ Slti(dst, lhs, rhs_imm); |
| 3805 | } else { |
| 3806 | if (use_imm) { |
| 3807 | rhs_reg = TMP; |
| 3808 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3809 | } |
| 3810 | __ Slt(dst, lhs, rhs_reg); |
| 3811 | } |
| 3812 | return (cond == kCondGE); |
| 3813 | |
| 3814 | case kCondLE: |
| 3815 | case kCondGT: |
| 3816 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 3817 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3818 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 3819 | return (cond == kCondGT); |
| 3820 | } else { |
| 3821 | if (use_imm) { |
| 3822 | rhs_reg = TMP; |
| 3823 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3824 | } |
| 3825 | __ Slt(dst, rhs_reg, lhs); |
| 3826 | return (cond == kCondLE); |
| 3827 | } |
| 3828 | |
| 3829 | case kCondB: |
| 3830 | case kCondAE: |
| 3831 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3832 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3833 | // the comparison and thus lets us compare directly with |
| 3834 | // unsigned values in the ranges [0, 0x7fff] and |
| 3835 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3836 | __ Sltiu(dst, lhs, rhs_imm); |
| 3837 | } else { |
| 3838 | if (use_imm) { |
| 3839 | rhs_reg = TMP; |
| 3840 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3841 | } |
| 3842 | __ Sltu(dst, lhs, rhs_reg); |
| 3843 | } |
| 3844 | return (cond == kCondAE); |
| 3845 | |
| 3846 | case kCondBE: |
| 3847 | case kCondA: |
| 3848 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 3849 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3850 | // Note that this only works if rhs + 1 does not overflow |
| 3851 | // to 0, hence the check above. |
| 3852 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3853 | // the comparison and thus lets us compare directly with |
| 3854 | // unsigned values in the ranges [0, 0x7fff] and |
| 3855 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3856 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 3857 | return (cond == kCondA); |
| 3858 | } else { |
| 3859 | if (use_imm) { |
| 3860 | rhs_reg = TMP; |
| 3861 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3862 | } |
| 3863 | __ Sltu(dst, rhs_reg, lhs); |
| 3864 | return (cond == kCondBE); |
| 3865 | } |
| 3866 | } |
| 3867 | } |
| 3868 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3869 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond, |
| 3870 | bool is64bit, |
| 3871 | LocationSummary* locations, |
| 3872 | Mips64Label* label) { |
| 3873 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3874 | Location rhs_location = locations->InAt(1); |
| 3875 | GpuRegister rhs_reg = ZERO; |
| 3876 | int64_t rhs_imm = 0; |
| 3877 | bool use_imm = rhs_location.IsConstant(); |
| 3878 | if (use_imm) { |
| 3879 | if (is64bit) { |
| 3880 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3881 | } else { |
| 3882 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3883 | } |
| 3884 | } else { |
| 3885 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3886 | } |
| 3887 | |
| 3888 | if (use_imm && rhs_imm == 0) { |
| 3889 | switch (cond) { |
| 3890 | case kCondEQ: |
| 3891 | case kCondBE: // <= 0 if zero |
| 3892 | __ Beqzc(lhs, label); |
| 3893 | break; |
| 3894 | case kCondNE: |
| 3895 | case kCondA: // > 0 if non-zero |
| 3896 | __ Bnezc(lhs, label); |
| 3897 | break; |
| 3898 | case kCondLT: |
| 3899 | __ Bltzc(lhs, label); |
| 3900 | break; |
| 3901 | case kCondGE: |
| 3902 | __ Bgezc(lhs, label); |
| 3903 | break; |
| 3904 | case kCondLE: |
| 3905 | __ Blezc(lhs, label); |
| 3906 | break; |
| 3907 | case kCondGT: |
| 3908 | __ Bgtzc(lhs, label); |
| 3909 | break; |
| 3910 | case kCondB: // always false |
| 3911 | break; |
| 3912 | case kCondAE: // always true |
| 3913 | __ Bc(label); |
| 3914 | break; |
| 3915 | } |
| 3916 | } else { |
| 3917 | if (use_imm) { |
| 3918 | rhs_reg = TMP; |
| 3919 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3920 | } |
| 3921 | switch (cond) { |
| 3922 | case kCondEQ: |
| 3923 | __ Beqc(lhs, rhs_reg, label); |
| 3924 | break; |
| 3925 | case kCondNE: |
| 3926 | __ Bnec(lhs, rhs_reg, label); |
| 3927 | break; |
| 3928 | case kCondLT: |
| 3929 | __ Bltc(lhs, rhs_reg, label); |
| 3930 | break; |
| 3931 | case kCondGE: |
| 3932 | __ Bgec(lhs, rhs_reg, label); |
| 3933 | break; |
| 3934 | case kCondLE: |
| 3935 | __ Bgec(rhs_reg, lhs, label); |
| 3936 | break; |
| 3937 | case kCondGT: |
| 3938 | __ Bltc(rhs_reg, lhs, label); |
| 3939 | break; |
| 3940 | case kCondB: |
| 3941 | __ Bltuc(lhs, rhs_reg, label); |
| 3942 | break; |
| 3943 | case kCondAE: |
| 3944 | __ Bgeuc(lhs, rhs_reg, label); |
| 3945 | break; |
| 3946 | case kCondBE: |
| 3947 | __ Bgeuc(rhs_reg, lhs, label); |
| 3948 | break; |
| 3949 | case kCondA: |
| 3950 | __ Bltuc(rhs_reg, lhs, label); |
| 3951 | break; |
| 3952 | } |
| 3953 | } |
| 3954 | } |
| 3955 | |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3956 | void InstructionCodeGeneratorMIPS64::GenerateFpCompare(IfCondition cond, |
| 3957 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3958 | DataType::Type type, |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3959 | LocationSummary* locations) { |
| 3960 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3961 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3962 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3963 | if (type == DataType::Type::kFloat32) { |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3964 | switch (cond) { |
| 3965 | case kCondEQ: |
| 3966 | __ CmpEqS(FTMP, lhs, rhs); |
| 3967 | __ Mfc1(dst, FTMP); |
| 3968 | __ Andi(dst, dst, 1); |
| 3969 | break; |
| 3970 | case kCondNE: |
| 3971 | __ CmpEqS(FTMP, lhs, rhs); |
| 3972 | __ Mfc1(dst, FTMP); |
| 3973 | __ Addiu(dst, dst, 1); |
| 3974 | break; |
| 3975 | case kCondLT: |
| 3976 | if (gt_bias) { |
| 3977 | __ CmpLtS(FTMP, lhs, rhs); |
| 3978 | } else { |
| 3979 | __ CmpUltS(FTMP, lhs, rhs); |
| 3980 | } |
| 3981 | __ Mfc1(dst, FTMP); |
| 3982 | __ Andi(dst, dst, 1); |
| 3983 | break; |
| 3984 | case kCondLE: |
| 3985 | if (gt_bias) { |
| 3986 | __ CmpLeS(FTMP, lhs, rhs); |
| 3987 | } else { |
| 3988 | __ CmpUleS(FTMP, lhs, rhs); |
| 3989 | } |
| 3990 | __ Mfc1(dst, FTMP); |
| 3991 | __ Andi(dst, dst, 1); |
| 3992 | break; |
| 3993 | case kCondGT: |
| 3994 | if (gt_bias) { |
| 3995 | __ CmpUltS(FTMP, rhs, lhs); |
| 3996 | } else { |
| 3997 | __ CmpLtS(FTMP, rhs, lhs); |
| 3998 | } |
| 3999 | __ Mfc1(dst, FTMP); |
| 4000 | __ Andi(dst, dst, 1); |
| 4001 | break; |
| 4002 | case kCondGE: |
| 4003 | if (gt_bias) { |
| 4004 | __ CmpUleS(FTMP, rhs, lhs); |
| 4005 | } else { |
| 4006 | __ CmpLeS(FTMP, rhs, lhs); |
| 4007 | } |
| 4008 | __ Mfc1(dst, FTMP); |
| 4009 | __ Andi(dst, dst, 1); |
| 4010 | break; |
| 4011 | default: |
| 4012 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4013 | UNREACHABLE(); |
| 4014 | } |
| 4015 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4016 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 4017 | switch (cond) { |
| 4018 | case kCondEQ: |
| 4019 | __ CmpEqD(FTMP, lhs, rhs); |
| 4020 | __ Mfc1(dst, FTMP); |
| 4021 | __ Andi(dst, dst, 1); |
| 4022 | break; |
| 4023 | case kCondNE: |
| 4024 | __ CmpEqD(FTMP, lhs, rhs); |
| 4025 | __ Mfc1(dst, FTMP); |
| 4026 | __ Addiu(dst, dst, 1); |
| 4027 | break; |
| 4028 | case kCondLT: |
| 4029 | if (gt_bias) { |
| 4030 | __ CmpLtD(FTMP, lhs, rhs); |
| 4031 | } else { |
| 4032 | __ CmpUltD(FTMP, lhs, rhs); |
| 4033 | } |
| 4034 | __ Mfc1(dst, FTMP); |
| 4035 | __ Andi(dst, dst, 1); |
| 4036 | break; |
| 4037 | case kCondLE: |
| 4038 | if (gt_bias) { |
| 4039 | __ CmpLeD(FTMP, lhs, rhs); |
| 4040 | } else { |
| 4041 | __ CmpUleD(FTMP, lhs, rhs); |
| 4042 | } |
| 4043 | __ Mfc1(dst, FTMP); |
| 4044 | __ Andi(dst, dst, 1); |
| 4045 | break; |
| 4046 | case kCondGT: |
| 4047 | if (gt_bias) { |
| 4048 | __ CmpUltD(FTMP, rhs, lhs); |
| 4049 | } else { |
| 4050 | __ CmpLtD(FTMP, rhs, lhs); |
| 4051 | } |
| 4052 | __ Mfc1(dst, FTMP); |
| 4053 | __ Andi(dst, dst, 1); |
| 4054 | break; |
| 4055 | case kCondGE: |
| 4056 | if (gt_bias) { |
| 4057 | __ CmpUleD(FTMP, rhs, lhs); |
| 4058 | } else { |
| 4059 | __ CmpLeD(FTMP, rhs, lhs); |
| 4060 | } |
| 4061 | __ Mfc1(dst, FTMP); |
| 4062 | __ Andi(dst, dst, 1); |
| 4063 | break; |
| 4064 | default: |
| 4065 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4066 | UNREACHABLE(); |
| 4067 | } |
| 4068 | } |
| 4069 | } |
| 4070 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4071 | bool InstructionCodeGeneratorMIPS64::MaterializeFpCompare(IfCondition cond, |
| 4072 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4073 | DataType::Type type, |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4074 | LocationSummary* input_locations, |
| 4075 | FpuRegister dst) { |
| 4076 | FpuRegister lhs = input_locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 4077 | FpuRegister rhs = input_locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4078 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4079 | switch (cond) { |
| 4080 | case kCondEQ: |
| 4081 | __ CmpEqS(dst, lhs, rhs); |
| 4082 | return false; |
| 4083 | case kCondNE: |
| 4084 | __ CmpEqS(dst, lhs, rhs); |
| 4085 | return true; |
| 4086 | case kCondLT: |
| 4087 | if (gt_bias) { |
| 4088 | __ CmpLtS(dst, lhs, rhs); |
| 4089 | } else { |
| 4090 | __ CmpUltS(dst, lhs, rhs); |
| 4091 | } |
| 4092 | return false; |
| 4093 | case kCondLE: |
| 4094 | if (gt_bias) { |
| 4095 | __ CmpLeS(dst, lhs, rhs); |
| 4096 | } else { |
| 4097 | __ CmpUleS(dst, lhs, rhs); |
| 4098 | } |
| 4099 | return false; |
| 4100 | case kCondGT: |
| 4101 | if (gt_bias) { |
| 4102 | __ CmpUltS(dst, rhs, lhs); |
| 4103 | } else { |
| 4104 | __ CmpLtS(dst, rhs, lhs); |
| 4105 | } |
| 4106 | return false; |
| 4107 | case kCondGE: |
| 4108 | if (gt_bias) { |
| 4109 | __ CmpUleS(dst, rhs, lhs); |
| 4110 | } else { |
| 4111 | __ CmpLeS(dst, rhs, lhs); |
| 4112 | } |
| 4113 | return false; |
| 4114 | default: |
| 4115 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4116 | UNREACHABLE(); |
| 4117 | } |
| 4118 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4119 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4120 | switch (cond) { |
| 4121 | case kCondEQ: |
| 4122 | __ CmpEqD(dst, lhs, rhs); |
| 4123 | return false; |
| 4124 | case kCondNE: |
| 4125 | __ CmpEqD(dst, lhs, rhs); |
| 4126 | return true; |
| 4127 | case kCondLT: |
| 4128 | if (gt_bias) { |
| 4129 | __ CmpLtD(dst, lhs, rhs); |
| 4130 | } else { |
| 4131 | __ CmpUltD(dst, lhs, rhs); |
| 4132 | } |
| 4133 | return false; |
| 4134 | case kCondLE: |
| 4135 | if (gt_bias) { |
| 4136 | __ CmpLeD(dst, lhs, rhs); |
| 4137 | } else { |
| 4138 | __ CmpUleD(dst, lhs, rhs); |
| 4139 | } |
| 4140 | return false; |
| 4141 | case kCondGT: |
| 4142 | if (gt_bias) { |
| 4143 | __ CmpUltD(dst, rhs, lhs); |
| 4144 | } else { |
| 4145 | __ CmpLtD(dst, rhs, lhs); |
| 4146 | } |
| 4147 | return false; |
| 4148 | case kCondGE: |
| 4149 | if (gt_bias) { |
| 4150 | __ CmpUleD(dst, rhs, lhs); |
| 4151 | } else { |
| 4152 | __ CmpLeD(dst, rhs, lhs); |
| 4153 | } |
| 4154 | return false; |
| 4155 | default: |
| 4156 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4157 | UNREACHABLE(); |
| 4158 | } |
| 4159 | } |
| 4160 | } |
| 4161 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4162 | void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond, |
| 4163 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4164 | DataType::Type type, |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4165 | LocationSummary* locations, |
| 4166 | Mips64Label* label) { |
| 4167 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 4168 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4169 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4170 | switch (cond) { |
| 4171 | case kCondEQ: |
| 4172 | __ CmpEqS(FTMP, lhs, rhs); |
| 4173 | __ Bc1nez(FTMP, label); |
| 4174 | break; |
| 4175 | case kCondNE: |
| 4176 | __ CmpEqS(FTMP, lhs, rhs); |
| 4177 | __ Bc1eqz(FTMP, label); |
| 4178 | break; |
| 4179 | case kCondLT: |
| 4180 | if (gt_bias) { |
| 4181 | __ CmpLtS(FTMP, lhs, rhs); |
| 4182 | } else { |
| 4183 | __ CmpUltS(FTMP, lhs, rhs); |
| 4184 | } |
| 4185 | __ Bc1nez(FTMP, label); |
| 4186 | break; |
| 4187 | case kCondLE: |
| 4188 | if (gt_bias) { |
| 4189 | __ CmpLeS(FTMP, lhs, rhs); |
| 4190 | } else { |
| 4191 | __ CmpUleS(FTMP, lhs, rhs); |
| 4192 | } |
| 4193 | __ Bc1nez(FTMP, label); |
| 4194 | break; |
| 4195 | case kCondGT: |
| 4196 | if (gt_bias) { |
| 4197 | __ CmpUltS(FTMP, rhs, lhs); |
| 4198 | } else { |
| 4199 | __ CmpLtS(FTMP, rhs, lhs); |
| 4200 | } |
| 4201 | __ Bc1nez(FTMP, label); |
| 4202 | break; |
| 4203 | case kCondGE: |
| 4204 | if (gt_bias) { |
| 4205 | __ CmpUleS(FTMP, rhs, lhs); |
| 4206 | } else { |
| 4207 | __ CmpLeS(FTMP, rhs, lhs); |
| 4208 | } |
| 4209 | __ Bc1nez(FTMP, label); |
| 4210 | break; |
| 4211 | default: |
| 4212 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4213 | UNREACHABLE(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4214 | } |
| 4215 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4216 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4217 | switch (cond) { |
| 4218 | case kCondEQ: |
| 4219 | __ CmpEqD(FTMP, lhs, rhs); |
| 4220 | __ Bc1nez(FTMP, label); |
| 4221 | break; |
| 4222 | case kCondNE: |
| 4223 | __ CmpEqD(FTMP, lhs, rhs); |
| 4224 | __ Bc1eqz(FTMP, label); |
| 4225 | break; |
| 4226 | case kCondLT: |
| 4227 | if (gt_bias) { |
| 4228 | __ CmpLtD(FTMP, lhs, rhs); |
| 4229 | } else { |
| 4230 | __ CmpUltD(FTMP, lhs, rhs); |
| 4231 | } |
| 4232 | __ Bc1nez(FTMP, label); |
| 4233 | break; |
| 4234 | case kCondLE: |
| 4235 | if (gt_bias) { |
| 4236 | __ CmpLeD(FTMP, lhs, rhs); |
| 4237 | } else { |
| 4238 | __ CmpUleD(FTMP, lhs, rhs); |
| 4239 | } |
| 4240 | __ Bc1nez(FTMP, label); |
| 4241 | break; |
| 4242 | case kCondGT: |
| 4243 | if (gt_bias) { |
| 4244 | __ CmpUltD(FTMP, rhs, lhs); |
| 4245 | } else { |
| 4246 | __ CmpLtD(FTMP, rhs, lhs); |
| 4247 | } |
| 4248 | __ Bc1nez(FTMP, label); |
| 4249 | break; |
| 4250 | case kCondGE: |
| 4251 | if (gt_bias) { |
| 4252 | __ CmpUleD(FTMP, rhs, lhs); |
| 4253 | } else { |
| 4254 | __ CmpLeD(FTMP, rhs, lhs); |
| 4255 | } |
| 4256 | __ Bc1nez(FTMP, label); |
| 4257 | break; |
| 4258 | default: |
| 4259 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4260 | UNREACHABLE(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4261 | } |
| 4262 | } |
| 4263 | } |
| 4264 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4265 | void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4266 | size_t condition_input_index, |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4267 | Mips64Label* true_target, |
| 4268 | Mips64Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4269 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4270 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4271 | if (true_target == nullptr && false_target == nullptr) { |
| 4272 | // Nothing to do. The code always falls through. |
| 4273 | return; |
| 4274 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4275 | // Constant condition, statically compared against "true" (integer value 1). |
| 4276 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4277 | if (true_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4278 | __ Bc(true_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4279 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4280 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4281 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4282 | if (false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4283 | __ Bc(false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4284 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4285 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4286 | return; |
| 4287 | } |
| 4288 | |
| 4289 | // The following code generates these patterns: |
| 4290 | // (1) true_target == nullptr && false_target != nullptr |
| 4291 | // - opposite condition true => branch to false_target |
| 4292 | // (2) true_target != nullptr && false_target == nullptr |
| 4293 | // - condition true => branch to true_target |
| 4294 | // (3) true_target != nullptr && false_target != nullptr |
| 4295 | // - condition true => branch to true_target |
| 4296 | // - branch to false_target |
| 4297 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4298 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4299 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4300 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4301 | if (true_target == nullptr) { |
| 4302 | __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target); |
| 4303 | } else { |
| 4304 | __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target); |
| 4305 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4306 | } else { |
| 4307 | // The condition instruction has not been materialized, use its inputs as |
| 4308 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4309 | HCondition* condition = cond->AsCondition(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4310 | DataType::Type type = condition->InputAt(0)->GetType(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4311 | LocationSummary* locations = cond->GetLocations(); |
| 4312 | IfCondition if_cond = condition->GetCondition(); |
| 4313 | Mips64Label* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4314 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4315 | if (true_target == nullptr) { |
| 4316 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4317 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4318 | } |
| 4319 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4320 | switch (type) { |
| 4321 | default: |
| 4322 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target); |
| 4323 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4324 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4325 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target); |
| 4326 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4327 | case DataType::Type::kFloat32: |
| 4328 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4329 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 4330 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4331 | } |
| 4332 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4333 | |
| 4334 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 4335 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 4336 | if (true_target != nullptr && false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4337 | __ Bc(false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4338 | } |
| 4339 | } |
| 4340 | |
| 4341 | void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4342 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4343 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4344 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4345 | } |
| 4346 | } |
| 4347 | |
| 4348 | void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4349 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 4350 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4351 | Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4352 | nullptr : codegen_->GetLabelOf(true_successor); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4353 | Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4354 | nullptr : codegen_->GetLabelOf(false_successor); |
| 4355 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4356 | } |
| 4357 | |
| 4358 | void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4359 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4360 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 4361 | InvokeRuntimeCallingConvention calling_convention; |
| 4362 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4363 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4364 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4365 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4366 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4367 | } |
| 4368 | } |
| 4369 | |
| 4370 | void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 4371 | SlowPathCodeMIPS64* slow_path = |
| 4372 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4373 | GenerateTestAndBranch(deoptimize, |
| 4374 | /* condition_input_index */ 0, |
| 4375 | slow_path->GetEntryLabel(), |
| 4376 | /* false_target */ nullptr); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4377 | } |
| 4378 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4379 | // This function returns true if a conditional move can be generated for HSelect. |
| 4380 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 4381 | // branches and regular moves. |
| 4382 | // |
| 4383 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 4384 | // |
| 4385 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 4386 | // are two distinct tasks, this function does both because they share quite a bit |
| 4387 | // of common logic. |
| 4388 | static bool CanMoveConditionally(HSelect* select, LocationSummary* locations_to_set) { |
| 4389 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 4390 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4391 | HCondition* condition = cond->AsCondition(); |
| 4392 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4393 | DataType::Type cond_type = |
| 4394 | materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType(); |
| 4395 | DataType::Type dst_type = select->GetType(); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4396 | |
| 4397 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 4398 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 4399 | bool is_true_value_zero_constant = |
| 4400 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 4401 | bool is_false_value_zero_constant = |
| 4402 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 4403 | |
| 4404 | bool can_move_conditionally = false; |
| 4405 | bool use_const_for_false_in = false; |
| 4406 | bool use_const_for_true_in = false; |
| 4407 | |
| 4408 | if (!cond->IsConstant()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4409 | if (!DataType::IsFloatingPointType(cond_type)) { |
| 4410 | if (!DataType::IsFloatingPointType(dst_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4411 | // Moving int/long on int/long condition. |
| 4412 | if (is_true_value_zero_constant) { |
| 4413 | // seleqz out_reg, false_reg, cond_reg |
| 4414 | can_move_conditionally = true; |
| 4415 | use_const_for_true_in = true; |
| 4416 | } else if (is_false_value_zero_constant) { |
| 4417 | // selnez out_reg, true_reg, cond_reg |
| 4418 | can_move_conditionally = true; |
| 4419 | use_const_for_false_in = true; |
| 4420 | } else if (materialized) { |
| 4421 | // Not materializing unmaterialized int conditions |
| 4422 | // to keep the instruction count low. |
| 4423 | // selnez AT, true_reg, cond_reg |
| 4424 | // seleqz TMP, false_reg, cond_reg |
| 4425 | // or out_reg, AT, TMP |
| 4426 | can_move_conditionally = true; |
| 4427 | } |
| 4428 | } else { |
| 4429 | // Moving float/double on int/long condition. |
| 4430 | if (materialized) { |
| 4431 | // Not materializing unmaterialized int conditions |
| 4432 | // to keep the instruction count low. |
| 4433 | can_move_conditionally = true; |
| 4434 | if (is_true_value_zero_constant) { |
| 4435 | // sltu TMP, ZERO, cond_reg |
| 4436 | // mtc1 TMP, temp_cond_reg |
| 4437 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4438 | use_const_for_true_in = true; |
| 4439 | } else if (is_false_value_zero_constant) { |
| 4440 | // sltu TMP, ZERO, cond_reg |
| 4441 | // mtc1 TMP, temp_cond_reg |
| 4442 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4443 | use_const_for_false_in = true; |
| 4444 | } else { |
| 4445 | // sltu TMP, ZERO, cond_reg |
| 4446 | // mtc1 TMP, temp_cond_reg |
| 4447 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4448 | // mov.fmt out_reg, temp_cond_reg |
| 4449 | } |
| 4450 | } |
| 4451 | } |
| 4452 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4453 | if (!DataType::IsFloatingPointType(dst_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4454 | // Moving int/long on float/double condition. |
| 4455 | can_move_conditionally = true; |
| 4456 | if (is_true_value_zero_constant) { |
| 4457 | // mfc1 TMP, temp_cond_reg |
| 4458 | // seleqz out_reg, false_reg, TMP |
| 4459 | use_const_for_true_in = true; |
| 4460 | } else if (is_false_value_zero_constant) { |
| 4461 | // mfc1 TMP, temp_cond_reg |
| 4462 | // selnez out_reg, true_reg, TMP |
| 4463 | use_const_for_false_in = true; |
| 4464 | } else { |
| 4465 | // mfc1 TMP, temp_cond_reg |
| 4466 | // selnez AT, true_reg, TMP |
| 4467 | // seleqz TMP, false_reg, TMP |
| 4468 | // or out_reg, AT, TMP |
| 4469 | } |
| 4470 | } else { |
| 4471 | // Moving float/double on float/double condition. |
| 4472 | can_move_conditionally = true; |
| 4473 | if (is_true_value_zero_constant) { |
| 4474 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4475 | use_const_for_true_in = true; |
| 4476 | } else if (is_false_value_zero_constant) { |
| 4477 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4478 | use_const_for_false_in = true; |
| 4479 | } else { |
| 4480 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4481 | // mov.fmt out_reg, temp_cond_reg |
| 4482 | } |
| 4483 | } |
| 4484 | } |
| 4485 | } |
| 4486 | |
| 4487 | if (can_move_conditionally) { |
| 4488 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 4489 | } else { |
| 4490 | DCHECK(!use_const_for_false_in); |
| 4491 | DCHECK(!use_const_for_true_in); |
| 4492 | } |
| 4493 | |
| 4494 | if (locations_to_set != nullptr) { |
| 4495 | if (use_const_for_false_in) { |
| 4496 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 4497 | } else { |
| 4498 | locations_to_set->SetInAt(0, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4499 | DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4500 | ? Location::RequiresFpuRegister() |
| 4501 | : Location::RequiresRegister()); |
| 4502 | } |
| 4503 | if (use_const_for_true_in) { |
| 4504 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 4505 | } else { |
| 4506 | locations_to_set->SetInAt(1, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4507 | DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4508 | ? Location::RequiresFpuRegister() |
| 4509 | : Location::RequiresRegister()); |
| 4510 | } |
| 4511 | if (materialized) { |
| 4512 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 4513 | } |
| 4514 | |
| 4515 | if (can_move_conditionally) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4516 | locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4517 | ? Location::RequiresFpuRegister() |
| 4518 | : Location::RequiresRegister()); |
| 4519 | } else { |
| 4520 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 4521 | } |
| 4522 | } |
| 4523 | |
| 4524 | return can_move_conditionally; |
| 4525 | } |
| 4526 | |
| 4527 | |
| 4528 | void InstructionCodeGeneratorMIPS64::GenConditionalMove(HSelect* select) { |
| 4529 | LocationSummary* locations = select->GetLocations(); |
| 4530 | Location dst = locations->Out(); |
| 4531 | Location false_src = locations->InAt(0); |
| 4532 | Location true_src = locations->InAt(1); |
| 4533 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4534 | GpuRegister cond_reg = TMP; |
| 4535 | FpuRegister fcond_reg = FTMP; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4536 | DataType::Type cond_type = DataType::Type::kInt32; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4537 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4538 | DataType::Type dst_type = select->GetType(); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4539 | |
| 4540 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 4541 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<GpuRegister>(); |
| 4542 | } else { |
| 4543 | HCondition* condition = cond->AsCondition(); |
| 4544 | LocationSummary* cond_locations = cond->GetLocations(); |
| 4545 | IfCondition if_cond = condition->GetCondition(); |
| 4546 | cond_type = condition->InputAt(0)->GetType(); |
| 4547 | switch (cond_type) { |
| 4548 | default: |
| 4549 | cond_inverted = MaterializeIntLongCompare(if_cond, |
| 4550 | /* is64bit */ false, |
| 4551 | cond_locations, |
| 4552 | cond_reg); |
| 4553 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4554 | case DataType::Type::kInt64: |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4555 | cond_inverted = MaterializeIntLongCompare(if_cond, |
| 4556 | /* is64bit */ true, |
| 4557 | cond_locations, |
| 4558 | cond_reg); |
| 4559 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4560 | case DataType::Type::kFloat32: |
| 4561 | case DataType::Type::kFloat64: |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4562 | cond_inverted = MaterializeFpCompare(if_cond, |
| 4563 | condition->IsGtBias(), |
| 4564 | cond_type, |
| 4565 | cond_locations, |
| 4566 | fcond_reg); |
| 4567 | break; |
| 4568 | } |
| 4569 | } |
| 4570 | |
| 4571 | if (true_src.IsConstant()) { |
| 4572 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 4573 | } |
| 4574 | if (false_src.IsConstant()) { |
| 4575 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 4576 | } |
| 4577 | |
| 4578 | switch (dst_type) { |
| 4579 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4580 | if (DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4581 | __ Mfc1(cond_reg, fcond_reg); |
| 4582 | } |
| 4583 | if (true_src.IsConstant()) { |
| 4584 | if (cond_inverted) { |
| 4585 | __ Selnez(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4586 | } else { |
| 4587 | __ Seleqz(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4588 | } |
| 4589 | } else if (false_src.IsConstant()) { |
| 4590 | if (cond_inverted) { |
| 4591 | __ Seleqz(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4592 | } else { |
| 4593 | __ Selnez(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4594 | } |
| 4595 | } else { |
| 4596 | DCHECK_NE(cond_reg, AT); |
| 4597 | if (cond_inverted) { |
| 4598 | __ Seleqz(AT, true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4599 | __ Selnez(TMP, false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4600 | } else { |
| 4601 | __ Selnez(AT, true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4602 | __ Seleqz(TMP, false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4603 | } |
| 4604 | __ Or(dst.AsRegister<GpuRegister>(), AT, TMP); |
| 4605 | } |
| 4606 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4607 | case DataType::Type::kFloat32: { |
| 4608 | if (!DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4609 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4610 | __ Sltu(TMP, ZERO, cond_reg); |
| 4611 | __ Mtc1(TMP, fcond_reg); |
| 4612 | } |
| 4613 | FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>(); |
| 4614 | if (true_src.IsConstant()) { |
| 4615 | FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>(); |
| 4616 | if (cond_inverted) { |
| 4617 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4618 | } else { |
| 4619 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4620 | } |
| 4621 | } else if (false_src.IsConstant()) { |
| 4622 | FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>(); |
| 4623 | if (cond_inverted) { |
| 4624 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4625 | } else { |
| 4626 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4627 | } |
| 4628 | } else { |
| 4629 | if (cond_inverted) { |
| 4630 | __ SelS(fcond_reg, |
| 4631 | true_src.AsFpuRegister<FpuRegister>(), |
| 4632 | false_src.AsFpuRegister<FpuRegister>()); |
| 4633 | } else { |
| 4634 | __ SelS(fcond_reg, |
| 4635 | false_src.AsFpuRegister<FpuRegister>(), |
| 4636 | true_src.AsFpuRegister<FpuRegister>()); |
| 4637 | } |
| 4638 | __ MovS(dst_reg, fcond_reg); |
| 4639 | } |
| 4640 | break; |
| 4641 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4642 | case DataType::Type::kFloat64: { |
| 4643 | if (!DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4644 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4645 | __ Sltu(TMP, ZERO, cond_reg); |
| 4646 | __ Mtc1(TMP, fcond_reg); |
| 4647 | } |
| 4648 | FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>(); |
| 4649 | if (true_src.IsConstant()) { |
| 4650 | FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>(); |
| 4651 | if (cond_inverted) { |
| 4652 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4653 | } else { |
| 4654 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4655 | } |
| 4656 | } else if (false_src.IsConstant()) { |
| 4657 | FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>(); |
| 4658 | if (cond_inverted) { |
| 4659 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4660 | } else { |
| 4661 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4662 | } |
| 4663 | } else { |
| 4664 | if (cond_inverted) { |
| 4665 | __ SelD(fcond_reg, |
| 4666 | true_src.AsFpuRegister<FpuRegister>(), |
| 4667 | false_src.AsFpuRegister<FpuRegister>()); |
| 4668 | } else { |
| 4669 | __ SelD(fcond_reg, |
| 4670 | false_src.AsFpuRegister<FpuRegister>(), |
| 4671 | true_src.AsFpuRegister<FpuRegister>()); |
| 4672 | } |
| 4673 | __ MovD(dst_reg, fcond_reg); |
| 4674 | } |
| 4675 | break; |
| 4676 | } |
| 4677 | } |
| 4678 | } |
| 4679 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4680 | void LocationsBuilderMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4681 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4682 | LocationSummary(flag, LocationSummary::kNoCall); |
| 4683 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4684 | } |
| 4685 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4686 | void InstructionCodeGeneratorMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 4687 | __ LoadFromOffset(kLoadWord, |
| 4688 | flag->GetLocations()->Out().AsRegister<GpuRegister>(), |
| 4689 | SP, |
| 4690 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4691 | } |
| 4692 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4693 | void LocationsBuilderMIPS64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4694 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4695 | CanMoveConditionally(select, locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4699 | if (CanMoveConditionally(select, /* locations_to_set */ nullptr)) { |
| 4700 | GenConditionalMove(select); |
| 4701 | } else { |
| 4702 | LocationSummary* locations = select->GetLocations(); |
| 4703 | Mips64Label false_target; |
| 4704 | GenerateTestAndBranch(select, |
| 4705 | /* condition_input_index */ 2, |
| 4706 | /* true_target */ nullptr, |
| 4707 | &false_target); |
| 4708 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 4709 | __ Bind(&false_target); |
| 4710 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4711 | } |
| 4712 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4713 | void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4714 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4715 | } |
| 4716 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 4717 | void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 4718 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | void CodeGeneratorMIPS64::GenerateNop() { |
| 4722 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4723 | } |
| 4724 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4725 | void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4726 | const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4727 | DataType::Type field_type = field_info.GetFieldType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4728 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4729 | kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4730 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4731 | instruction, |
| 4732 | object_field_get_with_read_barrier |
| 4733 | ? LocationSummary::kCallOnSlowPath |
| 4734 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 4735 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4736 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 4737 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4738 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4739 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4740 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4741 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4742 | // The output overlaps in the case of an object field get with |
| 4743 | // read barriers enabled: we do not want the move to overwrite the |
| 4744 | // object's location, as we need it to emit the read barrier. |
| 4745 | locations->SetOut(Location::RequiresRegister(), |
| 4746 | object_field_get_with_read_barrier |
| 4747 | ? Location::kOutputOverlap |
| 4748 | : Location::kNoOutputOverlap); |
| 4749 | } |
| 4750 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4751 | // We need a temporary register for the read barrier marking slow |
| 4752 | // path in CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4753 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 4754 | locations->AddTemp(Location::RequiresRegister()); |
| 4755 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4756 | } |
| 4757 | } |
| 4758 | |
| 4759 | void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction, |
| 4760 | const FieldInfo& field_info) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4761 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4762 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4763 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4764 | Location obj_loc = locations->InAt(0); |
| 4765 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 4766 | Location dst_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4767 | LoadOperandType load_type = kLoadUnsignedByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4768 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4769 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4770 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4771 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4772 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4773 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4774 | case DataType::Type::kUint8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4775 | load_type = kLoadUnsignedByte; |
| 4776 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4777 | case DataType::Type::kInt8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4778 | load_type = kLoadSignedByte; |
| 4779 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4780 | case DataType::Type::kUint16: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4781 | load_type = kLoadUnsignedHalfword; |
| 4782 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4783 | case DataType::Type::kInt16: |
| 4784 | load_type = kLoadSignedHalfword; |
| 4785 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4786 | case DataType::Type::kInt32: |
| 4787 | case DataType::Type::kFloat32: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4788 | load_type = kLoadWord; |
| 4789 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4790 | case DataType::Type::kInt64: |
| 4791 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4792 | load_type = kLoadDoubleword; |
| 4793 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4794 | case DataType::Type::kReference: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4795 | load_type = kLoadUnsignedWord; |
| 4796 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4797 | case DataType::Type::kUint32: |
| 4798 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4799 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4800 | LOG(FATAL) << "Unreachable type " << type; |
| 4801 | UNREACHABLE(); |
| 4802 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4803 | if (!DataType::IsFloatingPointType(type)) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4804 | DCHECK(dst_loc.IsRegister()); |
| 4805 | GpuRegister dst = dst_loc.AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4806 | if (type == DataType::Type::kReference) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4807 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 4808 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4809 | Location temp_loc = |
| 4810 | kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4811 | // Note that a potential implicit null check is handled in this |
| 4812 | // CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier call. |
| 4813 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4814 | dst_loc, |
| 4815 | obj, |
| 4816 | offset, |
| 4817 | temp_loc, |
| 4818 | /* needs_null_check */ true); |
| 4819 | if (is_volatile) { |
| 4820 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4821 | } |
| 4822 | } else { |
| 4823 | __ LoadFromOffset(kLoadUnsignedWord, dst, obj, offset, null_checker); |
| 4824 | if (is_volatile) { |
| 4825 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4826 | } |
| 4827 | // If read barriers are enabled, emit read barriers other than |
| 4828 | // Baker's using a slow path (and also unpoison the loaded |
| 4829 | // reference, if heap poisoning is enabled). |
| 4830 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 4831 | } |
| 4832 | } else { |
| 4833 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
| 4834 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4835 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4836 | DCHECK(dst_loc.IsFpuRegister()); |
| 4837 | FpuRegister dst = dst_loc.AsFpuRegister<FpuRegister>(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4838 | __ LoadFpuFromOffset(load_type, dst, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4839 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4840 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4841 | // Memory barriers, in the case of references, are handled in the |
| 4842 | // previous switch statement. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4843 | if (is_volatile && (type != DataType::Type::kReference)) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4844 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4845 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4846 | } |
| 4847 | |
| 4848 | void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction, |
| 4849 | const FieldInfo& field_info ATTRIBUTE_UNUSED) { |
| 4850 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4851 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4852 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4853 | if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4854 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4855 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4856 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4857 | } |
| 4858 | } |
| 4859 | |
| 4860 | void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction, |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4861 | const FieldInfo& field_info, |
| 4862 | bool value_can_be_null) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4863 | DataType::Type type = field_info.GetFieldType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4864 | LocationSummary* locations = instruction->GetLocations(); |
| 4865 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4866 | Location value_location = locations->InAt(1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4867 | StoreOperandType store_type = kStoreByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4868 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4869 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4870 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4871 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4872 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4873 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4874 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4875 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4876 | case DataType::Type::kInt8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4877 | store_type = kStoreByte; |
| 4878 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4879 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4880 | case DataType::Type::kInt16: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4881 | store_type = kStoreHalfword; |
| 4882 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4883 | case DataType::Type::kInt32: |
| 4884 | case DataType::Type::kFloat32: |
| 4885 | case DataType::Type::kReference: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4886 | store_type = kStoreWord; |
| 4887 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4888 | case DataType::Type::kInt64: |
| 4889 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4890 | store_type = kStoreDoubleword; |
| 4891 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4892 | case DataType::Type::kUint32: |
| 4893 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4894 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4895 | LOG(FATAL) << "Unreachable type " << type; |
| 4896 | UNREACHABLE(); |
| 4897 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4898 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4899 | if (is_volatile) { |
| 4900 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4901 | } |
| 4902 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4903 | if (value_location.IsConstant()) { |
| 4904 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 4905 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
| 4906 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4907 | if (!DataType::IsFloatingPointType(type)) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4908 | DCHECK(value_location.IsRegister()); |
| 4909 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
| 4910 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4911 | // Note that in the case where `value` is a null reference, |
| 4912 | // we do not enter this block, as a null reference does not |
| 4913 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4914 | DCHECK_EQ(type, DataType::Type::kReference); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4915 | __ PoisonHeapReference(TMP, src); |
| 4916 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 4917 | } else { |
| 4918 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 4919 | } |
| 4920 | } else { |
| 4921 | DCHECK(value_location.IsFpuRegister()); |
| 4922 | FpuRegister src = value_location.AsFpuRegister<FpuRegister>(); |
| 4923 | __ StoreFpuToOffset(store_type, src, obj, offset, null_checker); |
| 4924 | } |
| 4925 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4926 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4927 | if (needs_write_barrier) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4928 | DCHECK(value_location.IsRegister()); |
| 4929 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4930 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4931 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4932 | |
| 4933 | if (is_volatile) { |
| 4934 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4935 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4936 | } |
| 4937 | |
| 4938 | void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4939 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4940 | } |
| 4941 | |
| 4942 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4943 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4944 | } |
| 4945 | |
| 4946 | void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4947 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4948 | } |
| 4949 | |
| 4950 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4951 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4952 | } |
| 4953 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4954 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadOneRegister( |
| 4955 | HInstruction* instruction, |
| 4956 | Location out, |
| 4957 | uint32_t offset, |
| 4958 | Location maybe_temp, |
| 4959 | ReadBarrierOption read_barrier_option) { |
| 4960 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 4961 | if (read_barrier_option == kWithReadBarrier) { |
| 4962 | CHECK(kEmitCompilerReadBarrier); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4963 | if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) { |
| 4964 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 4965 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4966 | if (kUseBakerReadBarrier) { |
| 4967 | // Load with fast path based Baker's read barrier. |
| 4968 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4969 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4970 | out, |
| 4971 | out_reg, |
| 4972 | offset, |
| 4973 | maybe_temp, |
| 4974 | /* needs_null_check */ false); |
| 4975 | } else { |
| 4976 | // Load with slow path based read barrier. |
| 4977 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 4978 | // in the following move operation, as we will need it for the |
| 4979 | // read barrier below. |
| 4980 | __ Move(maybe_temp.AsRegister<GpuRegister>(), out_reg); |
| 4981 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4982 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4983 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 4984 | } |
| 4985 | } else { |
| 4986 | // Plain load with no read barrier. |
| 4987 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4988 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4989 | __ MaybeUnpoisonHeapReference(out_reg); |
| 4990 | } |
| 4991 | } |
| 4992 | |
| 4993 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadTwoRegisters( |
| 4994 | HInstruction* instruction, |
| 4995 | Location out, |
| 4996 | Location obj, |
| 4997 | uint32_t offset, |
| 4998 | Location maybe_temp, |
| 4999 | ReadBarrierOption read_barrier_option) { |
| 5000 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 5001 | GpuRegister obj_reg = obj.AsRegister<GpuRegister>(); |
| 5002 | if (read_barrier_option == kWithReadBarrier) { |
| 5003 | CHECK(kEmitCompilerReadBarrier); |
| 5004 | if (kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5005 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 5006 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 5007 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5008 | // Load with fast path based Baker's read barrier. |
| 5009 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5010 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5011 | out, |
| 5012 | obj_reg, |
| 5013 | offset, |
| 5014 | maybe_temp, |
| 5015 | /* needs_null_check */ false); |
| 5016 | } else { |
| 5017 | // Load with slow path based read barrier. |
| 5018 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5019 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 5020 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5021 | } |
| 5022 | } else { |
| 5023 | // Plain load with no read barrier. |
| 5024 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5025 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 5026 | __ MaybeUnpoisonHeapReference(out_reg); |
| 5027 | } |
| 5028 | } |
| 5029 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5030 | static inline int GetBakerMarkThunkNumber(GpuRegister reg) { |
| 5031 | static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 20, "Expecting equal"); |
| 5032 | if (reg >= V0 && reg <= T2) { // 13 consequtive regs. |
| 5033 | return reg - V0; |
| 5034 | } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs. |
| 5035 | return 13 + (reg - S2); |
| 5036 | } else if (reg == S8) { // One more. |
| 5037 | return 19; |
| 5038 | } |
| 5039 | LOG(FATAL) << "Unexpected register " << reg; |
| 5040 | UNREACHABLE(); |
| 5041 | } |
| 5042 | |
| 5043 | static inline int GetBakerMarkFieldArrayThunkDisplacement(GpuRegister reg, bool short_offset) { |
| 5044 | int num = GetBakerMarkThunkNumber(reg) + |
| 5045 | (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0); |
| 5046 | return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE; |
| 5047 | } |
| 5048 | |
| 5049 | static inline int GetBakerMarkGcRootThunkDisplacement(GpuRegister reg) { |
| 5050 | return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE + |
| 5051 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET; |
| 5052 | } |
| 5053 | |
| 5054 | void InstructionCodeGeneratorMIPS64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 5055 | Location root, |
| 5056 | GpuRegister obj, |
| 5057 | uint32_t offset, |
| 5058 | ReadBarrierOption read_barrier_option, |
| 5059 | Mips64Label* label_low) { |
| 5060 | if (label_low != nullptr) { |
| 5061 | DCHECK_EQ(offset, 0x5678u); |
| 5062 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5063 | GpuRegister root_reg = root.AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5064 | if (read_barrier_option == kWithReadBarrier) { |
| 5065 | DCHECK(kEmitCompilerReadBarrier); |
| 5066 | if (kUseBakerReadBarrier) { |
| 5067 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 5068 | // Baker's read barrier are used: |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5069 | if (kBakerReadBarrierThunksEnableForGcRoots) { |
| 5070 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5071 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 5072 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5073 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5074 | // vice versa. |
| 5075 | // |
| 5076 | // We use thunks for the slow path. That thunk checks the reference |
| 5077 | // and jumps to the entrypoint if needed. |
| 5078 | // |
| 5079 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5080 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5081 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5082 | // if (temp != nullptr) { |
| 5083 | // temp = &gc_root_thunk<root_reg> |
| 5084 | // root = temp(root) |
| 5085 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5086 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5087 | const int32_t entry_point_offset = |
| 5088 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5089 | const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg); |
| 5090 | int16_t offset_low = Low16Bits(offset); |
| 5091 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign |
| 5092 | // extension in lwu. |
| 5093 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 5094 | GpuRegister base = short_offset ? obj : TMP; |
| 5095 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5096 | // threads are suspended or running a checkpoint. |
| 5097 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 5098 | if (!short_offset) { |
| 5099 | DCHECK(!label_low); |
| 5100 | __ Daui(base, obj, offset_high); |
| 5101 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5102 | Mips64Label skip_call; |
| 5103 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5104 | if (label_low != nullptr) { |
| 5105 | DCHECK(short_offset); |
| 5106 | __ Bind(label_low); |
| 5107 | } |
| 5108 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5109 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, base, offset_low); // Single instruction |
| 5110 | // in delay slot. |
| 5111 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5112 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5113 | } else { |
| 5114 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5115 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 5116 | // load into `temp` (T9) the read barrier mark entry point corresponding |
| 5117 | // to register `root`. If `temp` is null, it means that `GetIsGcMarking()` |
| 5118 | // is false, and vice versa. |
| 5119 | // |
| 5120 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5121 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5122 | // if (temp != null) { |
| 5123 | // root = temp(root) |
| 5124 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5125 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5126 | if (label_low != nullptr) { |
| 5127 | __ Bind(label_low); |
| 5128 | } |
| 5129 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5130 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 5131 | static_assert( |
| 5132 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5133 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5134 | "have different sizes."); |
| 5135 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5136 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5137 | "have different sizes."); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5138 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5139 | // Slow path marking the GC root `root`. |
| 5140 | Location temp = Location::RegisterLocation(T9); |
| 5141 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5142 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64( |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5143 | instruction, |
| 5144 | root, |
| 5145 | /*entrypoint*/ temp); |
| 5146 | codegen_->AddSlowPath(slow_path); |
| 5147 | |
| 5148 | const int32_t entry_point_offset = |
| 5149 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(root.reg() - 1); |
| 5150 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5151 | // threads are suspended or running a checkpoint. |
| 5152 | __ LoadFromOffset(kLoadDoubleword, temp.AsRegister<GpuRegister>(), TR, entry_point_offset); |
| 5153 | __ Bnezc(temp.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 5154 | __ Bind(slow_path->GetExitLabel()); |
| 5155 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5156 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5157 | if (label_low != nullptr) { |
| 5158 | __ Bind(label_low); |
| 5159 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5160 | // GC root loaded through a slow path for read barriers other |
| 5161 | // than Baker's. |
| 5162 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 5163 | __ Daddiu64(root_reg, obj, static_cast<int32_t>(offset)); |
| 5164 | // /* mirror::Object* */ root = root->Read() |
| 5165 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5166 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5167 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5168 | if (label_low != nullptr) { |
| 5169 | __ Bind(label_low); |
| 5170 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5171 | // Plain GC root load with no read barrier. |
| 5172 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5173 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 5174 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5175 | // do not have to unpoison `root_reg` here. |
| 5176 | } |
| 5177 | } |
| 5178 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5179 | void CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5180 | Location ref, |
| 5181 | GpuRegister obj, |
| 5182 | uint32_t offset, |
| 5183 | Location temp, |
| 5184 | bool needs_null_check) { |
| 5185 | DCHECK(kEmitCompilerReadBarrier); |
| 5186 | DCHECK(kUseBakerReadBarrier); |
| 5187 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5188 | if (kBakerReadBarrierThunksEnableForFields) { |
| 5189 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5190 | // to decide whether to mark the loaded reference or not. Instead, we |
| 5191 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5192 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5193 | // vice versa. |
| 5194 | // |
| 5195 | // We use thunks for the slow path. That thunk checks the reference |
| 5196 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 5197 | // it issues a load-load memory barrier and returns to the original |
| 5198 | // reference load. |
| 5199 | // |
| 5200 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5201 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5202 | // if (temp != nullptr) { |
| 5203 | // temp = &field_array_thunk<holder_reg> |
| 5204 | // temp() |
| 5205 | // } |
| 5206 | // not_gray_return_address: |
| 5207 | // // If the offset is too large to fit into the lw instruction, we |
| 5208 | // // use an adjusted base register (TMP) here. This register |
| 5209 | // // receives bits 16 ... 31 of the offset before the thunk invocation |
| 5210 | // // and the thunk benefits from it. |
| 5211 | // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load. |
| 5212 | // gray_return_address: |
| 5213 | |
| 5214 | DCHECK(temp.IsInvalid()); |
| 5215 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 5216 | const int32_t entry_point_offset = |
| 5217 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5218 | // There may have or may have not been a null check if the field offset is smaller than |
| 5219 | // the page size. |
| 5220 | // There must've been a null check in case it's actually a load from an array. |
| 5221 | // We will, however, perform an explicit null check in the thunk as it's easier to |
| 5222 | // do it than not. |
| 5223 | if (instruction->IsArrayGet()) { |
| 5224 | DCHECK(!needs_null_check); |
| 5225 | } |
| 5226 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset); |
| 5227 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5228 | // threads are suspended or running a checkpoint. |
| 5229 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 5230 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5231 | Mips64Label skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5232 | if (short_offset) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5233 | __ Beqzc(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5234 | __ Nop(); // In forbidden slot. |
| 5235 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5236 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5237 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5238 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); // Single instruction. |
| 5239 | } else { |
| 5240 | int16_t offset_low = Low16Bits(offset); |
| 5241 | 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] | 5242 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5243 | __ Daui(TMP, obj, offset_high); // In delay slot. |
| 5244 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5245 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5246 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5247 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset_low); // Single instruction. |
| 5248 | } |
| 5249 | if (needs_null_check) { |
| 5250 | MaybeRecordImplicitNullCheck(instruction); |
| 5251 | } |
| 5252 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5253 | return; |
| 5254 | } |
| 5255 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5256 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5257 | Location no_index = Location::NoLocation(); |
| 5258 | ScaleFactor no_scale_factor = TIMES_1; |
| 5259 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5260 | ref, |
| 5261 | obj, |
| 5262 | offset, |
| 5263 | no_index, |
| 5264 | no_scale_factor, |
| 5265 | temp, |
| 5266 | needs_null_check); |
| 5267 | } |
| 5268 | |
| 5269 | void CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5270 | Location ref, |
| 5271 | GpuRegister obj, |
| 5272 | uint32_t data_offset, |
| 5273 | Location index, |
| 5274 | Location temp, |
| 5275 | bool needs_null_check) { |
| 5276 | DCHECK(kEmitCompilerReadBarrier); |
| 5277 | DCHECK(kUseBakerReadBarrier); |
| 5278 | |
| 5279 | static_assert( |
| 5280 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5281 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5282 | ScaleFactor scale_factor = TIMES_4; |
| 5283 | |
| 5284 | if (kBakerReadBarrierThunksEnableForArrays) { |
| 5285 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5286 | // to decide whether to mark the loaded reference or not. Instead, we |
| 5287 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5288 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5289 | // vice versa. |
| 5290 | // |
| 5291 | // We use thunks for the slow path. That thunk checks the reference |
| 5292 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 5293 | // it issues a load-load memory barrier and returns to the original |
| 5294 | // reference load. |
| 5295 | // |
| 5296 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5297 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5298 | // if (temp != nullptr) { |
| 5299 | // temp = &field_array_thunk<holder_reg> |
| 5300 | // temp() |
| 5301 | // } |
| 5302 | // not_gray_return_address: |
| 5303 | // // The element address is pre-calculated in the TMP register before the |
| 5304 | // // thunk invocation and the thunk benefits from it. |
| 5305 | // HeapReference<mirror::Object> reference = data[index]; // Original reference load. |
| 5306 | // gray_return_address: |
| 5307 | |
| 5308 | DCHECK(temp.IsInvalid()); |
| 5309 | DCHECK(index.IsValid()); |
| 5310 | const int32_t entry_point_offset = |
| 5311 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5312 | // We will not do the explicit null check in the thunk as some form of a null check |
| 5313 | // must've been done earlier. |
| 5314 | DCHECK(!needs_null_check); |
| 5315 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false); |
| 5316 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5317 | // threads are suspended or running a checkpoint. |
| 5318 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5319 | Mips64Label skip_call; |
| 5320 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5321 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
| 5322 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
| 5323 | __ Dlsa(TMP, index_reg, obj, scale_factor); // In delay slot. |
| 5324 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5325 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5326 | // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor)) |
| 5327 | DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset; |
| 5328 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, data_offset); // Single instruction. |
| 5329 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5330 | return; |
| 5331 | } |
| 5332 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5333 | // /* HeapReference<Object> */ ref = |
| 5334 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5335 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5336 | ref, |
| 5337 | obj, |
| 5338 | data_offset, |
| 5339 | index, |
| 5340 | scale_factor, |
| 5341 | temp, |
| 5342 | needs_null_check); |
| 5343 | } |
| 5344 | |
| 5345 | void CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5346 | Location ref, |
| 5347 | GpuRegister obj, |
| 5348 | uint32_t offset, |
| 5349 | Location index, |
| 5350 | ScaleFactor scale_factor, |
| 5351 | Location temp, |
| 5352 | bool needs_null_check, |
| 5353 | bool always_update_field) { |
| 5354 | DCHECK(kEmitCompilerReadBarrier); |
| 5355 | DCHECK(kUseBakerReadBarrier); |
| 5356 | |
| 5357 | // In slow path based read barriers, the read barrier call is |
| 5358 | // inserted after the original load. However, in fast path based |
| 5359 | // Baker's read barriers, we need to perform the load of |
| 5360 | // mirror::Object::monitor_ *before* the original reference load. |
| 5361 | // This load-load ordering is required by the read barrier. |
| 5362 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 5363 | // |
| 5364 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 5365 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 5366 | // HeapReference<Object> ref = *src; // Original reference load. |
| 5367 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 5368 | // if (is_gray) { |
| 5369 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 5370 | // } |
| 5371 | // |
| 5372 | // Note: the original implementation in ReadBarrier::Barrier is |
| 5373 | // slightly more complex as it performs additional checks that we do |
| 5374 | // not do here for performance reasons. |
| 5375 | |
| 5376 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
| 5377 | GpuRegister temp_reg = temp.AsRegister<GpuRegister>(); |
| 5378 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 5379 | |
| 5380 | // /* int32_t */ monitor = obj->monitor_ |
| 5381 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 5382 | if (needs_null_check) { |
| 5383 | MaybeRecordImplicitNullCheck(instruction); |
| 5384 | } |
| 5385 | // /* LockWord */ lock_word = LockWord(monitor) |
| 5386 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 5387 | "art::LockWord and int32_t have different sizes."); |
| 5388 | |
| 5389 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 5390 | |
| 5391 | // The actual reference load. |
| 5392 | if (index.IsValid()) { |
| 5393 | // Load types involving an "index": ArrayGet, |
| 5394 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 5395 | // intrinsics. |
| 5396 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 5397 | if (index.IsConstant()) { |
| 5398 | size_t computed_offset = |
| 5399 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 5400 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, computed_offset); |
| 5401 | } else { |
| 5402 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 5403 | if (scale_factor == TIMES_1) { |
| 5404 | __ Daddu(TMP, index_reg, obj); |
| 5405 | } else { |
| 5406 | __ Dlsa(TMP, index_reg, obj, scale_factor); |
| 5407 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5408 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset); |
| 5409 | } |
| 5410 | } else { |
| 5411 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5412 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); |
| 5413 | } |
| 5414 | |
| 5415 | // Object* ref = ref_addr->AsMirrorPtr() |
| 5416 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5417 | |
| 5418 | // Slow path marking the object `ref` when it is gray. |
| 5419 | SlowPathCodeMIPS64* slow_path; |
| 5420 | if (always_update_field) { |
| 5421 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 only supports address |
| 5422 | // of the form `obj + field_offset`, where `obj` is a register and |
| 5423 | // `field_offset` is a register. Thus `offset` and `scale_factor` |
| 5424 | // above are expected to be null in this code path. |
| 5425 | DCHECK_EQ(offset, 0u); |
| 5426 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5427 | slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5428 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(instruction, |
| 5429 | ref, |
| 5430 | obj, |
| 5431 | /* field_offset */ index, |
| 5432 | temp_reg); |
| 5433 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5434 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64(instruction, ref); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5435 | } |
| 5436 | AddSlowPath(slow_path); |
| 5437 | |
| 5438 | // if (rb_state == ReadBarrier::GrayState()) |
| 5439 | // ref = ReadBarrier::Mark(ref); |
| 5440 | // Given the numeric representation, it's enough to check the low bit of the |
| 5441 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 5442 | // performing a branch on less than zero. |
| 5443 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 5444 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 5445 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 5446 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 5447 | __ Bltzc(temp_reg, slow_path->GetEntryLabel()); |
| 5448 | __ Bind(slow_path->GetExitLabel()); |
| 5449 | } |
| 5450 | |
| 5451 | void CodeGeneratorMIPS64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 5452 | Location out, |
| 5453 | Location ref, |
| 5454 | Location obj, |
| 5455 | uint32_t offset, |
| 5456 | Location index) { |
| 5457 | DCHECK(kEmitCompilerReadBarrier); |
| 5458 | |
| 5459 | // Insert a slow path based read barrier *after* the reference load. |
| 5460 | // |
| 5461 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5462 | // reference will be carried out by the runtime within the slow |
| 5463 | // path. |
| 5464 | // |
| 5465 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5466 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5467 | // not used by the artReadBarrierSlow entry point. |
| 5468 | // |
| 5469 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5470 | SlowPathCodeMIPS64* slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5471 | ReadBarrierForHeapReferenceSlowPathMIPS64(instruction, out, ref, obj, offset, index); |
| 5472 | AddSlowPath(slow_path); |
| 5473 | |
| 5474 | __ Bc(slow_path->GetEntryLabel()); |
| 5475 | __ Bind(slow_path->GetExitLabel()); |
| 5476 | } |
| 5477 | |
| 5478 | void CodeGeneratorMIPS64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 5479 | Location out, |
| 5480 | Location ref, |
| 5481 | Location obj, |
| 5482 | uint32_t offset, |
| 5483 | Location index) { |
| 5484 | if (kEmitCompilerReadBarrier) { |
| 5485 | // Baker's read barriers shall be handled by the fast path |
| 5486 | // (CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier). |
| 5487 | DCHECK(!kUseBakerReadBarrier); |
| 5488 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5489 | // by the runtime within the slow path. |
| 5490 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 5491 | } else if (kPoisonHeapReferences) { |
| 5492 | __ UnpoisonHeapReference(out.AsRegister<GpuRegister>()); |
| 5493 | } |
| 5494 | } |
| 5495 | |
| 5496 | void CodeGeneratorMIPS64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 5497 | Location out, |
| 5498 | Location root) { |
| 5499 | DCHECK(kEmitCompilerReadBarrier); |
| 5500 | |
| 5501 | // Insert a slow path based read barrier *after* the GC root load. |
| 5502 | // |
| 5503 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5504 | // not need to do anything special for this here. |
| 5505 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5506 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS64(instruction, out, root); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5507 | AddSlowPath(slow_path); |
| 5508 | |
| 5509 | __ Bc(slow_path->GetEntryLabel()); |
| 5510 | __ Bind(slow_path->GetExitLabel()); |
| 5511 | } |
| 5512 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5513 | void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5514 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5515 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5516 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5517 | switch (type_check_kind) { |
| 5518 | case TypeCheckKind::kExactCheck: |
| 5519 | case TypeCheckKind::kAbstractClassCheck: |
| 5520 | case TypeCheckKind::kClassHierarchyCheck: |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5521 | case TypeCheckKind::kArrayObjectCheck: { |
| 5522 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 5523 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 5524 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5525 | break; |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5526 | } |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5527 | case TypeCheckKind::kArrayCheck: |
| 5528 | case TypeCheckKind::kUnresolvedCheck: |
| 5529 | case TypeCheckKind::kInterfaceCheck: |
| 5530 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5531 | break; |
| 5532 | } |
| 5533 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5534 | LocationSummary* locations = |
| 5535 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5536 | if (baker_read_barrier_slow_path) { |
| 5537 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5538 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5539 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 5540 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5541 | // The output does overlap inputs. |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5542 | // Note that TypeCheckSlowPathMIPS64 uses this register too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5543 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5544 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5545 | } |
| 5546 | |
| 5547 | void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5548 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5549 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5550 | Location obj_loc = locations->InAt(0); |
| 5551 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 5552 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5553 | Location out_loc = locations->Out(); |
| 5554 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 5555 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 5556 | DCHECK_LE(num_temps, 1u); |
| 5557 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5558 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5559 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5560 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5561 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5562 | Mips64Label done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5563 | SlowPathCodeMIPS64* slow_path = nullptr; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5564 | |
| 5565 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5566 | // Avoid this check if we know `obj` is not null. |
| 5567 | if (instruction->MustDoNullCheck()) { |
| 5568 | __ Move(out, ZERO); |
| 5569 | __ Beqzc(obj, &done); |
| 5570 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5571 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5572 | switch (type_check_kind) { |
| 5573 | case TypeCheckKind::kExactCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5574 | ReadBarrierOption read_barrier_option = |
| 5575 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5576 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5577 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5578 | out_loc, |
| 5579 | obj_loc, |
| 5580 | class_offset, |
| 5581 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5582 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5583 | // Classes must be equal for the instanceof to succeed. |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 5584 | __ Xor(out, out, cls); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5585 | __ Sltiu(out, out, 1); |
| 5586 | break; |
| 5587 | } |
| 5588 | |
| 5589 | case TypeCheckKind::kAbstractClassCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5590 | ReadBarrierOption read_barrier_option = |
| 5591 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5592 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5593 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5594 | out_loc, |
| 5595 | obj_loc, |
| 5596 | class_offset, |
| 5597 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5598 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5599 | // If the class is abstract, we eagerly fetch the super class of the |
| 5600 | // object to avoid doing a comparison we know will fail. |
| 5601 | Mips64Label loop; |
| 5602 | __ Bind(&loop); |
| 5603 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5604 | GenerateReferenceLoadOneRegister(instruction, |
| 5605 | out_loc, |
| 5606 | super_offset, |
| 5607 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5608 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5609 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5610 | __ Beqzc(out, &done); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 5611 | __ Bnec(out, cls, &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5612 | __ LoadConst32(out, 1); |
| 5613 | break; |
| 5614 | } |
| 5615 | |
| 5616 | case TypeCheckKind::kClassHierarchyCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5617 | ReadBarrierOption read_barrier_option = |
| 5618 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5619 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5620 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5621 | out_loc, |
| 5622 | obj_loc, |
| 5623 | class_offset, |
| 5624 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5625 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5626 | // Walk over the class hierarchy to find a match. |
| 5627 | Mips64Label loop, success; |
| 5628 | __ Bind(&loop); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 5629 | __ Beqc(out, cls, &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5630 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5631 | GenerateReferenceLoadOneRegister(instruction, |
| 5632 | out_loc, |
| 5633 | super_offset, |
| 5634 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5635 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5636 | __ Bnezc(out, &loop); |
| 5637 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5638 | __ Bc(&done); |
| 5639 | __ Bind(&success); |
| 5640 | __ LoadConst32(out, 1); |
| 5641 | break; |
| 5642 | } |
| 5643 | |
| 5644 | case TypeCheckKind::kArrayObjectCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5645 | ReadBarrierOption read_barrier_option = |
| 5646 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5647 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5648 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5649 | out_loc, |
| 5650 | obj_loc, |
| 5651 | class_offset, |
| 5652 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5653 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5654 | // Do an exact check. |
| 5655 | Mips64Label success; |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 5656 | __ Beqc(out, cls, &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5657 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 5658 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5659 | GenerateReferenceLoadOneRegister(instruction, |
| 5660 | out_loc, |
| 5661 | component_offset, |
| 5662 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5663 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5664 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5665 | __ Beqzc(out, &done); |
| 5666 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5667 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5668 | __ Sltiu(out, out, 1); |
| 5669 | __ Bc(&done); |
| 5670 | __ Bind(&success); |
| 5671 | __ LoadConst32(out, 1); |
| 5672 | break; |
| 5673 | } |
| 5674 | |
| 5675 | case TypeCheckKind::kArrayCheck: { |
| 5676 | // No read barrier since the slow path will retry upon failure. |
| 5677 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5678 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5679 | out_loc, |
| 5680 | obj_loc, |
| 5681 | class_offset, |
| 5682 | maybe_temp_loc, |
| 5683 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5684 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5685 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( |
| 5686 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5687 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 5688 | __ Bnec(out, cls, slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5689 | __ LoadConst32(out, 1); |
| 5690 | break; |
| 5691 | } |
| 5692 | |
| 5693 | case TypeCheckKind::kUnresolvedCheck: |
| 5694 | case TypeCheckKind::kInterfaceCheck: { |
| 5695 | // Note that we indeed only call on slow path, but we always go |
| 5696 | // into the slow path for the unresolved and interface check |
| 5697 | // cases. |
| 5698 | // |
| 5699 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5700 | // entry point without resorting to a type checking slow path |
| 5701 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5702 | // require to assign fixed registers for the inputs of this |
| 5703 | // HInstanceOf instruction (following the runtime calling |
| 5704 | // convention), which might be cluttered by the potential first |
| 5705 | // read barrier emission at the beginning of this method. |
| 5706 | // |
| 5707 | // TODO: Introduce a new runtime entry point taking the object |
| 5708 | // to test (instead of its class) as argument, and let it deal |
| 5709 | // with the read barrier issues. This will let us refactor this |
| 5710 | // case of the `switch` code as it was previously (with a direct |
| 5711 | // call to the runtime not using a type checking slow path). |
| 5712 | // This should also be beneficial for the other cases above. |
| 5713 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5714 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( |
| 5715 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5716 | codegen_->AddSlowPath(slow_path); |
| 5717 | __ Bc(slow_path->GetEntryLabel()); |
| 5718 | break; |
| 5719 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5720 | } |
| 5721 | |
| 5722 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5723 | |
| 5724 | if (slow_path != nullptr) { |
| 5725 | __ Bind(slow_path->GetExitLabel()); |
| 5726 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5727 | } |
| 5728 | |
| 5729 | void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5730 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5731 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5732 | } |
| 5733 | |
| 5734 | void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 5735 | // Will be generated at use site. |
| 5736 | } |
| 5737 | |
| 5738 | void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5739 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5740 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5741 | } |
| 5742 | |
| 5743 | void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 5744 | // Will be generated at use site. |
| 5745 | } |
| 5746 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 5747 | void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 5748 | // The trampoline uses the same calling convention as dex calling conventions, |
| 5749 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 5750 | // the method_idx. |
| 5751 | HandleInvoke(invoke); |
| 5752 | } |
| 5753 | |
| 5754 | void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 5755 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 5756 | } |
| 5757 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5758 | void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) { |
| 5759 | InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor; |
| 5760 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 5761 | } |
| 5762 | |
| 5763 | void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5764 | HandleInvoke(invoke); |
| 5765 | // The register T0 is required to be used for the hidden argument in |
| 5766 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
| 5767 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); |
| 5768 | } |
| 5769 | |
| 5770 | void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5771 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 5772 | GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5773 | Location receiver = invoke->GetLocations()->InAt(0); |
| 5774 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5775 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5776 | |
| 5777 | // Set the hidden argument. |
| 5778 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(), |
| 5779 | invoke->GetDexMethodIndex()); |
| 5780 | |
| 5781 | // temp = object->GetClass(); |
| 5782 | if (receiver.IsStackSlot()) { |
| 5783 | __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex()); |
| 5784 | __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset); |
| 5785 | } else { |
| 5786 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset); |
| 5787 | } |
| 5788 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5789 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5790 | // emit a read barrier for the previous class reference load. |
| 5791 | // However this is not required in practice, as this is an |
| 5792 | // intermediate/temporary reference and because the current |
| 5793 | // concurrent copying collector keeps the from-space memory |
| 5794 | // intact/accessible until the end of the marking phase (the |
| 5795 | // concurrent copying collector may not in the future). |
| 5796 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5797 | __ LoadFromOffset(kLoadDoubleword, temp, temp, |
| 5798 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 5799 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5800 | invoke->GetImtIndex(), kMips64PointerSize)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5801 | // temp = temp->GetImtEntryAt(method_offset); |
| 5802 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 5803 | // T9 = temp->GetEntryPoint(); |
| 5804 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 5805 | // T9(); |
| 5806 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5807 | __ Nop(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5808 | DCHECK(!codegen_->IsLeafMethod()); |
| 5809 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5810 | } |
| 5811 | |
| 5812 | void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5813 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 5814 | if (intrinsic.TryDispatch(invoke)) { |
| 5815 | return; |
| 5816 | } |
| 5817 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5818 | HandleInvoke(invoke); |
| 5819 | } |
| 5820 | |
| 5821 | void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5822 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5823 | // art::PrepareForRegisterAllocation. |
| 5824 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5825 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5826 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 5827 | if (intrinsic.TryDispatch(invoke)) { |
| 5828 | return; |
| 5829 | } |
| 5830 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5831 | HandleInvoke(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5832 | } |
| 5833 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 5834 | void LocationsBuilderMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5835 | HandleInvoke(invoke); |
| 5836 | } |
| 5837 | |
| 5838 | void InstructionCodeGeneratorMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5839 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 5840 | } |
| 5841 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5842 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5843 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5844 | IntrinsicCodeGeneratorMIPS64 intrinsic(codegen); |
| 5845 | intrinsic.Dispatch(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5846 | return true; |
| 5847 | } |
| 5848 | return false; |
| 5849 | } |
| 5850 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5851 | HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind( |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5852 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5853 | bool fallback_load = false; |
| 5854 | switch (desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5855 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame^] | 5856 | case HLoadString::LoadKind::kBootImageRelRo: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5857 | case HLoadString::LoadKind::kBssEntry: |
| 5858 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5859 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5860 | case HLoadString::LoadKind::kJitTableAddress: |
| 5861 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5862 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5863 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5864 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5865 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5866 | } |
| 5867 | if (fallback_load) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5868 | desired_string_load_kind = HLoadString::LoadKind::kRuntimeCall; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5869 | } |
| 5870 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5871 | } |
| 5872 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5873 | HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind( |
| 5874 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5875 | bool fallback_load = false; |
| 5876 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5877 | case HLoadClass::LoadKind::kInvalid: |
| 5878 | LOG(FATAL) << "UNREACHABLE"; |
| 5879 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5880 | case HLoadClass::LoadKind::kReferrersClass: |
| 5881 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5882 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame^] | 5883 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5884 | case HLoadClass::LoadKind::kBssEntry: |
| 5885 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5886 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5887 | case HLoadClass::LoadKind::kJitTableAddress: |
| 5888 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5889 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5890 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5891 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5892 | break; |
| 5893 | } |
| 5894 | if (fallback_load) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5895 | desired_class_load_kind = HLoadClass::LoadKind::kRuntimeCall; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5896 | } |
| 5897 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5898 | } |
| 5899 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5900 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch( |
| 5901 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5902 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5903 | // On MIPS64 we support all dispatch types. |
| 5904 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5905 | } |
| 5906 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5907 | void CodeGeneratorMIPS64::GenerateStaticOrDirectCall( |
| 5908 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5909 | // 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] | 5910 | 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] | 5911 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 5912 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
| 5913 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5914 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5915 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5916 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5917 | uint32_t offset = |
| 5918 | GetThreadOffset<kMips64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5919 | __ LoadFromOffset(kLoadDoubleword, |
| 5920 | temp.AsRegister<GpuRegister>(), |
| 5921 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5922 | offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5923 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5924 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5925 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5926 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5927 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5928 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 5929 | DCHECK(GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5930 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5931 | NewBootImageMethodPatch(invoke->GetTargetMethod()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5932 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5933 | NewBootImageMethodPatch(invoke->GetTargetMethod(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5934 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5935 | __ Daddiu(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 5936 | break; |
| 5937 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5938 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5939 | __ LoadLiteral(temp.AsRegister<GpuRegister>(), |
| 5940 | kLoadDoubleword, |
| 5941 | DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5942 | break; |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5943 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame^] | 5944 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5945 | PcRelativePatchInfo* info_high = NewBootImageRelRoPatch(boot_image_offset); |
| 5946 | PcRelativePatchInfo* info_low = NewBootImageRelRoPatch(boot_image_offset, info_high); |
| 5947 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 5948 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 5949 | __ Lwu(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 5950 | break; |
| 5951 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5952 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5953 | PcRelativePatchInfo* info_high = NewMethodBssEntryPatch( |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5954 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5955 | PcRelativePatchInfo* info_low = NewMethodBssEntryPatch( |
| 5956 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high); |
| 5957 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5958 | __ Ld(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 5959 | break; |
| 5960 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5961 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 5962 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 5963 | return; // No code pointer retrieval; the runtime performs the call directly. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5964 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5965 | } |
| 5966 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5967 | switch (code_ptr_location) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5968 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5969 | __ Balc(&frame_entry_label_); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5970 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5971 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 5972 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
| 5973 | __ LoadFromOffset(kLoadDoubleword, |
| 5974 | T9, |
| 5975 | callee_method.AsRegister<GpuRegister>(), |
| 5976 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5977 | kMips64PointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5978 | // T9() |
| 5979 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5980 | __ Nop(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5981 | break; |
| 5982 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5983 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 5984 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5985 | DCHECK(!IsLeafMethod()); |
| 5986 | } |
| 5987 | |
| 5988 | void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5989 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5990 | // art::PrepareForRegisterAllocation. |
| 5991 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5992 | |
| 5993 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5994 | return; |
| 5995 | } |
| 5996 | |
| 5997 | LocationSummary* locations = invoke->GetLocations(); |
| 5998 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 5999 | locations->HasTemps() |
| 6000 | ? locations->GetTemp(0) |
| 6001 | : Location::NoLocation()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6002 | } |
| 6003 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 6004 | void CodeGeneratorMIPS64::GenerateVirtualCall( |
| 6005 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6006 | // Use the calling convention instead of the location of the receiver, as |
| 6007 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 6008 | // slow path, the arguments have been moved to the right place, so here we are |
| 6009 | // guaranteed that the receiver is the first register of the calling convention. |
| 6010 | InvokeDexCallingConvention calling_convention; |
| 6011 | GpuRegister receiver = calling_convention.GetRegisterAt(0); |
| 6012 | |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 6013 | GpuRegister temp = temp_location.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6014 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 6015 | invoke->GetVTableIndex(), kMips64PointerSize).SizeValue(); |
| 6016 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6017 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6018 | |
| 6019 | // temp = object->GetClass(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6020 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 6021 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6022 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 6023 | // emit a read barrier for the previous class reference load. |
| 6024 | // However this is not required in practice, as this is an |
| 6025 | // intermediate/temporary reference and because the current |
| 6026 | // concurrent copying collector keeps the from-space memory |
| 6027 | // intact/accessible until the end of the marking phase (the |
| 6028 | // concurrent copying collector may not in the future). |
| 6029 | __ MaybeUnpoisonHeapReference(temp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6030 | // temp = temp->GetMethodAt(method_offset); |
| 6031 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 6032 | // T9 = temp->GetEntryPoint(); |
| 6033 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 6034 | // T9(); |
| 6035 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 6036 | __ Nop(); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 6037 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 6038 | } |
| 6039 | |
| 6040 | void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 6041 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 6042 | return; |
| 6043 | } |
| 6044 | |
| 6045 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6046 | DCHECK(!codegen_->IsLeafMethod()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6047 | } |
| 6048 | |
| 6049 | void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6050 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6051 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6052 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6053 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6054 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6055 | return; |
| 6056 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6057 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6058 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6059 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6060 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6061 | ? LocationSummary::kCallOnSlowPath |
| 6062 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6063 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6064 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 6065 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 6066 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6067 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6068 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6069 | } |
| 6070 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6071 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6072 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6073 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 6074 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6075 | InvokeRuntimeCallingConvention calling_convention; |
| 6076 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6077 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6078 | } else { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6079 | // For non-Baker read barriers we have a temp-clobbering call. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6080 | } |
| 6081 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6082 | } |
| 6083 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6084 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6085 | // move. |
| 6086 | void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6087 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6088 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6089 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6090 | return; |
| 6091 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6092 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6093 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6094 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6095 | Location out_loc = locations->Out(); |
| 6096 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 6097 | GpuRegister current_method_reg = ZERO; |
| 6098 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6099 | load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6100 | current_method_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6101 | } |
| 6102 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6103 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6104 | ? kWithoutReadBarrier |
| 6105 | : kCompilerReadBarrierOption; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6106 | bool generate_null_check = false; |
| 6107 | switch (load_kind) { |
| 6108 | case HLoadClass::LoadKind::kReferrersClass: |
| 6109 | DCHECK(!cls->CanCallRuntime()); |
| 6110 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6111 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6112 | GenerateGcRootFieldLoad(cls, |
| 6113 | out_loc, |
| 6114 | current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6115 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 6116 | read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6117 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6118 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6119 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6120 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6121 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6122 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6123 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6124 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6125 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6126 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
| 6127 | break; |
| 6128 | } |
| 6129 | case HLoadClass::LoadKind::kBootImageAddress: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6130 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6131 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6132 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6133 | DCHECK_NE(address, 0u); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6134 | __ LoadLiteral(out, |
| 6135 | kLoadUnsignedWord, |
| 6136 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6137 | break; |
| 6138 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame^] | 6139 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6140 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame^] | 6141 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6142 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame^] | 6143 | codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6144 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame^] | 6145 | codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6146 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 6147 | __ Lwu(out, AT, /* placeholder */ 0x5678); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6148 | break; |
| 6149 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6150 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6151 | CodeGeneratorMIPS64::PcRelativePatchInfo* bss_info_high = |
| 6152 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6153 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6154 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6155 | codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, out); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6156 | GenerateGcRootFieldLoad(cls, |
| 6157 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6158 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6159 | /* placeholder */ 0x5678, |
| 6160 | read_barrier_option, |
| 6161 | &info_low->label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6162 | generate_null_check = true; |
| 6163 | break; |
| 6164 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6165 | case HLoadClass::LoadKind::kJitTableAddress: |
| 6166 | __ LoadLiteral(out, |
| 6167 | kLoadUnsignedWord, |
| 6168 | codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6169 | cls->GetTypeIndex(), |
| 6170 | cls->GetClass())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6171 | GenerateGcRootFieldLoad(cls, out_loc, out, 0, read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6172 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6173 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6174 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6175 | LOG(FATAL) << "UNREACHABLE"; |
| 6176 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6177 | } |
| 6178 | |
| 6179 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6180 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6181 | SlowPathCodeMIPS64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64( |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6182 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6183 | codegen_->AddSlowPath(slow_path); |
| 6184 | if (generate_null_check) { |
| 6185 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 6186 | } |
| 6187 | if (cls->MustGenerateClinitCheck()) { |
| 6188 | GenerateClassInitializationCheck(slow_path, out); |
| 6189 | } else { |
| 6190 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6191 | } |
| 6192 | } |
| 6193 | } |
| 6194 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6195 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6196 | return Thread::ExceptionOffset<kMips64PointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6197 | } |
| 6198 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6199 | void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) { |
| 6200 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6201 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6202 | locations->SetOut(Location::RequiresRegister()); |
| 6203 | } |
| 6204 | |
| 6205 | void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) { |
| 6206 | GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6207 | __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset()); |
| 6208 | } |
| 6209 | |
| 6210 | void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6211 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6212 | } |
| 6213 | |
| 6214 | void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6215 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6216 | } |
| 6217 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6218 | void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6219 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6220 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6221 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6222 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6223 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6224 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6225 | } else { |
| 6226 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6227 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6228 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6229 | // Rely on the pResolveString and marking to save everything we need. |
| 6230 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6231 | InvokeRuntimeCallingConvention calling_convention; |
| 6232 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6233 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6234 | } else { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6235 | // For non-Baker read barriers we have a temp-clobbering call. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6236 | } |
| 6237 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6238 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6239 | } |
| 6240 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6241 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6242 | // move. |
| 6243 | void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6244 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6245 | LocationSummary* locations = load->GetLocations(); |
| 6246 | Location out_loc = locations->Out(); |
| 6247 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 6248 | |
| 6249 | switch (load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6250 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6251 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6252 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6253 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6254 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6255 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6256 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6257 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6258 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6259 | } |
| 6260 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6261 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6262 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6263 | DCHECK_NE(address, 0u); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6264 | __ LoadLiteral(out, |
| 6265 | kLoadUnsignedWord, |
| 6266 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6267 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6268 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame^] | 6269 | case HLoadString::LoadKind::kBootImageRelRo: { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6270 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame^] | 6271 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(load); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6272 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame^] | 6273 | codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6274 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame^] | 6275 | codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6276 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 6277 | __ Lwu(out, AT, /* placeholder */ 0x5678); |
| 6278 | return; |
| 6279 | } |
| 6280 | case HLoadString::LoadKind::kBssEntry: { |
| 6281 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6282 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
| 6283 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| 6284 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6285 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6286 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, out); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6287 | GenerateGcRootFieldLoad(load, |
| 6288 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6289 | out, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6290 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6291 | kCompilerReadBarrierOption, |
| 6292 | &info_low->label); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6293 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6294 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS64(load); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6295 | codegen_->AddSlowPath(slow_path); |
| 6296 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 6297 | __ Bind(slow_path->GetExitLabel()); |
| 6298 | return; |
| 6299 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6300 | case HLoadString::LoadKind::kJitTableAddress: |
| 6301 | __ LoadLiteral(out, |
| 6302 | kLoadUnsignedWord, |
| 6303 | codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
| 6304 | load->GetStringIndex(), |
| 6305 | load->GetString())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6306 | GenerateGcRootFieldLoad(load, out_loc, out, 0, kCompilerReadBarrierOption); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6307 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6308 | default: |
| 6309 | break; |
| 6310 | } |
| 6311 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6312 | // 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] | 6313 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6314 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6315 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6316 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
| 6317 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6318 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6319 | } |
| 6320 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6321 | void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6322 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6323 | locations->SetOut(Location::ConstantLocation(constant)); |
| 6324 | } |
| 6325 | |
| 6326 | void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 6327 | // Will be generated at use site. |
| 6328 | } |
| 6329 | |
| 6330 | void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6331 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6332 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6333 | InvokeRuntimeCallingConvention calling_convention; |
| 6334 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6335 | } |
| 6336 | |
| 6337 | void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6338 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6339 | instruction, |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6340 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6341 | if (instruction->IsEnter()) { |
| 6342 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6343 | } else { |
| 6344 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6345 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6346 | } |
| 6347 | |
| 6348 | void LocationsBuilderMIPS64::VisitMul(HMul* mul) { |
| 6349 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6350 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6351 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6352 | case DataType::Type::kInt32: |
| 6353 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6354 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6355 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6356 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6357 | break; |
| 6358 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6359 | case DataType::Type::kFloat32: |
| 6360 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6361 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6362 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 6363 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6364 | break; |
| 6365 | |
| 6366 | default: |
| 6367 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 6368 | } |
| 6369 | } |
| 6370 | |
| 6371 | void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6372 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6373 | LocationSummary* locations = instruction->GetLocations(); |
| 6374 | |
| 6375 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6376 | case DataType::Type::kInt32: |
| 6377 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6378 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6379 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6380 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6381 | if (type == DataType::Type::kInt32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6382 | __ MulR6(dst, lhs, rhs); |
| 6383 | else |
| 6384 | __ Dmul(dst, lhs, rhs); |
| 6385 | break; |
| 6386 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6387 | case DataType::Type::kFloat32: |
| 6388 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6389 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6390 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 6391 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6392 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6393 | __ MulS(dst, lhs, rhs); |
| 6394 | else |
| 6395 | __ MulD(dst, lhs, rhs); |
| 6396 | break; |
| 6397 | } |
| 6398 | default: |
| 6399 | LOG(FATAL) << "Unexpected mul type " << type; |
| 6400 | } |
| 6401 | } |
| 6402 | |
| 6403 | void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) { |
| 6404 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6405 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6406 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6407 | case DataType::Type::kInt32: |
| 6408 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6409 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6410 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6411 | break; |
| 6412 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6413 | case DataType::Type::kFloat32: |
| 6414 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6415 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6416 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6417 | break; |
| 6418 | |
| 6419 | default: |
| 6420 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 6421 | } |
| 6422 | } |
| 6423 | |
| 6424 | void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6425 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6426 | LocationSummary* locations = instruction->GetLocations(); |
| 6427 | |
| 6428 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6429 | case DataType::Type::kInt32: |
| 6430 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6431 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6432 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6433 | if (type == DataType::Type::kInt32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6434 | __ Subu(dst, ZERO, src); |
| 6435 | else |
| 6436 | __ Dsubu(dst, ZERO, src); |
| 6437 | break; |
| 6438 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6439 | case DataType::Type::kFloat32: |
| 6440 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6441 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6442 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6443 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6444 | __ NegS(dst, src); |
| 6445 | else |
| 6446 | __ NegD(dst, src); |
| 6447 | break; |
| 6448 | } |
| 6449 | default: |
| 6450 | LOG(FATAL) << "Unexpected neg type " << type; |
| 6451 | } |
| 6452 | } |
| 6453 | |
| 6454 | void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6455 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6456 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6457 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6458 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6459 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6460 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6461 | } |
| 6462 | |
| 6463 | void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6464 | // Note: if heap poisoning is enabled, the entry point takes care |
| 6465 | // of poisoning the reference. |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 6466 | QuickEntrypointEnum entrypoint = |
| 6467 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 6468 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6469 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 6470 | DCHECK(!codegen_->IsLeafMethod()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6471 | } |
| 6472 | |
| 6473 | void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6474 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6475 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6476 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6477 | if (instruction->IsStringAlloc()) { |
| 6478 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6479 | } else { |
| 6480 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6481 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6482 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6483 | } |
| 6484 | |
| 6485 | void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6486 | // Note: if heap poisoning is enabled, the entry point takes care |
| 6487 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6488 | if (instruction->IsStringAlloc()) { |
| 6489 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 6490 | GpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 6491 | MemberOffset code_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6492 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6493 | __ LoadFromOffset(kLoadDoubleword, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 6494 | __ LoadFromOffset(kLoadDoubleword, T9, temp, code_offset.Int32Value()); |
| 6495 | __ Jalr(T9); |
| 6496 | __ Nop(); |
| 6497 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 6498 | } else { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6499 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 6500 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6501 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6502 | } |
| 6503 | |
| 6504 | void LocationsBuilderMIPS64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6505 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6506 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6507 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6508 | } |
| 6509 | |
| 6510 | void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6511 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6512 | LocationSummary* locations = instruction->GetLocations(); |
| 6513 | |
| 6514 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6515 | case DataType::Type::kInt32: |
| 6516 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6517 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6518 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6519 | __ Nor(dst, src, ZERO); |
| 6520 | break; |
| 6521 | } |
| 6522 | |
| 6523 | default: |
| 6524 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 6525 | } |
| 6526 | } |
| 6527 | |
| 6528 | void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6529 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6530 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6531 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6532 | } |
| 6533 | |
| 6534 | void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
| 6535 | LocationSummary* locations = instruction->GetLocations(); |
| 6536 | __ Xori(locations->Out().AsRegister<GpuRegister>(), |
| 6537 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 6538 | 1); |
| 6539 | } |
| 6540 | |
| 6541 | void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6542 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 6543 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6544 | } |
| 6545 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6546 | void CodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6547 | if (CanMoveNullCheckToUser(instruction)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6548 | return; |
| 6549 | } |
| 6550 | Location obj = instruction->GetLocations()->InAt(0); |
| 6551 | |
| 6552 | __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6553 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6554 | } |
| 6555 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6556 | void CodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6557 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6558 | new (GetScopedAllocator()) NullCheckSlowPathMIPS64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6559 | AddSlowPath(slow_path); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6560 | |
| 6561 | Location obj = instruction->GetLocations()->InAt(0); |
| 6562 | |
| 6563 | __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 6564 | } |
| 6565 | |
| 6566 | void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6567 | codegen_->GenerateNullCheck(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6568 | } |
| 6569 | |
| 6570 | void LocationsBuilderMIPS64::VisitOr(HOr* instruction) { |
| 6571 | HandleBinaryOp(instruction); |
| 6572 | } |
| 6573 | |
| 6574 | void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) { |
| 6575 | HandleBinaryOp(instruction); |
| 6576 | } |
| 6577 | |
| 6578 | void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6579 | LOG(FATAL) << "Unreachable"; |
| 6580 | } |
| 6581 | |
| 6582 | void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6583 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6584 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6585 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6586 | // The back edge will generate the suspend check. |
| 6587 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6588 | } |
| 6589 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6590 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6591 | } |
| 6592 | |
| 6593 | void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6594 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6595 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 6596 | if (location.IsStackSlot()) { |
| 6597 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6598 | } else if (location.IsDoubleStackSlot()) { |
| 6599 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6600 | } |
| 6601 | locations->SetOut(location); |
| 6602 | } |
| 6603 | |
| 6604 | void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction |
| 6605 | ATTRIBUTE_UNUSED) { |
| 6606 | // Nothing to do, the parameter is already at its location. |
| 6607 | } |
| 6608 | |
| 6609 | void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 6610 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6611 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6612 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6613 | } |
| 6614 | |
| 6615 | void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction |
| 6616 | ATTRIBUTE_UNUSED) { |
| 6617 | // Nothing to do, the method is already at its location. |
| 6618 | } |
| 6619 | |
| 6620 | void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6621 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6622 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6623 | locations->SetInAt(i, Location::Any()); |
| 6624 | } |
| 6625 | locations->SetOut(Location::Any()); |
| 6626 | } |
| 6627 | |
| 6628 | void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 6629 | LOG(FATAL) << "Unreachable"; |
| 6630 | } |
| 6631 | |
| 6632 | void LocationsBuilderMIPS64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6633 | DataType::Type type = rem->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6634 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6635 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 6636 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6637 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6638 | |
| 6639 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6640 | case DataType::Type::kInt32: |
| 6641 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6642 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 6643 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6644 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6645 | break; |
| 6646 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6647 | case DataType::Type::kFloat32: |
| 6648 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6649 | InvokeRuntimeCallingConvention calling_convention; |
| 6650 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 6651 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 6652 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 6653 | break; |
| 6654 | } |
| 6655 | |
| 6656 | default: |
| 6657 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6658 | } |
| 6659 | } |
| 6660 | |
| 6661 | void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6662 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6663 | |
| 6664 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6665 | case DataType::Type::kInt32: |
| 6666 | case DataType::Type::kInt64: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 6667 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6668 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6669 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6670 | case DataType::Type::kFloat32: |
| 6671 | case DataType::Type::kFloat64: { |
| 6672 | QuickEntrypointEnum entrypoint = |
| 6673 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6674 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6675 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6676 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 6677 | } else { |
| 6678 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 6679 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6680 | break; |
| 6681 | } |
| 6682 | default: |
| 6683 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6684 | } |
| 6685 | } |
| 6686 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 6687 | void LocationsBuilderMIPS64::VisitAbs(HAbs* abs) { |
| 6688 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 6689 | switch (abs->GetResultType()) { |
| 6690 | case DataType::Type::kInt32: |
| 6691 | case DataType::Type::kInt64: |
| 6692 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6693 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6694 | break; |
| 6695 | case DataType::Type::kFloat32: |
| 6696 | case DataType::Type::kFloat64: |
| 6697 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6698 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6699 | break; |
| 6700 | default: |
| 6701 | LOG(FATAL) << "Unexpected abs type " << abs->GetResultType(); |
| 6702 | } |
| 6703 | } |
| 6704 | |
| 6705 | void InstructionCodeGeneratorMIPS64::VisitAbs(HAbs* abs) { |
| 6706 | LocationSummary* locations = abs->GetLocations(); |
| 6707 | switch (abs->GetResultType()) { |
| 6708 | case DataType::Type::kInt32: { |
| 6709 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6710 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 6711 | __ Sra(AT, in, 31); |
| 6712 | __ Xor(out, in, AT); |
| 6713 | __ Subu(out, out, AT); |
| 6714 | break; |
| 6715 | } |
| 6716 | case DataType::Type::kInt64: { |
| 6717 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6718 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 6719 | __ Dsra32(AT, in, 31); |
| 6720 | __ Xor(out, in, AT); |
| 6721 | __ Dsubu(out, out, AT); |
| 6722 | break; |
| 6723 | } |
| 6724 | case DataType::Type::kFloat32: { |
| 6725 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 6726 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6727 | __ AbsS(out, in); |
| 6728 | break; |
| 6729 | } |
| 6730 | case DataType::Type::kFloat64: { |
| 6731 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 6732 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6733 | __ AbsD(out, in); |
| 6734 | break; |
| 6735 | } |
| 6736 | default: |
| 6737 | LOG(FATAL) << "Unexpected abs type " << abs->GetResultType(); |
| 6738 | } |
| 6739 | } |
| 6740 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6741 | void LocationsBuilderMIPS64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 6742 | constructor_fence->SetLocations(nullptr); |
| 6743 | } |
| 6744 | |
| 6745 | void InstructionCodeGeneratorMIPS64::VisitConstructorFence( |
| 6746 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 6747 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 6748 | } |
| 6749 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6750 | void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6751 | memory_barrier->SetLocations(nullptr); |
| 6752 | } |
| 6753 | |
| 6754 | void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6755 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 6756 | } |
| 6757 | |
| 6758 | void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6759 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6760 | DataType::Type return_type = ret->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6761 | locations->SetInAt(0, Mips64ReturnLocation(return_type)); |
| 6762 | } |
| 6763 | |
| 6764 | void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 6765 | codegen_->GenerateFrameExit(); |
| 6766 | } |
| 6767 | |
| 6768 | void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) { |
| 6769 | ret->SetLocations(nullptr); |
| 6770 | } |
| 6771 | |
| 6772 | void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 6773 | codegen_->GenerateFrameExit(); |
| 6774 | } |
| 6775 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6776 | void LocationsBuilderMIPS64::VisitRor(HRor* ror) { |
| 6777 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6778 | } |
| 6779 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6780 | void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) { |
| 6781 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6782 | } |
| 6783 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6784 | void LocationsBuilderMIPS64::VisitShl(HShl* shl) { |
| 6785 | HandleShift(shl); |
| 6786 | } |
| 6787 | |
| 6788 | void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) { |
| 6789 | HandleShift(shl); |
| 6790 | } |
| 6791 | |
| 6792 | void LocationsBuilderMIPS64::VisitShr(HShr* shr) { |
| 6793 | HandleShift(shr); |
| 6794 | } |
| 6795 | |
| 6796 | void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) { |
| 6797 | HandleShift(shr); |
| 6798 | } |
| 6799 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6800 | void LocationsBuilderMIPS64::VisitSub(HSub* instruction) { |
| 6801 | HandleBinaryOp(instruction); |
| 6802 | } |
| 6803 | |
| 6804 | void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) { |
| 6805 | HandleBinaryOp(instruction); |
| 6806 | } |
| 6807 | |
| 6808 | void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6809 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6810 | } |
| 6811 | |
| 6812 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6813 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6814 | } |
| 6815 | |
| 6816 | void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6817 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6818 | } |
| 6819 | |
| 6820 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 6821 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6822 | } |
| 6823 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6824 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet( |
| 6825 | HUnresolvedInstanceFieldGet* instruction) { |
| 6826 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6827 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6828 | instruction, instruction->GetFieldType(), calling_convention); |
| 6829 | } |
| 6830 | |
| 6831 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet( |
| 6832 | HUnresolvedInstanceFieldGet* instruction) { |
| 6833 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6834 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6835 | instruction->GetFieldType(), |
| 6836 | instruction->GetFieldIndex(), |
| 6837 | instruction->GetDexPc(), |
| 6838 | calling_convention); |
| 6839 | } |
| 6840 | |
| 6841 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet( |
| 6842 | HUnresolvedInstanceFieldSet* instruction) { |
| 6843 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6844 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6845 | instruction, instruction->GetFieldType(), calling_convention); |
| 6846 | } |
| 6847 | |
| 6848 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet( |
| 6849 | HUnresolvedInstanceFieldSet* instruction) { |
| 6850 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6851 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6852 | instruction->GetFieldType(), |
| 6853 | instruction->GetFieldIndex(), |
| 6854 | instruction->GetDexPc(), |
| 6855 | calling_convention); |
| 6856 | } |
| 6857 | |
| 6858 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet( |
| 6859 | HUnresolvedStaticFieldGet* instruction) { |
| 6860 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6861 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6862 | instruction, instruction->GetFieldType(), calling_convention); |
| 6863 | } |
| 6864 | |
| 6865 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet( |
| 6866 | HUnresolvedStaticFieldGet* instruction) { |
| 6867 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6868 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6869 | instruction->GetFieldType(), |
| 6870 | instruction->GetFieldIndex(), |
| 6871 | instruction->GetDexPc(), |
| 6872 | calling_convention); |
| 6873 | } |
| 6874 | |
| 6875 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet( |
| 6876 | HUnresolvedStaticFieldSet* instruction) { |
| 6877 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6878 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6879 | instruction, instruction->GetFieldType(), calling_convention); |
| 6880 | } |
| 6881 | |
| 6882 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet( |
| 6883 | HUnresolvedStaticFieldSet* instruction) { |
| 6884 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6885 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6886 | instruction->GetFieldType(), |
| 6887 | instruction->GetFieldIndex(), |
| 6888 | instruction->GetDexPc(), |
| 6889 | calling_convention); |
| 6890 | } |
| 6891 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6892 | void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6893 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6894 | instruction, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 6895 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6896 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6897 | // registers in full width (since the runtime only saves/restores lower part). |
| 6898 | locations->SetCustomSlowPathCallerSaves( |
| 6899 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6900 | } |
| 6901 | |
| 6902 | void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6903 | HBasicBlock* block = instruction->GetBlock(); |
| 6904 | if (block->GetLoopInformation() != nullptr) { |
| 6905 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6906 | // The back edge will generate the suspend check. |
| 6907 | return; |
| 6908 | } |
| 6909 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6910 | // The goto will generate the suspend check. |
| 6911 | return; |
| 6912 | } |
| 6913 | GenerateSuspendCheck(instruction, nullptr); |
| 6914 | } |
| 6915 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6916 | void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6917 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6918 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6919 | InvokeRuntimeCallingConvention calling_convention; |
| 6920 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6921 | } |
| 6922 | |
| 6923 | void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6924 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6925 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 6926 | } |
| 6927 | |
| 6928 | void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6929 | DataType::Type input_type = conversion->GetInputType(); |
| 6930 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6931 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6932 | << input_type << " -> " << result_type; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6933 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6934 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 6935 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6936 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 6937 | } |
| 6938 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6939 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(conversion); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6940 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6941 | if (DataType::IsFloatingPointType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6942 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6943 | } else { |
| 6944 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6945 | } |
| 6946 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6947 | if (DataType::IsFloatingPointType(result_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6948 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6949 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6950 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6951 | } |
| 6952 | } |
| 6953 | |
| 6954 | void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
| 6955 | LocationSummary* locations = conversion->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6956 | DataType::Type result_type = conversion->GetResultType(); |
| 6957 | DataType::Type input_type = conversion->GetInputType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6958 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6959 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6960 | << input_type << " -> " << result_type; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6961 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6962 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6963 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6964 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6965 | |
| 6966 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6967 | case DataType::Type::kUint8: |
| 6968 | __ Andi(dst, src, 0xFF); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6969 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6970 | case DataType::Type::kInt8: |
| 6971 | if (input_type == DataType::Type::kInt64) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 6972 | // Type conversion from long to types narrower than int is a result of code |
| 6973 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 6974 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 6975 | __ Sll(dst, src, 0); |
| 6976 | __ Seb(dst, dst); |
| 6977 | } else { |
| 6978 | __ Seb(dst, src); |
| 6979 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6980 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6981 | case DataType::Type::kUint16: |
| 6982 | __ Andi(dst, src, 0xFFFF); |
| 6983 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6984 | case DataType::Type::kInt16: |
| 6985 | if (input_type == DataType::Type::kInt64) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 6986 | // Type conversion from long to types narrower than int is a result of code |
| 6987 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 6988 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 6989 | __ Sll(dst, src, 0); |
| 6990 | __ Seh(dst, dst); |
| 6991 | } else { |
| 6992 | __ Seh(dst, src); |
| 6993 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6994 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6995 | case DataType::Type::kInt32: |
| 6996 | case DataType::Type::kInt64: |
Goran Jakovljevic | 992bdb9 | 2016-12-28 16:21:48 +0100 | [diff] [blame] | 6997 | // Sign-extend 32-bit int into bits 32 through 63 for int-to-long and long-to-int |
| 6998 | // conversions, except when the input and output registers are the same and we are not |
| 6999 | // converting longs to shorter types. In these cases, do nothing. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7000 | if ((input_type == DataType::Type::kInt64) || (dst != src)) { |
Goran Jakovljevic | 992bdb9 | 2016-12-28 16:21:48 +0100 | [diff] [blame] | 7001 | __ Sll(dst, src, 0); |
| 7002 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7003 | break; |
| 7004 | |
| 7005 | default: |
| 7006 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 7007 | << " to " << result_type; |
| 7008 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7009 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7010 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 7011 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7012 | if (input_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7013 | __ Dmtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7014 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7015 | __ Cvtsl(dst, FTMP); |
| 7016 | } else { |
| 7017 | __ Cvtdl(dst, FTMP); |
| 7018 | } |
| 7019 | } else { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7020 | __ Mtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7021 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7022 | __ Cvtsw(dst, FTMP); |
| 7023 | } else { |
| 7024 | __ Cvtdw(dst, FTMP); |
| 7025 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7026 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7027 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 7028 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7029 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 7030 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7031 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7032 | if (result_type == DataType::Type::kInt64) { |
| 7033 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7034 | __ TruncLS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7035 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7036 | __ TruncLD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7037 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7038 | __ Dmfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7039 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7040 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7041 | __ TruncWS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7042 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7043 | __ TruncWD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7044 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7045 | __ Mfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7046 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7047 | } else if (DataType::IsFloatingPointType(result_type) && |
| 7048 | DataType::IsFloatingPointType(input_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7049 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 7050 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7051 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7052 | __ Cvtsd(dst, src); |
| 7053 | } else { |
| 7054 | __ Cvtds(dst, src); |
| 7055 | } |
| 7056 | } else { |
| 7057 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 7058 | << " to " << result_type; |
| 7059 | } |
| 7060 | } |
| 7061 | |
| 7062 | void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) { |
| 7063 | HandleShift(ushr); |
| 7064 | } |
| 7065 | |
| 7066 | void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) { |
| 7067 | HandleShift(ushr); |
| 7068 | } |
| 7069 | |
| 7070 | void LocationsBuilderMIPS64::VisitXor(HXor* instruction) { |
| 7071 | HandleBinaryOp(instruction); |
| 7072 | } |
| 7073 | |
| 7074 | void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) { |
| 7075 | HandleBinaryOp(instruction); |
| 7076 | } |
| 7077 | |
| 7078 | void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 7079 | // Nothing to do, this should be removed during prepare for register allocator. |
| 7080 | LOG(FATAL) << "Unreachable"; |
| 7081 | } |
| 7082 | |
| 7083 | void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 7084 | // Nothing to do, this should be removed during prepare for register allocator. |
| 7085 | LOG(FATAL) << "Unreachable"; |
| 7086 | } |
| 7087 | |
| 7088 | void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7089 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7090 | } |
| 7091 | |
| 7092 | void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7093 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7094 | } |
| 7095 | |
| 7096 | void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7097 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7098 | } |
| 7099 | |
| 7100 | void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7101 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7102 | } |
| 7103 | |
| 7104 | void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7105 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7106 | } |
| 7107 | |
| 7108 | void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7109 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7110 | } |
| 7111 | |
| 7112 | void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7113 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7114 | } |
| 7115 | |
| 7116 | void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7117 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7118 | } |
| 7119 | |
| 7120 | void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7121 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7122 | } |
| 7123 | |
| 7124 | void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7125 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7126 | } |
| 7127 | |
| 7128 | void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7129 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7130 | } |
| 7131 | |
| 7132 | void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7133 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7134 | } |
| 7135 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7136 | void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7137 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7138 | } |
| 7139 | |
| 7140 | void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7141 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7142 | } |
| 7143 | |
| 7144 | void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7145 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7146 | } |
| 7147 | |
| 7148 | void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7149 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7150 | } |
| 7151 | |
| 7152 | void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7153 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7154 | } |
| 7155 | |
| 7156 | void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7157 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7158 | } |
| 7159 | |
| 7160 | void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7161 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7162 | } |
| 7163 | |
| 7164 | void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7165 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7166 | } |
| 7167 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7168 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7169 | void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7170 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7171 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7172 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7173 | } |
| 7174 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7175 | void InstructionCodeGeneratorMIPS64::GenPackedSwitchWithCompares(GpuRegister value_reg, |
| 7176 | int32_t lower_bound, |
| 7177 | uint32_t num_entries, |
| 7178 | HBasicBlock* switch_block, |
| 7179 | HBasicBlock* default_block) { |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7180 | // Create a set of compare/jumps. |
| 7181 | GpuRegister temp_reg = TMP; |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7182 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7183 | // Jump to default if index is negative |
| 7184 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 7185 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 7186 | __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block)); |
| 7187 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7188 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7189 | // Jump to successors[0] if value == lower_bound. |
| 7190 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 7191 | int32_t last_index = 0; |
| 7192 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7193 | __ Addiu(temp_reg, temp_reg, -2); |
| 7194 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7195 | __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 7196 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7197 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 7198 | } |
| 7199 | if (num_entries - last_index == 2) { |
| 7200 | // The last missing case_value. |
| 7201 | __ Addiu(temp_reg, temp_reg, -1); |
| 7202 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7203 | } |
| 7204 | |
| 7205 | // And the default for any other value. |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7206 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 7207 | __ Bc(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7208 | } |
| 7209 | } |
| 7210 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7211 | void InstructionCodeGeneratorMIPS64::GenTableBasedPackedSwitch(GpuRegister value_reg, |
| 7212 | int32_t lower_bound, |
| 7213 | uint32_t num_entries, |
| 7214 | HBasicBlock* switch_block, |
| 7215 | HBasicBlock* default_block) { |
| 7216 | // Create a jump table. |
| 7217 | std::vector<Mips64Label*> labels(num_entries); |
| 7218 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7219 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7220 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7221 | } |
| 7222 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 7223 | |
| 7224 | // Is the value in range? |
| 7225 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 7226 | __ LoadConst32(AT, num_entries); |
| 7227 | __ Bgeuc(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 7228 | |
| 7229 | // We are in the range of the table. |
| 7230 | // Load the target address from the jump table, indexing by the value. |
| 7231 | __ LoadLabelAddress(AT, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 7232 | __ Dlsa(TMP, TMP, AT, 2); |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7233 | __ Lw(TMP, TMP, 0); |
| 7234 | // Compute the absolute target address by adding the table start address |
| 7235 | // (the table contains offsets to targets relative to its start). |
| 7236 | __ Daddu(TMP, TMP, AT); |
| 7237 | // And jump. |
| 7238 | __ Jr(TMP); |
| 7239 | __ Nop(); |
| 7240 | } |
| 7241 | |
| 7242 | void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7243 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7244 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7245 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7246 | GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 7247 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 7248 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7249 | |
| 7250 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
| 7251 | GenTableBasedPackedSwitch(value_reg, |
| 7252 | lower_bound, |
| 7253 | num_entries, |
| 7254 | switch_block, |
| 7255 | default_block); |
| 7256 | } else { |
| 7257 | GenPackedSwitchWithCompares(value_reg, |
| 7258 | lower_bound, |
| 7259 | num_entries, |
| 7260 | switch_block, |
| 7261 | default_block); |
| 7262 | } |
| 7263 | } |
| 7264 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7265 | void LocationsBuilderMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 7266 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7267 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7268 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7269 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7270 | } |
| 7271 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7272 | void InstructionCodeGeneratorMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 7273 | LocationSummary* locations = instruction->GetLocations(); |
| 7274 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 7275 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7276 | instruction->GetIndex(), kMips64PointerSize).SizeValue(); |
| 7277 | __ LoadFromOffset(kLoadDoubleword, |
| 7278 | locations->Out().AsRegister<GpuRegister>(), |
| 7279 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 7280 | method_offset); |
| 7281 | } else { |
| 7282 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 7283 | instruction->GetIndex(), kMips64PointerSize)); |
| 7284 | __ LoadFromOffset(kLoadDoubleword, |
| 7285 | locations->Out().AsRegister<GpuRegister>(), |
| 7286 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 7287 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 7288 | __ LoadFromOffset(kLoadDoubleword, |
| 7289 | locations->Out().AsRegister<GpuRegister>(), |
| 7290 | locations->Out().AsRegister<GpuRegister>(), |
| 7291 | method_offset); |
| 7292 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7293 | } |
| 7294 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7295 | void LocationsBuilderMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7296 | ATTRIBUTE_UNUSED) { |
| 7297 | LOG(FATAL) << "Unreachable"; |
| 7298 | } |
| 7299 | |
| 7300 | void InstructionCodeGeneratorMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7301 | ATTRIBUTE_UNUSED) { |
| 7302 | LOG(FATAL) << "Unreachable"; |
| 7303 | } |
| 7304 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7305 | } // namespace mips64 |
| 7306 | } // namespace art |