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 | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1540 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1541 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1542 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1543 | boot_image_string_patches_, linker_patches); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1544 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1545 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1546 | method_bss_entry_patches_, linker_patches); |
| 1547 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1548 | type_bss_entry_patches_, linker_patches); |
| 1549 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1550 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1551 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1552 | } |
| 1553 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame^] | 1554 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageRelRoPatch( |
| 1555 | uint32_t boot_image_offset, |
| 1556 | const PcRelativePatchInfo* info_high) { |
| 1557 | return NewPcRelativePatch( |
| 1558 | /* dex_file */ nullptr, boot_image_offset, info_high, &boot_image_method_patches_); |
| 1559 | } |
| 1560 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1561 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageMethodPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1562 | MethodReference target_method, |
| 1563 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1564 | return NewPcRelativePatch( |
| 1565 | 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] | 1566 | } |
| 1567 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1568 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewMethodBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1569 | MethodReference target_method, |
| 1570 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1571 | return NewPcRelativePatch( |
| 1572 | 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] | 1573 | } |
| 1574 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1575 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageTypePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1576 | const DexFile& dex_file, |
| 1577 | dex::TypeIndex type_index, |
| 1578 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1579 | 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] | 1580 | } |
| 1581 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1582 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewTypeBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1583 | const DexFile& dex_file, |
| 1584 | dex::TypeIndex type_index, |
| 1585 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1586 | 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] | 1587 | } |
| 1588 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1589 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewBootImageStringPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1590 | const DexFile& dex_file, |
| 1591 | dex::StringIndex string_index, |
| 1592 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1593 | return NewPcRelativePatch( |
| 1594 | &dex_file, string_index.index_, info_high, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1595 | } |
| 1596 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1597 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewStringBssEntryPatch( |
| 1598 | const DexFile& dex_file, |
| 1599 | dex::StringIndex string_index, |
| 1600 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1601 | 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] | 1602 | } |
| 1603 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1604 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1605 | const DexFile* dex_file, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1606 | uint32_t offset_or_index, |
| 1607 | const PcRelativePatchInfo* info_high, |
| 1608 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1609 | patches->emplace_back(dex_file, offset_or_index, info_high); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1610 | return &patches->back(); |
| 1611 | } |
| 1612 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1613 | Literal* CodeGeneratorMIPS64::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1614 | return map->GetOrCreate( |
| 1615 | value, |
| 1616 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1617 | } |
| 1618 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1619 | Literal* CodeGeneratorMIPS64::DeduplicateUint64Literal(uint64_t value) { |
| 1620 | return uint64_literals_.GetOrCreate( |
| 1621 | value, |
| 1622 | [this, value]() { return __ NewLiteral<uint64_t>(value); }); |
| 1623 | } |
| 1624 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1625 | Literal* CodeGeneratorMIPS64::DeduplicateBootImageAddressLiteral(uint64_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1626 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1627 | } |
| 1628 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1629 | void CodeGeneratorMIPS64::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high, |
| 1630 | GpuRegister out, |
| 1631 | PcRelativePatchInfo* info_low) { |
| 1632 | DCHECK(!info_high->patch_info_high); |
| 1633 | __ Bind(&info_high->label); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1634 | // Add the high half of a 32-bit offset to PC. |
| 1635 | __ Auipc(out, /* placeholder */ 0x1234); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1636 | // 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] | 1637 | // offset to `out` (e.g. ld, jialc, daddiu). |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1638 | if (info_low != nullptr) { |
| 1639 | DCHECK_EQ(info_low->patch_info_high, info_high); |
| 1640 | __ Bind(&info_low->label); |
| 1641 | } |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1642 | } |
| 1643 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1644 | Literal* CodeGeneratorMIPS64::DeduplicateJitStringLiteral(const DexFile& dex_file, |
| 1645 | dex::StringIndex string_index, |
| 1646 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1647 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1648 | return jit_string_patches_.GetOrCreate( |
| 1649 | StringReference(&dex_file, string_index), |
| 1650 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1651 | } |
| 1652 | |
| 1653 | Literal* CodeGeneratorMIPS64::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 1654 | dex::TypeIndex type_index, |
| 1655 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1656 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1657 | return jit_class_patches_.GetOrCreate( |
| 1658 | TypeReference(&dex_file, type_index), |
| 1659 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1660 | } |
| 1661 | |
| 1662 | void CodeGeneratorMIPS64::PatchJitRootUse(uint8_t* code, |
| 1663 | const uint8_t* roots_data, |
| 1664 | const Literal* literal, |
| 1665 | uint64_t index_in_table) const { |
| 1666 | uint32_t literal_offset = GetAssembler().GetLabelLocation(literal->GetLabel()); |
| 1667 | uintptr_t address = |
| 1668 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1669 | reinterpret_cast<uint32_t*>(code + literal_offset)[0] = dchecked_integral_cast<uint32_t>(address); |
| 1670 | } |
| 1671 | |
| 1672 | void CodeGeneratorMIPS64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1673 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1674 | const StringReference& string_reference = entry.first; |
| 1675 | Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1676 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1677 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1678 | } |
| 1679 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1680 | const TypeReference& type_reference = entry.first; |
| 1681 | Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1682 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1683 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1684 | } |
| 1685 | } |
| 1686 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1687 | void CodeGeneratorMIPS64::SetupBlockedRegisters() const { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1688 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1689 | blocked_core_registers_[ZERO] = true; |
| 1690 | blocked_core_registers_[K0] = true; |
| 1691 | blocked_core_registers_[K1] = true; |
| 1692 | blocked_core_registers_[GP] = true; |
| 1693 | blocked_core_registers_[SP] = true; |
| 1694 | blocked_core_registers_[RA] = true; |
| 1695 | |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1696 | // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch |
| 1697 | // registers (similar to how AT is used by MIPS assemblers). |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1698 | blocked_core_registers_[AT] = true; |
| 1699 | blocked_core_registers_[TMP] = true; |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1700 | blocked_core_registers_[TMP2] = true; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1701 | blocked_fpu_registers_[FTMP] = true; |
| 1702 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1703 | if (GetInstructionSetFeatures().HasMsa()) { |
| 1704 | // To be used just for MSA instructions. |
| 1705 | blocked_fpu_registers_[FTMP2] = true; |
| 1706 | } |
| 1707 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1708 | // Reserve suspend and thread registers. |
| 1709 | blocked_core_registers_[S0] = true; |
| 1710 | blocked_core_registers_[TR] = true; |
| 1711 | |
| 1712 | // Reserve T9 for function calls |
| 1713 | blocked_core_registers_[T9] = true; |
| 1714 | |
Goran Jakovljevic | 782be11 | 2016-06-21 12:39:04 +0200 | [diff] [blame] | 1715 | if (GetGraph()->IsDebuggable()) { |
| 1716 | // Stubs do not save callee-save floating point registers. If the graph |
| 1717 | // is debuggable, we need to deal with these registers differently. For |
| 1718 | // now, just block them. |
| 1719 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1720 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1721 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1722 | } |
| 1723 | } |
| 1724 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1725 | size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1726 | __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1727 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1731 | __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1732 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1736 | __ StoreFpuToOffset(GetGraph()->HasSIMD() ? kStoreQuadword : kStoreDoubleword, |
| 1737 | FpuRegister(reg_id), |
| 1738 | SP, |
| 1739 | stack_index); |
| 1740 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1744 | __ LoadFpuFromOffset(GetGraph()->HasSIMD() ? kLoadQuadword : kLoadDoubleword, |
| 1745 | FpuRegister(reg_id), |
| 1746 | SP, |
| 1747 | stack_index); |
| 1748 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1752 | stream << GpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1756 | stream << FpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1759 | void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1760 | HInstruction* instruction, |
| 1761 | uint32_t dex_pc, |
| 1762 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1763 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1764 | GenerateInvokeRuntime(GetThreadOffset<kMips64PointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 1765 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1766 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1767 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1770 | void CodeGeneratorMIPS64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1771 | HInstruction* instruction, |
| 1772 | SlowPathCode* slow_path) { |
| 1773 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1774 | GenerateInvokeRuntime(entry_point_offset); |
| 1775 | } |
| 1776 | |
| 1777 | void CodeGeneratorMIPS64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| 1778 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 1779 | __ Jalr(T9); |
| 1780 | __ Nop(); |
| 1781 | } |
| 1782 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1783 | void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path, |
| 1784 | GpuRegister class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1785 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 1786 | const size_t status_byte_offset = |
| 1787 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 1788 | constexpr uint32_t shifted_initialized_value = |
| 1789 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 1790 | |
| 1791 | __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, status_byte_offset); |
Lena Djokic | 3177e10 | 2018-02-28 11:32:40 +0100 | [diff] [blame] | 1792 | __ Sltiu(TMP, TMP, shifted_initialized_value); |
| 1793 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1794 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1795 | __ Sync(0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1796 | __ Bind(slow_path->GetExitLabel()); |
| 1797 | } |
| 1798 | |
| 1799 | void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1800 | __ Sync(0); // only stype 0 is supported |
| 1801 | } |
| 1802 | |
| 1803 | void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1804 | HBasicBlock* successor) { |
| 1805 | SuspendCheckSlowPathMIPS64* slow_path = |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 1806 | down_cast<SuspendCheckSlowPathMIPS64*>(instruction->GetSlowPath()); |
| 1807 | |
| 1808 | if (slow_path == nullptr) { |
| 1809 | slow_path = |
| 1810 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS64(instruction, successor); |
| 1811 | instruction->SetSlowPath(slow_path); |
| 1812 | codegen_->AddSlowPath(slow_path); |
| 1813 | if (successor != nullptr) { |
| 1814 | DCHECK(successor->IsLoopHeader()); |
| 1815 | } |
| 1816 | } else { |
| 1817 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1818 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1819 | |
| 1820 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1821 | TMP, |
| 1822 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1823 | Thread::ThreadFlagsOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1824 | if (successor == nullptr) { |
| 1825 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 1826 | __ Bind(slow_path->GetReturnLabel()); |
| 1827 | } else { |
| 1828 | __ Beqzc(TMP, codegen_->GetLabelOf(successor)); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1829 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1830 | // slow_path will return to GetLabelOf(successor). |
| 1831 | } |
| 1832 | } |
| 1833 | |
| 1834 | InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph, |
| 1835 | CodeGeneratorMIPS64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1836 | : InstructionCodeGenerator(graph, codegen), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1837 | assembler_(codegen->GetAssembler()), |
| 1838 | codegen_(codegen) {} |
| 1839 | |
| 1840 | void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1841 | DCHECK_EQ(instruction->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1842 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1843 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1844 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1845 | case DataType::Type::kInt32: |
| 1846 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1847 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1848 | HInstruction* right = instruction->InputAt(1); |
| 1849 | bool can_use_imm = false; |
| 1850 | if (right->IsConstant()) { |
| 1851 | int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant()); |
| 1852 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1853 | can_use_imm = IsUint<16>(imm); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1854 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1855 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 1856 | bool single_use = right->GetUses().HasExactlyOneElement(); |
| 1857 | if (instruction->IsSub()) { |
| 1858 | if (!(type == DataType::Type::kInt32 && imm == INT32_MIN)) { |
| 1859 | imm = -imm; |
| 1860 | } |
| 1861 | } |
| 1862 | if (type == DataType::Type::kInt32) { |
| 1863 | can_use_imm = IsInt<16>(imm) || (Low16Bits(imm) == 0) || single_use; |
| 1864 | } else { |
| 1865 | can_use_imm = IsInt<16>(imm) || (IsInt<32>(imm) && (Low16Bits(imm) == 0)) || single_use; |
| 1866 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1867 | } |
| 1868 | } |
| 1869 | if (can_use_imm) |
| 1870 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1871 | else |
| 1872 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1873 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1874 | } |
| 1875 | break; |
| 1876 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1877 | case DataType::Type::kFloat32: |
| 1878 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1879 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1880 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1881 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1882 | break; |
| 1883 | |
| 1884 | default: |
| 1885 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1886 | } |
| 1887 | } |
| 1888 | |
| 1889 | void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1890 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1891 | LocationSummary* locations = instruction->GetLocations(); |
| 1892 | |
| 1893 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1894 | case DataType::Type::kInt32: |
| 1895 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1896 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1897 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1898 | Location rhs_location = locations->InAt(1); |
| 1899 | |
| 1900 | GpuRegister rhs_reg = ZERO; |
| 1901 | int64_t rhs_imm = 0; |
| 1902 | bool use_imm = rhs_location.IsConstant(); |
| 1903 | if (use_imm) { |
| 1904 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1905 | } else { |
| 1906 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1907 | } |
| 1908 | |
| 1909 | if (instruction->IsAnd()) { |
| 1910 | if (use_imm) |
| 1911 | __ Andi(dst, lhs, rhs_imm); |
| 1912 | else |
| 1913 | __ And(dst, lhs, rhs_reg); |
| 1914 | } else if (instruction->IsOr()) { |
| 1915 | if (use_imm) |
| 1916 | __ Ori(dst, lhs, rhs_imm); |
| 1917 | else |
| 1918 | __ Or(dst, lhs, rhs_reg); |
| 1919 | } else if (instruction->IsXor()) { |
| 1920 | if (use_imm) |
| 1921 | __ Xori(dst, lhs, rhs_imm); |
| 1922 | else |
| 1923 | __ Xor(dst, lhs, rhs_reg); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1924 | } else if (instruction->IsAdd() || instruction->IsSub()) { |
| 1925 | if (instruction->IsSub()) { |
| 1926 | rhs_imm = -rhs_imm; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1927 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1928 | if (type == DataType::Type::kInt32) { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1929 | if (use_imm) { |
| 1930 | if (IsInt<16>(rhs_imm)) { |
| 1931 | __ Addiu(dst, lhs, rhs_imm); |
| 1932 | } else { |
| 1933 | int16_t rhs_imm_high = High16Bits(rhs_imm); |
| 1934 | int16_t rhs_imm_low = Low16Bits(rhs_imm); |
| 1935 | if (rhs_imm_low < 0) { |
| 1936 | rhs_imm_high += 1; |
| 1937 | } |
| 1938 | __ Aui(dst, lhs, rhs_imm_high); |
| 1939 | if (rhs_imm_low != 0) { |
| 1940 | __ Addiu(dst, dst, rhs_imm_low); |
| 1941 | } |
| 1942 | } |
| 1943 | } else { |
| 1944 | if (instruction->IsAdd()) { |
| 1945 | __ Addu(dst, lhs, rhs_reg); |
| 1946 | } else { |
| 1947 | DCHECK(instruction->IsSub()); |
| 1948 | __ Subu(dst, lhs, rhs_reg); |
| 1949 | } |
| 1950 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1951 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1952 | if (use_imm) { |
| 1953 | if (IsInt<16>(rhs_imm)) { |
| 1954 | __ Daddiu(dst, lhs, rhs_imm); |
| 1955 | } else if (IsInt<32>(rhs_imm)) { |
| 1956 | int16_t rhs_imm_high = High16Bits(rhs_imm); |
| 1957 | int16_t rhs_imm_low = Low16Bits(rhs_imm); |
| 1958 | bool overflow_hi16 = false; |
| 1959 | if (rhs_imm_low < 0) { |
| 1960 | rhs_imm_high += 1; |
| 1961 | overflow_hi16 = (rhs_imm_high == -32768); |
| 1962 | } |
| 1963 | __ Daui(dst, lhs, rhs_imm_high); |
| 1964 | if (rhs_imm_low != 0) { |
| 1965 | __ Daddiu(dst, dst, rhs_imm_low); |
| 1966 | } |
| 1967 | if (overflow_hi16) { |
| 1968 | __ Dahi(dst, 1); |
| 1969 | } |
| 1970 | } else { |
| 1971 | int16_t rhs_imm_low = Low16Bits(Low32Bits(rhs_imm)); |
| 1972 | if (rhs_imm_low < 0) { |
| 1973 | rhs_imm += (INT64_C(1) << 16); |
| 1974 | } |
| 1975 | int16_t rhs_imm_upper = High16Bits(Low32Bits(rhs_imm)); |
| 1976 | if (rhs_imm_upper < 0) { |
| 1977 | rhs_imm += (INT64_C(1) << 32); |
| 1978 | } |
| 1979 | int16_t rhs_imm_high = Low16Bits(High32Bits(rhs_imm)); |
| 1980 | if (rhs_imm_high < 0) { |
| 1981 | rhs_imm += (INT64_C(1) << 48); |
| 1982 | } |
| 1983 | int16_t rhs_imm_top = High16Bits(High32Bits(rhs_imm)); |
| 1984 | GpuRegister tmp = lhs; |
| 1985 | if (rhs_imm_low != 0) { |
| 1986 | __ Daddiu(dst, tmp, rhs_imm_low); |
| 1987 | tmp = dst; |
| 1988 | } |
| 1989 | // Dahi and Dati must use the same input and output register, so we have to initialize |
| 1990 | // the dst register using Daddiu or Daui, even when the intermediate value is zero: |
| 1991 | // Daui(dst, lhs, 0). |
| 1992 | if ((rhs_imm_upper != 0) || (rhs_imm_low == 0)) { |
| 1993 | __ Daui(dst, tmp, rhs_imm_upper); |
| 1994 | } |
| 1995 | if (rhs_imm_high != 0) { |
| 1996 | __ Dahi(dst, rhs_imm_high); |
| 1997 | } |
| 1998 | if (rhs_imm_top != 0) { |
| 1999 | __ Dati(dst, rhs_imm_top); |
| 2000 | } |
| 2001 | } |
| 2002 | } else if (instruction->IsAdd()) { |
| 2003 | __ Daddu(dst, lhs, rhs_reg); |
| 2004 | } else { |
| 2005 | DCHECK(instruction->IsSub()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2006 | __ Dsubu(dst, lhs, rhs_reg); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2007 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2008 | } |
| 2009 | } |
| 2010 | break; |
| 2011 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2012 | case DataType::Type::kFloat32: |
| 2013 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2014 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 2015 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 2016 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 2017 | if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2018 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2019 | __ AddS(dst, lhs, rhs); |
| 2020 | else |
| 2021 | __ AddD(dst, lhs, rhs); |
| 2022 | } else if (instruction->IsSub()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2023 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2024 | __ SubS(dst, lhs, rhs); |
| 2025 | else |
| 2026 | __ SubD(dst, lhs, rhs); |
| 2027 | } else { |
| 2028 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
| 2029 | } |
| 2030 | break; |
| 2031 | } |
| 2032 | default: |
| 2033 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 2034 | } |
| 2035 | } |
| 2036 | |
| 2037 | void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2038 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2039 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2040 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2041 | DataType::Type type = instr->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2042 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2043 | case DataType::Type::kInt32: |
| 2044 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2045 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2046 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2047 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2048 | break; |
| 2049 | } |
| 2050 | default: |
| 2051 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2056 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2057 | LocationSummary* locations = instr->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2058 | DataType::Type type = instr->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2059 | |
| 2060 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2061 | case DataType::Type::kInt32: |
| 2062 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2063 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 2064 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2065 | Location rhs_location = locations->InAt(1); |
| 2066 | |
| 2067 | GpuRegister rhs_reg = ZERO; |
| 2068 | int64_t rhs_imm = 0; |
| 2069 | bool use_imm = rhs_location.IsConstant(); |
| 2070 | if (use_imm) { |
| 2071 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 2072 | } else { |
| 2073 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 2074 | } |
| 2075 | |
| 2076 | if (use_imm) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2077 | uint32_t shift_value = rhs_imm & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2078 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2079 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2080 | if (shift_value == 0) { |
| 2081 | if (dst != lhs) { |
| 2082 | __ Move(dst, lhs); |
| 2083 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2084 | } else if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2085 | if (instr->IsShl()) { |
| 2086 | __ Sll(dst, lhs, shift_value); |
| 2087 | } else if (instr->IsShr()) { |
| 2088 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2089 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2090 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2091 | } else { |
| 2092 | __ Rotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2093 | } |
| 2094 | } else { |
| 2095 | if (shift_value < 32) { |
| 2096 | if (instr->IsShl()) { |
| 2097 | __ Dsll(dst, lhs, shift_value); |
| 2098 | } else if (instr->IsShr()) { |
| 2099 | __ Dsra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2100 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2101 | __ Dsrl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2102 | } else { |
| 2103 | __ Drotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2104 | } |
| 2105 | } else { |
| 2106 | shift_value -= 32; |
| 2107 | if (instr->IsShl()) { |
| 2108 | __ Dsll32(dst, lhs, shift_value); |
| 2109 | } else if (instr->IsShr()) { |
| 2110 | __ Dsra32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2111 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2112 | __ Dsrl32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2113 | } else { |
| 2114 | __ Drotr32(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2115 | } |
| 2116 | } |
| 2117 | } |
| 2118 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2119 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2120 | if (instr->IsShl()) { |
| 2121 | __ Sllv(dst, lhs, rhs_reg); |
| 2122 | } else if (instr->IsShr()) { |
| 2123 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2124 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2125 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2126 | } else { |
| 2127 | __ Rotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2128 | } |
| 2129 | } else { |
| 2130 | if (instr->IsShl()) { |
| 2131 | __ Dsllv(dst, lhs, rhs_reg); |
| 2132 | } else if (instr->IsShr()) { |
| 2133 | __ Dsrav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2134 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2135 | __ Dsrlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2136 | } else { |
| 2137 | __ Drotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2138 | } |
| 2139 | } |
| 2140 | } |
| 2141 | break; |
| 2142 | } |
| 2143 | default: |
| 2144 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) { |
| 2149 | HandleBinaryOp(instruction); |
| 2150 | } |
| 2151 | |
| 2152 | void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) { |
| 2153 | HandleBinaryOp(instruction); |
| 2154 | } |
| 2155 | |
| 2156 | void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) { |
| 2157 | HandleBinaryOp(instruction); |
| 2158 | } |
| 2159 | |
| 2160 | void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) { |
| 2161 | HandleBinaryOp(instruction); |
| 2162 | } |
| 2163 | |
| 2164 | void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2165 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2166 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2167 | kEmitCompilerReadBarrier && (type == DataType::Type::kReference); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2168 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2169 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2170 | object_array_get_with_read_barrier |
| 2171 | ? LocationSummary::kCallOnSlowPath |
| 2172 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 2173 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2174 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2175 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2176 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2177 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2178 | if (DataType::IsFloatingPointType(type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2179 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2180 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2181 | // The output overlaps in the case of an object array get with |
| 2182 | // read barriers enabled: we do not want the move to overwrite the |
| 2183 | // array's location, as we need it to emit the read barrier. |
| 2184 | locations->SetOut(Location::RequiresRegister(), |
| 2185 | object_array_get_with_read_barrier |
| 2186 | ? Location::kOutputOverlap |
| 2187 | : Location::kNoOutputOverlap); |
| 2188 | } |
| 2189 | // We need a temporary register for the read barrier marking slow |
| 2190 | // path in CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier. |
| 2191 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2192 | bool temp_needed = instruction->GetIndex()->IsConstant() |
| 2193 | ? !kBakerReadBarrierThunksEnableForFields |
| 2194 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2195 | if (temp_needed) { |
| 2196 | locations->AddTemp(Location::RequiresRegister()); |
| 2197 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2198 | } |
| 2199 | } |
| 2200 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2201 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS64* codegen) { |
| 2202 | auto null_checker = [codegen, instruction]() { |
| 2203 | codegen->MaybeRecordImplicitNullCheck(instruction); |
| 2204 | }; |
| 2205 | return null_checker; |
| 2206 | } |
| 2207 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2208 | void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) { |
| 2209 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2210 | Location obj_loc = locations->InAt(0); |
| 2211 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 2212 | Location out_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2213 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2214 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2215 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2216 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2217 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2218 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2219 | instruction->IsStringCharAt(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2220 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2221 | case DataType::Type::kBool: |
| 2222 | case DataType::Type::kUint8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2223 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2224 | if (index.IsConstant()) { |
| 2225 | size_t offset = |
| 2226 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2227 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2228 | } else { |
| 2229 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2230 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2231 | } |
| 2232 | break; |
| 2233 | } |
| 2234 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2235 | case DataType::Type::kInt8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2236 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2237 | if (index.IsConstant()) { |
| 2238 | size_t offset = |
| 2239 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2240 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2241 | } else { |
| 2242 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2243 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2244 | } |
| 2245 | break; |
| 2246 | } |
| 2247 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2248 | case DataType::Type::kUint16: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2249 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2250 | if (maybe_compressed_char_at) { |
| 2251 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2252 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2253 | __ Dext(TMP, TMP, 0, 1); |
| 2254 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2255 | "Expecting 0=compressed, 1=uncompressed"); |
| 2256 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2257 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2258 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2259 | if (maybe_compressed_char_at) { |
| 2260 | Mips64Label uncompressed_load, done; |
| 2261 | __ Bnezc(TMP, &uncompressed_load); |
| 2262 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2263 | out, |
| 2264 | obj, |
| 2265 | data_offset + (const_index << TIMES_1)); |
| 2266 | __ Bc(&done); |
| 2267 | __ Bind(&uncompressed_load); |
| 2268 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2269 | out, |
| 2270 | obj, |
| 2271 | data_offset + (const_index << TIMES_2)); |
| 2272 | __ Bind(&done); |
| 2273 | } else { |
| 2274 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2275 | out, |
| 2276 | obj, |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2277 | data_offset + (const_index << TIMES_2), |
| 2278 | null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2279 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2280 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2281 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
| 2282 | if (maybe_compressed_char_at) { |
| 2283 | Mips64Label uncompressed_load, done; |
| 2284 | __ Bnezc(TMP, &uncompressed_load); |
| 2285 | __ Daddu(TMP, obj, index_reg); |
| 2286 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2287 | __ Bc(&done); |
| 2288 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2289 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2290 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2291 | __ Bind(&done); |
| 2292 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2293 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2294 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2295 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2296 | } |
| 2297 | break; |
| 2298 | } |
| 2299 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2300 | case DataType::Type::kInt16: { |
| 2301 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 2302 | if (index.IsConstant()) { |
| 2303 | size_t offset = |
| 2304 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2305 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
| 2306 | } else { |
| 2307 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
| 2308 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
| 2309 | } |
| 2310 | break; |
| 2311 | } |
| 2312 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2313 | case DataType::Type::kInt32: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2314 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2315 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2316 | LoadOperandType load_type = |
| 2317 | (type == DataType::Type::kReference) ? kLoadUnsignedWord : kLoadWord; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2318 | if (index.IsConstant()) { |
| 2319 | size_t offset = |
| 2320 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2321 | __ LoadFromOffset(load_type, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2322 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2323 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2324 | __ LoadFromOffset(load_type, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2325 | } |
| 2326 | break; |
| 2327 | } |
| 2328 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2329 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2330 | static_assert( |
| 2331 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2332 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2333 | // /* HeapReference<Object> */ out = |
| 2334 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2335 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2336 | bool temp_needed = index.IsConstant() |
| 2337 | ? !kBakerReadBarrierThunksEnableForFields |
| 2338 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2339 | Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2340 | // Note that a potential implicit null check is handled in this |
| 2341 | // CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier call. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2342 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 2343 | if (index.IsConstant()) { |
| 2344 | // Array load with a constant index can be treated as a field load. |
| 2345 | size_t offset = |
| 2346 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2347 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2348 | out_loc, |
| 2349 | obj, |
| 2350 | offset, |
| 2351 | temp, |
| 2352 | /* needs_null_check */ false); |
| 2353 | } else { |
| 2354 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2355 | out_loc, |
| 2356 | obj, |
| 2357 | data_offset, |
| 2358 | index, |
| 2359 | temp, |
| 2360 | /* needs_null_check */ false); |
| 2361 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2362 | } else { |
| 2363 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 2364 | if (index.IsConstant()) { |
| 2365 | size_t offset = |
| 2366 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2367 | __ LoadFromOffset(kLoadUnsignedWord, out, obj, offset, null_checker); |
| 2368 | // If read barriers are enabled, emit read barriers other than |
| 2369 | // Baker's using a slow path (and also unpoison the loaded |
| 2370 | // reference, if heap poisoning is enabled). |
| 2371 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2372 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2373 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2374 | __ LoadFromOffset(kLoadUnsignedWord, out, TMP, data_offset, null_checker); |
| 2375 | // If read barriers are enabled, emit read barriers other than |
| 2376 | // Baker's using a slow path (and also unpoison the loaded |
| 2377 | // reference, if heap poisoning is enabled). |
| 2378 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2379 | out_loc, |
| 2380 | out_loc, |
| 2381 | obj_loc, |
| 2382 | data_offset, |
| 2383 | index); |
| 2384 | } |
| 2385 | } |
| 2386 | break; |
| 2387 | } |
| 2388 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2389 | case DataType::Type::kInt64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2390 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2391 | if (index.IsConstant()) { |
| 2392 | size_t offset = |
| 2393 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2394 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2395 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2396 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2397 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2398 | } |
| 2399 | break; |
| 2400 | } |
| 2401 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2402 | case DataType::Type::kFloat32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2403 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2404 | if (index.IsConstant()) { |
| 2405 | size_t offset = |
| 2406 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2407 | __ LoadFpuFromOffset(kLoadWord, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2408 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2409 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2410 | __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2411 | } |
| 2412 | break; |
| 2413 | } |
| 2414 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2415 | case DataType::Type::kFloat64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2416 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2417 | if (index.IsConstant()) { |
| 2418 | size_t offset = |
| 2419 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2420 | __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2421 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2422 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2423 | __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2424 | } |
| 2425 | break; |
| 2426 | } |
| 2427 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2428 | case DataType::Type::kUint32: |
| 2429 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2430 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2431 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2432 | UNREACHABLE(); |
| 2433 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2437 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2438 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2439 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2440 | } |
| 2441 | |
| 2442 | void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 2443 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2444 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2445 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2446 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2447 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2448 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2449 | // Mask out compression flag from String's array length. |
| 2450 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2451 | __ Srl(out, out, 1u); |
| 2452 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2453 | } |
| 2454 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2455 | Location LocationsBuilderMIPS64::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2456 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2457 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2458 | : Location::RequiresRegister(); |
| 2459 | } |
| 2460 | |
| 2461 | Location LocationsBuilderMIPS64::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2462 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2463 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2464 | // but we should only prefer this if the constant has a single use. |
| 2465 | if (instruction->IsConstant() && |
| 2466 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2467 | instruction->GetUses().HasExactlyOneElement())) { |
| 2468 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2469 | // Otherwise fall through and require an FPU register for the constant. |
| 2470 | } |
| 2471 | return Location::RequiresFpuRegister(); |
| 2472 | } |
| 2473 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2474 | void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2475 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2476 | |
| 2477 | bool needs_write_barrier = |
| 2478 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2479 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2480 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2481 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2482 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2483 | may_need_runtime_call_for_type_check ? |
| 2484 | LocationSummary::kCallOnSlowPath : |
| 2485 | LocationSummary::kNoCall); |
| 2486 | |
| 2487 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2488 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2489 | if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2490 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2491 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2492 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2493 | } |
| 2494 | if (needs_write_barrier) { |
| 2495 | // Temporary register for the write barrier. |
| 2496 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2497 | } |
| 2498 | } |
| 2499 | |
| 2500 | void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) { |
| 2501 | LocationSummary* locations = instruction->GetLocations(); |
| 2502 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2503 | Location index = locations->InAt(1); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2504 | Location value_location = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2505 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2506 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2507 | bool needs_write_barrier = |
| 2508 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2509 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2510 | GpuRegister base_reg = index.IsConstant() ? obj : TMP; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2511 | |
| 2512 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2513 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2514 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2515 | case DataType::Type::kInt8: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2516 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2517 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2518 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2519 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2520 | __ Daddu(base_reg, obj, index.AsRegister<GpuRegister>()); |
| 2521 | } |
| 2522 | if (value_location.IsConstant()) { |
| 2523 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2524 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2525 | } else { |
| 2526 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2527 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2528 | } |
| 2529 | break; |
| 2530 | } |
| 2531 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2532 | case DataType::Type::kUint16: |
| 2533 | case DataType::Type::kInt16: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2534 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2535 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2536 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2537 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2538 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2539 | } |
| 2540 | if (value_location.IsConstant()) { |
| 2541 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2542 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2543 | } else { |
| 2544 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2545 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2546 | } |
| 2547 | break; |
| 2548 | } |
| 2549 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2550 | case DataType::Type::kInt32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2551 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2552 | if (index.IsConstant()) { |
| 2553 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
| 2554 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2555 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2556 | } |
| 2557 | if (value_location.IsConstant()) { |
| 2558 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2559 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2560 | } else { |
| 2561 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2562 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2563 | } |
| 2564 | break; |
| 2565 | } |
| 2566 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2567 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2568 | if (value_location.IsConstant()) { |
| 2569 | // Just setting null. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2570 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2571 | if (index.IsConstant()) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2572 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2573 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2574 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2575 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2576 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2577 | DCHECK_EQ(value, 0); |
| 2578 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2579 | DCHECK(!needs_write_barrier); |
| 2580 | DCHECK(!may_need_runtime_call_for_type_check); |
| 2581 | break; |
| 2582 | } |
| 2583 | |
| 2584 | DCHECK(needs_write_barrier); |
| 2585 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2586 | GpuRegister temp1 = locations->GetTemp(0).AsRegister<GpuRegister>(); |
| 2587 | GpuRegister temp2 = TMP; // Doesn't need to survive slow path. |
| 2588 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2589 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2590 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2591 | Mips64Label done; |
| 2592 | SlowPathCodeMIPS64* slow_path = nullptr; |
| 2593 | |
| 2594 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2595 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS64(instruction); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2596 | codegen_->AddSlowPath(slow_path); |
| 2597 | if (instruction->GetValueCanBeNull()) { |
| 2598 | Mips64Label non_zero; |
| 2599 | __ Bnezc(value, &non_zero); |
| 2600 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2601 | if (index.IsConstant()) { |
| 2602 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2603 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2604 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2605 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2606 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2607 | __ Bc(&done); |
| 2608 | __ Bind(&non_zero); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2609 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2610 | |
| 2611 | // Note that when read barriers are enabled, the type checks |
| 2612 | // are performed without read barriers. This is fine, even in |
| 2613 | // the case where a class object is in the from-space after |
| 2614 | // the flip, as a comparison involving such a type would not |
| 2615 | // produce a false positive; it may of course produce a false |
| 2616 | // negative, in which case we would take the ArraySet slow |
| 2617 | // path. |
| 2618 | |
| 2619 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 2620 | __ LoadFromOffset(kLoadUnsignedWord, temp1, obj, class_offset, null_checker); |
| 2621 | __ MaybeUnpoisonHeapReference(temp1); |
| 2622 | |
| 2623 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2624 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, component_offset); |
| 2625 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2626 | __ LoadFromOffset(kLoadUnsignedWord, temp2, value, class_offset); |
| 2627 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 2628 | // nor `temp2`, as we are comparing two poisoned references. |
| 2629 | |
| 2630 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2631 | Mips64Label do_put; |
| 2632 | __ Beqc(temp1, temp2, &do_put); |
| 2633 | // If heap poisoning is enabled, the `temp1` reference has |
| 2634 | // not been unpoisoned yet; unpoison it now. |
| 2635 | __ MaybeUnpoisonHeapReference(temp1); |
| 2636 | |
| 2637 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 2638 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, super_offset); |
| 2639 | // If heap poisoning is enabled, no need to unpoison |
| 2640 | // `temp1`, as we are comparing against null below. |
| 2641 | __ Bnezc(temp1, slow_path->GetEntryLabel()); |
| 2642 | __ Bind(&do_put); |
| 2643 | } else { |
| 2644 | __ Bnec(temp1, temp2, slow_path->GetEntryLabel()); |
| 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | GpuRegister source = value; |
| 2649 | if (kPoisonHeapReferences) { |
| 2650 | // Note that in the case where `value` is a null reference, |
| 2651 | // we do not enter this block, as a null reference does not |
| 2652 | // need poisoning. |
| 2653 | __ Move(temp1, value); |
| 2654 | __ PoisonHeapReference(temp1); |
| 2655 | source = temp1; |
| 2656 | } |
| 2657 | |
| 2658 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2659 | if (index.IsConstant()) { |
| 2660 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2661 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2662 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2663 | } |
| 2664 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 2665 | |
| 2666 | if (!may_need_runtime_call_for_type_check) { |
| 2667 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2668 | } |
| 2669 | |
| 2670 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 2671 | |
| 2672 | if (done.IsLinked()) { |
| 2673 | __ Bind(&done); |
| 2674 | } |
| 2675 | |
| 2676 | if (slow_path != nullptr) { |
| 2677 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2678 | } |
| 2679 | break; |
| 2680 | } |
| 2681 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2682 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2683 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2684 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2685 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2686 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2687 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2688 | } |
| 2689 | if (value_location.IsConstant()) { |
| 2690 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2691 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2692 | } else { |
| 2693 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2694 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2695 | } |
| 2696 | break; |
| 2697 | } |
| 2698 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2699 | case DataType::Type::kFloat32: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2700 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2701 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2702 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2703 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2704 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2705 | } |
| 2706 | if (value_location.IsConstant()) { |
| 2707 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2708 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2709 | } else { |
| 2710 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2711 | __ StoreFpuToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2712 | } |
| 2713 | break; |
| 2714 | } |
| 2715 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2716 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2717 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2718 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2719 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2720 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2721 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2722 | } |
| 2723 | if (value_location.IsConstant()) { |
| 2724 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2725 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2726 | } else { |
| 2727 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2728 | __ StoreFpuToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2729 | } |
| 2730 | break; |
| 2731 | } |
| 2732 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2733 | case DataType::Type::kUint32: |
| 2734 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2735 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2736 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2737 | UNREACHABLE(); |
| 2738 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2742 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2743 | InvokeRuntimeCallingConvention calling_convention; |
| 2744 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2745 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2746 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2747 | |
| 2748 | HInstruction* index = instruction->InputAt(0); |
| 2749 | HInstruction* length = instruction->InputAt(1); |
| 2750 | |
| 2751 | bool const_index = false; |
| 2752 | bool const_length = false; |
| 2753 | |
| 2754 | if (index->IsConstant()) { |
| 2755 | if (length->IsConstant()) { |
| 2756 | const_index = true; |
| 2757 | const_length = true; |
| 2758 | } else { |
| 2759 | int32_t index_value = index->AsIntConstant()->GetValue(); |
| 2760 | if (index_value < 0 || IsInt<16>(index_value + 1)) { |
| 2761 | const_index = true; |
| 2762 | } |
| 2763 | } |
| 2764 | } else if (length->IsConstant()) { |
| 2765 | int32_t length_value = length->AsIntConstant()->GetValue(); |
| 2766 | if (IsUint<15>(length_value)) { |
| 2767 | const_length = true; |
| 2768 | } |
| 2769 | } |
| 2770 | |
| 2771 | locations->SetInAt(0, const_index |
| 2772 | ? Location::ConstantLocation(index->AsConstant()) |
| 2773 | : Location::RequiresRegister()); |
| 2774 | locations->SetInAt(1, const_length |
| 2775 | ? Location::ConstantLocation(length->AsConstant()) |
| 2776 | : Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2780 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2781 | Location index_loc = locations->InAt(0); |
| 2782 | Location length_loc = locations->InAt(1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2783 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2784 | if (length_loc.IsConstant()) { |
| 2785 | int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 2786 | if (index_loc.IsConstant()) { |
| 2787 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 2788 | if (index < 0 || index >= length) { |
| 2789 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2790 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction); |
| 2791 | codegen_->AddSlowPath(slow_path); |
| 2792 | __ Bc(slow_path->GetEntryLabel()); |
| 2793 | } else { |
| 2794 | // Nothing to be done. |
| 2795 | } |
| 2796 | return; |
| 2797 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2798 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 2799 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2800 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction); |
| 2801 | codegen_->AddSlowPath(slow_path); |
| 2802 | GpuRegister index = index_loc.AsRegister<GpuRegister>(); |
| 2803 | if (length == 0) { |
| 2804 | __ Bc(slow_path->GetEntryLabel()); |
| 2805 | } else if (length == 1) { |
| 2806 | __ Bnezc(index, slow_path->GetEntryLabel()); |
| 2807 | } else { |
| 2808 | DCHECK(IsUint<15>(length)) << length; |
| 2809 | __ Sltiu(TMP, index, length); |
| 2810 | __ Beqzc(TMP, slow_path->GetEntryLabel()); |
| 2811 | } |
| 2812 | } else { |
| 2813 | GpuRegister length = length_loc.AsRegister<GpuRegister>(); |
| 2814 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2815 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS64(instruction); |
| 2816 | codegen_->AddSlowPath(slow_path); |
| 2817 | if (index_loc.IsConstant()) { |
| 2818 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 2819 | if (index < 0) { |
| 2820 | __ Bc(slow_path->GetEntryLabel()); |
| 2821 | } else if (index == 0) { |
| 2822 | __ Blezc(length, slow_path->GetEntryLabel()); |
| 2823 | } else { |
| 2824 | DCHECK(IsInt<16>(index + 1)) << index; |
| 2825 | __ Sltiu(TMP, length, index + 1); |
| 2826 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 2827 | } |
| 2828 | } else { |
| 2829 | GpuRegister index = index_loc.AsRegister<GpuRegister>(); |
| 2830 | __ Bgeuc(index, length, slow_path->GetEntryLabel()); |
| 2831 | } |
| 2832 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2835 | // Temp is used for read barrier. |
| 2836 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 2837 | if (kEmitCompilerReadBarrier && |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2838 | !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) && |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2839 | (kUseBakerReadBarrier || |
| 2840 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2841 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2842 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 2843 | return 1; |
| 2844 | } |
| 2845 | return 0; |
| 2846 | } |
| 2847 | |
| 2848 | // Extra temp is used for read barrier. |
| 2849 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 2850 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 2851 | } |
| 2852 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2853 | void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2854 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 2855 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2856 | LocationSummary* locations = |
| 2857 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2858 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 2859 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2860 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2864 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2865 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2866 | Location obj_loc = locations->InAt(0); |
| 2867 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 2868 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2869 | Location temp_loc = locations->GetTemp(0); |
| 2870 | GpuRegister temp = temp_loc.AsRegister<GpuRegister>(); |
| 2871 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 2872 | DCHECK_LE(num_temps, 2u); |
| 2873 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2874 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2875 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2876 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2877 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 2878 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 2879 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 2880 | const uint32_t object_array_data_offset = |
| 2881 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 2882 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2883 | |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 2884 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2885 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2886 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( |
| 2887 | instruction, is_type_check_slow_path_fatal); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2888 | codegen_->AddSlowPath(slow_path); |
| 2889 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2890 | // Avoid this check if we know `obj` is not null. |
| 2891 | if (instruction->MustDoNullCheck()) { |
| 2892 | __ Beqzc(obj, &done); |
| 2893 | } |
| 2894 | |
| 2895 | switch (type_check_kind) { |
| 2896 | case TypeCheckKind::kExactCheck: |
| 2897 | case TypeCheckKind::kArrayCheck: { |
| 2898 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2899 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2900 | temp_loc, |
| 2901 | obj_loc, |
| 2902 | class_offset, |
| 2903 | maybe_temp2_loc, |
| 2904 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2905 | // Jump to slow path for throwing the exception or doing a |
| 2906 | // more involved array check. |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 2907 | __ Bnec(temp, cls, slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2908 | break; |
| 2909 | } |
| 2910 | |
| 2911 | case TypeCheckKind::kAbstractClassCheck: { |
| 2912 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2913 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2914 | temp_loc, |
| 2915 | obj_loc, |
| 2916 | class_offset, |
| 2917 | maybe_temp2_loc, |
| 2918 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2919 | // If the class is abstract, we eagerly fetch the super class of the |
| 2920 | // object to avoid doing a comparison we know will fail. |
| 2921 | Mips64Label loop; |
| 2922 | __ Bind(&loop); |
| 2923 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2924 | GenerateReferenceLoadOneRegister(instruction, |
| 2925 | temp_loc, |
| 2926 | super_offset, |
| 2927 | maybe_temp2_loc, |
| 2928 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2929 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2930 | // exception. |
| 2931 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2932 | // Otherwise, compare the classes. |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 2933 | __ Bnec(temp, cls, &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2934 | break; |
| 2935 | } |
| 2936 | |
| 2937 | case TypeCheckKind::kClassHierarchyCheck: { |
| 2938 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2939 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2940 | temp_loc, |
| 2941 | obj_loc, |
| 2942 | class_offset, |
| 2943 | maybe_temp2_loc, |
| 2944 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2945 | // Walk over the class hierarchy to find a match. |
| 2946 | Mips64Label loop; |
| 2947 | __ Bind(&loop); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 2948 | __ Beqc(temp, cls, &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2949 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2950 | GenerateReferenceLoadOneRegister(instruction, |
| 2951 | temp_loc, |
| 2952 | super_offset, |
| 2953 | maybe_temp2_loc, |
| 2954 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2955 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2956 | // exception. Otherwise, jump to the beginning of the loop. |
| 2957 | __ Bnezc(temp, &loop); |
| 2958 | __ Bc(slow_path->GetEntryLabel()); |
| 2959 | break; |
| 2960 | } |
| 2961 | |
| 2962 | case TypeCheckKind::kArrayObjectCheck: { |
| 2963 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2964 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2965 | temp_loc, |
| 2966 | obj_loc, |
| 2967 | class_offset, |
| 2968 | maybe_temp2_loc, |
| 2969 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2970 | // Do an exact check. |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 2971 | __ Beqc(temp, cls, &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2972 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 2973 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2974 | GenerateReferenceLoadOneRegister(instruction, |
| 2975 | temp_loc, |
| 2976 | component_offset, |
| 2977 | maybe_temp2_loc, |
| 2978 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2979 | // If the component type is null, jump to the slow path to throw the exception. |
| 2980 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2981 | // Otherwise, the object is indeed an array, further check that this component |
| 2982 | // type is not a primitive type. |
| 2983 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 2984 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 2985 | __ Bnezc(temp, slow_path->GetEntryLabel()); |
| 2986 | break; |
| 2987 | } |
| 2988 | |
| 2989 | case TypeCheckKind::kUnresolvedCheck: |
| 2990 | // We always go into the type check slow path for the unresolved check case. |
| 2991 | // We cannot directly call the CheckCast runtime entry point |
| 2992 | // without resorting to a type checking slow path here (i.e. by |
| 2993 | // calling InvokeRuntime directly), as it would require to |
| 2994 | // assign fixed registers for the inputs of this HInstanceOf |
| 2995 | // instruction (following the runtime calling convention), which |
| 2996 | // might be cluttered by the potential first read barrier |
| 2997 | // emission at the beginning of this method. |
| 2998 | __ Bc(slow_path->GetEntryLabel()); |
| 2999 | break; |
| 3000 | |
| 3001 | case TypeCheckKind::kInterfaceCheck: { |
| 3002 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 3003 | // positives by doing this. |
| 3004 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3005 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3006 | temp_loc, |
| 3007 | obj_loc, |
| 3008 | class_offset, |
| 3009 | maybe_temp2_loc, |
| 3010 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3011 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3012 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3013 | temp_loc, |
| 3014 | temp_loc, |
| 3015 | iftable_offset, |
| 3016 | maybe_temp2_loc, |
| 3017 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3018 | // Iftable is never null. |
| 3019 | __ Lw(TMP, temp, array_length_offset); |
| 3020 | // Loop through the iftable and check if any class matches. |
| 3021 | Mips64Label loop; |
| 3022 | __ Bind(&loop); |
| 3023 | __ Beqzc(TMP, slow_path->GetEntryLabel()); |
| 3024 | __ Lwu(AT, temp, object_array_data_offset); |
| 3025 | __ MaybeUnpoisonHeapReference(AT); |
| 3026 | // Go to next interface. |
| 3027 | __ Daddiu(temp, temp, 2 * kHeapReferenceSize); |
| 3028 | __ Addiu(TMP, TMP, -2); |
| 3029 | // Compare the classes and continue the loop if they do not match. |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 3030 | __ Bnec(AT, cls, &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3031 | break; |
| 3032 | } |
| 3033 | } |
| 3034 | |
| 3035 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3036 | __ Bind(slow_path->GetExitLabel()); |
| 3037 | } |
| 3038 | |
| 3039 | void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 3040 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3041 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3042 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3043 | if (check->HasUses()) { |
| 3044 | locations->SetOut(Location::SameAsFirstInput()); |
| 3045 | } |
| 3046 | } |
| 3047 | |
| 3048 | void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 3049 | // We assume the class is not null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3050 | SlowPathCodeMIPS64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64( |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3051 | check->GetLoadClass(), |
| 3052 | check, |
| 3053 | check->GetDexPc(), |
| 3054 | true); |
| 3055 | codegen_->AddSlowPath(slow_path); |
| 3056 | GenerateClassInitializationCheck(slow_path, |
| 3057 | check->GetLocations()->InAt(0).AsRegister<GpuRegister>()); |
| 3058 | } |
| 3059 | |
| 3060 | void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3061 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3062 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3063 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(compare); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3064 | |
| 3065 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3066 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3067 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3068 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3069 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3070 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3071 | case DataType::Type::kInt32: |
| 3072 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3073 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3074 | locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3075 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3076 | break; |
| 3077 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3078 | case DataType::Type::kFloat32: |
| 3079 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3080 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3081 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3082 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3083 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3084 | |
| 3085 | default: |
| 3086 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3087 | } |
| 3088 | } |
| 3089 | |
| 3090 | void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) { |
| 3091 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3092 | GpuRegister res = locations->Out().AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3093 | DataType::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3094 | |
| 3095 | // 0 if: left == right |
| 3096 | // 1 if: left > right |
| 3097 | // -1 if: left < right |
| 3098 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3099 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3100 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3101 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3102 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3103 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3104 | case DataType::Type::kInt32: |
| 3105 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3106 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3107 | Location rhs_location = locations->InAt(1); |
| 3108 | bool use_imm = rhs_location.IsConstant(); |
| 3109 | GpuRegister rhs = ZERO; |
| 3110 | if (use_imm) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3111 | if (in_type == DataType::Type::kInt64) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3112 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 3113 | if (value != 0) { |
| 3114 | rhs = AT; |
| 3115 | __ LoadConst64(rhs, value); |
| 3116 | } |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3117 | } else { |
| 3118 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 3119 | if (value != 0) { |
| 3120 | rhs = AT; |
| 3121 | __ LoadConst32(rhs, value); |
| 3122 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 3123 | } |
| 3124 | } else { |
| 3125 | rhs = rhs_location.AsRegister<GpuRegister>(); |
| 3126 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3127 | __ Slt(TMP, lhs, rhs); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3128 | __ Slt(res, rhs, lhs); |
| 3129 | __ Subu(res, res, TMP); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3130 | break; |
| 3131 | } |
| 3132 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3133 | case DataType::Type::kFloat32: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3134 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3135 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3136 | Mips64Label done; |
| 3137 | __ CmpEqS(FTMP, lhs, rhs); |
| 3138 | __ LoadConst32(res, 0); |
| 3139 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3140 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3141 | __ CmpLtS(FTMP, lhs, rhs); |
| 3142 | __ LoadConst32(res, -1); |
| 3143 | __ Bc1nez(FTMP, &done); |
| 3144 | __ LoadConst32(res, 1); |
| 3145 | } else { |
| 3146 | __ CmpLtS(FTMP, rhs, lhs); |
| 3147 | __ LoadConst32(res, 1); |
| 3148 | __ Bc1nez(FTMP, &done); |
| 3149 | __ LoadConst32(res, -1); |
| 3150 | } |
| 3151 | __ Bind(&done); |
| 3152 | break; |
| 3153 | } |
| 3154 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3155 | case DataType::Type::kFloat64: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3156 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3157 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3158 | Mips64Label done; |
| 3159 | __ CmpEqD(FTMP, lhs, rhs); |
| 3160 | __ LoadConst32(res, 0); |
| 3161 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3162 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3163 | __ CmpLtD(FTMP, lhs, rhs); |
| 3164 | __ LoadConst32(res, -1); |
| 3165 | __ Bc1nez(FTMP, &done); |
| 3166 | __ LoadConst32(res, 1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3167 | } else { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3168 | __ CmpLtD(FTMP, rhs, lhs); |
| 3169 | __ LoadConst32(res, 1); |
| 3170 | __ Bc1nez(FTMP, &done); |
| 3171 | __ LoadConst32(res, -1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3172 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3173 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3174 | break; |
| 3175 | } |
| 3176 | |
| 3177 | default: |
| 3178 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3179 | } |
| 3180 | } |
| 3181 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3182 | void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3183 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3184 | switch (instruction->InputAt(0)->GetType()) { |
| 3185 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3186 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3187 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3188 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3189 | break; |
| 3190 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3191 | case DataType::Type::kFloat32: |
| 3192 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3193 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3194 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3195 | break; |
| 3196 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3197 | if (!instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3198 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3199 | } |
| 3200 | } |
| 3201 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3202 | void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3203 | if (instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3204 | return; |
| 3205 | } |
| 3206 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3207 | DataType::Type type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3208 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3209 | switch (type) { |
| 3210 | default: |
| 3211 | // Integer case. |
| 3212 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations); |
| 3213 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3214 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3215 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations); |
| 3216 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3217 | case DataType::Type::kFloat32: |
| 3218 | case DataType::Type::kFloat64: |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3219 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 3220 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3221 | } |
| 3222 | } |
| 3223 | |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3224 | void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3225 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3226 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3227 | |
| 3228 | LocationSummary* locations = instruction->GetLocations(); |
| 3229 | Location second = locations->InAt(1); |
| 3230 | DCHECK(second.IsConstant()); |
| 3231 | |
| 3232 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3233 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3234 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3235 | DCHECK(imm == 1 || imm == -1); |
| 3236 | |
| 3237 | if (instruction->IsRem()) { |
| 3238 | __ Move(out, ZERO); |
| 3239 | } else { |
| 3240 | if (imm == -1) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3241 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3242 | __ Subu(out, ZERO, dividend); |
| 3243 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3244 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3245 | __ Dsubu(out, ZERO, dividend); |
| 3246 | } |
| 3247 | } else if (out != dividend) { |
| 3248 | __ Move(out, dividend); |
| 3249 | } |
| 3250 | } |
| 3251 | } |
| 3252 | |
| 3253 | void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3254 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3255 | DataType::Type type = instruction->GetResultType(); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3256 | |
| 3257 | LocationSummary* locations = instruction->GetLocations(); |
| 3258 | Location second = locations->InAt(1); |
| 3259 | DCHECK(second.IsConstant()); |
| 3260 | |
| 3261 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3262 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3263 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3264 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3265 | int ctz_imm = CTZ(abs_imm); |
| 3266 | |
| 3267 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3268 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3269 | if (ctz_imm == 1) { |
| 3270 | // Fast path for division by +/-2, which is very common. |
| 3271 | __ Srl(TMP, dividend, 31); |
| 3272 | } else { |
| 3273 | __ Sra(TMP, dividend, 31); |
| 3274 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3275 | } |
| 3276 | __ Addu(out, dividend, TMP); |
| 3277 | __ Sra(out, out, ctz_imm); |
| 3278 | if (imm < 0) { |
| 3279 | __ Subu(out, ZERO, out); |
| 3280 | } |
| 3281 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3282 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3283 | if (ctz_imm == 1) { |
| 3284 | // Fast path for division by +/-2, which is very common. |
| 3285 | __ Dsrl32(TMP, dividend, 31); |
| 3286 | } else { |
| 3287 | __ Dsra32(TMP, dividend, 31); |
| 3288 | if (ctz_imm > 32) { |
| 3289 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3290 | } else { |
| 3291 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3292 | } |
| 3293 | } |
| 3294 | __ Daddu(out, dividend, TMP); |
| 3295 | if (ctz_imm < 32) { |
| 3296 | __ Dsra(out, out, ctz_imm); |
| 3297 | } else { |
| 3298 | __ Dsra32(out, out, ctz_imm - 32); |
| 3299 | } |
| 3300 | if (imm < 0) { |
| 3301 | __ Dsubu(out, ZERO, out); |
| 3302 | } |
| 3303 | } |
| 3304 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3305 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3306 | if (ctz_imm == 1) { |
| 3307 | // Fast path for modulo +/-2, which is very common. |
| 3308 | __ Sra(TMP, dividend, 31); |
| 3309 | __ Subu(out, dividend, TMP); |
| 3310 | __ Andi(out, out, 1); |
| 3311 | __ Addu(out, out, TMP); |
| 3312 | } else { |
| 3313 | __ Sra(TMP, dividend, 31); |
| 3314 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3315 | __ Addu(out, dividend, TMP); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3316 | __ Ins(out, ZERO, ctz_imm, 32 - ctz_imm); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3317 | __ Subu(out, out, TMP); |
| 3318 | } |
| 3319 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3320 | DCHECK_EQ(type, DataType::Type::kInt64); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3321 | if (ctz_imm == 1) { |
| 3322 | // Fast path for modulo +/-2, which is very common. |
| 3323 | __ Dsra32(TMP, dividend, 31); |
| 3324 | __ Dsubu(out, dividend, TMP); |
| 3325 | __ Andi(out, out, 1); |
| 3326 | __ Daddu(out, out, TMP); |
| 3327 | } else { |
| 3328 | __ Dsra32(TMP, dividend, 31); |
| 3329 | if (ctz_imm > 32) { |
| 3330 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3331 | } else { |
| 3332 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3333 | } |
| 3334 | __ Daddu(out, dividend, TMP); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3335 | __ DblIns(out, ZERO, ctz_imm, 64 - ctz_imm); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3336 | __ Dsubu(out, out, TMP); |
| 3337 | } |
| 3338 | } |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3343 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3344 | |
| 3345 | LocationSummary* locations = instruction->GetLocations(); |
| 3346 | Location second = locations->InAt(1); |
| 3347 | DCHECK(second.IsConstant()); |
| 3348 | |
| 3349 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3350 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3351 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3352 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3353 | DataType::Type type = instruction->GetResultType(); |
| 3354 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type; |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3355 | |
| 3356 | int64_t magic; |
| 3357 | int shift; |
| 3358 | CalculateMagicAndShiftForDivRem(imm, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3359 | (type == DataType::Type::kInt64), |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3360 | &magic, |
| 3361 | &shift); |
| 3362 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3363 | if (type == DataType::Type::kInt32) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3364 | __ LoadConst32(TMP, magic); |
| 3365 | __ MuhR6(TMP, dividend, TMP); |
| 3366 | |
| 3367 | if (imm > 0 && magic < 0) { |
| 3368 | __ Addu(TMP, TMP, dividend); |
| 3369 | } else if (imm < 0 && magic > 0) { |
| 3370 | __ Subu(TMP, TMP, dividend); |
| 3371 | } |
| 3372 | |
| 3373 | if (shift != 0) { |
| 3374 | __ Sra(TMP, TMP, shift); |
| 3375 | } |
| 3376 | |
| 3377 | if (instruction->IsDiv()) { |
| 3378 | __ Sra(out, TMP, 31); |
| 3379 | __ Subu(out, TMP, out); |
| 3380 | } else { |
| 3381 | __ Sra(AT, TMP, 31); |
| 3382 | __ Subu(AT, TMP, AT); |
| 3383 | __ LoadConst32(TMP, imm); |
| 3384 | __ MulR6(TMP, AT, TMP); |
| 3385 | __ Subu(out, dividend, TMP); |
| 3386 | } |
| 3387 | } else { |
| 3388 | __ LoadConst64(TMP, magic); |
| 3389 | __ Dmuh(TMP, dividend, TMP); |
| 3390 | |
| 3391 | if (imm > 0 && magic < 0) { |
| 3392 | __ Daddu(TMP, TMP, dividend); |
| 3393 | } else if (imm < 0 && magic > 0) { |
| 3394 | __ Dsubu(TMP, TMP, dividend); |
| 3395 | } |
| 3396 | |
| 3397 | if (shift >= 32) { |
| 3398 | __ Dsra32(TMP, TMP, shift - 32); |
| 3399 | } else if (shift > 0) { |
| 3400 | __ Dsra(TMP, TMP, shift); |
| 3401 | } |
| 3402 | |
| 3403 | if (instruction->IsDiv()) { |
| 3404 | __ Dsra32(out, TMP, 31); |
| 3405 | __ Dsubu(out, TMP, out); |
| 3406 | } else { |
| 3407 | __ Dsra32(AT, TMP, 31); |
| 3408 | __ Dsubu(AT, TMP, AT); |
| 3409 | __ LoadConst64(TMP, imm); |
| 3410 | __ Dmul(TMP, AT, TMP); |
| 3411 | __ Dsubu(out, dividend, TMP); |
| 3412 | } |
| 3413 | } |
| 3414 | } |
| 3415 | |
| 3416 | void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3417 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3418 | DataType::Type type = instruction->GetResultType(); |
| 3419 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64) << type; |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3420 | |
| 3421 | LocationSummary* locations = instruction->GetLocations(); |
| 3422 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3423 | Location second = locations->InAt(1); |
| 3424 | |
| 3425 | if (second.IsConstant()) { |
| 3426 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3427 | if (imm == 0) { |
| 3428 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3429 | } else if (imm == 1 || imm == -1) { |
| 3430 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3431 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3432 | DivRemByPowerOfTwo(instruction); |
| 3433 | } else { |
| 3434 | DCHECK(imm <= -2 || imm >= 2); |
| 3435 | GenerateDivRemWithAnyConstant(instruction); |
| 3436 | } |
| 3437 | } else { |
| 3438 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3439 | GpuRegister divisor = second.AsRegister<GpuRegister>(); |
| 3440 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3441 | if (type == DataType::Type::kInt32) |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3442 | __ DivR6(out, dividend, divisor); |
| 3443 | else |
| 3444 | __ Ddiv(out, dividend, divisor); |
| 3445 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3446 | if (type == DataType::Type::kInt32) |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3447 | __ ModR6(out, dividend, divisor); |
| 3448 | else |
| 3449 | __ Dmod(out, dividend, divisor); |
| 3450 | } |
| 3451 | } |
| 3452 | } |
| 3453 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3454 | void LocationsBuilderMIPS64::VisitDiv(HDiv* div) { |
| 3455 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3456 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3457 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3458 | case DataType::Type::kInt32: |
| 3459 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3460 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3461 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3462 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3463 | break; |
| 3464 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3465 | case DataType::Type::kFloat32: |
| 3466 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3467 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3468 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3469 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3470 | break; |
| 3471 | |
| 3472 | default: |
| 3473 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3474 | } |
| 3475 | } |
| 3476 | |
| 3477 | void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3478 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3479 | LocationSummary* locations = instruction->GetLocations(); |
| 3480 | |
| 3481 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3482 | case DataType::Type::kInt32: |
| 3483 | case DataType::Type::kInt64: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3484 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3485 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3486 | case DataType::Type::kFloat32: |
| 3487 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3488 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 3489 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3490 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3491 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3492 | __ DivS(dst, lhs, rhs); |
| 3493 | else |
| 3494 | __ DivD(dst, lhs, rhs); |
| 3495 | break; |
| 3496 | } |
| 3497 | default: |
| 3498 | LOG(FATAL) << "Unexpected div type " << type; |
| 3499 | } |
| 3500 | } |
| 3501 | |
| 3502 | void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3503 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3504 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3505 | } |
| 3506 | |
| 3507 | void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3508 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3509 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS64(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3510 | codegen_->AddSlowPath(slow_path); |
| 3511 | Location value = instruction->GetLocations()->InAt(0); |
| 3512 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3513 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3514 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3515 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3516 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3517 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3518 | } |
| 3519 | |
| 3520 | if (value.IsConstant()) { |
| 3521 | int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant()); |
| 3522 | if (divisor == 0) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3523 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3524 | } else { |
| 3525 | // A division by a non-null constant is valid. We don't need to perform |
| 3526 | // any check, so simply fall through. |
| 3527 | } |
| 3528 | } else { |
| 3529 | __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 3530 | } |
| 3531 | } |
| 3532 | |
| 3533 | void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3534 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3535 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3536 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3537 | } |
| 3538 | |
| 3539 | void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 3540 | // Will be generated at use site. |
| 3541 | } |
| 3542 | |
| 3543 | void LocationsBuilderMIPS64::VisitExit(HExit* exit) { |
| 3544 | exit->SetLocations(nullptr); |
| 3545 | } |
| 3546 | |
| 3547 | void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 3548 | } |
| 3549 | |
| 3550 | void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) { |
| 3551 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3552 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3553 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3554 | } |
| 3555 | |
| 3556 | void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 3557 | // Will be generated at use site. |
| 3558 | } |
| 3559 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3560 | void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3561 | if (successor->IsExitBlock()) { |
| 3562 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3563 | return; // no code needed |
| 3564 | } |
| 3565 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3566 | HBasicBlock* block = got->GetBlock(); |
| 3567 | HInstruction* previous = got->GetPrevious(); |
| 3568 | HLoopInformation* info = block->GetLoopInformation(); |
| 3569 | |
| 3570 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Goran Jakovljevic | feec167 | 2018-02-08 10:20:14 +0100 | [diff] [blame] | 3571 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 3572 | __ Ld(AT, SP, kCurrentMethodStackOffset); |
| 3573 | __ Lhu(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value()); |
| 3574 | __ Addiu(TMP, TMP, 1); |
| 3575 | __ Sh(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value()); |
| 3576 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3577 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3578 | return; |
| 3579 | } |
| 3580 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3581 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3582 | } |
| 3583 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3584 | __ Bc(codegen_->GetLabelOf(successor)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3585 | } |
| 3586 | } |
| 3587 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3588 | void LocationsBuilderMIPS64::VisitGoto(HGoto* got) { |
| 3589 | got->SetLocations(nullptr); |
| 3590 | } |
| 3591 | |
| 3592 | void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) { |
| 3593 | HandleGoto(got, got->GetSuccessor()); |
| 3594 | } |
| 3595 | |
| 3596 | void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3597 | try_boundary->SetLocations(nullptr); |
| 3598 | } |
| 3599 | |
| 3600 | void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3601 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3602 | if (!successor->IsExitBlock()) { |
| 3603 | HandleGoto(try_boundary, successor); |
| 3604 | } |
| 3605 | } |
| 3606 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3607 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond, |
| 3608 | bool is64bit, |
| 3609 | LocationSummary* locations) { |
| 3610 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3611 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3612 | Location rhs_location = locations->InAt(1); |
| 3613 | GpuRegister rhs_reg = ZERO; |
| 3614 | int64_t rhs_imm = 0; |
| 3615 | bool use_imm = rhs_location.IsConstant(); |
| 3616 | if (use_imm) { |
| 3617 | if (is64bit) { |
| 3618 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3619 | } else { |
| 3620 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3621 | } |
| 3622 | } else { |
| 3623 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3624 | } |
| 3625 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 3626 | |
| 3627 | switch (cond) { |
| 3628 | case kCondEQ: |
| 3629 | case kCondNE: |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3630 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3631 | if (rhs_imm == 0) { |
| 3632 | if (cond == kCondEQ) { |
| 3633 | __ Sltiu(dst, lhs, 1); |
| 3634 | } else { |
| 3635 | __ Sltu(dst, ZERO, lhs); |
| 3636 | } |
| 3637 | } else { |
| 3638 | if (is64bit) { |
| 3639 | __ Daddiu(dst, lhs, -rhs_imm); |
| 3640 | } else { |
| 3641 | __ Addiu(dst, lhs, -rhs_imm); |
| 3642 | } |
| 3643 | if (cond == kCondEQ) { |
| 3644 | __ Sltiu(dst, dst, 1); |
| 3645 | } else { |
| 3646 | __ Sltu(dst, ZERO, dst); |
| 3647 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3648 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3649 | } else { |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3650 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 3651 | __ Xori(dst, lhs, rhs_imm); |
| 3652 | } else { |
| 3653 | if (use_imm) { |
| 3654 | rhs_reg = TMP; |
| 3655 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3656 | } |
| 3657 | __ Xor(dst, lhs, rhs_reg); |
| 3658 | } |
| 3659 | if (cond == kCondEQ) { |
| 3660 | __ Sltiu(dst, dst, 1); |
| 3661 | } else { |
| 3662 | __ Sltu(dst, ZERO, dst); |
| 3663 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3664 | } |
| 3665 | break; |
| 3666 | |
| 3667 | case kCondLT: |
| 3668 | case kCondGE: |
| 3669 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3670 | __ Slti(dst, lhs, rhs_imm); |
| 3671 | } else { |
| 3672 | if (use_imm) { |
| 3673 | rhs_reg = TMP; |
| 3674 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3675 | } |
| 3676 | __ Slt(dst, lhs, rhs_reg); |
| 3677 | } |
| 3678 | if (cond == kCondGE) { |
| 3679 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3680 | // only the slt instruction but no sge. |
| 3681 | __ Xori(dst, dst, 1); |
| 3682 | } |
| 3683 | break; |
| 3684 | |
| 3685 | case kCondLE: |
| 3686 | case kCondGT: |
| 3687 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 3688 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3689 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 3690 | if (cond == kCondGT) { |
| 3691 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3692 | // only the slti instruction but no sgti. |
| 3693 | __ Xori(dst, dst, 1); |
| 3694 | } |
| 3695 | } else { |
| 3696 | if (use_imm) { |
| 3697 | rhs_reg = TMP; |
| 3698 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3699 | } |
| 3700 | __ Slt(dst, rhs_reg, lhs); |
| 3701 | if (cond == kCondLE) { |
| 3702 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3703 | // only the slt instruction but no sle. |
| 3704 | __ Xori(dst, dst, 1); |
| 3705 | } |
| 3706 | } |
| 3707 | break; |
| 3708 | |
| 3709 | case kCondB: |
| 3710 | case kCondAE: |
| 3711 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3712 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3713 | // the comparison and thus lets us compare directly with |
| 3714 | // unsigned values in the ranges [0, 0x7fff] and |
| 3715 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3716 | __ Sltiu(dst, lhs, rhs_imm); |
| 3717 | } else { |
| 3718 | if (use_imm) { |
| 3719 | rhs_reg = TMP; |
| 3720 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3721 | } |
| 3722 | __ Sltu(dst, lhs, rhs_reg); |
| 3723 | } |
| 3724 | if (cond == kCondAE) { |
| 3725 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3726 | // only the sltu instruction but no sgeu. |
| 3727 | __ Xori(dst, dst, 1); |
| 3728 | } |
| 3729 | break; |
| 3730 | |
| 3731 | case kCondBE: |
| 3732 | case kCondA: |
| 3733 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 3734 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3735 | // Note that this only works if rhs + 1 does not overflow |
| 3736 | // to 0, hence the check above. |
| 3737 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3738 | // the comparison and thus lets us compare directly with |
| 3739 | // unsigned values in the ranges [0, 0x7fff] and |
| 3740 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3741 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 3742 | if (cond == kCondA) { |
| 3743 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3744 | // only the sltiu instruction but no sgtiu. |
| 3745 | __ Xori(dst, dst, 1); |
| 3746 | } |
| 3747 | } else { |
| 3748 | if (use_imm) { |
| 3749 | rhs_reg = TMP; |
| 3750 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3751 | } |
| 3752 | __ Sltu(dst, rhs_reg, lhs); |
| 3753 | if (cond == kCondBE) { |
| 3754 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3755 | // only the sltu instruction but no sleu. |
| 3756 | __ Xori(dst, dst, 1); |
| 3757 | } |
| 3758 | } |
| 3759 | break; |
| 3760 | } |
| 3761 | } |
| 3762 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 3763 | bool InstructionCodeGeneratorMIPS64::MaterializeIntLongCompare(IfCondition cond, |
| 3764 | bool is64bit, |
| 3765 | LocationSummary* input_locations, |
| 3766 | GpuRegister dst) { |
| 3767 | GpuRegister lhs = input_locations->InAt(0).AsRegister<GpuRegister>(); |
| 3768 | Location rhs_location = input_locations->InAt(1); |
| 3769 | GpuRegister rhs_reg = ZERO; |
| 3770 | int64_t rhs_imm = 0; |
| 3771 | bool use_imm = rhs_location.IsConstant(); |
| 3772 | if (use_imm) { |
| 3773 | if (is64bit) { |
| 3774 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3775 | } else { |
| 3776 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3777 | } |
| 3778 | } else { |
| 3779 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3780 | } |
| 3781 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 3782 | |
| 3783 | switch (cond) { |
| 3784 | case kCondEQ: |
| 3785 | case kCondNE: |
| 3786 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3787 | if (is64bit) { |
| 3788 | __ Daddiu(dst, lhs, -rhs_imm); |
| 3789 | } else { |
| 3790 | __ Addiu(dst, lhs, -rhs_imm); |
| 3791 | } |
| 3792 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 3793 | __ Xori(dst, lhs, rhs_imm); |
| 3794 | } else { |
| 3795 | if (use_imm) { |
| 3796 | rhs_reg = TMP; |
| 3797 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3798 | } |
| 3799 | __ Xor(dst, lhs, rhs_reg); |
| 3800 | } |
| 3801 | return (cond == kCondEQ); |
| 3802 | |
| 3803 | case kCondLT: |
| 3804 | case kCondGE: |
| 3805 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3806 | __ Slti(dst, lhs, rhs_imm); |
| 3807 | } else { |
| 3808 | if (use_imm) { |
| 3809 | rhs_reg = TMP; |
| 3810 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3811 | } |
| 3812 | __ Slt(dst, lhs, rhs_reg); |
| 3813 | } |
| 3814 | return (cond == kCondGE); |
| 3815 | |
| 3816 | case kCondLE: |
| 3817 | case kCondGT: |
| 3818 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 3819 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3820 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 3821 | return (cond == kCondGT); |
| 3822 | } else { |
| 3823 | if (use_imm) { |
| 3824 | rhs_reg = TMP; |
| 3825 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3826 | } |
| 3827 | __ Slt(dst, rhs_reg, lhs); |
| 3828 | return (cond == kCondLE); |
| 3829 | } |
| 3830 | |
| 3831 | case kCondB: |
| 3832 | case kCondAE: |
| 3833 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3834 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3835 | // the comparison and thus lets us compare directly with |
| 3836 | // unsigned values in the ranges [0, 0x7fff] and |
| 3837 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3838 | __ Sltiu(dst, lhs, rhs_imm); |
| 3839 | } else { |
| 3840 | if (use_imm) { |
| 3841 | rhs_reg = TMP; |
| 3842 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3843 | } |
| 3844 | __ Sltu(dst, lhs, rhs_reg); |
| 3845 | } |
| 3846 | return (cond == kCondAE); |
| 3847 | |
| 3848 | case kCondBE: |
| 3849 | case kCondA: |
| 3850 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 3851 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3852 | // Note that this only works if rhs + 1 does not overflow |
| 3853 | // to 0, hence the check above. |
| 3854 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3855 | // the comparison and thus lets us compare directly with |
| 3856 | // unsigned values in the ranges [0, 0x7fff] and |
| 3857 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3858 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 3859 | return (cond == kCondA); |
| 3860 | } else { |
| 3861 | if (use_imm) { |
| 3862 | rhs_reg = TMP; |
| 3863 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3864 | } |
| 3865 | __ Sltu(dst, rhs_reg, lhs); |
| 3866 | return (cond == kCondBE); |
| 3867 | } |
| 3868 | } |
| 3869 | } |
| 3870 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3871 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond, |
| 3872 | bool is64bit, |
| 3873 | LocationSummary* locations, |
| 3874 | Mips64Label* label) { |
| 3875 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3876 | Location rhs_location = locations->InAt(1); |
| 3877 | GpuRegister rhs_reg = ZERO; |
| 3878 | int64_t rhs_imm = 0; |
| 3879 | bool use_imm = rhs_location.IsConstant(); |
| 3880 | if (use_imm) { |
| 3881 | if (is64bit) { |
| 3882 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3883 | } else { |
| 3884 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3885 | } |
| 3886 | } else { |
| 3887 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3888 | } |
| 3889 | |
| 3890 | if (use_imm && rhs_imm == 0) { |
| 3891 | switch (cond) { |
| 3892 | case kCondEQ: |
| 3893 | case kCondBE: // <= 0 if zero |
| 3894 | __ Beqzc(lhs, label); |
| 3895 | break; |
| 3896 | case kCondNE: |
| 3897 | case kCondA: // > 0 if non-zero |
| 3898 | __ Bnezc(lhs, label); |
| 3899 | break; |
| 3900 | case kCondLT: |
| 3901 | __ Bltzc(lhs, label); |
| 3902 | break; |
| 3903 | case kCondGE: |
| 3904 | __ Bgezc(lhs, label); |
| 3905 | break; |
| 3906 | case kCondLE: |
| 3907 | __ Blezc(lhs, label); |
| 3908 | break; |
| 3909 | case kCondGT: |
| 3910 | __ Bgtzc(lhs, label); |
| 3911 | break; |
| 3912 | case kCondB: // always false |
| 3913 | break; |
| 3914 | case kCondAE: // always true |
| 3915 | __ Bc(label); |
| 3916 | break; |
| 3917 | } |
| 3918 | } else { |
| 3919 | if (use_imm) { |
| 3920 | rhs_reg = TMP; |
| 3921 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3922 | } |
| 3923 | switch (cond) { |
| 3924 | case kCondEQ: |
| 3925 | __ Beqc(lhs, rhs_reg, label); |
| 3926 | break; |
| 3927 | case kCondNE: |
| 3928 | __ Bnec(lhs, rhs_reg, label); |
| 3929 | break; |
| 3930 | case kCondLT: |
| 3931 | __ Bltc(lhs, rhs_reg, label); |
| 3932 | break; |
| 3933 | case kCondGE: |
| 3934 | __ Bgec(lhs, rhs_reg, label); |
| 3935 | break; |
| 3936 | case kCondLE: |
| 3937 | __ Bgec(rhs_reg, lhs, label); |
| 3938 | break; |
| 3939 | case kCondGT: |
| 3940 | __ Bltc(rhs_reg, lhs, label); |
| 3941 | break; |
| 3942 | case kCondB: |
| 3943 | __ Bltuc(lhs, rhs_reg, label); |
| 3944 | break; |
| 3945 | case kCondAE: |
| 3946 | __ Bgeuc(lhs, rhs_reg, label); |
| 3947 | break; |
| 3948 | case kCondBE: |
| 3949 | __ Bgeuc(rhs_reg, lhs, label); |
| 3950 | break; |
| 3951 | case kCondA: |
| 3952 | __ Bltuc(rhs_reg, lhs, label); |
| 3953 | break; |
| 3954 | } |
| 3955 | } |
| 3956 | } |
| 3957 | |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3958 | void InstructionCodeGeneratorMIPS64::GenerateFpCompare(IfCondition cond, |
| 3959 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3960 | DataType::Type type, |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3961 | LocationSummary* locations) { |
| 3962 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3963 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3964 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3965 | if (type == DataType::Type::kFloat32) { |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3966 | switch (cond) { |
| 3967 | case kCondEQ: |
| 3968 | __ CmpEqS(FTMP, lhs, rhs); |
| 3969 | __ Mfc1(dst, FTMP); |
| 3970 | __ Andi(dst, dst, 1); |
| 3971 | break; |
| 3972 | case kCondNE: |
| 3973 | __ CmpEqS(FTMP, lhs, rhs); |
| 3974 | __ Mfc1(dst, FTMP); |
| 3975 | __ Addiu(dst, dst, 1); |
| 3976 | break; |
| 3977 | case kCondLT: |
| 3978 | if (gt_bias) { |
| 3979 | __ CmpLtS(FTMP, lhs, rhs); |
| 3980 | } else { |
| 3981 | __ CmpUltS(FTMP, lhs, rhs); |
| 3982 | } |
| 3983 | __ Mfc1(dst, FTMP); |
| 3984 | __ Andi(dst, dst, 1); |
| 3985 | break; |
| 3986 | case kCondLE: |
| 3987 | if (gt_bias) { |
| 3988 | __ CmpLeS(FTMP, lhs, rhs); |
| 3989 | } else { |
| 3990 | __ CmpUleS(FTMP, lhs, rhs); |
| 3991 | } |
| 3992 | __ Mfc1(dst, FTMP); |
| 3993 | __ Andi(dst, dst, 1); |
| 3994 | break; |
| 3995 | case kCondGT: |
| 3996 | if (gt_bias) { |
| 3997 | __ CmpUltS(FTMP, rhs, lhs); |
| 3998 | } else { |
| 3999 | __ CmpLtS(FTMP, rhs, lhs); |
| 4000 | } |
| 4001 | __ Mfc1(dst, FTMP); |
| 4002 | __ Andi(dst, dst, 1); |
| 4003 | break; |
| 4004 | case kCondGE: |
| 4005 | if (gt_bias) { |
| 4006 | __ CmpUleS(FTMP, rhs, lhs); |
| 4007 | } else { |
| 4008 | __ CmpLeS(FTMP, rhs, lhs); |
| 4009 | } |
| 4010 | __ Mfc1(dst, FTMP); |
| 4011 | __ Andi(dst, dst, 1); |
| 4012 | break; |
| 4013 | default: |
| 4014 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4015 | UNREACHABLE(); |
| 4016 | } |
| 4017 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4018 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 4019 | switch (cond) { |
| 4020 | case kCondEQ: |
| 4021 | __ CmpEqD(FTMP, lhs, rhs); |
| 4022 | __ Mfc1(dst, FTMP); |
| 4023 | __ Andi(dst, dst, 1); |
| 4024 | break; |
| 4025 | case kCondNE: |
| 4026 | __ CmpEqD(FTMP, lhs, rhs); |
| 4027 | __ Mfc1(dst, FTMP); |
| 4028 | __ Addiu(dst, dst, 1); |
| 4029 | break; |
| 4030 | case kCondLT: |
| 4031 | if (gt_bias) { |
| 4032 | __ CmpLtD(FTMP, lhs, rhs); |
| 4033 | } else { |
| 4034 | __ CmpUltD(FTMP, lhs, rhs); |
| 4035 | } |
| 4036 | __ Mfc1(dst, FTMP); |
| 4037 | __ Andi(dst, dst, 1); |
| 4038 | break; |
| 4039 | case kCondLE: |
| 4040 | if (gt_bias) { |
| 4041 | __ CmpLeD(FTMP, lhs, rhs); |
| 4042 | } else { |
| 4043 | __ CmpUleD(FTMP, lhs, rhs); |
| 4044 | } |
| 4045 | __ Mfc1(dst, FTMP); |
| 4046 | __ Andi(dst, dst, 1); |
| 4047 | break; |
| 4048 | case kCondGT: |
| 4049 | if (gt_bias) { |
| 4050 | __ CmpUltD(FTMP, rhs, lhs); |
| 4051 | } else { |
| 4052 | __ CmpLtD(FTMP, rhs, lhs); |
| 4053 | } |
| 4054 | __ Mfc1(dst, FTMP); |
| 4055 | __ Andi(dst, dst, 1); |
| 4056 | break; |
| 4057 | case kCondGE: |
| 4058 | if (gt_bias) { |
| 4059 | __ CmpUleD(FTMP, rhs, lhs); |
| 4060 | } else { |
| 4061 | __ CmpLeD(FTMP, rhs, lhs); |
| 4062 | } |
| 4063 | __ Mfc1(dst, FTMP); |
| 4064 | __ Andi(dst, dst, 1); |
| 4065 | break; |
| 4066 | default: |
| 4067 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4068 | UNREACHABLE(); |
| 4069 | } |
| 4070 | } |
| 4071 | } |
| 4072 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4073 | bool InstructionCodeGeneratorMIPS64::MaterializeFpCompare(IfCondition cond, |
| 4074 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4075 | DataType::Type type, |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4076 | LocationSummary* input_locations, |
| 4077 | FpuRegister dst) { |
| 4078 | FpuRegister lhs = input_locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 4079 | FpuRegister rhs = input_locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4080 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4081 | switch (cond) { |
| 4082 | case kCondEQ: |
| 4083 | __ CmpEqS(dst, lhs, rhs); |
| 4084 | return false; |
| 4085 | case kCondNE: |
| 4086 | __ CmpEqS(dst, lhs, rhs); |
| 4087 | return true; |
| 4088 | case kCondLT: |
| 4089 | if (gt_bias) { |
| 4090 | __ CmpLtS(dst, lhs, rhs); |
| 4091 | } else { |
| 4092 | __ CmpUltS(dst, lhs, rhs); |
| 4093 | } |
| 4094 | return false; |
| 4095 | case kCondLE: |
| 4096 | if (gt_bias) { |
| 4097 | __ CmpLeS(dst, lhs, rhs); |
| 4098 | } else { |
| 4099 | __ CmpUleS(dst, lhs, rhs); |
| 4100 | } |
| 4101 | return false; |
| 4102 | case kCondGT: |
| 4103 | if (gt_bias) { |
| 4104 | __ CmpUltS(dst, rhs, lhs); |
| 4105 | } else { |
| 4106 | __ CmpLtS(dst, rhs, lhs); |
| 4107 | } |
| 4108 | return false; |
| 4109 | case kCondGE: |
| 4110 | if (gt_bias) { |
| 4111 | __ CmpUleS(dst, rhs, lhs); |
| 4112 | } else { |
| 4113 | __ CmpLeS(dst, rhs, lhs); |
| 4114 | } |
| 4115 | return false; |
| 4116 | default: |
| 4117 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4118 | UNREACHABLE(); |
| 4119 | } |
| 4120 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4121 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4122 | switch (cond) { |
| 4123 | case kCondEQ: |
| 4124 | __ CmpEqD(dst, lhs, rhs); |
| 4125 | return false; |
| 4126 | case kCondNE: |
| 4127 | __ CmpEqD(dst, lhs, rhs); |
| 4128 | return true; |
| 4129 | case kCondLT: |
| 4130 | if (gt_bias) { |
| 4131 | __ CmpLtD(dst, lhs, rhs); |
| 4132 | } else { |
| 4133 | __ CmpUltD(dst, lhs, rhs); |
| 4134 | } |
| 4135 | return false; |
| 4136 | case kCondLE: |
| 4137 | if (gt_bias) { |
| 4138 | __ CmpLeD(dst, lhs, rhs); |
| 4139 | } else { |
| 4140 | __ CmpUleD(dst, lhs, rhs); |
| 4141 | } |
| 4142 | return false; |
| 4143 | case kCondGT: |
| 4144 | if (gt_bias) { |
| 4145 | __ CmpUltD(dst, rhs, lhs); |
| 4146 | } else { |
| 4147 | __ CmpLtD(dst, rhs, lhs); |
| 4148 | } |
| 4149 | return false; |
| 4150 | case kCondGE: |
| 4151 | if (gt_bias) { |
| 4152 | __ CmpUleD(dst, rhs, lhs); |
| 4153 | } else { |
| 4154 | __ CmpLeD(dst, rhs, lhs); |
| 4155 | } |
| 4156 | return false; |
| 4157 | default: |
| 4158 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4159 | UNREACHABLE(); |
| 4160 | } |
| 4161 | } |
| 4162 | } |
| 4163 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4164 | void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond, |
| 4165 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4166 | DataType::Type type, |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4167 | LocationSummary* locations, |
| 4168 | Mips64Label* label) { |
| 4169 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 4170 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4171 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4172 | switch (cond) { |
| 4173 | case kCondEQ: |
| 4174 | __ CmpEqS(FTMP, lhs, rhs); |
| 4175 | __ Bc1nez(FTMP, label); |
| 4176 | break; |
| 4177 | case kCondNE: |
| 4178 | __ CmpEqS(FTMP, lhs, rhs); |
| 4179 | __ Bc1eqz(FTMP, label); |
| 4180 | break; |
| 4181 | case kCondLT: |
| 4182 | if (gt_bias) { |
| 4183 | __ CmpLtS(FTMP, lhs, rhs); |
| 4184 | } else { |
| 4185 | __ CmpUltS(FTMP, lhs, rhs); |
| 4186 | } |
| 4187 | __ Bc1nez(FTMP, label); |
| 4188 | break; |
| 4189 | case kCondLE: |
| 4190 | if (gt_bias) { |
| 4191 | __ CmpLeS(FTMP, lhs, rhs); |
| 4192 | } else { |
| 4193 | __ CmpUleS(FTMP, lhs, rhs); |
| 4194 | } |
| 4195 | __ Bc1nez(FTMP, label); |
| 4196 | break; |
| 4197 | case kCondGT: |
| 4198 | if (gt_bias) { |
| 4199 | __ CmpUltS(FTMP, rhs, lhs); |
| 4200 | } else { |
| 4201 | __ CmpLtS(FTMP, rhs, lhs); |
| 4202 | } |
| 4203 | __ Bc1nez(FTMP, label); |
| 4204 | break; |
| 4205 | case kCondGE: |
| 4206 | if (gt_bias) { |
| 4207 | __ CmpUleS(FTMP, rhs, lhs); |
| 4208 | } else { |
| 4209 | __ CmpLeS(FTMP, rhs, lhs); |
| 4210 | } |
| 4211 | __ Bc1nez(FTMP, label); |
| 4212 | break; |
| 4213 | default: |
| 4214 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4215 | UNREACHABLE(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4216 | } |
| 4217 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4218 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4219 | switch (cond) { |
| 4220 | case kCondEQ: |
| 4221 | __ CmpEqD(FTMP, lhs, rhs); |
| 4222 | __ Bc1nez(FTMP, label); |
| 4223 | break; |
| 4224 | case kCondNE: |
| 4225 | __ CmpEqD(FTMP, lhs, rhs); |
| 4226 | __ Bc1eqz(FTMP, label); |
| 4227 | break; |
| 4228 | case kCondLT: |
| 4229 | if (gt_bias) { |
| 4230 | __ CmpLtD(FTMP, lhs, rhs); |
| 4231 | } else { |
| 4232 | __ CmpUltD(FTMP, lhs, rhs); |
| 4233 | } |
| 4234 | __ Bc1nez(FTMP, label); |
| 4235 | break; |
| 4236 | case kCondLE: |
| 4237 | if (gt_bias) { |
| 4238 | __ CmpLeD(FTMP, lhs, rhs); |
| 4239 | } else { |
| 4240 | __ CmpUleD(FTMP, lhs, rhs); |
| 4241 | } |
| 4242 | __ Bc1nez(FTMP, label); |
| 4243 | break; |
| 4244 | case kCondGT: |
| 4245 | if (gt_bias) { |
| 4246 | __ CmpUltD(FTMP, rhs, lhs); |
| 4247 | } else { |
| 4248 | __ CmpLtD(FTMP, rhs, lhs); |
| 4249 | } |
| 4250 | __ Bc1nez(FTMP, label); |
| 4251 | break; |
| 4252 | case kCondGE: |
| 4253 | if (gt_bias) { |
| 4254 | __ CmpUleD(FTMP, rhs, lhs); |
| 4255 | } else { |
| 4256 | __ CmpLeD(FTMP, rhs, lhs); |
| 4257 | } |
| 4258 | __ Bc1nez(FTMP, label); |
| 4259 | break; |
| 4260 | default: |
| 4261 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4262 | UNREACHABLE(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4263 | } |
| 4264 | } |
| 4265 | } |
| 4266 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4267 | void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4268 | size_t condition_input_index, |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4269 | Mips64Label* true_target, |
| 4270 | Mips64Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4271 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4272 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4273 | if (true_target == nullptr && false_target == nullptr) { |
| 4274 | // Nothing to do. The code always falls through. |
| 4275 | return; |
| 4276 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4277 | // Constant condition, statically compared against "true" (integer value 1). |
| 4278 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4279 | if (true_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4280 | __ Bc(true_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4281 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4282 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4283 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4284 | if (false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4285 | __ Bc(false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4286 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4287 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4288 | return; |
| 4289 | } |
| 4290 | |
| 4291 | // The following code generates these patterns: |
| 4292 | // (1) true_target == nullptr && false_target != nullptr |
| 4293 | // - opposite condition true => branch to false_target |
| 4294 | // (2) true_target != nullptr && false_target == nullptr |
| 4295 | // - condition true => branch to true_target |
| 4296 | // (3) true_target != nullptr && false_target != nullptr |
| 4297 | // - condition true => branch to true_target |
| 4298 | // - branch to false_target |
| 4299 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4300 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4301 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4302 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4303 | if (true_target == nullptr) { |
| 4304 | __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target); |
| 4305 | } else { |
| 4306 | __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target); |
| 4307 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4308 | } else { |
| 4309 | // The condition instruction has not been materialized, use its inputs as |
| 4310 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4311 | HCondition* condition = cond->AsCondition(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4312 | DataType::Type type = condition->InputAt(0)->GetType(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4313 | LocationSummary* locations = cond->GetLocations(); |
| 4314 | IfCondition if_cond = condition->GetCondition(); |
| 4315 | Mips64Label* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4316 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4317 | if (true_target == nullptr) { |
| 4318 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4319 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4320 | } |
| 4321 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4322 | switch (type) { |
| 4323 | default: |
| 4324 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target); |
| 4325 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4326 | case DataType::Type::kInt64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4327 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target); |
| 4328 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4329 | case DataType::Type::kFloat32: |
| 4330 | case DataType::Type::kFloat64: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 4331 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 4332 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4333 | } |
| 4334 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4335 | |
| 4336 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 4337 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 4338 | if (true_target != nullptr && false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4339 | __ Bc(false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4340 | } |
| 4341 | } |
| 4342 | |
| 4343 | void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4344 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4345 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4346 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4347 | } |
| 4348 | } |
| 4349 | |
| 4350 | void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4351 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 4352 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4353 | Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4354 | nullptr : codegen_->GetLabelOf(true_successor); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4355 | Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4356 | nullptr : codegen_->GetLabelOf(false_successor); |
| 4357 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4358 | } |
| 4359 | |
| 4360 | void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4361 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4362 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 4363 | InvokeRuntimeCallingConvention calling_convention; |
| 4364 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4365 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4366 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4367 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4368 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4369 | } |
| 4370 | } |
| 4371 | |
| 4372 | void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 4373 | SlowPathCodeMIPS64* slow_path = |
| 4374 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4375 | GenerateTestAndBranch(deoptimize, |
| 4376 | /* condition_input_index */ 0, |
| 4377 | slow_path->GetEntryLabel(), |
| 4378 | /* false_target */ nullptr); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4379 | } |
| 4380 | |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4381 | // This function returns true if a conditional move can be generated for HSelect. |
| 4382 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 4383 | // branches and regular moves. |
| 4384 | // |
| 4385 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 4386 | // |
| 4387 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 4388 | // are two distinct tasks, this function does both because they share quite a bit |
| 4389 | // of common logic. |
| 4390 | static bool CanMoveConditionally(HSelect* select, LocationSummary* locations_to_set) { |
| 4391 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 4392 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4393 | HCondition* condition = cond->AsCondition(); |
| 4394 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4395 | DataType::Type cond_type = |
| 4396 | materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType(); |
| 4397 | DataType::Type dst_type = select->GetType(); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4398 | |
| 4399 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 4400 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 4401 | bool is_true_value_zero_constant = |
| 4402 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 4403 | bool is_false_value_zero_constant = |
| 4404 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 4405 | |
| 4406 | bool can_move_conditionally = false; |
| 4407 | bool use_const_for_false_in = false; |
| 4408 | bool use_const_for_true_in = false; |
| 4409 | |
| 4410 | if (!cond->IsConstant()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4411 | if (!DataType::IsFloatingPointType(cond_type)) { |
| 4412 | if (!DataType::IsFloatingPointType(dst_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4413 | // Moving int/long on int/long condition. |
| 4414 | if (is_true_value_zero_constant) { |
| 4415 | // seleqz out_reg, false_reg, cond_reg |
| 4416 | can_move_conditionally = true; |
| 4417 | use_const_for_true_in = true; |
| 4418 | } else if (is_false_value_zero_constant) { |
| 4419 | // selnez out_reg, true_reg, cond_reg |
| 4420 | can_move_conditionally = true; |
| 4421 | use_const_for_false_in = true; |
| 4422 | } else if (materialized) { |
| 4423 | // Not materializing unmaterialized int conditions |
| 4424 | // to keep the instruction count low. |
| 4425 | // selnez AT, true_reg, cond_reg |
| 4426 | // seleqz TMP, false_reg, cond_reg |
| 4427 | // or out_reg, AT, TMP |
| 4428 | can_move_conditionally = true; |
| 4429 | } |
| 4430 | } else { |
| 4431 | // Moving float/double on int/long condition. |
| 4432 | if (materialized) { |
| 4433 | // Not materializing unmaterialized int conditions |
| 4434 | // to keep the instruction count low. |
| 4435 | can_move_conditionally = true; |
| 4436 | if (is_true_value_zero_constant) { |
| 4437 | // sltu TMP, ZERO, cond_reg |
| 4438 | // mtc1 TMP, temp_cond_reg |
| 4439 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4440 | use_const_for_true_in = true; |
| 4441 | } else if (is_false_value_zero_constant) { |
| 4442 | // sltu TMP, ZERO, cond_reg |
| 4443 | // mtc1 TMP, temp_cond_reg |
| 4444 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4445 | use_const_for_false_in = true; |
| 4446 | } else { |
| 4447 | // sltu TMP, ZERO, cond_reg |
| 4448 | // mtc1 TMP, temp_cond_reg |
| 4449 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4450 | // mov.fmt out_reg, temp_cond_reg |
| 4451 | } |
| 4452 | } |
| 4453 | } |
| 4454 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4455 | if (!DataType::IsFloatingPointType(dst_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4456 | // Moving int/long on float/double condition. |
| 4457 | can_move_conditionally = true; |
| 4458 | if (is_true_value_zero_constant) { |
| 4459 | // mfc1 TMP, temp_cond_reg |
| 4460 | // seleqz out_reg, false_reg, TMP |
| 4461 | use_const_for_true_in = true; |
| 4462 | } else if (is_false_value_zero_constant) { |
| 4463 | // mfc1 TMP, temp_cond_reg |
| 4464 | // selnez out_reg, true_reg, TMP |
| 4465 | use_const_for_false_in = true; |
| 4466 | } else { |
| 4467 | // mfc1 TMP, temp_cond_reg |
| 4468 | // selnez AT, true_reg, TMP |
| 4469 | // seleqz TMP, false_reg, TMP |
| 4470 | // or out_reg, AT, TMP |
| 4471 | } |
| 4472 | } else { |
| 4473 | // Moving float/double on float/double condition. |
| 4474 | can_move_conditionally = true; |
| 4475 | if (is_true_value_zero_constant) { |
| 4476 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4477 | use_const_for_true_in = true; |
| 4478 | } else if (is_false_value_zero_constant) { |
| 4479 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4480 | use_const_for_false_in = true; |
| 4481 | } else { |
| 4482 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4483 | // mov.fmt out_reg, temp_cond_reg |
| 4484 | } |
| 4485 | } |
| 4486 | } |
| 4487 | } |
| 4488 | |
| 4489 | if (can_move_conditionally) { |
| 4490 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 4491 | } else { |
| 4492 | DCHECK(!use_const_for_false_in); |
| 4493 | DCHECK(!use_const_for_true_in); |
| 4494 | } |
| 4495 | |
| 4496 | if (locations_to_set != nullptr) { |
| 4497 | if (use_const_for_false_in) { |
| 4498 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 4499 | } else { |
| 4500 | locations_to_set->SetInAt(0, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4501 | DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4502 | ? Location::RequiresFpuRegister() |
| 4503 | : Location::RequiresRegister()); |
| 4504 | } |
| 4505 | if (use_const_for_true_in) { |
| 4506 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 4507 | } else { |
| 4508 | locations_to_set->SetInAt(1, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4509 | DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4510 | ? Location::RequiresFpuRegister() |
| 4511 | : Location::RequiresRegister()); |
| 4512 | } |
| 4513 | if (materialized) { |
| 4514 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 4515 | } |
| 4516 | |
| 4517 | if (can_move_conditionally) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4518 | locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type) |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4519 | ? Location::RequiresFpuRegister() |
| 4520 | : Location::RequiresRegister()); |
| 4521 | } else { |
| 4522 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 4523 | } |
| 4524 | } |
| 4525 | |
| 4526 | return can_move_conditionally; |
| 4527 | } |
| 4528 | |
| 4529 | |
| 4530 | void InstructionCodeGeneratorMIPS64::GenConditionalMove(HSelect* select) { |
| 4531 | LocationSummary* locations = select->GetLocations(); |
| 4532 | Location dst = locations->Out(); |
| 4533 | Location false_src = locations->InAt(0); |
| 4534 | Location true_src = locations->InAt(1); |
| 4535 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4536 | GpuRegister cond_reg = TMP; |
| 4537 | FpuRegister fcond_reg = FTMP; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4538 | DataType::Type cond_type = DataType::Type::kInt32; |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4539 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4540 | DataType::Type dst_type = select->GetType(); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4541 | |
| 4542 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 4543 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<GpuRegister>(); |
| 4544 | } else { |
| 4545 | HCondition* condition = cond->AsCondition(); |
| 4546 | LocationSummary* cond_locations = cond->GetLocations(); |
| 4547 | IfCondition if_cond = condition->GetCondition(); |
| 4548 | cond_type = condition->InputAt(0)->GetType(); |
| 4549 | switch (cond_type) { |
| 4550 | default: |
| 4551 | cond_inverted = MaterializeIntLongCompare(if_cond, |
| 4552 | /* is64bit */ false, |
| 4553 | cond_locations, |
| 4554 | cond_reg); |
| 4555 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4556 | case DataType::Type::kInt64: |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4557 | cond_inverted = MaterializeIntLongCompare(if_cond, |
| 4558 | /* is64bit */ true, |
| 4559 | cond_locations, |
| 4560 | cond_reg); |
| 4561 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4562 | case DataType::Type::kFloat32: |
| 4563 | case DataType::Type::kFloat64: |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4564 | cond_inverted = MaterializeFpCompare(if_cond, |
| 4565 | condition->IsGtBias(), |
| 4566 | cond_type, |
| 4567 | cond_locations, |
| 4568 | fcond_reg); |
| 4569 | break; |
| 4570 | } |
| 4571 | } |
| 4572 | |
| 4573 | if (true_src.IsConstant()) { |
| 4574 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 4575 | } |
| 4576 | if (false_src.IsConstant()) { |
| 4577 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 4578 | } |
| 4579 | |
| 4580 | switch (dst_type) { |
| 4581 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4582 | if (DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4583 | __ Mfc1(cond_reg, fcond_reg); |
| 4584 | } |
| 4585 | if (true_src.IsConstant()) { |
| 4586 | if (cond_inverted) { |
| 4587 | __ Selnez(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4588 | } else { |
| 4589 | __ Seleqz(dst.AsRegister<GpuRegister>(), false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4590 | } |
| 4591 | } else if (false_src.IsConstant()) { |
| 4592 | if (cond_inverted) { |
| 4593 | __ Seleqz(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4594 | } else { |
| 4595 | __ Selnez(dst.AsRegister<GpuRegister>(), true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4596 | } |
| 4597 | } else { |
| 4598 | DCHECK_NE(cond_reg, AT); |
| 4599 | if (cond_inverted) { |
| 4600 | __ Seleqz(AT, true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4601 | __ Selnez(TMP, false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4602 | } else { |
| 4603 | __ Selnez(AT, true_src.AsRegister<GpuRegister>(), cond_reg); |
| 4604 | __ Seleqz(TMP, false_src.AsRegister<GpuRegister>(), cond_reg); |
| 4605 | } |
| 4606 | __ Or(dst.AsRegister<GpuRegister>(), AT, TMP); |
| 4607 | } |
| 4608 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4609 | case DataType::Type::kFloat32: { |
| 4610 | if (!DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4611 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4612 | __ Sltu(TMP, ZERO, cond_reg); |
| 4613 | __ Mtc1(TMP, fcond_reg); |
| 4614 | } |
| 4615 | FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>(); |
| 4616 | if (true_src.IsConstant()) { |
| 4617 | FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>(); |
| 4618 | if (cond_inverted) { |
| 4619 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4620 | } else { |
| 4621 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4622 | } |
| 4623 | } else if (false_src.IsConstant()) { |
| 4624 | FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>(); |
| 4625 | if (cond_inverted) { |
| 4626 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4627 | } else { |
| 4628 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4629 | } |
| 4630 | } else { |
| 4631 | if (cond_inverted) { |
| 4632 | __ SelS(fcond_reg, |
| 4633 | true_src.AsFpuRegister<FpuRegister>(), |
| 4634 | false_src.AsFpuRegister<FpuRegister>()); |
| 4635 | } else { |
| 4636 | __ SelS(fcond_reg, |
| 4637 | false_src.AsFpuRegister<FpuRegister>(), |
| 4638 | true_src.AsFpuRegister<FpuRegister>()); |
| 4639 | } |
| 4640 | __ MovS(dst_reg, fcond_reg); |
| 4641 | } |
| 4642 | break; |
| 4643 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4644 | case DataType::Type::kFloat64: { |
| 4645 | if (!DataType::IsFloatingPointType(cond_type)) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4646 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4647 | __ Sltu(TMP, ZERO, cond_reg); |
| 4648 | __ Mtc1(TMP, fcond_reg); |
| 4649 | } |
| 4650 | FpuRegister dst_reg = dst.AsFpuRegister<FpuRegister>(); |
| 4651 | if (true_src.IsConstant()) { |
| 4652 | FpuRegister src_reg = false_src.AsFpuRegister<FpuRegister>(); |
| 4653 | if (cond_inverted) { |
| 4654 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4655 | } else { |
| 4656 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4657 | } |
| 4658 | } else if (false_src.IsConstant()) { |
| 4659 | FpuRegister src_reg = true_src.AsFpuRegister<FpuRegister>(); |
| 4660 | if (cond_inverted) { |
| 4661 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4662 | } else { |
| 4663 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4664 | } |
| 4665 | } else { |
| 4666 | if (cond_inverted) { |
| 4667 | __ SelD(fcond_reg, |
| 4668 | true_src.AsFpuRegister<FpuRegister>(), |
| 4669 | false_src.AsFpuRegister<FpuRegister>()); |
| 4670 | } else { |
| 4671 | __ SelD(fcond_reg, |
| 4672 | false_src.AsFpuRegister<FpuRegister>(), |
| 4673 | true_src.AsFpuRegister<FpuRegister>()); |
| 4674 | } |
| 4675 | __ MovD(dst_reg, fcond_reg); |
| 4676 | } |
| 4677 | break; |
| 4678 | } |
| 4679 | } |
| 4680 | } |
| 4681 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4682 | void LocationsBuilderMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4683 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4684 | LocationSummary(flag, LocationSummary::kNoCall); |
| 4685 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4686 | } |
| 4687 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4688 | void InstructionCodeGeneratorMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 4689 | __ LoadFromOffset(kLoadWord, |
| 4690 | flag->GetLocations()->Out().AsRegister<GpuRegister>(), |
| 4691 | SP, |
| 4692 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4693 | } |
| 4694 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4695 | void LocationsBuilderMIPS64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4696 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4697 | CanMoveConditionally(select, locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4698 | } |
| 4699 | |
| 4700 | void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) { |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 4701 | if (CanMoveConditionally(select, /* locations_to_set */ nullptr)) { |
| 4702 | GenConditionalMove(select); |
| 4703 | } else { |
| 4704 | LocationSummary* locations = select->GetLocations(); |
| 4705 | Mips64Label false_target; |
| 4706 | GenerateTestAndBranch(select, |
| 4707 | /* condition_input_index */ 2, |
| 4708 | /* true_target */ nullptr, |
| 4709 | &false_target); |
| 4710 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 4711 | __ Bind(&false_target); |
| 4712 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4713 | } |
| 4714 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4715 | void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4716 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4717 | } |
| 4718 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 4719 | void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 4720 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 4721 | } |
| 4722 | |
| 4723 | void CodeGeneratorMIPS64::GenerateNop() { |
| 4724 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4725 | } |
| 4726 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4727 | void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4728 | const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4729 | DataType::Type field_type = field_info.GetFieldType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4730 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4731 | kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4732 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4733 | instruction, |
| 4734 | object_field_get_with_read_barrier |
| 4735 | ? LocationSummary::kCallOnSlowPath |
| 4736 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 4737 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4738 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 4739 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4740 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4741 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4742 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4743 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4744 | // The output overlaps in the case of an object field get with |
| 4745 | // read barriers enabled: we do not want the move to overwrite the |
| 4746 | // object's location, as we need it to emit the read barrier. |
| 4747 | locations->SetOut(Location::RequiresRegister(), |
| 4748 | object_field_get_with_read_barrier |
| 4749 | ? Location::kOutputOverlap |
| 4750 | : Location::kNoOutputOverlap); |
| 4751 | } |
| 4752 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4753 | // We need a temporary register for the read barrier marking slow |
| 4754 | // path in CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4755 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 4756 | locations->AddTemp(Location::RequiresRegister()); |
| 4757 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4758 | } |
| 4759 | } |
| 4760 | |
| 4761 | void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction, |
| 4762 | const FieldInfo& field_info) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4763 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4764 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4765 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4766 | Location obj_loc = locations->InAt(0); |
| 4767 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 4768 | Location dst_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4769 | LoadOperandType load_type = kLoadUnsignedByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4770 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4771 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4772 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4773 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4774 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4775 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4776 | case DataType::Type::kUint8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4777 | load_type = kLoadUnsignedByte; |
| 4778 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4779 | case DataType::Type::kInt8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4780 | load_type = kLoadSignedByte; |
| 4781 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4782 | case DataType::Type::kUint16: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4783 | load_type = kLoadUnsignedHalfword; |
| 4784 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4785 | case DataType::Type::kInt16: |
| 4786 | load_type = kLoadSignedHalfword; |
| 4787 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4788 | case DataType::Type::kInt32: |
| 4789 | case DataType::Type::kFloat32: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4790 | load_type = kLoadWord; |
| 4791 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4792 | case DataType::Type::kInt64: |
| 4793 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4794 | load_type = kLoadDoubleword; |
| 4795 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4796 | case DataType::Type::kReference: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4797 | load_type = kLoadUnsignedWord; |
| 4798 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4799 | case DataType::Type::kUint32: |
| 4800 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4801 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4802 | LOG(FATAL) << "Unreachable type " << type; |
| 4803 | UNREACHABLE(); |
| 4804 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4805 | if (!DataType::IsFloatingPointType(type)) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4806 | DCHECK(dst_loc.IsRegister()); |
| 4807 | GpuRegister dst = dst_loc.AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4808 | if (type == DataType::Type::kReference) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4809 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 4810 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4811 | Location temp_loc = |
| 4812 | kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4813 | // Note that a potential implicit null check is handled in this |
| 4814 | // CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier call. |
| 4815 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4816 | dst_loc, |
| 4817 | obj, |
| 4818 | offset, |
| 4819 | temp_loc, |
| 4820 | /* needs_null_check */ true); |
| 4821 | if (is_volatile) { |
| 4822 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4823 | } |
| 4824 | } else { |
| 4825 | __ LoadFromOffset(kLoadUnsignedWord, dst, obj, offset, null_checker); |
| 4826 | if (is_volatile) { |
| 4827 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4828 | } |
| 4829 | // If read barriers are enabled, emit read barriers other than |
| 4830 | // Baker's using a slow path (and also unpoison the loaded |
| 4831 | // reference, if heap poisoning is enabled). |
| 4832 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 4833 | } |
| 4834 | } else { |
| 4835 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
| 4836 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4837 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4838 | DCHECK(dst_loc.IsFpuRegister()); |
| 4839 | FpuRegister dst = dst_loc.AsFpuRegister<FpuRegister>(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4840 | __ LoadFpuFromOffset(load_type, dst, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4841 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4842 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4843 | // Memory barriers, in the case of references, are handled in the |
| 4844 | // previous switch statement. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4845 | if (is_volatile && (type != DataType::Type::kReference)) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4846 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4847 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4848 | } |
| 4849 | |
| 4850 | void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction, |
| 4851 | const FieldInfo& field_info ATTRIBUTE_UNUSED) { |
| 4852 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4853 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4854 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4855 | if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4856 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4857 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4858 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4859 | } |
| 4860 | } |
| 4861 | |
| 4862 | void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction, |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4863 | const FieldInfo& field_info, |
| 4864 | bool value_can_be_null) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4865 | DataType::Type type = field_info.GetFieldType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4866 | LocationSummary* locations = instruction->GetLocations(); |
| 4867 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4868 | Location value_location = locations->InAt(1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4869 | StoreOperandType store_type = kStoreByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4870 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4871 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4872 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4873 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4874 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4875 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4876 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4877 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4878 | case DataType::Type::kInt8: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4879 | store_type = kStoreByte; |
| 4880 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4881 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4882 | case DataType::Type::kInt16: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4883 | store_type = kStoreHalfword; |
| 4884 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4885 | case DataType::Type::kInt32: |
| 4886 | case DataType::Type::kFloat32: |
| 4887 | case DataType::Type::kReference: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4888 | store_type = kStoreWord; |
| 4889 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4890 | case DataType::Type::kInt64: |
| 4891 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4892 | store_type = kStoreDoubleword; |
| 4893 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4894 | case DataType::Type::kUint32: |
| 4895 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4896 | case DataType::Type::kVoid: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4897 | LOG(FATAL) << "Unreachable type " << type; |
| 4898 | UNREACHABLE(); |
| 4899 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4900 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4901 | if (is_volatile) { |
| 4902 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4903 | } |
| 4904 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4905 | if (value_location.IsConstant()) { |
| 4906 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 4907 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
| 4908 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4909 | if (!DataType::IsFloatingPointType(type)) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4910 | DCHECK(value_location.IsRegister()); |
| 4911 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
| 4912 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4913 | // Note that in the case where `value` is a null reference, |
| 4914 | // we do not enter this block, as a null reference does not |
| 4915 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4916 | DCHECK_EQ(type, DataType::Type::kReference); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4917 | __ PoisonHeapReference(TMP, src); |
| 4918 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 4919 | } else { |
| 4920 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 4921 | } |
| 4922 | } else { |
| 4923 | DCHECK(value_location.IsFpuRegister()); |
| 4924 | FpuRegister src = value_location.AsFpuRegister<FpuRegister>(); |
| 4925 | __ StoreFpuToOffset(store_type, src, obj, offset, null_checker); |
| 4926 | } |
| 4927 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4928 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4929 | if (needs_write_barrier) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4930 | DCHECK(value_location.IsRegister()); |
| 4931 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4932 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4933 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4934 | |
| 4935 | if (is_volatile) { |
| 4936 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4937 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4938 | } |
| 4939 | |
| 4940 | void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4941 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4942 | } |
| 4943 | |
| 4944 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4945 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4946 | } |
| 4947 | |
| 4948 | void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4949 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4950 | } |
| 4951 | |
| 4952 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4953 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4954 | } |
| 4955 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4956 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadOneRegister( |
| 4957 | HInstruction* instruction, |
| 4958 | Location out, |
| 4959 | uint32_t offset, |
| 4960 | Location maybe_temp, |
| 4961 | ReadBarrierOption read_barrier_option) { |
| 4962 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 4963 | if (read_barrier_option == kWithReadBarrier) { |
| 4964 | CHECK(kEmitCompilerReadBarrier); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 4965 | if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) { |
| 4966 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 4967 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4968 | if (kUseBakerReadBarrier) { |
| 4969 | // Load with fast path based Baker's read barrier. |
| 4970 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4971 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4972 | out, |
| 4973 | out_reg, |
| 4974 | offset, |
| 4975 | maybe_temp, |
| 4976 | /* needs_null_check */ false); |
| 4977 | } else { |
| 4978 | // Load with slow path based read barrier. |
| 4979 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 4980 | // in the following move operation, as we will need it for the |
| 4981 | // read barrier below. |
| 4982 | __ Move(maybe_temp.AsRegister<GpuRegister>(), out_reg); |
| 4983 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4984 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4985 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 4986 | } |
| 4987 | } else { |
| 4988 | // Plain load with no read barrier. |
| 4989 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4990 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4991 | __ MaybeUnpoisonHeapReference(out_reg); |
| 4992 | } |
| 4993 | } |
| 4994 | |
| 4995 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadTwoRegisters( |
| 4996 | HInstruction* instruction, |
| 4997 | Location out, |
| 4998 | Location obj, |
| 4999 | uint32_t offset, |
| 5000 | Location maybe_temp, |
| 5001 | ReadBarrierOption read_barrier_option) { |
| 5002 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 5003 | GpuRegister obj_reg = obj.AsRegister<GpuRegister>(); |
| 5004 | if (read_barrier_option == kWithReadBarrier) { |
| 5005 | CHECK(kEmitCompilerReadBarrier); |
| 5006 | if (kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5007 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 5008 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 5009 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5010 | // Load with fast path based Baker's read barrier. |
| 5011 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5012 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5013 | out, |
| 5014 | obj_reg, |
| 5015 | offset, |
| 5016 | maybe_temp, |
| 5017 | /* needs_null_check */ false); |
| 5018 | } else { |
| 5019 | // Load with slow path based read barrier. |
| 5020 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5021 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 5022 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5023 | } |
| 5024 | } else { |
| 5025 | // Plain load with no read barrier. |
| 5026 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5027 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 5028 | __ MaybeUnpoisonHeapReference(out_reg); |
| 5029 | } |
| 5030 | } |
| 5031 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5032 | static inline int GetBakerMarkThunkNumber(GpuRegister reg) { |
| 5033 | static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 20, "Expecting equal"); |
| 5034 | if (reg >= V0 && reg <= T2) { // 13 consequtive regs. |
| 5035 | return reg - V0; |
| 5036 | } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs. |
| 5037 | return 13 + (reg - S2); |
| 5038 | } else if (reg == S8) { // One more. |
| 5039 | return 19; |
| 5040 | } |
| 5041 | LOG(FATAL) << "Unexpected register " << reg; |
| 5042 | UNREACHABLE(); |
| 5043 | } |
| 5044 | |
| 5045 | static inline int GetBakerMarkFieldArrayThunkDisplacement(GpuRegister reg, bool short_offset) { |
| 5046 | int num = GetBakerMarkThunkNumber(reg) + |
| 5047 | (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0); |
| 5048 | return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE; |
| 5049 | } |
| 5050 | |
| 5051 | static inline int GetBakerMarkGcRootThunkDisplacement(GpuRegister reg) { |
| 5052 | return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE + |
| 5053 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET; |
| 5054 | } |
| 5055 | |
| 5056 | void InstructionCodeGeneratorMIPS64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 5057 | Location root, |
| 5058 | GpuRegister obj, |
| 5059 | uint32_t offset, |
| 5060 | ReadBarrierOption read_barrier_option, |
| 5061 | Mips64Label* label_low) { |
| 5062 | if (label_low != nullptr) { |
| 5063 | DCHECK_EQ(offset, 0x5678u); |
| 5064 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5065 | GpuRegister root_reg = root.AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5066 | if (read_barrier_option == kWithReadBarrier) { |
| 5067 | DCHECK(kEmitCompilerReadBarrier); |
| 5068 | if (kUseBakerReadBarrier) { |
| 5069 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 5070 | // Baker's read barrier are used: |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5071 | if (kBakerReadBarrierThunksEnableForGcRoots) { |
| 5072 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5073 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 5074 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5075 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5076 | // vice versa. |
| 5077 | // |
| 5078 | // We use thunks for the slow path. That thunk checks the reference |
| 5079 | // and jumps to the entrypoint if needed. |
| 5080 | // |
| 5081 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5082 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5083 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5084 | // if (temp != nullptr) { |
| 5085 | // temp = &gc_root_thunk<root_reg> |
| 5086 | // root = temp(root) |
| 5087 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5088 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5089 | const int32_t entry_point_offset = |
| 5090 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5091 | const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg); |
| 5092 | int16_t offset_low = Low16Bits(offset); |
| 5093 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign |
| 5094 | // extension in lwu. |
| 5095 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 5096 | GpuRegister base = short_offset ? obj : TMP; |
| 5097 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5098 | // threads are suspended or running a checkpoint. |
| 5099 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 5100 | if (!short_offset) { |
| 5101 | DCHECK(!label_low); |
| 5102 | __ Daui(base, obj, offset_high); |
| 5103 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5104 | Mips64Label skip_call; |
| 5105 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5106 | if (label_low != nullptr) { |
| 5107 | DCHECK(short_offset); |
| 5108 | __ Bind(label_low); |
| 5109 | } |
| 5110 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5111 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, base, offset_low); // Single instruction |
| 5112 | // in delay slot. |
| 5113 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5114 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5115 | } else { |
| 5116 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5117 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 5118 | // load into `temp` (T9) the read barrier mark entry point corresponding |
| 5119 | // to register `root`. If `temp` is null, it means that `GetIsGcMarking()` |
| 5120 | // is false, and vice versa. |
| 5121 | // |
| 5122 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5123 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5124 | // if (temp != null) { |
| 5125 | // root = temp(root) |
| 5126 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5127 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5128 | if (label_low != nullptr) { |
| 5129 | __ Bind(label_low); |
| 5130 | } |
| 5131 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5132 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 5133 | static_assert( |
| 5134 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5135 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5136 | "have different sizes."); |
| 5137 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5138 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5139 | "have different sizes."); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5140 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5141 | // Slow path marking the GC root `root`. |
| 5142 | Location temp = Location::RegisterLocation(T9); |
| 5143 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5144 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64( |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5145 | instruction, |
| 5146 | root, |
| 5147 | /*entrypoint*/ temp); |
| 5148 | codegen_->AddSlowPath(slow_path); |
| 5149 | |
| 5150 | const int32_t entry_point_offset = |
| 5151 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(root.reg() - 1); |
| 5152 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5153 | // threads are suspended or running a checkpoint. |
| 5154 | __ LoadFromOffset(kLoadDoubleword, temp.AsRegister<GpuRegister>(), TR, entry_point_offset); |
| 5155 | __ Bnezc(temp.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 5156 | __ Bind(slow_path->GetExitLabel()); |
| 5157 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5158 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5159 | if (label_low != nullptr) { |
| 5160 | __ Bind(label_low); |
| 5161 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5162 | // GC root loaded through a slow path for read barriers other |
| 5163 | // than Baker's. |
| 5164 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 5165 | __ Daddiu64(root_reg, obj, static_cast<int32_t>(offset)); |
| 5166 | // /* mirror::Object* */ root = root->Read() |
| 5167 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5168 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5169 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5170 | if (label_low != nullptr) { |
| 5171 | __ Bind(label_low); |
| 5172 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5173 | // Plain GC root load with no read barrier. |
| 5174 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5175 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 5176 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5177 | // do not have to unpoison `root_reg` here. |
| 5178 | } |
| 5179 | } |
| 5180 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5181 | void CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5182 | Location ref, |
| 5183 | GpuRegister obj, |
| 5184 | uint32_t offset, |
| 5185 | Location temp, |
| 5186 | bool needs_null_check) { |
| 5187 | DCHECK(kEmitCompilerReadBarrier); |
| 5188 | DCHECK(kUseBakerReadBarrier); |
| 5189 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5190 | if (kBakerReadBarrierThunksEnableForFields) { |
| 5191 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5192 | // to decide whether to mark the loaded reference or not. Instead, we |
| 5193 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5194 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5195 | // vice versa. |
| 5196 | // |
| 5197 | // We use thunks for the slow path. That thunk checks the reference |
| 5198 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 5199 | // it issues a load-load memory barrier and returns to the original |
| 5200 | // reference load. |
| 5201 | // |
| 5202 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5203 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5204 | // if (temp != nullptr) { |
| 5205 | // temp = &field_array_thunk<holder_reg> |
| 5206 | // temp() |
| 5207 | // } |
| 5208 | // not_gray_return_address: |
| 5209 | // // If the offset is too large to fit into the lw instruction, we |
| 5210 | // // use an adjusted base register (TMP) here. This register |
| 5211 | // // receives bits 16 ... 31 of the offset before the thunk invocation |
| 5212 | // // and the thunk benefits from it. |
| 5213 | // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load. |
| 5214 | // gray_return_address: |
| 5215 | |
| 5216 | DCHECK(temp.IsInvalid()); |
| 5217 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 5218 | const int32_t entry_point_offset = |
| 5219 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5220 | // There may have or may have not been a null check if the field offset is smaller than |
| 5221 | // the page size. |
| 5222 | // There must've been a null check in case it's actually a load from an array. |
| 5223 | // We will, however, perform an explicit null check in the thunk as it's easier to |
| 5224 | // do it than not. |
| 5225 | if (instruction->IsArrayGet()) { |
| 5226 | DCHECK(!needs_null_check); |
| 5227 | } |
| 5228 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset); |
| 5229 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5230 | // threads are suspended or running a checkpoint. |
| 5231 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 5232 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5233 | Mips64Label skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5234 | if (short_offset) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5235 | __ Beqzc(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5236 | __ Nop(); // In forbidden slot. |
| 5237 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5238 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5239 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5240 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); // Single instruction. |
| 5241 | } else { |
| 5242 | int16_t offset_low = Low16Bits(offset); |
| 5243 | 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] | 5244 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5245 | __ Daui(TMP, obj, offset_high); // In delay slot. |
| 5246 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5247 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5248 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5249 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset_low); // Single instruction. |
| 5250 | } |
| 5251 | if (needs_null_check) { |
| 5252 | MaybeRecordImplicitNullCheck(instruction); |
| 5253 | } |
| 5254 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5255 | return; |
| 5256 | } |
| 5257 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5258 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5259 | Location no_index = Location::NoLocation(); |
| 5260 | ScaleFactor no_scale_factor = TIMES_1; |
| 5261 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5262 | ref, |
| 5263 | obj, |
| 5264 | offset, |
| 5265 | no_index, |
| 5266 | no_scale_factor, |
| 5267 | temp, |
| 5268 | needs_null_check); |
| 5269 | } |
| 5270 | |
| 5271 | void CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5272 | Location ref, |
| 5273 | GpuRegister obj, |
| 5274 | uint32_t data_offset, |
| 5275 | Location index, |
| 5276 | Location temp, |
| 5277 | bool needs_null_check) { |
| 5278 | DCHECK(kEmitCompilerReadBarrier); |
| 5279 | DCHECK(kUseBakerReadBarrier); |
| 5280 | |
| 5281 | static_assert( |
| 5282 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5283 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5284 | ScaleFactor scale_factor = TIMES_4; |
| 5285 | |
| 5286 | if (kBakerReadBarrierThunksEnableForArrays) { |
| 5287 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5288 | // to decide whether to mark the loaded reference or not. Instead, we |
| 5289 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 5290 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 5291 | // vice versa. |
| 5292 | // |
| 5293 | // We use thunks for the slow path. That thunk checks the reference |
| 5294 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 5295 | // it issues a load-load memory barrier and returns to the original |
| 5296 | // reference load. |
| 5297 | // |
| 5298 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 5299 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 5300 | // if (temp != nullptr) { |
| 5301 | // temp = &field_array_thunk<holder_reg> |
| 5302 | // temp() |
| 5303 | // } |
| 5304 | // not_gray_return_address: |
| 5305 | // // The element address is pre-calculated in the TMP register before the |
| 5306 | // // thunk invocation and the thunk benefits from it. |
| 5307 | // HeapReference<mirror::Object> reference = data[index]; // Original reference load. |
| 5308 | // gray_return_address: |
| 5309 | |
| 5310 | DCHECK(temp.IsInvalid()); |
| 5311 | DCHECK(index.IsValid()); |
| 5312 | const int32_t entry_point_offset = |
| 5313 | Thread::ReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(0); |
| 5314 | // We will not do the explicit null check in the thunk as some form of a null check |
| 5315 | // must've been done earlier. |
| 5316 | DCHECK(!needs_null_check); |
| 5317 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false); |
| 5318 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5319 | // threads are suspended or running a checkpoint. |
| 5320 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5321 | Mips64Label skip_call; |
| 5322 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5323 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
| 5324 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
| 5325 | __ Dlsa(TMP, index_reg, obj, scale_factor); // In delay slot. |
| 5326 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 5327 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 5328 | // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor)) |
| 5329 | DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset; |
| 5330 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, data_offset); // Single instruction. |
| 5331 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5332 | return; |
| 5333 | } |
| 5334 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5335 | // /* HeapReference<Object> */ ref = |
| 5336 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5337 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5338 | ref, |
| 5339 | obj, |
| 5340 | data_offset, |
| 5341 | index, |
| 5342 | scale_factor, |
| 5343 | temp, |
| 5344 | needs_null_check); |
| 5345 | } |
| 5346 | |
| 5347 | void CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5348 | Location ref, |
| 5349 | GpuRegister obj, |
| 5350 | uint32_t offset, |
| 5351 | Location index, |
| 5352 | ScaleFactor scale_factor, |
| 5353 | Location temp, |
| 5354 | bool needs_null_check, |
| 5355 | bool always_update_field) { |
| 5356 | DCHECK(kEmitCompilerReadBarrier); |
| 5357 | DCHECK(kUseBakerReadBarrier); |
| 5358 | |
| 5359 | // In slow path based read barriers, the read barrier call is |
| 5360 | // inserted after the original load. However, in fast path based |
| 5361 | // Baker's read barriers, we need to perform the load of |
| 5362 | // mirror::Object::monitor_ *before* the original reference load. |
| 5363 | // This load-load ordering is required by the read barrier. |
| 5364 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 5365 | // |
| 5366 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 5367 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 5368 | // HeapReference<Object> ref = *src; // Original reference load. |
| 5369 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 5370 | // if (is_gray) { |
| 5371 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 5372 | // } |
| 5373 | // |
| 5374 | // Note: the original implementation in ReadBarrier::Barrier is |
| 5375 | // slightly more complex as it performs additional checks that we do |
| 5376 | // not do here for performance reasons. |
| 5377 | |
| 5378 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
| 5379 | GpuRegister temp_reg = temp.AsRegister<GpuRegister>(); |
| 5380 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 5381 | |
| 5382 | // /* int32_t */ monitor = obj->monitor_ |
| 5383 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 5384 | if (needs_null_check) { |
| 5385 | MaybeRecordImplicitNullCheck(instruction); |
| 5386 | } |
| 5387 | // /* LockWord */ lock_word = LockWord(monitor) |
| 5388 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 5389 | "art::LockWord and int32_t have different sizes."); |
| 5390 | |
| 5391 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 5392 | |
| 5393 | // The actual reference load. |
| 5394 | if (index.IsValid()) { |
| 5395 | // Load types involving an "index": ArrayGet, |
| 5396 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 5397 | // intrinsics. |
| 5398 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 5399 | if (index.IsConstant()) { |
| 5400 | size_t computed_offset = |
| 5401 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 5402 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, computed_offset); |
| 5403 | } else { |
| 5404 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 5405 | if (scale_factor == TIMES_1) { |
| 5406 | __ Daddu(TMP, index_reg, obj); |
| 5407 | } else { |
| 5408 | __ Dlsa(TMP, index_reg, obj, scale_factor); |
| 5409 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5410 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset); |
| 5411 | } |
| 5412 | } else { |
| 5413 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5414 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); |
| 5415 | } |
| 5416 | |
| 5417 | // Object* ref = ref_addr->AsMirrorPtr() |
| 5418 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 5419 | |
| 5420 | // Slow path marking the object `ref` when it is gray. |
| 5421 | SlowPathCodeMIPS64* slow_path; |
| 5422 | if (always_update_field) { |
| 5423 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 only supports address |
| 5424 | // of the form `obj + field_offset`, where `obj` is a register and |
| 5425 | // `field_offset` is a register. Thus `offset` and `scale_factor` |
| 5426 | // above are expected to be null in this code path. |
| 5427 | DCHECK_EQ(offset, 0u); |
| 5428 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5429 | slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5430 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(instruction, |
| 5431 | ref, |
| 5432 | obj, |
| 5433 | /* field_offset */ index, |
| 5434 | temp_reg); |
| 5435 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5436 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS64(instruction, ref); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5437 | } |
| 5438 | AddSlowPath(slow_path); |
| 5439 | |
| 5440 | // if (rb_state == ReadBarrier::GrayState()) |
| 5441 | // ref = ReadBarrier::Mark(ref); |
| 5442 | // Given the numeric representation, it's enough to check the low bit of the |
| 5443 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 5444 | // performing a branch on less than zero. |
| 5445 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 5446 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 5447 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 5448 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 5449 | __ Bltzc(temp_reg, slow_path->GetEntryLabel()); |
| 5450 | __ Bind(slow_path->GetExitLabel()); |
| 5451 | } |
| 5452 | |
| 5453 | void CodeGeneratorMIPS64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 5454 | Location out, |
| 5455 | Location ref, |
| 5456 | Location obj, |
| 5457 | uint32_t offset, |
| 5458 | Location index) { |
| 5459 | DCHECK(kEmitCompilerReadBarrier); |
| 5460 | |
| 5461 | // Insert a slow path based read barrier *after* the reference load. |
| 5462 | // |
| 5463 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5464 | // reference will be carried out by the runtime within the slow |
| 5465 | // path. |
| 5466 | // |
| 5467 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5468 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5469 | // not used by the artReadBarrierSlow entry point. |
| 5470 | // |
| 5471 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5472 | SlowPathCodeMIPS64* slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5473 | ReadBarrierForHeapReferenceSlowPathMIPS64(instruction, out, ref, obj, offset, index); |
| 5474 | AddSlowPath(slow_path); |
| 5475 | |
| 5476 | __ Bc(slow_path->GetEntryLabel()); |
| 5477 | __ Bind(slow_path->GetExitLabel()); |
| 5478 | } |
| 5479 | |
| 5480 | void CodeGeneratorMIPS64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 5481 | Location out, |
| 5482 | Location ref, |
| 5483 | Location obj, |
| 5484 | uint32_t offset, |
| 5485 | Location index) { |
| 5486 | if (kEmitCompilerReadBarrier) { |
| 5487 | // Baker's read barriers shall be handled by the fast path |
| 5488 | // (CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier). |
| 5489 | DCHECK(!kUseBakerReadBarrier); |
| 5490 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5491 | // by the runtime within the slow path. |
| 5492 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 5493 | } else if (kPoisonHeapReferences) { |
| 5494 | __ UnpoisonHeapReference(out.AsRegister<GpuRegister>()); |
| 5495 | } |
| 5496 | } |
| 5497 | |
| 5498 | void CodeGeneratorMIPS64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 5499 | Location out, |
| 5500 | Location root) { |
| 5501 | DCHECK(kEmitCompilerReadBarrier); |
| 5502 | |
| 5503 | // Insert a slow path based read barrier *after* the GC root load. |
| 5504 | // |
| 5505 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5506 | // not need to do anything special for this here. |
| 5507 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5508 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS64(instruction, out, root); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5509 | AddSlowPath(slow_path); |
| 5510 | |
| 5511 | __ Bc(slow_path->GetEntryLabel()); |
| 5512 | __ Bind(slow_path->GetExitLabel()); |
| 5513 | } |
| 5514 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5515 | void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5516 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5517 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5518 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5519 | switch (type_check_kind) { |
| 5520 | case TypeCheckKind::kExactCheck: |
| 5521 | case TypeCheckKind::kAbstractClassCheck: |
| 5522 | case TypeCheckKind::kClassHierarchyCheck: |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5523 | case TypeCheckKind::kArrayObjectCheck: { |
| 5524 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 5525 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 5526 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5527 | break; |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5528 | } |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5529 | case TypeCheckKind::kArrayCheck: |
| 5530 | case TypeCheckKind::kUnresolvedCheck: |
| 5531 | case TypeCheckKind::kInterfaceCheck: |
| 5532 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5533 | break; |
| 5534 | } |
| 5535 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5536 | LocationSummary* locations = |
| 5537 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5538 | if (baker_read_barrier_slow_path) { |
| 5539 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5540 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5541 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 5542 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5543 | // The output does overlap inputs. |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5544 | // Note that TypeCheckSlowPathMIPS64 uses this register too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5545 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5546 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5547 | } |
| 5548 | |
| 5549 | void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5550 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5551 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5552 | Location obj_loc = locations->InAt(0); |
| 5553 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 5554 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5555 | Location out_loc = locations->Out(); |
| 5556 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 5557 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 5558 | DCHECK_LE(num_temps, 1u); |
| 5559 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5560 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5561 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5562 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5563 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5564 | Mips64Label done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5565 | SlowPathCodeMIPS64* slow_path = nullptr; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5566 | |
| 5567 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5568 | // Avoid this check if we know `obj` is not null. |
| 5569 | if (instruction->MustDoNullCheck()) { |
| 5570 | __ Move(out, ZERO); |
| 5571 | __ Beqzc(obj, &done); |
| 5572 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5573 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5574 | switch (type_check_kind) { |
| 5575 | case TypeCheckKind::kExactCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5576 | ReadBarrierOption read_barrier_option = |
| 5577 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5578 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5579 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5580 | out_loc, |
| 5581 | obj_loc, |
| 5582 | class_offset, |
| 5583 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5584 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5585 | // Classes must be equal for the instanceof to succeed. |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 5586 | __ Xor(out, out, cls); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5587 | __ Sltiu(out, out, 1); |
| 5588 | break; |
| 5589 | } |
| 5590 | |
| 5591 | case TypeCheckKind::kAbstractClassCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5592 | ReadBarrierOption read_barrier_option = |
| 5593 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5594 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5595 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5596 | out_loc, |
| 5597 | obj_loc, |
| 5598 | class_offset, |
| 5599 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5600 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5601 | // If the class is abstract, we eagerly fetch the super class of the |
| 5602 | // object to avoid doing a comparison we know will fail. |
| 5603 | Mips64Label loop; |
| 5604 | __ Bind(&loop); |
| 5605 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5606 | GenerateReferenceLoadOneRegister(instruction, |
| 5607 | out_loc, |
| 5608 | super_offset, |
| 5609 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5610 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5611 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5612 | __ Beqzc(out, &done); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 5613 | __ Bnec(out, cls, &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5614 | __ LoadConst32(out, 1); |
| 5615 | break; |
| 5616 | } |
| 5617 | |
| 5618 | case TypeCheckKind::kClassHierarchyCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5619 | ReadBarrierOption read_barrier_option = |
| 5620 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5621 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5622 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5623 | out_loc, |
| 5624 | obj_loc, |
| 5625 | class_offset, |
| 5626 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5627 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5628 | // Walk over the class hierarchy to find a match. |
| 5629 | Mips64Label loop, success; |
| 5630 | __ Bind(&loop); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 5631 | __ Beqc(out, cls, &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5632 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5633 | GenerateReferenceLoadOneRegister(instruction, |
| 5634 | out_loc, |
| 5635 | super_offset, |
| 5636 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5637 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5638 | __ Bnezc(out, &loop); |
| 5639 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5640 | __ Bc(&done); |
| 5641 | __ Bind(&success); |
| 5642 | __ LoadConst32(out, 1); |
| 5643 | break; |
| 5644 | } |
| 5645 | |
| 5646 | case TypeCheckKind::kArrayObjectCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5647 | ReadBarrierOption read_barrier_option = |
| 5648 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5649 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5650 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5651 | out_loc, |
| 5652 | obj_loc, |
| 5653 | class_offset, |
| 5654 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5655 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5656 | // Do an exact check. |
| 5657 | Mips64Label success; |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 5658 | __ Beqc(out, cls, &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5659 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 5660 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5661 | GenerateReferenceLoadOneRegister(instruction, |
| 5662 | out_loc, |
| 5663 | component_offset, |
| 5664 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 5665 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5666 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5667 | __ Beqzc(out, &done); |
| 5668 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5669 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5670 | __ Sltiu(out, out, 1); |
| 5671 | __ Bc(&done); |
| 5672 | __ Bind(&success); |
| 5673 | __ LoadConst32(out, 1); |
| 5674 | break; |
| 5675 | } |
| 5676 | |
| 5677 | case TypeCheckKind::kArrayCheck: { |
| 5678 | // No read barrier since the slow path will retry upon failure. |
| 5679 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5680 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5681 | out_loc, |
| 5682 | obj_loc, |
| 5683 | class_offset, |
| 5684 | maybe_temp_loc, |
| 5685 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5686 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5687 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( |
| 5688 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5689 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 5690 | __ Bnec(out, cls, slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5691 | __ LoadConst32(out, 1); |
| 5692 | break; |
| 5693 | } |
| 5694 | |
| 5695 | case TypeCheckKind::kUnresolvedCheck: |
| 5696 | case TypeCheckKind::kInterfaceCheck: { |
| 5697 | // Note that we indeed only call on slow path, but we always go |
| 5698 | // into the slow path for the unresolved and interface check |
| 5699 | // cases. |
| 5700 | // |
| 5701 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5702 | // entry point without resorting to a type checking slow path |
| 5703 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5704 | // require to assign fixed registers for the inputs of this |
| 5705 | // HInstanceOf instruction (following the runtime calling |
| 5706 | // convention), which might be cluttered by the potential first |
| 5707 | // read barrier emission at the beginning of this method. |
| 5708 | // |
| 5709 | // TODO: Introduce a new runtime entry point taking the object |
| 5710 | // to test (instead of its class) as argument, and let it deal |
| 5711 | // with the read barrier issues. This will let us refactor this |
| 5712 | // case of the `switch` code as it was previously (with a direct |
| 5713 | // call to the runtime not using a type checking slow path). |
| 5714 | // This should also be beneficial for the other cases above. |
| 5715 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5716 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( |
| 5717 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5718 | codegen_->AddSlowPath(slow_path); |
| 5719 | __ Bc(slow_path->GetEntryLabel()); |
| 5720 | break; |
| 5721 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 5725 | |
| 5726 | if (slow_path != nullptr) { |
| 5727 | __ Bind(slow_path->GetExitLabel()); |
| 5728 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5729 | } |
| 5730 | |
| 5731 | void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5732 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5733 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5734 | } |
| 5735 | |
| 5736 | void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 5737 | // Will be generated at use site. |
| 5738 | } |
| 5739 | |
| 5740 | void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5741 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5742 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5743 | } |
| 5744 | |
| 5745 | void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 5746 | // Will be generated at use site. |
| 5747 | } |
| 5748 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 5749 | void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 5750 | // The trampoline uses the same calling convention as dex calling conventions, |
| 5751 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 5752 | // the method_idx. |
| 5753 | HandleInvoke(invoke); |
| 5754 | } |
| 5755 | |
| 5756 | void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 5757 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 5758 | } |
| 5759 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5760 | void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) { |
| 5761 | InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor; |
| 5762 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 5763 | } |
| 5764 | |
| 5765 | void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5766 | HandleInvoke(invoke); |
| 5767 | // The register T0 is required to be used for the hidden argument in |
| 5768 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
| 5769 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); |
| 5770 | } |
| 5771 | |
| 5772 | void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5773 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 5774 | GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5775 | Location receiver = invoke->GetLocations()->InAt(0); |
| 5776 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5777 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5778 | |
| 5779 | // Set the hidden argument. |
| 5780 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(), |
| 5781 | invoke->GetDexMethodIndex()); |
| 5782 | |
| 5783 | // temp = object->GetClass(); |
| 5784 | if (receiver.IsStackSlot()) { |
| 5785 | __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex()); |
| 5786 | __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset); |
| 5787 | } else { |
| 5788 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset); |
| 5789 | } |
| 5790 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5791 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5792 | // emit a read barrier for the previous class reference load. |
| 5793 | // However this is not required in practice, as this is an |
| 5794 | // intermediate/temporary reference and because the current |
| 5795 | // concurrent copying collector keeps the from-space memory |
| 5796 | // intact/accessible until the end of the marking phase (the |
| 5797 | // concurrent copying collector may not in the future). |
| 5798 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5799 | __ LoadFromOffset(kLoadDoubleword, temp, temp, |
| 5800 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 5801 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5802 | invoke->GetImtIndex(), kMips64PointerSize)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5803 | // temp = temp->GetImtEntryAt(method_offset); |
| 5804 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 5805 | // T9 = temp->GetEntryPoint(); |
| 5806 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 5807 | // T9(); |
| 5808 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5809 | __ Nop(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5810 | DCHECK(!codegen_->IsLeafMethod()); |
| 5811 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5812 | } |
| 5813 | |
| 5814 | void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5815 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 5816 | if (intrinsic.TryDispatch(invoke)) { |
| 5817 | return; |
| 5818 | } |
| 5819 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5820 | HandleInvoke(invoke); |
| 5821 | } |
| 5822 | |
| 5823 | void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5824 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5825 | // art::PrepareForRegisterAllocation. |
| 5826 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5827 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5828 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 5829 | if (intrinsic.TryDispatch(invoke)) { |
| 5830 | return; |
| 5831 | } |
| 5832 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5833 | HandleInvoke(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5834 | } |
| 5835 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 5836 | void LocationsBuilderMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5837 | HandleInvoke(invoke); |
| 5838 | } |
| 5839 | |
| 5840 | void InstructionCodeGeneratorMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5841 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 5842 | } |
| 5843 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5844 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5845 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 5846 | IntrinsicCodeGeneratorMIPS64 intrinsic(codegen); |
| 5847 | intrinsic.Dispatch(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5848 | return true; |
| 5849 | } |
| 5850 | return false; |
| 5851 | } |
| 5852 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5853 | HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind( |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5854 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5855 | bool fallback_load = false; |
| 5856 | switch (desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5857 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5858 | case HLoadString::LoadKind::kBootImageInternTable: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5859 | case HLoadString::LoadKind::kBssEntry: |
| 5860 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5861 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5862 | case HLoadString::LoadKind::kJitTableAddress: |
| 5863 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5864 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5865 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5866 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5867 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5868 | } |
| 5869 | if (fallback_load) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5870 | desired_string_load_kind = HLoadString::LoadKind::kRuntimeCall; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5871 | } |
| 5872 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5873 | } |
| 5874 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5875 | HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind( |
| 5876 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5877 | bool fallback_load = false; |
| 5878 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5879 | case HLoadClass::LoadKind::kInvalid: |
| 5880 | LOG(FATAL) << "UNREACHABLE"; |
| 5881 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5882 | case HLoadClass::LoadKind::kReferrersClass: |
| 5883 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5884 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5885 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5886 | case HLoadClass::LoadKind::kBssEntry: |
| 5887 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5888 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5889 | case HLoadClass::LoadKind::kJitTableAddress: |
| 5890 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5891 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5892 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5893 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5894 | break; |
| 5895 | } |
| 5896 | if (fallback_load) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5897 | desired_class_load_kind = HLoadClass::LoadKind::kRuntimeCall; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5898 | } |
| 5899 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5900 | } |
| 5901 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5902 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch( |
| 5903 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5904 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5905 | // On MIPS64 we support all dispatch types. |
| 5906 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5907 | } |
| 5908 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5909 | void CodeGeneratorMIPS64::GenerateStaticOrDirectCall( |
| 5910 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5911 | // 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] | 5912 | 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] | 5913 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 5914 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
| 5915 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5916 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5917 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5918 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5919 | uint32_t offset = |
| 5920 | GetThreadOffset<kMips64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5921 | __ LoadFromOffset(kLoadDoubleword, |
| 5922 | temp.AsRegister<GpuRegister>(), |
| 5923 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5924 | offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5925 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5926 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5927 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5928 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5929 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5930 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 5931 | DCHECK(GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5932 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5933 | NewBootImageMethodPatch(invoke->GetTargetMethod()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5934 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5935 | NewBootImageMethodPatch(invoke->GetTargetMethod(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5936 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5937 | __ Daddiu(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 5938 | break; |
| 5939 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5940 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5941 | __ LoadLiteral(temp.AsRegister<GpuRegister>(), |
| 5942 | kLoadDoubleword, |
| 5943 | DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5944 | break; |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame^] | 5945 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 5946 | uint32_t boot_image_offset = invoke->GetDispatchInfo().method_load_data; |
| 5947 | PcRelativePatchInfo* info_high = NewBootImageRelRoPatch(boot_image_offset); |
| 5948 | PcRelativePatchInfo* info_low = NewBootImageRelRoPatch(boot_image_offset, info_high); |
| 5949 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 5950 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 5951 | __ Lwu(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 5952 | break; |
| 5953 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5954 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5955 | PcRelativePatchInfo* info_high = NewMethodBssEntryPatch( |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5956 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 5957 | PcRelativePatchInfo* info_low = NewMethodBssEntryPatch( |
| 5958 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high); |
| 5959 | EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5960 | __ Ld(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 5961 | break; |
| 5962 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5963 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 5964 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 5965 | return; // No code pointer retrieval; the runtime performs the call directly. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5966 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5967 | } |
| 5968 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5969 | switch (code_ptr_location) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5970 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5971 | __ Balc(&frame_entry_label_); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5972 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5973 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 5974 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
| 5975 | __ LoadFromOffset(kLoadDoubleword, |
| 5976 | T9, |
| 5977 | callee_method.AsRegister<GpuRegister>(), |
| 5978 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5979 | kMips64PointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5980 | // T9() |
| 5981 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5982 | __ Nop(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5983 | break; |
| 5984 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5985 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 5986 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5987 | DCHECK(!IsLeafMethod()); |
| 5988 | } |
| 5989 | |
| 5990 | void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5991 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5992 | // art::PrepareForRegisterAllocation. |
| 5993 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5994 | |
| 5995 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5996 | return; |
| 5997 | } |
| 5998 | |
| 5999 | LocationSummary* locations = invoke->GetLocations(); |
| 6000 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 6001 | locations->HasTemps() |
| 6002 | ? locations->GetTemp(0) |
| 6003 | : Location::NoLocation()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6004 | } |
| 6005 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 6006 | void CodeGeneratorMIPS64::GenerateVirtualCall( |
| 6007 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6008 | // Use the calling convention instead of the location of the receiver, as |
| 6009 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 6010 | // slow path, the arguments have been moved to the right place, so here we are |
| 6011 | // guaranteed that the receiver is the first register of the calling convention. |
| 6012 | InvokeDexCallingConvention calling_convention; |
| 6013 | GpuRegister receiver = calling_convention.GetRegisterAt(0); |
| 6014 | |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 6015 | GpuRegister temp = temp_location.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6016 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 6017 | invoke->GetVTableIndex(), kMips64PointerSize).SizeValue(); |
| 6018 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6019 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6020 | |
| 6021 | // temp = object->GetClass(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6022 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 6023 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6024 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 6025 | // emit a read barrier for the previous class reference load. |
| 6026 | // However this is not required in practice, as this is an |
| 6027 | // intermediate/temporary reference and because the current |
| 6028 | // concurrent copying collector keeps the from-space memory |
| 6029 | // intact/accessible until the end of the marking phase (the |
| 6030 | // concurrent copying collector may not in the future). |
| 6031 | __ MaybeUnpoisonHeapReference(temp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6032 | // temp = temp->GetMethodAt(method_offset); |
| 6033 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 6034 | // T9 = temp->GetEntryPoint(); |
| 6035 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 6036 | // T9(); |
| 6037 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 6038 | __ Nop(); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 6039 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 6040 | } |
| 6041 | |
| 6042 | void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 6043 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 6044 | return; |
| 6045 | } |
| 6046 | |
| 6047 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6048 | DCHECK(!codegen_->IsLeafMethod()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6049 | } |
| 6050 | |
| 6051 | void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6052 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6053 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6054 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6055 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6056 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6057 | return; |
| 6058 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6059 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6060 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6061 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6062 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6063 | ? LocationSummary::kCallOnSlowPath |
| 6064 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6065 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6066 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 6067 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 6068 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6069 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6070 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6071 | } |
| 6072 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6073 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6074 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6075 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 6076 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6077 | InvokeRuntimeCallingConvention calling_convention; |
| 6078 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6079 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6080 | } else { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6081 | // For non-Baker read barriers we have a temp-clobbering call. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6082 | } |
| 6083 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6084 | } |
| 6085 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6086 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6087 | // move. |
| 6088 | void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6089 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6090 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6091 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6092 | return; |
| 6093 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6094 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6095 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6096 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6097 | Location out_loc = locations->Out(); |
| 6098 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 6099 | GpuRegister current_method_reg = ZERO; |
| 6100 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6101 | load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6102 | current_method_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6103 | } |
| 6104 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6105 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6106 | ? kWithoutReadBarrier |
| 6107 | : kCompilerReadBarrierOption; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6108 | bool generate_null_check = false; |
| 6109 | switch (load_kind) { |
| 6110 | case HLoadClass::LoadKind::kReferrersClass: |
| 6111 | DCHECK(!cls->CanCallRuntime()); |
| 6112 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6113 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6114 | GenerateGcRootFieldLoad(cls, |
| 6115 | out_loc, |
| 6116 | current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6117 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 6118 | read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6119 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6120 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6121 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6122 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6123 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6124 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6125 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6126 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6127 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6128 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
| 6129 | break; |
| 6130 | } |
| 6131 | case HLoadClass::LoadKind::kBootImageAddress: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6132 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6133 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6134 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6135 | DCHECK_NE(address, 0u); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6136 | __ LoadLiteral(out, |
| 6137 | kLoadUnsignedWord, |
| 6138 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6139 | break; |
| 6140 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6141 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 6142 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6143 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6144 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6145 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6146 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6147 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 6148 | __ Lwu(out, AT, /* placeholder */ 0x5678); |
| 6149 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 6150 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 6151 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 6152 | if (masked_hash != 0) { |
| 6153 | __ Daddiu(out, out, -masked_hash); |
| 6154 | } |
| 6155 | break; |
| 6156 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6157 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6158 | CodeGeneratorMIPS64::PcRelativePatchInfo* bss_info_high = |
| 6159 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6160 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6161 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6162 | codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, out); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6163 | GenerateGcRootFieldLoad(cls, |
| 6164 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6165 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6166 | /* placeholder */ 0x5678, |
| 6167 | read_barrier_option, |
| 6168 | &info_low->label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6169 | generate_null_check = true; |
| 6170 | break; |
| 6171 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6172 | case HLoadClass::LoadKind::kJitTableAddress: |
| 6173 | __ LoadLiteral(out, |
| 6174 | kLoadUnsignedWord, |
| 6175 | codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6176 | cls->GetTypeIndex(), |
| 6177 | cls->GetClass())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6178 | GenerateGcRootFieldLoad(cls, out_loc, out, 0, read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6179 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6180 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6181 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6182 | LOG(FATAL) << "UNREACHABLE"; |
| 6183 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6184 | } |
| 6185 | |
| 6186 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6187 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6188 | SlowPathCodeMIPS64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS64( |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6189 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6190 | codegen_->AddSlowPath(slow_path); |
| 6191 | if (generate_null_check) { |
| 6192 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 6193 | } |
| 6194 | if (cls->MustGenerateClinitCheck()) { |
| 6195 | GenerateClassInitializationCheck(slow_path, out); |
| 6196 | } else { |
| 6197 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6198 | } |
| 6199 | } |
| 6200 | } |
| 6201 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6202 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6203 | return Thread::ExceptionOffset<kMips64PointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6204 | } |
| 6205 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6206 | void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) { |
| 6207 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6208 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6209 | locations->SetOut(Location::RequiresRegister()); |
| 6210 | } |
| 6211 | |
| 6212 | void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) { |
| 6213 | GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6214 | __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset()); |
| 6215 | } |
| 6216 | |
| 6217 | void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6218 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6219 | } |
| 6220 | |
| 6221 | void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6222 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6223 | } |
| 6224 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6225 | void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6226 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6227 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6228 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6229 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6230 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6231 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6232 | } else { |
| 6233 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6234 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6235 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6236 | // Rely on the pResolveString and marking to save everything we need. |
| 6237 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6238 | InvokeRuntimeCallingConvention calling_convention; |
| 6239 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6240 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6241 | } else { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6242 | // For non-Baker read barriers we have a temp-clobbering call. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6243 | } |
| 6244 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6245 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6246 | } |
| 6247 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6248 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6249 | // move. |
| 6250 | void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6251 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6252 | LocationSummary* locations = load->GetLocations(); |
| 6253 | Location out_loc = locations->Out(); |
| 6254 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 6255 | |
| 6256 | switch (load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6257 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6258 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6259 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6260 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6261 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6262 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6263 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6264 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6265 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6266 | } |
| 6267 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6268 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6269 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6270 | DCHECK_NE(address, 0u); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6271 | __ LoadLiteral(out, |
| 6272 | kLoadUnsignedWord, |
| 6273 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6274 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6275 | } |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6276 | case HLoadString::LoadKind::kBootImageInternTable: { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6277 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6278 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6279 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6280 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6281 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6282 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, AT, info_low); |
| 6283 | __ Lwu(out, AT, /* placeholder */ 0x5678); |
| 6284 | return; |
| 6285 | } |
| 6286 | case HLoadString::LoadKind::kBssEntry: { |
| 6287 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6288 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_high = |
| 6289 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| 6290 | CodeGeneratorMIPS64::PcRelativePatchInfo* info_low = |
| 6291 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6292 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, out); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6293 | GenerateGcRootFieldLoad(load, |
| 6294 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6295 | out, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6296 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6297 | kCompilerReadBarrierOption, |
| 6298 | &info_low->label); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 6299 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 6300 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS64(load); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6301 | codegen_->AddSlowPath(slow_path); |
| 6302 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 6303 | __ Bind(slow_path->GetExitLabel()); |
| 6304 | return; |
| 6305 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6306 | case HLoadString::LoadKind::kJitTableAddress: |
| 6307 | __ LoadLiteral(out, |
| 6308 | kLoadUnsignedWord, |
| 6309 | codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
| 6310 | load->GetStringIndex(), |
| 6311 | load->GetString())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6312 | GenerateGcRootFieldLoad(load, out_loc, out, 0, kCompilerReadBarrierOption); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6313 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6314 | default: |
| 6315 | break; |
| 6316 | } |
| 6317 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6318 | // 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] | 6319 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6320 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6321 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 6322 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
| 6323 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6324 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6325 | } |
| 6326 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6327 | void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6328 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6329 | locations->SetOut(Location::ConstantLocation(constant)); |
| 6330 | } |
| 6331 | |
| 6332 | void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 6333 | // Will be generated at use site. |
| 6334 | } |
| 6335 | |
| 6336 | void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6337 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6338 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6339 | InvokeRuntimeCallingConvention calling_convention; |
| 6340 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6341 | } |
| 6342 | |
| 6343 | void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6344 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6345 | instruction, |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6346 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6347 | if (instruction->IsEnter()) { |
| 6348 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6349 | } else { |
| 6350 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6351 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6352 | } |
| 6353 | |
| 6354 | void LocationsBuilderMIPS64::VisitMul(HMul* mul) { |
| 6355 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6356 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6357 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6358 | case DataType::Type::kInt32: |
| 6359 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6360 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6361 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6362 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6363 | break; |
| 6364 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6365 | case DataType::Type::kFloat32: |
| 6366 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6367 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6368 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 6369 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6370 | break; |
| 6371 | |
| 6372 | default: |
| 6373 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 6374 | } |
| 6375 | } |
| 6376 | |
| 6377 | void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6378 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6379 | LocationSummary* locations = instruction->GetLocations(); |
| 6380 | |
| 6381 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6382 | case DataType::Type::kInt32: |
| 6383 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6384 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6385 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6386 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6387 | if (type == DataType::Type::kInt32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6388 | __ MulR6(dst, lhs, rhs); |
| 6389 | else |
| 6390 | __ Dmul(dst, lhs, rhs); |
| 6391 | break; |
| 6392 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6393 | case DataType::Type::kFloat32: |
| 6394 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6395 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6396 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 6397 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6398 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6399 | __ MulS(dst, lhs, rhs); |
| 6400 | else |
| 6401 | __ MulD(dst, lhs, rhs); |
| 6402 | break; |
| 6403 | } |
| 6404 | default: |
| 6405 | LOG(FATAL) << "Unexpected mul type " << type; |
| 6406 | } |
| 6407 | } |
| 6408 | |
| 6409 | void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) { |
| 6410 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6411 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6412 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6413 | case DataType::Type::kInt32: |
| 6414 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6415 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6416 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6417 | break; |
| 6418 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6419 | case DataType::Type::kFloat32: |
| 6420 | case DataType::Type::kFloat64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6421 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6422 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6423 | break; |
| 6424 | |
| 6425 | default: |
| 6426 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 6427 | } |
| 6428 | } |
| 6429 | |
| 6430 | void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6431 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6432 | LocationSummary* locations = instruction->GetLocations(); |
| 6433 | |
| 6434 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6435 | case DataType::Type::kInt32: |
| 6436 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6437 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6438 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6439 | if (type == DataType::Type::kInt32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6440 | __ Subu(dst, ZERO, src); |
| 6441 | else |
| 6442 | __ Dsubu(dst, ZERO, src); |
| 6443 | break; |
| 6444 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6445 | case DataType::Type::kFloat32: |
| 6446 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6447 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6448 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6449 | if (type == DataType::Type::kFloat32) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6450 | __ NegS(dst, src); |
| 6451 | else |
| 6452 | __ NegD(dst, src); |
| 6453 | break; |
| 6454 | } |
| 6455 | default: |
| 6456 | LOG(FATAL) << "Unexpected neg type " << type; |
| 6457 | } |
| 6458 | } |
| 6459 | |
| 6460 | void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6461 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6462 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6463 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6464 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6465 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6466 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6467 | } |
| 6468 | |
| 6469 | void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6470 | // Note: if heap poisoning is enabled, the entry point takes care |
| 6471 | // of poisoning the reference. |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 6472 | QuickEntrypointEnum entrypoint = |
| 6473 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 6474 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6475 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 6476 | DCHECK(!codegen_->IsLeafMethod()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6477 | } |
| 6478 | |
| 6479 | void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6480 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6481 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6482 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6483 | if (instruction->IsStringAlloc()) { |
| 6484 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6485 | } else { |
| 6486 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6487 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6488 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6489 | } |
| 6490 | |
| 6491 | void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6492 | // Note: if heap poisoning is enabled, the entry point takes care |
| 6493 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6494 | if (instruction->IsStringAlloc()) { |
| 6495 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 6496 | GpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 6497 | MemberOffset code_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6498 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6499 | __ LoadFromOffset(kLoadDoubleword, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 6500 | __ LoadFromOffset(kLoadDoubleword, T9, temp, code_offset.Int32Value()); |
| 6501 | __ Jalr(T9); |
| 6502 | __ Nop(); |
| 6503 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 6504 | } else { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6505 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 6506 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6507 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6508 | } |
| 6509 | |
| 6510 | void LocationsBuilderMIPS64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6511 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6512 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6513 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6514 | } |
| 6515 | |
| 6516 | void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6517 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6518 | LocationSummary* locations = instruction->GetLocations(); |
| 6519 | |
| 6520 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6521 | case DataType::Type::kInt32: |
| 6522 | case DataType::Type::kInt64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6523 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6524 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6525 | __ Nor(dst, src, ZERO); |
| 6526 | break; |
| 6527 | } |
| 6528 | |
| 6529 | default: |
| 6530 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 6531 | } |
| 6532 | } |
| 6533 | |
| 6534 | void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6535 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6536 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6537 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6538 | } |
| 6539 | |
| 6540 | void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
| 6541 | LocationSummary* locations = instruction->GetLocations(); |
| 6542 | __ Xori(locations->Out().AsRegister<GpuRegister>(), |
| 6543 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 6544 | 1); |
| 6545 | } |
| 6546 | |
| 6547 | void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6548 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 6549 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6550 | } |
| 6551 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6552 | void CodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6553 | if (CanMoveNullCheckToUser(instruction)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6554 | return; |
| 6555 | } |
| 6556 | Location obj = instruction->GetLocations()->InAt(0); |
| 6557 | |
| 6558 | __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6559 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6560 | } |
| 6561 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6562 | void CodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6563 | SlowPathCodeMIPS64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6564 | new (GetScopedAllocator()) NullCheckSlowPathMIPS64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6565 | AddSlowPath(slow_path); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6566 | |
| 6567 | Location obj = instruction->GetLocations()->InAt(0); |
| 6568 | |
| 6569 | __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 6570 | } |
| 6571 | |
| 6572 | void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6573 | codegen_->GenerateNullCheck(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6574 | } |
| 6575 | |
| 6576 | void LocationsBuilderMIPS64::VisitOr(HOr* instruction) { |
| 6577 | HandleBinaryOp(instruction); |
| 6578 | } |
| 6579 | |
| 6580 | void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) { |
| 6581 | HandleBinaryOp(instruction); |
| 6582 | } |
| 6583 | |
| 6584 | void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6585 | LOG(FATAL) << "Unreachable"; |
| 6586 | } |
| 6587 | |
| 6588 | void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6589 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6590 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6591 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6592 | // The back edge will generate the suspend check. |
| 6593 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6594 | } |
| 6595 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6596 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6597 | } |
| 6598 | |
| 6599 | void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6600 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6601 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 6602 | if (location.IsStackSlot()) { |
| 6603 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6604 | } else if (location.IsDoubleStackSlot()) { |
| 6605 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6606 | } |
| 6607 | locations->SetOut(location); |
| 6608 | } |
| 6609 | |
| 6610 | void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction |
| 6611 | ATTRIBUTE_UNUSED) { |
| 6612 | // Nothing to do, the parameter is already at its location. |
| 6613 | } |
| 6614 | |
| 6615 | void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 6616 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6617 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6618 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6619 | } |
| 6620 | |
| 6621 | void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction |
| 6622 | ATTRIBUTE_UNUSED) { |
| 6623 | // Nothing to do, the method is already at its location. |
| 6624 | } |
| 6625 | |
| 6626 | void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6627 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6628 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6629 | locations->SetInAt(i, Location::Any()); |
| 6630 | } |
| 6631 | locations->SetOut(Location::Any()); |
| 6632 | } |
| 6633 | |
| 6634 | void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 6635 | LOG(FATAL) << "Unreachable"; |
| 6636 | } |
| 6637 | |
| 6638 | void LocationsBuilderMIPS64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6639 | DataType::Type type = rem->GetResultType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6640 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6641 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 6642 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6643 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6644 | |
| 6645 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6646 | case DataType::Type::kInt32: |
| 6647 | case DataType::Type::kInt64: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6648 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 6649 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6650 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6651 | break; |
| 6652 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6653 | case DataType::Type::kFloat32: |
| 6654 | case DataType::Type::kFloat64: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6655 | InvokeRuntimeCallingConvention calling_convention; |
| 6656 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 6657 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 6658 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 6659 | break; |
| 6660 | } |
| 6661 | |
| 6662 | default: |
| 6663 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6664 | } |
| 6665 | } |
| 6666 | |
| 6667 | void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6668 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6669 | |
| 6670 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6671 | case DataType::Type::kInt32: |
| 6672 | case DataType::Type::kInt64: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 6673 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6674 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6675 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6676 | case DataType::Type::kFloat32: |
| 6677 | case DataType::Type::kFloat64: { |
| 6678 | QuickEntrypointEnum entrypoint = |
| 6679 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6680 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6681 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6682 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 6683 | } else { |
| 6684 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 6685 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6686 | break; |
| 6687 | } |
| 6688 | default: |
| 6689 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6690 | } |
| 6691 | } |
| 6692 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 6693 | void LocationsBuilderMIPS64::VisitAbs(HAbs* abs) { |
| 6694 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 6695 | switch (abs->GetResultType()) { |
| 6696 | case DataType::Type::kInt32: |
| 6697 | case DataType::Type::kInt64: |
| 6698 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6699 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6700 | break; |
| 6701 | case DataType::Type::kFloat32: |
| 6702 | case DataType::Type::kFloat64: |
| 6703 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6704 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6705 | break; |
| 6706 | default: |
| 6707 | LOG(FATAL) << "Unexpected abs type " << abs->GetResultType(); |
| 6708 | } |
| 6709 | } |
| 6710 | |
| 6711 | void InstructionCodeGeneratorMIPS64::VisitAbs(HAbs* abs) { |
| 6712 | LocationSummary* locations = abs->GetLocations(); |
| 6713 | switch (abs->GetResultType()) { |
| 6714 | case DataType::Type::kInt32: { |
| 6715 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6716 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 6717 | __ Sra(AT, in, 31); |
| 6718 | __ Xor(out, in, AT); |
| 6719 | __ Subu(out, out, AT); |
| 6720 | break; |
| 6721 | } |
| 6722 | case DataType::Type::kInt64: { |
| 6723 | GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6724 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 6725 | __ Dsra32(AT, in, 31); |
| 6726 | __ Xor(out, in, AT); |
| 6727 | __ Dsubu(out, out, AT); |
| 6728 | break; |
| 6729 | } |
| 6730 | case DataType::Type::kFloat32: { |
| 6731 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 6732 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6733 | __ AbsS(out, in); |
| 6734 | break; |
| 6735 | } |
| 6736 | case DataType::Type::kFloat64: { |
| 6737 | FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 6738 | FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6739 | __ AbsD(out, in); |
| 6740 | break; |
| 6741 | } |
| 6742 | default: |
| 6743 | LOG(FATAL) << "Unexpected abs type " << abs->GetResultType(); |
| 6744 | } |
| 6745 | } |
| 6746 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6747 | void LocationsBuilderMIPS64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 6748 | constructor_fence->SetLocations(nullptr); |
| 6749 | } |
| 6750 | |
| 6751 | void InstructionCodeGeneratorMIPS64::VisitConstructorFence( |
| 6752 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 6753 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 6754 | } |
| 6755 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6756 | void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6757 | memory_barrier->SetLocations(nullptr); |
| 6758 | } |
| 6759 | |
| 6760 | void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6761 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 6762 | } |
| 6763 | |
| 6764 | void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6765 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6766 | DataType::Type return_type = ret->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6767 | locations->SetInAt(0, Mips64ReturnLocation(return_type)); |
| 6768 | } |
| 6769 | |
| 6770 | void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 6771 | codegen_->GenerateFrameExit(); |
| 6772 | } |
| 6773 | |
| 6774 | void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) { |
| 6775 | ret->SetLocations(nullptr); |
| 6776 | } |
| 6777 | |
| 6778 | void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 6779 | codegen_->GenerateFrameExit(); |
| 6780 | } |
| 6781 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6782 | void LocationsBuilderMIPS64::VisitRor(HRor* ror) { |
| 6783 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6784 | } |
| 6785 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6786 | void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) { |
| 6787 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6788 | } |
| 6789 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6790 | void LocationsBuilderMIPS64::VisitShl(HShl* shl) { |
| 6791 | HandleShift(shl); |
| 6792 | } |
| 6793 | |
| 6794 | void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) { |
| 6795 | HandleShift(shl); |
| 6796 | } |
| 6797 | |
| 6798 | void LocationsBuilderMIPS64::VisitShr(HShr* shr) { |
| 6799 | HandleShift(shr); |
| 6800 | } |
| 6801 | |
| 6802 | void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) { |
| 6803 | HandleShift(shr); |
| 6804 | } |
| 6805 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6806 | void LocationsBuilderMIPS64::VisitSub(HSub* instruction) { |
| 6807 | HandleBinaryOp(instruction); |
| 6808 | } |
| 6809 | |
| 6810 | void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) { |
| 6811 | HandleBinaryOp(instruction); |
| 6812 | } |
| 6813 | |
| 6814 | void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6815 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6816 | } |
| 6817 | |
| 6818 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6819 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6820 | } |
| 6821 | |
| 6822 | void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6823 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6824 | } |
| 6825 | |
| 6826 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 6827 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6828 | } |
| 6829 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6830 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet( |
| 6831 | HUnresolvedInstanceFieldGet* instruction) { |
| 6832 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6833 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6834 | instruction, instruction->GetFieldType(), calling_convention); |
| 6835 | } |
| 6836 | |
| 6837 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet( |
| 6838 | HUnresolvedInstanceFieldGet* instruction) { |
| 6839 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6840 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6841 | instruction->GetFieldType(), |
| 6842 | instruction->GetFieldIndex(), |
| 6843 | instruction->GetDexPc(), |
| 6844 | calling_convention); |
| 6845 | } |
| 6846 | |
| 6847 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet( |
| 6848 | HUnresolvedInstanceFieldSet* instruction) { |
| 6849 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6850 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6851 | instruction, instruction->GetFieldType(), calling_convention); |
| 6852 | } |
| 6853 | |
| 6854 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet( |
| 6855 | HUnresolvedInstanceFieldSet* instruction) { |
| 6856 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6857 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6858 | instruction->GetFieldType(), |
| 6859 | instruction->GetFieldIndex(), |
| 6860 | instruction->GetDexPc(), |
| 6861 | calling_convention); |
| 6862 | } |
| 6863 | |
| 6864 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet( |
| 6865 | HUnresolvedStaticFieldGet* instruction) { |
| 6866 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6867 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6868 | instruction, instruction->GetFieldType(), calling_convention); |
| 6869 | } |
| 6870 | |
| 6871 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet( |
| 6872 | HUnresolvedStaticFieldGet* instruction) { |
| 6873 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6874 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6875 | instruction->GetFieldType(), |
| 6876 | instruction->GetFieldIndex(), |
| 6877 | instruction->GetDexPc(), |
| 6878 | calling_convention); |
| 6879 | } |
| 6880 | |
| 6881 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet( |
| 6882 | HUnresolvedStaticFieldSet* instruction) { |
| 6883 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6884 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6885 | instruction, instruction->GetFieldType(), calling_convention); |
| 6886 | } |
| 6887 | |
| 6888 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet( |
| 6889 | HUnresolvedStaticFieldSet* instruction) { |
| 6890 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 6891 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6892 | instruction->GetFieldType(), |
| 6893 | instruction->GetFieldIndex(), |
| 6894 | instruction->GetDexPc(), |
| 6895 | calling_convention); |
| 6896 | } |
| 6897 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6898 | void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6899 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6900 | instruction, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 6901 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6902 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6903 | // registers in full width (since the runtime only saves/restores lower part). |
| 6904 | locations->SetCustomSlowPathCallerSaves( |
| 6905 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6906 | } |
| 6907 | |
| 6908 | void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6909 | HBasicBlock* block = instruction->GetBlock(); |
| 6910 | if (block->GetLoopInformation() != nullptr) { |
| 6911 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6912 | // The back edge will generate the suspend check. |
| 6913 | return; |
| 6914 | } |
| 6915 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6916 | // The goto will generate the suspend check. |
| 6917 | return; |
| 6918 | } |
| 6919 | GenerateSuspendCheck(instruction, nullptr); |
| 6920 | } |
| 6921 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6922 | void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6923 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6924 | instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6925 | InvokeRuntimeCallingConvention calling_convention; |
| 6926 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6927 | } |
| 6928 | |
| 6929 | void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 6930 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6931 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 6932 | } |
| 6933 | |
| 6934 | void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6935 | DataType::Type input_type = conversion->GetInputType(); |
| 6936 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6937 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6938 | << input_type << " -> " << result_type; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6939 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6940 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 6941 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6942 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 6943 | } |
| 6944 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6945 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(conversion); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6946 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6947 | if (DataType::IsFloatingPointType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6948 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6949 | } else { |
| 6950 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6951 | } |
| 6952 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6953 | if (DataType::IsFloatingPointType(result_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6954 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6955 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6956 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6957 | } |
| 6958 | } |
| 6959 | |
| 6960 | void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
| 6961 | LocationSummary* locations = conversion->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6962 | DataType::Type result_type = conversion->GetResultType(); |
| 6963 | DataType::Type input_type = conversion->GetInputType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6964 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6965 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6966 | << input_type << " -> " << result_type; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6967 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6968 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6969 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 6970 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6971 | |
| 6972 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6973 | case DataType::Type::kUint8: |
| 6974 | __ Andi(dst, src, 0xFF); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6975 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6976 | case DataType::Type::kInt8: |
| 6977 | if (input_type == DataType::Type::kInt64) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 6978 | // Type conversion from long to types narrower than int is a result of code |
| 6979 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 6980 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 6981 | __ Sll(dst, src, 0); |
| 6982 | __ Seb(dst, dst); |
| 6983 | } else { |
| 6984 | __ Seb(dst, src); |
| 6985 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6986 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6987 | case DataType::Type::kUint16: |
| 6988 | __ Andi(dst, src, 0xFFFF); |
| 6989 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6990 | case DataType::Type::kInt16: |
| 6991 | if (input_type == DataType::Type::kInt64) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 6992 | // Type conversion from long to types narrower than int is a result of code |
| 6993 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 6994 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 6995 | __ Sll(dst, src, 0); |
| 6996 | __ Seh(dst, dst); |
| 6997 | } else { |
| 6998 | __ Seh(dst, src); |
| 6999 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7000 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7001 | case DataType::Type::kInt32: |
| 7002 | case DataType::Type::kInt64: |
Goran Jakovljevic | 992bdb9 | 2016-12-28 16:21:48 +0100 | [diff] [blame] | 7003 | // Sign-extend 32-bit int into bits 32 through 63 for int-to-long and long-to-int |
| 7004 | // conversions, except when the input and output registers are the same and we are not |
| 7005 | // converting longs to shorter types. In these cases, do nothing. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7006 | if ((input_type == DataType::Type::kInt64) || (dst != src)) { |
Goran Jakovljevic | 992bdb9 | 2016-12-28 16:21:48 +0100 | [diff] [blame] | 7007 | __ Sll(dst, src, 0); |
| 7008 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7009 | break; |
| 7010 | |
| 7011 | default: |
| 7012 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 7013 | << " to " << result_type; |
| 7014 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7015 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7016 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 7017 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7018 | if (input_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7019 | __ Dmtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7020 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7021 | __ Cvtsl(dst, FTMP); |
| 7022 | } else { |
| 7023 | __ Cvtdl(dst, FTMP); |
| 7024 | } |
| 7025 | } else { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7026 | __ Mtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7027 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7028 | __ Cvtsw(dst, FTMP); |
| 7029 | } else { |
| 7030 | __ Cvtdw(dst, FTMP); |
| 7031 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7032 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7033 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 7034 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7035 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 7036 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7037 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7038 | if (result_type == DataType::Type::kInt64) { |
| 7039 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7040 | __ TruncLS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7041 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7042 | __ TruncLD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7043 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7044 | __ Dmfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7045 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7046 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7047 | __ TruncWS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7048 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7049 | __ TruncWD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7050 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7051 | __ Mfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7052 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7053 | } else if (DataType::IsFloatingPointType(result_type) && |
| 7054 | DataType::IsFloatingPointType(input_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7055 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 7056 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7057 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7058 | __ Cvtsd(dst, src); |
| 7059 | } else { |
| 7060 | __ Cvtds(dst, src); |
| 7061 | } |
| 7062 | } else { |
| 7063 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 7064 | << " to " << result_type; |
| 7065 | } |
| 7066 | } |
| 7067 | |
| 7068 | void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) { |
| 7069 | HandleShift(ushr); |
| 7070 | } |
| 7071 | |
| 7072 | void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) { |
| 7073 | HandleShift(ushr); |
| 7074 | } |
| 7075 | |
| 7076 | void LocationsBuilderMIPS64::VisitXor(HXor* instruction) { |
| 7077 | HandleBinaryOp(instruction); |
| 7078 | } |
| 7079 | |
| 7080 | void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) { |
| 7081 | HandleBinaryOp(instruction); |
| 7082 | } |
| 7083 | |
| 7084 | void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 7085 | // Nothing to do, this should be removed during prepare for register allocator. |
| 7086 | LOG(FATAL) << "Unreachable"; |
| 7087 | } |
| 7088 | |
| 7089 | void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 7090 | // Nothing to do, this should be removed during prepare for register allocator. |
| 7091 | LOG(FATAL) << "Unreachable"; |
| 7092 | } |
| 7093 | |
| 7094 | void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7095 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7096 | } |
| 7097 | |
| 7098 | void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7099 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7100 | } |
| 7101 | |
| 7102 | void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7103 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7104 | } |
| 7105 | |
| 7106 | void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7107 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7108 | } |
| 7109 | |
| 7110 | void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7111 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7112 | } |
| 7113 | |
| 7114 | void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7115 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7116 | } |
| 7117 | |
| 7118 | void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7119 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7120 | } |
| 7121 | |
| 7122 | void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7123 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7124 | } |
| 7125 | |
| 7126 | void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7127 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7128 | } |
| 7129 | |
| 7130 | void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7131 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7132 | } |
| 7133 | |
| 7134 | void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7135 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7136 | } |
| 7137 | |
| 7138 | void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7139 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7140 | } |
| 7141 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7142 | void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7143 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7144 | } |
| 7145 | |
| 7146 | void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7147 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7148 | } |
| 7149 | |
| 7150 | void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7151 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7152 | } |
| 7153 | |
| 7154 | void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7155 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7156 | } |
| 7157 | |
| 7158 | void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7159 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7160 | } |
| 7161 | |
| 7162 | void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7163 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7164 | } |
| 7165 | |
| 7166 | void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7167 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7168 | } |
| 7169 | |
| 7170 | void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7171 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 7172 | } |
| 7173 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7174 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7175 | void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7176 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7177 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7178 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7179 | } |
| 7180 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7181 | void InstructionCodeGeneratorMIPS64::GenPackedSwitchWithCompares(GpuRegister value_reg, |
| 7182 | int32_t lower_bound, |
| 7183 | uint32_t num_entries, |
| 7184 | HBasicBlock* switch_block, |
| 7185 | HBasicBlock* default_block) { |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7186 | // Create a set of compare/jumps. |
| 7187 | GpuRegister temp_reg = TMP; |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7188 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7189 | // Jump to default if index is negative |
| 7190 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 7191 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 7192 | __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block)); |
| 7193 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7194 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7195 | // Jump to successors[0] if value == lower_bound. |
| 7196 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 7197 | int32_t last_index = 0; |
| 7198 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7199 | __ Addiu(temp_reg, temp_reg, -2); |
| 7200 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7201 | __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 7202 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7203 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 7204 | } |
| 7205 | if (num_entries - last_index == 2) { |
| 7206 | // The last missing case_value. |
| 7207 | __ Addiu(temp_reg, temp_reg, -1); |
| 7208 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7209 | } |
| 7210 | |
| 7211 | // And the default for any other value. |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7212 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 7213 | __ Bc(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7214 | } |
| 7215 | } |
| 7216 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7217 | void InstructionCodeGeneratorMIPS64::GenTableBasedPackedSwitch(GpuRegister value_reg, |
| 7218 | int32_t lower_bound, |
| 7219 | uint32_t num_entries, |
| 7220 | HBasicBlock* switch_block, |
| 7221 | HBasicBlock* default_block) { |
| 7222 | // Create a jump table. |
| 7223 | std::vector<Mips64Label*> labels(num_entries); |
| 7224 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7225 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7226 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7227 | } |
| 7228 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 7229 | |
| 7230 | // Is the value in range? |
| 7231 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 7232 | __ LoadConst32(AT, num_entries); |
| 7233 | __ Bgeuc(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 7234 | |
| 7235 | // We are in the range of the table. |
| 7236 | // Load the target address from the jump table, indexing by the value. |
| 7237 | __ LoadLabelAddress(AT, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 7238 | __ Dlsa(TMP, TMP, AT, 2); |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 7239 | __ Lw(TMP, TMP, 0); |
| 7240 | // Compute the absolute target address by adding the table start address |
| 7241 | // (the table contains offsets to targets relative to its start). |
| 7242 | __ Daddu(TMP, TMP, AT); |
| 7243 | // And jump. |
| 7244 | __ Jr(TMP); |
| 7245 | __ Nop(); |
| 7246 | } |
| 7247 | |
| 7248 | void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7249 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7250 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7251 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7252 | GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 7253 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 7254 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7255 | |
| 7256 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
| 7257 | GenTableBasedPackedSwitch(value_reg, |
| 7258 | lower_bound, |
| 7259 | num_entries, |
| 7260 | switch_block, |
| 7261 | default_block); |
| 7262 | } else { |
| 7263 | GenPackedSwitchWithCompares(value_reg, |
| 7264 | lower_bound, |
| 7265 | num_entries, |
| 7266 | switch_block, |
| 7267 | default_block); |
| 7268 | } |
| 7269 | } |
| 7270 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7271 | void LocationsBuilderMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 7272 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7273 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7274 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7275 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7276 | } |
| 7277 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 7278 | void InstructionCodeGeneratorMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 7279 | LocationSummary* locations = instruction->GetLocations(); |
| 7280 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 7281 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7282 | instruction->GetIndex(), kMips64PointerSize).SizeValue(); |
| 7283 | __ LoadFromOffset(kLoadDoubleword, |
| 7284 | locations->Out().AsRegister<GpuRegister>(), |
| 7285 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 7286 | method_offset); |
| 7287 | } else { |
| 7288 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 7289 | instruction->GetIndex(), kMips64PointerSize)); |
| 7290 | __ LoadFromOffset(kLoadDoubleword, |
| 7291 | locations->Out().AsRegister<GpuRegister>(), |
| 7292 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 7293 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 7294 | __ LoadFromOffset(kLoadDoubleword, |
| 7295 | locations->Out().AsRegister<GpuRegister>(), |
| 7296 | locations->Out().AsRegister<GpuRegister>(), |
| 7297 | method_offset); |
| 7298 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7299 | } |
| 7300 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7301 | void LocationsBuilderMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7302 | ATTRIBUTE_UNUSED) { |
| 7303 | LOG(FATAL) << "Unreachable"; |
| 7304 | } |
| 7305 | |
| 7306 | void InstructionCodeGeneratorMIPS64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7307 | ATTRIBUTE_UNUSED) { |
| 7308 | LOG(FATAL) << "Unreachable"; |
| 7309 | } |
| 7310 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7311 | } // namespace mips64 |
| 7312 | } // namespace art |