Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [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_mips.h" |
| 18 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 19 | #include "arch/mips/asm_support_mips.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 20 | #include "arch/mips/entrypoints_direct_mips.h" |
| 21 | #include "arch/mips/instruction_set_features_mips.h" |
| 22 | #include "art_method.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 23 | #include "class_table.h" |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 24 | #include "code_generator_utils.h" |
Vladimir Marko | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 25 | #include "compiled_method.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 26 | #include "entrypoints/quick/quick_entrypoints.h" |
| 27 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| 28 | #include "gc/accounting/card_table.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 29 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 30 | #include "heap_poisoning.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 31 | #include "intrinsics.h" |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 32 | #include "intrinsics_mips.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 33 | #include "linker/linker_patch.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 34 | #include "mirror/array-inl.h" |
| 35 | #include "mirror/class-inl.h" |
| 36 | #include "offsets.h" |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 37 | #include "stack_map_stream.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 38 | #include "thread.h" |
| 39 | #include "utils/assembler.h" |
| 40 | #include "utils/mips/assembler_mips.h" |
| 41 | #include "utils/stack_checks.h" |
| 42 | |
| 43 | namespace art { |
| 44 | namespace mips { |
| 45 | |
| 46 | static constexpr int kCurrentMethodStackOffset = 0; |
| 47 | static constexpr Register kMethodRegisterArgument = A0; |
| 48 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 49 | // Flags controlling the use of thunks for Baker read barriers. |
| 50 | constexpr bool kBakerReadBarrierThunksEnableForFields = true; |
| 51 | constexpr bool kBakerReadBarrierThunksEnableForArrays = true; |
| 52 | constexpr bool kBakerReadBarrierThunksEnableForGcRoots = true; |
| 53 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 54 | Location MipsReturnLocation(DataType::Type return_type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 55 | switch (return_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 56 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 57 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 58 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 59 | case DataType::Type::kInt8: |
| 60 | case DataType::Type::kUint16: |
| 61 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 62 | case DataType::Type::kUint32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 63 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 64 | return Location::RegisterLocation(V0); |
| 65 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 66 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 67 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 68 | return Location::RegisterPairLocation(V0, V1); |
| 69 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 70 | case DataType::Type::kFloat32: |
| 71 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 72 | return Location::FpuRegisterLocation(F0); |
| 73 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 74 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 75 | return Location(); |
| 76 | } |
| 77 | UNREACHABLE(); |
| 78 | } |
| 79 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 80 | Location InvokeDexCallingConventionVisitorMIPS::GetReturnLocation(DataType::Type type) const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 81 | return MipsReturnLocation(type); |
| 82 | } |
| 83 | |
| 84 | Location InvokeDexCallingConventionVisitorMIPS::GetMethodLocation() const { |
| 85 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 86 | } |
| 87 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 88 | Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(DataType::Type type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 89 | Location next_location; |
| 90 | |
| 91 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 92 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 93 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 94 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 95 | case DataType::Type::kInt8: |
| 96 | case DataType::Type::kUint16: |
| 97 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 98 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 99 | uint32_t gp_index = gp_index_++; |
| 100 | if (gp_index < calling_convention.GetNumberOfRegisters()) { |
| 101 | next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index)); |
| 102 | } else { |
| 103 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 104 | next_location = Location::StackSlot(stack_offset); |
| 105 | } |
| 106 | break; |
| 107 | } |
| 108 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 109 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 110 | uint32_t gp_index = gp_index_; |
| 111 | gp_index_ += 2; |
| 112 | if (gp_index + 1 < calling_convention.GetNumberOfRegisters()) { |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 113 | Register reg = calling_convention.GetRegisterAt(gp_index); |
| 114 | if (reg == A1 || reg == A3) { |
| 115 | gp_index_++; // Skip A1(A3), and use A2_A3(T0_T1) instead. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 116 | gp_index++; |
| 117 | } |
| 118 | Register low_even = calling_convention.GetRegisterAt(gp_index); |
| 119 | Register high_odd = calling_convention.GetRegisterAt(gp_index + 1); |
| 120 | DCHECK_EQ(low_even + 1, high_odd); |
| 121 | next_location = Location::RegisterPairLocation(low_even, high_odd); |
| 122 | } else { |
| 123 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 124 | next_location = Location::DoubleStackSlot(stack_offset); |
| 125 | } |
| 126 | break; |
| 127 | } |
| 128 | |
| 129 | // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double |
| 130 | // will take up the even/odd pair, while floats are stored in even regs only. |
| 131 | // On 64 bit FPU, both double and float are stored in even registers only. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 132 | case DataType::Type::kFloat32: |
| 133 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 134 | uint32_t float_index = float_index_++; |
| 135 | if (float_index < calling_convention.GetNumberOfFpuRegisters()) { |
| 136 | next_location = Location::FpuRegisterLocation( |
| 137 | calling_convention.GetFpuRegisterAt(float_index)); |
| 138 | } else { |
| 139 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 140 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 141 | : Location::StackSlot(stack_offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 142 | } |
| 143 | break; |
| 144 | } |
| 145 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 146 | case DataType::Type::kUint32: |
| 147 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 148 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 149 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 150 | break; |
| 151 | } |
| 152 | |
| 153 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 154 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 155 | |
| 156 | return next_location; |
| 157 | } |
| 158 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 159 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 160 | return MipsReturnLocation(type); |
| 161 | } |
| 162 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 163 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 164 | InvokeRuntimeCallingConvention calling_convention; |
| 165 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 166 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 167 | // The reference is returned in the same register. This differs from the standard return location. |
| 168 | return caller_saves; |
| 169 | } |
| 170 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 171 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 172 | #define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 173 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 174 | |
| 175 | class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 176 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 177 | explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 178 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 179 | void EmitNativeCode(CodeGenerator* codegen) override { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 180 | LocationSummary* locations = instruction_->GetLocations(); |
| 181 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 182 | __ Bind(GetEntryLabel()); |
| 183 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 184 | // Live registers will be restored in the catch block if caught. |
| 185 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 186 | } |
| 187 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 188 | // move resolver. |
| 189 | InvokeRuntimeCallingConvention calling_convention; |
| 190 | codegen->EmitParallelMoves(locations->InAt(0), |
| 191 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 192 | DataType::Type::kInt32, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 193 | locations->InAt(1), |
| 194 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 195 | DataType::Type::kInt32); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 196 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 197 | ? kQuickThrowStringBounds |
| 198 | : kQuickThrowArrayBounds; |
| 199 | mips_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 200 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 201 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 202 | } |
| 203 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 204 | bool IsFatal() const override { return true; } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 205 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 206 | const char* GetDescription() const override { return "BoundsCheckSlowPathMIPS"; } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 207 | |
| 208 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 209 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS); |
| 210 | }; |
| 211 | |
| 212 | class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 213 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 214 | explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 215 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 216 | void EmitNativeCode(CodeGenerator* codegen) override { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 217 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 218 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 219 | mips_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 220 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 221 | } |
| 222 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 223 | bool IsFatal() const override { return true; } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 224 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 225 | const char* GetDescription() const override { return "DivZeroCheckSlowPathMIPS"; } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 226 | |
| 227 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 228 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS); |
| 229 | }; |
| 230 | |
| 231 | class LoadClassSlowPathMIPS : public SlowPathCodeMIPS { |
| 232 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 233 | LoadClassSlowPathMIPS(HLoadClass* cls, HInstruction* at) |
| 234 | : SlowPathCodeMIPS(at), cls_(cls) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 235 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 236 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 237 | } |
| 238 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 239 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 240 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 241 | Location out = locations->Out(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 242 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 243 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 244 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| 245 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 246 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 247 | __ Bind(GetEntryLabel()); |
| 248 | SaveLiveRegisters(codegen, locations); |
| 249 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 250 | InvokeRuntimeCallingConvention calling_convention; |
| 251 | if (must_resolve_type) { |
| 252 | DCHECK(IsSameDexFile(cls_->GetDexFile(), mips_codegen->GetGraph()->GetDexFile())); |
| 253 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 254 | __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_); |
Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 255 | mips_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 256 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 257 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 258 | } else { |
| 259 | DCHECK(must_do_clinit); |
| 260 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 261 | mips_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 262 | source, |
| 263 | cls_->GetType()); |
| 264 | } |
| 265 | if (must_do_clinit) { |
| 266 | mips_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 267 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | // Move the class to the desired location. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 271 | if (out.IsValid()) { |
| 272 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 273 | DataType::Type type = instruction_->GetType(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 274 | mips_codegen->MoveLocation(out, |
| 275 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 276 | type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 277 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 278 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 279 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 280 | __ B(GetExitLabel()); |
| 281 | } |
| 282 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 283 | const char* GetDescription() const override { return "LoadClassSlowPathMIPS"; } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 284 | |
| 285 | private: |
| 286 | // The class this slow path will load. |
| 287 | HLoadClass* const cls_; |
| 288 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 289 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS); |
| 290 | }; |
| 291 | |
| 292 | class LoadStringSlowPathMIPS : public SlowPathCodeMIPS { |
| 293 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 294 | explicit LoadStringSlowPathMIPS(HLoadString* instruction) |
| 295 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 296 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 297 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 298 | DCHECK(instruction_->IsLoadString()); |
| 299 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 300 | LocationSummary* locations = instruction_->GetLocations(); |
| 301 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 302 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 303 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 304 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 305 | __ Bind(GetEntryLabel()); |
| 306 | SaveLiveRegisters(codegen, locations); |
| 307 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 308 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 309 | mips_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 310 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 311 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 312 | DataType::Type type = instruction_->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 313 | mips_codegen->MoveLocation(locations->Out(), |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 314 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 315 | type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 316 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 317 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 318 | __ B(GetExitLabel()); |
| 319 | } |
| 320 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 321 | const char* GetDescription() const override { return "LoadStringSlowPathMIPS"; } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 322 | |
| 323 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 324 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS); |
| 325 | }; |
| 326 | |
| 327 | class NullCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 328 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 329 | explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 330 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 331 | void EmitNativeCode(CodeGenerator* codegen) override { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 332 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 333 | __ Bind(GetEntryLabel()); |
| 334 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 335 | // Live registers will be restored in the catch block if caught. |
| 336 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 337 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 338 | mips_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 339 | instruction_, |
| 340 | instruction_->GetDexPc(), |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 341 | this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 342 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 343 | } |
| 344 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 345 | bool IsFatal() const override { return true; } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 346 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 347 | const char* GetDescription() const override { return "NullCheckSlowPathMIPS"; } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 348 | |
| 349 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 350 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS); |
| 351 | }; |
| 352 | |
| 353 | class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 354 | public: |
| 355 | SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 356 | : SlowPathCodeMIPS(instruction), successor_(successor) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 357 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 358 | void EmitNativeCode(CodeGenerator* codegen) override { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 359 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 360 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 361 | __ Bind(GetEntryLabel()); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 362 | SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD. |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 363 | mips_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 364 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 365 | RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 366 | if (successor_ == nullptr) { |
| 367 | __ B(GetReturnLabel()); |
| 368 | } else { |
| 369 | __ B(mips_codegen->GetLabelOf(successor_)); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | MipsLabel* GetReturnLabel() { |
| 374 | DCHECK(successor_ == nullptr); |
| 375 | return &return_label_; |
| 376 | } |
| 377 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 378 | const char* GetDescription() const override { return "SuspendCheckSlowPathMIPS"; } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 379 | |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 380 | HBasicBlock* GetSuccessor() const { |
| 381 | return successor_; |
| 382 | } |
| 383 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 384 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 385 | // If not null, the block to branch to after the suspend check. |
| 386 | HBasicBlock* const successor_; |
| 387 | |
| 388 | // If `successor_` is null, the label to branch to after the suspend check. |
| 389 | MipsLabel return_label_; |
| 390 | |
| 391 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS); |
| 392 | }; |
| 393 | |
| 394 | class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 395 | public: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 396 | explicit TypeCheckSlowPathMIPS(HInstruction* instruction, bool is_fatal) |
| 397 | : SlowPathCodeMIPS(instruction), is_fatal_(is_fatal) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 398 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 399 | void EmitNativeCode(CodeGenerator* codegen) override { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 400 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 401 | uint32_t dex_pc = instruction_->GetDexPc(); |
| 402 | DCHECK(instruction_->IsCheckCast() |
| 403 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 404 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 405 | |
| 406 | __ Bind(GetEntryLabel()); |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 407 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 408 | SaveLiveRegisters(codegen, locations); |
| 409 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 410 | |
| 411 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 412 | // move resolver. |
| 413 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 414 | codegen->EmitParallelMoves(locations->InAt(0), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 415 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 416 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 417 | locations->InAt(1), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 418 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 419 | DataType::Type::kReference); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 420 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 421 | mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 422 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 423 | DataType::Type ret_type = instruction_->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 424 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 425 | mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 426 | } else { |
| 427 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 428 | mips_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 429 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 430 | } |
| 431 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 432 | if (!is_fatal_) { |
| 433 | RestoreLiveRegisters(codegen, locations); |
| 434 | __ B(GetExitLabel()); |
| 435 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 436 | } |
| 437 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 438 | const char* GetDescription() const override { return "TypeCheckSlowPathMIPS"; } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 439 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 440 | bool IsFatal() const override { return is_fatal_; } |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 441 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 442 | private: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 443 | const bool is_fatal_; |
| 444 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 445 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS); |
| 446 | }; |
| 447 | |
| 448 | class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS { |
| 449 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 450 | explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 451 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 452 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 453 | void EmitNativeCode(CodeGenerator* codegen) override { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 454 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 455 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 456 | LocationSummary* locations = instruction_->GetLocations(); |
| 457 | SaveLiveRegisters(codegen, locations); |
| 458 | InvokeRuntimeCallingConvention calling_convention; |
| 459 | __ LoadConst32(calling_convention.GetRegisterAt(0), |
| 460 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 461 | mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 462 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 463 | } |
| 464 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 465 | const char* GetDescription() const override { return "DeoptimizationSlowPathMIPS"; } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 466 | |
| 467 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 468 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS); |
| 469 | }; |
| 470 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 471 | class ArraySetSlowPathMIPS : public SlowPathCodeMIPS { |
| 472 | public: |
| 473 | explicit ArraySetSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {} |
| 474 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 475 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 476 | LocationSummary* locations = instruction_->GetLocations(); |
| 477 | __ Bind(GetEntryLabel()); |
| 478 | SaveLiveRegisters(codegen, locations); |
| 479 | |
| 480 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 481 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 482 | parallel_move.AddMove( |
| 483 | locations->InAt(0), |
| 484 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 485 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 486 | nullptr); |
| 487 | parallel_move.AddMove( |
| 488 | locations->InAt(1), |
| 489 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 490 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 491 | nullptr); |
| 492 | parallel_move.AddMove( |
| 493 | locations->InAt(2), |
| 494 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 495 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 496 | nullptr); |
| 497 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 498 | |
| 499 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 500 | mips_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 501 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 502 | RestoreLiveRegisters(codegen, locations); |
| 503 | __ B(GetExitLabel()); |
| 504 | } |
| 505 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 506 | const char* GetDescription() const override { return "ArraySetSlowPathMIPS"; } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 507 | |
| 508 | private: |
| 509 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS); |
| 510 | }; |
| 511 | |
| 512 | // Slow path marking an object reference `ref` during a read |
| 513 | // barrier. The field `obj.field` in the object `obj` holding this |
| 514 | // reference does not get updated by this slow path after marking (see |
| 515 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS below for that). |
| 516 | // |
| 517 | // This means that after the execution of this slow path, `ref` will |
| 518 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 519 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 520 | // probably still be a from-space reference (unless it gets updated by |
| 521 | // another thread, or if another thread installed another object |
| 522 | // reference (different from `ref`) in `obj.field`). |
| 523 | // |
| 524 | // If `entrypoint` is a valid location it is assumed to already be |
| 525 | // holding the entrypoint. The case where the entrypoint is passed in |
| 526 | // is for the GcRoot read barrier. |
| 527 | class ReadBarrierMarkSlowPathMIPS : public SlowPathCodeMIPS { |
| 528 | public: |
| 529 | ReadBarrierMarkSlowPathMIPS(HInstruction* instruction, |
| 530 | Location ref, |
| 531 | Location entrypoint = Location::NoLocation()) |
| 532 | : SlowPathCodeMIPS(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 533 | DCHECK(kEmitCompilerReadBarrier); |
| 534 | } |
| 535 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 536 | const char* GetDescription() const override { return "ReadBarrierMarkSlowPathMIPS"; } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 537 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 538 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 539 | LocationSummary* locations = instruction_->GetLocations(); |
| 540 | Register ref_reg = ref_.AsRegister<Register>(); |
| 541 | DCHECK(locations->CanCall()); |
| 542 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 543 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 544 | instruction_->IsStaticFieldGet() || |
| 545 | instruction_->IsArrayGet() || |
| 546 | instruction_->IsArraySet() || |
| 547 | instruction_->IsLoadClass() || |
| 548 | instruction_->IsLoadString() || |
| 549 | instruction_->IsInstanceOf() || |
| 550 | instruction_->IsCheckCast() || |
| 551 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 552 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 553 | << "Unexpected instruction in read barrier marking slow path: " |
| 554 | << instruction_->DebugName(); |
| 555 | |
| 556 | __ Bind(GetEntryLabel()); |
| 557 | // No need to save live registers; it's taken care of by the |
| 558 | // entrypoint. Also, there is no need to update the stack mask, |
| 559 | // as this runtime call will not trigger a garbage collection. |
| 560 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 561 | DCHECK((V0 <= ref_reg && ref_reg <= T7) || |
| 562 | (S2 <= ref_reg && ref_reg <= S7) || |
| 563 | (ref_reg == FP)) << ref_reg; |
| 564 | // "Compact" slow path, saving two moves. |
| 565 | // |
| 566 | // Instead of using the standard runtime calling convention (input |
| 567 | // and output in A0 and V0 respectively): |
| 568 | // |
| 569 | // A0 <- ref |
| 570 | // V0 <- ReadBarrierMark(A0) |
| 571 | // ref <- V0 |
| 572 | // |
| 573 | // we just use rX (the register containing `ref`) as input and output |
| 574 | // of a dedicated entrypoint: |
| 575 | // |
| 576 | // rX <- ReadBarrierMarkRegX(rX) |
| 577 | // |
| 578 | if (entrypoint_.IsValid()) { |
| 579 | mips_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 580 | DCHECK_EQ(entrypoint_.AsRegister<Register>(), T9); |
| 581 | __ Jalr(entrypoint_.AsRegister<Register>()); |
| 582 | __ NopIfNoReordering(); |
| 583 | } else { |
| 584 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 585 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 586 | // This runtime call does not require a stack map. |
| 587 | mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 588 | instruction_, |
| 589 | this, |
| 590 | /* direct */ false); |
| 591 | } |
| 592 | __ B(GetExitLabel()); |
| 593 | } |
| 594 | |
| 595 | private: |
| 596 | // The location (register) of the marked object reference. |
| 597 | const Location ref_; |
| 598 | |
| 599 | // The location of the entrypoint if already loaded. |
| 600 | const Location entrypoint_; |
| 601 | |
| 602 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS); |
| 603 | }; |
| 604 | |
| 605 | // Slow path marking an object reference `ref` during a read barrier, |
| 606 | // and if needed, atomically updating the field `obj.field` in the |
| 607 | // object `obj` holding this reference after marking (contrary to |
| 608 | // ReadBarrierMarkSlowPathMIPS above, which never tries to update |
| 609 | // `obj.field`). |
| 610 | // |
| 611 | // This means that after the execution of this slow path, both `ref` |
| 612 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 613 | // hold the same to-space reference (unless another thread installed |
| 614 | // another object reference (different from `ref`) in `obj.field`). |
| 615 | class ReadBarrierMarkAndUpdateFieldSlowPathMIPS : public SlowPathCodeMIPS { |
| 616 | public: |
| 617 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(HInstruction* instruction, |
| 618 | Location ref, |
| 619 | Register obj, |
| 620 | Location field_offset, |
| 621 | Register temp1) |
| 622 | : SlowPathCodeMIPS(instruction), |
| 623 | ref_(ref), |
| 624 | obj_(obj), |
| 625 | field_offset_(field_offset), |
| 626 | temp1_(temp1) { |
| 627 | DCHECK(kEmitCompilerReadBarrier); |
| 628 | } |
| 629 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 630 | const char* GetDescription() const override { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 631 | return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS"; |
| 632 | } |
| 633 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 634 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 635 | LocationSummary* locations = instruction_->GetLocations(); |
| 636 | Register ref_reg = ref_.AsRegister<Register>(); |
| 637 | DCHECK(locations->CanCall()); |
| 638 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 639 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 640 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 641 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 642 | << instruction_->DebugName(); |
| 643 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 644 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 645 | DCHECK(field_offset_.IsRegisterPair()) << field_offset_; |
| 646 | |
| 647 | __ Bind(GetEntryLabel()); |
| 648 | |
| 649 | // Save the old reference. |
| 650 | // Note that we cannot use AT or TMP to save the old reference, as those |
| 651 | // are used by the code that follows, but we need the old reference after |
| 652 | // the call to the ReadBarrierMarkRegX entry point. |
| 653 | DCHECK_NE(temp1_, AT); |
| 654 | DCHECK_NE(temp1_, TMP); |
| 655 | __ Move(temp1_, ref_reg); |
| 656 | |
| 657 | // No need to save live registers; it's taken care of by the |
| 658 | // entrypoint. Also, there is no need to update the stack mask, |
| 659 | // as this runtime call will not trigger a garbage collection. |
| 660 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 661 | DCHECK((V0 <= ref_reg && ref_reg <= T7) || |
| 662 | (S2 <= ref_reg && ref_reg <= S7) || |
| 663 | (ref_reg == FP)) << ref_reg; |
| 664 | // "Compact" slow path, saving two moves. |
| 665 | // |
| 666 | // Instead of using the standard runtime calling convention (input |
| 667 | // and output in A0 and V0 respectively): |
| 668 | // |
| 669 | // A0 <- ref |
| 670 | // V0 <- ReadBarrierMark(A0) |
| 671 | // ref <- V0 |
| 672 | // |
| 673 | // we just use rX (the register containing `ref`) as input and output |
| 674 | // of a dedicated entrypoint: |
| 675 | // |
| 676 | // rX <- ReadBarrierMarkRegX(rX) |
| 677 | // |
| 678 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 679 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 680 | // This runtime call does not require a stack map. |
| 681 | mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 682 | instruction_, |
| 683 | this, |
| 684 | /* direct */ false); |
| 685 | |
| 686 | // If the new reference is different from the old reference, |
| 687 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 688 | // |
| 689 | // Note that this field could also hold a different object, if |
| 690 | // another thread had concurrently changed it. In that case, the |
| 691 | // the compare-and-set (CAS) loop below would abort, leaving the |
| 692 | // field as-is. |
| 693 | MipsLabel done; |
| 694 | __ Beq(temp1_, ref_reg, &done); |
| 695 | |
| 696 | // Update the the holder's field atomically. This may fail if |
| 697 | // mutator updates before us, but it's OK. This is achieved |
| 698 | // using a strong compare-and-set (CAS) operation with relaxed |
| 699 | // memory synchronization ordering, where the expected value is |
| 700 | // the old reference and the desired value is the new reference. |
| 701 | |
| 702 | // Convenience aliases. |
| 703 | Register base = obj_; |
| 704 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 705 | // offset ("long offset"), of which only the low part contains |
| 706 | // data. |
| 707 | Register offset = field_offset_.AsRegisterPairLow<Register>(); |
| 708 | Register expected = temp1_; |
| 709 | Register value = ref_reg; |
| 710 | Register tmp_ptr = TMP; // Pointer to actual memory. |
| 711 | Register tmp = AT; // Value in memory. |
| 712 | |
| 713 | __ Addu(tmp_ptr, base, offset); |
| 714 | |
| 715 | if (kPoisonHeapReferences) { |
| 716 | __ PoisonHeapReference(expected); |
| 717 | // Do not poison `value` if it is the same register as |
| 718 | // `expected`, which has just been poisoned. |
| 719 | if (value != expected) { |
| 720 | __ PoisonHeapReference(value); |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | // do { |
| 725 | // tmp = [r_ptr] - expected; |
| 726 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 727 | |
| 728 | bool is_r6 = mips_codegen->GetInstructionSetFeatures().IsR6(); |
| 729 | MipsLabel loop_head, exit_loop; |
| 730 | __ Bind(&loop_head); |
| 731 | if (is_r6) { |
| 732 | __ LlR6(tmp, tmp_ptr); |
| 733 | } else { |
| 734 | __ LlR2(tmp, tmp_ptr); |
| 735 | } |
| 736 | __ Bne(tmp, expected, &exit_loop); |
| 737 | __ Move(tmp, value); |
| 738 | if (is_r6) { |
| 739 | __ ScR6(tmp, tmp_ptr); |
| 740 | } else { |
| 741 | __ ScR2(tmp, tmp_ptr); |
| 742 | } |
| 743 | __ Beqz(tmp, &loop_head); |
| 744 | __ Bind(&exit_loop); |
| 745 | |
| 746 | if (kPoisonHeapReferences) { |
| 747 | __ UnpoisonHeapReference(expected); |
| 748 | // Do not unpoison `value` if it is the same register as |
| 749 | // `expected`, which has just been unpoisoned. |
| 750 | if (value != expected) { |
| 751 | __ UnpoisonHeapReference(value); |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | __ Bind(&done); |
| 756 | __ B(GetExitLabel()); |
| 757 | } |
| 758 | |
| 759 | private: |
| 760 | // The location (register) of the marked object reference. |
| 761 | const Location ref_; |
| 762 | // The register containing the object holding the marked object reference field. |
| 763 | const Register obj_; |
| 764 | // The location of the offset of the marked reference field within `obj_`. |
| 765 | Location field_offset_; |
| 766 | |
| 767 | const Register temp1_; |
| 768 | |
| 769 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS); |
| 770 | }; |
| 771 | |
| 772 | // Slow path generating a read barrier for a heap reference. |
| 773 | class ReadBarrierForHeapReferenceSlowPathMIPS : public SlowPathCodeMIPS { |
| 774 | public: |
| 775 | ReadBarrierForHeapReferenceSlowPathMIPS(HInstruction* instruction, |
| 776 | Location out, |
| 777 | Location ref, |
| 778 | Location obj, |
| 779 | uint32_t offset, |
| 780 | Location index) |
| 781 | : SlowPathCodeMIPS(instruction), |
| 782 | out_(out), |
| 783 | ref_(ref), |
| 784 | obj_(obj), |
| 785 | offset_(offset), |
| 786 | index_(index) { |
| 787 | DCHECK(kEmitCompilerReadBarrier); |
| 788 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 789 | // has been overwritten by (or after) the heap object reference load |
| 790 | // to be instrumented, e.g.: |
| 791 | // |
| 792 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 793 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 794 | // |
| 795 | // In that case, we have lost the information about the original |
| 796 | // object, and the emitted read barrier cannot work properly. |
| 797 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 798 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 799 | } |
| 800 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 801 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 802 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 803 | LocationSummary* locations = instruction_->GetLocations(); |
| 804 | Register reg_out = out_.AsRegister<Register>(); |
| 805 | DCHECK(locations->CanCall()); |
| 806 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 807 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 808 | instruction_->IsStaticFieldGet() || |
| 809 | instruction_->IsArrayGet() || |
| 810 | instruction_->IsInstanceOf() || |
| 811 | instruction_->IsCheckCast() || |
| 812 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 813 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 814 | << instruction_->DebugName(); |
| 815 | |
| 816 | __ Bind(GetEntryLabel()); |
| 817 | SaveLiveRegisters(codegen, locations); |
| 818 | |
| 819 | // We may have to change the index's value, but as `index_` is a |
| 820 | // constant member (like other "inputs" of this slow path), |
| 821 | // introduce a copy of it, `index`. |
| 822 | Location index = index_; |
| 823 | if (index_.IsValid()) { |
| 824 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 825 | if (instruction_->IsArrayGet()) { |
| 826 | // Compute the actual memory offset and store it in `index`. |
| 827 | Register index_reg = index_.AsRegister<Register>(); |
| 828 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 829 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 830 | // We are about to change the value of `index_reg` (see the |
| 831 | // calls to art::mips::MipsAssembler::Sll and |
| 832 | // art::mips::MipsAssembler::Addiu32 below), but it has |
| 833 | // not been saved by the previous call to |
| 834 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 835 | // callee-save register -- |
| 836 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 837 | // callee-save registers, as it has been designed with the |
| 838 | // assumption that callee-save registers are supposed to be |
| 839 | // handled by the called function. So, as a callee-save |
| 840 | // register, `index_reg` _would_ eventually be saved onto |
| 841 | // the stack, but it would be too late: we would have |
| 842 | // changed its value earlier. Therefore, we manually save |
| 843 | // it here into another freely available register, |
| 844 | // `free_reg`, chosen of course among the caller-save |
| 845 | // registers (as a callee-save `free_reg` register would |
| 846 | // exhibit the same problem). |
| 847 | // |
| 848 | // Note we could have requested a temporary register from |
| 849 | // the register allocator instead; but we prefer not to, as |
| 850 | // this is a slow path, and we know we can find a |
| 851 | // caller-save register that is available. |
| 852 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 853 | __ Move(free_reg, index_reg); |
| 854 | index_reg = free_reg; |
| 855 | index = Location::RegisterLocation(index_reg); |
| 856 | } else { |
| 857 | // The initial register stored in `index_` has already been |
| 858 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 859 | // (as it is not a callee-save register), so we can freely |
| 860 | // use it. |
| 861 | } |
| 862 | // Shifting the index value contained in `index_reg` by the scale |
| 863 | // factor (2) cannot overflow in practice, as the runtime is |
| 864 | // unable to allocate object arrays with a size larger than |
| 865 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 866 | __ Sll(index_reg, index_reg, TIMES_4); |
| 867 | static_assert( |
| 868 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 869 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 870 | __ Addiu32(index_reg, index_reg, offset_); |
| 871 | } else { |
| 872 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 873 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 874 | // (as in the case of ArrayGet), as it is actually an offset |
| 875 | // to an object field within an object. |
| 876 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 877 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 878 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 879 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 880 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 881 | DCHECK_EQ(offset_, 0U); |
| 882 | DCHECK(index_.IsRegisterPair()); |
| 883 | // UnsafeGet's offset location is a register pair, the low |
| 884 | // part contains the correct offset. |
| 885 | index = index_.ToLow(); |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | // We're moving two or three locations to locations that could |
| 890 | // overlap, so we need a parallel move resolver. |
| 891 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 892 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 893 | parallel_move.AddMove(ref_, |
| 894 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 895 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 896 | nullptr); |
| 897 | parallel_move.AddMove(obj_, |
| 898 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 899 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 900 | nullptr); |
| 901 | if (index.IsValid()) { |
| 902 | parallel_move.AddMove(index, |
| 903 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 904 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 905 | nullptr); |
| 906 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 907 | } else { |
| 908 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 909 | __ LoadConst32(calling_convention.GetRegisterAt(2), offset_); |
| 910 | } |
| 911 | mips_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| 912 | instruction_, |
| 913 | instruction_->GetDexPc(), |
| 914 | this); |
| 915 | CheckEntrypointTypes< |
| 916 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 917 | mips_codegen->MoveLocation(out_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 918 | calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 919 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 920 | |
| 921 | RestoreLiveRegisters(codegen, locations); |
| 922 | __ B(GetExitLabel()); |
| 923 | } |
| 924 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 925 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathMIPS"; } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 926 | |
| 927 | private: |
| 928 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 929 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 930 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 931 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 932 | if (i != ref && |
| 933 | i != obj && |
| 934 | !codegen->IsCoreCalleeSaveRegister(i) && |
| 935 | !codegen->IsBlockedCoreRegister(i)) { |
| 936 | return static_cast<Register>(i); |
| 937 | } |
| 938 | } |
| 939 | // We shall never fail to find a free caller-save register, as |
| 940 | // there are more than two core caller-save registers on MIPS |
| 941 | // (meaning it is possible to find one which is different from |
| 942 | // `ref` and `obj`). |
| 943 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 944 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 945 | UNREACHABLE(); |
| 946 | } |
| 947 | |
| 948 | const Location out_; |
| 949 | const Location ref_; |
| 950 | const Location obj_; |
| 951 | const uint32_t offset_; |
| 952 | // An additional location containing an index to an array. |
| 953 | // Only used for HArrayGet and the UnsafeGetObject & |
| 954 | // UnsafeGetObjectVolatile intrinsics. |
| 955 | const Location index_; |
| 956 | |
| 957 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS); |
| 958 | }; |
| 959 | |
| 960 | // Slow path generating a read barrier for a GC root. |
| 961 | class ReadBarrierForRootSlowPathMIPS : public SlowPathCodeMIPS { |
| 962 | public: |
| 963 | ReadBarrierForRootSlowPathMIPS(HInstruction* instruction, Location out, Location root) |
| 964 | : SlowPathCodeMIPS(instruction), out_(out), root_(root) { |
| 965 | DCHECK(kEmitCompilerReadBarrier); |
| 966 | } |
| 967 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 968 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 969 | LocationSummary* locations = instruction_->GetLocations(); |
| 970 | Register reg_out = out_.AsRegister<Register>(); |
| 971 | DCHECK(locations->CanCall()); |
| 972 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 973 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 974 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 975 | << instruction_->DebugName(); |
| 976 | |
| 977 | __ Bind(GetEntryLabel()); |
| 978 | SaveLiveRegisters(codegen, locations); |
| 979 | |
| 980 | InvokeRuntimeCallingConvention calling_convention; |
| 981 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 982 | mips_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 983 | root_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 984 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 985 | mips_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 986 | instruction_, |
| 987 | instruction_->GetDexPc(), |
| 988 | this); |
| 989 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 990 | mips_codegen->MoveLocation(out_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 991 | calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 992 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 993 | |
| 994 | RestoreLiveRegisters(codegen, locations); |
| 995 | __ B(GetExitLabel()); |
| 996 | } |
| 997 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 998 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathMIPS"; } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 999 | |
| 1000 | private: |
| 1001 | const Location out_; |
| 1002 | const Location root_; |
| 1003 | |
| 1004 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS); |
| 1005 | }; |
| 1006 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1007 | CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1008 | const CompilerOptions& compiler_options, |
| 1009 | OptimizingCompilerStats* stats) |
| 1010 | : CodeGenerator(graph, |
| 1011 | kNumberOfCoreRegisters, |
| 1012 | kNumberOfFRegisters, |
| 1013 | kNumberOfRegisterPairs, |
| 1014 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1015 | arraysize(kCoreCalleeSaves)), |
| 1016 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1017 | arraysize(kFpuCalleeSaves)), |
| 1018 | compiler_options, |
| 1019 | stats), |
| 1020 | block_labels_(nullptr), |
| 1021 | location_builder_(graph, this), |
| 1022 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1023 | move_resolver_(graph->GetAllocator(), this), |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1024 | assembler_(graph->GetAllocator(), |
| 1025 | compiler_options.GetInstructionSetFeatures()->AsMipsInstructionSetFeatures()), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1026 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1027 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1028 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1029 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1030 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1031 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1032 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1033 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1034 | boot_image_intrinsic_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1035 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1036 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1037 | clobbered_ra_(false) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1038 | // Save RA (containing the return address) to mimic Quick. |
| 1039 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 1040 | } |
| 1041 | |
| 1042 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 1043 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1044 | #define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1045 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1046 | |
| 1047 | void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) { |
| 1048 | // Ensure that we fix up branches. |
| 1049 | __ FinalizeCode(); |
| 1050 | |
| 1051 | // Adjust native pc offsets in stack maps. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1052 | StackMapStream* stack_map_stream = GetStackMapStream(); |
| 1053 | for (size_t i = 0, num = stack_map_stream->GetNumberOfStackMaps(); i != num; ++i) { |
David Srbecky | d02b23f | 2018-05-29 23:27:22 +0100 | [diff] [blame] | 1054 | uint32_t old_position = stack_map_stream->GetStackMapNativePcOffset(i); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1055 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1056 | DCHECK_GE(new_position, old_position); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1057 | stack_map_stream->SetStackMapNativePcOffset(i, new_position); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | // Adjust pc offsets for the disassembly information. |
| 1061 | if (disasm_info_ != nullptr) { |
| 1062 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1063 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1064 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1065 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1066 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1067 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1068 | } |
| 1069 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1070 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1071 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | CodeGenerator::Finalize(allocator); |
| 1076 | } |
| 1077 | |
| 1078 | MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const { |
| 1079 | return codegen_->GetAssembler(); |
| 1080 | } |
| 1081 | |
| 1082 | void ParallelMoveResolverMIPS::EmitMove(size_t index) { |
| 1083 | DCHECK_LT(index, moves_.size()); |
| 1084 | MoveOperands* move = moves_[index]; |
| 1085 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1086 | } |
| 1087 | |
| 1088 | void ParallelMoveResolverMIPS::EmitSwap(size_t index) { |
| 1089 | DCHECK_LT(index, moves_.size()); |
| 1090 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1091 | DataType::Type type = move->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1092 | Location loc1 = move->GetDestination(); |
| 1093 | Location loc2 = move->GetSource(); |
| 1094 | |
| 1095 | DCHECK(!loc1.IsConstant()); |
| 1096 | DCHECK(!loc2.IsConstant()); |
| 1097 | |
| 1098 | if (loc1.Equals(loc2)) { |
| 1099 | return; |
| 1100 | } |
| 1101 | |
| 1102 | if (loc1.IsRegister() && loc2.IsRegister()) { |
| 1103 | // Swap 2 GPRs. |
| 1104 | Register r1 = loc1.AsRegister<Register>(); |
| 1105 | Register r2 = loc2.AsRegister<Register>(); |
| 1106 | __ Move(TMP, r2); |
| 1107 | __ Move(r2, r1); |
| 1108 | __ Move(r1, TMP); |
| 1109 | } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) { |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1110 | if (codegen_->GetGraph()->HasSIMD()) { |
| 1111 | __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(loc1)); |
| 1112 | __ MoveV(VectorRegisterFrom(loc1), VectorRegisterFrom(loc2)); |
| 1113 | __ MoveV(VectorRegisterFrom(loc2), static_cast<VectorRegister>(FTMP)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1114 | } else { |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1115 | FRegister f1 = loc1.AsFpuRegister<FRegister>(); |
| 1116 | FRegister f2 = loc2.AsFpuRegister<FRegister>(); |
| 1117 | if (type == DataType::Type::kFloat32) { |
| 1118 | __ MovS(FTMP, f2); |
| 1119 | __ MovS(f2, f1); |
| 1120 | __ MovS(f1, FTMP); |
| 1121 | } else { |
| 1122 | DCHECK_EQ(type, DataType::Type::kFloat64); |
| 1123 | __ MovD(FTMP, f2); |
| 1124 | __ MovD(f2, f1); |
| 1125 | __ MovD(f1, FTMP); |
| 1126 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1127 | } |
| 1128 | } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) || |
| 1129 | (loc1.IsFpuRegister() && loc2.IsRegister())) { |
| 1130 | // Swap FPR and GPR. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1131 | DCHECK_EQ(type, DataType::Type::kFloat32); // Can only swap a float. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1132 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1133 | : loc2.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1134 | Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1135 | __ Move(TMP, r2); |
| 1136 | __ Mfc1(r2, f1); |
| 1137 | __ Mtc1(TMP, f1); |
| 1138 | } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) { |
| 1139 | // Swap 2 GPR register pairs. |
| 1140 | Register r1 = loc1.AsRegisterPairLow<Register>(); |
| 1141 | Register r2 = loc2.AsRegisterPairLow<Register>(); |
| 1142 | __ Move(TMP, r2); |
| 1143 | __ Move(r2, r1); |
| 1144 | __ Move(r1, TMP); |
| 1145 | r1 = loc1.AsRegisterPairHigh<Register>(); |
| 1146 | r2 = loc2.AsRegisterPairHigh<Register>(); |
| 1147 | __ Move(TMP, r2); |
| 1148 | __ Move(r2, r1); |
| 1149 | __ Move(r1, TMP); |
| 1150 | } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) || |
| 1151 | (loc1.IsFpuRegister() && loc2.IsRegisterPair())) { |
| 1152 | // Swap FPR and GPR register pair. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1153 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1154 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1155 | : loc2.AsFpuRegister<FRegister>(); |
| 1156 | Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 1157 | : loc2.AsRegisterPairLow<Register>(); |
| 1158 | Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 1159 | : loc2.AsRegisterPairHigh<Register>(); |
| 1160 | // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and |
| 1161 | // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR |
| 1162 | // unpredictable and the following mfch1 will fail. |
| 1163 | __ Mfc1(TMP, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1164 | __ MoveFromFpuHigh(AT, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1165 | __ Mtc1(r2_l, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1166 | __ MoveToFpuHigh(r2_h, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1167 | __ Move(r2_l, TMP); |
| 1168 | __ Move(r2_h, AT); |
| 1169 | } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) { |
| 1170 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false); |
| 1171 | } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) { |
| 1172 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1173 | } else if (loc1.IsSIMDStackSlot() && loc2.IsSIMDStackSlot()) { |
| 1174 | ExchangeQuadSlots(loc1.GetStackIndex(), loc2.GetStackIndex()); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1175 | } else if ((loc1.IsRegister() && loc2.IsStackSlot()) || |
| 1176 | (loc1.IsStackSlot() && loc2.IsRegister())) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1177 | Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
| 1178 | intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1179 | __ Move(TMP, reg); |
| 1180 | __ LoadFromOffset(kLoadWord, reg, SP, offset); |
| 1181 | __ StoreToOffset(kStoreWord, TMP, SP, offset); |
| 1182 | } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) || |
| 1183 | (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) { |
| 1184 | Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 1185 | : loc2.AsRegisterPairLow<Register>(); |
| 1186 | Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 1187 | : loc2.AsRegisterPairHigh<Register>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1188 | intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1189 | intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize) |
| 1190 | : loc2.GetHighStackIndex(kMipsWordSize); |
| 1191 | __ Move(TMP, reg_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1192 | __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1193 | __ StoreToOffset(kStoreWord, TMP, SP, offset_l); |
David Brazdil | 04d3e87 | 2016-01-29 09:50:09 +0000 | [diff] [blame] | 1194 | __ Move(TMP, reg_h); |
| 1195 | __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h); |
| 1196 | __ StoreToOffset(kStoreWord, TMP, SP, offset_h); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1197 | } else if ((loc1.IsFpuRegister() && loc2.IsSIMDStackSlot()) || |
| 1198 | (loc1.IsSIMDStackSlot() && loc2.IsFpuRegister())) { |
| 1199 | Location fp_loc = loc1.IsFpuRegister() ? loc1 : loc2; |
| 1200 | intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex(); |
| 1201 | __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(fp_loc)); |
| 1202 | __ LoadQFromOffset(fp_loc.AsFpuRegister<FRegister>(), SP, offset); |
| 1203 | __ StoreQToOffset(FTMP, SP, offset); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1204 | } else if (loc1.IsFpuRegister() || loc2.IsFpuRegister()) { |
| 1205 | FRegister reg = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1206 | : loc2.AsFpuRegister<FRegister>(); |
| 1207 | intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1208 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1209 | __ MovS(FTMP, reg); |
| 1210 | __ LoadSFromOffset(reg, SP, offset); |
| 1211 | __ StoreSToOffset(FTMP, SP, offset); |
| 1212 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1213 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1214 | __ MovD(FTMP, reg); |
| 1215 | __ LoadDFromOffset(reg, SP, offset); |
| 1216 | __ StoreDToOffset(FTMP, SP, offset); |
| 1217 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1218 | } else { |
| 1219 | LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported"; |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | void ParallelMoveResolverMIPS::RestoreScratch(int reg) { |
| 1224 | __ Pop(static_cast<Register>(reg)); |
| 1225 | } |
| 1226 | |
| 1227 | void ParallelMoveResolverMIPS::SpillScratch(int reg) { |
| 1228 | __ Push(static_cast<Register>(reg)); |
| 1229 | } |
| 1230 | |
| 1231 | void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) { |
| 1232 | // Allocate a scratch register other than TMP, if available. |
| 1233 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 1234 | // automatically unspilled when the scratch scope object is destroyed). |
| 1235 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 1236 | // If V0 spills onto the stack, SP-relative offsets need to be adjusted. |
Chris Larsen | 715f43e | 2017-10-23 11:00:32 -0700 | [diff] [blame] | 1237 | int stack_offset = ensure_scratch.IsSpilled() ? kStackAlignment : 0; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1238 | for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) { |
| 1239 | __ LoadFromOffset(kLoadWord, |
| 1240 | Register(ensure_scratch.GetRegister()), |
| 1241 | SP, |
| 1242 | index1 + stack_offset); |
| 1243 | __ LoadFromOffset(kLoadWord, |
| 1244 | TMP, |
| 1245 | SP, |
| 1246 | index2 + stack_offset); |
| 1247 | __ StoreToOffset(kStoreWord, |
| 1248 | Register(ensure_scratch.GetRegister()), |
| 1249 | SP, |
| 1250 | index2 + stack_offset); |
| 1251 | __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset); |
| 1252 | } |
| 1253 | } |
| 1254 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1255 | void ParallelMoveResolverMIPS::ExchangeQuadSlots(int index1, int index2) { |
| 1256 | __ LoadQFromOffset(FTMP, SP, index1); |
| 1257 | __ LoadQFromOffset(FTMP2, SP, index2); |
| 1258 | __ StoreQToOffset(FTMP, SP, index2); |
| 1259 | __ StoreQToOffset(FTMP2, SP, index1); |
| 1260 | } |
| 1261 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1262 | void CodeGeneratorMIPS::ComputeSpillMask() { |
| 1263 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1264 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1265 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 1266 | // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved |
| 1267 | // registers, include the ZERO register to force alignment of FPU callee-saved registers |
| 1268 | // within the stack frame. |
| 1269 | if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) { |
| 1270 | core_spill_mask_ |= (1 << ZERO); |
| 1271 | } |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1275 | // If RA is clobbered by PC-relative operations on R2 and it's the only spilled register |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1276 | // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration() |
| 1277 | // into the path that creates a stack frame so that RA can be explicitly saved and restored. |
| 1278 | // RA can't otherwise be saved/restored when it's the only spilled register. |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1279 | return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_; |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1282 | static dwarf::Reg DWARFReg(Register reg) { |
| 1283 | return dwarf::Reg::MipsCore(static_cast<int>(reg)); |
| 1284 | } |
| 1285 | |
| 1286 | // TODO: mapping of floating-point registers to DWARF. |
| 1287 | |
| 1288 | void CodeGeneratorMIPS::GenerateFrameEntry() { |
| 1289 | __ Bind(&frame_entry_label_); |
| 1290 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1291 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
Goran Jakovljevic | feec167 | 2018-02-08 10:20:14 +0100 | [diff] [blame] | 1292 | __ Lhu(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()); |
| 1293 | __ Addiu(TMP, TMP, 1); |
| 1294 | __ Sh(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()); |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1297 | bool do_overflow_check = |
| 1298 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips) || !IsLeafMethod(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1299 | |
| 1300 | if (do_overflow_check) { |
| 1301 | __ LoadFromOffset(kLoadWord, |
| 1302 | ZERO, |
| 1303 | SP, |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1304 | -static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kMips))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1305 | RecordPcInfo(nullptr, 0); |
| 1306 | } |
| 1307 | |
| 1308 | if (HasEmptyFrame()) { |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1309 | CHECK_EQ(fpu_spill_mask_, 0u); |
| 1310 | CHECK_EQ(core_spill_mask_, 1u << RA); |
| 1311 | CHECK(!clobbered_ra_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1312 | return; |
| 1313 | } |
| 1314 | |
| 1315 | // Make sure the frame size isn't unreasonably large. |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1316 | if (GetFrameSize() > GetStackOverflowReservedBytes(InstructionSet::kMips)) { |
| 1317 | LOG(FATAL) << "Stack frame larger than " |
| 1318 | << GetStackOverflowReservedBytes(InstructionSet::kMips) << " bytes"; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | // Spill callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1322 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1323 | uint32_t ofs = GetFrameSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1324 | __ IncreaseFrameSize(ofs); |
| 1325 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1326 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 1327 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 1328 | mask ^= 1u << reg; |
| 1329 | ofs -= kMipsWordSize; |
| 1330 | // The ZERO register is only included for alignment. |
| 1331 | if (reg != ZERO) { |
| 1332 | __ StoreToOffset(kStoreWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1333 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 1334 | } |
| 1335 | } |
| 1336 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1337 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 1338 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 1339 | mask ^= 1u << reg; |
| 1340 | ofs -= kMipsDoublewordSize; |
| 1341 | __ StoreDToOffset(reg, SP, ofs); |
| 1342 | // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1343 | } |
| 1344 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1345 | // Save the current method if we need it. Note that we do not |
| 1346 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1347 | // in the SSA graph. |
| 1348 | if (RequiresCurrentMethod()) { |
| 1349 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
| 1350 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 1351 | |
| 1352 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1353 | // Initialize should deoptimize flag to 0. |
| 1354 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1355 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | void CodeGeneratorMIPS::GenerateFrameExit() { |
| 1359 | __ cfi().RememberState(); |
| 1360 | |
| 1361 | if (!HasEmptyFrame()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1362 | // Restore callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1363 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1364 | // For better instruction scheduling restore RA before other registers. |
| 1365 | uint32_t ofs = GetFrameSize(); |
| 1366 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 1367 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 1368 | mask ^= 1u << reg; |
| 1369 | ofs -= kMipsWordSize; |
| 1370 | // The ZERO register is only included for alignment. |
| 1371 | if (reg != ZERO) { |
| 1372 | __ LoadFromOffset(kLoadWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1373 | __ cfi().Restore(DWARFReg(reg)); |
| 1374 | } |
| 1375 | } |
| 1376 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1377 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 1378 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 1379 | mask ^= 1u << reg; |
| 1380 | ofs -= kMipsDoublewordSize; |
| 1381 | __ LoadDFromOffset(reg, SP, ofs); |
| 1382 | // TODO: __ cfi().Restore(DWARFReg(reg)); |
| 1383 | } |
| 1384 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1385 | size_t frame_size = GetFrameSize(); |
| 1386 | // Adjust the stack pointer in the delay slot if doing so doesn't break CFI. |
| 1387 | bool exchange = IsInt<16>(static_cast<int32_t>(frame_size)); |
| 1388 | bool reordering = __ SetReorder(false); |
| 1389 | if (exchange) { |
| 1390 | __ Jr(RA); |
| 1391 | __ DecreaseFrameSize(frame_size); // Single instruction in delay slot. |
| 1392 | } else { |
| 1393 | __ DecreaseFrameSize(frame_size); |
| 1394 | __ Jr(RA); |
| 1395 | __ Nop(); // In delay slot. |
| 1396 | } |
| 1397 | __ SetReorder(reordering); |
| 1398 | } else { |
| 1399 | __ Jr(RA); |
| 1400 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1401 | } |
| 1402 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1403 | __ cfi().RestoreState(); |
| 1404 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 1405 | } |
| 1406 | |
| 1407 | void CodeGeneratorMIPS::Bind(HBasicBlock* block) { |
| 1408 | __ Bind(GetLabelOf(block)); |
| 1409 | } |
| 1410 | |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1411 | VectorRegister VectorRegisterFrom(Location location) { |
| 1412 | DCHECK(location.IsFpuRegister()); |
| 1413 | return static_cast<VectorRegister>(location.AsFpuRegister<FRegister>()); |
| 1414 | } |
| 1415 | |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1416 | void CodeGeneratorMIPS::MoveLocation(Location destination, |
| 1417 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1418 | DataType::Type dst_type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1419 | if (source.Equals(destination)) { |
| 1420 | return; |
| 1421 | } |
| 1422 | |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1423 | if (source.IsConstant()) { |
| 1424 | MoveConstant(destination, source.GetConstant()); |
| 1425 | } else { |
| 1426 | if (destination.IsRegister()) { |
| 1427 | if (source.IsRegister()) { |
| 1428 | __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 1429 | } else if (source.IsFpuRegister()) { |
| 1430 | __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>()); |
| 1431 | } else { |
| 1432 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1433 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1434 | } |
| 1435 | } else if (destination.IsRegisterPair()) { |
| 1436 | if (source.IsRegisterPair()) { |
| 1437 | __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 1438 | __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 1439 | } else if (source.IsFpuRegister()) { |
| 1440 | Register dst_high = destination.AsRegisterPairHigh<Register>(); |
| 1441 | Register dst_low = destination.AsRegisterPairLow<Register>(); |
| 1442 | FRegister src = source.AsFpuRegister<FRegister>(); |
| 1443 | __ Mfc1(dst_low, src); |
| 1444 | __ MoveFromFpuHigh(dst_high, src); |
| 1445 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1446 | DCHECK(source.IsDoubleStackSlot()) |
| 1447 | << "Cannot move from " << source << " to " << destination; |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1448 | int32_t off = source.GetStackIndex(); |
| 1449 | Register r = destination.AsRegisterPairLow<Register>(); |
| 1450 | __ LoadFromOffset(kLoadDoubleword, r, SP, off); |
| 1451 | } |
| 1452 | } else if (destination.IsFpuRegister()) { |
| 1453 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1454 | DCHECK(!DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1455 | __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>()); |
| 1456 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1457 | DCHECK(DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1458 | FRegister dst = destination.AsFpuRegister<FRegister>(); |
| 1459 | Register src_high = source.AsRegisterPairHigh<Register>(); |
| 1460 | Register src_low = source.AsRegisterPairLow<Register>(); |
| 1461 | __ Mtc1(src_low, dst); |
| 1462 | __ MoveToFpuHigh(src_high, dst); |
| 1463 | } else if (source.IsFpuRegister()) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1464 | if (GetGraph()->HasSIMD()) { |
| 1465 | __ MoveV(VectorRegisterFrom(destination), |
| 1466 | VectorRegisterFrom(source)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1467 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1468 | if (DataType::Is64BitType(dst_type)) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1469 | __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 1470 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1471 | DCHECK_EQ(dst_type, DataType::Type::kFloat32); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1472 | __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 1473 | } |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1474 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1475 | } else if (source.IsSIMDStackSlot()) { |
| 1476 | __ LoadQFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1477 | } else if (source.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1478 | DCHECK(DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1479 | __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 1480 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1481 | DCHECK(!DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1482 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1483 | __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 1484 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1485 | } else if (destination.IsSIMDStackSlot()) { |
| 1486 | if (source.IsFpuRegister()) { |
| 1487 | __ StoreQToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex()); |
| 1488 | } else { |
| 1489 | DCHECK(source.IsSIMDStackSlot()); |
| 1490 | __ LoadQFromOffset(FTMP, SP, source.GetStackIndex()); |
| 1491 | __ StoreQToOffset(FTMP, SP, destination.GetStackIndex()); |
| 1492 | } |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1493 | } else if (destination.IsDoubleStackSlot()) { |
| 1494 | int32_t dst_offset = destination.GetStackIndex(); |
| 1495 | if (source.IsRegisterPair()) { |
| 1496 | __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, dst_offset); |
| 1497 | } else if (source.IsFpuRegister()) { |
| 1498 | __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset); |
| 1499 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1500 | DCHECK(source.IsDoubleStackSlot()) |
| 1501 | << "Cannot move from " << source << " to " << destination; |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1502 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1503 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset); |
| 1504 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4); |
| 1505 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset + 4); |
| 1506 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1507 | } else { |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1508 | DCHECK(destination.IsStackSlot()) << destination; |
| 1509 | int32_t dst_offset = destination.GetStackIndex(); |
| 1510 | if (source.IsRegister()) { |
| 1511 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, dst_offset); |
| 1512 | } else if (source.IsFpuRegister()) { |
| 1513 | __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset); |
| 1514 | } else { |
| 1515 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1516 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1517 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset); |
| 1518 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1519 | } |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) { |
| 1524 | if (c->IsIntConstant() || c->IsNullConstant()) { |
| 1525 | // Move 32 bit constant. |
| 1526 | int32_t value = GetInt32ValueOf(c); |
| 1527 | if (destination.IsRegister()) { |
| 1528 | Register dst = destination.AsRegister<Register>(); |
| 1529 | __ LoadConst32(dst, value); |
| 1530 | } else { |
| 1531 | DCHECK(destination.IsStackSlot()) |
| 1532 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1533 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1534 | } |
| 1535 | } else if (c->IsLongConstant()) { |
| 1536 | // Move 64 bit constant. |
| 1537 | int64_t value = GetInt64ValueOf(c); |
| 1538 | if (destination.IsRegisterPair()) { |
| 1539 | Register r_h = destination.AsRegisterPairHigh<Register>(); |
| 1540 | Register r_l = destination.AsRegisterPairLow<Register>(); |
| 1541 | __ LoadConst64(r_h, r_l, value); |
| 1542 | } else { |
| 1543 | DCHECK(destination.IsDoubleStackSlot()) |
| 1544 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1545 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1546 | } |
| 1547 | } else if (c->IsFloatConstant()) { |
| 1548 | // Move 32 bit float constant. |
| 1549 | int32_t value = GetInt32ValueOf(c); |
| 1550 | if (destination.IsFpuRegister()) { |
| 1551 | __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP); |
| 1552 | } else { |
| 1553 | DCHECK(destination.IsStackSlot()) |
| 1554 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1555 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1556 | } |
| 1557 | } else { |
| 1558 | // Move 64 bit double constant. |
| 1559 | DCHECK(c->IsDoubleConstant()) << c->DebugName(); |
| 1560 | int64_t value = GetInt64ValueOf(c); |
| 1561 | if (destination.IsFpuRegister()) { |
| 1562 | FRegister fd = destination.AsFpuRegister<FRegister>(); |
| 1563 | __ LoadDConst64(fd, value, TMP); |
| 1564 | } else { |
| 1565 | DCHECK(destination.IsDoubleStackSlot()) |
| 1566 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1567 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1568 | } |
| 1569 | } |
| 1570 | } |
| 1571 | |
| 1572 | void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) { |
| 1573 | DCHECK(destination.IsRegister()); |
| 1574 | Register dst = destination.AsRegister<Register>(); |
| 1575 | __ LoadConst32(dst, value); |
| 1576 | } |
| 1577 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1578 | void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1579 | if (location.IsRegister()) { |
| 1580 | locations->AddTemp(location); |
Alexey Frunze | c9e94f3 | 2015-10-26 16:11:39 -0700 | [diff] [blame] | 1581 | } else if (location.IsRegisterPair()) { |
| 1582 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1583 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1584 | } else { |
| 1585 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1586 | } |
| 1587 | } |
| 1588 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1589 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1590 | inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches( |
| 1591 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1592 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1593 | for (const PcRelativePatchInfo& info : infos) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1594 | const DexFile* dex_file = info.target_dex_file; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1595 | size_t offset_or_index = info.offset_or_index; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1596 | DCHECK(info.label.IsBound()); |
| 1597 | uint32_t literal_offset = __ GetLabelLocation(&info.label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1598 | // On R2 we use HMipsComputeBaseMethodAddress and patch relative to |
| 1599 | // the assembler's base label used for PC-relative addressing. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1600 | const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info; |
| 1601 | uint32_t pc_rel_offset = info_high.pc_rel_label.IsBound() |
| 1602 | ? __ GetLabelLocation(&info_high.pc_rel_label) |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1603 | : __ GetPcRelBaseLabelLocation(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1604 | linker_patches->push_back(Factory(literal_offset, dex_file, pc_rel_offset, offset_or_index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1605 | } |
| 1606 | } |
| 1607 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1608 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 1609 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 1610 | const DexFile* target_dex_file, |
| 1611 | uint32_t pc_insn_offset, |
| 1612 | uint32_t boot_image_offset) { |
| 1613 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 1614 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1617 | void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1618 | DCHECK(linker_patches->empty()); |
| 1619 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1620 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1621 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1622 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1623 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1624 | boot_image_string_patches_.size() + |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1625 | string_bss_entry_patches_.size() + |
| 1626 | boot_image_intrinsic_patches_.size(); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1627 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1628 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1629 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1630 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1631 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1632 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1633 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1634 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1635 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 1636 | boot_image_intrinsic_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1637 | } else { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1638 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1639 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1640 | DCHECK(boot_image_type_patches_.empty()); |
| 1641 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1642 | DCHECK(boot_image_intrinsic_patches_.empty()); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1643 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1644 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1645 | method_bss_entry_patches_, linker_patches); |
| 1646 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1647 | type_bss_entry_patches_, linker_patches); |
| 1648 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1649 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1650 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1653 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageIntrinsicPatch( |
| 1654 | uint32_t intrinsic_data, |
| 1655 | const PcRelativePatchInfo* info_high) { |
| 1656 | return NewPcRelativePatch( |
| 1657 | /* dex_file */ nullptr, intrinsic_data, info_high, &boot_image_intrinsic_patches_); |
| 1658 | } |
| 1659 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1660 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageRelRoPatch( |
| 1661 | uint32_t boot_image_offset, |
| 1662 | const PcRelativePatchInfo* info_high) { |
| 1663 | return NewPcRelativePatch( |
| 1664 | /* dex_file */ nullptr, boot_image_offset, info_high, &boot_image_method_patches_); |
| 1665 | } |
| 1666 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1667 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageMethodPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1668 | MethodReference target_method, |
| 1669 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1670 | return NewPcRelativePatch( |
| 1671 | target_method.dex_file, target_method.index, info_high, &boot_image_method_patches_); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1672 | } |
| 1673 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1674 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewMethodBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1675 | MethodReference target_method, |
| 1676 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1677 | return NewPcRelativePatch( |
| 1678 | 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] | 1679 | } |
| 1680 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1681 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageTypePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1682 | const DexFile& dex_file, |
| 1683 | dex::TypeIndex type_index, |
| 1684 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1685 | return NewPcRelativePatch(&dex_file, type_index.index_, info_high, &boot_image_type_patches_); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1686 | } |
| 1687 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1688 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewTypeBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1689 | const DexFile& dex_file, |
| 1690 | dex::TypeIndex type_index, |
| 1691 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1692 | 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] | 1693 | } |
| 1694 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1695 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageStringPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1696 | const DexFile& dex_file, |
| 1697 | dex::StringIndex string_index, |
| 1698 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1699 | return NewPcRelativePatch( |
| 1700 | &dex_file, string_index.index_, info_high, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1701 | } |
| 1702 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1703 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewStringBssEntryPatch( |
| 1704 | const DexFile& dex_file, |
| 1705 | dex::StringIndex string_index, |
| 1706 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1707 | 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] | 1708 | } |
| 1709 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1710 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1711 | const DexFile* dex_file, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1712 | uint32_t offset_or_index, |
| 1713 | const PcRelativePatchInfo* info_high, |
| 1714 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1715 | patches->emplace_back(dex_file, offset_or_index, info_high); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1716 | return &patches->back(); |
| 1717 | } |
| 1718 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1719 | Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1720 | return map->GetOrCreate( |
| 1721 | value, |
| 1722 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1723 | } |
| 1724 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1725 | Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1726 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1729 | void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high, |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1730 | Register out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1731 | Register base) { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1732 | DCHECK(!info_high->patch_info_high); |
Alexey Frunze | 6079dca | 2017-05-28 19:10:28 -0700 | [diff] [blame] | 1733 | DCHECK_NE(out, base); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1734 | bool reordering = __ SetReorder(false); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1735 | if (GetInstructionSetFeatures().IsR6()) { |
| 1736 | DCHECK_EQ(base, ZERO); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1737 | __ Bind(&info_high->label); |
| 1738 | __ Bind(&info_high->pc_rel_label); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1739 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1740 | __ Auipc(out, /* placeholder */ 0x1234); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1741 | __ SetReorder(reordering); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1742 | } else { |
| 1743 | // If base is ZERO, emit NAL to obtain the actual base. |
| 1744 | if (base == ZERO) { |
| 1745 | // Generate a dummy PC-relative call to obtain PC. |
| 1746 | __ Nal(); |
| 1747 | } |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1748 | __ Bind(&info_high->label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1749 | __ Lui(out, /* placeholder */ 0x1234); |
| 1750 | // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding |
| 1751 | // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler. |
| 1752 | if (base == ZERO) { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1753 | __ Bind(&info_high->pc_rel_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1754 | } |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1755 | __ SetReorder(reordering); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1756 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1757 | __ Addu(out, out, (base == ZERO) ? RA : base); |
| 1758 | } |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1759 | // A following instruction will add the sign-extended low half of the 32-bit |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1760 | // offset to `out` (e.g. lw, jialc, addiu). |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1761 | } |
| 1762 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1763 | void CodeGeneratorMIPS::LoadBootImageAddress(Register reg, uint32_t boot_image_reference) { |
| 1764 | if (GetCompilerOptions().IsBootImage()) { |
| 1765 | PcRelativePatchInfo* info_high = NewBootImageIntrinsicPatch(boot_image_reference); |
| 1766 | PcRelativePatchInfo* info_low = NewBootImageIntrinsicPatch(boot_image_reference, info_high); |
| 1767 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, /* base */ ZERO); |
| 1768 | __ Addiu(reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 1769 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1770 | PcRelativePatchInfo* info_high = NewBootImageRelRoPatch(boot_image_reference); |
| 1771 | PcRelativePatchInfo* info_low = NewBootImageRelRoPatch(boot_image_reference, info_high); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1772 | EmitPcRelativeAddressPlaceholderHigh(info_high, reg, /* base */ ZERO); |
| 1773 | __ Lw(reg, reg, /* placeholder */ 0x5678, &info_low->label); |
| 1774 | } else { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 1775 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1776 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1777 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1778 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1779 | __ LoadConst32(reg, dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address))); |
| 1780 | } |
| 1781 | } |
| 1782 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1783 | void CodeGeneratorMIPS::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 1784 | uint32_t boot_image_offset) { |
| 1785 | DCHECK(invoke->IsStatic()); |
| 1786 | InvokeRuntimeCallingConvention calling_convention; |
| 1787 | Register argument = calling_convention.GetRegisterAt(0); |
| 1788 | if (GetCompilerOptions().IsBootImage()) { |
| 1789 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 1790 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 1791 | MethodReference target_method = invoke->GetTargetMethod(); |
| 1792 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 1793 | PcRelativePatchInfo* info_high = NewBootImageTypePatch(*target_method.dex_file, type_idx); |
| 1794 | PcRelativePatchInfo* info_low = |
| 1795 | NewBootImageTypePatch(*target_method.dex_file, type_idx, info_high); |
| 1796 | EmitPcRelativeAddressPlaceholderHigh(info_high, argument, /* base */ ZERO); |
| 1797 | __ Addiu(argument, argument, /* placeholder */ 0x5678, &info_low->label); |
| 1798 | } else { |
| 1799 | LoadBootImageAddress(argument, boot_image_offset); |
| 1800 | } |
| 1801 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 1802 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 1803 | } |
| 1804 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1805 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootStringPatch( |
| 1806 | const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1807 | dex::StringIndex string_index, |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1808 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1809 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| 1810 | jit_string_patches_.emplace_back(dex_file, string_index.index_); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1811 | return &jit_string_patches_.back(); |
| 1812 | } |
| 1813 | |
| 1814 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootClassPatch( |
| 1815 | const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1816 | dex::TypeIndex type_index, |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1817 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1818 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| 1819 | jit_class_patches_.emplace_back(dex_file, type_index.index_); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1820 | return &jit_class_patches_.back(); |
| 1821 | } |
| 1822 | |
| 1823 | void CodeGeneratorMIPS::PatchJitRootUse(uint8_t* code, |
| 1824 | const uint8_t* roots_data, |
| 1825 | const CodeGeneratorMIPS::JitPatchInfo& info, |
| 1826 | uint64_t index_in_table) const { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1827 | uint32_t high_literal_offset = GetAssembler().GetLabelLocation(&info.high_label); |
| 1828 | uint32_t low_literal_offset = GetAssembler().GetLabelLocation(&info.low_label); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1829 | uintptr_t address = |
| 1830 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1831 | uint32_t addr32 = dchecked_integral_cast<uint32_t>(address); |
| 1832 | // lui reg, addr32_high |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1833 | DCHECK_EQ(code[high_literal_offset + 0], 0x34); |
| 1834 | DCHECK_EQ(code[high_literal_offset + 1], 0x12); |
| 1835 | DCHECK_EQ((code[high_literal_offset + 2] & 0xE0), 0x00); |
| 1836 | DCHECK_EQ(code[high_literal_offset + 3], 0x3C); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1837 | // instr reg, reg, addr32_low |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1838 | DCHECK_EQ(code[low_literal_offset + 0], 0x78); |
| 1839 | DCHECK_EQ(code[low_literal_offset + 1], 0x56); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1840 | addr32 += (addr32 & 0x8000) << 1; // Account for sign extension in "instr reg, reg, addr32_low". |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1841 | // lui reg, addr32_high |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1842 | code[high_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 16); |
| 1843 | code[high_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 24); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1844 | // instr reg, reg, addr32_low |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1845 | code[low_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 0); |
| 1846 | code[low_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 8); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | void CodeGeneratorMIPS::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1850 | for (const JitPatchInfo& info : jit_string_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1851 | StringReference string_reference(&info.target_dex_file, dex::StringIndex(info.index)); |
| 1852 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1853 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1854 | } |
| 1855 | for (const JitPatchInfo& info : jit_class_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1856 | TypeReference type_reference(&info.target_dex_file, dex::TypeIndex(info.index)); |
| 1857 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1858 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1859 | } |
| 1860 | } |
| 1861 | |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1862 | void CodeGeneratorMIPS::MarkGCCard(Register object, |
| 1863 | Register value, |
| 1864 | bool value_can_be_null) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1865 | MipsLabel done; |
| 1866 | Register card = AT; |
| 1867 | Register temp = TMP; |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1868 | if (value_can_be_null) { |
| 1869 | __ Beqz(value, &done); |
| 1870 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1871 | // Load the address of the card table into `card`. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1872 | __ LoadFromOffset(kLoadWord, |
| 1873 | card, |
| 1874 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1875 | Thread::CardTableOffset<kMipsPointerSize>().Int32Value()); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1876 | // Calculate the address of the card corresponding to `object`. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1877 | __ Srl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1878 | __ Addu(temp, card, temp); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1879 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 1880 | // `object`'s card. |
| 1881 | // |
| 1882 | // Register `card` contains the address of the card table. Note that the card |
| 1883 | // table's base is biased during its creation so that it always starts at an |
| 1884 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 1885 | // art::gc::accounting::CardTable::Create). Therefore the SB instruction |
| 1886 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 1887 | // (located at `card + object >> kCardShift`). |
| 1888 | // |
| 1889 | // This dual use of the value in register `card` (1. to calculate the location |
| 1890 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 1891 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1892 | __ Sb(card, temp, 0); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1893 | if (value_can_be_null) { |
| 1894 | __ Bind(&done); |
| 1895 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1896 | } |
| 1897 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1898 | void CodeGeneratorMIPS::SetupBlockedRegisters() const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1899 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1900 | blocked_core_registers_[ZERO] = true; |
| 1901 | blocked_core_registers_[K0] = true; |
| 1902 | blocked_core_registers_[K1] = true; |
| 1903 | blocked_core_registers_[GP] = true; |
| 1904 | blocked_core_registers_[SP] = true; |
| 1905 | blocked_core_registers_[RA] = true; |
| 1906 | |
| 1907 | // AT and TMP(T8) are used as temporary/scratch registers |
| 1908 | // (similar to how AT is used by MIPS assemblers). |
| 1909 | blocked_core_registers_[AT] = true; |
| 1910 | blocked_core_registers_[TMP] = true; |
| 1911 | blocked_fpu_registers_[FTMP] = true; |
| 1912 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1913 | if (GetInstructionSetFeatures().HasMsa()) { |
| 1914 | // To be used just for MSA instructions. |
| 1915 | blocked_fpu_registers_[FTMP2] = true; |
| 1916 | } |
| 1917 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1918 | // Reserve suspend and thread registers. |
| 1919 | blocked_core_registers_[S0] = true; |
| 1920 | blocked_core_registers_[TR] = true; |
| 1921 | |
| 1922 | // Reserve T9 for function calls |
| 1923 | blocked_core_registers_[T9] = true; |
| 1924 | |
| 1925 | // Reserve odd-numbered FPU registers. |
| 1926 | for (size_t i = 1; i < kNumberOfFRegisters; i += 2) { |
| 1927 | blocked_fpu_registers_[i] = true; |
| 1928 | } |
| 1929 | |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 1930 | if (GetGraph()->IsDebuggable()) { |
| 1931 | // Stubs do not save callee-save floating point registers. If the graph |
| 1932 | // is debuggable, we need to deal with these registers differently. For |
| 1933 | // now, just block them. |
| 1934 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1935 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1936 | } |
| 1937 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1938 | } |
| 1939 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1940 | size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1941 | __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index); |
| 1942 | return kMipsWordSize; |
| 1943 | } |
| 1944 | |
| 1945 | size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1946 | __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index); |
| 1947 | return kMipsWordSize; |
| 1948 | } |
| 1949 | |
| 1950 | size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1951 | if (GetGraph()->HasSIMD()) { |
| 1952 | __ StoreQToOffset(FRegister(reg_id), SP, stack_index); |
| 1953 | } else { |
| 1954 | __ StoreDToOffset(FRegister(reg_id), SP, stack_index); |
| 1955 | } |
| 1956 | return GetFloatingPointSpillSlotSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1960 | if (GetGraph()->HasSIMD()) { |
| 1961 | __ LoadQFromOffset(FRegister(reg_id), SP, stack_index); |
| 1962 | } else { |
| 1963 | __ LoadDFromOffset(FRegister(reg_id), SP, stack_index); |
| 1964 | } |
| 1965 | return GetFloatingPointSpillSlotSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1969 | stream << Register(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1973 | stream << FRegister(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1974 | } |
| 1975 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1976 | const MipsInstructionSetFeatures& CodeGeneratorMIPS::GetInstructionSetFeatures() const { |
| 1977 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsMipsInstructionSetFeatures(); |
| 1978 | } |
| 1979 | |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1980 | constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16; |
| 1981 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1982 | void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1983 | HInstruction* instruction, |
| 1984 | uint32_t dex_pc, |
| 1985 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1986 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1987 | GenerateInvokeRuntime(GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value(), |
| 1988 | IsDirectEntrypoint(entrypoint)); |
| 1989 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1990 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1991 | } |
| 1992 | } |
| 1993 | |
| 1994 | void CodeGeneratorMIPS::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1995 | HInstruction* instruction, |
| 1996 | SlowPathCode* slow_path, |
| 1997 | bool direct) { |
| 1998 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1999 | GenerateInvokeRuntime(entry_point_offset, direct); |
| 2000 | } |
| 2001 | |
| 2002 | void CodeGeneratorMIPS::GenerateInvokeRuntime(int32_t entry_point_offset, bool direct) { |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 2003 | bool reordering = __ SetReorder(false); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2004 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2005 | __ Jalr(T9); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2006 | if (direct) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2007 | // Reserve argument space on stack (for $a0-$a3) for |
| 2008 | // entrypoints that directly reference native implementations. |
| 2009 | // Called function may use this space to store $a0-$a3 regs. |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2010 | __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2011 | __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2012 | } else { |
| 2013 | __ Nop(); // In delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2014 | } |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 2015 | __ SetReorder(reordering); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, |
| 2019 | Register class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2020 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 2021 | const size_t status_byte_offset = |
| 2022 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 2023 | constexpr uint32_t shifted_initialized_value = |
| 2024 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 2025 | |
| 2026 | __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, status_byte_offset); |
Lena Djokic | 3177e10 | 2018-02-28 11:32:40 +0100 | [diff] [blame] | 2027 | __ Sltiu(TMP, TMP, shifted_initialized_value); |
| 2028 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2029 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 2030 | __ Sync(0); |
| 2031 | __ Bind(slow_path->GetExitLabel()); |
| 2032 | } |
| 2033 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2034 | void InstructionCodeGeneratorMIPS::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 2035 | Register temp) { |
| 2036 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 2037 | uint32_t mask = check->GetBitstringMask(); |
| 2038 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 2039 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 2040 | |
| 2041 | if (mask_bits == 16u) { |
| 2042 | // Load only the bitstring part of the status word. |
| 2043 | __ LoadFromOffset( |
| 2044 | kLoadUnsignedHalfword, temp, temp, mirror::Class::StatusOffset().Int32Value()); |
| 2045 | // Compare the bitstring bits using XOR. |
| 2046 | __ Xori(temp, temp, dchecked_integral_cast<uint16_t>(path_to_root)); |
| 2047 | } else { |
| 2048 | // /* uint32_t */ temp = temp->status_ |
| 2049 | __ LoadFromOffset(kLoadWord, temp, temp, mirror::Class::StatusOffset().Int32Value()); |
| 2050 | // Compare the bitstring bits using XOR. |
| 2051 | if (IsUint<16>(path_to_root)) { |
| 2052 | __ Xori(temp, temp, dchecked_integral_cast<uint16_t>(path_to_root)); |
| 2053 | } else { |
| 2054 | __ LoadConst32(TMP, path_to_root); |
| 2055 | __ Xor(temp, temp, TMP); |
| 2056 | } |
| 2057 | // Shift out bits that do not contribute to the comparison. |
| 2058 | __ Sll(temp, temp, 32 - mask_bits); |
| 2059 | } |
| 2060 | } |
| 2061 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2062 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 2063 | __ Sync(0); // Only stype 0 is supported. |
| 2064 | } |
| 2065 | |
| 2066 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2067 | HBasicBlock* successor) { |
| 2068 | SuspendCheckSlowPathMIPS* slow_path = |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 2069 | down_cast<SuspendCheckSlowPathMIPS*>(instruction->GetSlowPath()); |
| 2070 | |
| 2071 | if (slow_path == nullptr) { |
| 2072 | slow_path = |
| 2073 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS(instruction, successor); |
| 2074 | instruction->SetSlowPath(slow_path); |
| 2075 | codegen_->AddSlowPath(slow_path); |
| 2076 | if (successor != nullptr) { |
| 2077 | DCHECK(successor->IsLoopHeader()); |
| 2078 | } |
| 2079 | } else { |
| 2080 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2081 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2082 | |
| 2083 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2084 | TMP, |
| 2085 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2086 | Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2087 | if (successor == nullptr) { |
| 2088 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 2089 | __ Bind(slow_path->GetReturnLabel()); |
| 2090 | } else { |
| 2091 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); |
| 2092 | __ B(slow_path->GetEntryLabel()); |
| 2093 | // slow_path will return to GetLabelOf(successor). |
| 2094 | } |
| 2095 | } |
| 2096 | |
| 2097 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, |
| 2098 | CodeGeneratorMIPS* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2099 | : InstructionCodeGenerator(graph, codegen), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2100 | assembler_(codegen->GetAssembler()), |
| 2101 | codegen_(codegen) {} |
| 2102 | |
| 2103 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 2104 | DCHECK_EQ(instruction->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2105 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2106 | DataType::Type type = instruction->GetResultType(); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2107 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2108 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2109 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2110 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2111 | HInstruction* right = instruction->InputAt(1); |
| 2112 | bool can_use_imm = false; |
| 2113 | if (right->IsConstant()) { |
| 2114 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); |
| 2115 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 2116 | can_use_imm = IsUint<16>(imm); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2117 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2118 | DCHECK(instruction->IsSub() || instruction->IsAdd()); |
| 2119 | if (instruction->IsSub()) { |
| 2120 | imm = -imm; |
| 2121 | } |
| 2122 | if (isR6) { |
| 2123 | bool single_use = right->GetUses().HasExactlyOneElement(); |
| 2124 | int16_t imm_high = High16Bits(imm); |
| 2125 | int16_t imm_low = Low16Bits(imm); |
| 2126 | if (imm_low < 0) { |
| 2127 | imm_high += 1; |
| 2128 | } |
| 2129 | can_use_imm = !((imm_high != 0) && (imm_low != 0)) || single_use; |
| 2130 | } else { |
| 2131 | can_use_imm = IsInt<16>(imm); |
| 2132 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2133 | } |
| 2134 | } |
| 2135 | if (can_use_imm) |
| 2136 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 2137 | else |
| 2138 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2139 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2140 | break; |
| 2141 | } |
| 2142 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2143 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2144 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2145 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2146 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2147 | break; |
| 2148 | } |
| 2149 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2150 | case DataType::Type::kFloat32: |
| 2151 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2152 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 2153 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2154 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2155 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2156 | break; |
| 2157 | |
| 2158 | default: |
| 2159 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2164 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2165 | LocationSummary* locations = instruction->GetLocations(); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2166 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2167 | |
| 2168 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2169 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2170 | Register dst = locations->Out().AsRegister<Register>(); |
| 2171 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2172 | Location rhs_location = locations->InAt(1); |
| 2173 | |
| 2174 | Register rhs_reg = ZERO; |
| 2175 | int32_t rhs_imm = 0; |
| 2176 | bool use_imm = rhs_location.IsConstant(); |
| 2177 | if (use_imm) { |
| 2178 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2179 | } else { |
| 2180 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2181 | } |
| 2182 | |
| 2183 | if (instruction->IsAnd()) { |
| 2184 | if (use_imm) |
| 2185 | __ Andi(dst, lhs, rhs_imm); |
| 2186 | else |
| 2187 | __ And(dst, lhs, rhs_reg); |
| 2188 | } else if (instruction->IsOr()) { |
| 2189 | if (use_imm) |
| 2190 | __ Ori(dst, lhs, rhs_imm); |
| 2191 | else |
| 2192 | __ Or(dst, lhs, rhs_reg); |
| 2193 | } else if (instruction->IsXor()) { |
| 2194 | if (use_imm) |
| 2195 | __ Xori(dst, lhs, rhs_imm); |
| 2196 | else |
| 2197 | __ Xor(dst, lhs, rhs_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2198 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2199 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 2200 | if (use_imm) { |
| 2201 | if (instruction->IsSub()) { |
| 2202 | rhs_imm = -rhs_imm; |
| 2203 | } |
| 2204 | if (IsInt<16>(rhs_imm)) { |
| 2205 | __ Addiu(dst, lhs, rhs_imm); |
| 2206 | } else { |
| 2207 | DCHECK(isR6); |
| 2208 | int16_t rhs_imm_high = High16Bits(rhs_imm); |
| 2209 | int16_t rhs_imm_low = Low16Bits(rhs_imm); |
| 2210 | if (rhs_imm_low < 0) { |
| 2211 | rhs_imm_high += 1; |
| 2212 | } |
| 2213 | __ Aui(dst, lhs, rhs_imm_high); |
| 2214 | if (rhs_imm_low != 0) { |
| 2215 | __ Addiu(dst, dst, rhs_imm_low); |
| 2216 | } |
| 2217 | } |
| 2218 | } else if (instruction->IsAdd()) { |
| 2219 | __ Addu(dst, lhs, rhs_reg); |
| 2220 | } else { |
| 2221 | DCHECK(instruction->IsSub()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2222 | __ Subu(dst, lhs, rhs_reg); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2223 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2224 | } |
| 2225 | break; |
| 2226 | } |
| 2227 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2228 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2229 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2230 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2231 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2232 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2233 | Location rhs_location = locations->InAt(1); |
| 2234 | bool use_imm = rhs_location.IsConstant(); |
| 2235 | if (!use_imm) { |
| 2236 | Register rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 2237 | Register rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 2238 | if (instruction->IsAnd()) { |
| 2239 | __ And(dst_low, lhs_low, rhs_low); |
| 2240 | __ And(dst_high, lhs_high, rhs_high); |
| 2241 | } else if (instruction->IsOr()) { |
| 2242 | __ Or(dst_low, lhs_low, rhs_low); |
| 2243 | __ Or(dst_high, lhs_high, rhs_high); |
| 2244 | } else if (instruction->IsXor()) { |
| 2245 | __ Xor(dst_low, lhs_low, rhs_low); |
| 2246 | __ Xor(dst_high, lhs_high, rhs_high); |
| 2247 | } else if (instruction->IsAdd()) { |
| 2248 | if (lhs_low == rhs_low) { |
| 2249 | // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs. |
| 2250 | __ Slt(TMP, lhs_low, ZERO); |
| 2251 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2252 | } else { |
| 2253 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2254 | // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged. |
| 2255 | __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low); |
| 2256 | } |
| 2257 | __ Addu(dst_high, lhs_high, rhs_high); |
| 2258 | __ Addu(dst_high, dst_high, TMP); |
| 2259 | } else { |
| 2260 | DCHECK(instruction->IsSub()); |
| 2261 | __ Sltu(TMP, lhs_low, rhs_low); |
| 2262 | __ Subu(dst_low, lhs_low, rhs_low); |
| 2263 | __ Subu(dst_high, lhs_high, rhs_high); |
| 2264 | __ Subu(dst_high, dst_high, TMP); |
| 2265 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2266 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2267 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 2268 | if (instruction->IsOr()) { |
| 2269 | uint32_t low = Low32Bits(value); |
| 2270 | uint32_t high = High32Bits(value); |
| 2271 | if (IsUint<16>(low)) { |
| 2272 | if (dst_low != lhs_low || low != 0) { |
| 2273 | __ Ori(dst_low, lhs_low, low); |
| 2274 | } |
| 2275 | } else { |
| 2276 | __ LoadConst32(TMP, low); |
| 2277 | __ Or(dst_low, lhs_low, TMP); |
| 2278 | } |
| 2279 | if (IsUint<16>(high)) { |
| 2280 | if (dst_high != lhs_high || high != 0) { |
| 2281 | __ Ori(dst_high, lhs_high, high); |
| 2282 | } |
| 2283 | } else { |
| 2284 | if (high != low) { |
| 2285 | __ LoadConst32(TMP, high); |
| 2286 | } |
| 2287 | __ Or(dst_high, lhs_high, TMP); |
| 2288 | } |
| 2289 | } else if (instruction->IsXor()) { |
| 2290 | uint32_t low = Low32Bits(value); |
| 2291 | uint32_t high = High32Bits(value); |
| 2292 | if (IsUint<16>(low)) { |
| 2293 | if (dst_low != lhs_low || low != 0) { |
| 2294 | __ Xori(dst_low, lhs_low, low); |
| 2295 | } |
| 2296 | } else { |
| 2297 | __ LoadConst32(TMP, low); |
| 2298 | __ Xor(dst_low, lhs_low, TMP); |
| 2299 | } |
| 2300 | if (IsUint<16>(high)) { |
| 2301 | if (dst_high != lhs_high || high != 0) { |
| 2302 | __ Xori(dst_high, lhs_high, high); |
| 2303 | } |
| 2304 | } else { |
| 2305 | if (high != low) { |
| 2306 | __ LoadConst32(TMP, high); |
| 2307 | } |
| 2308 | __ Xor(dst_high, lhs_high, TMP); |
| 2309 | } |
| 2310 | } else if (instruction->IsAnd()) { |
| 2311 | uint32_t low = Low32Bits(value); |
| 2312 | uint32_t high = High32Bits(value); |
| 2313 | if (IsUint<16>(low)) { |
| 2314 | __ Andi(dst_low, lhs_low, low); |
| 2315 | } else if (low != 0xFFFFFFFF) { |
| 2316 | __ LoadConst32(TMP, low); |
| 2317 | __ And(dst_low, lhs_low, TMP); |
| 2318 | } else if (dst_low != lhs_low) { |
| 2319 | __ Move(dst_low, lhs_low); |
| 2320 | } |
| 2321 | if (IsUint<16>(high)) { |
| 2322 | __ Andi(dst_high, lhs_high, high); |
| 2323 | } else if (high != 0xFFFFFFFF) { |
| 2324 | if (high != low) { |
| 2325 | __ LoadConst32(TMP, high); |
| 2326 | } |
| 2327 | __ And(dst_high, lhs_high, TMP); |
| 2328 | } else if (dst_high != lhs_high) { |
| 2329 | __ Move(dst_high, lhs_high); |
| 2330 | } |
| 2331 | } else { |
| 2332 | if (instruction->IsSub()) { |
| 2333 | value = -value; |
| 2334 | } else { |
| 2335 | DCHECK(instruction->IsAdd()); |
| 2336 | } |
| 2337 | int32_t low = Low32Bits(value); |
| 2338 | int32_t high = High32Bits(value); |
| 2339 | if (IsInt<16>(low)) { |
| 2340 | if (dst_low != lhs_low || low != 0) { |
| 2341 | __ Addiu(dst_low, lhs_low, low); |
| 2342 | } |
| 2343 | if (low != 0) { |
| 2344 | __ Sltiu(AT, dst_low, low); |
| 2345 | } |
| 2346 | } else { |
| 2347 | __ LoadConst32(TMP, low); |
| 2348 | __ Addu(dst_low, lhs_low, TMP); |
| 2349 | __ Sltu(AT, dst_low, TMP); |
| 2350 | } |
| 2351 | if (IsInt<16>(high)) { |
| 2352 | if (dst_high != lhs_high || high != 0) { |
| 2353 | __ Addiu(dst_high, lhs_high, high); |
| 2354 | } |
| 2355 | } else { |
| 2356 | if (high != low) { |
| 2357 | __ LoadConst32(TMP, high); |
| 2358 | } |
| 2359 | __ Addu(dst_high, lhs_high, TMP); |
| 2360 | } |
| 2361 | if (low != 0) { |
| 2362 | __ Addu(dst_high, dst_high, AT); |
| 2363 | } |
| 2364 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2365 | } |
| 2366 | break; |
| 2367 | } |
| 2368 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2369 | case DataType::Type::kFloat32: |
| 2370 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2371 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2372 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2373 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2374 | if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2375 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2376 | __ AddS(dst, lhs, rhs); |
| 2377 | } else { |
| 2378 | __ AddD(dst, lhs, rhs); |
| 2379 | } |
| 2380 | } else { |
| 2381 | DCHECK(instruction->IsSub()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2382 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2383 | __ SubS(dst, lhs, rhs); |
| 2384 | } else { |
| 2385 | __ SubD(dst, lhs, rhs); |
| 2386 | } |
| 2387 | } |
| 2388 | break; |
| 2389 | } |
| 2390 | |
| 2391 | default: |
| 2392 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 2393 | } |
| 2394 | } |
| 2395 | |
| 2396 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2397 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2398 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2399 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2400 | DataType::Type type = instr->GetResultType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2401 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2402 | case DataType::Type::kInt32: |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2403 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2404 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2405 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2406 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2407 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2408 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2409 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2410 | locations->SetOut(Location::RequiresRegister()); |
| 2411 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2412 | default: |
| 2413 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2414 | } |
| 2415 | } |
| 2416 | |
| 2417 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; |
| 2418 | |
| 2419 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2420 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2421 | LocationSummary* locations = instr->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2422 | DataType::Type type = instr->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2423 | |
| 2424 | Location rhs_location = locations->InAt(1); |
| 2425 | bool use_imm = rhs_location.IsConstant(); |
| 2426 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); |
| 2427 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2428 | const uint32_t shift_mask = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2429 | (type == DataType::Type::kInt32) ? kMaxIntShiftDistance : kMaxLongShiftDistance; |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2430 | const uint32_t shift_value = rhs_imm & shift_mask; |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2431 | // Are the INS (Insert Bit Field) and ROTR instructions supported? |
| 2432 | bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2433 | |
| 2434 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2435 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2436 | Register dst = locations->Out().AsRegister<Register>(); |
| 2437 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2438 | if (use_imm) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2439 | if (shift_value == 0) { |
| 2440 | if (dst != lhs) { |
| 2441 | __ Move(dst, lhs); |
| 2442 | } |
| 2443 | } else if (instr->IsShl()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2444 | __ Sll(dst, lhs, shift_value); |
| 2445 | } else if (instr->IsShr()) { |
| 2446 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2447 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2448 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2449 | } else { |
| 2450 | if (has_ins_rotr) { |
| 2451 | __ Rotr(dst, lhs, shift_value); |
| 2452 | } else { |
| 2453 | __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask); |
| 2454 | __ Srl(dst, lhs, shift_value); |
| 2455 | __ Or(dst, dst, TMP); |
| 2456 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2457 | } |
| 2458 | } else { |
| 2459 | if (instr->IsShl()) { |
| 2460 | __ Sllv(dst, lhs, rhs_reg); |
| 2461 | } else if (instr->IsShr()) { |
| 2462 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2463 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2464 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2465 | } else { |
| 2466 | if (has_ins_rotr) { |
| 2467 | __ Rotrv(dst, lhs, rhs_reg); |
| 2468 | } else { |
| 2469 | __ Subu(TMP, ZERO, rhs_reg); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2470 | // 32-bit shift instructions use the 5 least significant bits of the shift count, so |
| 2471 | // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case |
| 2472 | // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out |
| 2473 | // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`, |
| 2474 | // IOW, the OR'd values are equal. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2475 | __ Sllv(TMP, lhs, TMP); |
| 2476 | __ Srlv(dst, lhs, rhs_reg); |
| 2477 | __ Or(dst, dst, TMP); |
| 2478 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2479 | } |
| 2480 | } |
| 2481 | break; |
| 2482 | } |
| 2483 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2484 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2485 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2486 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2487 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2488 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2489 | if (use_imm) { |
| 2490 | if (shift_value == 0) { |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 2491 | codegen_->MoveLocation(locations->Out(), locations->InAt(0), type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2492 | } else if (shift_value < kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2493 | if (has_ins_rotr) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2494 | if (instr->IsShl()) { |
| 2495 | __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2496 | __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value); |
| 2497 | __ Sll(dst_low, lhs_low, shift_value); |
| 2498 | } else if (instr->IsShr()) { |
| 2499 | __ Srl(dst_low, lhs_low, shift_value); |
| 2500 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2501 | __ Sra(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2502 | } else if (instr->IsUShr()) { |
| 2503 | __ Srl(dst_low, lhs_low, shift_value); |
| 2504 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2505 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2506 | } else { |
| 2507 | __ Srl(dst_low, lhs_low, shift_value); |
| 2508 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2509 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2510 | __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2511 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2512 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2513 | if (instr->IsShl()) { |
| 2514 | __ Sll(dst_low, lhs_low, shift_value); |
| 2515 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); |
| 2516 | __ Sll(dst_high, lhs_high, shift_value); |
| 2517 | __ Or(dst_high, dst_high, TMP); |
| 2518 | } else if (instr->IsShr()) { |
| 2519 | __ Sra(dst_high, lhs_high, shift_value); |
| 2520 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2521 | __ Srl(dst_low, lhs_low, shift_value); |
| 2522 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2523 | } else if (instr->IsUShr()) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2524 | __ Srl(dst_high, lhs_high, shift_value); |
| 2525 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2526 | __ Srl(dst_low, lhs_low, shift_value); |
| 2527 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2528 | } else { |
| 2529 | __ Srl(TMP, lhs_low, shift_value); |
| 2530 | __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value); |
| 2531 | __ Or(dst_low, dst_low, TMP); |
| 2532 | __ Srl(TMP, lhs_high, shift_value); |
| 2533 | __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2534 | __ Or(dst_high, dst_high, TMP); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2535 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2536 | } |
| 2537 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2538 | const uint32_t shift_value_high = shift_value - kMipsBitsPerWord; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2539 | if (instr->IsShl()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2540 | __ Sll(dst_high, lhs_low, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2541 | __ Move(dst_low, ZERO); |
| 2542 | } else if (instr->IsShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2543 | __ Sra(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2544 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2545 | } else if (instr->IsUShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2546 | __ Srl(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2547 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2548 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2549 | if (shift_value == kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2550 | // 64-bit rotation by 32 is just a swap. |
| 2551 | __ Move(dst_low, lhs_high); |
| 2552 | __ Move(dst_high, lhs_low); |
| 2553 | } else { |
| 2554 | if (has_ins_rotr) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2555 | __ Srl(dst_low, lhs_high, shift_value_high); |
| 2556 | __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high); |
| 2557 | __ Srl(dst_high, lhs_low, shift_value_high); |
| 2558 | __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2559 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2560 | __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high); |
| 2561 | __ Srl(dst_low, lhs_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2562 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2563 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high); |
| 2564 | __ Srl(dst_high, lhs_low, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2565 | __ Or(dst_high, dst_high, TMP); |
| 2566 | } |
| 2567 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2568 | } |
| 2569 | } |
| 2570 | } else { |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2571 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2572 | MipsLabel done; |
| 2573 | if (instr->IsShl()) { |
| 2574 | __ Sllv(dst_low, lhs_low, rhs_reg); |
| 2575 | __ Nor(AT, ZERO, rhs_reg); |
| 2576 | __ Srl(TMP, lhs_low, 1); |
| 2577 | __ Srlv(TMP, TMP, AT); |
| 2578 | __ Sllv(dst_high, lhs_high, rhs_reg); |
| 2579 | __ Or(dst_high, dst_high, TMP); |
| 2580 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2581 | if (isR6) { |
| 2582 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2583 | __ Move(dst_high, dst_low); |
| 2584 | __ Move(dst_low, ZERO); |
| 2585 | } else { |
| 2586 | __ Movn(dst_high, dst_low, TMP); |
| 2587 | __ Movn(dst_low, ZERO, TMP); |
| 2588 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2589 | } else if (instr->IsShr()) { |
| 2590 | __ Srav(dst_high, lhs_high, rhs_reg); |
| 2591 | __ Nor(AT, ZERO, rhs_reg); |
| 2592 | __ Sll(TMP, lhs_high, 1); |
| 2593 | __ Sllv(TMP, TMP, AT); |
| 2594 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2595 | __ Or(dst_low, dst_low, TMP); |
| 2596 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2597 | if (isR6) { |
| 2598 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2599 | __ Move(dst_low, dst_high); |
| 2600 | __ Sra(dst_high, dst_high, 31); |
| 2601 | } else { |
| 2602 | __ Sra(AT, dst_high, 31); |
| 2603 | __ Movn(dst_low, dst_high, TMP); |
| 2604 | __ Movn(dst_high, AT, TMP); |
| 2605 | } |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2606 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2607 | __ Srlv(dst_high, lhs_high, rhs_reg); |
| 2608 | __ Nor(AT, ZERO, rhs_reg); |
| 2609 | __ Sll(TMP, lhs_high, 1); |
| 2610 | __ Sllv(TMP, TMP, AT); |
| 2611 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2612 | __ Or(dst_low, dst_low, TMP); |
| 2613 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2614 | if (isR6) { |
| 2615 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2616 | __ Move(dst_low, dst_high); |
| 2617 | __ Move(dst_high, ZERO); |
| 2618 | } else { |
| 2619 | __ Movn(dst_low, dst_high, TMP); |
| 2620 | __ Movn(dst_high, ZERO, TMP); |
| 2621 | } |
| 2622 | } else { // Rotate. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2623 | __ Nor(AT, ZERO, rhs_reg); |
| 2624 | __ Srlv(TMP, lhs_low, rhs_reg); |
| 2625 | __ Sll(dst_low, lhs_high, 1); |
| 2626 | __ Sllv(dst_low, dst_low, AT); |
| 2627 | __ Or(dst_low, dst_low, TMP); |
| 2628 | __ Srlv(TMP, lhs_high, rhs_reg); |
| 2629 | __ Sll(dst_high, lhs_low, 1); |
| 2630 | __ Sllv(dst_high, dst_high, AT); |
| 2631 | __ Or(dst_high, dst_high, TMP); |
| 2632 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2633 | if (isR6) { |
| 2634 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2635 | __ Move(TMP, dst_high); |
| 2636 | __ Move(dst_high, dst_low); |
| 2637 | __ Move(dst_low, TMP); |
| 2638 | } else { |
| 2639 | __ Movn(AT, dst_high, TMP); |
| 2640 | __ Movn(dst_high, dst_low, TMP); |
| 2641 | __ Movn(dst_low, AT, TMP); |
| 2642 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2643 | } |
| 2644 | __ Bind(&done); |
| 2645 | } |
| 2646 | break; |
| 2647 | } |
| 2648 | |
| 2649 | default: |
| 2650 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2651 | } |
| 2652 | } |
| 2653 | |
| 2654 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { |
| 2655 | HandleBinaryOp(instruction); |
| 2656 | } |
| 2657 | |
| 2658 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { |
| 2659 | HandleBinaryOp(instruction); |
| 2660 | } |
| 2661 | |
| 2662 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { |
| 2663 | HandleBinaryOp(instruction); |
| 2664 | } |
| 2665 | |
| 2666 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { |
| 2667 | HandleBinaryOp(instruction); |
| 2668 | } |
| 2669 | |
| 2670 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2671 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2672 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2673 | kEmitCompilerReadBarrier && (type == DataType::Type::kReference); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2674 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2675 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2676 | object_array_get_with_read_barrier |
| 2677 | ? LocationSummary::kCallOnSlowPath |
| 2678 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 2679 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2680 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2681 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2682 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2683 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2684 | if (DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2685 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2686 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2687 | // The output overlaps in the case of an object array get with |
| 2688 | // read barriers enabled: we do not want the move to overwrite the |
| 2689 | // array's location, as we need it to emit the read barrier. |
| 2690 | locations->SetOut(Location::RequiresRegister(), |
| 2691 | object_array_get_with_read_barrier |
| 2692 | ? Location::kOutputOverlap |
| 2693 | : Location::kNoOutputOverlap); |
| 2694 | } |
| 2695 | // We need a temporary register for the read barrier marking slow |
| 2696 | // path in CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier. |
| 2697 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2698 | bool temp_needed = instruction->GetIndex()->IsConstant() |
| 2699 | ? !kBakerReadBarrierThunksEnableForFields |
| 2700 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2701 | if (temp_needed) { |
| 2702 | locations->AddTemp(Location::RequiresRegister()); |
| 2703 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2704 | } |
| 2705 | } |
| 2706 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2707 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS* codegen) { |
| 2708 | auto null_checker = [codegen, instruction]() { |
| 2709 | codegen->MaybeRecordImplicitNullCheck(instruction); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2710 | }; |
| 2711 | return null_checker; |
| 2712 | } |
| 2713 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2714 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 2715 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2716 | Location obj_loc = locations->InAt(0); |
| 2717 | Register obj = obj_loc.AsRegister<Register>(); |
| 2718 | Location out_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2719 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2720 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2721 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2722 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2723 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2724 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2725 | instruction->IsStringCharAt(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2726 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2727 | case DataType::Type::kBool: |
| 2728 | case DataType::Type::kUint8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2729 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2730 | if (index.IsConstant()) { |
| 2731 | size_t offset = |
| 2732 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2733 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2734 | } else { |
| 2735 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2736 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2737 | } |
| 2738 | break; |
| 2739 | } |
| 2740 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2741 | case DataType::Type::kInt8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2742 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2743 | if (index.IsConstant()) { |
| 2744 | size_t offset = |
| 2745 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2746 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2747 | } else { |
| 2748 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2749 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2750 | } |
| 2751 | break; |
| 2752 | } |
| 2753 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2754 | case DataType::Type::kUint16: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2755 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2756 | if (maybe_compressed_char_at) { |
| 2757 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2758 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
| 2759 | __ Sll(TMP, TMP, 31); // Extract compression flag into the most significant bit of TMP. |
| 2760 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2761 | "Expecting 0=compressed, 1=uncompressed"); |
| 2762 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2763 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2764 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2765 | if (maybe_compressed_char_at) { |
| 2766 | MipsLabel uncompressed_load, done; |
| 2767 | __ Bnez(TMP, &uncompressed_load); |
| 2768 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2769 | out, |
| 2770 | obj, |
| 2771 | data_offset + (const_index << TIMES_1)); |
| 2772 | __ B(&done); |
| 2773 | __ Bind(&uncompressed_load); |
| 2774 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2775 | out, |
| 2776 | obj, |
| 2777 | data_offset + (const_index << TIMES_2)); |
| 2778 | __ Bind(&done); |
| 2779 | } else { |
| 2780 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2781 | out, |
| 2782 | obj, |
| 2783 | data_offset + (const_index << TIMES_2), |
| 2784 | null_checker); |
| 2785 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2786 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2787 | Register index_reg = index.AsRegister<Register>(); |
| 2788 | if (maybe_compressed_char_at) { |
| 2789 | MipsLabel uncompressed_load, done; |
| 2790 | __ Bnez(TMP, &uncompressed_load); |
| 2791 | __ Addu(TMP, obj, index_reg); |
| 2792 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2793 | __ B(&done); |
| 2794 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2795 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2796 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2797 | __ Bind(&done); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2798 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2799 | __ Addu(TMP, index_reg, obj); |
| 2800 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2801 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2802 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2803 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
| 2804 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2805 | } |
| 2806 | break; |
| 2807 | } |
| 2808 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2809 | case DataType::Type::kInt16: { |
| 2810 | Register out = out_loc.AsRegister<Register>(); |
| 2811 | if (index.IsConstant()) { |
| 2812 | size_t offset = |
| 2813 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2814 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2815 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2816 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2817 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2818 | } else { |
| 2819 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_2, TMP); |
| 2820 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
| 2821 | } |
| 2822 | break; |
| 2823 | } |
| 2824 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2825 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2826 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2827 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2828 | if (index.IsConstant()) { |
| 2829 | size_t offset = |
| 2830 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2831 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2832 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2833 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2834 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2835 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2836 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2837 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2838 | } |
| 2839 | break; |
| 2840 | } |
| 2841 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2842 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2843 | static_assert( |
| 2844 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2845 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2846 | // /* HeapReference<Object> */ out = |
| 2847 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2848 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2849 | bool temp_needed = index.IsConstant() |
| 2850 | ? !kBakerReadBarrierThunksEnableForFields |
| 2851 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2852 | Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2853 | // Note that a potential implicit null check is handled in this |
| 2854 | // CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier call. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2855 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 2856 | if (index.IsConstant()) { |
| 2857 | // Array load with a constant index can be treated as a field load. |
| 2858 | size_t offset = |
| 2859 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2860 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2861 | out_loc, |
| 2862 | obj, |
| 2863 | offset, |
| 2864 | temp, |
| 2865 | /* needs_null_check */ false); |
| 2866 | } else { |
| 2867 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2868 | out_loc, |
| 2869 | obj, |
| 2870 | data_offset, |
| 2871 | index, |
| 2872 | temp, |
| 2873 | /* needs_null_check */ false); |
| 2874 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2875 | } else { |
| 2876 | Register out = out_loc.AsRegister<Register>(); |
| 2877 | if (index.IsConstant()) { |
| 2878 | size_t offset = |
| 2879 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2880 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
| 2881 | // If read barriers are enabled, emit read barriers other than |
| 2882 | // Baker's using a slow path (and also unpoison the loaded |
| 2883 | // reference, if heap poisoning is enabled). |
| 2884 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2885 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2886 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2887 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
| 2888 | // If read barriers are enabled, emit read barriers other than |
| 2889 | // Baker's using a slow path (and also unpoison the loaded |
| 2890 | // reference, if heap poisoning is enabled). |
| 2891 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2892 | out_loc, |
| 2893 | out_loc, |
| 2894 | obj_loc, |
| 2895 | data_offset, |
| 2896 | index); |
| 2897 | } |
| 2898 | } |
| 2899 | break; |
| 2900 | } |
| 2901 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2902 | case DataType::Type::kInt64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2903 | Register out = out_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2904 | if (index.IsConstant()) { |
| 2905 | size_t offset = |
| 2906 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2907 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2908 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2909 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2910 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2911 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2912 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2913 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2914 | } |
| 2915 | break; |
| 2916 | } |
| 2917 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2918 | case DataType::Type::kFloat32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2919 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2920 | if (index.IsConstant()) { |
| 2921 | size_t offset = |
| 2922 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2923 | __ LoadSFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2924 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2925 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2926 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2927 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2928 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2929 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2930 | } |
| 2931 | break; |
| 2932 | } |
| 2933 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2934 | case DataType::Type::kFloat64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2935 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2936 | if (index.IsConstant()) { |
| 2937 | size_t offset = |
| 2938 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2939 | __ LoadDFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2940 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2941 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2942 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2943 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2944 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2945 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2946 | } |
| 2947 | break; |
| 2948 | } |
| 2949 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2950 | case DataType::Type::kUint32: |
| 2951 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2952 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2953 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2954 | UNREACHABLE(); |
| 2955 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2956 | } |
| 2957 | |
| 2958 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2959 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2960 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2961 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2962 | } |
| 2963 | |
| 2964 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 2965 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2966 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2967 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2968 | Register out = locations->Out().AsRegister<Register>(); |
| 2969 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2970 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2971 | // Mask out compression flag from String's array length. |
| 2972 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2973 | __ Srl(out, out, 1u); |
| 2974 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2975 | } |
| 2976 | |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2977 | Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2978 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2979 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2980 | : Location::RequiresRegister(); |
| 2981 | } |
| 2982 | |
| 2983 | Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2984 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2985 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2986 | // but we should only prefer this if the constant has a single use. |
| 2987 | if (instruction->IsConstant() && |
| 2988 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2989 | instruction->GetUses().HasExactlyOneElement())) { |
| 2990 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2991 | // Otherwise fall through and require an FPU register for the constant. |
| 2992 | } |
| 2993 | return Location::RequiresFpuRegister(); |
| 2994 | } |
| 2995 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2996 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2997 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2998 | |
| 2999 | bool needs_write_barrier = |
| 3000 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 3001 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 3002 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3003 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3004 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3005 | may_need_runtime_call_for_type_check ? |
| 3006 | LocationSummary::kCallOnSlowPath : |
| 3007 | LocationSummary::kNoCall); |
| 3008 | |
| 3009 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3010 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3011 | if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3012 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3013 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3014 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 3015 | } |
| 3016 | if (needs_write_barrier) { |
| 3017 | // Temporary register for the write barrier. |
| 3018 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3019 | } |
| 3020 | } |
| 3021 | |
| 3022 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { |
| 3023 | LocationSummary* locations = instruction->GetLocations(); |
| 3024 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 3025 | Location index = locations->InAt(1); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3026 | Location value_location = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3027 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3028 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3029 | bool needs_write_barrier = |
| 3030 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 3031 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3032 | Register base_reg = index.IsConstant() ? obj : TMP; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3033 | |
| 3034 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3035 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3036 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3037 | case DataType::Type::kInt8: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3038 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3039 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3040 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3041 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3042 | __ Addu(base_reg, obj, index.AsRegister<Register>()); |
| 3043 | } |
| 3044 | if (value_location.IsConstant()) { |
| 3045 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3046 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 3047 | } else { |
| 3048 | Register value = value_location.AsRegister<Register>(); |
| 3049 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3050 | } |
| 3051 | break; |
| 3052 | } |
| 3053 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3054 | case DataType::Type::kUint16: |
| 3055 | case DataType::Type::kInt16: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3056 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3057 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3058 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3059 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3060 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3061 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3062 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_2, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3063 | } |
| 3064 | if (value_location.IsConstant()) { |
| 3065 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3066 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 3067 | } else { |
| 3068 | Register value = value_location.AsRegister<Register>(); |
| 3069 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3070 | } |
| 3071 | break; |
| 3072 | } |
| 3073 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3074 | case DataType::Type::kInt32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3075 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3076 | if (index.IsConstant()) { |
| 3077 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3078 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3079 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3080 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3081 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3082 | } |
| 3083 | if (value_location.IsConstant()) { |
| 3084 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3085 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 3086 | } else { |
| 3087 | Register value = value_location.AsRegister<Register>(); |
| 3088 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 3089 | } |
| 3090 | break; |
| 3091 | } |
| 3092 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3093 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3094 | if (value_location.IsConstant()) { |
| 3095 | // Just setting null. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3096 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3097 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3098 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3099 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3100 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3101 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3102 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3103 | DCHECK_EQ(value, 0); |
| 3104 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 3105 | DCHECK(!needs_write_barrier); |
| 3106 | DCHECK(!may_need_runtime_call_for_type_check); |
| 3107 | break; |
| 3108 | } |
| 3109 | |
| 3110 | DCHECK(needs_write_barrier); |
| 3111 | Register value = value_location.AsRegister<Register>(); |
| 3112 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 3113 | Register temp2 = TMP; // Doesn't need to survive slow path. |
| 3114 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3115 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3116 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3117 | MipsLabel done; |
| 3118 | SlowPathCodeMIPS* slow_path = nullptr; |
| 3119 | |
| 3120 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3121 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS(instruction); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3122 | codegen_->AddSlowPath(slow_path); |
| 3123 | if (instruction->GetValueCanBeNull()) { |
| 3124 | MipsLabel non_zero; |
| 3125 | __ Bnez(value, &non_zero); |
| 3126 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3127 | if (index.IsConstant()) { |
| 3128 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3129 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3130 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 3131 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3132 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 3133 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3134 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 3135 | __ B(&done); |
| 3136 | __ Bind(&non_zero); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3137 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3138 | |
| 3139 | // Note that when read barriers are enabled, the type checks |
| 3140 | // are performed without read barriers. This is fine, even in |
| 3141 | // the case where a class object is in the from-space after |
| 3142 | // the flip, as a comparison involving such a type would not |
| 3143 | // produce a false positive; it may of course produce a false |
| 3144 | // negative, in which case we would take the ArraySet slow |
| 3145 | // path. |
| 3146 | |
| 3147 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 3148 | __ LoadFromOffset(kLoadWord, temp1, obj, class_offset, null_checker); |
| 3149 | __ MaybeUnpoisonHeapReference(temp1); |
| 3150 | |
| 3151 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 3152 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 3153 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3154 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 3155 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 3156 | // nor `temp2`, as we are comparing two poisoned references. |
| 3157 | |
| 3158 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3159 | MipsLabel do_put; |
| 3160 | __ Beq(temp1, temp2, &do_put); |
| 3161 | // If heap poisoning is enabled, the `temp1` reference has |
| 3162 | // not been unpoisoned yet; unpoison it now. |
| 3163 | __ MaybeUnpoisonHeapReference(temp1); |
| 3164 | |
| 3165 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 3166 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 3167 | // If heap poisoning is enabled, no need to unpoison |
| 3168 | // `temp1`, as we are comparing against null below. |
| 3169 | __ Bnez(temp1, slow_path->GetEntryLabel()); |
| 3170 | __ Bind(&do_put); |
| 3171 | } else { |
| 3172 | __ Bne(temp1, temp2, slow_path->GetEntryLabel()); |
| 3173 | } |
| 3174 | } |
| 3175 | |
| 3176 | Register source = value; |
| 3177 | if (kPoisonHeapReferences) { |
| 3178 | // Note that in the case where `value` is a null reference, |
| 3179 | // we do not enter this block, as a null reference does not |
| 3180 | // need poisoning. |
| 3181 | __ Move(temp1, value); |
| 3182 | __ PoisonHeapReference(temp1); |
| 3183 | source = temp1; |
| 3184 | } |
| 3185 | |
| 3186 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3187 | if (index.IsConstant()) { |
| 3188 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3189 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3190 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3191 | } |
| 3192 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 3193 | |
| 3194 | if (!may_need_runtime_call_for_type_check) { |
| 3195 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3196 | } |
| 3197 | |
| 3198 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 3199 | |
| 3200 | if (done.IsLinked()) { |
| 3201 | __ Bind(&done); |
| 3202 | } |
| 3203 | |
| 3204 | if (slow_path != nullptr) { |
| 3205 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3206 | } |
| 3207 | break; |
| 3208 | } |
| 3209 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3210 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3211 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3212 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3213 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3214 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3215 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3216 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3217 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3218 | } |
| 3219 | if (value_location.IsConstant()) { |
| 3220 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3221 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3222 | } else { |
| 3223 | Register value = value_location.AsRegisterPairLow<Register>(); |
| 3224 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3225 | } |
| 3226 | break; |
| 3227 | } |
| 3228 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3229 | case DataType::Type::kFloat32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3230 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3231 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3232 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3233 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3234 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3235 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3236 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3237 | } |
| 3238 | if (value_location.IsConstant()) { |
| 3239 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3240 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 3241 | } else { |
| 3242 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3243 | __ StoreSToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3244 | } |
| 3245 | break; |
| 3246 | } |
| 3247 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3248 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3249 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3250 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3251 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3252 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3253 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3254 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3255 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3256 | } |
| 3257 | if (value_location.IsConstant()) { |
| 3258 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3259 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3260 | } else { |
| 3261 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3262 | __ StoreDToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3263 | } |
| 3264 | break; |
| 3265 | } |
| 3266 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 3267 | case DataType::Type::kUint32: |
| 3268 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3269 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3270 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 3271 | UNREACHABLE(); |
| 3272 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3273 | } |
| 3274 | |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3275 | void LocationsBuilderMIPS::VisitIntermediateArrayAddressIndex( |
| 3276 | HIntermediateArrayAddressIndex* instruction) { |
| 3277 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3278 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3279 | |
| 3280 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 3281 | |
| 3282 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3283 | locations->SetInAt(1, Location::ConstantLocation(shift)); |
| 3284 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3285 | } |
| 3286 | |
| 3287 | void InstructionCodeGeneratorMIPS::VisitIntermediateArrayAddressIndex( |
| 3288 | HIntermediateArrayAddressIndex* instruction) { |
| 3289 | LocationSummary* locations = instruction->GetLocations(); |
| 3290 | Register index_reg = locations->InAt(0).AsRegister<Register>(); |
| 3291 | uint32_t shift = instruction->GetShift()->AsIntConstant()->GetValue(); |
| 3292 | __ Sll(locations->Out().AsRegister<Register>(), index_reg, shift); |
| 3293 | } |
| 3294 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3295 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3296 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3297 | InvokeRuntimeCallingConvention calling_convention; |
| 3298 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3299 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3300 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3301 | |
| 3302 | HInstruction* index = instruction->InputAt(0); |
| 3303 | HInstruction* length = instruction->InputAt(1); |
| 3304 | |
| 3305 | bool const_index = false; |
| 3306 | bool const_length = false; |
| 3307 | |
| 3308 | if (index->IsConstant()) { |
| 3309 | if (length->IsConstant()) { |
| 3310 | const_index = true; |
| 3311 | const_length = true; |
| 3312 | } else { |
| 3313 | int32_t index_value = index->AsIntConstant()->GetValue(); |
| 3314 | if (index_value < 0 || IsInt<16>(index_value + 1)) { |
| 3315 | const_index = true; |
| 3316 | } |
| 3317 | } |
| 3318 | } else if (length->IsConstant()) { |
| 3319 | int32_t length_value = length->AsIntConstant()->GetValue(); |
| 3320 | if (IsUint<15>(length_value)) { |
| 3321 | const_length = true; |
| 3322 | } |
| 3323 | } |
| 3324 | |
| 3325 | locations->SetInAt(0, const_index |
| 3326 | ? Location::ConstantLocation(index->AsConstant()) |
| 3327 | : Location::RequiresRegister()); |
| 3328 | locations->SetInAt(1, const_length |
| 3329 | ? Location::ConstantLocation(length->AsConstant()) |
| 3330 | : Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3331 | } |
| 3332 | |
| 3333 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 3334 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3335 | Location index_loc = locations->InAt(0); |
| 3336 | Location length_loc = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3337 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3338 | if (length_loc.IsConstant()) { |
| 3339 | int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3340 | if (index_loc.IsConstant()) { |
| 3341 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3342 | if (index < 0 || index >= length) { |
| 3343 | BoundsCheckSlowPathMIPS* slow_path = |
| 3344 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3345 | codegen_->AddSlowPath(slow_path); |
| 3346 | __ B(slow_path->GetEntryLabel()); |
| 3347 | } else { |
| 3348 | // Nothing to be done. |
| 3349 | } |
| 3350 | return; |
| 3351 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3352 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3353 | BoundsCheckSlowPathMIPS* slow_path = |
| 3354 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3355 | codegen_->AddSlowPath(slow_path); |
| 3356 | Register index = index_loc.AsRegister<Register>(); |
| 3357 | if (length == 0) { |
| 3358 | __ B(slow_path->GetEntryLabel()); |
| 3359 | } else if (length == 1) { |
| 3360 | __ Bnez(index, slow_path->GetEntryLabel()); |
| 3361 | } else { |
| 3362 | DCHECK(IsUint<15>(length)) << length; |
| 3363 | __ Sltiu(TMP, index, length); |
| 3364 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3365 | } |
| 3366 | } else { |
| 3367 | Register length = length_loc.AsRegister<Register>(); |
| 3368 | BoundsCheckSlowPathMIPS* slow_path = |
| 3369 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3370 | codegen_->AddSlowPath(slow_path); |
| 3371 | if (index_loc.IsConstant()) { |
| 3372 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3373 | if (index < 0) { |
| 3374 | __ B(slow_path->GetEntryLabel()); |
| 3375 | } else if (index == 0) { |
| 3376 | __ Blez(length, slow_path->GetEntryLabel()); |
| 3377 | } else { |
| 3378 | DCHECK(IsInt<16>(index + 1)) << index; |
| 3379 | __ Sltiu(TMP, length, index + 1); |
| 3380 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 3381 | } |
| 3382 | } else { |
| 3383 | Register index = index_loc.AsRegister<Register>(); |
| 3384 | __ Bgeu(index, length, slow_path->GetEntryLabel()); |
| 3385 | } |
| 3386 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3387 | } |
| 3388 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3389 | // Temp is used for read barrier. |
| 3390 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3391 | if (kEmitCompilerReadBarrier && |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 3392 | !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) && |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3393 | (kUseBakerReadBarrier || |
| 3394 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3395 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3396 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3397 | return 1; |
| 3398 | } |
| 3399 | return 0; |
| 3400 | } |
| 3401 | |
| 3402 | // Extra temp is used for read barrier. |
| 3403 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3404 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 3405 | } |
| 3406 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3407 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3408 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 3409 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3410 | LocationSummary* locations = |
| 3411 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3412 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3413 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3414 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3415 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3416 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3417 | } else { |
| 3418 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3419 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3420 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3421 | } |
| 3422 | |
| 3423 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3424 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3425 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3426 | Location obj_loc = locations->InAt(0); |
| 3427 | Register obj = obj_loc.AsRegister<Register>(); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3428 | Location cls = locations->InAt(1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3429 | Location temp_loc = locations->GetTemp(0); |
| 3430 | Register temp = temp_loc.AsRegister<Register>(); |
| 3431 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 3432 | DCHECK_LE(num_temps, 2u); |
| 3433 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3434 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3435 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3436 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3437 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 3438 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 3439 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 3440 | const uint32_t object_array_data_offset = |
| 3441 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 3442 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3443 | |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 3444 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3445 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3446 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 3447 | instruction, is_type_check_slow_path_fatal); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3448 | codegen_->AddSlowPath(slow_path); |
| 3449 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3450 | // Avoid this check if we know `obj` is not null. |
| 3451 | if (instruction->MustDoNullCheck()) { |
| 3452 | __ Beqz(obj, &done); |
| 3453 | } |
| 3454 | |
| 3455 | switch (type_check_kind) { |
| 3456 | case TypeCheckKind::kExactCheck: |
| 3457 | case TypeCheckKind::kArrayCheck: { |
| 3458 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3459 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3460 | temp_loc, |
| 3461 | obj_loc, |
| 3462 | class_offset, |
| 3463 | maybe_temp2_loc, |
| 3464 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3465 | // Jump to slow path for throwing the exception or doing a |
| 3466 | // more involved array check. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3467 | __ Bne(temp, cls.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3468 | break; |
| 3469 | } |
| 3470 | |
| 3471 | case TypeCheckKind::kAbstractClassCheck: { |
| 3472 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3473 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3474 | temp_loc, |
| 3475 | obj_loc, |
| 3476 | class_offset, |
| 3477 | maybe_temp2_loc, |
| 3478 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3479 | // If the class is abstract, we eagerly fetch the super class of the |
| 3480 | // object to avoid doing a comparison we know will fail. |
| 3481 | MipsLabel loop; |
| 3482 | __ Bind(&loop); |
| 3483 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3484 | GenerateReferenceLoadOneRegister(instruction, |
| 3485 | temp_loc, |
| 3486 | super_offset, |
| 3487 | maybe_temp2_loc, |
| 3488 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3489 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3490 | // exception. |
| 3491 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3492 | // Otherwise, compare the classes. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3493 | __ Bne(temp, cls.AsRegister<Register>(), &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3494 | break; |
| 3495 | } |
| 3496 | |
| 3497 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3498 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3499 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3500 | temp_loc, |
| 3501 | obj_loc, |
| 3502 | class_offset, |
| 3503 | maybe_temp2_loc, |
| 3504 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3505 | // Walk over the class hierarchy to find a match. |
| 3506 | MipsLabel loop; |
| 3507 | __ Bind(&loop); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3508 | __ Beq(temp, cls.AsRegister<Register>(), &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3509 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3510 | GenerateReferenceLoadOneRegister(instruction, |
| 3511 | temp_loc, |
| 3512 | super_offset, |
| 3513 | maybe_temp2_loc, |
| 3514 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3515 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3516 | // exception. Otherwise, jump to the beginning of the loop. |
| 3517 | __ Bnez(temp, &loop); |
| 3518 | __ B(slow_path->GetEntryLabel()); |
| 3519 | break; |
| 3520 | } |
| 3521 | |
| 3522 | case TypeCheckKind::kArrayObjectCheck: { |
| 3523 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3524 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3525 | temp_loc, |
| 3526 | obj_loc, |
| 3527 | class_offset, |
| 3528 | maybe_temp2_loc, |
| 3529 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3530 | // Do an exact check. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3531 | __ Beq(temp, cls.AsRegister<Register>(), &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3532 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 3533 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3534 | GenerateReferenceLoadOneRegister(instruction, |
| 3535 | temp_loc, |
| 3536 | component_offset, |
| 3537 | maybe_temp2_loc, |
| 3538 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3539 | // If the component type is null, jump to the slow path to throw the exception. |
| 3540 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3541 | // Otherwise, the object is indeed an array, further check that this component |
| 3542 | // type is not a primitive type. |
| 3543 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 3544 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3545 | __ Bnez(temp, slow_path->GetEntryLabel()); |
| 3546 | break; |
| 3547 | } |
| 3548 | |
| 3549 | case TypeCheckKind::kUnresolvedCheck: |
| 3550 | // We always go into the type check slow path for the unresolved check case. |
| 3551 | // We cannot directly call the CheckCast runtime entry point |
| 3552 | // without resorting to a type checking slow path here (i.e. by |
| 3553 | // calling InvokeRuntime directly), as it would require to |
| 3554 | // assign fixed registers for the inputs of this HInstanceOf |
| 3555 | // instruction (following the runtime calling convention), which |
| 3556 | // might be cluttered by the potential first read barrier |
| 3557 | // emission at the beginning of this method. |
| 3558 | __ B(slow_path->GetEntryLabel()); |
| 3559 | break; |
| 3560 | |
| 3561 | case TypeCheckKind::kInterfaceCheck: { |
| 3562 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 3563 | // positives by doing this. |
| 3564 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3565 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3566 | temp_loc, |
| 3567 | obj_loc, |
| 3568 | class_offset, |
| 3569 | maybe_temp2_loc, |
| 3570 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3571 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3572 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3573 | temp_loc, |
| 3574 | temp_loc, |
| 3575 | iftable_offset, |
| 3576 | maybe_temp2_loc, |
| 3577 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3578 | // Iftable is never null. |
| 3579 | __ Lw(TMP, temp, array_length_offset); |
| 3580 | // Loop through the iftable and check if any class matches. |
| 3581 | MipsLabel loop; |
| 3582 | __ Bind(&loop); |
| 3583 | __ Addiu(temp, temp, 2 * kHeapReferenceSize); // Possibly in delay slot on R2. |
| 3584 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3585 | __ Lw(AT, temp, object_array_data_offset - 2 * kHeapReferenceSize); |
| 3586 | __ MaybeUnpoisonHeapReference(AT); |
| 3587 | // Go to next interface. |
| 3588 | __ Addiu(TMP, TMP, -2); |
| 3589 | // Compare the classes and continue the loop if they do not match. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3590 | __ Bne(AT, cls.AsRegister<Register>(), &loop); |
| 3591 | break; |
| 3592 | } |
| 3593 | |
| 3594 | case TypeCheckKind::kBitstringCheck: { |
| 3595 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3596 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3597 | temp_loc, |
| 3598 | obj_loc, |
| 3599 | class_offset, |
| 3600 | maybe_temp2_loc, |
| 3601 | kWithoutReadBarrier); |
| 3602 | |
| 3603 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 3604 | __ Bnez(temp, slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3605 | break; |
| 3606 | } |
| 3607 | } |
| 3608 | |
| 3609 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3610 | __ Bind(slow_path->GetExitLabel()); |
| 3611 | } |
| 3612 | |
| 3613 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3614 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3615 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3616 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3617 | if (check->HasUses()) { |
| 3618 | locations->SetOut(Location::SameAsFirstInput()); |
| 3619 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 3620 | // Rely on the type initialization to save everything we need. |
| 3621 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3622 | } |
| 3623 | |
| 3624 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3625 | // We assume the class is not null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 3626 | SlowPathCodeMIPS* slow_path = |
| 3627 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS(check->GetLoadClass(), check); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3628 | codegen_->AddSlowPath(slow_path); |
| 3629 | GenerateClassInitializationCheck(slow_path, |
| 3630 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| 3631 | } |
| 3632 | |
| 3633 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3634 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3635 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3636 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3637 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3638 | |
| 3639 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3640 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3641 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3642 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3643 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3644 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3645 | case DataType::Type::kInt32: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3646 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3647 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3648 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3649 | break; |
| 3650 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3651 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3652 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3653 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3654 | // Output overlaps because it is written before doing the low comparison. |
| 3655 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3656 | break; |
| 3657 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3658 | case DataType::Type::kFloat32: |
| 3659 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3660 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3661 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3662 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3663 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3664 | |
| 3665 | default: |
| 3666 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3667 | } |
| 3668 | } |
| 3669 | |
| 3670 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { |
| 3671 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3672 | Register res = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3673 | DataType::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3674 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3675 | |
| 3676 | // 0 if: left == right |
| 3677 | // 1 if: left > right |
| 3678 | // -1 if: left < right |
| 3679 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3680 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3681 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3682 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3683 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3684 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3685 | case DataType::Type::kInt32: { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3686 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3687 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 3688 | __ Slt(TMP, lhs, rhs); |
| 3689 | __ Slt(res, rhs, lhs); |
| 3690 | __ Subu(res, res, TMP); |
| 3691 | break; |
| 3692 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3693 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3694 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3695 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3696 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3697 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 3698 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 3699 | // TODO: more efficient (direct) comparison with a constant. |
| 3700 | __ Slt(TMP, lhs_high, rhs_high); |
| 3701 | __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt. |
| 3702 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3703 | __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal. |
| 3704 | __ Sltu(TMP, lhs_low, rhs_low); |
| 3705 | __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt. |
| 3706 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3707 | __ Bind(&done); |
| 3708 | break; |
| 3709 | } |
| 3710 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3711 | case DataType::Type::kFloat32: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3712 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3713 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3714 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3715 | MipsLabel done; |
| 3716 | if (isR6) { |
| 3717 | __ CmpEqS(FTMP, lhs, rhs); |
| 3718 | __ LoadConst32(res, 0); |
| 3719 | __ Bc1nez(FTMP, &done); |
| 3720 | if (gt_bias) { |
| 3721 | __ CmpLtS(FTMP, lhs, rhs); |
| 3722 | __ LoadConst32(res, -1); |
| 3723 | __ Bc1nez(FTMP, &done); |
| 3724 | __ LoadConst32(res, 1); |
| 3725 | } else { |
| 3726 | __ CmpLtS(FTMP, rhs, lhs); |
| 3727 | __ LoadConst32(res, 1); |
| 3728 | __ Bc1nez(FTMP, &done); |
| 3729 | __ LoadConst32(res, -1); |
| 3730 | } |
| 3731 | } else { |
| 3732 | if (gt_bias) { |
| 3733 | __ ColtS(0, lhs, rhs); |
| 3734 | __ LoadConst32(res, -1); |
| 3735 | __ Bc1t(0, &done); |
| 3736 | __ CeqS(0, lhs, rhs); |
| 3737 | __ LoadConst32(res, 1); |
| 3738 | __ Movt(res, ZERO, 0); |
| 3739 | } else { |
| 3740 | __ ColtS(0, rhs, lhs); |
| 3741 | __ LoadConst32(res, 1); |
| 3742 | __ Bc1t(0, &done); |
| 3743 | __ CeqS(0, lhs, rhs); |
| 3744 | __ LoadConst32(res, -1); |
| 3745 | __ Movt(res, ZERO, 0); |
| 3746 | } |
| 3747 | } |
| 3748 | __ Bind(&done); |
| 3749 | break; |
| 3750 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3751 | case DataType::Type::kFloat64: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3752 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3753 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3754 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3755 | MipsLabel done; |
| 3756 | if (isR6) { |
| 3757 | __ CmpEqD(FTMP, lhs, rhs); |
| 3758 | __ LoadConst32(res, 0); |
| 3759 | __ Bc1nez(FTMP, &done); |
| 3760 | if (gt_bias) { |
| 3761 | __ CmpLtD(FTMP, lhs, rhs); |
| 3762 | __ LoadConst32(res, -1); |
| 3763 | __ Bc1nez(FTMP, &done); |
| 3764 | __ LoadConst32(res, 1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3765 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3766 | __ CmpLtD(FTMP, rhs, lhs); |
| 3767 | __ LoadConst32(res, 1); |
| 3768 | __ Bc1nez(FTMP, &done); |
| 3769 | __ LoadConst32(res, -1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3770 | } |
| 3771 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3772 | if (gt_bias) { |
| 3773 | __ ColtD(0, lhs, rhs); |
| 3774 | __ LoadConst32(res, -1); |
| 3775 | __ Bc1t(0, &done); |
| 3776 | __ CeqD(0, lhs, rhs); |
| 3777 | __ LoadConst32(res, 1); |
| 3778 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3779 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3780 | __ ColtD(0, rhs, lhs); |
| 3781 | __ LoadConst32(res, 1); |
| 3782 | __ Bc1t(0, &done); |
| 3783 | __ CeqD(0, lhs, rhs); |
| 3784 | __ LoadConst32(res, -1); |
| 3785 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3786 | } |
| 3787 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3788 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3789 | break; |
| 3790 | } |
| 3791 | |
| 3792 | default: |
| 3793 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3794 | } |
| 3795 | } |
| 3796 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3797 | void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3798 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3799 | switch (instruction->InputAt(0)->GetType()) { |
| 3800 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3801 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3802 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3803 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3804 | break; |
| 3805 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3806 | case DataType::Type::kFloat32: |
| 3807 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3808 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3809 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3810 | break; |
| 3811 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3812 | if (!instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3813 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3814 | } |
| 3815 | } |
| 3816 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3817 | void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3818 | if (instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3819 | return; |
| 3820 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3821 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3822 | DataType::Type type = instruction->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3823 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3824 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3825 | switch (type) { |
| 3826 | default: |
| 3827 | // Integer case. |
| 3828 | GenerateIntCompare(instruction->GetCondition(), locations); |
| 3829 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3830 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3831 | case DataType::Type::kInt64: |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 3832 | GenerateLongCompare(instruction->GetCondition(), locations); |
| 3833 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3834 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3835 | case DataType::Type::kFloat32: |
| 3836 | case DataType::Type::kFloat64: |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 3837 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 3838 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3839 | } |
| 3840 | } |
| 3841 | |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3842 | void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3843 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3844 | |
| 3845 | LocationSummary* locations = instruction->GetLocations(); |
| 3846 | Location second = locations->InAt(1); |
| 3847 | DCHECK(second.IsConstant()); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3848 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3849 | DCHECK(imm == 1 || imm == -1); |
| 3850 | |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3851 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 3852 | Register out = locations->Out().AsRegister<Register>(); |
| 3853 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3854 | |
| 3855 | if (instruction->IsRem()) { |
| 3856 | __ Move(out, ZERO); |
| 3857 | } else { |
| 3858 | if (imm == -1) { |
| 3859 | __ Subu(out, ZERO, dividend); |
| 3860 | } else if (out != dividend) { |
| 3861 | __ Move(out, dividend); |
| 3862 | } |
| 3863 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3864 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3865 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 3866 | Register out_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 3867 | Register out_low = locations->Out().AsRegisterPairLow<Register>(); |
| 3868 | Register in_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3869 | Register in_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3870 | |
| 3871 | if (instruction->IsRem()) { |
| 3872 | __ Move(out_high, ZERO); |
| 3873 | __ Move(out_low, ZERO); |
| 3874 | } else { |
| 3875 | if (imm == -1) { |
| 3876 | __ Subu(out_low, ZERO, in_low); |
| 3877 | __ Sltu(AT, ZERO, out_low); |
| 3878 | __ Subu(out_high, ZERO, in_high); |
| 3879 | __ Subu(out_high, out_high, AT); |
| 3880 | } else { |
| 3881 | __ Move(out_low, in_low); |
| 3882 | __ Move(out_high, in_high); |
| 3883 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3884 | } |
| 3885 | } |
| 3886 | } |
| 3887 | |
| 3888 | void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3889 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3890 | |
| 3891 | LocationSummary* locations = instruction->GetLocations(); |
| 3892 | Location second = locations->InAt(1); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3893 | const bool is_r2_or_newer = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
| 3894 | const bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3895 | DCHECK(second.IsConstant()); |
| 3896 | |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3897 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 3898 | Register out = locations->Out().AsRegister<Register>(); |
| 3899 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3900 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3901 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 3902 | int ctz_imm = CTZ(abs_imm); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3903 | |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3904 | if (instruction->IsDiv()) { |
| 3905 | if (ctz_imm == 1) { |
| 3906 | // Fast path for division by +/-2, which is very common. |
| 3907 | __ Srl(TMP, dividend, 31); |
| 3908 | } else { |
| 3909 | __ Sra(TMP, dividend, 31); |
| 3910 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3911 | } |
| 3912 | __ Addu(out, dividend, TMP); |
| 3913 | __ Sra(out, out, ctz_imm); |
| 3914 | if (imm < 0) { |
| 3915 | __ Subu(out, ZERO, out); |
| 3916 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3917 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3918 | if (ctz_imm == 1) { |
| 3919 | // Fast path for modulo +/-2, which is very common. |
| 3920 | __ Sra(TMP, dividend, 31); |
| 3921 | __ Subu(out, dividend, TMP); |
| 3922 | __ Andi(out, out, 1); |
| 3923 | __ Addu(out, out, TMP); |
| 3924 | } else { |
| 3925 | __ Sra(TMP, dividend, 31); |
| 3926 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3927 | __ Addu(out, dividend, TMP); |
| 3928 | if (IsUint<16>(abs_imm - 1)) { |
| 3929 | __ Andi(out, out, abs_imm - 1); |
| 3930 | } else { |
| 3931 | if (is_r2_or_newer) { |
| 3932 | __ Ins(out, ZERO, ctz_imm, 32 - ctz_imm); |
| 3933 | } else { |
| 3934 | __ Sll(out, out, 32 - ctz_imm); |
| 3935 | __ Srl(out, out, 32 - ctz_imm); |
| 3936 | } |
| 3937 | } |
| 3938 | __ Subu(out, out, TMP); |
| 3939 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3940 | } |
| 3941 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3942 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 3943 | Register out_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 3944 | Register out_low = locations->Out().AsRegisterPairLow<Register>(); |
| 3945 | Register in_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3946 | Register in_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3947 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3948 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 3949 | int ctz_imm = CTZ(abs_imm); |
| 3950 | |
| 3951 | if (instruction->IsDiv()) { |
| 3952 | if (ctz_imm < 32) { |
| 3953 | if (ctz_imm == 1) { |
| 3954 | __ Srl(AT, in_high, 31); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3955 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3956 | __ Sra(AT, in_high, 31); |
| 3957 | __ Srl(AT, AT, 32 - ctz_imm); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3958 | } |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3959 | __ Addu(AT, AT, in_low); |
| 3960 | __ Sltu(TMP, AT, in_low); |
| 3961 | __ Addu(out_high, in_high, TMP); |
| 3962 | __ Srl(out_low, AT, ctz_imm); |
| 3963 | if (is_r2_or_newer) { |
| 3964 | __ Ins(out_low, out_high, 32 - ctz_imm, ctz_imm); |
| 3965 | __ Sra(out_high, out_high, ctz_imm); |
| 3966 | } else { |
| 3967 | __ Sll(AT, out_high, 32 - ctz_imm); |
| 3968 | __ Sra(out_high, out_high, ctz_imm); |
| 3969 | __ Or(out_low, out_low, AT); |
| 3970 | } |
| 3971 | if (imm < 0) { |
| 3972 | __ Subu(out_low, ZERO, out_low); |
| 3973 | __ Sltu(AT, ZERO, out_low); |
| 3974 | __ Subu(out_high, ZERO, out_high); |
| 3975 | __ Subu(out_high, out_high, AT); |
| 3976 | } |
| 3977 | } else if (ctz_imm == 32) { |
| 3978 | __ Sra(AT, in_high, 31); |
| 3979 | __ Addu(AT, AT, in_low); |
| 3980 | __ Sltu(AT, AT, in_low); |
| 3981 | __ Addu(out_low, in_high, AT); |
| 3982 | if (imm < 0) { |
| 3983 | __ Srl(TMP, out_low, 31); |
| 3984 | __ Subu(out_low, ZERO, out_low); |
| 3985 | __ Sltu(AT, ZERO, out_low); |
| 3986 | __ Subu(out_high, TMP, AT); |
| 3987 | } else { |
| 3988 | __ Sra(out_high, out_low, 31); |
| 3989 | } |
| 3990 | } else if (ctz_imm < 63) { |
| 3991 | __ Sra(AT, in_high, 31); |
| 3992 | __ Srl(TMP, AT, 64 - ctz_imm); |
| 3993 | __ Addu(AT, AT, in_low); |
| 3994 | __ Sltu(AT, AT, in_low); |
| 3995 | __ Addu(out_low, in_high, AT); |
| 3996 | __ Addu(out_low, out_low, TMP); |
| 3997 | __ Sra(out_low, out_low, ctz_imm - 32); |
| 3998 | if (imm < 0) { |
| 3999 | __ Subu(out_low, ZERO, out_low); |
| 4000 | } |
| 4001 | __ Sra(out_high, out_low, 31); |
| 4002 | } else { |
| 4003 | DCHECK_LT(imm, 0); |
| 4004 | if (is_r6) { |
| 4005 | __ Aui(AT, in_high, 0x8000); |
| 4006 | } else { |
| 4007 | __ Lui(AT, 0x8000); |
| 4008 | __ Xor(AT, AT, in_high); |
| 4009 | } |
| 4010 | __ Or(AT, AT, in_low); |
| 4011 | __ Sltiu(out_low, AT, 1); |
| 4012 | __ Move(out_high, ZERO); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4013 | } |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 4014 | } else { |
| 4015 | if ((ctz_imm == 1) && !is_r6) { |
| 4016 | __ Andi(AT, in_low, 1); |
| 4017 | __ Sll(TMP, in_low, 31); |
| 4018 | __ And(TMP, in_high, TMP); |
| 4019 | __ Sra(out_high, TMP, 31); |
| 4020 | __ Or(out_low, out_high, AT); |
| 4021 | } else if (ctz_imm < 32) { |
| 4022 | __ Sra(AT, in_high, 31); |
| 4023 | if (ctz_imm <= 16) { |
| 4024 | __ Andi(out_low, in_low, abs_imm - 1); |
| 4025 | } else if (is_r2_or_newer) { |
| 4026 | __ Ext(out_low, in_low, 0, ctz_imm); |
| 4027 | } else { |
| 4028 | __ Sll(out_low, in_low, 32 - ctz_imm); |
| 4029 | __ Srl(out_low, out_low, 32 - ctz_imm); |
| 4030 | } |
| 4031 | if (is_r6) { |
| 4032 | __ Selnez(out_high, AT, out_low); |
| 4033 | } else { |
| 4034 | __ Movz(AT, ZERO, out_low); |
| 4035 | __ Move(out_high, AT); |
| 4036 | } |
| 4037 | if (is_r2_or_newer) { |
| 4038 | __ Ins(out_low, out_high, ctz_imm, 32 - ctz_imm); |
| 4039 | } else { |
| 4040 | __ Sll(AT, out_high, ctz_imm); |
| 4041 | __ Or(out_low, out_low, AT); |
| 4042 | } |
| 4043 | } else if (ctz_imm == 32) { |
| 4044 | __ Sra(AT, in_high, 31); |
| 4045 | __ Move(out_low, in_low); |
| 4046 | if (is_r6) { |
| 4047 | __ Selnez(out_high, AT, out_low); |
| 4048 | } else { |
| 4049 | __ Movz(AT, ZERO, out_low); |
| 4050 | __ Move(out_high, AT); |
| 4051 | } |
| 4052 | } else if (ctz_imm < 63) { |
| 4053 | __ Sra(AT, in_high, 31); |
| 4054 | __ Move(TMP, in_low); |
| 4055 | if (ctz_imm - 32 <= 16) { |
| 4056 | __ Andi(out_high, in_high, (1 << (ctz_imm - 32)) - 1); |
| 4057 | } else if (is_r2_or_newer) { |
| 4058 | __ Ext(out_high, in_high, 0, ctz_imm - 32); |
| 4059 | } else { |
| 4060 | __ Sll(out_high, in_high, 64 - ctz_imm); |
| 4061 | __ Srl(out_high, out_high, 64 - ctz_imm); |
| 4062 | } |
| 4063 | __ Move(out_low, TMP); |
| 4064 | __ Or(TMP, TMP, out_high); |
| 4065 | if (is_r6) { |
| 4066 | __ Selnez(AT, AT, TMP); |
| 4067 | } else { |
| 4068 | __ Movz(AT, ZERO, TMP); |
| 4069 | } |
| 4070 | if (is_r2_or_newer) { |
| 4071 | __ Ins(out_high, AT, ctz_imm - 32, 64 - ctz_imm); |
| 4072 | } else { |
| 4073 | __ Sll(AT, AT, ctz_imm - 32); |
| 4074 | __ Or(out_high, out_high, AT); |
| 4075 | } |
| 4076 | } else { |
| 4077 | if (is_r6) { |
| 4078 | __ Aui(AT, in_high, 0x8000); |
| 4079 | } else { |
| 4080 | __ Lui(AT, 0x8000); |
| 4081 | __ Xor(AT, AT, in_high); |
| 4082 | } |
| 4083 | __ Or(AT, AT, in_low); |
| 4084 | __ Sltiu(AT, AT, 1); |
| 4085 | __ Sll(AT, AT, 31); |
| 4086 | __ Move(out_low, in_low); |
| 4087 | __ Xor(out_high, in_high, AT); |
| 4088 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4089 | } |
| 4090 | } |
| 4091 | } |
| 4092 | |
| 4093 | void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4094 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4095 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4096 | |
| 4097 | LocationSummary* locations = instruction->GetLocations(); |
| 4098 | Location second = locations->InAt(1); |
| 4099 | DCHECK(second.IsConstant()); |
| 4100 | |
| 4101 | Register out = locations->Out().AsRegister<Register>(); |
| 4102 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4103 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4104 | |
| 4105 | int64_t magic; |
| 4106 | int shift; |
| 4107 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4108 | |
| 4109 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4110 | |
| 4111 | __ LoadConst32(TMP, magic); |
| 4112 | if (isR6) { |
| 4113 | __ MuhR6(TMP, dividend, TMP); |
| 4114 | } else { |
| 4115 | __ MultR2(dividend, TMP); |
| 4116 | __ Mfhi(TMP); |
| 4117 | } |
| 4118 | if (imm > 0 && magic < 0) { |
| 4119 | __ Addu(TMP, TMP, dividend); |
| 4120 | } else if (imm < 0 && magic > 0) { |
| 4121 | __ Subu(TMP, TMP, dividend); |
| 4122 | } |
| 4123 | |
| 4124 | if (shift != 0) { |
| 4125 | __ Sra(TMP, TMP, shift); |
| 4126 | } |
| 4127 | |
| 4128 | if (instruction->IsDiv()) { |
| 4129 | __ Sra(out, TMP, 31); |
| 4130 | __ Subu(out, TMP, out); |
| 4131 | } else { |
| 4132 | __ Sra(AT, TMP, 31); |
| 4133 | __ Subu(AT, TMP, AT); |
| 4134 | __ LoadConst32(TMP, imm); |
| 4135 | if (isR6) { |
| 4136 | __ MulR6(TMP, AT, TMP); |
| 4137 | } else { |
| 4138 | __ MulR2(TMP, AT, TMP); |
| 4139 | } |
| 4140 | __ Subu(out, dividend, TMP); |
| 4141 | } |
| 4142 | } |
| 4143 | |
| 4144 | void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 4145 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4146 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4147 | |
| 4148 | LocationSummary* locations = instruction->GetLocations(); |
| 4149 | Register out = locations->Out().AsRegister<Register>(); |
| 4150 | Location second = locations->InAt(1); |
| 4151 | |
| 4152 | if (second.IsConstant()) { |
| 4153 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4154 | if (imm == 0) { |
| 4155 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4156 | } else if (imm == 1 || imm == -1) { |
| 4157 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4158 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4159 | DivRemByPowerOfTwo(instruction); |
| 4160 | } else { |
| 4161 | DCHECK(imm <= -2 || imm >= 2); |
| 4162 | GenerateDivRemWithAnyConstant(instruction); |
| 4163 | } |
| 4164 | } else { |
| 4165 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4166 | Register divisor = second.AsRegister<Register>(); |
| 4167 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4168 | if (instruction->IsDiv()) { |
| 4169 | if (isR6) { |
| 4170 | __ DivR6(out, dividend, divisor); |
| 4171 | } else { |
| 4172 | __ DivR2(out, dividend, divisor); |
| 4173 | } |
| 4174 | } else { |
| 4175 | if (isR6) { |
| 4176 | __ ModR6(out, dividend, divisor); |
| 4177 | } else { |
| 4178 | __ ModR2(out, dividend, divisor); |
| 4179 | } |
| 4180 | } |
| 4181 | } |
| 4182 | } |
| 4183 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4184 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4185 | DataType::Type type = div->GetResultType(); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 4186 | bool call_long_div = false; |
| 4187 | if (type == DataType::Type::kInt64) { |
| 4188 | if (div->InputAt(1)->IsConstant()) { |
| 4189 | int64_t imm = CodeGenerator::GetInt64ValueOf(div->InputAt(1)->AsConstant()); |
| 4190 | call_long_div = (imm != 0) && !IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm))); |
| 4191 | } else { |
| 4192 | call_long_div = true; |
| 4193 | } |
| 4194 | } |
| 4195 | LocationSummary::CallKind call_kind = call_long_div |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4196 | ? LocationSummary::kCallOnMainOnly |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4197 | : LocationSummary::kNoCall; |
| 4198 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4199 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4200 | |
| 4201 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4202 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4203 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4204 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4205 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4206 | break; |
| 4207 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4208 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 4209 | if (call_long_div) { |
| 4210 | InvokeRuntimeCallingConvention calling_convention; |
| 4211 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4212 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4213 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4214 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4215 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4216 | } else { |
| 4217 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4218 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 4219 | locations->SetOut(Location::RequiresRegister()); |
| 4220 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4221 | break; |
| 4222 | } |
| 4223 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4224 | case DataType::Type::kFloat32: |
| 4225 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4226 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4227 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4228 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4229 | break; |
| 4230 | |
| 4231 | default: |
| 4232 | LOG(FATAL) << "Unexpected div type " << type; |
| 4233 | } |
| 4234 | } |
| 4235 | |
| 4236 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4237 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4238 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4239 | |
| 4240 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4241 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4242 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4243 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4244 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 4245 | if (locations->InAt(1).IsConstant()) { |
| 4246 | int64_t imm = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue(); |
| 4247 | if (imm == 0) { |
| 4248 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4249 | } else if (imm == 1 || imm == -1) { |
| 4250 | DivRemOneOrMinusOne(instruction); |
| 4251 | } else { |
| 4252 | DCHECK(IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm)))); |
| 4253 | DivRemByPowerOfTwo(instruction); |
| 4254 | } |
| 4255 | } else { |
| 4256 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
| 4257 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| 4258 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4259 | break; |
| 4260 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4261 | case DataType::Type::kFloat32: |
| 4262 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4263 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 4264 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4265 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4266 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4267 | __ DivS(dst, lhs, rhs); |
| 4268 | } else { |
| 4269 | __ DivD(dst, lhs, rhs); |
| 4270 | } |
| 4271 | break; |
| 4272 | } |
| 4273 | default: |
| 4274 | LOG(FATAL) << "Unexpected div type " << type; |
| 4275 | } |
| 4276 | } |
| 4277 | |
| 4278 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4279 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4280 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4281 | } |
| 4282 | |
| 4283 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4284 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4285 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4286 | codegen_->AddSlowPath(slow_path); |
| 4287 | Location value = instruction->GetLocations()->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4288 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4289 | |
| 4290 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4291 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4292 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4293 | case DataType::Type::kInt8: |
| 4294 | case DataType::Type::kUint16: |
| 4295 | case DataType::Type::kInt16: |
| 4296 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4297 | if (value.IsConstant()) { |
| 4298 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 4299 | __ B(slow_path->GetEntryLabel()); |
| 4300 | } else { |
| 4301 | // A division by a non-null constant is valid. We don't need to perform |
| 4302 | // any check, so simply fall through. |
| 4303 | } |
| 4304 | } else { |
| 4305 | DCHECK(value.IsRegister()) << value; |
| 4306 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 4307 | } |
| 4308 | break; |
| 4309 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4310 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4311 | if (value.IsConstant()) { |
| 4312 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4313 | __ B(slow_path->GetEntryLabel()); |
| 4314 | } else { |
| 4315 | // A division by a non-null constant is valid. We don't need to perform |
| 4316 | // any check, so simply fall through. |
| 4317 | } |
| 4318 | } else { |
| 4319 | DCHECK(value.IsRegisterPair()) << value; |
| 4320 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); |
| 4321 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 4322 | } |
| 4323 | break; |
| 4324 | } |
| 4325 | default: |
| 4326 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| 4327 | } |
| 4328 | } |
| 4329 | |
| 4330 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { |
| 4331 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4332 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4333 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4334 | } |
| 4335 | |
| 4336 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 4337 | // Will be generated at use site. |
| 4338 | } |
| 4339 | |
| 4340 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { |
| 4341 | exit->SetLocations(nullptr); |
| 4342 | } |
| 4343 | |
| 4344 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 4345 | } |
| 4346 | |
| 4347 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { |
| 4348 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4349 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4350 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4351 | } |
| 4352 | |
| 4353 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 4354 | // Will be generated at use site. |
| 4355 | } |
| 4356 | |
| 4357 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { |
| 4358 | got->SetLocations(nullptr); |
| 4359 | } |
| 4360 | |
| 4361 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4362 | if (successor->IsExitBlock()) { |
| 4363 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 4364 | return; // no code needed |
| 4365 | } |
| 4366 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4367 | HBasicBlock* block = got->GetBlock(); |
| 4368 | HInstruction* previous = got->GetPrevious(); |
| 4369 | HLoopInformation* info = block->GetLoopInformation(); |
| 4370 | |
| 4371 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Goran Jakovljevic | feec167 | 2018-02-08 10:20:14 +0100 | [diff] [blame] | 4372 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 4373 | __ Lw(AT, SP, kCurrentMethodStackOffset); |
| 4374 | __ Lhu(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value()); |
| 4375 | __ Addiu(TMP, TMP, 1); |
| 4376 | __ Sh(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value()); |
| 4377 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4378 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 4379 | return; |
| 4380 | } |
| 4381 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 4382 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 4383 | } |
| 4384 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 4385 | __ B(codegen_->GetLabelOf(successor)); |
| 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { |
| 4390 | HandleGoto(got, got->GetSuccessor()); |
| 4391 | } |
| 4392 | |
| 4393 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 4394 | try_boundary->SetLocations(nullptr); |
| 4395 | } |
| 4396 | |
| 4397 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 4398 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 4399 | if (!successor->IsExitBlock()) { |
| 4400 | HandleGoto(try_boundary, successor); |
| 4401 | } |
| 4402 | } |
| 4403 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4404 | void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond, |
| 4405 | LocationSummary* locations) { |
| 4406 | Register dst = locations->Out().AsRegister<Register>(); |
| 4407 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4408 | Location rhs_location = locations->InAt(1); |
| 4409 | Register rhs_reg = ZERO; |
| 4410 | int64_t rhs_imm = 0; |
| 4411 | bool use_imm = rhs_location.IsConstant(); |
| 4412 | if (use_imm) { |
| 4413 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4414 | } else { |
| 4415 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4416 | } |
| 4417 | |
| 4418 | switch (cond) { |
| 4419 | case kCondEQ: |
| 4420 | case kCondNE: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4421 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4422 | if (rhs_imm == 0) { |
| 4423 | if (cond == kCondEQ) { |
| 4424 | __ Sltiu(dst, lhs, 1); |
| 4425 | } else { |
| 4426 | __ Sltu(dst, ZERO, lhs); |
| 4427 | } |
| 4428 | } else { |
| 4429 | __ Addiu(dst, lhs, -rhs_imm); |
| 4430 | if (cond == kCondEQ) { |
| 4431 | __ Sltiu(dst, dst, 1); |
| 4432 | } else { |
| 4433 | __ Sltu(dst, ZERO, dst); |
| 4434 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4435 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4436 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4437 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 4438 | __ Xori(dst, lhs, rhs_imm); |
| 4439 | } else { |
| 4440 | if (use_imm) { |
| 4441 | rhs_reg = TMP; |
| 4442 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4443 | } |
| 4444 | __ Xor(dst, lhs, rhs_reg); |
| 4445 | } |
| 4446 | if (cond == kCondEQ) { |
| 4447 | __ Sltiu(dst, dst, 1); |
| 4448 | } else { |
| 4449 | __ Sltu(dst, ZERO, dst); |
| 4450 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4451 | } |
| 4452 | break; |
| 4453 | |
| 4454 | case kCondLT: |
| 4455 | case kCondGE: |
| 4456 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4457 | __ Slti(dst, lhs, rhs_imm); |
| 4458 | } else { |
| 4459 | if (use_imm) { |
| 4460 | rhs_reg = TMP; |
| 4461 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4462 | } |
| 4463 | __ Slt(dst, lhs, rhs_reg); |
| 4464 | } |
| 4465 | if (cond == kCondGE) { |
| 4466 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4467 | // only the slt instruction but no sge. |
| 4468 | __ Xori(dst, dst, 1); |
| 4469 | } |
| 4470 | break; |
| 4471 | |
| 4472 | case kCondLE: |
| 4473 | case kCondGT: |
| 4474 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4475 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4476 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4477 | if (cond == kCondGT) { |
| 4478 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4479 | // only the slti instruction but no sgti. |
| 4480 | __ Xori(dst, dst, 1); |
| 4481 | } |
| 4482 | } else { |
| 4483 | if (use_imm) { |
| 4484 | rhs_reg = TMP; |
| 4485 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4486 | } |
| 4487 | __ Slt(dst, rhs_reg, lhs); |
| 4488 | if (cond == kCondLE) { |
| 4489 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4490 | // only the slt instruction but no sle. |
| 4491 | __ Xori(dst, dst, 1); |
| 4492 | } |
| 4493 | } |
| 4494 | break; |
| 4495 | |
| 4496 | case kCondB: |
| 4497 | case kCondAE: |
| 4498 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4499 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4500 | // the comparison and thus lets us compare directly with |
| 4501 | // unsigned values in the ranges [0, 0x7fff] and |
| 4502 | // [0xffff8000, 0xffffffff]. |
| 4503 | __ Sltiu(dst, lhs, rhs_imm); |
| 4504 | } else { |
| 4505 | if (use_imm) { |
| 4506 | rhs_reg = TMP; |
| 4507 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4508 | } |
| 4509 | __ Sltu(dst, lhs, rhs_reg); |
| 4510 | } |
| 4511 | if (cond == kCondAE) { |
| 4512 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4513 | // only the sltu instruction but no sgeu. |
| 4514 | __ Xori(dst, dst, 1); |
| 4515 | } |
| 4516 | break; |
| 4517 | |
| 4518 | case kCondBE: |
| 4519 | case kCondA: |
| 4520 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4521 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4522 | // Note that this only works if rhs + 1 does not overflow |
| 4523 | // to 0, hence the check above. |
| 4524 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4525 | // the comparison and thus lets us compare directly with |
| 4526 | // unsigned values in the ranges [0, 0x7fff] and |
| 4527 | // [0xffff8000, 0xffffffff]. |
| 4528 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4529 | if (cond == kCondA) { |
| 4530 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4531 | // only the sltiu instruction but no sgtiu. |
| 4532 | __ Xori(dst, dst, 1); |
| 4533 | } |
| 4534 | } else { |
| 4535 | if (use_imm) { |
| 4536 | rhs_reg = TMP; |
| 4537 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4538 | } |
| 4539 | __ Sltu(dst, rhs_reg, lhs); |
| 4540 | if (cond == kCondBE) { |
| 4541 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4542 | // only the sltu instruction but no sleu. |
| 4543 | __ Xori(dst, dst, 1); |
| 4544 | } |
| 4545 | } |
| 4546 | break; |
| 4547 | } |
| 4548 | } |
| 4549 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4550 | bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond, |
| 4551 | LocationSummary* input_locations, |
| 4552 | Register dst) { |
| 4553 | Register lhs = input_locations->InAt(0).AsRegister<Register>(); |
| 4554 | Location rhs_location = input_locations->InAt(1); |
| 4555 | Register rhs_reg = ZERO; |
| 4556 | int64_t rhs_imm = 0; |
| 4557 | bool use_imm = rhs_location.IsConstant(); |
| 4558 | if (use_imm) { |
| 4559 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4560 | } else { |
| 4561 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4562 | } |
| 4563 | |
| 4564 | switch (cond) { |
| 4565 | case kCondEQ: |
| 4566 | case kCondNE: |
| 4567 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4568 | __ Addiu(dst, lhs, -rhs_imm); |
| 4569 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 4570 | __ Xori(dst, lhs, rhs_imm); |
| 4571 | } else { |
| 4572 | if (use_imm) { |
| 4573 | rhs_reg = TMP; |
| 4574 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4575 | } |
| 4576 | __ Xor(dst, lhs, rhs_reg); |
| 4577 | } |
| 4578 | return (cond == kCondEQ); |
| 4579 | |
| 4580 | case kCondLT: |
| 4581 | case kCondGE: |
| 4582 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4583 | __ Slti(dst, lhs, rhs_imm); |
| 4584 | } else { |
| 4585 | if (use_imm) { |
| 4586 | rhs_reg = TMP; |
| 4587 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4588 | } |
| 4589 | __ Slt(dst, lhs, rhs_reg); |
| 4590 | } |
| 4591 | return (cond == kCondGE); |
| 4592 | |
| 4593 | case kCondLE: |
| 4594 | case kCondGT: |
| 4595 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4596 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4597 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4598 | return (cond == kCondGT); |
| 4599 | } else { |
| 4600 | if (use_imm) { |
| 4601 | rhs_reg = TMP; |
| 4602 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4603 | } |
| 4604 | __ Slt(dst, rhs_reg, lhs); |
| 4605 | return (cond == kCondLE); |
| 4606 | } |
| 4607 | |
| 4608 | case kCondB: |
| 4609 | case kCondAE: |
| 4610 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4611 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4612 | // the comparison and thus lets us compare directly with |
| 4613 | // unsigned values in the ranges [0, 0x7fff] and |
| 4614 | // [0xffff8000, 0xffffffff]. |
| 4615 | __ Sltiu(dst, lhs, rhs_imm); |
| 4616 | } else { |
| 4617 | if (use_imm) { |
| 4618 | rhs_reg = TMP; |
| 4619 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4620 | } |
| 4621 | __ Sltu(dst, lhs, rhs_reg); |
| 4622 | } |
| 4623 | return (cond == kCondAE); |
| 4624 | |
| 4625 | case kCondBE: |
| 4626 | case kCondA: |
| 4627 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4628 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4629 | // Note that this only works if rhs + 1 does not overflow |
| 4630 | // to 0, hence the check above. |
| 4631 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4632 | // the comparison and thus lets us compare directly with |
| 4633 | // unsigned values in the ranges [0, 0x7fff] and |
| 4634 | // [0xffff8000, 0xffffffff]. |
| 4635 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4636 | return (cond == kCondA); |
| 4637 | } else { |
| 4638 | if (use_imm) { |
| 4639 | rhs_reg = TMP; |
| 4640 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4641 | } |
| 4642 | __ Sltu(dst, rhs_reg, lhs); |
| 4643 | return (cond == kCondBE); |
| 4644 | } |
| 4645 | } |
| 4646 | } |
| 4647 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4648 | void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond, |
| 4649 | LocationSummary* locations, |
| 4650 | MipsLabel* label) { |
| 4651 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4652 | Location rhs_location = locations->InAt(1); |
| 4653 | Register rhs_reg = ZERO; |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4654 | int64_t rhs_imm = 0; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4655 | bool use_imm = rhs_location.IsConstant(); |
| 4656 | if (use_imm) { |
| 4657 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4658 | } else { |
| 4659 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4660 | } |
| 4661 | |
| 4662 | if (use_imm && rhs_imm == 0) { |
| 4663 | switch (cond) { |
| 4664 | case kCondEQ: |
| 4665 | case kCondBE: // <= 0 if zero |
| 4666 | __ Beqz(lhs, label); |
| 4667 | break; |
| 4668 | case kCondNE: |
| 4669 | case kCondA: // > 0 if non-zero |
| 4670 | __ Bnez(lhs, label); |
| 4671 | break; |
| 4672 | case kCondLT: |
| 4673 | __ Bltz(lhs, label); |
| 4674 | break; |
| 4675 | case kCondGE: |
| 4676 | __ Bgez(lhs, label); |
| 4677 | break; |
| 4678 | case kCondLE: |
| 4679 | __ Blez(lhs, label); |
| 4680 | break; |
| 4681 | case kCondGT: |
| 4682 | __ Bgtz(lhs, label); |
| 4683 | break; |
| 4684 | case kCondB: // always false |
| 4685 | break; |
| 4686 | case kCondAE: // always true |
| 4687 | __ B(label); |
| 4688 | break; |
| 4689 | } |
| 4690 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4691 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4692 | if (isR6 || !use_imm) { |
| 4693 | if (use_imm) { |
| 4694 | rhs_reg = TMP; |
| 4695 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4696 | } |
| 4697 | switch (cond) { |
| 4698 | case kCondEQ: |
| 4699 | __ Beq(lhs, rhs_reg, label); |
| 4700 | break; |
| 4701 | case kCondNE: |
| 4702 | __ Bne(lhs, rhs_reg, label); |
| 4703 | break; |
| 4704 | case kCondLT: |
| 4705 | __ Blt(lhs, rhs_reg, label); |
| 4706 | break; |
| 4707 | case kCondGE: |
| 4708 | __ Bge(lhs, rhs_reg, label); |
| 4709 | break; |
| 4710 | case kCondLE: |
| 4711 | __ Bge(rhs_reg, lhs, label); |
| 4712 | break; |
| 4713 | case kCondGT: |
| 4714 | __ Blt(rhs_reg, lhs, label); |
| 4715 | break; |
| 4716 | case kCondB: |
| 4717 | __ Bltu(lhs, rhs_reg, label); |
| 4718 | break; |
| 4719 | case kCondAE: |
| 4720 | __ Bgeu(lhs, rhs_reg, label); |
| 4721 | break; |
| 4722 | case kCondBE: |
| 4723 | __ Bgeu(rhs_reg, lhs, label); |
| 4724 | break; |
| 4725 | case kCondA: |
| 4726 | __ Bltu(rhs_reg, lhs, label); |
| 4727 | break; |
| 4728 | } |
| 4729 | } else { |
| 4730 | // Special cases for more efficient comparison with constants on R2. |
| 4731 | switch (cond) { |
| 4732 | case kCondEQ: |
| 4733 | __ LoadConst32(TMP, rhs_imm); |
| 4734 | __ Beq(lhs, TMP, label); |
| 4735 | break; |
| 4736 | case kCondNE: |
| 4737 | __ LoadConst32(TMP, rhs_imm); |
| 4738 | __ Bne(lhs, TMP, label); |
| 4739 | break; |
| 4740 | case kCondLT: |
| 4741 | if (IsInt<16>(rhs_imm)) { |
| 4742 | __ Slti(TMP, lhs, rhs_imm); |
| 4743 | __ Bnez(TMP, label); |
| 4744 | } else { |
| 4745 | __ LoadConst32(TMP, rhs_imm); |
| 4746 | __ Blt(lhs, TMP, label); |
| 4747 | } |
| 4748 | break; |
| 4749 | case kCondGE: |
| 4750 | if (IsInt<16>(rhs_imm)) { |
| 4751 | __ Slti(TMP, lhs, rhs_imm); |
| 4752 | __ Beqz(TMP, label); |
| 4753 | } else { |
| 4754 | __ LoadConst32(TMP, rhs_imm); |
| 4755 | __ Bge(lhs, TMP, label); |
| 4756 | } |
| 4757 | break; |
| 4758 | case kCondLE: |
| 4759 | if (IsInt<16>(rhs_imm + 1)) { |
| 4760 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4761 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4762 | __ Bnez(TMP, label); |
| 4763 | } else { |
| 4764 | __ LoadConst32(TMP, rhs_imm); |
| 4765 | __ Bge(TMP, lhs, label); |
| 4766 | } |
| 4767 | break; |
| 4768 | case kCondGT: |
| 4769 | if (IsInt<16>(rhs_imm + 1)) { |
| 4770 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4771 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4772 | __ Beqz(TMP, label); |
| 4773 | } else { |
| 4774 | __ LoadConst32(TMP, rhs_imm); |
| 4775 | __ Blt(TMP, lhs, label); |
| 4776 | } |
| 4777 | break; |
| 4778 | case kCondB: |
| 4779 | if (IsInt<16>(rhs_imm)) { |
| 4780 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4781 | __ Bnez(TMP, label); |
| 4782 | } else { |
| 4783 | __ LoadConst32(TMP, rhs_imm); |
| 4784 | __ Bltu(lhs, TMP, label); |
| 4785 | } |
| 4786 | break; |
| 4787 | case kCondAE: |
| 4788 | if (IsInt<16>(rhs_imm)) { |
| 4789 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4790 | __ Beqz(TMP, label); |
| 4791 | } else { |
| 4792 | __ LoadConst32(TMP, rhs_imm); |
| 4793 | __ Bgeu(lhs, TMP, label); |
| 4794 | } |
| 4795 | break; |
| 4796 | case kCondBE: |
| 4797 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4798 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4799 | // Note that this only works if rhs + 1 does not overflow |
| 4800 | // to 0, hence the check above. |
| 4801 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4802 | __ Bnez(TMP, label); |
| 4803 | } else { |
| 4804 | __ LoadConst32(TMP, rhs_imm); |
| 4805 | __ Bgeu(TMP, lhs, label); |
| 4806 | } |
| 4807 | break; |
| 4808 | case kCondA: |
| 4809 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4810 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4811 | // Note that this only works if rhs + 1 does not overflow |
| 4812 | // to 0, hence the check above. |
| 4813 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4814 | __ Beqz(TMP, label); |
| 4815 | } else { |
| 4816 | __ LoadConst32(TMP, rhs_imm); |
| 4817 | __ Bltu(TMP, lhs, label); |
| 4818 | } |
| 4819 | break; |
| 4820 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4821 | } |
| 4822 | } |
| 4823 | } |
| 4824 | |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 4825 | void InstructionCodeGeneratorMIPS::GenerateLongCompare(IfCondition cond, |
| 4826 | LocationSummary* locations) { |
| 4827 | Register dst = locations->Out().AsRegister<Register>(); |
| 4828 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4829 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4830 | Location rhs_location = locations->InAt(1); |
| 4831 | Register rhs_high = ZERO; |
| 4832 | Register rhs_low = ZERO; |
| 4833 | int64_t imm = 0; |
| 4834 | uint32_t imm_high = 0; |
| 4835 | uint32_t imm_low = 0; |
| 4836 | bool use_imm = rhs_location.IsConstant(); |
| 4837 | if (use_imm) { |
| 4838 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 4839 | imm_high = High32Bits(imm); |
| 4840 | imm_low = Low32Bits(imm); |
| 4841 | } else { |
| 4842 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 4843 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 4844 | } |
| 4845 | if (use_imm && imm == 0) { |
| 4846 | switch (cond) { |
| 4847 | case kCondEQ: |
| 4848 | case kCondBE: // <= 0 if zero |
| 4849 | __ Or(dst, lhs_high, lhs_low); |
| 4850 | __ Sltiu(dst, dst, 1); |
| 4851 | break; |
| 4852 | case kCondNE: |
| 4853 | case kCondA: // > 0 if non-zero |
| 4854 | __ Or(dst, lhs_high, lhs_low); |
| 4855 | __ Sltu(dst, ZERO, dst); |
| 4856 | break; |
| 4857 | case kCondLT: |
| 4858 | __ Slt(dst, lhs_high, ZERO); |
| 4859 | break; |
| 4860 | case kCondGE: |
| 4861 | __ Slt(dst, lhs_high, ZERO); |
| 4862 | __ Xori(dst, dst, 1); |
| 4863 | break; |
| 4864 | case kCondLE: |
| 4865 | __ Or(TMP, lhs_high, lhs_low); |
| 4866 | __ Sra(AT, lhs_high, 31); |
| 4867 | __ Sltu(dst, AT, TMP); |
| 4868 | __ Xori(dst, dst, 1); |
| 4869 | break; |
| 4870 | case kCondGT: |
| 4871 | __ Or(TMP, lhs_high, lhs_low); |
| 4872 | __ Sra(AT, lhs_high, 31); |
| 4873 | __ Sltu(dst, AT, TMP); |
| 4874 | break; |
| 4875 | case kCondB: // always false |
| 4876 | __ Andi(dst, dst, 0); |
| 4877 | break; |
| 4878 | case kCondAE: // always true |
| 4879 | __ Ori(dst, ZERO, 1); |
| 4880 | break; |
| 4881 | } |
| 4882 | } else if (use_imm) { |
| 4883 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 4884 | switch (cond) { |
| 4885 | case kCondEQ: |
| 4886 | __ LoadConst32(TMP, imm_high); |
| 4887 | __ Xor(TMP, TMP, lhs_high); |
| 4888 | __ LoadConst32(AT, imm_low); |
| 4889 | __ Xor(AT, AT, lhs_low); |
| 4890 | __ Or(dst, TMP, AT); |
| 4891 | __ Sltiu(dst, dst, 1); |
| 4892 | break; |
| 4893 | case kCondNE: |
| 4894 | __ LoadConst32(TMP, imm_high); |
| 4895 | __ Xor(TMP, TMP, lhs_high); |
| 4896 | __ LoadConst32(AT, imm_low); |
| 4897 | __ Xor(AT, AT, lhs_low); |
| 4898 | __ Or(dst, TMP, AT); |
| 4899 | __ Sltu(dst, ZERO, dst); |
| 4900 | break; |
| 4901 | case kCondLT: |
| 4902 | case kCondGE: |
| 4903 | if (dst == lhs_low) { |
| 4904 | __ LoadConst32(TMP, imm_low); |
| 4905 | __ Sltu(dst, lhs_low, TMP); |
| 4906 | } |
| 4907 | __ LoadConst32(TMP, imm_high); |
| 4908 | __ Slt(AT, lhs_high, TMP); |
| 4909 | __ Slt(TMP, TMP, lhs_high); |
| 4910 | if (dst != lhs_low) { |
| 4911 | __ LoadConst32(dst, imm_low); |
| 4912 | __ Sltu(dst, lhs_low, dst); |
| 4913 | } |
| 4914 | __ Slt(dst, TMP, dst); |
| 4915 | __ Or(dst, dst, AT); |
| 4916 | if (cond == kCondGE) { |
| 4917 | __ Xori(dst, dst, 1); |
| 4918 | } |
| 4919 | break; |
| 4920 | case kCondGT: |
| 4921 | case kCondLE: |
| 4922 | if (dst == lhs_low) { |
| 4923 | __ LoadConst32(TMP, imm_low); |
| 4924 | __ Sltu(dst, TMP, lhs_low); |
| 4925 | } |
| 4926 | __ LoadConst32(TMP, imm_high); |
| 4927 | __ Slt(AT, TMP, lhs_high); |
| 4928 | __ Slt(TMP, lhs_high, TMP); |
| 4929 | if (dst != lhs_low) { |
| 4930 | __ LoadConst32(dst, imm_low); |
| 4931 | __ Sltu(dst, dst, lhs_low); |
| 4932 | } |
| 4933 | __ Slt(dst, TMP, dst); |
| 4934 | __ Or(dst, dst, AT); |
| 4935 | if (cond == kCondLE) { |
| 4936 | __ Xori(dst, dst, 1); |
| 4937 | } |
| 4938 | break; |
| 4939 | case kCondB: |
| 4940 | case kCondAE: |
| 4941 | if (dst == lhs_low) { |
| 4942 | __ LoadConst32(TMP, imm_low); |
| 4943 | __ Sltu(dst, lhs_low, TMP); |
| 4944 | } |
| 4945 | __ LoadConst32(TMP, imm_high); |
| 4946 | __ Sltu(AT, lhs_high, TMP); |
| 4947 | __ Sltu(TMP, TMP, lhs_high); |
| 4948 | if (dst != lhs_low) { |
| 4949 | __ LoadConst32(dst, imm_low); |
| 4950 | __ Sltu(dst, lhs_low, dst); |
| 4951 | } |
| 4952 | __ Slt(dst, TMP, dst); |
| 4953 | __ Or(dst, dst, AT); |
| 4954 | if (cond == kCondAE) { |
| 4955 | __ Xori(dst, dst, 1); |
| 4956 | } |
| 4957 | break; |
| 4958 | case kCondA: |
| 4959 | case kCondBE: |
| 4960 | if (dst == lhs_low) { |
| 4961 | __ LoadConst32(TMP, imm_low); |
| 4962 | __ Sltu(dst, TMP, lhs_low); |
| 4963 | } |
| 4964 | __ LoadConst32(TMP, imm_high); |
| 4965 | __ Sltu(AT, TMP, lhs_high); |
| 4966 | __ Sltu(TMP, lhs_high, TMP); |
| 4967 | if (dst != lhs_low) { |
| 4968 | __ LoadConst32(dst, imm_low); |
| 4969 | __ Sltu(dst, dst, lhs_low); |
| 4970 | } |
| 4971 | __ Slt(dst, TMP, dst); |
| 4972 | __ Or(dst, dst, AT); |
| 4973 | if (cond == kCondBE) { |
| 4974 | __ Xori(dst, dst, 1); |
| 4975 | } |
| 4976 | break; |
| 4977 | } |
| 4978 | } else { |
| 4979 | switch (cond) { |
| 4980 | case kCondEQ: |
| 4981 | __ Xor(TMP, lhs_high, rhs_high); |
| 4982 | __ Xor(AT, lhs_low, rhs_low); |
| 4983 | __ Or(dst, TMP, AT); |
| 4984 | __ Sltiu(dst, dst, 1); |
| 4985 | break; |
| 4986 | case kCondNE: |
| 4987 | __ Xor(TMP, lhs_high, rhs_high); |
| 4988 | __ Xor(AT, lhs_low, rhs_low); |
| 4989 | __ Or(dst, TMP, AT); |
| 4990 | __ Sltu(dst, ZERO, dst); |
| 4991 | break; |
| 4992 | case kCondLT: |
| 4993 | case kCondGE: |
| 4994 | __ Slt(TMP, rhs_high, lhs_high); |
| 4995 | __ Sltu(AT, lhs_low, rhs_low); |
| 4996 | __ Slt(TMP, TMP, AT); |
| 4997 | __ Slt(AT, lhs_high, rhs_high); |
| 4998 | __ Or(dst, AT, TMP); |
| 4999 | if (cond == kCondGE) { |
| 5000 | __ Xori(dst, dst, 1); |
| 5001 | } |
| 5002 | break; |
| 5003 | case kCondGT: |
| 5004 | case kCondLE: |
| 5005 | __ Slt(TMP, lhs_high, rhs_high); |
| 5006 | __ Sltu(AT, rhs_low, lhs_low); |
| 5007 | __ Slt(TMP, TMP, AT); |
| 5008 | __ Slt(AT, rhs_high, lhs_high); |
| 5009 | __ Or(dst, AT, TMP); |
| 5010 | if (cond == kCondLE) { |
| 5011 | __ Xori(dst, dst, 1); |
| 5012 | } |
| 5013 | break; |
| 5014 | case kCondB: |
| 5015 | case kCondAE: |
| 5016 | __ Sltu(TMP, rhs_high, lhs_high); |
| 5017 | __ Sltu(AT, lhs_low, rhs_low); |
| 5018 | __ Slt(TMP, TMP, AT); |
| 5019 | __ Sltu(AT, lhs_high, rhs_high); |
| 5020 | __ Or(dst, AT, TMP); |
| 5021 | if (cond == kCondAE) { |
| 5022 | __ Xori(dst, dst, 1); |
| 5023 | } |
| 5024 | break; |
| 5025 | case kCondA: |
| 5026 | case kCondBE: |
| 5027 | __ Sltu(TMP, lhs_high, rhs_high); |
| 5028 | __ Sltu(AT, rhs_low, lhs_low); |
| 5029 | __ Slt(TMP, TMP, AT); |
| 5030 | __ Sltu(AT, rhs_high, lhs_high); |
| 5031 | __ Or(dst, AT, TMP); |
| 5032 | if (cond == kCondBE) { |
| 5033 | __ Xori(dst, dst, 1); |
| 5034 | } |
| 5035 | break; |
| 5036 | } |
| 5037 | } |
| 5038 | } |
| 5039 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5040 | void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond, |
| 5041 | LocationSummary* locations, |
| 5042 | MipsLabel* label) { |
| 5043 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 5044 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 5045 | Location rhs_location = locations->InAt(1); |
| 5046 | Register rhs_high = ZERO; |
| 5047 | Register rhs_low = ZERO; |
| 5048 | int64_t imm = 0; |
| 5049 | uint32_t imm_high = 0; |
| 5050 | uint32_t imm_low = 0; |
| 5051 | bool use_imm = rhs_location.IsConstant(); |
| 5052 | if (use_imm) { |
| 5053 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 5054 | imm_high = High32Bits(imm); |
| 5055 | imm_low = Low32Bits(imm); |
| 5056 | } else { |
| 5057 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 5058 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 5059 | } |
| 5060 | |
| 5061 | if (use_imm && imm == 0) { |
| 5062 | switch (cond) { |
| 5063 | case kCondEQ: |
| 5064 | case kCondBE: // <= 0 if zero |
| 5065 | __ Or(TMP, lhs_high, lhs_low); |
| 5066 | __ Beqz(TMP, label); |
| 5067 | break; |
| 5068 | case kCondNE: |
| 5069 | case kCondA: // > 0 if non-zero |
| 5070 | __ Or(TMP, lhs_high, lhs_low); |
| 5071 | __ Bnez(TMP, label); |
| 5072 | break; |
| 5073 | case kCondLT: |
| 5074 | __ Bltz(lhs_high, label); |
| 5075 | break; |
| 5076 | case kCondGE: |
| 5077 | __ Bgez(lhs_high, label); |
| 5078 | break; |
| 5079 | case kCondLE: |
| 5080 | __ Or(TMP, lhs_high, lhs_low); |
| 5081 | __ Sra(AT, lhs_high, 31); |
| 5082 | __ Bgeu(AT, TMP, label); |
| 5083 | break; |
| 5084 | case kCondGT: |
| 5085 | __ Or(TMP, lhs_high, lhs_low); |
| 5086 | __ Sra(AT, lhs_high, 31); |
| 5087 | __ Bltu(AT, TMP, label); |
| 5088 | break; |
| 5089 | case kCondB: // always false |
| 5090 | break; |
| 5091 | case kCondAE: // always true |
| 5092 | __ B(label); |
| 5093 | break; |
| 5094 | } |
| 5095 | } else if (use_imm) { |
| 5096 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 5097 | switch (cond) { |
| 5098 | case kCondEQ: |
| 5099 | __ LoadConst32(TMP, imm_high); |
| 5100 | __ Xor(TMP, TMP, lhs_high); |
| 5101 | __ LoadConst32(AT, imm_low); |
| 5102 | __ Xor(AT, AT, lhs_low); |
| 5103 | __ Or(TMP, TMP, AT); |
| 5104 | __ Beqz(TMP, label); |
| 5105 | break; |
| 5106 | case kCondNE: |
| 5107 | __ LoadConst32(TMP, imm_high); |
| 5108 | __ Xor(TMP, TMP, lhs_high); |
| 5109 | __ LoadConst32(AT, imm_low); |
| 5110 | __ Xor(AT, AT, lhs_low); |
| 5111 | __ Or(TMP, TMP, AT); |
| 5112 | __ Bnez(TMP, label); |
| 5113 | break; |
| 5114 | case kCondLT: |
| 5115 | __ LoadConst32(TMP, imm_high); |
| 5116 | __ Blt(lhs_high, TMP, label); |
| 5117 | __ Slt(TMP, TMP, lhs_high); |
| 5118 | __ LoadConst32(AT, imm_low); |
| 5119 | __ Sltu(AT, lhs_low, AT); |
| 5120 | __ Blt(TMP, AT, label); |
| 5121 | break; |
| 5122 | case kCondGE: |
| 5123 | __ LoadConst32(TMP, imm_high); |
| 5124 | __ Blt(TMP, lhs_high, label); |
| 5125 | __ Slt(TMP, lhs_high, TMP); |
| 5126 | __ LoadConst32(AT, imm_low); |
| 5127 | __ Sltu(AT, lhs_low, AT); |
| 5128 | __ Or(TMP, TMP, AT); |
| 5129 | __ Beqz(TMP, label); |
| 5130 | break; |
| 5131 | case kCondLE: |
| 5132 | __ LoadConst32(TMP, imm_high); |
| 5133 | __ Blt(lhs_high, TMP, label); |
| 5134 | __ Slt(TMP, TMP, lhs_high); |
| 5135 | __ LoadConst32(AT, imm_low); |
| 5136 | __ Sltu(AT, AT, lhs_low); |
| 5137 | __ Or(TMP, TMP, AT); |
| 5138 | __ Beqz(TMP, label); |
| 5139 | break; |
| 5140 | case kCondGT: |
| 5141 | __ LoadConst32(TMP, imm_high); |
| 5142 | __ Blt(TMP, lhs_high, label); |
| 5143 | __ Slt(TMP, lhs_high, TMP); |
| 5144 | __ LoadConst32(AT, imm_low); |
| 5145 | __ Sltu(AT, AT, lhs_low); |
| 5146 | __ Blt(TMP, AT, label); |
| 5147 | break; |
| 5148 | case kCondB: |
| 5149 | __ LoadConst32(TMP, imm_high); |
| 5150 | __ Bltu(lhs_high, TMP, label); |
| 5151 | __ Sltu(TMP, TMP, lhs_high); |
| 5152 | __ LoadConst32(AT, imm_low); |
| 5153 | __ Sltu(AT, lhs_low, AT); |
| 5154 | __ Blt(TMP, AT, label); |
| 5155 | break; |
| 5156 | case kCondAE: |
| 5157 | __ LoadConst32(TMP, imm_high); |
| 5158 | __ Bltu(TMP, lhs_high, label); |
| 5159 | __ Sltu(TMP, lhs_high, TMP); |
| 5160 | __ LoadConst32(AT, imm_low); |
| 5161 | __ Sltu(AT, lhs_low, AT); |
| 5162 | __ Or(TMP, TMP, AT); |
| 5163 | __ Beqz(TMP, label); |
| 5164 | break; |
| 5165 | case kCondBE: |
| 5166 | __ LoadConst32(TMP, imm_high); |
| 5167 | __ Bltu(lhs_high, TMP, label); |
| 5168 | __ Sltu(TMP, TMP, lhs_high); |
| 5169 | __ LoadConst32(AT, imm_low); |
| 5170 | __ Sltu(AT, AT, lhs_low); |
| 5171 | __ Or(TMP, TMP, AT); |
| 5172 | __ Beqz(TMP, label); |
| 5173 | break; |
| 5174 | case kCondA: |
| 5175 | __ LoadConst32(TMP, imm_high); |
| 5176 | __ Bltu(TMP, lhs_high, label); |
| 5177 | __ Sltu(TMP, lhs_high, TMP); |
| 5178 | __ LoadConst32(AT, imm_low); |
| 5179 | __ Sltu(AT, AT, lhs_low); |
| 5180 | __ Blt(TMP, AT, label); |
| 5181 | break; |
| 5182 | } |
| 5183 | } else { |
| 5184 | switch (cond) { |
| 5185 | case kCondEQ: |
| 5186 | __ Xor(TMP, lhs_high, rhs_high); |
| 5187 | __ Xor(AT, lhs_low, rhs_low); |
| 5188 | __ Or(TMP, TMP, AT); |
| 5189 | __ Beqz(TMP, label); |
| 5190 | break; |
| 5191 | case kCondNE: |
| 5192 | __ Xor(TMP, lhs_high, rhs_high); |
| 5193 | __ Xor(AT, lhs_low, rhs_low); |
| 5194 | __ Or(TMP, TMP, AT); |
| 5195 | __ Bnez(TMP, label); |
| 5196 | break; |
| 5197 | case kCondLT: |
| 5198 | __ Blt(lhs_high, rhs_high, label); |
| 5199 | __ Slt(TMP, rhs_high, lhs_high); |
| 5200 | __ Sltu(AT, lhs_low, rhs_low); |
| 5201 | __ Blt(TMP, AT, label); |
| 5202 | break; |
| 5203 | case kCondGE: |
| 5204 | __ Blt(rhs_high, lhs_high, label); |
| 5205 | __ Slt(TMP, lhs_high, rhs_high); |
| 5206 | __ Sltu(AT, lhs_low, rhs_low); |
| 5207 | __ Or(TMP, TMP, AT); |
| 5208 | __ Beqz(TMP, label); |
| 5209 | break; |
| 5210 | case kCondLE: |
| 5211 | __ Blt(lhs_high, rhs_high, label); |
| 5212 | __ Slt(TMP, rhs_high, lhs_high); |
| 5213 | __ Sltu(AT, rhs_low, lhs_low); |
| 5214 | __ Or(TMP, TMP, AT); |
| 5215 | __ Beqz(TMP, label); |
| 5216 | break; |
| 5217 | case kCondGT: |
| 5218 | __ Blt(rhs_high, lhs_high, label); |
| 5219 | __ Slt(TMP, lhs_high, rhs_high); |
| 5220 | __ Sltu(AT, rhs_low, lhs_low); |
| 5221 | __ Blt(TMP, AT, label); |
| 5222 | break; |
| 5223 | case kCondB: |
| 5224 | __ Bltu(lhs_high, rhs_high, label); |
| 5225 | __ Sltu(TMP, rhs_high, lhs_high); |
| 5226 | __ Sltu(AT, lhs_low, rhs_low); |
| 5227 | __ Blt(TMP, AT, label); |
| 5228 | break; |
| 5229 | case kCondAE: |
| 5230 | __ Bltu(rhs_high, lhs_high, label); |
| 5231 | __ Sltu(TMP, lhs_high, rhs_high); |
| 5232 | __ Sltu(AT, lhs_low, rhs_low); |
| 5233 | __ Or(TMP, TMP, AT); |
| 5234 | __ Beqz(TMP, label); |
| 5235 | break; |
| 5236 | case kCondBE: |
| 5237 | __ Bltu(lhs_high, rhs_high, label); |
| 5238 | __ Sltu(TMP, rhs_high, lhs_high); |
| 5239 | __ Sltu(AT, rhs_low, lhs_low); |
| 5240 | __ Or(TMP, TMP, AT); |
| 5241 | __ Beqz(TMP, label); |
| 5242 | break; |
| 5243 | case kCondA: |
| 5244 | __ Bltu(rhs_high, lhs_high, label); |
| 5245 | __ Sltu(TMP, lhs_high, rhs_high); |
| 5246 | __ Sltu(AT, rhs_low, lhs_low); |
| 5247 | __ Blt(TMP, AT, label); |
| 5248 | break; |
| 5249 | } |
| 5250 | } |
| 5251 | } |
| 5252 | |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5253 | void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond, |
| 5254 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5255 | DataType::Type type, |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5256 | LocationSummary* locations) { |
| 5257 | Register dst = locations->Out().AsRegister<Register>(); |
| 5258 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5259 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5260 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5261 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5262 | if (isR6) { |
| 5263 | switch (cond) { |
| 5264 | case kCondEQ: |
| 5265 | __ CmpEqS(FTMP, lhs, rhs); |
| 5266 | __ Mfc1(dst, FTMP); |
| 5267 | __ Andi(dst, dst, 1); |
| 5268 | break; |
| 5269 | case kCondNE: |
| 5270 | __ CmpEqS(FTMP, lhs, rhs); |
| 5271 | __ Mfc1(dst, FTMP); |
| 5272 | __ Addiu(dst, dst, 1); |
| 5273 | break; |
| 5274 | case kCondLT: |
| 5275 | if (gt_bias) { |
| 5276 | __ CmpLtS(FTMP, lhs, rhs); |
| 5277 | } else { |
| 5278 | __ CmpUltS(FTMP, lhs, rhs); |
| 5279 | } |
| 5280 | __ Mfc1(dst, FTMP); |
| 5281 | __ Andi(dst, dst, 1); |
| 5282 | break; |
| 5283 | case kCondLE: |
| 5284 | if (gt_bias) { |
| 5285 | __ CmpLeS(FTMP, lhs, rhs); |
| 5286 | } else { |
| 5287 | __ CmpUleS(FTMP, lhs, rhs); |
| 5288 | } |
| 5289 | __ Mfc1(dst, FTMP); |
| 5290 | __ Andi(dst, dst, 1); |
| 5291 | break; |
| 5292 | case kCondGT: |
| 5293 | if (gt_bias) { |
| 5294 | __ CmpUltS(FTMP, rhs, lhs); |
| 5295 | } else { |
| 5296 | __ CmpLtS(FTMP, rhs, lhs); |
| 5297 | } |
| 5298 | __ Mfc1(dst, FTMP); |
| 5299 | __ Andi(dst, dst, 1); |
| 5300 | break; |
| 5301 | case kCondGE: |
| 5302 | if (gt_bias) { |
| 5303 | __ CmpUleS(FTMP, rhs, lhs); |
| 5304 | } else { |
| 5305 | __ CmpLeS(FTMP, rhs, lhs); |
| 5306 | } |
| 5307 | __ Mfc1(dst, FTMP); |
| 5308 | __ Andi(dst, dst, 1); |
| 5309 | break; |
| 5310 | default: |
| 5311 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5312 | UNREACHABLE(); |
| 5313 | } |
| 5314 | } else { |
| 5315 | switch (cond) { |
| 5316 | case kCondEQ: |
| 5317 | __ CeqS(0, lhs, rhs); |
| 5318 | __ LoadConst32(dst, 1); |
| 5319 | __ Movf(dst, ZERO, 0); |
| 5320 | break; |
| 5321 | case kCondNE: |
| 5322 | __ CeqS(0, lhs, rhs); |
| 5323 | __ LoadConst32(dst, 1); |
| 5324 | __ Movt(dst, ZERO, 0); |
| 5325 | break; |
| 5326 | case kCondLT: |
| 5327 | if (gt_bias) { |
| 5328 | __ ColtS(0, lhs, rhs); |
| 5329 | } else { |
| 5330 | __ CultS(0, lhs, rhs); |
| 5331 | } |
| 5332 | __ LoadConst32(dst, 1); |
| 5333 | __ Movf(dst, ZERO, 0); |
| 5334 | break; |
| 5335 | case kCondLE: |
| 5336 | if (gt_bias) { |
| 5337 | __ ColeS(0, lhs, rhs); |
| 5338 | } else { |
| 5339 | __ CuleS(0, lhs, rhs); |
| 5340 | } |
| 5341 | __ LoadConst32(dst, 1); |
| 5342 | __ Movf(dst, ZERO, 0); |
| 5343 | break; |
| 5344 | case kCondGT: |
| 5345 | if (gt_bias) { |
| 5346 | __ CultS(0, rhs, lhs); |
| 5347 | } else { |
| 5348 | __ ColtS(0, rhs, lhs); |
| 5349 | } |
| 5350 | __ LoadConst32(dst, 1); |
| 5351 | __ Movf(dst, ZERO, 0); |
| 5352 | break; |
| 5353 | case kCondGE: |
| 5354 | if (gt_bias) { |
| 5355 | __ CuleS(0, rhs, lhs); |
| 5356 | } else { |
| 5357 | __ ColeS(0, rhs, lhs); |
| 5358 | } |
| 5359 | __ LoadConst32(dst, 1); |
| 5360 | __ Movf(dst, ZERO, 0); |
| 5361 | break; |
| 5362 | default: |
| 5363 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5364 | UNREACHABLE(); |
| 5365 | } |
| 5366 | } |
| 5367 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5368 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5369 | if (isR6) { |
| 5370 | switch (cond) { |
| 5371 | case kCondEQ: |
| 5372 | __ CmpEqD(FTMP, lhs, rhs); |
| 5373 | __ Mfc1(dst, FTMP); |
| 5374 | __ Andi(dst, dst, 1); |
| 5375 | break; |
| 5376 | case kCondNE: |
| 5377 | __ CmpEqD(FTMP, lhs, rhs); |
| 5378 | __ Mfc1(dst, FTMP); |
| 5379 | __ Addiu(dst, dst, 1); |
| 5380 | break; |
| 5381 | case kCondLT: |
| 5382 | if (gt_bias) { |
| 5383 | __ CmpLtD(FTMP, lhs, rhs); |
| 5384 | } else { |
| 5385 | __ CmpUltD(FTMP, lhs, rhs); |
| 5386 | } |
| 5387 | __ Mfc1(dst, FTMP); |
| 5388 | __ Andi(dst, dst, 1); |
| 5389 | break; |
| 5390 | case kCondLE: |
| 5391 | if (gt_bias) { |
| 5392 | __ CmpLeD(FTMP, lhs, rhs); |
| 5393 | } else { |
| 5394 | __ CmpUleD(FTMP, lhs, rhs); |
| 5395 | } |
| 5396 | __ Mfc1(dst, FTMP); |
| 5397 | __ Andi(dst, dst, 1); |
| 5398 | break; |
| 5399 | case kCondGT: |
| 5400 | if (gt_bias) { |
| 5401 | __ CmpUltD(FTMP, rhs, lhs); |
| 5402 | } else { |
| 5403 | __ CmpLtD(FTMP, rhs, lhs); |
| 5404 | } |
| 5405 | __ Mfc1(dst, FTMP); |
| 5406 | __ Andi(dst, dst, 1); |
| 5407 | break; |
| 5408 | case kCondGE: |
| 5409 | if (gt_bias) { |
| 5410 | __ CmpUleD(FTMP, rhs, lhs); |
| 5411 | } else { |
| 5412 | __ CmpLeD(FTMP, rhs, lhs); |
| 5413 | } |
| 5414 | __ Mfc1(dst, FTMP); |
| 5415 | __ Andi(dst, dst, 1); |
| 5416 | break; |
| 5417 | default: |
| 5418 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5419 | UNREACHABLE(); |
| 5420 | } |
| 5421 | } else { |
| 5422 | switch (cond) { |
| 5423 | case kCondEQ: |
| 5424 | __ CeqD(0, lhs, rhs); |
| 5425 | __ LoadConst32(dst, 1); |
| 5426 | __ Movf(dst, ZERO, 0); |
| 5427 | break; |
| 5428 | case kCondNE: |
| 5429 | __ CeqD(0, lhs, rhs); |
| 5430 | __ LoadConst32(dst, 1); |
| 5431 | __ Movt(dst, ZERO, 0); |
| 5432 | break; |
| 5433 | case kCondLT: |
| 5434 | if (gt_bias) { |
| 5435 | __ ColtD(0, lhs, rhs); |
| 5436 | } else { |
| 5437 | __ CultD(0, lhs, rhs); |
| 5438 | } |
| 5439 | __ LoadConst32(dst, 1); |
| 5440 | __ Movf(dst, ZERO, 0); |
| 5441 | break; |
| 5442 | case kCondLE: |
| 5443 | if (gt_bias) { |
| 5444 | __ ColeD(0, lhs, rhs); |
| 5445 | } else { |
| 5446 | __ CuleD(0, lhs, rhs); |
| 5447 | } |
| 5448 | __ LoadConst32(dst, 1); |
| 5449 | __ Movf(dst, ZERO, 0); |
| 5450 | break; |
| 5451 | case kCondGT: |
| 5452 | if (gt_bias) { |
| 5453 | __ CultD(0, rhs, lhs); |
| 5454 | } else { |
| 5455 | __ ColtD(0, rhs, lhs); |
| 5456 | } |
| 5457 | __ LoadConst32(dst, 1); |
| 5458 | __ Movf(dst, ZERO, 0); |
| 5459 | break; |
| 5460 | case kCondGE: |
| 5461 | if (gt_bias) { |
| 5462 | __ CuleD(0, rhs, lhs); |
| 5463 | } else { |
| 5464 | __ ColeD(0, rhs, lhs); |
| 5465 | } |
| 5466 | __ LoadConst32(dst, 1); |
| 5467 | __ Movf(dst, ZERO, 0); |
| 5468 | break; |
| 5469 | default: |
| 5470 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5471 | UNREACHABLE(); |
| 5472 | } |
| 5473 | } |
| 5474 | } |
| 5475 | } |
| 5476 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5477 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond, |
| 5478 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5479 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5480 | LocationSummary* input_locations, |
| 5481 | int cc) { |
| 5482 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5483 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5484 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5485 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5486 | switch (cond) { |
| 5487 | case kCondEQ: |
| 5488 | __ CeqS(cc, lhs, rhs); |
| 5489 | return false; |
| 5490 | case kCondNE: |
| 5491 | __ CeqS(cc, lhs, rhs); |
| 5492 | return true; |
| 5493 | case kCondLT: |
| 5494 | if (gt_bias) { |
| 5495 | __ ColtS(cc, lhs, rhs); |
| 5496 | } else { |
| 5497 | __ CultS(cc, lhs, rhs); |
| 5498 | } |
| 5499 | return false; |
| 5500 | case kCondLE: |
| 5501 | if (gt_bias) { |
| 5502 | __ ColeS(cc, lhs, rhs); |
| 5503 | } else { |
| 5504 | __ CuleS(cc, lhs, rhs); |
| 5505 | } |
| 5506 | return false; |
| 5507 | case kCondGT: |
| 5508 | if (gt_bias) { |
| 5509 | __ CultS(cc, rhs, lhs); |
| 5510 | } else { |
| 5511 | __ ColtS(cc, rhs, lhs); |
| 5512 | } |
| 5513 | return false; |
| 5514 | case kCondGE: |
| 5515 | if (gt_bias) { |
| 5516 | __ CuleS(cc, rhs, lhs); |
| 5517 | } else { |
| 5518 | __ ColeS(cc, rhs, lhs); |
| 5519 | } |
| 5520 | return false; |
| 5521 | default: |
| 5522 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5523 | UNREACHABLE(); |
| 5524 | } |
| 5525 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5526 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5527 | switch (cond) { |
| 5528 | case kCondEQ: |
| 5529 | __ CeqD(cc, lhs, rhs); |
| 5530 | return false; |
| 5531 | case kCondNE: |
| 5532 | __ CeqD(cc, lhs, rhs); |
| 5533 | return true; |
| 5534 | case kCondLT: |
| 5535 | if (gt_bias) { |
| 5536 | __ ColtD(cc, lhs, rhs); |
| 5537 | } else { |
| 5538 | __ CultD(cc, lhs, rhs); |
| 5539 | } |
| 5540 | return false; |
| 5541 | case kCondLE: |
| 5542 | if (gt_bias) { |
| 5543 | __ ColeD(cc, lhs, rhs); |
| 5544 | } else { |
| 5545 | __ CuleD(cc, lhs, rhs); |
| 5546 | } |
| 5547 | return false; |
| 5548 | case kCondGT: |
| 5549 | if (gt_bias) { |
| 5550 | __ CultD(cc, rhs, lhs); |
| 5551 | } else { |
| 5552 | __ ColtD(cc, rhs, lhs); |
| 5553 | } |
| 5554 | return false; |
| 5555 | case kCondGE: |
| 5556 | if (gt_bias) { |
| 5557 | __ CuleD(cc, rhs, lhs); |
| 5558 | } else { |
| 5559 | __ ColeD(cc, rhs, lhs); |
| 5560 | } |
| 5561 | return false; |
| 5562 | default: |
| 5563 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5564 | UNREACHABLE(); |
| 5565 | } |
| 5566 | } |
| 5567 | } |
| 5568 | |
| 5569 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond, |
| 5570 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5571 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5572 | LocationSummary* input_locations, |
| 5573 | FRegister dst) { |
| 5574 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5575 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5576 | CHECK(codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5577 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5578 | switch (cond) { |
| 5579 | case kCondEQ: |
| 5580 | __ CmpEqS(dst, lhs, rhs); |
| 5581 | return false; |
| 5582 | case kCondNE: |
| 5583 | __ CmpEqS(dst, lhs, rhs); |
| 5584 | return true; |
| 5585 | case kCondLT: |
| 5586 | if (gt_bias) { |
| 5587 | __ CmpLtS(dst, lhs, rhs); |
| 5588 | } else { |
| 5589 | __ CmpUltS(dst, lhs, rhs); |
| 5590 | } |
| 5591 | return false; |
| 5592 | case kCondLE: |
| 5593 | if (gt_bias) { |
| 5594 | __ CmpLeS(dst, lhs, rhs); |
| 5595 | } else { |
| 5596 | __ CmpUleS(dst, lhs, rhs); |
| 5597 | } |
| 5598 | return false; |
| 5599 | case kCondGT: |
| 5600 | if (gt_bias) { |
| 5601 | __ CmpUltS(dst, rhs, lhs); |
| 5602 | } else { |
| 5603 | __ CmpLtS(dst, rhs, lhs); |
| 5604 | } |
| 5605 | return false; |
| 5606 | case kCondGE: |
| 5607 | if (gt_bias) { |
| 5608 | __ CmpUleS(dst, rhs, lhs); |
| 5609 | } else { |
| 5610 | __ CmpLeS(dst, rhs, lhs); |
| 5611 | } |
| 5612 | return false; |
| 5613 | default: |
| 5614 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5615 | UNREACHABLE(); |
| 5616 | } |
| 5617 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5618 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5619 | switch (cond) { |
| 5620 | case kCondEQ: |
| 5621 | __ CmpEqD(dst, lhs, rhs); |
| 5622 | return false; |
| 5623 | case kCondNE: |
| 5624 | __ CmpEqD(dst, lhs, rhs); |
| 5625 | return true; |
| 5626 | case kCondLT: |
| 5627 | if (gt_bias) { |
| 5628 | __ CmpLtD(dst, lhs, rhs); |
| 5629 | } else { |
| 5630 | __ CmpUltD(dst, lhs, rhs); |
| 5631 | } |
| 5632 | return false; |
| 5633 | case kCondLE: |
| 5634 | if (gt_bias) { |
| 5635 | __ CmpLeD(dst, lhs, rhs); |
| 5636 | } else { |
| 5637 | __ CmpUleD(dst, lhs, rhs); |
| 5638 | } |
| 5639 | return false; |
| 5640 | case kCondGT: |
| 5641 | if (gt_bias) { |
| 5642 | __ CmpUltD(dst, rhs, lhs); |
| 5643 | } else { |
| 5644 | __ CmpLtD(dst, rhs, lhs); |
| 5645 | } |
| 5646 | return false; |
| 5647 | case kCondGE: |
| 5648 | if (gt_bias) { |
| 5649 | __ CmpUleD(dst, rhs, lhs); |
| 5650 | } else { |
| 5651 | __ CmpLeD(dst, rhs, lhs); |
| 5652 | } |
| 5653 | return false; |
| 5654 | default: |
| 5655 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5656 | UNREACHABLE(); |
| 5657 | } |
| 5658 | } |
| 5659 | } |
| 5660 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5661 | void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond, |
| 5662 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5663 | DataType::Type type, |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5664 | LocationSummary* locations, |
| 5665 | MipsLabel* label) { |
| 5666 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5667 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5668 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5669 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5670 | if (isR6) { |
| 5671 | switch (cond) { |
| 5672 | case kCondEQ: |
| 5673 | __ CmpEqS(FTMP, lhs, rhs); |
| 5674 | __ Bc1nez(FTMP, label); |
| 5675 | break; |
| 5676 | case kCondNE: |
| 5677 | __ CmpEqS(FTMP, lhs, rhs); |
| 5678 | __ Bc1eqz(FTMP, label); |
| 5679 | break; |
| 5680 | case kCondLT: |
| 5681 | if (gt_bias) { |
| 5682 | __ CmpLtS(FTMP, lhs, rhs); |
| 5683 | } else { |
| 5684 | __ CmpUltS(FTMP, lhs, rhs); |
| 5685 | } |
| 5686 | __ Bc1nez(FTMP, label); |
| 5687 | break; |
| 5688 | case kCondLE: |
| 5689 | if (gt_bias) { |
| 5690 | __ CmpLeS(FTMP, lhs, rhs); |
| 5691 | } else { |
| 5692 | __ CmpUleS(FTMP, lhs, rhs); |
| 5693 | } |
| 5694 | __ Bc1nez(FTMP, label); |
| 5695 | break; |
| 5696 | case kCondGT: |
| 5697 | if (gt_bias) { |
| 5698 | __ CmpUltS(FTMP, rhs, lhs); |
| 5699 | } else { |
| 5700 | __ CmpLtS(FTMP, rhs, lhs); |
| 5701 | } |
| 5702 | __ Bc1nez(FTMP, label); |
| 5703 | break; |
| 5704 | case kCondGE: |
| 5705 | if (gt_bias) { |
| 5706 | __ CmpUleS(FTMP, rhs, lhs); |
| 5707 | } else { |
| 5708 | __ CmpLeS(FTMP, rhs, lhs); |
| 5709 | } |
| 5710 | __ Bc1nez(FTMP, label); |
| 5711 | break; |
| 5712 | default: |
| 5713 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5714 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5715 | } |
| 5716 | } else { |
| 5717 | switch (cond) { |
| 5718 | case kCondEQ: |
| 5719 | __ CeqS(0, lhs, rhs); |
| 5720 | __ Bc1t(0, label); |
| 5721 | break; |
| 5722 | case kCondNE: |
| 5723 | __ CeqS(0, lhs, rhs); |
| 5724 | __ Bc1f(0, label); |
| 5725 | break; |
| 5726 | case kCondLT: |
| 5727 | if (gt_bias) { |
| 5728 | __ ColtS(0, lhs, rhs); |
| 5729 | } else { |
| 5730 | __ CultS(0, lhs, rhs); |
| 5731 | } |
| 5732 | __ Bc1t(0, label); |
| 5733 | break; |
| 5734 | case kCondLE: |
| 5735 | if (gt_bias) { |
| 5736 | __ ColeS(0, lhs, rhs); |
| 5737 | } else { |
| 5738 | __ CuleS(0, lhs, rhs); |
| 5739 | } |
| 5740 | __ Bc1t(0, label); |
| 5741 | break; |
| 5742 | case kCondGT: |
| 5743 | if (gt_bias) { |
| 5744 | __ CultS(0, rhs, lhs); |
| 5745 | } else { |
| 5746 | __ ColtS(0, rhs, lhs); |
| 5747 | } |
| 5748 | __ Bc1t(0, label); |
| 5749 | break; |
| 5750 | case kCondGE: |
| 5751 | if (gt_bias) { |
| 5752 | __ CuleS(0, rhs, lhs); |
| 5753 | } else { |
| 5754 | __ ColeS(0, rhs, lhs); |
| 5755 | } |
| 5756 | __ Bc1t(0, label); |
| 5757 | break; |
| 5758 | default: |
| 5759 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5760 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5761 | } |
| 5762 | } |
| 5763 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5764 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5765 | if (isR6) { |
| 5766 | switch (cond) { |
| 5767 | case kCondEQ: |
| 5768 | __ CmpEqD(FTMP, lhs, rhs); |
| 5769 | __ Bc1nez(FTMP, label); |
| 5770 | break; |
| 5771 | case kCondNE: |
| 5772 | __ CmpEqD(FTMP, lhs, rhs); |
| 5773 | __ Bc1eqz(FTMP, label); |
| 5774 | break; |
| 5775 | case kCondLT: |
| 5776 | if (gt_bias) { |
| 5777 | __ CmpLtD(FTMP, lhs, rhs); |
| 5778 | } else { |
| 5779 | __ CmpUltD(FTMP, lhs, rhs); |
| 5780 | } |
| 5781 | __ Bc1nez(FTMP, label); |
| 5782 | break; |
| 5783 | case kCondLE: |
| 5784 | if (gt_bias) { |
| 5785 | __ CmpLeD(FTMP, lhs, rhs); |
| 5786 | } else { |
| 5787 | __ CmpUleD(FTMP, lhs, rhs); |
| 5788 | } |
| 5789 | __ Bc1nez(FTMP, label); |
| 5790 | break; |
| 5791 | case kCondGT: |
| 5792 | if (gt_bias) { |
| 5793 | __ CmpUltD(FTMP, rhs, lhs); |
| 5794 | } else { |
| 5795 | __ CmpLtD(FTMP, rhs, lhs); |
| 5796 | } |
| 5797 | __ Bc1nez(FTMP, label); |
| 5798 | break; |
| 5799 | case kCondGE: |
| 5800 | if (gt_bias) { |
| 5801 | __ CmpUleD(FTMP, rhs, lhs); |
| 5802 | } else { |
| 5803 | __ CmpLeD(FTMP, rhs, lhs); |
| 5804 | } |
| 5805 | __ Bc1nez(FTMP, label); |
| 5806 | break; |
| 5807 | default: |
| 5808 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5809 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5810 | } |
| 5811 | } else { |
| 5812 | switch (cond) { |
| 5813 | case kCondEQ: |
| 5814 | __ CeqD(0, lhs, rhs); |
| 5815 | __ Bc1t(0, label); |
| 5816 | break; |
| 5817 | case kCondNE: |
| 5818 | __ CeqD(0, lhs, rhs); |
| 5819 | __ Bc1f(0, label); |
| 5820 | break; |
| 5821 | case kCondLT: |
| 5822 | if (gt_bias) { |
| 5823 | __ ColtD(0, lhs, rhs); |
| 5824 | } else { |
| 5825 | __ CultD(0, lhs, rhs); |
| 5826 | } |
| 5827 | __ Bc1t(0, label); |
| 5828 | break; |
| 5829 | case kCondLE: |
| 5830 | if (gt_bias) { |
| 5831 | __ ColeD(0, lhs, rhs); |
| 5832 | } else { |
| 5833 | __ CuleD(0, lhs, rhs); |
| 5834 | } |
| 5835 | __ Bc1t(0, label); |
| 5836 | break; |
| 5837 | case kCondGT: |
| 5838 | if (gt_bias) { |
| 5839 | __ CultD(0, rhs, lhs); |
| 5840 | } else { |
| 5841 | __ ColtD(0, rhs, lhs); |
| 5842 | } |
| 5843 | __ Bc1t(0, label); |
| 5844 | break; |
| 5845 | case kCondGE: |
| 5846 | if (gt_bias) { |
| 5847 | __ CuleD(0, rhs, lhs); |
| 5848 | } else { |
| 5849 | __ ColeD(0, rhs, lhs); |
| 5850 | } |
| 5851 | __ Bc1t(0, label); |
| 5852 | break; |
| 5853 | default: |
| 5854 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5855 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5856 | } |
| 5857 | } |
| 5858 | } |
| 5859 | } |
| 5860 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5861 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5862 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5863 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5864 | MipsLabel* false_target) { |
| 5865 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5866 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5867 | if (true_target == nullptr && false_target == nullptr) { |
| 5868 | // Nothing to do. The code always falls through. |
| 5869 | return; |
| 5870 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5871 | // Constant condition, statically compared against "true" (integer value 1). |
| 5872 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5873 | if (true_target != nullptr) { |
| 5874 | __ B(true_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5875 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5876 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5877 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5878 | if (false_target != nullptr) { |
| 5879 | __ B(false_target); |
| 5880 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5881 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5882 | return; |
| 5883 | } |
| 5884 | |
| 5885 | // The following code generates these patterns: |
| 5886 | // (1) true_target == nullptr && false_target != nullptr |
| 5887 | // - opposite condition true => branch to false_target |
| 5888 | // (2) true_target != nullptr && false_target == nullptr |
| 5889 | // - condition true => branch to true_target |
| 5890 | // (3) true_target != nullptr && false_target != nullptr |
| 5891 | // - condition true => branch to true_target |
| 5892 | // - branch to false_target |
| 5893 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5894 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5895 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5896 | DCHECK(cond_val.IsRegister()); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5897 | if (true_target == nullptr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5898 | __ Beqz(cond_val.AsRegister<Register>(), false_target); |
| 5899 | } else { |
| 5900 | __ Bnez(cond_val.AsRegister<Register>(), true_target); |
| 5901 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5902 | } else { |
| 5903 | // The condition instruction has not been materialized, use its inputs as |
| 5904 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5905 | HCondition* condition = cond->AsCondition(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5906 | DataType::Type type = condition->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5907 | LocationSummary* locations = cond->GetLocations(); |
| 5908 | IfCondition if_cond = condition->GetCondition(); |
| 5909 | MipsLabel* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5910 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5911 | if (true_target == nullptr) { |
| 5912 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5913 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5914 | } |
| 5915 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5916 | switch (type) { |
| 5917 | default: |
| 5918 | GenerateIntCompareAndBranch(if_cond, locations, branch_target); |
| 5919 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5920 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5921 | GenerateLongCompareAndBranch(if_cond, locations, branch_target); |
| 5922 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5923 | case DataType::Type::kFloat32: |
| 5924 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5925 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 5926 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5927 | } |
| 5928 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5929 | |
| 5930 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 5931 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 5932 | if (true_target != nullptr && false_target != nullptr) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5933 | __ B(false_target); |
| 5934 | } |
| 5935 | } |
| 5936 | |
| 5937 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5938 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5939 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5940 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5941 | } |
| 5942 | } |
| 5943 | |
| 5944 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5945 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 5946 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 5947 | MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 5948 | nullptr : codegen_->GetLabelOf(true_successor); |
| 5949 | MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 5950 | nullptr : codegen_->GetLabelOf(false_successor); |
| 5951 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5952 | } |
| 5953 | |
| 5954 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5955 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5956 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 5957 | InvokeRuntimeCallingConvention calling_convention; |
| 5958 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5959 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5960 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5961 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5962 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5963 | } |
| 5964 | } |
| 5965 | |
| 5966 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 5967 | SlowPathCodeMIPS* slow_path = |
| 5968 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5969 | GenerateTestAndBranch(deoptimize, |
| 5970 | /* condition_input_index */ 0, |
| 5971 | slow_path->GetEntryLabel(), |
| 5972 | /* false_target */ nullptr); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5973 | } |
| 5974 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5975 | // This function returns true if a conditional move can be generated for HSelect. |
| 5976 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 5977 | // branches and regular moves. |
| 5978 | // |
| 5979 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 5980 | // |
| 5981 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 5982 | // are two distinct tasks, this function does both because they share quite a bit |
| 5983 | // of common logic. |
| 5984 | static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) { |
| 5985 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 5986 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 5987 | HCondition* condition = cond->AsCondition(); |
| 5988 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5989 | DataType::Type cond_type = |
| 5990 | materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType(); |
| 5991 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5992 | |
| 5993 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 5994 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 5995 | bool is_true_value_zero_constant = |
| 5996 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 5997 | bool is_false_value_zero_constant = |
| 5998 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 5999 | |
| 6000 | bool can_move_conditionally = false; |
| 6001 | bool use_const_for_false_in = false; |
| 6002 | bool use_const_for_true_in = false; |
| 6003 | |
| 6004 | if (!cond->IsConstant()) { |
| 6005 | switch (cond_type) { |
| 6006 | default: |
| 6007 | switch (dst_type) { |
| 6008 | default: |
| 6009 | // Moving int on int condition. |
| 6010 | if (is_r6) { |
| 6011 | if (is_true_value_zero_constant) { |
| 6012 | // seleqz out_reg, false_reg, cond_reg |
| 6013 | can_move_conditionally = true; |
| 6014 | use_const_for_true_in = true; |
| 6015 | } else if (is_false_value_zero_constant) { |
| 6016 | // selnez out_reg, true_reg, cond_reg |
| 6017 | can_move_conditionally = true; |
| 6018 | use_const_for_false_in = true; |
| 6019 | } else if (materialized) { |
| 6020 | // Not materializing unmaterialized int conditions |
| 6021 | // to keep the instruction count low. |
| 6022 | // selnez AT, true_reg, cond_reg |
| 6023 | // seleqz TMP, false_reg, cond_reg |
| 6024 | // or out_reg, AT, TMP |
| 6025 | can_move_conditionally = true; |
| 6026 | } |
| 6027 | } else { |
| 6028 | // movn out_reg, true_reg/ZERO, cond_reg |
| 6029 | can_move_conditionally = true; |
| 6030 | use_const_for_true_in = is_true_value_zero_constant; |
| 6031 | } |
| 6032 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6033 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6034 | // Moving long on int condition. |
| 6035 | if (is_r6) { |
| 6036 | if (is_true_value_zero_constant) { |
| 6037 | // seleqz out_reg_lo, false_reg_lo, cond_reg |
| 6038 | // seleqz out_reg_hi, false_reg_hi, cond_reg |
| 6039 | can_move_conditionally = true; |
| 6040 | use_const_for_true_in = true; |
| 6041 | } else if (is_false_value_zero_constant) { |
| 6042 | // selnez out_reg_lo, true_reg_lo, cond_reg |
| 6043 | // selnez out_reg_hi, true_reg_hi, cond_reg |
| 6044 | can_move_conditionally = true; |
| 6045 | use_const_for_false_in = true; |
| 6046 | } |
| 6047 | // Other long conditional moves would generate 6+ instructions, |
| 6048 | // which is too many. |
| 6049 | } else { |
| 6050 | // movn out_reg_lo, true_reg_lo/ZERO, cond_reg |
| 6051 | // movn out_reg_hi, true_reg_hi/ZERO, cond_reg |
| 6052 | can_move_conditionally = true; |
| 6053 | use_const_for_true_in = is_true_value_zero_constant; |
| 6054 | } |
| 6055 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6056 | case DataType::Type::kFloat32: |
| 6057 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6058 | // Moving float/double on int condition. |
| 6059 | if (is_r6) { |
| 6060 | if (materialized) { |
| 6061 | // Not materializing unmaterialized int conditions |
| 6062 | // to keep the instruction count low. |
| 6063 | can_move_conditionally = true; |
| 6064 | if (is_true_value_zero_constant) { |
| 6065 | // sltu TMP, ZERO, cond_reg |
| 6066 | // mtc1 TMP, temp_cond_reg |
| 6067 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 6068 | use_const_for_true_in = true; |
| 6069 | } else if (is_false_value_zero_constant) { |
| 6070 | // sltu TMP, ZERO, cond_reg |
| 6071 | // mtc1 TMP, temp_cond_reg |
| 6072 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 6073 | use_const_for_false_in = true; |
| 6074 | } else { |
| 6075 | // sltu TMP, ZERO, cond_reg |
| 6076 | // mtc1 TMP, temp_cond_reg |
| 6077 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 6078 | // mov.fmt out_reg, temp_cond_reg |
| 6079 | } |
| 6080 | } |
| 6081 | } else { |
| 6082 | // movn.fmt out_reg, true_reg, cond_reg |
| 6083 | can_move_conditionally = true; |
| 6084 | } |
| 6085 | break; |
| 6086 | } |
| 6087 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6088 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6089 | // We don't materialize long comparison now |
| 6090 | // and use conditional branches instead. |
| 6091 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6092 | case DataType::Type::kFloat32: |
| 6093 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6094 | switch (dst_type) { |
| 6095 | default: |
| 6096 | // Moving int on float/double condition. |
| 6097 | if (is_r6) { |
| 6098 | if (is_true_value_zero_constant) { |
| 6099 | // mfc1 TMP, temp_cond_reg |
| 6100 | // seleqz out_reg, false_reg, TMP |
| 6101 | can_move_conditionally = true; |
| 6102 | use_const_for_true_in = true; |
| 6103 | } else if (is_false_value_zero_constant) { |
| 6104 | // mfc1 TMP, temp_cond_reg |
| 6105 | // selnez out_reg, true_reg, TMP |
| 6106 | can_move_conditionally = true; |
| 6107 | use_const_for_false_in = true; |
| 6108 | } else { |
| 6109 | // mfc1 TMP, temp_cond_reg |
| 6110 | // selnez AT, true_reg, TMP |
| 6111 | // seleqz TMP, false_reg, TMP |
| 6112 | // or out_reg, AT, TMP |
| 6113 | can_move_conditionally = true; |
| 6114 | } |
| 6115 | } else { |
| 6116 | // movt out_reg, true_reg/ZERO, cc |
| 6117 | can_move_conditionally = true; |
| 6118 | use_const_for_true_in = is_true_value_zero_constant; |
| 6119 | } |
| 6120 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6121 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6122 | // Moving long on float/double condition. |
| 6123 | if (is_r6) { |
| 6124 | if (is_true_value_zero_constant) { |
| 6125 | // mfc1 TMP, temp_cond_reg |
| 6126 | // seleqz out_reg_lo, false_reg_lo, TMP |
| 6127 | // seleqz out_reg_hi, false_reg_hi, TMP |
| 6128 | can_move_conditionally = true; |
| 6129 | use_const_for_true_in = true; |
| 6130 | } else if (is_false_value_zero_constant) { |
| 6131 | // mfc1 TMP, temp_cond_reg |
| 6132 | // selnez out_reg_lo, true_reg_lo, TMP |
| 6133 | // selnez out_reg_hi, true_reg_hi, TMP |
| 6134 | can_move_conditionally = true; |
| 6135 | use_const_for_false_in = true; |
| 6136 | } |
| 6137 | // Other long conditional moves would generate 6+ instructions, |
| 6138 | // which is too many. |
| 6139 | } else { |
| 6140 | // movt out_reg_lo, true_reg_lo/ZERO, cc |
| 6141 | // movt out_reg_hi, true_reg_hi/ZERO, cc |
| 6142 | can_move_conditionally = true; |
| 6143 | use_const_for_true_in = is_true_value_zero_constant; |
| 6144 | } |
| 6145 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6146 | case DataType::Type::kFloat32: |
| 6147 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6148 | // Moving float/double on float/double condition. |
| 6149 | if (is_r6) { |
| 6150 | can_move_conditionally = true; |
| 6151 | if (is_true_value_zero_constant) { |
| 6152 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 6153 | use_const_for_true_in = true; |
| 6154 | } else if (is_false_value_zero_constant) { |
| 6155 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 6156 | use_const_for_false_in = true; |
| 6157 | } else { |
| 6158 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 6159 | // mov.fmt out_reg, temp_cond_reg |
| 6160 | } |
| 6161 | } else { |
| 6162 | // movt.fmt out_reg, true_reg, cc |
| 6163 | can_move_conditionally = true; |
| 6164 | } |
| 6165 | break; |
| 6166 | } |
| 6167 | break; |
| 6168 | } |
| 6169 | } |
| 6170 | |
| 6171 | if (can_move_conditionally) { |
| 6172 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 6173 | } else { |
| 6174 | DCHECK(!use_const_for_false_in); |
| 6175 | DCHECK(!use_const_for_true_in); |
| 6176 | } |
| 6177 | |
| 6178 | if (locations_to_set != nullptr) { |
| 6179 | if (use_const_for_false_in) { |
| 6180 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 6181 | } else { |
| 6182 | locations_to_set->SetInAt(0, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6183 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6184 | ? Location::RequiresFpuRegister() |
| 6185 | : Location::RequiresRegister()); |
| 6186 | } |
| 6187 | if (use_const_for_true_in) { |
| 6188 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 6189 | } else { |
| 6190 | locations_to_set->SetInAt(1, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6191 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6192 | ? Location::RequiresFpuRegister() |
| 6193 | : Location::RequiresRegister()); |
| 6194 | } |
| 6195 | if (materialized) { |
| 6196 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 6197 | } |
| 6198 | // On R6 we don't require the output to be the same as the |
| 6199 | // first input for conditional moves unlike on R2. |
| 6200 | bool is_out_same_as_first_in = !can_move_conditionally || !is_r6; |
| 6201 | if (is_out_same_as_first_in) { |
| 6202 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 6203 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6204 | locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6205 | ? Location::RequiresFpuRegister() |
| 6206 | : Location::RequiresRegister()); |
| 6207 | } |
| 6208 | } |
| 6209 | |
| 6210 | return can_move_conditionally; |
| 6211 | } |
| 6212 | |
| 6213 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) { |
| 6214 | LocationSummary* locations = select->GetLocations(); |
| 6215 | Location dst = locations->Out(); |
| 6216 | Location src = locations->InAt(1); |
| 6217 | Register src_reg = ZERO; |
| 6218 | Register src_reg_high = ZERO; |
| 6219 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 6220 | Register cond_reg = TMP; |
| 6221 | int cond_cc = 0; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6222 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6223 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6224 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6225 | |
| 6226 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 6227 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 6228 | } else { |
| 6229 | HCondition* condition = cond->AsCondition(); |
| 6230 | LocationSummary* cond_locations = cond->GetLocations(); |
| 6231 | IfCondition if_cond = condition->GetCondition(); |
| 6232 | cond_type = condition->InputAt(0)->GetType(); |
| 6233 | switch (cond_type) { |
| 6234 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6235 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6236 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 6237 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6238 | case DataType::Type::kFloat32: |
| 6239 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6240 | cond_inverted = MaterializeFpCompareR2(if_cond, |
| 6241 | condition->IsGtBias(), |
| 6242 | cond_type, |
| 6243 | cond_locations, |
| 6244 | cond_cc); |
| 6245 | break; |
| 6246 | } |
| 6247 | } |
| 6248 | |
| 6249 | DCHECK(dst.Equals(locations->InAt(0))); |
| 6250 | if (src.IsRegister()) { |
| 6251 | src_reg = src.AsRegister<Register>(); |
| 6252 | } else if (src.IsRegisterPair()) { |
| 6253 | src_reg = src.AsRegisterPairLow<Register>(); |
| 6254 | src_reg_high = src.AsRegisterPairHigh<Register>(); |
| 6255 | } else if (src.IsConstant()) { |
| 6256 | DCHECK(src.GetConstant()->IsZeroBitPattern()); |
| 6257 | } |
| 6258 | |
| 6259 | switch (cond_type) { |
| 6260 | default: |
| 6261 | switch (dst_type) { |
| 6262 | default: |
| 6263 | if (cond_inverted) { |
| 6264 | __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 6265 | } else { |
| 6266 | __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 6267 | } |
| 6268 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6269 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6270 | if (cond_inverted) { |
| 6271 | __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 6272 | __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 6273 | } else { |
| 6274 | __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 6275 | __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 6276 | } |
| 6277 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6278 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6279 | if (cond_inverted) { |
| 6280 | __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6281 | } else { |
| 6282 | __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6283 | } |
| 6284 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6285 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6286 | if (cond_inverted) { |
| 6287 | __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6288 | } else { |
| 6289 | __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6290 | } |
| 6291 | break; |
| 6292 | } |
| 6293 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6294 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6295 | LOG(FATAL) << "Unreachable"; |
| 6296 | UNREACHABLE(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6297 | case DataType::Type::kFloat32: |
| 6298 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6299 | switch (dst_type) { |
| 6300 | default: |
| 6301 | if (cond_inverted) { |
| 6302 | __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 6303 | } else { |
| 6304 | __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 6305 | } |
| 6306 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6307 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6308 | if (cond_inverted) { |
| 6309 | __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 6310 | __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 6311 | } else { |
| 6312 | __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 6313 | __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 6314 | } |
| 6315 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6316 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6317 | if (cond_inverted) { |
| 6318 | __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6319 | } else { |
| 6320 | __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6321 | } |
| 6322 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6323 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6324 | if (cond_inverted) { |
| 6325 | __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6326 | } else { |
| 6327 | __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6328 | } |
| 6329 | break; |
| 6330 | } |
| 6331 | break; |
| 6332 | } |
| 6333 | } |
| 6334 | |
| 6335 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) { |
| 6336 | LocationSummary* locations = select->GetLocations(); |
| 6337 | Location dst = locations->Out(); |
| 6338 | Location false_src = locations->InAt(0); |
| 6339 | Location true_src = locations->InAt(1); |
| 6340 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 6341 | Register cond_reg = TMP; |
| 6342 | FRegister fcond_reg = FTMP; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6343 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6344 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6345 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6346 | |
| 6347 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 6348 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 6349 | } else { |
| 6350 | HCondition* condition = cond->AsCondition(); |
| 6351 | LocationSummary* cond_locations = cond->GetLocations(); |
| 6352 | IfCondition if_cond = condition->GetCondition(); |
| 6353 | cond_type = condition->InputAt(0)->GetType(); |
| 6354 | switch (cond_type) { |
| 6355 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6356 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6357 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 6358 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6359 | case DataType::Type::kFloat32: |
| 6360 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6361 | cond_inverted = MaterializeFpCompareR6(if_cond, |
| 6362 | condition->IsGtBias(), |
| 6363 | cond_type, |
| 6364 | cond_locations, |
| 6365 | fcond_reg); |
| 6366 | break; |
| 6367 | } |
| 6368 | } |
| 6369 | |
| 6370 | if (true_src.IsConstant()) { |
| 6371 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 6372 | } |
| 6373 | if (false_src.IsConstant()) { |
| 6374 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 6375 | } |
| 6376 | |
| 6377 | switch (dst_type) { |
| 6378 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6379 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6380 | __ Mfc1(cond_reg, fcond_reg); |
| 6381 | } |
| 6382 | if (true_src.IsConstant()) { |
| 6383 | if (cond_inverted) { |
| 6384 | __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 6385 | } else { |
| 6386 | __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 6387 | } |
| 6388 | } else if (false_src.IsConstant()) { |
| 6389 | if (cond_inverted) { |
| 6390 | __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 6391 | } else { |
| 6392 | __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 6393 | } |
| 6394 | } else { |
| 6395 | DCHECK_NE(cond_reg, AT); |
| 6396 | if (cond_inverted) { |
| 6397 | __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6398 | __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6399 | } else { |
| 6400 | __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6401 | __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6402 | } |
| 6403 | __ Or(dst.AsRegister<Register>(), AT, TMP); |
| 6404 | } |
| 6405 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6406 | case DataType::Type::kInt64: { |
| 6407 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6408 | __ Mfc1(cond_reg, fcond_reg); |
| 6409 | } |
| 6410 | Register dst_lo = dst.AsRegisterPairLow<Register>(); |
| 6411 | Register dst_hi = dst.AsRegisterPairHigh<Register>(); |
| 6412 | if (true_src.IsConstant()) { |
| 6413 | Register src_lo = false_src.AsRegisterPairLow<Register>(); |
| 6414 | Register src_hi = false_src.AsRegisterPairHigh<Register>(); |
| 6415 | if (cond_inverted) { |
| 6416 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6417 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6418 | } else { |
| 6419 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6420 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6421 | } |
| 6422 | } else { |
| 6423 | DCHECK(false_src.IsConstant()); |
| 6424 | Register src_lo = true_src.AsRegisterPairLow<Register>(); |
| 6425 | Register src_hi = true_src.AsRegisterPairHigh<Register>(); |
| 6426 | if (cond_inverted) { |
| 6427 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6428 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6429 | } else { |
| 6430 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6431 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6432 | } |
| 6433 | } |
| 6434 | break; |
| 6435 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6436 | case DataType::Type::kFloat32: { |
| 6437 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6438 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6439 | __ Sltu(TMP, ZERO, cond_reg); |
| 6440 | __ Mtc1(TMP, fcond_reg); |
| 6441 | } |
| 6442 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6443 | if (true_src.IsConstant()) { |
| 6444 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6445 | if (cond_inverted) { |
| 6446 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6447 | } else { |
| 6448 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6449 | } |
| 6450 | } else if (false_src.IsConstant()) { |
| 6451 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6452 | if (cond_inverted) { |
| 6453 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6454 | } else { |
| 6455 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6456 | } |
| 6457 | } else { |
| 6458 | if (cond_inverted) { |
| 6459 | __ SelS(fcond_reg, |
| 6460 | true_src.AsFpuRegister<FRegister>(), |
| 6461 | false_src.AsFpuRegister<FRegister>()); |
| 6462 | } else { |
| 6463 | __ SelS(fcond_reg, |
| 6464 | false_src.AsFpuRegister<FRegister>(), |
| 6465 | true_src.AsFpuRegister<FRegister>()); |
| 6466 | } |
| 6467 | __ MovS(dst_reg, fcond_reg); |
| 6468 | } |
| 6469 | break; |
| 6470 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6471 | case DataType::Type::kFloat64: { |
| 6472 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6473 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6474 | __ Sltu(TMP, ZERO, cond_reg); |
| 6475 | __ Mtc1(TMP, fcond_reg); |
| 6476 | } |
| 6477 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6478 | if (true_src.IsConstant()) { |
| 6479 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6480 | if (cond_inverted) { |
| 6481 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6482 | } else { |
| 6483 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6484 | } |
| 6485 | } else if (false_src.IsConstant()) { |
| 6486 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6487 | if (cond_inverted) { |
| 6488 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6489 | } else { |
| 6490 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6491 | } |
| 6492 | } else { |
| 6493 | if (cond_inverted) { |
| 6494 | __ SelD(fcond_reg, |
| 6495 | true_src.AsFpuRegister<FRegister>(), |
| 6496 | false_src.AsFpuRegister<FRegister>()); |
| 6497 | } else { |
| 6498 | __ SelD(fcond_reg, |
| 6499 | false_src.AsFpuRegister<FRegister>(), |
| 6500 | true_src.AsFpuRegister<FRegister>()); |
| 6501 | } |
| 6502 | __ MovD(dst_reg, fcond_reg); |
| 6503 | } |
| 6504 | break; |
| 6505 | } |
| 6506 | } |
| 6507 | } |
| 6508 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6509 | void LocationsBuilderMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6510 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6511 | LocationSummary(flag, LocationSummary::kNoCall); |
| 6512 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6513 | } |
| 6514 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6515 | void InstructionCodeGeneratorMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 6516 | __ LoadFromOffset(kLoadWord, |
| 6517 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 6518 | SP, |
| 6519 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6520 | } |
| 6521 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6522 | void LocationsBuilderMIPS::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6523 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6524 | CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6525 | } |
| 6526 | |
| 6527 | void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6528 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 6529 | if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) { |
| 6530 | if (is_r6) { |
| 6531 | GenConditionalMoveR6(select); |
| 6532 | } else { |
| 6533 | GenConditionalMoveR2(select); |
| 6534 | } |
| 6535 | } else { |
| 6536 | LocationSummary* locations = select->GetLocations(); |
| 6537 | MipsLabel false_target; |
| 6538 | GenerateTestAndBranch(select, |
| 6539 | /* condition_input_index */ 2, |
| 6540 | /* true_target */ nullptr, |
| 6541 | &false_target); |
| 6542 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 6543 | __ Bind(&false_target); |
| 6544 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6545 | } |
| 6546 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6547 | void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6548 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6549 | } |
| 6550 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 6551 | void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 6552 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 6553 | } |
| 6554 | |
| 6555 | void CodeGeneratorMIPS::GenerateNop() { |
| 6556 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6557 | } |
| 6558 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6559 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6560 | DataType::Type field_type = field_info.GetFieldType(); |
| 6561 | bool is_wide = (field_type == DataType::Type::kInt64) || (field_type == DataType::Type::kFloat64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6562 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6563 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6564 | kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6565 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6566 | instruction, |
| 6567 | generate_volatile |
| 6568 | ? LocationSummary::kCallOnMainOnly |
| 6569 | : (object_field_get_with_read_barrier |
| 6570 | ? LocationSummary::kCallOnSlowPath |
| 6571 | : LocationSummary::kNoCall)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6572 | |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6573 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6574 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 6575 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6576 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6577 | if (generate_volatile) { |
| 6578 | InvokeRuntimeCallingConvention calling_convention; |
| 6579 | // need A0 to hold base + offset |
| 6580 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6581 | if (field_type == DataType::Type::kInt64) { |
| 6582 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kInt64)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6583 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6584 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6585 | locations->SetOut(Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6586 | // Need some temp core regs since FP results are returned in core registers |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6587 | Location reg = calling_convention.GetReturnLocation(DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6588 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); |
| 6589 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); |
| 6590 | } |
| 6591 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6592 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6593 | locations->SetOut(Location::RequiresFpuRegister()); |
| 6594 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6595 | // The output overlaps in the case of an object field get with |
| 6596 | // read barriers enabled: we do not want the move to overwrite the |
| 6597 | // object's location, as we need it to emit the read barrier. |
| 6598 | locations->SetOut(Location::RequiresRegister(), |
| 6599 | object_field_get_with_read_barrier |
| 6600 | ? Location::kOutputOverlap |
| 6601 | : Location::kNoOutputOverlap); |
| 6602 | } |
| 6603 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6604 | // We need a temporary register for the read barrier marking slow |
| 6605 | // path in CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6606 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6607 | locations->AddTemp(Location::RequiresRegister()); |
| 6608 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6609 | } |
| 6610 | } |
| 6611 | } |
| 6612 | |
| 6613 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, |
| 6614 | const FieldInfo& field_info, |
| 6615 | uint32_t dex_pc) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6616 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 6617 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6618 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6619 | Location obj_loc = locations->InAt(0); |
| 6620 | Register obj = obj_loc.AsRegister<Register>(); |
| 6621 | Location dst_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6622 | LoadOperandType load_type = kLoadUnsignedByte; |
| 6623 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6624 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6625 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6626 | |
| 6627 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6628 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6629 | case DataType::Type::kUint8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6630 | load_type = kLoadUnsignedByte; |
| 6631 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6632 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6633 | load_type = kLoadSignedByte; |
| 6634 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6635 | case DataType::Type::kUint16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6636 | load_type = kLoadUnsignedHalfword; |
| 6637 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6638 | case DataType::Type::kInt16: |
| 6639 | load_type = kLoadSignedHalfword; |
| 6640 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6641 | case DataType::Type::kInt32: |
| 6642 | case DataType::Type::kFloat32: |
| 6643 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6644 | load_type = kLoadWord; |
| 6645 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6646 | case DataType::Type::kInt64: |
| 6647 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6648 | load_type = kLoadDoubleword; |
| 6649 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6650 | case DataType::Type::kUint32: |
| 6651 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6652 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6653 | LOG(FATAL) << "Unreachable type " << type; |
| 6654 | UNREACHABLE(); |
| 6655 | } |
| 6656 | |
| 6657 | if (is_volatile && load_type == kLoadDoubleword) { |
| 6658 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6659 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6660 | // Do implicit Null check |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6661 | __ LoadFromOffset(kLoadWord, |
| 6662 | ZERO, |
| 6663 | locations->GetTemp(0).AsRegister<Register>(), |
| 6664 | 0, |
| 6665 | null_checker); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6666 | codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6667 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6668 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6669 | // FP results are returned in core registers. Need to move them. |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6670 | if (dst_loc.IsFpuRegister()) { |
| 6671 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6672 | __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6673 | dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6674 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6675 | DCHECK(dst_loc.IsDoubleStackSlot()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6676 | __ StoreToOffset(kStoreWord, |
| 6677 | locations->GetTemp(1).AsRegister<Register>(), |
| 6678 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6679 | dst_loc.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6680 | __ StoreToOffset(kStoreWord, |
| 6681 | locations->GetTemp(2).AsRegister<Register>(), |
| 6682 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6683 | dst_loc.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6684 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6685 | } |
| 6686 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6687 | if (type == DataType::Type::kReference) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6688 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 6689 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6690 | Location temp_loc = |
| 6691 | kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6692 | // Note that a potential implicit null check is handled in this |
| 6693 | // CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier call. |
| 6694 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6695 | dst_loc, |
| 6696 | obj, |
| 6697 | offset, |
| 6698 | temp_loc, |
| 6699 | /* needs_null_check */ true); |
| 6700 | if (is_volatile) { |
| 6701 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6702 | } |
| 6703 | } else { |
| 6704 | __ LoadFromOffset(kLoadWord, dst_loc.AsRegister<Register>(), obj, offset, null_checker); |
| 6705 | if (is_volatile) { |
| 6706 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6707 | } |
| 6708 | // If read barriers are enabled, emit read barriers other than |
| 6709 | // Baker's using a slow path (and also unpoison the loaded |
| 6710 | // reference, if heap poisoning is enabled). |
| 6711 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 6712 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6713 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6714 | Register dst; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6715 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6716 | DCHECK(dst_loc.IsRegisterPair()); |
| 6717 | dst = dst_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6718 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6719 | DCHECK(dst_loc.IsRegister()); |
| 6720 | dst = dst_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6721 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6722 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6723 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6724 | DCHECK(dst_loc.IsFpuRegister()); |
| 6725 | FRegister dst = dst_loc.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6726 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6727 | __ LoadSFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6728 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6729 | __ LoadDFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6730 | } |
| 6731 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6732 | } |
| 6733 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6734 | // Memory barriers, in the case of references, are handled in the |
| 6735 | // previous switch statement. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6736 | if (is_volatile && (type != DataType::Type::kReference)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6737 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6738 | } |
| 6739 | } |
| 6740 | |
| 6741 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6742 | DataType::Type field_type = field_info.GetFieldType(); |
| 6743 | bool is_wide = (field_type == DataType::Type::kInt64) || (field_type == DataType::Type::kFloat64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6744 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6745 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6746 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6747 | |
| 6748 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6749 | if (generate_volatile) { |
| 6750 | InvokeRuntimeCallingConvention calling_convention; |
| 6751 | // need A0 to hold base + offset |
| 6752 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6753 | if (field_type == DataType::Type::kInt64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6754 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 6755 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 6756 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6757 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6758 | locations->SetInAt(1, Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6759 | // Pass FP parameters in core registers. |
| 6760 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 6761 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 6762 | } |
| 6763 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6764 | if (DataType::IsFloatingPointType(field_type)) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6765 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6766 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6767 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6768 | } |
| 6769 | } |
| 6770 | } |
| 6771 | |
| 6772 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, |
| 6773 | const FieldInfo& field_info, |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6774 | uint32_t dex_pc, |
| 6775 | bool value_can_be_null) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6776 | DataType::Type type = field_info.GetFieldType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6777 | LocationSummary* locations = instruction->GetLocations(); |
| 6778 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6779 | Location value_location = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6780 | StoreOperandType store_type = kStoreByte; |
| 6781 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6782 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6783 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6784 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6785 | |
| 6786 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6787 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6788 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6789 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6790 | store_type = kStoreByte; |
| 6791 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6792 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6793 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6794 | store_type = kStoreHalfword; |
| 6795 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6796 | case DataType::Type::kInt32: |
| 6797 | case DataType::Type::kFloat32: |
| 6798 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6799 | store_type = kStoreWord; |
| 6800 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6801 | case DataType::Type::kInt64: |
| 6802 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6803 | store_type = kStoreDoubleword; |
| 6804 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6805 | case DataType::Type::kUint32: |
| 6806 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6807 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6808 | LOG(FATAL) << "Unreachable type " << type; |
| 6809 | UNREACHABLE(); |
| 6810 | } |
| 6811 | |
| 6812 | if (is_volatile) { |
| 6813 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 6814 | } |
| 6815 | |
| 6816 | if (is_volatile && store_type == kStoreDoubleword) { |
| 6817 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6818 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6819 | // Do implicit Null check. |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6820 | __ LoadFromOffset(kLoadWord, |
| 6821 | ZERO, |
| 6822 | locations->GetTemp(0).AsRegister<Register>(), |
| 6823 | 0, |
| 6824 | null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6825 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6826 | // Pass FP parameters in core registers. |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6827 | if (value_location.IsFpuRegister()) { |
| 6828 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), |
| 6829 | value_location.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6830 | __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6831 | value_location.AsFpuRegister<FRegister>()); |
| 6832 | } else if (value_location.IsDoubleStackSlot()) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6833 | __ LoadFromOffset(kLoadWord, |
| 6834 | locations->GetTemp(1).AsRegister<Register>(), |
| 6835 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6836 | value_location.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6837 | __ LoadFromOffset(kLoadWord, |
| 6838 | locations->GetTemp(2).AsRegister<Register>(), |
| 6839 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6840 | value_location.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6841 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6842 | DCHECK(value_location.IsConstant()); |
| 6843 | DCHECK(value_location.GetConstant()->IsDoubleConstant()); |
| 6844 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6845 | __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(), |
| 6846 | locations->GetTemp(1).AsRegister<Register>(), |
| 6847 | value); |
| 6848 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6849 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6850 | codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6851 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); |
| 6852 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6853 | if (value_location.IsConstant()) { |
| 6854 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 6855 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6856 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6857 | Register src; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6858 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6859 | src = value_location.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6860 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6861 | src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6862 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6863 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 6864 | // Note that in the case where `value` is a null reference, |
| 6865 | // we do not enter this block, as a null reference does not |
| 6866 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6867 | DCHECK_EQ(type, DataType::Type::kReference); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6868 | __ PoisonHeapReference(TMP, src); |
| 6869 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 6870 | } else { |
| 6871 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 6872 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6873 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6874 | FRegister src = value_location.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6875 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6876 | __ StoreSToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6877 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6878 | __ StoreDToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6879 | } |
| 6880 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6881 | } |
| 6882 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6883 | if (needs_write_barrier) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6884 | Register src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6885 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6886 | } |
| 6887 | |
| 6888 | if (is_volatile) { |
| 6889 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 6890 | } |
| 6891 | } |
| 6892 | |
| 6893 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6894 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6895 | } |
| 6896 | |
| 6897 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6898 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 6899 | } |
| 6900 | |
| 6901 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6902 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6903 | } |
| 6904 | |
| 6905 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6906 | HandleFieldSet(instruction, |
| 6907 | instruction->GetFieldInfo(), |
| 6908 | instruction->GetDexPc(), |
| 6909 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6910 | } |
| 6911 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6912 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadOneRegister( |
| 6913 | HInstruction* instruction, |
| 6914 | Location out, |
| 6915 | uint32_t offset, |
| 6916 | Location maybe_temp, |
| 6917 | ReadBarrierOption read_barrier_option) { |
| 6918 | Register out_reg = out.AsRegister<Register>(); |
| 6919 | if (read_barrier_option == kWithReadBarrier) { |
| 6920 | CHECK(kEmitCompilerReadBarrier); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6921 | if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) { |
| 6922 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6923 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6924 | if (kUseBakerReadBarrier) { |
| 6925 | // Load with fast path based Baker's read barrier. |
| 6926 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6927 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6928 | out, |
| 6929 | out_reg, |
| 6930 | offset, |
| 6931 | maybe_temp, |
| 6932 | /* needs_null_check */ false); |
| 6933 | } else { |
| 6934 | // Load with slow path based read barrier. |
| 6935 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6936 | // in the following move operation, as we will need it for the |
| 6937 | // read barrier below. |
| 6938 | __ Move(maybe_temp.AsRegister<Register>(), out_reg); |
| 6939 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6940 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6941 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6942 | } |
| 6943 | } else { |
| 6944 | // Plain load with no read barrier. |
| 6945 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6946 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6947 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6948 | } |
| 6949 | } |
| 6950 | |
| 6951 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadTwoRegisters( |
| 6952 | HInstruction* instruction, |
| 6953 | Location out, |
| 6954 | Location obj, |
| 6955 | uint32_t offset, |
| 6956 | Location maybe_temp, |
| 6957 | ReadBarrierOption read_barrier_option) { |
| 6958 | Register out_reg = out.AsRegister<Register>(); |
| 6959 | Register obj_reg = obj.AsRegister<Register>(); |
| 6960 | if (read_barrier_option == kWithReadBarrier) { |
| 6961 | CHECK(kEmitCompilerReadBarrier); |
| 6962 | if (kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6963 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6964 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6965 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6966 | // Load with fast path based Baker's read barrier. |
| 6967 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6968 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6969 | out, |
| 6970 | obj_reg, |
| 6971 | offset, |
| 6972 | maybe_temp, |
| 6973 | /* needs_null_check */ false); |
| 6974 | } else { |
| 6975 | // Load with slow path based read barrier. |
| 6976 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6977 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6978 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6979 | } |
| 6980 | } else { |
| 6981 | // Plain load with no read barrier. |
| 6982 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6983 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6984 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6985 | } |
| 6986 | } |
| 6987 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6988 | static inline int GetBakerMarkThunkNumber(Register reg) { |
| 6989 | static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 21, "Expecting equal"); |
| 6990 | if (reg >= V0 && reg <= T7) { // 14 consequtive regs. |
| 6991 | return reg - V0; |
| 6992 | } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs. |
| 6993 | return 14 + (reg - S2); |
| 6994 | } else if (reg == FP) { // One more. |
| 6995 | return 20; |
| 6996 | } |
| 6997 | LOG(FATAL) << "Unexpected register " << reg; |
| 6998 | UNREACHABLE(); |
| 6999 | } |
| 7000 | |
| 7001 | static inline int GetBakerMarkFieldArrayThunkDisplacement(Register reg, bool short_offset) { |
| 7002 | int num = GetBakerMarkThunkNumber(reg) + |
| 7003 | (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0); |
| 7004 | return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE; |
| 7005 | } |
| 7006 | |
| 7007 | static inline int GetBakerMarkGcRootThunkDisplacement(Register reg) { |
| 7008 | return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE + |
| 7009 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET; |
| 7010 | } |
| 7011 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7012 | void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 7013 | Location root, |
| 7014 | Register obj, |
| 7015 | uint32_t offset, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7016 | ReadBarrierOption read_barrier_option, |
| 7017 | MipsLabel* label_low) { |
| 7018 | bool reordering; |
| 7019 | if (label_low != nullptr) { |
| 7020 | DCHECK_EQ(offset, 0x5678u); |
| 7021 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7022 | Register root_reg = root.AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7023 | if (read_barrier_option == kWithReadBarrier) { |
| 7024 | DCHECK(kEmitCompilerReadBarrier); |
| 7025 | if (kUseBakerReadBarrier) { |
| 7026 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7027 | // Baker's read barrier are used: |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7028 | if (kBakerReadBarrierThunksEnableForGcRoots) { |
| 7029 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 7030 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 7031 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 7032 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 7033 | // vice versa. |
| 7034 | // |
| 7035 | // We use thunks for the slow path. That thunk checks the reference |
| 7036 | // and jumps to the entrypoint if needed. |
| 7037 | // |
| 7038 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 7039 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 7040 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 7041 | // if (temp != nullptr) { |
| 7042 | // temp = &gc_root_thunk<root_reg> |
| 7043 | // root = temp(root) |
| 7044 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7045 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7046 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 7047 | const int32_t entry_point_offset = |
| 7048 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 7049 | const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg); |
| 7050 | int16_t offset_low = Low16Bits(offset); |
| 7051 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign |
| 7052 | // extension in lw. |
| 7053 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 7054 | Register base = short_offset ? obj : TMP; |
| 7055 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7056 | // threads are suspended or running a checkpoint. |
| 7057 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 7058 | reordering = __ SetReorder(false); |
| 7059 | if (!short_offset) { |
| 7060 | DCHECK(!label_low); |
| 7061 | __ AddUpper(base, obj, offset_high); |
| 7062 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7063 | MipsLabel skip_call; |
| 7064 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7065 | if (label_low != nullptr) { |
| 7066 | DCHECK(short_offset); |
| 7067 | __ Bind(label_low); |
| 7068 | } |
| 7069 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7070 | __ LoadFromOffset(kLoadWord, root_reg, base, offset_low); // Single instruction |
| 7071 | // in delay slot. |
| 7072 | if (isR6) { |
| 7073 | __ Jialc(T9, thunk_disp); |
| 7074 | } else { |
| 7075 | __ Addiu(T9, T9, thunk_disp); |
| 7076 | __ Jalr(T9); |
| 7077 | __ Nop(); |
| 7078 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7079 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7080 | __ SetReorder(reordering); |
| 7081 | } else { |
| 7082 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 7083 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 7084 | // load into `temp` (T9) the read barrier mark entry point corresponding |
| 7085 | // to register `root`. If `temp` is null, it means that `GetIsGcMarking()` |
| 7086 | // is false, and vice versa. |
| 7087 | // |
| 7088 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 7089 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7090 | // if (temp != null) { |
| 7091 | // root = temp(root) |
| 7092 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7093 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7094 | if (label_low != nullptr) { |
| 7095 | reordering = __ SetReorder(false); |
| 7096 | __ Bind(label_low); |
| 7097 | } |
| 7098 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7099 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7100 | if (label_low != nullptr) { |
| 7101 | __ SetReorder(reordering); |
| 7102 | } |
| 7103 | static_assert( |
| 7104 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7105 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7106 | "have different sizes."); |
| 7107 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7108 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7109 | "have different sizes."); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7110 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7111 | // Slow path marking the GC root `root`. |
| 7112 | Location temp = Location::RegisterLocation(T9); |
| 7113 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7114 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS( |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7115 | instruction, |
| 7116 | root, |
| 7117 | /*entrypoint*/ temp); |
| 7118 | codegen_->AddSlowPath(slow_path); |
| 7119 | |
| 7120 | const int32_t entry_point_offset = |
| 7121 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(root.reg() - 1); |
| 7122 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7123 | // threads are suspended or running a checkpoint. |
| 7124 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 7125 | __ Bnez(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 7126 | __ Bind(slow_path->GetExitLabel()); |
| 7127 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7128 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7129 | if (label_low != nullptr) { |
| 7130 | reordering = __ SetReorder(false); |
| 7131 | __ Bind(label_low); |
| 7132 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7133 | // GC root loaded through a slow path for read barriers other |
| 7134 | // than Baker's. |
| 7135 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 7136 | __ Addiu32(root_reg, obj, offset); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7137 | if (label_low != nullptr) { |
| 7138 | __ SetReorder(reordering); |
| 7139 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7140 | // /* mirror::Object* */ root = root->Read() |
| 7141 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7142 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7143 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7144 | if (label_low != nullptr) { |
| 7145 | reordering = __ SetReorder(false); |
| 7146 | __ Bind(label_low); |
| 7147 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7148 | // Plain GC root load with no read barrier. |
| 7149 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7150 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7151 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7152 | // do not have to unpoison `root_reg` here. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7153 | if (label_low != nullptr) { |
| 7154 | __ SetReorder(reordering); |
| 7155 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7156 | } |
| 7157 | } |
| 7158 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7159 | void CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7160 | Location ref, |
| 7161 | Register obj, |
| 7162 | uint32_t offset, |
| 7163 | Location temp, |
| 7164 | bool needs_null_check) { |
| 7165 | DCHECK(kEmitCompilerReadBarrier); |
| 7166 | DCHECK(kUseBakerReadBarrier); |
| 7167 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7168 | if (kBakerReadBarrierThunksEnableForFields) { |
| 7169 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 7170 | // to decide whether to mark the loaded reference or not. Instead, we |
| 7171 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 7172 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 7173 | // vice versa. |
| 7174 | // |
| 7175 | // We use thunks for the slow path. That thunk checks the reference |
| 7176 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 7177 | // it issues a load-load memory barrier and returns to the original |
| 7178 | // reference load. |
| 7179 | // |
| 7180 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 7181 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 7182 | // if (temp != nullptr) { |
| 7183 | // temp = &field_array_thunk<holder_reg> |
| 7184 | // temp() |
| 7185 | // } |
| 7186 | // not_gray_return_address: |
| 7187 | // // If the offset is too large to fit into the lw instruction, we |
| 7188 | // // use an adjusted base register (TMP) here. This register |
| 7189 | // // receives bits 16 ... 31 of the offset before the thunk invocation |
| 7190 | // // and the thunk benefits from it. |
| 7191 | // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load. |
| 7192 | // gray_return_address: |
| 7193 | |
| 7194 | DCHECK(temp.IsInvalid()); |
| 7195 | bool isR6 = GetInstructionSetFeatures().IsR6(); |
| 7196 | int16_t offset_low = Low16Bits(offset); |
| 7197 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lw. |
| 7198 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 7199 | bool reordering = __ SetReorder(false); |
| 7200 | const int32_t entry_point_offset = |
| 7201 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 7202 | // There may have or may have not been a null check if the field offset is smaller than |
| 7203 | // the page size. |
| 7204 | // There must've been a null check in case it's actually a load from an array. |
| 7205 | // We will, however, perform an explicit null check in the thunk as it's easier to |
| 7206 | // do it than not. |
| 7207 | if (instruction->IsArrayGet()) { |
| 7208 | DCHECK(!needs_null_check); |
| 7209 | } |
| 7210 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset); |
| 7211 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7212 | // threads are suspended or running a checkpoint. |
| 7213 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 7214 | Register ref_reg = ref.AsRegister<Register>(); |
| 7215 | Register base = short_offset ? obj : TMP; |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7216 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7217 | if (short_offset) { |
| 7218 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7219 | __ Beqzc(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7220 | __ Nop(); // In forbidden slot. |
| 7221 | __ Jialc(T9, thunk_disp); |
| 7222 | } else { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7223 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7224 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 7225 | __ Jalr(T9); |
| 7226 | __ Nop(); // In delay slot. |
| 7227 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7228 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7229 | } else { |
| 7230 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7231 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7232 | __ Aui(base, obj, offset_high); // In delay slot. |
| 7233 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7234 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7235 | } else { |
| 7236 | __ Lui(base, offset_high); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7237 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7238 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 7239 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7240 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7241 | __ Addu(base, base, obj); // In delay slot. |
| 7242 | } |
| 7243 | } |
| 7244 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7245 | __ LoadFromOffset(kLoadWord, ref_reg, base, offset_low); // Single instruction. |
| 7246 | if (needs_null_check) { |
| 7247 | MaybeRecordImplicitNullCheck(instruction); |
| 7248 | } |
| 7249 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7250 | __ SetReorder(reordering); |
| 7251 | return; |
| 7252 | } |
| 7253 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7254 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7255 | Location no_index = Location::NoLocation(); |
| 7256 | ScaleFactor no_scale_factor = TIMES_1; |
| 7257 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 7258 | ref, |
| 7259 | obj, |
| 7260 | offset, |
| 7261 | no_index, |
| 7262 | no_scale_factor, |
| 7263 | temp, |
| 7264 | needs_null_check); |
| 7265 | } |
| 7266 | |
| 7267 | void CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7268 | Location ref, |
| 7269 | Register obj, |
| 7270 | uint32_t data_offset, |
| 7271 | Location index, |
| 7272 | Location temp, |
| 7273 | bool needs_null_check) { |
| 7274 | DCHECK(kEmitCompilerReadBarrier); |
| 7275 | DCHECK(kUseBakerReadBarrier); |
| 7276 | |
| 7277 | static_assert( |
| 7278 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7279 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7280 | ScaleFactor scale_factor = TIMES_4; |
| 7281 | |
| 7282 | if (kBakerReadBarrierThunksEnableForArrays) { |
| 7283 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 7284 | // to decide whether to mark the loaded reference or not. Instead, we |
| 7285 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 7286 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 7287 | // vice versa. |
| 7288 | // |
| 7289 | // We use thunks for the slow path. That thunk checks the reference |
| 7290 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 7291 | // it issues a load-load memory barrier and returns to the original |
| 7292 | // reference load. |
| 7293 | // |
| 7294 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 7295 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 7296 | // if (temp != nullptr) { |
| 7297 | // temp = &field_array_thunk<holder_reg> |
| 7298 | // temp() |
| 7299 | // } |
| 7300 | // not_gray_return_address: |
| 7301 | // // The element address is pre-calculated in the TMP register before the |
| 7302 | // // thunk invocation and the thunk benefits from it. |
| 7303 | // HeapReference<mirror::Object> reference = data[index]; // Original reference load. |
| 7304 | // gray_return_address: |
| 7305 | |
| 7306 | DCHECK(temp.IsInvalid()); |
| 7307 | DCHECK(index.IsValid()); |
| 7308 | bool reordering = __ SetReorder(false); |
| 7309 | const int32_t entry_point_offset = |
| 7310 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 7311 | // We will not do the explicit null check in the thunk as some form of a null check |
| 7312 | // must've been done earlier. |
| 7313 | DCHECK(!needs_null_check); |
| 7314 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false); |
| 7315 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7316 | // threads are suspended or running a checkpoint. |
| 7317 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 7318 | Register ref_reg = ref.AsRegister<Register>(); |
| 7319 | Register index_reg = index.IsRegisterPair() |
| 7320 | ? index.AsRegisterPairLow<Register>() |
| 7321 | : index.AsRegister<Register>(); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7322 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7323 | if (GetInstructionSetFeatures().IsR6()) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7324 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7325 | __ Lsa(TMP, index_reg, obj, scale_factor); // In delay slot. |
| 7326 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7327 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7328 | } else { |
| 7329 | __ Sll(TMP, index_reg, scale_factor); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7330 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7331 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 7332 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7333 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7334 | __ Addu(TMP, TMP, obj); // In delay slot. |
| 7335 | } |
| 7336 | // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor)) |
| 7337 | DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset; |
| 7338 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, data_offset); // Single instruction. |
| 7339 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7340 | __ SetReorder(reordering); |
| 7341 | return; |
| 7342 | } |
| 7343 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7344 | // /* HeapReference<Object> */ ref = |
| 7345 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7346 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 7347 | ref, |
| 7348 | obj, |
| 7349 | data_offset, |
| 7350 | index, |
| 7351 | scale_factor, |
| 7352 | temp, |
| 7353 | needs_null_check); |
| 7354 | } |
| 7355 | |
| 7356 | void CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7357 | Location ref, |
| 7358 | Register obj, |
| 7359 | uint32_t offset, |
| 7360 | Location index, |
| 7361 | ScaleFactor scale_factor, |
| 7362 | Location temp, |
| 7363 | bool needs_null_check, |
| 7364 | bool always_update_field) { |
| 7365 | DCHECK(kEmitCompilerReadBarrier); |
| 7366 | DCHECK(kUseBakerReadBarrier); |
| 7367 | |
| 7368 | // In slow path based read barriers, the read barrier call is |
| 7369 | // inserted after the original load. However, in fast path based |
| 7370 | // Baker's read barriers, we need to perform the load of |
| 7371 | // mirror::Object::monitor_ *before* the original reference load. |
| 7372 | // This load-load ordering is required by the read barrier. |
| 7373 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7374 | // |
| 7375 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7376 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7377 | // HeapReference<Object> ref = *src; // Original reference load. |
| 7378 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 7379 | // if (is_gray) { |
| 7380 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7381 | // } |
| 7382 | // |
| 7383 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7384 | // slightly more complex as it performs additional checks that we do |
| 7385 | // not do here for performance reasons. |
| 7386 | |
| 7387 | Register ref_reg = ref.AsRegister<Register>(); |
| 7388 | Register temp_reg = temp.AsRegister<Register>(); |
| 7389 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7390 | |
| 7391 | // /* int32_t */ monitor = obj->monitor_ |
| 7392 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 7393 | if (needs_null_check) { |
| 7394 | MaybeRecordImplicitNullCheck(instruction); |
| 7395 | } |
| 7396 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7397 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7398 | "art::LockWord and int32_t have different sizes."); |
| 7399 | |
| 7400 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 7401 | |
| 7402 | // The actual reference load. |
| 7403 | if (index.IsValid()) { |
| 7404 | // Load types involving an "index": ArrayGet, |
| 7405 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7406 | // intrinsics. |
| 7407 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 7408 | if (index.IsConstant()) { |
| 7409 | size_t computed_offset = |
| 7410 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 7411 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7412 | } else { |
| 7413 | // Handle the special case of the |
| 7414 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7415 | // intrinsics, which use a register pair as index ("long |
| 7416 | // offset"), of which only the low part contains data. |
| 7417 | Register index_reg = index.IsRegisterPair() |
| 7418 | ? index.AsRegisterPairLow<Register>() |
| 7419 | : index.AsRegister<Register>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 7420 | __ ShiftAndAdd(TMP, index_reg, obj, scale_factor, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7421 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, offset); |
| 7422 | } |
| 7423 | } else { |
| 7424 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7425 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7426 | } |
| 7427 | |
| 7428 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7429 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7430 | |
| 7431 | // Slow path marking the object `ref` when it is gray. |
| 7432 | SlowPathCodeMIPS* slow_path; |
| 7433 | if (always_update_field) { |
| 7434 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS only supports address |
| 7435 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7436 | // `field_offset` is a register pair (of which only the lower half |
| 7437 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7438 | // to be null in this code path. |
| 7439 | DCHECK_EQ(offset, 0u); |
| 7440 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7441 | slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7442 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(instruction, |
| 7443 | ref, |
| 7444 | obj, |
| 7445 | /* field_offset */ index, |
| 7446 | temp_reg); |
| 7447 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7448 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS(instruction, ref); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7449 | } |
| 7450 | AddSlowPath(slow_path); |
| 7451 | |
| 7452 | // if (rb_state == ReadBarrier::GrayState()) |
| 7453 | // ref = ReadBarrier::Mark(ref); |
| 7454 | // Given the numeric representation, it's enough to check the low bit of the |
| 7455 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 7456 | // performing a branch on less than zero. |
Roland Levillain | 14e5a29 | 2018-06-28 12:00:56 +0100 | [diff] [blame] | 7457 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7458 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 7459 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 7460 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 7461 | __ Bltz(temp_reg, slow_path->GetEntryLabel()); |
| 7462 | __ Bind(slow_path->GetExitLabel()); |
| 7463 | } |
| 7464 | |
| 7465 | void CodeGeneratorMIPS::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7466 | Location out, |
| 7467 | Location ref, |
| 7468 | Location obj, |
| 7469 | uint32_t offset, |
| 7470 | Location index) { |
| 7471 | DCHECK(kEmitCompilerReadBarrier); |
| 7472 | |
| 7473 | // Insert a slow path based read barrier *after* the reference load. |
| 7474 | // |
| 7475 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7476 | // reference will be carried out by the runtime within the slow |
| 7477 | // path. |
| 7478 | // |
| 7479 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7480 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7481 | // not used by the artReadBarrierSlow entry point. |
| 7482 | // |
| 7483 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7484 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7485 | ReadBarrierForHeapReferenceSlowPathMIPS(instruction, out, ref, obj, offset, index); |
| 7486 | AddSlowPath(slow_path); |
| 7487 | |
| 7488 | __ B(slow_path->GetEntryLabel()); |
| 7489 | __ Bind(slow_path->GetExitLabel()); |
| 7490 | } |
| 7491 | |
| 7492 | void CodeGeneratorMIPS::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7493 | Location out, |
| 7494 | Location ref, |
| 7495 | Location obj, |
| 7496 | uint32_t offset, |
| 7497 | Location index) { |
| 7498 | if (kEmitCompilerReadBarrier) { |
| 7499 | // Baker's read barriers shall be handled by the fast path |
| 7500 | // (CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier). |
| 7501 | DCHECK(!kUseBakerReadBarrier); |
| 7502 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7503 | // by the runtime within the slow path. |
| 7504 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 7505 | } else if (kPoisonHeapReferences) { |
| 7506 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7507 | } |
| 7508 | } |
| 7509 | |
| 7510 | void CodeGeneratorMIPS::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7511 | Location out, |
| 7512 | Location root) { |
| 7513 | DCHECK(kEmitCompilerReadBarrier); |
| 7514 | |
| 7515 | // Insert a slow path based read barrier *after* the GC root load. |
| 7516 | // |
| 7517 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7518 | // not need to do anything special for this here. |
| 7519 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7520 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS(instruction, out, root); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7521 | AddSlowPath(slow_path); |
| 7522 | |
| 7523 | __ B(slow_path->GetEntryLabel()); |
| 7524 | __ Bind(slow_path->GetExitLabel()); |
| 7525 | } |
| 7526 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7527 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7528 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7529 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7530 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7531 | switch (type_check_kind) { |
| 7532 | case TypeCheckKind::kExactCheck: |
| 7533 | case TypeCheckKind::kAbstractClassCheck: |
| 7534 | case TypeCheckKind::kClassHierarchyCheck: |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7535 | case TypeCheckKind::kArrayObjectCheck: { |
| 7536 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7537 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7538 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7539 | break; |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7540 | } |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7541 | case TypeCheckKind::kArrayCheck: |
| 7542 | case TypeCheckKind::kUnresolvedCheck: |
| 7543 | case TypeCheckKind::kInterfaceCheck: |
| 7544 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7545 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7546 | case TypeCheckKind::kBitstringCheck: |
| 7547 | break; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7548 | } |
| 7549 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7550 | LocationSummary* locations = |
| 7551 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7552 | if (baker_read_barrier_slow_path) { |
| 7553 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7554 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7555 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7556 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7557 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7558 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7559 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7560 | } else { |
| 7561 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7562 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7563 | // The output does overlap inputs. |
| 7564 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 7565 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7566 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7567 | } |
| 7568 | |
| 7569 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7570 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7571 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7572 | Location obj_loc = locations->InAt(0); |
| 7573 | Register obj = obj_loc.AsRegister<Register>(); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7574 | Location cls = locations->InAt(1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7575 | Location out_loc = locations->Out(); |
| 7576 | Register out = out_loc.AsRegister<Register>(); |
| 7577 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7578 | DCHECK_LE(num_temps, 1u); |
| 7579 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7580 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7581 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7582 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7583 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7584 | MipsLabel done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7585 | SlowPathCodeMIPS* slow_path = nullptr; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7586 | |
| 7587 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7588 | // Avoid this check if we know `obj` is not null. |
| 7589 | if (instruction->MustDoNullCheck()) { |
| 7590 | __ Move(out, ZERO); |
| 7591 | __ Beqz(obj, &done); |
| 7592 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7593 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7594 | switch (type_check_kind) { |
| 7595 | case TypeCheckKind::kExactCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7596 | ReadBarrierOption read_barrier_option = |
| 7597 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7598 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7599 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7600 | out_loc, |
| 7601 | obj_loc, |
| 7602 | class_offset, |
| 7603 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7604 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7605 | // Classes must be equal for the instanceof to succeed. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7606 | __ Xor(out, out, cls.AsRegister<Register>()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7607 | __ Sltiu(out, out, 1); |
| 7608 | break; |
| 7609 | } |
| 7610 | |
| 7611 | case TypeCheckKind::kAbstractClassCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7612 | ReadBarrierOption read_barrier_option = |
| 7613 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7614 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7615 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7616 | out_loc, |
| 7617 | obj_loc, |
| 7618 | class_offset, |
| 7619 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7620 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7621 | // If the class is abstract, we eagerly fetch the super class of the |
| 7622 | // object to avoid doing a comparison we know will fail. |
| 7623 | MipsLabel loop; |
| 7624 | __ Bind(&loop); |
| 7625 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7626 | GenerateReferenceLoadOneRegister(instruction, |
| 7627 | out_loc, |
| 7628 | super_offset, |
| 7629 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7630 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7631 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7632 | __ Beqz(out, &done); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7633 | __ Bne(out, cls.AsRegister<Register>(), &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7634 | __ LoadConst32(out, 1); |
| 7635 | break; |
| 7636 | } |
| 7637 | |
| 7638 | case TypeCheckKind::kClassHierarchyCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7639 | ReadBarrierOption read_barrier_option = |
| 7640 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7641 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7642 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7643 | out_loc, |
| 7644 | obj_loc, |
| 7645 | class_offset, |
| 7646 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7647 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7648 | // Walk over the class hierarchy to find a match. |
| 7649 | MipsLabel loop, success; |
| 7650 | __ Bind(&loop); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7651 | __ Beq(out, cls.AsRegister<Register>(), &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7652 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7653 | GenerateReferenceLoadOneRegister(instruction, |
| 7654 | out_loc, |
| 7655 | super_offset, |
| 7656 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7657 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7658 | __ Bnez(out, &loop); |
| 7659 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7660 | __ B(&done); |
| 7661 | __ Bind(&success); |
| 7662 | __ LoadConst32(out, 1); |
| 7663 | break; |
| 7664 | } |
| 7665 | |
| 7666 | case TypeCheckKind::kArrayObjectCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7667 | ReadBarrierOption read_barrier_option = |
| 7668 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7669 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7670 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7671 | out_loc, |
| 7672 | obj_loc, |
| 7673 | class_offset, |
| 7674 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7675 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7676 | // Do an exact check. |
| 7677 | MipsLabel success; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7678 | __ Beq(out, cls.AsRegister<Register>(), &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7679 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7680 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7681 | GenerateReferenceLoadOneRegister(instruction, |
| 7682 | out_loc, |
| 7683 | component_offset, |
| 7684 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7685 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7686 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7687 | __ Beqz(out, &done); |
| 7688 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7689 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 7690 | __ Sltiu(out, out, 1); |
| 7691 | __ B(&done); |
| 7692 | __ Bind(&success); |
| 7693 | __ LoadConst32(out, 1); |
| 7694 | break; |
| 7695 | } |
| 7696 | |
| 7697 | case TypeCheckKind::kArrayCheck: { |
| 7698 | // No read barrier since the slow path will retry upon failure. |
| 7699 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7700 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7701 | out_loc, |
| 7702 | obj_loc, |
| 7703 | class_offset, |
| 7704 | maybe_temp_loc, |
| 7705 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7706 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7707 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7708 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7709 | codegen_->AddSlowPath(slow_path); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7710 | __ Bne(out, cls.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7711 | __ LoadConst32(out, 1); |
| 7712 | break; |
| 7713 | } |
| 7714 | |
| 7715 | case TypeCheckKind::kUnresolvedCheck: |
| 7716 | case TypeCheckKind::kInterfaceCheck: { |
| 7717 | // Note that we indeed only call on slow path, but we always go |
| 7718 | // into the slow path for the unresolved and interface check |
| 7719 | // cases. |
| 7720 | // |
| 7721 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7722 | // entry point without resorting to a type checking slow path |
| 7723 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7724 | // require to assign fixed registers for the inputs of this |
| 7725 | // HInstanceOf instruction (following the runtime calling |
| 7726 | // convention), which might be cluttered by the potential first |
| 7727 | // read barrier emission at the beginning of this method. |
| 7728 | // |
| 7729 | // TODO: Introduce a new runtime entry point taking the object |
| 7730 | // to test (instead of its class) as argument, and let it deal |
| 7731 | // with the read barrier issues. This will let us refactor this |
| 7732 | // case of the `switch` code as it was previously (with a direct |
| 7733 | // call to the runtime not using a type checking slow path). |
| 7734 | // This should also be beneficial for the other cases above. |
| 7735 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7736 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7737 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7738 | codegen_->AddSlowPath(slow_path); |
| 7739 | __ B(slow_path->GetEntryLabel()); |
| 7740 | break; |
| 7741 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7742 | |
| 7743 | case TypeCheckKind::kBitstringCheck: { |
| 7744 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7745 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7746 | out_loc, |
| 7747 | obj_loc, |
| 7748 | class_offset, |
| 7749 | maybe_temp_loc, |
| 7750 | kWithoutReadBarrier); |
| 7751 | |
| 7752 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 7753 | __ Sltiu(out, out, 1); |
| 7754 | break; |
| 7755 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7756 | } |
| 7757 | |
| 7758 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7759 | |
| 7760 | if (slow_path != nullptr) { |
| 7761 | __ Bind(slow_path->GetExitLabel()); |
| 7762 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7763 | } |
| 7764 | |
| 7765 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7766 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7767 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7768 | } |
| 7769 | |
| 7770 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 7771 | // Will be generated at use site. |
| 7772 | } |
| 7773 | |
| 7774 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7775 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7776 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7777 | } |
| 7778 | |
| 7779 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 7780 | // Will be generated at use site. |
| 7781 | } |
| 7782 | |
| 7783 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { |
| 7784 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 7785 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 7786 | } |
| 7787 | |
| 7788 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7789 | HandleInvoke(invoke); |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7790 | // The register T7 is required to be used for the hidden argument in |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7791 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7792 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T7)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7793 | } |
| 7794 | |
| 7795 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7796 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 7797 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7798 | Location receiver = invoke->GetLocations()->InAt(0); |
| 7799 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7800 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7801 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7802 | // temp = object->GetClass(); |
| 7803 | if (receiver.IsStackSlot()) { |
| 7804 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 7805 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 7806 | } else { |
| 7807 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 7808 | } |
| 7809 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7810 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7811 | // emit a read barrier for the previous class reference load. |
| 7812 | // However this is not required in practice, as this is an |
| 7813 | // intermediate/temporary reference and because the current |
| 7814 | // concurrent copying collector keeps the from-space memory |
| 7815 | // intact/accessible until the end of the marking phase (the |
| 7816 | // concurrent copying collector may not in the future). |
| 7817 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 7818 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 7819 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
| 7820 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7821 | invoke->GetImtIndex(), kMipsPointerSize)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7822 | // temp = temp->GetImtEntryAt(method_offset); |
| 7823 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7824 | // T9 = temp->GetEntryPoint(); |
| 7825 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
Lena Djokic | 3177e10 | 2018-02-28 11:32:40 +0100 | [diff] [blame] | 7826 | // Set the hidden argument. |
| 7827 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 7828 | invoke->GetDexMethodIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7829 | // T9(); |
| 7830 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7831 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7832 | DCHECK(!codegen_->IsLeafMethod()); |
| 7833 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 7834 | } |
| 7835 | |
| 7836 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7837 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7838 | if (intrinsic.TryDispatch(invoke)) { |
| 7839 | return; |
| 7840 | } |
| 7841 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7842 | HandleInvoke(invoke); |
| 7843 | } |
| 7844 | |
| 7845 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 7846 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 7847 | // art::PrepareForRegisterAllocation. |
| 7848 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7849 | |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7850 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7851 | bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
| 7852 | bool has_extra_input = invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7853 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7854 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7855 | if (intrinsic.TryDispatch(invoke)) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7856 | if (invoke->GetLocations()->CanCall() && has_extra_input) { |
| 7857 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 7858 | } |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7859 | return; |
| 7860 | } |
| 7861 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7862 | HandleInvoke(invoke); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7863 | |
| 7864 | // Add the extra input register if either the dex cache array base register |
| 7865 | // or the PC-relative base register for accessing literals is needed. |
| 7866 | if (has_extra_input) { |
| 7867 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 7868 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7869 | } |
| 7870 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 7871 | void LocationsBuilderMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7872 | HandleInvoke(invoke); |
| 7873 | } |
| 7874 | |
| 7875 | void InstructionCodeGeneratorMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7876 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 7877 | } |
| 7878 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 7879 | void LocationsBuilderMIPS::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 7880 | HandleInvoke(invoke); |
| 7881 | } |
| 7882 | |
| 7883 | void InstructionCodeGeneratorMIPS::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 7884 | codegen_->GenerateInvokeCustomCall(invoke); |
| 7885 | } |
| 7886 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7887 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7888 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7889 | IntrinsicCodeGeneratorMIPS intrinsic(codegen); |
| 7890 | intrinsic.Dispatch(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7891 | return true; |
| 7892 | } |
| 7893 | return false; |
| 7894 | } |
| 7895 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7896 | HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7897 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7898 | switch (desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7899 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7900 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7901 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7902 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7903 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7904 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7905 | case HLoadString::LoadKind::kJitTableAddress: |
| 7906 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7907 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7908 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7909 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7910 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7911 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7912 | } |
| 7913 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7914 | HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind( |
| 7915 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7916 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7917 | case HLoadClass::LoadKind::kInvalid: |
| 7918 | LOG(FATAL) << "UNREACHABLE"; |
| 7919 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7920 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7921 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7922 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7923 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7924 | case HLoadClass::LoadKind::kBssEntry: |
| 7925 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7926 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7927 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7928 | case HLoadClass::LoadKind::kJitTableAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7929 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7930 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7931 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7932 | break; |
| 7933 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7934 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7935 | } |
| 7936 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7937 | Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7938 | Register temp) { |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7939 | CHECK(!GetInstructionSetFeatures().IsR6()); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7940 | CHECK(!GetGraph()->HasIrreducibleLoops()); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7941 | CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7942 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7943 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7944 | return location.AsRegister<Register>(); |
| 7945 | } |
| 7946 | // For intrinsics we allow any location, so it may be on the stack. |
| 7947 | if (!location.IsRegister()) { |
| 7948 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7949 | return temp; |
| 7950 | } |
| 7951 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7952 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7953 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7954 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7955 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 7956 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 7957 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 7958 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7959 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7960 | return temp; |
| 7961 | } |
| 7962 | return location.AsRegister<Register>(); |
| 7963 | } |
| 7964 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7965 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( |
| 7966 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 7967 | ArtMethod* method ATTRIBUTE_UNUSED) { |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7968 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7969 | } |
| 7970 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7971 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall( |
| 7972 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7973 | // All registers are assumed to be correctly set up per the calling convention. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7974 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7975 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 7976 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7977 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7978 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 7979 | Register base_reg = (invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7980 | ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>()) |
| 7981 | : ZERO; |
| 7982 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7983 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7984 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7985 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7986 | uint32_t offset = |
| 7987 | GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7988 | __ LoadFromOffset(kLoadWord, |
| 7989 | temp.AsRegister<Register>(), |
| 7990 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7991 | offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7992 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7993 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7994 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7995 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7996 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7997 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 7998 | DCHECK(GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7999 | PcRelativePatchInfo* info_high = NewBootImageMethodPatch(invoke->GetTargetMethod()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8000 | PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8001 | NewBootImageMethodPatch(invoke->GetTargetMethod(), info_high); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8002 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 8003 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 8004 | __ Addiu(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8005 | break; |
| 8006 | } |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 8007 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8008 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 8009 | PcRelativePatchInfo* info_high = NewBootImageRelRoPatch(boot_image_offset); |
| 8010 | PcRelativePatchInfo* info_low = NewBootImageRelRoPatch(boot_image_offset, info_high); |
| 8011 | Register temp_reg = temp.AsRegister<Register>(); |
| 8012 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 8013 | __ Lw(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
| 8014 | break; |
| 8015 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 8016 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8017 | PcRelativePatchInfo* info_high = NewMethodBssEntryPatch( |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 8018 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8019 | PcRelativePatchInfo* info_low = NewMethodBssEntryPatch( |
| 8020 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 8021 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 8022 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 8023 | __ Lw(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 8024 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 8025 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 8026 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 8027 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 8028 | break; |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8029 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 8030 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 8031 | return; // No code pointer retrieval; the runtime performs the call directly. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8032 | } |
| 8033 | } |
| 8034 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 8035 | switch (code_ptr_location) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8036 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 8037 | __ Bal(&frame_entry_label_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8038 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8039 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 8040 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 8041 | __ LoadFromOffset(kLoadWord, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8042 | T9, |
| 8043 | callee_method.AsRegister<Register>(), |
| 8044 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8045 | kMipsPointerSize).Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8046 | // T9() |
| 8047 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 8048 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8049 | break; |
| 8050 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8051 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 8052 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8053 | DCHECK(!IsLeafMethod()); |
| 8054 | } |
| 8055 | |
| 8056 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 8057 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 8058 | // art::PrepareForRegisterAllocation. |
| 8059 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8060 | |
| 8061 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 8062 | return; |
| 8063 | } |
| 8064 | |
| 8065 | LocationSummary* locations = invoke->GetLocations(); |
| 8066 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 8067 | locations->HasTemps() |
| 8068 | ? locations->GetTemp(0) |
| 8069 | : Location::NoLocation()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8070 | } |
| 8071 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8072 | void CodeGeneratorMIPS::GenerateVirtualCall( |
| 8073 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 8074 | // Use the calling convention instead of the location of the receiver, as |
| 8075 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 8076 | // slow path, the arguments have been moved to the right place, so here we are |
| 8077 | // guaranteed that the receiver is the first register of the calling convention. |
| 8078 | InvokeDexCallingConvention calling_convention; |
| 8079 | Register receiver = calling_convention.GetRegisterAt(0); |
| 8080 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 8081 | Register temp = temp_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8082 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 8083 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); |
| 8084 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8085 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8086 | |
| 8087 | // temp = object->GetClass(); |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 8088 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 8089 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8090 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 8091 | // emit a read barrier for the previous class reference load. |
| 8092 | // However this is not required in practice, as this is an |
| 8093 | // intermediate/temporary reference and because the current |
| 8094 | // concurrent copying collector keeps the from-space memory |
| 8095 | // intact/accessible until the end of the marking phase (the |
| 8096 | // concurrent copying collector may not in the future). |
| 8097 | __ MaybeUnpoisonHeapReference(temp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8098 | // temp = temp->GetMethodAt(method_offset); |
| 8099 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 8100 | // T9 = temp->GetEntryPoint(); |
| 8101 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 8102 | // T9(); |
| 8103 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 8104 | __ NopIfNoReordering(); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8105 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 8106 | } |
| 8107 | |
| 8108 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 8109 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 8110 | return; |
| 8111 | } |
| 8112 | |
| 8113 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8114 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8115 | } |
| 8116 | |
| 8117 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8118 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8119 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8120 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8121 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 8122 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8123 | return; |
| 8124 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8125 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8126 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8127 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8128 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 8129 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8130 | ? LocationSummary::kCallOnSlowPath |
| 8131 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8132 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8133 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 8134 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 8135 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8136 | switch (load_kind) { |
| 8137 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8138 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8139 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8140 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 8141 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8142 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8143 | break; |
| 8144 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8145 | if (has_irreducible_loops) { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 8146 | if (load_kind != HLoadClass::LoadKind::kJitBootImageAddress) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 8147 | codegen_->ClobberRA(); |
| 8148 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8149 | break; |
| 8150 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8151 | FALLTHROUGH_INTENDED; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8152 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8153 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8154 | break; |
| 8155 | default: |
| 8156 | break; |
| 8157 | } |
| 8158 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8159 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 8160 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 8161 | // Rely on the type resolution or initialization and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 8162 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8163 | } else { |
| 8164 | // For non-Baker read barriers we have a temp-clobbering call. |
| 8165 | } |
| 8166 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8167 | } |
| 8168 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 8169 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 8170 | // move. |
| 8171 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8172 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8173 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8174 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 8175 | return; |
| 8176 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8177 | DCHECK(!cls->NeedsAccessCheck()); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 8178 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8179 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8180 | Location out_loc = locations->Out(); |
| 8181 | Register out = out_loc.AsRegister<Register>(); |
| 8182 | Register base_or_current_method_reg; |
| 8183 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8184 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8185 | switch (load_kind) { |
| 8186 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8187 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8188 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8189 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 8190 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8191 | base_or_current_method_reg = |
| 8192 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8193 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8194 | case HLoadClass::LoadKind::kReferrersClass: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8195 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8196 | base_or_current_method_reg = locations->InAt(0).AsRegister<Register>(); |
| 8197 | break; |
| 8198 | default: |
| 8199 | base_or_current_method_reg = ZERO; |
| 8200 | break; |
| 8201 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 8202 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8203 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 8204 | ? kWithoutReadBarrier |
| 8205 | : kCompilerReadBarrierOption; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8206 | bool generate_null_check = false; |
| 8207 | switch (load_kind) { |
| 8208 | case HLoadClass::LoadKind::kReferrersClass: { |
| 8209 | DCHECK(!cls->CanCallRuntime()); |
| 8210 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 8211 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 8212 | GenerateGcRootFieldLoad(cls, |
| 8213 | out_loc, |
| 8214 | base_or_current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8215 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 8216 | read_barrier_option); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8217 | break; |
| 8218 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8219 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8220 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8221 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8222 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8223 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8224 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8225 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8226 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8227 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 8228 | base_or_current_method_reg); |
| 8229 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8230 | break; |
| 8231 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8232 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8233 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8234 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8235 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8236 | codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8237 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8238 | codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8239 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8240 | out, |
| 8241 | base_or_current_method_reg); |
| 8242 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8243 | break; |
| 8244 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8245 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8246 | CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high = |
| 8247 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8248 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8249 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8250 | codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8251 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8252 | base_or_current_method_reg); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8253 | GenerateGcRootFieldLoad(cls, |
| 8254 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8255 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8256 | /* placeholder */ 0x5678, |
| 8257 | read_barrier_option, |
| 8258 | &info_low->label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8259 | generate_null_check = true; |
| 8260 | break; |
| 8261 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 8262 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 8263 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 8264 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 8265 | DCHECK_NE(address, 0u); |
| 8266 | if (isR6 || !has_irreducible_loops) { |
| 8267 | __ LoadLiteral(out, |
| 8268 | base_or_current_method_reg, |
| 8269 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 8270 | } else { |
| 8271 | __ LoadConst32(out, address); |
| 8272 | } |
| 8273 | break; |
| 8274 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8275 | case HLoadClass::LoadKind::kJitTableAddress: { |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8276 | CodeGeneratorMIPS::JitPatchInfo* info = codegen_->NewJitRootClassPatch(cls->GetDexFile(), |
| 8277 | cls->GetTypeIndex(), |
| 8278 | cls->GetClass()); |
| 8279 | bool reordering = __ SetReorder(false); |
| 8280 | __ Bind(&info->high_label); |
| 8281 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8282 | __ SetReorder(reordering); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8283 | GenerateGcRootFieldLoad(cls, |
| 8284 | out_loc, |
| 8285 | out, |
| 8286 | /* placeholder */ 0x5678, |
| 8287 | read_barrier_option, |
| 8288 | &info->low_label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8289 | break; |
| 8290 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8291 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 8292 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8293 | LOG(FATAL) << "UNREACHABLE"; |
| 8294 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8295 | } |
| 8296 | |
| 8297 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 8298 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 8299 | SlowPathCodeMIPS* slow_path = |
| 8300 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS(cls, cls); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8301 | codegen_->AddSlowPath(slow_path); |
| 8302 | if (generate_null_check) { |
| 8303 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 8304 | } |
| 8305 | if (cls->MustGenerateClinitCheck()) { |
| 8306 | GenerateClassInitializationCheck(slow_path, out); |
| 8307 | } else { |
| 8308 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8309 | } |
| 8310 | } |
| 8311 | } |
| 8312 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 8313 | void LocationsBuilderMIPS::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 8314 | InvokeRuntimeCallingConvention calling_convention; |
| 8315 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 8316 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, loc, loc); |
| 8317 | } |
| 8318 | |
| 8319 | void InstructionCodeGeneratorMIPS::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 8320 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 8321 | } |
| 8322 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 8323 | void LocationsBuilderMIPS::VisitLoadMethodType(HLoadMethodType* load) { |
| 8324 | InvokeRuntimeCallingConvention calling_convention; |
| 8325 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 8326 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, loc, loc); |
| 8327 | } |
| 8328 | |
| 8329 | void InstructionCodeGeneratorMIPS::VisitLoadMethodType(HLoadMethodType* load) { |
| 8330 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 8331 | } |
| 8332 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8333 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8334 | return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8335 | } |
| 8336 | |
| 8337 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { |
| 8338 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8339 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8340 | locations->SetOut(Location::RequiresRegister()); |
| 8341 | } |
| 8342 | |
| 8343 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { |
| 8344 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
| 8345 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 8346 | } |
| 8347 | |
| 8348 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8349 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8350 | } |
| 8351 | |
| 8352 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 8353 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
| 8354 | } |
| 8355 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8356 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 8357 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8358 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8359 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8360 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8361 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8362 | switch (load_kind) { |
| 8363 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8364 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8365 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8366 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 8367 | case HLoadString::LoadKind::kJitBootImageAddress: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8368 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8369 | break; |
| 8370 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8371 | if (has_irreducible_loops) { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 8372 | if (load_kind != HLoadString::LoadKind::kJitBootImageAddress) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 8373 | codegen_->ClobberRA(); |
| 8374 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8375 | break; |
| 8376 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8377 | FALLTHROUGH_INTENDED; |
| 8378 | // We need an extra register for PC-relative dex cache accesses. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8379 | case HLoadString::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8380 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8381 | break; |
| 8382 | default: |
| 8383 | break; |
| 8384 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8385 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8386 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8387 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8388 | } else { |
| 8389 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8390 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 8391 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 8392 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 8393 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8394 | } else { |
| 8395 | // For non-Baker read barriers we have a temp-clobbering call. |
| 8396 | } |
| 8397 | } |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8398 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8399 | } |
| 8400 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8401 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 8402 | // move. |
| 8403 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8404 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8405 | LocationSummary* locations = load->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8406 | Location out_loc = locations->Out(); |
| 8407 | Register out = out_loc.AsRegister<Register>(); |
| 8408 | Register base_or_current_method_reg; |
| 8409 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8410 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8411 | switch (load_kind) { |
| 8412 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8413 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8414 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8415 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 8416 | case HLoadString::LoadKind::kJitBootImageAddress: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8417 | base_or_current_method_reg = |
| 8418 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8419 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8420 | default: |
| 8421 | base_or_current_method_reg = ZERO; |
| 8422 | break; |
| 8423 | } |
| 8424 | |
| 8425 | switch (load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8426 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8427 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8428 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8429 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8430 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8431 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8432 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8433 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 8434 | base_or_current_method_reg); |
| 8435 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8436 | return; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8437 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8438 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8439 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8440 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(load); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8441 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8442 | codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8443 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8444 | codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8445 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8446 | out, |
| 8447 | base_or_current_method_reg); |
| 8448 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
| 8449 | return; |
| 8450 | } |
| 8451 | case HLoadString::LoadKind::kBssEntry: { |
| 8452 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 8453 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
| 8454 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| 8455 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8456 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8457 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8458 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8459 | base_or_current_method_reg); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8460 | GenerateGcRootFieldLoad(load, |
| 8461 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8462 | out, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8463 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8464 | kCompilerReadBarrierOption, |
| 8465 | &info_low->label); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8466 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8467 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8468 | codegen_->AddSlowPath(slow_path); |
| 8469 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 8470 | __ Bind(slow_path->GetExitLabel()); |
| 8471 | return; |
| 8472 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 8473 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 8474 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 8475 | DCHECK_NE(address, 0u); |
| 8476 | if (isR6 || !has_irreducible_loops) { |
| 8477 | __ LoadLiteral(out, |
| 8478 | base_or_current_method_reg, |
| 8479 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 8480 | } else { |
| 8481 | __ LoadConst32(out, address); |
| 8482 | } |
| 8483 | return; |
| 8484 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8485 | case HLoadString::LoadKind::kJitTableAddress: { |
| 8486 | CodeGeneratorMIPS::JitPatchInfo* info = |
| 8487 | codegen_->NewJitRootStringPatch(load->GetDexFile(), |
| 8488 | load->GetStringIndex(), |
| 8489 | load->GetString()); |
| 8490 | bool reordering = __ SetReorder(false); |
| 8491 | __ Bind(&info->high_label); |
| 8492 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8493 | __ SetReorder(reordering); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8494 | GenerateGcRootFieldLoad(load, |
| 8495 | out_loc, |
| 8496 | out, |
| 8497 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8498 | kCompilerReadBarrierOption, |
| 8499 | &info->low_label); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8500 | return; |
| 8501 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8502 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8503 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8504 | } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 8505 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8506 | // 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] | 8507 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8508 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8509 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8510 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8511 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 8512 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8513 | } |
| 8514 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8515 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8516 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8517 | locations->SetOut(Location::ConstantLocation(constant)); |
| 8518 | } |
| 8519 | |
| 8520 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 8521 | // Will be generated at use site. |
| 8522 | } |
| 8523 | |
| 8524 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8525 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8526 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8527 | InvokeRuntimeCallingConvention calling_convention; |
| 8528 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8529 | } |
| 8530 | |
| 8531 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8532 | if (instruction->IsEnter()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8533 | codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8534 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8535 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8536 | codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8537 | } |
| 8538 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8539 | } |
| 8540 | |
| 8541 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { |
| 8542 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8543 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8544 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8545 | case DataType::Type::kInt32: |
| 8546 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8547 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8548 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8549 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8550 | break; |
| 8551 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8552 | case DataType::Type::kFloat32: |
| 8553 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8554 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8555 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 8556 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8557 | break; |
| 8558 | |
| 8559 | default: |
| 8560 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 8561 | } |
| 8562 | } |
| 8563 | |
| 8564 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8565 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8566 | LocationSummary* locations = instruction->GetLocations(); |
| 8567 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 8568 | |
| 8569 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8570 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8571 | Register dst = locations->Out().AsRegister<Register>(); |
| 8572 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 8573 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 8574 | |
| 8575 | if (isR6) { |
| 8576 | __ MulR6(dst, lhs, rhs); |
| 8577 | } else { |
| 8578 | __ MulR2(dst, lhs, rhs); |
| 8579 | } |
| 8580 | break; |
| 8581 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8582 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8583 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8584 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8585 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8586 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8587 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 8588 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 8589 | |
| 8590 | // Extra checks to protect caused by the existance of A1_A2. |
| 8591 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: |
| 8592 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). |
| 8593 | DCHECK_NE(dst_high, lhs_low); |
| 8594 | DCHECK_NE(dst_high, rhs_low); |
| 8595 | |
| 8596 | // A_B * C_D |
| 8597 | // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ] |
| 8598 | // dst_lo: [ low(B*D) ] |
| 8599 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. |
| 8600 | |
| 8601 | if (isR6) { |
| 8602 | __ MulR6(TMP, lhs_high, rhs_low); |
| 8603 | __ MulR6(dst_high, lhs_low, rhs_high); |
| 8604 | __ Addu(dst_high, dst_high, TMP); |
| 8605 | __ MuhuR6(TMP, lhs_low, rhs_low); |
| 8606 | __ Addu(dst_high, dst_high, TMP); |
| 8607 | __ MulR6(dst_low, lhs_low, rhs_low); |
| 8608 | } else { |
| 8609 | __ MulR2(TMP, lhs_high, rhs_low); |
| 8610 | __ MulR2(dst_high, lhs_low, rhs_high); |
| 8611 | __ Addu(dst_high, dst_high, TMP); |
| 8612 | __ MultuR2(lhs_low, rhs_low); |
| 8613 | __ Mfhi(TMP); |
| 8614 | __ Addu(dst_high, dst_high, TMP); |
| 8615 | __ Mflo(dst_low); |
| 8616 | } |
| 8617 | break; |
| 8618 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8619 | case DataType::Type::kFloat32: |
| 8620 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8621 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8622 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8623 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8624 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8625 | __ MulS(dst, lhs, rhs); |
| 8626 | } else { |
| 8627 | __ MulD(dst, lhs, rhs); |
| 8628 | } |
| 8629 | break; |
| 8630 | } |
| 8631 | default: |
| 8632 | LOG(FATAL) << "Unexpected mul type " << type; |
| 8633 | } |
| 8634 | } |
| 8635 | |
| 8636 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { |
| 8637 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8638 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8639 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8640 | case DataType::Type::kInt32: |
| 8641 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8642 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8643 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8644 | break; |
| 8645 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8646 | case DataType::Type::kFloat32: |
| 8647 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8648 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8649 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8650 | break; |
| 8651 | |
| 8652 | default: |
| 8653 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 8654 | } |
| 8655 | } |
| 8656 | |
| 8657 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8658 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8659 | LocationSummary* locations = instruction->GetLocations(); |
| 8660 | |
| 8661 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8662 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8663 | Register dst = locations->Out().AsRegister<Register>(); |
| 8664 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8665 | __ Subu(dst, ZERO, src); |
| 8666 | break; |
| 8667 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8668 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8669 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8670 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8671 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8672 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8673 | __ Subu(dst_low, ZERO, src_low); |
| 8674 | __ Sltu(TMP, ZERO, dst_low); |
| 8675 | __ Subu(dst_high, ZERO, src_high); |
| 8676 | __ Subu(dst_high, dst_high, TMP); |
| 8677 | break; |
| 8678 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8679 | case DataType::Type::kFloat32: |
| 8680 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8681 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8682 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8683 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8684 | __ NegS(dst, src); |
| 8685 | } else { |
| 8686 | __ NegD(dst, src); |
| 8687 | } |
| 8688 | break; |
| 8689 | } |
| 8690 | default: |
| 8691 | LOG(FATAL) << "Unexpected neg type " << type; |
| 8692 | } |
| 8693 | } |
| 8694 | |
| 8695 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8696 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8697 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8698 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8699 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8700 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8701 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8702 | } |
| 8703 | |
| 8704 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 8705 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 8706 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8707 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8708 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8709 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8710 | } |
| 8711 | |
| 8712 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8713 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8714 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8715 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 8716 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8717 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8718 | } |
| 8719 | |
| 8720 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 8721 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 8722 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8723 | } |
| 8724 | |
| 8725 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8726 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8727 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8728 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8729 | } |
| 8730 | |
| 8731 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8732 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8733 | LocationSummary* locations = instruction->GetLocations(); |
| 8734 | |
| 8735 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8736 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8737 | Register dst = locations->Out().AsRegister<Register>(); |
| 8738 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8739 | __ Nor(dst, src, ZERO); |
| 8740 | break; |
| 8741 | } |
| 8742 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8743 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8744 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8745 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8746 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8747 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8748 | __ Nor(dst_high, src_high, ZERO); |
| 8749 | __ Nor(dst_low, src_low, ZERO); |
| 8750 | break; |
| 8751 | } |
| 8752 | |
| 8753 | default: |
| 8754 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 8755 | } |
| 8756 | } |
| 8757 | |
| 8758 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8759 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8760 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8761 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8762 | } |
| 8763 | |
| 8764 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 8765 | LocationSummary* locations = instruction->GetLocations(); |
| 8766 | __ Xori(locations->Out().AsRegister<Register>(), |
| 8767 | locations->InAt(0).AsRegister<Register>(), |
| 8768 | 1); |
| 8769 | } |
| 8770 | |
| 8771 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 8772 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 8773 | locations->SetInAt(0, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8774 | } |
| 8775 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8776 | void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 8777 | if (CanMoveNullCheckToUser(instruction)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8778 | return; |
| 8779 | } |
| 8780 | Location obj = instruction->GetLocations()->InAt(0); |
| 8781 | |
| 8782 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8783 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8784 | } |
| 8785 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8786 | void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8787 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) NullCheckSlowPathMIPS(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8788 | AddSlowPath(slow_path); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8789 | |
| 8790 | Location obj = instruction->GetLocations()->InAt(0); |
| 8791 | |
| 8792 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8793 | } |
| 8794 | |
| 8795 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8796 | codegen_->GenerateNullCheck(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8797 | } |
| 8798 | |
| 8799 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { |
| 8800 | HandleBinaryOp(instruction); |
| 8801 | } |
| 8802 | |
| 8803 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { |
| 8804 | HandleBinaryOp(instruction); |
| 8805 | } |
| 8806 | |
| 8807 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 8808 | LOG(FATAL) << "Unreachable"; |
| 8809 | } |
| 8810 | |
| 8811 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 8812 | if (instruction->GetNext()->IsSuspendCheck() && |
| 8813 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 8814 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 8815 | // The back edge will generate the suspend check. |
| 8816 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 8817 | } |
| 8818 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8819 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 8820 | } |
| 8821 | |
| 8822 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8823 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8824 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 8825 | if (location.IsStackSlot()) { |
| 8826 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8827 | } else if (location.IsDoubleStackSlot()) { |
| 8828 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8829 | } |
| 8830 | locations->SetOut(location); |
| 8831 | } |
| 8832 | |
| 8833 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction |
| 8834 | ATTRIBUTE_UNUSED) { |
| 8835 | // Nothing to do, the parameter is already at its location. |
| 8836 | } |
| 8837 | |
| 8838 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 8839 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8840 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8841 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 8842 | } |
| 8843 | |
| 8844 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction |
| 8845 | ATTRIBUTE_UNUSED) { |
| 8846 | // Nothing to do, the method is already at its location. |
| 8847 | } |
| 8848 | |
| 8849 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8850 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 8851 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8852 | locations->SetInAt(i, Location::Any()); |
| 8853 | } |
| 8854 | locations->SetOut(Location::Any()); |
| 8855 | } |
| 8856 | |
| 8857 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 8858 | LOG(FATAL) << "Unreachable"; |
| 8859 | } |
| 8860 | |
| 8861 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8862 | DataType::Type type = rem->GetResultType(); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8863 | bool call_rem; |
| 8864 | if ((type == DataType::Type::kInt64) && rem->InputAt(1)->IsConstant()) { |
| 8865 | int64_t imm = CodeGenerator::GetInt64ValueOf(rem->InputAt(1)->AsConstant()); |
| 8866 | call_rem = (imm != 0) && !IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm))); |
| 8867 | } else { |
| 8868 | call_rem = (type != DataType::Type::kInt32); |
| 8869 | } |
| 8870 | LocationSummary::CallKind call_kind = call_rem |
| 8871 | ? LocationSummary::kCallOnMainOnly |
| 8872 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8873 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8874 | |
| 8875 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8876 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8877 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8878 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8879 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8880 | break; |
| 8881 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8882 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8883 | if (call_rem) { |
| 8884 | InvokeRuntimeCallingConvention calling_convention; |
| 8885 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 8886 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 8887 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 8888 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 8889 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8890 | } else { |
| 8891 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8892 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 8893 | locations->SetOut(Location::RequiresRegister()); |
| 8894 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8895 | break; |
| 8896 | } |
| 8897 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8898 | case DataType::Type::kFloat32: |
| 8899 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8900 | InvokeRuntimeCallingConvention calling_convention; |
| 8901 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 8902 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 8903 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8904 | break; |
| 8905 | } |
| 8906 | |
| 8907 | default: |
| 8908 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8909 | } |
| 8910 | } |
| 8911 | |
| 8912 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8913 | DataType::Type type = instruction->GetType(); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8914 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8915 | |
| 8916 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8917 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8918 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8919 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8920 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8921 | if (locations->InAt(1).IsConstant()) { |
| 8922 | int64_t imm = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue(); |
| 8923 | if (imm == 0) { |
| 8924 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 8925 | } else if (imm == 1 || imm == -1) { |
| 8926 | DivRemOneOrMinusOne(instruction); |
| 8927 | } else { |
| 8928 | DCHECK(IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm)))); |
| 8929 | DivRemByPowerOfTwo(instruction); |
| 8930 | } |
| 8931 | } else { |
| 8932 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
| 8933 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 8934 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8935 | break; |
| 8936 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8937 | case DataType::Type::kFloat32: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8938 | codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8939 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8940 | break; |
| 8941 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8942 | case DataType::Type::kFloat64: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8943 | codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8944 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8945 | break; |
| 8946 | } |
| 8947 | default: |
| 8948 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8949 | } |
| 8950 | } |
| 8951 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 8952 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 8953 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 8954 | switch (minmax->GetResultType()) { |
| 8955 | case DataType::Type::kInt32: |
| 8956 | case DataType::Type::kInt64: |
| 8957 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8958 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8959 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8960 | break; |
| 8961 | case DataType::Type::kFloat32: |
| 8962 | case DataType::Type::kFloat64: |
| 8963 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8964 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 8965 | locations->SetOut(Location::RequiresFpuRegister(), Location::kOutputOverlap); |
| 8966 | break; |
| 8967 | default: |
| 8968 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 8969 | } |
| 8970 | } |
| 8971 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 8972 | void InstructionCodeGeneratorMIPS::GenerateMinMaxInt(LocationSummary* locations, |
| 8973 | bool is_min, |
| 8974 | bool isR6, |
| 8975 | DataType::Type type) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 8976 | if (isR6) { |
| 8977 | // Some architectures, such as ARM and MIPS (prior to r6), have a |
| 8978 | // conditional move instruction which only changes the target |
| 8979 | // (output) register if the condition is true (MIPS prior to r6 had |
| 8980 | // MOVF, MOVT, MOVN, and MOVZ). The SELEQZ and SELNEZ instructions |
| 8981 | // always change the target (output) register. If the condition is |
| 8982 | // true the output register gets the contents of the "rs" register; |
| 8983 | // otherwise, the output register is set to zero. One consequence |
| 8984 | // of this is that to implement something like "rd = c==0 ? rs : rt" |
| 8985 | // MIPS64r6 needs to use a pair of SELEQZ/SELNEZ instructions. |
| 8986 | // After executing this pair of instructions one of the output |
| 8987 | // registers from the pair will necessarily contain zero. Then the |
| 8988 | // code ORs the output registers from the SELEQZ/SELNEZ instructions |
| 8989 | // to get the final result. |
| 8990 | // |
| 8991 | // The initial test to see if the output register is same as the |
| 8992 | // first input register is needed to make sure that value in the |
| 8993 | // first input register isn't clobbered before we've finished |
| 8994 | // computing the output value. The logic in the corresponding else |
| 8995 | // clause performs the same task but makes sure the second input |
| 8996 | // register isn't clobbered in the event that it's the same register |
| 8997 | // as the output register; the else clause also handles the case |
| 8998 | // where the output register is distinct from both the first, and the |
| 8999 | // second input registers. |
| 9000 | if (type == DataType::Type::kInt64) { |
| 9001 | Register a_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 9002 | Register a_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 9003 | Register b_lo = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 9004 | Register b_hi = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 9005 | Register out_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 9006 | Register out_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 9007 | |
| 9008 | MipsLabel compare_done; |
| 9009 | |
| 9010 | if (a_lo == b_lo) { |
| 9011 | if (out_lo != a_lo) { |
| 9012 | __ Move(out_lo, a_lo); |
| 9013 | __ Move(out_hi, a_hi); |
| 9014 | } |
| 9015 | } else { |
| 9016 | __ Slt(TMP, b_hi, a_hi); |
| 9017 | __ Bne(b_hi, a_hi, &compare_done); |
| 9018 | |
| 9019 | __ Sltu(TMP, b_lo, a_lo); |
| 9020 | |
| 9021 | __ Bind(&compare_done); |
| 9022 | |
| 9023 | if (is_min) { |
| 9024 | __ Seleqz(AT, a_lo, TMP); |
| 9025 | __ Selnez(out_lo, b_lo, TMP); // Safe even if out_lo == a_lo/b_lo |
| 9026 | // because at this point we're |
| 9027 | // done using a_lo/b_lo. |
| 9028 | } else { |
| 9029 | __ Selnez(AT, a_lo, TMP); |
| 9030 | __ Seleqz(out_lo, b_lo, TMP); // ditto |
| 9031 | } |
| 9032 | __ Or(out_lo, out_lo, AT); |
| 9033 | if (is_min) { |
| 9034 | __ Seleqz(AT, a_hi, TMP); |
| 9035 | __ Selnez(out_hi, b_hi, TMP); // ditto but for out_hi & a_hi/b_hi |
| 9036 | } else { |
| 9037 | __ Selnez(AT, a_hi, TMP); |
| 9038 | __ Seleqz(out_hi, b_hi, TMP); // ditto but for out_hi & a_hi/b_hi |
| 9039 | } |
| 9040 | __ Or(out_hi, out_hi, AT); |
| 9041 | } |
| 9042 | } else { |
| 9043 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 9044 | Register a = locations->InAt(0).AsRegister<Register>(); |
| 9045 | Register b = locations->InAt(1).AsRegister<Register>(); |
| 9046 | Register out = locations->Out().AsRegister<Register>(); |
| 9047 | |
| 9048 | if (a == b) { |
| 9049 | if (out != a) { |
| 9050 | __ Move(out, a); |
| 9051 | } |
| 9052 | } else { |
| 9053 | __ Slt(AT, b, a); |
| 9054 | if (is_min) { |
| 9055 | __ Seleqz(TMP, a, AT); |
| 9056 | __ Selnez(AT, b, AT); |
| 9057 | } else { |
| 9058 | __ Selnez(TMP, a, AT); |
| 9059 | __ Seleqz(AT, b, AT); |
| 9060 | } |
| 9061 | __ Or(out, TMP, AT); |
| 9062 | } |
| 9063 | } |
| 9064 | } else { // !isR6 |
| 9065 | if (type == DataType::Type::kInt64) { |
| 9066 | Register a_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 9067 | Register a_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 9068 | Register b_lo = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 9069 | Register b_hi = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 9070 | Register out_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 9071 | Register out_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 9072 | |
| 9073 | MipsLabel compare_done; |
| 9074 | |
| 9075 | if (a_lo == b_lo) { |
| 9076 | if (out_lo != a_lo) { |
| 9077 | __ Move(out_lo, a_lo); |
| 9078 | __ Move(out_hi, a_hi); |
| 9079 | } |
| 9080 | } else { |
| 9081 | __ Slt(TMP, a_hi, b_hi); |
| 9082 | __ Bne(a_hi, b_hi, &compare_done); |
| 9083 | |
| 9084 | __ Sltu(TMP, a_lo, b_lo); |
| 9085 | |
| 9086 | __ Bind(&compare_done); |
| 9087 | |
| 9088 | if (is_min) { |
| 9089 | if (out_lo != a_lo) { |
| 9090 | __ Movn(out_hi, a_hi, TMP); |
| 9091 | __ Movn(out_lo, a_lo, TMP); |
| 9092 | } |
| 9093 | if (out_lo != b_lo) { |
| 9094 | __ Movz(out_hi, b_hi, TMP); |
| 9095 | __ Movz(out_lo, b_lo, TMP); |
| 9096 | } |
| 9097 | } else { |
| 9098 | if (out_lo != a_lo) { |
| 9099 | __ Movz(out_hi, a_hi, TMP); |
| 9100 | __ Movz(out_lo, a_lo, TMP); |
| 9101 | } |
| 9102 | if (out_lo != b_lo) { |
| 9103 | __ Movn(out_hi, b_hi, TMP); |
| 9104 | __ Movn(out_lo, b_lo, TMP); |
| 9105 | } |
| 9106 | } |
| 9107 | } |
| 9108 | } else { |
| 9109 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 9110 | Register a = locations->InAt(0).AsRegister<Register>(); |
| 9111 | Register b = locations->InAt(1).AsRegister<Register>(); |
| 9112 | Register out = locations->Out().AsRegister<Register>(); |
| 9113 | |
| 9114 | if (a == b) { |
| 9115 | if (out != a) { |
| 9116 | __ Move(out, a); |
| 9117 | } |
| 9118 | } else { |
| 9119 | __ Slt(AT, a, b); |
| 9120 | if (is_min) { |
| 9121 | if (out != a) { |
| 9122 | __ Movn(out, a, AT); |
| 9123 | } |
| 9124 | if (out != b) { |
| 9125 | __ Movz(out, b, AT); |
| 9126 | } |
| 9127 | } else { |
| 9128 | if (out != a) { |
| 9129 | __ Movz(out, a, AT); |
| 9130 | } |
| 9131 | if (out != b) { |
| 9132 | __ Movn(out, b, AT); |
| 9133 | } |
| 9134 | } |
| 9135 | } |
| 9136 | } |
| 9137 | } |
| 9138 | } |
| 9139 | |
| 9140 | void InstructionCodeGeneratorMIPS::GenerateMinMaxFP(LocationSummary* locations, |
| 9141 | bool is_min, |
| 9142 | bool isR6, |
| 9143 | DataType::Type type) { |
| 9144 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 9145 | FRegister a = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9146 | FRegister b = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 9147 | |
| 9148 | if (isR6) { |
| 9149 | MipsLabel noNaNs; |
| 9150 | MipsLabel done; |
| 9151 | FRegister ftmp = ((out != a) && (out != b)) ? out : FTMP; |
| 9152 | |
| 9153 | // When Java computes min/max it prefers a NaN to a number; the |
| 9154 | // behavior of MIPSR6 is to prefer numbers to NaNs, i.e., if one of |
| 9155 | // the inputs is a NaN and the other is a valid number, the MIPS |
| 9156 | // instruction will return the number; Java wants the NaN value |
| 9157 | // returned. This is why there is extra logic preceding the use of |
| 9158 | // the MIPS min.fmt/max.fmt instructions. If either a, or b holds a |
| 9159 | // NaN, return the NaN, otherwise return the min/max. |
| 9160 | if (type == DataType::Type::kFloat64) { |
| 9161 | __ CmpUnD(FTMP, a, b); |
| 9162 | __ Bc1eqz(FTMP, &noNaNs); |
| 9163 | |
| 9164 | // One of the inputs is a NaN |
| 9165 | __ CmpEqD(ftmp, a, a); |
| 9166 | // If a == a then b is the NaN, otherwise a is the NaN. |
| 9167 | __ SelD(ftmp, a, b); |
| 9168 | |
| 9169 | if (ftmp != out) { |
| 9170 | __ MovD(out, ftmp); |
| 9171 | } |
| 9172 | |
| 9173 | __ B(&done); |
| 9174 | |
| 9175 | __ Bind(&noNaNs); |
| 9176 | |
| 9177 | if (is_min) { |
| 9178 | __ MinD(out, a, b); |
| 9179 | } else { |
| 9180 | __ MaxD(out, a, b); |
| 9181 | } |
| 9182 | } else { |
| 9183 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 9184 | __ CmpUnS(FTMP, a, b); |
| 9185 | __ Bc1eqz(FTMP, &noNaNs); |
| 9186 | |
| 9187 | // One of the inputs is a NaN |
| 9188 | __ CmpEqS(ftmp, a, a); |
| 9189 | // If a == a then b is the NaN, otherwise a is the NaN. |
| 9190 | __ SelS(ftmp, a, b); |
| 9191 | |
| 9192 | if (ftmp != out) { |
| 9193 | __ MovS(out, ftmp); |
| 9194 | } |
| 9195 | |
| 9196 | __ B(&done); |
| 9197 | |
| 9198 | __ Bind(&noNaNs); |
| 9199 | |
| 9200 | if (is_min) { |
| 9201 | __ MinS(out, a, b); |
| 9202 | } else { |
| 9203 | __ MaxS(out, a, b); |
| 9204 | } |
| 9205 | } |
| 9206 | |
| 9207 | __ Bind(&done); |
| 9208 | |
| 9209 | } else { // !isR6 |
| 9210 | MipsLabel ordered; |
| 9211 | MipsLabel compare; |
| 9212 | MipsLabel select; |
| 9213 | MipsLabel done; |
| 9214 | |
| 9215 | if (type == DataType::Type::kFloat64) { |
| 9216 | __ CunD(a, b); |
| 9217 | } else { |
| 9218 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 9219 | __ CunS(a, b); |
| 9220 | } |
| 9221 | __ Bc1f(&ordered); |
| 9222 | |
| 9223 | // a or b (or both) is a NaN. Return one, which is a NaN. |
| 9224 | if (type == DataType::Type::kFloat64) { |
| 9225 | __ CeqD(b, b); |
| 9226 | } else { |
| 9227 | __ CeqS(b, b); |
| 9228 | } |
| 9229 | __ B(&select); |
| 9230 | |
| 9231 | __ Bind(&ordered); |
| 9232 | |
| 9233 | // Neither is a NaN. |
| 9234 | // a == b? (-0.0 compares equal with +0.0) |
| 9235 | // If equal, handle zeroes, else compare further. |
| 9236 | if (type == DataType::Type::kFloat64) { |
| 9237 | __ CeqD(a, b); |
| 9238 | } else { |
| 9239 | __ CeqS(a, b); |
| 9240 | } |
| 9241 | __ Bc1f(&compare); |
| 9242 | |
| 9243 | // a == b either bit for bit or one is -0.0 and the other is +0.0. |
| 9244 | if (type == DataType::Type::kFloat64) { |
| 9245 | __ MoveFromFpuHigh(TMP, a); |
| 9246 | __ MoveFromFpuHigh(AT, b); |
| 9247 | } else { |
| 9248 | __ Mfc1(TMP, a); |
| 9249 | __ Mfc1(AT, b); |
| 9250 | } |
| 9251 | |
| 9252 | if (is_min) { |
| 9253 | // -0.0 prevails over +0.0. |
| 9254 | __ Or(TMP, TMP, AT); |
| 9255 | } else { |
| 9256 | // +0.0 prevails over -0.0. |
| 9257 | __ And(TMP, TMP, AT); |
| 9258 | } |
| 9259 | |
| 9260 | if (type == DataType::Type::kFloat64) { |
| 9261 | __ Mfc1(AT, a); |
| 9262 | __ Mtc1(AT, out); |
| 9263 | __ MoveToFpuHigh(TMP, out); |
| 9264 | } else { |
| 9265 | __ Mtc1(TMP, out); |
| 9266 | } |
| 9267 | __ B(&done); |
| 9268 | |
| 9269 | __ Bind(&compare); |
| 9270 | |
| 9271 | if (type == DataType::Type::kFloat64) { |
| 9272 | if (is_min) { |
| 9273 | // return (a <= b) ? a : b; |
| 9274 | __ ColeD(a, b); |
| 9275 | } else { |
| 9276 | // return (a >= b) ? a : b; |
| 9277 | __ ColeD(b, a); // b <= a |
| 9278 | } |
| 9279 | } else { |
| 9280 | if (is_min) { |
| 9281 | // return (a <= b) ? a : b; |
| 9282 | __ ColeS(a, b); |
| 9283 | } else { |
| 9284 | // return (a >= b) ? a : b; |
| 9285 | __ ColeS(b, a); // b <= a |
| 9286 | } |
| 9287 | } |
| 9288 | |
| 9289 | __ Bind(&select); |
| 9290 | |
| 9291 | if (type == DataType::Type::kFloat64) { |
| 9292 | __ MovtD(out, a); |
| 9293 | __ MovfD(out, b); |
| 9294 | } else { |
| 9295 | __ MovtS(out, a); |
| 9296 | __ MovfS(out, b); |
| 9297 | } |
| 9298 | |
| 9299 | __ Bind(&done); |
| 9300 | } |
| 9301 | } |
| 9302 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 9303 | void InstructionCodeGeneratorMIPS::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 9304 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 9305 | DataType::Type type = minmax->GetResultType(); |
| 9306 | switch (type) { |
| 9307 | case DataType::Type::kInt32: |
| 9308 | case DataType::Type::kInt64: |
| 9309 | GenerateMinMaxInt(minmax->GetLocations(), is_min, isR6, type); |
| 9310 | break; |
| 9311 | case DataType::Type::kFloat32: |
| 9312 | case DataType::Type::kFloat64: |
| 9313 | GenerateMinMaxFP(minmax->GetLocations(), is_min, isR6, type); |
| 9314 | break; |
| 9315 | default: |
| 9316 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 9317 | } |
| 9318 | } |
| 9319 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 9320 | void LocationsBuilderMIPS::VisitMin(HMin* min) { |
| 9321 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 9322 | } |
| 9323 | |
| 9324 | void InstructionCodeGeneratorMIPS::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 9325 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 9326 | } |
| 9327 | |
| 9328 | void LocationsBuilderMIPS::VisitMax(HMax* max) { |
| 9329 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 9330 | } |
| 9331 | |
| 9332 | void InstructionCodeGeneratorMIPS::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 9333 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 9334 | } |
| 9335 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 9336 | void LocationsBuilderMIPS::VisitAbs(HAbs* abs) { |
| 9337 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 9338 | switch (abs->GetResultType()) { |
| 9339 | case DataType::Type::kInt32: |
| 9340 | case DataType::Type::kInt64: |
| 9341 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9342 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9343 | break; |
| 9344 | case DataType::Type::kFloat32: |
| 9345 | case DataType::Type::kFloat64: |
| 9346 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 9347 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 9348 | break; |
| 9349 | default: |
| 9350 | LOG(FATAL) << "Unexpected abs type " << abs->GetResultType(); |
| 9351 | } |
| 9352 | } |
| 9353 | |
| 9354 | void InstructionCodeGeneratorMIPS::GenerateAbsFP(LocationSummary* locations, |
| 9355 | DataType::Type type, |
| 9356 | bool isR2OrNewer, |
| 9357 | bool isR6) { |
| 9358 | FRegister in = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9359 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 9360 | |
| 9361 | // Note, as a "quality of implementation", rather than pure "spec compliance", we require that |
| 9362 | // Math.abs() clears the sign bit (but changes nothing else) for all numbers, including NaN |
| 9363 | // (signaling NaN may become quiet though). |
| 9364 | // |
| 9365 | // The ABS.fmt instructions (abs.s and abs.d) do exactly that when NAN2008=1 (R6). For this case, |
| 9366 | // both regular floating point numbers and NAN values are treated alike, only the sign bit is |
| 9367 | // affected by this instruction. |
| 9368 | // But when NAN2008=0 (R2 and before), the ABS.fmt instructions can't be used. For this case, any |
| 9369 | // NaN operand signals invalid operation. This means that other bits (not just sign bit) might be |
| 9370 | // changed when doing abs(NaN). Because of that, we clear sign bit in a different way. |
| 9371 | if (isR6) { |
| 9372 | if (type == DataType::Type::kFloat64) { |
| 9373 | __ AbsD(out, in); |
| 9374 | } else { |
| 9375 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 9376 | __ AbsS(out, in); |
| 9377 | } |
| 9378 | } else { |
| 9379 | if (type == DataType::Type::kFloat64) { |
| 9380 | if (in != out) { |
| 9381 | __ MovD(out, in); |
| 9382 | } |
| 9383 | __ MoveFromFpuHigh(TMP, in); |
| 9384 | // ins instruction is not available for R1. |
| 9385 | if (isR2OrNewer) { |
| 9386 | __ Ins(TMP, ZERO, 31, 1); |
| 9387 | } else { |
| 9388 | __ Sll(TMP, TMP, 1); |
| 9389 | __ Srl(TMP, TMP, 1); |
| 9390 | } |
| 9391 | __ MoveToFpuHigh(TMP, out); |
| 9392 | } else { |
| 9393 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 9394 | __ Mfc1(TMP, in); |
| 9395 | // ins instruction is not available for R1. |
| 9396 | if (isR2OrNewer) { |
| 9397 | __ Ins(TMP, ZERO, 31, 1); |
| 9398 | } else { |
| 9399 | __ Sll(TMP, TMP, 1); |
| 9400 | __ Srl(TMP, TMP, 1); |
| 9401 | } |
| 9402 | __ Mtc1(TMP, out); |
| 9403 | } |
| 9404 | } |
| 9405 | } |
| 9406 | |
| 9407 | void InstructionCodeGeneratorMIPS::VisitAbs(HAbs* abs) { |
| 9408 | LocationSummary* locations = abs->GetLocations(); |
| 9409 | bool isR2OrNewer = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
| 9410 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 9411 | switch (abs->GetResultType()) { |
| 9412 | case DataType::Type::kInt32: { |
| 9413 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 9414 | Register out = locations->Out().AsRegister<Register>(); |
| 9415 | __ Sra(AT, in, 31); |
| 9416 | __ Xor(out, in, AT); |
| 9417 | __ Subu(out, out, AT); |
| 9418 | break; |
| 9419 | } |
| 9420 | case DataType::Type::kInt64: { |
| 9421 | Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 9422 | Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 9423 | Register out_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 9424 | Register out_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 9425 | // The comments in this section show the analogous operations which would |
| 9426 | // be performed if we had 64-bit registers "in", and "out". |
| 9427 | // __ Dsra32(AT, in, 31); |
| 9428 | __ Sra(AT, in_hi, 31); |
| 9429 | // __ Xor(out, in, AT); |
| 9430 | __ Xor(TMP, in_lo, AT); |
| 9431 | __ Xor(out_hi, in_hi, AT); |
| 9432 | // __ Dsubu(out, out, AT); |
| 9433 | __ Subu(out_lo, TMP, AT); |
| 9434 | __ Sltu(TMP, out_lo, TMP); |
| 9435 | __ Addu(out_hi, out_hi, TMP); |
| 9436 | break; |
| 9437 | } |
| 9438 | case DataType::Type::kFloat32: |
| 9439 | case DataType::Type::kFloat64: |
| 9440 | GenerateAbsFP(locations, abs->GetResultType(), isR2OrNewer, isR6); |
| 9441 | break; |
| 9442 | default: |
| 9443 | LOG(FATAL) << "Unexpected abs type " << abs->GetResultType(); |
| 9444 | } |
| 9445 | } |
| 9446 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 9447 | void LocationsBuilderMIPS::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 9448 | constructor_fence->SetLocations(nullptr); |
| 9449 | } |
| 9450 | |
| 9451 | void InstructionCodeGeneratorMIPS::VisitConstructorFence( |
| 9452 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 9453 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 9454 | } |
| 9455 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9456 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 9457 | memory_barrier->SetLocations(nullptr); |
| 9458 | } |
| 9459 | |
| 9460 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 9461 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 9462 | } |
| 9463 | |
| 9464 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9465 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9466 | DataType::Type return_type = ret->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9467 | locations->SetInAt(0, MipsReturnLocation(return_type)); |
| 9468 | } |
| 9469 | |
| 9470 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 9471 | codegen_->GenerateFrameExit(); |
| 9472 | } |
| 9473 | |
| 9474 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { |
| 9475 | ret->SetLocations(nullptr); |
| 9476 | } |
| 9477 | |
| 9478 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 9479 | codegen_->GenerateFrameExit(); |
| 9480 | } |
| 9481 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 9482 | void LocationsBuilderMIPS::VisitRor(HRor* ror) { |
| 9483 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 9484 | } |
| 9485 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 9486 | void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) { |
| 9487 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 9488 | } |
| 9489 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9490 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { |
| 9491 | HandleShift(shl); |
| 9492 | } |
| 9493 | |
| 9494 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { |
| 9495 | HandleShift(shl); |
| 9496 | } |
| 9497 | |
| 9498 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { |
| 9499 | HandleShift(shr); |
| 9500 | } |
| 9501 | |
| 9502 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { |
| 9503 | HandleShift(shr); |
| 9504 | } |
| 9505 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9506 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { |
| 9507 | HandleBinaryOp(instruction); |
| 9508 | } |
| 9509 | |
| 9510 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { |
| 9511 | HandleBinaryOp(instruction); |
| 9512 | } |
| 9513 | |
| 9514 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 9515 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 9516 | } |
| 9517 | |
| 9518 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 9519 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 9520 | } |
| 9521 | |
| 9522 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 9523 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 9524 | } |
| 9525 | |
| 9526 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 9527 | HandleFieldSet(instruction, |
| 9528 | instruction->GetFieldInfo(), |
| 9529 | instruction->GetDexPc(), |
| 9530 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9531 | } |
| 9532 | |
| 9533 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( |
| 9534 | HUnresolvedInstanceFieldGet* instruction) { |
| 9535 | FieldAccessCallingConventionMIPS calling_convention; |
| 9536 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 9537 | instruction->GetFieldType(), |
| 9538 | calling_convention); |
| 9539 | } |
| 9540 | |
| 9541 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( |
| 9542 | HUnresolvedInstanceFieldGet* instruction) { |
| 9543 | FieldAccessCallingConventionMIPS calling_convention; |
| 9544 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 9545 | instruction->GetFieldType(), |
| 9546 | instruction->GetFieldIndex(), |
| 9547 | instruction->GetDexPc(), |
| 9548 | calling_convention); |
| 9549 | } |
| 9550 | |
| 9551 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( |
| 9552 | HUnresolvedInstanceFieldSet* instruction) { |
| 9553 | FieldAccessCallingConventionMIPS calling_convention; |
| 9554 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 9555 | instruction->GetFieldType(), |
| 9556 | calling_convention); |
| 9557 | } |
| 9558 | |
| 9559 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( |
| 9560 | HUnresolvedInstanceFieldSet* instruction) { |
| 9561 | FieldAccessCallingConventionMIPS calling_convention; |
| 9562 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 9563 | instruction->GetFieldType(), |
| 9564 | instruction->GetFieldIndex(), |
| 9565 | instruction->GetDexPc(), |
| 9566 | calling_convention); |
| 9567 | } |
| 9568 | |
| 9569 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( |
| 9570 | HUnresolvedStaticFieldGet* instruction) { |
| 9571 | FieldAccessCallingConventionMIPS calling_convention; |
| 9572 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 9573 | instruction->GetFieldType(), |
| 9574 | calling_convention); |
| 9575 | } |
| 9576 | |
| 9577 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( |
| 9578 | HUnresolvedStaticFieldGet* instruction) { |
| 9579 | FieldAccessCallingConventionMIPS calling_convention; |
| 9580 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 9581 | instruction->GetFieldType(), |
| 9582 | instruction->GetFieldIndex(), |
| 9583 | instruction->GetDexPc(), |
| 9584 | calling_convention); |
| 9585 | } |
| 9586 | |
| 9587 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( |
| 9588 | HUnresolvedStaticFieldSet* instruction) { |
| 9589 | FieldAccessCallingConventionMIPS calling_convention; |
| 9590 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 9591 | instruction->GetFieldType(), |
| 9592 | calling_convention); |
| 9593 | } |
| 9594 | |
| 9595 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( |
| 9596 | HUnresolvedStaticFieldSet* instruction) { |
| 9597 | FieldAccessCallingConventionMIPS calling_convention; |
| 9598 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 9599 | instruction->GetFieldType(), |
| 9600 | instruction->GetFieldIndex(), |
| 9601 | instruction->GetDexPc(), |
| 9602 | calling_convention); |
| 9603 | } |
| 9604 | |
| 9605 | void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9606 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 9607 | instruction, LocationSummary::kCallOnSlowPath); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 9608 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 9609 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 9610 | // registers in full width (since the runtime only saves/restores lower part). |
| 9611 | locations->SetCustomSlowPathCallerSaves( |
| 9612 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9613 | } |
| 9614 | |
| 9615 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 9616 | HBasicBlock* block = instruction->GetBlock(); |
| 9617 | if (block->GetLoopInformation() != nullptr) { |
| 9618 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 9619 | // The back edge will generate the suspend check. |
| 9620 | return; |
| 9621 | } |
| 9622 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 9623 | // The goto will generate the suspend check. |
| 9624 | return; |
| 9625 | } |
| 9626 | GenerateSuspendCheck(instruction, nullptr); |
| 9627 | } |
| 9628 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9629 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9630 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 9631 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9632 | InvokeRuntimeCallingConvention calling_convention; |
| 9633 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 9634 | } |
| 9635 | |
| 9636 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 9637 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9638 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 9639 | } |
| 9640 | |
| 9641 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9642 | DataType::Type input_type = conversion->GetInputType(); |
| 9643 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9644 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 9645 | << input_type << " -> " << result_type; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9646 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9647 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9648 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 9649 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9650 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 9651 | } |
| 9652 | |
| 9653 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9654 | if (!isR6 && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9655 | ((DataType::IsFloatingPointType(result_type) && input_type == DataType::Type::kInt64) || |
| 9656 | (result_type == DataType::Type::kInt64 && DataType::IsFloatingPointType(input_type)))) { |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 9657 | call_kind = LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9658 | } |
| 9659 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9660 | LocationSummary* locations = |
| 9661 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9662 | |
| 9663 | if (call_kind == LocationSummary::kNoCall) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9664 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9665 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 9666 | } else { |
| 9667 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9668 | } |
| 9669 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9670 | if (DataType::IsFloatingPointType(result_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9671 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 9672 | } else { |
| 9673 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9674 | } |
| 9675 | } else { |
| 9676 | InvokeRuntimeCallingConvention calling_convention; |
| 9677 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9678 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9679 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 9680 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9681 | DCHECK_EQ(input_type, DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9682 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 9683 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 9684 | } |
| 9685 | |
| 9686 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 9687 | } |
| 9688 | } |
| 9689 | |
| 9690 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 9691 | LocationSummary* locations = conversion->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9692 | DataType::Type result_type = conversion->GetResultType(); |
| 9693 | DataType::Type input_type = conversion->GetInputType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9694 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9695 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9696 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9697 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 9698 | << input_type << " -> " << result_type; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9699 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9700 | if (result_type == DataType::Type::kInt64 && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9701 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 9702 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 9703 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 9704 | |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 9705 | if (dst_low != src) { |
| 9706 | __ Move(dst_low, src); |
| 9707 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9708 | __ Sra(dst_high, src, 31); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9709 | } else if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9710 | Register dst = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9711 | Register src = (input_type == DataType::Type::kInt64) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9712 | ? locations->InAt(0).AsRegisterPairLow<Register>() |
| 9713 | : locations->InAt(0).AsRegister<Register>(); |
| 9714 | |
| 9715 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9716 | case DataType::Type::kUint8: |
| 9717 | __ Andi(dst, src, 0xFF); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9718 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9719 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9720 | if (has_sign_extension) { |
| 9721 | __ Seb(dst, src); |
| 9722 | } else { |
| 9723 | __ Sll(dst, src, 24); |
| 9724 | __ Sra(dst, dst, 24); |
| 9725 | } |
| 9726 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9727 | case DataType::Type::kUint16: |
| 9728 | __ Andi(dst, src, 0xFFFF); |
| 9729 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9730 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9731 | if (has_sign_extension) { |
| 9732 | __ Seh(dst, src); |
| 9733 | } else { |
| 9734 | __ Sll(dst, src, 16); |
| 9735 | __ Sra(dst, dst, 16); |
| 9736 | } |
| 9737 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9738 | case DataType::Type::kInt32: |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 9739 | if (dst != src) { |
| 9740 | __ Move(dst, src); |
| 9741 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9742 | break; |
| 9743 | |
| 9744 | default: |
| 9745 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 9746 | << " to " << result_type; |
| 9747 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9748 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
| 9749 | if (input_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9750 | if (isR6) { |
| 9751 | // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 9752 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 9753 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 9754 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 9755 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 9756 | __ Mtc1(src_low, FTMP); |
| 9757 | __ Mthc1(src_high, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9758 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9759 | __ Cvtsl(dst, FTMP); |
| 9760 | } else { |
| 9761 | __ Cvtdl(dst, FTMP); |
| 9762 | } |
| 9763 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9764 | QuickEntrypointEnum entrypoint = |
| 9765 | (result_type == DataType::Type::kFloat32) ? kQuickL2f : kQuickL2d; |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 9766 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9767 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9768 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 9769 | } else { |
| 9770 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 9771 | } |
| 9772 | } |
| 9773 | } else { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9774 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 9775 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 9776 | __ Mtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9777 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9778 | __ Cvtsw(dst, FTMP); |
| 9779 | } else { |
| 9780 | __ Cvtdw(dst, FTMP); |
| 9781 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9782 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9783 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 9784 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9785 | |
| 9786 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum |
| 9787 | // value of the output type if the input is outside of the range after the truncation or |
| 9788 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct |
| 9789 | // results. This matches the desired float/double-to-int/long conversion exactly. |
| 9790 | // |
| 9791 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive |
| 9792 | // value when the input is either a NaN or is outside of the range of the output type |
| 9793 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce |
| 9794 | // the same result. |
| 9795 | // |
| 9796 | // The code takes care of the different behaviors by first comparing the input to the |
| 9797 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). |
| 9798 | // If the input is greater than or equal to the minimum, it procedes to the truncate |
| 9799 | // instruction, which will handle such an input the same way irrespective of NAN2008. |
| 9800 | // Otherwise the input is compared to itself to determine whether it is a NaN or not |
| 9801 | // in order to return either zero or the minimum value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9802 | if (result_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9803 | if (isR6) { |
| 9804 | // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 9805 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 9806 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9807 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 9808 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9809 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9810 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9811 | __ TruncLS(FTMP, src); |
| 9812 | } else { |
| 9813 | __ TruncLD(FTMP, src); |
| 9814 | } |
| 9815 | __ Mfc1(dst_low, FTMP); |
| 9816 | __ Mfhc1(dst_high, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9817 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9818 | QuickEntrypointEnum entrypoint = |
| 9819 | (input_type == DataType::Type::kFloat32) ? kQuickF2l : kQuickD2l; |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 9820 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9821 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9822 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 9823 | } else { |
| 9824 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 9825 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9826 | } |
| 9827 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9828 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9829 | Register dst = locations->Out().AsRegister<Register>(); |
| 9830 | MipsLabel truncate; |
| 9831 | MipsLabel done; |
| 9832 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9833 | if (!isR6) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9834 | if (input_type == DataType::Type::kFloat32) { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9835 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); |
| 9836 | __ LoadConst32(TMP, min_val); |
| 9837 | __ Mtc1(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9838 | } else { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9839 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); |
| 9840 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 9841 | __ Mtc1(ZERO, FTMP); |
| 9842 | __ MoveToFpuHigh(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9843 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9844 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9845 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9846 | __ ColeS(0, FTMP, src); |
| 9847 | } else { |
| 9848 | __ ColeD(0, FTMP, src); |
| 9849 | } |
| 9850 | __ Bc1t(0, &truncate); |
| 9851 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9852 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9853 | __ CeqS(0, src, src); |
| 9854 | } else { |
| 9855 | __ CeqD(0, src, src); |
| 9856 | } |
| 9857 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 9858 | __ Movf(dst, ZERO, 0); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9859 | |
| 9860 | __ B(&done); |
| 9861 | |
| 9862 | __ Bind(&truncate); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9863 | } |
| 9864 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9865 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9866 | __ TruncWS(FTMP, src); |
| 9867 | } else { |
| 9868 | __ TruncWD(FTMP, src); |
| 9869 | } |
| 9870 | __ Mfc1(dst, FTMP); |
| 9871 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9872 | if (!isR6) { |
| 9873 | __ Bind(&done); |
| 9874 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9875 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9876 | } else if (DataType::IsFloatingPointType(result_type) && |
| 9877 | DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9878 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 9879 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9880 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9881 | __ Cvtsd(dst, src); |
| 9882 | } else { |
| 9883 | __ Cvtds(dst, src); |
| 9884 | } |
| 9885 | } else { |
| 9886 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 9887 | << " to " << result_type; |
| 9888 | } |
| 9889 | } |
| 9890 | |
| 9891 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { |
| 9892 | HandleShift(ushr); |
| 9893 | } |
| 9894 | |
| 9895 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { |
| 9896 | HandleShift(ushr); |
| 9897 | } |
| 9898 | |
| 9899 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { |
| 9900 | HandleBinaryOp(instruction); |
| 9901 | } |
| 9902 | |
| 9903 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { |
| 9904 | HandleBinaryOp(instruction); |
| 9905 | } |
| 9906 | |
| 9907 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9908 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9909 | LOG(FATAL) << "Unreachable"; |
| 9910 | } |
| 9911 | |
| 9912 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9913 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9914 | LOG(FATAL) << "Unreachable"; |
| 9915 | } |
| 9916 | |
| 9917 | void LocationsBuilderMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9918 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9919 | } |
| 9920 | |
| 9921 | void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9922 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9923 | } |
| 9924 | |
| 9925 | void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9926 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9927 | } |
| 9928 | |
| 9929 | void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9930 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9931 | } |
| 9932 | |
| 9933 | void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9934 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9935 | } |
| 9936 | |
| 9937 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9938 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9939 | } |
| 9940 | |
| 9941 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9942 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9943 | } |
| 9944 | |
| 9945 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9946 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9947 | } |
| 9948 | |
| 9949 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9950 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9951 | } |
| 9952 | |
| 9953 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9954 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9955 | } |
| 9956 | |
| 9957 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9958 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9959 | } |
| 9960 | |
| 9961 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9962 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9963 | } |
| 9964 | |
| 9965 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9966 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9967 | } |
| 9968 | |
| 9969 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9970 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9971 | } |
| 9972 | |
| 9973 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9974 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9975 | } |
| 9976 | |
| 9977 | void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9978 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9979 | } |
| 9980 | |
| 9981 | void LocationsBuilderMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9982 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9983 | } |
| 9984 | |
| 9985 | void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9986 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9987 | } |
| 9988 | |
| 9989 | void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9990 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9991 | } |
| 9992 | |
| 9993 | void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9994 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9995 | } |
| 9996 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9997 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9998 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9999 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 10000 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 10001 | if (!codegen_->GetInstructionSetFeatures().IsR6()) { |
| 10002 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 10003 | if (num_entries > InstructionCodeGeneratorMIPS::kPackedSwitchJumpTableThreshold) { |
| 10004 | // When there's no HMipsComputeBaseMethodAddress input, R2 uses the NAL |
| 10005 | // instruction to simulate PC-relative addressing when accessing the jump table. |
| 10006 | // NAL clobbers RA. Make sure RA is preserved. |
| 10007 | codegen_->ClobberRA(); |
| 10008 | } |
| 10009 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 10010 | } |
| 10011 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10012 | void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg, |
| 10013 | int32_t lower_bound, |
| 10014 | uint32_t num_entries, |
| 10015 | HBasicBlock* switch_block, |
| 10016 | HBasicBlock* default_block) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 10017 | // Create a set of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 10018 | Register temp_reg = TMP; |
| 10019 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
| 10020 | // Jump to default if index is negative |
| 10021 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 10022 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 10023 | __ Bltz(temp_reg, codegen_->GetLabelOf(default_block)); |
| 10024 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10025 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 10026 | // Jump to successors[0] if value == lower_bound. |
| 10027 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 10028 | int32_t last_index = 0; |
| 10029 | for (; num_entries - last_index > 2; last_index += 2) { |
| 10030 | __ Addiu(temp_reg, temp_reg, -2); |
| 10031 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 10032 | __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 10033 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 10034 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 10035 | } |
| 10036 | if (num_entries - last_index == 2) { |
| 10037 | // The last missing case_value. |
| 10038 | __ Addiu(temp_reg, temp_reg, -1); |
| 10039 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 10040 | } |
| 10041 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 10042 | // And the default for any other value. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10043 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 10044 | __ B(codegen_->GetLabelOf(default_block)); |
| 10045 | } |
| 10046 | } |
| 10047 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10048 | void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg, |
| 10049 | Register constant_area, |
| 10050 | int32_t lower_bound, |
| 10051 | uint32_t num_entries, |
| 10052 | HBasicBlock* switch_block, |
| 10053 | HBasicBlock* default_block) { |
| 10054 | // Create a jump table. |
| 10055 | std::vector<MipsLabel*> labels(num_entries); |
| 10056 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 10057 | for (uint32_t i = 0; i < num_entries; i++) { |
| 10058 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 10059 | } |
| 10060 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 10061 | |
| 10062 | // Is the value in range? |
| 10063 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 10064 | if (IsInt<16>(static_cast<int32_t>(num_entries))) { |
| 10065 | __ Sltiu(AT, TMP, num_entries); |
| 10066 | __ Beqz(AT, codegen_->GetLabelOf(default_block)); |
| 10067 | } else { |
| 10068 | __ LoadConst32(AT, num_entries); |
| 10069 | __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 10070 | } |
| 10071 | |
| 10072 | // We are in the range of the table. |
| 10073 | // Load the target address from the jump table, indexing by the value. |
| 10074 | __ LoadLabelAddress(AT, constant_area, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 10075 | __ ShiftAndAdd(TMP, TMP, AT, 2, TMP); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10076 | __ Lw(TMP, TMP, 0); |
| 10077 | // Compute the absolute target address by adding the table start address |
| 10078 | // (the table contains offsets to targets relative to its start). |
| 10079 | __ Addu(TMP, TMP, AT); |
| 10080 | // And jump. |
| 10081 | __ Jr(TMP); |
| 10082 | __ NopIfNoReordering(); |
| 10083 | } |
| 10084 | |
| 10085 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 10086 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 10087 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 10088 | LocationSummary* locations = switch_instr->GetLocations(); |
| 10089 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 10090 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 10091 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 10092 | |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 10093 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10094 | // R6 uses PC-relative addressing to access the jump table. |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 10095 | // |
| 10096 | // R2, OTOH, uses an HMipsComputeBaseMethodAddress input (when available) |
| 10097 | // to access the jump table and it is implemented by changing HPackedSwitch to |
| 10098 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress (see |
| 10099 | // VisitMipsPackedSwitch()). |
| 10100 | // |
| 10101 | // When there's no HMipsComputeBaseMethodAddress input (e.g. in presence of |
| 10102 | // irreducible loops), R2 uses the NAL instruction to simulate PC-relative |
| 10103 | // addressing. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10104 | GenTableBasedPackedSwitch(value_reg, |
| 10105 | ZERO, |
| 10106 | lower_bound, |
| 10107 | num_entries, |
| 10108 | switch_block, |
| 10109 | default_block); |
| 10110 | } else { |
| 10111 | GenPackedSwitchWithCompares(value_reg, |
| 10112 | lower_bound, |
| 10113 | num_entries, |
| 10114 | switch_block, |
| 10115 | default_block); |
| 10116 | } |
| 10117 | } |
| 10118 | |
| 10119 | void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 10120 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 10121 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10122 | locations->SetInAt(0, Location::RequiresRegister()); |
| 10123 | // Constant area pointer (HMipsComputeBaseMethodAddress). |
| 10124 | locations->SetInAt(1, Location::RequiresRegister()); |
| 10125 | } |
| 10126 | |
| 10127 | void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 10128 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 10129 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 10130 | LocationSummary* locations = switch_instr->GetLocations(); |
| 10131 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 10132 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 10133 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 10134 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 10135 | |
| 10136 | // This is an R2-only path. HPackedSwitch has been changed to |
| 10137 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress |
| 10138 | // required to address the jump table relative to PC. |
| 10139 | GenTableBasedPackedSwitch(value_reg, |
| 10140 | constant_area, |
| 10141 | lower_bound, |
| 10142 | num_entries, |
| 10143 | switch_block, |
| 10144 | default_block); |
| 10145 | } |
| 10146 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 10147 | void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress( |
| 10148 | HMipsComputeBaseMethodAddress* insn) { |
| 10149 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 10150 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 10151 | locations->SetOut(Location::RequiresRegister()); |
| 10152 | } |
| 10153 | |
| 10154 | void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress( |
| 10155 | HMipsComputeBaseMethodAddress* insn) { |
| 10156 | LocationSummary* locations = insn->GetLocations(); |
| 10157 | Register reg = locations->Out().AsRegister<Register>(); |
| 10158 | |
| 10159 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 10160 | |
| 10161 | // Generate a dummy PC-relative call to obtain PC. |
| 10162 | __ Nal(); |
| 10163 | // Grab the return address off RA. |
| 10164 | __ Move(reg, RA); |
| 10165 | |
| 10166 | // Remember this offset (the obtained PC value) for later use with constant area. |
| 10167 | __ BindPcRelBaseLabel(); |
| 10168 | } |
| 10169 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 10170 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 10171 | // The trampoline uses the same calling convention as dex calling conventions, |
| 10172 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 10173 | // the method_idx. |
| 10174 | HandleInvoke(invoke); |
| 10175 | } |
| 10176 | |
| 10177 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 10178 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 10179 | } |
| 10180 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10181 | void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 10182 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 10183 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10184 | locations->SetInAt(0, Location::RequiresRegister()); |
| 10185 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 10186 | } |
| 10187 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10188 | void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 10189 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 10190 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 10191 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10192 | instruction->GetIndex(), kMipsPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 10193 | __ LoadFromOffset(kLoadWord, |
| 10194 | locations->Out().AsRegister<Register>(), |
| 10195 | locations->InAt(0).AsRegister<Register>(), |
| 10196 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10197 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 10198 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 10199 | instruction->GetIndex(), kMipsPointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 10200 | __ LoadFromOffset(kLoadWord, |
| 10201 | locations->Out().AsRegister<Register>(), |
| 10202 | locations->InAt(0).AsRegister<Register>(), |
| 10203 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 10204 | __ LoadFromOffset(kLoadWord, |
| 10205 | locations->Out().AsRegister<Register>(), |
| 10206 | locations->Out().AsRegister<Register>(), |
| 10207 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10208 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 10209 | } |
| 10210 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 10211 | void LocationsBuilderMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 10212 | ATTRIBUTE_UNUSED) { |
| 10213 | LOG(FATAL) << "Unreachable"; |
| 10214 | } |
| 10215 | |
| 10216 | void InstructionCodeGeneratorMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 10217 | ATTRIBUTE_UNUSED) { |
| 10218 | LOG(FATAL) << "Unreachable"; |
| 10219 | } |
| 10220 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 10221 | #undef __ |
| 10222 | #undef QUICK_ENTRY_POINT |
| 10223 | |
| 10224 | } // namespace mips |
| 10225 | } // namespace art |