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" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 29 | #include "heap_poisoning.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 30 | #include "intrinsics.h" |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 31 | #include "intrinsics_mips.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 32 | #include "linker/linker_patch.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 33 | #include "mirror/array-inl.h" |
| 34 | #include "mirror/class-inl.h" |
| 35 | #include "offsets.h" |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 36 | #include "stack_map_stream.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 37 | #include "thread.h" |
| 38 | #include "utils/assembler.h" |
| 39 | #include "utils/mips/assembler_mips.h" |
| 40 | #include "utils/stack_checks.h" |
| 41 | |
| 42 | namespace art { |
| 43 | namespace mips { |
| 44 | |
| 45 | static constexpr int kCurrentMethodStackOffset = 0; |
| 46 | static constexpr Register kMethodRegisterArgument = A0; |
| 47 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 48 | // Flags controlling the use of thunks for Baker read barriers. |
| 49 | constexpr bool kBakerReadBarrierThunksEnableForFields = true; |
| 50 | constexpr bool kBakerReadBarrierThunksEnableForArrays = true; |
| 51 | constexpr bool kBakerReadBarrierThunksEnableForGcRoots = true; |
| 52 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 53 | Location MipsReturnLocation(DataType::Type return_type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 54 | switch (return_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 55 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 56 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 57 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 58 | case DataType::Type::kInt8: |
| 59 | case DataType::Type::kUint16: |
| 60 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 61 | case DataType::Type::kUint32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 62 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 63 | return Location::RegisterLocation(V0); |
| 64 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 65 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 66 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 67 | return Location::RegisterPairLocation(V0, V1); |
| 68 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 69 | case DataType::Type::kFloat32: |
| 70 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 71 | return Location::FpuRegisterLocation(F0); |
| 72 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 73 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 74 | return Location(); |
| 75 | } |
| 76 | UNREACHABLE(); |
| 77 | } |
| 78 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 79 | Location InvokeDexCallingConventionVisitorMIPS::GetReturnLocation(DataType::Type type) const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 80 | return MipsReturnLocation(type); |
| 81 | } |
| 82 | |
| 83 | Location InvokeDexCallingConventionVisitorMIPS::GetMethodLocation() const { |
| 84 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 85 | } |
| 86 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 87 | Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(DataType::Type type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 88 | Location next_location; |
| 89 | |
| 90 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 91 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 92 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 93 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 94 | case DataType::Type::kInt8: |
| 95 | case DataType::Type::kUint16: |
| 96 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 97 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 98 | uint32_t gp_index = gp_index_++; |
| 99 | if (gp_index < calling_convention.GetNumberOfRegisters()) { |
| 100 | next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index)); |
| 101 | } else { |
| 102 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 103 | next_location = Location::StackSlot(stack_offset); |
| 104 | } |
| 105 | break; |
| 106 | } |
| 107 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 108 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 109 | uint32_t gp_index = gp_index_; |
| 110 | gp_index_ += 2; |
| 111 | if (gp_index + 1 < calling_convention.GetNumberOfRegisters()) { |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 112 | Register reg = calling_convention.GetRegisterAt(gp_index); |
| 113 | if (reg == A1 || reg == A3) { |
| 114 | gp_index_++; // Skip A1(A3), and use A2_A3(T0_T1) instead. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 115 | gp_index++; |
| 116 | } |
| 117 | Register low_even = calling_convention.GetRegisterAt(gp_index); |
| 118 | Register high_odd = calling_convention.GetRegisterAt(gp_index + 1); |
| 119 | DCHECK_EQ(low_even + 1, high_odd); |
| 120 | next_location = Location::RegisterPairLocation(low_even, high_odd); |
| 121 | } else { |
| 122 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 123 | next_location = Location::DoubleStackSlot(stack_offset); |
| 124 | } |
| 125 | break; |
| 126 | } |
| 127 | |
| 128 | // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double |
| 129 | // will take up the even/odd pair, while floats are stored in even regs only. |
| 130 | // 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] | 131 | case DataType::Type::kFloat32: |
| 132 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 133 | uint32_t float_index = float_index_++; |
| 134 | if (float_index < calling_convention.GetNumberOfFpuRegisters()) { |
| 135 | next_location = Location::FpuRegisterLocation( |
| 136 | calling_convention.GetFpuRegisterAt(float_index)); |
| 137 | } else { |
| 138 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 139 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 140 | : Location::StackSlot(stack_offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 141 | } |
| 142 | break; |
| 143 | } |
| 144 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 145 | case DataType::Type::kUint32: |
| 146 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 147 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 148 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 149 | break; |
| 150 | } |
| 151 | |
| 152 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 153 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 154 | |
| 155 | return next_location; |
| 156 | } |
| 157 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 158 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 159 | return MipsReturnLocation(type); |
| 160 | } |
| 161 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 162 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 163 | #define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 164 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 165 | |
| 166 | class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 167 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 168 | explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 169 | |
| 170 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 171 | LocationSummary* locations = instruction_->GetLocations(); |
| 172 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 173 | __ Bind(GetEntryLabel()); |
| 174 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 175 | // Live registers will be restored in the catch block if caught. |
| 176 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 177 | } |
| 178 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 179 | // move resolver. |
| 180 | InvokeRuntimeCallingConvention calling_convention; |
| 181 | codegen->EmitParallelMoves(locations->InAt(0), |
| 182 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 183 | DataType::Type::kInt32, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 184 | locations->InAt(1), |
| 185 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 186 | DataType::Type::kInt32); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 187 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 188 | ? kQuickThrowStringBounds |
| 189 | : kQuickThrowArrayBounds; |
| 190 | mips_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 191 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 192 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 193 | } |
| 194 | |
| 195 | bool IsFatal() const OVERRIDE { return true; } |
| 196 | |
| 197 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; } |
| 198 | |
| 199 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 200 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS); |
| 201 | }; |
| 202 | |
| 203 | class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 204 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 205 | explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 206 | |
| 207 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 208 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 209 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 210 | mips_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 211 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 212 | } |
| 213 | |
| 214 | bool IsFatal() const OVERRIDE { return true; } |
| 215 | |
| 216 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; } |
| 217 | |
| 218 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 219 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS); |
| 220 | }; |
| 221 | |
| 222 | class LoadClassSlowPathMIPS : public SlowPathCodeMIPS { |
| 223 | public: |
| 224 | LoadClassSlowPathMIPS(HLoadClass* cls, |
| 225 | HInstruction* at, |
| 226 | uint32_t dex_pc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 227 | bool do_clinit) |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 228 | : SlowPathCodeMIPS(at), |
| 229 | cls_(cls), |
| 230 | dex_pc_(dex_pc), |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 231 | do_clinit_(do_clinit) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 232 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 233 | } |
| 234 | |
| 235 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 236 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 237 | Location out = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 238 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 239 | InvokeRuntimeCallingConvention calling_convention; |
| 240 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 241 | __ Bind(GetEntryLabel()); |
| 242 | SaveLiveRegisters(codegen, locations); |
| 243 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 244 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 245 | __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 246 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 247 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 248 | mips_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 249 | if (do_clinit_) { |
| 250 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 251 | } else { |
| 252 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 253 | } |
| 254 | |
| 255 | // Move the class to the desired location. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 256 | if (out.IsValid()) { |
| 257 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 258 | DataType::Type type = instruction_->GetType(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 259 | mips_codegen->MoveLocation(out, |
| 260 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 261 | type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 262 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 263 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 264 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 265 | __ B(GetExitLabel()); |
| 266 | } |
| 267 | |
| 268 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; } |
| 269 | |
| 270 | private: |
| 271 | // The class this slow path will load. |
| 272 | HLoadClass* const cls_; |
| 273 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 274 | // The dex PC of `at_`. |
| 275 | const uint32_t dex_pc_; |
| 276 | |
| 277 | // Whether to initialize the class. |
| 278 | const bool do_clinit_; |
| 279 | |
| 280 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS); |
| 281 | }; |
| 282 | |
| 283 | class LoadStringSlowPathMIPS : public SlowPathCodeMIPS { |
| 284 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 285 | explicit LoadStringSlowPathMIPS(HLoadString* instruction) |
| 286 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 287 | |
| 288 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 289 | DCHECK(instruction_->IsLoadString()); |
| 290 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 291 | LocationSummary* locations = instruction_->GetLocations(); |
| 292 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 293 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 294 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 295 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 296 | __ Bind(GetEntryLabel()); |
| 297 | SaveLiveRegisters(codegen, locations); |
| 298 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 299 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 300 | mips_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 301 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 302 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 303 | DataType::Type type = instruction_->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 304 | mips_codegen->MoveLocation(locations->Out(), |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 305 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 306 | type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 307 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 308 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 309 | __ B(GetExitLabel()); |
| 310 | } |
| 311 | |
| 312 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; } |
| 313 | |
| 314 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 315 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS); |
| 316 | }; |
| 317 | |
| 318 | class NullCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 319 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 320 | explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 321 | |
| 322 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 323 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 324 | __ Bind(GetEntryLabel()); |
| 325 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 326 | // Live registers will be restored in the catch block if caught. |
| 327 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 328 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 329 | mips_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 330 | instruction_, |
| 331 | instruction_->GetDexPc(), |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 332 | this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 333 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 334 | } |
| 335 | |
| 336 | bool IsFatal() const OVERRIDE { return true; } |
| 337 | |
| 338 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; } |
| 339 | |
| 340 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 341 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS); |
| 342 | }; |
| 343 | |
| 344 | class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 345 | public: |
| 346 | SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 347 | : SlowPathCodeMIPS(instruction), successor_(successor) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 348 | |
| 349 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 350 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 351 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 352 | __ Bind(GetEntryLabel()); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 353 | SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD. |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 354 | mips_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 355 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 356 | RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 357 | if (successor_ == nullptr) { |
| 358 | __ B(GetReturnLabel()); |
| 359 | } else { |
| 360 | __ B(mips_codegen->GetLabelOf(successor_)); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | MipsLabel* GetReturnLabel() { |
| 365 | DCHECK(successor_ == nullptr); |
| 366 | return &return_label_; |
| 367 | } |
| 368 | |
| 369 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; } |
| 370 | |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 371 | HBasicBlock* GetSuccessor() const { |
| 372 | return successor_; |
| 373 | } |
| 374 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 375 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 376 | // If not null, the block to branch to after the suspend check. |
| 377 | HBasicBlock* const successor_; |
| 378 | |
| 379 | // If `successor_` is null, the label to branch to after the suspend check. |
| 380 | MipsLabel return_label_; |
| 381 | |
| 382 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS); |
| 383 | }; |
| 384 | |
| 385 | class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 386 | public: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 387 | explicit TypeCheckSlowPathMIPS(HInstruction* instruction, bool is_fatal) |
| 388 | : SlowPathCodeMIPS(instruction), is_fatal_(is_fatal) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 389 | |
| 390 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 391 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 392 | uint32_t dex_pc = instruction_->GetDexPc(); |
| 393 | DCHECK(instruction_->IsCheckCast() |
| 394 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 395 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 396 | |
| 397 | __ Bind(GetEntryLabel()); |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 398 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 399 | SaveLiveRegisters(codegen, locations); |
| 400 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 401 | |
| 402 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 403 | // move resolver. |
| 404 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 405 | codegen->EmitParallelMoves(locations->InAt(0), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 406 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 407 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 408 | locations->InAt(1), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 409 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 410 | DataType::Type::kReference); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 411 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 412 | mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 413 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 414 | DataType::Type ret_type = instruction_->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 415 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 416 | mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 417 | } else { |
| 418 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 419 | mips_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 420 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 421 | } |
| 422 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 423 | if (!is_fatal_) { |
| 424 | RestoreLiveRegisters(codegen, locations); |
| 425 | __ B(GetExitLabel()); |
| 426 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; } |
| 430 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 431 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 432 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 433 | private: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 434 | const bool is_fatal_; |
| 435 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 436 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS); |
| 437 | }; |
| 438 | |
| 439 | class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS { |
| 440 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 441 | explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 442 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 443 | |
| 444 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 445 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 446 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 447 | LocationSummary* locations = instruction_->GetLocations(); |
| 448 | SaveLiveRegisters(codegen, locations); |
| 449 | InvokeRuntimeCallingConvention calling_convention; |
| 450 | __ LoadConst32(calling_convention.GetRegisterAt(0), |
| 451 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 452 | mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 453 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; } |
| 457 | |
| 458 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 459 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS); |
| 460 | }; |
| 461 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 462 | class ArraySetSlowPathMIPS : public SlowPathCodeMIPS { |
| 463 | public: |
| 464 | explicit ArraySetSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {} |
| 465 | |
| 466 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 467 | LocationSummary* locations = instruction_->GetLocations(); |
| 468 | __ Bind(GetEntryLabel()); |
| 469 | SaveLiveRegisters(codegen, locations); |
| 470 | |
| 471 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 472 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 473 | parallel_move.AddMove( |
| 474 | locations->InAt(0), |
| 475 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 476 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 477 | nullptr); |
| 478 | parallel_move.AddMove( |
| 479 | locations->InAt(1), |
| 480 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 481 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 482 | nullptr); |
| 483 | parallel_move.AddMove( |
| 484 | locations->InAt(2), |
| 485 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 486 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 487 | nullptr); |
| 488 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 489 | |
| 490 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 491 | mips_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 492 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 493 | RestoreLiveRegisters(codegen, locations); |
| 494 | __ B(GetExitLabel()); |
| 495 | } |
| 496 | |
| 497 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS"; } |
| 498 | |
| 499 | private: |
| 500 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS); |
| 501 | }; |
| 502 | |
| 503 | // Slow path marking an object reference `ref` during a read |
| 504 | // barrier. The field `obj.field` in the object `obj` holding this |
| 505 | // reference does not get updated by this slow path after marking (see |
| 506 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS below for that). |
| 507 | // |
| 508 | // This means that after the execution of this slow path, `ref` will |
| 509 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 510 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 511 | // probably still be a from-space reference (unless it gets updated by |
| 512 | // another thread, or if another thread installed another object |
| 513 | // reference (different from `ref`) in `obj.field`). |
| 514 | // |
| 515 | // If `entrypoint` is a valid location it is assumed to already be |
| 516 | // holding the entrypoint. The case where the entrypoint is passed in |
| 517 | // is for the GcRoot read barrier. |
| 518 | class ReadBarrierMarkSlowPathMIPS : public SlowPathCodeMIPS { |
| 519 | public: |
| 520 | ReadBarrierMarkSlowPathMIPS(HInstruction* instruction, |
| 521 | Location ref, |
| 522 | Location entrypoint = Location::NoLocation()) |
| 523 | : SlowPathCodeMIPS(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 524 | DCHECK(kEmitCompilerReadBarrier); |
| 525 | } |
| 526 | |
| 527 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; } |
| 528 | |
| 529 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 530 | LocationSummary* locations = instruction_->GetLocations(); |
| 531 | Register ref_reg = ref_.AsRegister<Register>(); |
| 532 | DCHECK(locations->CanCall()); |
| 533 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 534 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 535 | instruction_->IsStaticFieldGet() || |
| 536 | instruction_->IsArrayGet() || |
| 537 | instruction_->IsArraySet() || |
| 538 | instruction_->IsLoadClass() || |
| 539 | instruction_->IsLoadString() || |
| 540 | instruction_->IsInstanceOf() || |
| 541 | instruction_->IsCheckCast() || |
| 542 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 543 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 544 | << "Unexpected instruction in read barrier marking slow path: " |
| 545 | << instruction_->DebugName(); |
| 546 | |
| 547 | __ Bind(GetEntryLabel()); |
| 548 | // No need to save live registers; it's taken care of by the |
| 549 | // entrypoint. Also, there is no need to update the stack mask, |
| 550 | // as this runtime call will not trigger a garbage collection. |
| 551 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 552 | DCHECK((V0 <= ref_reg && ref_reg <= T7) || |
| 553 | (S2 <= ref_reg && ref_reg <= S7) || |
| 554 | (ref_reg == FP)) << ref_reg; |
| 555 | // "Compact" slow path, saving two moves. |
| 556 | // |
| 557 | // Instead of using the standard runtime calling convention (input |
| 558 | // and output in A0 and V0 respectively): |
| 559 | // |
| 560 | // A0 <- ref |
| 561 | // V0 <- ReadBarrierMark(A0) |
| 562 | // ref <- V0 |
| 563 | // |
| 564 | // we just use rX (the register containing `ref`) as input and output |
| 565 | // of a dedicated entrypoint: |
| 566 | // |
| 567 | // rX <- ReadBarrierMarkRegX(rX) |
| 568 | // |
| 569 | if (entrypoint_.IsValid()) { |
| 570 | mips_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 571 | DCHECK_EQ(entrypoint_.AsRegister<Register>(), T9); |
| 572 | __ Jalr(entrypoint_.AsRegister<Register>()); |
| 573 | __ NopIfNoReordering(); |
| 574 | } else { |
| 575 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 576 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 577 | // This runtime call does not require a stack map. |
| 578 | mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 579 | instruction_, |
| 580 | this, |
| 581 | /* direct */ false); |
| 582 | } |
| 583 | __ B(GetExitLabel()); |
| 584 | } |
| 585 | |
| 586 | private: |
| 587 | // The location (register) of the marked object reference. |
| 588 | const Location ref_; |
| 589 | |
| 590 | // The location of the entrypoint if already loaded. |
| 591 | const Location entrypoint_; |
| 592 | |
| 593 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS); |
| 594 | }; |
| 595 | |
| 596 | // Slow path marking an object reference `ref` during a read barrier, |
| 597 | // and if needed, atomically updating the field `obj.field` in the |
| 598 | // object `obj` holding this reference after marking (contrary to |
| 599 | // ReadBarrierMarkSlowPathMIPS above, which never tries to update |
| 600 | // `obj.field`). |
| 601 | // |
| 602 | // This means that after the execution of this slow path, both `ref` |
| 603 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 604 | // hold the same to-space reference (unless another thread installed |
| 605 | // another object reference (different from `ref`) in `obj.field`). |
| 606 | class ReadBarrierMarkAndUpdateFieldSlowPathMIPS : public SlowPathCodeMIPS { |
| 607 | public: |
| 608 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(HInstruction* instruction, |
| 609 | Location ref, |
| 610 | Register obj, |
| 611 | Location field_offset, |
| 612 | Register temp1) |
| 613 | : SlowPathCodeMIPS(instruction), |
| 614 | ref_(ref), |
| 615 | obj_(obj), |
| 616 | field_offset_(field_offset), |
| 617 | temp1_(temp1) { |
| 618 | DCHECK(kEmitCompilerReadBarrier); |
| 619 | } |
| 620 | |
| 621 | const char* GetDescription() const OVERRIDE { |
| 622 | return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS"; |
| 623 | } |
| 624 | |
| 625 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 626 | LocationSummary* locations = instruction_->GetLocations(); |
| 627 | Register ref_reg = ref_.AsRegister<Register>(); |
| 628 | DCHECK(locations->CanCall()); |
| 629 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 630 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 631 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 632 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 633 | << instruction_->DebugName(); |
| 634 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 635 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 636 | DCHECK(field_offset_.IsRegisterPair()) << field_offset_; |
| 637 | |
| 638 | __ Bind(GetEntryLabel()); |
| 639 | |
| 640 | // Save the old reference. |
| 641 | // Note that we cannot use AT or TMP to save the old reference, as those |
| 642 | // are used by the code that follows, but we need the old reference after |
| 643 | // the call to the ReadBarrierMarkRegX entry point. |
| 644 | DCHECK_NE(temp1_, AT); |
| 645 | DCHECK_NE(temp1_, TMP); |
| 646 | __ Move(temp1_, ref_reg); |
| 647 | |
| 648 | // No need to save live registers; it's taken care of by the |
| 649 | // entrypoint. Also, there is no need to update the stack mask, |
| 650 | // as this runtime call will not trigger a garbage collection. |
| 651 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 652 | DCHECK((V0 <= ref_reg && ref_reg <= T7) || |
| 653 | (S2 <= ref_reg && ref_reg <= S7) || |
| 654 | (ref_reg == FP)) << ref_reg; |
| 655 | // "Compact" slow path, saving two moves. |
| 656 | // |
| 657 | // Instead of using the standard runtime calling convention (input |
| 658 | // and output in A0 and V0 respectively): |
| 659 | // |
| 660 | // A0 <- ref |
| 661 | // V0 <- ReadBarrierMark(A0) |
| 662 | // ref <- V0 |
| 663 | // |
| 664 | // we just use rX (the register containing `ref`) as input and output |
| 665 | // of a dedicated entrypoint: |
| 666 | // |
| 667 | // rX <- ReadBarrierMarkRegX(rX) |
| 668 | // |
| 669 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 670 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 671 | // This runtime call does not require a stack map. |
| 672 | mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 673 | instruction_, |
| 674 | this, |
| 675 | /* direct */ false); |
| 676 | |
| 677 | // If the new reference is different from the old reference, |
| 678 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 679 | // |
| 680 | // Note that this field could also hold a different object, if |
| 681 | // another thread had concurrently changed it. In that case, the |
| 682 | // the compare-and-set (CAS) loop below would abort, leaving the |
| 683 | // field as-is. |
| 684 | MipsLabel done; |
| 685 | __ Beq(temp1_, ref_reg, &done); |
| 686 | |
| 687 | // Update the the holder's field atomically. This may fail if |
| 688 | // mutator updates before us, but it's OK. This is achieved |
| 689 | // using a strong compare-and-set (CAS) operation with relaxed |
| 690 | // memory synchronization ordering, where the expected value is |
| 691 | // the old reference and the desired value is the new reference. |
| 692 | |
| 693 | // Convenience aliases. |
| 694 | Register base = obj_; |
| 695 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 696 | // offset ("long offset"), of which only the low part contains |
| 697 | // data. |
| 698 | Register offset = field_offset_.AsRegisterPairLow<Register>(); |
| 699 | Register expected = temp1_; |
| 700 | Register value = ref_reg; |
| 701 | Register tmp_ptr = TMP; // Pointer to actual memory. |
| 702 | Register tmp = AT; // Value in memory. |
| 703 | |
| 704 | __ Addu(tmp_ptr, base, offset); |
| 705 | |
| 706 | if (kPoisonHeapReferences) { |
| 707 | __ PoisonHeapReference(expected); |
| 708 | // Do not poison `value` if it is the same register as |
| 709 | // `expected`, which has just been poisoned. |
| 710 | if (value != expected) { |
| 711 | __ PoisonHeapReference(value); |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | // do { |
| 716 | // tmp = [r_ptr] - expected; |
| 717 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 718 | |
| 719 | bool is_r6 = mips_codegen->GetInstructionSetFeatures().IsR6(); |
| 720 | MipsLabel loop_head, exit_loop; |
| 721 | __ Bind(&loop_head); |
| 722 | if (is_r6) { |
| 723 | __ LlR6(tmp, tmp_ptr); |
| 724 | } else { |
| 725 | __ LlR2(tmp, tmp_ptr); |
| 726 | } |
| 727 | __ Bne(tmp, expected, &exit_loop); |
| 728 | __ Move(tmp, value); |
| 729 | if (is_r6) { |
| 730 | __ ScR6(tmp, tmp_ptr); |
| 731 | } else { |
| 732 | __ ScR2(tmp, tmp_ptr); |
| 733 | } |
| 734 | __ Beqz(tmp, &loop_head); |
| 735 | __ Bind(&exit_loop); |
| 736 | |
| 737 | if (kPoisonHeapReferences) { |
| 738 | __ UnpoisonHeapReference(expected); |
| 739 | // Do not unpoison `value` if it is the same register as |
| 740 | // `expected`, which has just been unpoisoned. |
| 741 | if (value != expected) { |
| 742 | __ UnpoisonHeapReference(value); |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | __ Bind(&done); |
| 747 | __ B(GetExitLabel()); |
| 748 | } |
| 749 | |
| 750 | private: |
| 751 | // The location (register) of the marked object reference. |
| 752 | const Location ref_; |
| 753 | // The register containing the object holding the marked object reference field. |
| 754 | const Register obj_; |
| 755 | // The location of the offset of the marked reference field within `obj_`. |
| 756 | Location field_offset_; |
| 757 | |
| 758 | const Register temp1_; |
| 759 | |
| 760 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS); |
| 761 | }; |
| 762 | |
| 763 | // Slow path generating a read barrier for a heap reference. |
| 764 | class ReadBarrierForHeapReferenceSlowPathMIPS : public SlowPathCodeMIPS { |
| 765 | public: |
| 766 | ReadBarrierForHeapReferenceSlowPathMIPS(HInstruction* instruction, |
| 767 | Location out, |
| 768 | Location ref, |
| 769 | Location obj, |
| 770 | uint32_t offset, |
| 771 | Location index) |
| 772 | : SlowPathCodeMIPS(instruction), |
| 773 | out_(out), |
| 774 | ref_(ref), |
| 775 | obj_(obj), |
| 776 | offset_(offset), |
| 777 | index_(index) { |
| 778 | DCHECK(kEmitCompilerReadBarrier); |
| 779 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 780 | // has been overwritten by (or after) the heap object reference load |
| 781 | // to be instrumented, e.g.: |
| 782 | // |
| 783 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 784 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 785 | // |
| 786 | // In that case, we have lost the information about the original |
| 787 | // object, and the emitted read barrier cannot work properly. |
| 788 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 789 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 790 | } |
| 791 | |
| 792 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 793 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 794 | LocationSummary* locations = instruction_->GetLocations(); |
| 795 | Register reg_out = out_.AsRegister<Register>(); |
| 796 | DCHECK(locations->CanCall()); |
| 797 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 798 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 799 | instruction_->IsStaticFieldGet() || |
| 800 | instruction_->IsArrayGet() || |
| 801 | instruction_->IsInstanceOf() || |
| 802 | instruction_->IsCheckCast() || |
| 803 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 804 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 805 | << instruction_->DebugName(); |
| 806 | |
| 807 | __ Bind(GetEntryLabel()); |
| 808 | SaveLiveRegisters(codegen, locations); |
| 809 | |
| 810 | // We may have to change the index's value, but as `index_` is a |
| 811 | // constant member (like other "inputs" of this slow path), |
| 812 | // introduce a copy of it, `index`. |
| 813 | Location index = index_; |
| 814 | if (index_.IsValid()) { |
| 815 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 816 | if (instruction_->IsArrayGet()) { |
| 817 | // Compute the actual memory offset and store it in `index`. |
| 818 | Register index_reg = index_.AsRegister<Register>(); |
| 819 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 820 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 821 | // We are about to change the value of `index_reg` (see the |
| 822 | // calls to art::mips::MipsAssembler::Sll and |
| 823 | // art::mips::MipsAssembler::Addiu32 below), but it has |
| 824 | // not been saved by the previous call to |
| 825 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 826 | // callee-save register -- |
| 827 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 828 | // callee-save registers, as it has been designed with the |
| 829 | // assumption that callee-save registers are supposed to be |
| 830 | // handled by the called function. So, as a callee-save |
| 831 | // register, `index_reg` _would_ eventually be saved onto |
| 832 | // the stack, but it would be too late: we would have |
| 833 | // changed its value earlier. Therefore, we manually save |
| 834 | // it here into another freely available register, |
| 835 | // `free_reg`, chosen of course among the caller-save |
| 836 | // registers (as a callee-save `free_reg` register would |
| 837 | // exhibit the same problem). |
| 838 | // |
| 839 | // Note we could have requested a temporary register from |
| 840 | // the register allocator instead; but we prefer not to, as |
| 841 | // this is a slow path, and we know we can find a |
| 842 | // caller-save register that is available. |
| 843 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 844 | __ Move(free_reg, index_reg); |
| 845 | index_reg = free_reg; |
| 846 | index = Location::RegisterLocation(index_reg); |
| 847 | } else { |
| 848 | // The initial register stored in `index_` has already been |
| 849 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 850 | // (as it is not a callee-save register), so we can freely |
| 851 | // use it. |
| 852 | } |
| 853 | // Shifting the index value contained in `index_reg` by the scale |
| 854 | // factor (2) cannot overflow in practice, as the runtime is |
| 855 | // unable to allocate object arrays with a size larger than |
| 856 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 857 | __ Sll(index_reg, index_reg, TIMES_4); |
| 858 | static_assert( |
| 859 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 860 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 861 | __ Addiu32(index_reg, index_reg, offset_); |
| 862 | } else { |
| 863 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 864 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 865 | // (as in the case of ArrayGet), as it is actually an offset |
| 866 | // to an object field within an object. |
| 867 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 868 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 869 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 870 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 871 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 872 | DCHECK_EQ(offset_, 0U); |
| 873 | DCHECK(index_.IsRegisterPair()); |
| 874 | // UnsafeGet's offset location is a register pair, the low |
| 875 | // part contains the correct offset. |
| 876 | index = index_.ToLow(); |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | // We're moving two or three locations to locations that could |
| 881 | // overlap, so we need a parallel move resolver. |
| 882 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 883 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 884 | parallel_move.AddMove(ref_, |
| 885 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 886 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 887 | nullptr); |
| 888 | parallel_move.AddMove(obj_, |
| 889 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 890 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 891 | nullptr); |
| 892 | if (index.IsValid()) { |
| 893 | parallel_move.AddMove(index, |
| 894 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 895 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 896 | nullptr); |
| 897 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 898 | } else { |
| 899 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 900 | __ LoadConst32(calling_convention.GetRegisterAt(2), offset_); |
| 901 | } |
| 902 | mips_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| 903 | instruction_, |
| 904 | instruction_->GetDexPc(), |
| 905 | this); |
| 906 | CheckEntrypointTypes< |
| 907 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 908 | mips_codegen->MoveLocation(out_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 909 | calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 910 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 911 | |
| 912 | RestoreLiveRegisters(codegen, locations); |
| 913 | __ B(GetExitLabel()); |
| 914 | } |
| 915 | |
| 916 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathMIPS"; } |
| 917 | |
| 918 | private: |
| 919 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 920 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 921 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 922 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 923 | if (i != ref && |
| 924 | i != obj && |
| 925 | !codegen->IsCoreCalleeSaveRegister(i) && |
| 926 | !codegen->IsBlockedCoreRegister(i)) { |
| 927 | return static_cast<Register>(i); |
| 928 | } |
| 929 | } |
| 930 | // We shall never fail to find a free caller-save register, as |
| 931 | // there are more than two core caller-save registers on MIPS |
| 932 | // (meaning it is possible to find one which is different from |
| 933 | // `ref` and `obj`). |
| 934 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 935 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 936 | UNREACHABLE(); |
| 937 | } |
| 938 | |
| 939 | const Location out_; |
| 940 | const Location ref_; |
| 941 | const Location obj_; |
| 942 | const uint32_t offset_; |
| 943 | // An additional location containing an index to an array. |
| 944 | // Only used for HArrayGet and the UnsafeGetObject & |
| 945 | // UnsafeGetObjectVolatile intrinsics. |
| 946 | const Location index_; |
| 947 | |
| 948 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS); |
| 949 | }; |
| 950 | |
| 951 | // Slow path generating a read barrier for a GC root. |
| 952 | class ReadBarrierForRootSlowPathMIPS : public SlowPathCodeMIPS { |
| 953 | public: |
| 954 | ReadBarrierForRootSlowPathMIPS(HInstruction* instruction, Location out, Location root) |
| 955 | : SlowPathCodeMIPS(instruction), out_(out), root_(root) { |
| 956 | DCHECK(kEmitCompilerReadBarrier); |
| 957 | } |
| 958 | |
| 959 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 960 | LocationSummary* locations = instruction_->GetLocations(); |
| 961 | Register reg_out = out_.AsRegister<Register>(); |
| 962 | DCHECK(locations->CanCall()); |
| 963 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 964 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 965 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 966 | << instruction_->DebugName(); |
| 967 | |
| 968 | __ Bind(GetEntryLabel()); |
| 969 | SaveLiveRegisters(codegen, locations); |
| 970 | |
| 971 | InvokeRuntimeCallingConvention calling_convention; |
| 972 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 973 | mips_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 974 | root_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 975 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 976 | mips_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 977 | instruction_, |
| 978 | instruction_->GetDexPc(), |
| 979 | this); |
| 980 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 981 | mips_codegen->MoveLocation(out_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 982 | calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 983 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 984 | |
| 985 | RestoreLiveRegisters(codegen, locations); |
| 986 | __ B(GetExitLabel()); |
| 987 | } |
| 988 | |
| 989 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS"; } |
| 990 | |
| 991 | private: |
| 992 | const Location out_; |
| 993 | const Location root_; |
| 994 | |
| 995 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS); |
| 996 | }; |
| 997 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 998 | CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph, |
| 999 | const MipsInstructionSetFeatures& isa_features, |
| 1000 | const CompilerOptions& compiler_options, |
| 1001 | OptimizingCompilerStats* stats) |
| 1002 | : CodeGenerator(graph, |
| 1003 | kNumberOfCoreRegisters, |
| 1004 | kNumberOfFRegisters, |
| 1005 | kNumberOfRegisterPairs, |
| 1006 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1007 | arraysize(kCoreCalleeSaves)), |
| 1008 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1009 | arraysize(kFpuCalleeSaves)), |
| 1010 | compiler_options, |
| 1011 | stats), |
| 1012 | block_labels_(nullptr), |
| 1013 | location_builder_(graph, this), |
| 1014 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1015 | move_resolver_(graph->GetAllocator(), this), |
| 1016 | assembler_(graph->GetAllocator(), &isa_features), |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1017 | isa_features_(isa_features), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1018 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1019 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1020 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1021 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1022 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1023 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1024 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1025 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1026 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1027 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1028 | clobbered_ra_(false) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1029 | // Save RA (containing the return address) to mimic Quick. |
| 1030 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 1031 | } |
| 1032 | |
| 1033 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 1034 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1035 | #define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1036 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1037 | |
| 1038 | void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) { |
| 1039 | // Ensure that we fix up branches. |
| 1040 | __ FinalizeCode(); |
| 1041 | |
| 1042 | // Adjust native pc offsets in stack maps. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1043 | StackMapStream* stack_map_stream = GetStackMapStream(); |
| 1044 | 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] | 1045 | uint32_t old_position = stack_map_stream->GetStackMapNativePcOffset(i); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1046 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1047 | DCHECK_GE(new_position, old_position); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1048 | stack_map_stream->SetStackMapNativePcOffset(i, new_position); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | // Adjust pc offsets for the disassembly information. |
| 1052 | if (disasm_info_ != nullptr) { |
| 1053 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1054 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1055 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1056 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1057 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1058 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1059 | } |
| 1060 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1061 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1062 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | CodeGenerator::Finalize(allocator); |
| 1067 | } |
| 1068 | |
| 1069 | MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const { |
| 1070 | return codegen_->GetAssembler(); |
| 1071 | } |
| 1072 | |
| 1073 | void ParallelMoveResolverMIPS::EmitMove(size_t index) { |
| 1074 | DCHECK_LT(index, moves_.size()); |
| 1075 | MoveOperands* move = moves_[index]; |
| 1076 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1077 | } |
| 1078 | |
| 1079 | void ParallelMoveResolverMIPS::EmitSwap(size_t index) { |
| 1080 | DCHECK_LT(index, moves_.size()); |
| 1081 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1082 | DataType::Type type = move->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1083 | Location loc1 = move->GetDestination(); |
| 1084 | Location loc2 = move->GetSource(); |
| 1085 | |
| 1086 | DCHECK(!loc1.IsConstant()); |
| 1087 | DCHECK(!loc2.IsConstant()); |
| 1088 | |
| 1089 | if (loc1.Equals(loc2)) { |
| 1090 | return; |
| 1091 | } |
| 1092 | |
| 1093 | if (loc1.IsRegister() && loc2.IsRegister()) { |
| 1094 | // Swap 2 GPRs. |
| 1095 | Register r1 = loc1.AsRegister<Register>(); |
| 1096 | Register r2 = loc2.AsRegister<Register>(); |
| 1097 | __ Move(TMP, r2); |
| 1098 | __ Move(r2, r1); |
| 1099 | __ Move(r1, TMP); |
| 1100 | } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) { |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1101 | if (codegen_->GetGraph()->HasSIMD()) { |
| 1102 | __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(loc1)); |
| 1103 | __ MoveV(VectorRegisterFrom(loc1), VectorRegisterFrom(loc2)); |
| 1104 | __ MoveV(VectorRegisterFrom(loc2), static_cast<VectorRegister>(FTMP)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1105 | } else { |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1106 | FRegister f1 = loc1.AsFpuRegister<FRegister>(); |
| 1107 | FRegister f2 = loc2.AsFpuRegister<FRegister>(); |
| 1108 | if (type == DataType::Type::kFloat32) { |
| 1109 | __ MovS(FTMP, f2); |
| 1110 | __ MovS(f2, f1); |
| 1111 | __ MovS(f1, FTMP); |
| 1112 | } else { |
| 1113 | DCHECK_EQ(type, DataType::Type::kFloat64); |
| 1114 | __ MovD(FTMP, f2); |
| 1115 | __ MovD(f2, f1); |
| 1116 | __ MovD(f1, FTMP); |
| 1117 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1118 | } |
| 1119 | } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) || |
| 1120 | (loc1.IsFpuRegister() && loc2.IsRegister())) { |
| 1121 | // Swap FPR and GPR. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1122 | DCHECK_EQ(type, DataType::Type::kFloat32); // Can only swap a float. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1123 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1124 | : loc2.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1125 | Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1126 | __ Move(TMP, r2); |
| 1127 | __ Mfc1(r2, f1); |
| 1128 | __ Mtc1(TMP, f1); |
| 1129 | } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) { |
| 1130 | // Swap 2 GPR register pairs. |
| 1131 | Register r1 = loc1.AsRegisterPairLow<Register>(); |
| 1132 | Register r2 = loc2.AsRegisterPairLow<Register>(); |
| 1133 | __ Move(TMP, r2); |
| 1134 | __ Move(r2, r1); |
| 1135 | __ Move(r1, TMP); |
| 1136 | r1 = loc1.AsRegisterPairHigh<Register>(); |
| 1137 | r2 = loc2.AsRegisterPairHigh<Register>(); |
| 1138 | __ Move(TMP, r2); |
| 1139 | __ Move(r2, r1); |
| 1140 | __ Move(r1, TMP); |
| 1141 | } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) || |
| 1142 | (loc1.IsFpuRegister() && loc2.IsRegisterPair())) { |
| 1143 | // Swap FPR and GPR register pair. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1144 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1145 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1146 | : loc2.AsFpuRegister<FRegister>(); |
| 1147 | Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 1148 | : loc2.AsRegisterPairLow<Register>(); |
| 1149 | Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 1150 | : loc2.AsRegisterPairHigh<Register>(); |
| 1151 | // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and |
| 1152 | // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR |
| 1153 | // unpredictable and the following mfch1 will fail. |
| 1154 | __ Mfc1(TMP, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1155 | __ MoveFromFpuHigh(AT, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1156 | __ Mtc1(r2_l, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1157 | __ MoveToFpuHigh(r2_h, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1158 | __ Move(r2_l, TMP); |
| 1159 | __ Move(r2_h, AT); |
| 1160 | } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) { |
| 1161 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false); |
| 1162 | } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) { |
| 1163 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1164 | } else if (loc1.IsSIMDStackSlot() && loc2.IsSIMDStackSlot()) { |
| 1165 | ExchangeQuadSlots(loc1.GetStackIndex(), loc2.GetStackIndex()); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1166 | } else if ((loc1.IsRegister() && loc2.IsStackSlot()) || |
| 1167 | (loc1.IsStackSlot() && loc2.IsRegister())) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1168 | Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
| 1169 | intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1170 | __ Move(TMP, reg); |
| 1171 | __ LoadFromOffset(kLoadWord, reg, SP, offset); |
| 1172 | __ StoreToOffset(kStoreWord, TMP, SP, offset); |
| 1173 | } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) || |
| 1174 | (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) { |
| 1175 | Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 1176 | : loc2.AsRegisterPairLow<Register>(); |
| 1177 | Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 1178 | : loc2.AsRegisterPairHigh<Register>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1179 | intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1180 | intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize) |
| 1181 | : loc2.GetHighStackIndex(kMipsWordSize); |
| 1182 | __ Move(TMP, reg_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1183 | __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1184 | __ StoreToOffset(kStoreWord, TMP, SP, offset_l); |
David Brazdil | 04d3e87 | 2016-01-29 09:50:09 +0000 | [diff] [blame] | 1185 | __ Move(TMP, reg_h); |
| 1186 | __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h); |
| 1187 | __ StoreToOffset(kStoreWord, TMP, SP, offset_h); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1188 | } else if ((loc1.IsFpuRegister() && loc2.IsSIMDStackSlot()) || |
| 1189 | (loc1.IsSIMDStackSlot() && loc2.IsFpuRegister())) { |
| 1190 | Location fp_loc = loc1.IsFpuRegister() ? loc1 : loc2; |
| 1191 | intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex(); |
| 1192 | __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(fp_loc)); |
| 1193 | __ LoadQFromOffset(fp_loc.AsFpuRegister<FRegister>(), SP, offset); |
| 1194 | __ StoreQToOffset(FTMP, SP, offset); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1195 | } else if (loc1.IsFpuRegister() || loc2.IsFpuRegister()) { |
| 1196 | FRegister reg = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1197 | : loc2.AsFpuRegister<FRegister>(); |
| 1198 | intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1199 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1200 | __ MovS(FTMP, reg); |
| 1201 | __ LoadSFromOffset(reg, SP, offset); |
| 1202 | __ StoreSToOffset(FTMP, SP, offset); |
| 1203 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1204 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1205 | __ MovD(FTMP, reg); |
| 1206 | __ LoadDFromOffset(reg, SP, offset); |
| 1207 | __ StoreDToOffset(FTMP, SP, offset); |
| 1208 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1209 | } else { |
| 1210 | LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported"; |
| 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | void ParallelMoveResolverMIPS::RestoreScratch(int reg) { |
| 1215 | __ Pop(static_cast<Register>(reg)); |
| 1216 | } |
| 1217 | |
| 1218 | void ParallelMoveResolverMIPS::SpillScratch(int reg) { |
| 1219 | __ Push(static_cast<Register>(reg)); |
| 1220 | } |
| 1221 | |
| 1222 | void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) { |
| 1223 | // Allocate a scratch register other than TMP, if available. |
| 1224 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 1225 | // automatically unspilled when the scratch scope object is destroyed). |
| 1226 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 1227 | // 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] | 1228 | int stack_offset = ensure_scratch.IsSpilled() ? kStackAlignment : 0; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1229 | for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) { |
| 1230 | __ LoadFromOffset(kLoadWord, |
| 1231 | Register(ensure_scratch.GetRegister()), |
| 1232 | SP, |
| 1233 | index1 + stack_offset); |
| 1234 | __ LoadFromOffset(kLoadWord, |
| 1235 | TMP, |
| 1236 | SP, |
| 1237 | index2 + stack_offset); |
| 1238 | __ StoreToOffset(kStoreWord, |
| 1239 | Register(ensure_scratch.GetRegister()), |
| 1240 | SP, |
| 1241 | index2 + stack_offset); |
| 1242 | __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset); |
| 1243 | } |
| 1244 | } |
| 1245 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1246 | void ParallelMoveResolverMIPS::ExchangeQuadSlots(int index1, int index2) { |
| 1247 | __ LoadQFromOffset(FTMP, SP, index1); |
| 1248 | __ LoadQFromOffset(FTMP2, SP, index2); |
| 1249 | __ StoreQToOffset(FTMP, SP, index2); |
| 1250 | __ StoreQToOffset(FTMP2, SP, index1); |
| 1251 | } |
| 1252 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1253 | void CodeGeneratorMIPS::ComputeSpillMask() { |
| 1254 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1255 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1256 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 1257 | // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved |
| 1258 | // registers, include the ZERO register to force alignment of FPU callee-saved registers |
| 1259 | // within the stack frame. |
| 1260 | if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) { |
| 1261 | core_spill_mask_ |= (1 << ZERO); |
| 1262 | } |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1266 | // 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] | 1267 | // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration() |
| 1268 | // into the path that creates a stack frame so that RA can be explicitly saved and restored. |
| 1269 | // 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] | 1270 | return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_; |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1273 | static dwarf::Reg DWARFReg(Register reg) { |
| 1274 | return dwarf::Reg::MipsCore(static_cast<int>(reg)); |
| 1275 | } |
| 1276 | |
| 1277 | // TODO: mapping of floating-point registers to DWARF. |
| 1278 | |
| 1279 | void CodeGeneratorMIPS::GenerateFrameEntry() { |
| 1280 | __ Bind(&frame_entry_label_); |
| 1281 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1282 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
Goran Jakovljevic | feec167 | 2018-02-08 10:20:14 +0100 | [diff] [blame] | 1283 | __ Lhu(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()); |
| 1284 | __ Addiu(TMP, TMP, 1); |
| 1285 | __ Sh(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()); |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1288 | bool do_overflow_check = |
| 1289 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips) || !IsLeafMethod(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1290 | |
| 1291 | if (do_overflow_check) { |
| 1292 | __ LoadFromOffset(kLoadWord, |
| 1293 | ZERO, |
| 1294 | SP, |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1295 | -static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kMips))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1296 | RecordPcInfo(nullptr, 0); |
| 1297 | } |
| 1298 | |
| 1299 | if (HasEmptyFrame()) { |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1300 | CHECK_EQ(fpu_spill_mask_, 0u); |
| 1301 | CHECK_EQ(core_spill_mask_, 1u << RA); |
| 1302 | CHECK(!clobbered_ra_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1303 | return; |
| 1304 | } |
| 1305 | |
| 1306 | // Make sure the frame size isn't unreasonably large. |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1307 | if (GetFrameSize() > GetStackOverflowReservedBytes(InstructionSet::kMips)) { |
| 1308 | LOG(FATAL) << "Stack frame larger than " |
| 1309 | << GetStackOverflowReservedBytes(InstructionSet::kMips) << " bytes"; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | // Spill callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1313 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1314 | uint32_t ofs = GetFrameSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1315 | __ IncreaseFrameSize(ofs); |
| 1316 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1317 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 1318 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 1319 | mask ^= 1u << reg; |
| 1320 | ofs -= kMipsWordSize; |
| 1321 | // The ZERO register is only included for alignment. |
| 1322 | if (reg != ZERO) { |
| 1323 | __ StoreToOffset(kStoreWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1324 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 1325 | } |
| 1326 | } |
| 1327 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1328 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 1329 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 1330 | mask ^= 1u << reg; |
| 1331 | ofs -= kMipsDoublewordSize; |
| 1332 | __ StoreDToOffset(reg, SP, ofs); |
| 1333 | // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1334 | } |
| 1335 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1336 | // Save the current method if we need it. Note that we do not |
| 1337 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1338 | // in the SSA graph. |
| 1339 | if (RequiresCurrentMethod()) { |
| 1340 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
| 1341 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 1342 | |
| 1343 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1344 | // Initialize should deoptimize flag to 0. |
| 1345 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1346 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | void CodeGeneratorMIPS::GenerateFrameExit() { |
| 1350 | __ cfi().RememberState(); |
| 1351 | |
| 1352 | if (!HasEmptyFrame()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1353 | // Restore callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1354 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1355 | // For better instruction scheduling restore RA before other registers. |
| 1356 | uint32_t ofs = GetFrameSize(); |
| 1357 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 1358 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 1359 | mask ^= 1u << reg; |
| 1360 | ofs -= kMipsWordSize; |
| 1361 | // The ZERO register is only included for alignment. |
| 1362 | if (reg != ZERO) { |
| 1363 | __ LoadFromOffset(kLoadWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1364 | __ cfi().Restore(DWARFReg(reg)); |
| 1365 | } |
| 1366 | } |
| 1367 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1368 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 1369 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 1370 | mask ^= 1u << reg; |
| 1371 | ofs -= kMipsDoublewordSize; |
| 1372 | __ LoadDFromOffset(reg, SP, ofs); |
| 1373 | // TODO: __ cfi().Restore(DWARFReg(reg)); |
| 1374 | } |
| 1375 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1376 | size_t frame_size = GetFrameSize(); |
| 1377 | // Adjust the stack pointer in the delay slot if doing so doesn't break CFI. |
| 1378 | bool exchange = IsInt<16>(static_cast<int32_t>(frame_size)); |
| 1379 | bool reordering = __ SetReorder(false); |
| 1380 | if (exchange) { |
| 1381 | __ Jr(RA); |
| 1382 | __ DecreaseFrameSize(frame_size); // Single instruction in delay slot. |
| 1383 | } else { |
| 1384 | __ DecreaseFrameSize(frame_size); |
| 1385 | __ Jr(RA); |
| 1386 | __ Nop(); // In delay slot. |
| 1387 | } |
| 1388 | __ SetReorder(reordering); |
| 1389 | } else { |
| 1390 | __ Jr(RA); |
| 1391 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1392 | } |
| 1393 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1394 | __ cfi().RestoreState(); |
| 1395 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 1396 | } |
| 1397 | |
| 1398 | void CodeGeneratorMIPS::Bind(HBasicBlock* block) { |
| 1399 | __ Bind(GetLabelOf(block)); |
| 1400 | } |
| 1401 | |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1402 | VectorRegister VectorRegisterFrom(Location location) { |
| 1403 | DCHECK(location.IsFpuRegister()); |
| 1404 | return static_cast<VectorRegister>(location.AsFpuRegister<FRegister>()); |
| 1405 | } |
| 1406 | |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1407 | void CodeGeneratorMIPS::MoveLocation(Location destination, |
| 1408 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1409 | DataType::Type dst_type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1410 | if (source.Equals(destination)) { |
| 1411 | return; |
| 1412 | } |
| 1413 | |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1414 | if (source.IsConstant()) { |
| 1415 | MoveConstant(destination, source.GetConstant()); |
| 1416 | } else { |
| 1417 | if (destination.IsRegister()) { |
| 1418 | if (source.IsRegister()) { |
| 1419 | __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 1420 | } else if (source.IsFpuRegister()) { |
| 1421 | __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>()); |
| 1422 | } else { |
| 1423 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1424 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1425 | } |
| 1426 | } else if (destination.IsRegisterPair()) { |
| 1427 | if (source.IsRegisterPair()) { |
| 1428 | __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 1429 | __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 1430 | } else if (source.IsFpuRegister()) { |
| 1431 | Register dst_high = destination.AsRegisterPairHigh<Register>(); |
| 1432 | Register dst_low = destination.AsRegisterPairLow<Register>(); |
| 1433 | FRegister src = source.AsFpuRegister<FRegister>(); |
| 1434 | __ Mfc1(dst_low, src); |
| 1435 | __ MoveFromFpuHigh(dst_high, src); |
| 1436 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1437 | DCHECK(source.IsDoubleStackSlot()) |
| 1438 | << "Cannot move from " << source << " to " << destination; |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1439 | int32_t off = source.GetStackIndex(); |
| 1440 | Register r = destination.AsRegisterPairLow<Register>(); |
| 1441 | __ LoadFromOffset(kLoadDoubleword, r, SP, off); |
| 1442 | } |
| 1443 | } else if (destination.IsFpuRegister()) { |
| 1444 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1445 | DCHECK(!DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1446 | __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>()); |
| 1447 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1448 | DCHECK(DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1449 | FRegister dst = destination.AsFpuRegister<FRegister>(); |
| 1450 | Register src_high = source.AsRegisterPairHigh<Register>(); |
| 1451 | Register src_low = source.AsRegisterPairLow<Register>(); |
| 1452 | __ Mtc1(src_low, dst); |
| 1453 | __ MoveToFpuHigh(src_high, dst); |
| 1454 | } else if (source.IsFpuRegister()) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1455 | if (GetGraph()->HasSIMD()) { |
| 1456 | __ MoveV(VectorRegisterFrom(destination), |
| 1457 | VectorRegisterFrom(source)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1458 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1459 | if (DataType::Is64BitType(dst_type)) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1460 | __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 1461 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1462 | DCHECK_EQ(dst_type, DataType::Type::kFloat32); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1463 | __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 1464 | } |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1465 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1466 | } else if (source.IsSIMDStackSlot()) { |
| 1467 | __ LoadQFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1468 | } else if (source.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1469 | DCHECK(DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1470 | __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 1471 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1472 | DCHECK(!DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1473 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1474 | __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 1475 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1476 | } else if (destination.IsSIMDStackSlot()) { |
| 1477 | if (source.IsFpuRegister()) { |
| 1478 | __ StoreQToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex()); |
| 1479 | } else { |
| 1480 | DCHECK(source.IsSIMDStackSlot()); |
| 1481 | __ LoadQFromOffset(FTMP, SP, source.GetStackIndex()); |
| 1482 | __ StoreQToOffset(FTMP, SP, destination.GetStackIndex()); |
| 1483 | } |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1484 | } else if (destination.IsDoubleStackSlot()) { |
| 1485 | int32_t dst_offset = destination.GetStackIndex(); |
| 1486 | if (source.IsRegisterPair()) { |
| 1487 | __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, dst_offset); |
| 1488 | } else if (source.IsFpuRegister()) { |
| 1489 | __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset); |
| 1490 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1491 | DCHECK(source.IsDoubleStackSlot()) |
| 1492 | << "Cannot move from " << source << " to " << destination; |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1493 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1494 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset); |
| 1495 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4); |
| 1496 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset + 4); |
| 1497 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1498 | } else { |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1499 | DCHECK(destination.IsStackSlot()) << destination; |
| 1500 | int32_t dst_offset = destination.GetStackIndex(); |
| 1501 | if (source.IsRegister()) { |
| 1502 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, dst_offset); |
| 1503 | } else if (source.IsFpuRegister()) { |
| 1504 | __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset); |
| 1505 | } else { |
| 1506 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1507 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1508 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset); |
| 1509 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1510 | } |
| 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) { |
| 1515 | if (c->IsIntConstant() || c->IsNullConstant()) { |
| 1516 | // Move 32 bit constant. |
| 1517 | int32_t value = GetInt32ValueOf(c); |
| 1518 | if (destination.IsRegister()) { |
| 1519 | Register dst = destination.AsRegister<Register>(); |
| 1520 | __ LoadConst32(dst, value); |
| 1521 | } else { |
| 1522 | DCHECK(destination.IsStackSlot()) |
| 1523 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1524 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1525 | } |
| 1526 | } else if (c->IsLongConstant()) { |
| 1527 | // Move 64 bit constant. |
| 1528 | int64_t value = GetInt64ValueOf(c); |
| 1529 | if (destination.IsRegisterPair()) { |
| 1530 | Register r_h = destination.AsRegisterPairHigh<Register>(); |
| 1531 | Register r_l = destination.AsRegisterPairLow<Register>(); |
| 1532 | __ LoadConst64(r_h, r_l, value); |
| 1533 | } else { |
| 1534 | DCHECK(destination.IsDoubleStackSlot()) |
| 1535 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1536 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1537 | } |
| 1538 | } else if (c->IsFloatConstant()) { |
| 1539 | // Move 32 bit float constant. |
| 1540 | int32_t value = GetInt32ValueOf(c); |
| 1541 | if (destination.IsFpuRegister()) { |
| 1542 | __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP); |
| 1543 | } else { |
| 1544 | DCHECK(destination.IsStackSlot()) |
| 1545 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1546 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1547 | } |
| 1548 | } else { |
| 1549 | // Move 64 bit double constant. |
| 1550 | DCHECK(c->IsDoubleConstant()) << c->DebugName(); |
| 1551 | int64_t value = GetInt64ValueOf(c); |
| 1552 | if (destination.IsFpuRegister()) { |
| 1553 | FRegister fd = destination.AsFpuRegister<FRegister>(); |
| 1554 | __ LoadDConst64(fd, value, TMP); |
| 1555 | } else { |
| 1556 | DCHECK(destination.IsDoubleStackSlot()) |
| 1557 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1558 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1559 | } |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) { |
| 1564 | DCHECK(destination.IsRegister()); |
| 1565 | Register dst = destination.AsRegister<Register>(); |
| 1566 | __ LoadConst32(dst, value); |
| 1567 | } |
| 1568 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1569 | void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1570 | if (location.IsRegister()) { |
| 1571 | locations->AddTemp(location); |
Alexey Frunze | c9e94f3 | 2015-10-26 16:11:39 -0700 | [diff] [blame] | 1572 | } else if (location.IsRegisterPair()) { |
| 1573 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1574 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1575 | } else { |
| 1576 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1577 | } |
| 1578 | } |
| 1579 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1580 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1581 | inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches( |
| 1582 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1583 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1584 | for (const PcRelativePatchInfo& info : infos) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1585 | const DexFile* dex_file = info.target_dex_file; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1586 | size_t offset_or_index = info.offset_or_index; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1587 | DCHECK(info.label.IsBound()); |
| 1588 | uint32_t literal_offset = __ GetLabelLocation(&info.label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1589 | // On R2 we use HMipsComputeBaseMethodAddress and patch relative to |
| 1590 | // the assembler's base label used for PC-relative addressing. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1591 | const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info; |
| 1592 | uint32_t pc_rel_offset = info_high.pc_rel_label.IsBound() |
| 1593 | ? __ GetLabelLocation(&info_high.pc_rel_label) |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1594 | : __ GetPcRelBaseLabelLocation(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1595 | 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] | 1596 | } |
| 1597 | } |
| 1598 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1599 | linker::LinkerPatch DataBimgRelRoPatchAdapter(size_t literal_offset, |
| 1600 | const DexFile* target_dex_file, |
| 1601 | uint32_t pc_insn_offset, |
| 1602 | uint32_t boot_image_offset) { |
| 1603 | DCHECK(target_dex_file == nullptr); // Unused for DataBimgRelRoPatch(), should be null. |
| 1604 | return linker::LinkerPatch::DataBimgRelRoPatch(literal_offset, pc_insn_offset, boot_image_offset); |
| 1605 | } |
| 1606 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1607 | void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1608 | DCHECK(linker_patches->empty()); |
| 1609 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1610 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1611 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1612 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1613 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1614 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1615 | string_bss_entry_patches_.size(); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1616 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1617 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1618 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1619 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1620 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1621 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1622 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1623 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1624 | } else { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1625 | EmitPcRelativeLinkerPatches<DataBimgRelRoPatchAdapter>( |
| 1626 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1627 | DCHECK(boot_image_type_patches_.empty()); |
| 1628 | DCHECK(boot_image_string_patches_.empty()); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1629 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1630 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1631 | method_bss_entry_patches_, linker_patches); |
| 1632 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1633 | type_bss_entry_patches_, linker_patches); |
| 1634 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1635 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1636 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1639 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageRelRoPatch( |
| 1640 | uint32_t boot_image_offset, |
| 1641 | const PcRelativePatchInfo* info_high) { |
| 1642 | return NewPcRelativePatch( |
| 1643 | /* dex_file */ nullptr, boot_image_offset, info_high, &boot_image_method_patches_); |
| 1644 | } |
| 1645 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1646 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageMethodPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1647 | MethodReference target_method, |
| 1648 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1649 | return NewPcRelativePatch( |
| 1650 | 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] | 1651 | } |
| 1652 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1653 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewMethodBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1654 | MethodReference target_method, |
| 1655 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1656 | return NewPcRelativePatch( |
| 1657 | 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] | 1658 | } |
| 1659 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1660 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageTypePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1661 | const DexFile& dex_file, |
| 1662 | dex::TypeIndex type_index, |
| 1663 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1664 | 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] | 1665 | } |
| 1666 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1667 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewTypeBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1668 | const DexFile& dex_file, |
| 1669 | dex::TypeIndex type_index, |
| 1670 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1671 | 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] | 1672 | } |
| 1673 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1674 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageStringPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1675 | const DexFile& dex_file, |
| 1676 | dex::StringIndex string_index, |
| 1677 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1678 | return NewPcRelativePatch( |
| 1679 | &dex_file, string_index.index_, info_high, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1680 | } |
| 1681 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1682 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewStringBssEntryPatch( |
| 1683 | const DexFile& dex_file, |
| 1684 | dex::StringIndex string_index, |
| 1685 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1686 | 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] | 1687 | } |
| 1688 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1689 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1690 | const DexFile* dex_file, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1691 | uint32_t offset_or_index, |
| 1692 | const PcRelativePatchInfo* info_high, |
| 1693 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1694 | patches->emplace_back(dex_file, offset_or_index, info_high); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1695 | return &patches->back(); |
| 1696 | } |
| 1697 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1698 | Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1699 | return map->GetOrCreate( |
| 1700 | value, |
| 1701 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1702 | } |
| 1703 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1704 | Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1705 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1706 | } |
| 1707 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1708 | void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high, |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1709 | Register out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1710 | Register base) { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1711 | DCHECK(!info_high->patch_info_high); |
Alexey Frunze | 6079dca | 2017-05-28 19:10:28 -0700 | [diff] [blame] | 1712 | DCHECK_NE(out, base); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1713 | bool reordering = __ SetReorder(false); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1714 | if (GetInstructionSetFeatures().IsR6()) { |
| 1715 | DCHECK_EQ(base, ZERO); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1716 | __ Bind(&info_high->label); |
| 1717 | __ Bind(&info_high->pc_rel_label); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1718 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1719 | __ Auipc(out, /* placeholder */ 0x1234); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1720 | __ SetReorder(reordering); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1721 | } else { |
| 1722 | // If base is ZERO, emit NAL to obtain the actual base. |
| 1723 | if (base == ZERO) { |
| 1724 | // Generate a dummy PC-relative call to obtain PC. |
| 1725 | __ Nal(); |
| 1726 | } |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1727 | __ Bind(&info_high->label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1728 | __ Lui(out, /* placeholder */ 0x1234); |
| 1729 | // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding |
| 1730 | // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler. |
| 1731 | if (base == ZERO) { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1732 | __ Bind(&info_high->pc_rel_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1733 | } |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1734 | __ SetReorder(reordering); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1735 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1736 | __ Addu(out, out, (base == ZERO) ? RA : base); |
| 1737 | } |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1738 | // 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] | 1739 | // offset to `out` (e.g. lw, jialc, addiu). |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1742 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootStringPatch( |
| 1743 | const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1744 | dex::StringIndex string_index, |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1745 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1746 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| 1747 | jit_string_patches_.emplace_back(dex_file, string_index.index_); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1748 | return &jit_string_patches_.back(); |
| 1749 | } |
| 1750 | |
| 1751 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootClassPatch( |
| 1752 | const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1753 | dex::TypeIndex type_index, |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1754 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1755 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| 1756 | jit_class_patches_.emplace_back(dex_file, type_index.index_); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1757 | return &jit_class_patches_.back(); |
| 1758 | } |
| 1759 | |
| 1760 | void CodeGeneratorMIPS::PatchJitRootUse(uint8_t* code, |
| 1761 | const uint8_t* roots_data, |
| 1762 | const CodeGeneratorMIPS::JitPatchInfo& info, |
| 1763 | uint64_t index_in_table) const { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1764 | uint32_t high_literal_offset = GetAssembler().GetLabelLocation(&info.high_label); |
| 1765 | uint32_t low_literal_offset = GetAssembler().GetLabelLocation(&info.low_label); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1766 | uintptr_t address = |
| 1767 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1768 | uint32_t addr32 = dchecked_integral_cast<uint32_t>(address); |
| 1769 | // lui reg, addr32_high |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1770 | DCHECK_EQ(code[high_literal_offset + 0], 0x34); |
| 1771 | DCHECK_EQ(code[high_literal_offset + 1], 0x12); |
| 1772 | DCHECK_EQ((code[high_literal_offset + 2] & 0xE0), 0x00); |
| 1773 | DCHECK_EQ(code[high_literal_offset + 3], 0x3C); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1774 | // instr reg, reg, addr32_low |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1775 | DCHECK_EQ(code[low_literal_offset + 0], 0x78); |
| 1776 | DCHECK_EQ(code[low_literal_offset + 1], 0x56); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1777 | 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] | 1778 | // lui reg, addr32_high |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1779 | code[high_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 16); |
| 1780 | code[high_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 24); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1781 | // instr reg, reg, addr32_low |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1782 | code[low_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 0); |
| 1783 | code[low_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 8); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | void CodeGeneratorMIPS::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1787 | for (const JitPatchInfo& info : jit_string_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1788 | StringReference string_reference(&info.target_dex_file, dex::StringIndex(info.index)); |
| 1789 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1790 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1791 | } |
| 1792 | for (const JitPatchInfo& info : jit_class_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1793 | TypeReference type_reference(&info.target_dex_file, dex::TypeIndex(info.index)); |
| 1794 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1795 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1796 | } |
| 1797 | } |
| 1798 | |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1799 | void CodeGeneratorMIPS::MarkGCCard(Register object, |
| 1800 | Register value, |
| 1801 | bool value_can_be_null) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1802 | MipsLabel done; |
| 1803 | Register card = AT; |
| 1804 | Register temp = TMP; |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1805 | if (value_can_be_null) { |
| 1806 | __ Beqz(value, &done); |
| 1807 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1808 | __ LoadFromOffset(kLoadWord, |
| 1809 | card, |
| 1810 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1811 | Thread::CardTableOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1812 | __ Srl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1813 | __ Addu(temp, card, temp); |
| 1814 | __ Sb(card, temp, 0); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1815 | if (value_can_be_null) { |
| 1816 | __ Bind(&done); |
| 1817 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1818 | } |
| 1819 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1820 | void CodeGeneratorMIPS::SetupBlockedRegisters() const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1821 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1822 | blocked_core_registers_[ZERO] = true; |
| 1823 | blocked_core_registers_[K0] = true; |
| 1824 | blocked_core_registers_[K1] = true; |
| 1825 | blocked_core_registers_[GP] = true; |
| 1826 | blocked_core_registers_[SP] = true; |
| 1827 | blocked_core_registers_[RA] = true; |
| 1828 | |
| 1829 | // AT and TMP(T8) are used as temporary/scratch registers |
| 1830 | // (similar to how AT is used by MIPS assemblers). |
| 1831 | blocked_core_registers_[AT] = true; |
| 1832 | blocked_core_registers_[TMP] = true; |
| 1833 | blocked_fpu_registers_[FTMP] = true; |
| 1834 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1835 | if (GetInstructionSetFeatures().HasMsa()) { |
| 1836 | // To be used just for MSA instructions. |
| 1837 | blocked_fpu_registers_[FTMP2] = true; |
| 1838 | } |
| 1839 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1840 | // Reserve suspend and thread registers. |
| 1841 | blocked_core_registers_[S0] = true; |
| 1842 | blocked_core_registers_[TR] = true; |
| 1843 | |
| 1844 | // Reserve T9 for function calls |
| 1845 | blocked_core_registers_[T9] = true; |
| 1846 | |
| 1847 | // Reserve odd-numbered FPU registers. |
| 1848 | for (size_t i = 1; i < kNumberOfFRegisters; i += 2) { |
| 1849 | blocked_fpu_registers_[i] = true; |
| 1850 | } |
| 1851 | |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 1852 | if (GetGraph()->IsDebuggable()) { |
| 1853 | // Stubs do not save callee-save floating point registers. If the graph |
| 1854 | // is debuggable, we need to deal with these registers differently. For |
| 1855 | // now, just block them. |
| 1856 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1857 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1858 | } |
| 1859 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1860 | } |
| 1861 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1862 | size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1863 | __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index); |
| 1864 | return kMipsWordSize; |
| 1865 | } |
| 1866 | |
| 1867 | size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1868 | __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index); |
| 1869 | return kMipsWordSize; |
| 1870 | } |
| 1871 | |
| 1872 | size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1873 | if (GetGraph()->HasSIMD()) { |
| 1874 | __ StoreQToOffset(FRegister(reg_id), SP, stack_index); |
| 1875 | } else { |
| 1876 | __ StoreDToOffset(FRegister(reg_id), SP, stack_index); |
| 1877 | } |
| 1878 | return GetFloatingPointSpillSlotSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1882 | if (GetGraph()->HasSIMD()) { |
| 1883 | __ LoadQFromOffset(FRegister(reg_id), SP, stack_index); |
| 1884 | } else { |
| 1885 | __ LoadDFromOffset(FRegister(reg_id), SP, stack_index); |
| 1886 | } |
| 1887 | return GetFloatingPointSpillSlotSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1891 | stream << Register(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1892 | } |
| 1893 | |
| 1894 | void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1895 | stream << FRegister(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1896 | } |
| 1897 | |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1898 | constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16; |
| 1899 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1900 | void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1901 | HInstruction* instruction, |
| 1902 | uint32_t dex_pc, |
| 1903 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1904 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1905 | GenerateInvokeRuntime(GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value(), |
| 1906 | IsDirectEntrypoint(entrypoint)); |
| 1907 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1908 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | void CodeGeneratorMIPS::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1913 | HInstruction* instruction, |
| 1914 | SlowPathCode* slow_path, |
| 1915 | bool direct) { |
| 1916 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1917 | GenerateInvokeRuntime(entry_point_offset, direct); |
| 1918 | } |
| 1919 | |
| 1920 | void CodeGeneratorMIPS::GenerateInvokeRuntime(int32_t entry_point_offset, bool direct) { |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1921 | bool reordering = __ SetReorder(false); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1922 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1923 | __ Jalr(T9); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1924 | if (direct) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1925 | // Reserve argument space on stack (for $a0-$a3) for |
| 1926 | // entrypoints that directly reference native implementations. |
| 1927 | // Called function may use this space to store $a0-$a3 regs. |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1928 | __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1929 | __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1930 | } else { |
| 1931 | __ Nop(); // In delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1932 | } |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1933 | __ SetReorder(reordering); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, |
| 1937 | Register class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1938 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 1939 | const size_t status_byte_offset = |
| 1940 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 1941 | constexpr uint32_t shifted_initialized_value = |
| 1942 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 1943 | |
| 1944 | __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, status_byte_offset); |
Lena Djokic | 3177e10 | 2018-02-28 11:32:40 +0100 | [diff] [blame] | 1945 | __ Sltiu(TMP, TMP, shifted_initialized_value); |
| 1946 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1947 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1948 | __ Sync(0); |
| 1949 | __ Bind(slow_path->GetExitLabel()); |
| 1950 | } |
| 1951 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 1952 | void InstructionCodeGeneratorMIPS::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 1953 | Register temp) { |
| 1954 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 1955 | uint32_t mask = check->GetBitstringMask(); |
| 1956 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 1957 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 1958 | |
| 1959 | if (mask_bits == 16u) { |
| 1960 | // Load only the bitstring part of the status word. |
| 1961 | __ LoadFromOffset( |
| 1962 | kLoadUnsignedHalfword, temp, temp, mirror::Class::StatusOffset().Int32Value()); |
| 1963 | // Compare the bitstring bits using XOR. |
| 1964 | __ Xori(temp, temp, dchecked_integral_cast<uint16_t>(path_to_root)); |
| 1965 | } else { |
| 1966 | // /* uint32_t */ temp = temp->status_ |
| 1967 | __ LoadFromOffset(kLoadWord, temp, temp, mirror::Class::StatusOffset().Int32Value()); |
| 1968 | // Compare the bitstring bits using XOR. |
| 1969 | if (IsUint<16>(path_to_root)) { |
| 1970 | __ Xori(temp, temp, dchecked_integral_cast<uint16_t>(path_to_root)); |
| 1971 | } else { |
| 1972 | __ LoadConst32(TMP, path_to_root); |
| 1973 | __ Xor(temp, temp, TMP); |
| 1974 | } |
| 1975 | // Shift out bits that do not contribute to the comparison. |
| 1976 | __ Sll(temp, temp, 32 - mask_bits); |
| 1977 | } |
| 1978 | } |
| 1979 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1980 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1981 | __ Sync(0); // Only stype 0 is supported. |
| 1982 | } |
| 1983 | |
| 1984 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1985 | HBasicBlock* successor) { |
| 1986 | SuspendCheckSlowPathMIPS* slow_path = |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 1987 | down_cast<SuspendCheckSlowPathMIPS*>(instruction->GetSlowPath()); |
| 1988 | |
| 1989 | if (slow_path == nullptr) { |
| 1990 | slow_path = |
| 1991 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS(instruction, successor); |
| 1992 | instruction->SetSlowPath(slow_path); |
| 1993 | codegen_->AddSlowPath(slow_path); |
| 1994 | if (successor != nullptr) { |
| 1995 | DCHECK(successor->IsLoopHeader()); |
| 1996 | } |
| 1997 | } else { |
| 1998 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1999 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2000 | |
| 2001 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2002 | TMP, |
| 2003 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2004 | Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2005 | if (successor == nullptr) { |
| 2006 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 2007 | __ Bind(slow_path->GetReturnLabel()); |
| 2008 | } else { |
| 2009 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); |
| 2010 | __ B(slow_path->GetEntryLabel()); |
| 2011 | // slow_path will return to GetLabelOf(successor). |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, |
| 2016 | CodeGeneratorMIPS* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2017 | : InstructionCodeGenerator(graph, codegen), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2018 | assembler_(codegen->GetAssembler()), |
| 2019 | codegen_(codegen) {} |
| 2020 | |
| 2021 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 2022 | DCHECK_EQ(instruction->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2023 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2024 | DataType::Type type = instruction->GetResultType(); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2025 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2026 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2027 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2028 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2029 | HInstruction* right = instruction->InputAt(1); |
| 2030 | bool can_use_imm = false; |
| 2031 | if (right->IsConstant()) { |
| 2032 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); |
| 2033 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 2034 | can_use_imm = IsUint<16>(imm); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2035 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2036 | DCHECK(instruction->IsSub() || instruction->IsAdd()); |
| 2037 | if (instruction->IsSub()) { |
| 2038 | imm = -imm; |
| 2039 | } |
| 2040 | if (isR6) { |
| 2041 | bool single_use = right->GetUses().HasExactlyOneElement(); |
| 2042 | int16_t imm_high = High16Bits(imm); |
| 2043 | int16_t imm_low = Low16Bits(imm); |
| 2044 | if (imm_low < 0) { |
| 2045 | imm_high += 1; |
| 2046 | } |
| 2047 | can_use_imm = !((imm_high != 0) && (imm_low != 0)) || single_use; |
| 2048 | } else { |
| 2049 | can_use_imm = IsInt<16>(imm); |
| 2050 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2051 | } |
| 2052 | } |
| 2053 | if (can_use_imm) |
| 2054 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 2055 | else |
| 2056 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2057 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2058 | break; |
| 2059 | } |
| 2060 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2061 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2062 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2063 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2064 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2065 | break; |
| 2066 | } |
| 2067 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2068 | case DataType::Type::kFloat32: |
| 2069 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2070 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 2071 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2072 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2073 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2074 | break; |
| 2075 | |
| 2076 | default: |
| 2077 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2082 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2083 | LocationSummary* locations = instruction->GetLocations(); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2084 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2085 | |
| 2086 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2087 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2088 | Register dst = locations->Out().AsRegister<Register>(); |
| 2089 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2090 | Location rhs_location = locations->InAt(1); |
| 2091 | |
| 2092 | Register rhs_reg = ZERO; |
| 2093 | int32_t rhs_imm = 0; |
| 2094 | bool use_imm = rhs_location.IsConstant(); |
| 2095 | if (use_imm) { |
| 2096 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2097 | } else { |
| 2098 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2099 | } |
| 2100 | |
| 2101 | if (instruction->IsAnd()) { |
| 2102 | if (use_imm) |
| 2103 | __ Andi(dst, lhs, rhs_imm); |
| 2104 | else |
| 2105 | __ And(dst, lhs, rhs_reg); |
| 2106 | } else if (instruction->IsOr()) { |
| 2107 | if (use_imm) |
| 2108 | __ Ori(dst, lhs, rhs_imm); |
| 2109 | else |
| 2110 | __ Or(dst, lhs, rhs_reg); |
| 2111 | } else if (instruction->IsXor()) { |
| 2112 | if (use_imm) |
| 2113 | __ Xori(dst, lhs, rhs_imm); |
| 2114 | else |
| 2115 | __ Xor(dst, lhs, rhs_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2116 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2117 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 2118 | if (use_imm) { |
| 2119 | if (instruction->IsSub()) { |
| 2120 | rhs_imm = -rhs_imm; |
| 2121 | } |
| 2122 | if (IsInt<16>(rhs_imm)) { |
| 2123 | __ Addiu(dst, lhs, rhs_imm); |
| 2124 | } else { |
| 2125 | DCHECK(isR6); |
| 2126 | int16_t rhs_imm_high = High16Bits(rhs_imm); |
| 2127 | int16_t rhs_imm_low = Low16Bits(rhs_imm); |
| 2128 | if (rhs_imm_low < 0) { |
| 2129 | rhs_imm_high += 1; |
| 2130 | } |
| 2131 | __ Aui(dst, lhs, rhs_imm_high); |
| 2132 | if (rhs_imm_low != 0) { |
| 2133 | __ Addiu(dst, dst, rhs_imm_low); |
| 2134 | } |
| 2135 | } |
| 2136 | } else if (instruction->IsAdd()) { |
| 2137 | __ Addu(dst, lhs, rhs_reg); |
| 2138 | } else { |
| 2139 | DCHECK(instruction->IsSub()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2140 | __ Subu(dst, lhs, rhs_reg); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2141 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2142 | } |
| 2143 | break; |
| 2144 | } |
| 2145 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2146 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2147 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2148 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2149 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2150 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2151 | Location rhs_location = locations->InAt(1); |
| 2152 | bool use_imm = rhs_location.IsConstant(); |
| 2153 | if (!use_imm) { |
| 2154 | Register rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 2155 | Register rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 2156 | if (instruction->IsAnd()) { |
| 2157 | __ And(dst_low, lhs_low, rhs_low); |
| 2158 | __ And(dst_high, lhs_high, rhs_high); |
| 2159 | } else if (instruction->IsOr()) { |
| 2160 | __ Or(dst_low, lhs_low, rhs_low); |
| 2161 | __ Or(dst_high, lhs_high, rhs_high); |
| 2162 | } else if (instruction->IsXor()) { |
| 2163 | __ Xor(dst_low, lhs_low, rhs_low); |
| 2164 | __ Xor(dst_high, lhs_high, rhs_high); |
| 2165 | } else if (instruction->IsAdd()) { |
| 2166 | if (lhs_low == rhs_low) { |
| 2167 | // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs. |
| 2168 | __ Slt(TMP, lhs_low, ZERO); |
| 2169 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2170 | } else { |
| 2171 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2172 | // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged. |
| 2173 | __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low); |
| 2174 | } |
| 2175 | __ Addu(dst_high, lhs_high, rhs_high); |
| 2176 | __ Addu(dst_high, dst_high, TMP); |
| 2177 | } else { |
| 2178 | DCHECK(instruction->IsSub()); |
| 2179 | __ Sltu(TMP, lhs_low, rhs_low); |
| 2180 | __ Subu(dst_low, lhs_low, rhs_low); |
| 2181 | __ Subu(dst_high, lhs_high, rhs_high); |
| 2182 | __ Subu(dst_high, dst_high, TMP); |
| 2183 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2184 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2185 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 2186 | if (instruction->IsOr()) { |
| 2187 | uint32_t low = Low32Bits(value); |
| 2188 | uint32_t high = High32Bits(value); |
| 2189 | if (IsUint<16>(low)) { |
| 2190 | if (dst_low != lhs_low || low != 0) { |
| 2191 | __ Ori(dst_low, lhs_low, low); |
| 2192 | } |
| 2193 | } else { |
| 2194 | __ LoadConst32(TMP, low); |
| 2195 | __ Or(dst_low, lhs_low, TMP); |
| 2196 | } |
| 2197 | if (IsUint<16>(high)) { |
| 2198 | if (dst_high != lhs_high || high != 0) { |
| 2199 | __ Ori(dst_high, lhs_high, high); |
| 2200 | } |
| 2201 | } else { |
| 2202 | if (high != low) { |
| 2203 | __ LoadConst32(TMP, high); |
| 2204 | } |
| 2205 | __ Or(dst_high, lhs_high, TMP); |
| 2206 | } |
| 2207 | } else if (instruction->IsXor()) { |
| 2208 | uint32_t low = Low32Bits(value); |
| 2209 | uint32_t high = High32Bits(value); |
| 2210 | if (IsUint<16>(low)) { |
| 2211 | if (dst_low != lhs_low || low != 0) { |
| 2212 | __ Xori(dst_low, lhs_low, low); |
| 2213 | } |
| 2214 | } else { |
| 2215 | __ LoadConst32(TMP, low); |
| 2216 | __ Xor(dst_low, lhs_low, TMP); |
| 2217 | } |
| 2218 | if (IsUint<16>(high)) { |
| 2219 | if (dst_high != lhs_high || high != 0) { |
| 2220 | __ Xori(dst_high, lhs_high, high); |
| 2221 | } |
| 2222 | } else { |
| 2223 | if (high != low) { |
| 2224 | __ LoadConst32(TMP, high); |
| 2225 | } |
| 2226 | __ Xor(dst_high, lhs_high, TMP); |
| 2227 | } |
| 2228 | } else if (instruction->IsAnd()) { |
| 2229 | uint32_t low = Low32Bits(value); |
| 2230 | uint32_t high = High32Bits(value); |
| 2231 | if (IsUint<16>(low)) { |
| 2232 | __ Andi(dst_low, lhs_low, low); |
| 2233 | } else if (low != 0xFFFFFFFF) { |
| 2234 | __ LoadConst32(TMP, low); |
| 2235 | __ And(dst_low, lhs_low, TMP); |
| 2236 | } else if (dst_low != lhs_low) { |
| 2237 | __ Move(dst_low, lhs_low); |
| 2238 | } |
| 2239 | if (IsUint<16>(high)) { |
| 2240 | __ Andi(dst_high, lhs_high, high); |
| 2241 | } else if (high != 0xFFFFFFFF) { |
| 2242 | if (high != low) { |
| 2243 | __ LoadConst32(TMP, high); |
| 2244 | } |
| 2245 | __ And(dst_high, lhs_high, TMP); |
| 2246 | } else if (dst_high != lhs_high) { |
| 2247 | __ Move(dst_high, lhs_high); |
| 2248 | } |
| 2249 | } else { |
| 2250 | if (instruction->IsSub()) { |
| 2251 | value = -value; |
| 2252 | } else { |
| 2253 | DCHECK(instruction->IsAdd()); |
| 2254 | } |
| 2255 | int32_t low = Low32Bits(value); |
| 2256 | int32_t high = High32Bits(value); |
| 2257 | if (IsInt<16>(low)) { |
| 2258 | if (dst_low != lhs_low || low != 0) { |
| 2259 | __ Addiu(dst_low, lhs_low, low); |
| 2260 | } |
| 2261 | if (low != 0) { |
| 2262 | __ Sltiu(AT, dst_low, low); |
| 2263 | } |
| 2264 | } else { |
| 2265 | __ LoadConst32(TMP, low); |
| 2266 | __ Addu(dst_low, lhs_low, TMP); |
| 2267 | __ Sltu(AT, dst_low, TMP); |
| 2268 | } |
| 2269 | if (IsInt<16>(high)) { |
| 2270 | if (dst_high != lhs_high || high != 0) { |
| 2271 | __ Addiu(dst_high, lhs_high, high); |
| 2272 | } |
| 2273 | } else { |
| 2274 | if (high != low) { |
| 2275 | __ LoadConst32(TMP, high); |
| 2276 | } |
| 2277 | __ Addu(dst_high, lhs_high, TMP); |
| 2278 | } |
| 2279 | if (low != 0) { |
| 2280 | __ Addu(dst_high, dst_high, AT); |
| 2281 | } |
| 2282 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2283 | } |
| 2284 | break; |
| 2285 | } |
| 2286 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2287 | case DataType::Type::kFloat32: |
| 2288 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2289 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2290 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2291 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2292 | if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2293 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2294 | __ AddS(dst, lhs, rhs); |
| 2295 | } else { |
| 2296 | __ AddD(dst, lhs, rhs); |
| 2297 | } |
| 2298 | } else { |
| 2299 | DCHECK(instruction->IsSub()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2300 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2301 | __ SubS(dst, lhs, rhs); |
| 2302 | } else { |
| 2303 | __ SubD(dst, lhs, rhs); |
| 2304 | } |
| 2305 | } |
| 2306 | break; |
| 2307 | } |
| 2308 | |
| 2309 | default: |
| 2310 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 2311 | } |
| 2312 | } |
| 2313 | |
| 2314 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2315 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2316 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2317 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2318 | DataType::Type type = instr->GetResultType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2319 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2320 | case DataType::Type::kInt32: |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2321 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2322 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2323 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2324 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2325 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2326 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2327 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2328 | locations->SetOut(Location::RequiresRegister()); |
| 2329 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2330 | default: |
| 2331 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2332 | } |
| 2333 | } |
| 2334 | |
| 2335 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; |
| 2336 | |
| 2337 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2338 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2339 | LocationSummary* locations = instr->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2340 | DataType::Type type = instr->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2341 | |
| 2342 | Location rhs_location = locations->InAt(1); |
| 2343 | bool use_imm = rhs_location.IsConstant(); |
| 2344 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); |
| 2345 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2346 | const uint32_t shift_mask = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2347 | (type == DataType::Type::kInt32) ? kMaxIntShiftDistance : kMaxLongShiftDistance; |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2348 | const uint32_t shift_value = rhs_imm & shift_mask; |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2349 | // Are the INS (Insert Bit Field) and ROTR instructions supported? |
| 2350 | bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2351 | |
| 2352 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2353 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2354 | Register dst = locations->Out().AsRegister<Register>(); |
| 2355 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2356 | if (use_imm) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2357 | if (shift_value == 0) { |
| 2358 | if (dst != lhs) { |
| 2359 | __ Move(dst, lhs); |
| 2360 | } |
| 2361 | } else if (instr->IsShl()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2362 | __ Sll(dst, lhs, shift_value); |
| 2363 | } else if (instr->IsShr()) { |
| 2364 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2365 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2366 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2367 | } else { |
| 2368 | if (has_ins_rotr) { |
| 2369 | __ Rotr(dst, lhs, shift_value); |
| 2370 | } else { |
| 2371 | __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask); |
| 2372 | __ Srl(dst, lhs, shift_value); |
| 2373 | __ Or(dst, dst, TMP); |
| 2374 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2375 | } |
| 2376 | } else { |
| 2377 | if (instr->IsShl()) { |
| 2378 | __ Sllv(dst, lhs, rhs_reg); |
| 2379 | } else if (instr->IsShr()) { |
| 2380 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2381 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2382 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2383 | } else { |
| 2384 | if (has_ins_rotr) { |
| 2385 | __ Rotrv(dst, lhs, rhs_reg); |
| 2386 | } else { |
| 2387 | __ Subu(TMP, ZERO, rhs_reg); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2388 | // 32-bit shift instructions use the 5 least significant bits of the shift count, so |
| 2389 | // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case |
| 2390 | // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out |
| 2391 | // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`, |
| 2392 | // IOW, the OR'd values are equal. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2393 | __ Sllv(TMP, lhs, TMP); |
| 2394 | __ Srlv(dst, lhs, rhs_reg); |
| 2395 | __ Or(dst, dst, TMP); |
| 2396 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2397 | } |
| 2398 | } |
| 2399 | break; |
| 2400 | } |
| 2401 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2402 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2403 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2404 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2405 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2406 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2407 | if (use_imm) { |
| 2408 | if (shift_value == 0) { |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 2409 | codegen_->MoveLocation(locations->Out(), locations->InAt(0), type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2410 | } else if (shift_value < kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2411 | if (has_ins_rotr) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2412 | if (instr->IsShl()) { |
| 2413 | __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2414 | __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value); |
| 2415 | __ Sll(dst_low, lhs_low, shift_value); |
| 2416 | } else if (instr->IsShr()) { |
| 2417 | __ Srl(dst_low, lhs_low, shift_value); |
| 2418 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2419 | __ Sra(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2420 | } else if (instr->IsUShr()) { |
| 2421 | __ Srl(dst_low, lhs_low, shift_value); |
| 2422 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2423 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2424 | } else { |
| 2425 | __ Srl(dst_low, lhs_low, shift_value); |
| 2426 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2427 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2428 | __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2429 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2430 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2431 | if (instr->IsShl()) { |
| 2432 | __ Sll(dst_low, lhs_low, shift_value); |
| 2433 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); |
| 2434 | __ Sll(dst_high, lhs_high, shift_value); |
| 2435 | __ Or(dst_high, dst_high, TMP); |
| 2436 | } else if (instr->IsShr()) { |
| 2437 | __ Sra(dst_high, lhs_high, shift_value); |
| 2438 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2439 | __ Srl(dst_low, lhs_low, shift_value); |
| 2440 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2441 | } else if (instr->IsUShr()) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2442 | __ Srl(dst_high, lhs_high, shift_value); |
| 2443 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2444 | __ Srl(dst_low, lhs_low, shift_value); |
| 2445 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2446 | } else { |
| 2447 | __ Srl(TMP, lhs_low, shift_value); |
| 2448 | __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value); |
| 2449 | __ Or(dst_low, dst_low, TMP); |
| 2450 | __ Srl(TMP, lhs_high, shift_value); |
| 2451 | __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2452 | __ Or(dst_high, dst_high, TMP); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2453 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2454 | } |
| 2455 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2456 | const uint32_t shift_value_high = shift_value - kMipsBitsPerWord; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2457 | if (instr->IsShl()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2458 | __ Sll(dst_high, lhs_low, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2459 | __ Move(dst_low, ZERO); |
| 2460 | } else if (instr->IsShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2461 | __ Sra(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2462 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2463 | } else if (instr->IsUShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2464 | __ Srl(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2465 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2466 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2467 | if (shift_value == kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2468 | // 64-bit rotation by 32 is just a swap. |
| 2469 | __ Move(dst_low, lhs_high); |
| 2470 | __ Move(dst_high, lhs_low); |
| 2471 | } else { |
| 2472 | if (has_ins_rotr) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2473 | __ Srl(dst_low, lhs_high, shift_value_high); |
| 2474 | __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high); |
| 2475 | __ Srl(dst_high, lhs_low, shift_value_high); |
| 2476 | __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2477 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2478 | __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high); |
| 2479 | __ Srl(dst_low, lhs_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2480 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2481 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high); |
| 2482 | __ Srl(dst_high, lhs_low, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2483 | __ Or(dst_high, dst_high, TMP); |
| 2484 | } |
| 2485 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2486 | } |
| 2487 | } |
| 2488 | } else { |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2489 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2490 | MipsLabel done; |
| 2491 | if (instr->IsShl()) { |
| 2492 | __ Sllv(dst_low, lhs_low, rhs_reg); |
| 2493 | __ Nor(AT, ZERO, rhs_reg); |
| 2494 | __ Srl(TMP, lhs_low, 1); |
| 2495 | __ Srlv(TMP, TMP, AT); |
| 2496 | __ Sllv(dst_high, lhs_high, rhs_reg); |
| 2497 | __ Or(dst_high, dst_high, TMP); |
| 2498 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2499 | if (isR6) { |
| 2500 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2501 | __ Move(dst_high, dst_low); |
| 2502 | __ Move(dst_low, ZERO); |
| 2503 | } else { |
| 2504 | __ Movn(dst_high, dst_low, TMP); |
| 2505 | __ Movn(dst_low, ZERO, TMP); |
| 2506 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2507 | } else if (instr->IsShr()) { |
| 2508 | __ Srav(dst_high, lhs_high, rhs_reg); |
| 2509 | __ Nor(AT, ZERO, rhs_reg); |
| 2510 | __ Sll(TMP, lhs_high, 1); |
| 2511 | __ Sllv(TMP, TMP, AT); |
| 2512 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2513 | __ Or(dst_low, dst_low, TMP); |
| 2514 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2515 | if (isR6) { |
| 2516 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2517 | __ Move(dst_low, dst_high); |
| 2518 | __ Sra(dst_high, dst_high, 31); |
| 2519 | } else { |
| 2520 | __ Sra(AT, dst_high, 31); |
| 2521 | __ Movn(dst_low, dst_high, TMP); |
| 2522 | __ Movn(dst_high, AT, TMP); |
| 2523 | } |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2524 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2525 | __ Srlv(dst_high, lhs_high, rhs_reg); |
| 2526 | __ Nor(AT, ZERO, rhs_reg); |
| 2527 | __ Sll(TMP, lhs_high, 1); |
| 2528 | __ Sllv(TMP, TMP, AT); |
| 2529 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2530 | __ Or(dst_low, dst_low, TMP); |
| 2531 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2532 | if (isR6) { |
| 2533 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2534 | __ Move(dst_low, dst_high); |
| 2535 | __ Move(dst_high, ZERO); |
| 2536 | } else { |
| 2537 | __ Movn(dst_low, dst_high, TMP); |
| 2538 | __ Movn(dst_high, ZERO, TMP); |
| 2539 | } |
| 2540 | } else { // Rotate. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2541 | __ Nor(AT, ZERO, rhs_reg); |
| 2542 | __ Srlv(TMP, lhs_low, rhs_reg); |
| 2543 | __ Sll(dst_low, lhs_high, 1); |
| 2544 | __ Sllv(dst_low, dst_low, AT); |
| 2545 | __ Or(dst_low, dst_low, TMP); |
| 2546 | __ Srlv(TMP, lhs_high, rhs_reg); |
| 2547 | __ Sll(dst_high, lhs_low, 1); |
| 2548 | __ Sllv(dst_high, dst_high, AT); |
| 2549 | __ Or(dst_high, dst_high, TMP); |
| 2550 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2551 | if (isR6) { |
| 2552 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2553 | __ Move(TMP, dst_high); |
| 2554 | __ Move(dst_high, dst_low); |
| 2555 | __ Move(dst_low, TMP); |
| 2556 | } else { |
| 2557 | __ Movn(AT, dst_high, TMP); |
| 2558 | __ Movn(dst_high, dst_low, TMP); |
| 2559 | __ Movn(dst_low, AT, TMP); |
| 2560 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2561 | } |
| 2562 | __ Bind(&done); |
| 2563 | } |
| 2564 | break; |
| 2565 | } |
| 2566 | |
| 2567 | default: |
| 2568 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2569 | } |
| 2570 | } |
| 2571 | |
| 2572 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { |
| 2573 | HandleBinaryOp(instruction); |
| 2574 | } |
| 2575 | |
| 2576 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { |
| 2577 | HandleBinaryOp(instruction); |
| 2578 | } |
| 2579 | |
| 2580 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { |
| 2581 | HandleBinaryOp(instruction); |
| 2582 | } |
| 2583 | |
| 2584 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { |
| 2585 | HandleBinaryOp(instruction); |
| 2586 | } |
| 2587 | |
| 2588 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2589 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2590 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2591 | kEmitCompilerReadBarrier && (type == DataType::Type::kReference); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2592 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2593 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2594 | object_array_get_with_read_barrier |
| 2595 | ? LocationSummary::kCallOnSlowPath |
| 2596 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 2597 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2598 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2599 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2600 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2601 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2602 | if (DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2603 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2604 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2605 | // The output overlaps in the case of an object array get with |
| 2606 | // read barriers enabled: we do not want the move to overwrite the |
| 2607 | // array's location, as we need it to emit the read barrier. |
| 2608 | locations->SetOut(Location::RequiresRegister(), |
| 2609 | object_array_get_with_read_barrier |
| 2610 | ? Location::kOutputOverlap |
| 2611 | : Location::kNoOutputOverlap); |
| 2612 | } |
| 2613 | // We need a temporary register for the read barrier marking slow |
| 2614 | // path in CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier. |
| 2615 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2616 | bool temp_needed = instruction->GetIndex()->IsConstant() |
| 2617 | ? !kBakerReadBarrierThunksEnableForFields |
| 2618 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2619 | if (temp_needed) { |
| 2620 | locations->AddTemp(Location::RequiresRegister()); |
| 2621 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2622 | } |
| 2623 | } |
| 2624 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2625 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS* codegen) { |
| 2626 | auto null_checker = [codegen, instruction]() { |
| 2627 | codegen->MaybeRecordImplicitNullCheck(instruction); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2628 | }; |
| 2629 | return null_checker; |
| 2630 | } |
| 2631 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2632 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 2633 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2634 | Location obj_loc = locations->InAt(0); |
| 2635 | Register obj = obj_loc.AsRegister<Register>(); |
| 2636 | Location out_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2637 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2638 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2639 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2640 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2641 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2642 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2643 | instruction->IsStringCharAt(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2644 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2645 | case DataType::Type::kBool: |
| 2646 | case DataType::Type::kUint8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2647 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2648 | if (index.IsConstant()) { |
| 2649 | size_t offset = |
| 2650 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2651 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2652 | } else { |
| 2653 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2654 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2655 | } |
| 2656 | break; |
| 2657 | } |
| 2658 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2659 | case DataType::Type::kInt8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2660 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2661 | if (index.IsConstant()) { |
| 2662 | size_t offset = |
| 2663 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2664 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2665 | } else { |
| 2666 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2667 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2668 | } |
| 2669 | break; |
| 2670 | } |
| 2671 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2672 | case DataType::Type::kUint16: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2673 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2674 | if (maybe_compressed_char_at) { |
| 2675 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2676 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
| 2677 | __ Sll(TMP, TMP, 31); // Extract compression flag into the most significant bit of TMP. |
| 2678 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2679 | "Expecting 0=compressed, 1=uncompressed"); |
| 2680 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2681 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2682 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2683 | if (maybe_compressed_char_at) { |
| 2684 | MipsLabel uncompressed_load, done; |
| 2685 | __ Bnez(TMP, &uncompressed_load); |
| 2686 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2687 | out, |
| 2688 | obj, |
| 2689 | data_offset + (const_index << TIMES_1)); |
| 2690 | __ B(&done); |
| 2691 | __ Bind(&uncompressed_load); |
| 2692 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2693 | out, |
| 2694 | obj, |
| 2695 | data_offset + (const_index << TIMES_2)); |
| 2696 | __ Bind(&done); |
| 2697 | } else { |
| 2698 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2699 | out, |
| 2700 | obj, |
| 2701 | data_offset + (const_index << TIMES_2), |
| 2702 | null_checker); |
| 2703 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2704 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2705 | Register index_reg = index.AsRegister<Register>(); |
| 2706 | if (maybe_compressed_char_at) { |
| 2707 | MipsLabel uncompressed_load, done; |
| 2708 | __ Bnez(TMP, &uncompressed_load); |
| 2709 | __ Addu(TMP, obj, index_reg); |
| 2710 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2711 | __ B(&done); |
| 2712 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2713 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2714 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2715 | __ Bind(&done); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2716 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2717 | __ Addu(TMP, index_reg, obj); |
| 2718 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2719 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2720 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2721 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
| 2722 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2723 | } |
| 2724 | break; |
| 2725 | } |
| 2726 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2727 | case DataType::Type::kInt16: { |
| 2728 | Register out = out_loc.AsRegister<Register>(); |
| 2729 | if (index.IsConstant()) { |
| 2730 | size_t offset = |
| 2731 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2732 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2733 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2734 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2735 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2736 | } else { |
| 2737 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_2, TMP); |
| 2738 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
| 2739 | } |
| 2740 | break; |
| 2741 | } |
| 2742 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2743 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2744 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2745 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2746 | if (index.IsConstant()) { |
| 2747 | size_t offset = |
| 2748 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2749 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2750 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2751 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2752 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2753 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2754 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2755 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2756 | } |
| 2757 | break; |
| 2758 | } |
| 2759 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2760 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2761 | static_assert( |
| 2762 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2763 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2764 | // /* HeapReference<Object> */ out = |
| 2765 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2766 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2767 | bool temp_needed = index.IsConstant() |
| 2768 | ? !kBakerReadBarrierThunksEnableForFields |
| 2769 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2770 | Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2771 | // Note that a potential implicit null check is handled in this |
| 2772 | // CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier call. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2773 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 2774 | if (index.IsConstant()) { |
| 2775 | // Array load with a constant index can be treated as a field load. |
| 2776 | size_t offset = |
| 2777 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2778 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2779 | out_loc, |
| 2780 | obj, |
| 2781 | offset, |
| 2782 | temp, |
| 2783 | /* needs_null_check */ false); |
| 2784 | } else { |
| 2785 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2786 | out_loc, |
| 2787 | obj, |
| 2788 | data_offset, |
| 2789 | index, |
| 2790 | temp, |
| 2791 | /* needs_null_check */ false); |
| 2792 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2793 | } else { |
| 2794 | Register out = out_loc.AsRegister<Register>(); |
| 2795 | if (index.IsConstant()) { |
| 2796 | size_t offset = |
| 2797 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2798 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
| 2799 | // If read barriers are enabled, emit read barriers other than |
| 2800 | // Baker's using a slow path (and also unpoison the loaded |
| 2801 | // reference, if heap poisoning is enabled). |
| 2802 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2803 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2804 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2805 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
| 2806 | // If read barriers are enabled, emit read barriers other than |
| 2807 | // Baker's using a slow path (and also unpoison the loaded |
| 2808 | // reference, if heap poisoning is enabled). |
| 2809 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2810 | out_loc, |
| 2811 | out_loc, |
| 2812 | obj_loc, |
| 2813 | data_offset, |
| 2814 | index); |
| 2815 | } |
| 2816 | } |
| 2817 | break; |
| 2818 | } |
| 2819 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2820 | case DataType::Type::kInt64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2821 | Register out = out_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2822 | if (index.IsConstant()) { |
| 2823 | size_t offset = |
| 2824 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2825 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2826 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2827 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2828 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2829 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2830 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2831 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2832 | } |
| 2833 | break; |
| 2834 | } |
| 2835 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2836 | case DataType::Type::kFloat32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2837 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2838 | if (index.IsConstant()) { |
| 2839 | size_t offset = |
| 2840 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2841 | __ LoadSFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2842 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2843 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2844 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2845 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2846 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2847 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2848 | } |
| 2849 | break; |
| 2850 | } |
| 2851 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2852 | case DataType::Type::kFloat64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2853 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2854 | if (index.IsConstant()) { |
| 2855 | size_t offset = |
| 2856 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2857 | __ LoadDFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2858 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2859 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2860 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2861 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2862 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2863 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2864 | } |
| 2865 | break; |
| 2866 | } |
| 2867 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2868 | case DataType::Type::kUint32: |
| 2869 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2870 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2871 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2872 | UNREACHABLE(); |
| 2873 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2874 | } |
| 2875 | |
| 2876 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2877 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2878 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2879 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2880 | } |
| 2881 | |
| 2882 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 2883 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2884 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2885 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2886 | Register out = locations->Out().AsRegister<Register>(); |
| 2887 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2888 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2889 | // Mask out compression flag from String's array length. |
| 2890 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2891 | __ Srl(out, out, 1u); |
| 2892 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2893 | } |
| 2894 | |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2895 | Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2896 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2897 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2898 | : Location::RequiresRegister(); |
| 2899 | } |
| 2900 | |
| 2901 | Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2902 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2903 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2904 | // but we should only prefer this if the constant has a single use. |
| 2905 | if (instruction->IsConstant() && |
| 2906 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2907 | instruction->GetUses().HasExactlyOneElement())) { |
| 2908 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2909 | // Otherwise fall through and require an FPU register for the constant. |
| 2910 | } |
| 2911 | return Location::RequiresFpuRegister(); |
| 2912 | } |
| 2913 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2914 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2915 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2916 | |
| 2917 | bool needs_write_barrier = |
| 2918 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2919 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2920 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2921 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2922 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2923 | may_need_runtime_call_for_type_check ? |
| 2924 | LocationSummary::kCallOnSlowPath : |
| 2925 | LocationSummary::kNoCall); |
| 2926 | |
| 2927 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2928 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2929 | if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2930 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2931 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2932 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2933 | } |
| 2934 | if (needs_write_barrier) { |
| 2935 | // Temporary register for the write barrier. |
| 2936 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2937 | } |
| 2938 | } |
| 2939 | |
| 2940 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { |
| 2941 | LocationSummary* locations = instruction->GetLocations(); |
| 2942 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2943 | Location index = locations->InAt(1); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2944 | Location value_location = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2945 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2946 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2947 | bool needs_write_barrier = |
| 2948 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2949 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2950 | Register base_reg = index.IsConstant() ? obj : TMP; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2951 | |
| 2952 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2953 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2954 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2955 | case DataType::Type::kInt8: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2956 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2957 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2958 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2959 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2960 | __ Addu(base_reg, obj, index.AsRegister<Register>()); |
| 2961 | } |
| 2962 | if (value_location.IsConstant()) { |
| 2963 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2964 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2965 | } else { |
| 2966 | Register value = value_location.AsRegister<Register>(); |
| 2967 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2968 | } |
| 2969 | break; |
| 2970 | } |
| 2971 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2972 | case DataType::Type::kUint16: |
| 2973 | case DataType::Type::kInt16: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2974 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2975 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2976 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2977 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2978 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2979 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2980 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_2, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2981 | } |
| 2982 | if (value_location.IsConstant()) { |
| 2983 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2984 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2985 | } else { |
| 2986 | Register value = value_location.AsRegister<Register>(); |
| 2987 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2988 | } |
| 2989 | break; |
| 2990 | } |
| 2991 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2992 | case DataType::Type::kInt32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2993 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2994 | if (index.IsConstant()) { |
| 2995 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2996 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2997 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2998 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2999 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3000 | } |
| 3001 | if (value_location.IsConstant()) { |
| 3002 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3003 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 3004 | } else { |
| 3005 | Register value = value_location.AsRegister<Register>(); |
| 3006 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 3007 | } |
| 3008 | break; |
| 3009 | } |
| 3010 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3011 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3012 | if (value_location.IsConstant()) { |
| 3013 | // Just setting null. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3014 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3015 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3016 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3017 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3018 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3019 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3020 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3021 | DCHECK_EQ(value, 0); |
| 3022 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 3023 | DCHECK(!needs_write_barrier); |
| 3024 | DCHECK(!may_need_runtime_call_for_type_check); |
| 3025 | break; |
| 3026 | } |
| 3027 | |
| 3028 | DCHECK(needs_write_barrier); |
| 3029 | Register value = value_location.AsRegister<Register>(); |
| 3030 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 3031 | Register temp2 = TMP; // Doesn't need to survive slow path. |
| 3032 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3033 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3034 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3035 | MipsLabel done; |
| 3036 | SlowPathCodeMIPS* slow_path = nullptr; |
| 3037 | |
| 3038 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3039 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS(instruction); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3040 | codegen_->AddSlowPath(slow_path); |
| 3041 | if (instruction->GetValueCanBeNull()) { |
| 3042 | MipsLabel non_zero; |
| 3043 | __ Bnez(value, &non_zero); |
| 3044 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3045 | if (index.IsConstant()) { |
| 3046 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3047 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3048 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 3049 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3050 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 3051 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3052 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 3053 | __ B(&done); |
| 3054 | __ Bind(&non_zero); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3055 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3056 | |
| 3057 | // Note that when read barriers are enabled, the type checks |
| 3058 | // are performed without read barriers. This is fine, even in |
| 3059 | // the case where a class object is in the from-space after |
| 3060 | // the flip, as a comparison involving such a type would not |
| 3061 | // produce a false positive; it may of course produce a false |
| 3062 | // negative, in which case we would take the ArraySet slow |
| 3063 | // path. |
| 3064 | |
| 3065 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 3066 | __ LoadFromOffset(kLoadWord, temp1, obj, class_offset, null_checker); |
| 3067 | __ MaybeUnpoisonHeapReference(temp1); |
| 3068 | |
| 3069 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 3070 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 3071 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3072 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 3073 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 3074 | // nor `temp2`, as we are comparing two poisoned references. |
| 3075 | |
| 3076 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3077 | MipsLabel do_put; |
| 3078 | __ Beq(temp1, temp2, &do_put); |
| 3079 | // If heap poisoning is enabled, the `temp1` reference has |
| 3080 | // not been unpoisoned yet; unpoison it now. |
| 3081 | __ MaybeUnpoisonHeapReference(temp1); |
| 3082 | |
| 3083 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 3084 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 3085 | // If heap poisoning is enabled, no need to unpoison |
| 3086 | // `temp1`, as we are comparing against null below. |
| 3087 | __ Bnez(temp1, slow_path->GetEntryLabel()); |
| 3088 | __ Bind(&do_put); |
| 3089 | } else { |
| 3090 | __ Bne(temp1, temp2, slow_path->GetEntryLabel()); |
| 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | Register source = value; |
| 3095 | if (kPoisonHeapReferences) { |
| 3096 | // Note that in the case where `value` is a null reference, |
| 3097 | // we do not enter this block, as a null reference does not |
| 3098 | // need poisoning. |
| 3099 | __ Move(temp1, value); |
| 3100 | __ PoisonHeapReference(temp1); |
| 3101 | source = temp1; |
| 3102 | } |
| 3103 | |
| 3104 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3105 | if (index.IsConstant()) { |
| 3106 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3107 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3108 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3109 | } |
| 3110 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 3111 | |
| 3112 | if (!may_need_runtime_call_for_type_check) { |
| 3113 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3114 | } |
| 3115 | |
| 3116 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 3117 | |
| 3118 | if (done.IsLinked()) { |
| 3119 | __ Bind(&done); |
| 3120 | } |
| 3121 | |
| 3122 | if (slow_path != nullptr) { |
| 3123 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3124 | } |
| 3125 | break; |
| 3126 | } |
| 3127 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3128 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3129 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3130 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3131 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3132 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3133 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3134 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3135 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3136 | } |
| 3137 | if (value_location.IsConstant()) { |
| 3138 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3139 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3140 | } else { |
| 3141 | Register value = value_location.AsRegisterPairLow<Register>(); |
| 3142 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3143 | } |
| 3144 | break; |
| 3145 | } |
| 3146 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3147 | case DataType::Type::kFloat32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3148 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3149 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3150 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3151 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3152 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3153 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3154 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3155 | } |
| 3156 | if (value_location.IsConstant()) { |
| 3157 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3158 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 3159 | } else { |
| 3160 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3161 | __ StoreSToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3162 | } |
| 3163 | break; |
| 3164 | } |
| 3165 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3166 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3167 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3168 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3169 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3170 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3171 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3172 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3173 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3174 | } |
| 3175 | if (value_location.IsConstant()) { |
| 3176 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3177 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3178 | } else { |
| 3179 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3180 | __ StoreDToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3181 | } |
| 3182 | break; |
| 3183 | } |
| 3184 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 3185 | case DataType::Type::kUint32: |
| 3186 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3187 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3188 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 3189 | UNREACHABLE(); |
| 3190 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3191 | } |
| 3192 | |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3193 | void LocationsBuilderMIPS::VisitIntermediateArrayAddressIndex( |
| 3194 | HIntermediateArrayAddressIndex* instruction) { |
| 3195 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3196 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3197 | |
| 3198 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 3199 | |
| 3200 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3201 | locations->SetInAt(1, Location::ConstantLocation(shift)); |
| 3202 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3203 | } |
| 3204 | |
| 3205 | void InstructionCodeGeneratorMIPS::VisitIntermediateArrayAddressIndex( |
| 3206 | HIntermediateArrayAddressIndex* instruction) { |
| 3207 | LocationSummary* locations = instruction->GetLocations(); |
| 3208 | Register index_reg = locations->InAt(0).AsRegister<Register>(); |
| 3209 | uint32_t shift = instruction->GetShift()->AsIntConstant()->GetValue(); |
| 3210 | __ Sll(locations->Out().AsRegister<Register>(), index_reg, shift); |
| 3211 | } |
| 3212 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3213 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3214 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3215 | InvokeRuntimeCallingConvention calling_convention; |
| 3216 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3217 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3218 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3219 | |
| 3220 | HInstruction* index = instruction->InputAt(0); |
| 3221 | HInstruction* length = instruction->InputAt(1); |
| 3222 | |
| 3223 | bool const_index = false; |
| 3224 | bool const_length = false; |
| 3225 | |
| 3226 | if (index->IsConstant()) { |
| 3227 | if (length->IsConstant()) { |
| 3228 | const_index = true; |
| 3229 | const_length = true; |
| 3230 | } else { |
| 3231 | int32_t index_value = index->AsIntConstant()->GetValue(); |
| 3232 | if (index_value < 0 || IsInt<16>(index_value + 1)) { |
| 3233 | const_index = true; |
| 3234 | } |
| 3235 | } |
| 3236 | } else if (length->IsConstant()) { |
| 3237 | int32_t length_value = length->AsIntConstant()->GetValue(); |
| 3238 | if (IsUint<15>(length_value)) { |
| 3239 | const_length = true; |
| 3240 | } |
| 3241 | } |
| 3242 | |
| 3243 | locations->SetInAt(0, const_index |
| 3244 | ? Location::ConstantLocation(index->AsConstant()) |
| 3245 | : Location::RequiresRegister()); |
| 3246 | locations->SetInAt(1, const_length |
| 3247 | ? Location::ConstantLocation(length->AsConstant()) |
| 3248 | : Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 3252 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3253 | Location index_loc = locations->InAt(0); |
| 3254 | Location length_loc = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3255 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3256 | if (length_loc.IsConstant()) { |
| 3257 | int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3258 | if (index_loc.IsConstant()) { |
| 3259 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3260 | if (index < 0 || index >= length) { |
| 3261 | BoundsCheckSlowPathMIPS* slow_path = |
| 3262 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3263 | codegen_->AddSlowPath(slow_path); |
| 3264 | __ B(slow_path->GetEntryLabel()); |
| 3265 | } else { |
| 3266 | // Nothing to be done. |
| 3267 | } |
| 3268 | return; |
| 3269 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3270 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3271 | BoundsCheckSlowPathMIPS* slow_path = |
| 3272 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3273 | codegen_->AddSlowPath(slow_path); |
| 3274 | Register index = index_loc.AsRegister<Register>(); |
| 3275 | if (length == 0) { |
| 3276 | __ B(slow_path->GetEntryLabel()); |
| 3277 | } else if (length == 1) { |
| 3278 | __ Bnez(index, slow_path->GetEntryLabel()); |
| 3279 | } else { |
| 3280 | DCHECK(IsUint<15>(length)) << length; |
| 3281 | __ Sltiu(TMP, index, length); |
| 3282 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3283 | } |
| 3284 | } else { |
| 3285 | Register length = length_loc.AsRegister<Register>(); |
| 3286 | BoundsCheckSlowPathMIPS* slow_path = |
| 3287 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3288 | codegen_->AddSlowPath(slow_path); |
| 3289 | if (index_loc.IsConstant()) { |
| 3290 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3291 | if (index < 0) { |
| 3292 | __ B(slow_path->GetEntryLabel()); |
| 3293 | } else if (index == 0) { |
| 3294 | __ Blez(length, slow_path->GetEntryLabel()); |
| 3295 | } else { |
| 3296 | DCHECK(IsInt<16>(index + 1)) << index; |
| 3297 | __ Sltiu(TMP, length, index + 1); |
| 3298 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 3299 | } |
| 3300 | } else { |
| 3301 | Register index = index_loc.AsRegister<Register>(); |
| 3302 | __ Bgeu(index, length, slow_path->GetEntryLabel()); |
| 3303 | } |
| 3304 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3305 | } |
| 3306 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3307 | // Temp is used for read barrier. |
| 3308 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3309 | if (kEmitCompilerReadBarrier && |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 3310 | !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) && |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3311 | (kUseBakerReadBarrier || |
| 3312 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3313 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3314 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3315 | return 1; |
| 3316 | } |
| 3317 | return 0; |
| 3318 | } |
| 3319 | |
| 3320 | // Extra temp is used for read barrier. |
| 3321 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3322 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 3323 | } |
| 3324 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3325 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3326 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 3327 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3328 | LocationSummary* locations = |
| 3329 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3330 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3331 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3332 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3333 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3334 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3335 | } else { |
| 3336 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3337 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3338 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3339 | } |
| 3340 | |
| 3341 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3342 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3343 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3344 | Location obj_loc = locations->InAt(0); |
| 3345 | Register obj = obj_loc.AsRegister<Register>(); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3346 | Location cls = locations->InAt(1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3347 | Location temp_loc = locations->GetTemp(0); |
| 3348 | Register temp = temp_loc.AsRegister<Register>(); |
| 3349 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 3350 | DCHECK_LE(num_temps, 2u); |
| 3351 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3352 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3353 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3354 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3355 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 3356 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 3357 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 3358 | const uint32_t object_array_data_offset = |
| 3359 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 3360 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3361 | |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 3362 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3363 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3364 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 3365 | instruction, is_type_check_slow_path_fatal); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3366 | codegen_->AddSlowPath(slow_path); |
| 3367 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3368 | // Avoid this check if we know `obj` is not null. |
| 3369 | if (instruction->MustDoNullCheck()) { |
| 3370 | __ Beqz(obj, &done); |
| 3371 | } |
| 3372 | |
| 3373 | switch (type_check_kind) { |
| 3374 | case TypeCheckKind::kExactCheck: |
| 3375 | case TypeCheckKind::kArrayCheck: { |
| 3376 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3377 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3378 | temp_loc, |
| 3379 | obj_loc, |
| 3380 | class_offset, |
| 3381 | maybe_temp2_loc, |
| 3382 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3383 | // Jump to slow path for throwing the exception or doing a |
| 3384 | // more involved array check. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3385 | __ Bne(temp, cls.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3386 | break; |
| 3387 | } |
| 3388 | |
| 3389 | case TypeCheckKind::kAbstractClassCheck: { |
| 3390 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3391 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3392 | temp_loc, |
| 3393 | obj_loc, |
| 3394 | class_offset, |
| 3395 | maybe_temp2_loc, |
| 3396 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3397 | // If the class is abstract, we eagerly fetch the super class of the |
| 3398 | // object to avoid doing a comparison we know will fail. |
| 3399 | MipsLabel loop; |
| 3400 | __ Bind(&loop); |
| 3401 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3402 | GenerateReferenceLoadOneRegister(instruction, |
| 3403 | temp_loc, |
| 3404 | super_offset, |
| 3405 | maybe_temp2_loc, |
| 3406 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3407 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3408 | // exception. |
| 3409 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3410 | // Otherwise, compare the classes. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3411 | __ Bne(temp, cls.AsRegister<Register>(), &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3412 | break; |
| 3413 | } |
| 3414 | |
| 3415 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3416 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3417 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3418 | temp_loc, |
| 3419 | obj_loc, |
| 3420 | class_offset, |
| 3421 | maybe_temp2_loc, |
| 3422 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3423 | // Walk over the class hierarchy to find a match. |
| 3424 | MipsLabel loop; |
| 3425 | __ Bind(&loop); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3426 | __ Beq(temp, cls.AsRegister<Register>(), &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3427 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3428 | GenerateReferenceLoadOneRegister(instruction, |
| 3429 | temp_loc, |
| 3430 | super_offset, |
| 3431 | maybe_temp2_loc, |
| 3432 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3433 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3434 | // exception. Otherwise, jump to the beginning of the loop. |
| 3435 | __ Bnez(temp, &loop); |
| 3436 | __ B(slow_path->GetEntryLabel()); |
| 3437 | break; |
| 3438 | } |
| 3439 | |
| 3440 | case TypeCheckKind::kArrayObjectCheck: { |
| 3441 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3442 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3443 | temp_loc, |
| 3444 | obj_loc, |
| 3445 | class_offset, |
| 3446 | maybe_temp2_loc, |
| 3447 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3448 | // Do an exact check. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3449 | __ Beq(temp, cls.AsRegister<Register>(), &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3450 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 3451 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3452 | GenerateReferenceLoadOneRegister(instruction, |
| 3453 | temp_loc, |
| 3454 | component_offset, |
| 3455 | maybe_temp2_loc, |
| 3456 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3457 | // If the component type is null, jump to the slow path to throw the exception. |
| 3458 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3459 | // Otherwise, the object is indeed an array, further check that this component |
| 3460 | // type is not a primitive type. |
| 3461 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 3462 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3463 | __ Bnez(temp, slow_path->GetEntryLabel()); |
| 3464 | break; |
| 3465 | } |
| 3466 | |
| 3467 | case TypeCheckKind::kUnresolvedCheck: |
| 3468 | // We always go into the type check slow path for the unresolved check case. |
| 3469 | // We cannot directly call the CheckCast runtime entry point |
| 3470 | // without resorting to a type checking slow path here (i.e. by |
| 3471 | // calling InvokeRuntime directly), as it would require to |
| 3472 | // assign fixed registers for the inputs of this HInstanceOf |
| 3473 | // instruction (following the runtime calling convention), which |
| 3474 | // might be cluttered by the potential first read barrier |
| 3475 | // emission at the beginning of this method. |
| 3476 | __ B(slow_path->GetEntryLabel()); |
| 3477 | break; |
| 3478 | |
| 3479 | case TypeCheckKind::kInterfaceCheck: { |
| 3480 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 3481 | // positives by doing this. |
| 3482 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3483 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3484 | temp_loc, |
| 3485 | obj_loc, |
| 3486 | class_offset, |
| 3487 | maybe_temp2_loc, |
| 3488 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3489 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3490 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3491 | temp_loc, |
| 3492 | temp_loc, |
| 3493 | iftable_offset, |
| 3494 | maybe_temp2_loc, |
| 3495 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3496 | // Iftable is never null. |
| 3497 | __ Lw(TMP, temp, array_length_offset); |
| 3498 | // Loop through the iftable and check if any class matches. |
| 3499 | MipsLabel loop; |
| 3500 | __ Bind(&loop); |
| 3501 | __ Addiu(temp, temp, 2 * kHeapReferenceSize); // Possibly in delay slot on R2. |
| 3502 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3503 | __ Lw(AT, temp, object_array_data_offset - 2 * kHeapReferenceSize); |
| 3504 | __ MaybeUnpoisonHeapReference(AT); |
| 3505 | // Go to next interface. |
| 3506 | __ Addiu(TMP, TMP, -2); |
| 3507 | // Compare the classes and continue the loop if they do not match. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3508 | __ Bne(AT, cls.AsRegister<Register>(), &loop); |
| 3509 | break; |
| 3510 | } |
| 3511 | |
| 3512 | case TypeCheckKind::kBitstringCheck: { |
| 3513 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3514 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3515 | temp_loc, |
| 3516 | obj_loc, |
| 3517 | class_offset, |
| 3518 | maybe_temp2_loc, |
| 3519 | kWithoutReadBarrier); |
| 3520 | |
| 3521 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 3522 | __ Bnez(temp, slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3523 | break; |
| 3524 | } |
| 3525 | } |
| 3526 | |
| 3527 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3528 | __ Bind(slow_path->GetExitLabel()); |
| 3529 | } |
| 3530 | |
| 3531 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3532 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3533 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3534 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3535 | if (check->HasUses()) { |
| 3536 | locations->SetOut(Location::SameAsFirstInput()); |
| 3537 | } |
| 3538 | } |
| 3539 | |
| 3540 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3541 | // We assume the class is not null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3542 | SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS( |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3543 | check->GetLoadClass(), |
| 3544 | check, |
| 3545 | check->GetDexPc(), |
| 3546 | true); |
| 3547 | codegen_->AddSlowPath(slow_path); |
| 3548 | GenerateClassInitializationCheck(slow_path, |
| 3549 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| 3550 | } |
| 3551 | |
| 3552 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3553 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3554 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3555 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3556 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3557 | |
| 3558 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3559 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3560 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3561 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3562 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3563 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3564 | case DataType::Type::kInt32: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3565 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3566 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3567 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3568 | break; |
| 3569 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3570 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3571 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3572 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3573 | // Output overlaps because it is written before doing the low comparison. |
| 3574 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3575 | break; |
| 3576 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3577 | case DataType::Type::kFloat32: |
| 3578 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3579 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3580 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3581 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3582 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3583 | |
| 3584 | default: |
| 3585 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3586 | } |
| 3587 | } |
| 3588 | |
| 3589 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { |
| 3590 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3591 | Register res = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3592 | DataType::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3593 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3594 | |
| 3595 | // 0 if: left == right |
| 3596 | // 1 if: left > right |
| 3597 | // -1 if: left < right |
| 3598 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3599 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3600 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3601 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3602 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3603 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3604 | case DataType::Type::kInt32: { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3605 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3606 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 3607 | __ Slt(TMP, lhs, rhs); |
| 3608 | __ Slt(res, rhs, lhs); |
| 3609 | __ Subu(res, res, TMP); |
| 3610 | break; |
| 3611 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3612 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3613 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3614 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3615 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3616 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 3617 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 3618 | // TODO: more efficient (direct) comparison with a constant. |
| 3619 | __ Slt(TMP, lhs_high, rhs_high); |
| 3620 | __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt. |
| 3621 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3622 | __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal. |
| 3623 | __ Sltu(TMP, lhs_low, rhs_low); |
| 3624 | __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt. |
| 3625 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3626 | __ Bind(&done); |
| 3627 | break; |
| 3628 | } |
| 3629 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3630 | case DataType::Type::kFloat32: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3631 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3632 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3633 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3634 | MipsLabel done; |
| 3635 | if (isR6) { |
| 3636 | __ CmpEqS(FTMP, lhs, rhs); |
| 3637 | __ LoadConst32(res, 0); |
| 3638 | __ Bc1nez(FTMP, &done); |
| 3639 | if (gt_bias) { |
| 3640 | __ CmpLtS(FTMP, lhs, rhs); |
| 3641 | __ LoadConst32(res, -1); |
| 3642 | __ Bc1nez(FTMP, &done); |
| 3643 | __ LoadConst32(res, 1); |
| 3644 | } else { |
| 3645 | __ CmpLtS(FTMP, rhs, lhs); |
| 3646 | __ LoadConst32(res, 1); |
| 3647 | __ Bc1nez(FTMP, &done); |
| 3648 | __ LoadConst32(res, -1); |
| 3649 | } |
| 3650 | } else { |
| 3651 | if (gt_bias) { |
| 3652 | __ ColtS(0, lhs, rhs); |
| 3653 | __ LoadConst32(res, -1); |
| 3654 | __ Bc1t(0, &done); |
| 3655 | __ CeqS(0, lhs, rhs); |
| 3656 | __ LoadConst32(res, 1); |
| 3657 | __ Movt(res, ZERO, 0); |
| 3658 | } else { |
| 3659 | __ ColtS(0, rhs, lhs); |
| 3660 | __ LoadConst32(res, 1); |
| 3661 | __ Bc1t(0, &done); |
| 3662 | __ CeqS(0, lhs, rhs); |
| 3663 | __ LoadConst32(res, -1); |
| 3664 | __ Movt(res, ZERO, 0); |
| 3665 | } |
| 3666 | } |
| 3667 | __ Bind(&done); |
| 3668 | break; |
| 3669 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3670 | case DataType::Type::kFloat64: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3671 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3672 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3673 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3674 | MipsLabel done; |
| 3675 | if (isR6) { |
| 3676 | __ CmpEqD(FTMP, lhs, rhs); |
| 3677 | __ LoadConst32(res, 0); |
| 3678 | __ Bc1nez(FTMP, &done); |
| 3679 | if (gt_bias) { |
| 3680 | __ CmpLtD(FTMP, lhs, rhs); |
| 3681 | __ LoadConst32(res, -1); |
| 3682 | __ Bc1nez(FTMP, &done); |
| 3683 | __ LoadConst32(res, 1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3684 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3685 | __ CmpLtD(FTMP, rhs, lhs); |
| 3686 | __ LoadConst32(res, 1); |
| 3687 | __ Bc1nez(FTMP, &done); |
| 3688 | __ LoadConst32(res, -1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3689 | } |
| 3690 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3691 | if (gt_bias) { |
| 3692 | __ ColtD(0, lhs, rhs); |
| 3693 | __ LoadConst32(res, -1); |
| 3694 | __ Bc1t(0, &done); |
| 3695 | __ CeqD(0, lhs, rhs); |
| 3696 | __ LoadConst32(res, 1); |
| 3697 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3698 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3699 | __ ColtD(0, rhs, lhs); |
| 3700 | __ LoadConst32(res, 1); |
| 3701 | __ Bc1t(0, &done); |
| 3702 | __ CeqD(0, lhs, rhs); |
| 3703 | __ LoadConst32(res, -1); |
| 3704 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3705 | } |
| 3706 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3707 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3708 | break; |
| 3709 | } |
| 3710 | |
| 3711 | default: |
| 3712 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3713 | } |
| 3714 | } |
| 3715 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3716 | void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3717 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3718 | switch (instruction->InputAt(0)->GetType()) { |
| 3719 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3720 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3721 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3722 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3723 | break; |
| 3724 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3725 | case DataType::Type::kFloat32: |
| 3726 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3727 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3728 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3729 | break; |
| 3730 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3731 | if (!instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3732 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3733 | } |
| 3734 | } |
| 3735 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3736 | void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3737 | if (instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3738 | return; |
| 3739 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3740 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3741 | DataType::Type type = instruction->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3742 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3743 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3744 | switch (type) { |
| 3745 | default: |
| 3746 | // Integer case. |
| 3747 | GenerateIntCompare(instruction->GetCondition(), locations); |
| 3748 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3749 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3750 | case DataType::Type::kInt64: |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 3751 | GenerateLongCompare(instruction->GetCondition(), locations); |
| 3752 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3753 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3754 | case DataType::Type::kFloat32: |
| 3755 | case DataType::Type::kFloat64: |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 3756 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 3757 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3758 | } |
| 3759 | } |
| 3760 | |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3761 | void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3762 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3763 | |
| 3764 | LocationSummary* locations = instruction->GetLocations(); |
| 3765 | Location second = locations->InAt(1); |
| 3766 | DCHECK(second.IsConstant()); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3767 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3768 | DCHECK(imm == 1 || imm == -1); |
| 3769 | |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3770 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 3771 | Register out = locations->Out().AsRegister<Register>(); |
| 3772 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3773 | |
| 3774 | if (instruction->IsRem()) { |
| 3775 | __ Move(out, ZERO); |
| 3776 | } else { |
| 3777 | if (imm == -1) { |
| 3778 | __ Subu(out, ZERO, dividend); |
| 3779 | } else if (out != dividend) { |
| 3780 | __ Move(out, dividend); |
| 3781 | } |
| 3782 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3783 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3784 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 3785 | Register out_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 3786 | Register out_low = locations->Out().AsRegisterPairLow<Register>(); |
| 3787 | Register in_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3788 | Register in_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3789 | |
| 3790 | if (instruction->IsRem()) { |
| 3791 | __ Move(out_high, ZERO); |
| 3792 | __ Move(out_low, ZERO); |
| 3793 | } else { |
| 3794 | if (imm == -1) { |
| 3795 | __ Subu(out_low, ZERO, in_low); |
| 3796 | __ Sltu(AT, ZERO, out_low); |
| 3797 | __ Subu(out_high, ZERO, in_high); |
| 3798 | __ Subu(out_high, out_high, AT); |
| 3799 | } else { |
| 3800 | __ Move(out_low, in_low); |
| 3801 | __ Move(out_high, in_high); |
| 3802 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3803 | } |
| 3804 | } |
| 3805 | } |
| 3806 | |
| 3807 | void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3808 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3809 | |
| 3810 | LocationSummary* locations = instruction->GetLocations(); |
| 3811 | Location second = locations->InAt(1); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3812 | const bool is_r2_or_newer = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
| 3813 | const bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3814 | DCHECK(second.IsConstant()); |
| 3815 | |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3816 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 3817 | Register out = locations->Out().AsRegister<Register>(); |
| 3818 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3819 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3820 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 3821 | int ctz_imm = CTZ(abs_imm); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3822 | |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3823 | if (instruction->IsDiv()) { |
| 3824 | if (ctz_imm == 1) { |
| 3825 | // Fast path for division by +/-2, which is very common. |
| 3826 | __ Srl(TMP, dividend, 31); |
| 3827 | } else { |
| 3828 | __ Sra(TMP, dividend, 31); |
| 3829 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3830 | } |
| 3831 | __ Addu(out, dividend, TMP); |
| 3832 | __ Sra(out, out, ctz_imm); |
| 3833 | if (imm < 0) { |
| 3834 | __ Subu(out, ZERO, out); |
| 3835 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3836 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3837 | if (ctz_imm == 1) { |
| 3838 | // Fast path for modulo +/-2, which is very common. |
| 3839 | __ Sra(TMP, dividend, 31); |
| 3840 | __ Subu(out, dividend, TMP); |
| 3841 | __ Andi(out, out, 1); |
| 3842 | __ Addu(out, out, TMP); |
| 3843 | } else { |
| 3844 | __ Sra(TMP, dividend, 31); |
| 3845 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3846 | __ Addu(out, dividend, TMP); |
| 3847 | if (IsUint<16>(abs_imm - 1)) { |
| 3848 | __ Andi(out, out, abs_imm - 1); |
| 3849 | } else { |
| 3850 | if (is_r2_or_newer) { |
| 3851 | __ Ins(out, ZERO, ctz_imm, 32 - ctz_imm); |
| 3852 | } else { |
| 3853 | __ Sll(out, out, 32 - ctz_imm); |
| 3854 | __ Srl(out, out, 32 - ctz_imm); |
| 3855 | } |
| 3856 | } |
| 3857 | __ Subu(out, out, TMP); |
| 3858 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3859 | } |
| 3860 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3861 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 3862 | Register out_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 3863 | Register out_low = locations->Out().AsRegisterPairLow<Register>(); |
| 3864 | Register in_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3865 | Register in_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3866 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3867 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 3868 | int ctz_imm = CTZ(abs_imm); |
| 3869 | |
| 3870 | if (instruction->IsDiv()) { |
| 3871 | if (ctz_imm < 32) { |
| 3872 | if (ctz_imm == 1) { |
| 3873 | __ Srl(AT, in_high, 31); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3874 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3875 | __ Sra(AT, in_high, 31); |
| 3876 | __ Srl(AT, AT, 32 - ctz_imm); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3877 | } |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3878 | __ Addu(AT, AT, in_low); |
| 3879 | __ Sltu(TMP, AT, in_low); |
| 3880 | __ Addu(out_high, in_high, TMP); |
| 3881 | __ Srl(out_low, AT, ctz_imm); |
| 3882 | if (is_r2_or_newer) { |
| 3883 | __ Ins(out_low, out_high, 32 - ctz_imm, ctz_imm); |
| 3884 | __ Sra(out_high, out_high, ctz_imm); |
| 3885 | } else { |
| 3886 | __ Sll(AT, out_high, 32 - ctz_imm); |
| 3887 | __ Sra(out_high, out_high, ctz_imm); |
| 3888 | __ Or(out_low, out_low, AT); |
| 3889 | } |
| 3890 | if (imm < 0) { |
| 3891 | __ Subu(out_low, ZERO, out_low); |
| 3892 | __ Sltu(AT, ZERO, out_low); |
| 3893 | __ Subu(out_high, ZERO, out_high); |
| 3894 | __ Subu(out_high, out_high, AT); |
| 3895 | } |
| 3896 | } else if (ctz_imm == 32) { |
| 3897 | __ Sra(AT, in_high, 31); |
| 3898 | __ Addu(AT, AT, in_low); |
| 3899 | __ Sltu(AT, AT, in_low); |
| 3900 | __ Addu(out_low, in_high, AT); |
| 3901 | if (imm < 0) { |
| 3902 | __ Srl(TMP, out_low, 31); |
| 3903 | __ Subu(out_low, ZERO, out_low); |
| 3904 | __ Sltu(AT, ZERO, out_low); |
| 3905 | __ Subu(out_high, TMP, AT); |
| 3906 | } else { |
| 3907 | __ Sra(out_high, out_low, 31); |
| 3908 | } |
| 3909 | } else if (ctz_imm < 63) { |
| 3910 | __ Sra(AT, in_high, 31); |
| 3911 | __ Srl(TMP, AT, 64 - ctz_imm); |
| 3912 | __ Addu(AT, AT, in_low); |
| 3913 | __ Sltu(AT, AT, in_low); |
| 3914 | __ Addu(out_low, in_high, AT); |
| 3915 | __ Addu(out_low, out_low, TMP); |
| 3916 | __ Sra(out_low, out_low, ctz_imm - 32); |
| 3917 | if (imm < 0) { |
| 3918 | __ Subu(out_low, ZERO, out_low); |
| 3919 | } |
| 3920 | __ Sra(out_high, out_low, 31); |
| 3921 | } else { |
| 3922 | DCHECK_LT(imm, 0); |
| 3923 | if (is_r6) { |
| 3924 | __ Aui(AT, in_high, 0x8000); |
| 3925 | } else { |
| 3926 | __ Lui(AT, 0x8000); |
| 3927 | __ Xor(AT, AT, in_high); |
| 3928 | } |
| 3929 | __ Or(AT, AT, in_low); |
| 3930 | __ Sltiu(out_low, AT, 1); |
| 3931 | __ Move(out_high, ZERO); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3932 | } |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3933 | } else { |
| 3934 | if ((ctz_imm == 1) && !is_r6) { |
| 3935 | __ Andi(AT, in_low, 1); |
| 3936 | __ Sll(TMP, in_low, 31); |
| 3937 | __ And(TMP, in_high, TMP); |
| 3938 | __ Sra(out_high, TMP, 31); |
| 3939 | __ Or(out_low, out_high, AT); |
| 3940 | } else if (ctz_imm < 32) { |
| 3941 | __ Sra(AT, in_high, 31); |
| 3942 | if (ctz_imm <= 16) { |
| 3943 | __ Andi(out_low, in_low, abs_imm - 1); |
| 3944 | } else if (is_r2_or_newer) { |
| 3945 | __ Ext(out_low, in_low, 0, ctz_imm); |
| 3946 | } else { |
| 3947 | __ Sll(out_low, in_low, 32 - ctz_imm); |
| 3948 | __ Srl(out_low, out_low, 32 - ctz_imm); |
| 3949 | } |
| 3950 | if (is_r6) { |
| 3951 | __ Selnez(out_high, AT, out_low); |
| 3952 | } else { |
| 3953 | __ Movz(AT, ZERO, out_low); |
| 3954 | __ Move(out_high, AT); |
| 3955 | } |
| 3956 | if (is_r2_or_newer) { |
| 3957 | __ Ins(out_low, out_high, ctz_imm, 32 - ctz_imm); |
| 3958 | } else { |
| 3959 | __ Sll(AT, out_high, ctz_imm); |
| 3960 | __ Or(out_low, out_low, AT); |
| 3961 | } |
| 3962 | } else if (ctz_imm == 32) { |
| 3963 | __ Sra(AT, in_high, 31); |
| 3964 | __ Move(out_low, in_low); |
| 3965 | if (is_r6) { |
| 3966 | __ Selnez(out_high, AT, out_low); |
| 3967 | } else { |
| 3968 | __ Movz(AT, ZERO, out_low); |
| 3969 | __ Move(out_high, AT); |
| 3970 | } |
| 3971 | } else if (ctz_imm < 63) { |
| 3972 | __ Sra(AT, in_high, 31); |
| 3973 | __ Move(TMP, in_low); |
| 3974 | if (ctz_imm - 32 <= 16) { |
| 3975 | __ Andi(out_high, in_high, (1 << (ctz_imm - 32)) - 1); |
| 3976 | } else if (is_r2_or_newer) { |
| 3977 | __ Ext(out_high, in_high, 0, ctz_imm - 32); |
| 3978 | } else { |
| 3979 | __ Sll(out_high, in_high, 64 - ctz_imm); |
| 3980 | __ Srl(out_high, out_high, 64 - ctz_imm); |
| 3981 | } |
| 3982 | __ Move(out_low, TMP); |
| 3983 | __ Or(TMP, TMP, out_high); |
| 3984 | if (is_r6) { |
| 3985 | __ Selnez(AT, AT, TMP); |
| 3986 | } else { |
| 3987 | __ Movz(AT, ZERO, TMP); |
| 3988 | } |
| 3989 | if (is_r2_or_newer) { |
| 3990 | __ Ins(out_high, AT, ctz_imm - 32, 64 - ctz_imm); |
| 3991 | } else { |
| 3992 | __ Sll(AT, AT, ctz_imm - 32); |
| 3993 | __ Or(out_high, out_high, AT); |
| 3994 | } |
| 3995 | } else { |
| 3996 | if (is_r6) { |
| 3997 | __ Aui(AT, in_high, 0x8000); |
| 3998 | } else { |
| 3999 | __ Lui(AT, 0x8000); |
| 4000 | __ Xor(AT, AT, in_high); |
| 4001 | } |
| 4002 | __ Or(AT, AT, in_low); |
| 4003 | __ Sltiu(AT, AT, 1); |
| 4004 | __ Sll(AT, AT, 31); |
| 4005 | __ Move(out_low, in_low); |
| 4006 | __ Xor(out_high, in_high, AT); |
| 4007 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4008 | } |
| 4009 | } |
| 4010 | } |
| 4011 | |
| 4012 | void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4013 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4014 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4015 | |
| 4016 | LocationSummary* locations = instruction->GetLocations(); |
| 4017 | Location second = locations->InAt(1); |
| 4018 | DCHECK(second.IsConstant()); |
| 4019 | |
| 4020 | Register out = locations->Out().AsRegister<Register>(); |
| 4021 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4022 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4023 | |
| 4024 | int64_t magic; |
| 4025 | int shift; |
| 4026 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4027 | |
| 4028 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4029 | |
| 4030 | __ LoadConst32(TMP, magic); |
| 4031 | if (isR6) { |
| 4032 | __ MuhR6(TMP, dividend, TMP); |
| 4033 | } else { |
| 4034 | __ MultR2(dividend, TMP); |
| 4035 | __ Mfhi(TMP); |
| 4036 | } |
| 4037 | if (imm > 0 && magic < 0) { |
| 4038 | __ Addu(TMP, TMP, dividend); |
| 4039 | } else if (imm < 0 && magic > 0) { |
| 4040 | __ Subu(TMP, TMP, dividend); |
| 4041 | } |
| 4042 | |
| 4043 | if (shift != 0) { |
| 4044 | __ Sra(TMP, TMP, shift); |
| 4045 | } |
| 4046 | |
| 4047 | if (instruction->IsDiv()) { |
| 4048 | __ Sra(out, TMP, 31); |
| 4049 | __ Subu(out, TMP, out); |
| 4050 | } else { |
| 4051 | __ Sra(AT, TMP, 31); |
| 4052 | __ Subu(AT, TMP, AT); |
| 4053 | __ LoadConst32(TMP, imm); |
| 4054 | if (isR6) { |
| 4055 | __ MulR6(TMP, AT, TMP); |
| 4056 | } else { |
| 4057 | __ MulR2(TMP, AT, TMP); |
| 4058 | } |
| 4059 | __ Subu(out, dividend, TMP); |
| 4060 | } |
| 4061 | } |
| 4062 | |
| 4063 | void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 4064 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4065 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4066 | |
| 4067 | LocationSummary* locations = instruction->GetLocations(); |
| 4068 | Register out = locations->Out().AsRegister<Register>(); |
| 4069 | Location second = locations->InAt(1); |
| 4070 | |
| 4071 | if (second.IsConstant()) { |
| 4072 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4073 | if (imm == 0) { |
| 4074 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4075 | } else if (imm == 1 || imm == -1) { |
| 4076 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4077 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4078 | DivRemByPowerOfTwo(instruction); |
| 4079 | } else { |
| 4080 | DCHECK(imm <= -2 || imm >= 2); |
| 4081 | GenerateDivRemWithAnyConstant(instruction); |
| 4082 | } |
| 4083 | } else { |
| 4084 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4085 | Register divisor = second.AsRegister<Register>(); |
| 4086 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4087 | if (instruction->IsDiv()) { |
| 4088 | if (isR6) { |
| 4089 | __ DivR6(out, dividend, divisor); |
| 4090 | } else { |
| 4091 | __ DivR2(out, dividend, divisor); |
| 4092 | } |
| 4093 | } else { |
| 4094 | if (isR6) { |
| 4095 | __ ModR6(out, dividend, divisor); |
| 4096 | } else { |
| 4097 | __ ModR2(out, dividend, divisor); |
| 4098 | } |
| 4099 | } |
| 4100 | } |
| 4101 | } |
| 4102 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4103 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4104 | DataType::Type type = div->GetResultType(); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 4105 | bool call_long_div = false; |
| 4106 | if (type == DataType::Type::kInt64) { |
| 4107 | if (div->InputAt(1)->IsConstant()) { |
| 4108 | int64_t imm = CodeGenerator::GetInt64ValueOf(div->InputAt(1)->AsConstant()); |
| 4109 | call_long_div = (imm != 0) && !IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm))); |
| 4110 | } else { |
| 4111 | call_long_div = true; |
| 4112 | } |
| 4113 | } |
| 4114 | LocationSummary::CallKind call_kind = call_long_div |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4115 | ? LocationSummary::kCallOnMainOnly |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4116 | : LocationSummary::kNoCall; |
| 4117 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4118 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4119 | |
| 4120 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4121 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4122 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4123 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4124 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4125 | break; |
| 4126 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4127 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 4128 | if (call_long_div) { |
| 4129 | InvokeRuntimeCallingConvention calling_convention; |
| 4130 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4131 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4132 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4133 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4134 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4135 | } else { |
| 4136 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4137 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 4138 | locations->SetOut(Location::RequiresRegister()); |
| 4139 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4140 | break; |
| 4141 | } |
| 4142 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4143 | case DataType::Type::kFloat32: |
| 4144 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4145 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4146 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4147 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4148 | break; |
| 4149 | |
| 4150 | default: |
| 4151 | LOG(FATAL) << "Unexpected div type " << type; |
| 4152 | } |
| 4153 | } |
| 4154 | |
| 4155 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4156 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4157 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4158 | |
| 4159 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4160 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4161 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4162 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4163 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 4164 | if (locations->InAt(1).IsConstant()) { |
| 4165 | int64_t imm = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue(); |
| 4166 | if (imm == 0) { |
| 4167 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4168 | } else if (imm == 1 || imm == -1) { |
| 4169 | DivRemOneOrMinusOne(instruction); |
| 4170 | } else { |
| 4171 | DCHECK(IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm)))); |
| 4172 | DivRemByPowerOfTwo(instruction); |
| 4173 | } |
| 4174 | } else { |
| 4175 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
| 4176 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| 4177 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4178 | break; |
| 4179 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4180 | case DataType::Type::kFloat32: |
| 4181 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4182 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 4183 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4184 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4185 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4186 | __ DivS(dst, lhs, rhs); |
| 4187 | } else { |
| 4188 | __ DivD(dst, lhs, rhs); |
| 4189 | } |
| 4190 | break; |
| 4191 | } |
| 4192 | default: |
| 4193 | LOG(FATAL) << "Unexpected div type " << type; |
| 4194 | } |
| 4195 | } |
| 4196 | |
| 4197 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4198 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4199 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4200 | } |
| 4201 | |
| 4202 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4203 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4204 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4205 | codegen_->AddSlowPath(slow_path); |
| 4206 | Location value = instruction->GetLocations()->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4207 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4208 | |
| 4209 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4210 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4211 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4212 | case DataType::Type::kInt8: |
| 4213 | case DataType::Type::kUint16: |
| 4214 | case DataType::Type::kInt16: |
| 4215 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4216 | if (value.IsConstant()) { |
| 4217 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 4218 | __ B(slow_path->GetEntryLabel()); |
| 4219 | } else { |
| 4220 | // A division by a non-null constant is valid. We don't need to perform |
| 4221 | // any check, so simply fall through. |
| 4222 | } |
| 4223 | } else { |
| 4224 | DCHECK(value.IsRegister()) << value; |
| 4225 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 4226 | } |
| 4227 | break; |
| 4228 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4229 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4230 | if (value.IsConstant()) { |
| 4231 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4232 | __ B(slow_path->GetEntryLabel()); |
| 4233 | } else { |
| 4234 | // A division by a non-null constant is valid. We don't need to perform |
| 4235 | // any check, so simply fall through. |
| 4236 | } |
| 4237 | } else { |
| 4238 | DCHECK(value.IsRegisterPair()) << value; |
| 4239 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); |
| 4240 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 4241 | } |
| 4242 | break; |
| 4243 | } |
| 4244 | default: |
| 4245 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| 4246 | } |
| 4247 | } |
| 4248 | |
| 4249 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { |
| 4250 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4251 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4252 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4253 | } |
| 4254 | |
| 4255 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 4256 | // Will be generated at use site. |
| 4257 | } |
| 4258 | |
| 4259 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { |
| 4260 | exit->SetLocations(nullptr); |
| 4261 | } |
| 4262 | |
| 4263 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 4264 | } |
| 4265 | |
| 4266 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { |
| 4267 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4268 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4269 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4270 | } |
| 4271 | |
| 4272 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 4273 | // Will be generated at use site. |
| 4274 | } |
| 4275 | |
| 4276 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { |
| 4277 | got->SetLocations(nullptr); |
| 4278 | } |
| 4279 | |
| 4280 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4281 | if (successor->IsExitBlock()) { |
| 4282 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 4283 | return; // no code needed |
| 4284 | } |
| 4285 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4286 | HBasicBlock* block = got->GetBlock(); |
| 4287 | HInstruction* previous = got->GetPrevious(); |
| 4288 | HLoopInformation* info = block->GetLoopInformation(); |
| 4289 | |
| 4290 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Goran Jakovljevic | feec167 | 2018-02-08 10:20:14 +0100 | [diff] [blame] | 4291 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 4292 | __ Lw(AT, SP, kCurrentMethodStackOffset); |
| 4293 | __ Lhu(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value()); |
| 4294 | __ Addiu(TMP, TMP, 1); |
| 4295 | __ Sh(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value()); |
| 4296 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4297 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 4298 | return; |
| 4299 | } |
| 4300 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 4301 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 4302 | } |
| 4303 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 4304 | __ B(codegen_->GetLabelOf(successor)); |
| 4305 | } |
| 4306 | } |
| 4307 | |
| 4308 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { |
| 4309 | HandleGoto(got, got->GetSuccessor()); |
| 4310 | } |
| 4311 | |
| 4312 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 4313 | try_boundary->SetLocations(nullptr); |
| 4314 | } |
| 4315 | |
| 4316 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 4317 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 4318 | if (!successor->IsExitBlock()) { |
| 4319 | HandleGoto(try_boundary, successor); |
| 4320 | } |
| 4321 | } |
| 4322 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4323 | void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond, |
| 4324 | LocationSummary* locations) { |
| 4325 | Register dst = locations->Out().AsRegister<Register>(); |
| 4326 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4327 | Location rhs_location = locations->InAt(1); |
| 4328 | Register rhs_reg = ZERO; |
| 4329 | int64_t rhs_imm = 0; |
| 4330 | bool use_imm = rhs_location.IsConstant(); |
| 4331 | if (use_imm) { |
| 4332 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4333 | } else { |
| 4334 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4335 | } |
| 4336 | |
| 4337 | switch (cond) { |
| 4338 | case kCondEQ: |
| 4339 | case kCondNE: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4340 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4341 | if (rhs_imm == 0) { |
| 4342 | if (cond == kCondEQ) { |
| 4343 | __ Sltiu(dst, lhs, 1); |
| 4344 | } else { |
| 4345 | __ Sltu(dst, ZERO, lhs); |
| 4346 | } |
| 4347 | } else { |
| 4348 | __ Addiu(dst, lhs, -rhs_imm); |
| 4349 | if (cond == kCondEQ) { |
| 4350 | __ Sltiu(dst, dst, 1); |
| 4351 | } else { |
| 4352 | __ Sltu(dst, ZERO, dst); |
| 4353 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4354 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4355 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4356 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 4357 | __ Xori(dst, lhs, rhs_imm); |
| 4358 | } else { |
| 4359 | if (use_imm) { |
| 4360 | rhs_reg = TMP; |
| 4361 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4362 | } |
| 4363 | __ Xor(dst, lhs, rhs_reg); |
| 4364 | } |
| 4365 | if (cond == kCondEQ) { |
| 4366 | __ Sltiu(dst, dst, 1); |
| 4367 | } else { |
| 4368 | __ Sltu(dst, ZERO, dst); |
| 4369 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4370 | } |
| 4371 | break; |
| 4372 | |
| 4373 | case kCondLT: |
| 4374 | case kCondGE: |
| 4375 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4376 | __ Slti(dst, lhs, rhs_imm); |
| 4377 | } else { |
| 4378 | if (use_imm) { |
| 4379 | rhs_reg = TMP; |
| 4380 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4381 | } |
| 4382 | __ Slt(dst, lhs, rhs_reg); |
| 4383 | } |
| 4384 | if (cond == kCondGE) { |
| 4385 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4386 | // only the slt instruction but no sge. |
| 4387 | __ Xori(dst, dst, 1); |
| 4388 | } |
| 4389 | break; |
| 4390 | |
| 4391 | case kCondLE: |
| 4392 | case kCondGT: |
| 4393 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4394 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4395 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4396 | if (cond == kCondGT) { |
| 4397 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4398 | // only the slti instruction but no sgti. |
| 4399 | __ Xori(dst, dst, 1); |
| 4400 | } |
| 4401 | } else { |
| 4402 | if (use_imm) { |
| 4403 | rhs_reg = TMP; |
| 4404 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4405 | } |
| 4406 | __ Slt(dst, rhs_reg, lhs); |
| 4407 | if (cond == kCondLE) { |
| 4408 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4409 | // only the slt instruction but no sle. |
| 4410 | __ Xori(dst, dst, 1); |
| 4411 | } |
| 4412 | } |
| 4413 | break; |
| 4414 | |
| 4415 | case kCondB: |
| 4416 | case kCondAE: |
| 4417 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4418 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4419 | // the comparison and thus lets us compare directly with |
| 4420 | // unsigned values in the ranges [0, 0x7fff] and |
| 4421 | // [0xffff8000, 0xffffffff]. |
| 4422 | __ Sltiu(dst, lhs, rhs_imm); |
| 4423 | } else { |
| 4424 | if (use_imm) { |
| 4425 | rhs_reg = TMP; |
| 4426 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4427 | } |
| 4428 | __ Sltu(dst, lhs, rhs_reg); |
| 4429 | } |
| 4430 | if (cond == kCondAE) { |
| 4431 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4432 | // only the sltu instruction but no sgeu. |
| 4433 | __ Xori(dst, dst, 1); |
| 4434 | } |
| 4435 | break; |
| 4436 | |
| 4437 | case kCondBE: |
| 4438 | case kCondA: |
| 4439 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4440 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4441 | // Note that this only works if rhs + 1 does not overflow |
| 4442 | // to 0, hence the check above. |
| 4443 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4444 | // the comparison and thus lets us compare directly with |
| 4445 | // unsigned values in the ranges [0, 0x7fff] and |
| 4446 | // [0xffff8000, 0xffffffff]. |
| 4447 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4448 | if (cond == kCondA) { |
| 4449 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4450 | // only the sltiu instruction but no sgtiu. |
| 4451 | __ Xori(dst, dst, 1); |
| 4452 | } |
| 4453 | } else { |
| 4454 | if (use_imm) { |
| 4455 | rhs_reg = TMP; |
| 4456 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4457 | } |
| 4458 | __ Sltu(dst, rhs_reg, lhs); |
| 4459 | if (cond == kCondBE) { |
| 4460 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4461 | // only the sltu instruction but no sleu. |
| 4462 | __ Xori(dst, dst, 1); |
| 4463 | } |
| 4464 | } |
| 4465 | break; |
| 4466 | } |
| 4467 | } |
| 4468 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4469 | bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond, |
| 4470 | LocationSummary* input_locations, |
| 4471 | Register dst) { |
| 4472 | Register lhs = input_locations->InAt(0).AsRegister<Register>(); |
| 4473 | Location rhs_location = input_locations->InAt(1); |
| 4474 | Register rhs_reg = ZERO; |
| 4475 | int64_t rhs_imm = 0; |
| 4476 | bool use_imm = rhs_location.IsConstant(); |
| 4477 | if (use_imm) { |
| 4478 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4479 | } else { |
| 4480 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4481 | } |
| 4482 | |
| 4483 | switch (cond) { |
| 4484 | case kCondEQ: |
| 4485 | case kCondNE: |
| 4486 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4487 | __ Addiu(dst, lhs, -rhs_imm); |
| 4488 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 4489 | __ Xori(dst, lhs, rhs_imm); |
| 4490 | } else { |
| 4491 | if (use_imm) { |
| 4492 | rhs_reg = TMP; |
| 4493 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4494 | } |
| 4495 | __ Xor(dst, lhs, rhs_reg); |
| 4496 | } |
| 4497 | return (cond == kCondEQ); |
| 4498 | |
| 4499 | case kCondLT: |
| 4500 | case kCondGE: |
| 4501 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4502 | __ Slti(dst, lhs, rhs_imm); |
| 4503 | } else { |
| 4504 | if (use_imm) { |
| 4505 | rhs_reg = TMP; |
| 4506 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4507 | } |
| 4508 | __ Slt(dst, lhs, rhs_reg); |
| 4509 | } |
| 4510 | return (cond == kCondGE); |
| 4511 | |
| 4512 | case kCondLE: |
| 4513 | case kCondGT: |
| 4514 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4515 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4516 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4517 | return (cond == kCondGT); |
| 4518 | } else { |
| 4519 | if (use_imm) { |
| 4520 | rhs_reg = TMP; |
| 4521 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4522 | } |
| 4523 | __ Slt(dst, rhs_reg, lhs); |
| 4524 | return (cond == kCondLE); |
| 4525 | } |
| 4526 | |
| 4527 | case kCondB: |
| 4528 | case kCondAE: |
| 4529 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4530 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4531 | // the comparison and thus lets us compare directly with |
| 4532 | // unsigned values in the ranges [0, 0x7fff] and |
| 4533 | // [0xffff8000, 0xffffffff]. |
| 4534 | __ Sltiu(dst, lhs, rhs_imm); |
| 4535 | } else { |
| 4536 | if (use_imm) { |
| 4537 | rhs_reg = TMP; |
| 4538 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4539 | } |
| 4540 | __ Sltu(dst, lhs, rhs_reg); |
| 4541 | } |
| 4542 | return (cond == kCondAE); |
| 4543 | |
| 4544 | case kCondBE: |
| 4545 | case kCondA: |
| 4546 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4547 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4548 | // Note that this only works if rhs + 1 does not overflow |
| 4549 | // to 0, hence the check above. |
| 4550 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4551 | // the comparison and thus lets us compare directly with |
| 4552 | // unsigned values in the ranges [0, 0x7fff] and |
| 4553 | // [0xffff8000, 0xffffffff]. |
| 4554 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4555 | return (cond == kCondA); |
| 4556 | } else { |
| 4557 | if (use_imm) { |
| 4558 | rhs_reg = TMP; |
| 4559 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4560 | } |
| 4561 | __ Sltu(dst, rhs_reg, lhs); |
| 4562 | return (cond == kCondBE); |
| 4563 | } |
| 4564 | } |
| 4565 | } |
| 4566 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4567 | void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond, |
| 4568 | LocationSummary* locations, |
| 4569 | MipsLabel* label) { |
| 4570 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4571 | Location rhs_location = locations->InAt(1); |
| 4572 | Register rhs_reg = ZERO; |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4573 | int64_t rhs_imm = 0; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4574 | bool use_imm = rhs_location.IsConstant(); |
| 4575 | if (use_imm) { |
| 4576 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4577 | } else { |
| 4578 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4579 | } |
| 4580 | |
| 4581 | if (use_imm && rhs_imm == 0) { |
| 4582 | switch (cond) { |
| 4583 | case kCondEQ: |
| 4584 | case kCondBE: // <= 0 if zero |
| 4585 | __ Beqz(lhs, label); |
| 4586 | break; |
| 4587 | case kCondNE: |
| 4588 | case kCondA: // > 0 if non-zero |
| 4589 | __ Bnez(lhs, label); |
| 4590 | break; |
| 4591 | case kCondLT: |
| 4592 | __ Bltz(lhs, label); |
| 4593 | break; |
| 4594 | case kCondGE: |
| 4595 | __ Bgez(lhs, label); |
| 4596 | break; |
| 4597 | case kCondLE: |
| 4598 | __ Blez(lhs, label); |
| 4599 | break; |
| 4600 | case kCondGT: |
| 4601 | __ Bgtz(lhs, label); |
| 4602 | break; |
| 4603 | case kCondB: // always false |
| 4604 | break; |
| 4605 | case kCondAE: // always true |
| 4606 | __ B(label); |
| 4607 | break; |
| 4608 | } |
| 4609 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4610 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4611 | if (isR6 || !use_imm) { |
| 4612 | if (use_imm) { |
| 4613 | rhs_reg = TMP; |
| 4614 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4615 | } |
| 4616 | switch (cond) { |
| 4617 | case kCondEQ: |
| 4618 | __ Beq(lhs, rhs_reg, label); |
| 4619 | break; |
| 4620 | case kCondNE: |
| 4621 | __ Bne(lhs, rhs_reg, label); |
| 4622 | break; |
| 4623 | case kCondLT: |
| 4624 | __ Blt(lhs, rhs_reg, label); |
| 4625 | break; |
| 4626 | case kCondGE: |
| 4627 | __ Bge(lhs, rhs_reg, label); |
| 4628 | break; |
| 4629 | case kCondLE: |
| 4630 | __ Bge(rhs_reg, lhs, label); |
| 4631 | break; |
| 4632 | case kCondGT: |
| 4633 | __ Blt(rhs_reg, lhs, label); |
| 4634 | break; |
| 4635 | case kCondB: |
| 4636 | __ Bltu(lhs, rhs_reg, label); |
| 4637 | break; |
| 4638 | case kCondAE: |
| 4639 | __ Bgeu(lhs, rhs_reg, label); |
| 4640 | break; |
| 4641 | case kCondBE: |
| 4642 | __ Bgeu(rhs_reg, lhs, label); |
| 4643 | break; |
| 4644 | case kCondA: |
| 4645 | __ Bltu(rhs_reg, lhs, label); |
| 4646 | break; |
| 4647 | } |
| 4648 | } else { |
| 4649 | // Special cases for more efficient comparison with constants on R2. |
| 4650 | switch (cond) { |
| 4651 | case kCondEQ: |
| 4652 | __ LoadConst32(TMP, rhs_imm); |
| 4653 | __ Beq(lhs, TMP, label); |
| 4654 | break; |
| 4655 | case kCondNE: |
| 4656 | __ LoadConst32(TMP, rhs_imm); |
| 4657 | __ Bne(lhs, TMP, label); |
| 4658 | break; |
| 4659 | case kCondLT: |
| 4660 | if (IsInt<16>(rhs_imm)) { |
| 4661 | __ Slti(TMP, lhs, rhs_imm); |
| 4662 | __ Bnez(TMP, label); |
| 4663 | } else { |
| 4664 | __ LoadConst32(TMP, rhs_imm); |
| 4665 | __ Blt(lhs, TMP, label); |
| 4666 | } |
| 4667 | break; |
| 4668 | case kCondGE: |
| 4669 | if (IsInt<16>(rhs_imm)) { |
| 4670 | __ Slti(TMP, lhs, rhs_imm); |
| 4671 | __ Beqz(TMP, label); |
| 4672 | } else { |
| 4673 | __ LoadConst32(TMP, rhs_imm); |
| 4674 | __ Bge(lhs, TMP, label); |
| 4675 | } |
| 4676 | break; |
| 4677 | case kCondLE: |
| 4678 | if (IsInt<16>(rhs_imm + 1)) { |
| 4679 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4680 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4681 | __ Bnez(TMP, label); |
| 4682 | } else { |
| 4683 | __ LoadConst32(TMP, rhs_imm); |
| 4684 | __ Bge(TMP, lhs, label); |
| 4685 | } |
| 4686 | break; |
| 4687 | case kCondGT: |
| 4688 | if (IsInt<16>(rhs_imm + 1)) { |
| 4689 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4690 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4691 | __ Beqz(TMP, label); |
| 4692 | } else { |
| 4693 | __ LoadConst32(TMP, rhs_imm); |
| 4694 | __ Blt(TMP, lhs, label); |
| 4695 | } |
| 4696 | break; |
| 4697 | case kCondB: |
| 4698 | if (IsInt<16>(rhs_imm)) { |
| 4699 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4700 | __ Bnez(TMP, label); |
| 4701 | } else { |
| 4702 | __ LoadConst32(TMP, rhs_imm); |
| 4703 | __ Bltu(lhs, TMP, label); |
| 4704 | } |
| 4705 | break; |
| 4706 | case kCondAE: |
| 4707 | if (IsInt<16>(rhs_imm)) { |
| 4708 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4709 | __ Beqz(TMP, label); |
| 4710 | } else { |
| 4711 | __ LoadConst32(TMP, rhs_imm); |
| 4712 | __ Bgeu(lhs, TMP, label); |
| 4713 | } |
| 4714 | break; |
| 4715 | case kCondBE: |
| 4716 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4717 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4718 | // Note that this only works if rhs + 1 does not overflow |
| 4719 | // to 0, hence the check above. |
| 4720 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4721 | __ Bnez(TMP, label); |
| 4722 | } else { |
| 4723 | __ LoadConst32(TMP, rhs_imm); |
| 4724 | __ Bgeu(TMP, lhs, label); |
| 4725 | } |
| 4726 | break; |
| 4727 | case kCondA: |
| 4728 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4729 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4730 | // Note that this only works if rhs + 1 does not overflow |
| 4731 | // to 0, hence the check above. |
| 4732 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4733 | __ Beqz(TMP, label); |
| 4734 | } else { |
| 4735 | __ LoadConst32(TMP, rhs_imm); |
| 4736 | __ Bltu(TMP, lhs, label); |
| 4737 | } |
| 4738 | break; |
| 4739 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4740 | } |
| 4741 | } |
| 4742 | } |
| 4743 | |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 4744 | void InstructionCodeGeneratorMIPS::GenerateLongCompare(IfCondition cond, |
| 4745 | LocationSummary* locations) { |
| 4746 | Register dst = locations->Out().AsRegister<Register>(); |
| 4747 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4748 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4749 | Location rhs_location = locations->InAt(1); |
| 4750 | Register rhs_high = ZERO; |
| 4751 | Register rhs_low = ZERO; |
| 4752 | int64_t imm = 0; |
| 4753 | uint32_t imm_high = 0; |
| 4754 | uint32_t imm_low = 0; |
| 4755 | bool use_imm = rhs_location.IsConstant(); |
| 4756 | if (use_imm) { |
| 4757 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 4758 | imm_high = High32Bits(imm); |
| 4759 | imm_low = Low32Bits(imm); |
| 4760 | } else { |
| 4761 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 4762 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 4763 | } |
| 4764 | if (use_imm && imm == 0) { |
| 4765 | switch (cond) { |
| 4766 | case kCondEQ: |
| 4767 | case kCondBE: // <= 0 if zero |
| 4768 | __ Or(dst, lhs_high, lhs_low); |
| 4769 | __ Sltiu(dst, dst, 1); |
| 4770 | break; |
| 4771 | case kCondNE: |
| 4772 | case kCondA: // > 0 if non-zero |
| 4773 | __ Or(dst, lhs_high, lhs_low); |
| 4774 | __ Sltu(dst, ZERO, dst); |
| 4775 | break; |
| 4776 | case kCondLT: |
| 4777 | __ Slt(dst, lhs_high, ZERO); |
| 4778 | break; |
| 4779 | case kCondGE: |
| 4780 | __ Slt(dst, lhs_high, ZERO); |
| 4781 | __ Xori(dst, dst, 1); |
| 4782 | break; |
| 4783 | case kCondLE: |
| 4784 | __ Or(TMP, lhs_high, lhs_low); |
| 4785 | __ Sra(AT, lhs_high, 31); |
| 4786 | __ Sltu(dst, AT, TMP); |
| 4787 | __ Xori(dst, dst, 1); |
| 4788 | break; |
| 4789 | case kCondGT: |
| 4790 | __ Or(TMP, lhs_high, lhs_low); |
| 4791 | __ Sra(AT, lhs_high, 31); |
| 4792 | __ Sltu(dst, AT, TMP); |
| 4793 | break; |
| 4794 | case kCondB: // always false |
| 4795 | __ Andi(dst, dst, 0); |
| 4796 | break; |
| 4797 | case kCondAE: // always true |
| 4798 | __ Ori(dst, ZERO, 1); |
| 4799 | break; |
| 4800 | } |
| 4801 | } else if (use_imm) { |
| 4802 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 4803 | switch (cond) { |
| 4804 | case kCondEQ: |
| 4805 | __ LoadConst32(TMP, imm_high); |
| 4806 | __ Xor(TMP, TMP, lhs_high); |
| 4807 | __ LoadConst32(AT, imm_low); |
| 4808 | __ Xor(AT, AT, lhs_low); |
| 4809 | __ Or(dst, TMP, AT); |
| 4810 | __ Sltiu(dst, dst, 1); |
| 4811 | break; |
| 4812 | case kCondNE: |
| 4813 | __ LoadConst32(TMP, imm_high); |
| 4814 | __ Xor(TMP, TMP, lhs_high); |
| 4815 | __ LoadConst32(AT, imm_low); |
| 4816 | __ Xor(AT, AT, lhs_low); |
| 4817 | __ Or(dst, TMP, AT); |
| 4818 | __ Sltu(dst, ZERO, dst); |
| 4819 | break; |
| 4820 | case kCondLT: |
| 4821 | case kCondGE: |
| 4822 | if (dst == lhs_low) { |
| 4823 | __ LoadConst32(TMP, imm_low); |
| 4824 | __ Sltu(dst, lhs_low, TMP); |
| 4825 | } |
| 4826 | __ LoadConst32(TMP, imm_high); |
| 4827 | __ Slt(AT, lhs_high, TMP); |
| 4828 | __ Slt(TMP, TMP, lhs_high); |
| 4829 | if (dst != lhs_low) { |
| 4830 | __ LoadConst32(dst, imm_low); |
| 4831 | __ Sltu(dst, lhs_low, dst); |
| 4832 | } |
| 4833 | __ Slt(dst, TMP, dst); |
| 4834 | __ Or(dst, dst, AT); |
| 4835 | if (cond == kCondGE) { |
| 4836 | __ Xori(dst, dst, 1); |
| 4837 | } |
| 4838 | break; |
| 4839 | case kCondGT: |
| 4840 | case kCondLE: |
| 4841 | if (dst == lhs_low) { |
| 4842 | __ LoadConst32(TMP, imm_low); |
| 4843 | __ Sltu(dst, TMP, lhs_low); |
| 4844 | } |
| 4845 | __ LoadConst32(TMP, imm_high); |
| 4846 | __ Slt(AT, TMP, lhs_high); |
| 4847 | __ Slt(TMP, lhs_high, TMP); |
| 4848 | if (dst != lhs_low) { |
| 4849 | __ LoadConst32(dst, imm_low); |
| 4850 | __ Sltu(dst, dst, lhs_low); |
| 4851 | } |
| 4852 | __ Slt(dst, TMP, dst); |
| 4853 | __ Or(dst, dst, AT); |
| 4854 | if (cond == kCondLE) { |
| 4855 | __ Xori(dst, dst, 1); |
| 4856 | } |
| 4857 | break; |
| 4858 | case kCondB: |
| 4859 | case kCondAE: |
| 4860 | if (dst == lhs_low) { |
| 4861 | __ LoadConst32(TMP, imm_low); |
| 4862 | __ Sltu(dst, lhs_low, TMP); |
| 4863 | } |
| 4864 | __ LoadConst32(TMP, imm_high); |
| 4865 | __ Sltu(AT, lhs_high, TMP); |
| 4866 | __ Sltu(TMP, TMP, lhs_high); |
| 4867 | if (dst != lhs_low) { |
| 4868 | __ LoadConst32(dst, imm_low); |
| 4869 | __ Sltu(dst, lhs_low, dst); |
| 4870 | } |
| 4871 | __ Slt(dst, TMP, dst); |
| 4872 | __ Or(dst, dst, AT); |
| 4873 | if (cond == kCondAE) { |
| 4874 | __ Xori(dst, dst, 1); |
| 4875 | } |
| 4876 | break; |
| 4877 | case kCondA: |
| 4878 | case kCondBE: |
| 4879 | if (dst == lhs_low) { |
| 4880 | __ LoadConst32(TMP, imm_low); |
| 4881 | __ Sltu(dst, TMP, lhs_low); |
| 4882 | } |
| 4883 | __ LoadConst32(TMP, imm_high); |
| 4884 | __ Sltu(AT, TMP, lhs_high); |
| 4885 | __ Sltu(TMP, lhs_high, TMP); |
| 4886 | if (dst != lhs_low) { |
| 4887 | __ LoadConst32(dst, imm_low); |
| 4888 | __ Sltu(dst, dst, lhs_low); |
| 4889 | } |
| 4890 | __ Slt(dst, TMP, dst); |
| 4891 | __ Or(dst, dst, AT); |
| 4892 | if (cond == kCondBE) { |
| 4893 | __ Xori(dst, dst, 1); |
| 4894 | } |
| 4895 | break; |
| 4896 | } |
| 4897 | } else { |
| 4898 | switch (cond) { |
| 4899 | case kCondEQ: |
| 4900 | __ Xor(TMP, lhs_high, rhs_high); |
| 4901 | __ Xor(AT, lhs_low, rhs_low); |
| 4902 | __ Or(dst, TMP, AT); |
| 4903 | __ Sltiu(dst, dst, 1); |
| 4904 | break; |
| 4905 | case kCondNE: |
| 4906 | __ Xor(TMP, lhs_high, rhs_high); |
| 4907 | __ Xor(AT, lhs_low, rhs_low); |
| 4908 | __ Or(dst, TMP, AT); |
| 4909 | __ Sltu(dst, ZERO, dst); |
| 4910 | break; |
| 4911 | case kCondLT: |
| 4912 | case kCondGE: |
| 4913 | __ Slt(TMP, rhs_high, lhs_high); |
| 4914 | __ Sltu(AT, lhs_low, rhs_low); |
| 4915 | __ Slt(TMP, TMP, AT); |
| 4916 | __ Slt(AT, lhs_high, rhs_high); |
| 4917 | __ Or(dst, AT, TMP); |
| 4918 | if (cond == kCondGE) { |
| 4919 | __ Xori(dst, dst, 1); |
| 4920 | } |
| 4921 | break; |
| 4922 | case kCondGT: |
| 4923 | case kCondLE: |
| 4924 | __ Slt(TMP, lhs_high, rhs_high); |
| 4925 | __ Sltu(AT, rhs_low, lhs_low); |
| 4926 | __ Slt(TMP, TMP, AT); |
| 4927 | __ Slt(AT, rhs_high, lhs_high); |
| 4928 | __ Or(dst, AT, TMP); |
| 4929 | if (cond == kCondLE) { |
| 4930 | __ Xori(dst, dst, 1); |
| 4931 | } |
| 4932 | break; |
| 4933 | case kCondB: |
| 4934 | case kCondAE: |
| 4935 | __ Sltu(TMP, rhs_high, lhs_high); |
| 4936 | __ Sltu(AT, lhs_low, rhs_low); |
| 4937 | __ Slt(TMP, TMP, AT); |
| 4938 | __ Sltu(AT, lhs_high, rhs_high); |
| 4939 | __ Or(dst, AT, TMP); |
| 4940 | if (cond == kCondAE) { |
| 4941 | __ Xori(dst, dst, 1); |
| 4942 | } |
| 4943 | break; |
| 4944 | case kCondA: |
| 4945 | case kCondBE: |
| 4946 | __ Sltu(TMP, lhs_high, rhs_high); |
| 4947 | __ Sltu(AT, rhs_low, lhs_low); |
| 4948 | __ Slt(TMP, TMP, AT); |
| 4949 | __ Sltu(AT, rhs_high, lhs_high); |
| 4950 | __ Or(dst, AT, TMP); |
| 4951 | if (cond == kCondBE) { |
| 4952 | __ Xori(dst, dst, 1); |
| 4953 | } |
| 4954 | break; |
| 4955 | } |
| 4956 | } |
| 4957 | } |
| 4958 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4959 | void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond, |
| 4960 | LocationSummary* locations, |
| 4961 | MipsLabel* label) { |
| 4962 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4963 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4964 | Location rhs_location = locations->InAt(1); |
| 4965 | Register rhs_high = ZERO; |
| 4966 | Register rhs_low = ZERO; |
| 4967 | int64_t imm = 0; |
| 4968 | uint32_t imm_high = 0; |
| 4969 | uint32_t imm_low = 0; |
| 4970 | bool use_imm = rhs_location.IsConstant(); |
| 4971 | if (use_imm) { |
| 4972 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 4973 | imm_high = High32Bits(imm); |
| 4974 | imm_low = Low32Bits(imm); |
| 4975 | } else { |
| 4976 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 4977 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 4978 | } |
| 4979 | |
| 4980 | if (use_imm && imm == 0) { |
| 4981 | switch (cond) { |
| 4982 | case kCondEQ: |
| 4983 | case kCondBE: // <= 0 if zero |
| 4984 | __ Or(TMP, lhs_high, lhs_low); |
| 4985 | __ Beqz(TMP, label); |
| 4986 | break; |
| 4987 | case kCondNE: |
| 4988 | case kCondA: // > 0 if non-zero |
| 4989 | __ Or(TMP, lhs_high, lhs_low); |
| 4990 | __ Bnez(TMP, label); |
| 4991 | break; |
| 4992 | case kCondLT: |
| 4993 | __ Bltz(lhs_high, label); |
| 4994 | break; |
| 4995 | case kCondGE: |
| 4996 | __ Bgez(lhs_high, label); |
| 4997 | break; |
| 4998 | case kCondLE: |
| 4999 | __ Or(TMP, lhs_high, lhs_low); |
| 5000 | __ Sra(AT, lhs_high, 31); |
| 5001 | __ Bgeu(AT, TMP, label); |
| 5002 | break; |
| 5003 | case kCondGT: |
| 5004 | __ Or(TMP, lhs_high, lhs_low); |
| 5005 | __ Sra(AT, lhs_high, 31); |
| 5006 | __ Bltu(AT, TMP, label); |
| 5007 | break; |
| 5008 | case kCondB: // always false |
| 5009 | break; |
| 5010 | case kCondAE: // always true |
| 5011 | __ B(label); |
| 5012 | break; |
| 5013 | } |
| 5014 | } else if (use_imm) { |
| 5015 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 5016 | switch (cond) { |
| 5017 | case kCondEQ: |
| 5018 | __ LoadConst32(TMP, imm_high); |
| 5019 | __ Xor(TMP, TMP, lhs_high); |
| 5020 | __ LoadConst32(AT, imm_low); |
| 5021 | __ Xor(AT, AT, lhs_low); |
| 5022 | __ Or(TMP, TMP, AT); |
| 5023 | __ Beqz(TMP, label); |
| 5024 | break; |
| 5025 | case kCondNE: |
| 5026 | __ LoadConst32(TMP, imm_high); |
| 5027 | __ Xor(TMP, TMP, lhs_high); |
| 5028 | __ LoadConst32(AT, imm_low); |
| 5029 | __ Xor(AT, AT, lhs_low); |
| 5030 | __ Or(TMP, TMP, AT); |
| 5031 | __ Bnez(TMP, label); |
| 5032 | break; |
| 5033 | case kCondLT: |
| 5034 | __ LoadConst32(TMP, imm_high); |
| 5035 | __ Blt(lhs_high, TMP, label); |
| 5036 | __ Slt(TMP, TMP, lhs_high); |
| 5037 | __ LoadConst32(AT, imm_low); |
| 5038 | __ Sltu(AT, lhs_low, AT); |
| 5039 | __ Blt(TMP, AT, label); |
| 5040 | break; |
| 5041 | case kCondGE: |
| 5042 | __ LoadConst32(TMP, imm_high); |
| 5043 | __ Blt(TMP, lhs_high, label); |
| 5044 | __ Slt(TMP, lhs_high, TMP); |
| 5045 | __ LoadConst32(AT, imm_low); |
| 5046 | __ Sltu(AT, lhs_low, AT); |
| 5047 | __ Or(TMP, TMP, AT); |
| 5048 | __ Beqz(TMP, label); |
| 5049 | break; |
| 5050 | case kCondLE: |
| 5051 | __ LoadConst32(TMP, imm_high); |
| 5052 | __ Blt(lhs_high, TMP, label); |
| 5053 | __ Slt(TMP, TMP, lhs_high); |
| 5054 | __ LoadConst32(AT, imm_low); |
| 5055 | __ Sltu(AT, AT, lhs_low); |
| 5056 | __ Or(TMP, TMP, AT); |
| 5057 | __ Beqz(TMP, label); |
| 5058 | break; |
| 5059 | case kCondGT: |
| 5060 | __ LoadConst32(TMP, imm_high); |
| 5061 | __ Blt(TMP, lhs_high, label); |
| 5062 | __ Slt(TMP, lhs_high, TMP); |
| 5063 | __ LoadConst32(AT, imm_low); |
| 5064 | __ Sltu(AT, AT, lhs_low); |
| 5065 | __ Blt(TMP, AT, label); |
| 5066 | break; |
| 5067 | case kCondB: |
| 5068 | __ LoadConst32(TMP, imm_high); |
| 5069 | __ Bltu(lhs_high, TMP, label); |
| 5070 | __ Sltu(TMP, TMP, lhs_high); |
| 5071 | __ LoadConst32(AT, imm_low); |
| 5072 | __ Sltu(AT, lhs_low, AT); |
| 5073 | __ Blt(TMP, AT, label); |
| 5074 | break; |
| 5075 | case kCondAE: |
| 5076 | __ LoadConst32(TMP, imm_high); |
| 5077 | __ Bltu(TMP, lhs_high, label); |
| 5078 | __ Sltu(TMP, lhs_high, TMP); |
| 5079 | __ LoadConst32(AT, imm_low); |
| 5080 | __ Sltu(AT, lhs_low, AT); |
| 5081 | __ Or(TMP, TMP, AT); |
| 5082 | __ Beqz(TMP, label); |
| 5083 | break; |
| 5084 | case kCondBE: |
| 5085 | __ LoadConst32(TMP, imm_high); |
| 5086 | __ Bltu(lhs_high, TMP, label); |
| 5087 | __ Sltu(TMP, TMP, lhs_high); |
| 5088 | __ LoadConst32(AT, imm_low); |
| 5089 | __ Sltu(AT, AT, lhs_low); |
| 5090 | __ Or(TMP, TMP, AT); |
| 5091 | __ Beqz(TMP, label); |
| 5092 | break; |
| 5093 | case kCondA: |
| 5094 | __ LoadConst32(TMP, imm_high); |
| 5095 | __ Bltu(TMP, lhs_high, label); |
| 5096 | __ Sltu(TMP, lhs_high, TMP); |
| 5097 | __ LoadConst32(AT, imm_low); |
| 5098 | __ Sltu(AT, AT, lhs_low); |
| 5099 | __ Blt(TMP, AT, label); |
| 5100 | break; |
| 5101 | } |
| 5102 | } else { |
| 5103 | switch (cond) { |
| 5104 | case kCondEQ: |
| 5105 | __ Xor(TMP, lhs_high, rhs_high); |
| 5106 | __ Xor(AT, lhs_low, rhs_low); |
| 5107 | __ Or(TMP, TMP, AT); |
| 5108 | __ Beqz(TMP, label); |
| 5109 | break; |
| 5110 | case kCondNE: |
| 5111 | __ Xor(TMP, lhs_high, rhs_high); |
| 5112 | __ Xor(AT, lhs_low, rhs_low); |
| 5113 | __ Or(TMP, TMP, AT); |
| 5114 | __ Bnez(TMP, label); |
| 5115 | break; |
| 5116 | case kCondLT: |
| 5117 | __ Blt(lhs_high, rhs_high, label); |
| 5118 | __ Slt(TMP, rhs_high, lhs_high); |
| 5119 | __ Sltu(AT, lhs_low, rhs_low); |
| 5120 | __ Blt(TMP, AT, label); |
| 5121 | break; |
| 5122 | case kCondGE: |
| 5123 | __ Blt(rhs_high, lhs_high, label); |
| 5124 | __ Slt(TMP, lhs_high, rhs_high); |
| 5125 | __ Sltu(AT, lhs_low, rhs_low); |
| 5126 | __ Or(TMP, TMP, AT); |
| 5127 | __ Beqz(TMP, label); |
| 5128 | break; |
| 5129 | case kCondLE: |
| 5130 | __ Blt(lhs_high, rhs_high, label); |
| 5131 | __ Slt(TMP, rhs_high, lhs_high); |
| 5132 | __ Sltu(AT, rhs_low, lhs_low); |
| 5133 | __ Or(TMP, TMP, AT); |
| 5134 | __ Beqz(TMP, label); |
| 5135 | break; |
| 5136 | case kCondGT: |
| 5137 | __ Blt(rhs_high, lhs_high, label); |
| 5138 | __ Slt(TMP, lhs_high, rhs_high); |
| 5139 | __ Sltu(AT, rhs_low, lhs_low); |
| 5140 | __ Blt(TMP, AT, label); |
| 5141 | break; |
| 5142 | case kCondB: |
| 5143 | __ Bltu(lhs_high, rhs_high, label); |
| 5144 | __ Sltu(TMP, rhs_high, lhs_high); |
| 5145 | __ Sltu(AT, lhs_low, rhs_low); |
| 5146 | __ Blt(TMP, AT, label); |
| 5147 | break; |
| 5148 | case kCondAE: |
| 5149 | __ Bltu(rhs_high, lhs_high, label); |
| 5150 | __ Sltu(TMP, lhs_high, rhs_high); |
| 5151 | __ Sltu(AT, lhs_low, rhs_low); |
| 5152 | __ Or(TMP, TMP, AT); |
| 5153 | __ Beqz(TMP, label); |
| 5154 | break; |
| 5155 | case kCondBE: |
| 5156 | __ Bltu(lhs_high, rhs_high, label); |
| 5157 | __ Sltu(TMP, rhs_high, lhs_high); |
| 5158 | __ Sltu(AT, rhs_low, lhs_low); |
| 5159 | __ Or(TMP, TMP, AT); |
| 5160 | __ Beqz(TMP, label); |
| 5161 | break; |
| 5162 | case kCondA: |
| 5163 | __ Bltu(rhs_high, lhs_high, label); |
| 5164 | __ Sltu(TMP, lhs_high, rhs_high); |
| 5165 | __ Sltu(AT, rhs_low, lhs_low); |
| 5166 | __ Blt(TMP, AT, label); |
| 5167 | break; |
| 5168 | } |
| 5169 | } |
| 5170 | } |
| 5171 | |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5172 | void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond, |
| 5173 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5174 | DataType::Type type, |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5175 | LocationSummary* locations) { |
| 5176 | Register dst = locations->Out().AsRegister<Register>(); |
| 5177 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5178 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5179 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5180 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5181 | if (isR6) { |
| 5182 | switch (cond) { |
| 5183 | case kCondEQ: |
| 5184 | __ CmpEqS(FTMP, lhs, rhs); |
| 5185 | __ Mfc1(dst, FTMP); |
| 5186 | __ Andi(dst, dst, 1); |
| 5187 | break; |
| 5188 | case kCondNE: |
| 5189 | __ CmpEqS(FTMP, lhs, rhs); |
| 5190 | __ Mfc1(dst, FTMP); |
| 5191 | __ Addiu(dst, dst, 1); |
| 5192 | break; |
| 5193 | case kCondLT: |
| 5194 | if (gt_bias) { |
| 5195 | __ CmpLtS(FTMP, lhs, rhs); |
| 5196 | } else { |
| 5197 | __ CmpUltS(FTMP, lhs, rhs); |
| 5198 | } |
| 5199 | __ Mfc1(dst, FTMP); |
| 5200 | __ Andi(dst, dst, 1); |
| 5201 | break; |
| 5202 | case kCondLE: |
| 5203 | if (gt_bias) { |
| 5204 | __ CmpLeS(FTMP, lhs, rhs); |
| 5205 | } else { |
| 5206 | __ CmpUleS(FTMP, lhs, rhs); |
| 5207 | } |
| 5208 | __ Mfc1(dst, FTMP); |
| 5209 | __ Andi(dst, dst, 1); |
| 5210 | break; |
| 5211 | case kCondGT: |
| 5212 | if (gt_bias) { |
| 5213 | __ CmpUltS(FTMP, rhs, lhs); |
| 5214 | } else { |
| 5215 | __ CmpLtS(FTMP, rhs, lhs); |
| 5216 | } |
| 5217 | __ Mfc1(dst, FTMP); |
| 5218 | __ Andi(dst, dst, 1); |
| 5219 | break; |
| 5220 | case kCondGE: |
| 5221 | if (gt_bias) { |
| 5222 | __ CmpUleS(FTMP, rhs, lhs); |
| 5223 | } else { |
| 5224 | __ CmpLeS(FTMP, rhs, lhs); |
| 5225 | } |
| 5226 | __ Mfc1(dst, FTMP); |
| 5227 | __ Andi(dst, dst, 1); |
| 5228 | break; |
| 5229 | default: |
| 5230 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5231 | UNREACHABLE(); |
| 5232 | } |
| 5233 | } else { |
| 5234 | switch (cond) { |
| 5235 | case kCondEQ: |
| 5236 | __ CeqS(0, lhs, rhs); |
| 5237 | __ LoadConst32(dst, 1); |
| 5238 | __ Movf(dst, ZERO, 0); |
| 5239 | break; |
| 5240 | case kCondNE: |
| 5241 | __ CeqS(0, lhs, rhs); |
| 5242 | __ LoadConst32(dst, 1); |
| 5243 | __ Movt(dst, ZERO, 0); |
| 5244 | break; |
| 5245 | case kCondLT: |
| 5246 | if (gt_bias) { |
| 5247 | __ ColtS(0, lhs, rhs); |
| 5248 | } else { |
| 5249 | __ CultS(0, lhs, rhs); |
| 5250 | } |
| 5251 | __ LoadConst32(dst, 1); |
| 5252 | __ Movf(dst, ZERO, 0); |
| 5253 | break; |
| 5254 | case kCondLE: |
| 5255 | if (gt_bias) { |
| 5256 | __ ColeS(0, lhs, rhs); |
| 5257 | } else { |
| 5258 | __ CuleS(0, lhs, rhs); |
| 5259 | } |
| 5260 | __ LoadConst32(dst, 1); |
| 5261 | __ Movf(dst, ZERO, 0); |
| 5262 | break; |
| 5263 | case kCondGT: |
| 5264 | if (gt_bias) { |
| 5265 | __ CultS(0, rhs, lhs); |
| 5266 | } else { |
| 5267 | __ ColtS(0, rhs, lhs); |
| 5268 | } |
| 5269 | __ LoadConst32(dst, 1); |
| 5270 | __ Movf(dst, ZERO, 0); |
| 5271 | break; |
| 5272 | case kCondGE: |
| 5273 | if (gt_bias) { |
| 5274 | __ CuleS(0, rhs, lhs); |
| 5275 | } else { |
| 5276 | __ ColeS(0, rhs, lhs); |
| 5277 | } |
| 5278 | __ LoadConst32(dst, 1); |
| 5279 | __ Movf(dst, ZERO, 0); |
| 5280 | break; |
| 5281 | default: |
| 5282 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5283 | UNREACHABLE(); |
| 5284 | } |
| 5285 | } |
| 5286 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5287 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5288 | if (isR6) { |
| 5289 | switch (cond) { |
| 5290 | case kCondEQ: |
| 5291 | __ CmpEqD(FTMP, lhs, rhs); |
| 5292 | __ Mfc1(dst, FTMP); |
| 5293 | __ Andi(dst, dst, 1); |
| 5294 | break; |
| 5295 | case kCondNE: |
| 5296 | __ CmpEqD(FTMP, lhs, rhs); |
| 5297 | __ Mfc1(dst, FTMP); |
| 5298 | __ Addiu(dst, dst, 1); |
| 5299 | break; |
| 5300 | case kCondLT: |
| 5301 | if (gt_bias) { |
| 5302 | __ CmpLtD(FTMP, lhs, rhs); |
| 5303 | } else { |
| 5304 | __ CmpUltD(FTMP, lhs, rhs); |
| 5305 | } |
| 5306 | __ Mfc1(dst, FTMP); |
| 5307 | __ Andi(dst, dst, 1); |
| 5308 | break; |
| 5309 | case kCondLE: |
| 5310 | if (gt_bias) { |
| 5311 | __ CmpLeD(FTMP, lhs, rhs); |
| 5312 | } else { |
| 5313 | __ CmpUleD(FTMP, lhs, rhs); |
| 5314 | } |
| 5315 | __ Mfc1(dst, FTMP); |
| 5316 | __ Andi(dst, dst, 1); |
| 5317 | break; |
| 5318 | case kCondGT: |
| 5319 | if (gt_bias) { |
| 5320 | __ CmpUltD(FTMP, rhs, lhs); |
| 5321 | } else { |
| 5322 | __ CmpLtD(FTMP, rhs, lhs); |
| 5323 | } |
| 5324 | __ Mfc1(dst, FTMP); |
| 5325 | __ Andi(dst, dst, 1); |
| 5326 | break; |
| 5327 | case kCondGE: |
| 5328 | if (gt_bias) { |
| 5329 | __ CmpUleD(FTMP, rhs, lhs); |
| 5330 | } else { |
| 5331 | __ CmpLeD(FTMP, rhs, lhs); |
| 5332 | } |
| 5333 | __ Mfc1(dst, FTMP); |
| 5334 | __ Andi(dst, dst, 1); |
| 5335 | break; |
| 5336 | default: |
| 5337 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5338 | UNREACHABLE(); |
| 5339 | } |
| 5340 | } else { |
| 5341 | switch (cond) { |
| 5342 | case kCondEQ: |
| 5343 | __ CeqD(0, lhs, rhs); |
| 5344 | __ LoadConst32(dst, 1); |
| 5345 | __ Movf(dst, ZERO, 0); |
| 5346 | break; |
| 5347 | case kCondNE: |
| 5348 | __ CeqD(0, lhs, rhs); |
| 5349 | __ LoadConst32(dst, 1); |
| 5350 | __ Movt(dst, ZERO, 0); |
| 5351 | break; |
| 5352 | case kCondLT: |
| 5353 | if (gt_bias) { |
| 5354 | __ ColtD(0, lhs, rhs); |
| 5355 | } else { |
| 5356 | __ CultD(0, lhs, rhs); |
| 5357 | } |
| 5358 | __ LoadConst32(dst, 1); |
| 5359 | __ Movf(dst, ZERO, 0); |
| 5360 | break; |
| 5361 | case kCondLE: |
| 5362 | if (gt_bias) { |
| 5363 | __ ColeD(0, lhs, rhs); |
| 5364 | } else { |
| 5365 | __ CuleD(0, lhs, rhs); |
| 5366 | } |
| 5367 | __ LoadConst32(dst, 1); |
| 5368 | __ Movf(dst, ZERO, 0); |
| 5369 | break; |
| 5370 | case kCondGT: |
| 5371 | if (gt_bias) { |
| 5372 | __ CultD(0, rhs, lhs); |
| 5373 | } else { |
| 5374 | __ ColtD(0, rhs, lhs); |
| 5375 | } |
| 5376 | __ LoadConst32(dst, 1); |
| 5377 | __ Movf(dst, ZERO, 0); |
| 5378 | break; |
| 5379 | case kCondGE: |
| 5380 | if (gt_bias) { |
| 5381 | __ CuleD(0, rhs, lhs); |
| 5382 | } else { |
| 5383 | __ ColeD(0, rhs, lhs); |
| 5384 | } |
| 5385 | __ LoadConst32(dst, 1); |
| 5386 | __ Movf(dst, ZERO, 0); |
| 5387 | break; |
| 5388 | default: |
| 5389 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5390 | UNREACHABLE(); |
| 5391 | } |
| 5392 | } |
| 5393 | } |
| 5394 | } |
| 5395 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5396 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond, |
| 5397 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5398 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5399 | LocationSummary* input_locations, |
| 5400 | int cc) { |
| 5401 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5402 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5403 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5404 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5405 | switch (cond) { |
| 5406 | case kCondEQ: |
| 5407 | __ CeqS(cc, lhs, rhs); |
| 5408 | return false; |
| 5409 | case kCondNE: |
| 5410 | __ CeqS(cc, lhs, rhs); |
| 5411 | return true; |
| 5412 | case kCondLT: |
| 5413 | if (gt_bias) { |
| 5414 | __ ColtS(cc, lhs, rhs); |
| 5415 | } else { |
| 5416 | __ CultS(cc, lhs, rhs); |
| 5417 | } |
| 5418 | return false; |
| 5419 | case kCondLE: |
| 5420 | if (gt_bias) { |
| 5421 | __ ColeS(cc, lhs, rhs); |
| 5422 | } else { |
| 5423 | __ CuleS(cc, lhs, rhs); |
| 5424 | } |
| 5425 | return false; |
| 5426 | case kCondGT: |
| 5427 | if (gt_bias) { |
| 5428 | __ CultS(cc, rhs, lhs); |
| 5429 | } else { |
| 5430 | __ ColtS(cc, rhs, lhs); |
| 5431 | } |
| 5432 | return false; |
| 5433 | case kCondGE: |
| 5434 | if (gt_bias) { |
| 5435 | __ CuleS(cc, rhs, lhs); |
| 5436 | } else { |
| 5437 | __ ColeS(cc, rhs, lhs); |
| 5438 | } |
| 5439 | return false; |
| 5440 | default: |
| 5441 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5442 | UNREACHABLE(); |
| 5443 | } |
| 5444 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5445 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5446 | switch (cond) { |
| 5447 | case kCondEQ: |
| 5448 | __ CeqD(cc, lhs, rhs); |
| 5449 | return false; |
| 5450 | case kCondNE: |
| 5451 | __ CeqD(cc, lhs, rhs); |
| 5452 | return true; |
| 5453 | case kCondLT: |
| 5454 | if (gt_bias) { |
| 5455 | __ ColtD(cc, lhs, rhs); |
| 5456 | } else { |
| 5457 | __ CultD(cc, lhs, rhs); |
| 5458 | } |
| 5459 | return false; |
| 5460 | case kCondLE: |
| 5461 | if (gt_bias) { |
| 5462 | __ ColeD(cc, lhs, rhs); |
| 5463 | } else { |
| 5464 | __ CuleD(cc, lhs, rhs); |
| 5465 | } |
| 5466 | return false; |
| 5467 | case kCondGT: |
| 5468 | if (gt_bias) { |
| 5469 | __ CultD(cc, rhs, lhs); |
| 5470 | } else { |
| 5471 | __ ColtD(cc, rhs, lhs); |
| 5472 | } |
| 5473 | return false; |
| 5474 | case kCondGE: |
| 5475 | if (gt_bias) { |
| 5476 | __ CuleD(cc, rhs, lhs); |
| 5477 | } else { |
| 5478 | __ ColeD(cc, rhs, lhs); |
| 5479 | } |
| 5480 | return false; |
| 5481 | default: |
| 5482 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5483 | UNREACHABLE(); |
| 5484 | } |
| 5485 | } |
| 5486 | } |
| 5487 | |
| 5488 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond, |
| 5489 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5490 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5491 | LocationSummary* input_locations, |
| 5492 | FRegister dst) { |
| 5493 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5494 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5495 | CHECK(codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5496 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5497 | switch (cond) { |
| 5498 | case kCondEQ: |
| 5499 | __ CmpEqS(dst, lhs, rhs); |
| 5500 | return false; |
| 5501 | case kCondNE: |
| 5502 | __ CmpEqS(dst, lhs, rhs); |
| 5503 | return true; |
| 5504 | case kCondLT: |
| 5505 | if (gt_bias) { |
| 5506 | __ CmpLtS(dst, lhs, rhs); |
| 5507 | } else { |
| 5508 | __ CmpUltS(dst, lhs, rhs); |
| 5509 | } |
| 5510 | return false; |
| 5511 | case kCondLE: |
| 5512 | if (gt_bias) { |
| 5513 | __ CmpLeS(dst, lhs, rhs); |
| 5514 | } else { |
| 5515 | __ CmpUleS(dst, lhs, rhs); |
| 5516 | } |
| 5517 | return false; |
| 5518 | case kCondGT: |
| 5519 | if (gt_bias) { |
| 5520 | __ CmpUltS(dst, rhs, lhs); |
| 5521 | } else { |
| 5522 | __ CmpLtS(dst, rhs, lhs); |
| 5523 | } |
| 5524 | return false; |
| 5525 | case kCondGE: |
| 5526 | if (gt_bias) { |
| 5527 | __ CmpUleS(dst, rhs, lhs); |
| 5528 | } else { |
| 5529 | __ CmpLeS(dst, rhs, lhs); |
| 5530 | } |
| 5531 | return false; |
| 5532 | default: |
| 5533 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5534 | UNREACHABLE(); |
| 5535 | } |
| 5536 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5537 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5538 | switch (cond) { |
| 5539 | case kCondEQ: |
| 5540 | __ CmpEqD(dst, lhs, rhs); |
| 5541 | return false; |
| 5542 | case kCondNE: |
| 5543 | __ CmpEqD(dst, lhs, rhs); |
| 5544 | return true; |
| 5545 | case kCondLT: |
| 5546 | if (gt_bias) { |
| 5547 | __ CmpLtD(dst, lhs, rhs); |
| 5548 | } else { |
| 5549 | __ CmpUltD(dst, lhs, rhs); |
| 5550 | } |
| 5551 | return false; |
| 5552 | case kCondLE: |
| 5553 | if (gt_bias) { |
| 5554 | __ CmpLeD(dst, lhs, rhs); |
| 5555 | } else { |
| 5556 | __ CmpUleD(dst, lhs, rhs); |
| 5557 | } |
| 5558 | return false; |
| 5559 | case kCondGT: |
| 5560 | if (gt_bias) { |
| 5561 | __ CmpUltD(dst, rhs, lhs); |
| 5562 | } else { |
| 5563 | __ CmpLtD(dst, rhs, lhs); |
| 5564 | } |
| 5565 | return false; |
| 5566 | case kCondGE: |
| 5567 | if (gt_bias) { |
| 5568 | __ CmpUleD(dst, rhs, lhs); |
| 5569 | } else { |
| 5570 | __ CmpLeD(dst, rhs, lhs); |
| 5571 | } |
| 5572 | return false; |
| 5573 | default: |
| 5574 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5575 | UNREACHABLE(); |
| 5576 | } |
| 5577 | } |
| 5578 | } |
| 5579 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5580 | void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond, |
| 5581 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5582 | DataType::Type type, |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5583 | LocationSummary* locations, |
| 5584 | MipsLabel* label) { |
| 5585 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5586 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5587 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5588 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5589 | if (isR6) { |
| 5590 | switch (cond) { |
| 5591 | case kCondEQ: |
| 5592 | __ CmpEqS(FTMP, lhs, rhs); |
| 5593 | __ Bc1nez(FTMP, label); |
| 5594 | break; |
| 5595 | case kCondNE: |
| 5596 | __ CmpEqS(FTMP, lhs, rhs); |
| 5597 | __ Bc1eqz(FTMP, label); |
| 5598 | break; |
| 5599 | case kCondLT: |
| 5600 | if (gt_bias) { |
| 5601 | __ CmpLtS(FTMP, lhs, rhs); |
| 5602 | } else { |
| 5603 | __ CmpUltS(FTMP, lhs, rhs); |
| 5604 | } |
| 5605 | __ Bc1nez(FTMP, label); |
| 5606 | break; |
| 5607 | case kCondLE: |
| 5608 | if (gt_bias) { |
| 5609 | __ CmpLeS(FTMP, lhs, rhs); |
| 5610 | } else { |
| 5611 | __ CmpUleS(FTMP, lhs, rhs); |
| 5612 | } |
| 5613 | __ Bc1nez(FTMP, label); |
| 5614 | break; |
| 5615 | case kCondGT: |
| 5616 | if (gt_bias) { |
| 5617 | __ CmpUltS(FTMP, rhs, lhs); |
| 5618 | } else { |
| 5619 | __ CmpLtS(FTMP, rhs, lhs); |
| 5620 | } |
| 5621 | __ Bc1nez(FTMP, label); |
| 5622 | break; |
| 5623 | case kCondGE: |
| 5624 | if (gt_bias) { |
| 5625 | __ CmpUleS(FTMP, rhs, lhs); |
| 5626 | } else { |
| 5627 | __ CmpLeS(FTMP, rhs, lhs); |
| 5628 | } |
| 5629 | __ Bc1nez(FTMP, label); |
| 5630 | break; |
| 5631 | default: |
| 5632 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5633 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5634 | } |
| 5635 | } else { |
| 5636 | switch (cond) { |
| 5637 | case kCondEQ: |
| 5638 | __ CeqS(0, lhs, rhs); |
| 5639 | __ Bc1t(0, label); |
| 5640 | break; |
| 5641 | case kCondNE: |
| 5642 | __ CeqS(0, lhs, rhs); |
| 5643 | __ Bc1f(0, label); |
| 5644 | break; |
| 5645 | case kCondLT: |
| 5646 | if (gt_bias) { |
| 5647 | __ ColtS(0, lhs, rhs); |
| 5648 | } else { |
| 5649 | __ CultS(0, lhs, rhs); |
| 5650 | } |
| 5651 | __ Bc1t(0, label); |
| 5652 | break; |
| 5653 | case kCondLE: |
| 5654 | if (gt_bias) { |
| 5655 | __ ColeS(0, lhs, rhs); |
| 5656 | } else { |
| 5657 | __ CuleS(0, lhs, rhs); |
| 5658 | } |
| 5659 | __ Bc1t(0, label); |
| 5660 | break; |
| 5661 | case kCondGT: |
| 5662 | if (gt_bias) { |
| 5663 | __ CultS(0, rhs, lhs); |
| 5664 | } else { |
| 5665 | __ ColtS(0, rhs, lhs); |
| 5666 | } |
| 5667 | __ Bc1t(0, label); |
| 5668 | break; |
| 5669 | case kCondGE: |
| 5670 | if (gt_bias) { |
| 5671 | __ CuleS(0, rhs, lhs); |
| 5672 | } else { |
| 5673 | __ ColeS(0, rhs, lhs); |
| 5674 | } |
| 5675 | __ Bc1t(0, label); |
| 5676 | break; |
| 5677 | default: |
| 5678 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5679 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5680 | } |
| 5681 | } |
| 5682 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5683 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5684 | if (isR6) { |
| 5685 | switch (cond) { |
| 5686 | case kCondEQ: |
| 5687 | __ CmpEqD(FTMP, lhs, rhs); |
| 5688 | __ Bc1nez(FTMP, label); |
| 5689 | break; |
| 5690 | case kCondNE: |
| 5691 | __ CmpEqD(FTMP, lhs, rhs); |
| 5692 | __ Bc1eqz(FTMP, label); |
| 5693 | break; |
| 5694 | case kCondLT: |
| 5695 | if (gt_bias) { |
| 5696 | __ CmpLtD(FTMP, lhs, rhs); |
| 5697 | } else { |
| 5698 | __ CmpUltD(FTMP, lhs, rhs); |
| 5699 | } |
| 5700 | __ Bc1nez(FTMP, label); |
| 5701 | break; |
| 5702 | case kCondLE: |
| 5703 | if (gt_bias) { |
| 5704 | __ CmpLeD(FTMP, lhs, rhs); |
| 5705 | } else { |
| 5706 | __ CmpUleD(FTMP, lhs, rhs); |
| 5707 | } |
| 5708 | __ Bc1nez(FTMP, label); |
| 5709 | break; |
| 5710 | case kCondGT: |
| 5711 | if (gt_bias) { |
| 5712 | __ CmpUltD(FTMP, rhs, lhs); |
| 5713 | } else { |
| 5714 | __ CmpLtD(FTMP, rhs, lhs); |
| 5715 | } |
| 5716 | __ Bc1nez(FTMP, label); |
| 5717 | break; |
| 5718 | case kCondGE: |
| 5719 | if (gt_bias) { |
| 5720 | __ CmpUleD(FTMP, rhs, lhs); |
| 5721 | } else { |
| 5722 | __ CmpLeD(FTMP, rhs, lhs); |
| 5723 | } |
| 5724 | __ Bc1nez(FTMP, label); |
| 5725 | break; |
| 5726 | default: |
| 5727 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5728 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5729 | } |
| 5730 | } else { |
| 5731 | switch (cond) { |
| 5732 | case kCondEQ: |
| 5733 | __ CeqD(0, lhs, rhs); |
| 5734 | __ Bc1t(0, label); |
| 5735 | break; |
| 5736 | case kCondNE: |
| 5737 | __ CeqD(0, lhs, rhs); |
| 5738 | __ Bc1f(0, label); |
| 5739 | break; |
| 5740 | case kCondLT: |
| 5741 | if (gt_bias) { |
| 5742 | __ ColtD(0, lhs, rhs); |
| 5743 | } else { |
| 5744 | __ CultD(0, lhs, rhs); |
| 5745 | } |
| 5746 | __ Bc1t(0, label); |
| 5747 | break; |
| 5748 | case kCondLE: |
| 5749 | if (gt_bias) { |
| 5750 | __ ColeD(0, lhs, rhs); |
| 5751 | } else { |
| 5752 | __ CuleD(0, lhs, rhs); |
| 5753 | } |
| 5754 | __ Bc1t(0, label); |
| 5755 | break; |
| 5756 | case kCondGT: |
| 5757 | if (gt_bias) { |
| 5758 | __ CultD(0, rhs, lhs); |
| 5759 | } else { |
| 5760 | __ ColtD(0, rhs, lhs); |
| 5761 | } |
| 5762 | __ Bc1t(0, label); |
| 5763 | break; |
| 5764 | case kCondGE: |
| 5765 | if (gt_bias) { |
| 5766 | __ CuleD(0, rhs, lhs); |
| 5767 | } else { |
| 5768 | __ ColeD(0, rhs, lhs); |
| 5769 | } |
| 5770 | __ Bc1t(0, label); |
| 5771 | break; |
| 5772 | default: |
| 5773 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5774 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5775 | } |
| 5776 | } |
| 5777 | } |
| 5778 | } |
| 5779 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5780 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5781 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5782 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5783 | MipsLabel* false_target) { |
| 5784 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5785 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5786 | if (true_target == nullptr && false_target == nullptr) { |
| 5787 | // Nothing to do. The code always falls through. |
| 5788 | return; |
| 5789 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5790 | // Constant condition, statically compared against "true" (integer value 1). |
| 5791 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5792 | if (true_target != nullptr) { |
| 5793 | __ B(true_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5794 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5795 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5796 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5797 | if (false_target != nullptr) { |
| 5798 | __ B(false_target); |
| 5799 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5800 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5801 | return; |
| 5802 | } |
| 5803 | |
| 5804 | // The following code generates these patterns: |
| 5805 | // (1) true_target == nullptr && false_target != nullptr |
| 5806 | // - opposite condition true => branch to false_target |
| 5807 | // (2) true_target != nullptr && false_target == nullptr |
| 5808 | // - condition true => branch to true_target |
| 5809 | // (3) true_target != nullptr && false_target != nullptr |
| 5810 | // - condition true => branch to true_target |
| 5811 | // - branch to false_target |
| 5812 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5813 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5814 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5815 | DCHECK(cond_val.IsRegister()); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5816 | if (true_target == nullptr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5817 | __ Beqz(cond_val.AsRegister<Register>(), false_target); |
| 5818 | } else { |
| 5819 | __ Bnez(cond_val.AsRegister<Register>(), true_target); |
| 5820 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5821 | } else { |
| 5822 | // The condition instruction has not been materialized, use its inputs as |
| 5823 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5824 | HCondition* condition = cond->AsCondition(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5825 | DataType::Type type = condition->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5826 | LocationSummary* locations = cond->GetLocations(); |
| 5827 | IfCondition if_cond = condition->GetCondition(); |
| 5828 | MipsLabel* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5829 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5830 | if (true_target == nullptr) { |
| 5831 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5832 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5833 | } |
| 5834 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5835 | switch (type) { |
| 5836 | default: |
| 5837 | GenerateIntCompareAndBranch(if_cond, locations, branch_target); |
| 5838 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5839 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5840 | GenerateLongCompareAndBranch(if_cond, locations, branch_target); |
| 5841 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5842 | case DataType::Type::kFloat32: |
| 5843 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5844 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 5845 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5846 | } |
| 5847 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5848 | |
| 5849 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 5850 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 5851 | if (true_target != nullptr && false_target != nullptr) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5852 | __ B(false_target); |
| 5853 | } |
| 5854 | } |
| 5855 | |
| 5856 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5857 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5858 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5859 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5860 | } |
| 5861 | } |
| 5862 | |
| 5863 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5864 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 5865 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 5866 | MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 5867 | nullptr : codegen_->GetLabelOf(true_successor); |
| 5868 | MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 5869 | nullptr : codegen_->GetLabelOf(false_successor); |
| 5870 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5871 | } |
| 5872 | |
| 5873 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5874 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5875 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 5876 | InvokeRuntimeCallingConvention calling_convention; |
| 5877 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5878 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5879 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5880 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5881 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5882 | } |
| 5883 | } |
| 5884 | |
| 5885 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 5886 | SlowPathCodeMIPS* slow_path = |
| 5887 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5888 | GenerateTestAndBranch(deoptimize, |
| 5889 | /* condition_input_index */ 0, |
| 5890 | slow_path->GetEntryLabel(), |
| 5891 | /* false_target */ nullptr); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5892 | } |
| 5893 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5894 | // This function returns true if a conditional move can be generated for HSelect. |
| 5895 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 5896 | // branches and regular moves. |
| 5897 | // |
| 5898 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 5899 | // |
| 5900 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 5901 | // are two distinct tasks, this function does both because they share quite a bit |
| 5902 | // of common logic. |
| 5903 | static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) { |
| 5904 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 5905 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 5906 | HCondition* condition = cond->AsCondition(); |
| 5907 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5908 | DataType::Type cond_type = |
| 5909 | materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType(); |
| 5910 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5911 | |
| 5912 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 5913 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 5914 | bool is_true_value_zero_constant = |
| 5915 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 5916 | bool is_false_value_zero_constant = |
| 5917 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 5918 | |
| 5919 | bool can_move_conditionally = false; |
| 5920 | bool use_const_for_false_in = false; |
| 5921 | bool use_const_for_true_in = false; |
| 5922 | |
| 5923 | if (!cond->IsConstant()) { |
| 5924 | switch (cond_type) { |
| 5925 | default: |
| 5926 | switch (dst_type) { |
| 5927 | default: |
| 5928 | // Moving int on int condition. |
| 5929 | if (is_r6) { |
| 5930 | if (is_true_value_zero_constant) { |
| 5931 | // seleqz out_reg, false_reg, cond_reg |
| 5932 | can_move_conditionally = true; |
| 5933 | use_const_for_true_in = true; |
| 5934 | } else if (is_false_value_zero_constant) { |
| 5935 | // selnez out_reg, true_reg, cond_reg |
| 5936 | can_move_conditionally = true; |
| 5937 | use_const_for_false_in = true; |
| 5938 | } else if (materialized) { |
| 5939 | // Not materializing unmaterialized int conditions |
| 5940 | // to keep the instruction count low. |
| 5941 | // selnez AT, true_reg, cond_reg |
| 5942 | // seleqz TMP, false_reg, cond_reg |
| 5943 | // or out_reg, AT, TMP |
| 5944 | can_move_conditionally = true; |
| 5945 | } |
| 5946 | } else { |
| 5947 | // movn out_reg, true_reg/ZERO, cond_reg |
| 5948 | can_move_conditionally = true; |
| 5949 | use_const_for_true_in = is_true_value_zero_constant; |
| 5950 | } |
| 5951 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5952 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5953 | // Moving long on int condition. |
| 5954 | if (is_r6) { |
| 5955 | if (is_true_value_zero_constant) { |
| 5956 | // seleqz out_reg_lo, false_reg_lo, cond_reg |
| 5957 | // seleqz out_reg_hi, false_reg_hi, cond_reg |
| 5958 | can_move_conditionally = true; |
| 5959 | use_const_for_true_in = true; |
| 5960 | } else if (is_false_value_zero_constant) { |
| 5961 | // selnez out_reg_lo, true_reg_lo, cond_reg |
| 5962 | // selnez out_reg_hi, true_reg_hi, cond_reg |
| 5963 | can_move_conditionally = true; |
| 5964 | use_const_for_false_in = true; |
| 5965 | } |
| 5966 | // Other long conditional moves would generate 6+ instructions, |
| 5967 | // which is too many. |
| 5968 | } else { |
| 5969 | // movn out_reg_lo, true_reg_lo/ZERO, cond_reg |
| 5970 | // movn out_reg_hi, true_reg_hi/ZERO, cond_reg |
| 5971 | can_move_conditionally = true; |
| 5972 | use_const_for_true_in = is_true_value_zero_constant; |
| 5973 | } |
| 5974 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5975 | case DataType::Type::kFloat32: |
| 5976 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5977 | // Moving float/double on int condition. |
| 5978 | if (is_r6) { |
| 5979 | if (materialized) { |
| 5980 | // Not materializing unmaterialized int conditions |
| 5981 | // to keep the instruction count low. |
| 5982 | can_move_conditionally = true; |
| 5983 | if (is_true_value_zero_constant) { |
| 5984 | // sltu TMP, ZERO, cond_reg |
| 5985 | // mtc1 TMP, temp_cond_reg |
| 5986 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 5987 | use_const_for_true_in = true; |
| 5988 | } else if (is_false_value_zero_constant) { |
| 5989 | // sltu TMP, ZERO, cond_reg |
| 5990 | // mtc1 TMP, temp_cond_reg |
| 5991 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 5992 | use_const_for_false_in = true; |
| 5993 | } else { |
| 5994 | // sltu TMP, ZERO, cond_reg |
| 5995 | // mtc1 TMP, temp_cond_reg |
| 5996 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 5997 | // mov.fmt out_reg, temp_cond_reg |
| 5998 | } |
| 5999 | } |
| 6000 | } else { |
| 6001 | // movn.fmt out_reg, true_reg, cond_reg |
| 6002 | can_move_conditionally = true; |
| 6003 | } |
| 6004 | break; |
| 6005 | } |
| 6006 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6007 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6008 | // We don't materialize long comparison now |
| 6009 | // and use conditional branches instead. |
| 6010 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6011 | case DataType::Type::kFloat32: |
| 6012 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6013 | switch (dst_type) { |
| 6014 | default: |
| 6015 | // Moving int on float/double condition. |
| 6016 | if (is_r6) { |
| 6017 | if (is_true_value_zero_constant) { |
| 6018 | // mfc1 TMP, temp_cond_reg |
| 6019 | // seleqz out_reg, false_reg, TMP |
| 6020 | can_move_conditionally = true; |
| 6021 | use_const_for_true_in = true; |
| 6022 | } else if (is_false_value_zero_constant) { |
| 6023 | // mfc1 TMP, temp_cond_reg |
| 6024 | // selnez out_reg, true_reg, TMP |
| 6025 | can_move_conditionally = true; |
| 6026 | use_const_for_false_in = true; |
| 6027 | } else { |
| 6028 | // mfc1 TMP, temp_cond_reg |
| 6029 | // selnez AT, true_reg, TMP |
| 6030 | // seleqz TMP, false_reg, TMP |
| 6031 | // or out_reg, AT, TMP |
| 6032 | can_move_conditionally = true; |
| 6033 | } |
| 6034 | } else { |
| 6035 | // movt out_reg, true_reg/ZERO, cc |
| 6036 | can_move_conditionally = true; |
| 6037 | use_const_for_true_in = is_true_value_zero_constant; |
| 6038 | } |
| 6039 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6040 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6041 | // Moving long on float/double condition. |
| 6042 | if (is_r6) { |
| 6043 | if (is_true_value_zero_constant) { |
| 6044 | // mfc1 TMP, temp_cond_reg |
| 6045 | // seleqz out_reg_lo, false_reg_lo, TMP |
| 6046 | // seleqz out_reg_hi, false_reg_hi, TMP |
| 6047 | can_move_conditionally = true; |
| 6048 | use_const_for_true_in = true; |
| 6049 | } else if (is_false_value_zero_constant) { |
| 6050 | // mfc1 TMP, temp_cond_reg |
| 6051 | // selnez out_reg_lo, true_reg_lo, TMP |
| 6052 | // selnez out_reg_hi, true_reg_hi, TMP |
| 6053 | can_move_conditionally = true; |
| 6054 | use_const_for_false_in = true; |
| 6055 | } |
| 6056 | // Other long conditional moves would generate 6+ instructions, |
| 6057 | // which is too many. |
| 6058 | } else { |
| 6059 | // movt out_reg_lo, true_reg_lo/ZERO, cc |
| 6060 | // movt out_reg_hi, true_reg_hi/ZERO, cc |
| 6061 | can_move_conditionally = true; |
| 6062 | use_const_for_true_in = is_true_value_zero_constant; |
| 6063 | } |
| 6064 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6065 | case DataType::Type::kFloat32: |
| 6066 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6067 | // Moving float/double on float/double condition. |
| 6068 | if (is_r6) { |
| 6069 | can_move_conditionally = true; |
| 6070 | if (is_true_value_zero_constant) { |
| 6071 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 6072 | use_const_for_true_in = true; |
| 6073 | } else if (is_false_value_zero_constant) { |
| 6074 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 6075 | use_const_for_false_in = true; |
| 6076 | } else { |
| 6077 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 6078 | // mov.fmt out_reg, temp_cond_reg |
| 6079 | } |
| 6080 | } else { |
| 6081 | // movt.fmt out_reg, true_reg, cc |
| 6082 | can_move_conditionally = true; |
| 6083 | } |
| 6084 | break; |
| 6085 | } |
| 6086 | break; |
| 6087 | } |
| 6088 | } |
| 6089 | |
| 6090 | if (can_move_conditionally) { |
| 6091 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 6092 | } else { |
| 6093 | DCHECK(!use_const_for_false_in); |
| 6094 | DCHECK(!use_const_for_true_in); |
| 6095 | } |
| 6096 | |
| 6097 | if (locations_to_set != nullptr) { |
| 6098 | if (use_const_for_false_in) { |
| 6099 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 6100 | } else { |
| 6101 | locations_to_set->SetInAt(0, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6102 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6103 | ? Location::RequiresFpuRegister() |
| 6104 | : Location::RequiresRegister()); |
| 6105 | } |
| 6106 | if (use_const_for_true_in) { |
| 6107 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 6108 | } else { |
| 6109 | locations_to_set->SetInAt(1, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6110 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6111 | ? Location::RequiresFpuRegister() |
| 6112 | : Location::RequiresRegister()); |
| 6113 | } |
| 6114 | if (materialized) { |
| 6115 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 6116 | } |
| 6117 | // On R6 we don't require the output to be the same as the |
| 6118 | // first input for conditional moves unlike on R2. |
| 6119 | bool is_out_same_as_first_in = !can_move_conditionally || !is_r6; |
| 6120 | if (is_out_same_as_first_in) { |
| 6121 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 6122 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6123 | locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6124 | ? Location::RequiresFpuRegister() |
| 6125 | : Location::RequiresRegister()); |
| 6126 | } |
| 6127 | } |
| 6128 | |
| 6129 | return can_move_conditionally; |
| 6130 | } |
| 6131 | |
| 6132 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) { |
| 6133 | LocationSummary* locations = select->GetLocations(); |
| 6134 | Location dst = locations->Out(); |
| 6135 | Location src = locations->InAt(1); |
| 6136 | Register src_reg = ZERO; |
| 6137 | Register src_reg_high = ZERO; |
| 6138 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 6139 | Register cond_reg = TMP; |
| 6140 | int cond_cc = 0; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6141 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6142 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6143 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6144 | |
| 6145 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 6146 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 6147 | } else { |
| 6148 | HCondition* condition = cond->AsCondition(); |
| 6149 | LocationSummary* cond_locations = cond->GetLocations(); |
| 6150 | IfCondition if_cond = condition->GetCondition(); |
| 6151 | cond_type = condition->InputAt(0)->GetType(); |
| 6152 | switch (cond_type) { |
| 6153 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6154 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6155 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 6156 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6157 | case DataType::Type::kFloat32: |
| 6158 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6159 | cond_inverted = MaterializeFpCompareR2(if_cond, |
| 6160 | condition->IsGtBias(), |
| 6161 | cond_type, |
| 6162 | cond_locations, |
| 6163 | cond_cc); |
| 6164 | break; |
| 6165 | } |
| 6166 | } |
| 6167 | |
| 6168 | DCHECK(dst.Equals(locations->InAt(0))); |
| 6169 | if (src.IsRegister()) { |
| 6170 | src_reg = src.AsRegister<Register>(); |
| 6171 | } else if (src.IsRegisterPair()) { |
| 6172 | src_reg = src.AsRegisterPairLow<Register>(); |
| 6173 | src_reg_high = src.AsRegisterPairHigh<Register>(); |
| 6174 | } else if (src.IsConstant()) { |
| 6175 | DCHECK(src.GetConstant()->IsZeroBitPattern()); |
| 6176 | } |
| 6177 | |
| 6178 | switch (cond_type) { |
| 6179 | default: |
| 6180 | switch (dst_type) { |
| 6181 | default: |
| 6182 | if (cond_inverted) { |
| 6183 | __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 6184 | } else { |
| 6185 | __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 6186 | } |
| 6187 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6188 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6189 | if (cond_inverted) { |
| 6190 | __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 6191 | __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 6192 | } else { |
| 6193 | __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 6194 | __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 6195 | } |
| 6196 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6197 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6198 | if (cond_inverted) { |
| 6199 | __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6200 | } else { |
| 6201 | __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6202 | } |
| 6203 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6204 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6205 | if (cond_inverted) { |
| 6206 | __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6207 | } else { |
| 6208 | __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6209 | } |
| 6210 | break; |
| 6211 | } |
| 6212 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6213 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6214 | LOG(FATAL) << "Unreachable"; |
| 6215 | UNREACHABLE(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6216 | case DataType::Type::kFloat32: |
| 6217 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6218 | switch (dst_type) { |
| 6219 | default: |
| 6220 | if (cond_inverted) { |
| 6221 | __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 6222 | } else { |
| 6223 | __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 6224 | } |
| 6225 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6226 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6227 | if (cond_inverted) { |
| 6228 | __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 6229 | __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 6230 | } else { |
| 6231 | __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 6232 | __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 6233 | } |
| 6234 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6235 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6236 | if (cond_inverted) { |
| 6237 | __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6238 | } else { |
| 6239 | __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6240 | } |
| 6241 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6242 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6243 | if (cond_inverted) { |
| 6244 | __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6245 | } else { |
| 6246 | __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6247 | } |
| 6248 | break; |
| 6249 | } |
| 6250 | break; |
| 6251 | } |
| 6252 | } |
| 6253 | |
| 6254 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) { |
| 6255 | LocationSummary* locations = select->GetLocations(); |
| 6256 | Location dst = locations->Out(); |
| 6257 | Location false_src = locations->InAt(0); |
| 6258 | Location true_src = locations->InAt(1); |
| 6259 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 6260 | Register cond_reg = TMP; |
| 6261 | FRegister fcond_reg = FTMP; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6262 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6263 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6264 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6265 | |
| 6266 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 6267 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 6268 | } else { |
| 6269 | HCondition* condition = cond->AsCondition(); |
| 6270 | LocationSummary* cond_locations = cond->GetLocations(); |
| 6271 | IfCondition if_cond = condition->GetCondition(); |
| 6272 | cond_type = condition->InputAt(0)->GetType(); |
| 6273 | switch (cond_type) { |
| 6274 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6275 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6276 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 6277 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6278 | case DataType::Type::kFloat32: |
| 6279 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6280 | cond_inverted = MaterializeFpCompareR6(if_cond, |
| 6281 | condition->IsGtBias(), |
| 6282 | cond_type, |
| 6283 | cond_locations, |
| 6284 | fcond_reg); |
| 6285 | break; |
| 6286 | } |
| 6287 | } |
| 6288 | |
| 6289 | if (true_src.IsConstant()) { |
| 6290 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 6291 | } |
| 6292 | if (false_src.IsConstant()) { |
| 6293 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 6294 | } |
| 6295 | |
| 6296 | switch (dst_type) { |
| 6297 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6298 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6299 | __ Mfc1(cond_reg, fcond_reg); |
| 6300 | } |
| 6301 | if (true_src.IsConstant()) { |
| 6302 | if (cond_inverted) { |
| 6303 | __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 6304 | } else { |
| 6305 | __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 6306 | } |
| 6307 | } else if (false_src.IsConstant()) { |
| 6308 | if (cond_inverted) { |
| 6309 | __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 6310 | } else { |
| 6311 | __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 6312 | } |
| 6313 | } else { |
| 6314 | DCHECK_NE(cond_reg, AT); |
| 6315 | if (cond_inverted) { |
| 6316 | __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6317 | __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6318 | } else { |
| 6319 | __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6320 | __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6321 | } |
| 6322 | __ Or(dst.AsRegister<Register>(), AT, TMP); |
| 6323 | } |
| 6324 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6325 | case DataType::Type::kInt64: { |
| 6326 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6327 | __ Mfc1(cond_reg, fcond_reg); |
| 6328 | } |
| 6329 | Register dst_lo = dst.AsRegisterPairLow<Register>(); |
| 6330 | Register dst_hi = dst.AsRegisterPairHigh<Register>(); |
| 6331 | if (true_src.IsConstant()) { |
| 6332 | Register src_lo = false_src.AsRegisterPairLow<Register>(); |
| 6333 | Register src_hi = false_src.AsRegisterPairHigh<Register>(); |
| 6334 | if (cond_inverted) { |
| 6335 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6336 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6337 | } else { |
| 6338 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6339 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6340 | } |
| 6341 | } else { |
| 6342 | DCHECK(false_src.IsConstant()); |
| 6343 | Register src_lo = true_src.AsRegisterPairLow<Register>(); |
| 6344 | Register src_hi = true_src.AsRegisterPairHigh<Register>(); |
| 6345 | if (cond_inverted) { |
| 6346 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6347 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6348 | } else { |
| 6349 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6350 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6351 | } |
| 6352 | } |
| 6353 | break; |
| 6354 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6355 | case DataType::Type::kFloat32: { |
| 6356 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6357 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6358 | __ Sltu(TMP, ZERO, cond_reg); |
| 6359 | __ Mtc1(TMP, fcond_reg); |
| 6360 | } |
| 6361 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6362 | if (true_src.IsConstant()) { |
| 6363 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6364 | if (cond_inverted) { |
| 6365 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6366 | } else { |
| 6367 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6368 | } |
| 6369 | } else if (false_src.IsConstant()) { |
| 6370 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6371 | if (cond_inverted) { |
| 6372 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6373 | } else { |
| 6374 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6375 | } |
| 6376 | } else { |
| 6377 | if (cond_inverted) { |
| 6378 | __ SelS(fcond_reg, |
| 6379 | true_src.AsFpuRegister<FRegister>(), |
| 6380 | false_src.AsFpuRegister<FRegister>()); |
| 6381 | } else { |
| 6382 | __ SelS(fcond_reg, |
| 6383 | false_src.AsFpuRegister<FRegister>(), |
| 6384 | true_src.AsFpuRegister<FRegister>()); |
| 6385 | } |
| 6386 | __ MovS(dst_reg, fcond_reg); |
| 6387 | } |
| 6388 | break; |
| 6389 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6390 | case DataType::Type::kFloat64: { |
| 6391 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6392 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6393 | __ Sltu(TMP, ZERO, cond_reg); |
| 6394 | __ Mtc1(TMP, fcond_reg); |
| 6395 | } |
| 6396 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6397 | if (true_src.IsConstant()) { |
| 6398 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6399 | if (cond_inverted) { |
| 6400 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6401 | } else { |
| 6402 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6403 | } |
| 6404 | } else if (false_src.IsConstant()) { |
| 6405 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6406 | if (cond_inverted) { |
| 6407 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6408 | } else { |
| 6409 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6410 | } |
| 6411 | } else { |
| 6412 | if (cond_inverted) { |
| 6413 | __ SelD(fcond_reg, |
| 6414 | true_src.AsFpuRegister<FRegister>(), |
| 6415 | false_src.AsFpuRegister<FRegister>()); |
| 6416 | } else { |
| 6417 | __ SelD(fcond_reg, |
| 6418 | false_src.AsFpuRegister<FRegister>(), |
| 6419 | true_src.AsFpuRegister<FRegister>()); |
| 6420 | } |
| 6421 | __ MovD(dst_reg, fcond_reg); |
| 6422 | } |
| 6423 | break; |
| 6424 | } |
| 6425 | } |
| 6426 | } |
| 6427 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6428 | void LocationsBuilderMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6429 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6430 | LocationSummary(flag, LocationSummary::kNoCall); |
| 6431 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6432 | } |
| 6433 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6434 | void InstructionCodeGeneratorMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 6435 | __ LoadFromOffset(kLoadWord, |
| 6436 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 6437 | SP, |
| 6438 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6439 | } |
| 6440 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6441 | void LocationsBuilderMIPS::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6442 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6443 | CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6444 | } |
| 6445 | |
| 6446 | void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6447 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 6448 | if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) { |
| 6449 | if (is_r6) { |
| 6450 | GenConditionalMoveR6(select); |
| 6451 | } else { |
| 6452 | GenConditionalMoveR2(select); |
| 6453 | } |
| 6454 | } else { |
| 6455 | LocationSummary* locations = select->GetLocations(); |
| 6456 | MipsLabel false_target; |
| 6457 | GenerateTestAndBranch(select, |
| 6458 | /* condition_input_index */ 2, |
| 6459 | /* true_target */ nullptr, |
| 6460 | &false_target); |
| 6461 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 6462 | __ Bind(&false_target); |
| 6463 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6464 | } |
| 6465 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6466 | void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6467 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6468 | } |
| 6469 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 6470 | void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 6471 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 6472 | } |
| 6473 | |
| 6474 | void CodeGeneratorMIPS::GenerateNop() { |
| 6475 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6476 | } |
| 6477 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6478 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6479 | DataType::Type field_type = field_info.GetFieldType(); |
| 6480 | 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] | 6481 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6482 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6483 | kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6484 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6485 | instruction, |
| 6486 | generate_volatile |
| 6487 | ? LocationSummary::kCallOnMainOnly |
| 6488 | : (object_field_get_with_read_barrier |
| 6489 | ? LocationSummary::kCallOnSlowPath |
| 6490 | : LocationSummary::kNoCall)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6491 | |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6492 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6493 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 6494 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6495 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6496 | if (generate_volatile) { |
| 6497 | InvokeRuntimeCallingConvention calling_convention; |
| 6498 | // need A0 to hold base + offset |
| 6499 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6500 | if (field_type == DataType::Type::kInt64) { |
| 6501 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kInt64)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6502 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6503 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6504 | locations->SetOut(Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6505 | // 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] | 6506 | Location reg = calling_convention.GetReturnLocation(DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6507 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); |
| 6508 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); |
| 6509 | } |
| 6510 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6511 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6512 | locations->SetOut(Location::RequiresFpuRegister()); |
| 6513 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6514 | // The output overlaps in the case of an object field get with |
| 6515 | // read barriers enabled: we do not want the move to overwrite the |
| 6516 | // object's location, as we need it to emit the read barrier. |
| 6517 | locations->SetOut(Location::RequiresRegister(), |
| 6518 | object_field_get_with_read_barrier |
| 6519 | ? Location::kOutputOverlap |
| 6520 | : Location::kNoOutputOverlap); |
| 6521 | } |
| 6522 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6523 | // We need a temporary register for the read barrier marking slow |
| 6524 | // path in CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6525 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6526 | locations->AddTemp(Location::RequiresRegister()); |
| 6527 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6528 | } |
| 6529 | } |
| 6530 | } |
| 6531 | |
| 6532 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, |
| 6533 | const FieldInfo& field_info, |
| 6534 | uint32_t dex_pc) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6535 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 6536 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6537 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6538 | Location obj_loc = locations->InAt(0); |
| 6539 | Register obj = obj_loc.AsRegister<Register>(); |
| 6540 | Location dst_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6541 | LoadOperandType load_type = kLoadUnsignedByte; |
| 6542 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6543 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6544 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6545 | |
| 6546 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6547 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6548 | case DataType::Type::kUint8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6549 | load_type = kLoadUnsignedByte; |
| 6550 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6551 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6552 | load_type = kLoadSignedByte; |
| 6553 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6554 | case DataType::Type::kUint16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6555 | load_type = kLoadUnsignedHalfword; |
| 6556 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6557 | case DataType::Type::kInt16: |
| 6558 | load_type = kLoadSignedHalfword; |
| 6559 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6560 | case DataType::Type::kInt32: |
| 6561 | case DataType::Type::kFloat32: |
| 6562 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6563 | load_type = kLoadWord; |
| 6564 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6565 | case DataType::Type::kInt64: |
| 6566 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6567 | load_type = kLoadDoubleword; |
| 6568 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6569 | case DataType::Type::kUint32: |
| 6570 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6571 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6572 | LOG(FATAL) << "Unreachable type " << type; |
| 6573 | UNREACHABLE(); |
| 6574 | } |
| 6575 | |
| 6576 | if (is_volatile && load_type == kLoadDoubleword) { |
| 6577 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6578 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6579 | // Do implicit Null check |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6580 | __ LoadFromOffset(kLoadWord, |
| 6581 | ZERO, |
| 6582 | locations->GetTemp(0).AsRegister<Register>(), |
| 6583 | 0, |
| 6584 | null_checker); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6585 | codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6586 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6587 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6588 | // FP results are returned in core registers. Need to move them. |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6589 | if (dst_loc.IsFpuRegister()) { |
| 6590 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6591 | __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6592 | dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6593 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6594 | DCHECK(dst_loc.IsDoubleStackSlot()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6595 | __ StoreToOffset(kStoreWord, |
| 6596 | locations->GetTemp(1).AsRegister<Register>(), |
| 6597 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6598 | dst_loc.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6599 | __ StoreToOffset(kStoreWord, |
| 6600 | locations->GetTemp(2).AsRegister<Register>(), |
| 6601 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6602 | dst_loc.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6603 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6604 | } |
| 6605 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6606 | if (type == DataType::Type::kReference) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6607 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 6608 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6609 | Location temp_loc = |
| 6610 | kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6611 | // Note that a potential implicit null check is handled in this |
| 6612 | // CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier call. |
| 6613 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6614 | dst_loc, |
| 6615 | obj, |
| 6616 | offset, |
| 6617 | temp_loc, |
| 6618 | /* needs_null_check */ true); |
| 6619 | if (is_volatile) { |
| 6620 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6621 | } |
| 6622 | } else { |
| 6623 | __ LoadFromOffset(kLoadWord, dst_loc.AsRegister<Register>(), obj, offset, null_checker); |
| 6624 | if (is_volatile) { |
| 6625 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6626 | } |
| 6627 | // If read barriers are enabled, emit read barriers other than |
| 6628 | // Baker's using a slow path (and also unpoison the loaded |
| 6629 | // reference, if heap poisoning is enabled). |
| 6630 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 6631 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6632 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6633 | Register dst; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6634 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6635 | DCHECK(dst_loc.IsRegisterPair()); |
| 6636 | dst = dst_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6637 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6638 | DCHECK(dst_loc.IsRegister()); |
| 6639 | dst = dst_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6640 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6641 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6642 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6643 | DCHECK(dst_loc.IsFpuRegister()); |
| 6644 | FRegister dst = dst_loc.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6645 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6646 | __ LoadSFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6647 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6648 | __ LoadDFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6649 | } |
| 6650 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6651 | } |
| 6652 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6653 | // Memory barriers, in the case of references, are handled in the |
| 6654 | // previous switch statement. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6655 | if (is_volatile && (type != DataType::Type::kReference)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6656 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6657 | } |
| 6658 | } |
| 6659 | |
| 6660 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6661 | DataType::Type field_type = field_info.GetFieldType(); |
| 6662 | 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] | 6663 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6664 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6665 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6666 | |
| 6667 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6668 | if (generate_volatile) { |
| 6669 | InvokeRuntimeCallingConvention calling_convention; |
| 6670 | // need A0 to hold base + offset |
| 6671 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6672 | if (field_type == DataType::Type::kInt64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6673 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 6674 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 6675 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6676 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6677 | locations->SetInAt(1, Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6678 | // Pass FP parameters in core registers. |
| 6679 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 6680 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 6681 | } |
| 6682 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6683 | if (DataType::IsFloatingPointType(field_type)) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6684 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6685 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6686 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6687 | } |
| 6688 | } |
| 6689 | } |
| 6690 | |
| 6691 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, |
| 6692 | const FieldInfo& field_info, |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6693 | uint32_t dex_pc, |
| 6694 | bool value_can_be_null) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6695 | DataType::Type type = field_info.GetFieldType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6696 | LocationSummary* locations = instruction->GetLocations(); |
| 6697 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6698 | Location value_location = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6699 | StoreOperandType store_type = kStoreByte; |
| 6700 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6701 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6702 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6703 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6704 | |
| 6705 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6706 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6707 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6708 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6709 | store_type = kStoreByte; |
| 6710 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6711 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6712 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6713 | store_type = kStoreHalfword; |
| 6714 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6715 | case DataType::Type::kInt32: |
| 6716 | case DataType::Type::kFloat32: |
| 6717 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6718 | store_type = kStoreWord; |
| 6719 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6720 | case DataType::Type::kInt64: |
| 6721 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6722 | store_type = kStoreDoubleword; |
| 6723 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6724 | case DataType::Type::kUint32: |
| 6725 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6726 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6727 | LOG(FATAL) << "Unreachable type " << type; |
| 6728 | UNREACHABLE(); |
| 6729 | } |
| 6730 | |
| 6731 | if (is_volatile) { |
| 6732 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 6733 | } |
| 6734 | |
| 6735 | if (is_volatile && store_type == kStoreDoubleword) { |
| 6736 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6737 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6738 | // Do implicit Null check. |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6739 | __ LoadFromOffset(kLoadWord, |
| 6740 | ZERO, |
| 6741 | locations->GetTemp(0).AsRegister<Register>(), |
| 6742 | 0, |
| 6743 | null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6744 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6745 | // Pass FP parameters in core registers. |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6746 | if (value_location.IsFpuRegister()) { |
| 6747 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), |
| 6748 | value_location.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6749 | __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6750 | value_location.AsFpuRegister<FRegister>()); |
| 6751 | } else if (value_location.IsDoubleStackSlot()) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6752 | __ LoadFromOffset(kLoadWord, |
| 6753 | locations->GetTemp(1).AsRegister<Register>(), |
| 6754 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6755 | value_location.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6756 | __ LoadFromOffset(kLoadWord, |
| 6757 | locations->GetTemp(2).AsRegister<Register>(), |
| 6758 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6759 | value_location.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6760 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6761 | DCHECK(value_location.IsConstant()); |
| 6762 | DCHECK(value_location.GetConstant()->IsDoubleConstant()); |
| 6763 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6764 | __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(), |
| 6765 | locations->GetTemp(1).AsRegister<Register>(), |
| 6766 | value); |
| 6767 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6768 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6769 | codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6770 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); |
| 6771 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6772 | if (value_location.IsConstant()) { |
| 6773 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 6774 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6775 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6776 | Register src; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6777 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6778 | src = value_location.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6779 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6780 | src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6781 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6782 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 6783 | // Note that in the case where `value` is a null reference, |
| 6784 | // we do not enter this block, as a null reference does not |
| 6785 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6786 | DCHECK_EQ(type, DataType::Type::kReference); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6787 | __ PoisonHeapReference(TMP, src); |
| 6788 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 6789 | } else { |
| 6790 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 6791 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6792 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6793 | FRegister src = value_location.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6794 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6795 | __ StoreSToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6796 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6797 | __ StoreDToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6798 | } |
| 6799 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6800 | } |
| 6801 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6802 | if (needs_write_barrier) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6803 | Register src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6804 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6805 | } |
| 6806 | |
| 6807 | if (is_volatile) { |
| 6808 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 6809 | } |
| 6810 | } |
| 6811 | |
| 6812 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6813 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6814 | } |
| 6815 | |
| 6816 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6817 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 6818 | } |
| 6819 | |
| 6820 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6821 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6822 | } |
| 6823 | |
| 6824 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6825 | HandleFieldSet(instruction, |
| 6826 | instruction->GetFieldInfo(), |
| 6827 | instruction->GetDexPc(), |
| 6828 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6829 | } |
| 6830 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6831 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadOneRegister( |
| 6832 | HInstruction* instruction, |
| 6833 | Location out, |
| 6834 | uint32_t offset, |
| 6835 | Location maybe_temp, |
| 6836 | ReadBarrierOption read_barrier_option) { |
| 6837 | Register out_reg = out.AsRegister<Register>(); |
| 6838 | if (read_barrier_option == kWithReadBarrier) { |
| 6839 | CHECK(kEmitCompilerReadBarrier); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6840 | if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) { |
| 6841 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6842 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6843 | if (kUseBakerReadBarrier) { |
| 6844 | // Load with fast path based Baker's read barrier. |
| 6845 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6846 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6847 | out, |
| 6848 | out_reg, |
| 6849 | offset, |
| 6850 | maybe_temp, |
| 6851 | /* needs_null_check */ false); |
| 6852 | } else { |
| 6853 | // Load with slow path based read barrier. |
| 6854 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6855 | // in the following move operation, as we will need it for the |
| 6856 | // read barrier below. |
| 6857 | __ Move(maybe_temp.AsRegister<Register>(), out_reg); |
| 6858 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6859 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6860 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6861 | } |
| 6862 | } else { |
| 6863 | // Plain load with no read barrier. |
| 6864 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6865 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6866 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6867 | } |
| 6868 | } |
| 6869 | |
| 6870 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadTwoRegisters( |
| 6871 | HInstruction* instruction, |
| 6872 | Location out, |
| 6873 | Location obj, |
| 6874 | uint32_t offset, |
| 6875 | Location maybe_temp, |
| 6876 | ReadBarrierOption read_barrier_option) { |
| 6877 | Register out_reg = out.AsRegister<Register>(); |
| 6878 | Register obj_reg = obj.AsRegister<Register>(); |
| 6879 | if (read_barrier_option == kWithReadBarrier) { |
| 6880 | CHECK(kEmitCompilerReadBarrier); |
| 6881 | if (kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6882 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6883 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6884 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6885 | // Load with fast path based Baker's read barrier. |
| 6886 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6887 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6888 | out, |
| 6889 | obj_reg, |
| 6890 | offset, |
| 6891 | maybe_temp, |
| 6892 | /* needs_null_check */ false); |
| 6893 | } else { |
| 6894 | // Load with slow path based read barrier. |
| 6895 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6896 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6897 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6898 | } |
| 6899 | } else { |
| 6900 | // Plain load with no read barrier. |
| 6901 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6902 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6903 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6904 | } |
| 6905 | } |
| 6906 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6907 | static inline int GetBakerMarkThunkNumber(Register reg) { |
| 6908 | static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 21, "Expecting equal"); |
| 6909 | if (reg >= V0 && reg <= T7) { // 14 consequtive regs. |
| 6910 | return reg - V0; |
| 6911 | } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs. |
| 6912 | return 14 + (reg - S2); |
| 6913 | } else if (reg == FP) { // One more. |
| 6914 | return 20; |
| 6915 | } |
| 6916 | LOG(FATAL) << "Unexpected register " << reg; |
| 6917 | UNREACHABLE(); |
| 6918 | } |
| 6919 | |
| 6920 | static inline int GetBakerMarkFieldArrayThunkDisplacement(Register reg, bool short_offset) { |
| 6921 | int num = GetBakerMarkThunkNumber(reg) + |
| 6922 | (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0); |
| 6923 | return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE; |
| 6924 | } |
| 6925 | |
| 6926 | static inline int GetBakerMarkGcRootThunkDisplacement(Register reg) { |
| 6927 | return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE + |
| 6928 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET; |
| 6929 | } |
| 6930 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6931 | void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6932 | Location root, |
| 6933 | Register obj, |
| 6934 | uint32_t offset, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6935 | ReadBarrierOption read_barrier_option, |
| 6936 | MipsLabel* label_low) { |
| 6937 | bool reordering; |
| 6938 | if (label_low != nullptr) { |
| 6939 | DCHECK_EQ(offset, 0x5678u); |
| 6940 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6941 | Register root_reg = root.AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6942 | if (read_barrier_option == kWithReadBarrier) { |
| 6943 | DCHECK(kEmitCompilerReadBarrier); |
| 6944 | if (kUseBakerReadBarrier) { |
| 6945 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6946 | // Baker's read barrier are used: |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6947 | if (kBakerReadBarrierThunksEnableForGcRoots) { |
| 6948 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6949 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 6950 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 6951 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 6952 | // vice versa. |
| 6953 | // |
| 6954 | // We use thunks for the slow path. That thunk checks the reference |
| 6955 | // and jumps to the entrypoint if needed. |
| 6956 | // |
| 6957 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 6958 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 6959 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6960 | // if (temp != nullptr) { |
| 6961 | // temp = &gc_root_thunk<root_reg> |
| 6962 | // root = temp(root) |
| 6963 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6964 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6965 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 6966 | const int32_t entry_point_offset = |
| 6967 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 6968 | const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg); |
| 6969 | int16_t offset_low = Low16Bits(offset); |
| 6970 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign |
| 6971 | // extension in lw. |
| 6972 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 6973 | Register base = short_offset ? obj : TMP; |
| 6974 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6975 | // threads are suspended or running a checkpoint. |
| 6976 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 6977 | reordering = __ SetReorder(false); |
| 6978 | if (!short_offset) { |
| 6979 | DCHECK(!label_low); |
| 6980 | __ AddUpper(base, obj, offset_high); |
| 6981 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6982 | MipsLabel skip_call; |
| 6983 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6984 | if (label_low != nullptr) { |
| 6985 | DCHECK(short_offset); |
| 6986 | __ Bind(label_low); |
| 6987 | } |
| 6988 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6989 | __ LoadFromOffset(kLoadWord, root_reg, base, offset_low); // Single instruction |
| 6990 | // in delay slot. |
| 6991 | if (isR6) { |
| 6992 | __ Jialc(T9, thunk_disp); |
| 6993 | } else { |
| 6994 | __ Addiu(T9, T9, thunk_disp); |
| 6995 | __ Jalr(T9); |
| 6996 | __ Nop(); |
| 6997 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6998 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6999 | __ SetReorder(reordering); |
| 7000 | } else { |
| 7001 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 7002 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 7003 | // load into `temp` (T9) the read barrier mark entry point corresponding |
| 7004 | // to register `root`. If `temp` is null, it means that `GetIsGcMarking()` |
| 7005 | // is false, and vice versa. |
| 7006 | // |
| 7007 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 7008 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7009 | // if (temp != null) { |
| 7010 | // root = temp(root) |
| 7011 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7012 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7013 | if (label_low != nullptr) { |
| 7014 | reordering = __ SetReorder(false); |
| 7015 | __ Bind(label_low); |
| 7016 | } |
| 7017 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7018 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7019 | if (label_low != nullptr) { |
| 7020 | __ SetReorder(reordering); |
| 7021 | } |
| 7022 | static_assert( |
| 7023 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7024 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7025 | "have different sizes."); |
| 7026 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7027 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7028 | "have different sizes."); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7029 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7030 | // Slow path marking the GC root `root`. |
| 7031 | Location temp = Location::RegisterLocation(T9); |
| 7032 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7033 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS( |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7034 | instruction, |
| 7035 | root, |
| 7036 | /*entrypoint*/ temp); |
| 7037 | codegen_->AddSlowPath(slow_path); |
| 7038 | |
| 7039 | const int32_t entry_point_offset = |
| 7040 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(root.reg() - 1); |
| 7041 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7042 | // threads are suspended or running a checkpoint. |
| 7043 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 7044 | __ Bnez(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 7045 | __ Bind(slow_path->GetExitLabel()); |
| 7046 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7047 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7048 | if (label_low != nullptr) { |
| 7049 | reordering = __ SetReorder(false); |
| 7050 | __ Bind(label_low); |
| 7051 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7052 | // GC root loaded through a slow path for read barriers other |
| 7053 | // than Baker's. |
| 7054 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 7055 | __ Addiu32(root_reg, obj, offset); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7056 | if (label_low != nullptr) { |
| 7057 | __ SetReorder(reordering); |
| 7058 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7059 | // /* mirror::Object* */ root = root->Read() |
| 7060 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7061 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7062 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7063 | if (label_low != nullptr) { |
| 7064 | reordering = __ SetReorder(false); |
| 7065 | __ Bind(label_low); |
| 7066 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7067 | // Plain GC root load with no read barrier. |
| 7068 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7069 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7070 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7071 | // do not have to unpoison `root_reg` here. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7072 | if (label_low != nullptr) { |
| 7073 | __ SetReorder(reordering); |
| 7074 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7075 | } |
| 7076 | } |
| 7077 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7078 | void CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7079 | Location ref, |
| 7080 | Register obj, |
| 7081 | uint32_t offset, |
| 7082 | Location temp, |
| 7083 | bool needs_null_check) { |
| 7084 | DCHECK(kEmitCompilerReadBarrier); |
| 7085 | DCHECK(kUseBakerReadBarrier); |
| 7086 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7087 | if (kBakerReadBarrierThunksEnableForFields) { |
| 7088 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 7089 | // to decide whether to mark the loaded reference or not. Instead, we |
| 7090 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 7091 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 7092 | // vice versa. |
| 7093 | // |
| 7094 | // We use thunks for the slow path. That thunk checks the reference |
| 7095 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 7096 | // it issues a load-load memory barrier and returns to the original |
| 7097 | // reference load. |
| 7098 | // |
| 7099 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 7100 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 7101 | // if (temp != nullptr) { |
| 7102 | // temp = &field_array_thunk<holder_reg> |
| 7103 | // temp() |
| 7104 | // } |
| 7105 | // not_gray_return_address: |
| 7106 | // // If the offset is too large to fit into the lw instruction, we |
| 7107 | // // use an adjusted base register (TMP) here. This register |
| 7108 | // // receives bits 16 ... 31 of the offset before the thunk invocation |
| 7109 | // // and the thunk benefits from it. |
| 7110 | // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load. |
| 7111 | // gray_return_address: |
| 7112 | |
| 7113 | DCHECK(temp.IsInvalid()); |
| 7114 | bool isR6 = GetInstructionSetFeatures().IsR6(); |
| 7115 | int16_t offset_low = Low16Bits(offset); |
| 7116 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lw. |
| 7117 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 7118 | bool reordering = __ SetReorder(false); |
| 7119 | const int32_t entry_point_offset = |
| 7120 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 7121 | // There may have or may have not been a null check if the field offset is smaller than |
| 7122 | // the page size. |
| 7123 | // There must've been a null check in case it's actually a load from an array. |
| 7124 | // We will, however, perform an explicit null check in the thunk as it's easier to |
| 7125 | // do it than not. |
| 7126 | if (instruction->IsArrayGet()) { |
| 7127 | DCHECK(!needs_null_check); |
| 7128 | } |
| 7129 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset); |
| 7130 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7131 | // threads are suspended or running a checkpoint. |
| 7132 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 7133 | Register ref_reg = ref.AsRegister<Register>(); |
| 7134 | Register base = short_offset ? obj : TMP; |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7135 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7136 | if (short_offset) { |
| 7137 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7138 | __ Beqzc(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7139 | __ Nop(); // In forbidden slot. |
| 7140 | __ Jialc(T9, thunk_disp); |
| 7141 | } else { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7142 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7143 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 7144 | __ Jalr(T9); |
| 7145 | __ Nop(); // In delay slot. |
| 7146 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7147 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7148 | } else { |
| 7149 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7150 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7151 | __ Aui(base, obj, offset_high); // In delay slot. |
| 7152 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7153 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7154 | } else { |
| 7155 | __ Lui(base, offset_high); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7156 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7157 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 7158 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7159 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7160 | __ Addu(base, base, obj); // In delay slot. |
| 7161 | } |
| 7162 | } |
| 7163 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7164 | __ LoadFromOffset(kLoadWord, ref_reg, base, offset_low); // Single instruction. |
| 7165 | if (needs_null_check) { |
| 7166 | MaybeRecordImplicitNullCheck(instruction); |
| 7167 | } |
| 7168 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7169 | __ SetReorder(reordering); |
| 7170 | return; |
| 7171 | } |
| 7172 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7173 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7174 | Location no_index = Location::NoLocation(); |
| 7175 | ScaleFactor no_scale_factor = TIMES_1; |
| 7176 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 7177 | ref, |
| 7178 | obj, |
| 7179 | offset, |
| 7180 | no_index, |
| 7181 | no_scale_factor, |
| 7182 | temp, |
| 7183 | needs_null_check); |
| 7184 | } |
| 7185 | |
| 7186 | void CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7187 | Location ref, |
| 7188 | Register obj, |
| 7189 | uint32_t data_offset, |
| 7190 | Location index, |
| 7191 | Location temp, |
| 7192 | bool needs_null_check) { |
| 7193 | DCHECK(kEmitCompilerReadBarrier); |
| 7194 | DCHECK(kUseBakerReadBarrier); |
| 7195 | |
| 7196 | static_assert( |
| 7197 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7198 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7199 | ScaleFactor scale_factor = TIMES_4; |
| 7200 | |
| 7201 | if (kBakerReadBarrierThunksEnableForArrays) { |
| 7202 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 7203 | // to decide whether to mark the loaded reference or not. Instead, we |
| 7204 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 7205 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 7206 | // vice versa. |
| 7207 | // |
| 7208 | // We use thunks for the slow path. That thunk checks the reference |
| 7209 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 7210 | // it issues a load-load memory barrier and returns to the original |
| 7211 | // reference load. |
| 7212 | // |
| 7213 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 7214 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 7215 | // if (temp != nullptr) { |
| 7216 | // temp = &field_array_thunk<holder_reg> |
| 7217 | // temp() |
| 7218 | // } |
| 7219 | // not_gray_return_address: |
| 7220 | // // The element address is pre-calculated in the TMP register before the |
| 7221 | // // thunk invocation and the thunk benefits from it. |
| 7222 | // HeapReference<mirror::Object> reference = data[index]; // Original reference load. |
| 7223 | // gray_return_address: |
| 7224 | |
| 7225 | DCHECK(temp.IsInvalid()); |
| 7226 | DCHECK(index.IsValid()); |
| 7227 | bool reordering = __ SetReorder(false); |
| 7228 | const int32_t entry_point_offset = |
| 7229 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 7230 | // We will not do the explicit null check in the thunk as some form of a null check |
| 7231 | // must've been done earlier. |
| 7232 | DCHECK(!needs_null_check); |
| 7233 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false); |
| 7234 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7235 | // threads are suspended or running a checkpoint. |
| 7236 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 7237 | Register ref_reg = ref.AsRegister<Register>(); |
| 7238 | Register index_reg = index.IsRegisterPair() |
| 7239 | ? index.AsRegisterPairLow<Register>() |
| 7240 | : index.AsRegister<Register>(); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7241 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7242 | if (GetInstructionSetFeatures().IsR6()) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7243 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7244 | __ Lsa(TMP, index_reg, obj, scale_factor); // In delay slot. |
| 7245 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7246 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7247 | } else { |
| 7248 | __ Sll(TMP, index_reg, scale_factor); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7249 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7250 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 7251 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7252 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7253 | __ Addu(TMP, TMP, obj); // In delay slot. |
| 7254 | } |
| 7255 | // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor)) |
| 7256 | DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset; |
| 7257 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, data_offset); // Single instruction. |
| 7258 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7259 | __ SetReorder(reordering); |
| 7260 | return; |
| 7261 | } |
| 7262 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7263 | // /* HeapReference<Object> */ ref = |
| 7264 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7265 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 7266 | ref, |
| 7267 | obj, |
| 7268 | data_offset, |
| 7269 | index, |
| 7270 | scale_factor, |
| 7271 | temp, |
| 7272 | needs_null_check); |
| 7273 | } |
| 7274 | |
| 7275 | void CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7276 | Location ref, |
| 7277 | Register obj, |
| 7278 | uint32_t offset, |
| 7279 | Location index, |
| 7280 | ScaleFactor scale_factor, |
| 7281 | Location temp, |
| 7282 | bool needs_null_check, |
| 7283 | bool always_update_field) { |
| 7284 | DCHECK(kEmitCompilerReadBarrier); |
| 7285 | DCHECK(kUseBakerReadBarrier); |
| 7286 | |
| 7287 | // In slow path based read barriers, the read barrier call is |
| 7288 | // inserted after the original load. However, in fast path based |
| 7289 | // Baker's read barriers, we need to perform the load of |
| 7290 | // mirror::Object::monitor_ *before* the original reference load. |
| 7291 | // This load-load ordering is required by the read barrier. |
| 7292 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7293 | // |
| 7294 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7295 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7296 | // HeapReference<Object> ref = *src; // Original reference load. |
| 7297 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 7298 | // if (is_gray) { |
| 7299 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7300 | // } |
| 7301 | // |
| 7302 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7303 | // slightly more complex as it performs additional checks that we do |
| 7304 | // not do here for performance reasons. |
| 7305 | |
| 7306 | Register ref_reg = ref.AsRegister<Register>(); |
| 7307 | Register temp_reg = temp.AsRegister<Register>(); |
| 7308 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7309 | |
| 7310 | // /* int32_t */ monitor = obj->monitor_ |
| 7311 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 7312 | if (needs_null_check) { |
| 7313 | MaybeRecordImplicitNullCheck(instruction); |
| 7314 | } |
| 7315 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7316 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7317 | "art::LockWord and int32_t have different sizes."); |
| 7318 | |
| 7319 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 7320 | |
| 7321 | // The actual reference load. |
| 7322 | if (index.IsValid()) { |
| 7323 | // Load types involving an "index": ArrayGet, |
| 7324 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7325 | // intrinsics. |
| 7326 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 7327 | if (index.IsConstant()) { |
| 7328 | size_t computed_offset = |
| 7329 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 7330 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7331 | } else { |
| 7332 | // Handle the special case of the |
| 7333 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7334 | // intrinsics, which use a register pair as index ("long |
| 7335 | // offset"), of which only the low part contains data. |
| 7336 | Register index_reg = index.IsRegisterPair() |
| 7337 | ? index.AsRegisterPairLow<Register>() |
| 7338 | : index.AsRegister<Register>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 7339 | __ ShiftAndAdd(TMP, index_reg, obj, scale_factor, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7340 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, offset); |
| 7341 | } |
| 7342 | } else { |
| 7343 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7344 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7345 | } |
| 7346 | |
| 7347 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7348 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7349 | |
| 7350 | // Slow path marking the object `ref` when it is gray. |
| 7351 | SlowPathCodeMIPS* slow_path; |
| 7352 | if (always_update_field) { |
| 7353 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS only supports address |
| 7354 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7355 | // `field_offset` is a register pair (of which only the lower half |
| 7356 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7357 | // to be null in this code path. |
| 7358 | DCHECK_EQ(offset, 0u); |
| 7359 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7360 | slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7361 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(instruction, |
| 7362 | ref, |
| 7363 | obj, |
| 7364 | /* field_offset */ index, |
| 7365 | temp_reg); |
| 7366 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7367 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS(instruction, ref); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7368 | } |
| 7369 | AddSlowPath(slow_path); |
| 7370 | |
| 7371 | // if (rb_state == ReadBarrier::GrayState()) |
| 7372 | // ref = ReadBarrier::Mark(ref); |
| 7373 | // Given the numeric representation, it's enough to check the low bit of the |
| 7374 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 7375 | // performing a branch on less than zero. |
| 7376 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7377 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 7378 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 7379 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 7380 | __ Bltz(temp_reg, slow_path->GetEntryLabel()); |
| 7381 | __ Bind(slow_path->GetExitLabel()); |
| 7382 | } |
| 7383 | |
| 7384 | void CodeGeneratorMIPS::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7385 | Location out, |
| 7386 | Location ref, |
| 7387 | Location obj, |
| 7388 | uint32_t offset, |
| 7389 | Location index) { |
| 7390 | DCHECK(kEmitCompilerReadBarrier); |
| 7391 | |
| 7392 | // Insert a slow path based read barrier *after* the reference load. |
| 7393 | // |
| 7394 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7395 | // reference will be carried out by the runtime within the slow |
| 7396 | // path. |
| 7397 | // |
| 7398 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7399 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7400 | // not used by the artReadBarrierSlow entry point. |
| 7401 | // |
| 7402 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7403 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7404 | ReadBarrierForHeapReferenceSlowPathMIPS(instruction, out, ref, obj, offset, index); |
| 7405 | AddSlowPath(slow_path); |
| 7406 | |
| 7407 | __ B(slow_path->GetEntryLabel()); |
| 7408 | __ Bind(slow_path->GetExitLabel()); |
| 7409 | } |
| 7410 | |
| 7411 | void CodeGeneratorMIPS::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7412 | Location out, |
| 7413 | Location ref, |
| 7414 | Location obj, |
| 7415 | uint32_t offset, |
| 7416 | Location index) { |
| 7417 | if (kEmitCompilerReadBarrier) { |
| 7418 | // Baker's read barriers shall be handled by the fast path |
| 7419 | // (CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier). |
| 7420 | DCHECK(!kUseBakerReadBarrier); |
| 7421 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7422 | // by the runtime within the slow path. |
| 7423 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 7424 | } else if (kPoisonHeapReferences) { |
| 7425 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7426 | } |
| 7427 | } |
| 7428 | |
| 7429 | void CodeGeneratorMIPS::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7430 | Location out, |
| 7431 | Location root) { |
| 7432 | DCHECK(kEmitCompilerReadBarrier); |
| 7433 | |
| 7434 | // Insert a slow path based read barrier *after* the GC root load. |
| 7435 | // |
| 7436 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7437 | // not need to do anything special for this here. |
| 7438 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7439 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS(instruction, out, root); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7440 | AddSlowPath(slow_path); |
| 7441 | |
| 7442 | __ B(slow_path->GetEntryLabel()); |
| 7443 | __ Bind(slow_path->GetExitLabel()); |
| 7444 | } |
| 7445 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7446 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7447 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7448 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7449 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7450 | switch (type_check_kind) { |
| 7451 | case TypeCheckKind::kExactCheck: |
| 7452 | case TypeCheckKind::kAbstractClassCheck: |
| 7453 | case TypeCheckKind::kClassHierarchyCheck: |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7454 | case TypeCheckKind::kArrayObjectCheck: { |
| 7455 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7456 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7457 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7458 | break; |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7459 | } |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7460 | case TypeCheckKind::kArrayCheck: |
| 7461 | case TypeCheckKind::kUnresolvedCheck: |
| 7462 | case TypeCheckKind::kInterfaceCheck: |
| 7463 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7464 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7465 | case TypeCheckKind::kBitstringCheck: |
| 7466 | break; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7467 | } |
| 7468 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7469 | LocationSummary* locations = |
| 7470 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7471 | if (baker_read_barrier_slow_path) { |
| 7472 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7473 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7474 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7475 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7476 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7477 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7478 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7479 | } else { |
| 7480 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7481 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7482 | // The output does overlap inputs. |
| 7483 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 7484 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7485 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7486 | } |
| 7487 | |
| 7488 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7489 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7490 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7491 | Location obj_loc = locations->InAt(0); |
| 7492 | Register obj = obj_loc.AsRegister<Register>(); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7493 | Location cls = locations->InAt(1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7494 | Location out_loc = locations->Out(); |
| 7495 | Register out = out_loc.AsRegister<Register>(); |
| 7496 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7497 | DCHECK_LE(num_temps, 1u); |
| 7498 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7499 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7500 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7501 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7502 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7503 | MipsLabel done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7504 | SlowPathCodeMIPS* slow_path = nullptr; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7505 | |
| 7506 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7507 | // Avoid this check if we know `obj` is not null. |
| 7508 | if (instruction->MustDoNullCheck()) { |
| 7509 | __ Move(out, ZERO); |
| 7510 | __ Beqz(obj, &done); |
| 7511 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7512 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7513 | switch (type_check_kind) { |
| 7514 | case TypeCheckKind::kExactCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7515 | ReadBarrierOption read_barrier_option = |
| 7516 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7517 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7518 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7519 | out_loc, |
| 7520 | obj_loc, |
| 7521 | class_offset, |
| 7522 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7523 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7524 | // Classes must be equal for the instanceof to succeed. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7525 | __ Xor(out, out, cls.AsRegister<Register>()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7526 | __ Sltiu(out, out, 1); |
| 7527 | break; |
| 7528 | } |
| 7529 | |
| 7530 | case TypeCheckKind::kAbstractClassCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7531 | ReadBarrierOption read_barrier_option = |
| 7532 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7533 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7534 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7535 | out_loc, |
| 7536 | obj_loc, |
| 7537 | class_offset, |
| 7538 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7539 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7540 | // If the class is abstract, we eagerly fetch the super class of the |
| 7541 | // object to avoid doing a comparison we know will fail. |
| 7542 | MipsLabel loop; |
| 7543 | __ Bind(&loop); |
| 7544 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7545 | GenerateReferenceLoadOneRegister(instruction, |
| 7546 | out_loc, |
| 7547 | super_offset, |
| 7548 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7549 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7550 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7551 | __ Beqz(out, &done); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7552 | __ Bne(out, cls.AsRegister<Register>(), &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7553 | __ LoadConst32(out, 1); |
| 7554 | break; |
| 7555 | } |
| 7556 | |
| 7557 | case TypeCheckKind::kClassHierarchyCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7558 | ReadBarrierOption read_barrier_option = |
| 7559 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7560 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7561 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7562 | out_loc, |
| 7563 | obj_loc, |
| 7564 | class_offset, |
| 7565 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7566 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7567 | // Walk over the class hierarchy to find a match. |
| 7568 | MipsLabel loop, success; |
| 7569 | __ Bind(&loop); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7570 | __ Beq(out, cls.AsRegister<Register>(), &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7571 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7572 | GenerateReferenceLoadOneRegister(instruction, |
| 7573 | out_loc, |
| 7574 | super_offset, |
| 7575 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7576 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7577 | __ Bnez(out, &loop); |
| 7578 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7579 | __ B(&done); |
| 7580 | __ Bind(&success); |
| 7581 | __ LoadConst32(out, 1); |
| 7582 | break; |
| 7583 | } |
| 7584 | |
| 7585 | case TypeCheckKind::kArrayObjectCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7586 | ReadBarrierOption read_barrier_option = |
| 7587 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7588 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7589 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7590 | out_loc, |
| 7591 | obj_loc, |
| 7592 | class_offset, |
| 7593 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7594 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7595 | // Do an exact check. |
| 7596 | MipsLabel success; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7597 | __ Beq(out, cls.AsRegister<Register>(), &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7598 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7599 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7600 | GenerateReferenceLoadOneRegister(instruction, |
| 7601 | out_loc, |
| 7602 | component_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 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7606 | __ Beqz(out, &done); |
| 7607 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7608 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 7609 | __ Sltiu(out, out, 1); |
| 7610 | __ B(&done); |
| 7611 | __ Bind(&success); |
| 7612 | __ LoadConst32(out, 1); |
| 7613 | break; |
| 7614 | } |
| 7615 | |
| 7616 | case TypeCheckKind::kArrayCheck: { |
| 7617 | // No read barrier since the slow path will retry upon failure. |
| 7618 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7619 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7620 | out_loc, |
| 7621 | obj_loc, |
| 7622 | class_offset, |
| 7623 | maybe_temp_loc, |
| 7624 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7625 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7626 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7627 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7628 | codegen_->AddSlowPath(slow_path); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7629 | __ Bne(out, cls.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7630 | __ LoadConst32(out, 1); |
| 7631 | break; |
| 7632 | } |
| 7633 | |
| 7634 | case TypeCheckKind::kUnresolvedCheck: |
| 7635 | case TypeCheckKind::kInterfaceCheck: { |
| 7636 | // Note that we indeed only call on slow path, but we always go |
| 7637 | // into the slow path for the unresolved and interface check |
| 7638 | // cases. |
| 7639 | // |
| 7640 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7641 | // entry point without resorting to a type checking slow path |
| 7642 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7643 | // require to assign fixed registers for the inputs of this |
| 7644 | // HInstanceOf instruction (following the runtime calling |
| 7645 | // convention), which might be cluttered by the potential first |
| 7646 | // read barrier emission at the beginning of this method. |
| 7647 | // |
| 7648 | // TODO: Introduce a new runtime entry point taking the object |
| 7649 | // to test (instead of its class) as argument, and let it deal |
| 7650 | // with the read barrier issues. This will let us refactor this |
| 7651 | // case of the `switch` code as it was previously (with a direct |
| 7652 | // call to the runtime not using a type checking slow path). |
| 7653 | // This should also be beneficial for the other cases above. |
| 7654 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7655 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7656 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7657 | codegen_->AddSlowPath(slow_path); |
| 7658 | __ B(slow_path->GetEntryLabel()); |
| 7659 | break; |
| 7660 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7661 | |
| 7662 | case TypeCheckKind::kBitstringCheck: { |
| 7663 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7664 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7665 | out_loc, |
| 7666 | obj_loc, |
| 7667 | class_offset, |
| 7668 | maybe_temp_loc, |
| 7669 | kWithoutReadBarrier); |
| 7670 | |
| 7671 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 7672 | __ Sltiu(out, out, 1); |
| 7673 | break; |
| 7674 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7675 | } |
| 7676 | |
| 7677 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7678 | |
| 7679 | if (slow_path != nullptr) { |
| 7680 | __ Bind(slow_path->GetExitLabel()); |
| 7681 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7682 | } |
| 7683 | |
| 7684 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7685 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7686 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7687 | } |
| 7688 | |
| 7689 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 7690 | // Will be generated at use site. |
| 7691 | } |
| 7692 | |
| 7693 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7694 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7695 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7696 | } |
| 7697 | |
| 7698 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 7699 | // Will be generated at use site. |
| 7700 | } |
| 7701 | |
| 7702 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { |
| 7703 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 7704 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 7705 | } |
| 7706 | |
| 7707 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7708 | HandleInvoke(invoke); |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7709 | // 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] | 7710 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7711 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T7)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7712 | } |
| 7713 | |
| 7714 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7715 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 7716 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7717 | Location receiver = invoke->GetLocations()->InAt(0); |
| 7718 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7719 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7720 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7721 | // temp = object->GetClass(); |
| 7722 | if (receiver.IsStackSlot()) { |
| 7723 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 7724 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 7725 | } else { |
| 7726 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 7727 | } |
| 7728 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7729 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7730 | // emit a read barrier for the previous class reference load. |
| 7731 | // However this is not required in practice, as this is an |
| 7732 | // intermediate/temporary reference and because the current |
| 7733 | // concurrent copying collector keeps the from-space memory |
| 7734 | // intact/accessible until the end of the marking phase (the |
| 7735 | // concurrent copying collector may not in the future). |
| 7736 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 7737 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 7738 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
| 7739 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7740 | invoke->GetImtIndex(), kMipsPointerSize)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7741 | // temp = temp->GetImtEntryAt(method_offset); |
| 7742 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7743 | // T9 = temp->GetEntryPoint(); |
| 7744 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
Lena Djokic | 3177e10 | 2018-02-28 11:32:40 +0100 | [diff] [blame] | 7745 | // Set the hidden argument. |
| 7746 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 7747 | invoke->GetDexMethodIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7748 | // T9(); |
| 7749 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7750 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7751 | DCHECK(!codegen_->IsLeafMethod()); |
| 7752 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 7753 | } |
| 7754 | |
| 7755 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7756 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7757 | if (intrinsic.TryDispatch(invoke)) { |
| 7758 | return; |
| 7759 | } |
| 7760 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7761 | HandleInvoke(invoke); |
| 7762 | } |
| 7763 | |
| 7764 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 7765 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 7766 | // art::PrepareForRegisterAllocation. |
| 7767 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7768 | |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7769 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7770 | bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
| 7771 | bool has_extra_input = invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7772 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7773 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7774 | if (intrinsic.TryDispatch(invoke)) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7775 | if (invoke->GetLocations()->CanCall() && has_extra_input) { |
| 7776 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 7777 | } |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7778 | return; |
| 7779 | } |
| 7780 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7781 | HandleInvoke(invoke); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7782 | |
| 7783 | // Add the extra input register if either the dex cache array base register |
| 7784 | // or the PC-relative base register for accessing literals is needed. |
| 7785 | if (has_extra_input) { |
| 7786 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 7787 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7788 | } |
| 7789 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 7790 | void LocationsBuilderMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7791 | HandleInvoke(invoke); |
| 7792 | } |
| 7793 | |
| 7794 | void InstructionCodeGeneratorMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7795 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 7796 | } |
| 7797 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 7798 | void LocationsBuilderMIPS::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 7799 | HandleInvoke(invoke); |
| 7800 | } |
| 7801 | |
| 7802 | void InstructionCodeGeneratorMIPS::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 7803 | codegen_->GenerateInvokeCustomCall(invoke); |
| 7804 | } |
| 7805 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7806 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7807 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7808 | IntrinsicCodeGeneratorMIPS intrinsic(codegen); |
| 7809 | intrinsic.Dispatch(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7810 | return true; |
| 7811 | } |
| 7812 | return false; |
| 7813 | } |
| 7814 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7815 | HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7816 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7817 | switch (desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7818 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7819 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7820 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7821 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7822 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7823 | case HLoadString::LoadKind::kJitTableAddress: |
| 7824 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7825 | break; |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7826 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7827 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7828 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7829 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7830 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7831 | } |
| 7832 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7833 | HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind( |
| 7834 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7835 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7836 | case HLoadClass::LoadKind::kInvalid: |
| 7837 | LOG(FATAL) << "UNREACHABLE"; |
| 7838 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7839 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7840 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7841 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7842 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7843 | case HLoadClass::LoadKind::kBssEntry: |
| 7844 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7845 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7846 | case HLoadClass::LoadKind::kJitTableAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7847 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7848 | break; |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7849 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7850 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7851 | break; |
| 7852 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7853 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7854 | } |
| 7855 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7856 | Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7857 | Register temp) { |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7858 | CHECK(!GetInstructionSetFeatures().IsR6()); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7859 | CHECK(!GetGraph()->HasIrreducibleLoops()); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7860 | CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7861 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7862 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7863 | return location.AsRegister<Register>(); |
| 7864 | } |
| 7865 | // For intrinsics we allow any location, so it may be on the stack. |
| 7866 | if (!location.IsRegister()) { |
| 7867 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7868 | return temp; |
| 7869 | } |
| 7870 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7871 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7872 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7873 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7874 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 7875 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 7876 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 7877 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7878 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7879 | return temp; |
| 7880 | } |
| 7881 | return location.AsRegister<Register>(); |
| 7882 | } |
| 7883 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7884 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( |
| 7885 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 7886 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7887 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7888 | } |
| 7889 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7890 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall( |
| 7891 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7892 | // 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] | 7893 | 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] | 7894 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 7895 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7896 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7897 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 7898 | Register base_reg = (invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7899 | ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>()) |
| 7900 | : ZERO; |
| 7901 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7902 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7903 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7904 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7905 | uint32_t offset = |
| 7906 | GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7907 | __ LoadFromOffset(kLoadWord, |
| 7908 | temp.AsRegister<Register>(), |
| 7909 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7910 | offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7911 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7912 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7913 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7914 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7915 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7916 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 7917 | DCHECK(GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7918 | PcRelativePatchInfo* info_high = NewBootImageMethodPatch(invoke->GetTargetMethod()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7919 | PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7920 | NewBootImageMethodPatch(invoke->GetTargetMethod(), info_high); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7921 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7922 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 7923 | __ Addiu(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7924 | break; |
| 7925 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7926 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7927 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 7928 | break; |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 7929 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7930 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 7931 | PcRelativePatchInfo* info_high = NewBootImageRelRoPatch(boot_image_offset); |
| 7932 | PcRelativePatchInfo* info_low = NewBootImageRelRoPatch(boot_image_offset, info_high); |
| 7933 | Register temp_reg = temp.AsRegister<Register>(); |
| 7934 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 7935 | __ Lw(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
| 7936 | break; |
| 7937 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7938 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7939 | PcRelativePatchInfo* info_high = NewMethodBssEntryPatch( |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7940 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7941 | PcRelativePatchInfo* info_low = NewMethodBssEntryPatch( |
| 7942 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7943 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7944 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 7945 | __ Lw(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7946 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7947 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7948 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 7949 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 7950 | return; // No code pointer retrieval; the runtime performs the call directly. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7951 | } |
| 7952 | } |
| 7953 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7954 | switch (code_ptr_location) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7955 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7956 | __ Bal(&frame_entry_label_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7957 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7958 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7959 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 7960 | __ LoadFromOffset(kLoadWord, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7961 | T9, |
| 7962 | callee_method.AsRegister<Register>(), |
| 7963 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7964 | kMipsPointerSize).Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7965 | // T9() |
| 7966 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7967 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7968 | break; |
| 7969 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7970 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 7971 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7972 | DCHECK(!IsLeafMethod()); |
| 7973 | } |
| 7974 | |
| 7975 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 7976 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 7977 | // art::PrepareForRegisterAllocation. |
| 7978 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7979 | |
| 7980 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 7981 | return; |
| 7982 | } |
| 7983 | |
| 7984 | LocationSummary* locations = invoke->GetLocations(); |
| 7985 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 7986 | locations->HasTemps() |
| 7987 | ? locations->GetTemp(0) |
| 7988 | : Location::NoLocation()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7989 | } |
| 7990 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7991 | void CodeGeneratorMIPS::GenerateVirtualCall( |
| 7992 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 7993 | // Use the calling convention instead of the location of the receiver, as |
| 7994 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7995 | // slow path, the arguments have been moved to the right place, so here we are |
| 7996 | // guaranteed that the receiver is the first register of the calling convention. |
| 7997 | InvokeDexCallingConvention calling_convention; |
| 7998 | Register receiver = calling_convention.GetRegisterAt(0); |
| 7999 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 8000 | Register temp = temp_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8001 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 8002 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); |
| 8003 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8004 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8005 | |
| 8006 | // temp = object->GetClass(); |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 8007 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 8008 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8009 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 8010 | // emit a read barrier for the previous class reference load. |
| 8011 | // However this is not required in practice, as this is an |
| 8012 | // intermediate/temporary reference and because the current |
| 8013 | // concurrent copying collector keeps the from-space memory |
| 8014 | // intact/accessible until the end of the marking phase (the |
| 8015 | // concurrent copying collector may not in the future). |
| 8016 | __ MaybeUnpoisonHeapReference(temp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8017 | // temp = temp->GetMethodAt(method_offset); |
| 8018 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 8019 | // T9 = temp->GetEntryPoint(); |
| 8020 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 8021 | // T9(); |
| 8022 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 8023 | __ NopIfNoReordering(); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8024 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 8025 | } |
| 8026 | |
| 8027 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 8028 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 8029 | return; |
| 8030 | } |
| 8031 | |
| 8032 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8033 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8034 | } |
| 8035 | |
| 8036 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8037 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8038 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8039 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8040 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 8041 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8042 | return; |
| 8043 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8044 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8045 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8046 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8047 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 8048 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8049 | ? LocationSummary::kCallOnSlowPath |
| 8050 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8051 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8052 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 8053 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 8054 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8055 | switch (load_kind) { |
| 8056 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8057 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8058 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8059 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8060 | case HLoadClass::LoadKind::kBssEntry: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8061 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8062 | break; |
| 8063 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8064 | if (has_irreducible_loops) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 8065 | if (load_kind != HLoadClass::LoadKind::kBootImageAddress) { |
| 8066 | codegen_->ClobberRA(); |
| 8067 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8068 | break; |
| 8069 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8070 | FALLTHROUGH_INTENDED; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8071 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8072 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8073 | break; |
| 8074 | default: |
| 8075 | break; |
| 8076 | } |
| 8077 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8078 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 8079 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 8080 | // Rely on the type resolution or initialization and marking to save everything we need. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8081 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 8082 | InvokeRuntimeCallingConvention calling_convention; |
| 8083 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8084 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 8085 | } else { |
| 8086 | // For non-Baker read barriers we have a temp-clobbering call. |
| 8087 | } |
| 8088 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8089 | } |
| 8090 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 8091 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 8092 | // move. |
| 8093 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8094 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8095 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8096 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 8097 | return; |
| 8098 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8099 | DCHECK(!cls->NeedsAccessCheck()); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 8100 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8101 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8102 | Location out_loc = locations->Out(); |
| 8103 | Register out = out_loc.AsRegister<Register>(); |
| 8104 | Register base_or_current_method_reg; |
| 8105 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8106 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8107 | switch (load_kind) { |
| 8108 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8109 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8110 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8111 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8112 | case HLoadClass::LoadKind::kBssEntry: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8113 | base_or_current_method_reg = |
| 8114 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8115 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8116 | case HLoadClass::LoadKind::kReferrersClass: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8117 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8118 | base_or_current_method_reg = locations->InAt(0).AsRegister<Register>(); |
| 8119 | break; |
| 8120 | default: |
| 8121 | base_or_current_method_reg = ZERO; |
| 8122 | break; |
| 8123 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 8124 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8125 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 8126 | ? kWithoutReadBarrier |
| 8127 | : kCompilerReadBarrierOption; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8128 | bool generate_null_check = false; |
| 8129 | switch (load_kind) { |
| 8130 | case HLoadClass::LoadKind::kReferrersClass: { |
| 8131 | DCHECK(!cls->CanCallRuntime()); |
| 8132 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 8133 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 8134 | GenerateGcRootFieldLoad(cls, |
| 8135 | out_loc, |
| 8136 | base_or_current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8137 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 8138 | read_barrier_option); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8139 | break; |
| 8140 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8141 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8142 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8143 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8144 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8145 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8146 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8147 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8148 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8149 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 8150 | base_or_current_method_reg); |
| 8151 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8152 | break; |
| 8153 | } |
| 8154 | case HLoadClass::LoadKind::kBootImageAddress: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8155 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 8156 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 8157 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 8158 | DCHECK_NE(address, 0u); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8159 | if (isR6 || !has_irreducible_loops) { |
| 8160 | __ LoadLiteral(out, |
| 8161 | base_or_current_method_reg, |
| 8162 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 8163 | } else { |
| 8164 | __ LoadConst32(out, address); |
| 8165 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8166 | break; |
| 8167 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8168 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8169 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8170 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8171 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8172 | codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8173 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8174 | codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8175 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8176 | out, |
| 8177 | base_or_current_method_reg); |
| 8178 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8179 | break; |
| 8180 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8181 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8182 | CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high = |
| 8183 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8184 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8185 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8186 | codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8187 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8188 | base_or_current_method_reg); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8189 | GenerateGcRootFieldLoad(cls, |
| 8190 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8191 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8192 | /* placeholder */ 0x5678, |
| 8193 | read_barrier_option, |
| 8194 | &info_low->label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8195 | generate_null_check = true; |
| 8196 | break; |
| 8197 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8198 | case HLoadClass::LoadKind::kJitTableAddress: { |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8199 | CodeGeneratorMIPS::JitPatchInfo* info = codegen_->NewJitRootClassPatch(cls->GetDexFile(), |
| 8200 | cls->GetTypeIndex(), |
| 8201 | cls->GetClass()); |
| 8202 | bool reordering = __ SetReorder(false); |
| 8203 | __ Bind(&info->high_label); |
| 8204 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8205 | __ SetReorder(reordering); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8206 | GenerateGcRootFieldLoad(cls, |
| 8207 | out_loc, |
| 8208 | out, |
| 8209 | /* placeholder */ 0x5678, |
| 8210 | read_barrier_option, |
| 8211 | &info->low_label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8212 | break; |
| 8213 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8214 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 8215 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8216 | LOG(FATAL) << "UNREACHABLE"; |
| 8217 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8218 | } |
| 8219 | |
| 8220 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 8221 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8222 | SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS( |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8223 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8224 | codegen_->AddSlowPath(slow_path); |
| 8225 | if (generate_null_check) { |
| 8226 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 8227 | } |
| 8228 | if (cls->MustGenerateClinitCheck()) { |
| 8229 | GenerateClassInitializationCheck(slow_path, out); |
| 8230 | } else { |
| 8231 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8232 | } |
| 8233 | } |
| 8234 | } |
| 8235 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 8236 | void LocationsBuilderMIPS::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 8237 | InvokeRuntimeCallingConvention calling_convention; |
| 8238 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 8239 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, loc, loc); |
| 8240 | } |
| 8241 | |
| 8242 | void InstructionCodeGeneratorMIPS::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 8243 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 8244 | } |
| 8245 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 8246 | void LocationsBuilderMIPS::VisitLoadMethodType(HLoadMethodType* load) { |
| 8247 | InvokeRuntimeCallingConvention calling_convention; |
| 8248 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 8249 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, loc, loc); |
| 8250 | } |
| 8251 | |
| 8252 | void InstructionCodeGeneratorMIPS::VisitLoadMethodType(HLoadMethodType* load) { |
| 8253 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 8254 | } |
| 8255 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8256 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8257 | return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8258 | } |
| 8259 | |
| 8260 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { |
| 8261 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8262 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8263 | locations->SetOut(Location::RequiresRegister()); |
| 8264 | } |
| 8265 | |
| 8266 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { |
| 8267 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
| 8268 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 8269 | } |
| 8270 | |
| 8271 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8272 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8273 | } |
| 8274 | |
| 8275 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 8276 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
| 8277 | } |
| 8278 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8279 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 8280 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8281 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8282 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8283 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8284 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8285 | switch (load_kind) { |
| 8286 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8287 | case HLoadString::LoadKind::kBootImageAddress: |
| 8288 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8289 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8290 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8291 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8292 | break; |
| 8293 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8294 | if (has_irreducible_loops) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 8295 | if (load_kind != HLoadString::LoadKind::kBootImageAddress) { |
| 8296 | codegen_->ClobberRA(); |
| 8297 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8298 | break; |
| 8299 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8300 | FALLTHROUGH_INTENDED; |
| 8301 | // We need an extra register for PC-relative dex cache accesses. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8302 | case HLoadString::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8303 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8304 | break; |
| 8305 | default: |
| 8306 | break; |
| 8307 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8308 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8309 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8310 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8311 | } else { |
| 8312 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8313 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 8314 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 8315 | // Rely on the pResolveString and marking to save everything we need. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8316 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 8317 | InvokeRuntimeCallingConvention calling_convention; |
| 8318 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8319 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 8320 | } else { |
| 8321 | // For non-Baker read barriers we have a temp-clobbering call. |
| 8322 | } |
| 8323 | } |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8324 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8325 | } |
| 8326 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8327 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 8328 | // move. |
| 8329 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8330 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8331 | LocationSummary* locations = load->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8332 | Location out_loc = locations->Out(); |
| 8333 | Register out = out_loc.AsRegister<Register>(); |
| 8334 | Register base_or_current_method_reg; |
| 8335 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8336 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8337 | switch (load_kind) { |
| 8338 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8339 | case HLoadString::LoadKind::kBootImageAddress: |
| 8340 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8341 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8342 | case HLoadString::LoadKind::kBssEntry: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8343 | base_or_current_method_reg = |
| 8344 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8345 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8346 | default: |
| 8347 | base_or_current_method_reg = ZERO; |
| 8348 | break; |
| 8349 | } |
| 8350 | |
| 8351 | switch (load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8352 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8353 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8354 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8355 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8356 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8357 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8358 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8359 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 8360 | base_or_current_method_reg); |
| 8361 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8362 | return; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8363 | } |
| 8364 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8365 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 8366 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 8367 | DCHECK_NE(address, 0u); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8368 | if (isR6 || !has_irreducible_loops) { |
| 8369 | __ LoadLiteral(out, |
| 8370 | base_or_current_method_reg, |
| 8371 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 8372 | } else { |
| 8373 | __ LoadConst32(out, address); |
| 8374 | } |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8375 | return; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8376 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8377 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8378 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8379 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(load); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8380 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8381 | codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8382 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8383 | codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8384 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8385 | out, |
| 8386 | base_or_current_method_reg); |
| 8387 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
| 8388 | return; |
| 8389 | } |
| 8390 | case HLoadString::LoadKind::kBssEntry: { |
| 8391 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 8392 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
| 8393 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| 8394 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8395 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8396 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8397 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8398 | base_or_current_method_reg); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8399 | GenerateGcRootFieldLoad(load, |
| 8400 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8401 | out, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8402 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8403 | kCompilerReadBarrierOption, |
| 8404 | &info_low->label); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8405 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8406 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8407 | codegen_->AddSlowPath(slow_path); |
| 8408 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 8409 | __ Bind(slow_path->GetExitLabel()); |
| 8410 | return; |
| 8411 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8412 | case HLoadString::LoadKind::kJitTableAddress: { |
| 8413 | CodeGeneratorMIPS::JitPatchInfo* info = |
| 8414 | codegen_->NewJitRootStringPatch(load->GetDexFile(), |
| 8415 | load->GetStringIndex(), |
| 8416 | load->GetString()); |
| 8417 | bool reordering = __ SetReorder(false); |
| 8418 | __ Bind(&info->high_label); |
| 8419 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8420 | __ SetReorder(reordering); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8421 | GenerateGcRootFieldLoad(load, |
| 8422 | out_loc, |
| 8423 | out, |
| 8424 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8425 | kCompilerReadBarrierOption, |
| 8426 | &info->low_label); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8427 | return; |
| 8428 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8429 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8430 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8431 | } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 8432 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8433 | // 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] | 8434 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8435 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8436 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8437 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8438 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 8439 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8440 | } |
| 8441 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8442 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8443 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8444 | locations->SetOut(Location::ConstantLocation(constant)); |
| 8445 | } |
| 8446 | |
| 8447 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 8448 | // Will be generated at use site. |
| 8449 | } |
| 8450 | |
| 8451 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8452 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8453 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8454 | InvokeRuntimeCallingConvention calling_convention; |
| 8455 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8456 | } |
| 8457 | |
| 8458 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8459 | if (instruction->IsEnter()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8460 | codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8461 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8462 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8463 | codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8464 | } |
| 8465 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8466 | } |
| 8467 | |
| 8468 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { |
| 8469 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8470 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8471 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8472 | case DataType::Type::kInt32: |
| 8473 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8474 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8475 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8476 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8477 | break; |
| 8478 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8479 | case DataType::Type::kFloat32: |
| 8480 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8481 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8482 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 8483 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8484 | break; |
| 8485 | |
| 8486 | default: |
| 8487 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 8488 | } |
| 8489 | } |
| 8490 | |
| 8491 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8492 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8493 | LocationSummary* locations = instruction->GetLocations(); |
| 8494 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 8495 | |
| 8496 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8497 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8498 | Register dst = locations->Out().AsRegister<Register>(); |
| 8499 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 8500 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 8501 | |
| 8502 | if (isR6) { |
| 8503 | __ MulR6(dst, lhs, rhs); |
| 8504 | } else { |
| 8505 | __ MulR2(dst, lhs, rhs); |
| 8506 | } |
| 8507 | break; |
| 8508 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8509 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8510 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8511 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8512 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8513 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8514 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 8515 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 8516 | |
| 8517 | // Extra checks to protect caused by the existance of A1_A2. |
| 8518 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: |
| 8519 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). |
| 8520 | DCHECK_NE(dst_high, lhs_low); |
| 8521 | DCHECK_NE(dst_high, rhs_low); |
| 8522 | |
| 8523 | // A_B * C_D |
| 8524 | // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ] |
| 8525 | // dst_lo: [ low(B*D) ] |
| 8526 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. |
| 8527 | |
| 8528 | if (isR6) { |
| 8529 | __ MulR6(TMP, lhs_high, rhs_low); |
| 8530 | __ MulR6(dst_high, lhs_low, rhs_high); |
| 8531 | __ Addu(dst_high, dst_high, TMP); |
| 8532 | __ MuhuR6(TMP, lhs_low, rhs_low); |
| 8533 | __ Addu(dst_high, dst_high, TMP); |
| 8534 | __ MulR6(dst_low, lhs_low, rhs_low); |
| 8535 | } else { |
| 8536 | __ MulR2(TMP, lhs_high, rhs_low); |
| 8537 | __ MulR2(dst_high, lhs_low, rhs_high); |
| 8538 | __ Addu(dst_high, dst_high, TMP); |
| 8539 | __ MultuR2(lhs_low, rhs_low); |
| 8540 | __ Mfhi(TMP); |
| 8541 | __ Addu(dst_high, dst_high, TMP); |
| 8542 | __ Mflo(dst_low); |
| 8543 | } |
| 8544 | break; |
| 8545 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8546 | case DataType::Type::kFloat32: |
| 8547 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8548 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8549 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8550 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8551 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8552 | __ MulS(dst, lhs, rhs); |
| 8553 | } else { |
| 8554 | __ MulD(dst, lhs, rhs); |
| 8555 | } |
| 8556 | break; |
| 8557 | } |
| 8558 | default: |
| 8559 | LOG(FATAL) << "Unexpected mul type " << type; |
| 8560 | } |
| 8561 | } |
| 8562 | |
| 8563 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { |
| 8564 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8565 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8566 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8567 | case DataType::Type::kInt32: |
| 8568 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8569 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8570 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8571 | break; |
| 8572 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8573 | case DataType::Type::kFloat32: |
| 8574 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8575 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8576 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8577 | break; |
| 8578 | |
| 8579 | default: |
| 8580 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 8581 | } |
| 8582 | } |
| 8583 | |
| 8584 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8585 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8586 | LocationSummary* locations = instruction->GetLocations(); |
| 8587 | |
| 8588 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8589 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8590 | Register dst = locations->Out().AsRegister<Register>(); |
| 8591 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8592 | __ Subu(dst, ZERO, src); |
| 8593 | break; |
| 8594 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8595 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8596 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8597 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8598 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8599 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8600 | __ Subu(dst_low, ZERO, src_low); |
| 8601 | __ Sltu(TMP, ZERO, dst_low); |
| 8602 | __ Subu(dst_high, ZERO, src_high); |
| 8603 | __ Subu(dst_high, dst_high, TMP); |
| 8604 | break; |
| 8605 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8606 | case DataType::Type::kFloat32: |
| 8607 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8608 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8609 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8610 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8611 | __ NegS(dst, src); |
| 8612 | } else { |
| 8613 | __ NegD(dst, src); |
| 8614 | } |
| 8615 | break; |
| 8616 | } |
| 8617 | default: |
| 8618 | LOG(FATAL) << "Unexpected neg type " << type; |
| 8619 | } |
| 8620 | } |
| 8621 | |
| 8622 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8623 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8624 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8625 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8626 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8627 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8628 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8629 | } |
| 8630 | |
| 8631 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8632 | // Note: if heap poisoning is enabled, the entry point takes care |
| 8633 | // of poisoning the reference. |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8634 | QuickEntrypointEnum entrypoint = |
| 8635 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 8636 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8637 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8638 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8639 | } |
| 8640 | |
| 8641 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8642 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8643 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8644 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8645 | if (instruction->IsStringAlloc()) { |
| 8646 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 8647 | } else { |
| 8648 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8649 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8650 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8651 | } |
| 8652 | |
| 8653 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8654 | // Note: if heap poisoning is enabled, the entry point takes care |
| 8655 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8656 | if (instruction->IsStringAlloc()) { |
| 8657 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 8658 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8659 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8660 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 8661 | __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value()); |
| 8662 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 8663 | __ NopIfNoReordering(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8664 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 8665 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8666 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 8667 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8668 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8669 | } |
| 8670 | |
| 8671 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8672 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8673 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8674 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8675 | } |
| 8676 | |
| 8677 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8678 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8679 | LocationSummary* locations = instruction->GetLocations(); |
| 8680 | |
| 8681 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8682 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8683 | Register dst = locations->Out().AsRegister<Register>(); |
| 8684 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8685 | __ Nor(dst, src, ZERO); |
| 8686 | break; |
| 8687 | } |
| 8688 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8689 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8690 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8691 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8692 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8693 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8694 | __ Nor(dst_high, src_high, ZERO); |
| 8695 | __ Nor(dst_low, src_low, ZERO); |
| 8696 | break; |
| 8697 | } |
| 8698 | |
| 8699 | default: |
| 8700 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 8701 | } |
| 8702 | } |
| 8703 | |
| 8704 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8705 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8706 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8707 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8708 | } |
| 8709 | |
| 8710 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 8711 | LocationSummary* locations = instruction->GetLocations(); |
| 8712 | __ Xori(locations->Out().AsRegister<Register>(), |
| 8713 | locations->InAt(0).AsRegister<Register>(), |
| 8714 | 1); |
| 8715 | } |
| 8716 | |
| 8717 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 8718 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 8719 | locations->SetInAt(0, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8720 | } |
| 8721 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8722 | void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 8723 | if (CanMoveNullCheckToUser(instruction)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8724 | return; |
| 8725 | } |
| 8726 | Location obj = instruction->GetLocations()->InAt(0); |
| 8727 | |
| 8728 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8729 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8730 | } |
| 8731 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8732 | void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8733 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) NullCheckSlowPathMIPS(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8734 | AddSlowPath(slow_path); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8735 | |
| 8736 | Location obj = instruction->GetLocations()->InAt(0); |
| 8737 | |
| 8738 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8739 | } |
| 8740 | |
| 8741 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8742 | codegen_->GenerateNullCheck(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8743 | } |
| 8744 | |
| 8745 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { |
| 8746 | HandleBinaryOp(instruction); |
| 8747 | } |
| 8748 | |
| 8749 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { |
| 8750 | HandleBinaryOp(instruction); |
| 8751 | } |
| 8752 | |
| 8753 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 8754 | LOG(FATAL) << "Unreachable"; |
| 8755 | } |
| 8756 | |
| 8757 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 8758 | if (instruction->GetNext()->IsSuspendCheck() && |
| 8759 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 8760 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 8761 | // The back edge will generate the suspend check. |
| 8762 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 8763 | } |
| 8764 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8765 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 8766 | } |
| 8767 | |
| 8768 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8769 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8770 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 8771 | if (location.IsStackSlot()) { |
| 8772 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8773 | } else if (location.IsDoubleStackSlot()) { |
| 8774 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8775 | } |
| 8776 | locations->SetOut(location); |
| 8777 | } |
| 8778 | |
| 8779 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction |
| 8780 | ATTRIBUTE_UNUSED) { |
| 8781 | // Nothing to do, the parameter is already at its location. |
| 8782 | } |
| 8783 | |
| 8784 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 8785 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8786 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8787 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 8788 | } |
| 8789 | |
| 8790 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction |
| 8791 | ATTRIBUTE_UNUSED) { |
| 8792 | // Nothing to do, the method is already at its location. |
| 8793 | } |
| 8794 | |
| 8795 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8796 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 8797 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8798 | locations->SetInAt(i, Location::Any()); |
| 8799 | } |
| 8800 | locations->SetOut(Location::Any()); |
| 8801 | } |
| 8802 | |
| 8803 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 8804 | LOG(FATAL) << "Unreachable"; |
| 8805 | } |
| 8806 | |
| 8807 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8808 | DataType::Type type = rem->GetResultType(); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8809 | bool call_rem; |
| 8810 | if ((type == DataType::Type::kInt64) && rem->InputAt(1)->IsConstant()) { |
| 8811 | int64_t imm = CodeGenerator::GetInt64ValueOf(rem->InputAt(1)->AsConstant()); |
| 8812 | call_rem = (imm != 0) && !IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm))); |
| 8813 | } else { |
| 8814 | call_rem = (type != DataType::Type::kInt32); |
| 8815 | } |
| 8816 | LocationSummary::CallKind call_kind = call_rem |
| 8817 | ? LocationSummary::kCallOnMainOnly |
| 8818 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8819 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8820 | |
| 8821 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8822 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8823 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8824 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8825 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8826 | break; |
| 8827 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8828 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8829 | if (call_rem) { |
| 8830 | InvokeRuntimeCallingConvention calling_convention; |
| 8831 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 8832 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 8833 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 8834 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 8835 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8836 | } else { |
| 8837 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8838 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 8839 | locations->SetOut(Location::RequiresRegister()); |
| 8840 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8841 | break; |
| 8842 | } |
| 8843 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8844 | case DataType::Type::kFloat32: |
| 8845 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8846 | InvokeRuntimeCallingConvention calling_convention; |
| 8847 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 8848 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 8849 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8850 | break; |
| 8851 | } |
| 8852 | |
| 8853 | default: |
| 8854 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8855 | } |
| 8856 | } |
| 8857 | |
| 8858 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8859 | DataType::Type type = instruction->GetType(); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8860 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8861 | |
| 8862 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8863 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8864 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8865 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8866 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8867 | if (locations->InAt(1).IsConstant()) { |
| 8868 | int64_t imm = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue(); |
| 8869 | if (imm == 0) { |
| 8870 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 8871 | } else if (imm == 1 || imm == -1) { |
| 8872 | DivRemOneOrMinusOne(instruction); |
| 8873 | } else { |
| 8874 | DCHECK(IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm)))); |
| 8875 | DivRemByPowerOfTwo(instruction); |
| 8876 | } |
| 8877 | } else { |
| 8878 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
| 8879 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 8880 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8881 | break; |
| 8882 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8883 | case DataType::Type::kFloat32: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8884 | codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8885 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8886 | break; |
| 8887 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8888 | case DataType::Type::kFloat64: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8889 | codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8890 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8891 | break; |
| 8892 | } |
| 8893 | default: |
| 8894 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8895 | } |
| 8896 | } |
| 8897 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 8898 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 8899 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 8900 | switch (minmax->GetResultType()) { |
| 8901 | case DataType::Type::kInt32: |
| 8902 | case DataType::Type::kInt64: |
| 8903 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8904 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8905 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8906 | break; |
| 8907 | case DataType::Type::kFloat32: |
| 8908 | case DataType::Type::kFloat64: |
| 8909 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8910 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 8911 | locations->SetOut(Location::RequiresFpuRegister(), Location::kOutputOverlap); |
| 8912 | break; |
| 8913 | default: |
| 8914 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 8915 | } |
| 8916 | } |
| 8917 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 8918 | void InstructionCodeGeneratorMIPS::GenerateMinMaxInt(LocationSummary* locations, |
| 8919 | bool is_min, |
| 8920 | bool isR6, |
| 8921 | DataType::Type type) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 8922 | if (isR6) { |
| 8923 | // Some architectures, such as ARM and MIPS (prior to r6), have a |
| 8924 | // conditional move instruction which only changes the target |
| 8925 | // (output) register if the condition is true (MIPS prior to r6 had |
| 8926 | // MOVF, MOVT, MOVN, and MOVZ). The SELEQZ and SELNEZ instructions |
| 8927 | // always change the target (output) register. If the condition is |
| 8928 | // true the output register gets the contents of the "rs" register; |
| 8929 | // otherwise, the output register is set to zero. One consequence |
| 8930 | // of this is that to implement something like "rd = c==0 ? rs : rt" |
| 8931 | // MIPS64r6 needs to use a pair of SELEQZ/SELNEZ instructions. |
| 8932 | // After executing this pair of instructions one of the output |
| 8933 | // registers from the pair will necessarily contain zero. Then the |
| 8934 | // code ORs the output registers from the SELEQZ/SELNEZ instructions |
| 8935 | // to get the final result. |
| 8936 | // |
| 8937 | // The initial test to see if the output register is same as the |
| 8938 | // first input register is needed to make sure that value in the |
| 8939 | // first input register isn't clobbered before we've finished |
| 8940 | // computing the output value. The logic in the corresponding else |
| 8941 | // clause performs the same task but makes sure the second input |
| 8942 | // register isn't clobbered in the event that it's the same register |
| 8943 | // as the output register; the else clause also handles the case |
| 8944 | // where the output register is distinct from both the first, and the |
| 8945 | // second input registers. |
| 8946 | if (type == DataType::Type::kInt64) { |
| 8947 | Register a_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8948 | Register a_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8949 | Register b_lo = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 8950 | Register b_hi = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 8951 | Register out_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 8952 | Register out_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 8953 | |
| 8954 | MipsLabel compare_done; |
| 8955 | |
| 8956 | if (a_lo == b_lo) { |
| 8957 | if (out_lo != a_lo) { |
| 8958 | __ Move(out_lo, a_lo); |
| 8959 | __ Move(out_hi, a_hi); |
| 8960 | } |
| 8961 | } else { |
| 8962 | __ Slt(TMP, b_hi, a_hi); |
| 8963 | __ Bne(b_hi, a_hi, &compare_done); |
| 8964 | |
| 8965 | __ Sltu(TMP, b_lo, a_lo); |
| 8966 | |
| 8967 | __ Bind(&compare_done); |
| 8968 | |
| 8969 | if (is_min) { |
| 8970 | __ Seleqz(AT, a_lo, TMP); |
| 8971 | __ Selnez(out_lo, b_lo, TMP); // Safe even if out_lo == a_lo/b_lo |
| 8972 | // because at this point we're |
| 8973 | // done using a_lo/b_lo. |
| 8974 | } else { |
| 8975 | __ Selnez(AT, a_lo, TMP); |
| 8976 | __ Seleqz(out_lo, b_lo, TMP); // ditto |
| 8977 | } |
| 8978 | __ Or(out_lo, out_lo, AT); |
| 8979 | if (is_min) { |
| 8980 | __ Seleqz(AT, a_hi, TMP); |
| 8981 | __ Selnez(out_hi, b_hi, TMP); // ditto but for out_hi & a_hi/b_hi |
| 8982 | } else { |
| 8983 | __ Selnez(AT, a_hi, TMP); |
| 8984 | __ Seleqz(out_hi, b_hi, TMP); // ditto but for out_hi & a_hi/b_hi |
| 8985 | } |
| 8986 | __ Or(out_hi, out_hi, AT); |
| 8987 | } |
| 8988 | } else { |
| 8989 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 8990 | Register a = locations->InAt(0).AsRegister<Register>(); |
| 8991 | Register b = locations->InAt(1).AsRegister<Register>(); |
| 8992 | Register out = locations->Out().AsRegister<Register>(); |
| 8993 | |
| 8994 | if (a == b) { |
| 8995 | if (out != a) { |
| 8996 | __ Move(out, a); |
| 8997 | } |
| 8998 | } else { |
| 8999 | __ Slt(AT, b, a); |
| 9000 | if (is_min) { |
| 9001 | __ Seleqz(TMP, a, AT); |
| 9002 | __ Selnez(AT, b, AT); |
| 9003 | } else { |
| 9004 | __ Selnez(TMP, a, AT); |
| 9005 | __ Seleqz(AT, b, AT); |
| 9006 | } |
| 9007 | __ Or(out, TMP, AT); |
| 9008 | } |
| 9009 | } |
| 9010 | } else { // !isR6 |
| 9011 | if (type == DataType::Type::kInt64) { |
| 9012 | Register a_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 9013 | Register a_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 9014 | Register b_lo = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 9015 | Register b_hi = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 9016 | Register out_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 9017 | Register out_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 9018 | |
| 9019 | MipsLabel compare_done; |
| 9020 | |
| 9021 | if (a_lo == b_lo) { |
| 9022 | if (out_lo != a_lo) { |
| 9023 | __ Move(out_lo, a_lo); |
| 9024 | __ Move(out_hi, a_hi); |
| 9025 | } |
| 9026 | } else { |
| 9027 | __ Slt(TMP, a_hi, b_hi); |
| 9028 | __ Bne(a_hi, b_hi, &compare_done); |
| 9029 | |
| 9030 | __ Sltu(TMP, a_lo, b_lo); |
| 9031 | |
| 9032 | __ Bind(&compare_done); |
| 9033 | |
| 9034 | if (is_min) { |
| 9035 | if (out_lo != a_lo) { |
| 9036 | __ Movn(out_hi, a_hi, TMP); |
| 9037 | __ Movn(out_lo, a_lo, TMP); |
| 9038 | } |
| 9039 | if (out_lo != b_lo) { |
| 9040 | __ Movz(out_hi, b_hi, TMP); |
| 9041 | __ Movz(out_lo, b_lo, TMP); |
| 9042 | } |
| 9043 | } else { |
| 9044 | if (out_lo != a_lo) { |
| 9045 | __ Movz(out_hi, a_hi, TMP); |
| 9046 | __ Movz(out_lo, a_lo, TMP); |
| 9047 | } |
| 9048 | if (out_lo != b_lo) { |
| 9049 | __ Movn(out_hi, b_hi, TMP); |
| 9050 | __ Movn(out_lo, b_lo, TMP); |
| 9051 | } |
| 9052 | } |
| 9053 | } |
| 9054 | } else { |
| 9055 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 9056 | Register a = locations->InAt(0).AsRegister<Register>(); |
| 9057 | Register b = locations->InAt(1).AsRegister<Register>(); |
| 9058 | Register out = locations->Out().AsRegister<Register>(); |
| 9059 | |
| 9060 | if (a == b) { |
| 9061 | if (out != a) { |
| 9062 | __ Move(out, a); |
| 9063 | } |
| 9064 | } else { |
| 9065 | __ Slt(AT, a, b); |
| 9066 | if (is_min) { |
| 9067 | if (out != a) { |
| 9068 | __ Movn(out, a, AT); |
| 9069 | } |
| 9070 | if (out != b) { |
| 9071 | __ Movz(out, b, AT); |
| 9072 | } |
| 9073 | } else { |
| 9074 | if (out != a) { |
| 9075 | __ Movz(out, a, AT); |
| 9076 | } |
| 9077 | if (out != b) { |
| 9078 | __ Movn(out, b, AT); |
| 9079 | } |
| 9080 | } |
| 9081 | } |
| 9082 | } |
| 9083 | } |
| 9084 | } |
| 9085 | |
| 9086 | void InstructionCodeGeneratorMIPS::GenerateMinMaxFP(LocationSummary* locations, |
| 9087 | bool is_min, |
| 9088 | bool isR6, |
| 9089 | DataType::Type type) { |
| 9090 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 9091 | FRegister a = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9092 | FRegister b = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 9093 | |
| 9094 | if (isR6) { |
| 9095 | MipsLabel noNaNs; |
| 9096 | MipsLabel done; |
| 9097 | FRegister ftmp = ((out != a) && (out != b)) ? out : FTMP; |
| 9098 | |
| 9099 | // When Java computes min/max it prefers a NaN to a number; the |
| 9100 | // behavior of MIPSR6 is to prefer numbers to NaNs, i.e., if one of |
| 9101 | // the inputs is a NaN and the other is a valid number, the MIPS |
| 9102 | // instruction will return the number; Java wants the NaN value |
| 9103 | // returned. This is why there is extra logic preceding the use of |
| 9104 | // the MIPS min.fmt/max.fmt instructions. If either a, or b holds a |
| 9105 | // NaN, return the NaN, otherwise return the min/max. |
| 9106 | if (type == DataType::Type::kFloat64) { |
| 9107 | __ CmpUnD(FTMP, a, b); |
| 9108 | __ Bc1eqz(FTMP, &noNaNs); |
| 9109 | |
| 9110 | // One of the inputs is a NaN |
| 9111 | __ CmpEqD(ftmp, a, a); |
| 9112 | // If a == a then b is the NaN, otherwise a is the NaN. |
| 9113 | __ SelD(ftmp, a, b); |
| 9114 | |
| 9115 | if (ftmp != out) { |
| 9116 | __ MovD(out, ftmp); |
| 9117 | } |
| 9118 | |
| 9119 | __ B(&done); |
| 9120 | |
| 9121 | __ Bind(&noNaNs); |
| 9122 | |
| 9123 | if (is_min) { |
| 9124 | __ MinD(out, a, b); |
| 9125 | } else { |
| 9126 | __ MaxD(out, a, b); |
| 9127 | } |
| 9128 | } else { |
| 9129 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 9130 | __ CmpUnS(FTMP, a, b); |
| 9131 | __ Bc1eqz(FTMP, &noNaNs); |
| 9132 | |
| 9133 | // One of the inputs is a NaN |
| 9134 | __ CmpEqS(ftmp, a, a); |
| 9135 | // If a == a then b is the NaN, otherwise a is the NaN. |
| 9136 | __ SelS(ftmp, a, b); |
| 9137 | |
| 9138 | if (ftmp != out) { |
| 9139 | __ MovS(out, ftmp); |
| 9140 | } |
| 9141 | |
| 9142 | __ B(&done); |
| 9143 | |
| 9144 | __ Bind(&noNaNs); |
| 9145 | |
| 9146 | if (is_min) { |
| 9147 | __ MinS(out, a, b); |
| 9148 | } else { |
| 9149 | __ MaxS(out, a, b); |
| 9150 | } |
| 9151 | } |
| 9152 | |
| 9153 | __ Bind(&done); |
| 9154 | |
| 9155 | } else { // !isR6 |
| 9156 | MipsLabel ordered; |
| 9157 | MipsLabel compare; |
| 9158 | MipsLabel select; |
| 9159 | MipsLabel done; |
| 9160 | |
| 9161 | if (type == DataType::Type::kFloat64) { |
| 9162 | __ CunD(a, b); |
| 9163 | } else { |
| 9164 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 9165 | __ CunS(a, b); |
| 9166 | } |
| 9167 | __ Bc1f(&ordered); |
| 9168 | |
| 9169 | // a or b (or both) is a NaN. Return one, which is a NaN. |
| 9170 | if (type == DataType::Type::kFloat64) { |
| 9171 | __ CeqD(b, b); |
| 9172 | } else { |
| 9173 | __ CeqS(b, b); |
| 9174 | } |
| 9175 | __ B(&select); |
| 9176 | |
| 9177 | __ Bind(&ordered); |
| 9178 | |
| 9179 | // Neither is a NaN. |
| 9180 | // a == b? (-0.0 compares equal with +0.0) |
| 9181 | // If equal, handle zeroes, else compare further. |
| 9182 | if (type == DataType::Type::kFloat64) { |
| 9183 | __ CeqD(a, b); |
| 9184 | } else { |
| 9185 | __ CeqS(a, b); |
| 9186 | } |
| 9187 | __ Bc1f(&compare); |
| 9188 | |
| 9189 | // a == b either bit for bit or one is -0.0 and the other is +0.0. |
| 9190 | if (type == DataType::Type::kFloat64) { |
| 9191 | __ MoveFromFpuHigh(TMP, a); |
| 9192 | __ MoveFromFpuHigh(AT, b); |
| 9193 | } else { |
| 9194 | __ Mfc1(TMP, a); |
| 9195 | __ Mfc1(AT, b); |
| 9196 | } |
| 9197 | |
| 9198 | if (is_min) { |
| 9199 | // -0.0 prevails over +0.0. |
| 9200 | __ Or(TMP, TMP, AT); |
| 9201 | } else { |
| 9202 | // +0.0 prevails over -0.0. |
| 9203 | __ And(TMP, TMP, AT); |
| 9204 | } |
| 9205 | |
| 9206 | if (type == DataType::Type::kFloat64) { |
| 9207 | __ Mfc1(AT, a); |
| 9208 | __ Mtc1(AT, out); |
| 9209 | __ MoveToFpuHigh(TMP, out); |
| 9210 | } else { |
| 9211 | __ Mtc1(TMP, out); |
| 9212 | } |
| 9213 | __ B(&done); |
| 9214 | |
| 9215 | __ Bind(&compare); |
| 9216 | |
| 9217 | if (type == DataType::Type::kFloat64) { |
| 9218 | if (is_min) { |
| 9219 | // return (a <= b) ? a : b; |
| 9220 | __ ColeD(a, b); |
| 9221 | } else { |
| 9222 | // return (a >= b) ? a : b; |
| 9223 | __ ColeD(b, a); // b <= a |
| 9224 | } |
| 9225 | } else { |
| 9226 | if (is_min) { |
| 9227 | // return (a <= b) ? a : b; |
| 9228 | __ ColeS(a, b); |
| 9229 | } else { |
| 9230 | // return (a >= b) ? a : b; |
| 9231 | __ ColeS(b, a); // b <= a |
| 9232 | } |
| 9233 | } |
| 9234 | |
| 9235 | __ Bind(&select); |
| 9236 | |
| 9237 | if (type == DataType::Type::kFloat64) { |
| 9238 | __ MovtD(out, a); |
| 9239 | __ MovfD(out, b); |
| 9240 | } else { |
| 9241 | __ MovtS(out, a); |
| 9242 | __ MovfS(out, b); |
| 9243 | } |
| 9244 | |
| 9245 | __ Bind(&done); |
| 9246 | } |
| 9247 | } |
| 9248 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 9249 | void InstructionCodeGeneratorMIPS::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 9250 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 9251 | DataType::Type type = minmax->GetResultType(); |
| 9252 | switch (type) { |
| 9253 | case DataType::Type::kInt32: |
| 9254 | case DataType::Type::kInt64: |
| 9255 | GenerateMinMaxInt(minmax->GetLocations(), is_min, isR6, type); |
| 9256 | break; |
| 9257 | case DataType::Type::kFloat32: |
| 9258 | case DataType::Type::kFloat64: |
| 9259 | GenerateMinMaxFP(minmax->GetLocations(), is_min, isR6, type); |
| 9260 | break; |
| 9261 | default: |
| 9262 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 9263 | } |
| 9264 | } |
| 9265 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 9266 | void LocationsBuilderMIPS::VisitMin(HMin* min) { |
| 9267 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 9268 | } |
| 9269 | |
| 9270 | void InstructionCodeGeneratorMIPS::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 9271 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 9272 | } |
| 9273 | |
| 9274 | void LocationsBuilderMIPS::VisitMax(HMax* max) { |
| 9275 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 9276 | } |
| 9277 | |
| 9278 | void InstructionCodeGeneratorMIPS::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 9279 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 9280 | } |
| 9281 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 9282 | void LocationsBuilderMIPS::VisitAbs(HAbs* abs) { |
| 9283 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 9284 | switch (abs->GetResultType()) { |
| 9285 | case DataType::Type::kInt32: |
| 9286 | case DataType::Type::kInt64: |
| 9287 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9288 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9289 | break; |
| 9290 | case DataType::Type::kFloat32: |
| 9291 | case DataType::Type::kFloat64: |
| 9292 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 9293 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 9294 | break; |
| 9295 | default: |
| 9296 | LOG(FATAL) << "Unexpected abs type " << abs->GetResultType(); |
| 9297 | } |
| 9298 | } |
| 9299 | |
| 9300 | void InstructionCodeGeneratorMIPS::GenerateAbsFP(LocationSummary* locations, |
| 9301 | DataType::Type type, |
| 9302 | bool isR2OrNewer, |
| 9303 | bool isR6) { |
| 9304 | FRegister in = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9305 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 9306 | |
| 9307 | // Note, as a "quality of implementation", rather than pure "spec compliance", we require that |
| 9308 | // Math.abs() clears the sign bit (but changes nothing else) for all numbers, including NaN |
| 9309 | // (signaling NaN may become quiet though). |
| 9310 | // |
| 9311 | // The ABS.fmt instructions (abs.s and abs.d) do exactly that when NAN2008=1 (R6). For this case, |
| 9312 | // both regular floating point numbers and NAN values are treated alike, only the sign bit is |
| 9313 | // affected by this instruction. |
| 9314 | // But when NAN2008=0 (R2 and before), the ABS.fmt instructions can't be used. For this case, any |
| 9315 | // NaN operand signals invalid operation. This means that other bits (not just sign bit) might be |
| 9316 | // changed when doing abs(NaN). Because of that, we clear sign bit in a different way. |
| 9317 | if (isR6) { |
| 9318 | if (type == DataType::Type::kFloat64) { |
| 9319 | __ AbsD(out, in); |
| 9320 | } else { |
| 9321 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 9322 | __ AbsS(out, in); |
| 9323 | } |
| 9324 | } else { |
| 9325 | if (type == DataType::Type::kFloat64) { |
| 9326 | if (in != out) { |
| 9327 | __ MovD(out, in); |
| 9328 | } |
| 9329 | __ MoveFromFpuHigh(TMP, in); |
| 9330 | // ins instruction is not available for R1. |
| 9331 | if (isR2OrNewer) { |
| 9332 | __ Ins(TMP, ZERO, 31, 1); |
| 9333 | } else { |
| 9334 | __ Sll(TMP, TMP, 1); |
| 9335 | __ Srl(TMP, TMP, 1); |
| 9336 | } |
| 9337 | __ MoveToFpuHigh(TMP, out); |
| 9338 | } else { |
| 9339 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 9340 | __ Mfc1(TMP, in); |
| 9341 | // ins instruction is not available for R1. |
| 9342 | if (isR2OrNewer) { |
| 9343 | __ Ins(TMP, ZERO, 31, 1); |
| 9344 | } else { |
| 9345 | __ Sll(TMP, TMP, 1); |
| 9346 | __ Srl(TMP, TMP, 1); |
| 9347 | } |
| 9348 | __ Mtc1(TMP, out); |
| 9349 | } |
| 9350 | } |
| 9351 | } |
| 9352 | |
| 9353 | void InstructionCodeGeneratorMIPS::VisitAbs(HAbs* abs) { |
| 9354 | LocationSummary* locations = abs->GetLocations(); |
| 9355 | bool isR2OrNewer = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
| 9356 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 9357 | switch (abs->GetResultType()) { |
| 9358 | case DataType::Type::kInt32: { |
| 9359 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 9360 | Register out = locations->Out().AsRegister<Register>(); |
| 9361 | __ Sra(AT, in, 31); |
| 9362 | __ Xor(out, in, AT); |
| 9363 | __ Subu(out, out, AT); |
| 9364 | break; |
| 9365 | } |
| 9366 | case DataType::Type::kInt64: { |
| 9367 | Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 9368 | Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 9369 | Register out_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 9370 | Register out_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 9371 | // The comments in this section show the analogous operations which would |
| 9372 | // be performed if we had 64-bit registers "in", and "out". |
| 9373 | // __ Dsra32(AT, in, 31); |
| 9374 | __ Sra(AT, in_hi, 31); |
| 9375 | // __ Xor(out, in, AT); |
| 9376 | __ Xor(TMP, in_lo, AT); |
| 9377 | __ Xor(out_hi, in_hi, AT); |
| 9378 | // __ Dsubu(out, out, AT); |
| 9379 | __ Subu(out_lo, TMP, AT); |
| 9380 | __ Sltu(TMP, out_lo, TMP); |
| 9381 | __ Addu(out_hi, out_hi, TMP); |
| 9382 | break; |
| 9383 | } |
| 9384 | case DataType::Type::kFloat32: |
| 9385 | case DataType::Type::kFloat64: |
| 9386 | GenerateAbsFP(locations, abs->GetResultType(), isR2OrNewer, isR6); |
| 9387 | break; |
| 9388 | default: |
| 9389 | LOG(FATAL) << "Unexpected abs type " << abs->GetResultType(); |
| 9390 | } |
| 9391 | } |
| 9392 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 9393 | void LocationsBuilderMIPS::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 9394 | constructor_fence->SetLocations(nullptr); |
| 9395 | } |
| 9396 | |
| 9397 | void InstructionCodeGeneratorMIPS::VisitConstructorFence( |
| 9398 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 9399 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 9400 | } |
| 9401 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9402 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 9403 | memory_barrier->SetLocations(nullptr); |
| 9404 | } |
| 9405 | |
| 9406 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 9407 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 9408 | } |
| 9409 | |
| 9410 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9411 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9412 | DataType::Type return_type = ret->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9413 | locations->SetInAt(0, MipsReturnLocation(return_type)); |
| 9414 | } |
| 9415 | |
| 9416 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 9417 | codegen_->GenerateFrameExit(); |
| 9418 | } |
| 9419 | |
| 9420 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { |
| 9421 | ret->SetLocations(nullptr); |
| 9422 | } |
| 9423 | |
| 9424 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 9425 | codegen_->GenerateFrameExit(); |
| 9426 | } |
| 9427 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 9428 | void LocationsBuilderMIPS::VisitRor(HRor* ror) { |
| 9429 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 9430 | } |
| 9431 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 9432 | void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) { |
| 9433 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 9434 | } |
| 9435 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9436 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { |
| 9437 | HandleShift(shl); |
| 9438 | } |
| 9439 | |
| 9440 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { |
| 9441 | HandleShift(shl); |
| 9442 | } |
| 9443 | |
| 9444 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { |
| 9445 | HandleShift(shr); |
| 9446 | } |
| 9447 | |
| 9448 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { |
| 9449 | HandleShift(shr); |
| 9450 | } |
| 9451 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9452 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { |
| 9453 | HandleBinaryOp(instruction); |
| 9454 | } |
| 9455 | |
| 9456 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { |
| 9457 | HandleBinaryOp(instruction); |
| 9458 | } |
| 9459 | |
| 9460 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 9461 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 9462 | } |
| 9463 | |
| 9464 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 9465 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 9466 | } |
| 9467 | |
| 9468 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 9469 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 9470 | } |
| 9471 | |
| 9472 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 9473 | HandleFieldSet(instruction, |
| 9474 | instruction->GetFieldInfo(), |
| 9475 | instruction->GetDexPc(), |
| 9476 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9477 | } |
| 9478 | |
| 9479 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( |
| 9480 | HUnresolvedInstanceFieldGet* instruction) { |
| 9481 | FieldAccessCallingConventionMIPS calling_convention; |
| 9482 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 9483 | instruction->GetFieldType(), |
| 9484 | calling_convention); |
| 9485 | } |
| 9486 | |
| 9487 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( |
| 9488 | HUnresolvedInstanceFieldGet* instruction) { |
| 9489 | FieldAccessCallingConventionMIPS calling_convention; |
| 9490 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 9491 | instruction->GetFieldType(), |
| 9492 | instruction->GetFieldIndex(), |
| 9493 | instruction->GetDexPc(), |
| 9494 | calling_convention); |
| 9495 | } |
| 9496 | |
| 9497 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( |
| 9498 | HUnresolvedInstanceFieldSet* instruction) { |
| 9499 | FieldAccessCallingConventionMIPS calling_convention; |
| 9500 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 9501 | instruction->GetFieldType(), |
| 9502 | calling_convention); |
| 9503 | } |
| 9504 | |
| 9505 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( |
| 9506 | HUnresolvedInstanceFieldSet* instruction) { |
| 9507 | FieldAccessCallingConventionMIPS calling_convention; |
| 9508 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 9509 | instruction->GetFieldType(), |
| 9510 | instruction->GetFieldIndex(), |
| 9511 | instruction->GetDexPc(), |
| 9512 | calling_convention); |
| 9513 | } |
| 9514 | |
| 9515 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( |
| 9516 | HUnresolvedStaticFieldGet* instruction) { |
| 9517 | FieldAccessCallingConventionMIPS calling_convention; |
| 9518 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 9519 | instruction->GetFieldType(), |
| 9520 | calling_convention); |
| 9521 | } |
| 9522 | |
| 9523 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( |
| 9524 | HUnresolvedStaticFieldGet* instruction) { |
| 9525 | FieldAccessCallingConventionMIPS calling_convention; |
| 9526 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 9527 | instruction->GetFieldType(), |
| 9528 | instruction->GetFieldIndex(), |
| 9529 | instruction->GetDexPc(), |
| 9530 | calling_convention); |
| 9531 | } |
| 9532 | |
| 9533 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( |
| 9534 | HUnresolvedStaticFieldSet* instruction) { |
| 9535 | FieldAccessCallingConventionMIPS calling_convention; |
| 9536 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 9537 | instruction->GetFieldType(), |
| 9538 | calling_convention); |
| 9539 | } |
| 9540 | |
| 9541 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( |
| 9542 | HUnresolvedStaticFieldSet* 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::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9552 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 9553 | instruction, LocationSummary::kCallOnSlowPath); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 9554 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 9555 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 9556 | // registers in full width (since the runtime only saves/restores lower part). |
| 9557 | locations->SetCustomSlowPathCallerSaves( |
| 9558 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9559 | } |
| 9560 | |
| 9561 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 9562 | HBasicBlock* block = instruction->GetBlock(); |
| 9563 | if (block->GetLoopInformation() != nullptr) { |
| 9564 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 9565 | // The back edge will generate the suspend check. |
| 9566 | return; |
| 9567 | } |
| 9568 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 9569 | // The goto will generate the suspend check. |
| 9570 | return; |
| 9571 | } |
| 9572 | GenerateSuspendCheck(instruction, nullptr); |
| 9573 | } |
| 9574 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9575 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9576 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 9577 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9578 | InvokeRuntimeCallingConvention calling_convention; |
| 9579 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 9580 | } |
| 9581 | |
| 9582 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 9583 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9584 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 9585 | } |
| 9586 | |
| 9587 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9588 | DataType::Type input_type = conversion->GetInputType(); |
| 9589 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9590 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 9591 | << input_type << " -> " << result_type; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9592 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9593 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9594 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 9595 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9596 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 9597 | } |
| 9598 | |
| 9599 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9600 | if (!isR6 && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9601 | ((DataType::IsFloatingPointType(result_type) && input_type == DataType::Type::kInt64) || |
| 9602 | (result_type == DataType::Type::kInt64 && DataType::IsFloatingPointType(input_type)))) { |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 9603 | call_kind = LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9604 | } |
| 9605 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9606 | LocationSummary* locations = |
| 9607 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9608 | |
| 9609 | if (call_kind == LocationSummary::kNoCall) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9610 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9611 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 9612 | } else { |
| 9613 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9614 | } |
| 9615 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9616 | if (DataType::IsFloatingPointType(result_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9617 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 9618 | } else { |
| 9619 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9620 | } |
| 9621 | } else { |
| 9622 | InvokeRuntimeCallingConvention calling_convention; |
| 9623 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9624 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9625 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 9626 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9627 | DCHECK_EQ(input_type, DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9628 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 9629 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 9630 | } |
| 9631 | |
| 9632 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 9633 | } |
| 9634 | } |
| 9635 | |
| 9636 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 9637 | LocationSummary* locations = conversion->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9638 | DataType::Type result_type = conversion->GetResultType(); |
| 9639 | DataType::Type input_type = conversion->GetInputType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9640 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9641 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9642 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9643 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 9644 | << input_type << " -> " << result_type; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9645 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9646 | if (result_type == DataType::Type::kInt64 && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9647 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 9648 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 9649 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 9650 | |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 9651 | if (dst_low != src) { |
| 9652 | __ Move(dst_low, src); |
| 9653 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9654 | __ Sra(dst_high, src, 31); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9655 | } else if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9656 | Register dst = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9657 | Register src = (input_type == DataType::Type::kInt64) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9658 | ? locations->InAt(0).AsRegisterPairLow<Register>() |
| 9659 | : locations->InAt(0).AsRegister<Register>(); |
| 9660 | |
| 9661 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9662 | case DataType::Type::kUint8: |
| 9663 | __ Andi(dst, src, 0xFF); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9664 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9665 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9666 | if (has_sign_extension) { |
| 9667 | __ Seb(dst, src); |
| 9668 | } else { |
| 9669 | __ Sll(dst, src, 24); |
| 9670 | __ Sra(dst, dst, 24); |
| 9671 | } |
| 9672 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9673 | case DataType::Type::kUint16: |
| 9674 | __ Andi(dst, src, 0xFFFF); |
| 9675 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9676 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9677 | if (has_sign_extension) { |
| 9678 | __ Seh(dst, src); |
| 9679 | } else { |
| 9680 | __ Sll(dst, src, 16); |
| 9681 | __ Sra(dst, dst, 16); |
| 9682 | } |
| 9683 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9684 | case DataType::Type::kInt32: |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 9685 | if (dst != src) { |
| 9686 | __ Move(dst, src); |
| 9687 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9688 | break; |
| 9689 | |
| 9690 | default: |
| 9691 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 9692 | << " to " << result_type; |
| 9693 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9694 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
| 9695 | if (input_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9696 | if (isR6) { |
| 9697 | // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 9698 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 9699 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 9700 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 9701 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 9702 | __ Mtc1(src_low, FTMP); |
| 9703 | __ Mthc1(src_high, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9704 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9705 | __ Cvtsl(dst, FTMP); |
| 9706 | } else { |
| 9707 | __ Cvtdl(dst, FTMP); |
| 9708 | } |
| 9709 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9710 | QuickEntrypointEnum entrypoint = |
| 9711 | (result_type == DataType::Type::kFloat32) ? kQuickL2f : kQuickL2d; |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 9712 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9713 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9714 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 9715 | } else { |
| 9716 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 9717 | } |
| 9718 | } |
| 9719 | } else { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9720 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 9721 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 9722 | __ Mtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9723 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9724 | __ Cvtsw(dst, FTMP); |
| 9725 | } else { |
| 9726 | __ Cvtdw(dst, FTMP); |
| 9727 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9728 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9729 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 9730 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9731 | |
| 9732 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum |
| 9733 | // value of the output type if the input is outside of the range after the truncation or |
| 9734 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct |
| 9735 | // results. This matches the desired float/double-to-int/long conversion exactly. |
| 9736 | // |
| 9737 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive |
| 9738 | // value when the input is either a NaN or is outside of the range of the output type |
| 9739 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce |
| 9740 | // the same result. |
| 9741 | // |
| 9742 | // The code takes care of the different behaviors by first comparing the input to the |
| 9743 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). |
| 9744 | // If the input is greater than or equal to the minimum, it procedes to the truncate |
| 9745 | // instruction, which will handle such an input the same way irrespective of NAN2008. |
| 9746 | // Otherwise the input is compared to itself to determine whether it is a NaN or not |
| 9747 | // in order to return either zero or the minimum value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9748 | if (result_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9749 | if (isR6) { |
| 9750 | // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 9751 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 9752 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9753 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 9754 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9755 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9756 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9757 | __ TruncLS(FTMP, src); |
| 9758 | } else { |
| 9759 | __ TruncLD(FTMP, src); |
| 9760 | } |
| 9761 | __ Mfc1(dst_low, FTMP); |
| 9762 | __ Mfhc1(dst_high, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9763 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9764 | QuickEntrypointEnum entrypoint = |
| 9765 | (input_type == DataType::Type::kFloat32) ? kQuickF2l : kQuickD2l; |
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 (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9768 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 9769 | } else { |
| 9770 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 9771 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9772 | } |
| 9773 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9774 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9775 | Register dst = locations->Out().AsRegister<Register>(); |
| 9776 | MipsLabel truncate; |
| 9777 | MipsLabel done; |
| 9778 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9779 | if (!isR6) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9780 | if (input_type == DataType::Type::kFloat32) { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9781 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); |
| 9782 | __ LoadConst32(TMP, min_val); |
| 9783 | __ Mtc1(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9784 | } else { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9785 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); |
| 9786 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 9787 | __ Mtc1(ZERO, FTMP); |
| 9788 | __ MoveToFpuHigh(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9789 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9790 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9791 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9792 | __ ColeS(0, FTMP, src); |
| 9793 | } else { |
| 9794 | __ ColeD(0, FTMP, src); |
| 9795 | } |
| 9796 | __ Bc1t(0, &truncate); |
| 9797 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9798 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9799 | __ CeqS(0, src, src); |
| 9800 | } else { |
| 9801 | __ CeqD(0, src, src); |
| 9802 | } |
| 9803 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 9804 | __ Movf(dst, ZERO, 0); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9805 | |
| 9806 | __ B(&done); |
| 9807 | |
| 9808 | __ Bind(&truncate); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9809 | } |
| 9810 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9811 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9812 | __ TruncWS(FTMP, src); |
| 9813 | } else { |
| 9814 | __ TruncWD(FTMP, src); |
| 9815 | } |
| 9816 | __ Mfc1(dst, FTMP); |
| 9817 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9818 | if (!isR6) { |
| 9819 | __ Bind(&done); |
| 9820 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9821 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9822 | } else if (DataType::IsFloatingPointType(result_type) && |
| 9823 | DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9824 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 9825 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9826 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9827 | __ Cvtsd(dst, src); |
| 9828 | } else { |
| 9829 | __ Cvtds(dst, src); |
| 9830 | } |
| 9831 | } else { |
| 9832 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 9833 | << " to " << result_type; |
| 9834 | } |
| 9835 | } |
| 9836 | |
| 9837 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { |
| 9838 | HandleShift(ushr); |
| 9839 | } |
| 9840 | |
| 9841 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { |
| 9842 | HandleShift(ushr); |
| 9843 | } |
| 9844 | |
| 9845 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { |
| 9846 | HandleBinaryOp(instruction); |
| 9847 | } |
| 9848 | |
| 9849 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { |
| 9850 | HandleBinaryOp(instruction); |
| 9851 | } |
| 9852 | |
| 9853 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9854 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9855 | LOG(FATAL) << "Unreachable"; |
| 9856 | } |
| 9857 | |
| 9858 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9859 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9860 | LOG(FATAL) << "Unreachable"; |
| 9861 | } |
| 9862 | |
| 9863 | void LocationsBuilderMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9864 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9865 | } |
| 9866 | |
| 9867 | void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9868 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9869 | } |
| 9870 | |
| 9871 | void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9872 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9873 | } |
| 9874 | |
| 9875 | void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9876 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9877 | } |
| 9878 | |
| 9879 | void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9880 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9881 | } |
| 9882 | |
| 9883 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9884 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9885 | } |
| 9886 | |
| 9887 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9888 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9889 | } |
| 9890 | |
| 9891 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9892 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9893 | } |
| 9894 | |
| 9895 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9896 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9897 | } |
| 9898 | |
| 9899 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9900 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9901 | } |
| 9902 | |
| 9903 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9904 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9905 | } |
| 9906 | |
| 9907 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9908 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9909 | } |
| 9910 | |
| 9911 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9912 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9913 | } |
| 9914 | |
| 9915 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9916 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9917 | } |
| 9918 | |
| 9919 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9920 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9921 | } |
| 9922 | |
| 9923 | void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9924 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9925 | } |
| 9926 | |
| 9927 | void LocationsBuilderMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9928 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9929 | } |
| 9930 | |
| 9931 | void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9932 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9933 | } |
| 9934 | |
| 9935 | void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9936 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9937 | } |
| 9938 | |
| 9939 | void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9940 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9941 | } |
| 9942 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9943 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9944 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9945 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9946 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9947 | if (!codegen_->GetInstructionSetFeatures().IsR6()) { |
| 9948 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9949 | if (num_entries > InstructionCodeGeneratorMIPS::kPackedSwitchJumpTableThreshold) { |
| 9950 | // When there's no HMipsComputeBaseMethodAddress input, R2 uses the NAL |
| 9951 | // instruction to simulate PC-relative addressing when accessing the jump table. |
| 9952 | // NAL clobbers RA. Make sure RA is preserved. |
| 9953 | codegen_->ClobberRA(); |
| 9954 | } |
| 9955 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9956 | } |
| 9957 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9958 | void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg, |
| 9959 | int32_t lower_bound, |
| 9960 | uint32_t num_entries, |
| 9961 | HBasicBlock* switch_block, |
| 9962 | HBasicBlock* default_block) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9963 | // Create a set of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9964 | Register temp_reg = TMP; |
| 9965 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
| 9966 | // Jump to default if index is negative |
| 9967 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 9968 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 9969 | __ Bltz(temp_reg, codegen_->GetLabelOf(default_block)); |
| 9970 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9971 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9972 | // Jump to successors[0] if value == lower_bound. |
| 9973 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 9974 | int32_t last_index = 0; |
| 9975 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9976 | __ Addiu(temp_reg, temp_reg, -2); |
| 9977 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9978 | __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9979 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9980 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9981 | } |
| 9982 | if (num_entries - last_index == 2) { |
| 9983 | // The last missing case_value. |
| 9984 | __ Addiu(temp_reg, temp_reg, -1); |
| 9985 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9986 | } |
| 9987 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9988 | // And the default for any other value. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9989 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9990 | __ B(codegen_->GetLabelOf(default_block)); |
| 9991 | } |
| 9992 | } |
| 9993 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9994 | void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg, |
| 9995 | Register constant_area, |
| 9996 | int32_t lower_bound, |
| 9997 | uint32_t num_entries, |
| 9998 | HBasicBlock* switch_block, |
| 9999 | HBasicBlock* default_block) { |
| 10000 | // Create a jump table. |
| 10001 | std::vector<MipsLabel*> labels(num_entries); |
| 10002 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 10003 | for (uint32_t i = 0; i < num_entries; i++) { |
| 10004 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 10005 | } |
| 10006 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 10007 | |
| 10008 | // Is the value in range? |
| 10009 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 10010 | if (IsInt<16>(static_cast<int32_t>(num_entries))) { |
| 10011 | __ Sltiu(AT, TMP, num_entries); |
| 10012 | __ Beqz(AT, codegen_->GetLabelOf(default_block)); |
| 10013 | } else { |
| 10014 | __ LoadConst32(AT, num_entries); |
| 10015 | __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 10016 | } |
| 10017 | |
| 10018 | // We are in the range of the table. |
| 10019 | // Load the target address from the jump table, indexing by the value. |
| 10020 | __ LoadLabelAddress(AT, constant_area, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 10021 | __ ShiftAndAdd(TMP, TMP, AT, 2, TMP); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10022 | __ Lw(TMP, TMP, 0); |
| 10023 | // Compute the absolute target address by adding the table start address |
| 10024 | // (the table contains offsets to targets relative to its start). |
| 10025 | __ Addu(TMP, TMP, AT); |
| 10026 | // And jump. |
| 10027 | __ Jr(TMP); |
| 10028 | __ NopIfNoReordering(); |
| 10029 | } |
| 10030 | |
| 10031 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 10032 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 10033 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 10034 | LocationSummary* locations = switch_instr->GetLocations(); |
| 10035 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 10036 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 10037 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 10038 | |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 10039 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10040 | // R6 uses PC-relative addressing to access the jump table. |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 10041 | // |
| 10042 | // R2, OTOH, uses an HMipsComputeBaseMethodAddress input (when available) |
| 10043 | // to access the jump table and it is implemented by changing HPackedSwitch to |
| 10044 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress (see |
| 10045 | // VisitMipsPackedSwitch()). |
| 10046 | // |
| 10047 | // When there's no HMipsComputeBaseMethodAddress input (e.g. in presence of |
| 10048 | // irreducible loops), R2 uses the NAL instruction to simulate PC-relative |
| 10049 | // addressing. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10050 | GenTableBasedPackedSwitch(value_reg, |
| 10051 | ZERO, |
| 10052 | lower_bound, |
| 10053 | num_entries, |
| 10054 | switch_block, |
| 10055 | default_block); |
| 10056 | } else { |
| 10057 | GenPackedSwitchWithCompares(value_reg, |
| 10058 | lower_bound, |
| 10059 | num_entries, |
| 10060 | switch_block, |
| 10061 | default_block); |
| 10062 | } |
| 10063 | } |
| 10064 | |
| 10065 | void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 10066 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 10067 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10068 | locations->SetInAt(0, Location::RequiresRegister()); |
| 10069 | // Constant area pointer (HMipsComputeBaseMethodAddress). |
| 10070 | locations->SetInAt(1, Location::RequiresRegister()); |
| 10071 | } |
| 10072 | |
| 10073 | void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 10074 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 10075 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 10076 | LocationSummary* locations = switch_instr->GetLocations(); |
| 10077 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 10078 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 10079 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 10080 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 10081 | |
| 10082 | // This is an R2-only path. HPackedSwitch has been changed to |
| 10083 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress |
| 10084 | // required to address the jump table relative to PC. |
| 10085 | GenTableBasedPackedSwitch(value_reg, |
| 10086 | constant_area, |
| 10087 | lower_bound, |
| 10088 | num_entries, |
| 10089 | switch_block, |
| 10090 | default_block); |
| 10091 | } |
| 10092 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 10093 | void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress( |
| 10094 | HMipsComputeBaseMethodAddress* insn) { |
| 10095 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 10096 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 10097 | locations->SetOut(Location::RequiresRegister()); |
| 10098 | } |
| 10099 | |
| 10100 | void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress( |
| 10101 | HMipsComputeBaseMethodAddress* insn) { |
| 10102 | LocationSummary* locations = insn->GetLocations(); |
| 10103 | Register reg = locations->Out().AsRegister<Register>(); |
| 10104 | |
| 10105 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 10106 | |
| 10107 | // Generate a dummy PC-relative call to obtain PC. |
| 10108 | __ Nal(); |
| 10109 | // Grab the return address off RA. |
| 10110 | __ Move(reg, RA); |
| 10111 | |
| 10112 | // Remember this offset (the obtained PC value) for later use with constant area. |
| 10113 | __ BindPcRelBaseLabel(); |
| 10114 | } |
| 10115 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 10116 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 10117 | // The trampoline uses the same calling convention as dex calling conventions, |
| 10118 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 10119 | // the method_idx. |
| 10120 | HandleInvoke(invoke); |
| 10121 | } |
| 10122 | |
| 10123 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 10124 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 10125 | } |
| 10126 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10127 | void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 10128 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 10129 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10130 | locations->SetInAt(0, Location::RequiresRegister()); |
| 10131 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 10132 | } |
| 10133 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10134 | void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 10135 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 10136 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 10137 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10138 | instruction->GetIndex(), kMipsPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 10139 | __ LoadFromOffset(kLoadWord, |
| 10140 | locations->Out().AsRegister<Register>(), |
| 10141 | locations->InAt(0).AsRegister<Register>(), |
| 10142 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10143 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 10144 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 10145 | instruction->GetIndex(), kMipsPointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 10146 | __ LoadFromOffset(kLoadWord, |
| 10147 | locations->Out().AsRegister<Register>(), |
| 10148 | locations->InAt(0).AsRegister<Register>(), |
| 10149 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 10150 | __ LoadFromOffset(kLoadWord, |
| 10151 | locations->Out().AsRegister<Register>(), |
| 10152 | locations->Out().AsRegister<Register>(), |
| 10153 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10154 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 10155 | } |
| 10156 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 10157 | void LocationsBuilderMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 10158 | ATTRIBUTE_UNUSED) { |
| 10159 | LOG(FATAL) << "Unreachable"; |
| 10160 | } |
| 10161 | |
| 10162 | void InstructionCodeGeneratorMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 10163 | ATTRIBUTE_UNUSED) { |
| 10164 | LOG(FATAL) << "Unreachable"; |
| 10165 | } |
| 10166 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 10167 | #undef __ |
| 10168 | #undef QUICK_ENTRY_POINT |
| 10169 | |
| 10170 | } // namespace mips |
| 10171 | } // namespace art |