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) { |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1045 | uint32_t old_position = |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1046 | stack_map_stream->GetStackMap(i).native_pc_code_offset.Uint32Value(InstructionSet::kMips); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1047 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1048 | DCHECK_GE(new_position, old_position); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1049 | stack_map_stream->SetStackMapNativePcOffset(i, new_position); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | // Adjust pc offsets for the disassembly information. |
| 1053 | if (disasm_info_ != nullptr) { |
| 1054 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1055 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1056 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1057 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1058 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1059 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1060 | } |
| 1061 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1062 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1063 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | CodeGenerator::Finalize(allocator); |
| 1068 | } |
| 1069 | |
| 1070 | MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const { |
| 1071 | return codegen_->GetAssembler(); |
| 1072 | } |
| 1073 | |
| 1074 | void ParallelMoveResolverMIPS::EmitMove(size_t index) { |
| 1075 | DCHECK_LT(index, moves_.size()); |
| 1076 | MoveOperands* move = moves_[index]; |
| 1077 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1078 | } |
| 1079 | |
| 1080 | void ParallelMoveResolverMIPS::EmitSwap(size_t index) { |
| 1081 | DCHECK_LT(index, moves_.size()); |
| 1082 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1083 | DataType::Type type = move->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1084 | Location loc1 = move->GetDestination(); |
| 1085 | Location loc2 = move->GetSource(); |
| 1086 | |
| 1087 | DCHECK(!loc1.IsConstant()); |
| 1088 | DCHECK(!loc2.IsConstant()); |
| 1089 | |
| 1090 | if (loc1.Equals(loc2)) { |
| 1091 | return; |
| 1092 | } |
| 1093 | |
| 1094 | if (loc1.IsRegister() && loc2.IsRegister()) { |
| 1095 | // Swap 2 GPRs. |
| 1096 | Register r1 = loc1.AsRegister<Register>(); |
| 1097 | Register r2 = loc2.AsRegister<Register>(); |
| 1098 | __ Move(TMP, r2); |
| 1099 | __ Move(r2, r1); |
| 1100 | __ Move(r1, TMP); |
| 1101 | } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) { |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1102 | if (codegen_->GetGraph()->HasSIMD()) { |
| 1103 | __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(loc1)); |
| 1104 | __ MoveV(VectorRegisterFrom(loc1), VectorRegisterFrom(loc2)); |
| 1105 | __ MoveV(VectorRegisterFrom(loc2), static_cast<VectorRegister>(FTMP)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1106 | } else { |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1107 | FRegister f1 = loc1.AsFpuRegister<FRegister>(); |
| 1108 | FRegister f2 = loc2.AsFpuRegister<FRegister>(); |
| 1109 | if (type == DataType::Type::kFloat32) { |
| 1110 | __ MovS(FTMP, f2); |
| 1111 | __ MovS(f2, f1); |
| 1112 | __ MovS(f1, FTMP); |
| 1113 | } else { |
| 1114 | DCHECK_EQ(type, DataType::Type::kFloat64); |
| 1115 | __ MovD(FTMP, f2); |
| 1116 | __ MovD(f2, f1); |
| 1117 | __ MovD(f1, FTMP); |
| 1118 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1119 | } |
| 1120 | } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) || |
| 1121 | (loc1.IsFpuRegister() && loc2.IsRegister())) { |
| 1122 | // Swap FPR and GPR. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1123 | DCHECK_EQ(type, DataType::Type::kFloat32); // Can only swap a float. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1124 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1125 | : loc2.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1126 | Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1127 | __ Move(TMP, r2); |
| 1128 | __ Mfc1(r2, f1); |
| 1129 | __ Mtc1(TMP, f1); |
| 1130 | } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) { |
| 1131 | // Swap 2 GPR register pairs. |
| 1132 | Register r1 = loc1.AsRegisterPairLow<Register>(); |
| 1133 | Register r2 = loc2.AsRegisterPairLow<Register>(); |
| 1134 | __ Move(TMP, r2); |
| 1135 | __ Move(r2, r1); |
| 1136 | __ Move(r1, TMP); |
| 1137 | r1 = loc1.AsRegisterPairHigh<Register>(); |
| 1138 | r2 = loc2.AsRegisterPairHigh<Register>(); |
| 1139 | __ Move(TMP, r2); |
| 1140 | __ Move(r2, r1); |
| 1141 | __ Move(r1, TMP); |
| 1142 | } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) || |
| 1143 | (loc1.IsFpuRegister() && loc2.IsRegisterPair())) { |
| 1144 | // Swap FPR and GPR register pair. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1145 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1146 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1147 | : loc2.AsFpuRegister<FRegister>(); |
| 1148 | Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 1149 | : loc2.AsRegisterPairLow<Register>(); |
| 1150 | Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 1151 | : loc2.AsRegisterPairHigh<Register>(); |
| 1152 | // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and |
| 1153 | // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR |
| 1154 | // unpredictable and the following mfch1 will fail. |
| 1155 | __ Mfc1(TMP, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1156 | __ MoveFromFpuHigh(AT, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1157 | __ Mtc1(r2_l, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1158 | __ MoveToFpuHigh(r2_h, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1159 | __ Move(r2_l, TMP); |
| 1160 | __ Move(r2_h, AT); |
| 1161 | } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) { |
| 1162 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false); |
| 1163 | } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) { |
| 1164 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1165 | } else if (loc1.IsSIMDStackSlot() && loc2.IsSIMDStackSlot()) { |
| 1166 | ExchangeQuadSlots(loc1.GetStackIndex(), loc2.GetStackIndex()); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1167 | } else if ((loc1.IsRegister() && loc2.IsStackSlot()) || |
| 1168 | (loc1.IsStackSlot() && loc2.IsRegister())) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1169 | Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
| 1170 | intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1171 | __ Move(TMP, reg); |
| 1172 | __ LoadFromOffset(kLoadWord, reg, SP, offset); |
| 1173 | __ StoreToOffset(kStoreWord, TMP, SP, offset); |
| 1174 | } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) || |
| 1175 | (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) { |
| 1176 | Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 1177 | : loc2.AsRegisterPairLow<Register>(); |
| 1178 | Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 1179 | : loc2.AsRegisterPairHigh<Register>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1180 | intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1181 | intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize) |
| 1182 | : loc2.GetHighStackIndex(kMipsWordSize); |
| 1183 | __ Move(TMP, reg_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1184 | __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1185 | __ StoreToOffset(kStoreWord, TMP, SP, offset_l); |
David Brazdil | 04d3e87 | 2016-01-29 09:50:09 +0000 | [diff] [blame] | 1186 | __ Move(TMP, reg_h); |
| 1187 | __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h); |
| 1188 | __ StoreToOffset(kStoreWord, TMP, SP, offset_h); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1189 | } else if ((loc1.IsFpuRegister() && loc2.IsSIMDStackSlot()) || |
| 1190 | (loc1.IsSIMDStackSlot() && loc2.IsFpuRegister())) { |
| 1191 | Location fp_loc = loc1.IsFpuRegister() ? loc1 : loc2; |
| 1192 | intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex(); |
| 1193 | __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(fp_loc)); |
| 1194 | __ LoadQFromOffset(fp_loc.AsFpuRegister<FRegister>(), SP, offset); |
| 1195 | __ StoreQToOffset(FTMP, SP, offset); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1196 | } else if (loc1.IsFpuRegister() || loc2.IsFpuRegister()) { |
| 1197 | FRegister reg = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1198 | : loc2.AsFpuRegister<FRegister>(); |
| 1199 | intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1200 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1201 | __ MovS(FTMP, reg); |
| 1202 | __ LoadSFromOffset(reg, SP, offset); |
| 1203 | __ StoreSToOffset(FTMP, SP, offset); |
| 1204 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1205 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1206 | __ MovD(FTMP, reg); |
| 1207 | __ LoadDFromOffset(reg, SP, offset); |
| 1208 | __ StoreDToOffset(FTMP, SP, offset); |
| 1209 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1210 | } else { |
| 1211 | LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported"; |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | void ParallelMoveResolverMIPS::RestoreScratch(int reg) { |
| 1216 | __ Pop(static_cast<Register>(reg)); |
| 1217 | } |
| 1218 | |
| 1219 | void ParallelMoveResolverMIPS::SpillScratch(int reg) { |
| 1220 | __ Push(static_cast<Register>(reg)); |
| 1221 | } |
| 1222 | |
| 1223 | void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) { |
| 1224 | // Allocate a scratch register other than TMP, if available. |
| 1225 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 1226 | // automatically unspilled when the scratch scope object is destroyed). |
| 1227 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 1228 | // 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] | 1229 | int stack_offset = ensure_scratch.IsSpilled() ? kStackAlignment : 0; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1230 | for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) { |
| 1231 | __ LoadFromOffset(kLoadWord, |
| 1232 | Register(ensure_scratch.GetRegister()), |
| 1233 | SP, |
| 1234 | index1 + stack_offset); |
| 1235 | __ LoadFromOffset(kLoadWord, |
| 1236 | TMP, |
| 1237 | SP, |
| 1238 | index2 + stack_offset); |
| 1239 | __ StoreToOffset(kStoreWord, |
| 1240 | Register(ensure_scratch.GetRegister()), |
| 1241 | SP, |
| 1242 | index2 + stack_offset); |
| 1243 | __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset); |
| 1244 | } |
| 1245 | } |
| 1246 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1247 | void ParallelMoveResolverMIPS::ExchangeQuadSlots(int index1, int index2) { |
| 1248 | __ LoadQFromOffset(FTMP, SP, index1); |
| 1249 | __ LoadQFromOffset(FTMP2, SP, index2); |
| 1250 | __ StoreQToOffset(FTMP, SP, index2); |
| 1251 | __ StoreQToOffset(FTMP2, SP, index1); |
| 1252 | } |
| 1253 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1254 | void CodeGeneratorMIPS::ComputeSpillMask() { |
| 1255 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1256 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1257 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 1258 | // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved |
| 1259 | // registers, include the ZERO register to force alignment of FPU callee-saved registers |
| 1260 | // within the stack frame. |
| 1261 | if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) { |
| 1262 | core_spill_mask_ |= (1 << ZERO); |
| 1263 | } |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1267 | // 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] | 1268 | // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration() |
| 1269 | // into the path that creates a stack frame so that RA can be explicitly saved and restored. |
| 1270 | // 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] | 1271 | return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_; |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1274 | static dwarf::Reg DWARFReg(Register reg) { |
| 1275 | return dwarf::Reg::MipsCore(static_cast<int>(reg)); |
| 1276 | } |
| 1277 | |
| 1278 | // TODO: mapping of floating-point registers to DWARF. |
| 1279 | |
| 1280 | void CodeGeneratorMIPS::GenerateFrameEntry() { |
| 1281 | __ Bind(&frame_entry_label_); |
| 1282 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1283 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
Goran Jakovljevic | feec167 | 2018-02-08 10:20:14 +0100 | [diff] [blame] | 1284 | __ Lhu(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()); |
| 1285 | __ Addiu(TMP, TMP, 1); |
| 1286 | __ Sh(TMP, kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()); |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1287 | } |
| 1288 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1289 | bool do_overflow_check = |
| 1290 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips) || !IsLeafMethod(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1291 | |
| 1292 | if (do_overflow_check) { |
| 1293 | __ LoadFromOffset(kLoadWord, |
| 1294 | ZERO, |
| 1295 | SP, |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1296 | -static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kMips))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1297 | RecordPcInfo(nullptr, 0); |
| 1298 | } |
| 1299 | |
| 1300 | if (HasEmptyFrame()) { |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1301 | CHECK_EQ(fpu_spill_mask_, 0u); |
| 1302 | CHECK_EQ(core_spill_mask_, 1u << RA); |
| 1303 | CHECK(!clobbered_ra_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1304 | return; |
| 1305 | } |
| 1306 | |
| 1307 | // Make sure the frame size isn't unreasonably large. |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1308 | if (GetFrameSize() > GetStackOverflowReservedBytes(InstructionSet::kMips)) { |
| 1309 | LOG(FATAL) << "Stack frame larger than " |
| 1310 | << GetStackOverflowReservedBytes(InstructionSet::kMips) << " bytes"; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | // Spill callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1314 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1315 | uint32_t ofs = GetFrameSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1316 | __ IncreaseFrameSize(ofs); |
| 1317 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1318 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 1319 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 1320 | mask ^= 1u << reg; |
| 1321 | ofs -= kMipsWordSize; |
| 1322 | // The ZERO register is only included for alignment. |
| 1323 | if (reg != ZERO) { |
| 1324 | __ StoreToOffset(kStoreWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1325 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 1326 | } |
| 1327 | } |
| 1328 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1329 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 1330 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 1331 | mask ^= 1u << reg; |
| 1332 | ofs -= kMipsDoublewordSize; |
| 1333 | __ StoreDToOffset(reg, SP, ofs); |
| 1334 | // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1335 | } |
| 1336 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1337 | // Save the current method if we need it. Note that we do not |
| 1338 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1339 | // in the SSA graph. |
| 1340 | if (RequiresCurrentMethod()) { |
| 1341 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
| 1342 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 1343 | |
| 1344 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1345 | // Initialize should deoptimize flag to 0. |
| 1346 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1347 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | void CodeGeneratorMIPS::GenerateFrameExit() { |
| 1351 | __ cfi().RememberState(); |
| 1352 | |
| 1353 | if (!HasEmptyFrame()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1354 | // Restore callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1355 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1356 | // For better instruction scheduling restore RA before other registers. |
| 1357 | uint32_t ofs = GetFrameSize(); |
| 1358 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 1359 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 1360 | mask ^= 1u << reg; |
| 1361 | ofs -= kMipsWordSize; |
| 1362 | // The ZERO register is only included for alignment. |
| 1363 | if (reg != ZERO) { |
| 1364 | __ LoadFromOffset(kLoadWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1365 | __ cfi().Restore(DWARFReg(reg)); |
| 1366 | } |
| 1367 | } |
| 1368 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1369 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 1370 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 1371 | mask ^= 1u << reg; |
| 1372 | ofs -= kMipsDoublewordSize; |
| 1373 | __ LoadDFromOffset(reg, SP, ofs); |
| 1374 | // TODO: __ cfi().Restore(DWARFReg(reg)); |
| 1375 | } |
| 1376 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1377 | size_t frame_size = GetFrameSize(); |
| 1378 | // Adjust the stack pointer in the delay slot if doing so doesn't break CFI. |
| 1379 | bool exchange = IsInt<16>(static_cast<int32_t>(frame_size)); |
| 1380 | bool reordering = __ SetReorder(false); |
| 1381 | if (exchange) { |
| 1382 | __ Jr(RA); |
| 1383 | __ DecreaseFrameSize(frame_size); // Single instruction in delay slot. |
| 1384 | } else { |
| 1385 | __ DecreaseFrameSize(frame_size); |
| 1386 | __ Jr(RA); |
| 1387 | __ Nop(); // In delay slot. |
| 1388 | } |
| 1389 | __ SetReorder(reordering); |
| 1390 | } else { |
| 1391 | __ Jr(RA); |
| 1392 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1393 | } |
| 1394 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1395 | __ cfi().RestoreState(); |
| 1396 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 1397 | } |
| 1398 | |
| 1399 | void CodeGeneratorMIPS::Bind(HBasicBlock* block) { |
| 1400 | __ Bind(GetLabelOf(block)); |
| 1401 | } |
| 1402 | |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1403 | VectorRegister VectorRegisterFrom(Location location) { |
| 1404 | DCHECK(location.IsFpuRegister()); |
| 1405 | return static_cast<VectorRegister>(location.AsFpuRegister<FRegister>()); |
| 1406 | } |
| 1407 | |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1408 | void CodeGeneratorMIPS::MoveLocation(Location destination, |
| 1409 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1410 | DataType::Type dst_type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1411 | if (source.Equals(destination)) { |
| 1412 | return; |
| 1413 | } |
| 1414 | |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1415 | if (source.IsConstant()) { |
| 1416 | MoveConstant(destination, source.GetConstant()); |
| 1417 | } else { |
| 1418 | if (destination.IsRegister()) { |
| 1419 | if (source.IsRegister()) { |
| 1420 | __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 1421 | } else if (source.IsFpuRegister()) { |
| 1422 | __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>()); |
| 1423 | } else { |
| 1424 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1425 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1426 | } |
| 1427 | } else if (destination.IsRegisterPair()) { |
| 1428 | if (source.IsRegisterPair()) { |
| 1429 | __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 1430 | __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 1431 | } else if (source.IsFpuRegister()) { |
| 1432 | Register dst_high = destination.AsRegisterPairHigh<Register>(); |
| 1433 | Register dst_low = destination.AsRegisterPairLow<Register>(); |
| 1434 | FRegister src = source.AsFpuRegister<FRegister>(); |
| 1435 | __ Mfc1(dst_low, src); |
| 1436 | __ MoveFromFpuHigh(dst_high, src); |
| 1437 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1438 | DCHECK(source.IsDoubleStackSlot()) |
| 1439 | << "Cannot move from " << source << " to " << destination; |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1440 | int32_t off = source.GetStackIndex(); |
| 1441 | Register r = destination.AsRegisterPairLow<Register>(); |
| 1442 | __ LoadFromOffset(kLoadDoubleword, r, SP, off); |
| 1443 | } |
| 1444 | } else if (destination.IsFpuRegister()) { |
| 1445 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1446 | DCHECK(!DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1447 | __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>()); |
| 1448 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1449 | DCHECK(DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1450 | FRegister dst = destination.AsFpuRegister<FRegister>(); |
| 1451 | Register src_high = source.AsRegisterPairHigh<Register>(); |
| 1452 | Register src_low = source.AsRegisterPairLow<Register>(); |
| 1453 | __ Mtc1(src_low, dst); |
| 1454 | __ MoveToFpuHigh(src_high, dst); |
| 1455 | } else if (source.IsFpuRegister()) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1456 | if (GetGraph()->HasSIMD()) { |
| 1457 | __ MoveV(VectorRegisterFrom(destination), |
| 1458 | VectorRegisterFrom(source)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1459 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1460 | if (DataType::Is64BitType(dst_type)) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1461 | __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 1462 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1463 | DCHECK_EQ(dst_type, DataType::Type::kFloat32); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1464 | __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 1465 | } |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1466 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1467 | } else if (source.IsSIMDStackSlot()) { |
| 1468 | __ LoadQFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1469 | } else if (source.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1470 | DCHECK(DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1471 | __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 1472 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1473 | DCHECK(!DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1474 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1475 | __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 1476 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1477 | } else if (destination.IsSIMDStackSlot()) { |
| 1478 | if (source.IsFpuRegister()) { |
| 1479 | __ StoreQToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex()); |
| 1480 | } else { |
| 1481 | DCHECK(source.IsSIMDStackSlot()); |
| 1482 | __ LoadQFromOffset(FTMP, SP, source.GetStackIndex()); |
| 1483 | __ StoreQToOffset(FTMP, SP, destination.GetStackIndex()); |
| 1484 | } |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1485 | } else if (destination.IsDoubleStackSlot()) { |
| 1486 | int32_t dst_offset = destination.GetStackIndex(); |
| 1487 | if (source.IsRegisterPair()) { |
| 1488 | __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, dst_offset); |
| 1489 | } else if (source.IsFpuRegister()) { |
| 1490 | __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset); |
| 1491 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1492 | DCHECK(source.IsDoubleStackSlot()) |
| 1493 | << "Cannot move from " << source << " to " << destination; |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1494 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1495 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset); |
| 1496 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4); |
| 1497 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset + 4); |
| 1498 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1499 | } else { |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1500 | DCHECK(destination.IsStackSlot()) << destination; |
| 1501 | int32_t dst_offset = destination.GetStackIndex(); |
| 1502 | if (source.IsRegister()) { |
| 1503 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, dst_offset); |
| 1504 | } else if (source.IsFpuRegister()) { |
| 1505 | __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset); |
| 1506 | } else { |
| 1507 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1508 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1509 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset); |
| 1510 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1511 | } |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) { |
| 1516 | if (c->IsIntConstant() || c->IsNullConstant()) { |
| 1517 | // Move 32 bit constant. |
| 1518 | int32_t value = GetInt32ValueOf(c); |
| 1519 | if (destination.IsRegister()) { |
| 1520 | Register dst = destination.AsRegister<Register>(); |
| 1521 | __ LoadConst32(dst, value); |
| 1522 | } else { |
| 1523 | DCHECK(destination.IsStackSlot()) |
| 1524 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1525 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1526 | } |
| 1527 | } else if (c->IsLongConstant()) { |
| 1528 | // Move 64 bit constant. |
| 1529 | int64_t value = GetInt64ValueOf(c); |
| 1530 | if (destination.IsRegisterPair()) { |
| 1531 | Register r_h = destination.AsRegisterPairHigh<Register>(); |
| 1532 | Register r_l = destination.AsRegisterPairLow<Register>(); |
| 1533 | __ LoadConst64(r_h, r_l, value); |
| 1534 | } else { |
| 1535 | DCHECK(destination.IsDoubleStackSlot()) |
| 1536 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1537 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1538 | } |
| 1539 | } else if (c->IsFloatConstant()) { |
| 1540 | // Move 32 bit float constant. |
| 1541 | int32_t value = GetInt32ValueOf(c); |
| 1542 | if (destination.IsFpuRegister()) { |
| 1543 | __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP); |
| 1544 | } else { |
| 1545 | DCHECK(destination.IsStackSlot()) |
| 1546 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1547 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1548 | } |
| 1549 | } else { |
| 1550 | // Move 64 bit double constant. |
| 1551 | DCHECK(c->IsDoubleConstant()) << c->DebugName(); |
| 1552 | int64_t value = GetInt64ValueOf(c); |
| 1553 | if (destination.IsFpuRegister()) { |
| 1554 | FRegister fd = destination.AsFpuRegister<FRegister>(); |
| 1555 | __ LoadDConst64(fd, value, TMP); |
| 1556 | } else { |
| 1557 | DCHECK(destination.IsDoubleStackSlot()) |
| 1558 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1559 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1560 | } |
| 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) { |
| 1565 | DCHECK(destination.IsRegister()); |
| 1566 | Register dst = destination.AsRegister<Register>(); |
| 1567 | __ LoadConst32(dst, value); |
| 1568 | } |
| 1569 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1570 | void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1571 | if (location.IsRegister()) { |
| 1572 | locations->AddTemp(location); |
Alexey Frunze | c9e94f3 | 2015-10-26 16:11:39 -0700 | [diff] [blame] | 1573 | } else if (location.IsRegisterPair()) { |
| 1574 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1575 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1576 | } else { |
| 1577 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1578 | } |
| 1579 | } |
| 1580 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1581 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1582 | inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches( |
| 1583 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1584 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1585 | for (const PcRelativePatchInfo& info : infos) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1586 | const DexFile* dex_file = info.target_dex_file; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1587 | size_t offset_or_index = info.offset_or_index; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1588 | DCHECK(info.label.IsBound()); |
| 1589 | uint32_t literal_offset = __ GetLabelLocation(&info.label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1590 | // On R2 we use HMipsComputeBaseMethodAddress and patch relative to |
| 1591 | // the assembler's base label used for PC-relative addressing. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1592 | const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info; |
| 1593 | uint32_t pc_rel_offset = info_high.pc_rel_label.IsBound() |
| 1594 | ? __ GetLabelLocation(&info_high.pc_rel_label) |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1595 | : __ GetPcRelBaseLabelLocation(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1596 | 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] | 1597 | } |
| 1598 | } |
| 1599 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1600 | void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1601 | DCHECK(linker_patches->empty()); |
| 1602 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1603 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1604 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1605 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1606 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1607 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1608 | string_bss_entry_patches_.size(); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1609 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1610 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1611 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1612 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1613 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1614 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1615 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1616 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1617 | } else { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1618 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1619 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1620 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1621 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1622 | boot_image_string_patches_, linker_patches); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1623 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1624 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1625 | method_bss_entry_patches_, linker_patches); |
| 1626 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1627 | type_bss_entry_patches_, linker_patches); |
| 1628 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1629 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1630 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1631 | } |
| 1632 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1633 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageMethodPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1634 | MethodReference target_method, |
| 1635 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1636 | return NewPcRelativePatch( |
| 1637 | 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] | 1638 | } |
| 1639 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1640 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewMethodBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1641 | MethodReference target_method, |
| 1642 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1643 | return NewPcRelativePatch( |
| 1644 | 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] | 1645 | } |
| 1646 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1647 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageTypePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1648 | const DexFile& dex_file, |
| 1649 | dex::TypeIndex type_index, |
| 1650 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1651 | 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] | 1652 | } |
| 1653 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1654 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewTypeBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1655 | const DexFile& dex_file, |
| 1656 | dex::TypeIndex type_index, |
| 1657 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1658 | 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] | 1659 | } |
| 1660 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1661 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageStringPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1662 | const DexFile& dex_file, |
| 1663 | dex::StringIndex string_index, |
| 1664 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1665 | return NewPcRelativePatch( |
| 1666 | &dex_file, string_index.index_, info_high, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1667 | } |
| 1668 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1669 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewStringBssEntryPatch( |
| 1670 | const DexFile& dex_file, |
| 1671 | dex::StringIndex string_index, |
| 1672 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1673 | 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] | 1674 | } |
| 1675 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1676 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1677 | const DexFile* dex_file, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1678 | uint32_t offset_or_index, |
| 1679 | const PcRelativePatchInfo* info_high, |
| 1680 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1681 | patches->emplace_back(dex_file, offset_or_index, info_high); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1682 | return &patches->back(); |
| 1683 | } |
| 1684 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1685 | Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1686 | return map->GetOrCreate( |
| 1687 | value, |
| 1688 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1689 | } |
| 1690 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1691 | Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1692 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1695 | void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high, |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1696 | Register out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1697 | Register base) { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1698 | DCHECK(!info_high->patch_info_high); |
Alexey Frunze | 6079dca | 2017-05-28 19:10:28 -0700 | [diff] [blame] | 1699 | DCHECK_NE(out, base); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1700 | bool reordering = __ SetReorder(false); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1701 | if (GetInstructionSetFeatures().IsR6()) { |
| 1702 | DCHECK_EQ(base, ZERO); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1703 | __ Bind(&info_high->label); |
| 1704 | __ Bind(&info_high->pc_rel_label); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1705 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1706 | __ Auipc(out, /* placeholder */ 0x1234); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1707 | __ SetReorder(reordering); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1708 | } else { |
| 1709 | // If base is ZERO, emit NAL to obtain the actual base. |
| 1710 | if (base == ZERO) { |
| 1711 | // Generate a dummy PC-relative call to obtain PC. |
| 1712 | __ Nal(); |
| 1713 | } |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1714 | __ Bind(&info_high->label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1715 | __ Lui(out, /* placeholder */ 0x1234); |
| 1716 | // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding |
| 1717 | // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler. |
| 1718 | if (base == ZERO) { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1719 | __ Bind(&info_high->pc_rel_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1720 | } |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1721 | __ SetReorder(reordering); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1722 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1723 | __ Addu(out, out, (base == ZERO) ? RA : base); |
| 1724 | } |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1725 | // 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] | 1726 | // offset to `out` (e.g. lw, jialc, addiu). |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1727 | } |
| 1728 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1729 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootStringPatch( |
| 1730 | const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1731 | dex::StringIndex string_index, |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1732 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1733 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| 1734 | jit_string_patches_.emplace_back(dex_file, string_index.index_); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1735 | return &jit_string_patches_.back(); |
| 1736 | } |
| 1737 | |
| 1738 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootClassPatch( |
| 1739 | const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1740 | dex::TypeIndex type_index, |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1741 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1742 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| 1743 | jit_class_patches_.emplace_back(dex_file, type_index.index_); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1744 | return &jit_class_patches_.back(); |
| 1745 | } |
| 1746 | |
| 1747 | void CodeGeneratorMIPS::PatchJitRootUse(uint8_t* code, |
| 1748 | const uint8_t* roots_data, |
| 1749 | const CodeGeneratorMIPS::JitPatchInfo& info, |
| 1750 | uint64_t index_in_table) const { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1751 | uint32_t high_literal_offset = GetAssembler().GetLabelLocation(&info.high_label); |
| 1752 | uint32_t low_literal_offset = GetAssembler().GetLabelLocation(&info.low_label); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1753 | uintptr_t address = |
| 1754 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1755 | uint32_t addr32 = dchecked_integral_cast<uint32_t>(address); |
| 1756 | // lui reg, addr32_high |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1757 | DCHECK_EQ(code[high_literal_offset + 0], 0x34); |
| 1758 | DCHECK_EQ(code[high_literal_offset + 1], 0x12); |
| 1759 | DCHECK_EQ((code[high_literal_offset + 2] & 0xE0), 0x00); |
| 1760 | DCHECK_EQ(code[high_literal_offset + 3], 0x3C); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1761 | // instr reg, reg, addr32_low |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1762 | DCHECK_EQ(code[low_literal_offset + 0], 0x78); |
| 1763 | DCHECK_EQ(code[low_literal_offset + 1], 0x56); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1764 | 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] | 1765 | // lui reg, addr32_high |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1766 | code[high_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 16); |
| 1767 | code[high_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 24); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1768 | // instr reg, reg, addr32_low |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1769 | code[low_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 0); |
| 1770 | code[low_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 8); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | void CodeGeneratorMIPS::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1774 | for (const JitPatchInfo& info : jit_string_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1775 | StringReference string_reference(&info.target_dex_file, dex::StringIndex(info.index)); |
| 1776 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1777 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1778 | } |
| 1779 | for (const JitPatchInfo& info : jit_class_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1780 | TypeReference type_reference(&info.target_dex_file, dex::TypeIndex(info.index)); |
| 1781 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1782 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1783 | } |
| 1784 | } |
| 1785 | |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1786 | void CodeGeneratorMIPS::MarkGCCard(Register object, |
| 1787 | Register value, |
| 1788 | bool value_can_be_null) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1789 | MipsLabel done; |
| 1790 | Register card = AT; |
| 1791 | Register temp = TMP; |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1792 | if (value_can_be_null) { |
| 1793 | __ Beqz(value, &done); |
| 1794 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1795 | __ LoadFromOffset(kLoadWord, |
| 1796 | card, |
| 1797 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1798 | Thread::CardTableOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1799 | __ Srl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1800 | __ Addu(temp, card, temp); |
| 1801 | __ Sb(card, temp, 0); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1802 | if (value_can_be_null) { |
| 1803 | __ Bind(&done); |
| 1804 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1805 | } |
| 1806 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1807 | void CodeGeneratorMIPS::SetupBlockedRegisters() const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1808 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1809 | blocked_core_registers_[ZERO] = true; |
| 1810 | blocked_core_registers_[K0] = true; |
| 1811 | blocked_core_registers_[K1] = true; |
| 1812 | blocked_core_registers_[GP] = true; |
| 1813 | blocked_core_registers_[SP] = true; |
| 1814 | blocked_core_registers_[RA] = true; |
| 1815 | |
| 1816 | // AT and TMP(T8) are used as temporary/scratch registers |
| 1817 | // (similar to how AT is used by MIPS assemblers). |
| 1818 | blocked_core_registers_[AT] = true; |
| 1819 | blocked_core_registers_[TMP] = true; |
| 1820 | blocked_fpu_registers_[FTMP] = true; |
| 1821 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1822 | if (GetInstructionSetFeatures().HasMsa()) { |
| 1823 | // To be used just for MSA instructions. |
| 1824 | blocked_fpu_registers_[FTMP2] = true; |
| 1825 | } |
| 1826 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1827 | // Reserve suspend and thread registers. |
| 1828 | blocked_core_registers_[S0] = true; |
| 1829 | blocked_core_registers_[TR] = true; |
| 1830 | |
| 1831 | // Reserve T9 for function calls |
| 1832 | blocked_core_registers_[T9] = true; |
| 1833 | |
| 1834 | // Reserve odd-numbered FPU registers. |
| 1835 | for (size_t i = 1; i < kNumberOfFRegisters; i += 2) { |
| 1836 | blocked_fpu_registers_[i] = true; |
| 1837 | } |
| 1838 | |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 1839 | if (GetGraph()->IsDebuggable()) { |
| 1840 | // Stubs do not save callee-save floating point registers. If the graph |
| 1841 | // is debuggable, we need to deal with these registers differently. For |
| 1842 | // now, just block them. |
| 1843 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1844 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1845 | } |
| 1846 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1847 | } |
| 1848 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1849 | size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1850 | __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index); |
| 1851 | return kMipsWordSize; |
| 1852 | } |
| 1853 | |
| 1854 | size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1855 | __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index); |
| 1856 | return kMipsWordSize; |
| 1857 | } |
| 1858 | |
| 1859 | size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1860 | if (GetGraph()->HasSIMD()) { |
| 1861 | __ StoreQToOffset(FRegister(reg_id), SP, stack_index); |
| 1862 | } else { |
| 1863 | __ StoreDToOffset(FRegister(reg_id), SP, stack_index); |
| 1864 | } |
| 1865 | return GetFloatingPointSpillSlotSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1869 | if (GetGraph()->HasSIMD()) { |
| 1870 | __ LoadQFromOffset(FRegister(reg_id), SP, stack_index); |
| 1871 | } else { |
| 1872 | __ LoadDFromOffset(FRegister(reg_id), SP, stack_index); |
| 1873 | } |
| 1874 | return GetFloatingPointSpillSlotSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1878 | stream << Register(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1882 | stream << FRegister(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1883 | } |
| 1884 | |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1885 | constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16; |
| 1886 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1887 | void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1888 | HInstruction* instruction, |
| 1889 | uint32_t dex_pc, |
| 1890 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1891 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1892 | GenerateInvokeRuntime(GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value(), |
| 1893 | IsDirectEntrypoint(entrypoint)); |
| 1894 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1895 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1896 | } |
| 1897 | } |
| 1898 | |
| 1899 | void CodeGeneratorMIPS::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1900 | HInstruction* instruction, |
| 1901 | SlowPathCode* slow_path, |
| 1902 | bool direct) { |
| 1903 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1904 | GenerateInvokeRuntime(entry_point_offset, direct); |
| 1905 | } |
| 1906 | |
| 1907 | void CodeGeneratorMIPS::GenerateInvokeRuntime(int32_t entry_point_offset, bool direct) { |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1908 | bool reordering = __ SetReorder(false); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1909 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1910 | __ Jalr(T9); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1911 | if (direct) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1912 | // Reserve argument space on stack (for $a0-$a3) for |
| 1913 | // entrypoints that directly reference native implementations. |
| 1914 | // Called function may use this space to store $a0-$a3 regs. |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1915 | __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1916 | __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1917 | } else { |
| 1918 | __ Nop(); // In delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1919 | } |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1920 | __ SetReorder(reordering); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1921 | } |
| 1922 | |
| 1923 | void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, |
| 1924 | Register class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1925 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 1926 | const size_t status_byte_offset = |
| 1927 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 1928 | constexpr uint32_t shifted_initialized_value = |
| 1929 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 1930 | |
| 1931 | __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, status_byte_offset); |
| 1932 | __ LoadConst32(AT, shifted_initialized_value); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 1933 | __ Bltu(TMP, AT, slow_path->GetEntryLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1934 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1935 | __ Sync(0); |
| 1936 | __ Bind(slow_path->GetExitLabel()); |
| 1937 | } |
| 1938 | |
| 1939 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1940 | __ Sync(0); // Only stype 0 is supported. |
| 1941 | } |
| 1942 | |
| 1943 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1944 | HBasicBlock* successor) { |
| 1945 | SuspendCheckSlowPathMIPS* slow_path = |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 1946 | down_cast<SuspendCheckSlowPathMIPS*>(instruction->GetSlowPath()); |
| 1947 | |
| 1948 | if (slow_path == nullptr) { |
| 1949 | slow_path = |
| 1950 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS(instruction, successor); |
| 1951 | instruction->SetSlowPath(slow_path); |
| 1952 | codegen_->AddSlowPath(slow_path); |
| 1953 | if (successor != nullptr) { |
| 1954 | DCHECK(successor->IsLoopHeader()); |
| 1955 | } |
| 1956 | } else { |
| 1957 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1958 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1959 | |
| 1960 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1961 | TMP, |
| 1962 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1963 | Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1964 | if (successor == nullptr) { |
| 1965 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 1966 | __ Bind(slow_path->GetReturnLabel()); |
| 1967 | } else { |
| 1968 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); |
| 1969 | __ B(slow_path->GetEntryLabel()); |
| 1970 | // slow_path will return to GetLabelOf(successor). |
| 1971 | } |
| 1972 | } |
| 1973 | |
| 1974 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, |
| 1975 | CodeGeneratorMIPS* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1976 | : InstructionCodeGenerator(graph, codegen), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1977 | assembler_(codegen->GetAssembler()), |
| 1978 | codegen_(codegen) {} |
| 1979 | |
| 1980 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1981 | DCHECK_EQ(instruction->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1982 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1983 | DataType::Type type = instruction->GetResultType(); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1984 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1985 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1986 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1987 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1988 | HInstruction* right = instruction->InputAt(1); |
| 1989 | bool can_use_imm = false; |
| 1990 | if (right->IsConstant()) { |
| 1991 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); |
| 1992 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1993 | can_use_imm = IsUint<16>(imm); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1994 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1995 | DCHECK(instruction->IsSub() || instruction->IsAdd()); |
| 1996 | if (instruction->IsSub()) { |
| 1997 | imm = -imm; |
| 1998 | } |
| 1999 | if (isR6) { |
| 2000 | bool single_use = right->GetUses().HasExactlyOneElement(); |
| 2001 | int16_t imm_high = High16Bits(imm); |
| 2002 | int16_t imm_low = Low16Bits(imm); |
| 2003 | if (imm_low < 0) { |
| 2004 | imm_high += 1; |
| 2005 | } |
| 2006 | can_use_imm = !((imm_high != 0) && (imm_low != 0)) || single_use; |
| 2007 | } else { |
| 2008 | can_use_imm = IsInt<16>(imm); |
| 2009 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2010 | } |
| 2011 | } |
| 2012 | if (can_use_imm) |
| 2013 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 2014 | else |
| 2015 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2016 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2017 | break; |
| 2018 | } |
| 2019 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2020 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2021 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2022 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2023 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2024 | break; |
| 2025 | } |
| 2026 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2027 | case DataType::Type::kFloat32: |
| 2028 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2029 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 2030 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2031 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2032 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2033 | break; |
| 2034 | |
| 2035 | default: |
| 2036 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2041 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2042 | LocationSummary* locations = instruction->GetLocations(); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2043 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2044 | |
| 2045 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2046 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2047 | Register dst = locations->Out().AsRegister<Register>(); |
| 2048 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2049 | Location rhs_location = locations->InAt(1); |
| 2050 | |
| 2051 | Register rhs_reg = ZERO; |
| 2052 | int32_t rhs_imm = 0; |
| 2053 | bool use_imm = rhs_location.IsConstant(); |
| 2054 | if (use_imm) { |
| 2055 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2056 | } else { |
| 2057 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2058 | } |
| 2059 | |
| 2060 | if (instruction->IsAnd()) { |
| 2061 | if (use_imm) |
| 2062 | __ Andi(dst, lhs, rhs_imm); |
| 2063 | else |
| 2064 | __ And(dst, lhs, rhs_reg); |
| 2065 | } else if (instruction->IsOr()) { |
| 2066 | if (use_imm) |
| 2067 | __ Ori(dst, lhs, rhs_imm); |
| 2068 | else |
| 2069 | __ Or(dst, lhs, rhs_reg); |
| 2070 | } else if (instruction->IsXor()) { |
| 2071 | if (use_imm) |
| 2072 | __ Xori(dst, lhs, rhs_imm); |
| 2073 | else |
| 2074 | __ Xor(dst, lhs, rhs_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2075 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2076 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 2077 | if (use_imm) { |
| 2078 | if (instruction->IsSub()) { |
| 2079 | rhs_imm = -rhs_imm; |
| 2080 | } |
| 2081 | if (IsInt<16>(rhs_imm)) { |
| 2082 | __ Addiu(dst, lhs, rhs_imm); |
| 2083 | } else { |
| 2084 | DCHECK(isR6); |
| 2085 | int16_t rhs_imm_high = High16Bits(rhs_imm); |
| 2086 | int16_t rhs_imm_low = Low16Bits(rhs_imm); |
| 2087 | if (rhs_imm_low < 0) { |
| 2088 | rhs_imm_high += 1; |
| 2089 | } |
| 2090 | __ Aui(dst, lhs, rhs_imm_high); |
| 2091 | if (rhs_imm_low != 0) { |
| 2092 | __ Addiu(dst, dst, rhs_imm_low); |
| 2093 | } |
| 2094 | } |
| 2095 | } else if (instruction->IsAdd()) { |
| 2096 | __ Addu(dst, lhs, rhs_reg); |
| 2097 | } else { |
| 2098 | DCHECK(instruction->IsSub()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2099 | __ Subu(dst, lhs, rhs_reg); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2100 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2101 | } |
| 2102 | break; |
| 2103 | } |
| 2104 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2105 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2106 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2107 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2108 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2109 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2110 | Location rhs_location = locations->InAt(1); |
| 2111 | bool use_imm = rhs_location.IsConstant(); |
| 2112 | if (!use_imm) { |
| 2113 | Register rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 2114 | Register rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 2115 | if (instruction->IsAnd()) { |
| 2116 | __ And(dst_low, lhs_low, rhs_low); |
| 2117 | __ And(dst_high, lhs_high, rhs_high); |
| 2118 | } else if (instruction->IsOr()) { |
| 2119 | __ Or(dst_low, lhs_low, rhs_low); |
| 2120 | __ Or(dst_high, lhs_high, rhs_high); |
| 2121 | } else if (instruction->IsXor()) { |
| 2122 | __ Xor(dst_low, lhs_low, rhs_low); |
| 2123 | __ Xor(dst_high, lhs_high, rhs_high); |
| 2124 | } else if (instruction->IsAdd()) { |
| 2125 | if (lhs_low == rhs_low) { |
| 2126 | // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs. |
| 2127 | __ Slt(TMP, lhs_low, ZERO); |
| 2128 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2129 | } else { |
| 2130 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2131 | // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged. |
| 2132 | __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low); |
| 2133 | } |
| 2134 | __ Addu(dst_high, lhs_high, rhs_high); |
| 2135 | __ Addu(dst_high, dst_high, TMP); |
| 2136 | } else { |
| 2137 | DCHECK(instruction->IsSub()); |
| 2138 | __ Sltu(TMP, lhs_low, rhs_low); |
| 2139 | __ Subu(dst_low, lhs_low, rhs_low); |
| 2140 | __ Subu(dst_high, lhs_high, rhs_high); |
| 2141 | __ Subu(dst_high, dst_high, TMP); |
| 2142 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2143 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2144 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 2145 | if (instruction->IsOr()) { |
| 2146 | uint32_t low = Low32Bits(value); |
| 2147 | uint32_t high = High32Bits(value); |
| 2148 | if (IsUint<16>(low)) { |
| 2149 | if (dst_low != lhs_low || low != 0) { |
| 2150 | __ Ori(dst_low, lhs_low, low); |
| 2151 | } |
| 2152 | } else { |
| 2153 | __ LoadConst32(TMP, low); |
| 2154 | __ Or(dst_low, lhs_low, TMP); |
| 2155 | } |
| 2156 | if (IsUint<16>(high)) { |
| 2157 | if (dst_high != lhs_high || high != 0) { |
| 2158 | __ Ori(dst_high, lhs_high, high); |
| 2159 | } |
| 2160 | } else { |
| 2161 | if (high != low) { |
| 2162 | __ LoadConst32(TMP, high); |
| 2163 | } |
| 2164 | __ Or(dst_high, lhs_high, TMP); |
| 2165 | } |
| 2166 | } else if (instruction->IsXor()) { |
| 2167 | uint32_t low = Low32Bits(value); |
| 2168 | uint32_t high = High32Bits(value); |
| 2169 | if (IsUint<16>(low)) { |
| 2170 | if (dst_low != lhs_low || low != 0) { |
| 2171 | __ Xori(dst_low, lhs_low, low); |
| 2172 | } |
| 2173 | } else { |
| 2174 | __ LoadConst32(TMP, low); |
| 2175 | __ Xor(dst_low, lhs_low, TMP); |
| 2176 | } |
| 2177 | if (IsUint<16>(high)) { |
| 2178 | if (dst_high != lhs_high || high != 0) { |
| 2179 | __ Xori(dst_high, lhs_high, high); |
| 2180 | } |
| 2181 | } else { |
| 2182 | if (high != low) { |
| 2183 | __ LoadConst32(TMP, high); |
| 2184 | } |
| 2185 | __ Xor(dst_high, lhs_high, TMP); |
| 2186 | } |
| 2187 | } else if (instruction->IsAnd()) { |
| 2188 | uint32_t low = Low32Bits(value); |
| 2189 | uint32_t high = High32Bits(value); |
| 2190 | if (IsUint<16>(low)) { |
| 2191 | __ Andi(dst_low, lhs_low, low); |
| 2192 | } else if (low != 0xFFFFFFFF) { |
| 2193 | __ LoadConst32(TMP, low); |
| 2194 | __ And(dst_low, lhs_low, TMP); |
| 2195 | } else if (dst_low != lhs_low) { |
| 2196 | __ Move(dst_low, lhs_low); |
| 2197 | } |
| 2198 | if (IsUint<16>(high)) { |
| 2199 | __ Andi(dst_high, lhs_high, high); |
| 2200 | } else if (high != 0xFFFFFFFF) { |
| 2201 | if (high != low) { |
| 2202 | __ LoadConst32(TMP, high); |
| 2203 | } |
| 2204 | __ And(dst_high, lhs_high, TMP); |
| 2205 | } else if (dst_high != lhs_high) { |
| 2206 | __ Move(dst_high, lhs_high); |
| 2207 | } |
| 2208 | } else { |
| 2209 | if (instruction->IsSub()) { |
| 2210 | value = -value; |
| 2211 | } else { |
| 2212 | DCHECK(instruction->IsAdd()); |
| 2213 | } |
| 2214 | int32_t low = Low32Bits(value); |
| 2215 | int32_t high = High32Bits(value); |
| 2216 | if (IsInt<16>(low)) { |
| 2217 | if (dst_low != lhs_low || low != 0) { |
| 2218 | __ Addiu(dst_low, lhs_low, low); |
| 2219 | } |
| 2220 | if (low != 0) { |
| 2221 | __ Sltiu(AT, dst_low, low); |
| 2222 | } |
| 2223 | } else { |
| 2224 | __ LoadConst32(TMP, low); |
| 2225 | __ Addu(dst_low, lhs_low, TMP); |
| 2226 | __ Sltu(AT, dst_low, TMP); |
| 2227 | } |
| 2228 | if (IsInt<16>(high)) { |
| 2229 | if (dst_high != lhs_high || high != 0) { |
| 2230 | __ Addiu(dst_high, lhs_high, high); |
| 2231 | } |
| 2232 | } else { |
| 2233 | if (high != low) { |
| 2234 | __ LoadConst32(TMP, high); |
| 2235 | } |
| 2236 | __ Addu(dst_high, lhs_high, TMP); |
| 2237 | } |
| 2238 | if (low != 0) { |
| 2239 | __ Addu(dst_high, dst_high, AT); |
| 2240 | } |
| 2241 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2242 | } |
| 2243 | break; |
| 2244 | } |
| 2245 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2246 | case DataType::Type::kFloat32: |
| 2247 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2248 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2249 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2250 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2251 | if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2252 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2253 | __ AddS(dst, lhs, rhs); |
| 2254 | } else { |
| 2255 | __ AddD(dst, lhs, rhs); |
| 2256 | } |
| 2257 | } else { |
| 2258 | DCHECK(instruction->IsSub()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2259 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2260 | __ SubS(dst, lhs, rhs); |
| 2261 | } else { |
| 2262 | __ SubD(dst, lhs, rhs); |
| 2263 | } |
| 2264 | } |
| 2265 | break; |
| 2266 | } |
| 2267 | |
| 2268 | default: |
| 2269 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 2270 | } |
| 2271 | } |
| 2272 | |
| 2273 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2274 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2275 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2276 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2277 | DataType::Type type = instr->GetResultType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2278 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2279 | case DataType::Type::kInt32: |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2280 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2281 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2282 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2283 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2284 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2285 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2286 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2287 | locations->SetOut(Location::RequiresRegister()); |
| 2288 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2289 | default: |
| 2290 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; |
| 2295 | |
| 2296 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2297 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2298 | LocationSummary* locations = instr->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2299 | DataType::Type type = instr->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2300 | |
| 2301 | Location rhs_location = locations->InAt(1); |
| 2302 | bool use_imm = rhs_location.IsConstant(); |
| 2303 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); |
| 2304 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2305 | const uint32_t shift_mask = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2306 | (type == DataType::Type::kInt32) ? kMaxIntShiftDistance : kMaxLongShiftDistance; |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2307 | const uint32_t shift_value = rhs_imm & shift_mask; |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2308 | // Are the INS (Insert Bit Field) and ROTR instructions supported? |
| 2309 | bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2310 | |
| 2311 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2312 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2313 | Register dst = locations->Out().AsRegister<Register>(); |
| 2314 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2315 | if (use_imm) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2316 | if (shift_value == 0) { |
| 2317 | if (dst != lhs) { |
| 2318 | __ Move(dst, lhs); |
| 2319 | } |
| 2320 | } else if (instr->IsShl()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2321 | __ Sll(dst, lhs, shift_value); |
| 2322 | } else if (instr->IsShr()) { |
| 2323 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2324 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2325 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2326 | } else { |
| 2327 | if (has_ins_rotr) { |
| 2328 | __ Rotr(dst, lhs, shift_value); |
| 2329 | } else { |
| 2330 | __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask); |
| 2331 | __ Srl(dst, lhs, shift_value); |
| 2332 | __ Or(dst, dst, TMP); |
| 2333 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2334 | } |
| 2335 | } else { |
| 2336 | if (instr->IsShl()) { |
| 2337 | __ Sllv(dst, lhs, rhs_reg); |
| 2338 | } else if (instr->IsShr()) { |
| 2339 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2340 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2341 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2342 | } else { |
| 2343 | if (has_ins_rotr) { |
| 2344 | __ Rotrv(dst, lhs, rhs_reg); |
| 2345 | } else { |
| 2346 | __ Subu(TMP, ZERO, rhs_reg); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2347 | // 32-bit shift instructions use the 5 least significant bits of the shift count, so |
| 2348 | // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case |
| 2349 | // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out |
| 2350 | // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`, |
| 2351 | // IOW, the OR'd values are equal. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2352 | __ Sllv(TMP, lhs, TMP); |
| 2353 | __ Srlv(dst, lhs, rhs_reg); |
| 2354 | __ Or(dst, dst, TMP); |
| 2355 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2356 | } |
| 2357 | } |
| 2358 | break; |
| 2359 | } |
| 2360 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2361 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2362 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2363 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2364 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2365 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2366 | if (use_imm) { |
| 2367 | if (shift_value == 0) { |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 2368 | codegen_->MoveLocation(locations->Out(), locations->InAt(0), type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2369 | } else if (shift_value < kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2370 | if (has_ins_rotr) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2371 | if (instr->IsShl()) { |
| 2372 | __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2373 | __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value); |
| 2374 | __ Sll(dst_low, lhs_low, shift_value); |
| 2375 | } else if (instr->IsShr()) { |
| 2376 | __ Srl(dst_low, lhs_low, shift_value); |
| 2377 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2378 | __ Sra(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2379 | } else if (instr->IsUShr()) { |
| 2380 | __ Srl(dst_low, lhs_low, shift_value); |
| 2381 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2382 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2383 | } else { |
| 2384 | __ Srl(dst_low, lhs_low, shift_value); |
| 2385 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2386 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2387 | __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2388 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2389 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2390 | if (instr->IsShl()) { |
| 2391 | __ Sll(dst_low, lhs_low, shift_value); |
| 2392 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); |
| 2393 | __ Sll(dst_high, lhs_high, shift_value); |
| 2394 | __ Or(dst_high, dst_high, TMP); |
| 2395 | } else if (instr->IsShr()) { |
| 2396 | __ Sra(dst_high, lhs_high, shift_value); |
| 2397 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2398 | __ Srl(dst_low, lhs_low, shift_value); |
| 2399 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2400 | } else if (instr->IsUShr()) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2401 | __ Srl(dst_high, lhs_high, shift_value); |
| 2402 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2403 | __ Srl(dst_low, lhs_low, shift_value); |
| 2404 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2405 | } else { |
| 2406 | __ Srl(TMP, lhs_low, shift_value); |
| 2407 | __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value); |
| 2408 | __ Or(dst_low, dst_low, TMP); |
| 2409 | __ Srl(TMP, lhs_high, shift_value); |
| 2410 | __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2411 | __ Or(dst_high, dst_high, TMP); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2412 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2413 | } |
| 2414 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2415 | const uint32_t shift_value_high = shift_value - kMipsBitsPerWord; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2416 | if (instr->IsShl()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2417 | __ Sll(dst_high, lhs_low, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2418 | __ Move(dst_low, ZERO); |
| 2419 | } else if (instr->IsShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2420 | __ Sra(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2421 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2422 | } else if (instr->IsUShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2423 | __ Srl(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2424 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2425 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2426 | if (shift_value == kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2427 | // 64-bit rotation by 32 is just a swap. |
| 2428 | __ Move(dst_low, lhs_high); |
| 2429 | __ Move(dst_high, lhs_low); |
| 2430 | } else { |
| 2431 | if (has_ins_rotr) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2432 | __ Srl(dst_low, lhs_high, shift_value_high); |
| 2433 | __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high); |
| 2434 | __ Srl(dst_high, lhs_low, shift_value_high); |
| 2435 | __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2436 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2437 | __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high); |
| 2438 | __ Srl(dst_low, lhs_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2439 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2440 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high); |
| 2441 | __ Srl(dst_high, lhs_low, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2442 | __ Or(dst_high, dst_high, TMP); |
| 2443 | } |
| 2444 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2445 | } |
| 2446 | } |
| 2447 | } else { |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2448 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2449 | MipsLabel done; |
| 2450 | if (instr->IsShl()) { |
| 2451 | __ Sllv(dst_low, lhs_low, rhs_reg); |
| 2452 | __ Nor(AT, ZERO, rhs_reg); |
| 2453 | __ Srl(TMP, lhs_low, 1); |
| 2454 | __ Srlv(TMP, TMP, AT); |
| 2455 | __ Sllv(dst_high, lhs_high, rhs_reg); |
| 2456 | __ Or(dst_high, dst_high, TMP); |
| 2457 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2458 | if (isR6) { |
| 2459 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2460 | __ Move(dst_high, dst_low); |
| 2461 | __ Move(dst_low, ZERO); |
| 2462 | } else { |
| 2463 | __ Movn(dst_high, dst_low, TMP); |
| 2464 | __ Movn(dst_low, ZERO, TMP); |
| 2465 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2466 | } else if (instr->IsShr()) { |
| 2467 | __ Srav(dst_high, lhs_high, rhs_reg); |
| 2468 | __ Nor(AT, ZERO, rhs_reg); |
| 2469 | __ Sll(TMP, lhs_high, 1); |
| 2470 | __ Sllv(TMP, TMP, AT); |
| 2471 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2472 | __ Or(dst_low, dst_low, TMP); |
| 2473 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2474 | if (isR6) { |
| 2475 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2476 | __ Move(dst_low, dst_high); |
| 2477 | __ Sra(dst_high, dst_high, 31); |
| 2478 | } else { |
| 2479 | __ Sra(AT, dst_high, 31); |
| 2480 | __ Movn(dst_low, dst_high, TMP); |
| 2481 | __ Movn(dst_high, AT, TMP); |
| 2482 | } |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2483 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2484 | __ Srlv(dst_high, lhs_high, rhs_reg); |
| 2485 | __ Nor(AT, ZERO, rhs_reg); |
| 2486 | __ Sll(TMP, lhs_high, 1); |
| 2487 | __ Sllv(TMP, TMP, AT); |
| 2488 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2489 | __ Or(dst_low, dst_low, TMP); |
| 2490 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2491 | if (isR6) { |
| 2492 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2493 | __ Move(dst_low, dst_high); |
| 2494 | __ Move(dst_high, ZERO); |
| 2495 | } else { |
| 2496 | __ Movn(dst_low, dst_high, TMP); |
| 2497 | __ Movn(dst_high, ZERO, TMP); |
| 2498 | } |
| 2499 | } else { // Rotate. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2500 | __ Nor(AT, ZERO, rhs_reg); |
| 2501 | __ Srlv(TMP, lhs_low, rhs_reg); |
| 2502 | __ Sll(dst_low, lhs_high, 1); |
| 2503 | __ Sllv(dst_low, dst_low, AT); |
| 2504 | __ Or(dst_low, dst_low, TMP); |
| 2505 | __ Srlv(TMP, lhs_high, rhs_reg); |
| 2506 | __ Sll(dst_high, lhs_low, 1); |
| 2507 | __ Sllv(dst_high, dst_high, AT); |
| 2508 | __ Or(dst_high, dst_high, TMP); |
| 2509 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2510 | if (isR6) { |
| 2511 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2512 | __ Move(TMP, dst_high); |
| 2513 | __ Move(dst_high, dst_low); |
| 2514 | __ Move(dst_low, TMP); |
| 2515 | } else { |
| 2516 | __ Movn(AT, dst_high, TMP); |
| 2517 | __ Movn(dst_high, dst_low, TMP); |
| 2518 | __ Movn(dst_low, AT, TMP); |
| 2519 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2520 | } |
| 2521 | __ Bind(&done); |
| 2522 | } |
| 2523 | break; |
| 2524 | } |
| 2525 | |
| 2526 | default: |
| 2527 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2528 | } |
| 2529 | } |
| 2530 | |
| 2531 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { |
| 2532 | HandleBinaryOp(instruction); |
| 2533 | } |
| 2534 | |
| 2535 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { |
| 2536 | HandleBinaryOp(instruction); |
| 2537 | } |
| 2538 | |
| 2539 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { |
| 2540 | HandleBinaryOp(instruction); |
| 2541 | } |
| 2542 | |
| 2543 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { |
| 2544 | HandleBinaryOp(instruction); |
| 2545 | } |
| 2546 | |
| 2547 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2548 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2549 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2550 | kEmitCompilerReadBarrier && (type == DataType::Type::kReference); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2551 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2552 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2553 | object_array_get_with_read_barrier |
| 2554 | ? LocationSummary::kCallOnSlowPath |
| 2555 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 2556 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2557 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2558 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2559 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2560 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2561 | if (DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2562 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2563 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2564 | // The output overlaps in the case of an object array get with |
| 2565 | // read barriers enabled: we do not want the move to overwrite the |
| 2566 | // array's location, as we need it to emit the read barrier. |
| 2567 | locations->SetOut(Location::RequiresRegister(), |
| 2568 | object_array_get_with_read_barrier |
| 2569 | ? Location::kOutputOverlap |
| 2570 | : Location::kNoOutputOverlap); |
| 2571 | } |
| 2572 | // We need a temporary register for the read barrier marking slow |
| 2573 | // path in CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier. |
| 2574 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2575 | bool temp_needed = instruction->GetIndex()->IsConstant() |
| 2576 | ? !kBakerReadBarrierThunksEnableForFields |
| 2577 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2578 | if (temp_needed) { |
| 2579 | locations->AddTemp(Location::RequiresRegister()); |
| 2580 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2581 | } |
| 2582 | } |
| 2583 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2584 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS* codegen) { |
| 2585 | auto null_checker = [codegen, instruction]() { |
| 2586 | codegen->MaybeRecordImplicitNullCheck(instruction); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2587 | }; |
| 2588 | return null_checker; |
| 2589 | } |
| 2590 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2591 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 2592 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2593 | Location obj_loc = locations->InAt(0); |
| 2594 | Register obj = obj_loc.AsRegister<Register>(); |
| 2595 | Location out_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2596 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2597 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2598 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2599 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2600 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2601 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2602 | instruction->IsStringCharAt(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2603 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2604 | case DataType::Type::kBool: |
| 2605 | case DataType::Type::kUint8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2606 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2607 | if (index.IsConstant()) { |
| 2608 | size_t offset = |
| 2609 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2610 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2611 | } else { |
| 2612 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2613 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2614 | } |
| 2615 | break; |
| 2616 | } |
| 2617 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2618 | case DataType::Type::kInt8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2619 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2620 | if (index.IsConstant()) { |
| 2621 | size_t offset = |
| 2622 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2623 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2624 | } else { |
| 2625 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2626 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2627 | } |
| 2628 | break; |
| 2629 | } |
| 2630 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2631 | case DataType::Type::kUint16: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2632 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2633 | if (maybe_compressed_char_at) { |
| 2634 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2635 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
| 2636 | __ Sll(TMP, TMP, 31); // Extract compression flag into the most significant bit of TMP. |
| 2637 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2638 | "Expecting 0=compressed, 1=uncompressed"); |
| 2639 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2640 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2641 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2642 | if (maybe_compressed_char_at) { |
| 2643 | MipsLabel uncompressed_load, done; |
| 2644 | __ Bnez(TMP, &uncompressed_load); |
| 2645 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2646 | out, |
| 2647 | obj, |
| 2648 | data_offset + (const_index << TIMES_1)); |
| 2649 | __ B(&done); |
| 2650 | __ Bind(&uncompressed_load); |
| 2651 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2652 | out, |
| 2653 | obj, |
| 2654 | data_offset + (const_index << TIMES_2)); |
| 2655 | __ Bind(&done); |
| 2656 | } else { |
| 2657 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2658 | out, |
| 2659 | obj, |
| 2660 | data_offset + (const_index << TIMES_2), |
| 2661 | null_checker); |
| 2662 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2663 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2664 | Register index_reg = index.AsRegister<Register>(); |
| 2665 | if (maybe_compressed_char_at) { |
| 2666 | MipsLabel uncompressed_load, done; |
| 2667 | __ Bnez(TMP, &uncompressed_load); |
| 2668 | __ Addu(TMP, obj, index_reg); |
| 2669 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2670 | __ B(&done); |
| 2671 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2672 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2673 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2674 | __ Bind(&done); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2675 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2676 | __ Addu(TMP, index_reg, obj); |
| 2677 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2678 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2679 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2680 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
| 2681 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2682 | } |
| 2683 | break; |
| 2684 | } |
| 2685 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2686 | case DataType::Type::kInt16: { |
| 2687 | Register out = out_loc.AsRegister<Register>(); |
| 2688 | if (index.IsConstant()) { |
| 2689 | size_t offset = |
| 2690 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2691 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2692 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2693 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2694 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2695 | } else { |
| 2696 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_2, TMP); |
| 2697 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
| 2698 | } |
| 2699 | break; |
| 2700 | } |
| 2701 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2702 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2703 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2704 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2705 | if (index.IsConstant()) { |
| 2706 | size_t offset = |
| 2707 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2708 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2709 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2710 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2711 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2712 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2713 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2714 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2715 | } |
| 2716 | break; |
| 2717 | } |
| 2718 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2719 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2720 | static_assert( |
| 2721 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2722 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2723 | // /* HeapReference<Object> */ out = |
| 2724 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2725 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2726 | bool temp_needed = index.IsConstant() |
| 2727 | ? !kBakerReadBarrierThunksEnableForFields |
| 2728 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2729 | Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2730 | // Note that a potential implicit null check is handled in this |
| 2731 | // CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier call. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2732 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 2733 | if (index.IsConstant()) { |
| 2734 | // Array load with a constant index can be treated as a field load. |
| 2735 | size_t offset = |
| 2736 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2737 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2738 | out_loc, |
| 2739 | obj, |
| 2740 | offset, |
| 2741 | temp, |
| 2742 | /* needs_null_check */ false); |
| 2743 | } else { |
| 2744 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2745 | out_loc, |
| 2746 | obj, |
| 2747 | data_offset, |
| 2748 | index, |
| 2749 | temp, |
| 2750 | /* needs_null_check */ false); |
| 2751 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2752 | } else { |
| 2753 | Register out = out_loc.AsRegister<Register>(); |
| 2754 | if (index.IsConstant()) { |
| 2755 | size_t offset = |
| 2756 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2757 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
| 2758 | // If read barriers are enabled, emit read barriers other than |
| 2759 | // Baker's using a slow path (and also unpoison the loaded |
| 2760 | // reference, if heap poisoning is enabled). |
| 2761 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2762 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2763 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2764 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
| 2765 | // If read barriers are enabled, emit read barriers other than |
| 2766 | // Baker's using a slow path (and also unpoison the loaded |
| 2767 | // reference, if heap poisoning is enabled). |
| 2768 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2769 | out_loc, |
| 2770 | out_loc, |
| 2771 | obj_loc, |
| 2772 | data_offset, |
| 2773 | index); |
| 2774 | } |
| 2775 | } |
| 2776 | break; |
| 2777 | } |
| 2778 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2779 | case DataType::Type::kInt64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2780 | Register out = out_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2781 | if (index.IsConstant()) { |
| 2782 | size_t offset = |
| 2783 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2784 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2785 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2786 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2787 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2788 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2789 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2790 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2791 | } |
| 2792 | break; |
| 2793 | } |
| 2794 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2795 | case DataType::Type::kFloat32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2796 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2797 | if (index.IsConstant()) { |
| 2798 | size_t offset = |
| 2799 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2800 | __ LoadSFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2801 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2802 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2803 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2804 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2805 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2806 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2807 | } |
| 2808 | break; |
| 2809 | } |
| 2810 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2811 | case DataType::Type::kFloat64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2812 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2813 | if (index.IsConstant()) { |
| 2814 | size_t offset = |
| 2815 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2816 | __ LoadDFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2817 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2818 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2819 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2820 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2821 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2822 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2823 | } |
| 2824 | break; |
| 2825 | } |
| 2826 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2827 | case DataType::Type::kUint32: |
| 2828 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2829 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2830 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2831 | UNREACHABLE(); |
| 2832 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2836 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2837 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2838 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2839 | } |
| 2840 | |
| 2841 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 2842 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2843 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2844 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2845 | Register out = locations->Out().AsRegister<Register>(); |
| 2846 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2847 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2848 | // Mask out compression flag from String's array length. |
| 2849 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2850 | __ Srl(out, out, 1u); |
| 2851 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2852 | } |
| 2853 | |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2854 | Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2855 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2856 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2857 | : Location::RequiresRegister(); |
| 2858 | } |
| 2859 | |
| 2860 | Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2861 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2862 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2863 | // but we should only prefer this if the constant has a single use. |
| 2864 | if (instruction->IsConstant() && |
| 2865 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2866 | instruction->GetUses().HasExactlyOneElement())) { |
| 2867 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2868 | // Otherwise fall through and require an FPU register for the constant. |
| 2869 | } |
| 2870 | return Location::RequiresFpuRegister(); |
| 2871 | } |
| 2872 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2873 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2874 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2875 | |
| 2876 | bool needs_write_barrier = |
| 2877 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2878 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2879 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2880 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2881 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2882 | may_need_runtime_call_for_type_check ? |
| 2883 | LocationSummary::kCallOnSlowPath : |
| 2884 | LocationSummary::kNoCall); |
| 2885 | |
| 2886 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2887 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2888 | if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2889 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2890 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2891 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2892 | } |
| 2893 | if (needs_write_barrier) { |
| 2894 | // Temporary register for the write barrier. |
| 2895 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2896 | } |
| 2897 | } |
| 2898 | |
| 2899 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { |
| 2900 | LocationSummary* locations = instruction->GetLocations(); |
| 2901 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2902 | Location index = locations->InAt(1); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2903 | Location value_location = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2904 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2905 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2906 | bool needs_write_barrier = |
| 2907 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2908 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2909 | Register base_reg = index.IsConstant() ? obj : TMP; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2910 | |
| 2911 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2912 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2913 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2914 | case DataType::Type::kInt8: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2915 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2916 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2917 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2918 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2919 | __ Addu(base_reg, obj, index.AsRegister<Register>()); |
| 2920 | } |
| 2921 | if (value_location.IsConstant()) { |
| 2922 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2923 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2924 | } else { |
| 2925 | Register value = value_location.AsRegister<Register>(); |
| 2926 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2927 | } |
| 2928 | break; |
| 2929 | } |
| 2930 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2931 | case DataType::Type::kUint16: |
| 2932 | case DataType::Type::kInt16: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2933 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2934 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2935 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2936 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2937 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2938 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2939 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_2, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2940 | } |
| 2941 | if (value_location.IsConstant()) { |
| 2942 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2943 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2944 | } else { |
| 2945 | Register value = value_location.AsRegister<Register>(); |
| 2946 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2947 | } |
| 2948 | break; |
| 2949 | } |
| 2950 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2951 | case DataType::Type::kInt32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2952 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2953 | if (index.IsConstant()) { |
| 2954 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2955 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2956 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2957 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2958 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2959 | } |
| 2960 | if (value_location.IsConstant()) { |
| 2961 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2962 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2963 | } else { |
| 2964 | Register value = value_location.AsRegister<Register>(); |
| 2965 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2966 | } |
| 2967 | break; |
| 2968 | } |
| 2969 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2970 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2971 | if (value_location.IsConstant()) { |
| 2972 | // Just setting null. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2973 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2974 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2975 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2976 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2977 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2978 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2979 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2980 | DCHECK_EQ(value, 0); |
| 2981 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2982 | DCHECK(!needs_write_barrier); |
| 2983 | DCHECK(!may_need_runtime_call_for_type_check); |
| 2984 | break; |
| 2985 | } |
| 2986 | |
| 2987 | DCHECK(needs_write_barrier); |
| 2988 | Register value = value_location.AsRegister<Register>(); |
| 2989 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2990 | Register temp2 = TMP; // Doesn't need to survive slow path. |
| 2991 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2992 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2993 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2994 | MipsLabel done; |
| 2995 | SlowPathCodeMIPS* slow_path = nullptr; |
| 2996 | |
| 2997 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2998 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS(instruction); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2999 | codegen_->AddSlowPath(slow_path); |
| 3000 | if (instruction->GetValueCanBeNull()) { |
| 3001 | MipsLabel non_zero; |
| 3002 | __ Bnez(value, &non_zero); |
| 3003 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3004 | if (index.IsConstant()) { |
| 3005 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3006 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3007 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 3008 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3009 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 3010 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3011 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 3012 | __ B(&done); |
| 3013 | __ Bind(&non_zero); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3014 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3015 | |
| 3016 | // Note that when read barriers are enabled, the type checks |
| 3017 | // are performed without read barriers. This is fine, even in |
| 3018 | // the case where a class object is in the from-space after |
| 3019 | // the flip, as a comparison involving such a type would not |
| 3020 | // produce a false positive; it may of course produce a false |
| 3021 | // negative, in which case we would take the ArraySet slow |
| 3022 | // path. |
| 3023 | |
| 3024 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 3025 | __ LoadFromOffset(kLoadWord, temp1, obj, class_offset, null_checker); |
| 3026 | __ MaybeUnpoisonHeapReference(temp1); |
| 3027 | |
| 3028 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 3029 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 3030 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3031 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 3032 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 3033 | // nor `temp2`, as we are comparing two poisoned references. |
| 3034 | |
| 3035 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3036 | MipsLabel do_put; |
| 3037 | __ Beq(temp1, temp2, &do_put); |
| 3038 | // If heap poisoning is enabled, the `temp1` reference has |
| 3039 | // not been unpoisoned yet; unpoison it now. |
| 3040 | __ MaybeUnpoisonHeapReference(temp1); |
| 3041 | |
| 3042 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 3043 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 3044 | // If heap poisoning is enabled, no need to unpoison |
| 3045 | // `temp1`, as we are comparing against null below. |
| 3046 | __ Bnez(temp1, slow_path->GetEntryLabel()); |
| 3047 | __ Bind(&do_put); |
| 3048 | } else { |
| 3049 | __ Bne(temp1, temp2, slow_path->GetEntryLabel()); |
| 3050 | } |
| 3051 | } |
| 3052 | |
| 3053 | Register source = value; |
| 3054 | if (kPoisonHeapReferences) { |
| 3055 | // Note that in the case where `value` is a null reference, |
| 3056 | // we do not enter this block, as a null reference does not |
| 3057 | // need poisoning. |
| 3058 | __ Move(temp1, value); |
| 3059 | __ PoisonHeapReference(temp1); |
| 3060 | source = temp1; |
| 3061 | } |
| 3062 | |
| 3063 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3064 | if (index.IsConstant()) { |
| 3065 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3066 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3067 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3068 | } |
| 3069 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 3070 | |
| 3071 | if (!may_need_runtime_call_for_type_check) { |
| 3072 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3073 | } |
| 3074 | |
| 3075 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 3076 | |
| 3077 | if (done.IsLinked()) { |
| 3078 | __ Bind(&done); |
| 3079 | } |
| 3080 | |
| 3081 | if (slow_path != nullptr) { |
| 3082 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3083 | } |
| 3084 | break; |
| 3085 | } |
| 3086 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3087 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3088 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3089 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3090 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3091 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3092 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3093 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3094 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3095 | } |
| 3096 | if (value_location.IsConstant()) { |
| 3097 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3098 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3099 | } else { |
| 3100 | Register value = value_location.AsRegisterPairLow<Register>(); |
| 3101 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3102 | } |
| 3103 | break; |
| 3104 | } |
| 3105 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3106 | case DataType::Type::kFloat32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3107 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3108 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3109 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3110 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3111 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3112 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3113 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3114 | } |
| 3115 | if (value_location.IsConstant()) { |
| 3116 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3117 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 3118 | } else { |
| 3119 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3120 | __ StoreSToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3121 | } |
| 3122 | break; |
| 3123 | } |
| 3124 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3125 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3126 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3127 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3128 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3129 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3130 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3131 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3132 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3133 | } |
| 3134 | if (value_location.IsConstant()) { |
| 3135 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3136 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3137 | } else { |
| 3138 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3139 | __ StoreDToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3140 | } |
| 3141 | break; |
| 3142 | } |
| 3143 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 3144 | case DataType::Type::kUint32: |
| 3145 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3146 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3147 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 3148 | UNREACHABLE(); |
| 3149 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3150 | } |
| 3151 | |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3152 | void LocationsBuilderMIPS::VisitIntermediateArrayAddressIndex( |
| 3153 | HIntermediateArrayAddressIndex* instruction) { |
| 3154 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3155 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3156 | |
| 3157 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 3158 | |
| 3159 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3160 | locations->SetInAt(1, Location::ConstantLocation(shift)); |
| 3161 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3162 | } |
| 3163 | |
| 3164 | void InstructionCodeGeneratorMIPS::VisitIntermediateArrayAddressIndex( |
| 3165 | HIntermediateArrayAddressIndex* instruction) { |
| 3166 | LocationSummary* locations = instruction->GetLocations(); |
| 3167 | Register index_reg = locations->InAt(0).AsRegister<Register>(); |
| 3168 | uint32_t shift = instruction->GetShift()->AsIntConstant()->GetValue(); |
| 3169 | __ Sll(locations->Out().AsRegister<Register>(), index_reg, shift); |
| 3170 | } |
| 3171 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3172 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3173 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3174 | InvokeRuntimeCallingConvention calling_convention; |
| 3175 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3176 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3177 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3178 | |
| 3179 | HInstruction* index = instruction->InputAt(0); |
| 3180 | HInstruction* length = instruction->InputAt(1); |
| 3181 | |
| 3182 | bool const_index = false; |
| 3183 | bool const_length = false; |
| 3184 | |
| 3185 | if (index->IsConstant()) { |
| 3186 | if (length->IsConstant()) { |
| 3187 | const_index = true; |
| 3188 | const_length = true; |
| 3189 | } else { |
| 3190 | int32_t index_value = index->AsIntConstant()->GetValue(); |
| 3191 | if (index_value < 0 || IsInt<16>(index_value + 1)) { |
| 3192 | const_index = true; |
| 3193 | } |
| 3194 | } |
| 3195 | } else if (length->IsConstant()) { |
| 3196 | int32_t length_value = length->AsIntConstant()->GetValue(); |
| 3197 | if (IsUint<15>(length_value)) { |
| 3198 | const_length = true; |
| 3199 | } |
| 3200 | } |
| 3201 | |
| 3202 | locations->SetInAt(0, const_index |
| 3203 | ? Location::ConstantLocation(index->AsConstant()) |
| 3204 | : Location::RequiresRegister()); |
| 3205 | locations->SetInAt(1, const_length |
| 3206 | ? Location::ConstantLocation(length->AsConstant()) |
| 3207 | : Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3208 | } |
| 3209 | |
| 3210 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 3211 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3212 | Location index_loc = locations->InAt(0); |
| 3213 | Location length_loc = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3214 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3215 | if (length_loc.IsConstant()) { |
| 3216 | int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3217 | if (index_loc.IsConstant()) { |
| 3218 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3219 | if (index < 0 || index >= length) { |
| 3220 | BoundsCheckSlowPathMIPS* slow_path = |
| 3221 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3222 | codegen_->AddSlowPath(slow_path); |
| 3223 | __ B(slow_path->GetEntryLabel()); |
| 3224 | } else { |
| 3225 | // Nothing to be done. |
| 3226 | } |
| 3227 | return; |
| 3228 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3229 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3230 | BoundsCheckSlowPathMIPS* slow_path = |
| 3231 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3232 | codegen_->AddSlowPath(slow_path); |
| 3233 | Register index = index_loc.AsRegister<Register>(); |
| 3234 | if (length == 0) { |
| 3235 | __ B(slow_path->GetEntryLabel()); |
| 3236 | } else if (length == 1) { |
| 3237 | __ Bnez(index, slow_path->GetEntryLabel()); |
| 3238 | } else { |
| 3239 | DCHECK(IsUint<15>(length)) << length; |
| 3240 | __ Sltiu(TMP, index, length); |
| 3241 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3242 | } |
| 3243 | } else { |
| 3244 | Register length = length_loc.AsRegister<Register>(); |
| 3245 | BoundsCheckSlowPathMIPS* slow_path = |
| 3246 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3247 | codegen_->AddSlowPath(slow_path); |
| 3248 | if (index_loc.IsConstant()) { |
| 3249 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3250 | if (index < 0) { |
| 3251 | __ B(slow_path->GetEntryLabel()); |
| 3252 | } else if (index == 0) { |
| 3253 | __ Blez(length, slow_path->GetEntryLabel()); |
| 3254 | } else { |
| 3255 | DCHECK(IsInt<16>(index + 1)) << index; |
| 3256 | __ Sltiu(TMP, length, index + 1); |
| 3257 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 3258 | } |
| 3259 | } else { |
| 3260 | Register index = index_loc.AsRegister<Register>(); |
| 3261 | __ Bgeu(index, length, slow_path->GetEntryLabel()); |
| 3262 | } |
| 3263 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3264 | } |
| 3265 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3266 | // Temp is used for read barrier. |
| 3267 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3268 | if (kEmitCompilerReadBarrier && |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 3269 | !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) && |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3270 | (kUseBakerReadBarrier || |
| 3271 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3272 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3273 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3274 | return 1; |
| 3275 | } |
| 3276 | return 0; |
| 3277 | } |
| 3278 | |
| 3279 | // Extra temp is used for read barrier. |
| 3280 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3281 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 3282 | } |
| 3283 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3284 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3285 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 3286 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3287 | LocationSummary* locations = |
| 3288 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3289 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 3290 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3291 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3292 | } |
| 3293 | |
| 3294 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3295 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3296 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3297 | Location obj_loc = locations->InAt(0); |
| 3298 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 3299 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3300 | Location temp_loc = locations->GetTemp(0); |
| 3301 | Register temp = temp_loc.AsRegister<Register>(); |
| 3302 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 3303 | DCHECK_LE(num_temps, 2u); |
| 3304 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3305 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3306 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3307 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3308 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 3309 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 3310 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 3311 | const uint32_t object_array_data_offset = |
| 3312 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 3313 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3314 | |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 3315 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3316 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3317 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 3318 | instruction, is_type_check_slow_path_fatal); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3319 | codegen_->AddSlowPath(slow_path); |
| 3320 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3321 | // Avoid this check if we know `obj` is not null. |
| 3322 | if (instruction->MustDoNullCheck()) { |
| 3323 | __ Beqz(obj, &done); |
| 3324 | } |
| 3325 | |
| 3326 | switch (type_check_kind) { |
| 3327 | case TypeCheckKind::kExactCheck: |
| 3328 | case TypeCheckKind::kArrayCheck: { |
| 3329 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3330 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3331 | temp_loc, |
| 3332 | obj_loc, |
| 3333 | class_offset, |
| 3334 | maybe_temp2_loc, |
| 3335 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3336 | // Jump to slow path for throwing the exception or doing a |
| 3337 | // more involved array check. |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 3338 | __ Bne(temp, cls, slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3339 | break; |
| 3340 | } |
| 3341 | |
| 3342 | case TypeCheckKind::kAbstractClassCheck: { |
| 3343 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3344 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3345 | temp_loc, |
| 3346 | obj_loc, |
| 3347 | class_offset, |
| 3348 | maybe_temp2_loc, |
| 3349 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3350 | // If the class is abstract, we eagerly fetch the super class of the |
| 3351 | // object to avoid doing a comparison we know will fail. |
| 3352 | MipsLabel loop; |
| 3353 | __ Bind(&loop); |
| 3354 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3355 | GenerateReferenceLoadOneRegister(instruction, |
| 3356 | temp_loc, |
| 3357 | super_offset, |
| 3358 | maybe_temp2_loc, |
| 3359 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3360 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3361 | // exception. |
| 3362 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3363 | // Otherwise, compare the classes. |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 3364 | __ Bne(temp, cls, &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3365 | break; |
| 3366 | } |
| 3367 | |
| 3368 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3369 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3370 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3371 | temp_loc, |
| 3372 | obj_loc, |
| 3373 | class_offset, |
| 3374 | maybe_temp2_loc, |
| 3375 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3376 | // Walk over the class hierarchy to find a match. |
| 3377 | MipsLabel loop; |
| 3378 | __ Bind(&loop); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 3379 | __ Beq(temp, cls, &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3380 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3381 | GenerateReferenceLoadOneRegister(instruction, |
| 3382 | temp_loc, |
| 3383 | super_offset, |
| 3384 | maybe_temp2_loc, |
| 3385 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3386 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3387 | // exception. Otherwise, jump to the beginning of the loop. |
| 3388 | __ Bnez(temp, &loop); |
| 3389 | __ B(slow_path->GetEntryLabel()); |
| 3390 | break; |
| 3391 | } |
| 3392 | |
| 3393 | case TypeCheckKind::kArrayObjectCheck: { |
| 3394 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3395 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3396 | temp_loc, |
| 3397 | obj_loc, |
| 3398 | class_offset, |
| 3399 | maybe_temp2_loc, |
| 3400 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3401 | // Do an exact check. |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 3402 | __ Beq(temp, cls, &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3403 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 3404 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3405 | GenerateReferenceLoadOneRegister(instruction, |
| 3406 | temp_loc, |
| 3407 | component_offset, |
| 3408 | maybe_temp2_loc, |
| 3409 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3410 | // If the component type is null, jump to the slow path to throw the exception. |
| 3411 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3412 | // Otherwise, the object is indeed an array, further check that this component |
| 3413 | // type is not a primitive type. |
| 3414 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 3415 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3416 | __ Bnez(temp, slow_path->GetEntryLabel()); |
| 3417 | break; |
| 3418 | } |
| 3419 | |
| 3420 | case TypeCheckKind::kUnresolvedCheck: |
| 3421 | // We always go into the type check slow path for the unresolved check case. |
| 3422 | // We cannot directly call the CheckCast runtime entry point |
| 3423 | // without resorting to a type checking slow path here (i.e. by |
| 3424 | // calling InvokeRuntime directly), as it would require to |
| 3425 | // assign fixed registers for the inputs of this HInstanceOf |
| 3426 | // instruction (following the runtime calling convention), which |
| 3427 | // might be cluttered by the potential first read barrier |
| 3428 | // emission at the beginning of this method. |
| 3429 | __ B(slow_path->GetEntryLabel()); |
| 3430 | break; |
| 3431 | |
| 3432 | case TypeCheckKind::kInterfaceCheck: { |
| 3433 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 3434 | // positives by doing this. |
| 3435 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3436 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3437 | temp_loc, |
| 3438 | obj_loc, |
| 3439 | class_offset, |
| 3440 | maybe_temp2_loc, |
| 3441 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3442 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3443 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3444 | temp_loc, |
| 3445 | temp_loc, |
| 3446 | iftable_offset, |
| 3447 | maybe_temp2_loc, |
| 3448 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3449 | // Iftable is never null. |
| 3450 | __ Lw(TMP, temp, array_length_offset); |
| 3451 | // Loop through the iftable and check if any class matches. |
| 3452 | MipsLabel loop; |
| 3453 | __ Bind(&loop); |
| 3454 | __ Addiu(temp, temp, 2 * kHeapReferenceSize); // Possibly in delay slot on R2. |
| 3455 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3456 | __ Lw(AT, temp, object_array_data_offset - 2 * kHeapReferenceSize); |
| 3457 | __ MaybeUnpoisonHeapReference(AT); |
| 3458 | // Go to next interface. |
| 3459 | __ Addiu(TMP, TMP, -2); |
| 3460 | // Compare the classes and continue the loop if they do not match. |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 3461 | __ Bne(AT, cls, &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3462 | break; |
| 3463 | } |
| 3464 | } |
| 3465 | |
| 3466 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3467 | __ Bind(slow_path->GetExitLabel()); |
| 3468 | } |
| 3469 | |
| 3470 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3471 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3472 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3473 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3474 | if (check->HasUses()) { |
| 3475 | locations->SetOut(Location::SameAsFirstInput()); |
| 3476 | } |
| 3477 | } |
| 3478 | |
| 3479 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3480 | // We assume the class is not null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3481 | SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS( |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3482 | check->GetLoadClass(), |
| 3483 | check, |
| 3484 | check->GetDexPc(), |
| 3485 | true); |
| 3486 | codegen_->AddSlowPath(slow_path); |
| 3487 | GenerateClassInitializationCheck(slow_path, |
| 3488 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| 3489 | } |
| 3490 | |
| 3491 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3492 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3493 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3494 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3495 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3496 | |
| 3497 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3498 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3499 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3500 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3501 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3502 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3503 | case DataType::Type::kInt32: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3504 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3505 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3506 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3507 | break; |
| 3508 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3509 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3510 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3511 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3512 | // Output overlaps because it is written before doing the low comparison. |
| 3513 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3514 | break; |
| 3515 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3516 | case DataType::Type::kFloat32: |
| 3517 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3518 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3519 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3520 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3521 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3522 | |
| 3523 | default: |
| 3524 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3525 | } |
| 3526 | } |
| 3527 | |
| 3528 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { |
| 3529 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3530 | Register res = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3531 | DataType::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3532 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3533 | |
| 3534 | // 0 if: left == right |
| 3535 | // 1 if: left > right |
| 3536 | // -1 if: left < right |
| 3537 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3538 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3539 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3540 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3541 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3542 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3543 | case DataType::Type::kInt32: { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3544 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3545 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 3546 | __ Slt(TMP, lhs, rhs); |
| 3547 | __ Slt(res, rhs, lhs); |
| 3548 | __ Subu(res, res, TMP); |
| 3549 | break; |
| 3550 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3551 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3552 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3553 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3554 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3555 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 3556 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 3557 | // TODO: more efficient (direct) comparison with a constant. |
| 3558 | __ Slt(TMP, lhs_high, rhs_high); |
| 3559 | __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt. |
| 3560 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3561 | __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal. |
| 3562 | __ Sltu(TMP, lhs_low, rhs_low); |
| 3563 | __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt. |
| 3564 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3565 | __ Bind(&done); |
| 3566 | break; |
| 3567 | } |
| 3568 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3569 | case DataType::Type::kFloat32: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3570 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3571 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3572 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3573 | MipsLabel done; |
| 3574 | if (isR6) { |
| 3575 | __ CmpEqS(FTMP, lhs, rhs); |
| 3576 | __ LoadConst32(res, 0); |
| 3577 | __ Bc1nez(FTMP, &done); |
| 3578 | if (gt_bias) { |
| 3579 | __ CmpLtS(FTMP, lhs, rhs); |
| 3580 | __ LoadConst32(res, -1); |
| 3581 | __ Bc1nez(FTMP, &done); |
| 3582 | __ LoadConst32(res, 1); |
| 3583 | } else { |
| 3584 | __ CmpLtS(FTMP, rhs, lhs); |
| 3585 | __ LoadConst32(res, 1); |
| 3586 | __ Bc1nez(FTMP, &done); |
| 3587 | __ LoadConst32(res, -1); |
| 3588 | } |
| 3589 | } else { |
| 3590 | if (gt_bias) { |
| 3591 | __ ColtS(0, lhs, rhs); |
| 3592 | __ LoadConst32(res, -1); |
| 3593 | __ Bc1t(0, &done); |
| 3594 | __ CeqS(0, lhs, rhs); |
| 3595 | __ LoadConst32(res, 1); |
| 3596 | __ Movt(res, ZERO, 0); |
| 3597 | } else { |
| 3598 | __ ColtS(0, rhs, lhs); |
| 3599 | __ LoadConst32(res, 1); |
| 3600 | __ Bc1t(0, &done); |
| 3601 | __ CeqS(0, lhs, rhs); |
| 3602 | __ LoadConst32(res, -1); |
| 3603 | __ Movt(res, ZERO, 0); |
| 3604 | } |
| 3605 | } |
| 3606 | __ Bind(&done); |
| 3607 | break; |
| 3608 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3609 | case DataType::Type::kFloat64: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3610 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3611 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3612 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3613 | MipsLabel done; |
| 3614 | if (isR6) { |
| 3615 | __ CmpEqD(FTMP, lhs, rhs); |
| 3616 | __ LoadConst32(res, 0); |
| 3617 | __ Bc1nez(FTMP, &done); |
| 3618 | if (gt_bias) { |
| 3619 | __ CmpLtD(FTMP, lhs, rhs); |
| 3620 | __ LoadConst32(res, -1); |
| 3621 | __ Bc1nez(FTMP, &done); |
| 3622 | __ LoadConst32(res, 1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3623 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3624 | __ CmpLtD(FTMP, rhs, lhs); |
| 3625 | __ LoadConst32(res, 1); |
| 3626 | __ Bc1nez(FTMP, &done); |
| 3627 | __ LoadConst32(res, -1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3628 | } |
| 3629 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3630 | if (gt_bias) { |
| 3631 | __ ColtD(0, lhs, rhs); |
| 3632 | __ LoadConst32(res, -1); |
| 3633 | __ Bc1t(0, &done); |
| 3634 | __ CeqD(0, lhs, rhs); |
| 3635 | __ LoadConst32(res, 1); |
| 3636 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3637 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3638 | __ ColtD(0, rhs, lhs); |
| 3639 | __ LoadConst32(res, 1); |
| 3640 | __ Bc1t(0, &done); |
| 3641 | __ CeqD(0, lhs, rhs); |
| 3642 | __ LoadConst32(res, -1); |
| 3643 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3644 | } |
| 3645 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3646 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3647 | break; |
| 3648 | } |
| 3649 | |
| 3650 | default: |
| 3651 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3652 | } |
| 3653 | } |
| 3654 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3655 | void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3656 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3657 | switch (instruction->InputAt(0)->GetType()) { |
| 3658 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3659 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3660 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3661 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3662 | break; |
| 3663 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3664 | case DataType::Type::kFloat32: |
| 3665 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3666 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3667 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3668 | break; |
| 3669 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3670 | if (!instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3671 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3672 | } |
| 3673 | } |
| 3674 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3675 | void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3676 | if (instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3677 | return; |
| 3678 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3679 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3680 | DataType::Type type = instruction->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3681 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3682 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3683 | switch (type) { |
| 3684 | default: |
| 3685 | // Integer case. |
| 3686 | GenerateIntCompare(instruction->GetCondition(), locations); |
| 3687 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3688 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3689 | case DataType::Type::kInt64: |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 3690 | GenerateLongCompare(instruction->GetCondition(), locations); |
| 3691 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3692 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3693 | case DataType::Type::kFloat32: |
| 3694 | case DataType::Type::kFloat64: |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 3695 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 3696 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3697 | } |
| 3698 | } |
| 3699 | |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3700 | void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3701 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3702 | |
| 3703 | LocationSummary* locations = instruction->GetLocations(); |
| 3704 | Location second = locations->InAt(1); |
| 3705 | DCHECK(second.IsConstant()); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3706 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3707 | DCHECK(imm == 1 || imm == -1); |
| 3708 | |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3709 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 3710 | Register out = locations->Out().AsRegister<Register>(); |
| 3711 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3712 | |
| 3713 | if (instruction->IsRem()) { |
| 3714 | __ Move(out, ZERO); |
| 3715 | } else { |
| 3716 | if (imm == -1) { |
| 3717 | __ Subu(out, ZERO, dividend); |
| 3718 | } else if (out != dividend) { |
| 3719 | __ Move(out, dividend); |
| 3720 | } |
| 3721 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3722 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3723 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 3724 | Register out_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 3725 | Register out_low = locations->Out().AsRegisterPairLow<Register>(); |
| 3726 | Register in_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3727 | Register in_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3728 | |
| 3729 | if (instruction->IsRem()) { |
| 3730 | __ Move(out_high, ZERO); |
| 3731 | __ Move(out_low, ZERO); |
| 3732 | } else { |
| 3733 | if (imm == -1) { |
| 3734 | __ Subu(out_low, ZERO, in_low); |
| 3735 | __ Sltu(AT, ZERO, out_low); |
| 3736 | __ Subu(out_high, ZERO, in_high); |
| 3737 | __ Subu(out_high, out_high, AT); |
| 3738 | } else { |
| 3739 | __ Move(out_low, in_low); |
| 3740 | __ Move(out_high, in_high); |
| 3741 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3742 | } |
| 3743 | } |
| 3744 | } |
| 3745 | |
| 3746 | void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3747 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3748 | |
| 3749 | LocationSummary* locations = instruction->GetLocations(); |
| 3750 | Location second = locations->InAt(1); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3751 | const bool is_r2_or_newer = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
| 3752 | const bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3753 | DCHECK(second.IsConstant()); |
| 3754 | |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3755 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 3756 | Register out = locations->Out().AsRegister<Register>(); |
| 3757 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3758 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3759 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 3760 | int ctz_imm = CTZ(abs_imm); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3761 | |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3762 | if (instruction->IsDiv()) { |
| 3763 | if (ctz_imm == 1) { |
| 3764 | // Fast path for division by +/-2, which is very common. |
| 3765 | __ Srl(TMP, dividend, 31); |
| 3766 | } else { |
| 3767 | __ Sra(TMP, dividend, 31); |
| 3768 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3769 | } |
| 3770 | __ Addu(out, dividend, TMP); |
| 3771 | __ Sra(out, out, ctz_imm); |
| 3772 | if (imm < 0) { |
| 3773 | __ Subu(out, ZERO, out); |
| 3774 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3775 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3776 | if (ctz_imm == 1) { |
| 3777 | // Fast path for modulo +/-2, which is very common. |
| 3778 | __ Sra(TMP, dividend, 31); |
| 3779 | __ Subu(out, dividend, TMP); |
| 3780 | __ Andi(out, out, 1); |
| 3781 | __ Addu(out, out, TMP); |
| 3782 | } else { |
| 3783 | __ Sra(TMP, dividend, 31); |
| 3784 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3785 | __ Addu(out, dividend, TMP); |
| 3786 | if (IsUint<16>(abs_imm - 1)) { |
| 3787 | __ Andi(out, out, abs_imm - 1); |
| 3788 | } else { |
| 3789 | if (is_r2_or_newer) { |
| 3790 | __ Ins(out, ZERO, ctz_imm, 32 - ctz_imm); |
| 3791 | } else { |
| 3792 | __ Sll(out, out, 32 - ctz_imm); |
| 3793 | __ Srl(out, out, 32 - ctz_imm); |
| 3794 | } |
| 3795 | } |
| 3796 | __ Subu(out, out, TMP); |
| 3797 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3798 | } |
| 3799 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3800 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 3801 | Register out_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 3802 | Register out_low = locations->Out().AsRegisterPairLow<Register>(); |
| 3803 | Register in_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3804 | Register in_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3805 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3806 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 3807 | int ctz_imm = CTZ(abs_imm); |
| 3808 | |
| 3809 | if (instruction->IsDiv()) { |
| 3810 | if (ctz_imm < 32) { |
| 3811 | if (ctz_imm == 1) { |
| 3812 | __ Srl(AT, in_high, 31); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3813 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3814 | __ Sra(AT, in_high, 31); |
| 3815 | __ Srl(AT, AT, 32 - ctz_imm); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3816 | } |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3817 | __ Addu(AT, AT, in_low); |
| 3818 | __ Sltu(TMP, AT, in_low); |
| 3819 | __ Addu(out_high, in_high, TMP); |
| 3820 | __ Srl(out_low, AT, ctz_imm); |
| 3821 | if (is_r2_or_newer) { |
| 3822 | __ Ins(out_low, out_high, 32 - ctz_imm, ctz_imm); |
| 3823 | __ Sra(out_high, out_high, ctz_imm); |
| 3824 | } else { |
| 3825 | __ Sll(AT, out_high, 32 - ctz_imm); |
| 3826 | __ Sra(out_high, out_high, ctz_imm); |
| 3827 | __ Or(out_low, out_low, AT); |
| 3828 | } |
| 3829 | if (imm < 0) { |
| 3830 | __ Subu(out_low, ZERO, out_low); |
| 3831 | __ Sltu(AT, ZERO, out_low); |
| 3832 | __ Subu(out_high, ZERO, out_high); |
| 3833 | __ Subu(out_high, out_high, AT); |
| 3834 | } |
| 3835 | } else if (ctz_imm == 32) { |
| 3836 | __ Sra(AT, in_high, 31); |
| 3837 | __ Addu(AT, AT, in_low); |
| 3838 | __ Sltu(AT, AT, in_low); |
| 3839 | __ Addu(out_low, in_high, AT); |
| 3840 | if (imm < 0) { |
| 3841 | __ Srl(TMP, out_low, 31); |
| 3842 | __ Subu(out_low, ZERO, out_low); |
| 3843 | __ Sltu(AT, ZERO, out_low); |
| 3844 | __ Subu(out_high, TMP, AT); |
| 3845 | } else { |
| 3846 | __ Sra(out_high, out_low, 31); |
| 3847 | } |
| 3848 | } else if (ctz_imm < 63) { |
| 3849 | __ Sra(AT, in_high, 31); |
| 3850 | __ Srl(TMP, AT, 64 - ctz_imm); |
| 3851 | __ Addu(AT, AT, in_low); |
| 3852 | __ Sltu(AT, AT, in_low); |
| 3853 | __ Addu(out_low, in_high, AT); |
| 3854 | __ Addu(out_low, out_low, TMP); |
| 3855 | __ Sra(out_low, out_low, ctz_imm - 32); |
| 3856 | if (imm < 0) { |
| 3857 | __ Subu(out_low, ZERO, out_low); |
| 3858 | } |
| 3859 | __ Sra(out_high, out_low, 31); |
| 3860 | } else { |
| 3861 | DCHECK_LT(imm, 0); |
| 3862 | if (is_r6) { |
| 3863 | __ Aui(AT, in_high, 0x8000); |
| 3864 | } else { |
| 3865 | __ Lui(AT, 0x8000); |
| 3866 | __ Xor(AT, AT, in_high); |
| 3867 | } |
| 3868 | __ Or(AT, AT, in_low); |
| 3869 | __ Sltiu(out_low, AT, 1); |
| 3870 | __ Move(out_high, ZERO); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3871 | } |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3872 | } else { |
| 3873 | if ((ctz_imm == 1) && !is_r6) { |
| 3874 | __ Andi(AT, in_low, 1); |
| 3875 | __ Sll(TMP, in_low, 31); |
| 3876 | __ And(TMP, in_high, TMP); |
| 3877 | __ Sra(out_high, TMP, 31); |
| 3878 | __ Or(out_low, out_high, AT); |
| 3879 | } else if (ctz_imm < 32) { |
| 3880 | __ Sra(AT, in_high, 31); |
| 3881 | if (ctz_imm <= 16) { |
| 3882 | __ Andi(out_low, in_low, abs_imm - 1); |
| 3883 | } else if (is_r2_or_newer) { |
| 3884 | __ Ext(out_low, in_low, 0, ctz_imm); |
| 3885 | } else { |
| 3886 | __ Sll(out_low, in_low, 32 - ctz_imm); |
| 3887 | __ Srl(out_low, out_low, 32 - ctz_imm); |
| 3888 | } |
| 3889 | if (is_r6) { |
| 3890 | __ Selnez(out_high, AT, out_low); |
| 3891 | } else { |
| 3892 | __ Movz(AT, ZERO, out_low); |
| 3893 | __ Move(out_high, AT); |
| 3894 | } |
| 3895 | if (is_r2_or_newer) { |
| 3896 | __ Ins(out_low, out_high, ctz_imm, 32 - ctz_imm); |
| 3897 | } else { |
| 3898 | __ Sll(AT, out_high, ctz_imm); |
| 3899 | __ Or(out_low, out_low, AT); |
| 3900 | } |
| 3901 | } else if (ctz_imm == 32) { |
| 3902 | __ Sra(AT, in_high, 31); |
| 3903 | __ Move(out_low, in_low); |
| 3904 | if (is_r6) { |
| 3905 | __ Selnez(out_high, AT, out_low); |
| 3906 | } else { |
| 3907 | __ Movz(AT, ZERO, out_low); |
| 3908 | __ Move(out_high, AT); |
| 3909 | } |
| 3910 | } else if (ctz_imm < 63) { |
| 3911 | __ Sra(AT, in_high, 31); |
| 3912 | __ Move(TMP, in_low); |
| 3913 | if (ctz_imm - 32 <= 16) { |
| 3914 | __ Andi(out_high, in_high, (1 << (ctz_imm - 32)) - 1); |
| 3915 | } else if (is_r2_or_newer) { |
| 3916 | __ Ext(out_high, in_high, 0, ctz_imm - 32); |
| 3917 | } else { |
| 3918 | __ Sll(out_high, in_high, 64 - ctz_imm); |
| 3919 | __ Srl(out_high, out_high, 64 - ctz_imm); |
| 3920 | } |
| 3921 | __ Move(out_low, TMP); |
| 3922 | __ Or(TMP, TMP, out_high); |
| 3923 | if (is_r6) { |
| 3924 | __ Selnez(AT, AT, TMP); |
| 3925 | } else { |
| 3926 | __ Movz(AT, ZERO, TMP); |
| 3927 | } |
| 3928 | if (is_r2_or_newer) { |
| 3929 | __ Ins(out_high, AT, ctz_imm - 32, 64 - ctz_imm); |
| 3930 | } else { |
| 3931 | __ Sll(AT, AT, ctz_imm - 32); |
| 3932 | __ Or(out_high, out_high, AT); |
| 3933 | } |
| 3934 | } else { |
| 3935 | if (is_r6) { |
| 3936 | __ Aui(AT, in_high, 0x8000); |
| 3937 | } else { |
| 3938 | __ Lui(AT, 0x8000); |
| 3939 | __ Xor(AT, AT, in_high); |
| 3940 | } |
| 3941 | __ Or(AT, AT, in_low); |
| 3942 | __ Sltiu(AT, AT, 1); |
| 3943 | __ Sll(AT, AT, 31); |
| 3944 | __ Move(out_low, in_low); |
| 3945 | __ Xor(out_high, in_high, AT); |
| 3946 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3947 | } |
| 3948 | } |
| 3949 | } |
| 3950 | |
| 3951 | void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3952 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3953 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3954 | |
| 3955 | LocationSummary* locations = instruction->GetLocations(); |
| 3956 | Location second = locations->InAt(1); |
| 3957 | DCHECK(second.IsConstant()); |
| 3958 | |
| 3959 | Register out = locations->Out().AsRegister<Register>(); |
| 3960 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3961 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3962 | |
| 3963 | int64_t magic; |
| 3964 | int shift; |
| 3965 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3966 | |
| 3967 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3968 | |
| 3969 | __ LoadConst32(TMP, magic); |
| 3970 | if (isR6) { |
| 3971 | __ MuhR6(TMP, dividend, TMP); |
| 3972 | } else { |
| 3973 | __ MultR2(dividend, TMP); |
| 3974 | __ Mfhi(TMP); |
| 3975 | } |
| 3976 | if (imm > 0 && magic < 0) { |
| 3977 | __ Addu(TMP, TMP, dividend); |
| 3978 | } else if (imm < 0 && magic > 0) { |
| 3979 | __ Subu(TMP, TMP, dividend); |
| 3980 | } |
| 3981 | |
| 3982 | if (shift != 0) { |
| 3983 | __ Sra(TMP, TMP, shift); |
| 3984 | } |
| 3985 | |
| 3986 | if (instruction->IsDiv()) { |
| 3987 | __ Sra(out, TMP, 31); |
| 3988 | __ Subu(out, TMP, out); |
| 3989 | } else { |
| 3990 | __ Sra(AT, TMP, 31); |
| 3991 | __ Subu(AT, TMP, AT); |
| 3992 | __ LoadConst32(TMP, imm); |
| 3993 | if (isR6) { |
| 3994 | __ MulR6(TMP, AT, TMP); |
| 3995 | } else { |
| 3996 | __ MulR2(TMP, AT, TMP); |
| 3997 | } |
| 3998 | __ Subu(out, dividend, TMP); |
| 3999 | } |
| 4000 | } |
| 4001 | |
| 4002 | void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 4003 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4004 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4005 | |
| 4006 | LocationSummary* locations = instruction->GetLocations(); |
| 4007 | Register out = locations->Out().AsRegister<Register>(); |
| 4008 | Location second = locations->InAt(1); |
| 4009 | |
| 4010 | if (second.IsConstant()) { |
| 4011 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4012 | if (imm == 0) { |
| 4013 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4014 | } else if (imm == 1 || imm == -1) { |
| 4015 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4016 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4017 | DivRemByPowerOfTwo(instruction); |
| 4018 | } else { |
| 4019 | DCHECK(imm <= -2 || imm >= 2); |
| 4020 | GenerateDivRemWithAnyConstant(instruction); |
| 4021 | } |
| 4022 | } else { |
| 4023 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4024 | Register divisor = second.AsRegister<Register>(); |
| 4025 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4026 | if (instruction->IsDiv()) { |
| 4027 | if (isR6) { |
| 4028 | __ DivR6(out, dividend, divisor); |
| 4029 | } else { |
| 4030 | __ DivR2(out, dividend, divisor); |
| 4031 | } |
| 4032 | } else { |
| 4033 | if (isR6) { |
| 4034 | __ ModR6(out, dividend, divisor); |
| 4035 | } else { |
| 4036 | __ ModR2(out, dividend, divisor); |
| 4037 | } |
| 4038 | } |
| 4039 | } |
| 4040 | } |
| 4041 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4042 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4043 | DataType::Type type = div->GetResultType(); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 4044 | bool call_long_div = false; |
| 4045 | if (type == DataType::Type::kInt64) { |
| 4046 | if (div->InputAt(1)->IsConstant()) { |
| 4047 | int64_t imm = CodeGenerator::GetInt64ValueOf(div->InputAt(1)->AsConstant()); |
| 4048 | call_long_div = (imm != 0) && !IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm))); |
| 4049 | } else { |
| 4050 | call_long_div = true; |
| 4051 | } |
| 4052 | } |
| 4053 | LocationSummary::CallKind call_kind = call_long_div |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4054 | ? LocationSummary::kCallOnMainOnly |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4055 | : LocationSummary::kNoCall; |
| 4056 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4057 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4058 | |
| 4059 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4060 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4061 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4062 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4063 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4064 | break; |
| 4065 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4066 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 4067 | if (call_long_div) { |
| 4068 | InvokeRuntimeCallingConvention calling_convention; |
| 4069 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4070 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4071 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4072 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4073 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4074 | } else { |
| 4075 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4076 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 4077 | locations->SetOut(Location::RequiresRegister()); |
| 4078 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4079 | break; |
| 4080 | } |
| 4081 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4082 | case DataType::Type::kFloat32: |
| 4083 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4084 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4085 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4086 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4087 | break; |
| 4088 | |
| 4089 | default: |
| 4090 | LOG(FATAL) << "Unexpected div type " << type; |
| 4091 | } |
| 4092 | } |
| 4093 | |
| 4094 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4095 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4096 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4097 | |
| 4098 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4099 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4100 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4101 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4102 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 4103 | if (locations->InAt(1).IsConstant()) { |
| 4104 | int64_t imm = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue(); |
| 4105 | if (imm == 0) { |
| 4106 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4107 | } else if (imm == 1 || imm == -1) { |
| 4108 | DivRemOneOrMinusOne(instruction); |
| 4109 | } else { |
| 4110 | DCHECK(IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm)))); |
| 4111 | DivRemByPowerOfTwo(instruction); |
| 4112 | } |
| 4113 | } else { |
| 4114 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
| 4115 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| 4116 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4117 | break; |
| 4118 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4119 | case DataType::Type::kFloat32: |
| 4120 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4121 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 4122 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4123 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4124 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4125 | __ DivS(dst, lhs, rhs); |
| 4126 | } else { |
| 4127 | __ DivD(dst, lhs, rhs); |
| 4128 | } |
| 4129 | break; |
| 4130 | } |
| 4131 | default: |
| 4132 | LOG(FATAL) << "Unexpected div type " << type; |
| 4133 | } |
| 4134 | } |
| 4135 | |
| 4136 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4137 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4138 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4139 | } |
| 4140 | |
| 4141 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4142 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4143 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4144 | codegen_->AddSlowPath(slow_path); |
| 4145 | Location value = instruction->GetLocations()->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4146 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4147 | |
| 4148 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4149 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4150 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4151 | case DataType::Type::kInt8: |
| 4152 | case DataType::Type::kUint16: |
| 4153 | case DataType::Type::kInt16: |
| 4154 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4155 | if (value.IsConstant()) { |
| 4156 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 4157 | __ B(slow_path->GetEntryLabel()); |
| 4158 | } else { |
| 4159 | // A division by a non-null constant is valid. We don't need to perform |
| 4160 | // any check, so simply fall through. |
| 4161 | } |
| 4162 | } else { |
| 4163 | DCHECK(value.IsRegister()) << value; |
| 4164 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 4165 | } |
| 4166 | break; |
| 4167 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4168 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4169 | if (value.IsConstant()) { |
| 4170 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4171 | __ B(slow_path->GetEntryLabel()); |
| 4172 | } else { |
| 4173 | // A division by a non-null constant is valid. We don't need to perform |
| 4174 | // any check, so simply fall through. |
| 4175 | } |
| 4176 | } else { |
| 4177 | DCHECK(value.IsRegisterPair()) << value; |
| 4178 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); |
| 4179 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 4180 | } |
| 4181 | break; |
| 4182 | } |
| 4183 | default: |
| 4184 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| 4185 | } |
| 4186 | } |
| 4187 | |
| 4188 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { |
| 4189 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4190 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4191 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4192 | } |
| 4193 | |
| 4194 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 4195 | // Will be generated at use site. |
| 4196 | } |
| 4197 | |
| 4198 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { |
| 4199 | exit->SetLocations(nullptr); |
| 4200 | } |
| 4201 | |
| 4202 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 4203 | } |
| 4204 | |
| 4205 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { |
| 4206 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4207 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4208 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4209 | } |
| 4210 | |
| 4211 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 4212 | // Will be generated at use site. |
| 4213 | } |
| 4214 | |
| 4215 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { |
| 4216 | got->SetLocations(nullptr); |
| 4217 | } |
| 4218 | |
| 4219 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4220 | if (successor->IsExitBlock()) { |
| 4221 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 4222 | return; // no code needed |
| 4223 | } |
| 4224 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4225 | HBasicBlock* block = got->GetBlock(); |
| 4226 | HInstruction* previous = got->GetPrevious(); |
| 4227 | HLoopInformation* info = block->GetLoopInformation(); |
| 4228 | |
| 4229 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Goran Jakovljevic | feec167 | 2018-02-08 10:20:14 +0100 | [diff] [blame] | 4230 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 4231 | __ Lw(AT, SP, kCurrentMethodStackOffset); |
| 4232 | __ Lhu(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value()); |
| 4233 | __ Addiu(TMP, TMP, 1); |
| 4234 | __ Sh(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value()); |
| 4235 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4236 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 4237 | return; |
| 4238 | } |
| 4239 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 4240 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 4241 | } |
| 4242 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 4243 | __ B(codegen_->GetLabelOf(successor)); |
| 4244 | } |
| 4245 | } |
| 4246 | |
| 4247 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { |
| 4248 | HandleGoto(got, got->GetSuccessor()); |
| 4249 | } |
| 4250 | |
| 4251 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 4252 | try_boundary->SetLocations(nullptr); |
| 4253 | } |
| 4254 | |
| 4255 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 4256 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 4257 | if (!successor->IsExitBlock()) { |
| 4258 | HandleGoto(try_boundary, successor); |
| 4259 | } |
| 4260 | } |
| 4261 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4262 | void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond, |
| 4263 | LocationSummary* locations) { |
| 4264 | Register dst = locations->Out().AsRegister<Register>(); |
| 4265 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4266 | Location rhs_location = locations->InAt(1); |
| 4267 | Register rhs_reg = ZERO; |
| 4268 | int64_t rhs_imm = 0; |
| 4269 | bool use_imm = rhs_location.IsConstant(); |
| 4270 | if (use_imm) { |
| 4271 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4272 | } else { |
| 4273 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4274 | } |
| 4275 | |
| 4276 | switch (cond) { |
| 4277 | case kCondEQ: |
| 4278 | case kCondNE: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4279 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4280 | if (rhs_imm == 0) { |
| 4281 | if (cond == kCondEQ) { |
| 4282 | __ Sltiu(dst, lhs, 1); |
| 4283 | } else { |
| 4284 | __ Sltu(dst, ZERO, lhs); |
| 4285 | } |
| 4286 | } else { |
| 4287 | __ Addiu(dst, lhs, -rhs_imm); |
| 4288 | if (cond == kCondEQ) { |
| 4289 | __ Sltiu(dst, dst, 1); |
| 4290 | } else { |
| 4291 | __ Sltu(dst, ZERO, dst); |
| 4292 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4293 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4294 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4295 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 4296 | __ Xori(dst, lhs, rhs_imm); |
| 4297 | } else { |
| 4298 | if (use_imm) { |
| 4299 | rhs_reg = TMP; |
| 4300 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4301 | } |
| 4302 | __ Xor(dst, lhs, rhs_reg); |
| 4303 | } |
| 4304 | if (cond == kCondEQ) { |
| 4305 | __ Sltiu(dst, dst, 1); |
| 4306 | } else { |
| 4307 | __ Sltu(dst, ZERO, dst); |
| 4308 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4309 | } |
| 4310 | break; |
| 4311 | |
| 4312 | case kCondLT: |
| 4313 | case kCondGE: |
| 4314 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4315 | __ Slti(dst, lhs, rhs_imm); |
| 4316 | } else { |
| 4317 | if (use_imm) { |
| 4318 | rhs_reg = TMP; |
| 4319 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4320 | } |
| 4321 | __ Slt(dst, lhs, rhs_reg); |
| 4322 | } |
| 4323 | if (cond == kCondGE) { |
| 4324 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4325 | // only the slt instruction but no sge. |
| 4326 | __ Xori(dst, dst, 1); |
| 4327 | } |
| 4328 | break; |
| 4329 | |
| 4330 | case kCondLE: |
| 4331 | case kCondGT: |
| 4332 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4333 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4334 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4335 | if (cond == kCondGT) { |
| 4336 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4337 | // only the slti instruction but no sgti. |
| 4338 | __ Xori(dst, dst, 1); |
| 4339 | } |
| 4340 | } else { |
| 4341 | if (use_imm) { |
| 4342 | rhs_reg = TMP; |
| 4343 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4344 | } |
| 4345 | __ Slt(dst, rhs_reg, lhs); |
| 4346 | if (cond == kCondLE) { |
| 4347 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4348 | // only the slt instruction but no sle. |
| 4349 | __ Xori(dst, dst, 1); |
| 4350 | } |
| 4351 | } |
| 4352 | break; |
| 4353 | |
| 4354 | case kCondB: |
| 4355 | case kCondAE: |
| 4356 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4357 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4358 | // the comparison and thus lets us compare directly with |
| 4359 | // unsigned values in the ranges [0, 0x7fff] and |
| 4360 | // [0xffff8000, 0xffffffff]. |
| 4361 | __ Sltiu(dst, lhs, rhs_imm); |
| 4362 | } else { |
| 4363 | if (use_imm) { |
| 4364 | rhs_reg = TMP; |
| 4365 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4366 | } |
| 4367 | __ Sltu(dst, lhs, rhs_reg); |
| 4368 | } |
| 4369 | if (cond == kCondAE) { |
| 4370 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4371 | // only the sltu instruction but no sgeu. |
| 4372 | __ Xori(dst, dst, 1); |
| 4373 | } |
| 4374 | break; |
| 4375 | |
| 4376 | case kCondBE: |
| 4377 | case kCondA: |
| 4378 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4379 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4380 | // Note that this only works if rhs + 1 does not overflow |
| 4381 | // to 0, hence the check above. |
| 4382 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4383 | // the comparison and thus lets us compare directly with |
| 4384 | // unsigned values in the ranges [0, 0x7fff] and |
| 4385 | // [0xffff8000, 0xffffffff]. |
| 4386 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4387 | if (cond == kCondA) { |
| 4388 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4389 | // only the sltiu instruction but no sgtiu. |
| 4390 | __ Xori(dst, dst, 1); |
| 4391 | } |
| 4392 | } else { |
| 4393 | if (use_imm) { |
| 4394 | rhs_reg = TMP; |
| 4395 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4396 | } |
| 4397 | __ Sltu(dst, rhs_reg, lhs); |
| 4398 | if (cond == kCondBE) { |
| 4399 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4400 | // only the sltu instruction but no sleu. |
| 4401 | __ Xori(dst, dst, 1); |
| 4402 | } |
| 4403 | } |
| 4404 | break; |
| 4405 | } |
| 4406 | } |
| 4407 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4408 | bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond, |
| 4409 | LocationSummary* input_locations, |
| 4410 | Register dst) { |
| 4411 | Register lhs = input_locations->InAt(0).AsRegister<Register>(); |
| 4412 | Location rhs_location = input_locations->InAt(1); |
| 4413 | Register rhs_reg = ZERO; |
| 4414 | int64_t rhs_imm = 0; |
| 4415 | bool use_imm = rhs_location.IsConstant(); |
| 4416 | if (use_imm) { |
| 4417 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4418 | } else { |
| 4419 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4420 | } |
| 4421 | |
| 4422 | switch (cond) { |
| 4423 | case kCondEQ: |
| 4424 | case kCondNE: |
| 4425 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4426 | __ Addiu(dst, lhs, -rhs_imm); |
| 4427 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 4428 | __ Xori(dst, lhs, rhs_imm); |
| 4429 | } else { |
| 4430 | if (use_imm) { |
| 4431 | rhs_reg = TMP; |
| 4432 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4433 | } |
| 4434 | __ Xor(dst, lhs, rhs_reg); |
| 4435 | } |
| 4436 | return (cond == kCondEQ); |
| 4437 | |
| 4438 | case kCondLT: |
| 4439 | case kCondGE: |
| 4440 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4441 | __ Slti(dst, lhs, rhs_imm); |
| 4442 | } else { |
| 4443 | if (use_imm) { |
| 4444 | rhs_reg = TMP; |
| 4445 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4446 | } |
| 4447 | __ Slt(dst, lhs, rhs_reg); |
| 4448 | } |
| 4449 | return (cond == kCondGE); |
| 4450 | |
| 4451 | case kCondLE: |
| 4452 | case kCondGT: |
| 4453 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4454 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4455 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4456 | return (cond == kCondGT); |
| 4457 | } else { |
| 4458 | if (use_imm) { |
| 4459 | rhs_reg = TMP; |
| 4460 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4461 | } |
| 4462 | __ Slt(dst, rhs_reg, lhs); |
| 4463 | return (cond == kCondLE); |
| 4464 | } |
| 4465 | |
| 4466 | case kCondB: |
| 4467 | case kCondAE: |
| 4468 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4469 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4470 | // the comparison and thus lets us compare directly with |
| 4471 | // unsigned values in the ranges [0, 0x7fff] and |
| 4472 | // [0xffff8000, 0xffffffff]. |
| 4473 | __ Sltiu(dst, lhs, rhs_imm); |
| 4474 | } else { |
| 4475 | if (use_imm) { |
| 4476 | rhs_reg = TMP; |
| 4477 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4478 | } |
| 4479 | __ Sltu(dst, lhs, rhs_reg); |
| 4480 | } |
| 4481 | return (cond == kCondAE); |
| 4482 | |
| 4483 | case kCondBE: |
| 4484 | case kCondA: |
| 4485 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4486 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4487 | // Note that this only works if rhs + 1 does not overflow |
| 4488 | // to 0, hence the check above. |
| 4489 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4490 | // the comparison and thus lets us compare directly with |
| 4491 | // unsigned values in the ranges [0, 0x7fff] and |
| 4492 | // [0xffff8000, 0xffffffff]. |
| 4493 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4494 | return (cond == kCondA); |
| 4495 | } else { |
| 4496 | if (use_imm) { |
| 4497 | rhs_reg = TMP; |
| 4498 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4499 | } |
| 4500 | __ Sltu(dst, rhs_reg, lhs); |
| 4501 | return (cond == kCondBE); |
| 4502 | } |
| 4503 | } |
| 4504 | } |
| 4505 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4506 | void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond, |
| 4507 | LocationSummary* locations, |
| 4508 | MipsLabel* label) { |
| 4509 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4510 | Location rhs_location = locations->InAt(1); |
| 4511 | Register rhs_reg = ZERO; |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4512 | int64_t rhs_imm = 0; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4513 | bool use_imm = rhs_location.IsConstant(); |
| 4514 | if (use_imm) { |
| 4515 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4516 | } else { |
| 4517 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4518 | } |
| 4519 | |
| 4520 | if (use_imm && rhs_imm == 0) { |
| 4521 | switch (cond) { |
| 4522 | case kCondEQ: |
| 4523 | case kCondBE: // <= 0 if zero |
| 4524 | __ Beqz(lhs, label); |
| 4525 | break; |
| 4526 | case kCondNE: |
| 4527 | case kCondA: // > 0 if non-zero |
| 4528 | __ Bnez(lhs, label); |
| 4529 | break; |
| 4530 | case kCondLT: |
| 4531 | __ Bltz(lhs, label); |
| 4532 | break; |
| 4533 | case kCondGE: |
| 4534 | __ Bgez(lhs, label); |
| 4535 | break; |
| 4536 | case kCondLE: |
| 4537 | __ Blez(lhs, label); |
| 4538 | break; |
| 4539 | case kCondGT: |
| 4540 | __ Bgtz(lhs, label); |
| 4541 | break; |
| 4542 | case kCondB: // always false |
| 4543 | break; |
| 4544 | case kCondAE: // always true |
| 4545 | __ B(label); |
| 4546 | break; |
| 4547 | } |
| 4548 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4549 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4550 | if (isR6 || !use_imm) { |
| 4551 | if (use_imm) { |
| 4552 | rhs_reg = TMP; |
| 4553 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4554 | } |
| 4555 | switch (cond) { |
| 4556 | case kCondEQ: |
| 4557 | __ Beq(lhs, rhs_reg, label); |
| 4558 | break; |
| 4559 | case kCondNE: |
| 4560 | __ Bne(lhs, rhs_reg, label); |
| 4561 | break; |
| 4562 | case kCondLT: |
| 4563 | __ Blt(lhs, rhs_reg, label); |
| 4564 | break; |
| 4565 | case kCondGE: |
| 4566 | __ Bge(lhs, rhs_reg, label); |
| 4567 | break; |
| 4568 | case kCondLE: |
| 4569 | __ Bge(rhs_reg, lhs, label); |
| 4570 | break; |
| 4571 | case kCondGT: |
| 4572 | __ Blt(rhs_reg, lhs, label); |
| 4573 | break; |
| 4574 | case kCondB: |
| 4575 | __ Bltu(lhs, rhs_reg, label); |
| 4576 | break; |
| 4577 | case kCondAE: |
| 4578 | __ Bgeu(lhs, rhs_reg, label); |
| 4579 | break; |
| 4580 | case kCondBE: |
| 4581 | __ Bgeu(rhs_reg, lhs, label); |
| 4582 | break; |
| 4583 | case kCondA: |
| 4584 | __ Bltu(rhs_reg, lhs, label); |
| 4585 | break; |
| 4586 | } |
| 4587 | } else { |
| 4588 | // Special cases for more efficient comparison with constants on R2. |
| 4589 | switch (cond) { |
| 4590 | case kCondEQ: |
| 4591 | __ LoadConst32(TMP, rhs_imm); |
| 4592 | __ Beq(lhs, TMP, label); |
| 4593 | break; |
| 4594 | case kCondNE: |
| 4595 | __ LoadConst32(TMP, rhs_imm); |
| 4596 | __ Bne(lhs, TMP, label); |
| 4597 | break; |
| 4598 | case kCondLT: |
| 4599 | if (IsInt<16>(rhs_imm)) { |
| 4600 | __ Slti(TMP, lhs, rhs_imm); |
| 4601 | __ Bnez(TMP, label); |
| 4602 | } else { |
| 4603 | __ LoadConst32(TMP, rhs_imm); |
| 4604 | __ Blt(lhs, TMP, label); |
| 4605 | } |
| 4606 | break; |
| 4607 | case kCondGE: |
| 4608 | if (IsInt<16>(rhs_imm)) { |
| 4609 | __ Slti(TMP, lhs, rhs_imm); |
| 4610 | __ Beqz(TMP, label); |
| 4611 | } else { |
| 4612 | __ LoadConst32(TMP, rhs_imm); |
| 4613 | __ Bge(lhs, TMP, label); |
| 4614 | } |
| 4615 | break; |
| 4616 | case kCondLE: |
| 4617 | if (IsInt<16>(rhs_imm + 1)) { |
| 4618 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4619 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4620 | __ Bnez(TMP, label); |
| 4621 | } else { |
| 4622 | __ LoadConst32(TMP, rhs_imm); |
| 4623 | __ Bge(TMP, lhs, label); |
| 4624 | } |
| 4625 | break; |
| 4626 | case kCondGT: |
| 4627 | if (IsInt<16>(rhs_imm + 1)) { |
| 4628 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4629 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4630 | __ Beqz(TMP, label); |
| 4631 | } else { |
| 4632 | __ LoadConst32(TMP, rhs_imm); |
| 4633 | __ Blt(TMP, lhs, label); |
| 4634 | } |
| 4635 | break; |
| 4636 | case kCondB: |
| 4637 | if (IsInt<16>(rhs_imm)) { |
| 4638 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4639 | __ Bnez(TMP, label); |
| 4640 | } else { |
| 4641 | __ LoadConst32(TMP, rhs_imm); |
| 4642 | __ Bltu(lhs, TMP, label); |
| 4643 | } |
| 4644 | break; |
| 4645 | case kCondAE: |
| 4646 | if (IsInt<16>(rhs_imm)) { |
| 4647 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4648 | __ Beqz(TMP, label); |
| 4649 | } else { |
| 4650 | __ LoadConst32(TMP, rhs_imm); |
| 4651 | __ Bgeu(lhs, TMP, label); |
| 4652 | } |
| 4653 | break; |
| 4654 | case kCondBE: |
| 4655 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4656 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4657 | // Note that this only works if rhs + 1 does not overflow |
| 4658 | // to 0, hence the check above. |
| 4659 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4660 | __ Bnez(TMP, label); |
| 4661 | } else { |
| 4662 | __ LoadConst32(TMP, rhs_imm); |
| 4663 | __ Bgeu(TMP, lhs, label); |
| 4664 | } |
| 4665 | break; |
| 4666 | case kCondA: |
| 4667 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4668 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4669 | // Note that this only works if rhs + 1 does not overflow |
| 4670 | // to 0, hence the check above. |
| 4671 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4672 | __ Beqz(TMP, label); |
| 4673 | } else { |
| 4674 | __ LoadConst32(TMP, rhs_imm); |
| 4675 | __ Bltu(TMP, lhs, label); |
| 4676 | } |
| 4677 | break; |
| 4678 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4679 | } |
| 4680 | } |
| 4681 | } |
| 4682 | |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 4683 | void InstructionCodeGeneratorMIPS::GenerateLongCompare(IfCondition cond, |
| 4684 | LocationSummary* locations) { |
| 4685 | Register dst = locations->Out().AsRegister<Register>(); |
| 4686 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4687 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4688 | Location rhs_location = locations->InAt(1); |
| 4689 | Register rhs_high = ZERO; |
| 4690 | Register rhs_low = ZERO; |
| 4691 | int64_t imm = 0; |
| 4692 | uint32_t imm_high = 0; |
| 4693 | uint32_t imm_low = 0; |
| 4694 | bool use_imm = rhs_location.IsConstant(); |
| 4695 | if (use_imm) { |
| 4696 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 4697 | imm_high = High32Bits(imm); |
| 4698 | imm_low = Low32Bits(imm); |
| 4699 | } else { |
| 4700 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 4701 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 4702 | } |
| 4703 | if (use_imm && imm == 0) { |
| 4704 | switch (cond) { |
| 4705 | case kCondEQ: |
| 4706 | case kCondBE: // <= 0 if zero |
| 4707 | __ Or(dst, lhs_high, lhs_low); |
| 4708 | __ Sltiu(dst, dst, 1); |
| 4709 | break; |
| 4710 | case kCondNE: |
| 4711 | case kCondA: // > 0 if non-zero |
| 4712 | __ Or(dst, lhs_high, lhs_low); |
| 4713 | __ Sltu(dst, ZERO, dst); |
| 4714 | break; |
| 4715 | case kCondLT: |
| 4716 | __ Slt(dst, lhs_high, ZERO); |
| 4717 | break; |
| 4718 | case kCondGE: |
| 4719 | __ Slt(dst, lhs_high, ZERO); |
| 4720 | __ Xori(dst, dst, 1); |
| 4721 | break; |
| 4722 | case kCondLE: |
| 4723 | __ Or(TMP, lhs_high, lhs_low); |
| 4724 | __ Sra(AT, lhs_high, 31); |
| 4725 | __ Sltu(dst, AT, TMP); |
| 4726 | __ Xori(dst, dst, 1); |
| 4727 | break; |
| 4728 | case kCondGT: |
| 4729 | __ Or(TMP, lhs_high, lhs_low); |
| 4730 | __ Sra(AT, lhs_high, 31); |
| 4731 | __ Sltu(dst, AT, TMP); |
| 4732 | break; |
| 4733 | case kCondB: // always false |
| 4734 | __ Andi(dst, dst, 0); |
| 4735 | break; |
| 4736 | case kCondAE: // always true |
| 4737 | __ Ori(dst, ZERO, 1); |
| 4738 | break; |
| 4739 | } |
| 4740 | } else if (use_imm) { |
| 4741 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 4742 | switch (cond) { |
| 4743 | case kCondEQ: |
| 4744 | __ LoadConst32(TMP, imm_high); |
| 4745 | __ Xor(TMP, TMP, lhs_high); |
| 4746 | __ LoadConst32(AT, imm_low); |
| 4747 | __ Xor(AT, AT, lhs_low); |
| 4748 | __ Or(dst, TMP, AT); |
| 4749 | __ Sltiu(dst, dst, 1); |
| 4750 | break; |
| 4751 | case kCondNE: |
| 4752 | __ LoadConst32(TMP, imm_high); |
| 4753 | __ Xor(TMP, TMP, lhs_high); |
| 4754 | __ LoadConst32(AT, imm_low); |
| 4755 | __ Xor(AT, AT, lhs_low); |
| 4756 | __ Or(dst, TMP, AT); |
| 4757 | __ Sltu(dst, ZERO, dst); |
| 4758 | break; |
| 4759 | case kCondLT: |
| 4760 | case kCondGE: |
| 4761 | if (dst == lhs_low) { |
| 4762 | __ LoadConst32(TMP, imm_low); |
| 4763 | __ Sltu(dst, lhs_low, TMP); |
| 4764 | } |
| 4765 | __ LoadConst32(TMP, imm_high); |
| 4766 | __ Slt(AT, lhs_high, TMP); |
| 4767 | __ Slt(TMP, TMP, lhs_high); |
| 4768 | if (dst != lhs_low) { |
| 4769 | __ LoadConst32(dst, imm_low); |
| 4770 | __ Sltu(dst, lhs_low, dst); |
| 4771 | } |
| 4772 | __ Slt(dst, TMP, dst); |
| 4773 | __ Or(dst, dst, AT); |
| 4774 | if (cond == kCondGE) { |
| 4775 | __ Xori(dst, dst, 1); |
| 4776 | } |
| 4777 | break; |
| 4778 | case kCondGT: |
| 4779 | case kCondLE: |
| 4780 | if (dst == lhs_low) { |
| 4781 | __ LoadConst32(TMP, imm_low); |
| 4782 | __ Sltu(dst, TMP, lhs_low); |
| 4783 | } |
| 4784 | __ LoadConst32(TMP, imm_high); |
| 4785 | __ Slt(AT, TMP, lhs_high); |
| 4786 | __ Slt(TMP, lhs_high, TMP); |
| 4787 | if (dst != lhs_low) { |
| 4788 | __ LoadConst32(dst, imm_low); |
| 4789 | __ Sltu(dst, dst, lhs_low); |
| 4790 | } |
| 4791 | __ Slt(dst, TMP, dst); |
| 4792 | __ Or(dst, dst, AT); |
| 4793 | if (cond == kCondLE) { |
| 4794 | __ Xori(dst, dst, 1); |
| 4795 | } |
| 4796 | break; |
| 4797 | case kCondB: |
| 4798 | case kCondAE: |
| 4799 | if (dst == lhs_low) { |
| 4800 | __ LoadConst32(TMP, imm_low); |
| 4801 | __ Sltu(dst, lhs_low, TMP); |
| 4802 | } |
| 4803 | __ LoadConst32(TMP, imm_high); |
| 4804 | __ Sltu(AT, lhs_high, TMP); |
| 4805 | __ Sltu(TMP, TMP, lhs_high); |
| 4806 | if (dst != lhs_low) { |
| 4807 | __ LoadConst32(dst, imm_low); |
| 4808 | __ Sltu(dst, lhs_low, dst); |
| 4809 | } |
| 4810 | __ Slt(dst, TMP, dst); |
| 4811 | __ Or(dst, dst, AT); |
| 4812 | if (cond == kCondAE) { |
| 4813 | __ Xori(dst, dst, 1); |
| 4814 | } |
| 4815 | break; |
| 4816 | case kCondA: |
| 4817 | case kCondBE: |
| 4818 | if (dst == lhs_low) { |
| 4819 | __ LoadConst32(TMP, imm_low); |
| 4820 | __ Sltu(dst, TMP, lhs_low); |
| 4821 | } |
| 4822 | __ LoadConst32(TMP, imm_high); |
| 4823 | __ Sltu(AT, TMP, lhs_high); |
| 4824 | __ Sltu(TMP, lhs_high, TMP); |
| 4825 | if (dst != lhs_low) { |
| 4826 | __ LoadConst32(dst, imm_low); |
| 4827 | __ Sltu(dst, dst, lhs_low); |
| 4828 | } |
| 4829 | __ Slt(dst, TMP, dst); |
| 4830 | __ Or(dst, dst, AT); |
| 4831 | if (cond == kCondBE) { |
| 4832 | __ Xori(dst, dst, 1); |
| 4833 | } |
| 4834 | break; |
| 4835 | } |
| 4836 | } else { |
| 4837 | switch (cond) { |
| 4838 | case kCondEQ: |
| 4839 | __ Xor(TMP, lhs_high, rhs_high); |
| 4840 | __ Xor(AT, lhs_low, rhs_low); |
| 4841 | __ Or(dst, TMP, AT); |
| 4842 | __ Sltiu(dst, dst, 1); |
| 4843 | break; |
| 4844 | case kCondNE: |
| 4845 | __ Xor(TMP, lhs_high, rhs_high); |
| 4846 | __ Xor(AT, lhs_low, rhs_low); |
| 4847 | __ Or(dst, TMP, AT); |
| 4848 | __ Sltu(dst, ZERO, dst); |
| 4849 | break; |
| 4850 | case kCondLT: |
| 4851 | case kCondGE: |
| 4852 | __ Slt(TMP, rhs_high, lhs_high); |
| 4853 | __ Sltu(AT, lhs_low, rhs_low); |
| 4854 | __ Slt(TMP, TMP, AT); |
| 4855 | __ Slt(AT, lhs_high, rhs_high); |
| 4856 | __ Or(dst, AT, TMP); |
| 4857 | if (cond == kCondGE) { |
| 4858 | __ Xori(dst, dst, 1); |
| 4859 | } |
| 4860 | break; |
| 4861 | case kCondGT: |
| 4862 | case kCondLE: |
| 4863 | __ Slt(TMP, lhs_high, rhs_high); |
| 4864 | __ Sltu(AT, rhs_low, lhs_low); |
| 4865 | __ Slt(TMP, TMP, AT); |
| 4866 | __ Slt(AT, rhs_high, lhs_high); |
| 4867 | __ Or(dst, AT, TMP); |
| 4868 | if (cond == kCondLE) { |
| 4869 | __ Xori(dst, dst, 1); |
| 4870 | } |
| 4871 | break; |
| 4872 | case kCondB: |
| 4873 | case kCondAE: |
| 4874 | __ Sltu(TMP, rhs_high, lhs_high); |
| 4875 | __ Sltu(AT, lhs_low, rhs_low); |
| 4876 | __ Slt(TMP, TMP, AT); |
| 4877 | __ Sltu(AT, lhs_high, rhs_high); |
| 4878 | __ Or(dst, AT, TMP); |
| 4879 | if (cond == kCondAE) { |
| 4880 | __ Xori(dst, dst, 1); |
| 4881 | } |
| 4882 | break; |
| 4883 | case kCondA: |
| 4884 | case kCondBE: |
| 4885 | __ Sltu(TMP, lhs_high, rhs_high); |
| 4886 | __ Sltu(AT, rhs_low, lhs_low); |
| 4887 | __ Slt(TMP, TMP, AT); |
| 4888 | __ Sltu(AT, rhs_high, lhs_high); |
| 4889 | __ Or(dst, AT, TMP); |
| 4890 | if (cond == kCondBE) { |
| 4891 | __ Xori(dst, dst, 1); |
| 4892 | } |
| 4893 | break; |
| 4894 | } |
| 4895 | } |
| 4896 | } |
| 4897 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4898 | void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond, |
| 4899 | LocationSummary* locations, |
| 4900 | MipsLabel* label) { |
| 4901 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4902 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4903 | Location rhs_location = locations->InAt(1); |
| 4904 | Register rhs_high = ZERO; |
| 4905 | Register rhs_low = ZERO; |
| 4906 | int64_t imm = 0; |
| 4907 | uint32_t imm_high = 0; |
| 4908 | uint32_t imm_low = 0; |
| 4909 | bool use_imm = rhs_location.IsConstant(); |
| 4910 | if (use_imm) { |
| 4911 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 4912 | imm_high = High32Bits(imm); |
| 4913 | imm_low = Low32Bits(imm); |
| 4914 | } else { |
| 4915 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 4916 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 4917 | } |
| 4918 | |
| 4919 | if (use_imm && imm == 0) { |
| 4920 | switch (cond) { |
| 4921 | case kCondEQ: |
| 4922 | case kCondBE: // <= 0 if zero |
| 4923 | __ Or(TMP, lhs_high, lhs_low); |
| 4924 | __ Beqz(TMP, label); |
| 4925 | break; |
| 4926 | case kCondNE: |
| 4927 | case kCondA: // > 0 if non-zero |
| 4928 | __ Or(TMP, lhs_high, lhs_low); |
| 4929 | __ Bnez(TMP, label); |
| 4930 | break; |
| 4931 | case kCondLT: |
| 4932 | __ Bltz(lhs_high, label); |
| 4933 | break; |
| 4934 | case kCondGE: |
| 4935 | __ Bgez(lhs_high, label); |
| 4936 | break; |
| 4937 | case kCondLE: |
| 4938 | __ Or(TMP, lhs_high, lhs_low); |
| 4939 | __ Sra(AT, lhs_high, 31); |
| 4940 | __ Bgeu(AT, TMP, label); |
| 4941 | break; |
| 4942 | case kCondGT: |
| 4943 | __ Or(TMP, lhs_high, lhs_low); |
| 4944 | __ Sra(AT, lhs_high, 31); |
| 4945 | __ Bltu(AT, TMP, label); |
| 4946 | break; |
| 4947 | case kCondB: // always false |
| 4948 | break; |
| 4949 | case kCondAE: // always true |
| 4950 | __ B(label); |
| 4951 | break; |
| 4952 | } |
| 4953 | } else if (use_imm) { |
| 4954 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 4955 | switch (cond) { |
| 4956 | case kCondEQ: |
| 4957 | __ LoadConst32(TMP, imm_high); |
| 4958 | __ Xor(TMP, TMP, lhs_high); |
| 4959 | __ LoadConst32(AT, imm_low); |
| 4960 | __ Xor(AT, AT, lhs_low); |
| 4961 | __ Or(TMP, TMP, AT); |
| 4962 | __ Beqz(TMP, label); |
| 4963 | break; |
| 4964 | case kCondNE: |
| 4965 | __ LoadConst32(TMP, imm_high); |
| 4966 | __ Xor(TMP, TMP, lhs_high); |
| 4967 | __ LoadConst32(AT, imm_low); |
| 4968 | __ Xor(AT, AT, lhs_low); |
| 4969 | __ Or(TMP, TMP, AT); |
| 4970 | __ Bnez(TMP, label); |
| 4971 | break; |
| 4972 | case kCondLT: |
| 4973 | __ LoadConst32(TMP, imm_high); |
| 4974 | __ Blt(lhs_high, TMP, label); |
| 4975 | __ Slt(TMP, TMP, lhs_high); |
| 4976 | __ LoadConst32(AT, imm_low); |
| 4977 | __ Sltu(AT, lhs_low, AT); |
| 4978 | __ Blt(TMP, AT, label); |
| 4979 | break; |
| 4980 | case kCondGE: |
| 4981 | __ LoadConst32(TMP, imm_high); |
| 4982 | __ Blt(TMP, lhs_high, label); |
| 4983 | __ Slt(TMP, lhs_high, TMP); |
| 4984 | __ LoadConst32(AT, imm_low); |
| 4985 | __ Sltu(AT, lhs_low, AT); |
| 4986 | __ Or(TMP, TMP, AT); |
| 4987 | __ Beqz(TMP, label); |
| 4988 | break; |
| 4989 | case kCondLE: |
| 4990 | __ LoadConst32(TMP, imm_high); |
| 4991 | __ Blt(lhs_high, TMP, label); |
| 4992 | __ Slt(TMP, TMP, lhs_high); |
| 4993 | __ LoadConst32(AT, imm_low); |
| 4994 | __ Sltu(AT, AT, lhs_low); |
| 4995 | __ Or(TMP, TMP, AT); |
| 4996 | __ Beqz(TMP, label); |
| 4997 | break; |
| 4998 | case kCondGT: |
| 4999 | __ LoadConst32(TMP, imm_high); |
| 5000 | __ Blt(TMP, lhs_high, label); |
| 5001 | __ Slt(TMP, lhs_high, TMP); |
| 5002 | __ LoadConst32(AT, imm_low); |
| 5003 | __ Sltu(AT, AT, lhs_low); |
| 5004 | __ Blt(TMP, AT, label); |
| 5005 | break; |
| 5006 | case kCondB: |
| 5007 | __ LoadConst32(TMP, imm_high); |
| 5008 | __ Bltu(lhs_high, TMP, label); |
| 5009 | __ Sltu(TMP, TMP, lhs_high); |
| 5010 | __ LoadConst32(AT, imm_low); |
| 5011 | __ Sltu(AT, lhs_low, AT); |
| 5012 | __ Blt(TMP, AT, label); |
| 5013 | break; |
| 5014 | case kCondAE: |
| 5015 | __ LoadConst32(TMP, imm_high); |
| 5016 | __ Bltu(TMP, lhs_high, label); |
| 5017 | __ Sltu(TMP, lhs_high, TMP); |
| 5018 | __ LoadConst32(AT, imm_low); |
| 5019 | __ Sltu(AT, lhs_low, AT); |
| 5020 | __ Or(TMP, TMP, AT); |
| 5021 | __ Beqz(TMP, label); |
| 5022 | break; |
| 5023 | case kCondBE: |
| 5024 | __ LoadConst32(TMP, imm_high); |
| 5025 | __ Bltu(lhs_high, TMP, label); |
| 5026 | __ Sltu(TMP, TMP, lhs_high); |
| 5027 | __ LoadConst32(AT, imm_low); |
| 5028 | __ Sltu(AT, AT, lhs_low); |
| 5029 | __ Or(TMP, TMP, AT); |
| 5030 | __ Beqz(TMP, label); |
| 5031 | break; |
| 5032 | case kCondA: |
| 5033 | __ LoadConst32(TMP, imm_high); |
| 5034 | __ Bltu(TMP, lhs_high, label); |
| 5035 | __ Sltu(TMP, lhs_high, TMP); |
| 5036 | __ LoadConst32(AT, imm_low); |
| 5037 | __ Sltu(AT, AT, lhs_low); |
| 5038 | __ Blt(TMP, AT, label); |
| 5039 | break; |
| 5040 | } |
| 5041 | } else { |
| 5042 | switch (cond) { |
| 5043 | case kCondEQ: |
| 5044 | __ Xor(TMP, lhs_high, rhs_high); |
| 5045 | __ Xor(AT, lhs_low, rhs_low); |
| 5046 | __ Or(TMP, TMP, AT); |
| 5047 | __ Beqz(TMP, label); |
| 5048 | break; |
| 5049 | case kCondNE: |
| 5050 | __ Xor(TMP, lhs_high, rhs_high); |
| 5051 | __ Xor(AT, lhs_low, rhs_low); |
| 5052 | __ Or(TMP, TMP, AT); |
| 5053 | __ Bnez(TMP, label); |
| 5054 | break; |
| 5055 | case kCondLT: |
| 5056 | __ Blt(lhs_high, rhs_high, label); |
| 5057 | __ Slt(TMP, rhs_high, lhs_high); |
| 5058 | __ Sltu(AT, lhs_low, rhs_low); |
| 5059 | __ Blt(TMP, AT, label); |
| 5060 | break; |
| 5061 | case kCondGE: |
| 5062 | __ Blt(rhs_high, lhs_high, label); |
| 5063 | __ Slt(TMP, lhs_high, rhs_high); |
| 5064 | __ Sltu(AT, lhs_low, rhs_low); |
| 5065 | __ Or(TMP, TMP, AT); |
| 5066 | __ Beqz(TMP, label); |
| 5067 | break; |
| 5068 | case kCondLE: |
| 5069 | __ Blt(lhs_high, rhs_high, label); |
| 5070 | __ Slt(TMP, rhs_high, lhs_high); |
| 5071 | __ Sltu(AT, rhs_low, lhs_low); |
| 5072 | __ Or(TMP, TMP, AT); |
| 5073 | __ Beqz(TMP, label); |
| 5074 | break; |
| 5075 | case kCondGT: |
| 5076 | __ Blt(rhs_high, lhs_high, label); |
| 5077 | __ Slt(TMP, lhs_high, rhs_high); |
| 5078 | __ Sltu(AT, rhs_low, lhs_low); |
| 5079 | __ Blt(TMP, AT, label); |
| 5080 | break; |
| 5081 | case kCondB: |
| 5082 | __ Bltu(lhs_high, rhs_high, label); |
| 5083 | __ Sltu(TMP, rhs_high, lhs_high); |
| 5084 | __ Sltu(AT, lhs_low, rhs_low); |
| 5085 | __ Blt(TMP, AT, label); |
| 5086 | break; |
| 5087 | case kCondAE: |
| 5088 | __ Bltu(rhs_high, lhs_high, label); |
| 5089 | __ Sltu(TMP, lhs_high, rhs_high); |
| 5090 | __ Sltu(AT, lhs_low, rhs_low); |
| 5091 | __ Or(TMP, TMP, AT); |
| 5092 | __ Beqz(TMP, label); |
| 5093 | break; |
| 5094 | case kCondBE: |
| 5095 | __ Bltu(lhs_high, rhs_high, label); |
| 5096 | __ Sltu(TMP, rhs_high, lhs_high); |
| 5097 | __ Sltu(AT, rhs_low, lhs_low); |
| 5098 | __ Or(TMP, TMP, AT); |
| 5099 | __ Beqz(TMP, label); |
| 5100 | break; |
| 5101 | case kCondA: |
| 5102 | __ Bltu(rhs_high, lhs_high, label); |
| 5103 | __ Sltu(TMP, lhs_high, rhs_high); |
| 5104 | __ Sltu(AT, rhs_low, lhs_low); |
| 5105 | __ Blt(TMP, AT, label); |
| 5106 | break; |
| 5107 | } |
| 5108 | } |
| 5109 | } |
| 5110 | |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5111 | void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond, |
| 5112 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5113 | DataType::Type type, |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5114 | LocationSummary* locations) { |
| 5115 | Register dst = locations->Out().AsRegister<Register>(); |
| 5116 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5117 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5118 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5119 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5120 | if (isR6) { |
| 5121 | switch (cond) { |
| 5122 | case kCondEQ: |
| 5123 | __ CmpEqS(FTMP, lhs, rhs); |
| 5124 | __ Mfc1(dst, FTMP); |
| 5125 | __ Andi(dst, dst, 1); |
| 5126 | break; |
| 5127 | case kCondNE: |
| 5128 | __ CmpEqS(FTMP, lhs, rhs); |
| 5129 | __ Mfc1(dst, FTMP); |
| 5130 | __ Addiu(dst, dst, 1); |
| 5131 | break; |
| 5132 | case kCondLT: |
| 5133 | if (gt_bias) { |
| 5134 | __ CmpLtS(FTMP, lhs, rhs); |
| 5135 | } else { |
| 5136 | __ CmpUltS(FTMP, lhs, rhs); |
| 5137 | } |
| 5138 | __ Mfc1(dst, FTMP); |
| 5139 | __ Andi(dst, dst, 1); |
| 5140 | break; |
| 5141 | case kCondLE: |
| 5142 | if (gt_bias) { |
| 5143 | __ CmpLeS(FTMP, lhs, rhs); |
| 5144 | } else { |
| 5145 | __ CmpUleS(FTMP, lhs, rhs); |
| 5146 | } |
| 5147 | __ Mfc1(dst, FTMP); |
| 5148 | __ Andi(dst, dst, 1); |
| 5149 | break; |
| 5150 | case kCondGT: |
| 5151 | if (gt_bias) { |
| 5152 | __ CmpUltS(FTMP, rhs, lhs); |
| 5153 | } else { |
| 5154 | __ CmpLtS(FTMP, rhs, lhs); |
| 5155 | } |
| 5156 | __ Mfc1(dst, FTMP); |
| 5157 | __ Andi(dst, dst, 1); |
| 5158 | break; |
| 5159 | case kCondGE: |
| 5160 | if (gt_bias) { |
| 5161 | __ CmpUleS(FTMP, rhs, lhs); |
| 5162 | } else { |
| 5163 | __ CmpLeS(FTMP, rhs, lhs); |
| 5164 | } |
| 5165 | __ Mfc1(dst, FTMP); |
| 5166 | __ Andi(dst, dst, 1); |
| 5167 | break; |
| 5168 | default: |
| 5169 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5170 | UNREACHABLE(); |
| 5171 | } |
| 5172 | } else { |
| 5173 | switch (cond) { |
| 5174 | case kCondEQ: |
| 5175 | __ CeqS(0, lhs, rhs); |
| 5176 | __ LoadConst32(dst, 1); |
| 5177 | __ Movf(dst, ZERO, 0); |
| 5178 | break; |
| 5179 | case kCondNE: |
| 5180 | __ CeqS(0, lhs, rhs); |
| 5181 | __ LoadConst32(dst, 1); |
| 5182 | __ Movt(dst, ZERO, 0); |
| 5183 | break; |
| 5184 | case kCondLT: |
| 5185 | if (gt_bias) { |
| 5186 | __ ColtS(0, lhs, rhs); |
| 5187 | } else { |
| 5188 | __ CultS(0, lhs, rhs); |
| 5189 | } |
| 5190 | __ LoadConst32(dst, 1); |
| 5191 | __ Movf(dst, ZERO, 0); |
| 5192 | break; |
| 5193 | case kCondLE: |
| 5194 | if (gt_bias) { |
| 5195 | __ ColeS(0, lhs, rhs); |
| 5196 | } else { |
| 5197 | __ CuleS(0, lhs, rhs); |
| 5198 | } |
| 5199 | __ LoadConst32(dst, 1); |
| 5200 | __ Movf(dst, ZERO, 0); |
| 5201 | break; |
| 5202 | case kCondGT: |
| 5203 | if (gt_bias) { |
| 5204 | __ CultS(0, rhs, lhs); |
| 5205 | } else { |
| 5206 | __ ColtS(0, rhs, lhs); |
| 5207 | } |
| 5208 | __ LoadConst32(dst, 1); |
| 5209 | __ Movf(dst, ZERO, 0); |
| 5210 | break; |
| 5211 | case kCondGE: |
| 5212 | if (gt_bias) { |
| 5213 | __ CuleS(0, rhs, lhs); |
| 5214 | } else { |
| 5215 | __ ColeS(0, rhs, lhs); |
| 5216 | } |
| 5217 | __ LoadConst32(dst, 1); |
| 5218 | __ Movf(dst, ZERO, 0); |
| 5219 | break; |
| 5220 | default: |
| 5221 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5222 | UNREACHABLE(); |
| 5223 | } |
| 5224 | } |
| 5225 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5226 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5227 | if (isR6) { |
| 5228 | switch (cond) { |
| 5229 | case kCondEQ: |
| 5230 | __ CmpEqD(FTMP, lhs, rhs); |
| 5231 | __ Mfc1(dst, FTMP); |
| 5232 | __ Andi(dst, dst, 1); |
| 5233 | break; |
| 5234 | case kCondNE: |
| 5235 | __ CmpEqD(FTMP, lhs, rhs); |
| 5236 | __ Mfc1(dst, FTMP); |
| 5237 | __ Addiu(dst, dst, 1); |
| 5238 | break; |
| 5239 | case kCondLT: |
| 5240 | if (gt_bias) { |
| 5241 | __ CmpLtD(FTMP, lhs, rhs); |
| 5242 | } else { |
| 5243 | __ CmpUltD(FTMP, lhs, rhs); |
| 5244 | } |
| 5245 | __ Mfc1(dst, FTMP); |
| 5246 | __ Andi(dst, dst, 1); |
| 5247 | break; |
| 5248 | case kCondLE: |
| 5249 | if (gt_bias) { |
| 5250 | __ CmpLeD(FTMP, lhs, rhs); |
| 5251 | } else { |
| 5252 | __ CmpUleD(FTMP, lhs, rhs); |
| 5253 | } |
| 5254 | __ Mfc1(dst, FTMP); |
| 5255 | __ Andi(dst, dst, 1); |
| 5256 | break; |
| 5257 | case kCondGT: |
| 5258 | if (gt_bias) { |
| 5259 | __ CmpUltD(FTMP, rhs, lhs); |
| 5260 | } else { |
| 5261 | __ CmpLtD(FTMP, rhs, lhs); |
| 5262 | } |
| 5263 | __ Mfc1(dst, FTMP); |
| 5264 | __ Andi(dst, dst, 1); |
| 5265 | break; |
| 5266 | case kCondGE: |
| 5267 | if (gt_bias) { |
| 5268 | __ CmpUleD(FTMP, rhs, lhs); |
| 5269 | } else { |
| 5270 | __ CmpLeD(FTMP, rhs, lhs); |
| 5271 | } |
| 5272 | __ Mfc1(dst, FTMP); |
| 5273 | __ Andi(dst, dst, 1); |
| 5274 | break; |
| 5275 | default: |
| 5276 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5277 | UNREACHABLE(); |
| 5278 | } |
| 5279 | } else { |
| 5280 | switch (cond) { |
| 5281 | case kCondEQ: |
| 5282 | __ CeqD(0, lhs, rhs); |
| 5283 | __ LoadConst32(dst, 1); |
| 5284 | __ Movf(dst, ZERO, 0); |
| 5285 | break; |
| 5286 | case kCondNE: |
| 5287 | __ CeqD(0, lhs, rhs); |
| 5288 | __ LoadConst32(dst, 1); |
| 5289 | __ Movt(dst, ZERO, 0); |
| 5290 | break; |
| 5291 | case kCondLT: |
| 5292 | if (gt_bias) { |
| 5293 | __ ColtD(0, lhs, rhs); |
| 5294 | } else { |
| 5295 | __ CultD(0, lhs, rhs); |
| 5296 | } |
| 5297 | __ LoadConst32(dst, 1); |
| 5298 | __ Movf(dst, ZERO, 0); |
| 5299 | break; |
| 5300 | case kCondLE: |
| 5301 | if (gt_bias) { |
| 5302 | __ ColeD(0, lhs, rhs); |
| 5303 | } else { |
| 5304 | __ CuleD(0, lhs, rhs); |
| 5305 | } |
| 5306 | __ LoadConst32(dst, 1); |
| 5307 | __ Movf(dst, ZERO, 0); |
| 5308 | break; |
| 5309 | case kCondGT: |
| 5310 | if (gt_bias) { |
| 5311 | __ CultD(0, rhs, lhs); |
| 5312 | } else { |
| 5313 | __ ColtD(0, rhs, lhs); |
| 5314 | } |
| 5315 | __ LoadConst32(dst, 1); |
| 5316 | __ Movf(dst, ZERO, 0); |
| 5317 | break; |
| 5318 | case kCondGE: |
| 5319 | if (gt_bias) { |
| 5320 | __ CuleD(0, rhs, lhs); |
| 5321 | } else { |
| 5322 | __ ColeD(0, rhs, lhs); |
| 5323 | } |
| 5324 | __ LoadConst32(dst, 1); |
| 5325 | __ Movf(dst, ZERO, 0); |
| 5326 | break; |
| 5327 | default: |
| 5328 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5329 | UNREACHABLE(); |
| 5330 | } |
| 5331 | } |
| 5332 | } |
| 5333 | } |
| 5334 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5335 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond, |
| 5336 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5337 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5338 | LocationSummary* input_locations, |
| 5339 | int cc) { |
| 5340 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5341 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5342 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5343 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5344 | switch (cond) { |
| 5345 | case kCondEQ: |
| 5346 | __ CeqS(cc, lhs, rhs); |
| 5347 | return false; |
| 5348 | case kCondNE: |
| 5349 | __ CeqS(cc, lhs, rhs); |
| 5350 | return true; |
| 5351 | case kCondLT: |
| 5352 | if (gt_bias) { |
| 5353 | __ ColtS(cc, lhs, rhs); |
| 5354 | } else { |
| 5355 | __ CultS(cc, lhs, rhs); |
| 5356 | } |
| 5357 | return false; |
| 5358 | case kCondLE: |
| 5359 | if (gt_bias) { |
| 5360 | __ ColeS(cc, lhs, rhs); |
| 5361 | } else { |
| 5362 | __ CuleS(cc, lhs, rhs); |
| 5363 | } |
| 5364 | return false; |
| 5365 | case kCondGT: |
| 5366 | if (gt_bias) { |
| 5367 | __ CultS(cc, rhs, lhs); |
| 5368 | } else { |
| 5369 | __ ColtS(cc, rhs, lhs); |
| 5370 | } |
| 5371 | return false; |
| 5372 | case kCondGE: |
| 5373 | if (gt_bias) { |
| 5374 | __ CuleS(cc, rhs, lhs); |
| 5375 | } else { |
| 5376 | __ ColeS(cc, rhs, lhs); |
| 5377 | } |
| 5378 | return false; |
| 5379 | default: |
| 5380 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5381 | UNREACHABLE(); |
| 5382 | } |
| 5383 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5384 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5385 | switch (cond) { |
| 5386 | case kCondEQ: |
| 5387 | __ CeqD(cc, lhs, rhs); |
| 5388 | return false; |
| 5389 | case kCondNE: |
| 5390 | __ CeqD(cc, lhs, rhs); |
| 5391 | return true; |
| 5392 | case kCondLT: |
| 5393 | if (gt_bias) { |
| 5394 | __ ColtD(cc, lhs, rhs); |
| 5395 | } else { |
| 5396 | __ CultD(cc, lhs, rhs); |
| 5397 | } |
| 5398 | return false; |
| 5399 | case kCondLE: |
| 5400 | if (gt_bias) { |
| 5401 | __ ColeD(cc, lhs, rhs); |
| 5402 | } else { |
| 5403 | __ CuleD(cc, lhs, rhs); |
| 5404 | } |
| 5405 | return false; |
| 5406 | case kCondGT: |
| 5407 | if (gt_bias) { |
| 5408 | __ CultD(cc, rhs, lhs); |
| 5409 | } else { |
| 5410 | __ ColtD(cc, rhs, lhs); |
| 5411 | } |
| 5412 | return false; |
| 5413 | case kCondGE: |
| 5414 | if (gt_bias) { |
| 5415 | __ CuleD(cc, rhs, lhs); |
| 5416 | } else { |
| 5417 | __ ColeD(cc, rhs, lhs); |
| 5418 | } |
| 5419 | return false; |
| 5420 | default: |
| 5421 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5422 | UNREACHABLE(); |
| 5423 | } |
| 5424 | } |
| 5425 | } |
| 5426 | |
| 5427 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond, |
| 5428 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5429 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5430 | LocationSummary* input_locations, |
| 5431 | FRegister dst) { |
| 5432 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5433 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5434 | CHECK(codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5435 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5436 | switch (cond) { |
| 5437 | case kCondEQ: |
| 5438 | __ CmpEqS(dst, lhs, rhs); |
| 5439 | return false; |
| 5440 | case kCondNE: |
| 5441 | __ CmpEqS(dst, lhs, rhs); |
| 5442 | return true; |
| 5443 | case kCondLT: |
| 5444 | if (gt_bias) { |
| 5445 | __ CmpLtS(dst, lhs, rhs); |
| 5446 | } else { |
| 5447 | __ CmpUltS(dst, lhs, rhs); |
| 5448 | } |
| 5449 | return false; |
| 5450 | case kCondLE: |
| 5451 | if (gt_bias) { |
| 5452 | __ CmpLeS(dst, lhs, rhs); |
| 5453 | } else { |
| 5454 | __ CmpUleS(dst, lhs, rhs); |
| 5455 | } |
| 5456 | return false; |
| 5457 | case kCondGT: |
| 5458 | if (gt_bias) { |
| 5459 | __ CmpUltS(dst, rhs, lhs); |
| 5460 | } else { |
| 5461 | __ CmpLtS(dst, rhs, lhs); |
| 5462 | } |
| 5463 | return false; |
| 5464 | case kCondGE: |
| 5465 | if (gt_bias) { |
| 5466 | __ CmpUleS(dst, rhs, lhs); |
| 5467 | } else { |
| 5468 | __ CmpLeS(dst, rhs, lhs); |
| 5469 | } |
| 5470 | return false; |
| 5471 | default: |
| 5472 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5473 | UNREACHABLE(); |
| 5474 | } |
| 5475 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5476 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5477 | switch (cond) { |
| 5478 | case kCondEQ: |
| 5479 | __ CmpEqD(dst, lhs, rhs); |
| 5480 | return false; |
| 5481 | case kCondNE: |
| 5482 | __ CmpEqD(dst, lhs, rhs); |
| 5483 | return true; |
| 5484 | case kCondLT: |
| 5485 | if (gt_bias) { |
| 5486 | __ CmpLtD(dst, lhs, rhs); |
| 5487 | } else { |
| 5488 | __ CmpUltD(dst, lhs, rhs); |
| 5489 | } |
| 5490 | return false; |
| 5491 | case kCondLE: |
| 5492 | if (gt_bias) { |
| 5493 | __ CmpLeD(dst, lhs, rhs); |
| 5494 | } else { |
| 5495 | __ CmpUleD(dst, lhs, rhs); |
| 5496 | } |
| 5497 | return false; |
| 5498 | case kCondGT: |
| 5499 | if (gt_bias) { |
| 5500 | __ CmpUltD(dst, rhs, lhs); |
| 5501 | } else { |
| 5502 | __ CmpLtD(dst, rhs, lhs); |
| 5503 | } |
| 5504 | return false; |
| 5505 | case kCondGE: |
| 5506 | if (gt_bias) { |
| 5507 | __ CmpUleD(dst, rhs, lhs); |
| 5508 | } else { |
| 5509 | __ CmpLeD(dst, rhs, lhs); |
| 5510 | } |
| 5511 | return false; |
| 5512 | default: |
| 5513 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5514 | UNREACHABLE(); |
| 5515 | } |
| 5516 | } |
| 5517 | } |
| 5518 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5519 | void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond, |
| 5520 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5521 | DataType::Type type, |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5522 | LocationSummary* locations, |
| 5523 | MipsLabel* label) { |
| 5524 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5525 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5526 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5527 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5528 | if (isR6) { |
| 5529 | switch (cond) { |
| 5530 | case kCondEQ: |
| 5531 | __ CmpEqS(FTMP, lhs, rhs); |
| 5532 | __ Bc1nez(FTMP, label); |
| 5533 | break; |
| 5534 | case kCondNE: |
| 5535 | __ CmpEqS(FTMP, lhs, rhs); |
| 5536 | __ Bc1eqz(FTMP, label); |
| 5537 | break; |
| 5538 | case kCondLT: |
| 5539 | if (gt_bias) { |
| 5540 | __ CmpLtS(FTMP, lhs, rhs); |
| 5541 | } else { |
| 5542 | __ CmpUltS(FTMP, lhs, rhs); |
| 5543 | } |
| 5544 | __ Bc1nez(FTMP, label); |
| 5545 | break; |
| 5546 | case kCondLE: |
| 5547 | if (gt_bias) { |
| 5548 | __ CmpLeS(FTMP, lhs, rhs); |
| 5549 | } else { |
| 5550 | __ CmpUleS(FTMP, lhs, rhs); |
| 5551 | } |
| 5552 | __ Bc1nez(FTMP, label); |
| 5553 | break; |
| 5554 | case kCondGT: |
| 5555 | if (gt_bias) { |
| 5556 | __ CmpUltS(FTMP, rhs, lhs); |
| 5557 | } else { |
| 5558 | __ CmpLtS(FTMP, rhs, lhs); |
| 5559 | } |
| 5560 | __ Bc1nez(FTMP, label); |
| 5561 | break; |
| 5562 | case kCondGE: |
| 5563 | if (gt_bias) { |
| 5564 | __ CmpUleS(FTMP, rhs, lhs); |
| 5565 | } else { |
| 5566 | __ CmpLeS(FTMP, rhs, lhs); |
| 5567 | } |
| 5568 | __ Bc1nez(FTMP, label); |
| 5569 | break; |
| 5570 | default: |
| 5571 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5572 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5573 | } |
| 5574 | } else { |
| 5575 | switch (cond) { |
| 5576 | case kCondEQ: |
| 5577 | __ CeqS(0, lhs, rhs); |
| 5578 | __ Bc1t(0, label); |
| 5579 | break; |
| 5580 | case kCondNE: |
| 5581 | __ CeqS(0, lhs, rhs); |
| 5582 | __ Bc1f(0, label); |
| 5583 | break; |
| 5584 | case kCondLT: |
| 5585 | if (gt_bias) { |
| 5586 | __ ColtS(0, lhs, rhs); |
| 5587 | } else { |
| 5588 | __ CultS(0, lhs, rhs); |
| 5589 | } |
| 5590 | __ Bc1t(0, label); |
| 5591 | break; |
| 5592 | case kCondLE: |
| 5593 | if (gt_bias) { |
| 5594 | __ ColeS(0, lhs, rhs); |
| 5595 | } else { |
| 5596 | __ CuleS(0, lhs, rhs); |
| 5597 | } |
| 5598 | __ Bc1t(0, label); |
| 5599 | break; |
| 5600 | case kCondGT: |
| 5601 | if (gt_bias) { |
| 5602 | __ CultS(0, rhs, lhs); |
| 5603 | } else { |
| 5604 | __ ColtS(0, rhs, lhs); |
| 5605 | } |
| 5606 | __ Bc1t(0, label); |
| 5607 | break; |
| 5608 | case kCondGE: |
| 5609 | if (gt_bias) { |
| 5610 | __ CuleS(0, rhs, lhs); |
| 5611 | } else { |
| 5612 | __ ColeS(0, rhs, lhs); |
| 5613 | } |
| 5614 | __ Bc1t(0, label); |
| 5615 | break; |
| 5616 | default: |
| 5617 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5618 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5619 | } |
| 5620 | } |
| 5621 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5622 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5623 | if (isR6) { |
| 5624 | switch (cond) { |
| 5625 | case kCondEQ: |
| 5626 | __ CmpEqD(FTMP, lhs, rhs); |
| 5627 | __ Bc1nez(FTMP, label); |
| 5628 | break; |
| 5629 | case kCondNE: |
| 5630 | __ CmpEqD(FTMP, lhs, rhs); |
| 5631 | __ Bc1eqz(FTMP, label); |
| 5632 | break; |
| 5633 | case kCondLT: |
| 5634 | if (gt_bias) { |
| 5635 | __ CmpLtD(FTMP, lhs, rhs); |
| 5636 | } else { |
| 5637 | __ CmpUltD(FTMP, lhs, rhs); |
| 5638 | } |
| 5639 | __ Bc1nez(FTMP, label); |
| 5640 | break; |
| 5641 | case kCondLE: |
| 5642 | if (gt_bias) { |
| 5643 | __ CmpLeD(FTMP, lhs, rhs); |
| 5644 | } else { |
| 5645 | __ CmpUleD(FTMP, lhs, rhs); |
| 5646 | } |
| 5647 | __ Bc1nez(FTMP, label); |
| 5648 | break; |
| 5649 | case kCondGT: |
| 5650 | if (gt_bias) { |
| 5651 | __ CmpUltD(FTMP, rhs, lhs); |
| 5652 | } else { |
| 5653 | __ CmpLtD(FTMP, rhs, lhs); |
| 5654 | } |
| 5655 | __ Bc1nez(FTMP, label); |
| 5656 | break; |
| 5657 | case kCondGE: |
| 5658 | if (gt_bias) { |
| 5659 | __ CmpUleD(FTMP, rhs, lhs); |
| 5660 | } else { |
| 5661 | __ CmpLeD(FTMP, rhs, lhs); |
| 5662 | } |
| 5663 | __ Bc1nez(FTMP, label); |
| 5664 | break; |
| 5665 | default: |
| 5666 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5667 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5668 | } |
| 5669 | } else { |
| 5670 | switch (cond) { |
| 5671 | case kCondEQ: |
| 5672 | __ CeqD(0, lhs, rhs); |
| 5673 | __ Bc1t(0, label); |
| 5674 | break; |
| 5675 | case kCondNE: |
| 5676 | __ CeqD(0, lhs, rhs); |
| 5677 | __ Bc1f(0, label); |
| 5678 | break; |
| 5679 | case kCondLT: |
| 5680 | if (gt_bias) { |
| 5681 | __ ColtD(0, lhs, rhs); |
| 5682 | } else { |
| 5683 | __ CultD(0, lhs, rhs); |
| 5684 | } |
| 5685 | __ Bc1t(0, label); |
| 5686 | break; |
| 5687 | case kCondLE: |
| 5688 | if (gt_bias) { |
| 5689 | __ ColeD(0, lhs, rhs); |
| 5690 | } else { |
| 5691 | __ CuleD(0, lhs, rhs); |
| 5692 | } |
| 5693 | __ Bc1t(0, label); |
| 5694 | break; |
| 5695 | case kCondGT: |
| 5696 | if (gt_bias) { |
| 5697 | __ CultD(0, rhs, lhs); |
| 5698 | } else { |
| 5699 | __ ColtD(0, rhs, lhs); |
| 5700 | } |
| 5701 | __ Bc1t(0, label); |
| 5702 | break; |
| 5703 | case kCondGE: |
| 5704 | if (gt_bias) { |
| 5705 | __ CuleD(0, rhs, lhs); |
| 5706 | } else { |
| 5707 | __ ColeD(0, rhs, lhs); |
| 5708 | } |
| 5709 | __ Bc1t(0, label); |
| 5710 | break; |
| 5711 | default: |
| 5712 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5713 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5714 | } |
| 5715 | } |
| 5716 | } |
| 5717 | } |
| 5718 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5719 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5720 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5721 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5722 | MipsLabel* false_target) { |
| 5723 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5724 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5725 | if (true_target == nullptr && false_target == nullptr) { |
| 5726 | // Nothing to do. The code always falls through. |
| 5727 | return; |
| 5728 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5729 | // Constant condition, statically compared against "true" (integer value 1). |
| 5730 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5731 | if (true_target != nullptr) { |
| 5732 | __ B(true_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5733 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5734 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5735 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5736 | if (false_target != nullptr) { |
| 5737 | __ B(false_target); |
| 5738 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5739 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5740 | return; |
| 5741 | } |
| 5742 | |
| 5743 | // The following code generates these patterns: |
| 5744 | // (1) true_target == nullptr && false_target != nullptr |
| 5745 | // - opposite condition true => branch to false_target |
| 5746 | // (2) true_target != nullptr && false_target == nullptr |
| 5747 | // - condition true => branch to true_target |
| 5748 | // (3) true_target != nullptr && false_target != nullptr |
| 5749 | // - condition true => branch to true_target |
| 5750 | // - branch to false_target |
| 5751 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5752 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5753 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5754 | DCHECK(cond_val.IsRegister()); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5755 | if (true_target == nullptr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5756 | __ Beqz(cond_val.AsRegister<Register>(), false_target); |
| 5757 | } else { |
| 5758 | __ Bnez(cond_val.AsRegister<Register>(), true_target); |
| 5759 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5760 | } else { |
| 5761 | // The condition instruction has not been materialized, use its inputs as |
| 5762 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5763 | HCondition* condition = cond->AsCondition(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5764 | DataType::Type type = condition->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5765 | LocationSummary* locations = cond->GetLocations(); |
| 5766 | IfCondition if_cond = condition->GetCondition(); |
| 5767 | MipsLabel* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5768 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5769 | if (true_target == nullptr) { |
| 5770 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5771 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5772 | } |
| 5773 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5774 | switch (type) { |
| 5775 | default: |
| 5776 | GenerateIntCompareAndBranch(if_cond, locations, branch_target); |
| 5777 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5778 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5779 | GenerateLongCompareAndBranch(if_cond, locations, branch_target); |
| 5780 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5781 | case DataType::Type::kFloat32: |
| 5782 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5783 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 5784 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5785 | } |
| 5786 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5787 | |
| 5788 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 5789 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 5790 | if (true_target != nullptr && false_target != nullptr) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5791 | __ B(false_target); |
| 5792 | } |
| 5793 | } |
| 5794 | |
| 5795 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5796 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5797 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5798 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5799 | } |
| 5800 | } |
| 5801 | |
| 5802 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5803 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 5804 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 5805 | MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 5806 | nullptr : codegen_->GetLabelOf(true_successor); |
| 5807 | MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 5808 | nullptr : codegen_->GetLabelOf(false_successor); |
| 5809 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5810 | } |
| 5811 | |
| 5812 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5813 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5814 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 5815 | InvokeRuntimeCallingConvention calling_convention; |
| 5816 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5817 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5818 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5819 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5820 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5821 | } |
| 5822 | } |
| 5823 | |
| 5824 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 5825 | SlowPathCodeMIPS* slow_path = |
| 5826 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5827 | GenerateTestAndBranch(deoptimize, |
| 5828 | /* condition_input_index */ 0, |
| 5829 | slow_path->GetEntryLabel(), |
| 5830 | /* false_target */ nullptr); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5831 | } |
| 5832 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5833 | // This function returns true if a conditional move can be generated for HSelect. |
| 5834 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 5835 | // branches and regular moves. |
| 5836 | // |
| 5837 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 5838 | // |
| 5839 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 5840 | // are two distinct tasks, this function does both because they share quite a bit |
| 5841 | // of common logic. |
| 5842 | static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) { |
| 5843 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 5844 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 5845 | HCondition* condition = cond->AsCondition(); |
| 5846 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5847 | DataType::Type cond_type = |
| 5848 | materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType(); |
| 5849 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5850 | |
| 5851 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 5852 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 5853 | bool is_true_value_zero_constant = |
| 5854 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 5855 | bool is_false_value_zero_constant = |
| 5856 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 5857 | |
| 5858 | bool can_move_conditionally = false; |
| 5859 | bool use_const_for_false_in = false; |
| 5860 | bool use_const_for_true_in = false; |
| 5861 | |
| 5862 | if (!cond->IsConstant()) { |
| 5863 | switch (cond_type) { |
| 5864 | default: |
| 5865 | switch (dst_type) { |
| 5866 | default: |
| 5867 | // Moving int on int condition. |
| 5868 | if (is_r6) { |
| 5869 | if (is_true_value_zero_constant) { |
| 5870 | // seleqz out_reg, false_reg, cond_reg |
| 5871 | can_move_conditionally = true; |
| 5872 | use_const_for_true_in = true; |
| 5873 | } else if (is_false_value_zero_constant) { |
| 5874 | // selnez out_reg, true_reg, cond_reg |
| 5875 | can_move_conditionally = true; |
| 5876 | use_const_for_false_in = true; |
| 5877 | } else if (materialized) { |
| 5878 | // Not materializing unmaterialized int conditions |
| 5879 | // to keep the instruction count low. |
| 5880 | // selnez AT, true_reg, cond_reg |
| 5881 | // seleqz TMP, false_reg, cond_reg |
| 5882 | // or out_reg, AT, TMP |
| 5883 | can_move_conditionally = true; |
| 5884 | } |
| 5885 | } else { |
| 5886 | // movn out_reg, true_reg/ZERO, cond_reg |
| 5887 | can_move_conditionally = true; |
| 5888 | use_const_for_true_in = is_true_value_zero_constant; |
| 5889 | } |
| 5890 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5891 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5892 | // Moving long on int condition. |
| 5893 | if (is_r6) { |
| 5894 | if (is_true_value_zero_constant) { |
| 5895 | // seleqz out_reg_lo, false_reg_lo, cond_reg |
| 5896 | // seleqz out_reg_hi, false_reg_hi, cond_reg |
| 5897 | can_move_conditionally = true; |
| 5898 | use_const_for_true_in = true; |
| 5899 | } else if (is_false_value_zero_constant) { |
| 5900 | // selnez out_reg_lo, true_reg_lo, cond_reg |
| 5901 | // selnez out_reg_hi, true_reg_hi, cond_reg |
| 5902 | can_move_conditionally = true; |
| 5903 | use_const_for_false_in = true; |
| 5904 | } |
| 5905 | // Other long conditional moves would generate 6+ instructions, |
| 5906 | // which is too many. |
| 5907 | } else { |
| 5908 | // movn out_reg_lo, true_reg_lo/ZERO, cond_reg |
| 5909 | // movn out_reg_hi, true_reg_hi/ZERO, cond_reg |
| 5910 | can_move_conditionally = true; |
| 5911 | use_const_for_true_in = is_true_value_zero_constant; |
| 5912 | } |
| 5913 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5914 | case DataType::Type::kFloat32: |
| 5915 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5916 | // Moving float/double on int condition. |
| 5917 | if (is_r6) { |
| 5918 | if (materialized) { |
| 5919 | // Not materializing unmaterialized int conditions |
| 5920 | // to keep the instruction count low. |
| 5921 | can_move_conditionally = true; |
| 5922 | if (is_true_value_zero_constant) { |
| 5923 | // sltu TMP, ZERO, cond_reg |
| 5924 | // mtc1 TMP, temp_cond_reg |
| 5925 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 5926 | use_const_for_true_in = true; |
| 5927 | } else if (is_false_value_zero_constant) { |
| 5928 | // sltu TMP, ZERO, cond_reg |
| 5929 | // mtc1 TMP, temp_cond_reg |
| 5930 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 5931 | use_const_for_false_in = true; |
| 5932 | } else { |
| 5933 | // sltu TMP, ZERO, cond_reg |
| 5934 | // mtc1 TMP, temp_cond_reg |
| 5935 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 5936 | // mov.fmt out_reg, temp_cond_reg |
| 5937 | } |
| 5938 | } |
| 5939 | } else { |
| 5940 | // movn.fmt out_reg, true_reg, cond_reg |
| 5941 | can_move_conditionally = true; |
| 5942 | } |
| 5943 | break; |
| 5944 | } |
| 5945 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5946 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5947 | // We don't materialize long comparison now |
| 5948 | // and use conditional branches instead. |
| 5949 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5950 | case DataType::Type::kFloat32: |
| 5951 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5952 | switch (dst_type) { |
| 5953 | default: |
| 5954 | // Moving int on float/double condition. |
| 5955 | if (is_r6) { |
| 5956 | if (is_true_value_zero_constant) { |
| 5957 | // mfc1 TMP, temp_cond_reg |
| 5958 | // seleqz out_reg, false_reg, TMP |
| 5959 | can_move_conditionally = true; |
| 5960 | use_const_for_true_in = true; |
| 5961 | } else if (is_false_value_zero_constant) { |
| 5962 | // mfc1 TMP, temp_cond_reg |
| 5963 | // selnez out_reg, true_reg, TMP |
| 5964 | can_move_conditionally = true; |
| 5965 | use_const_for_false_in = true; |
| 5966 | } else { |
| 5967 | // mfc1 TMP, temp_cond_reg |
| 5968 | // selnez AT, true_reg, TMP |
| 5969 | // seleqz TMP, false_reg, TMP |
| 5970 | // or out_reg, AT, TMP |
| 5971 | can_move_conditionally = true; |
| 5972 | } |
| 5973 | } else { |
| 5974 | // movt out_reg, true_reg/ZERO, cc |
| 5975 | can_move_conditionally = true; |
| 5976 | use_const_for_true_in = is_true_value_zero_constant; |
| 5977 | } |
| 5978 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5979 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5980 | // Moving long on float/double condition. |
| 5981 | if (is_r6) { |
| 5982 | if (is_true_value_zero_constant) { |
| 5983 | // mfc1 TMP, temp_cond_reg |
| 5984 | // seleqz out_reg_lo, false_reg_lo, TMP |
| 5985 | // seleqz out_reg_hi, false_reg_hi, TMP |
| 5986 | can_move_conditionally = true; |
| 5987 | use_const_for_true_in = true; |
| 5988 | } else if (is_false_value_zero_constant) { |
| 5989 | // mfc1 TMP, temp_cond_reg |
| 5990 | // selnez out_reg_lo, true_reg_lo, TMP |
| 5991 | // selnez out_reg_hi, true_reg_hi, TMP |
| 5992 | can_move_conditionally = true; |
| 5993 | use_const_for_false_in = true; |
| 5994 | } |
| 5995 | // Other long conditional moves would generate 6+ instructions, |
| 5996 | // which is too many. |
| 5997 | } else { |
| 5998 | // movt out_reg_lo, true_reg_lo/ZERO, cc |
| 5999 | // movt out_reg_hi, true_reg_hi/ZERO, cc |
| 6000 | can_move_conditionally = true; |
| 6001 | use_const_for_true_in = is_true_value_zero_constant; |
| 6002 | } |
| 6003 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6004 | case DataType::Type::kFloat32: |
| 6005 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6006 | // Moving float/double on float/double condition. |
| 6007 | if (is_r6) { |
| 6008 | can_move_conditionally = true; |
| 6009 | if (is_true_value_zero_constant) { |
| 6010 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 6011 | use_const_for_true_in = true; |
| 6012 | } else if (is_false_value_zero_constant) { |
| 6013 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 6014 | use_const_for_false_in = true; |
| 6015 | } else { |
| 6016 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 6017 | // mov.fmt out_reg, temp_cond_reg |
| 6018 | } |
| 6019 | } else { |
| 6020 | // movt.fmt out_reg, true_reg, cc |
| 6021 | can_move_conditionally = true; |
| 6022 | } |
| 6023 | break; |
| 6024 | } |
| 6025 | break; |
| 6026 | } |
| 6027 | } |
| 6028 | |
| 6029 | if (can_move_conditionally) { |
| 6030 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 6031 | } else { |
| 6032 | DCHECK(!use_const_for_false_in); |
| 6033 | DCHECK(!use_const_for_true_in); |
| 6034 | } |
| 6035 | |
| 6036 | if (locations_to_set != nullptr) { |
| 6037 | if (use_const_for_false_in) { |
| 6038 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 6039 | } else { |
| 6040 | locations_to_set->SetInAt(0, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6041 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6042 | ? Location::RequiresFpuRegister() |
| 6043 | : Location::RequiresRegister()); |
| 6044 | } |
| 6045 | if (use_const_for_true_in) { |
| 6046 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 6047 | } else { |
| 6048 | locations_to_set->SetInAt(1, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6049 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6050 | ? Location::RequiresFpuRegister() |
| 6051 | : Location::RequiresRegister()); |
| 6052 | } |
| 6053 | if (materialized) { |
| 6054 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 6055 | } |
| 6056 | // On R6 we don't require the output to be the same as the |
| 6057 | // first input for conditional moves unlike on R2. |
| 6058 | bool is_out_same_as_first_in = !can_move_conditionally || !is_r6; |
| 6059 | if (is_out_same_as_first_in) { |
| 6060 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 6061 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6062 | locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6063 | ? Location::RequiresFpuRegister() |
| 6064 | : Location::RequiresRegister()); |
| 6065 | } |
| 6066 | } |
| 6067 | |
| 6068 | return can_move_conditionally; |
| 6069 | } |
| 6070 | |
| 6071 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) { |
| 6072 | LocationSummary* locations = select->GetLocations(); |
| 6073 | Location dst = locations->Out(); |
| 6074 | Location src = locations->InAt(1); |
| 6075 | Register src_reg = ZERO; |
| 6076 | Register src_reg_high = ZERO; |
| 6077 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 6078 | Register cond_reg = TMP; |
| 6079 | int cond_cc = 0; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6080 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6081 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6082 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6083 | |
| 6084 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 6085 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 6086 | } else { |
| 6087 | HCondition* condition = cond->AsCondition(); |
| 6088 | LocationSummary* cond_locations = cond->GetLocations(); |
| 6089 | IfCondition if_cond = condition->GetCondition(); |
| 6090 | cond_type = condition->InputAt(0)->GetType(); |
| 6091 | switch (cond_type) { |
| 6092 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6093 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6094 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 6095 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6096 | case DataType::Type::kFloat32: |
| 6097 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6098 | cond_inverted = MaterializeFpCompareR2(if_cond, |
| 6099 | condition->IsGtBias(), |
| 6100 | cond_type, |
| 6101 | cond_locations, |
| 6102 | cond_cc); |
| 6103 | break; |
| 6104 | } |
| 6105 | } |
| 6106 | |
| 6107 | DCHECK(dst.Equals(locations->InAt(0))); |
| 6108 | if (src.IsRegister()) { |
| 6109 | src_reg = src.AsRegister<Register>(); |
| 6110 | } else if (src.IsRegisterPair()) { |
| 6111 | src_reg = src.AsRegisterPairLow<Register>(); |
| 6112 | src_reg_high = src.AsRegisterPairHigh<Register>(); |
| 6113 | } else if (src.IsConstant()) { |
| 6114 | DCHECK(src.GetConstant()->IsZeroBitPattern()); |
| 6115 | } |
| 6116 | |
| 6117 | switch (cond_type) { |
| 6118 | default: |
| 6119 | switch (dst_type) { |
| 6120 | default: |
| 6121 | if (cond_inverted) { |
| 6122 | __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 6123 | } else { |
| 6124 | __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 6125 | } |
| 6126 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6127 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6128 | if (cond_inverted) { |
| 6129 | __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 6130 | __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 6131 | } else { |
| 6132 | __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 6133 | __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 6134 | } |
| 6135 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6136 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6137 | if (cond_inverted) { |
| 6138 | __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6139 | } else { |
| 6140 | __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6141 | } |
| 6142 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6143 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6144 | if (cond_inverted) { |
| 6145 | __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6146 | } else { |
| 6147 | __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6148 | } |
| 6149 | break; |
| 6150 | } |
| 6151 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6152 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6153 | LOG(FATAL) << "Unreachable"; |
| 6154 | UNREACHABLE(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6155 | case DataType::Type::kFloat32: |
| 6156 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6157 | switch (dst_type) { |
| 6158 | default: |
| 6159 | if (cond_inverted) { |
| 6160 | __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 6161 | } else { |
| 6162 | __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 6163 | } |
| 6164 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6165 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6166 | if (cond_inverted) { |
| 6167 | __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 6168 | __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 6169 | } else { |
| 6170 | __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 6171 | __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 6172 | } |
| 6173 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6174 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6175 | if (cond_inverted) { |
| 6176 | __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6177 | } else { |
| 6178 | __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6179 | } |
| 6180 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6181 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6182 | if (cond_inverted) { |
| 6183 | __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6184 | } else { |
| 6185 | __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6186 | } |
| 6187 | break; |
| 6188 | } |
| 6189 | break; |
| 6190 | } |
| 6191 | } |
| 6192 | |
| 6193 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) { |
| 6194 | LocationSummary* locations = select->GetLocations(); |
| 6195 | Location dst = locations->Out(); |
| 6196 | Location false_src = locations->InAt(0); |
| 6197 | Location true_src = locations->InAt(1); |
| 6198 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 6199 | Register cond_reg = TMP; |
| 6200 | FRegister fcond_reg = FTMP; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6201 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6202 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6203 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6204 | |
| 6205 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 6206 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 6207 | } else { |
| 6208 | HCondition* condition = cond->AsCondition(); |
| 6209 | LocationSummary* cond_locations = cond->GetLocations(); |
| 6210 | IfCondition if_cond = condition->GetCondition(); |
| 6211 | cond_type = condition->InputAt(0)->GetType(); |
| 6212 | switch (cond_type) { |
| 6213 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6214 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6215 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 6216 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6217 | case DataType::Type::kFloat32: |
| 6218 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6219 | cond_inverted = MaterializeFpCompareR6(if_cond, |
| 6220 | condition->IsGtBias(), |
| 6221 | cond_type, |
| 6222 | cond_locations, |
| 6223 | fcond_reg); |
| 6224 | break; |
| 6225 | } |
| 6226 | } |
| 6227 | |
| 6228 | if (true_src.IsConstant()) { |
| 6229 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 6230 | } |
| 6231 | if (false_src.IsConstant()) { |
| 6232 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 6233 | } |
| 6234 | |
| 6235 | switch (dst_type) { |
| 6236 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6237 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6238 | __ Mfc1(cond_reg, fcond_reg); |
| 6239 | } |
| 6240 | if (true_src.IsConstant()) { |
| 6241 | if (cond_inverted) { |
| 6242 | __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 6243 | } else { |
| 6244 | __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 6245 | } |
| 6246 | } else if (false_src.IsConstant()) { |
| 6247 | if (cond_inverted) { |
| 6248 | __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 6249 | } else { |
| 6250 | __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 6251 | } |
| 6252 | } else { |
| 6253 | DCHECK_NE(cond_reg, AT); |
| 6254 | if (cond_inverted) { |
| 6255 | __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6256 | __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6257 | } else { |
| 6258 | __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6259 | __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6260 | } |
| 6261 | __ Or(dst.AsRegister<Register>(), AT, TMP); |
| 6262 | } |
| 6263 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6264 | case DataType::Type::kInt64: { |
| 6265 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6266 | __ Mfc1(cond_reg, fcond_reg); |
| 6267 | } |
| 6268 | Register dst_lo = dst.AsRegisterPairLow<Register>(); |
| 6269 | Register dst_hi = dst.AsRegisterPairHigh<Register>(); |
| 6270 | if (true_src.IsConstant()) { |
| 6271 | Register src_lo = false_src.AsRegisterPairLow<Register>(); |
| 6272 | Register src_hi = false_src.AsRegisterPairHigh<Register>(); |
| 6273 | if (cond_inverted) { |
| 6274 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6275 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6276 | } else { |
| 6277 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6278 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6279 | } |
| 6280 | } else { |
| 6281 | DCHECK(false_src.IsConstant()); |
| 6282 | Register src_lo = true_src.AsRegisterPairLow<Register>(); |
| 6283 | Register src_hi = true_src.AsRegisterPairHigh<Register>(); |
| 6284 | if (cond_inverted) { |
| 6285 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6286 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6287 | } else { |
| 6288 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6289 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6290 | } |
| 6291 | } |
| 6292 | break; |
| 6293 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6294 | case DataType::Type::kFloat32: { |
| 6295 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6296 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6297 | __ Sltu(TMP, ZERO, cond_reg); |
| 6298 | __ Mtc1(TMP, fcond_reg); |
| 6299 | } |
| 6300 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6301 | if (true_src.IsConstant()) { |
| 6302 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6303 | if (cond_inverted) { |
| 6304 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6305 | } else { |
| 6306 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6307 | } |
| 6308 | } else if (false_src.IsConstant()) { |
| 6309 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6310 | if (cond_inverted) { |
| 6311 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6312 | } else { |
| 6313 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6314 | } |
| 6315 | } else { |
| 6316 | if (cond_inverted) { |
| 6317 | __ SelS(fcond_reg, |
| 6318 | true_src.AsFpuRegister<FRegister>(), |
| 6319 | false_src.AsFpuRegister<FRegister>()); |
| 6320 | } else { |
| 6321 | __ SelS(fcond_reg, |
| 6322 | false_src.AsFpuRegister<FRegister>(), |
| 6323 | true_src.AsFpuRegister<FRegister>()); |
| 6324 | } |
| 6325 | __ MovS(dst_reg, fcond_reg); |
| 6326 | } |
| 6327 | break; |
| 6328 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6329 | case DataType::Type::kFloat64: { |
| 6330 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6331 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6332 | __ Sltu(TMP, ZERO, cond_reg); |
| 6333 | __ Mtc1(TMP, fcond_reg); |
| 6334 | } |
| 6335 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6336 | if (true_src.IsConstant()) { |
| 6337 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6338 | if (cond_inverted) { |
| 6339 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6340 | } else { |
| 6341 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6342 | } |
| 6343 | } else if (false_src.IsConstant()) { |
| 6344 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6345 | if (cond_inverted) { |
| 6346 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6347 | } else { |
| 6348 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6349 | } |
| 6350 | } else { |
| 6351 | if (cond_inverted) { |
| 6352 | __ SelD(fcond_reg, |
| 6353 | true_src.AsFpuRegister<FRegister>(), |
| 6354 | false_src.AsFpuRegister<FRegister>()); |
| 6355 | } else { |
| 6356 | __ SelD(fcond_reg, |
| 6357 | false_src.AsFpuRegister<FRegister>(), |
| 6358 | true_src.AsFpuRegister<FRegister>()); |
| 6359 | } |
| 6360 | __ MovD(dst_reg, fcond_reg); |
| 6361 | } |
| 6362 | break; |
| 6363 | } |
| 6364 | } |
| 6365 | } |
| 6366 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6367 | void LocationsBuilderMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6368 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6369 | LocationSummary(flag, LocationSummary::kNoCall); |
| 6370 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6371 | } |
| 6372 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6373 | void InstructionCodeGeneratorMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 6374 | __ LoadFromOffset(kLoadWord, |
| 6375 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 6376 | SP, |
| 6377 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6378 | } |
| 6379 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6380 | void LocationsBuilderMIPS::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6381 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6382 | CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6383 | } |
| 6384 | |
| 6385 | void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6386 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 6387 | if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) { |
| 6388 | if (is_r6) { |
| 6389 | GenConditionalMoveR6(select); |
| 6390 | } else { |
| 6391 | GenConditionalMoveR2(select); |
| 6392 | } |
| 6393 | } else { |
| 6394 | LocationSummary* locations = select->GetLocations(); |
| 6395 | MipsLabel false_target; |
| 6396 | GenerateTestAndBranch(select, |
| 6397 | /* condition_input_index */ 2, |
| 6398 | /* true_target */ nullptr, |
| 6399 | &false_target); |
| 6400 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 6401 | __ Bind(&false_target); |
| 6402 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6403 | } |
| 6404 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6405 | void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6406 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6407 | } |
| 6408 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 6409 | void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 6410 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 6411 | } |
| 6412 | |
| 6413 | void CodeGeneratorMIPS::GenerateNop() { |
| 6414 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6415 | } |
| 6416 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6417 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6418 | DataType::Type field_type = field_info.GetFieldType(); |
| 6419 | 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] | 6420 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6421 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6422 | kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6423 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6424 | instruction, |
| 6425 | generate_volatile |
| 6426 | ? LocationSummary::kCallOnMainOnly |
| 6427 | : (object_field_get_with_read_barrier |
| 6428 | ? LocationSummary::kCallOnSlowPath |
| 6429 | : LocationSummary::kNoCall)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6430 | |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6431 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6432 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 6433 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6434 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6435 | if (generate_volatile) { |
| 6436 | InvokeRuntimeCallingConvention calling_convention; |
| 6437 | // need A0 to hold base + offset |
| 6438 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6439 | if (field_type == DataType::Type::kInt64) { |
| 6440 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kInt64)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6441 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6442 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6443 | locations->SetOut(Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6444 | // 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] | 6445 | Location reg = calling_convention.GetReturnLocation(DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6446 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); |
| 6447 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); |
| 6448 | } |
| 6449 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6450 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6451 | locations->SetOut(Location::RequiresFpuRegister()); |
| 6452 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6453 | // The output overlaps in the case of an object field get with |
| 6454 | // read barriers enabled: we do not want the move to overwrite the |
| 6455 | // object's location, as we need it to emit the read barrier. |
| 6456 | locations->SetOut(Location::RequiresRegister(), |
| 6457 | object_field_get_with_read_barrier |
| 6458 | ? Location::kOutputOverlap |
| 6459 | : Location::kNoOutputOverlap); |
| 6460 | } |
| 6461 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6462 | // We need a temporary register for the read barrier marking slow |
| 6463 | // path in CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6464 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6465 | locations->AddTemp(Location::RequiresRegister()); |
| 6466 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6467 | } |
| 6468 | } |
| 6469 | } |
| 6470 | |
| 6471 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, |
| 6472 | const FieldInfo& field_info, |
| 6473 | uint32_t dex_pc) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6474 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 6475 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6476 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6477 | Location obj_loc = locations->InAt(0); |
| 6478 | Register obj = obj_loc.AsRegister<Register>(); |
| 6479 | Location dst_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6480 | LoadOperandType load_type = kLoadUnsignedByte; |
| 6481 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6482 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6483 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6484 | |
| 6485 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6486 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6487 | case DataType::Type::kUint8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6488 | load_type = kLoadUnsignedByte; |
| 6489 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6490 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6491 | load_type = kLoadSignedByte; |
| 6492 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6493 | case DataType::Type::kUint16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6494 | load_type = kLoadUnsignedHalfword; |
| 6495 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6496 | case DataType::Type::kInt16: |
| 6497 | load_type = kLoadSignedHalfword; |
| 6498 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6499 | case DataType::Type::kInt32: |
| 6500 | case DataType::Type::kFloat32: |
| 6501 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6502 | load_type = kLoadWord; |
| 6503 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6504 | case DataType::Type::kInt64: |
| 6505 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6506 | load_type = kLoadDoubleword; |
| 6507 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6508 | case DataType::Type::kUint32: |
| 6509 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6510 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6511 | LOG(FATAL) << "Unreachable type " << type; |
| 6512 | UNREACHABLE(); |
| 6513 | } |
| 6514 | |
| 6515 | if (is_volatile && load_type == kLoadDoubleword) { |
| 6516 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6517 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6518 | // Do implicit Null check |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6519 | __ LoadFromOffset(kLoadWord, |
| 6520 | ZERO, |
| 6521 | locations->GetTemp(0).AsRegister<Register>(), |
| 6522 | 0, |
| 6523 | null_checker); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6524 | codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6525 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6526 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6527 | // FP results are returned in core registers. Need to move them. |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6528 | if (dst_loc.IsFpuRegister()) { |
| 6529 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6530 | __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6531 | dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6532 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6533 | DCHECK(dst_loc.IsDoubleStackSlot()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6534 | __ StoreToOffset(kStoreWord, |
| 6535 | locations->GetTemp(1).AsRegister<Register>(), |
| 6536 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6537 | dst_loc.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6538 | __ StoreToOffset(kStoreWord, |
| 6539 | locations->GetTemp(2).AsRegister<Register>(), |
| 6540 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6541 | dst_loc.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6542 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6543 | } |
| 6544 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6545 | if (type == DataType::Type::kReference) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6546 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 6547 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6548 | Location temp_loc = |
| 6549 | kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6550 | // Note that a potential implicit null check is handled in this |
| 6551 | // CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier call. |
| 6552 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6553 | dst_loc, |
| 6554 | obj, |
| 6555 | offset, |
| 6556 | temp_loc, |
| 6557 | /* needs_null_check */ true); |
| 6558 | if (is_volatile) { |
| 6559 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6560 | } |
| 6561 | } else { |
| 6562 | __ LoadFromOffset(kLoadWord, dst_loc.AsRegister<Register>(), obj, offset, null_checker); |
| 6563 | if (is_volatile) { |
| 6564 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6565 | } |
| 6566 | // If read barriers are enabled, emit read barriers other than |
| 6567 | // Baker's using a slow path (and also unpoison the loaded |
| 6568 | // reference, if heap poisoning is enabled). |
| 6569 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 6570 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6571 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6572 | Register dst; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6573 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6574 | DCHECK(dst_loc.IsRegisterPair()); |
| 6575 | dst = dst_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6576 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6577 | DCHECK(dst_loc.IsRegister()); |
| 6578 | dst = dst_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6579 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6580 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6581 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6582 | DCHECK(dst_loc.IsFpuRegister()); |
| 6583 | FRegister dst = dst_loc.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6584 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6585 | __ LoadSFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6586 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6587 | __ LoadDFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6588 | } |
| 6589 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6590 | } |
| 6591 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6592 | // Memory barriers, in the case of references, are handled in the |
| 6593 | // previous switch statement. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6594 | if (is_volatile && (type != DataType::Type::kReference)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6595 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6596 | } |
| 6597 | } |
| 6598 | |
| 6599 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6600 | DataType::Type field_type = field_info.GetFieldType(); |
| 6601 | 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] | 6602 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6603 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6604 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6605 | |
| 6606 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6607 | if (generate_volatile) { |
| 6608 | InvokeRuntimeCallingConvention calling_convention; |
| 6609 | // need A0 to hold base + offset |
| 6610 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6611 | if (field_type == DataType::Type::kInt64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6612 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 6613 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 6614 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6615 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6616 | locations->SetInAt(1, Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6617 | // Pass FP parameters in core registers. |
| 6618 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 6619 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 6620 | } |
| 6621 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6622 | if (DataType::IsFloatingPointType(field_type)) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6623 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6624 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6625 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6626 | } |
| 6627 | } |
| 6628 | } |
| 6629 | |
| 6630 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, |
| 6631 | const FieldInfo& field_info, |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6632 | uint32_t dex_pc, |
| 6633 | bool value_can_be_null) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6634 | DataType::Type type = field_info.GetFieldType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6635 | LocationSummary* locations = instruction->GetLocations(); |
| 6636 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6637 | Location value_location = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6638 | StoreOperandType store_type = kStoreByte; |
| 6639 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6640 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6641 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6642 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6643 | |
| 6644 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6645 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6646 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6647 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6648 | store_type = kStoreByte; |
| 6649 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6650 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6651 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6652 | store_type = kStoreHalfword; |
| 6653 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6654 | case DataType::Type::kInt32: |
| 6655 | case DataType::Type::kFloat32: |
| 6656 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6657 | store_type = kStoreWord; |
| 6658 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6659 | case DataType::Type::kInt64: |
| 6660 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6661 | store_type = kStoreDoubleword; |
| 6662 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6663 | case DataType::Type::kUint32: |
| 6664 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6665 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6666 | LOG(FATAL) << "Unreachable type " << type; |
| 6667 | UNREACHABLE(); |
| 6668 | } |
| 6669 | |
| 6670 | if (is_volatile) { |
| 6671 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 6672 | } |
| 6673 | |
| 6674 | if (is_volatile && store_type == kStoreDoubleword) { |
| 6675 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6676 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6677 | // Do implicit Null check. |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6678 | __ LoadFromOffset(kLoadWord, |
| 6679 | ZERO, |
| 6680 | locations->GetTemp(0).AsRegister<Register>(), |
| 6681 | 0, |
| 6682 | null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6683 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6684 | // Pass FP parameters in core registers. |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6685 | if (value_location.IsFpuRegister()) { |
| 6686 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), |
| 6687 | value_location.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6688 | __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6689 | value_location.AsFpuRegister<FRegister>()); |
| 6690 | } else if (value_location.IsDoubleStackSlot()) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6691 | __ LoadFromOffset(kLoadWord, |
| 6692 | locations->GetTemp(1).AsRegister<Register>(), |
| 6693 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6694 | value_location.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6695 | __ LoadFromOffset(kLoadWord, |
| 6696 | locations->GetTemp(2).AsRegister<Register>(), |
| 6697 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6698 | value_location.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6699 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6700 | DCHECK(value_location.IsConstant()); |
| 6701 | DCHECK(value_location.GetConstant()->IsDoubleConstant()); |
| 6702 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6703 | __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(), |
| 6704 | locations->GetTemp(1).AsRegister<Register>(), |
| 6705 | value); |
| 6706 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6707 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6708 | codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6709 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); |
| 6710 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6711 | if (value_location.IsConstant()) { |
| 6712 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 6713 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6714 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6715 | Register src; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6716 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6717 | src = value_location.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6718 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6719 | src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6720 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6721 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 6722 | // Note that in the case where `value` is a null reference, |
| 6723 | // we do not enter this block, as a null reference does not |
| 6724 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6725 | DCHECK_EQ(type, DataType::Type::kReference); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6726 | __ PoisonHeapReference(TMP, src); |
| 6727 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 6728 | } else { |
| 6729 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 6730 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6731 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6732 | FRegister src = value_location.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6733 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6734 | __ StoreSToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6735 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6736 | __ StoreDToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6737 | } |
| 6738 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6739 | } |
| 6740 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6741 | if (needs_write_barrier) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6742 | Register src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6743 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6744 | } |
| 6745 | |
| 6746 | if (is_volatile) { |
| 6747 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 6748 | } |
| 6749 | } |
| 6750 | |
| 6751 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6752 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6753 | } |
| 6754 | |
| 6755 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6756 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 6757 | } |
| 6758 | |
| 6759 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6760 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6761 | } |
| 6762 | |
| 6763 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6764 | HandleFieldSet(instruction, |
| 6765 | instruction->GetFieldInfo(), |
| 6766 | instruction->GetDexPc(), |
| 6767 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6768 | } |
| 6769 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6770 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadOneRegister( |
| 6771 | HInstruction* instruction, |
| 6772 | Location out, |
| 6773 | uint32_t offset, |
| 6774 | Location maybe_temp, |
| 6775 | ReadBarrierOption read_barrier_option) { |
| 6776 | Register out_reg = out.AsRegister<Register>(); |
| 6777 | if (read_barrier_option == kWithReadBarrier) { |
| 6778 | CHECK(kEmitCompilerReadBarrier); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6779 | if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) { |
| 6780 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6781 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6782 | if (kUseBakerReadBarrier) { |
| 6783 | // Load with fast path based Baker's read barrier. |
| 6784 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6785 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6786 | out, |
| 6787 | out_reg, |
| 6788 | offset, |
| 6789 | maybe_temp, |
| 6790 | /* needs_null_check */ false); |
| 6791 | } else { |
| 6792 | // Load with slow path based read barrier. |
| 6793 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6794 | // in the following move operation, as we will need it for the |
| 6795 | // read barrier below. |
| 6796 | __ Move(maybe_temp.AsRegister<Register>(), out_reg); |
| 6797 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6798 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6799 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6800 | } |
| 6801 | } else { |
| 6802 | // Plain load with no read barrier. |
| 6803 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6804 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6805 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6806 | } |
| 6807 | } |
| 6808 | |
| 6809 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadTwoRegisters( |
| 6810 | HInstruction* instruction, |
| 6811 | Location out, |
| 6812 | Location obj, |
| 6813 | uint32_t offset, |
| 6814 | Location maybe_temp, |
| 6815 | ReadBarrierOption read_barrier_option) { |
| 6816 | Register out_reg = out.AsRegister<Register>(); |
| 6817 | Register obj_reg = obj.AsRegister<Register>(); |
| 6818 | if (read_barrier_option == kWithReadBarrier) { |
| 6819 | CHECK(kEmitCompilerReadBarrier); |
| 6820 | if (kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6821 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6822 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6823 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6824 | // Load with fast path based Baker's read barrier. |
| 6825 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6826 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6827 | out, |
| 6828 | obj_reg, |
| 6829 | offset, |
| 6830 | maybe_temp, |
| 6831 | /* needs_null_check */ false); |
| 6832 | } else { |
| 6833 | // Load with slow path based read barrier. |
| 6834 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6835 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6836 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6837 | } |
| 6838 | } else { |
| 6839 | // Plain load with no read barrier. |
| 6840 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6841 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6842 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6843 | } |
| 6844 | } |
| 6845 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6846 | static inline int GetBakerMarkThunkNumber(Register reg) { |
| 6847 | static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 21, "Expecting equal"); |
| 6848 | if (reg >= V0 && reg <= T7) { // 14 consequtive regs. |
| 6849 | return reg - V0; |
| 6850 | } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs. |
| 6851 | return 14 + (reg - S2); |
| 6852 | } else if (reg == FP) { // One more. |
| 6853 | return 20; |
| 6854 | } |
| 6855 | LOG(FATAL) << "Unexpected register " << reg; |
| 6856 | UNREACHABLE(); |
| 6857 | } |
| 6858 | |
| 6859 | static inline int GetBakerMarkFieldArrayThunkDisplacement(Register reg, bool short_offset) { |
| 6860 | int num = GetBakerMarkThunkNumber(reg) + |
| 6861 | (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0); |
| 6862 | return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE; |
| 6863 | } |
| 6864 | |
| 6865 | static inline int GetBakerMarkGcRootThunkDisplacement(Register reg) { |
| 6866 | return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE + |
| 6867 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET; |
| 6868 | } |
| 6869 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6870 | void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6871 | Location root, |
| 6872 | Register obj, |
| 6873 | uint32_t offset, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6874 | ReadBarrierOption read_barrier_option, |
| 6875 | MipsLabel* label_low) { |
| 6876 | bool reordering; |
| 6877 | if (label_low != nullptr) { |
| 6878 | DCHECK_EQ(offset, 0x5678u); |
| 6879 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6880 | Register root_reg = root.AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6881 | if (read_barrier_option == kWithReadBarrier) { |
| 6882 | DCHECK(kEmitCompilerReadBarrier); |
| 6883 | if (kUseBakerReadBarrier) { |
| 6884 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6885 | // Baker's read barrier are used: |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6886 | if (kBakerReadBarrierThunksEnableForGcRoots) { |
| 6887 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6888 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 6889 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 6890 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 6891 | // vice versa. |
| 6892 | // |
| 6893 | // We use thunks for the slow path. That thunk checks the reference |
| 6894 | // and jumps to the entrypoint if needed. |
| 6895 | // |
| 6896 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 6897 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 6898 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6899 | // if (temp != nullptr) { |
| 6900 | // temp = &gc_root_thunk<root_reg> |
| 6901 | // root = temp(root) |
| 6902 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6903 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6904 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 6905 | const int32_t entry_point_offset = |
| 6906 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 6907 | const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg); |
| 6908 | int16_t offset_low = Low16Bits(offset); |
| 6909 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign |
| 6910 | // extension in lw. |
| 6911 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 6912 | Register base = short_offset ? obj : TMP; |
| 6913 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6914 | // threads are suspended or running a checkpoint. |
| 6915 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 6916 | reordering = __ SetReorder(false); |
| 6917 | if (!short_offset) { |
| 6918 | DCHECK(!label_low); |
| 6919 | __ AddUpper(base, obj, offset_high); |
| 6920 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6921 | MipsLabel skip_call; |
| 6922 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6923 | if (label_low != nullptr) { |
| 6924 | DCHECK(short_offset); |
| 6925 | __ Bind(label_low); |
| 6926 | } |
| 6927 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6928 | __ LoadFromOffset(kLoadWord, root_reg, base, offset_low); // Single instruction |
| 6929 | // in delay slot. |
| 6930 | if (isR6) { |
| 6931 | __ Jialc(T9, thunk_disp); |
| 6932 | } else { |
| 6933 | __ Addiu(T9, T9, thunk_disp); |
| 6934 | __ Jalr(T9); |
| 6935 | __ Nop(); |
| 6936 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6937 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6938 | __ SetReorder(reordering); |
| 6939 | } else { |
| 6940 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6941 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 6942 | // load into `temp` (T9) the read barrier mark entry point corresponding |
| 6943 | // to register `root`. If `temp` is null, it means that `GetIsGcMarking()` |
| 6944 | // is false, and vice versa. |
| 6945 | // |
| 6946 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6947 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6948 | // if (temp != null) { |
| 6949 | // root = temp(root) |
| 6950 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6951 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6952 | if (label_low != nullptr) { |
| 6953 | reordering = __ SetReorder(false); |
| 6954 | __ Bind(label_low); |
| 6955 | } |
| 6956 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6957 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6958 | if (label_low != nullptr) { |
| 6959 | __ SetReorder(reordering); |
| 6960 | } |
| 6961 | static_assert( |
| 6962 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6963 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6964 | "have different sizes."); |
| 6965 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6966 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6967 | "have different sizes."); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6968 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6969 | // Slow path marking the GC root `root`. |
| 6970 | Location temp = Location::RegisterLocation(T9); |
| 6971 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6972 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS( |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6973 | instruction, |
| 6974 | root, |
| 6975 | /*entrypoint*/ temp); |
| 6976 | codegen_->AddSlowPath(slow_path); |
| 6977 | |
| 6978 | const int32_t entry_point_offset = |
| 6979 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(root.reg() - 1); |
| 6980 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6981 | // threads are suspended or running a checkpoint. |
| 6982 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 6983 | __ Bnez(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 6984 | __ Bind(slow_path->GetExitLabel()); |
| 6985 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6986 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6987 | if (label_low != nullptr) { |
| 6988 | reordering = __ SetReorder(false); |
| 6989 | __ Bind(label_low); |
| 6990 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6991 | // GC root loaded through a slow path for read barriers other |
| 6992 | // than Baker's. |
| 6993 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6994 | __ Addiu32(root_reg, obj, offset); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6995 | if (label_low != nullptr) { |
| 6996 | __ SetReorder(reordering); |
| 6997 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6998 | // /* mirror::Object* */ root = root->Read() |
| 6999 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7000 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7001 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7002 | if (label_low != nullptr) { |
| 7003 | reordering = __ SetReorder(false); |
| 7004 | __ Bind(label_low); |
| 7005 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7006 | // Plain GC root load with no read barrier. |
| 7007 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7008 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7009 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7010 | // do not have to unpoison `root_reg` here. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7011 | if (label_low != nullptr) { |
| 7012 | __ SetReorder(reordering); |
| 7013 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7014 | } |
| 7015 | } |
| 7016 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7017 | void CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7018 | Location ref, |
| 7019 | Register obj, |
| 7020 | uint32_t offset, |
| 7021 | Location temp, |
| 7022 | bool needs_null_check) { |
| 7023 | DCHECK(kEmitCompilerReadBarrier); |
| 7024 | DCHECK(kUseBakerReadBarrier); |
| 7025 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7026 | if (kBakerReadBarrierThunksEnableForFields) { |
| 7027 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 7028 | // to decide whether to mark the loaded reference or not. Instead, we |
| 7029 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 7030 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 7031 | // vice versa. |
| 7032 | // |
| 7033 | // We use thunks for the slow path. That thunk checks the reference |
| 7034 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 7035 | // it issues a load-load memory barrier and returns to the original |
| 7036 | // reference load. |
| 7037 | // |
| 7038 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 7039 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 7040 | // if (temp != nullptr) { |
| 7041 | // temp = &field_array_thunk<holder_reg> |
| 7042 | // temp() |
| 7043 | // } |
| 7044 | // not_gray_return_address: |
| 7045 | // // If the offset is too large to fit into the lw instruction, we |
| 7046 | // // use an adjusted base register (TMP) here. This register |
| 7047 | // // receives bits 16 ... 31 of the offset before the thunk invocation |
| 7048 | // // and the thunk benefits from it. |
| 7049 | // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load. |
| 7050 | // gray_return_address: |
| 7051 | |
| 7052 | DCHECK(temp.IsInvalid()); |
| 7053 | bool isR6 = GetInstructionSetFeatures().IsR6(); |
| 7054 | int16_t offset_low = Low16Bits(offset); |
| 7055 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lw. |
| 7056 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 7057 | bool reordering = __ SetReorder(false); |
| 7058 | const int32_t entry_point_offset = |
| 7059 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 7060 | // There may have or may have not been a null check if the field offset is smaller than |
| 7061 | // the page size. |
| 7062 | // There must've been a null check in case it's actually a load from an array. |
| 7063 | // We will, however, perform an explicit null check in the thunk as it's easier to |
| 7064 | // do it than not. |
| 7065 | if (instruction->IsArrayGet()) { |
| 7066 | DCHECK(!needs_null_check); |
| 7067 | } |
| 7068 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset); |
| 7069 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7070 | // threads are suspended or running a checkpoint. |
| 7071 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 7072 | Register ref_reg = ref.AsRegister<Register>(); |
| 7073 | Register base = short_offset ? obj : TMP; |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7074 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7075 | if (short_offset) { |
| 7076 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7077 | __ Beqzc(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7078 | __ Nop(); // In forbidden slot. |
| 7079 | __ Jialc(T9, thunk_disp); |
| 7080 | } else { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7081 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7082 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 7083 | __ Jalr(T9); |
| 7084 | __ Nop(); // In delay slot. |
| 7085 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7086 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7087 | } else { |
| 7088 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7089 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7090 | __ Aui(base, obj, offset_high); // In delay slot. |
| 7091 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7092 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7093 | } else { |
| 7094 | __ Lui(base, offset_high); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7095 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7096 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 7097 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7098 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7099 | __ Addu(base, base, obj); // In delay slot. |
| 7100 | } |
| 7101 | } |
| 7102 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7103 | __ LoadFromOffset(kLoadWord, ref_reg, base, offset_low); // Single instruction. |
| 7104 | if (needs_null_check) { |
| 7105 | MaybeRecordImplicitNullCheck(instruction); |
| 7106 | } |
| 7107 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7108 | __ SetReorder(reordering); |
| 7109 | return; |
| 7110 | } |
| 7111 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7112 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7113 | Location no_index = Location::NoLocation(); |
| 7114 | ScaleFactor no_scale_factor = TIMES_1; |
| 7115 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 7116 | ref, |
| 7117 | obj, |
| 7118 | offset, |
| 7119 | no_index, |
| 7120 | no_scale_factor, |
| 7121 | temp, |
| 7122 | needs_null_check); |
| 7123 | } |
| 7124 | |
| 7125 | void CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7126 | Location ref, |
| 7127 | Register obj, |
| 7128 | uint32_t data_offset, |
| 7129 | Location index, |
| 7130 | Location temp, |
| 7131 | bool needs_null_check) { |
| 7132 | DCHECK(kEmitCompilerReadBarrier); |
| 7133 | DCHECK(kUseBakerReadBarrier); |
| 7134 | |
| 7135 | static_assert( |
| 7136 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7137 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7138 | ScaleFactor scale_factor = TIMES_4; |
| 7139 | |
| 7140 | if (kBakerReadBarrierThunksEnableForArrays) { |
| 7141 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 7142 | // to decide whether to mark the loaded reference or not. Instead, we |
| 7143 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 7144 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 7145 | // vice versa. |
| 7146 | // |
| 7147 | // We use thunks for the slow path. That thunk checks the reference |
| 7148 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 7149 | // it issues a load-load memory barrier and returns to the original |
| 7150 | // reference load. |
| 7151 | // |
| 7152 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 7153 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 7154 | // if (temp != nullptr) { |
| 7155 | // temp = &field_array_thunk<holder_reg> |
| 7156 | // temp() |
| 7157 | // } |
| 7158 | // not_gray_return_address: |
| 7159 | // // The element address is pre-calculated in the TMP register before the |
| 7160 | // // thunk invocation and the thunk benefits from it. |
| 7161 | // HeapReference<mirror::Object> reference = data[index]; // Original reference load. |
| 7162 | // gray_return_address: |
| 7163 | |
| 7164 | DCHECK(temp.IsInvalid()); |
| 7165 | DCHECK(index.IsValid()); |
| 7166 | bool reordering = __ SetReorder(false); |
| 7167 | const int32_t entry_point_offset = |
| 7168 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 7169 | // We will not do the explicit null check in the thunk as some form of a null check |
| 7170 | // must've been done earlier. |
| 7171 | DCHECK(!needs_null_check); |
| 7172 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false); |
| 7173 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7174 | // threads are suspended or running a checkpoint. |
| 7175 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 7176 | Register ref_reg = ref.AsRegister<Register>(); |
| 7177 | Register index_reg = index.IsRegisterPair() |
| 7178 | ? index.AsRegisterPairLow<Register>() |
| 7179 | : index.AsRegister<Register>(); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7180 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7181 | if (GetInstructionSetFeatures().IsR6()) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7182 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7183 | __ Lsa(TMP, index_reg, obj, scale_factor); // In delay slot. |
| 7184 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7185 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7186 | } else { |
| 7187 | __ Sll(TMP, index_reg, scale_factor); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7188 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7189 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 7190 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7191 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7192 | __ Addu(TMP, TMP, obj); // In delay slot. |
| 7193 | } |
| 7194 | // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor)) |
| 7195 | DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset; |
| 7196 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, data_offset); // Single instruction. |
| 7197 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7198 | __ SetReorder(reordering); |
| 7199 | return; |
| 7200 | } |
| 7201 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7202 | // /* HeapReference<Object> */ ref = |
| 7203 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7204 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 7205 | ref, |
| 7206 | obj, |
| 7207 | data_offset, |
| 7208 | index, |
| 7209 | scale_factor, |
| 7210 | temp, |
| 7211 | needs_null_check); |
| 7212 | } |
| 7213 | |
| 7214 | void CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7215 | Location ref, |
| 7216 | Register obj, |
| 7217 | uint32_t offset, |
| 7218 | Location index, |
| 7219 | ScaleFactor scale_factor, |
| 7220 | Location temp, |
| 7221 | bool needs_null_check, |
| 7222 | bool always_update_field) { |
| 7223 | DCHECK(kEmitCompilerReadBarrier); |
| 7224 | DCHECK(kUseBakerReadBarrier); |
| 7225 | |
| 7226 | // In slow path based read barriers, the read barrier call is |
| 7227 | // inserted after the original load. However, in fast path based |
| 7228 | // Baker's read barriers, we need to perform the load of |
| 7229 | // mirror::Object::monitor_ *before* the original reference load. |
| 7230 | // This load-load ordering is required by the read barrier. |
| 7231 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7232 | // |
| 7233 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7234 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7235 | // HeapReference<Object> ref = *src; // Original reference load. |
| 7236 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 7237 | // if (is_gray) { |
| 7238 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7239 | // } |
| 7240 | // |
| 7241 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7242 | // slightly more complex as it performs additional checks that we do |
| 7243 | // not do here for performance reasons. |
| 7244 | |
| 7245 | Register ref_reg = ref.AsRegister<Register>(); |
| 7246 | Register temp_reg = temp.AsRegister<Register>(); |
| 7247 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7248 | |
| 7249 | // /* int32_t */ monitor = obj->monitor_ |
| 7250 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 7251 | if (needs_null_check) { |
| 7252 | MaybeRecordImplicitNullCheck(instruction); |
| 7253 | } |
| 7254 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7255 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7256 | "art::LockWord and int32_t have different sizes."); |
| 7257 | |
| 7258 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 7259 | |
| 7260 | // The actual reference load. |
| 7261 | if (index.IsValid()) { |
| 7262 | // Load types involving an "index": ArrayGet, |
| 7263 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7264 | // intrinsics. |
| 7265 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 7266 | if (index.IsConstant()) { |
| 7267 | size_t computed_offset = |
| 7268 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 7269 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7270 | } else { |
| 7271 | // Handle the special case of the |
| 7272 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7273 | // intrinsics, which use a register pair as index ("long |
| 7274 | // offset"), of which only the low part contains data. |
| 7275 | Register index_reg = index.IsRegisterPair() |
| 7276 | ? index.AsRegisterPairLow<Register>() |
| 7277 | : index.AsRegister<Register>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 7278 | __ ShiftAndAdd(TMP, index_reg, obj, scale_factor, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7279 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, offset); |
| 7280 | } |
| 7281 | } else { |
| 7282 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7283 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7284 | } |
| 7285 | |
| 7286 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7287 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7288 | |
| 7289 | // Slow path marking the object `ref` when it is gray. |
| 7290 | SlowPathCodeMIPS* slow_path; |
| 7291 | if (always_update_field) { |
| 7292 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS only supports address |
| 7293 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7294 | // `field_offset` is a register pair (of which only the lower half |
| 7295 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7296 | // to be null in this code path. |
| 7297 | DCHECK_EQ(offset, 0u); |
| 7298 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7299 | slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7300 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(instruction, |
| 7301 | ref, |
| 7302 | obj, |
| 7303 | /* field_offset */ index, |
| 7304 | temp_reg); |
| 7305 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7306 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS(instruction, ref); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7307 | } |
| 7308 | AddSlowPath(slow_path); |
| 7309 | |
| 7310 | // if (rb_state == ReadBarrier::GrayState()) |
| 7311 | // ref = ReadBarrier::Mark(ref); |
| 7312 | // Given the numeric representation, it's enough to check the low bit of the |
| 7313 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 7314 | // performing a branch on less than zero. |
| 7315 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7316 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 7317 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 7318 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 7319 | __ Bltz(temp_reg, slow_path->GetEntryLabel()); |
| 7320 | __ Bind(slow_path->GetExitLabel()); |
| 7321 | } |
| 7322 | |
| 7323 | void CodeGeneratorMIPS::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7324 | Location out, |
| 7325 | Location ref, |
| 7326 | Location obj, |
| 7327 | uint32_t offset, |
| 7328 | Location index) { |
| 7329 | DCHECK(kEmitCompilerReadBarrier); |
| 7330 | |
| 7331 | // Insert a slow path based read barrier *after* the reference load. |
| 7332 | // |
| 7333 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7334 | // reference will be carried out by the runtime within the slow |
| 7335 | // path. |
| 7336 | // |
| 7337 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7338 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7339 | // not used by the artReadBarrierSlow entry point. |
| 7340 | // |
| 7341 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7342 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7343 | ReadBarrierForHeapReferenceSlowPathMIPS(instruction, out, ref, obj, offset, index); |
| 7344 | AddSlowPath(slow_path); |
| 7345 | |
| 7346 | __ B(slow_path->GetEntryLabel()); |
| 7347 | __ Bind(slow_path->GetExitLabel()); |
| 7348 | } |
| 7349 | |
| 7350 | void CodeGeneratorMIPS::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7351 | Location out, |
| 7352 | Location ref, |
| 7353 | Location obj, |
| 7354 | uint32_t offset, |
| 7355 | Location index) { |
| 7356 | if (kEmitCompilerReadBarrier) { |
| 7357 | // Baker's read barriers shall be handled by the fast path |
| 7358 | // (CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier). |
| 7359 | DCHECK(!kUseBakerReadBarrier); |
| 7360 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7361 | // by the runtime within the slow path. |
| 7362 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 7363 | } else if (kPoisonHeapReferences) { |
| 7364 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7365 | } |
| 7366 | } |
| 7367 | |
| 7368 | void CodeGeneratorMIPS::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7369 | Location out, |
| 7370 | Location root) { |
| 7371 | DCHECK(kEmitCompilerReadBarrier); |
| 7372 | |
| 7373 | // Insert a slow path based read barrier *after* the GC root load. |
| 7374 | // |
| 7375 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7376 | // not need to do anything special for this here. |
| 7377 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7378 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS(instruction, out, root); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7379 | AddSlowPath(slow_path); |
| 7380 | |
| 7381 | __ B(slow_path->GetEntryLabel()); |
| 7382 | __ Bind(slow_path->GetExitLabel()); |
| 7383 | } |
| 7384 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7385 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7386 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7387 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7388 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7389 | switch (type_check_kind) { |
| 7390 | case TypeCheckKind::kExactCheck: |
| 7391 | case TypeCheckKind::kAbstractClassCheck: |
| 7392 | case TypeCheckKind::kClassHierarchyCheck: |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7393 | case TypeCheckKind::kArrayObjectCheck: { |
| 7394 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7395 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7396 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7397 | break; |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7398 | } |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7399 | case TypeCheckKind::kArrayCheck: |
| 7400 | case TypeCheckKind::kUnresolvedCheck: |
| 7401 | case TypeCheckKind::kInterfaceCheck: |
| 7402 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7403 | break; |
| 7404 | } |
| 7405 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7406 | LocationSummary* locations = |
| 7407 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7408 | if (baker_read_barrier_slow_path) { |
| 7409 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7410 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7411 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 7412 | locations->SetInAt(1, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7413 | // The output does overlap inputs. |
| 7414 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 7415 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7416 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7417 | } |
| 7418 | |
| 7419 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7420 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7421 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7422 | Location obj_loc = locations->InAt(0); |
| 7423 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 7424 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7425 | Location out_loc = locations->Out(); |
| 7426 | Register out = out_loc.AsRegister<Register>(); |
| 7427 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7428 | DCHECK_LE(num_temps, 1u); |
| 7429 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7430 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7431 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7432 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7433 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7434 | MipsLabel done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7435 | SlowPathCodeMIPS* slow_path = nullptr; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7436 | |
| 7437 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7438 | // Avoid this check if we know `obj` is not null. |
| 7439 | if (instruction->MustDoNullCheck()) { |
| 7440 | __ Move(out, ZERO); |
| 7441 | __ Beqz(obj, &done); |
| 7442 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7443 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7444 | switch (type_check_kind) { |
| 7445 | case TypeCheckKind::kExactCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7446 | ReadBarrierOption read_barrier_option = |
| 7447 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7448 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7449 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7450 | out_loc, |
| 7451 | obj_loc, |
| 7452 | class_offset, |
| 7453 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7454 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7455 | // Classes must be equal for the instanceof to succeed. |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 7456 | __ Xor(out, out, cls); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7457 | __ Sltiu(out, out, 1); |
| 7458 | break; |
| 7459 | } |
| 7460 | |
| 7461 | case TypeCheckKind::kAbstractClassCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7462 | ReadBarrierOption read_barrier_option = |
| 7463 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7464 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7465 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7466 | out_loc, |
| 7467 | obj_loc, |
| 7468 | class_offset, |
| 7469 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7470 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7471 | // If the class is abstract, we eagerly fetch the super class of the |
| 7472 | // object to avoid doing a comparison we know will fail. |
| 7473 | MipsLabel loop; |
| 7474 | __ Bind(&loop); |
| 7475 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7476 | GenerateReferenceLoadOneRegister(instruction, |
| 7477 | out_loc, |
| 7478 | super_offset, |
| 7479 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7480 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7481 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7482 | __ Beqz(out, &done); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 7483 | __ Bne(out, cls, &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7484 | __ LoadConst32(out, 1); |
| 7485 | break; |
| 7486 | } |
| 7487 | |
| 7488 | case TypeCheckKind::kClassHierarchyCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7489 | ReadBarrierOption read_barrier_option = |
| 7490 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7491 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7492 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7493 | out_loc, |
| 7494 | obj_loc, |
| 7495 | class_offset, |
| 7496 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7497 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7498 | // Walk over the class hierarchy to find a match. |
| 7499 | MipsLabel loop, success; |
| 7500 | __ Bind(&loop); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 7501 | __ Beq(out, cls, &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7502 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7503 | GenerateReferenceLoadOneRegister(instruction, |
| 7504 | out_loc, |
| 7505 | super_offset, |
| 7506 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7507 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7508 | __ Bnez(out, &loop); |
| 7509 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7510 | __ B(&done); |
| 7511 | __ Bind(&success); |
| 7512 | __ LoadConst32(out, 1); |
| 7513 | break; |
| 7514 | } |
| 7515 | |
| 7516 | case TypeCheckKind::kArrayObjectCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7517 | ReadBarrierOption read_barrier_option = |
| 7518 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7519 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7520 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7521 | out_loc, |
| 7522 | obj_loc, |
| 7523 | class_offset, |
| 7524 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7525 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7526 | // Do an exact check. |
| 7527 | MipsLabel success; |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 7528 | __ Beq(out, cls, &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7529 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7530 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7531 | GenerateReferenceLoadOneRegister(instruction, |
| 7532 | out_loc, |
| 7533 | component_offset, |
| 7534 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7535 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7536 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7537 | __ Beqz(out, &done); |
| 7538 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7539 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 7540 | __ Sltiu(out, out, 1); |
| 7541 | __ B(&done); |
| 7542 | __ Bind(&success); |
| 7543 | __ LoadConst32(out, 1); |
| 7544 | break; |
| 7545 | } |
| 7546 | |
| 7547 | case TypeCheckKind::kArrayCheck: { |
| 7548 | // No read barrier since the slow path will retry upon failure. |
| 7549 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7550 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7551 | out_loc, |
| 7552 | obj_loc, |
| 7553 | class_offset, |
| 7554 | maybe_temp_loc, |
| 7555 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7556 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7557 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7558 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7559 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 7560 | __ Bne(out, cls, slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7561 | __ LoadConst32(out, 1); |
| 7562 | break; |
| 7563 | } |
| 7564 | |
| 7565 | case TypeCheckKind::kUnresolvedCheck: |
| 7566 | case TypeCheckKind::kInterfaceCheck: { |
| 7567 | // Note that we indeed only call on slow path, but we always go |
| 7568 | // into the slow path for the unresolved and interface check |
| 7569 | // cases. |
| 7570 | // |
| 7571 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7572 | // entry point without resorting to a type checking slow path |
| 7573 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7574 | // require to assign fixed registers for the inputs of this |
| 7575 | // HInstanceOf instruction (following the runtime calling |
| 7576 | // convention), which might be cluttered by the potential first |
| 7577 | // read barrier emission at the beginning of this method. |
| 7578 | // |
| 7579 | // TODO: Introduce a new runtime entry point taking the object |
| 7580 | // to test (instead of its class) as argument, and let it deal |
| 7581 | // with the read barrier issues. This will let us refactor this |
| 7582 | // case of the `switch` code as it was previously (with a direct |
| 7583 | // call to the runtime not using a type checking slow path). |
| 7584 | // This should also be beneficial for the other cases above. |
| 7585 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7586 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7587 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7588 | codegen_->AddSlowPath(slow_path); |
| 7589 | __ B(slow_path->GetEntryLabel()); |
| 7590 | break; |
| 7591 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7592 | } |
| 7593 | |
| 7594 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7595 | |
| 7596 | if (slow_path != nullptr) { |
| 7597 | __ Bind(slow_path->GetExitLabel()); |
| 7598 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7599 | } |
| 7600 | |
| 7601 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7602 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7603 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7604 | } |
| 7605 | |
| 7606 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 7607 | // Will be generated at use site. |
| 7608 | } |
| 7609 | |
| 7610 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7611 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7612 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7613 | } |
| 7614 | |
| 7615 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 7616 | // Will be generated at use site. |
| 7617 | } |
| 7618 | |
| 7619 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { |
| 7620 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 7621 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 7622 | } |
| 7623 | |
| 7624 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7625 | HandleInvoke(invoke); |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7626 | // 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] | 7627 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7628 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T7)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7629 | } |
| 7630 | |
| 7631 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7632 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 7633 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7634 | Location receiver = invoke->GetLocations()->InAt(0); |
| 7635 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7636 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7637 | |
| 7638 | // Set the hidden argument. |
| 7639 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 7640 | invoke->GetDexMethodIndex()); |
| 7641 | |
| 7642 | // temp = object->GetClass(); |
| 7643 | if (receiver.IsStackSlot()) { |
| 7644 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 7645 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 7646 | } else { |
| 7647 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 7648 | } |
| 7649 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7650 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7651 | // emit a read barrier for the previous class reference load. |
| 7652 | // However this is not required in practice, as this is an |
| 7653 | // intermediate/temporary reference and because the current |
| 7654 | // concurrent copying collector keeps the from-space memory |
| 7655 | // intact/accessible until the end of the marking phase (the |
| 7656 | // concurrent copying collector may not in the future). |
| 7657 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 7658 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 7659 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
| 7660 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7661 | invoke->GetImtIndex(), kMipsPointerSize)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7662 | // temp = temp->GetImtEntryAt(method_offset); |
| 7663 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7664 | // T9 = temp->GetEntryPoint(); |
| 7665 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 7666 | // T9(); |
| 7667 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7668 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7669 | DCHECK(!codegen_->IsLeafMethod()); |
| 7670 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 7671 | } |
| 7672 | |
| 7673 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7674 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7675 | if (intrinsic.TryDispatch(invoke)) { |
| 7676 | return; |
| 7677 | } |
| 7678 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7679 | HandleInvoke(invoke); |
| 7680 | } |
| 7681 | |
| 7682 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 7683 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 7684 | // art::PrepareForRegisterAllocation. |
| 7685 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7686 | |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7687 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7688 | bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
| 7689 | bool has_extra_input = invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7690 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7691 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7692 | if (intrinsic.TryDispatch(invoke)) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7693 | if (invoke->GetLocations()->CanCall() && has_extra_input) { |
| 7694 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 7695 | } |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7696 | return; |
| 7697 | } |
| 7698 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7699 | HandleInvoke(invoke); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7700 | |
| 7701 | // Add the extra input register if either the dex cache array base register |
| 7702 | // or the PC-relative base register for accessing literals is needed. |
| 7703 | if (has_extra_input) { |
| 7704 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 7705 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7706 | } |
| 7707 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 7708 | void LocationsBuilderMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7709 | HandleInvoke(invoke); |
| 7710 | } |
| 7711 | |
| 7712 | void InstructionCodeGeneratorMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7713 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 7714 | } |
| 7715 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7716 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7717 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7718 | IntrinsicCodeGeneratorMIPS intrinsic(codegen); |
| 7719 | intrinsic.Dispatch(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7720 | return true; |
| 7721 | } |
| 7722 | return false; |
| 7723 | } |
| 7724 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7725 | HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7726 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7727 | switch (desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7728 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7729 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7730 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7731 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7732 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7733 | case HLoadString::LoadKind::kJitTableAddress: |
| 7734 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7735 | break; |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7736 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7737 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7738 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7739 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7740 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7741 | } |
| 7742 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7743 | HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind( |
| 7744 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7745 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7746 | case HLoadClass::LoadKind::kInvalid: |
| 7747 | LOG(FATAL) << "UNREACHABLE"; |
| 7748 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7749 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7750 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7751 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7752 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7753 | case HLoadClass::LoadKind::kBssEntry: |
| 7754 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7755 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7756 | case HLoadClass::LoadKind::kJitTableAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7757 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7758 | break; |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7759 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7760 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7761 | break; |
| 7762 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7763 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7764 | } |
| 7765 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7766 | Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7767 | Register temp) { |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7768 | CHECK(!GetInstructionSetFeatures().IsR6()); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7769 | CHECK(!GetGraph()->HasIrreducibleLoops()); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7770 | CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7771 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7772 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7773 | return location.AsRegister<Register>(); |
| 7774 | } |
| 7775 | // For intrinsics we allow any location, so it may be on the stack. |
| 7776 | if (!location.IsRegister()) { |
| 7777 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7778 | return temp; |
| 7779 | } |
| 7780 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7781 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7782 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7783 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7784 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 7785 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 7786 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 7787 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7788 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7789 | return temp; |
| 7790 | } |
| 7791 | return location.AsRegister<Register>(); |
| 7792 | } |
| 7793 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7794 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( |
| 7795 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 7796 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7797 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7798 | } |
| 7799 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7800 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall( |
| 7801 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7802 | // 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] | 7803 | 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] | 7804 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 7805 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7806 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7807 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 7808 | Register base_reg = (invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7809 | ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>()) |
| 7810 | : ZERO; |
| 7811 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7812 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7813 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7814 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7815 | uint32_t offset = |
| 7816 | GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7817 | __ LoadFromOffset(kLoadWord, |
| 7818 | temp.AsRegister<Register>(), |
| 7819 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7820 | offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7821 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7822 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7823 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7824 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7825 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7826 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 7827 | DCHECK(GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7828 | PcRelativePatchInfo* info_high = NewBootImageMethodPatch(invoke->GetTargetMethod()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7829 | PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7830 | NewBootImageMethodPatch(invoke->GetTargetMethod(), info_high); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7831 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7832 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 7833 | __ Addiu(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7834 | break; |
| 7835 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7836 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7837 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 7838 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7839 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7840 | PcRelativePatchInfo* info_high = NewMethodBssEntryPatch( |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7841 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7842 | PcRelativePatchInfo* info_low = NewMethodBssEntryPatch( |
| 7843 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7844 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7845 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 7846 | __ Lw(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7847 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7848 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7849 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 7850 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 7851 | return; // No code pointer retrieval; the runtime performs the call directly. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7852 | } |
| 7853 | } |
| 7854 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7855 | switch (code_ptr_location) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7856 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7857 | __ Bal(&frame_entry_label_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7858 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7859 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7860 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 7861 | __ LoadFromOffset(kLoadWord, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7862 | T9, |
| 7863 | callee_method.AsRegister<Register>(), |
| 7864 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7865 | kMipsPointerSize).Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7866 | // T9() |
| 7867 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7868 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7869 | break; |
| 7870 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7871 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 7872 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7873 | DCHECK(!IsLeafMethod()); |
| 7874 | } |
| 7875 | |
| 7876 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 7877 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 7878 | // art::PrepareForRegisterAllocation. |
| 7879 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7880 | |
| 7881 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 7882 | return; |
| 7883 | } |
| 7884 | |
| 7885 | LocationSummary* locations = invoke->GetLocations(); |
| 7886 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 7887 | locations->HasTemps() |
| 7888 | ? locations->GetTemp(0) |
| 7889 | : Location::NoLocation()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7890 | } |
| 7891 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7892 | void CodeGeneratorMIPS::GenerateVirtualCall( |
| 7893 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 7894 | // Use the calling convention instead of the location of the receiver, as |
| 7895 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7896 | // slow path, the arguments have been moved to the right place, so here we are |
| 7897 | // guaranteed that the receiver is the first register of the calling convention. |
| 7898 | InvokeDexCallingConvention calling_convention; |
| 7899 | Register receiver = calling_convention.GetRegisterAt(0); |
| 7900 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7901 | Register temp = temp_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7902 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7903 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); |
| 7904 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7905 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7906 | |
| 7907 | // temp = object->GetClass(); |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 7908 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7909 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7910 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7911 | // emit a read barrier for the previous class reference load. |
| 7912 | // However this is not required in practice, as this is an |
| 7913 | // intermediate/temporary reference and because the current |
| 7914 | // concurrent copying collector keeps the from-space memory |
| 7915 | // intact/accessible until the end of the marking phase (the |
| 7916 | // concurrent copying collector may not in the future). |
| 7917 | __ MaybeUnpoisonHeapReference(temp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7918 | // temp = temp->GetMethodAt(method_offset); |
| 7919 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7920 | // T9 = temp->GetEntryPoint(); |
| 7921 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 7922 | // T9(); |
| 7923 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7924 | __ NopIfNoReordering(); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7925 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7926 | } |
| 7927 | |
| 7928 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 7929 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 7930 | return; |
| 7931 | } |
| 7932 | |
| 7933 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7934 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7935 | } |
| 7936 | |
| 7937 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7938 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7939 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7940 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7941 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 7942 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7943 | return; |
| 7944 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7945 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7946 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7947 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7948 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7949 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7950 | ? LocationSummary::kCallOnSlowPath |
| 7951 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7952 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7953 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 7954 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7955 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7956 | switch (load_kind) { |
| 7957 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7958 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7959 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7960 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7961 | case HLoadClass::LoadKind::kBssEntry: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7962 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7963 | break; |
| 7964 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7965 | if (has_irreducible_loops) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 7966 | if (load_kind != HLoadClass::LoadKind::kBootImageAddress) { |
| 7967 | codegen_->ClobberRA(); |
| 7968 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7969 | break; |
| 7970 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7971 | FALLTHROUGH_INTENDED; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7972 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7973 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7974 | break; |
| 7975 | default: |
| 7976 | break; |
| 7977 | } |
| 7978 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7979 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7980 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7981 | // 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] | 7982 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7983 | InvokeRuntimeCallingConvention calling_convention; |
| 7984 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7985 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 7986 | } else { |
| 7987 | // For non-Baker read barriers we have a temp-clobbering call. |
| 7988 | } |
| 7989 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7990 | } |
| 7991 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7992 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7993 | // move. |
| 7994 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7995 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7996 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7997 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 7998 | return; |
| 7999 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8000 | DCHECK(!cls->NeedsAccessCheck()); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 8001 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8002 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8003 | Location out_loc = locations->Out(); |
| 8004 | Register out = out_loc.AsRegister<Register>(); |
| 8005 | Register base_or_current_method_reg; |
| 8006 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8007 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8008 | switch (load_kind) { |
| 8009 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8010 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8011 | case HLoadClass::LoadKind::kBootImageAddress: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8012 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8013 | case HLoadClass::LoadKind::kBssEntry: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8014 | base_or_current_method_reg = |
| 8015 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8016 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8017 | case HLoadClass::LoadKind::kReferrersClass: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8018 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8019 | base_or_current_method_reg = locations->InAt(0).AsRegister<Register>(); |
| 8020 | break; |
| 8021 | default: |
| 8022 | base_or_current_method_reg = ZERO; |
| 8023 | break; |
| 8024 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 8025 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8026 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 8027 | ? kWithoutReadBarrier |
| 8028 | : kCompilerReadBarrierOption; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8029 | bool generate_null_check = false; |
| 8030 | switch (load_kind) { |
| 8031 | case HLoadClass::LoadKind::kReferrersClass: { |
| 8032 | DCHECK(!cls->CanCallRuntime()); |
| 8033 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 8034 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 8035 | GenerateGcRootFieldLoad(cls, |
| 8036 | out_loc, |
| 8037 | base_or_current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8038 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 8039 | read_barrier_option); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8040 | break; |
| 8041 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8042 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8043 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8044 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8045 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8046 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8047 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8048 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8049 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8050 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 8051 | base_or_current_method_reg); |
| 8052 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8053 | break; |
| 8054 | } |
| 8055 | case HLoadClass::LoadKind::kBootImageAddress: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8056 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 8057 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 8058 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 8059 | DCHECK_NE(address, 0u); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8060 | if (isR6 || !has_irreducible_loops) { |
| 8061 | __ LoadLiteral(out, |
| 8062 | base_or_current_method_reg, |
| 8063 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 8064 | } else { |
| 8065 | __ LoadConst32(out, address); |
| 8066 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8067 | break; |
| 8068 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8069 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 8070 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 8071 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8072 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8073 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8074 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8075 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8076 | out, |
| 8077 | base_or_current_method_reg); |
| 8078 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
| 8079 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 8080 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 8081 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 8082 | if (masked_hash != 0) { |
| 8083 | __ Addiu(out, out, -masked_hash); |
| 8084 | } |
| 8085 | break; |
| 8086 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8087 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8088 | CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high = |
| 8089 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8090 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8091 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8092 | codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8093 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8094 | base_or_current_method_reg); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8095 | GenerateGcRootFieldLoad(cls, |
| 8096 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8097 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8098 | /* placeholder */ 0x5678, |
| 8099 | read_barrier_option, |
| 8100 | &info_low->label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8101 | generate_null_check = true; |
| 8102 | break; |
| 8103 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8104 | case HLoadClass::LoadKind::kJitTableAddress: { |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8105 | CodeGeneratorMIPS::JitPatchInfo* info = codegen_->NewJitRootClassPatch(cls->GetDexFile(), |
| 8106 | cls->GetTypeIndex(), |
| 8107 | cls->GetClass()); |
| 8108 | bool reordering = __ SetReorder(false); |
| 8109 | __ Bind(&info->high_label); |
| 8110 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8111 | __ SetReorder(reordering); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8112 | GenerateGcRootFieldLoad(cls, |
| 8113 | out_loc, |
| 8114 | out, |
| 8115 | /* placeholder */ 0x5678, |
| 8116 | read_barrier_option, |
| 8117 | &info->low_label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8118 | break; |
| 8119 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8120 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 8121 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8122 | LOG(FATAL) << "UNREACHABLE"; |
| 8123 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8124 | } |
| 8125 | |
| 8126 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 8127 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8128 | SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS( |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8129 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8130 | codegen_->AddSlowPath(slow_path); |
| 8131 | if (generate_null_check) { |
| 8132 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 8133 | } |
| 8134 | if (cls->MustGenerateClinitCheck()) { |
| 8135 | GenerateClassInitializationCheck(slow_path, out); |
| 8136 | } else { |
| 8137 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8138 | } |
| 8139 | } |
| 8140 | } |
| 8141 | |
| 8142 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8143 | return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8144 | } |
| 8145 | |
| 8146 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { |
| 8147 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8148 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8149 | locations->SetOut(Location::RequiresRegister()); |
| 8150 | } |
| 8151 | |
| 8152 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { |
| 8153 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
| 8154 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 8155 | } |
| 8156 | |
| 8157 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8158 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8159 | } |
| 8160 | |
| 8161 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 8162 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
| 8163 | } |
| 8164 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8165 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 8166 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8167 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8168 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8169 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8170 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8171 | switch (load_kind) { |
| 8172 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8173 | case HLoadString::LoadKind::kBootImageAddress: |
| 8174 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8175 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8176 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8177 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8178 | break; |
| 8179 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8180 | if (has_irreducible_loops) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 8181 | if (load_kind != HLoadString::LoadKind::kBootImageAddress) { |
| 8182 | codegen_->ClobberRA(); |
| 8183 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8184 | break; |
| 8185 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8186 | FALLTHROUGH_INTENDED; |
| 8187 | // We need an extra register for PC-relative dex cache accesses. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8188 | case HLoadString::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8189 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8190 | break; |
| 8191 | default: |
| 8192 | break; |
| 8193 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8194 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8195 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8196 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8197 | } else { |
| 8198 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8199 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 8200 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 8201 | // Rely on the pResolveString and marking to save everything we need. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8202 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 8203 | InvokeRuntimeCallingConvention calling_convention; |
| 8204 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8205 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 8206 | } else { |
| 8207 | // For non-Baker read barriers we have a temp-clobbering call. |
| 8208 | } |
| 8209 | } |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8210 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8211 | } |
| 8212 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8213 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 8214 | // move. |
| 8215 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8216 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8217 | LocationSummary* locations = load->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8218 | Location out_loc = locations->Out(); |
| 8219 | Register out = out_loc.AsRegister<Register>(); |
| 8220 | Register base_or_current_method_reg; |
| 8221 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8222 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8223 | switch (load_kind) { |
| 8224 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8225 | case HLoadString::LoadKind::kBootImageAddress: |
| 8226 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8227 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8228 | case HLoadString::LoadKind::kBssEntry: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8229 | base_or_current_method_reg = |
| 8230 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8231 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8232 | default: |
| 8233 | base_or_current_method_reg = ZERO; |
| 8234 | break; |
| 8235 | } |
| 8236 | |
| 8237 | switch (load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8238 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8239 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8240 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8241 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8242 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8243 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8244 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8245 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 8246 | base_or_current_method_reg); |
| 8247 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8248 | return; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8249 | } |
| 8250 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8251 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 8252 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 8253 | DCHECK_NE(address, 0u); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8254 | if (isR6 || !has_irreducible_loops) { |
| 8255 | __ LoadLiteral(out, |
| 8256 | base_or_current_method_reg, |
| 8257 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 8258 | } else { |
| 8259 | __ LoadConst32(out, address); |
| 8260 | } |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8261 | return; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8262 | } |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8263 | case HLoadString::LoadKind::kBootImageInternTable: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8264 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8265 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8266 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8267 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8268 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8269 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8270 | out, |
| 8271 | base_or_current_method_reg); |
| 8272 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
| 8273 | return; |
| 8274 | } |
| 8275 | case HLoadString::LoadKind::kBssEntry: { |
| 8276 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 8277 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
| 8278 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| 8279 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8280 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8281 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8282 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8283 | base_or_current_method_reg); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8284 | GenerateGcRootFieldLoad(load, |
| 8285 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8286 | out, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8287 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8288 | kCompilerReadBarrierOption, |
| 8289 | &info_low->label); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8290 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8291 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8292 | codegen_->AddSlowPath(slow_path); |
| 8293 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 8294 | __ Bind(slow_path->GetExitLabel()); |
| 8295 | return; |
| 8296 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8297 | case HLoadString::LoadKind::kJitTableAddress: { |
| 8298 | CodeGeneratorMIPS::JitPatchInfo* info = |
| 8299 | codegen_->NewJitRootStringPatch(load->GetDexFile(), |
| 8300 | load->GetStringIndex(), |
| 8301 | load->GetString()); |
| 8302 | bool reordering = __ SetReorder(false); |
| 8303 | __ Bind(&info->high_label); |
| 8304 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8305 | __ SetReorder(reordering); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8306 | GenerateGcRootFieldLoad(load, |
| 8307 | out_loc, |
| 8308 | out, |
| 8309 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8310 | kCompilerReadBarrierOption, |
| 8311 | &info->low_label); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8312 | return; |
| 8313 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8314 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8315 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8316 | } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 8317 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8318 | // 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] | 8319 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8320 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8321 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8322 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8323 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 8324 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8325 | } |
| 8326 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8327 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8328 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8329 | locations->SetOut(Location::ConstantLocation(constant)); |
| 8330 | } |
| 8331 | |
| 8332 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 8333 | // Will be generated at use site. |
| 8334 | } |
| 8335 | |
| 8336 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8337 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8338 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8339 | InvokeRuntimeCallingConvention calling_convention; |
| 8340 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8341 | } |
| 8342 | |
| 8343 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8344 | if (instruction->IsEnter()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8345 | codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8346 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8347 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8348 | codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8349 | } |
| 8350 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8351 | } |
| 8352 | |
| 8353 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { |
| 8354 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8355 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8356 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8357 | case DataType::Type::kInt32: |
| 8358 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8359 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8360 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8361 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8362 | break; |
| 8363 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8364 | case DataType::Type::kFloat32: |
| 8365 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8366 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8367 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 8368 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8369 | break; |
| 8370 | |
| 8371 | default: |
| 8372 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 8373 | } |
| 8374 | } |
| 8375 | |
| 8376 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8377 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8378 | LocationSummary* locations = instruction->GetLocations(); |
| 8379 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 8380 | |
| 8381 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8382 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8383 | Register dst = locations->Out().AsRegister<Register>(); |
| 8384 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 8385 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 8386 | |
| 8387 | if (isR6) { |
| 8388 | __ MulR6(dst, lhs, rhs); |
| 8389 | } else { |
| 8390 | __ MulR2(dst, lhs, rhs); |
| 8391 | } |
| 8392 | break; |
| 8393 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8394 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8395 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8396 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8397 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8398 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8399 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 8400 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 8401 | |
| 8402 | // Extra checks to protect caused by the existance of A1_A2. |
| 8403 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: |
| 8404 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). |
| 8405 | DCHECK_NE(dst_high, lhs_low); |
| 8406 | DCHECK_NE(dst_high, rhs_low); |
| 8407 | |
| 8408 | // A_B * C_D |
| 8409 | // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ] |
| 8410 | // dst_lo: [ low(B*D) ] |
| 8411 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. |
| 8412 | |
| 8413 | if (isR6) { |
| 8414 | __ MulR6(TMP, lhs_high, rhs_low); |
| 8415 | __ MulR6(dst_high, lhs_low, rhs_high); |
| 8416 | __ Addu(dst_high, dst_high, TMP); |
| 8417 | __ MuhuR6(TMP, lhs_low, rhs_low); |
| 8418 | __ Addu(dst_high, dst_high, TMP); |
| 8419 | __ MulR6(dst_low, lhs_low, rhs_low); |
| 8420 | } else { |
| 8421 | __ MulR2(TMP, lhs_high, rhs_low); |
| 8422 | __ MulR2(dst_high, lhs_low, rhs_high); |
| 8423 | __ Addu(dst_high, dst_high, TMP); |
| 8424 | __ MultuR2(lhs_low, rhs_low); |
| 8425 | __ Mfhi(TMP); |
| 8426 | __ Addu(dst_high, dst_high, TMP); |
| 8427 | __ Mflo(dst_low); |
| 8428 | } |
| 8429 | break; |
| 8430 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8431 | case DataType::Type::kFloat32: |
| 8432 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8433 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8434 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8435 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8436 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8437 | __ MulS(dst, lhs, rhs); |
| 8438 | } else { |
| 8439 | __ MulD(dst, lhs, rhs); |
| 8440 | } |
| 8441 | break; |
| 8442 | } |
| 8443 | default: |
| 8444 | LOG(FATAL) << "Unexpected mul type " << type; |
| 8445 | } |
| 8446 | } |
| 8447 | |
| 8448 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { |
| 8449 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8450 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8451 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8452 | case DataType::Type::kInt32: |
| 8453 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8454 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8455 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8456 | break; |
| 8457 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8458 | case DataType::Type::kFloat32: |
| 8459 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8460 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8461 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8462 | break; |
| 8463 | |
| 8464 | default: |
| 8465 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 8466 | } |
| 8467 | } |
| 8468 | |
| 8469 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8470 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8471 | LocationSummary* locations = instruction->GetLocations(); |
| 8472 | |
| 8473 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8474 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8475 | Register dst = locations->Out().AsRegister<Register>(); |
| 8476 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8477 | __ Subu(dst, ZERO, src); |
| 8478 | break; |
| 8479 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8480 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8481 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8482 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8483 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8484 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8485 | __ Subu(dst_low, ZERO, src_low); |
| 8486 | __ Sltu(TMP, ZERO, dst_low); |
| 8487 | __ Subu(dst_high, ZERO, src_high); |
| 8488 | __ Subu(dst_high, dst_high, TMP); |
| 8489 | break; |
| 8490 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8491 | case DataType::Type::kFloat32: |
| 8492 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8493 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8494 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8495 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8496 | __ NegS(dst, src); |
| 8497 | } else { |
| 8498 | __ NegD(dst, src); |
| 8499 | } |
| 8500 | break; |
| 8501 | } |
| 8502 | default: |
| 8503 | LOG(FATAL) << "Unexpected neg type " << type; |
| 8504 | } |
| 8505 | } |
| 8506 | |
| 8507 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8508 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8509 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8510 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8511 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8512 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8513 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8514 | } |
| 8515 | |
| 8516 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8517 | // Note: if heap poisoning is enabled, the entry point takes care |
| 8518 | // of poisoning the reference. |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8519 | QuickEntrypointEnum entrypoint = |
| 8520 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 8521 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8522 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8523 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8524 | } |
| 8525 | |
| 8526 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8527 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8528 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8529 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8530 | if (instruction->IsStringAlloc()) { |
| 8531 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 8532 | } else { |
| 8533 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8534 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8535 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8536 | } |
| 8537 | |
| 8538 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8539 | // Note: if heap poisoning is enabled, the entry point takes care |
| 8540 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8541 | if (instruction->IsStringAlloc()) { |
| 8542 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 8543 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8544 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8545 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 8546 | __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value()); |
| 8547 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 8548 | __ NopIfNoReordering(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8549 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 8550 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8551 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 8552 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8553 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8554 | } |
| 8555 | |
| 8556 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8557 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8558 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8559 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8560 | } |
| 8561 | |
| 8562 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8563 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8564 | LocationSummary* locations = instruction->GetLocations(); |
| 8565 | |
| 8566 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8567 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8568 | Register dst = locations->Out().AsRegister<Register>(); |
| 8569 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8570 | __ Nor(dst, src, ZERO); |
| 8571 | break; |
| 8572 | } |
| 8573 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8574 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8575 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8576 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8577 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8578 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8579 | __ Nor(dst_high, src_high, ZERO); |
| 8580 | __ Nor(dst_low, src_low, ZERO); |
| 8581 | break; |
| 8582 | } |
| 8583 | |
| 8584 | default: |
| 8585 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 8586 | } |
| 8587 | } |
| 8588 | |
| 8589 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8590 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8591 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8592 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8593 | } |
| 8594 | |
| 8595 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 8596 | LocationSummary* locations = instruction->GetLocations(); |
| 8597 | __ Xori(locations->Out().AsRegister<Register>(), |
| 8598 | locations->InAt(0).AsRegister<Register>(), |
| 8599 | 1); |
| 8600 | } |
| 8601 | |
| 8602 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 8603 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 8604 | locations->SetInAt(0, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8605 | } |
| 8606 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8607 | void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 8608 | if (CanMoveNullCheckToUser(instruction)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8609 | return; |
| 8610 | } |
| 8611 | Location obj = instruction->GetLocations()->InAt(0); |
| 8612 | |
| 8613 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8614 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8615 | } |
| 8616 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8617 | void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8618 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) NullCheckSlowPathMIPS(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8619 | AddSlowPath(slow_path); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8620 | |
| 8621 | Location obj = instruction->GetLocations()->InAt(0); |
| 8622 | |
| 8623 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8624 | } |
| 8625 | |
| 8626 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8627 | codegen_->GenerateNullCheck(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8628 | } |
| 8629 | |
| 8630 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { |
| 8631 | HandleBinaryOp(instruction); |
| 8632 | } |
| 8633 | |
| 8634 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { |
| 8635 | HandleBinaryOp(instruction); |
| 8636 | } |
| 8637 | |
| 8638 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 8639 | LOG(FATAL) << "Unreachable"; |
| 8640 | } |
| 8641 | |
| 8642 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 8643 | if (instruction->GetNext()->IsSuspendCheck() && |
| 8644 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 8645 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 8646 | // The back edge will generate the suspend check. |
| 8647 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 8648 | } |
| 8649 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8650 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 8651 | } |
| 8652 | |
| 8653 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8654 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8655 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 8656 | if (location.IsStackSlot()) { |
| 8657 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8658 | } else if (location.IsDoubleStackSlot()) { |
| 8659 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8660 | } |
| 8661 | locations->SetOut(location); |
| 8662 | } |
| 8663 | |
| 8664 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction |
| 8665 | ATTRIBUTE_UNUSED) { |
| 8666 | // Nothing to do, the parameter is already at its location. |
| 8667 | } |
| 8668 | |
| 8669 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 8670 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8671 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8672 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 8673 | } |
| 8674 | |
| 8675 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction |
| 8676 | ATTRIBUTE_UNUSED) { |
| 8677 | // Nothing to do, the method is already at its location. |
| 8678 | } |
| 8679 | |
| 8680 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8681 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 8682 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8683 | locations->SetInAt(i, Location::Any()); |
| 8684 | } |
| 8685 | locations->SetOut(Location::Any()); |
| 8686 | } |
| 8687 | |
| 8688 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 8689 | LOG(FATAL) << "Unreachable"; |
| 8690 | } |
| 8691 | |
| 8692 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8693 | DataType::Type type = rem->GetResultType(); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8694 | bool call_rem; |
| 8695 | if ((type == DataType::Type::kInt64) && rem->InputAt(1)->IsConstant()) { |
| 8696 | int64_t imm = CodeGenerator::GetInt64ValueOf(rem->InputAt(1)->AsConstant()); |
| 8697 | call_rem = (imm != 0) && !IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm))); |
| 8698 | } else { |
| 8699 | call_rem = (type != DataType::Type::kInt32); |
| 8700 | } |
| 8701 | LocationSummary::CallKind call_kind = call_rem |
| 8702 | ? LocationSummary::kCallOnMainOnly |
| 8703 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8704 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8705 | |
| 8706 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8707 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8708 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8709 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8710 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8711 | break; |
| 8712 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8713 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8714 | if (call_rem) { |
| 8715 | InvokeRuntimeCallingConvention calling_convention; |
| 8716 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 8717 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 8718 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 8719 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 8720 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8721 | } else { |
| 8722 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8723 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 8724 | locations->SetOut(Location::RequiresRegister()); |
| 8725 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8726 | break; |
| 8727 | } |
| 8728 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8729 | case DataType::Type::kFloat32: |
| 8730 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8731 | InvokeRuntimeCallingConvention calling_convention; |
| 8732 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 8733 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 8734 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8735 | break; |
| 8736 | } |
| 8737 | |
| 8738 | default: |
| 8739 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8740 | } |
| 8741 | } |
| 8742 | |
| 8743 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8744 | DataType::Type type = instruction->GetType(); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8745 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8746 | |
| 8747 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8748 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8749 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8750 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8751 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8752 | if (locations->InAt(1).IsConstant()) { |
| 8753 | int64_t imm = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue(); |
| 8754 | if (imm == 0) { |
| 8755 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 8756 | } else if (imm == 1 || imm == -1) { |
| 8757 | DivRemOneOrMinusOne(instruction); |
| 8758 | } else { |
| 8759 | DCHECK(IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm)))); |
| 8760 | DivRemByPowerOfTwo(instruction); |
| 8761 | } |
| 8762 | } else { |
| 8763 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
| 8764 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 8765 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8766 | break; |
| 8767 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8768 | case DataType::Type::kFloat32: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8769 | codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8770 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8771 | break; |
| 8772 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8773 | case DataType::Type::kFloat64: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8774 | codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8775 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8776 | break; |
| 8777 | } |
| 8778 | default: |
| 8779 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8780 | } |
| 8781 | } |
| 8782 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame^] | 8783 | void LocationsBuilderMIPS::VisitAbs(HAbs* abs) { |
| 8784 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 8785 | switch (abs->GetResultType()) { |
| 8786 | case DataType::Type::kInt32: |
| 8787 | case DataType::Type::kInt64: |
| 8788 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8789 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8790 | break; |
| 8791 | case DataType::Type::kFloat32: |
| 8792 | case DataType::Type::kFloat64: |
| 8793 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8794 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8795 | break; |
| 8796 | default: |
| 8797 | LOG(FATAL) << "Unexpected abs type " << abs->GetResultType(); |
| 8798 | } |
| 8799 | } |
| 8800 | |
| 8801 | void InstructionCodeGeneratorMIPS::GenerateAbsFP(LocationSummary* locations, |
| 8802 | DataType::Type type, |
| 8803 | bool isR2OrNewer, |
| 8804 | bool isR6) { |
| 8805 | FRegister in = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8806 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 8807 | |
| 8808 | // Note, as a "quality of implementation", rather than pure "spec compliance", we require that |
| 8809 | // Math.abs() clears the sign bit (but changes nothing else) for all numbers, including NaN |
| 8810 | // (signaling NaN may become quiet though). |
| 8811 | // |
| 8812 | // The ABS.fmt instructions (abs.s and abs.d) do exactly that when NAN2008=1 (R6). For this case, |
| 8813 | // both regular floating point numbers and NAN values are treated alike, only the sign bit is |
| 8814 | // affected by this instruction. |
| 8815 | // But when NAN2008=0 (R2 and before), the ABS.fmt instructions can't be used. For this case, any |
| 8816 | // NaN operand signals invalid operation. This means that other bits (not just sign bit) might be |
| 8817 | // changed when doing abs(NaN). Because of that, we clear sign bit in a different way. |
| 8818 | if (isR6) { |
| 8819 | if (type == DataType::Type::kFloat64) { |
| 8820 | __ AbsD(out, in); |
| 8821 | } else { |
| 8822 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 8823 | __ AbsS(out, in); |
| 8824 | } |
| 8825 | } else { |
| 8826 | if (type == DataType::Type::kFloat64) { |
| 8827 | if (in != out) { |
| 8828 | __ MovD(out, in); |
| 8829 | } |
| 8830 | __ MoveFromFpuHigh(TMP, in); |
| 8831 | // ins instruction is not available for R1. |
| 8832 | if (isR2OrNewer) { |
| 8833 | __ Ins(TMP, ZERO, 31, 1); |
| 8834 | } else { |
| 8835 | __ Sll(TMP, TMP, 1); |
| 8836 | __ Srl(TMP, TMP, 1); |
| 8837 | } |
| 8838 | __ MoveToFpuHigh(TMP, out); |
| 8839 | } else { |
| 8840 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 8841 | __ Mfc1(TMP, in); |
| 8842 | // ins instruction is not available for R1. |
| 8843 | if (isR2OrNewer) { |
| 8844 | __ Ins(TMP, ZERO, 31, 1); |
| 8845 | } else { |
| 8846 | __ Sll(TMP, TMP, 1); |
| 8847 | __ Srl(TMP, TMP, 1); |
| 8848 | } |
| 8849 | __ Mtc1(TMP, out); |
| 8850 | } |
| 8851 | } |
| 8852 | } |
| 8853 | |
| 8854 | void InstructionCodeGeneratorMIPS::VisitAbs(HAbs* abs) { |
| 8855 | LocationSummary* locations = abs->GetLocations(); |
| 8856 | bool isR2OrNewer = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
| 8857 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 8858 | switch (abs->GetResultType()) { |
| 8859 | case DataType::Type::kInt32: { |
| 8860 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 8861 | Register out = locations->Out().AsRegister<Register>(); |
| 8862 | __ Sra(AT, in, 31); |
| 8863 | __ Xor(out, in, AT); |
| 8864 | __ Subu(out, out, AT); |
| 8865 | break; |
| 8866 | } |
| 8867 | case DataType::Type::kInt64: { |
| 8868 | Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8869 | Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8870 | Register out_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 8871 | Register out_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 8872 | // The comments in this section show the analogous operations which would |
| 8873 | // be performed if we had 64-bit registers "in", and "out". |
| 8874 | // __ Dsra32(AT, in, 31); |
| 8875 | __ Sra(AT, in_hi, 31); |
| 8876 | // __ Xor(out, in, AT); |
| 8877 | __ Xor(TMP, in_lo, AT); |
| 8878 | __ Xor(out_hi, in_hi, AT); |
| 8879 | // __ Dsubu(out, out, AT); |
| 8880 | __ Subu(out_lo, TMP, AT); |
| 8881 | __ Sltu(TMP, out_lo, TMP); |
| 8882 | __ Addu(out_hi, out_hi, TMP); |
| 8883 | break; |
| 8884 | } |
| 8885 | case DataType::Type::kFloat32: |
| 8886 | case DataType::Type::kFloat64: |
| 8887 | GenerateAbsFP(locations, abs->GetResultType(), isR2OrNewer, isR6); |
| 8888 | break; |
| 8889 | default: |
| 8890 | LOG(FATAL) << "Unexpected abs type " << abs->GetResultType(); |
| 8891 | } |
| 8892 | } |
| 8893 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8894 | void LocationsBuilderMIPS::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 8895 | constructor_fence->SetLocations(nullptr); |
| 8896 | } |
| 8897 | |
| 8898 | void InstructionCodeGeneratorMIPS::VisitConstructorFence( |
| 8899 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 8900 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 8901 | } |
| 8902 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8903 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 8904 | memory_barrier->SetLocations(nullptr); |
| 8905 | } |
| 8906 | |
| 8907 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 8908 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 8909 | } |
| 8910 | |
| 8911 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8912 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8913 | DataType::Type return_type = ret->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8914 | locations->SetInAt(0, MipsReturnLocation(return_type)); |
| 8915 | } |
| 8916 | |
| 8917 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 8918 | codegen_->GenerateFrameExit(); |
| 8919 | } |
| 8920 | |
| 8921 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { |
| 8922 | ret->SetLocations(nullptr); |
| 8923 | } |
| 8924 | |
| 8925 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 8926 | codegen_->GenerateFrameExit(); |
| 8927 | } |
| 8928 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 8929 | void LocationsBuilderMIPS::VisitRor(HRor* ror) { |
| 8930 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 8931 | } |
| 8932 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 8933 | void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) { |
| 8934 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 8935 | } |
| 8936 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8937 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { |
| 8938 | HandleShift(shl); |
| 8939 | } |
| 8940 | |
| 8941 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { |
| 8942 | HandleShift(shl); |
| 8943 | } |
| 8944 | |
| 8945 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { |
| 8946 | HandleShift(shr); |
| 8947 | } |
| 8948 | |
| 8949 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { |
| 8950 | HandleShift(shr); |
| 8951 | } |
| 8952 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8953 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { |
| 8954 | HandleBinaryOp(instruction); |
| 8955 | } |
| 8956 | |
| 8957 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { |
| 8958 | HandleBinaryOp(instruction); |
| 8959 | } |
| 8960 | |
| 8961 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 8962 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 8963 | } |
| 8964 | |
| 8965 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 8966 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 8967 | } |
| 8968 | |
| 8969 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 8970 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 8971 | } |
| 8972 | |
| 8973 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 8974 | HandleFieldSet(instruction, |
| 8975 | instruction->GetFieldInfo(), |
| 8976 | instruction->GetDexPc(), |
| 8977 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8978 | } |
| 8979 | |
| 8980 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( |
| 8981 | HUnresolvedInstanceFieldGet* instruction) { |
| 8982 | FieldAccessCallingConventionMIPS calling_convention; |
| 8983 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8984 | instruction->GetFieldType(), |
| 8985 | calling_convention); |
| 8986 | } |
| 8987 | |
| 8988 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( |
| 8989 | HUnresolvedInstanceFieldGet* instruction) { |
| 8990 | FieldAccessCallingConventionMIPS calling_convention; |
| 8991 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8992 | instruction->GetFieldType(), |
| 8993 | instruction->GetFieldIndex(), |
| 8994 | instruction->GetDexPc(), |
| 8995 | calling_convention); |
| 8996 | } |
| 8997 | |
| 8998 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( |
| 8999 | HUnresolvedInstanceFieldSet* instruction) { |
| 9000 | FieldAccessCallingConventionMIPS calling_convention; |
| 9001 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 9002 | instruction->GetFieldType(), |
| 9003 | calling_convention); |
| 9004 | } |
| 9005 | |
| 9006 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( |
| 9007 | HUnresolvedInstanceFieldSet* instruction) { |
| 9008 | FieldAccessCallingConventionMIPS calling_convention; |
| 9009 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 9010 | instruction->GetFieldType(), |
| 9011 | instruction->GetFieldIndex(), |
| 9012 | instruction->GetDexPc(), |
| 9013 | calling_convention); |
| 9014 | } |
| 9015 | |
| 9016 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( |
| 9017 | HUnresolvedStaticFieldGet* instruction) { |
| 9018 | FieldAccessCallingConventionMIPS calling_convention; |
| 9019 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 9020 | instruction->GetFieldType(), |
| 9021 | calling_convention); |
| 9022 | } |
| 9023 | |
| 9024 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( |
| 9025 | HUnresolvedStaticFieldGet* instruction) { |
| 9026 | FieldAccessCallingConventionMIPS calling_convention; |
| 9027 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 9028 | instruction->GetFieldType(), |
| 9029 | instruction->GetFieldIndex(), |
| 9030 | instruction->GetDexPc(), |
| 9031 | calling_convention); |
| 9032 | } |
| 9033 | |
| 9034 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( |
| 9035 | HUnresolvedStaticFieldSet* instruction) { |
| 9036 | FieldAccessCallingConventionMIPS calling_convention; |
| 9037 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 9038 | instruction->GetFieldType(), |
| 9039 | calling_convention); |
| 9040 | } |
| 9041 | |
| 9042 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( |
| 9043 | HUnresolvedStaticFieldSet* instruction) { |
| 9044 | FieldAccessCallingConventionMIPS calling_convention; |
| 9045 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 9046 | instruction->GetFieldType(), |
| 9047 | instruction->GetFieldIndex(), |
| 9048 | instruction->GetDexPc(), |
| 9049 | calling_convention); |
| 9050 | } |
| 9051 | |
| 9052 | void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9053 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 9054 | instruction, LocationSummary::kCallOnSlowPath); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 9055 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 9056 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 9057 | // registers in full width (since the runtime only saves/restores lower part). |
| 9058 | locations->SetCustomSlowPathCallerSaves( |
| 9059 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9060 | } |
| 9061 | |
| 9062 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 9063 | HBasicBlock* block = instruction->GetBlock(); |
| 9064 | if (block->GetLoopInformation() != nullptr) { |
| 9065 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 9066 | // The back edge will generate the suspend check. |
| 9067 | return; |
| 9068 | } |
| 9069 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 9070 | // The goto will generate the suspend check. |
| 9071 | return; |
| 9072 | } |
| 9073 | GenerateSuspendCheck(instruction, nullptr); |
| 9074 | } |
| 9075 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9076 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9077 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 9078 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9079 | InvokeRuntimeCallingConvention calling_convention; |
| 9080 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 9081 | } |
| 9082 | |
| 9083 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 9084 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9085 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 9086 | } |
| 9087 | |
| 9088 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9089 | DataType::Type input_type = conversion->GetInputType(); |
| 9090 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9091 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 9092 | << input_type << " -> " << result_type; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9093 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9094 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9095 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 9096 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9097 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 9098 | } |
| 9099 | |
| 9100 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9101 | if (!isR6 && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9102 | ((DataType::IsFloatingPointType(result_type) && input_type == DataType::Type::kInt64) || |
| 9103 | (result_type == DataType::Type::kInt64 && DataType::IsFloatingPointType(input_type)))) { |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 9104 | call_kind = LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9105 | } |
| 9106 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9107 | LocationSummary* locations = |
| 9108 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9109 | |
| 9110 | if (call_kind == LocationSummary::kNoCall) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9111 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9112 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 9113 | } else { |
| 9114 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9115 | } |
| 9116 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9117 | if (DataType::IsFloatingPointType(result_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9118 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 9119 | } else { |
| 9120 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9121 | } |
| 9122 | } else { |
| 9123 | InvokeRuntimeCallingConvention calling_convention; |
| 9124 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9125 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9126 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 9127 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9128 | DCHECK_EQ(input_type, DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9129 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 9130 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 9131 | } |
| 9132 | |
| 9133 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 9134 | } |
| 9135 | } |
| 9136 | |
| 9137 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 9138 | LocationSummary* locations = conversion->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9139 | DataType::Type result_type = conversion->GetResultType(); |
| 9140 | DataType::Type input_type = conversion->GetInputType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9141 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9142 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9143 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9144 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 9145 | << input_type << " -> " << result_type; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9146 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9147 | if (result_type == DataType::Type::kInt64 && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9148 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 9149 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 9150 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 9151 | |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 9152 | if (dst_low != src) { |
| 9153 | __ Move(dst_low, src); |
| 9154 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9155 | __ Sra(dst_high, src, 31); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9156 | } else if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9157 | Register dst = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9158 | Register src = (input_type == DataType::Type::kInt64) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9159 | ? locations->InAt(0).AsRegisterPairLow<Register>() |
| 9160 | : locations->InAt(0).AsRegister<Register>(); |
| 9161 | |
| 9162 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9163 | case DataType::Type::kUint8: |
| 9164 | __ Andi(dst, src, 0xFF); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9165 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9166 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9167 | if (has_sign_extension) { |
| 9168 | __ Seb(dst, src); |
| 9169 | } else { |
| 9170 | __ Sll(dst, src, 24); |
| 9171 | __ Sra(dst, dst, 24); |
| 9172 | } |
| 9173 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9174 | case DataType::Type::kUint16: |
| 9175 | __ Andi(dst, src, 0xFFFF); |
| 9176 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9177 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9178 | if (has_sign_extension) { |
| 9179 | __ Seh(dst, src); |
| 9180 | } else { |
| 9181 | __ Sll(dst, src, 16); |
| 9182 | __ Sra(dst, dst, 16); |
| 9183 | } |
| 9184 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9185 | case DataType::Type::kInt32: |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 9186 | if (dst != src) { |
| 9187 | __ Move(dst, src); |
| 9188 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9189 | break; |
| 9190 | |
| 9191 | default: |
| 9192 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 9193 | << " to " << result_type; |
| 9194 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9195 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
| 9196 | if (input_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9197 | if (isR6) { |
| 9198 | // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 9199 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 9200 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 9201 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 9202 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 9203 | __ Mtc1(src_low, FTMP); |
| 9204 | __ Mthc1(src_high, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9205 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9206 | __ Cvtsl(dst, FTMP); |
| 9207 | } else { |
| 9208 | __ Cvtdl(dst, FTMP); |
| 9209 | } |
| 9210 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9211 | QuickEntrypointEnum entrypoint = |
| 9212 | (result_type == DataType::Type::kFloat32) ? kQuickL2f : kQuickL2d; |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 9213 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9214 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9215 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 9216 | } else { |
| 9217 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 9218 | } |
| 9219 | } |
| 9220 | } else { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9221 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 9222 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 9223 | __ Mtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9224 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9225 | __ Cvtsw(dst, FTMP); |
| 9226 | } else { |
| 9227 | __ Cvtdw(dst, FTMP); |
| 9228 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9229 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9230 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 9231 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9232 | |
| 9233 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum |
| 9234 | // value of the output type if the input is outside of the range after the truncation or |
| 9235 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct |
| 9236 | // results. This matches the desired float/double-to-int/long conversion exactly. |
| 9237 | // |
| 9238 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive |
| 9239 | // value when the input is either a NaN or is outside of the range of the output type |
| 9240 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce |
| 9241 | // the same result. |
| 9242 | // |
| 9243 | // The code takes care of the different behaviors by first comparing the input to the |
| 9244 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). |
| 9245 | // If the input is greater than or equal to the minimum, it procedes to the truncate |
| 9246 | // instruction, which will handle such an input the same way irrespective of NAN2008. |
| 9247 | // Otherwise the input is compared to itself to determine whether it is a NaN or not |
| 9248 | // in order to return either zero or the minimum value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9249 | if (result_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9250 | if (isR6) { |
| 9251 | // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 9252 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 9253 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9254 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 9255 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9256 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9257 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9258 | __ TruncLS(FTMP, src); |
| 9259 | } else { |
| 9260 | __ TruncLD(FTMP, src); |
| 9261 | } |
| 9262 | __ Mfc1(dst_low, FTMP); |
| 9263 | __ Mfhc1(dst_high, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9264 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9265 | QuickEntrypointEnum entrypoint = |
| 9266 | (input_type == DataType::Type::kFloat32) ? kQuickF2l : kQuickD2l; |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 9267 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9268 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9269 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 9270 | } else { |
| 9271 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 9272 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9273 | } |
| 9274 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9275 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9276 | Register dst = locations->Out().AsRegister<Register>(); |
| 9277 | MipsLabel truncate; |
| 9278 | MipsLabel done; |
| 9279 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9280 | if (!isR6) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9281 | if (input_type == DataType::Type::kFloat32) { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9282 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); |
| 9283 | __ LoadConst32(TMP, min_val); |
| 9284 | __ Mtc1(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9285 | } else { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9286 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); |
| 9287 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 9288 | __ Mtc1(ZERO, FTMP); |
| 9289 | __ MoveToFpuHigh(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9290 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9291 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9292 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9293 | __ ColeS(0, FTMP, src); |
| 9294 | } else { |
| 9295 | __ ColeD(0, FTMP, src); |
| 9296 | } |
| 9297 | __ Bc1t(0, &truncate); |
| 9298 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9299 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9300 | __ CeqS(0, src, src); |
| 9301 | } else { |
| 9302 | __ CeqD(0, src, src); |
| 9303 | } |
| 9304 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 9305 | __ Movf(dst, ZERO, 0); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9306 | |
| 9307 | __ B(&done); |
| 9308 | |
| 9309 | __ Bind(&truncate); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9310 | } |
| 9311 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9312 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9313 | __ TruncWS(FTMP, src); |
| 9314 | } else { |
| 9315 | __ TruncWD(FTMP, src); |
| 9316 | } |
| 9317 | __ Mfc1(dst, FTMP); |
| 9318 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9319 | if (!isR6) { |
| 9320 | __ Bind(&done); |
| 9321 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9322 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9323 | } else if (DataType::IsFloatingPointType(result_type) && |
| 9324 | DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9325 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 9326 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9327 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9328 | __ Cvtsd(dst, src); |
| 9329 | } else { |
| 9330 | __ Cvtds(dst, src); |
| 9331 | } |
| 9332 | } else { |
| 9333 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 9334 | << " to " << result_type; |
| 9335 | } |
| 9336 | } |
| 9337 | |
| 9338 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { |
| 9339 | HandleShift(ushr); |
| 9340 | } |
| 9341 | |
| 9342 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { |
| 9343 | HandleShift(ushr); |
| 9344 | } |
| 9345 | |
| 9346 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { |
| 9347 | HandleBinaryOp(instruction); |
| 9348 | } |
| 9349 | |
| 9350 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { |
| 9351 | HandleBinaryOp(instruction); |
| 9352 | } |
| 9353 | |
| 9354 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9355 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9356 | LOG(FATAL) << "Unreachable"; |
| 9357 | } |
| 9358 | |
| 9359 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9360 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9361 | LOG(FATAL) << "Unreachable"; |
| 9362 | } |
| 9363 | |
| 9364 | void LocationsBuilderMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9365 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9366 | } |
| 9367 | |
| 9368 | void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9369 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9370 | } |
| 9371 | |
| 9372 | void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9373 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9374 | } |
| 9375 | |
| 9376 | void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9377 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9378 | } |
| 9379 | |
| 9380 | void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9381 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9382 | } |
| 9383 | |
| 9384 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9385 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9386 | } |
| 9387 | |
| 9388 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9389 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9390 | } |
| 9391 | |
| 9392 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9393 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9394 | } |
| 9395 | |
| 9396 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9397 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9398 | } |
| 9399 | |
| 9400 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9401 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9402 | } |
| 9403 | |
| 9404 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9405 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9406 | } |
| 9407 | |
| 9408 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9409 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9410 | } |
| 9411 | |
| 9412 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9413 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9414 | } |
| 9415 | |
| 9416 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9417 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9418 | } |
| 9419 | |
| 9420 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9421 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9422 | } |
| 9423 | |
| 9424 | void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9425 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9426 | } |
| 9427 | |
| 9428 | void LocationsBuilderMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9429 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9430 | } |
| 9431 | |
| 9432 | void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9433 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9434 | } |
| 9435 | |
| 9436 | void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9437 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9438 | } |
| 9439 | |
| 9440 | void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9441 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9442 | } |
| 9443 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9444 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9445 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9446 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9447 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9448 | if (!codegen_->GetInstructionSetFeatures().IsR6()) { |
| 9449 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9450 | if (num_entries > InstructionCodeGeneratorMIPS::kPackedSwitchJumpTableThreshold) { |
| 9451 | // When there's no HMipsComputeBaseMethodAddress input, R2 uses the NAL |
| 9452 | // instruction to simulate PC-relative addressing when accessing the jump table. |
| 9453 | // NAL clobbers RA. Make sure RA is preserved. |
| 9454 | codegen_->ClobberRA(); |
| 9455 | } |
| 9456 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9457 | } |
| 9458 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9459 | void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg, |
| 9460 | int32_t lower_bound, |
| 9461 | uint32_t num_entries, |
| 9462 | HBasicBlock* switch_block, |
| 9463 | HBasicBlock* default_block) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9464 | // Create a set of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9465 | Register temp_reg = TMP; |
| 9466 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
| 9467 | // Jump to default if index is negative |
| 9468 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 9469 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 9470 | __ Bltz(temp_reg, codegen_->GetLabelOf(default_block)); |
| 9471 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9472 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9473 | // Jump to successors[0] if value == lower_bound. |
| 9474 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 9475 | int32_t last_index = 0; |
| 9476 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9477 | __ Addiu(temp_reg, temp_reg, -2); |
| 9478 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9479 | __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9480 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9481 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9482 | } |
| 9483 | if (num_entries - last_index == 2) { |
| 9484 | // The last missing case_value. |
| 9485 | __ Addiu(temp_reg, temp_reg, -1); |
| 9486 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9487 | } |
| 9488 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9489 | // And the default for any other value. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9490 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9491 | __ B(codegen_->GetLabelOf(default_block)); |
| 9492 | } |
| 9493 | } |
| 9494 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9495 | void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg, |
| 9496 | Register constant_area, |
| 9497 | int32_t lower_bound, |
| 9498 | uint32_t num_entries, |
| 9499 | HBasicBlock* switch_block, |
| 9500 | HBasicBlock* default_block) { |
| 9501 | // Create a jump table. |
| 9502 | std::vector<MipsLabel*> labels(num_entries); |
| 9503 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 9504 | for (uint32_t i = 0; i < num_entries; i++) { |
| 9505 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 9506 | } |
| 9507 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 9508 | |
| 9509 | // Is the value in range? |
| 9510 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 9511 | if (IsInt<16>(static_cast<int32_t>(num_entries))) { |
| 9512 | __ Sltiu(AT, TMP, num_entries); |
| 9513 | __ Beqz(AT, codegen_->GetLabelOf(default_block)); |
| 9514 | } else { |
| 9515 | __ LoadConst32(AT, num_entries); |
| 9516 | __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 9517 | } |
| 9518 | |
| 9519 | // We are in the range of the table. |
| 9520 | // Load the target address from the jump table, indexing by the value. |
| 9521 | __ LoadLabelAddress(AT, constant_area, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 9522 | __ ShiftAndAdd(TMP, TMP, AT, 2, TMP); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9523 | __ Lw(TMP, TMP, 0); |
| 9524 | // Compute the absolute target address by adding the table start address |
| 9525 | // (the table contains offsets to targets relative to its start). |
| 9526 | __ Addu(TMP, TMP, AT); |
| 9527 | // And jump. |
| 9528 | __ Jr(TMP); |
| 9529 | __ NopIfNoReordering(); |
| 9530 | } |
| 9531 | |
| 9532 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9533 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9534 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9535 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9536 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 9537 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 9538 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9539 | |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9540 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9541 | // R6 uses PC-relative addressing to access the jump table. |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9542 | // |
| 9543 | // R2, OTOH, uses an HMipsComputeBaseMethodAddress input (when available) |
| 9544 | // to access the jump table and it is implemented by changing HPackedSwitch to |
| 9545 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress (see |
| 9546 | // VisitMipsPackedSwitch()). |
| 9547 | // |
| 9548 | // When there's no HMipsComputeBaseMethodAddress input (e.g. in presence of |
| 9549 | // irreducible loops), R2 uses the NAL instruction to simulate PC-relative |
| 9550 | // addressing. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9551 | GenTableBasedPackedSwitch(value_reg, |
| 9552 | ZERO, |
| 9553 | lower_bound, |
| 9554 | num_entries, |
| 9555 | switch_block, |
| 9556 | default_block); |
| 9557 | } else { |
| 9558 | GenPackedSwitchWithCompares(value_reg, |
| 9559 | lower_bound, |
| 9560 | num_entries, |
| 9561 | switch_block, |
| 9562 | default_block); |
| 9563 | } |
| 9564 | } |
| 9565 | |
| 9566 | void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 9567 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9568 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9569 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9570 | // Constant area pointer (HMipsComputeBaseMethodAddress). |
| 9571 | locations->SetInAt(1, Location::RequiresRegister()); |
| 9572 | } |
| 9573 | |
| 9574 | void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 9575 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9576 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9577 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9578 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 9579 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 9580 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 9581 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9582 | |
| 9583 | // This is an R2-only path. HPackedSwitch has been changed to |
| 9584 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress |
| 9585 | // required to address the jump table relative to PC. |
| 9586 | GenTableBasedPackedSwitch(value_reg, |
| 9587 | constant_area, |
| 9588 | lower_bound, |
| 9589 | num_entries, |
| 9590 | switch_block, |
| 9591 | default_block); |
| 9592 | } |
| 9593 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 9594 | void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress( |
| 9595 | HMipsComputeBaseMethodAddress* insn) { |
| 9596 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9597 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 9598 | locations->SetOut(Location::RequiresRegister()); |
| 9599 | } |
| 9600 | |
| 9601 | void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress( |
| 9602 | HMipsComputeBaseMethodAddress* insn) { |
| 9603 | LocationSummary* locations = insn->GetLocations(); |
| 9604 | Register reg = locations->Out().AsRegister<Register>(); |
| 9605 | |
| 9606 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 9607 | |
| 9608 | // Generate a dummy PC-relative call to obtain PC. |
| 9609 | __ Nal(); |
| 9610 | // Grab the return address off RA. |
| 9611 | __ Move(reg, RA); |
| 9612 | |
| 9613 | // Remember this offset (the obtained PC value) for later use with constant area. |
| 9614 | __ BindPcRelBaseLabel(); |
| 9615 | } |
| 9616 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9617 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 9618 | // The trampoline uses the same calling convention as dex calling conventions, |
| 9619 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 9620 | // the method_idx. |
| 9621 | HandleInvoke(invoke); |
| 9622 | } |
| 9623 | |
| 9624 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 9625 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 9626 | } |
| 9627 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9628 | void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 9629 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9630 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9631 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9632 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9633 | } |
| 9634 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9635 | void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 9636 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 9637 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9638 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9639 | instruction->GetIndex(), kMipsPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9640 | __ LoadFromOffset(kLoadWord, |
| 9641 | locations->Out().AsRegister<Register>(), |
| 9642 | locations->InAt(0).AsRegister<Register>(), |
| 9643 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9644 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9645 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 9646 | instruction->GetIndex(), kMipsPointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 9647 | __ LoadFromOffset(kLoadWord, |
| 9648 | locations->Out().AsRegister<Register>(), |
| 9649 | locations->InAt(0).AsRegister<Register>(), |
| 9650 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9651 | __ LoadFromOffset(kLoadWord, |
| 9652 | locations->Out().AsRegister<Register>(), |
| 9653 | locations->Out().AsRegister<Register>(), |
| 9654 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9655 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9656 | } |
| 9657 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 9658 | void LocationsBuilderMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 9659 | ATTRIBUTE_UNUSED) { |
| 9660 | LOG(FATAL) << "Unreachable"; |
| 9661 | } |
| 9662 | |
| 9663 | void InstructionCodeGeneratorMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 9664 | ATTRIBUTE_UNUSED) { |
| 9665 | LOG(FATAL) << "Unreachable"; |
| 9666 | } |
| 9667 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9668 | #undef __ |
| 9669 | #undef QUICK_ENTRY_POINT |
| 9670 | |
| 9671 | } // namespace mips |
| 9672 | } // namespace art |