Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_mips.h" |
| 18 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 19 | #include "arch/mips/asm_support_mips.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 20 | #include "arch/mips/entrypoints_direct_mips.h" |
| 21 | #include "arch/mips/instruction_set_features_mips.h" |
| 22 | #include "art_method.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 23 | #include "class_table.h" |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 24 | #include "code_generator_utils.h" |
Vladimir Marko | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 25 | #include "compiled_method.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 26 | #include "entrypoints/quick/quick_entrypoints.h" |
| 27 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| 28 | #include "gc/accounting/card_table.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 29 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 30 | #include "heap_poisoning.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 31 | #include "intrinsics.h" |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 32 | #include "intrinsics_mips.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 33 | #include "linker/linker_patch.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 34 | #include "mirror/array-inl.h" |
| 35 | #include "mirror/class-inl.h" |
| 36 | #include "offsets.h" |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 37 | #include "stack_map_stream.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 38 | #include "thread.h" |
| 39 | #include "utils/assembler.h" |
| 40 | #include "utils/mips/assembler_mips.h" |
| 41 | #include "utils/stack_checks.h" |
| 42 | |
| 43 | namespace art { |
| 44 | namespace mips { |
| 45 | |
| 46 | static constexpr int kCurrentMethodStackOffset = 0; |
| 47 | static constexpr Register kMethodRegisterArgument = A0; |
| 48 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 49 | // Flags controlling the use of thunks for Baker read barriers. |
| 50 | constexpr bool kBakerReadBarrierThunksEnableForFields = true; |
| 51 | constexpr bool kBakerReadBarrierThunksEnableForArrays = true; |
| 52 | constexpr bool kBakerReadBarrierThunksEnableForGcRoots = true; |
| 53 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 54 | Location MipsReturnLocation(DataType::Type return_type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 55 | switch (return_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 56 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 57 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 58 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 59 | case DataType::Type::kInt8: |
| 60 | case DataType::Type::kUint16: |
| 61 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 62 | case DataType::Type::kUint32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 63 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 64 | return Location::RegisterLocation(V0); |
| 65 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 66 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 67 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 68 | return Location::RegisterPairLocation(V0, V1); |
| 69 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 70 | case DataType::Type::kFloat32: |
| 71 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 72 | return Location::FpuRegisterLocation(F0); |
| 73 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 74 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 75 | return Location(); |
| 76 | } |
| 77 | UNREACHABLE(); |
| 78 | } |
| 79 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 80 | Location InvokeDexCallingConventionVisitorMIPS::GetReturnLocation(DataType::Type type) const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 81 | return MipsReturnLocation(type); |
| 82 | } |
| 83 | |
| 84 | Location InvokeDexCallingConventionVisitorMIPS::GetMethodLocation() const { |
| 85 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 86 | } |
| 87 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 88 | Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(DataType::Type type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 89 | Location next_location; |
| 90 | |
| 91 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 92 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 93 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 94 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 95 | case DataType::Type::kInt8: |
| 96 | case DataType::Type::kUint16: |
| 97 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 98 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 99 | uint32_t gp_index = gp_index_++; |
| 100 | if (gp_index < calling_convention.GetNumberOfRegisters()) { |
| 101 | next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index)); |
| 102 | } else { |
| 103 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 104 | next_location = Location::StackSlot(stack_offset); |
| 105 | } |
| 106 | break; |
| 107 | } |
| 108 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 109 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 110 | uint32_t gp_index = gp_index_; |
| 111 | gp_index_ += 2; |
| 112 | if (gp_index + 1 < calling_convention.GetNumberOfRegisters()) { |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 113 | Register reg = calling_convention.GetRegisterAt(gp_index); |
| 114 | if (reg == A1 || reg == A3) { |
| 115 | gp_index_++; // Skip A1(A3), and use A2_A3(T0_T1) instead. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 116 | gp_index++; |
| 117 | } |
| 118 | Register low_even = calling_convention.GetRegisterAt(gp_index); |
| 119 | Register high_odd = calling_convention.GetRegisterAt(gp_index + 1); |
| 120 | DCHECK_EQ(low_even + 1, high_odd); |
| 121 | next_location = Location::RegisterPairLocation(low_even, high_odd); |
| 122 | } else { |
| 123 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 124 | next_location = Location::DoubleStackSlot(stack_offset); |
| 125 | } |
| 126 | break; |
| 127 | } |
| 128 | |
| 129 | // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double |
| 130 | // will take up the even/odd pair, while floats are stored in even regs only. |
| 131 | // On 64 bit FPU, both double and float are stored in even registers only. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 132 | case DataType::Type::kFloat32: |
| 133 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 134 | uint32_t float_index = float_index_++; |
| 135 | if (float_index < calling_convention.GetNumberOfFpuRegisters()) { |
| 136 | next_location = Location::FpuRegisterLocation( |
| 137 | calling_convention.GetFpuRegisterAt(float_index)); |
| 138 | } else { |
| 139 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 140 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 141 | : Location::StackSlot(stack_offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 142 | } |
| 143 | break; |
| 144 | } |
| 145 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 146 | case DataType::Type::kUint32: |
| 147 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 148 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 149 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 150 | break; |
| 151 | } |
| 152 | |
| 153 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 154 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 155 | |
| 156 | return next_location; |
| 157 | } |
| 158 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 159 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 160 | return MipsReturnLocation(type); |
| 161 | } |
| 162 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 163 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 164 | #define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 165 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 166 | |
| 167 | class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 168 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 169 | explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 170 | |
| 171 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 172 | LocationSummary* locations = instruction_->GetLocations(); |
| 173 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 174 | __ Bind(GetEntryLabel()); |
| 175 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 176 | // Live registers will be restored in the catch block if caught. |
| 177 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 178 | } |
| 179 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 180 | // move resolver. |
| 181 | InvokeRuntimeCallingConvention calling_convention; |
| 182 | codegen->EmitParallelMoves(locations->InAt(0), |
| 183 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 184 | DataType::Type::kInt32, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 185 | locations->InAt(1), |
| 186 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 187 | DataType::Type::kInt32); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 188 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 189 | ? kQuickThrowStringBounds |
| 190 | : kQuickThrowArrayBounds; |
| 191 | mips_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 192 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 193 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 194 | } |
| 195 | |
| 196 | bool IsFatal() const OVERRIDE { return true; } |
| 197 | |
| 198 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; } |
| 199 | |
| 200 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 201 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS); |
| 202 | }; |
| 203 | |
| 204 | class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 205 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 206 | explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 207 | |
| 208 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 209 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 210 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 211 | mips_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 212 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 213 | } |
| 214 | |
| 215 | bool IsFatal() const OVERRIDE { return true; } |
| 216 | |
| 217 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; } |
| 218 | |
| 219 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 220 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS); |
| 221 | }; |
| 222 | |
| 223 | class LoadClassSlowPathMIPS : public SlowPathCodeMIPS { |
| 224 | public: |
| 225 | LoadClassSlowPathMIPS(HLoadClass* cls, |
| 226 | HInstruction* at, |
| 227 | uint32_t dex_pc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 228 | bool do_clinit) |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 229 | : SlowPathCodeMIPS(at), |
| 230 | cls_(cls), |
| 231 | dex_pc_(dex_pc), |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 232 | do_clinit_(do_clinit) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 233 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 234 | } |
| 235 | |
| 236 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 237 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 238 | Location out = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 239 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 240 | InvokeRuntimeCallingConvention calling_convention; |
| 241 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 242 | __ Bind(GetEntryLabel()); |
| 243 | SaveLiveRegisters(codegen, locations); |
| 244 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 245 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 246 | __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 247 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 248 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 249 | mips_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 250 | if (do_clinit_) { |
| 251 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 252 | } else { |
| 253 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 254 | } |
| 255 | |
| 256 | // Move the class to the desired location. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 257 | if (out.IsValid()) { |
| 258 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 259 | DataType::Type type = instruction_->GetType(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 260 | mips_codegen->MoveLocation(out, |
| 261 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 262 | type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 263 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 264 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 265 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 266 | __ B(GetExitLabel()); |
| 267 | } |
| 268 | |
| 269 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; } |
| 270 | |
| 271 | private: |
| 272 | // The class this slow path will load. |
| 273 | HLoadClass* const cls_; |
| 274 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 275 | // The dex PC of `at_`. |
| 276 | const uint32_t dex_pc_; |
| 277 | |
| 278 | // Whether to initialize the class. |
| 279 | const bool do_clinit_; |
| 280 | |
| 281 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS); |
| 282 | }; |
| 283 | |
| 284 | class LoadStringSlowPathMIPS : public SlowPathCodeMIPS { |
| 285 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 286 | explicit LoadStringSlowPathMIPS(HLoadString* instruction) |
| 287 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 288 | |
| 289 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 290 | DCHECK(instruction_->IsLoadString()); |
| 291 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 292 | LocationSummary* locations = instruction_->GetLocations(); |
| 293 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 294 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 295 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 296 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 297 | __ Bind(GetEntryLabel()); |
| 298 | SaveLiveRegisters(codegen, locations); |
| 299 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 300 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 301 | mips_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 302 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 303 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 304 | DataType::Type type = instruction_->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 305 | mips_codegen->MoveLocation(locations->Out(), |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 306 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 307 | type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 308 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 309 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 310 | __ B(GetExitLabel()); |
| 311 | } |
| 312 | |
| 313 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; } |
| 314 | |
| 315 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 316 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS); |
| 317 | }; |
| 318 | |
| 319 | class NullCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 320 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 321 | explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 322 | |
| 323 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 324 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 325 | __ Bind(GetEntryLabel()); |
| 326 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 327 | // Live registers will be restored in the catch block if caught. |
| 328 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 329 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 330 | mips_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 331 | instruction_, |
| 332 | instruction_->GetDexPc(), |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 333 | this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 334 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 335 | } |
| 336 | |
| 337 | bool IsFatal() const OVERRIDE { return true; } |
| 338 | |
| 339 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; } |
| 340 | |
| 341 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 342 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS); |
| 343 | }; |
| 344 | |
| 345 | class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 346 | public: |
| 347 | SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 348 | : SlowPathCodeMIPS(instruction), successor_(successor) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 349 | |
| 350 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 351 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 352 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 353 | __ Bind(GetEntryLabel()); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 354 | SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD. |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 355 | mips_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 356 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 357 | RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 358 | if (successor_ == nullptr) { |
| 359 | __ B(GetReturnLabel()); |
| 360 | } else { |
| 361 | __ B(mips_codegen->GetLabelOf(successor_)); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | MipsLabel* GetReturnLabel() { |
| 366 | DCHECK(successor_ == nullptr); |
| 367 | return &return_label_; |
| 368 | } |
| 369 | |
| 370 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; } |
| 371 | |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 372 | HBasicBlock* GetSuccessor() const { |
| 373 | return successor_; |
| 374 | } |
| 375 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 376 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 377 | // If not null, the block to branch to after the suspend check. |
| 378 | HBasicBlock* const successor_; |
| 379 | |
| 380 | // If `successor_` is null, the label to branch to after the suspend check. |
| 381 | MipsLabel return_label_; |
| 382 | |
| 383 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS); |
| 384 | }; |
| 385 | |
| 386 | class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 387 | public: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 388 | explicit TypeCheckSlowPathMIPS(HInstruction* instruction, bool is_fatal) |
| 389 | : SlowPathCodeMIPS(instruction), is_fatal_(is_fatal) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 390 | |
| 391 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 392 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 393 | uint32_t dex_pc = instruction_->GetDexPc(); |
| 394 | DCHECK(instruction_->IsCheckCast() |
| 395 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 396 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 397 | |
| 398 | __ Bind(GetEntryLabel()); |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 399 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 400 | SaveLiveRegisters(codegen, locations); |
| 401 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 402 | |
| 403 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 404 | // move resolver. |
| 405 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 406 | codegen->EmitParallelMoves(locations->InAt(0), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 407 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 408 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 409 | locations->InAt(1), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 410 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 411 | DataType::Type::kReference); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 412 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 413 | mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 414 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 415 | DataType::Type ret_type = instruction_->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 416 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 417 | mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 418 | } else { |
| 419 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 420 | mips_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 421 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 422 | } |
| 423 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 424 | if (!is_fatal_) { |
| 425 | RestoreLiveRegisters(codegen, locations); |
| 426 | __ B(GetExitLabel()); |
| 427 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; } |
| 431 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 432 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 433 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 434 | private: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 435 | const bool is_fatal_; |
| 436 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 437 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS); |
| 438 | }; |
| 439 | |
| 440 | class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS { |
| 441 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 442 | explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 443 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 444 | |
| 445 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 446 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 447 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 448 | LocationSummary* locations = instruction_->GetLocations(); |
| 449 | SaveLiveRegisters(codegen, locations); |
| 450 | InvokeRuntimeCallingConvention calling_convention; |
| 451 | __ LoadConst32(calling_convention.GetRegisterAt(0), |
| 452 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 453 | mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 454 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; } |
| 458 | |
| 459 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 460 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS); |
| 461 | }; |
| 462 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 463 | class ArraySetSlowPathMIPS : public SlowPathCodeMIPS { |
| 464 | public: |
| 465 | explicit ArraySetSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {} |
| 466 | |
| 467 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 468 | LocationSummary* locations = instruction_->GetLocations(); |
| 469 | __ Bind(GetEntryLabel()); |
| 470 | SaveLiveRegisters(codegen, locations); |
| 471 | |
| 472 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 473 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 474 | parallel_move.AddMove( |
| 475 | locations->InAt(0), |
| 476 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 477 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 478 | nullptr); |
| 479 | parallel_move.AddMove( |
| 480 | locations->InAt(1), |
| 481 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 482 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 483 | nullptr); |
| 484 | parallel_move.AddMove( |
| 485 | locations->InAt(2), |
| 486 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 487 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 488 | nullptr); |
| 489 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 490 | |
| 491 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 492 | mips_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 493 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 494 | RestoreLiveRegisters(codegen, locations); |
| 495 | __ B(GetExitLabel()); |
| 496 | } |
| 497 | |
| 498 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS"; } |
| 499 | |
| 500 | private: |
| 501 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS); |
| 502 | }; |
| 503 | |
| 504 | // Slow path marking an object reference `ref` during a read |
| 505 | // barrier. The field `obj.field` in the object `obj` holding this |
| 506 | // reference does not get updated by this slow path after marking (see |
| 507 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS below for that). |
| 508 | // |
| 509 | // This means that after the execution of this slow path, `ref` will |
| 510 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 511 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 512 | // probably still be a from-space reference (unless it gets updated by |
| 513 | // another thread, or if another thread installed another object |
| 514 | // reference (different from `ref`) in `obj.field`). |
| 515 | // |
| 516 | // If `entrypoint` is a valid location it is assumed to already be |
| 517 | // holding the entrypoint. The case where the entrypoint is passed in |
| 518 | // is for the GcRoot read barrier. |
| 519 | class ReadBarrierMarkSlowPathMIPS : public SlowPathCodeMIPS { |
| 520 | public: |
| 521 | ReadBarrierMarkSlowPathMIPS(HInstruction* instruction, |
| 522 | Location ref, |
| 523 | Location entrypoint = Location::NoLocation()) |
| 524 | : SlowPathCodeMIPS(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 525 | DCHECK(kEmitCompilerReadBarrier); |
| 526 | } |
| 527 | |
| 528 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; } |
| 529 | |
| 530 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 531 | LocationSummary* locations = instruction_->GetLocations(); |
| 532 | Register ref_reg = ref_.AsRegister<Register>(); |
| 533 | DCHECK(locations->CanCall()); |
| 534 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 535 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 536 | instruction_->IsStaticFieldGet() || |
| 537 | instruction_->IsArrayGet() || |
| 538 | instruction_->IsArraySet() || |
| 539 | instruction_->IsLoadClass() || |
| 540 | instruction_->IsLoadString() || |
| 541 | instruction_->IsInstanceOf() || |
| 542 | instruction_->IsCheckCast() || |
| 543 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 544 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 545 | << "Unexpected instruction in read barrier marking slow path: " |
| 546 | << instruction_->DebugName(); |
| 547 | |
| 548 | __ Bind(GetEntryLabel()); |
| 549 | // No need to save live registers; it's taken care of by the |
| 550 | // entrypoint. Also, there is no need to update the stack mask, |
| 551 | // as this runtime call will not trigger a garbage collection. |
| 552 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 553 | DCHECK((V0 <= ref_reg && ref_reg <= T7) || |
| 554 | (S2 <= ref_reg && ref_reg <= S7) || |
| 555 | (ref_reg == FP)) << ref_reg; |
| 556 | // "Compact" slow path, saving two moves. |
| 557 | // |
| 558 | // Instead of using the standard runtime calling convention (input |
| 559 | // and output in A0 and V0 respectively): |
| 560 | // |
| 561 | // A0 <- ref |
| 562 | // V0 <- ReadBarrierMark(A0) |
| 563 | // ref <- V0 |
| 564 | // |
| 565 | // we just use rX (the register containing `ref`) as input and output |
| 566 | // of a dedicated entrypoint: |
| 567 | // |
| 568 | // rX <- ReadBarrierMarkRegX(rX) |
| 569 | // |
| 570 | if (entrypoint_.IsValid()) { |
| 571 | mips_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 572 | DCHECK_EQ(entrypoint_.AsRegister<Register>(), T9); |
| 573 | __ Jalr(entrypoint_.AsRegister<Register>()); |
| 574 | __ NopIfNoReordering(); |
| 575 | } else { |
| 576 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 577 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 578 | // This runtime call does not require a stack map. |
| 579 | mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 580 | instruction_, |
| 581 | this, |
| 582 | /* direct */ false); |
| 583 | } |
| 584 | __ B(GetExitLabel()); |
| 585 | } |
| 586 | |
| 587 | private: |
| 588 | // The location (register) of the marked object reference. |
| 589 | const Location ref_; |
| 590 | |
| 591 | // The location of the entrypoint if already loaded. |
| 592 | const Location entrypoint_; |
| 593 | |
| 594 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS); |
| 595 | }; |
| 596 | |
| 597 | // Slow path marking an object reference `ref` during a read barrier, |
| 598 | // and if needed, atomically updating the field `obj.field` in the |
| 599 | // object `obj` holding this reference after marking (contrary to |
| 600 | // ReadBarrierMarkSlowPathMIPS above, which never tries to update |
| 601 | // `obj.field`). |
| 602 | // |
| 603 | // This means that after the execution of this slow path, both `ref` |
| 604 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 605 | // hold the same to-space reference (unless another thread installed |
| 606 | // another object reference (different from `ref`) in `obj.field`). |
| 607 | class ReadBarrierMarkAndUpdateFieldSlowPathMIPS : public SlowPathCodeMIPS { |
| 608 | public: |
| 609 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(HInstruction* instruction, |
| 610 | Location ref, |
| 611 | Register obj, |
| 612 | Location field_offset, |
| 613 | Register temp1) |
| 614 | : SlowPathCodeMIPS(instruction), |
| 615 | ref_(ref), |
| 616 | obj_(obj), |
| 617 | field_offset_(field_offset), |
| 618 | temp1_(temp1) { |
| 619 | DCHECK(kEmitCompilerReadBarrier); |
| 620 | } |
| 621 | |
| 622 | const char* GetDescription() const OVERRIDE { |
| 623 | return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS"; |
| 624 | } |
| 625 | |
| 626 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 627 | LocationSummary* locations = instruction_->GetLocations(); |
| 628 | Register ref_reg = ref_.AsRegister<Register>(); |
| 629 | DCHECK(locations->CanCall()); |
| 630 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 631 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 632 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 633 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 634 | << instruction_->DebugName(); |
| 635 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 636 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 637 | DCHECK(field_offset_.IsRegisterPair()) << field_offset_; |
| 638 | |
| 639 | __ Bind(GetEntryLabel()); |
| 640 | |
| 641 | // Save the old reference. |
| 642 | // Note that we cannot use AT or TMP to save the old reference, as those |
| 643 | // are used by the code that follows, but we need the old reference after |
| 644 | // the call to the ReadBarrierMarkRegX entry point. |
| 645 | DCHECK_NE(temp1_, AT); |
| 646 | DCHECK_NE(temp1_, TMP); |
| 647 | __ Move(temp1_, ref_reg); |
| 648 | |
| 649 | // No need to save live registers; it's taken care of by the |
| 650 | // entrypoint. Also, there is no need to update the stack mask, |
| 651 | // as this runtime call will not trigger a garbage collection. |
| 652 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 653 | DCHECK((V0 <= ref_reg && ref_reg <= T7) || |
| 654 | (S2 <= ref_reg && ref_reg <= S7) || |
| 655 | (ref_reg == FP)) << ref_reg; |
| 656 | // "Compact" slow path, saving two moves. |
| 657 | // |
| 658 | // Instead of using the standard runtime calling convention (input |
| 659 | // and output in A0 and V0 respectively): |
| 660 | // |
| 661 | // A0 <- ref |
| 662 | // V0 <- ReadBarrierMark(A0) |
| 663 | // ref <- V0 |
| 664 | // |
| 665 | // we just use rX (the register containing `ref`) as input and output |
| 666 | // of a dedicated entrypoint: |
| 667 | // |
| 668 | // rX <- ReadBarrierMarkRegX(rX) |
| 669 | // |
| 670 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 671 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 672 | // This runtime call does not require a stack map. |
| 673 | mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 674 | instruction_, |
| 675 | this, |
| 676 | /* direct */ false); |
| 677 | |
| 678 | // If the new reference is different from the old reference, |
| 679 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 680 | // |
| 681 | // Note that this field could also hold a different object, if |
| 682 | // another thread had concurrently changed it. In that case, the |
| 683 | // the compare-and-set (CAS) loop below would abort, leaving the |
| 684 | // field as-is. |
| 685 | MipsLabel done; |
| 686 | __ Beq(temp1_, ref_reg, &done); |
| 687 | |
| 688 | // Update the the holder's field atomically. This may fail if |
| 689 | // mutator updates before us, but it's OK. This is achieved |
| 690 | // using a strong compare-and-set (CAS) operation with relaxed |
| 691 | // memory synchronization ordering, where the expected value is |
| 692 | // the old reference and the desired value is the new reference. |
| 693 | |
| 694 | // Convenience aliases. |
| 695 | Register base = obj_; |
| 696 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 697 | // offset ("long offset"), of which only the low part contains |
| 698 | // data. |
| 699 | Register offset = field_offset_.AsRegisterPairLow<Register>(); |
| 700 | Register expected = temp1_; |
| 701 | Register value = ref_reg; |
| 702 | Register tmp_ptr = TMP; // Pointer to actual memory. |
| 703 | Register tmp = AT; // Value in memory. |
| 704 | |
| 705 | __ Addu(tmp_ptr, base, offset); |
| 706 | |
| 707 | if (kPoisonHeapReferences) { |
| 708 | __ PoisonHeapReference(expected); |
| 709 | // Do not poison `value` if it is the same register as |
| 710 | // `expected`, which has just been poisoned. |
| 711 | if (value != expected) { |
| 712 | __ PoisonHeapReference(value); |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | // do { |
| 717 | // tmp = [r_ptr] - expected; |
| 718 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 719 | |
| 720 | bool is_r6 = mips_codegen->GetInstructionSetFeatures().IsR6(); |
| 721 | MipsLabel loop_head, exit_loop; |
| 722 | __ Bind(&loop_head); |
| 723 | if (is_r6) { |
| 724 | __ LlR6(tmp, tmp_ptr); |
| 725 | } else { |
| 726 | __ LlR2(tmp, tmp_ptr); |
| 727 | } |
| 728 | __ Bne(tmp, expected, &exit_loop); |
| 729 | __ Move(tmp, value); |
| 730 | if (is_r6) { |
| 731 | __ ScR6(tmp, tmp_ptr); |
| 732 | } else { |
| 733 | __ ScR2(tmp, tmp_ptr); |
| 734 | } |
| 735 | __ Beqz(tmp, &loop_head); |
| 736 | __ Bind(&exit_loop); |
| 737 | |
| 738 | if (kPoisonHeapReferences) { |
| 739 | __ UnpoisonHeapReference(expected); |
| 740 | // Do not unpoison `value` if it is the same register as |
| 741 | // `expected`, which has just been unpoisoned. |
| 742 | if (value != expected) { |
| 743 | __ UnpoisonHeapReference(value); |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | __ Bind(&done); |
| 748 | __ B(GetExitLabel()); |
| 749 | } |
| 750 | |
| 751 | private: |
| 752 | // The location (register) of the marked object reference. |
| 753 | const Location ref_; |
| 754 | // The register containing the object holding the marked object reference field. |
| 755 | const Register obj_; |
| 756 | // The location of the offset of the marked reference field within `obj_`. |
| 757 | Location field_offset_; |
| 758 | |
| 759 | const Register temp1_; |
| 760 | |
| 761 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS); |
| 762 | }; |
| 763 | |
| 764 | // Slow path generating a read barrier for a heap reference. |
| 765 | class ReadBarrierForHeapReferenceSlowPathMIPS : public SlowPathCodeMIPS { |
| 766 | public: |
| 767 | ReadBarrierForHeapReferenceSlowPathMIPS(HInstruction* instruction, |
| 768 | Location out, |
| 769 | Location ref, |
| 770 | Location obj, |
| 771 | uint32_t offset, |
| 772 | Location index) |
| 773 | : SlowPathCodeMIPS(instruction), |
| 774 | out_(out), |
| 775 | ref_(ref), |
| 776 | obj_(obj), |
| 777 | offset_(offset), |
| 778 | index_(index) { |
| 779 | DCHECK(kEmitCompilerReadBarrier); |
| 780 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 781 | // has been overwritten by (or after) the heap object reference load |
| 782 | // to be instrumented, e.g.: |
| 783 | // |
| 784 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 785 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 786 | // |
| 787 | // In that case, we have lost the information about the original |
| 788 | // object, and the emitted read barrier cannot work properly. |
| 789 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 790 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 791 | } |
| 792 | |
| 793 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 794 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 795 | LocationSummary* locations = instruction_->GetLocations(); |
| 796 | Register reg_out = out_.AsRegister<Register>(); |
| 797 | DCHECK(locations->CanCall()); |
| 798 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 799 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 800 | instruction_->IsStaticFieldGet() || |
| 801 | instruction_->IsArrayGet() || |
| 802 | instruction_->IsInstanceOf() || |
| 803 | instruction_->IsCheckCast() || |
| 804 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 805 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 806 | << instruction_->DebugName(); |
| 807 | |
| 808 | __ Bind(GetEntryLabel()); |
| 809 | SaveLiveRegisters(codegen, locations); |
| 810 | |
| 811 | // We may have to change the index's value, but as `index_` is a |
| 812 | // constant member (like other "inputs" of this slow path), |
| 813 | // introduce a copy of it, `index`. |
| 814 | Location index = index_; |
| 815 | if (index_.IsValid()) { |
| 816 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 817 | if (instruction_->IsArrayGet()) { |
| 818 | // Compute the actual memory offset and store it in `index`. |
| 819 | Register index_reg = index_.AsRegister<Register>(); |
| 820 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 821 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 822 | // We are about to change the value of `index_reg` (see the |
| 823 | // calls to art::mips::MipsAssembler::Sll and |
| 824 | // art::mips::MipsAssembler::Addiu32 below), but it has |
| 825 | // not been saved by the previous call to |
| 826 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 827 | // callee-save register -- |
| 828 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 829 | // callee-save registers, as it has been designed with the |
| 830 | // assumption that callee-save registers are supposed to be |
| 831 | // handled by the called function. So, as a callee-save |
| 832 | // register, `index_reg` _would_ eventually be saved onto |
| 833 | // the stack, but it would be too late: we would have |
| 834 | // changed its value earlier. Therefore, we manually save |
| 835 | // it here into another freely available register, |
| 836 | // `free_reg`, chosen of course among the caller-save |
| 837 | // registers (as a callee-save `free_reg` register would |
| 838 | // exhibit the same problem). |
| 839 | // |
| 840 | // Note we could have requested a temporary register from |
| 841 | // the register allocator instead; but we prefer not to, as |
| 842 | // this is a slow path, and we know we can find a |
| 843 | // caller-save register that is available. |
| 844 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 845 | __ Move(free_reg, index_reg); |
| 846 | index_reg = free_reg; |
| 847 | index = Location::RegisterLocation(index_reg); |
| 848 | } else { |
| 849 | // The initial register stored in `index_` has already been |
| 850 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 851 | // (as it is not a callee-save register), so we can freely |
| 852 | // use it. |
| 853 | } |
| 854 | // Shifting the index value contained in `index_reg` by the scale |
| 855 | // factor (2) cannot overflow in practice, as the runtime is |
| 856 | // unable to allocate object arrays with a size larger than |
| 857 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 858 | __ Sll(index_reg, index_reg, TIMES_4); |
| 859 | static_assert( |
| 860 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 861 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 862 | __ Addiu32(index_reg, index_reg, offset_); |
| 863 | } else { |
| 864 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 865 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 866 | // (as in the case of ArrayGet), as it is actually an offset |
| 867 | // to an object field within an object. |
| 868 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 869 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 870 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 871 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 872 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 873 | DCHECK_EQ(offset_, 0U); |
| 874 | DCHECK(index_.IsRegisterPair()); |
| 875 | // UnsafeGet's offset location is a register pair, the low |
| 876 | // part contains the correct offset. |
| 877 | index = index_.ToLow(); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | // We're moving two or three locations to locations that could |
| 882 | // overlap, so we need a parallel move resolver. |
| 883 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 884 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 885 | parallel_move.AddMove(ref_, |
| 886 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 887 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 888 | nullptr); |
| 889 | parallel_move.AddMove(obj_, |
| 890 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 891 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 892 | nullptr); |
| 893 | if (index.IsValid()) { |
| 894 | parallel_move.AddMove(index, |
| 895 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 896 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 897 | nullptr); |
| 898 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 899 | } else { |
| 900 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 901 | __ LoadConst32(calling_convention.GetRegisterAt(2), offset_); |
| 902 | } |
| 903 | mips_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| 904 | instruction_, |
| 905 | instruction_->GetDexPc(), |
| 906 | this); |
| 907 | CheckEntrypointTypes< |
| 908 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 909 | mips_codegen->MoveLocation(out_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 910 | calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 911 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 912 | |
| 913 | RestoreLiveRegisters(codegen, locations); |
| 914 | __ B(GetExitLabel()); |
| 915 | } |
| 916 | |
| 917 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathMIPS"; } |
| 918 | |
| 919 | private: |
| 920 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 921 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 922 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 923 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 924 | if (i != ref && |
| 925 | i != obj && |
| 926 | !codegen->IsCoreCalleeSaveRegister(i) && |
| 927 | !codegen->IsBlockedCoreRegister(i)) { |
| 928 | return static_cast<Register>(i); |
| 929 | } |
| 930 | } |
| 931 | // We shall never fail to find a free caller-save register, as |
| 932 | // there are more than two core caller-save registers on MIPS |
| 933 | // (meaning it is possible to find one which is different from |
| 934 | // `ref` and `obj`). |
| 935 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 936 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 937 | UNREACHABLE(); |
| 938 | } |
| 939 | |
| 940 | const Location out_; |
| 941 | const Location ref_; |
| 942 | const Location obj_; |
| 943 | const uint32_t offset_; |
| 944 | // An additional location containing an index to an array. |
| 945 | // Only used for HArrayGet and the UnsafeGetObject & |
| 946 | // UnsafeGetObjectVolatile intrinsics. |
| 947 | const Location index_; |
| 948 | |
| 949 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS); |
| 950 | }; |
| 951 | |
| 952 | // Slow path generating a read barrier for a GC root. |
| 953 | class ReadBarrierForRootSlowPathMIPS : public SlowPathCodeMIPS { |
| 954 | public: |
| 955 | ReadBarrierForRootSlowPathMIPS(HInstruction* instruction, Location out, Location root) |
| 956 | : SlowPathCodeMIPS(instruction), out_(out), root_(root) { |
| 957 | DCHECK(kEmitCompilerReadBarrier); |
| 958 | } |
| 959 | |
| 960 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 961 | LocationSummary* locations = instruction_->GetLocations(); |
| 962 | Register reg_out = out_.AsRegister<Register>(); |
| 963 | DCHECK(locations->CanCall()); |
| 964 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 965 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 966 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 967 | << instruction_->DebugName(); |
| 968 | |
| 969 | __ Bind(GetEntryLabel()); |
| 970 | SaveLiveRegisters(codegen, locations); |
| 971 | |
| 972 | InvokeRuntimeCallingConvention calling_convention; |
| 973 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 974 | mips_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 975 | root_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 976 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 977 | mips_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 978 | instruction_, |
| 979 | instruction_->GetDexPc(), |
| 980 | this); |
| 981 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 982 | mips_codegen->MoveLocation(out_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 983 | calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 984 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 985 | |
| 986 | RestoreLiveRegisters(codegen, locations); |
| 987 | __ B(GetExitLabel()); |
| 988 | } |
| 989 | |
| 990 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS"; } |
| 991 | |
| 992 | private: |
| 993 | const Location out_; |
| 994 | const Location root_; |
| 995 | |
| 996 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS); |
| 997 | }; |
| 998 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 999 | CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 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), |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1016 | assembler_(graph->GetAllocator(), |
| 1017 | compiler_options.GetInstructionSetFeatures()->AsMipsInstructionSetFeatures()), |
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)), |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1026 | boot_image_intrinsic_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1027 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1028 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1029 | clobbered_ra_(false) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1030 | // Save RA (containing the return address) to mimic Quick. |
| 1031 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 1032 | } |
| 1033 | |
| 1034 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 1035 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1036 | #define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1037 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1038 | |
| 1039 | void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) { |
| 1040 | // Ensure that we fix up branches. |
| 1041 | __ FinalizeCode(); |
| 1042 | |
| 1043 | // Adjust native pc offsets in stack maps. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1044 | StackMapStream* stack_map_stream = GetStackMapStream(); |
| 1045 | for (size_t i = 0, num = stack_map_stream->GetNumberOfStackMaps(); i != num; ++i) { |
David Srbecky | d02b23f | 2018-05-29 23:27:22 +0100 | [diff] [blame] | 1046 | uint32_t old_position = stack_map_stream->GetStackMapNativePcOffset(i); |
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 | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1600 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 1601 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 1602 | const DexFile* target_dex_file, |
| 1603 | uint32_t pc_insn_offset, |
| 1604 | uint32_t boot_image_offset) { |
| 1605 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 1606 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1609 | void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1610 | DCHECK(linker_patches->empty()); |
| 1611 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1612 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1613 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1614 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1615 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1616 | boot_image_string_patches_.size() + |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1617 | string_bss_entry_patches_.size() + |
| 1618 | boot_image_intrinsic_patches_.size(); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1619 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1620 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1621 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1622 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1623 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1624 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1625 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1626 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1627 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 1628 | boot_image_intrinsic_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1629 | } else { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1630 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1631 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1632 | DCHECK(boot_image_type_patches_.empty()); |
| 1633 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1634 | DCHECK(boot_image_intrinsic_patches_.empty()); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1635 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1636 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1637 | method_bss_entry_patches_, linker_patches); |
| 1638 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1639 | type_bss_entry_patches_, linker_patches); |
| 1640 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1641 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1642 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1645 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageIntrinsicPatch( |
| 1646 | uint32_t intrinsic_data, |
| 1647 | const PcRelativePatchInfo* info_high) { |
| 1648 | return NewPcRelativePatch( |
| 1649 | /* dex_file */ nullptr, intrinsic_data, info_high, &boot_image_intrinsic_patches_); |
| 1650 | } |
| 1651 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1652 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageRelRoPatch( |
| 1653 | uint32_t boot_image_offset, |
| 1654 | const PcRelativePatchInfo* info_high) { |
| 1655 | return NewPcRelativePatch( |
| 1656 | /* dex_file */ nullptr, boot_image_offset, info_high, &boot_image_method_patches_); |
| 1657 | } |
| 1658 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1659 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageMethodPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1660 | MethodReference target_method, |
| 1661 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1662 | return NewPcRelativePatch( |
| 1663 | 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] | 1664 | } |
| 1665 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1666 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewMethodBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1667 | MethodReference target_method, |
| 1668 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1669 | return NewPcRelativePatch( |
| 1670 | 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] | 1671 | } |
| 1672 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1673 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageTypePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1674 | const DexFile& dex_file, |
| 1675 | dex::TypeIndex type_index, |
| 1676 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1677 | 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] | 1678 | } |
| 1679 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1680 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewTypeBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1681 | const DexFile& dex_file, |
| 1682 | dex::TypeIndex type_index, |
| 1683 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1684 | 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] | 1685 | } |
| 1686 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1687 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewBootImageStringPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1688 | const DexFile& dex_file, |
| 1689 | dex::StringIndex string_index, |
| 1690 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1691 | return NewPcRelativePatch( |
| 1692 | &dex_file, string_index.index_, info_high, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1693 | } |
| 1694 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1695 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewStringBssEntryPatch( |
| 1696 | const DexFile& dex_file, |
| 1697 | dex::StringIndex string_index, |
| 1698 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1699 | return NewPcRelativePatch(&dex_file, string_index.index_, info_high, &string_bss_entry_patches_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1700 | } |
| 1701 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1702 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1703 | const DexFile* dex_file, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1704 | uint32_t offset_or_index, |
| 1705 | const PcRelativePatchInfo* info_high, |
| 1706 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1707 | patches->emplace_back(dex_file, offset_or_index, info_high); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1708 | return &patches->back(); |
| 1709 | } |
| 1710 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1711 | Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1712 | return map->GetOrCreate( |
| 1713 | value, |
| 1714 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1715 | } |
| 1716 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1717 | Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1718 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1721 | void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high, |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1722 | Register out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1723 | Register base) { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1724 | DCHECK(!info_high->patch_info_high); |
Alexey Frunze | 6079dca | 2017-05-28 19:10:28 -0700 | [diff] [blame] | 1725 | DCHECK_NE(out, base); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1726 | bool reordering = __ SetReorder(false); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1727 | if (GetInstructionSetFeatures().IsR6()) { |
| 1728 | DCHECK_EQ(base, ZERO); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1729 | __ Bind(&info_high->label); |
| 1730 | __ Bind(&info_high->pc_rel_label); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1731 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1732 | __ Auipc(out, /* placeholder */ 0x1234); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1733 | __ SetReorder(reordering); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1734 | } else { |
| 1735 | // If base is ZERO, emit NAL to obtain the actual base. |
| 1736 | if (base == ZERO) { |
| 1737 | // Generate a dummy PC-relative call to obtain PC. |
| 1738 | __ Nal(); |
| 1739 | } |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1740 | __ Bind(&info_high->label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1741 | __ Lui(out, /* placeholder */ 0x1234); |
| 1742 | // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding |
| 1743 | // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler. |
| 1744 | if (base == ZERO) { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1745 | __ Bind(&info_high->pc_rel_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1746 | } |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1747 | __ SetReorder(reordering); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1748 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1749 | __ Addu(out, out, (base == ZERO) ? RA : base); |
| 1750 | } |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1751 | // 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] | 1752 | // offset to `out` (e.g. lw, jialc, addiu). |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1755 | void CodeGeneratorMIPS::LoadBootImageAddress(Register reg, uint32_t boot_image_reference) { |
| 1756 | if (GetCompilerOptions().IsBootImage()) { |
| 1757 | PcRelativePatchInfo* info_high = NewBootImageIntrinsicPatch(boot_image_reference); |
| 1758 | PcRelativePatchInfo* info_low = NewBootImageIntrinsicPatch(boot_image_reference, info_high); |
| 1759 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, /* base */ ZERO); |
| 1760 | __ Addiu(reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame^] | 1761 | } else if (Runtime::Current()->IsAotCompiler()) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1762 | PcRelativePatchInfo* info_high = NewBootImageRelRoPatch(boot_image_reference); |
| 1763 | PcRelativePatchInfo* info_low = NewBootImageRelRoPatch(boot_image_reference, info_high); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1764 | EmitPcRelativeAddressPlaceholderHigh(info_high, reg, /* base */ ZERO); |
| 1765 | __ Lw(reg, reg, /* placeholder */ 0x5678, &info_low->label); |
| 1766 | } else { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame^] | 1767 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1768 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1769 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1770 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1771 | __ LoadConst32(reg, dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address))); |
| 1772 | } |
| 1773 | } |
| 1774 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1775 | void CodeGeneratorMIPS::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 1776 | uint32_t boot_image_offset) { |
| 1777 | DCHECK(invoke->IsStatic()); |
| 1778 | InvokeRuntimeCallingConvention calling_convention; |
| 1779 | Register argument = calling_convention.GetRegisterAt(0); |
| 1780 | if (GetCompilerOptions().IsBootImage()) { |
| 1781 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 1782 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 1783 | MethodReference target_method = invoke->GetTargetMethod(); |
| 1784 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 1785 | PcRelativePatchInfo* info_high = NewBootImageTypePatch(*target_method.dex_file, type_idx); |
| 1786 | PcRelativePatchInfo* info_low = |
| 1787 | NewBootImageTypePatch(*target_method.dex_file, type_idx, info_high); |
| 1788 | EmitPcRelativeAddressPlaceholderHigh(info_high, argument, /* base */ ZERO); |
| 1789 | __ Addiu(argument, argument, /* placeholder */ 0x5678, &info_low->label); |
| 1790 | } else { |
| 1791 | LoadBootImageAddress(argument, boot_image_offset); |
| 1792 | } |
| 1793 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 1794 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 1795 | } |
| 1796 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1797 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootStringPatch( |
| 1798 | const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1799 | dex::StringIndex string_index, |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1800 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1801 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| 1802 | jit_string_patches_.emplace_back(dex_file, string_index.index_); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1803 | return &jit_string_patches_.back(); |
| 1804 | } |
| 1805 | |
| 1806 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootClassPatch( |
| 1807 | const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1808 | dex::TypeIndex type_index, |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1809 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1810 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| 1811 | jit_class_patches_.emplace_back(dex_file, type_index.index_); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1812 | return &jit_class_patches_.back(); |
| 1813 | } |
| 1814 | |
| 1815 | void CodeGeneratorMIPS::PatchJitRootUse(uint8_t* code, |
| 1816 | const uint8_t* roots_data, |
| 1817 | const CodeGeneratorMIPS::JitPatchInfo& info, |
| 1818 | uint64_t index_in_table) const { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1819 | uint32_t high_literal_offset = GetAssembler().GetLabelLocation(&info.high_label); |
| 1820 | uint32_t low_literal_offset = GetAssembler().GetLabelLocation(&info.low_label); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1821 | uintptr_t address = |
| 1822 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1823 | uint32_t addr32 = dchecked_integral_cast<uint32_t>(address); |
| 1824 | // lui reg, addr32_high |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1825 | DCHECK_EQ(code[high_literal_offset + 0], 0x34); |
| 1826 | DCHECK_EQ(code[high_literal_offset + 1], 0x12); |
| 1827 | DCHECK_EQ((code[high_literal_offset + 2] & 0xE0), 0x00); |
| 1828 | DCHECK_EQ(code[high_literal_offset + 3], 0x3C); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1829 | // instr reg, reg, addr32_low |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1830 | DCHECK_EQ(code[low_literal_offset + 0], 0x78); |
| 1831 | DCHECK_EQ(code[low_literal_offset + 1], 0x56); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1832 | 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] | 1833 | // lui reg, addr32_high |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1834 | code[high_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 16); |
| 1835 | code[high_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 24); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1836 | // instr reg, reg, addr32_low |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1837 | code[low_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 0); |
| 1838 | code[low_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 8); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | void CodeGeneratorMIPS::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1842 | for (const JitPatchInfo& info : jit_string_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1843 | StringReference string_reference(&info.target_dex_file, dex::StringIndex(info.index)); |
| 1844 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1845 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1846 | } |
| 1847 | for (const JitPatchInfo& info : jit_class_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1848 | TypeReference type_reference(&info.target_dex_file, dex::TypeIndex(info.index)); |
| 1849 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1850 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1851 | } |
| 1852 | } |
| 1853 | |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1854 | void CodeGeneratorMIPS::MarkGCCard(Register object, |
| 1855 | Register value, |
| 1856 | bool value_can_be_null) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1857 | MipsLabel done; |
| 1858 | Register card = AT; |
| 1859 | Register temp = TMP; |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1860 | if (value_can_be_null) { |
| 1861 | __ Beqz(value, &done); |
| 1862 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1863 | __ LoadFromOffset(kLoadWord, |
| 1864 | card, |
| 1865 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1866 | Thread::CardTableOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1867 | __ Srl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1868 | __ Addu(temp, card, temp); |
| 1869 | __ Sb(card, temp, 0); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1870 | if (value_can_be_null) { |
| 1871 | __ Bind(&done); |
| 1872 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1873 | } |
| 1874 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1875 | void CodeGeneratorMIPS::SetupBlockedRegisters() const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1876 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1877 | blocked_core_registers_[ZERO] = true; |
| 1878 | blocked_core_registers_[K0] = true; |
| 1879 | blocked_core_registers_[K1] = true; |
| 1880 | blocked_core_registers_[GP] = true; |
| 1881 | blocked_core_registers_[SP] = true; |
| 1882 | blocked_core_registers_[RA] = true; |
| 1883 | |
| 1884 | // AT and TMP(T8) are used as temporary/scratch registers |
| 1885 | // (similar to how AT is used by MIPS assemblers). |
| 1886 | blocked_core_registers_[AT] = true; |
| 1887 | blocked_core_registers_[TMP] = true; |
| 1888 | blocked_fpu_registers_[FTMP] = true; |
| 1889 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1890 | if (GetInstructionSetFeatures().HasMsa()) { |
| 1891 | // To be used just for MSA instructions. |
| 1892 | blocked_fpu_registers_[FTMP2] = true; |
| 1893 | } |
| 1894 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1895 | // Reserve suspend and thread registers. |
| 1896 | blocked_core_registers_[S0] = true; |
| 1897 | blocked_core_registers_[TR] = true; |
| 1898 | |
| 1899 | // Reserve T9 for function calls |
| 1900 | blocked_core_registers_[T9] = true; |
| 1901 | |
| 1902 | // Reserve odd-numbered FPU registers. |
| 1903 | for (size_t i = 1; i < kNumberOfFRegisters; i += 2) { |
| 1904 | blocked_fpu_registers_[i] = true; |
| 1905 | } |
| 1906 | |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 1907 | if (GetGraph()->IsDebuggable()) { |
| 1908 | // Stubs do not save callee-save floating point registers. If the graph |
| 1909 | // is debuggable, we need to deal with these registers differently. For |
| 1910 | // now, just block them. |
| 1911 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1912 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1913 | } |
| 1914 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1915 | } |
| 1916 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1917 | size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1918 | __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index); |
| 1919 | return kMipsWordSize; |
| 1920 | } |
| 1921 | |
| 1922 | size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1923 | __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index); |
| 1924 | return kMipsWordSize; |
| 1925 | } |
| 1926 | |
| 1927 | size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1928 | if (GetGraph()->HasSIMD()) { |
| 1929 | __ StoreQToOffset(FRegister(reg_id), SP, stack_index); |
| 1930 | } else { |
| 1931 | __ StoreDToOffset(FRegister(reg_id), SP, stack_index); |
| 1932 | } |
| 1933 | return GetFloatingPointSpillSlotSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1937 | if (GetGraph()->HasSIMD()) { |
| 1938 | __ LoadQFromOffset(FRegister(reg_id), SP, stack_index); |
| 1939 | } else { |
| 1940 | __ LoadDFromOffset(FRegister(reg_id), SP, stack_index); |
| 1941 | } |
| 1942 | return GetFloatingPointSpillSlotSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1946 | stream << Register(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1950 | stream << FRegister(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1951 | } |
| 1952 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1953 | const MipsInstructionSetFeatures& CodeGeneratorMIPS::GetInstructionSetFeatures() const { |
| 1954 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsMipsInstructionSetFeatures(); |
| 1955 | } |
| 1956 | |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1957 | constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16; |
| 1958 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1959 | void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1960 | HInstruction* instruction, |
| 1961 | uint32_t dex_pc, |
| 1962 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1963 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1964 | GenerateInvokeRuntime(GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value(), |
| 1965 | IsDirectEntrypoint(entrypoint)); |
| 1966 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1967 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | void CodeGeneratorMIPS::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1972 | HInstruction* instruction, |
| 1973 | SlowPathCode* slow_path, |
| 1974 | bool direct) { |
| 1975 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1976 | GenerateInvokeRuntime(entry_point_offset, direct); |
| 1977 | } |
| 1978 | |
| 1979 | void CodeGeneratorMIPS::GenerateInvokeRuntime(int32_t entry_point_offset, bool direct) { |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1980 | bool reordering = __ SetReorder(false); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1981 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1982 | __ Jalr(T9); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1983 | if (direct) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1984 | // Reserve argument space on stack (for $a0-$a3) for |
| 1985 | // entrypoints that directly reference native implementations. |
| 1986 | // Called function may use this space to store $a0-$a3 regs. |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1987 | __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1988 | __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1989 | } else { |
| 1990 | __ Nop(); // In delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1991 | } |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1992 | __ SetReorder(reordering); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, |
| 1996 | Register class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1997 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 1998 | const size_t status_byte_offset = |
| 1999 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 2000 | constexpr uint32_t shifted_initialized_value = |
| 2001 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 2002 | |
| 2003 | __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, status_byte_offset); |
Lena Djokic | 3177e10 | 2018-02-28 11:32:40 +0100 | [diff] [blame] | 2004 | __ Sltiu(TMP, TMP, shifted_initialized_value); |
| 2005 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2006 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 2007 | __ Sync(0); |
| 2008 | __ Bind(slow_path->GetExitLabel()); |
| 2009 | } |
| 2010 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2011 | void InstructionCodeGeneratorMIPS::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 2012 | Register temp) { |
| 2013 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 2014 | uint32_t mask = check->GetBitstringMask(); |
| 2015 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 2016 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 2017 | |
| 2018 | if (mask_bits == 16u) { |
| 2019 | // Load only the bitstring part of the status word. |
| 2020 | __ LoadFromOffset( |
| 2021 | kLoadUnsignedHalfword, temp, temp, mirror::Class::StatusOffset().Int32Value()); |
| 2022 | // Compare the bitstring bits using XOR. |
| 2023 | __ Xori(temp, temp, dchecked_integral_cast<uint16_t>(path_to_root)); |
| 2024 | } else { |
| 2025 | // /* uint32_t */ temp = temp->status_ |
| 2026 | __ LoadFromOffset(kLoadWord, temp, temp, mirror::Class::StatusOffset().Int32Value()); |
| 2027 | // Compare the bitstring bits using XOR. |
| 2028 | if (IsUint<16>(path_to_root)) { |
| 2029 | __ Xori(temp, temp, dchecked_integral_cast<uint16_t>(path_to_root)); |
| 2030 | } else { |
| 2031 | __ LoadConst32(TMP, path_to_root); |
| 2032 | __ Xor(temp, temp, TMP); |
| 2033 | } |
| 2034 | // Shift out bits that do not contribute to the comparison. |
| 2035 | __ Sll(temp, temp, 32 - mask_bits); |
| 2036 | } |
| 2037 | } |
| 2038 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2039 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 2040 | __ Sync(0); // Only stype 0 is supported. |
| 2041 | } |
| 2042 | |
| 2043 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2044 | HBasicBlock* successor) { |
| 2045 | SuspendCheckSlowPathMIPS* slow_path = |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 2046 | down_cast<SuspendCheckSlowPathMIPS*>(instruction->GetSlowPath()); |
| 2047 | |
| 2048 | if (slow_path == nullptr) { |
| 2049 | slow_path = |
| 2050 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS(instruction, successor); |
| 2051 | instruction->SetSlowPath(slow_path); |
| 2052 | codegen_->AddSlowPath(slow_path); |
| 2053 | if (successor != nullptr) { |
| 2054 | DCHECK(successor->IsLoopHeader()); |
| 2055 | } |
| 2056 | } else { |
| 2057 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2058 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2059 | |
| 2060 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2061 | TMP, |
| 2062 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2063 | Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2064 | if (successor == nullptr) { |
| 2065 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 2066 | __ Bind(slow_path->GetReturnLabel()); |
| 2067 | } else { |
| 2068 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); |
| 2069 | __ B(slow_path->GetEntryLabel()); |
| 2070 | // slow_path will return to GetLabelOf(successor). |
| 2071 | } |
| 2072 | } |
| 2073 | |
| 2074 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, |
| 2075 | CodeGeneratorMIPS* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2076 | : InstructionCodeGenerator(graph, codegen), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2077 | assembler_(codegen->GetAssembler()), |
| 2078 | codegen_(codegen) {} |
| 2079 | |
| 2080 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 2081 | DCHECK_EQ(instruction->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2082 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2083 | DataType::Type type = instruction->GetResultType(); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2084 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2085 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2086 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2087 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2088 | HInstruction* right = instruction->InputAt(1); |
| 2089 | bool can_use_imm = false; |
| 2090 | if (right->IsConstant()) { |
| 2091 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); |
| 2092 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 2093 | can_use_imm = IsUint<16>(imm); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2094 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2095 | DCHECK(instruction->IsSub() || instruction->IsAdd()); |
| 2096 | if (instruction->IsSub()) { |
| 2097 | imm = -imm; |
| 2098 | } |
| 2099 | if (isR6) { |
| 2100 | bool single_use = right->GetUses().HasExactlyOneElement(); |
| 2101 | int16_t imm_high = High16Bits(imm); |
| 2102 | int16_t imm_low = Low16Bits(imm); |
| 2103 | if (imm_low < 0) { |
| 2104 | imm_high += 1; |
| 2105 | } |
| 2106 | can_use_imm = !((imm_high != 0) && (imm_low != 0)) || single_use; |
| 2107 | } else { |
| 2108 | can_use_imm = IsInt<16>(imm); |
| 2109 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2110 | } |
| 2111 | } |
| 2112 | if (can_use_imm) |
| 2113 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 2114 | else |
| 2115 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2116 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2117 | break; |
| 2118 | } |
| 2119 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2120 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2121 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2122 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2123 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2124 | break; |
| 2125 | } |
| 2126 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2127 | case DataType::Type::kFloat32: |
| 2128 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2129 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 2130 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2131 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2132 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2133 | break; |
| 2134 | |
| 2135 | default: |
| 2136 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2141 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2142 | LocationSummary* locations = instruction->GetLocations(); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2143 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2144 | |
| 2145 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2146 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2147 | Register dst = locations->Out().AsRegister<Register>(); |
| 2148 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2149 | Location rhs_location = locations->InAt(1); |
| 2150 | |
| 2151 | Register rhs_reg = ZERO; |
| 2152 | int32_t rhs_imm = 0; |
| 2153 | bool use_imm = rhs_location.IsConstant(); |
| 2154 | if (use_imm) { |
| 2155 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2156 | } else { |
| 2157 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2158 | } |
| 2159 | |
| 2160 | if (instruction->IsAnd()) { |
| 2161 | if (use_imm) |
| 2162 | __ Andi(dst, lhs, rhs_imm); |
| 2163 | else |
| 2164 | __ And(dst, lhs, rhs_reg); |
| 2165 | } else if (instruction->IsOr()) { |
| 2166 | if (use_imm) |
| 2167 | __ Ori(dst, lhs, rhs_imm); |
| 2168 | else |
| 2169 | __ Or(dst, lhs, rhs_reg); |
| 2170 | } else if (instruction->IsXor()) { |
| 2171 | if (use_imm) |
| 2172 | __ Xori(dst, lhs, rhs_imm); |
| 2173 | else |
| 2174 | __ Xor(dst, lhs, rhs_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2175 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2176 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 2177 | if (use_imm) { |
| 2178 | if (instruction->IsSub()) { |
| 2179 | rhs_imm = -rhs_imm; |
| 2180 | } |
| 2181 | if (IsInt<16>(rhs_imm)) { |
| 2182 | __ Addiu(dst, lhs, rhs_imm); |
| 2183 | } else { |
| 2184 | DCHECK(isR6); |
| 2185 | int16_t rhs_imm_high = High16Bits(rhs_imm); |
| 2186 | int16_t rhs_imm_low = Low16Bits(rhs_imm); |
| 2187 | if (rhs_imm_low < 0) { |
| 2188 | rhs_imm_high += 1; |
| 2189 | } |
| 2190 | __ Aui(dst, lhs, rhs_imm_high); |
| 2191 | if (rhs_imm_low != 0) { |
| 2192 | __ Addiu(dst, dst, rhs_imm_low); |
| 2193 | } |
| 2194 | } |
| 2195 | } else if (instruction->IsAdd()) { |
| 2196 | __ Addu(dst, lhs, rhs_reg); |
| 2197 | } else { |
| 2198 | DCHECK(instruction->IsSub()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2199 | __ Subu(dst, lhs, rhs_reg); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2200 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2201 | } |
| 2202 | break; |
| 2203 | } |
| 2204 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2205 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2206 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2207 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2208 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2209 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2210 | Location rhs_location = locations->InAt(1); |
| 2211 | bool use_imm = rhs_location.IsConstant(); |
| 2212 | if (!use_imm) { |
| 2213 | Register rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 2214 | Register rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 2215 | if (instruction->IsAnd()) { |
| 2216 | __ And(dst_low, lhs_low, rhs_low); |
| 2217 | __ And(dst_high, lhs_high, rhs_high); |
| 2218 | } else if (instruction->IsOr()) { |
| 2219 | __ Or(dst_low, lhs_low, rhs_low); |
| 2220 | __ Or(dst_high, lhs_high, rhs_high); |
| 2221 | } else if (instruction->IsXor()) { |
| 2222 | __ Xor(dst_low, lhs_low, rhs_low); |
| 2223 | __ Xor(dst_high, lhs_high, rhs_high); |
| 2224 | } else if (instruction->IsAdd()) { |
| 2225 | if (lhs_low == rhs_low) { |
| 2226 | // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs. |
| 2227 | __ Slt(TMP, lhs_low, ZERO); |
| 2228 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2229 | } else { |
| 2230 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2231 | // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged. |
| 2232 | __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low); |
| 2233 | } |
| 2234 | __ Addu(dst_high, lhs_high, rhs_high); |
| 2235 | __ Addu(dst_high, dst_high, TMP); |
| 2236 | } else { |
| 2237 | DCHECK(instruction->IsSub()); |
| 2238 | __ Sltu(TMP, lhs_low, rhs_low); |
| 2239 | __ Subu(dst_low, lhs_low, rhs_low); |
| 2240 | __ Subu(dst_high, lhs_high, rhs_high); |
| 2241 | __ Subu(dst_high, dst_high, TMP); |
| 2242 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2243 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2244 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 2245 | if (instruction->IsOr()) { |
| 2246 | uint32_t low = Low32Bits(value); |
| 2247 | uint32_t high = High32Bits(value); |
| 2248 | if (IsUint<16>(low)) { |
| 2249 | if (dst_low != lhs_low || low != 0) { |
| 2250 | __ Ori(dst_low, lhs_low, low); |
| 2251 | } |
| 2252 | } else { |
| 2253 | __ LoadConst32(TMP, low); |
| 2254 | __ Or(dst_low, lhs_low, TMP); |
| 2255 | } |
| 2256 | if (IsUint<16>(high)) { |
| 2257 | if (dst_high != lhs_high || high != 0) { |
| 2258 | __ Ori(dst_high, lhs_high, high); |
| 2259 | } |
| 2260 | } else { |
| 2261 | if (high != low) { |
| 2262 | __ LoadConst32(TMP, high); |
| 2263 | } |
| 2264 | __ Or(dst_high, lhs_high, TMP); |
| 2265 | } |
| 2266 | } else if (instruction->IsXor()) { |
| 2267 | uint32_t low = Low32Bits(value); |
| 2268 | uint32_t high = High32Bits(value); |
| 2269 | if (IsUint<16>(low)) { |
| 2270 | if (dst_low != lhs_low || low != 0) { |
| 2271 | __ Xori(dst_low, lhs_low, low); |
| 2272 | } |
| 2273 | } else { |
| 2274 | __ LoadConst32(TMP, low); |
| 2275 | __ Xor(dst_low, lhs_low, TMP); |
| 2276 | } |
| 2277 | if (IsUint<16>(high)) { |
| 2278 | if (dst_high != lhs_high || high != 0) { |
| 2279 | __ Xori(dst_high, lhs_high, high); |
| 2280 | } |
| 2281 | } else { |
| 2282 | if (high != low) { |
| 2283 | __ LoadConst32(TMP, high); |
| 2284 | } |
| 2285 | __ Xor(dst_high, lhs_high, TMP); |
| 2286 | } |
| 2287 | } else if (instruction->IsAnd()) { |
| 2288 | uint32_t low = Low32Bits(value); |
| 2289 | uint32_t high = High32Bits(value); |
| 2290 | if (IsUint<16>(low)) { |
| 2291 | __ Andi(dst_low, lhs_low, low); |
| 2292 | } else if (low != 0xFFFFFFFF) { |
| 2293 | __ LoadConst32(TMP, low); |
| 2294 | __ And(dst_low, lhs_low, TMP); |
| 2295 | } else if (dst_low != lhs_low) { |
| 2296 | __ Move(dst_low, lhs_low); |
| 2297 | } |
| 2298 | if (IsUint<16>(high)) { |
| 2299 | __ Andi(dst_high, lhs_high, high); |
| 2300 | } else if (high != 0xFFFFFFFF) { |
| 2301 | if (high != low) { |
| 2302 | __ LoadConst32(TMP, high); |
| 2303 | } |
| 2304 | __ And(dst_high, lhs_high, TMP); |
| 2305 | } else if (dst_high != lhs_high) { |
| 2306 | __ Move(dst_high, lhs_high); |
| 2307 | } |
| 2308 | } else { |
| 2309 | if (instruction->IsSub()) { |
| 2310 | value = -value; |
| 2311 | } else { |
| 2312 | DCHECK(instruction->IsAdd()); |
| 2313 | } |
| 2314 | int32_t low = Low32Bits(value); |
| 2315 | int32_t high = High32Bits(value); |
| 2316 | if (IsInt<16>(low)) { |
| 2317 | if (dst_low != lhs_low || low != 0) { |
| 2318 | __ Addiu(dst_low, lhs_low, low); |
| 2319 | } |
| 2320 | if (low != 0) { |
| 2321 | __ Sltiu(AT, dst_low, low); |
| 2322 | } |
| 2323 | } else { |
| 2324 | __ LoadConst32(TMP, low); |
| 2325 | __ Addu(dst_low, lhs_low, TMP); |
| 2326 | __ Sltu(AT, dst_low, TMP); |
| 2327 | } |
| 2328 | if (IsInt<16>(high)) { |
| 2329 | if (dst_high != lhs_high || high != 0) { |
| 2330 | __ Addiu(dst_high, lhs_high, high); |
| 2331 | } |
| 2332 | } else { |
| 2333 | if (high != low) { |
| 2334 | __ LoadConst32(TMP, high); |
| 2335 | } |
| 2336 | __ Addu(dst_high, lhs_high, TMP); |
| 2337 | } |
| 2338 | if (low != 0) { |
| 2339 | __ Addu(dst_high, dst_high, AT); |
| 2340 | } |
| 2341 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2342 | } |
| 2343 | break; |
| 2344 | } |
| 2345 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2346 | case DataType::Type::kFloat32: |
| 2347 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2348 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2349 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2350 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2351 | if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2352 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2353 | __ AddS(dst, lhs, rhs); |
| 2354 | } else { |
| 2355 | __ AddD(dst, lhs, rhs); |
| 2356 | } |
| 2357 | } else { |
| 2358 | DCHECK(instruction->IsSub()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2359 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2360 | __ SubS(dst, lhs, rhs); |
| 2361 | } else { |
| 2362 | __ SubD(dst, lhs, rhs); |
| 2363 | } |
| 2364 | } |
| 2365 | break; |
| 2366 | } |
| 2367 | |
| 2368 | default: |
| 2369 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 2370 | } |
| 2371 | } |
| 2372 | |
| 2373 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2374 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2375 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2376 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2377 | DataType::Type type = instr->GetResultType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2378 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2379 | case DataType::Type::kInt32: |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2380 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2381 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2382 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2383 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2384 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2385 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2386 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2387 | locations->SetOut(Location::RequiresRegister()); |
| 2388 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2389 | default: |
| 2390 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2391 | } |
| 2392 | } |
| 2393 | |
| 2394 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; |
| 2395 | |
| 2396 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2397 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2398 | LocationSummary* locations = instr->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2399 | DataType::Type type = instr->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2400 | |
| 2401 | Location rhs_location = locations->InAt(1); |
| 2402 | bool use_imm = rhs_location.IsConstant(); |
| 2403 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); |
| 2404 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2405 | const uint32_t shift_mask = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2406 | (type == DataType::Type::kInt32) ? kMaxIntShiftDistance : kMaxLongShiftDistance; |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2407 | const uint32_t shift_value = rhs_imm & shift_mask; |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2408 | // Are the INS (Insert Bit Field) and ROTR instructions supported? |
| 2409 | bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2410 | |
| 2411 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2412 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2413 | Register dst = locations->Out().AsRegister<Register>(); |
| 2414 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2415 | if (use_imm) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2416 | if (shift_value == 0) { |
| 2417 | if (dst != lhs) { |
| 2418 | __ Move(dst, lhs); |
| 2419 | } |
| 2420 | } else if (instr->IsShl()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2421 | __ Sll(dst, lhs, shift_value); |
| 2422 | } else if (instr->IsShr()) { |
| 2423 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2424 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2425 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2426 | } else { |
| 2427 | if (has_ins_rotr) { |
| 2428 | __ Rotr(dst, lhs, shift_value); |
| 2429 | } else { |
| 2430 | __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask); |
| 2431 | __ Srl(dst, lhs, shift_value); |
| 2432 | __ Or(dst, dst, TMP); |
| 2433 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2434 | } |
| 2435 | } else { |
| 2436 | if (instr->IsShl()) { |
| 2437 | __ Sllv(dst, lhs, rhs_reg); |
| 2438 | } else if (instr->IsShr()) { |
| 2439 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2440 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2441 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2442 | } else { |
| 2443 | if (has_ins_rotr) { |
| 2444 | __ Rotrv(dst, lhs, rhs_reg); |
| 2445 | } else { |
| 2446 | __ Subu(TMP, ZERO, rhs_reg); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2447 | // 32-bit shift instructions use the 5 least significant bits of the shift count, so |
| 2448 | // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case |
| 2449 | // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out |
| 2450 | // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`, |
| 2451 | // IOW, the OR'd values are equal. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2452 | __ Sllv(TMP, lhs, TMP); |
| 2453 | __ Srlv(dst, lhs, rhs_reg); |
| 2454 | __ Or(dst, dst, TMP); |
| 2455 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2456 | } |
| 2457 | } |
| 2458 | break; |
| 2459 | } |
| 2460 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2461 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2462 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2463 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2464 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2465 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2466 | if (use_imm) { |
| 2467 | if (shift_value == 0) { |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 2468 | codegen_->MoveLocation(locations->Out(), locations->InAt(0), type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2469 | } else if (shift_value < kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2470 | if (has_ins_rotr) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2471 | if (instr->IsShl()) { |
| 2472 | __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2473 | __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value); |
| 2474 | __ Sll(dst_low, lhs_low, shift_value); |
| 2475 | } else if (instr->IsShr()) { |
| 2476 | __ Srl(dst_low, lhs_low, shift_value); |
| 2477 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2478 | __ Sra(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2479 | } else if (instr->IsUShr()) { |
| 2480 | __ Srl(dst_low, lhs_low, shift_value); |
| 2481 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2482 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2483 | } else { |
| 2484 | __ Srl(dst_low, lhs_low, shift_value); |
| 2485 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2486 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2487 | __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2488 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2489 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2490 | if (instr->IsShl()) { |
| 2491 | __ Sll(dst_low, lhs_low, shift_value); |
| 2492 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); |
| 2493 | __ Sll(dst_high, lhs_high, shift_value); |
| 2494 | __ Or(dst_high, dst_high, TMP); |
| 2495 | } else if (instr->IsShr()) { |
| 2496 | __ Sra(dst_high, lhs_high, shift_value); |
| 2497 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2498 | __ Srl(dst_low, lhs_low, shift_value); |
| 2499 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2500 | } else if (instr->IsUShr()) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2501 | __ Srl(dst_high, lhs_high, shift_value); |
| 2502 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2503 | __ Srl(dst_low, lhs_low, shift_value); |
| 2504 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2505 | } else { |
| 2506 | __ Srl(TMP, lhs_low, shift_value); |
| 2507 | __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value); |
| 2508 | __ Or(dst_low, dst_low, TMP); |
| 2509 | __ Srl(TMP, lhs_high, shift_value); |
| 2510 | __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2511 | __ Or(dst_high, dst_high, TMP); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2512 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2513 | } |
| 2514 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2515 | const uint32_t shift_value_high = shift_value - kMipsBitsPerWord; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2516 | if (instr->IsShl()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2517 | __ Sll(dst_high, lhs_low, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2518 | __ Move(dst_low, ZERO); |
| 2519 | } else if (instr->IsShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2520 | __ Sra(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2521 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2522 | } else if (instr->IsUShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2523 | __ Srl(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2524 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2525 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2526 | if (shift_value == kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2527 | // 64-bit rotation by 32 is just a swap. |
| 2528 | __ Move(dst_low, lhs_high); |
| 2529 | __ Move(dst_high, lhs_low); |
| 2530 | } else { |
| 2531 | if (has_ins_rotr) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2532 | __ Srl(dst_low, lhs_high, shift_value_high); |
| 2533 | __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high); |
| 2534 | __ Srl(dst_high, lhs_low, shift_value_high); |
| 2535 | __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2536 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2537 | __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high); |
| 2538 | __ Srl(dst_low, lhs_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2539 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2540 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high); |
| 2541 | __ Srl(dst_high, lhs_low, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2542 | __ Or(dst_high, dst_high, TMP); |
| 2543 | } |
| 2544 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2545 | } |
| 2546 | } |
| 2547 | } else { |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2548 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2549 | MipsLabel done; |
| 2550 | if (instr->IsShl()) { |
| 2551 | __ Sllv(dst_low, lhs_low, rhs_reg); |
| 2552 | __ Nor(AT, ZERO, rhs_reg); |
| 2553 | __ Srl(TMP, lhs_low, 1); |
| 2554 | __ Srlv(TMP, TMP, AT); |
| 2555 | __ Sllv(dst_high, lhs_high, rhs_reg); |
| 2556 | __ Or(dst_high, dst_high, TMP); |
| 2557 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2558 | if (isR6) { |
| 2559 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2560 | __ Move(dst_high, dst_low); |
| 2561 | __ Move(dst_low, ZERO); |
| 2562 | } else { |
| 2563 | __ Movn(dst_high, dst_low, TMP); |
| 2564 | __ Movn(dst_low, ZERO, TMP); |
| 2565 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2566 | } else if (instr->IsShr()) { |
| 2567 | __ Srav(dst_high, lhs_high, rhs_reg); |
| 2568 | __ Nor(AT, ZERO, rhs_reg); |
| 2569 | __ Sll(TMP, lhs_high, 1); |
| 2570 | __ Sllv(TMP, TMP, AT); |
| 2571 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2572 | __ Or(dst_low, dst_low, TMP); |
| 2573 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2574 | if (isR6) { |
| 2575 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2576 | __ Move(dst_low, dst_high); |
| 2577 | __ Sra(dst_high, dst_high, 31); |
| 2578 | } else { |
| 2579 | __ Sra(AT, dst_high, 31); |
| 2580 | __ Movn(dst_low, dst_high, TMP); |
| 2581 | __ Movn(dst_high, AT, TMP); |
| 2582 | } |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2583 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2584 | __ Srlv(dst_high, lhs_high, rhs_reg); |
| 2585 | __ Nor(AT, ZERO, rhs_reg); |
| 2586 | __ Sll(TMP, lhs_high, 1); |
| 2587 | __ Sllv(TMP, TMP, AT); |
| 2588 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2589 | __ Or(dst_low, dst_low, TMP); |
| 2590 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2591 | if (isR6) { |
| 2592 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2593 | __ Move(dst_low, dst_high); |
| 2594 | __ Move(dst_high, ZERO); |
| 2595 | } else { |
| 2596 | __ Movn(dst_low, dst_high, TMP); |
| 2597 | __ Movn(dst_high, ZERO, TMP); |
| 2598 | } |
| 2599 | } else { // Rotate. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2600 | __ Nor(AT, ZERO, rhs_reg); |
| 2601 | __ Srlv(TMP, lhs_low, rhs_reg); |
| 2602 | __ Sll(dst_low, lhs_high, 1); |
| 2603 | __ Sllv(dst_low, dst_low, AT); |
| 2604 | __ Or(dst_low, dst_low, TMP); |
| 2605 | __ Srlv(TMP, lhs_high, rhs_reg); |
| 2606 | __ Sll(dst_high, lhs_low, 1); |
| 2607 | __ Sllv(dst_high, dst_high, AT); |
| 2608 | __ Or(dst_high, dst_high, TMP); |
| 2609 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2610 | if (isR6) { |
| 2611 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2612 | __ Move(TMP, dst_high); |
| 2613 | __ Move(dst_high, dst_low); |
| 2614 | __ Move(dst_low, TMP); |
| 2615 | } else { |
| 2616 | __ Movn(AT, dst_high, TMP); |
| 2617 | __ Movn(dst_high, dst_low, TMP); |
| 2618 | __ Movn(dst_low, AT, TMP); |
| 2619 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2620 | } |
| 2621 | __ Bind(&done); |
| 2622 | } |
| 2623 | break; |
| 2624 | } |
| 2625 | |
| 2626 | default: |
| 2627 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2628 | } |
| 2629 | } |
| 2630 | |
| 2631 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { |
| 2632 | HandleBinaryOp(instruction); |
| 2633 | } |
| 2634 | |
| 2635 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { |
| 2636 | HandleBinaryOp(instruction); |
| 2637 | } |
| 2638 | |
| 2639 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { |
| 2640 | HandleBinaryOp(instruction); |
| 2641 | } |
| 2642 | |
| 2643 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { |
| 2644 | HandleBinaryOp(instruction); |
| 2645 | } |
| 2646 | |
| 2647 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2648 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2649 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2650 | kEmitCompilerReadBarrier && (type == DataType::Type::kReference); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2651 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2652 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2653 | object_array_get_with_read_barrier |
| 2654 | ? LocationSummary::kCallOnSlowPath |
| 2655 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 2656 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2657 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2658 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2659 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2660 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2661 | if (DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2662 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2663 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2664 | // The output overlaps in the case of an object array get with |
| 2665 | // read barriers enabled: we do not want the move to overwrite the |
| 2666 | // array's location, as we need it to emit the read barrier. |
| 2667 | locations->SetOut(Location::RequiresRegister(), |
| 2668 | object_array_get_with_read_barrier |
| 2669 | ? Location::kOutputOverlap |
| 2670 | : Location::kNoOutputOverlap); |
| 2671 | } |
| 2672 | // We need a temporary register for the read barrier marking slow |
| 2673 | // path in CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier. |
| 2674 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2675 | bool temp_needed = instruction->GetIndex()->IsConstant() |
| 2676 | ? !kBakerReadBarrierThunksEnableForFields |
| 2677 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2678 | if (temp_needed) { |
| 2679 | locations->AddTemp(Location::RequiresRegister()); |
| 2680 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2681 | } |
| 2682 | } |
| 2683 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2684 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS* codegen) { |
| 2685 | auto null_checker = [codegen, instruction]() { |
| 2686 | codegen->MaybeRecordImplicitNullCheck(instruction); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2687 | }; |
| 2688 | return null_checker; |
| 2689 | } |
| 2690 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2691 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 2692 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2693 | Location obj_loc = locations->InAt(0); |
| 2694 | Register obj = obj_loc.AsRegister<Register>(); |
| 2695 | Location out_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2696 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2697 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2698 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2699 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2700 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2701 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2702 | instruction->IsStringCharAt(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2703 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2704 | case DataType::Type::kBool: |
| 2705 | case DataType::Type::kUint8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2706 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2707 | if (index.IsConstant()) { |
| 2708 | size_t offset = |
| 2709 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2710 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2711 | } else { |
| 2712 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2713 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2714 | } |
| 2715 | break; |
| 2716 | } |
| 2717 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2718 | case DataType::Type::kInt8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2719 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2720 | if (index.IsConstant()) { |
| 2721 | size_t offset = |
| 2722 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2723 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2724 | } else { |
| 2725 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2726 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2727 | } |
| 2728 | break; |
| 2729 | } |
| 2730 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2731 | case DataType::Type::kUint16: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2732 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2733 | if (maybe_compressed_char_at) { |
| 2734 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2735 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
| 2736 | __ Sll(TMP, TMP, 31); // Extract compression flag into the most significant bit of TMP. |
| 2737 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2738 | "Expecting 0=compressed, 1=uncompressed"); |
| 2739 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2740 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2741 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2742 | if (maybe_compressed_char_at) { |
| 2743 | MipsLabel uncompressed_load, done; |
| 2744 | __ Bnez(TMP, &uncompressed_load); |
| 2745 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2746 | out, |
| 2747 | obj, |
| 2748 | data_offset + (const_index << TIMES_1)); |
| 2749 | __ B(&done); |
| 2750 | __ Bind(&uncompressed_load); |
| 2751 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2752 | out, |
| 2753 | obj, |
| 2754 | data_offset + (const_index << TIMES_2)); |
| 2755 | __ Bind(&done); |
| 2756 | } else { |
| 2757 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2758 | out, |
| 2759 | obj, |
| 2760 | data_offset + (const_index << TIMES_2), |
| 2761 | null_checker); |
| 2762 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2763 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2764 | Register index_reg = index.AsRegister<Register>(); |
| 2765 | if (maybe_compressed_char_at) { |
| 2766 | MipsLabel uncompressed_load, done; |
| 2767 | __ Bnez(TMP, &uncompressed_load); |
| 2768 | __ Addu(TMP, obj, index_reg); |
| 2769 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2770 | __ B(&done); |
| 2771 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2772 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2773 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2774 | __ Bind(&done); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2775 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2776 | __ Addu(TMP, index_reg, obj); |
| 2777 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2778 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2779 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2780 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
| 2781 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2782 | } |
| 2783 | break; |
| 2784 | } |
| 2785 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2786 | case DataType::Type::kInt16: { |
| 2787 | Register out = out_loc.AsRegister<Register>(); |
| 2788 | if (index.IsConstant()) { |
| 2789 | size_t offset = |
| 2790 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2791 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2792 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2793 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2794 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2795 | } else { |
| 2796 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_2, TMP); |
| 2797 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
| 2798 | } |
| 2799 | break; |
| 2800 | } |
| 2801 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2802 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2803 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2804 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2805 | if (index.IsConstant()) { |
| 2806 | size_t offset = |
| 2807 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2808 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2809 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2810 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2811 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2812 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2813 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2814 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2815 | } |
| 2816 | break; |
| 2817 | } |
| 2818 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2819 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2820 | static_assert( |
| 2821 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2822 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2823 | // /* HeapReference<Object> */ out = |
| 2824 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2825 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2826 | bool temp_needed = index.IsConstant() |
| 2827 | ? !kBakerReadBarrierThunksEnableForFields |
| 2828 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2829 | Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2830 | // Note that a potential implicit null check is handled in this |
| 2831 | // CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier call. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2832 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 2833 | if (index.IsConstant()) { |
| 2834 | // Array load with a constant index can be treated as a field load. |
| 2835 | size_t offset = |
| 2836 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2837 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2838 | out_loc, |
| 2839 | obj, |
| 2840 | offset, |
| 2841 | temp, |
| 2842 | /* needs_null_check */ false); |
| 2843 | } else { |
| 2844 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2845 | out_loc, |
| 2846 | obj, |
| 2847 | data_offset, |
| 2848 | index, |
| 2849 | temp, |
| 2850 | /* needs_null_check */ false); |
| 2851 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2852 | } else { |
| 2853 | Register out = out_loc.AsRegister<Register>(); |
| 2854 | if (index.IsConstant()) { |
| 2855 | size_t offset = |
| 2856 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2857 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
| 2858 | // If read barriers are enabled, emit read barriers other than |
| 2859 | // Baker's using a slow path (and also unpoison the loaded |
| 2860 | // reference, if heap poisoning is enabled). |
| 2861 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2862 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2863 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2864 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
| 2865 | // If read barriers are enabled, emit read barriers other than |
| 2866 | // Baker's using a slow path (and also unpoison the loaded |
| 2867 | // reference, if heap poisoning is enabled). |
| 2868 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2869 | out_loc, |
| 2870 | out_loc, |
| 2871 | obj_loc, |
| 2872 | data_offset, |
| 2873 | index); |
| 2874 | } |
| 2875 | } |
| 2876 | break; |
| 2877 | } |
| 2878 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2879 | case DataType::Type::kInt64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2880 | Register out = out_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2881 | if (index.IsConstant()) { |
| 2882 | size_t offset = |
| 2883 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2884 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2885 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2886 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2887 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2888 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2889 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2890 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2891 | } |
| 2892 | break; |
| 2893 | } |
| 2894 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2895 | case DataType::Type::kFloat32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2896 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2897 | if (index.IsConstant()) { |
| 2898 | size_t offset = |
| 2899 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2900 | __ LoadSFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2901 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2902 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2903 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2904 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2905 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2906 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2907 | } |
| 2908 | break; |
| 2909 | } |
| 2910 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2911 | case DataType::Type::kFloat64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2912 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2913 | if (index.IsConstant()) { |
| 2914 | size_t offset = |
| 2915 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2916 | __ LoadDFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2917 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2918 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2919 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2920 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2921 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2922 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2923 | } |
| 2924 | break; |
| 2925 | } |
| 2926 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2927 | case DataType::Type::kUint32: |
| 2928 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2929 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2930 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2931 | UNREACHABLE(); |
| 2932 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2936 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2937 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2938 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2939 | } |
| 2940 | |
| 2941 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 2942 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2943 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2944 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2945 | Register out = locations->Out().AsRegister<Register>(); |
| 2946 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2947 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2948 | // Mask out compression flag from String's array length. |
| 2949 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2950 | __ Srl(out, out, 1u); |
| 2951 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2952 | } |
| 2953 | |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2954 | Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2955 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2956 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2957 | : Location::RequiresRegister(); |
| 2958 | } |
| 2959 | |
| 2960 | Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2961 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2962 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2963 | // but we should only prefer this if the constant has a single use. |
| 2964 | if (instruction->IsConstant() && |
| 2965 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2966 | instruction->GetUses().HasExactlyOneElement())) { |
| 2967 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2968 | // Otherwise fall through and require an FPU register for the constant. |
| 2969 | } |
| 2970 | return Location::RequiresFpuRegister(); |
| 2971 | } |
| 2972 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2973 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2974 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2975 | |
| 2976 | bool needs_write_barrier = |
| 2977 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2978 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2979 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2980 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2981 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2982 | may_need_runtime_call_for_type_check ? |
| 2983 | LocationSummary::kCallOnSlowPath : |
| 2984 | LocationSummary::kNoCall); |
| 2985 | |
| 2986 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2987 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2988 | if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2989 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2990 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2991 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2992 | } |
| 2993 | if (needs_write_barrier) { |
| 2994 | // Temporary register for the write barrier. |
| 2995 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2996 | } |
| 2997 | } |
| 2998 | |
| 2999 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { |
| 3000 | LocationSummary* locations = instruction->GetLocations(); |
| 3001 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 3002 | Location index = locations->InAt(1); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3003 | Location value_location = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3004 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3005 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3006 | bool needs_write_barrier = |
| 3007 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 3008 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3009 | Register base_reg = index.IsConstant() ? obj : TMP; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3010 | |
| 3011 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3012 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3013 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3014 | case DataType::Type::kInt8: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3015 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3016 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3017 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3018 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3019 | __ Addu(base_reg, obj, index.AsRegister<Register>()); |
| 3020 | } |
| 3021 | if (value_location.IsConstant()) { |
| 3022 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3023 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 3024 | } else { |
| 3025 | Register value = value_location.AsRegister<Register>(); |
| 3026 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3027 | } |
| 3028 | break; |
| 3029 | } |
| 3030 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3031 | case DataType::Type::kUint16: |
| 3032 | case DataType::Type::kInt16: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3033 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3034 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3035 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3036 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3037 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3038 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3039 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_2, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3040 | } |
| 3041 | if (value_location.IsConstant()) { |
| 3042 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3043 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 3044 | } else { |
| 3045 | Register value = value_location.AsRegister<Register>(); |
| 3046 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3047 | } |
| 3048 | break; |
| 3049 | } |
| 3050 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3051 | case DataType::Type::kInt32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3052 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3053 | if (index.IsConstant()) { |
| 3054 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3055 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3056 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3057 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3058 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3059 | } |
| 3060 | if (value_location.IsConstant()) { |
| 3061 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3062 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 3063 | } else { |
| 3064 | Register value = value_location.AsRegister<Register>(); |
| 3065 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 3066 | } |
| 3067 | break; |
| 3068 | } |
| 3069 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3070 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3071 | if (value_location.IsConstant()) { |
| 3072 | // Just setting null. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3073 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3074 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3075 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3076 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3077 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3078 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3079 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3080 | DCHECK_EQ(value, 0); |
| 3081 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 3082 | DCHECK(!needs_write_barrier); |
| 3083 | DCHECK(!may_need_runtime_call_for_type_check); |
| 3084 | break; |
| 3085 | } |
| 3086 | |
| 3087 | DCHECK(needs_write_barrier); |
| 3088 | Register value = value_location.AsRegister<Register>(); |
| 3089 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 3090 | Register temp2 = TMP; // Doesn't need to survive slow path. |
| 3091 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3092 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3093 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3094 | MipsLabel done; |
| 3095 | SlowPathCodeMIPS* slow_path = nullptr; |
| 3096 | |
| 3097 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3098 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS(instruction); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3099 | codegen_->AddSlowPath(slow_path); |
| 3100 | if (instruction->GetValueCanBeNull()) { |
| 3101 | MipsLabel non_zero; |
| 3102 | __ Bnez(value, &non_zero); |
| 3103 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3104 | if (index.IsConstant()) { |
| 3105 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3106 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3107 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 3108 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3109 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 3110 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3111 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 3112 | __ B(&done); |
| 3113 | __ Bind(&non_zero); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3114 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3115 | |
| 3116 | // Note that when read barriers are enabled, the type checks |
| 3117 | // are performed without read barriers. This is fine, even in |
| 3118 | // the case where a class object is in the from-space after |
| 3119 | // the flip, as a comparison involving such a type would not |
| 3120 | // produce a false positive; it may of course produce a false |
| 3121 | // negative, in which case we would take the ArraySet slow |
| 3122 | // path. |
| 3123 | |
| 3124 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 3125 | __ LoadFromOffset(kLoadWord, temp1, obj, class_offset, null_checker); |
| 3126 | __ MaybeUnpoisonHeapReference(temp1); |
| 3127 | |
| 3128 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 3129 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 3130 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3131 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 3132 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 3133 | // nor `temp2`, as we are comparing two poisoned references. |
| 3134 | |
| 3135 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3136 | MipsLabel do_put; |
| 3137 | __ Beq(temp1, temp2, &do_put); |
| 3138 | // If heap poisoning is enabled, the `temp1` reference has |
| 3139 | // not been unpoisoned yet; unpoison it now. |
| 3140 | __ MaybeUnpoisonHeapReference(temp1); |
| 3141 | |
| 3142 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 3143 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 3144 | // If heap poisoning is enabled, no need to unpoison |
| 3145 | // `temp1`, as we are comparing against null below. |
| 3146 | __ Bnez(temp1, slow_path->GetEntryLabel()); |
| 3147 | __ Bind(&do_put); |
| 3148 | } else { |
| 3149 | __ Bne(temp1, temp2, slow_path->GetEntryLabel()); |
| 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | Register source = value; |
| 3154 | if (kPoisonHeapReferences) { |
| 3155 | // Note that in the case where `value` is a null reference, |
| 3156 | // we do not enter this block, as a null reference does not |
| 3157 | // need poisoning. |
| 3158 | __ Move(temp1, value); |
| 3159 | __ PoisonHeapReference(temp1); |
| 3160 | source = temp1; |
| 3161 | } |
| 3162 | |
| 3163 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3164 | if (index.IsConstant()) { |
| 3165 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3166 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3167 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3168 | } |
| 3169 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 3170 | |
| 3171 | if (!may_need_runtime_call_for_type_check) { |
| 3172 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3173 | } |
| 3174 | |
| 3175 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 3176 | |
| 3177 | if (done.IsLinked()) { |
| 3178 | __ Bind(&done); |
| 3179 | } |
| 3180 | |
| 3181 | if (slow_path != nullptr) { |
| 3182 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3183 | } |
| 3184 | break; |
| 3185 | } |
| 3186 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3187 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3188 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3189 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3190 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3191 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3192 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3193 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3194 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3195 | } |
| 3196 | if (value_location.IsConstant()) { |
| 3197 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3198 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3199 | } else { |
| 3200 | Register value = value_location.AsRegisterPairLow<Register>(); |
| 3201 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3202 | } |
| 3203 | break; |
| 3204 | } |
| 3205 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3206 | case DataType::Type::kFloat32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3207 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3208 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3209 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3210 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3211 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3212 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3213 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3214 | } |
| 3215 | if (value_location.IsConstant()) { |
| 3216 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3217 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 3218 | } else { |
| 3219 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3220 | __ StoreSToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3221 | } |
| 3222 | break; |
| 3223 | } |
| 3224 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3225 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3226 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3227 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3228 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3229 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3230 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3231 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3232 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3233 | } |
| 3234 | if (value_location.IsConstant()) { |
| 3235 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3236 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3237 | } else { |
| 3238 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3239 | __ StoreDToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3240 | } |
| 3241 | break; |
| 3242 | } |
| 3243 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 3244 | case DataType::Type::kUint32: |
| 3245 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3246 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3247 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 3248 | UNREACHABLE(); |
| 3249 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3250 | } |
| 3251 | |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3252 | void LocationsBuilderMIPS::VisitIntermediateArrayAddressIndex( |
| 3253 | HIntermediateArrayAddressIndex* instruction) { |
| 3254 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3255 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3256 | |
| 3257 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 3258 | |
| 3259 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3260 | locations->SetInAt(1, Location::ConstantLocation(shift)); |
| 3261 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3262 | } |
| 3263 | |
| 3264 | void InstructionCodeGeneratorMIPS::VisitIntermediateArrayAddressIndex( |
| 3265 | HIntermediateArrayAddressIndex* instruction) { |
| 3266 | LocationSummary* locations = instruction->GetLocations(); |
| 3267 | Register index_reg = locations->InAt(0).AsRegister<Register>(); |
| 3268 | uint32_t shift = instruction->GetShift()->AsIntConstant()->GetValue(); |
| 3269 | __ Sll(locations->Out().AsRegister<Register>(), index_reg, shift); |
| 3270 | } |
| 3271 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3272 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3273 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3274 | InvokeRuntimeCallingConvention calling_convention; |
| 3275 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3276 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3277 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3278 | |
| 3279 | HInstruction* index = instruction->InputAt(0); |
| 3280 | HInstruction* length = instruction->InputAt(1); |
| 3281 | |
| 3282 | bool const_index = false; |
| 3283 | bool const_length = false; |
| 3284 | |
| 3285 | if (index->IsConstant()) { |
| 3286 | if (length->IsConstant()) { |
| 3287 | const_index = true; |
| 3288 | const_length = true; |
| 3289 | } else { |
| 3290 | int32_t index_value = index->AsIntConstant()->GetValue(); |
| 3291 | if (index_value < 0 || IsInt<16>(index_value + 1)) { |
| 3292 | const_index = true; |
| 3293 | } |
| 3294 | } |
| 3295 | } else if (length->IsConstant()) { |
| 3296 | int32_t length_value = length->AsIntConstant()->GetValue(); |
| 3297 | if (IsUint<15>(length_value)) { |
| 3298 | const_length = true; |
| 3299 | } |
| 3300 | } |
| 3301 | |
| 3302 | locations->SetInAt(0, const_index |
| 3303 | ? Location::ConstantLocation(index->AsConstant()) |
| 3304 | : Location::RequiresRegister()); |
| 3305 | locations->SetInAt(1, const_length |
| 3306 | ? Location::ConstantLocation(length->AsConstant()) |
| 3307 | : Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3308 | } |
| 3309 | |
| 3310 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 3311 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3312 | Location index_loc = locations->InAt(0); |
| 3313 | Location length_loc = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3314 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3315 | if (length_loc.IsConstant()) { |
| 3316 | int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3317 | if (index_loc.IsConstant()) { |
| 3318 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3319 | if (index < 0 || index >= length) { |
| 3320 | BoundsCheckSlowPathMIPS* slow_path = |
| 3321 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3322 | codegen_->AddSlowPath(slow_path); |
| 3323 | __ B(slow_path->GetEntryLabel()); |
| 3324 | } else { |
| 3325 | // Nothing to be done. |
| 3326 | } |
| 3327 | return; |
| 3328 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3329 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3330 | BoundsCheckSlowPathMIPS* slow_path = |
| 3331 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3332 | codegen_->AddSlowPath(slow_path); |
| 3333 | Register index = index_loc.AsRegister<Register>(); |
| 3334 | if (length == 0) { |
| 3335 | __ B(slow_path->GetEntryLabel()); |
| 3336 | } else if (length == 1) { |
| 3337 | __ Bnez(index, slow_path->GetEntryLabel()); |
| 3338 | } else { |
| 3339 | DCHECK(IsUint<15>(length)) << length; |
| 3340 | __ Sltiu(TMP, index, length); |
| 3341 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3342 | } |
| 3343 | } else { |
| 3344 | Register length = length_loc.AsRegister<Register>(); |
| 3345 | BoundsCheckSlowPathMIPS* slow_path = |
| 3346 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3347 | codegen_->AddSlowPath(slow_path); |
| 3348 | if (index_loc.IsConstant()) { |
| 3349 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3350 | if (index < 0) { |
| 3351 | __ B(slow_path->GetEntryLabel()); |
| 3352 | } else if (index == 0) { |
| 3353 | __ Blez(length, slow_path->GetEntryLabel()); |
| 3354 | } else { |
| 3355 | DCHECK(IsInt<16>(index + 1)) << index; |
| 3356 | __ Sltiu(TMP, length, index + 1); |
| 3357 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 3358 | } |
| 3359 | } else { |
| 3360 | Register index = index_loc.AsRegister<Register>(); |
| 3361 | __ Bgeu(index, length, slow_path->GetEntryLabel()); |
| 3362 | } |
| 3363 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3364 | } |
| 3365 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3366 | // Temp is used for read barrier. |
| 3367 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3368 | if (kEmitCompilerReadBarrier && |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 3369 | !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) && |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3370 | (kUseBakerReadBarrier || |
| 3371 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3372 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3373 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3374 | return 1; |
| 3375 | } |
| 3376 | return 0; |
| 3377 | } |
| 3378 | |
| 3379 | // Extra temp is used for read barrier. |
| 3380 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3381 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 3382 | } |
| 3383 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3384 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3385 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 3386 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3387 | LocationSummary* locations = |
| 3388 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3389 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3390 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3391 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3392 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3393 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3394 | } else { |
| 3395 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3396 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3397 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3398 | } |
| 3399 | |
| 3400 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3401 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3402 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3403 | Location obj_loc = locations->InAt(0); |
| 3404 | Register obj = obj_loc.AsRegister<Register>(); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3405 | Location cls = locations->InAt(1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3406 | Location temp_loc = locations->GetTemp(0); |
| 3407 | Register temp = temp_loc.AsRegister<Register>(); |
| 3408 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 3409 | DCHECK_LE(num_temps, 2u); |
| 3410 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3411 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3412 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3413 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3414 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 3415 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 3416 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 3417 | const uint32_t object_array_data_offset = |
| 3418 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 3419 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3420 | |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 3421 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3422 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3423 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 3424 | instruction, is_type_check_slow_path_fatal); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3425 | codegen_->AddSlowPath(slow_path); |
| 3426 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3427 | // Avoid this check if we know `obj` is not null. |
| 3428 | if (instruction->MustDoNullCheck()) { |
| 3429 | __ Beqz(obj, &done); |
| 3430 | } |
| 3431 | |
| 3432 | switch (type_check_kind) { |
| 3433 | case TypeCheckKind::kExactCheck: |
| 3434 | case TypeCheckKind::kArrayCheck: { |
| 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 | // Jump to slow path for throwing the exception or doing a |
| 3443 | // more involved array check. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3444 | __ Bne(temp, cls.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3445 | break; |
| 3446 | } |
| 3447 | |
| 3448 | case TypeCheckKind::kAbstractClassCheck: { |
| 3449 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3450 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3451 | temp_loc, |
| 3452 | obj_loc, |
| 3453 | class_offset, |
| 3454 | maybe_temp2_loc, |
| 3455 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3456 | // If the class is abstract, we eagerly fetch the super class of the |
| 3457 | // object to avoid doing a comparison we know will fail. |
| 3458 | MipsLabel loop; |
| 3459 | __ Bind(&loop); |
| 3460 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3461 | GenerateReferenceLoadOneRegister(instruction, |
| 3462 | temp_loc, |
| 3463 | super_offset, |
| 3464 | maybe_temp2_loc, |
| 3465 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3466 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3467 | // exception. |
| 3468 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3469 | // Otherwise, compare the classes. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3470 | __ Bne(temp, cls.AsRegister<Register>(), &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3471 | break; |
| 3472 | } |
| 3473 | |
| 3474 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3475 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3476 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3477 | temp_loc, |
| 3478 | obj_loc, |
| 3479 | class_offset, |
| 3480 | maybe_temp2_loc, |
| 3481 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3482 | // Walk over the class hierarchy to find a match. |
| 3483 | MipsLabel loop; |
| 3484 | __ Bind(&loop); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3485 | __ Beq(temp, cls.AsRegister<Register>(), &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3486 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3487 | GenerateReferenceLoadOneRegister(instruction, |
| 3488 | temp_loc, |
| 3489 | super_offset, |
| 3490 | maybe_temp2_loc, |
| 3491 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3492 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3493 | // exception. Otherwise, jump to the beginning of the loop. |
| 3494 | __ Bnez(temp, &loop); |
| 3495 | __ B(slow_path->GetEntryLabel()); |
| 3496 | break; |
| 3497 | } |
| 3498 | |
| 3499 | case TypeCheckKind::kArrayObjectCheck: { |
| 3500 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3501 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3502 | temp_loc, |
| 3503 | obj_loc, |
| 3504 | class_offset, |
| 3505 | maybe_temp2_loc, |
| 3506 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3507 | // Do an exact check. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3508 | __ Beq(temp, cls.AsRegister<Register>(), &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3509 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 3510 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3511 | GenerateReferenceLoadOneRegister(instruction, |
| 3512 | temp_loc, |
| 3513 | component_offset, |
| 3514 | maybe_temp2_loc, |
| 3515 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3516 | // If the component type is null, jump to the slow path to throw the exception. |
| 3517 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3518 | // Otherwise, the object is indeed an array, further check that this component |
| 3519 | // type is not a primitive type. |
| 3520 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 3521 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3522 | __ Bnez(temp, slow_path->GetEntryLabel()); |
| 3523 | break; |
| 3524 | } |
| 3525 | |
| 3526 | case TypeCheckKind::kUnresolvedCheck: |
| 3527 | // We always go into the type check slow path for the unresolved check case. |
| 3528 | // We cannot directly call the CheckCast runtime entry point |
| 3529 | // without resorting to a type checking slow path here (i.e. by |
| 3530 | // calling InvokeRuntime directly), as it would require to |
| 3531 | // assign fixed registers for the inputs of this HInstanceOf |
| 3532 | // instruction (following the runtime calling convention), which |
| 3533 | // might be cluttered by the potential first read barrier |
| 3534 | // emission at the beginning of this method. |
| 3535 | __ B(slow_path->GetEntryLabel()); |
| 3536 | break; |
| 3537 | |
| 3538 | case TypeCheckKind::kInterfaceCheck: { |
| 3539 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 3540 | // positives by doing this. |
| 3541 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3542 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3543 | temp_loc, |
| 3544 | obj_loc, |
| 3545 | class_offset, |
| 3546 | maybe_temp2_loc, |
| 3547 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3548 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3549 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3550 | temp_loc, |
| 3551 | temp_loc, |
| 3552 | iftable_offset, |
| 3553 | maybe_temp2_loc, |
| 3554 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3555 | // Iftable is never null. |
| 3556 | __ Lw(TMP, temp, array_length_offset); |
| 3557 | // Loop through the iftable and check if any class matches. |
| 3558 | MipsLabel loop; |
| 3559 | __ Bind(&loop); |
| 3560 | __ Addiu(temp, temp, 2 * kHeapReferenceSize); // Possibly in delay slot on R2. |
| 3561 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3562 | __ Lw(AT, temp, object_array_data_offset - 2 * kHeapReferenceSize); |
| 3563 | __ MaybeUnpoisonHeapReference(AT); |
| 3564 | // Go to next interface. |
| 3565 | __ Addiu(TMP, TMP, -2); |
| 3566 | // Compare the classes and continue the loop if they do not match. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3567 | __ Bne(AT, cls.AsRegister<Register>(), &loop); |
| 3568 | break; |
| 3569 | } |
| 3570 | |
| 3571 | case TypeCheckKind::kBitstringCheck: { |
| 3572 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3573 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3574 | temp_loc, |
| 3575 | obj_loc, |
| 3576 | class_offset, |
| 3577 | maybe_temp2_loc, |
| 3578 | kWithoutReadBarrier); |
| 3579 | |
| 3580 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 3581 | __ Bnez(temp, slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3582 | break; |
| 3583 | } |
| 3584 | } |
| 3585 | |
| 3586 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3587 | __ Bind(slow_path->GetExitLabel()); |
| 3588 | } |
| 3589 | |
| 3590 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3591 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3592 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3593 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3594 | if (check->HasUses()) { |
| 3595 | locations->SetOut(Location::SameAsFirstInput()); |
| 3596 | } |
| 3597 | } |
| 3598 | |
| 3599 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3600 | // We assume the class is not null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3601 | SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS( |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3602 | check->GetLoadClass(), |
| 3603 | check, |
| 3604 | check->GetDexPc(), |
| 3605 | true); |
| 3606 | codegen_->AddSlowPath(slow_path); |
| 3607 | GenerateClassInitializationCheck(slow_path, |
| 3608 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| 3609 | } |
| 3610 | |
| 3611 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3612 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3613 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3614 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3615 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3616 | |
| 3617 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3618 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3619 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3620 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3621 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3622 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3623 | case DataType::Type::kInt32: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3624 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3625 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3626 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3627 | break; |
| 3628 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3629 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3630 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3631 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3632 | // Output overlaps because it is written before doing the low comparison. |
| 3633 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3634 | break; |
| 3635 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3636 | case DataType::Type::kFloat32: |
| 3637 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3638 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3639 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3640 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3641 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3642 | |
| 3643 | default: |
| 3644 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3645 | } |
| 3646 | } |
| 3647 | |
| 3648 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { |
| 3649 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3650 | Register res = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3651 | DataType::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3652 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3653 | |
| 3654 | // 0 if: left == right |
| 3655 | // 1 if: left > right |
| 3656 | // -1 if: left < right |
| 3657 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3658 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3659 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3660 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3661 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3662 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3663 | case DataType::Type::kInt32: { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3664 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3665 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 3666 | __ Slt(TMP, lhs, rhs); |
| 3667 | __ Slt(res, rhs, lhs); |
| 3668 | __ Subu(res, res, TMP); |
| 3669 | break; |
| 3670 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3671 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3672 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3673 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3674 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3675 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 3676 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 3677 | // TODO: more efficient (direct) comparison with a constant. |
| 3678 | __ Slt(TMP, lhs_high, rhs_high); |
| 3679 | __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt. |
| 3680 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3681 | __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal. |
| 3682 | __ Sltu(TMP, lhs_low, rhs_low); |
| 3683 | __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt. |
| 3684 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3685 | __ Bind(&done); |
| 3686 | break; |
| 3687 | } |
| 3688 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3689 | case DataType::Type::kFloat32: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3690 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3691 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3692 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3693 | MipsLabel done; |
| 3694 | if (isR6) { |
| 3695 | __ CmpEqS(FTMP, lhs, rhs); |
| 3696 | __ LoadConst32(res, 0); |
| 3697 | __ Bc1nez(FTMP, &done); |
| 3698 | if (gt_bias) { |
| 3699 | __ CmpLtS(FTMP, lhs, rhs); |
| 3700 | __ LoadConst32(res, -1); |
| 3701 | __ Bc1nez(FTMP, &done); |
| 3702 | __ LoadConst32(res, 1); |
| 3703 | } else { |
| 3704 | __ CmpLtS(FTMP, rhs, lhs); |
| 3705 | __ LoadConst32(res, 1); |
| 3706 | __ Bc1nez(FTMP, &done); |
| 3707 | __ LoadConst32(res, -1); |
| 3708 | } |
| 3709 | } else { |
| 3710 | if (gt_bias) { |
| 3711 | __ ColtS(0, lhs, rhs); |
| 3712 | __ LoadConst32(res, -1); |
| 3713 | __ Bc1t(0, &done); |
| 3714 | __ CeqS(0, lhs, rhs); |
| 3715 | __ LoadConst32(res, 1); |
| 3716 | __ Movt(res, ZERO, 0); |
| 3717 | } else { |
| 3718 | __ ColtS(0, rhs, lhs); |
| 3719 | __ LoadConst32(res, 1); |
| 3720 | __ Bc1t(0, &done); |
| 3721 | __ CeqS(0, lhs, rhs); |
| 3722 | __ LoadConst32(res, -1); |
| 3723 | __ Movt(res, ZERO, 0); |
| 3724 | } |
| 3725 | } |
| 3726 | __ Bind(&done); |
| 3727 | break; |
| 3728 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3729 | case DataType::Type::kFloat64: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3730 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3731 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3732 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3733 | MipsLabel done; |
| 3734 | if (isR6) { |
| 3735 | __ CmpEqD(FTMP, lhs, rhs); |
| 3736 | __ LoadConst32(res, 0); |
| 3737 | __ Bc1nez(FTMP, &done); |
| 3738 | if (gt_bias) { |
| 3739 | __ CmpLtD(FTMP, lhs, rhs); |
| 3740 | __ LoadConst32(res, -1); |
| 3741 | __ Bc1nez(FTMP, &done); |
| 3742 | __ LoadConst32(res, 1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3743 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3744 | __ CmpLtD(FTMP, rhs, lhs); |
| 3745 | __ LoadConst32(res, 1); |
| 3746 | __ Bc1nez(FTMP, &done); |
| 3747 | __ LoadConst32(res, -1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3748 | } |
| 3749 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3750 | if (gt_bias) { |
| 3751 | __ ColtD(0, lhs, rhs); |
| 3752 | __ LoadConst32(res, -1); |
| 3753 | __ Bc1t(0, &done); |
| 3754 | __ CeqD(0, lhs, rhs); |
| 3755 | __ LoadConst32(res, 1); |
| 3756 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3757 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3758 | __ ColtD(0, rhs, lhs); |
| 3759 | __ LoadConst32(res, 1); |
| 3760 | __ Bc1t(0, &done); |
| 3761 | __ CeqD(0, lhs, rhs); |
| 3762 | __ LoadConst32(res, -1); |
| 3763 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3764 | } |
| 3765 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3766 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3767 | break; |
| 3768 | } |
| 3769 | |
| 3770 | default: |
| 3771 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3772 | } |
| 3773 | } |
| 3774 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3775 | void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3776 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3777 | switch (instruction->InputAt(0)->GetType()) { |
| 3778 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3779 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3780 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3781 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3782 | break; |
| 3783 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3784 | case DataType::Type::kFloat32: |
| 3785 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3786 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3787 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3788 | break; |
| 3789 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3790 | if (!instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3791 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3792 | } |
| 3793 | } |
| 3794 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3795 | void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3796 | if (instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3797 | return; |
| 3798 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3799 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3800 | DataType::Type type = instruction->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3801 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3802 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3803 | switch (type) { |
| 3804 | default: |
| 3805 | // Integer case. |
| 3806 | GenerateIntCompare(instruction->GetCondition(), locations); |
| 3807 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3808 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3809 | case DataType::Type::kInt64: |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 3810 | GenerateLongCompare(instruction->GetCondition(), locations); |
| 3811 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3812 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3813 | case DataType::Type::kFloat32: |
| 3814 | case DataType::Type::kFloat64: |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 3815 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 3816 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3817 | } |
| 3818 | } |
| 3819 | |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3820 | void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3821 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3822 | |
| 3823 | LocationSummary* locations = instruction->GetLocations(); |
| 3824 | Location second = locations->InAt(1); |
| 3825 | DCHECK(second.IsConstant()); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3826 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3827 | DCHECK(imm == 1 || imm == -1); |
| 3828 | |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3829 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 3830 | Register out = locations->Out().AsRegister<Register>(); |
| 3831 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3832 | |
| 3833 | if (instruction->IsRem()) { |
| 3834 | __ Move(out, ZERO); |
| 3835 | } else { |
| 3836 | if (imm == -1) { |
| 3837 | __ Subu(out, ZERO, dividend); |
| 3838 | } else if (out != dividend) { |
| 3839 | __ Move(out, dividend); |
| 3840 | } |
| 3841 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3842 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3843 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 3844 | Register out_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 3845 | Register out_low = locations->Out().AsRegisterPairLow<Register>(); |
| 3846 | Register in_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3847 | Register in_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3848 | |
| 3849 | if (instruction->IsRem()) { |
| 3850 | __ Move(out_high, ZERO); |
| 3851 | __ Move(out_low, ZERO); |
| 3852 | } else { |
| 3853 | if (imm == -1) { |
| 3854 | __ Subu(out_low, ZERO, in_low); |
| 3855 | __ Sltu(AT, ZERO, out_low); |
| 3856 | __ Subu(out_high, ZERO, in_high); |
| 3857 | __ Subu(out_high, out_high, AT); |
| 3858 | } else { |
| 3859 | __ Move(out_low, in_low); |
| 3860 | __ Move(out_high, in_high); |
| 3861 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3862 | } |
| 3863 | } |
| 3864 | } |
| 3865 | |
| 3866 | void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3867 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3868 | |
| 3869 | LocationSummary* locations = instruction->GetLocations(); |
| 3870 | Location second = locations->InAt(1); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3871 | const bool is_r2_or_newer = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
| 3872 | const bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3873 | DCHECK(second.IsConstant()); |
| 3874 | |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3875 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 3876 | Register out = locations->Out().AsRegister<Register>(); |
| 3877 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3878 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3879 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 3880 | int ctz_imm = CTZ(abs_imm); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3881 | |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3882 | if (instruction->IsDiv()) { |
| 3883 | if (ctz_imm == 1) { |
| 3884 | // Fast path for division by +/-2, which is very common. |
| 3885 | __ Srl(TMP, dividend, 31); |
| 3886 | } else { |
| 3887 | __ Sra(TMP, dividend, 31); |
| 3888 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3889 | } |
| 3890 | __ Addu(out, dividend, TMP); |
| 3891 | __ Sra(out, out, ctz_imm); |
| 3892 | if (imm < 0) { |
| 3893 | __ Subu(out, ZERO, out); |
| 3894 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3895 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3896 | if (ctz_imm == 1) { |
| 3897 | // Fast path for modulo +/-2, which is very common. |
| 3898 | __ Sra(TMP, dividend, 31); |
| 3899 | __ Subu(out, dividend, TMP); |
| 3900 | __ Andi(out, out, 1); |
| 3901 | __ Addu(out, out, TMP); |
| 3902 | } else { |
| 3903 | __ Sra(TMP, dividend, 31); |
| 3904 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3905 | __ Addu(out, dividend, TMP); |
| 3906 | if (IsUint<16>(abs_imm - 1)) { |
| 3907 | __ Andi(out, out, abs_imm - 1); |
| 3908 | } else { |
| 3909 | if (is_r2_or_newer) { |
| 3910 | __ Ins(out, ZERO, ctz_imm, 32 - ctz_imm); |
| 3911 | } else { |
| 3912 | __ Sll(out, out, 32 - ctz_imm); |
| 3913 | __ Srl(out, out, 32 - ctz_imm); |
| 3914 | } |
| 3915 | } |
| 3916 | __ Subu(out, out, TMP); |
| 3917 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3918 | } |
| 3919 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3920 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 3921 | Register out_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 3922 | Register out_low = locations->Out().AsRegisterPairLow<Register>(); |
| 3923 | Register in_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3924 | Register in_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3925 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3926 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 3927 | int ctz_imm = CTZ(abs_imm); |
| 3928 | |
| 3929 | if (instruction->IsDiv()) { |
| 3930 | if (ctz_imm < 32) { |
| 3931 | if (ctz_imm == 1) { |
| 3932 | __ Srl(AT, in_high, 31); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3933 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3934 | __ Sra(AT, in_high, 31); |
| 3935 | __ Srl(AT, AT, 32 - ctz_imm); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3936 | } |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3937 | __ Addu(AT, AT, in_low); |
| 3938 | __ Sltu(TMP, AT, in_low); |
| 3939 | __ Addu(out_high, in_high, TMP); |
| 3940 | __ Srl(out_low, AT, ctz_imm); |
| 3941 | if (is_r2_or_newer) { |
| 3942 | __ Ins(out_low, out_high, 32 - ctz_imm, ctz_imm); |
| 3943 | __ Sra(out_high, out_high, ctz_imm); |
| 3944 | } else { |
| 3945 | __ Sll(AT, out_high, 32 - ctz_imm); |
| 3946 | __ Sra(out_high, out_high, ctz_imm); |
| 3947 | __ Or(out_low, out_low, AT); |
| 3948 | } |
| 3949 | if (imm < 0) { |
| 3950 | __ Subu(out_low, ZERO, out_low); |
| 3951 | __ Sltu(AT, ZERO, out_low); |
| 3952 | __ Subu(out_high, ZERO, out_high); |
| 3953 | __ Subu(out_high, out_high, AT); |
| 3954 | } |
| 3955 | } else if (ctz_imm == 32) { |
| 3956 | __ Sra(AT, in_high, 31); |
| 3957 | __ Addu(AT, AT, in_low); |
| 3958 | __ Sltu(AT, AT, in_low); |
| 3959 | __ Addu(out_low, in_high, AT); |
| 3960 | if (imm < 0) { |
| 3961 | __ Srl(TMP, out_low, 31); |
| 3962 | __ Subu(out_low, ZERO, out_low); |
| 3963 | __ Sltu(AT, ZERO, out_low); |
| 3964 | __ Subu(out_high, TMP, AT); |
| 3965 | } else { |
| 3966 | __ Sra(out_high, out_low, 31); |
| 3967 | } |
| 3968 | } else if (ctz_imm < 63) { |
| 3969 | __ Sra(AT, in_high, 31); |
| 3970 | __ Srl(TMP, AT, 64 - ctz_imm); |
| 3971 | __ Addu(AT, AT, in_low); |
| 3972 | __ Sltu(AT, AT, in_low); |
| 3973 | __ Addu(out_low, in_high, AT); |
| 3974 | __ Addu(out_low, out_low, TMP); |
| 3975 | __ Sra(out_low, out_low, ctz_imm - 32); |
| 3976 | if (imm < 0) { |
| 3977 | __ Subu(out_low, ZERO, out_low); |
| 3978 | } |
| 3979 | __ Sra(out_high, out_low, 31); |
| 3980 | } else { |
| 3981 | DCHECK_LT(imm, 0); |
| 3982 | if (is_r6) { |
| 3983 | __ Aui(AT, in_high, 0x8000); |
| 3984 | } else { |
| 3985 | __ Lui(AT, 0x8000); |
| 3986 | __ Xor(AT, AT, in_high); |
| 3987 | } |
| 3988 | __ Or(AT, AT, in_low); |
| 3989 | __ Sltiu(out_low, AT, 1); |
| 3990 | __ Move(out_high, ZERO); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3991 | } |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 3992 | } else { |
| 3993 | if ((ctz_imm == 1) && !is_r6) { |
| 3994 | __ Andi(AT, in_low, 1); |
| 3995 | __ Sll(TMP, in_low, 31); |
| 3996 | __ And(TMP, in_high, TMP); |
| 3997 | __ Sra(out_high, TMP, 31); |
| 3998 | __ Or(out_low, out_high, AT); |
| 3999 | } else if (ctz_imm < 32) { |
| 4000 | __ Sra(AT, in_high, 31); |
| 4001 | if (ctz_imm <= 16) { |
| 4002 | __ Andi(out_low, in_low, abs_imm - 1); |
| 4003 | } else if (is_r2_or_newer) { |
| 4004 | __ Ext(out_low, in_low, 0, ctz_imm); |
| 4005 | } else { |
| 4006 | __ Sll(out_low, in_low, 32 - ctz_imm); |
| 4007 | __ Srl(out_low, out_low, 32 - ctz_imm); |
| 4008 | } |
| 4009 | if (is_r6) { |
| 4010 | __ Selnez(out_high, AT, out_low); |
| 4011 | } else { |
| 4012 | __ Movz(AT, ZERO, out_low); |
| 4013 | __ Move(out_high, AT); |
| 4014 | } |
| 4015 | if (is_r2_or_newer) { |
| 4016 | __ Ins(out_low, out_high, ctz_imm, 32 - ctz_imm); |
| 4017 | } else { |
| 4018 | __ Sll(AT, out_high, ctz_imm); |
| 4019 | __ Or(out_low, out_low, AT); |
| 4020 | } |
| 4021 | } else if (ctz_imm == 32) { |
| 4022 | __ Sra(AT, in_high, 31); |
| 4023 | __ Move(out_low, in_low); |
| 4024 | if (is_r6) { |
| 4025 | __ Selnez(out_high, AT, out_low); |
| 4026 | } else { |
| 4027 | __ Movz(AT, ZERO, out_low); |
| 4028 | __ Move(out_high, AT); |
| 4029 | } |
| 4030 | } else if (ctz_imm < 63) { |
| 4031 | __ Sra(AT, in_high, 31); |
| 4032 | __ Move(TMP, in_low); |
| 4033 | if (ctz_imm - 32 <= 16) { |
| 4034 | __ Andi(out_high, in_high, (1 << (ctz_imm - 32)) - 1); |
| 4035 | } else if (is_r2_or_newer) { |
| 4036 | __ Ext(out_high, in_high, 0, ctz_imm - 32); |
| 4037 | } else { |
| 4038 | __ Sll(out_high, in_high, 64 - ctz_imm); |
| 4039 | __ Srl(out_high, out_high, 64 - ctz_imm); |
| 4040 | } |
| 4041 | __ Move(out_low, TMP); |
| 4042 | __ Or(TMP, TMP, out_high); |
| 4043 | if (is_r6) { |
| 4044 | __ Selnez(AT, AT, TMP); |
| 4045 | } else { |
| 4046 | __ Movz(AT, ZERO, TMP); |
| 4047 | } |
| 4048 | if (is_r2_or_newer) { |
| 4049 | __ Ins(out_high, AT, ctz_imm - 32, 64 - ctz_imm); |
| 4050 | } else { |
| 4051 | __ Sll(AT, AT, ctz_imm - 32); |
| 4052 | __ Or(out_high, out_high, AT); |
| 4053 | } |
| 4054 | } else { |
| 4055 | if (is_r6) { |
| 4056 | __ Aui(AT, in_high, 0x8000); |
| 4057 | } else { |
| 4058 | __ Lui(AT, 0x8000); |
| 4059 | __ Xor(AT, AT, in_high); |
| 4060 | } |
| 4061 | __ Or(AT, AT, in_low); |
| 4062 | __ Sltiu(AT, AT, 1); |
| 4063 | __ Sll(AT, AT, 31); |
| 4064 | __ Move(out_low, in_low); |
| 4065 | __ Xor(out_high, in_high, AT); |
| 4066 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4067 | } |
| 4068 | } |
| 4069 | } |
| 4070 | |
| 4071 | void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4072 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4073 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4074 | |
| 4075 | LocationSummary* locations = instruction->GetLocations(); |
| 4076 | Location second = locations->InAt(1); |
| 4077 | DCHECK(second.IsConstant()); |
| 4078 | |
| 4079 | Register out = locations->Out().AsRegister<Register>(); |
| 4080 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4081 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4082 | |
| 4083 | int64_t magic; |
| 4084 | int shift; |
| 4085 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4086 | |
| 4087 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4088 | |
| 4089 | __ LoadConst32(TMP, magic); |
| 4090 | if (isR6) { |
| 4091 | __ MuhR6(TMP, dividend, TMP); |
| 4092 | } else { |
| 4093 | __ MultR2(dividend, TMP); |
| 4094 | __ Mfhi(TMP); |
| 4095 | } |
| 4096 | if (imm > 0 && magic < 0) { |
| 4097 | __ Addu(TMP, TMP, dividend); |
| 4098 | } else if (imm < 0 && magic > 0) { |
| 4099 | __ Subu(TMP, TMP, dividend); |
| 4100 | } |
| 4101 | |
| 4102 | if (shift != 0) { |
| 4103 | __ Sra(TMP, TMP, shift); |
| 4104 | } |
| 4105 | |
| 4106 | if (instruction->IsDiv()) { |
| 4107 | __ Sra(out, TMP, 31); |
| 4108 | __ Subu(out, TMP, out); |
| 4109 | } else { |
| 4110 | __ Sra(AT, TMP, 31); |
| 4111 | __ Subu(AT, TMP, AT); |
| 4112 | __ LoadConst32(TMP, imm); |
| 4113 | if (isR6) { |
| 4114 | __ MulR6(TMP, AT, TMP); |
| 4115 | } else { |
| 4116 | __ MulR2(TMP, AT, TMP); |
| 4117 | } |
| 4118 | __ Subu(out, dividend, TMP); |
| 4119 | } |
| 4120 | } |
| 4121 | |
| 4122 | void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 4123 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4124 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4125 | |
| 4126 | LocationSummary* locations = instruction->GetLocations(); |
| 4127 | Register out = locations->Out().AsRegister<Register>(); |
| 4128 | Location second = locations->InAt(1); |
| 4129 | |
| 4130 | if (second.IsConstant()) { |
| 4131 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4132 | if (imm == 0) { |
| 4133 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4134 | } else if (imm == 1 || imm == -1) { |
| 4135 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4136 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4137 | DivRemByPowerOfTwo(instruction); |
| 4138 | } else { |
| 4139 | DCHECK(imm <= -2 || imm >= 2); |
| 4140 | GenerateDivRemWithAnyConstant(instruction); |
| 4141 | } |
| 4142 | } else { |
| 4143 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4144 | Register divisor = second.AsRegister<Register>(); |
| 4145 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4146 | if (instruction->IsDiv()) { |
| 4147 | if (isR6) { |
| 4148 | __ DivR6(out, dividend, divisor); |
| 4149 | } else { |
| 4150 | __ DivR2(out, dividend, divisor); |
| 4151 | } |
| 4152 | } else { |
| 4153 | if (isR6) { |
| 4154 | __ ModR6(out, dividend, divisor); |
| 4155 | } else { |
| 4156 | __ ModR2(out, dividend, divisor); |
| 4157 | } |
| 4158 | } |
| 4159 | } |
| 4160 | } |
| 4161 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4162 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4163 | DataType::Type type = div->GetResultType(); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 4164 | bool call_long_div = false; |
| 4165 | if (type == DataType::Type::kInt64) { |
| 4166 | if (div->InputAt(1)->IsConstant()) { |
| 4167 | int64_t imm = CodeGenerator::GetInt64ValueOf(div->InputAt(1)->AsConstant()); |
| 4168 | call_long_div = (imm != 0) && !IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm))); |
| 4169 | } else { |
| 4170 | call_long_div = true; |
| 4171 | } |
| 4172 | } |
| 4173 | LocationSummary::CallKind call_kind = call_long_div |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4174 | ? LocationSummary::kCallOnMainOnly |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4175 | : LocationSummary::kNoCall; |
| 4176 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4177 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4178 | |
| 4179 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4180 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4181 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4182 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4183 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4184 | break; |
| 4185 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4186 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 4187 | if (call_long_div) { |
| 4188 | InvokeRuntimeCallingConvention calling_convention; |
| 4189 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4190 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4191 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4192 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4193 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4194 | } else { |
| 4195 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4196 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 4197 | locations->SetOut(Location::RequiresRegister()); |
| 4198 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4199 | break; |
| 4200 | } |
| 4201 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4202 | case DataType::Type::kFloat32: |
| 4203 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4204 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4205 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4206 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4207 | break; |
| 4208 | |
| 4209 | default: |
| 4210 | LOG(FATAL) << "Unexpected div type " << type; |
| 4211 | } |
| 4212 | } |
| 4213 | |
| 4214 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4215 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4216 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4217 | |
| 4218 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4219 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4220 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4221 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4222 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 4223 | if (locations->InAt(1).IsConstant()) { |
| 4224 | int64_t imm = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue(); |
| 4225 | if (imm == 0) { |
| 4226 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4227 | } else if (imm == 1 || imm == -1) { |
| 4228 | DivRemOneOrMinusOne(instruction); |
| 4229 | } else { |
| 4230 | DCHECK(IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm)))); |
| 4231 | DivRemByPowerOfTwo(instruction); |
| 4232 | } |
| 4233 | } else { |
| 4234 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
| 4235 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| 4236 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4237 | break; |
| 4238 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4239 | case DataType::Type::kFloat32: |
| 4240 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4241 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 4242 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4243 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4244 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4245 | __ DivS(dst, lhs, rhs); |
| 4246 | } else { |
| 4247 | __ DivD(dst, lhs, rhs); |
| 4248 | } |
| 4249 | break; |
| 4250 | } |
| 4251 | default: |
| 4252 | LOG(FATAL) << "Unexpected div type " << type; |
| 4253 | } |
| 4254 | } |
| 4255 | |
| 4256 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4257 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4258 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4262 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4263 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4264 | codegen_->AddSlowPath(slow_path); |
| 4265 | Location value = instruction->GetLocations()->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4266 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4267 | |
| 4268 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4269 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4270 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4271 | case DataType::Type::kInt8: |
| 4272 | case DataType::Type::kUint16: |
| 4273 | case DataType::Type::kInt16: |
| 4274 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4275 | if (value.IsConstant()) { |
| 4276 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 4277 | __ B(slow_path->GetEntryLabel()); |
| 4278 | } else { |
| 4279 | // A division by a non-null constant is valid. We don't need to perform |
| 4280 | // any check, so simply fall through. |
| 4281 | } |
| 4282 | } else { |
| 4283 | DCHECK(value.IsRegister()) << value; |
| 4284 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 4285 | } |
| 4286 | break; |
| 4287 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4288 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4289 | if (value.IsConstant()) { |
| 4290 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4291 | __ B(slow_path->GetEntryLabel()); |
| 4292 | } else { |
| 4293 | // A division by a non-null constant is valid. We don't need to perform |
| 4294 | // any check, so simply fall through. |
| 4295 | } |
| 4296 | } else { |
| 4297 | DCHECK(value.IsRegisterPair()) << value; |
| 4298 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); |
| 4299 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 4300 | } |
| 4301 | break; |
| 4302 | } |
| 4303 | default: |
| 4304 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| 4305 | } |
| 4306 | } |
| 4307 | |
| 4308 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { |
| 4309 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4310 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4311 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4312 | } |
| 4313 | |
| 4314 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 4315 | // Will be generated at use site. |
| 4316 | } |
| 4317 | |
| 4318 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { |
| 4319 | exit->SetLocations(nullptr); |
| 4320 | } |
| 4321 | |
| 4322 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 4323 | } |
| 4324 | |
| 4325 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { |
| 4326 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4327 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4328 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4329 | } |
| 4330 | |
| 4331 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 4332 | // Will be generated at use site. |
| 4333 | } |
| 4334 | |
| 4335 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { |
| 4336 | got->SetLocations(nullptr); |
| 4337 | } |
| 4338 | |
| 4339 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4340 | if (successor->IsExitBlock()) { |
| 4341 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 4342 | return; // no code needed |
| 4343 | } |
| 4344 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4345 | HBasicBlock* block = got->GetBlock(); |
| 4346 | HInstruction* previous = got->GetPrevious(); |
| 4347 | HLoopInformation* info = block->GetLoopInformation(); |
| 4348 | |
| 4349 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Goran Jakovljevic | feec167 | 2018-02-08 10:20:14 +0100 | [diff] [blame] | 4350 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 4351 | __ Lw(AT, SP, kCurrentMethodStackOffset); |
| 4352 | __ Lhu(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value()); |
| 4353 | __ Addiu(TMP, TMP, 1); |
| 4354 | __ Sh(TMP, AT, ArtMethod::HotnessCountOffset().Int32Value()); |
| 4355 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4356 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 4357 | return; |
| 4358 | } |
| 4359 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 4360 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 4361 | } |
| 4362 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 4363 | __ B(codegen_->GetLabelOf(successor)); |
| 4364 | } |
| 4365 | } |
| 4366 | |
| 4367 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { |
| 4368 | HandleGoto(got, got->GetSuccessor()); |
| 4369 | } |
| 4370 | |
| 4371 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 4372 | try_boundary->SetLocations(nullptr); |
| 4373 | } |
| 4374 | |
| 4375 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 4376 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 4377 | if (!successor->IsExitBlock()) { |
| 4378 | HandleGoto(try_boundary, successor); |
| 4379 | } |
| 4380 | } |
| 4381 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4382 | void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond, |
| 4383 | LocationSummary* locations) { |
| 4384 | Register dst = locations->Out().AsRegister<Register>(); |
| 4385 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4386 | Location rhs_location = locations->InAt(1); |
| 4387 | Register rhs_reg = ZERO; |
| 4388 | int64_t rhs_imm = 0; |
| 4389 | bool use_imm = rhs_location.IsConstant(); |
| 4390 | if (use_imm) { |
| 4391 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4392 | } else { |
| 4393 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4394 | } |
| 4395 | |
| 4396 | switch (cond) { |
| 4397 | case kCondEQ: |
| 4398 | case kCondNE: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4399 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4400 | if (rhs_imm == 0) { |
| 4401 | if (cond == kCondEQ) { |
| 4402 | __ Sltiu(dst, lhs, 1); |
| 4403 | } else { |
| 4404 | __ Sltu(dst, ZERO, lhs); |
| 4405 | } |
| 4406 | } else { |
| 4407 | __ Addiu(dst, lhs, -rhs_imm); |
| 4408 | if (cond == kCondEQ) { |
| 4409 | __ Sltiu(dst, dst, 1); |
| 4410 | } else { |
| 4411 | __ Sltu(dst, ZERO, dst); |
| 4412 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4413 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4414 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4415 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 4416 | __ Xori(dst, lhs, rhs_imm); |
| 4417 | } else { |
| 4418 | if (use_imm) { |
| 4419 | rhs_reg = TMP; |
| 4420 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4421 | } |
| 4422 | __ Xor(dst, lhs, rhs_reg); |
| 4423 | } |
| 4424 | if (cond == kCondEQ) { |
| 4425 | __ Sltiu(dst, dst, 1); |
| 4426 | } else { |
| 4427 | __ Sltu(dst, ZERO, dst); |
| 4428 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4429 | } |
| 4430 | break; |
| 4431 | |
| 4432 | case kCondLT: |
| 4433 | case kCondGE: |
| 4434 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4435 | __ Slti(dst, lhs, rhs_imm); |
| 4436 | } else { |
| 4437 | if (use_imm) { |
| 4438 | rhs_reg = TMP; |
| 4439 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4440 | } |
| 4441 | __ Slt(dst, lhs, rhs_reg); |
| 4442 | } |
| 4443 | if (cond == kCondGE) { |
| 4444 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4445 | // only the slt instruction but no sge. |
| 4446 | __ Xori(dst, dst, 1); |
| 4447 | } |
| 4448 | break; |
| 4449 | |
| 4450 | case kCondLE: |
| 4451 | case kCondGT: |
| 4452 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4453 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4454 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4455 | if (cond == kCondGT) { |
| 4456 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4457 | // only the slti instruction but no sgti. |
| 4458 | __ Xori(dst, dst, 1); |
| 4459 | } |
| 4460 | } else { |
| 4461 | if (use_imm) { |
| 4462 | rhs_reg = TMP; |
| 4463 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4464 | } |
| 4465 | __ Slt(dst, rhs_reg, lhs); |
| 4466 | if (cond == kCondLE) { |
| 4467 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4468 | // only the slt instruction but no sle. |
| 4469 | __ Xori(dst, dst, 1); |
| 4470 | } |
| 4471 | } |
| 4472 | break; |
| 4473 | |
| 4474 | case kCondB: |
| 4475 | case kCondAE: |
| 4476 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4477 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4478 | // the comparison and thus lets us compare directly with |
| 4479 | // unsigned values in the ranges [0, 0x7fff] and |
| 4480 | // [0xffff8000, 0xffffffff]. |
| 4481 | __ Sltiu(dst, lhs, rhs_imm); |
| 4482 | } else { |
| 4483 | if (use_imm) { |
| 4484 | rhs_reg = TMP; |
| 4485 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4486 | } |
| 4487 | __ Sltu(dst, lhs, rhs_reg); |
| 4488 | } |
| 4489 | if (cond == kCondAE) { |
| 4490 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4491 | // only the sltu instruction but no sgeu. |
| 4492 | __ Xori(dst, dst, 1); |
| 4493 | } |
| 4494 | break; |
| 4495 | |
| 4496 | case kCondBE: |
| 4497 | case kCondA: |
| 4498 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4499 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4500 | // Note that this only works if rhs + 1 does not overflow |
| 4501 | // to 0, hence the check above. |
| 4502 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4503 | // the comparison and thus lets us compare directly with |
| 4504 | // unsigned values in the ranges [0, 0x7fff] and |
| 4505 | // [0xffff8000, 0xffffffff]. |
| 4506 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4507 | if (cond == kCondA) { |
| 4508 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4509 | // only the sltiu instruction but no sgtiu. |
| 4510 | __ Xori(dst, dst, 1); |
| 4511 | } |
| 4512 | } else { |
| 4513 | if (use_imm) { |
| 4514 | rhs_reg = TMP; |
| 4515 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4516 | } |
| 4517 | __ Sltu(dst, rhs_reg, lhs); |
| 4518 | if (cond == kCondBE) { |
| 4519 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4520 | // only the sltu instruction but no sleu. |
| 4521 | __ Xori(dst, dst, 1); |
| 4522 | } |
| 4523 | } |
| 4524 | break; |
| 4525 | } |
| 4526 | } |
| 4527 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4528 | bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond, |
| 4529 | LocationSummary* input_locations, |
| 4530 | Register dst) { |
| 4531 | Register lhs = input_locations->InAt(0).AsRegister<Register>(); |
| 4532 | Location rhs_location = input_locations->InAt(1); |
| 4533 | Register rhs_reg = ZERO; |
| 4534 | int64_t rhs_imm = 0; |
| 4535 | bool use_imm = rhs_location.IsConstant(); |
| 4536 | if (use_imm) { |
| 4537 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4538 | } else { |
| 4539 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4540 | } |
| 4541 | |
| 4542 | switch (cond) { |
| 4543 | case kCondEQ: |
| 4544 | case kCondNE: |
| 4545 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4546 | __ Addiu(dst, lhs, -rhs_imm); |
| 4547 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 4548 | __ Xori(dst, lhs, rhs_imm); |
| 4549 | } else { |
| 4550 | if (use_imm) { |
| 4551 | rhs_reg = TMP; |
| 4552 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4553 | } |
| 4554 | __ Xor(dst, lhs, rhs_reg); |
| 4555 | } |
| 4556 | return (cond == kCondEQ); |
| 4557 | |
| 4558 | case kCondLT: |
| 4559 | case kCondGE: |
| 4560 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4561 | __ Slti(dst, lhs, rhs_imm); |
| 4562 | } else { |
| 4563 | if (use_imm) { |
| 4564 | rhs_reg = TMP; |
| 4565 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4566 | } |
| 4567 | __ Slt(dst, lhs, rhs_reg); |
| 4568 | } |
| 4569 | return (cond == kCondGE); |
| 4570 | |
| 4571 | case kCondLE: |
| 4572 | case kCondGT: |
| 4573 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4574 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4575 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4576 | return (cond == kCondGT); |
| 4577 | } else { |
| 4578 | if (use_imm) { |
| 4579 | rhs_reg = TMP; |
| 4580 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4581 | } |
| 4582 | __ Slt(dst, rhs_reg, lhs); |
| 4583 | return (cond == kCondLE); |
| 4584 | } |
| 4585 | |
| 4586 | case kCondB: |
| 4587 | case kCondAE: |
| 4588 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4589 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4590 | // the comparison and thus lets us compare directly with |
| 4591 | // unsigned values in the ranges [0, 0x7fff] and |
| 4592 | // [0xffff8000, 0xffffffff]. |
| 4593 | __ Sltiu(dst, lhs, rhs_imm); |
| 4594 | } else { |
| 4595 | if (use_imm) { |
| 4596 | rhs_reg = TMP; |
| 4597 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4598 | } |
| 4599 | __ Sltu(dst, lhs, rhs_reg); |
| 4600 | } |
| 4601 | return (cond == kCondAE); |
| 4602 | |
| 4603 | case kCondBE: |
| 4604 | case kCondA: |
| 4605 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4606 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4607 | // Note that this only works if rhs + 1 does not overflow |
| 4608 | // to 0, hence the check above. |
| 4609 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4610 | // the comparison and thus lets us compare directly with |
| 4611 | // unsigned values in the ranges [0, 0x7fff] and |
| 4612 | // [0xffff8000, 0xffffffff]. |
| 4613 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4614 | return (cond == kCondA); |
| 4615 | } else { |
| 4616 | if (use_imm) { |
| 4617 | rhs_reg = TMP; |
| 4618 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4619 | } |
| 4620 | __ Sltu(dst, rhs_reg, lhs); |
| 4621 | return (cond == kCondBE); |
| 4622 | } |
| 4623 | } |
| 4624 | } |
| 4625 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4626 | void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond, |
| 4627 | LocationSummary* locations, |
| 4628 | MipsLabel* label) { |
| 4629 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4630 | Location rhs_location = locations->InAt(1); |
| 4631 | Register rhs_reg = ZERO; |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4632 | int64_t rhs_imm = 0; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4633 | bool use_imm = rhs_location.IsConstant(); |
| 4634 | if (use_imm) { |
| 4635 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4636 | } else { |
| 4637 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4638 | } |
| 4639 | |
| 4640 | if (use_imm && rhs_imm == 0) { |
| 4641 | switch (cond) { |
| 4642 | case kCondEQ: |
| 4643 | case kCondBE: // <= 0 if zero |
| 4644 | __ Beqz(lhs, label); |
| 4645 | break; |
| 4646 | case kCondNE: |
| 4647 | case kCondA: // > 0 if non-zero |
| 4648 | __ Bnez(lhs, label); |
| 4649 | break; |
| 4650 | case kCondLT: |
| 4651 | __ Bltz(lhs, label); |
| 4652 | break; |
| 4653 | case kCondGE: |
| 4654 | __ Bgez(lhs, label); |
| 4655 | break; |
| 4656 | case kCondLE: |
| 4657 | __ Blez(lhs, label); |
| 4658 | break; |
| 4659 | case kCondGT: |
| 4660 | __ Bgtz(lhs, label); |
| 4661 | break; |
| 4662 | case kCondB: // always false |
| 4663 | break; |
| 4664 | case kCondAE: // always true |
| 4665 | __ B(label); |
| 4666 | break; |
| 4667 | } |
| 4668 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4669 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4670 | if (isR6 || !use_imm) { |
| 4671 | if (use_imm) { |
| 4672 | rhs_reg = TMP; |
| 4673 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4674 | } |
| 4675 | switch (cond) { |
| 4676 | case kCondEQ: |
| 4677 | __ Beq(lhs, rhs_reg, label); |
| 4678 | break; |
| 4679 | case kCondNE: |
| 4680 | __ Bne(lhs, rhs_reg, label); |
| 4681 | break; |
| 4682 | case kCondLT: |
| 4683 | __ Blt(lhs, rhs_reg, label); |
| 4684 | break; |
| 4685 | case kCondGE: |
| 4686 | __ Bge(lhs, rhs_reg, label); |
| 4687 | break; |
| 4688 | case kCondLE: |
| 4689 | __ Bge(rhs_reg, lhs, label); |
| 4690 | break; |
| 4691 | case kCondGT: |
| 4692 | __ Blt(rhs_reg, lhs, label); |
| 4693 | break; |
| 4694 | case kCondB: |
| 4695 | __ Bltu(lhs, rhs_reg, label); |
| 4696 | break; |
| 4697 | case kCondAE: |
| 4698 | __ Bgeu(lhs, rhs_reg, label); |
| 4699 | break; |
| 4700 | case kCondBE: |
| 4701 | __ Bgeu(rhs_reg, lhs, label); |
| 4702 | break; |
| 4703 | case kCondA: |
| 4704 | __ Bltu(rhs_reg, lhs, label); |
| 4705 | break; |
| 4706 | } |
| 4707 | } else { |
| 4708 | // Special cases for more efficient comparison with constants on R2. |
| 4709 | switch (cond) { |
| 4710 | case kCondEQ: |
| 4711 | __ LoadConst32(TMP, rhs_imm); |
| 4712 | __ Beq(lhs, TMP, label); |
| 4713 | break; |
| 4714 | case kCondNE: |
| 4715 | __ LoadConst32(TMP, rhs_imm); |
| 4716 | __ Bne(lhs, TMP, label); |
| 4717 | break; |
| 4718 | case kCondLT: |
| 4719 | if (IsInt<16>(rhs_imm)) { |
| 4720 | __ Slti(TMP, lhs, rhs_imm); |
| 4721 | __ Bnez(TMP, label); |
| 4722 | } else { |
| 4723 | __ LoadConst32(TMP, rhs_imm); |
| 4724 | __ Blt(lhs, TMP, label); |
| 4725 | } |
| 4726 | break; |
| 4727 | case kCondGE: |
| 4728 | if (IsInt<16>(rhs_imm)) { |
| 4729 | __ Slti(TMP, lhs, rhs_imm); |
| 4730 | __ Beqz(TMP, label); |
| 4731 | } else { |
| 4732 | __ LoadConst32(TMP, rhs_imm); |
| 4733 | __ Bge(lhs, TMP, label); |
| 4734 | } |
| 4735 | break; |
| 4736 | case kCondLE: |
| 4737 | if (IsInt<16>(rhs_imm + 1)) { |
| 4738 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4739 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4740 | __ Bnez(TMP, label); |
| 4741 | } else { |
| 4742 | __ LoadConst32(TMP, rhs_imm); |
| 4743 | __ Bge(TMP, lhs, label); |
| 4744 | } |
| 4745 | break; |
| 4746 | case kCondGT: |
| 4747 | if (IsInt<16>(rhs_imm + 1)) { |
| 4748 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4749 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4750 | __ Beqz(TMP, label); |
| 4751 | } else { |
| 4752 | __ LoadConst32(TMP, rhs_imm); |
| 4753 | __ Blt(TMP, lhs, label); |
| 4754 | } |
| 4755 | break; |
| 4756 | case kCondB: |
| 4757 | if (IsInt<16>(rhs_imm)) { |
| 4758 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4759 | __ Bnez(TMP, label); |
| 4760 | } else { |
| 4761 | __ LoadConst32(TMP, rhs_imm); |
| 4762 | __ Bltu(lhs, TMP, label); |
| 4763 | } |
| 4764 | break; |
| 4765 | case kCondAE: |
| 4766 | if (IsInt<16>(rhs_imm)) { |
| 4767 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4768 | __ Beqz(TMP, label); |
| 4769 | } else { |
| 4770 | __ LoadConst32(TMP, rhs_imm); |
| 4771 | __ Bgeu(lhs, TMP, label); |
| 4772 | } |
| 4773 | break; |
| 4774 | case kCondBE: |
| 4775 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4776 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4777 | // Note that this only works if rhs + 1 does not overflow |
| 4778 | // to 0, hence the check above. |
| 4779 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4780 | __ Bnez(TMP, label); |
| 4781 | } else { |
| 4782 | __ LoadConst32(TMP, rhs_imm); |
| 4783 | __ Bgeu(TMP, lhs, label); |
| 4784 | } |
| 4785 | break; |
| 4786 | case kCondA: |
| 4787 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4788 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4789 | // Note that this only works if rhs + 1 does not overflow |
| 4790 | // to 0, hence the check above. |
| 4791 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4792 | __ Beqz(TMP, label); |
| 4793 | } else { |
| 4794 | __ LoadConst32(TMP, rhs_imm); |
| 4795 | __ Bltu(TMP, lhs, label); |
| 4796 | } |
| 4797 | break; |
| 4798 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4799 | } |
| 4800 | } |
| 4801 | } |
| 4802 | |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 4803 | void InstructionCodeGeneratorMIPS::GenerateLongCompare(IfCondition cond, |
| 4804 | LocationSummary* locations) { |
| 4805 | Register dst = locations->Out().AsRegister<Register>(); |
| 4806 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4807 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4808 | Location rhs_location = locations->InAt(1); |
| 4809 | Register rhs_high = ZERO; |
| 4810 | Register rhs_low = ZERO; |
| 4811 | int64_t imm = 0; |
| 4812 | uint32_t imm_high = 0; |
| 4813 | uint32_t imm_low = 0; |
| 4814 | bool use_imm = rhs_location.IsConstant(); |
| 4815 | if (use_imm) { |
| 4816 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 4817 | imm_high = High32Bits(imm); |
| 4818 | imm_low = Low32Bits(imm); |
| 4819 | } else { |
| 4820 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 4821 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 4822 | } |
| 4823 | if (use_imm && imm == 0) { |
| 4824 | switch (cond) { |
| 4825 | case kCondEQ: |
| 4826 | case kCondBE: // <= 0 if zero |
| 4827 | __ Or(dst, lhs_high, lhs_low); |
| 4828 | __ Sltiu(dst, dst, 1); |
| 4829 | break; |
| 4830 | case kCondNE: |
| 4831 | case kCondA: // > 0 if non-zero |
| 4832 | __ Or(dst, lhs_high, lhs_low); |
| 4833 | __ Sltu(dst, ZERO, dst); |
| 4834 | break; |
| 4835 | case kCondLT: |
| 4836 | __ Slt(dst, lhs_high, ZERO); |
| 4837 | break; |
| 4838 | case kCondGE: |
| 4839 | __ Slt(dst, lhs_high, ZERO); |
| 4840 | __ Xori(dst, dst, 1); |
| 4841 | break; |
| 4842 | case kCondLE: |
| 4843 | __ Or(TMP, lhs_high, lhs_low); |
| 4844 | __ Sra(AT, lhs_high, 31); |
| 4845 | __ Sltu(dst, AT, TMP); |
| 4846 | __ Xori(dst, dst, 1); |
| 4847 | break; |
| 4848 | case kCondGT: |
| 4849 | __ Or(TMP, lhs_high, lhs_low); |
| 4850 | __ Sra(AT, lhs_high, 31); |
| 4851 | __ Sltu(dst, AT, TMP); |
| 4852 | break; |
| 4853 | case kCondB: // always false |
| 4854 | __ Andi(dst, dst, 0); |
| 4855 | break; |
| 4856 | case kCondAE: // always true |
| 4857 | __ Ori(dst, ZERO, 1); |
| 4858 | break; |
| 4859 | } |
| 4860 | } else if (use_imm) { |
| 4861 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 4862 | switch (cond) { |
| 4863 | case kCondEQ: |
| 4864 | __ LoadConst32(TMP, imm_high); |
| 4865 | __ Xor(TMP, TMP, lhs_high); |
| 4866 | __ LoadConst32(AT, imm_low); |
| 4867 | __ Xor(AT, AT, lhs_low); |
| 4868 | __ Or(dst, TMP, AT); |
| 4869 | __ Sltiu(dst, dst, 1); |
| 4870 | break; |
| 4871 | case kCondNE: |
| 4872 | __ LoadConst32(TMP, imm_high); |
| 4873 | __ Xor(TMP, TMP, lhs_high); |
| 4874 | __ LoadConst32(AT, imm_low); |
| 4875 | __ Xor(AT, AT, lhs_low); |
| 4876 | __ Or(dst, TMP, AT); |
| 4877 | __ Sltu(dst, ZERO, dst); |
| 4878 | break; |
| 4879 | case kCondLT: |
| 4880 | case kCondGE: |
| 4881 | if (dst == lhs_low) { |
| 4882 | __ LoadConst32(TMP, imm_low); |
| 4883 | __ Sltu(dst, lhs_low, TMP); |
| 4884 | } |
| 4885 | __ LoadConst32(TMP, imm_high); |
| 4886 | __ Slt(AT, lhs_high, TMP); |
| 4887 | __ Slt(TMP, TMP, lhs_high); |
| 4888 | if (dst != lhs_low) { |
| 4889 | __ LoadConst32(dst, imm_low); |
| 4890 | __ Sltu(dst, lhs_low, dst); |
| 4891 | } |
| 4892 | __ Slt(dst, TMP, dst); |
| 4893 | __ Or(dst, dst, AT); |
| 4894 | if (cond == kCondGE) { |
| 4895 | __ Xori(dst, dst, 1); |
| 4896 | } |
| 4897 | break; |
| 4898 | case kCondGT: |
| 4899 | case kCondLE: |
| 4900 | if (dst == lhs_low) { |
| 4901 | __ LoadConst32(TMP, imm_low); |
| 4902 | __ Sltu(dst, TMP, lhs_low); |
| 4903 | } |
| 4904 | __ LoadConst32(TMP, imm_high); |
| 4905 | __ Slt(AT, TMP, lhs_high); |
| 4906 | __ Slt(TMP, lhs_high, TMP); |
| 4907 | if (dst != lhs_low) { |
| 4908 | __ LoadConst32(dst, imm_low); |
| 4909 | __ Sltu(dst, dst, lhs_low); |
| 4910 | } |
| 4911 | __ Slt(dst, TMP, dst); |
| 4912 | __ Or(dst, dst, AT); |
| 4913 | if (cond == kCondLE) { |
| 4914 | __ Xori(dst, dst, 1); |
| 4915 | } |
| 4916 | break; |
| 4917 | case kCondB: |
| 4918 | case kCondAE: |
| 4919 | if (dst == lhs_low) { |
| 4920 | __ LoadConst32(TMP, imm_low); |
| 4921 | __ Sltu(dst, lhs_low, TMP); |
| 4922 | } |
| 4923 | __ LoadConst32(TMP, imm_high); |
| 4924 | __ Sltu(AT, lhs_high, TMP); |
| 4925 | __ Sltu(TMP, TMP, lhs_high); |
| 4926 | if (dst != lhs_low) { |
| 4927 | __ LoadConst32(dst, imm_low); |
| 4928 | __ Sltu(dst, lhs_low, dst); |
| 4929 | } |
| 4930 | __ Slt(dst, TMP, dst); |
| 4931 | __ Or(dst, dst, AT); |
| 4932 | if (cond == kCondAE) { |
| 4933 | __ Xori(dst, dst, 1); |
| 4934 | } |
| 4935 | break; |
| 4936 | case kCondA: |
| 4937 | case kCondBE: |
| 4938 | if (dst == lhs_low) { |
| 4939 | __ LoadConst32(TMP, imm_low); |
| 4940 | __ Sltu(dst, TMP, lhs_low); |
| 4941 | } |
| 4942 | __ LoadConst32(TMP, imm_high); |
| 4943 | __ Sltu(AT, TMP, lhs_high); |
| 4944 | __ Sltu(TMP, lhs_high, TMP); |
| 4945 | if (dst != lhs_low) { |
| 4946 | __ LoadConst32(dst, imm_low); |
| 4947 | __ Sltu(dst, dst, lhs_low); |
| 4948 | } |
| 4949 | __ Slt(dst, TMP, dst); |
| 4950 | __ Or(dst, dst, AT); |
| 4951 | if (cond == kCondBE) { |
| 4952 | __ Xori(dst, dst, 1); |
| 4953 | } |
| 4954 | break; |
| 4955 | } |
| 4956 | } else { |
| 4957 | switch (cond) { |
| 4958 | case kCondEQ: |
| 4959 | __ Xor(TMP, lhs_high, rhs_high); |
| 4960 | __ Xor(AT, lhs_low, rhs_low); |
| 4961 | __ Or(dst, TMP, AT); |
| 4962 | __ Sltiu(dst, dst, 1); |
| 4963 | break; |
| 4964 | case kCondNE: |
| 4965 | __ Xor(TMP, lhs_high, rhs_high); |
| 4966 | __ Xor(AT, lhs_low, rhs_low); |
| 4967 | __ Or(dst, TMP, AT); |
| 4968 | __ Sltu(dst, ZERO, dst); |
| 4969 | break; |
| 4970 | case kCondLT: |
| 4971 | case kCondGE: |
| 4972 | __ Slt(TMP, rhs_high, lhs_high); |
| 4973 | __ Sltu(AT, lhs_low, rhs_low); |
| 4974 | __ Slt(TMP, TMP, AT); |
| 4975 | __ Slt(AT, lhs_high, rhs_high); |
| 4976 | __ Or(dst, AT, TMP); |
| 4977 | if (cond == kCondGE) { |
| 4978 | __ Xori(dst, dst, 1); |
| 4979 | } |
| 4980 | break; |
| 4981 | case kCondGT: |
| 4982 | case kCondLE: |
| 4983 | __ Slt(TMP, lhs_high, rhs_high); |
| 4984 | __ Sltu(AT, rhs_low, lhs_low); |
| 4985 | __ Slt(TMP, TMP, AT); |
| 4986 | __ Slt(AT, rhs_high, lhs_high); |
| 4987 | __ Or(dst, AT, TMP); |
| 4988 | if (cond == kCondLE) { |
| 4989 | __ Xori(dst, dst, 1); |
| 4990 | } |
| 4991 | break; |
| 4992 | case kCondB: |
| 4993 | case kCondAE: |
| 4994 | __ Sltu(TMP, rhs_high, lhs_high); |
| 4995 | __ Sltu(AT, lhs_low, rhs_low); |
| 4996 | __ Slt(TMP, TMP, AT); |
| 4997 | __ Sltu(AT, lhs_high, rhs_high); |
| 4998 | __ Or(dst, AT, TMP); |
| 4999 | if (cond == kCondAE) { |
| 5000 | __ Xori(dst, dst, 1); |
| 5001 | } |
| 5002 | break; |
| 5003 | case kCondA: |
| 5004 | case kCondBE: |
| 5005 | __ Sltu(TMP, lhs_high, rhs_high); |
| 5006 | __ Sltu(AT, rhs_low, lhs_low); |
| 5007 | __ Slt(TMP, TMP, AT); |
| 5008 | __ Sltu(AT, rhs_high, lhs_high); |
| 5009 | __ Or(dst, AT, TMP); |
| 5010 | if (cond == kCondBE) { |
| 5011 | __ Xori(dst, dst, 1); |
| 5012 | } |
| 5013 | break; |
| 5014 | } |
| 5015 | } |
| 5016 | } |
| 5017 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5018 | void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond, |
| 5019 | LocationSummary* locations, |
| 5020 | MipsLabel* label) { |
| 5021 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 5022 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 5023 | Location rhs_location = locations->InAt(1); |
| 5024 | Register rhs_high = ZERO; |
| 5025 | Register rhs_low = ZERO; |
| 5026 | int64_t imm = 0; |
| 5027 | uint32_t imm_high = 0; |
| 5028 | uint32_t imm_low = 0; |
| 5029 | bool use_imm = rhs_location.IsConstant(); |
| 5030 | if (use_imm) { |
| 5031 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 5032 | imm_high = High32Bits(imm); |
| 5033 | imm_low = Low32Bits(imm); |
| 5034 | } else { |
| 5035 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 5036 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 5037 | } |
| 5038 | |
| 5039 | if (use_imm && imm == 0) { |
| 5040 | switch (cond) { |
| 5041 | case kCondEQ: |
| 5042 | case kCondBE: // <= 0 if zero |
| 5043 | __ Or(TMP, lhs_high, lhs_low); |
| 5044 | __ Beqz(TMP, label); |
| 5045 | break; |
| 5046 | case kCondNE: |
| 5047 | case kCondA: // > 0 if non-zero |
| 5048 | __ Or(TMP, lhs_high, lhs_low); |
| 5049 | __ Bnez(TMP, label); |
| 5050 | break; |
| 5051 | case kCondLT: |
| 5052 | __ Bltz(lhs_high, label); |
| 5053 | break; |
| 5054 | case kCondGE: |
| 5055 | __ Bgez(lhs_high, label); |
| 5056 | break; |
| 5057 | case kCondLE: |
| 5058 | __ Or(TMP, lhs_high, lhs_low); |
| 5059 | __ Sra(AT, lhs_high, 31); |
| 5060 | __ Bgeu(AT, TMP, label); |
| 5061 | break; |
| 5062 | case kCondGT: |
| 5063 | __ Or(TMP, lhs_high, lhs_low); |
| 5064 | __ Sra(AT, lhs_high, 31); |
| 5065 | __ Bltu(AT, TMP, label); |
| 5066 | break; |
| 5067 | case kCondB: // always false |
| 5068 | break; |
| 5069 | case kCondAE: // always true |
| 5070 | __ B(label); |
| 5071 | break; |
| 5072 | } |
| 5073 | } else if (use_imm) { |
| 5074 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 5075 | switch (cond) { |
| 5076 | case kCondEQ: |
| 5077 | __ LoadConst32(TMP, imm_high); |
| 5078 | __ Xor(TMP, TMP, lhs_high); |
| 5079 | __ LoadConst32(AT, imm_low); |
| 5080 | __ Xor(AT, AT, lhs_low); |
| 5081 | __ Or(TMP, TMP, AT); |
| 5082 | __ Beqz(TMP, label); |
| 5083 | break; |
| 5084 | case kCondNE: |
| 5085 | __ LoadConst32(TMP, imm_high); |
| 5086 | __ Xor(TMP, TMP, lhs_high); |
| 5087 | __ LoadConst32(AT, imm_low); |
| 5088 | __ Xor(AT, AT, lhs_low); |
| 5089 | __ Or(TMP, TMP, AT); |
| 5090 | __ Bnez(TMP, label); |
| 5091 | break; |
| 5092 | case kCondLT: |
| 5093 | __ LoadConst32(TMP, imm_high); |
| 5094 | __ Blt(lhs_high, TMP, label); |
| 5095 | __ Slt(TMP, TMP, lhs_high); |
| 5096 | __ LoadConst32(AT, imm_low); |
| 5097 | __ Sltu(AT, lhs_low, AT); |
| 5098 | __ Blt(TMP, AT, label); |
| 5099 | break; |
| 5100 | case kCondGE: |
| 5101 | __ LoadConst32(TMP, imm_high); |
| 5102 | __ Blt(TMP, lhs_high, label); |
| 5103 | __ Slt(TMP, lhs_high, TMP); |
| 5104 | __ LoadConst32(AT, imm_low); |
| 5105 | __ Sltu(AT, lhs_low, AT); |
| 5106 | __ Or(TMP, TMP, AT); |
| 5107 | __ Beqz(TMP, label); |
| 5108 | break; |
| 5109 | case kCondLE: |
| 5110 | __ LoadConst32(TMP, imm_high); |
| 5111 | __ Blt(lhs_high, TMP, label); |
| 5112 | __ Slt(TMP, TMP, lhs_high); |
| 5113 | __ LoadConst32(AT, imm_low); |
| 5114 | __ Sltu(AT, AT, lhs_low); |
| 5115 | __ Or(TMP, TMP, AT); |
| 5116 | __ Beqz(TMP, label); |
| 5117 | break; |
| 5118 | case kCondGT: |
| 5119 | __ LoadConst32(TMP, imm_high); |
| 5120 | __ Blt(TMP, lhs_high, label); |
| 5121 | __ Slt(TMP, lhs_high, TMP); |
| 5122 | __ LoadConst32(AT, imm_low); |
| 5123 | __ Sltu(AT, AT, lhs_low); |
| 5124 | __ Blt(TMP, AT, label); |
| 5125 | break; |
| 5126 | case kCondB: |
| 5127 | __ LoadConst32(TMP, imm_high); |
| 5128 | __ Bltu(lhs_high, TMP, label); |
| 5129 | __ Sltu(TMP, TMP, lhs_high); |
| 5130 | __ LoadConst32(AT, imm_low); |
| 5131 | __ Sltu(AT, lhs_low, AT); |
| 5132 | __ Blt(TMP, AT, label); |
| 5133 | break; |
| 5134 | case kCondAE: |
| 5135 | __ LoadConst32(TMP, imm_high); |
| 5136 | __ Bltu(TMP, lhs_high, label); |
| 5137 | __ Sltu(TMP, lhs_high, TMP); |
| 5138 | __ LoadConst32(AT, imm_low); |
| 5139 | __ Sltu(AT, lhs_low, AT); |
| 5140 | __ Or(TMP, TMP, AT); |
| 5141 | __ Beqz(TMP, label); |
| 5142 | break; |
| 5143 | case kCondBE: |
| 5144 | __ LoadConst32(TMP, imm_high); |
| 5145 | __ Bltu(lhs_high, TMP, label); |
| 5146 | __ Sltu(TMP, TMP, lhs_high); |
| 5147 | __ LoadConst32(AT, imm_low); |
| 5148 | __ Sltu(AT, AT, lhs_low); |
| 5149 | __ Or(TMP, TMP, AT); |
| 5150 | __ Beqz(TMP, label); |
| 5151 | break; |
| 5152 | case kCondA: |
| 5153 | __ LoadConst32(TMP, imm_high); |
| 5154 | __ Bltu(TMP, lhs_high, label); |
| 5155 | __ Sltu(TMP, lhs_high, TMP); |
| 5156 | __ LoadConst32(AT, imm_low); |
| 5157 | __ Sltu(AT, AT, lhs_low); |
| 5158 | __ Blt(TMP, AT, label); |
| 5159 | break; |
| 5160 | } |
| 5161 | } else { |
| 5162 | switch (cond) { |
| 5163 | case kCondEQ: |
| 5164 | __ Xor(TMP, lhs_high, rhs_high); |
| 5165 | __ Xor(AT, lhs_low, rhs_low); |
| 5166 | __ Or(TMP, TMP, AT); |
| 5167 | __ Beqz(TMP, label); |
| 5168 | break; |
| 5169 | case kCondNE: |
| 5170 | __ Xor(TMP, lhs_high, rhs_high); |
| 5171 | __ Xor(AT, lhs_low, rhs_low); |
| 5172 | __ Or(TMP, TMP, AT); |
| 5173 | __ Bnez(TMP, label); |
| 5174 | break; |
| 5175 | case kCondLT: |
| 5176 | __ Blt(lhs_high, rhs_high, label); |
| 5177 | __ Slt(TMP, rhs_high, lhs_high); |
| 5178 | __ Sltu(AT, lhs_low, rhs_low); |
| 5179 | __ Blt(TMP, AT, label); |
| 5180 | break; |
| 5181 | case kCondGE: |
| 5182 | __ Blt(rhs_high, lhs_high, label); |
| 5183 | __ Slt(TMP, lhs_high, rhs_high); |
| 5184 | __ Sltu(AT, lhs_low, rhs_low); |
| 5185 | __ Or(TMP, TMP, AT); |
| 5186 | __ Beqz(TMP, label); |
| 5187 | break; |
| 5188 | case kCondLE: |
| 5189 | __ Blt(lhs_high, rhs_high, label); |
| 5190 | __ Slt(TMP, rhs_high, lhs_high); |
| 5191 | __ Sltu(AT, rhs_low, lhs_low); |
| 5192 | __ Or(TMP, TMP, AT); |
| 5193 | __ Beqz(TMP, label); |
| 5194 | break; |
| 5195 | case kCondGT: |
| 5196 | __ Blt(rhs_high, lhs_high, label); |
| 5197 | __ Slt(TMP, lhs_high, rhs_high); |
| 5198 | __ Sltu(AT, rhs_low, lhs_low); |
| 5199 | __ Blt(TMP, AT, label); |
| 5200 | break; |
| 5201 | case kCondB: |
| 5202 | __ Bltu(lhs_high, rhs_high, label); |
| 5203 | __ Sltu(TMP, rhs_high, lhs_high); |
| 5204 | __ Sltu(AT, lhs_low, rhs_low); |
| 5205 | __ Blt(TMP, AT, label); |
| 5206 | break; |
| 5207 | case kCondAE: |
| 5208 | __ Bltu(rhs_high, lhs_high, label); |
| 5209 | __ Sltu(TMP, lhs_high, rhs_high); |
| 5210 | __ Sltu(AT, lhs_low, rhs_low); |
| 5211 | __ Or(TMP, TMP, AT); |
| 5212 | __ Beqz(TMP, label); |
| 5213 | break; |
| 5214 | case kCondBE: |
| 5215 | __ Bltu(lhs_high, rhs_high, label); |
| 5216 | __ Sltu(TMP, rhs_high, lhs_high); |
| 5217 | __ Sltu(AT, rhs_low, lhs_low); |
| 5218 | __ Or(TMP, TMP, AT); |
| 5219 | __ Beqz(TMP, label); |
| 5220 | break; |
| 5221 | case kCondA: |
| 5222 | __ Bltu(rhs_high, lhs_high, label); |
| 5223 | __ Sltu(TMP, lhs_high, rhs_high); |
| 5224 | __ Sltu(AT, rhs_low, lhs_low); |
| 5225 | __ Blt(TMP, AT, label); |
| 5226 | break; |
| 5227 | } |
| 5228 | } |
| 5229 | } |
| 5230 | |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5231 | void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond, |
| 5232 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5233 | DataType::Type type, |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5234 | LocationSummary* locations) { |
| 5235 | Register dst = locations->Out().AsRegister<Register>(); |
| 5236 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5237 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5238 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5239 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5240 | if (isR6) { |
| 5241 | switch (cond) { |
| 5242 | case kCondEQ: |
| 5243 | __ CmpEqS(FTMP, lhs, rhs); |
| 5244 | __ Mfc1(dst, FTMP); |
| 5245 | __ Andi(dst, dst, 1); |
| 5246 | break; |
| 5247 | case kCondNE: |
| 5248 | __ CmpEqS(FTMP, lhs, rhs); |
| 5249 | __ Mfc1(dst, FTMP); |
| 5250 | __ Addiu(dst, dst, 1); |
| 5251 | break; |
| 5252 | case kCondLT: |
| 5253 | if (gt_bias) { |
| 5254 | __ CmpLtS(FTMP, lhs, rhs); |
| 5255 | } else { |
| 5256 | __ CmpUltS(FTMP, lhs, rhs); |
| 5257 | } |
| 5258 | __ Mfc1(dst, FTMP); |
| 5259 | __ Andi(dst, dst, 1); |
| 5260 | break; |
| 5261 | case kCondLE: |
| 5262 | if (gt_bias) { |
| 5263 | __ CmpLeS(FTMP, lhs, rhs); |
| 5264 | } else { |
| 5265 | __ CmpUleS(FTMP, lhs, rhs); |
| 5266 | } |
| 5267 | __ Mfc1(dst, FTMP); |
| 5268 | __ Andi(dst, dst, 1); |
| 5269 | break; |
| 5270 | case kCondGT: |
| 5271 | if (gt_bias) { |
| 5272 | __ CmpUltS(FTMP, rhs, lhs); |
| 5273 | } else { |
| 5274 | __ CmpLtS(FTMP, rhs, lhs); |
| 5275 | } |
| 5276 | __ Mfc1(dst, FTMP); |
| 5277 | __ Andi(dst, dst, 1); |
| 5278 | break; |
| 5279 | case kCondGE: |
| 5280 | if (gt_bias) { |
| 5281 | __ CmpUleS(FTMP, rhs, lhs); |
| 5282 | } else { |
| 5283 | __ CmpLeS(FTMP, rhs, lhs); |
| 5284 | } |
| 5285 | __ Mfc1(dst, FTMP); |
| 5286 | __ Andi(dst, dst, 1); |
| 5287 | break; |
| 5288 | default: |
| 5289 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5290 | UNREACHABLE(); |
| 5291 | } |
| 5292 | } else { |
| 5293 | switch (cond) { |
| 5294 | case kCondEQ: |
| 5295 | __ CeqS(0, lhs, rhs); |
| 5296 | __ LoadConst32(dst, 1); |
| 5297 | __ Movf(dst, ZERO, 0); |
| 5298 | break; |
| 5299 | case kCondNE: |
| 5300 | __ CeqS(0, lhs, rhs); |
| 5301 | __ LoadConst32(dst, 1); |
| 5302 | __ Movt(dst, ZERO, 0); |
| 5303 | break; |
| 5304 | case kCondLT: |
| 5305 | if (gt_bias) { |
| 5306 | __ ColtS(0, lhs, rhs); |
| 5307 | } else { |
| 5308 | __ CultS(0, lhs, rhs); |
| 5309 | } |
| 5310 | __ LoadConst32(dst, 1); |
| 5311 | __ Movf(dst, ZERO, 0); |
| 5312 | break; |
| 5313 | case kCondLE: |
| 5314 | if (gt_bias) { |
| 5315 | __ ColeS(0, lhs, rhs); |
| 5316 | } else { |
| 5317 | __ CuleS(0, lhs, rhs); |
| 5318 | } |
| 5319 | __ LoadConst32(dst, 1); |
| 5320 | __ Movf(dst, ZERO, 0); |
| 5321 | break; |
| 5322 | case kCondGT: |
| 5323 | if (gt_bias) { |
| 5324 | __ CultS(0, rhs, lhs); |
| 5325 | } else { |
| 5326 | __ ColtS(0, rhs, lhs); |
| 5327 | } |
| 5328 | __ LoadConst32(dst, 1); |
| 5329 | __ Movf(dst, ZERO, 0); |
| 5330 | break; |
| 5331 | case kCondGE: |
| 5332 | if (gt_bias) { |
| 5333 | __ CuleS(0, rhs, lhs); |
| 5334 | } else { |
| 5335 | __ ColeS(0, rhs, lhs); |
| 5336 | } |
| 5337 | __ LoadConst32(dst, 1); |
| 5338 | __ Movf(dst, ZERO, 0); |
| 5339 | break; |
| 5340 | default: |
| 5341 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5342 | UNREACHABLE(); |
| 5343 | } |
| 5344 | } |
| 5345 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5346 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5347 | if (isR6) { |
| 5348 | switch (cond) { |
| 5349 | case kCondEQ: |
| 5350 | __ CmpEqD(FTMP, lhs, rhs); |
| 5351 | __ Mfc1(dst, FTMP); |
| 5352 | __ Andi(dst, dst, 1); |
| 5353 | break; |
| 5354 | case kCondNE: |
| 5355 | __ CmpEqD(FTMP, lhs, rhs); |
| 5356 | __ Mfc1(dst, FTMP); |
| 5357 | __ Addiu(dst, dst, 1); |
| 5358 | break; |
| 5359 | case kCondLT: |
| 5360 | if (gt_bias) { |
| 5361 | __ CmpLtD(FTMP, lhs, rhs); |
| 5362 | } else { |
| 5363 | __ CmpUltD(FTMP, lhs, rhs); |
| 5364 | } |
| 5365 | __ Mfc1(dst, FTMP); |
| 5366 | __ Andi(dst, dst, 1); |
| 5367 | break; |
| 5368 | case kCondLE: |
| 5369 | if (gt_bias) { |
| 5370 | __ CmpLeD(FTMP, lhs, rhs); |
| 5371 | } else { |
| 5372 | __ CmpUleD(FTMP, lhs, rhs); |
| 5373 | } |
| 5374 | __ Mfc1(dst, FTMP); |
| 5375 | __ Andi(dst, dst, 1); |
| 5376 | break; |
| 5377 | case kCondGT: |
| 5378 | if (gt_bias) { |
| 5379 | __ CmpUltD(FTMP, rhs, lhs); |
| 5380 | } else { |
| 5381 | __ CmpLtD(FTMP, rhs, lhs); |
| 5382 | } |
| 5383 | __ Mfc1(dst, FTMP); |
| 5384 | __ Andi(dst, dst, 1); |
| 5385 | break; |
| 5386 | case kCondGE: |
| 5387 | if (gt_bias) { |
| 5388 | __ CmpUleD(FTMP, rhs, lhs); |
| 5389 | } else { |
| 5390 | __ CmpLeD(FTMP, rhs, lhs); |
| 5391 | } |
| 5392 | __ Mfc1(dst, FTMP); |
| 5393 | __ Andi(dst, dst, 1); |
| 5394 | break; |
| 5395 | default: |
| 5396 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5397 | UNREACHABLE(); |
| 5398 | } |
| 5399 | } else { |
| 5400 | switch (cond) { |
| 5401 | case kCondEQ: |
| 5402 | __ CeqD(0, lhs, rhs); |
| 5403 | __ LoadConst32(dst, 1); |
| 5404 | __ Movf(dst, ZERO, 0); |
| 5405 | break; |
| 5406 | case kCondNE: |
| 5407 | __ CeqD(0, lhs, rhs); |
| 5408 | __ LoadConst32(dst, 1); |
| 5409 | __ Movt(dst, ZERO, 0); |
| 5410 | break; |
| 5411 | case kCondLT: |
| 5412 | if (gt_bias) { |
| 5413 | __ ColtD(0, lhs, rhs); |
| 5414 | } else { |
| 5415 | __ CultD(0, lhs, rhs); |
| 5416 | } |
| 5417 | __ LoadConst32(dst, 1); |
| 5418 | __ Movf(dst, ZERO, 0); |
| 5419 | break; |
| 5420 | case kCondLE: |
| 5421 | if (gt_bias) { |
| 5422 | __ ColeD(0, lhs, rhs); |
| 5423 | } else { |
| 5424 | __ CuleD(0, lhs, rhs); |
| 5425 | } |
| 5426 | __ LoadConst32(dst, 1); |
| 5427 | __ Movf(dst, ZERO, 0); |
| 5428 | break; |
| 5429 | case kCondGT: |
| 5430 | if (gt_bias) { |
| 5431 | __ CultD(0, rhs, lhs); |
| 5432 | } else { |
| 5433 | __ ColtD(0, rhs, lhs); |
| 5434 | } |
| 5435 | __ LoadConst32(dst, 1); |
| 5436 | __ Movf(dst, ZERO, 0); |
| 5437 | break; |
| 5438 | case kCondGE: |
| 5439 | if (gt_bias) { |
| 5440 | __ CuleD(0, rhs, lhs); |
| 5441 | } else { |
| 5442 | __ ColeD(0, rhs, lhs); |
| 5443 | } |
| 5444 | __ LoadConst32(dst, 1); |
| 5445 | __ Movf(dst, ZERO, 0); |
| 5446 | break; |
| 5447 | default: |
| 5448 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5449 | UNREACHABLE(); |
| 5450 | } |
| 5451 | } |
| 5452 | } |
| 5453 | } |
| 5454 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5455 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond, |
| 5456 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5457 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5458 | LocationSummary* input_locations, |
| 5459 | int cc) { |
| 5460 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5461 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5462 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5463 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5464 | switch (cond) { |
| 5465 | case kCondEQ: |
| 5466 | __ CeqS(cc, lhs, rhs); |
| 5467 | return false; |
| 5468 | case kCondNE: |
| 5469 | __ CeqS(cc, lhs, rhs); |
| 5470 | return true; |
| 5471 | case kCondLT: |
| 5472 | if (gt_bias) { |
| 5473 | __ ColtS(cc, lhs, rhs); |
| 5474 | } else { |
| 5475 | __ CultS(cc, lhs, rhs); |
| 5476 | } |
| 5477 | return false; |
| 5478 | case kCondLE: |
| 5479 | if (gt_bias) { |
| 5480 | __ ColeS(cc, lhs, rhs); |
| 5481 | } else { |
| 5482 | __ CuleS(cc, lhs, rhs); |
| 5483 | } |
| 5484 | return false; |
| 5485 | case kCondGT: |
| 5486 | if (gt_bias) { |
| 5487 | __ CultS(cc, rhs, lhs); |
| 5488 | } else { |
| 5489 | __ ColtS(cc, rhs, lhs); |
| 5490 | } |
| 5491 | return false; |
| 5492 | case kCondGE: |
| 5493 | if (gt_bias) { |
| 5494 | __ CuleS(cc, rhs, lhs); |
| 5495 | } else { |
| 5496 | __ ColeS(cc, rhs, lhs); |
| 5497 | } |
| 5498 | return false; |
| 5499 | default: |
| 5500 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5501 | UNREACHABLE(); |
| 5502 | } |
| 5503 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5504 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5505 | switch (cond) { |
| 5506 | case kCondEQ: |
| 5507 | __ CeqD(cc, lhs, rhs); |
| 5508 | return false; |
| 5509 | case kCondNE: |
| 5510 | __ CeqD(cc, lhs, rhs); |
| 5511 | return true; |
| 5512 | case kCondLT: |
| 5513 | if (gt_bias) { |
| 5514 | __ ColtD(cc, lhs, rhs); |
| 5515 | } else { |
| 5516 | __ CultD(cc, lhs, rhs); |
| 5517 | } |
| 5518 | return false; |
| 5519 | case kCondLE: |
| 5520 | if (gt_bias) { |
| 5521 | __ ColeD(cc, lhs, rhs); |
| 5522 | } else { |
| 5523 | __ CuleD(cc, lhs, rhs); |
| 5524 | } |
| 5525 | return false; |
| 5526 | case kCondGT: |
| 5527 | if (gt_bias) { |
| 5528 | __ CultD(cc, rhs, lhs); |
| 5529 | } else { |
| 5530 | __ ColtD(cc, rhs, lhs); |
| 5531 | } |
| 5532 | return false; |
| 5533 | case kCondGE: |
| 5534 | if (gt_bias) { |
| 5535 | __ CuleD(cc, rhs, lhs); |
| 5536 | } else { |
| 5537 | __ ColeD(cc, rhs, lhs); |
| 5538 | } |
| 5539 | return false; |
| 5540 | default: |
| 5541 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5542 | UNREACHABLE(); |
| 5543 | } |
| 5544 | } |
| 5545 | } |
| 5546 | |
| 5547 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond, |
| 5548 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5549 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5550 | LocationSummary* input_locations, |
| 5551 | FRegister dst) { |
| 5552 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5553 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5554 | CHECK(codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5555 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5556 | switch (cond) { |
| 5557 | case kCondEQ: |
| 5558 | __ CmpEqS(dst, lhs, rhs); |
| 5559 | return false; |
| 5560 | case kCondNE: |
| 5561 | __ CmpEqS(dst, lhs, rhs); |
| 5562 | return true; |
| 5563 | case kCondLT: |
| 5564 | if (gt_bias) { |
| 5565 | __ CmpLtS(dst, lhs, rhs); |
| 5566 | } else { |
| 5567 | __ CmpUltS(dst, lhs, rhs); |
| 5568 | } |
| 5569 | return false; |
| 5570 | case kCondLE: |
| 5571 | if (gt_bias) { |
| 5572 | __ CmpLeS(dst, lhs, rhs); |
| 5573 | } else { |
| 5574 | __ CmpUleS(dst, lhs, rhs); |
| 5575 | } |
| 5576 | return false; |
| 5577 | case kCondGT: |
| 5578 | if (gt_bias) { |
| 5579 | __ CmpUltS(dst, rhs, lhs); |
| 5580 | } else { |
| 5581 | __ CmpLtS(dst, rhs, lhs); |
| 5582 | } |
| 5583 | return false; |
| 5584 | case kCondGE: |
| 5585 | if (gt_bias) { |
| 5586 | __ CmpUleS(dst, rhs, lhs); |
| 5587 | } else { |
| 5588 | __ CmpLeS(dst, rhs, lhs); |
| 5589 | } |
| 5590 | return false; |
| 5591 | default: |
| 5592 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5593 | UNREACHABLE(); |
| 5594 | } |
| 5595 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5596 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5597 | switch (cond) { |
| 5598 | case kCondEQ: |
| 5599 | __ CmpEqD(dst, lhs, rhs); |
| 5600 | return false; |
| 5601 | case kCondNE: |
| 5602 | __ CmpEqD(dst, lhs, rhs); |
| 5603 | return true; |
| 5604 | case kCondLT: |
| 5605 | if (gt_bias) { |
| 5606 | __ CmpLtD(dst, lhs, rhs); |
| 5607 | } else { |
| 5608 | __ CmpUltD(dst, lhs, rhs); |
| 5609 | } |
| 5610 | return false; |
| 5611 | case kCondLE: |
| 5612 | if (gt_bias) { |
| 5613 | __ CmpLeD(dst, lhs, rhs); |
| 5614 | } else { |
| 5615 | __ CmpUleD(dst, lhs, rhs); |
| 5616 | } |
| 5617 | return false; |
| 5618 | case kCondGT: |
| 5619 | if (gt_bias) { |
| 5620 | __ CmpUltD(dst, rhs, lhs); |
| 5621 | } else { |
| 5622 | __ CmpLtD(dst, rhs, lhs); |
| 5623 | } |
| 5624 | return false; |
| 5625 | case kCondGE: |
| 5626 | if (gt_bias) { |
| 5627 | __ CmpUleD(dst, rhs, lhs); |
| 5628 | } else { |
| 5629 | __ CmpLeD(dst, rhs, lhs); |
| 5630 | } |
| 5631 | return false; |
| 5632 | default: |
| 5633 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5634 | UNREACHABLE(); |
| 5635 | } |
| 5636 | } |
| 5637 | } |
| 5638 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5639 | void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond, |
| 5640 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5641 | DataType::Type type, |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5642 | LocationSummary* locations, |
| 5643 | MipsLabel* label) { |
| 5644 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5645 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5646 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5647 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5648 | if (isR6) { |
| 5649 | switch (cond) { |
| 5650 | case kCondEQ: |
| 5651 | __ CmpEqS(FTMP, lhs, rhs); |
| 5652 | __ Bc1nez(FTMP, label); |
| 5653 | break; |
| 5654 | case kCondNE: |
| 5655 | __ CmpEqS(FTMP, lhs, rhs); |
| 5656 | __ Bc1eqz(FTMP, label); |
| 5657 | break; |
| 5658 | case kCondLT: |
| 5659 | if (gt_bias) { |
| 5660 | __ CmpLtS(FTMP, lhs, rhs); |
| 5661 | } else { |
| 5662 | __ CmpUltS(FTMP, lhs, rhs); |
| 5663 | } |
| 5664 | __ Bc1nez(FTMP, label); |
| 5665 | break; |
| 5666 | case kCondLE: |
| 5667 | if (gt_bias) { |
| 5668 | __ CmpLeS(FTMP, lhs, rhs); |
| 5669 | } else { |
| 5670 | __ CmpUleS(FTMP, lhs, rhs); |
| 5671 | } |
| 5672 | __ Bc1nez(FTMP, label); |
| 5673 | break; |
| 5674 | case kCondGT: |
| 5675 | if (gt_bias) { |
| 5676 | __ CmpUltS(FTMP, rhs, lhs); |
| 5677 | } else { |
| 5678 | __ CmpLtS(FTMP, rhs, lhs); |
| 5679 | } |
| 5680 | __ Bc1nez(FTMP, label); |
| 5681 | break; |
| 5682 | case kCondGE: |
| 5683 | if (gt_bias) { |
| 5684 | __ CmpUleS(FTMP, rhs, lhs); |
| 5685 | } else { |
| 5686 | __ CmpLeS(FTMP, rhs, lhs); |
| 5687 | } |
| 5688 | __ Bc1nez(FTMP, label); |
| 5689 | break; |
| 5690 | default: |
| 5691 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5692 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5693 | } |
| 5694 | } else { |
| 5695 | switch (cond) { |
| 5696 | case kCondEQ: |
| 5697 | __ CeqS(0, lhs, rhs); |
| 5698 | __ Bc1t(0, label); |
| 5699 | break; |
| 5700 | case kCondNE: |
| 5701 | __ CeqS(0, lhs, rhs); |
| 5702 | __ Bc1f(0, label); |
| 5703 | break; |
| 5704 | case kCondLT: |
| 5705 | if (gt_bias) { |
| 5706 | __ ColtS(0, lhs, rhs); |
| 5707 | } else { |
| 5708 | __ CultS(0, lhs, rhs); |
| 5709 | } |
| 5710 | __ Bc1t(0, label); |
| 5711 | break; |
| 5712 | case kCondLE: |
| 5713 | if (gt_bias) { |
| 5714 | __ ColeS(0, lhs, rhs); |
| 5715 | } else { |
| 5716 | __ CuleS(0, lhs, rhs); |
| 5717 | } |
| 5718 | __ Bc1t(0, label); |
| 5719 | break; |
| 5720 | case kCondGT: |
| 5721 | if (gt_bias) { |
| 5722 | __ CultS(0, rhs, lhs); |
| 5723 | } else { |
| 5724 | __ ColtS(0, rhs, lhs); |
| 5725 | } |
| 5726 | __ Bc1t(0, label); |
| 5727 | break; |
| 5728 | case kCondGE: |
| 5729 | if (gt_bias) { |
| 5730 | __ CuleS(0, rhs, lhs); |
| 5731 | } else { |
| 5732 | __ ColeS(0, rhs, lhs); |
| 5733 | } |
| 5734 | __ Bc1t(0, label); |
| 5735 | break; |
| 5736 | default: |
| 5737 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5738 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5739 | } |
| 5740 | } |
| 5741 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5742 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5743 | if (isR6) { |
| 5744 | switch (cond) { |
| 5745 | case kCondEQ: |
| 5746 | __ CmpEqD(FTMP, lhs, rhs); |
| 5747 | __ Bc1nez(FTMP, label); |
| 5748 | break; |
| 5749 | case kCondNE: |
| 5750 | __ CmpEqD(FTMP, lhs, rhs); |
| 5751 | __ Bc1eqz(FTMP, label); |
| 5752 | break; |
| 5753 | case kCondLT: |
| 5754 | if (gt_bias) { |
| 5755 | __ CmpLtD(FTMP, lhs, rhs); |
| 5756 | } else { |
| 5757 | __ CmpUltD(FTMP, lhs, rhs); |
| 5758 | } |
| 5759 | __ Bc1nez(FTMP, label); |
| 5760 | break; |
| 5761 | case kCondLE: |
| 5762 | if (gt_bias) { |
| 5763 | __ CmpLeD(FTMP, lhs, rhs); |
| 5764 | } else { |
| 5765 | __ CmpUleD(FTMP, lhs, rhs); |
| 5766 | } |
| 5767 | __ Bc1nez(FTMP, label); |
| 5768 | break; |
| 5769 | case kCondGT: |
| 5770 | if (gt_bias) { |
| 5771 | __ CmpUltD(FTMP, rhs, lhs); |
| 5772 | } else { |
| 5773 | __ CmpLtD(FTMP, rhs, lhs); |
| 5774 | } |
| 5775 | __ Bc1nez(FTMP, label); |
| 5776 | break; |
| 5777 | case kCondGE: |
| 5778 | if (gt_bias) { |
| 5779 | __ CmpUleD(FTMP, rhs, lhs); |
| 5780 | } else { |
| 5781 | __ CmpLeD(FTMP, rhs, lhs); |
| 5782 | } |
| 5783 | __ Bc1nez(FTMP, label); |
| 5784 | break; |
| 5785 | default: |
| 5786 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5787 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5788 | } |
| 5789 | } else { |
| 5790 | switch (cond) { |
| 5791 | case kCondEQ: |
| 5792 | __ CeqD(0, lhs, rhs); |
| 5793 | __ Bc1t(0, label); |
| 5794 | break; |
| 5795 | case kCondNE: |
| 5796 | __ CeqD(0, lhs, rhs); |
| 5797 | __ Bc1f(0, label); |
| 5798 | break; |
| 5799 | case kCondLT: |
| 5800 | if (gt_bias) { |
| 5801 | __ ColtD(0, lhs, rhs); |
| 5802 | } else { |
| 5803 | __ CultD(0, lhs, rhs); |
| 5804 | } |
| 5805 | __ Bc1t(0, label); |
| 5806 | break; |
| 5807 | case kCondLE: |
| 5808 | if (gt_bias) { |
| 5809 | __ ColeD(0, lhs, rhs); |
| 5810 | } else { |
| 5811 | __ CuleD(0, lhs, rhs); |
| 5812 | } |
| 5813 | __ Bc1t(0, label); |
| 5814 | break; |
| 5815 | case kCondGT: |
| 5816 | if (gt_bias) { |
| 5817 | __ CultD(0, rhs, lhs); |
| 5818 | } else { |
| 5819 | __ ColtD(0, rhs, lhs); |
| 5820 | } |
| 5821 | __ Bc1t(0, label); |
| 5822 | break; |
| 5823 | case kCondGE: |
| 5824 | if (gt_bias) { |
| 5825 | __ CuleD(0, rhs, lhs); |
| 5826 | } else { |
| 5827 | __ ColeD(0, rhs, lhs); |
| 5828 | } |
| 5829 | __ Bc1t(0, label); |
| 5830 | break; |
| 5831 | default: |
| 5832 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5833 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5834 | } |
| 5835 | } |
| 5836 | } |
| 5837 | } |
| 5838 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5839 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5840 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5841 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5842 | MipsLabel* false_target) { |
| 5843 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5844 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5845 | if (true_target == nullptr && false_target == nullptr) { |
| 5846 | // Nothing to do. The code always falls through. |
| 5847 | return; |
| 5848 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5849 | // Constant condition, statically compared against "true" (integer value 1). |
| 5850 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5851 | if (true_target != nullptr) { |
| 5852 | __ B(true_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5853 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5854 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5855 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5856 | if (false_target != nullptr) { |
| 5857 | __ B(false_target); |
| 5858 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5859 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5860 | return; |
| 5861 | } |
| 5862 | |
| 5863 | // The following code generates these patterns: |
| 5864 | // (1) true_target == nullptr && false_target != nullptr |
| 5865 | // - opposite condition true => branch to false_target |
| 5866 | // (2) true_target != nullptr && false_target == nullptr |
| 5867 | // - condition true => branch to true_target |
| 5868 | // (3) true_target != nullptr && false_target != nullptr |
| 5869 | // - condition true => branch to true_target |
| 5870 | // - branch to false_target |
| 5871 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5872 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5873 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5874 | DCHECK(cond_val.IsRegister()); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5875 | if (true_target == nullptr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5876 | __ Beqz(cond_val.AsRegister<Register>(), false_target); |
| 5877 | } else { |
| 5878 | __ Bnez(cond_val.AsRegister<Register>(), true_target); |
| 5879 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5880 | } else { |
| 5881 | // The condition instruction has not been materialized, use its inputs as |
| 5882 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5883 | HCondition* condition = cond->AsCondition(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5884 | DataType::Type type = condition->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5885 | LocationSummary* locations = cond->GetLocations(); |
| 5886 | IfCondition if_cond = condition->GetCondition(); |
| 5887 | MipsLabel* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5888 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5889 | if (true_target == nullptr) { |
| 5890 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5891 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5892 | } |
| 5893 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5894 | switch (type) { |
| 5895 | default: |
| 5896 | GenerateIntCompareAndBranch(if_cond, locations, branch_target); |
| 5897 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5898 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5899 | GenerateLongCompareAndBranch(if_cond, locations, branch_target); |
| 5900 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5901 | case DataType::Type::kFloat32: |
| 5902 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5903 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 5904 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5905 | } |
| 5906 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5907 | |
| 5908 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 5909 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 5910 | if (true_target != nullptr && false_target != nullptr) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5911 | __ B(false_target); |
| 5912 | } |
| 5913 | } |
| 5914 | |
| 5915 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5916 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5917 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5918 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5919 | } |
| 5920 | } |
| 5921 | |
| 5922 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5923 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 5924 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 5925 | MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 5926 | nullptr : codegen_->GetLabelOf(true_successor); |
| 5927 | MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 5928 | nullptr : codegen_->GetLabelOf(false_successor); |
| 5929 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5930 | } |
| 5931 | |
| 5932 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5933 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5934 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 5935 | InvokeRuntimeCallingConvention calling_convention; |
| 5936 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5937 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5938 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5939 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5940 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5941 | } |
| 5942 | } |
| 5943 | |
| 5944 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 5945 | SlowPathCodeMIPS* slow_path = |
| 5946 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5947 | GenerateTestAndBranch(deoptimize, |
| 5948 | /* condition_input_index */ 0, |
| 5949 | slow_path->GetEntryLabel(), |
| 5950 | /* false_target */ nullptr); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5951 | } |
| 5952 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5953 | // This function returns true if a conditional move can be generated for HSelect. |
| 5954 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 5955 | // branches and regular moves. |
| 5956 | // |
| 5957 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 5958 | // |
| 5959 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 5960 | // are two distinct tasks, this function does both because they share quite a bit |
| 5961 | // of common logic. |
| 5962 | static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) { |
| 5963 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 5964 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 5965 | HCondition* condition = cond->AsCondition(); |
| 5966 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5967 | DataType::Type cond_type = |
| 5968 | materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType(); |
| 5969 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5970 | |
| 5971 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 5972 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 5973 | bool is_true_value_zero_constant = |
| 5974 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 5975 | bool is_false_value_zero_constant = |
| 5976 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 5977 | |
| 5978 | bool can_move_conditionally = false; |
| 5979 | bool use_const_for_false_in = false; |
| 5980 | bool use_const_for_true_in = false; |
| 5981 | |
| 5982 | if (!cond->IsConstant()) { |
| 5983 | switch (cond_type) { |
| 5984 | default: |
| 5985 | switch (dst_type) { |
| 5986 | default: |
| 5987 | // Moving int on int condition. |
| 5988 | if (is_r6) { |
| 5989 | if (is_true_value_zero_constant) { |
| 5990 | // seleqz out_reg, false_reg, cond_reg |
| 5991 | can_move_conditionally = true; |
| 5992 | use_const_for_true_in = true; |
| 5993 | } else if (is_false_value_zero_constant) { |
| 5994 | // selnez out_reg, true_reg, cond_reg |
| 5995 | can_move_conditionally = true; |
| 5996 | use_const_for_false_in = true; |
| 5997 | } else if (materialized) { |
| 5998 | // Not materializing unmaterialized int conditions |
| 5999 | // to keep the instruction count low. |
| 6000 | // selnez AT, true_reg, cond_reg |
| 6001 | // seleqz TMP, false_reg, cond_reg |
| 6002 | // or out_reg, AT, TMP |
| 6003 | can_move_conditionally = true; |
| 6004 | } |
| 6005 | } else { |
| 6006 | // movn out_reg, true_reg/ZERO, cond_reg |
| 6007 | can_move_conditionally = true; |
| 6008 | use_const_for_true_in = is_true_value_zero_constant; |
| 6009 | } |
| 6010 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6011 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6012 | // Moving long on int condition. |
| 6013 | if (is_r6) { |
| 6014 | if (is_true_value_zero_constant) { |
| 6015 | // seleqz out_reg_lo, false_reg_lo, cond_reg |
| 6016 | // seleqz out_reg_hi, false_reg_hi, cond_reg |
| 6017 | can_move_conditionally = true; |
| 6018 | use_const_for_true_in = true; |
| 6019 | } else if (is_false_value_zero_constant) { |
| 6020 | // selnez out_reg_lo, true_reg_lo, cond_reg |
| 6021 | // selnez out_reg_hi, true_reg_hi, cond_reg |
| 6022 | can_move_conditionally = true; |
| 6023 | use_const_for_false_in = true; |
| 6024 | } |
| 6025 | // Other long conditional moves would generate 6+ instructions, |
| 6026 | // which is too many. |
| 6027 | } else { |
| 6028 | // movn out_reg_lo, true_reg_lo/ZERO, cond_reg |
| 6029 | // movn out_reg_hi, true_reg_hi/ZERO, cond_reg |
| 6030 | can_move_conditionally = true; |
| 6031 | use_const_for_true_in = is_true_value_zero_constant; |
| 6032 | } |
| 6033 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6034 | case DataType::Type::kFloat32: |
| 6035 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6036 | // Moving float/double on int condition. |
| 6037 | if (is_r6) { |
| 6038 | if (materialized) { |
| 6039 | // Not materializing unmaterialized int conditions |
| 6040 | // to keep the instruction count low. |
| 6041 | can_move_conditionally = true; |
| 6042 | if (is_true_value_zero_constant) { |
| 6043 | // sltu TMP, ZERO, cond_reg |
| 6044 | // mtc1 TMP, temp_cond_reg |
| 6045 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 6046 | use_const_for_true_in = true; |
| 6047 | } else if (is_false_value_zero_constant) { |
| 6048 | // sltu TMP, ZERO, cond_reg |
| 6049 | // mtc1 TMP, temp_cond_reg |
| 6050 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 6051 | use_const_for_false_in = true; |
| 6052 | } else { |
| 6053 | // sltu TMP, ZERO, cond_reg |
| 6054 | // mtc1 TMP, temp_cond_reg |
| 6055 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 6056 | // mov.fmt out_reg, temp_cond_reg |
| 6057 | } |
| 6058 | } |
| 6059 | } else { |
| 6060 | // movn.fmt out_reg, true_reg, cond_reg |
| 6061 | can_move_conditionally = true; |
| 6062 | } |
| 6063 | break; |
| 6064 | } |
| 6065 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6066 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6067 | // We don't materialize long comparison now |
| 6068 | // and use conditional branches instead. |
| 6069 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6070 | case DataType::Type::kFloat32: |
| 6071 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6072 | switch (dst_type) { |
| 6073 | default: |
| 6074 | // Moving int on float/double condition. |
| 6075 | if (is_r6) { |
| 6076 | if (is_true_value_zero_constant) { |
| 6077 | // mfc1 TMP, temp_cond_reg |
| 6078 | // seleqz out_reg, false_reg, TMP |
| 6079 | can_move_conditionally = true; |
| 6080 | use_const_for_true_in = true; |
| 6081 | } else if (is_false_value_zero_constant) { |
| 6082 | // mfc1 TMP, temp_cond_reg |
| 6083 | // selnez out_reg, true_reg, TMP |
| 6084 | can_move_conditionally = true; |
| 6085 | use_const_for_false_in = true; |
| 6086 | } else { |
| 6087 | // mfc1 TMP, temp_cond_reg |
| 6088 | // selnez AT, true_reg, TMP |
| 6089 | // seleqz TMP, false_reg, TMP |
| 6090 | // or out_reg, AT, TMP |
| 6091 | can_move_conditionally = true; |
| 6092 | } |
| 6093 | } else { |
| 6094 | // movt out_reg, true_reg/ZERO, cc |
| 6095 | can_move_conditionally = true; |
| 6096 | use_const_for_true_in = is_true_value_zero_constant; |
| 6097 | } |
| 6098 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6099 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6100 | // Moving long on float/double condition. |
| 6101 | if (is_r6) { |
| 6102 | if (is_true_value_zero_constant) { |
| 6103 | // mfc1 TMP, temp_cond_reg |
| 6104 | // seleqz out_reg_lo, false_reg_lo, TMP |
| 6105 | // seleqz out_reg_hi, false_reg_hi, TMP |
| 6106 | can_move_conditionally = true; |
| 6107 | use_const_for_true_in = true; |
| 6108 | } else if (is_false_value_zero_constant) { |
| 6109 | // mfc1 TMP, temp_cond_reg |
| 6110 | // selnez out_reg_lo, true_reg_lo, TMP |
| 6111 | // selnez out_reg_hi, true_reg_hi, TMP |
| 6112 | can_move_conditionally = true; |
| 6113 | use_const_for_false_in = true; |
| 6114 | } |
| 6115 | // Other long conditional moves would generate 6+ instructions, |
| 6116 | // which is too many. |
| 6117 | } else { |
| 6118 | // movt out_reg_lo, true_reg_lo/ZERO, cc |
| 6119 | // movt out_reg_hi, true_reg_hi/ZERO, cc |
| 6120 | can_move_conditionally = true; |
| 6121 | use_const_for_true_in = is_true_value_zero_constant; |
| 6122 | } |
| 6123 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6124 | case DataType::Type::kFloat32: |
| 6125 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6126 | // Moving float/double on float/double condition. |
| 6127 | if (is_r6) { |
| 6128 | can_move_conditionally = true; |
| 6129 | if (is_true_value_zero_constant) { |
| 6130 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 6131 | use_const_for_true_in = true; |
| 6132 | } else if (is_false_value_zero_constant) { |
| 6133 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 6134 | use_const_for_false_in = true; |
| 6135 | } else { |
| 6136 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 6137 | // mov.fmt out_reg, temp_cond_reg |
| 6138 | } |
| 6139 | } else { |
| 6140 | // movt.fmt out_reg, true_reg, cc |
| 6141 | can_move_conditionally = true; |
| 6142 | } |
| 6143 | break; |
| 6144 | } |
| 6145 | break; |
| 6146 | } |
| 6147 | } |
| 6148 | |
| 6149 | if (can_move_conditionally) { |
| 6150 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 6151 | } else { |
| 6152 | DCHECK(!use_const_for_false_in); |
| 6153 | DCHECK(!use_const_for_true_in); |
| 6154 | } |
| 6155 | |
| 6156 | if (locations_to_set != nullptr) { |
| 6157 | if (use_const_for_false_in) { |
| 6158 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 6159 | } else { |
| 6160 | locations_to_set->SetInAt(0, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6161 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6162 | ? Location::RequiresFpuRegister() |
| 6163 | : Location::RequiresRegister()); |
| 6164 | } |
| 6165 | if (use_const_for_true_in) { |
| 6166 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 6167 | } else { |
| 6168 | locations_to_set->SetInAt(1, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6169 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6170 | ? Location::RequiresFpuRegister() |
| 6171 | : Location::RequiresRegister()); |
| 6172 | } |
| 6173 | if (materialized) { |
| 6174 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 6175 | } |
| 6176 | // On R6 we don't require the output to be the same as the |
| 6177 | // first input for conditional moves unlike on R2. |
| 6178 | bool is_out_same_as_first_in = !can_move_conditionally || !is_r6; |
| 6179 | if (is_out_same_as_first_in) { |
| 6180 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 6181 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6182 | locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6183 | ? Location::RequiresFpuRegister() |
| 6184 | : Location::RequiresRegister()); |
| 6185 | } |
| 6186 | } |
| 6187 | |
| 6188 | return can_move_conditionally; |
| 6189 | } |
| 6190 | |
| 6191 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) { |
| 6192 | LocationSummary* locations = select->GetLocations(); |
| 6193 | Location dst = locations->Out(); |
| 6194 | Location src = locations->InAt(1); |
| 6195 | Register src_reg = ZERO; |
| 6196 | Register src_reg_high = ZERO; |
| 6197 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 6198 | Register cond_reg = TMP; |
| 6199 | int cond_cc = 0; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6200 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6201 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6202 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6203 | |
| 6204 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 6205 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 6206 | } else { |
| 6207 | HCondition* condition = cond->AsCondition(); |
| 6208 | LocationSummary* cond_locations = cond->GetLocations(); |
| 6209 | IfCondition if_cond = condition->GetCondition(); |
| 6210 | cond_type = condition->InputAt(0)->GetType(); |
| 6211 | switch (cond_type) { |
| 6212 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6213 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6214 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 6215 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6216 | case DataType::Type::kFloat32: |
| 6217 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6218 | cond_inverted = MaterializeFpCompareR2(if_cond, |
| 6219 | condition->IsGtBias(), |
| 6220 | cond_type, |
| 6221 | cond_locations, |
| 6222 | cond_cc); |
| 6223 | break; |
| 6224 | } |
| 6225 | } |
| 6226 | |
| 6227 | DCHECK(dst.Equals(locations->InAt(0))); |
| 6228 | if (src.IsRegister()) { |
| 6229 | src_reg = src.AsRegister<Register>(); |
| 6230 | } else if (src.IsRegisterPair()) { |
| 6231 | src_reg = src.AsRegisterPairLow<Register>(); |
| 6232 | src_reg_high = src.AsRegisterPairHigh<Register>(); |
| 6233 | } else if (src.IsConstant()) { |
| 6234 | DCHECK(src.GetConstant()->IsZeroBitPattern()); |
| 6235 | } |
| 6236 | |
| 6237 | switch (cond_type) { |
| 6238 | default: |
| 6239 | switch (dst_type) { |
| 6240 | default: |
| 6241 | if (cond_inverted) { |
| 6242 | __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 6243 | } else { |
| 6244 | __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 6245 | } |
| 6246 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6247 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6248 | if (cond_inverted) { |
| 6249 | __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 6250 | __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 6251 | } else { |
| 6252 | __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 6253 | __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 6254 | } |
| 6255 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6256 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6257 | if (cond_inverted) { |
| 6258 | __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6259 | } else { |
| 6260 | __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6261 | } |
| 6262 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6263 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6264 | if (cond_inverted) { |
| 6265 | __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6266 | } else { |
| 6267 | __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6268 | } |
| 6269 | break; |
| 6270 | } |
| 6271 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6272 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6273 | LOG(FATAL) << "Unreachable"; |
| 6274 | UNREACHABLE(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6275 | case DataType::Type::kFloat32: |
| 6276 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6277 | switch (dst_type) { |
| 6278 | default: |
| 6279 | if (cond_inverted) { |
| 6280 | __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 6281 | } else { |
| 6282 | __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 6283 | } |
| 6284 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6285 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6286 | if (cond_inverted) { |
| 6287 | __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 6288 | __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 6289 | } else { |
| 6290 | __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 6291 | __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 6292 | } |
| 6293 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6294 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6295 | if (cond_inverted) { |
| 6296 | __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6297 | } else { |
| 6298 | __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6299 | } |
| 6300 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6301 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6302 | if (cond_inverted) { |
| 6303 | __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6304 | } else { |
| 6305 | __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6306 | } |
| 6307 | break; |
| 6308 | } |
| 6309 | break; |
| 6310 | } |
| 6311 | } |
| 6312 | |
| 6313 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) { |
| 6314 | LocationSummary* locations = select->GetLocations(); |
| 6315 | Location dst = locations->Out(); |
| 6316 | Location false_src = locations->InAt(0); |
| 6317 | Location true_src = locations->InAt(1); |
| 6318 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 6319 | Register cond_reg = TMP; |
| 6320 | FRegister fcond_reg = FTMP; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6321 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6322 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6323 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6324 | |
| 6325 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 6326 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 6327 | } else { |
| 6328 | HCondition* condition = cond->AsCondition(); |
| 6329 | LocationSummary* cond_locations = cond->GetLocations(); |
| 6330 | IfCondition if_cond = condition->GetCondition(); |
| 6331 | cond_type = condition->InputAt(0)->GetType(); |
| 6332 | switch (cond_type) { |
| 6333 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6334 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6335 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 6336 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6337 | case DataType::Type::kFloat32: |
| 6338 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6339 | cond_inverted = MaterializeFpCompareR6(if_cond, |
| 6340 | condition->IsGtBias(), |
| 6341 | cond_type, |
| 6342 | cond_locations, |
| 6343 | fcond_reg); |
| 6344 | break; |
| 6345 | } |
| 6346 | } |
| 6347 | |
| 6348 | if (true_src.IsConstant()) { |
| 6349 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 6350 | } |
| 6351 | if (false_src.IsConstant()) { |
| 6352 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 6353 | } |
| 6354 | |
| 6355 | switch (dst_type) { |
| 6356 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6357 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6358 | __ Mfc1(cond_reg, fcond_reg); |
| 6359 | } |
| 6360 | if (true_src.IsConstant()) { |
| 6361 | if (cond_inverted) { |
| 6362 | __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 6363 | } else { |
| 6364 | __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 6365 | } |
| 6366 | } else if (false_src.IsConstant()) { |
| 6367 | if (cond_inverted) { |
| 6368 | __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 6369 | } else { |
| 6370 | __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 6371 | } |
| 6372 | } else { |
| 6373 | DCHECK_NE(cond_reg, AT); |
| 6374 | if (cond_inverted) { |
| 6375 | __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6376 | __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6377 | } else { |
| 6378 | __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6379 | __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6380 | } |
| 6381 | __ Or(dst.AsRegister<Register>(), AT, TMP); |
| 6382 | } |
| 6383 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6384 | case DataType::Type::kInt64: { |
| 6385 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6386 | __ Mfc1(cond_reg, fcond_reg); |
| 6387 | } |
| 6388 | Register dst_lo = dst.AsRegisterPairLow<Register>(); |
| 6389 | Register dst_hi = dst.AsRegisterPairHigh<Register>(); |
| 6390 | if (true_src.IsConstant()) { |
| 6391 | Register src_lo = false_src.AsRegisterPairLow<Register>(); |
| 6392 | Register src_hi = false_src.AsRegisterPairHigh<Register>(); |
| 6393 | if (cond_inverted) { |
| 6394 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6395 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6396 | } else { |
| 6397 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6398 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6399 | } |
| 6400 | } else { |
| 6401 | DCHECK(false_src.IsConstant()); |
| 6402 | Register src_lo = true_src.AsRegisterPairLow<Register>(); |
| 6403 | Register src_hi = true_src.AsRegisterPairHigh<Register>(); |
| 6404 | if (cond_inverted) { |
| 6405 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6406 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6407 | } else { |
| 6408 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6409 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6410 | } |
| 6411 | } |
| 6412 | break; |
| 6413 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6414 | case DataType::Type::kFloat32: { |
| 6415 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6416 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6417 | __ Sltu(TMP, ZERO, cond_reg); |
| 6418 | __ Mtc1(TMP, fcond_reg); |
| 6419 | } |
| 6420 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6421 | if (true_src.IsConstant()) { |
| 6422 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6423 | if (cond_inverted) { |
| 6424 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6425 | } else { |
| 6426 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6427 | } |
| 6428 | } else if (false_src.IsConstant()) { |
| 6429 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6430 | if (cond_inverted) { |
| 6431 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6432 | } else { |
| 6433 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6434 | } |
| 6435 | } else { |
| 6436 | if (cond_inverted) { |
| 6437 | __ SelS(fcond_reg, |
| 6438 | true_src.AsFpuRegister<FRegister>(), |
| 6439 | false_src.AsFpuRegister<FRegister>()); |
| 6440 | } else { |
| 6441 | __ SelS(fcond_reg, |
| 6442 | false_src.AsFpuRegister<FRegister>(), |
| 6443 | true_src.AsFpuRegister<FRegister>()); |
| 6444 | } |
| 6445 | __ MovS(dst_reg, fcond_reg); |
| 6446 | } |
| 6447 | break; |
| 6448 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6449 | case DataType::Type::kFloat64: { |
| 6450 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6451 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6452 | __ Sltu(TMP, ZERO, cond_reg); |
| 6453 | __ Mtc1(TMP, fcond_reg); |
| 6454 | } |
| 6455 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6456 | if (true_src.IsConstant()) { |
| 6457 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6458 | if (cond_inverted) { |
| 6459 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6460 | } else { |
| 6461 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6462 | } |
| 6463 | } else if (false_src.IsConstant()) { |
| 6464 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6465 | if (cond_inverted) { |
| 6466 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6467 | } else { |
| 6468 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6469 | } |
| 6470 | } else { |
| 6471 | if (cond_inverted) { |
| 6472 | __ SelD(fcond_reg, |
| 6473 | true_src.AsFpuRegister<FRegister>(), |
| 6474 | false_src.AsFpuRegister<FRegister>()); |
| 6475 | } else { |
| 6476 | __ SelD(fcond_reg, |
| 6477 | false_src.AsFpuRegister<FRegister>(), |
| 6478 | true_src.AsFpuRegister<FRegister>()); |
| 6479 | } |
| 6480 | __ MovD(dst_reg, fcond_reg); |
| 6481 | } |
| 6482 | break; |
| 6483 | } |
| 6484 | } |
| 6485 | } |
| 6486 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6487 | void LocationsBuilderMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6488 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6489 | LocationSummary(flag, LocationSummary::kNoCall); |
| 6490 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6491 | } |
| 6492 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6493 | void InstructionCodeGeneratorMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 6494 | __ LoadFromOffset(kLoadWord, |
| 6495 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 6496 | SP, |
| 6497 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6498 | } |
| 6499 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6500 | void LocationsBuilderMIPS::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6501 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6502 | CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6503 | } |
| 6504 | |
| 6505 | void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6506 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 6507 | if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) { |
| 6508 | if (is_r6) { |
| 6509 | GenConditionalMoveR6(select); |
| 6510 | } else { |
| 6511 | GenConditionalMoveR2(select); |
| 6512 | } |
| 6513 | } else { |
| 6514 | LocationSummary* locations = select->GetLocations(); |
| 6515 | MipsLabel false_target; |
| 6516 | GenerateTestAndBranch(select, |
| 6517 | /* condition_input_index */ 2, |
| 6518 | /* true_target */ nullptr, |
| 6519 | &false_target); |
| 6520 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 6521 | __ Bind(&false_target); |
| 6522 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6523 | } |
| 6524 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6525 | void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6526 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6527 | } |
| 6528 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 6529 | void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 6530 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 6531 | } |
| 6532 | |
| 6533 | void CodeGeneratorMIPS::GenerateNop() { |
| 6534 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6535 | } |
| 6536 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6537 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6538 | DataType::Type field_type = field_info.GetFieldType(); |
| 6539 | 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] | 6540 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6541 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6542 | kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6543 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6544 | instruction, |
| 6545 | generate_volatile |
| 6546 | ? LocationSummary::kCallOnMainOnly |
| 6547 | : (object_field_get_with_read_barrier |
| 6548 | ? LocationSummary::kCallOnSlowPath |
| 6549 | : LocationSummary::kNoCall)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6550 | |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6551 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6552 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 6553 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6554 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6555 | if (generate_volatile) { |
| 6556 | InvokeRuntimeCallingConvention calling_convention; |
| 6557 | // need A0 to hold base + offset |
| 6558 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6559 | if (field_type == DataType::Type::kInt64) { |
| 6560 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kInt64)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6561 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6562 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6563 | locations->SetOut(Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6564 | // 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] | 6565 | Location reg = calling_convention.GetReturnLocation(DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6566 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); |
| 6567 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); |
| 6568 | } |
| 6569 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6570 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6571 | locations->SetOut(Location::RequiresFpuRegister()); |
| 6572 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6573 | // The output overlaps in the case of an object field get with |
| 6574 | // read barriers enabled: we do not want the move to overwrite the |
| 6575 | // object's location, as we need it to emit the read barrier. |
| 6576 | locations->SetOut(Location::RequiresRegister(), |
| 6577 | object_field_get_with_read_barrier |
| 6578 | ? Location::kOutputOverlap |
| 6579 | : Location::kNoOutputOverlap); |
| 6580 | } |
| 6581 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6582 | // We need a temporary register for the read barrier marking slow |
| 6583 | // path in CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6584 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6585 | locations->AddTemp(Location::RequiresRegister()); |
| 6586 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6587 | } |
| 6588 | } |
| 6589 | } |
| 6590 | |
| 6591 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, |
| 6592 | const FieldInfo& field_info, |
| 6593 | uint32_t dex_pc) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6594 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 6595 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6596 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6597 | Location obj_loc = locations->InAt(0); |
| 6598 | Register obj = obj_loc.AsRegister<Register>(); |
| 6599 | Location dst_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6600 | LoadOperandType load_type = kLoadUnsignedByte; |
| 6601 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6602 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6603 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6604 | |
| 6605 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6606 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6607 | case DataType::Type::kUint8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6608 | load_type = kLoadUnsignedByte; |
| 6609 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6610 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6611 | load_type = kLoadSignedByte; |
| 6612 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6613 | case DataType::Type::kUint16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6614 | load_type = kLoadUnsignedHalfword; |
| 6615 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6616 | case DataType::Type::kInt16: |
| 6617 | load_type = kLoadSignedHalfword; |
| 6618 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6619 | case DataType::Type::kInt32: |
| 6620 | case DataType::Type::kFloat32: |
| 6621 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6622 | load_type = kLoadWord; |
| 6623 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6624 | case DataType::Type::kInt64: |
| 6625 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6626 | load_type = kLoadDoubleword; |
| 6627 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6628 | case DataType::Type::kUint32: |
| 6629 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6630 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6631 | LOG(FATAL) << "Unreachable type " << type; |
| 6632 | UNREACHABLE(); |
| 6633 | } |
| 6634 | |
| 6635 | if (is_volatile && load_type == kLoadDoubleword) { |
| 6636 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6637 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6638 | // Do implicit Null check |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6639 | __ LoadFromOffset(kLoadWord, |
| 6640 | ZERO, |
| 6641 | locations->GetTemp(0).AsRegister<Register>(), |
| 6642 | 0, |
| 6643 | null_checker); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6644 | codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6645 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6646 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6647 | // FP results are returned in core registers. Need to move them. |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6648 | if (dst_loc.IsFpuRegister()) { |
| 6649 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6650 | __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6651 | dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6652 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6653 | DCHECK(dst_loc.IsDoubleStackSlot()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6654 | __ StoreToOffset(kStoreWord, |
| 6655 | locations->GetTemp(1).AsRegister<Register>(), |
| 6656 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6657 | dst_loc.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6658 | __ StoreToOffset(kStoreWord, |
| 6659 | locations->GetTemp(2).AsRegister<Register>(), |
| 6660 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6661 | dst_loc.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6662 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6663 | } |
| 6664 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6665 | if (type == DataType::Type::kReference) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6666 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 6667 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6668 | Location temp_loc = |
| 6669 | kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6670 | // Note that a potential implicit null check is handled in this |
| 6671 | // CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier call. |
| 6672 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6673 | dst_loc, |
| 6674 | obj, |
| 6675 | offset, |
| 6676 | temp_loc, |
| 6677 | /* needs_null_check */ true); |
| 6678 | if (is_volatile) { |
| 6679 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6680 | } |
| 6681 | } else { |
| 6682 | __ LoadFromOffset(kLoadWord, dst_loc.AsRegister<Register>(), obj, offset, null_checker); |
| 6683 | if (is_volatile) { |
| 6684 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6685 | } |
| 6686 | // If read barriers are enabled, emit read barriers other than |
| 6687 | // Baker's using a slow path (and also unpoison the loaded |
| 6688 | // reference, if heap poisoning is enabled). |
| 6689 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 6690 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6691 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6692 | Register dst; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6693 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6694 | DCHECK(dst_loc.IsRegisterPair()); |
| 6695 | dst = dst_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6696 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6697 | DCHECK(dst_loc.IsRegister()); |
| 6698 | dst = dst_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6699 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6700 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6701 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6702 | DCHECK(dst_loc.IsFpuRegister()); |
| 6703 | FRegister dst = dst_loc.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6704 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6705 | __ LoadSFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6706 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6707 | __ LoadDFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6708 | } |
| 6709 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6710 | } |
| 6711 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6712 | // Memory barriers, in the case of references, are handled in the |
| 6713 | // previous switch statement. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6714 | if (is_volatile && (type != DataType::Type::kReference)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6715 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6716 | } |
| 6717 | } |
| 6718 | |
| 6719 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6720 | DataType::Type field_type = field_info.GetFieldType(); |
| 6721 | 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] | 6722 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6723 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6724 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6725 | |
| 6726 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6727 | if (generate_volatile) { |
| 6728 | InvokeRuntimeCallingConvention calling_convention; |
| 6729 | // need A0 to hold base + offset |
| 6730 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6731 | if (field_type == DataType::Type::kInt64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6732 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 6733 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 6734 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6735 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6736 | locations->SetInAt(1, Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6737 | // Pass FP parameters in core registers. |
| 6738 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 6739 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 6740 | } |
| 6741 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6742 | if (DataType::IsFloatingPointType(field_type)) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6743 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6744 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6745 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6746 | } |
| 6747 | } |
| 6748 | } |
| 6749 | |
| 6750 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, |
| 6751 | const FieldInfo& field_info, |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6752 | uint32_t dex_pc, |
| 6753 | bool value_can_be_null) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6754 | DataType::Type type = field_info.GetFieldType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6755 | LocationSummary* locations = instruction->GetLocations(); |
| 6756 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6757 | Location value_location = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6758 | StoreOperandType store_type = kStoreByte; |
| 6759 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6760 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6761 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6762 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6763 | |
| 6764 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6765 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6766 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6767 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6768 | store_type = kStoreByte; |
| 6769 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6770 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6771 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6772 | store_type = kStoreHalfword; |
| 6773 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6774 | case DataType::Type::kInt32: |
| 6775 | case DataType::Type::kFloat32: |
| 6776 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6777 | store_type = kStoreWord; |
| 6778 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6779 | case DataType::Type::kInt64: |
| 6780 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6781 | store_type = kStoreDoubleword; |
| 6782 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6783 | case DataType::Type::kUint32: |
| 6784 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6785 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6786 | LOG(FATAL) << "Unreachable type " << type; |
| 6787 | UNREACHABLE(); |
| 6788 | } |
| 6789 | |
| 6790 | if (is_volatile) { |
| 6791 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 6792 | } |
| 6793 | |
| 6794 | if (is_volatile && store_type == kStoreDoubleword) { |
| 6795 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6796 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6797 | // Do implicit Null check. |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6798 | __ LoadFromOffset(kLoadWord, |
| 6799 | ZERO, |
| 6800 | locations->GetTemp(0).AsRegister<Register>(), |
| 6801 | 0, |
| 6802 | null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6803 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6804 | // Pass FP parameters in core registers. |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6805 | if (value_location.IsFpuRegister()) { |
| 6806 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), |
| 6807 | value_location.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6808 | __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6809 | value_location.AsFpuRegister<FRegister>()); |
| 6810 | } else if (value_location.IsDoubleStackSlot()) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6811 | __ LoadFromOffset(kLoadWord, |
| 6812 | locations->GetTemp(1).AsRegister<Register>(), |
| 6813 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6814 | value_location.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6815 | __ LoadFromOffset(kLoadWord, |
| 6816 | locations->GetTemp(2).AsRegister<Register>(), |
| 6817 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6818 | value_location.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6819 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6820 | DCHECK(value_location.IsConstant()); |
| 6821 | DCHECK(value_location.GetConstant()->IsDoubleConstant()); |
| 6822 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6823 | __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(), |
| 6824 | locations->GetTemp(1).AsRegister<Register>(), |
| 6825 | value); |
| 6826 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6827 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6828 | codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6829 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); |
| 6830 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6831 | if (value_location.IsConstant()) { |
| 6832 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 6833 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6834 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6835 | Register src; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6836 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6837 | src = value_location.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6838 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6839 | src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6840 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6841 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 6842 | // Note that in the case where `value` is a null reference, |
| 6843 | // we do not enter this block, as a null reference does not |
| 6844 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6845 | DCHECK_EQ(type, DataType::Type::kReference); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6846 | __ PoisonHeapReference(TMP, src); |
| 6847 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 6848 | } else { |
| 6849 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 6850 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6851 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6852 | FRegister src = value_location.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6853 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6854 | __ StoreSToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6855 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6856 | __ StoreDToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6857 | } |
| 6858 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6859 | } |
| 6860 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6861 | if (needs_write_barrier) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6862 | Register src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6863 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6864 | } |
| 6865 | |
| 6866 | if (is_volatile) { |
| 6867 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 6868 | } |
| 6869 | } |
| 6870 | |
| 6871 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6872 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6873 | } |
| 6874 | |
| 6875 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6876 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 6877 | } |
| 6878 | |
| 6879 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6880 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6881 | } |
| 6882 | |
| 6883 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6884 | HandleFieldSet(instruction, |
| 6885 | instruction->GetFieldInfo(), |
| 6886 | instruction->GetDexPc(), |
| 6887 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6888 | } |
| 6889 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6890 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadOneRegister( |
| 6891 | HInstruction* instruction, |
| 6892 | Location out, |
| 6893 | uint32_t offset, |
| 6894 | Location maybe_temp, |
| 6895 | ReadBarrierOption read_barrier_option) { |
| 6896 | Register out_reg = out.AsRegister<Register>(); |
| 6897 | if (read_barrier_option == kWithReadBarrier) { |
| 6898 | CHECK(kEmitCompilerReadBarrier); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6899 | if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) { |
| 6900 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6901 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6902 | if (kUseBakerReadBarrier) { |
| 6903 | // Load with fast path based Baker's read barrier. |
| 6904 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6905 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6906 | out, |
| 6907 | out_reg, |
| 6908 | offset, |
| 6909 | maybe_temp, |
| 6910 | /* needs_null_check */ false); |
| 6911 | } else { |
| 6912 | // Load with slow path based read barrier. |
| 6913 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6914 | // in the following move operation, as we will need it for the |
| 6915 | // read barrier below. |
| 6916 | __ Move(maybe_temp.AsRegister<Register>(), out_reg); |
| 6917 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6918 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6919 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6920 | } |
| 6921 | } else { |
| 6922 | // Plain load with no read barrier. |
| 6923 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6924 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6925 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6926 | } |
| 6927 | } |
| 6928 | |
| 6929 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadTwoRegisters( |
| 6930 | HInstruction* instruction, |
| 6931 | Location out, |
| 6932 | Location obj, |
| 6933 | uint32_t offset, |
| 6934 | Location maybe_temp, |
| 6935 | ReadBarrierOption read_barrier_option) { |
| 6936 | Register out_reg = out.AsRegister<Register>(); |
| 6937 | Register obj_reg = obj.AsRegister<Register>(); |
| 6938 | if (read_barrier_option == kWithReadBarrier) { |
| 6939 | CHECK(kEmitCompilerReadBarrier); |
| 6940 | if (kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6941 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6942 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6943 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6944 | // Load with fast path based Baker's read barrier. |
| 6945 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6946 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6947 | out, |
| 6948 | obj_reg, |
| 6949 | offset, |
| 6950 | maybe_temp, |
| 6951 | /* needs_null_check */ false); |
| 6952 | } else { |
| 6953 | // Load with slow path based read barrier. |
| 6954 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6955 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6956 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6957 | } |
| 6958 | } else { |
| 6959 | // Plain load with no read barrier. |
| 6960 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6961 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6962 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6963 | } |
| 6964 | } |
| 6965 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6966 | static inline int GetBakerMarkThunkNumber(Register reg) { |
| 6967 | static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 21, "Expecting equal"); |
| 6968 | if (reg >= V0 && reg <= T7) { // 14 consequtive regs. |
| 6969 | return reg - V0; |
| 6970 | } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs. |
| 6971 | return 14 + (reg - S2); |
| 6972 | } else if (reg == FP) { // One more. |
| 6973 | return 20; |
| 6974 | } |
| 6975 | LOG(FATAL) << "Unexpected register " << reg; |
| 6976 | UNREACHABLE(); |
| 6977 | } |
| 6978 | |
| 6979 | static inline int GetBakerMarkFieldArrayThunkDisplacement(Register reg, bool short_offset) { |
| 6980 | int num = GetBakerMarkThunkNumber(reg) + |
| 6981 | (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0); |
| 6982 | return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE; |
| 6983 | } |
| 6984 | |
| 6985 | static inline int GetBakerMarkGcRootThunkDisplacement(Register reg) { |
| 6986 | return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE + |
| 6987 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET; |
| 6988 | } |
| 6989 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6990 | void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6991 | Location root, |
| 6992 | Register obj, |
| 6993 | uint32_t offset, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6994 | ReadBarrierOption read_barrier_option, |
| 6995 | MipsLabel* label_low) { |
| 6996 | bool reordering; |
| 6997 | if (label_low != nullptr) { |
| 6998 | DCHECK_EQ(offset, 0x5678u); |
| 6999 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7000 | Register root_reg = root.AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7001 | if (read_barrier_option == kWithReadBarrier) { |
| 7002 | DCHECK(kEmitCompilerReadBarrier); |
| 7003 | if (kUseBakerReadBarrier) { |
| 7004 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7005 | // Baker's read barrier are used: |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7006 | if (kBakerReadBarrierThunksEnableForGcRoots) { |
| 7007 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 7008 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 7009 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 7010 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 7011 | // vice versa. |
| 7012 | // |
| 7013 | // We use thunks for the slow path. That thunk checks the reference |
| 7014 | // and jumps to the entrypoint if needed. |
| 7015 | // |
| 7016 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 7017 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 7018 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 7019 | // if (temp != nullptr) { |
| 7020 | // temp = &gc_root_thunk<root_reg> |
| 7021 | // root = temp(root) |
| 7022 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7023 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7024 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 7025 | const int32_t entry_point_offset = |
| 7026 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 7027 | const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg); |
| 7028 | int16_t offset_low = Low16Bits(offset); |
| 7029 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign |
| 7030 | // extension in lw. |
| 7031 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 7032 | Register base = short_offset ? obj : TMP; |
| 7033 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7034 | // threads are suspended or running a checkpoint. |
| 7035 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 7036 | reordering = __ SetReorder(false); |
| 7037 | if (!short_offset) { |
| 7038 | DCHECK(!label_low); |
| 7039 | __ AddUpper(base, obj, offset_high); |
| 7040 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7041 | MipsLabel skip_call; |
| 7042 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7043 | if (label_low != nullptr) { |
| 7044 | DCHECK(short_offset); |
| 7045 | __ Bind(label_low); |
| 7046 | } |
| 7047 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7048 | __ LoadFromOffset(kLoadWord, root_reg, base, offset_low); // Single instruction |
| 7049 | // in delay slot. |
| 7050 | if (isR6) { |
| 7051 | __ Jialc(T9, thunk_disp); |
| 7052 | } else { |
| 7053 | __ Addiu(T9, T9, thunk_disp); |
| 7054 | __ Jalr(T9); |
| 7055 | __ Nop(); |
| 7056 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7057 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7058 | __ SetReorder(reordering); |
| 7059 | } else { |
| 7060 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 7061 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 7062 | // load into `temp` (T9) the read barrier mark entry point corresponding |
| 7063 | // to register `root`. If `temp` is null, it means that `GetIsGcMarking()` |
| 7064 | // is false, and vice versa. |
| 7065 | // |
| 7066 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 7067 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7068 | // if (temp != null) { |
| 7069 | // root = temp(root) |
| 7070 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7071 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7072 | if (label_low != nullptr) { |
| 7073 | reordering = __ SetReorder(false); |
| 7074 | __ Bind(label_low); |
| 7075 | } |
| 7076 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7077 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7078 | if (label_low != nullptr) { |
| 7079 | __ SetReorder(reordering); |
| 7080 | } |
| 7081 | static_assert( |
| 7082 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7083 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7084 | "have different sizes."); |
| 7085 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7086 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7087 | "have different sizes."); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7088 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7089 | // Slow path marking the GC root `root`. |
| 7090 | Location temp = Location::RegisterLocation(T9); |
| 7091 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7092 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS( |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7093 | instruction, |
| 7094 | root, |
| 7095 | /*entrypoint*/ temp); |
| 7096 | codegen_->AddSlowPath(slow_path); |
| 7097 | |
| 7098 | const int32_t entry_point_offset = |
| 7099 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(root.reg() - 1); |
| 7100 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7101 | // threads are suspended or running a checkpoint. |
| 7102 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 7103 | __ Bnez(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 7104 | __ Bind(slow_path->GetExitLabel()); |
| 7105 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7106 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7107 | if (label_low != nullptr) { |
| 7108 | reordering = __ SetReorder(false); |
| 7109 | __ Bind(label_low); |
| 7110 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7111 | // GC root loaded through a slow path for read barriers other |
| 7112 | // than Baker's. |
| 7113 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 7114 | __ Addiu32(root_reg, obj, offset); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7115 | if (label_low != nullptr) { |
| 7116 | __ SetReorder(reordering); |
| 7117 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7118 | // /* mirror::Object* */ root = root->Read() |
| 7119 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7120 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7121 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7122 | if (label_low != nullptr) { |
| 7123 | reordering = __ SetReorder(false); |
| 7124 | __ Bind(label_low); |
| 7125 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7126 | // Plain GC root load with no read barrier. |
| 7127 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7128 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7129 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7130 | // do not have to unpoison `root_reg` here. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7131 | if (label_low != nullptr) { |
| 7132 | __ SetReorder(reordering); |
| 7133 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7134 | } |
| 7135 | } |
| 7136 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7137 | void CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7138 | Location ref, |
| 7139 | Register obj, |
| 7140 | uint32_t offset, |
| 7141 | Location temp, |
| 7142 | bool needs_null_check) { |
| 7143 | DCHECK(kEmitCompilerReadBarrier); |
| 7144 | DCHECK(kUseBakerReadBarrier); |
| 7145 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7146 | if (kBakerReadBarrierThunksEnableForFields) { |
| 7147 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 7148 | // to decide whether to mark the loaded reference or not. Instead, we |
| 7149 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 7150 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 7151 | // vice versa. |
| 7152 | // |
| 7153 | // We use thunks for the slow path. That thunk checks the reference |
| 7154 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 7155 | // it issues a load-load memory barrier and returns to the original |
| 7156 | // reference load. |
| 7157 | // |
| 7158 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 7159 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 7160 | // if (temp != nullptr) { |
| 7161 | // temp = &field_array_thunk<holder_reg> |
| 7162 | // temp() |
| 7163 | // } |
| 7164 | // not_gray_return_address: |
| 7165 | // // If the offset is too large to fit into the lw instruction, we |
| 7166 | // // use an adjusted base register (TMP) here. This register |
| 7167 | // // receives bits 16 ... 31 of the offset before the thunk invocation |
| 7168 | // // and the thunk benefits from it. |
| 7169 | // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load. |
| 7170 | // gray_return_address: |
| 7171 | |
| 7172 | DCHECK(temp.IsInvalid()); |
| 7173 | bool isR6 = GetInstructionSetFeatures().IsR6(); |
| 7174 | int16_t offset_low = Low16Bits(offset); |
| 7175 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lw. |
| 7176 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 7177 | bool reordering = __ SetReorder(false); |
| 7178 | const int32_t entry_point_offset = |
| 7179 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 7180 | // There may have or may have not been a null check if the field offset is smaller than |
| 7181 | // the page size. |
| 7182 | // There must've been a null check in case it's actually a load from an array. |
| 7183 | // We will, however, perform an explicit null check in the thunk as it's easier to |
| 7184 | // do it than not. |
| 7185 | if (instruction->IsArrayGet()) { |
| 7186 | DCHECK(!needs_null_check); |
| 7187 | } |
| 7188 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset); |
| 7189 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7190 | // threads are suspended or running a checkpoint. |
| 7191 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 7192 | Register ref_reg = ref.AsRegister<Register>(); |
| 7193 | Register base = short_offset ? obj : TMP; |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7194 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7195 | if (short_offset) { |
| 7196 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7197 | __ Beqzc(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7198 | __ Nop(); // In forbidden slot. |
| 7199 | __ Jialc(T9, thunk_disp); |
| 7200 | } else { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7201 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7202 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 7203 | __ Jalr(T9); |
| 7204 | __ Nop(); // In delay slot. |
| 7205 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7206 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7207 | } else { |
| 7208 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7209 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7210 | __ Aui(base, obj, offset_high); // In delay slot. |
| 7211 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7212 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7213 | } else { |
| 7214 | __ Lui(base, offset_high); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7215 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7216 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 7217 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7218 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7219 | __ Addu(base, base, obj); // In delay slot. |
| 7220 | } |
| 7221 | } |
| 7222 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7223 | __ LoadFromOffset(kLoadWord, ref_reg, base, offset_low); // Single instruction. |
| 7224 | if (needs_null_check) { |
| 7225 | MaybeRecordImplicitNullCheck(instruction); |
| 7226 | } |
| 7227 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7228 | __ SetReorder(reordering); |
| 7229 | return; |
| 7230 | } |
| 7231 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7232 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7233 | Location no_index = Location::NoLocation(); |
| 7234 | ScaleFactor no_scale_factor = TIMES_1; |
| 7235 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 7236 | ref, |
| 7237 | obj, |
| 7238 | offset, |
| 7239 | no_index, |
| 7240 | no_scale_factor, |
| 7241 | temp, |
| 7242 | needs_null_check); |
| 7243 | } |
| 7244 | |
| 7245 | void CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7246 | Location ref, |
| 7247 | Register obj, |
| 7248 | uint32_t data_offset, |
| 7249 | Location index, |
| 7250 | Location temp, |
| 7251 | bool needs_null_check) { |
| 7252 | DCHECK(kEmitCompilerReadBarrier); |
| 7253 | DCHECK(kUseBakerReadBarrier); |
| 7254 | |
| 7255 | static_assert( |
| 7256 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7257 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7258 | ScaleFactor scale_factor = TIMES_4; |
| 7259 | |
| 7260 | if (kBakerReadBarrierThunksEnableForArrays) { |
| 7261 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 7262 | // to decide whether to mark the loaded reference or not. Instead, we |
| 7263 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 7264 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 7265 | // vice versa. |
| 7266 | // |
| 7267 | // We use thunks for the slow path. That thunk checks the reference |
| 7268 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 7269 | // it issues a load-load memory barrier and returns to the original |
| 7270 | // reference load. |
| 7271 | // |
| 7272 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 7273 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 7274 | // if (temp != nullptr) { |
| 7275 | // temp = &field_array_thunk<holder_reg> |
| 7276 | // temp() |
| 7277 | // } |
| 7278 | // not_gray_return_address: |
| 7279 | // // The element address is pre-calculated in the TMP register before the |
| 7280 | // // thunk invocation and the thunk benefits from it. |
| 7281 | // HeapReference<mirror::Object> reference = data[index]; // Original reference load. |
| 7282 | // gray_return_address: |
| 7283 | |
| 7284 | DCHECK(temp.IsInvalid()); |
| 7285 | DCHECK(index.IsValid()); |
| 7286 | bool reordering = __ SetReorder(false); |
| 7287 | const int32_t entry_point_offset = |
| 7288 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 7289 | // We will not do the explicit null check in the thunk as some form of a null check |
| 7290 | // must've been done earlier. |
| 7291 | DCHECK(!needs_null_check); |
| 7292 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false); |
| 7293 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7294 | // threads are suspended or running a checkpoint. |
| 7295 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 7296 | Register ref_reg = ref.AsRegister<Register>(); |
| 7297 | Register index_reg = index.IsRegisterPair() |
| 7298 | ? index.AsRegisterPairLow<Register>() |
| 7299 | : index.AsRegister<Register>(); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7300 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7301 | if (GetInstructionSetFeatures().IsR6()) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7302 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7303 | __ Lsa(TMP, index_reg, obj, scale_factor); // In delay slot. |
| 7304 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7305 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7306 | } else { |
| 7307 | __ Sll(TMP, index_reg, scale_factor); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7308 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7309 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 7310 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7311 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7312 | __ Addu(TMP, TMP, obj); // In delay slot. |
| 7313 | } |
| 7314 | // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor)) |
| 7315 | DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset; |
| 7316 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, data_offset); // Single instruction. |
| 7317 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7318 | __ SetReorder(reordering); |
| 7319 | return; |
| 7320 | } |
| 7321 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7322 | // /* HeapReference<Object> */ ref = |
| 7323 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7324 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 7325 | ref, |
| 7326 | obj, |
| 7327 | data_offset, |
| 7328 | index, |
| 7329 | scale_factor, |
| 7330 | temp, |
| 7331 | needs_null_check); |
| 7332 | } |
| 7333 | |
| 7334 | void CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7335 | Location ref, |
| 7336 | Register obj, |
| 7337 | uint32_t offset, |
| 7338 | Location index, |
| 7339 | ScaleFactor scale_factor, |
| 7340 | Location temp, |
| 7341 | bool needs_null_check, |
| 7342 | bool always_update_field) { |
| 7343 | DCHECK(kEmitCompilerReadBarrier); |
| 7344 | DCHECK(kUseBakerReadBarrier); |
| 7345 | |
| 7346 | // In slow path based read barriers, the read barrier call is |
| 7347 | // inserted after the original load. However, in fast path based |
| 7348 | // Baker's read barriers, we need to perform the load of |
| 7349 | // mirror::Object::monitor_ *before* the original reference load. |
| 7350 | // This load-load ordering is required by the read barrier. |
| 7351 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7352 | // |
| 7353 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7354 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7355 | // HeapReference<Object> ref = *src; // Original reference load. |
| 7356 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 7357 | // if (is_gray) { |
| 7358 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7359 | // } |
| 7360 | // |
| 7361 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7362 | // slightly more complex as it performs additional checks that we do |
| 7363 | // not do here for performance reasons. |
| 7364 | |
| 7365 | Register ref_reg = ref.AsRegister<Register>(); |
| 7366 | Register temp_reg = temp.AsRegister<Register>(); |
| 7367 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7368 | |
| 7369 | // /* int32_t */ monitor = obj->monitor_ |
| 7370 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 7371 | if (needs_null_check) { |
| 7372 | MaybeRecordImplicitNullCheck(instruction); |
| 7373 | } |
| 7374 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7375 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7376 | "art::LockWord and int32_t have different sizes."); |
| 7377 | |
| 7378 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 7379 | |
| 7380 | // The actual reference load. |
| 7381 | if (index.IsValid()) { |
| 7382 | // Load types involving an "index": ArrayGet, |
| 7383 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7384 | // intrinsics. |
| 7385 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 7386 | if (index.IsConstant()) { |
| 7387 | size_t computed_offset = |
| 7388 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 7389 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7390 | } else { |
| 7391 | // Handle the special case of the |
| 7392 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7393 | // intrinsics, which use a register pair as index ("long |
| 7394 | // offset"), of which only the low part contains data. |
| 7395 | Register index_reg = index.IsRegisterPair() |
| 7396 | ? index.AsRegisterPairLow<Register>() |
| 7397 | : index.AsRegister<Register>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 7398 | __ ShiftAndAdd(TMP, index_reg, obj, scale_factor, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7399 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, offset); |
| 7400 | } |
| 7401 | } else { |
| 7402 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7403 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7404 | } |
| 7405 | |
| 7406 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7407 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7408 | |
| 7409 | // Slow path marking the object `ref` when it is gray. |
| 7410 | SlowPathCodeMIPS* slow_path; |
| 7411 | if (always_update_field) { |
| 7412 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS only supports address |
| 7413 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7414 | // `field_offset` is a register pair (of which only the lower half |
| 7415 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7416 | // to be null in this code path. |
| 7417 | DCHECK_EQ(offset, 0u); |
| 7418 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7419 | slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7420 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(instruction, |
| 7421 | ref, |
| 7422 | obj, |
| 7423 | /* field_offset */ index, |
| 7424 | temp_reg); |
| 7425 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7426 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS(instruction, ref); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7427 | } |
| 7428 | AddSlowPath(slow_path); |
| 7429 | |
| 7430 | // if (rb_state == ReadBarrier::GrayState()) |
| 7431 | // ref = ReadBarrier::Mark(ref); |
| 7432 | // Given the numeric representation, it's enough to check the low bit of the |
| 7433 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 7434 | // performing a branch on less than zero. |
| 7435 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7436 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 7437 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 7438 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 7439 | __ Bltz(temp_reg, slow_path->GetEntryLabel()); |
| 7440 | __ Bind(slow_path->GetExitLabel()); |
| 7441 | } |
| 7442 | |
| 7443 | void CodeGeneratorMIPS::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7444 | Location out, |
| 7445 | Location ref, |
| 7446 | Location obj, |
| 7447 | uint32_t offset, |
| 7448 | Location index) { |
| 7449 | DCHECK(kEmitCompilerReadBarrier); |
| 7450 | |
| 7451 | // Insert a slow path based read barrier *after* the reference load. |
| 7452 | // |
| 7453 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7454 | // reference will be carried out by the runtime within the slow |
| 7455 | // path. |
| 7456 | // |
| 7457 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7458 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7459 | // not used by the artReadBarrierSlow entry point. |
| 7460 | // |
| 7461 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7462 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7463 | ReadBarrierForHeapReferenceSlowPathMIPS(instruction, out, ref, obj, offset, index); |
| 7464 | AddSlowPath(slow_path); |
| 7465 | |
| 7466 | __ B(slow_path->GetEntryLabel()); |
| 7467 | __ Bind(slow_path->GetExitLabel()); |
| 7468 | } |
| 7469 | |
| 7470 | void CodeGeneratorMIPS::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7471 | Location out, |
| 7472 | Location ref, |
| 7473 | Location obj, |
| 7474 | uint32_t offset, |
| 7475 | Location index) { |
| 7476 | if (kEmitCompilerReadBarrier) { |
| 7477 | // Baker's read barriers shall be handled by the fast path |
| 7478 | // (CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier). |
| 7479 | DCHECK(!kUseBakerReadBarrier); |
| 7480 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7481 | // by the runtime within the slow path. |
| 7482 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 7483 | } else if (kPoisonHeapReferences) { |
| 7484 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7485 | } |
| 7486 | } |
| 7487 | |
| 7488 | void CodeGeneratorMIPS::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7489 | Location out, |
| 7490 | Location root) { |
| 7491 | DCHECK(kEmitCompilerReadBarrier); |
| 7492 | |
| 7493 | // Insert a slow path based read barrier *after* the GC root load. |
| 7494 | // |
| 7495 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7496 | // not need to do anything special for this here. |
| 7497 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7498 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS(instruction, out, root); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7499 | AddSlowPath(slow_path); |
| 7500 | |
| 7501 | __ B(slow_path->GetEntryLabel()); |
| 7502 | __ Bind(slow_path->GetExitLabel()); |
| 7503 | } |
| 7504 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7505 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7506 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7507 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7508 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7509 | switch (type_check_kind) { |
| 7510 | case TypeCheckKind::kExactCheck: |
| 7511 | case TypeCheckKind::kAbstractClassCheck: |
| 7512 | case TypeCheckKind::kClassHierarchyCheck: |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7513 | case TypeCheckKind::kArrayObjectCheck: { |
| 7514 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7515 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7516 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7517 | break; |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7518 | } |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7519 | case TypeCheckKind::kArrayCheck: |
| 7520 | case TypeCheckKind::kUnresolvedCheck: |
| 7521 | case TypeCheckKind::kInterfaceCheck: |
| 7522 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7523 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7524 | case TypeCheckKind::kBitstringCheck: |
| 7525 | break; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7526 | } |
| 7527 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7528 | LocationSummary* locations = |
| 7529 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7530 | if (baker_read_barrier_slow_path) { |
| 7531 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7532 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7533 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7534 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7535 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7536 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7537 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7538 | } else { |
| 7539 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7540 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7541 | // The output does overlap inputs. |
| 7542 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 7543 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7544 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7545 | } |
| 7546 | |
| 7547 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7548 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7549 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7550 | Location obj_loc = locations->InAt(0); |
| 7551 | Register obj = obj_loc.AsRegister<Register>(); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7552 | Location cls = locations->InAt(1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7553 | Location out_loc = locations->Out(); |
| 7554 | Register out = out_loc.AsRegister<Register>(); |
| 7555 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7556 | DCHECK_LE(num_temps, 1u); |
| 7557 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7558 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7559 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7560 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7561 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7562 | MipsLabel done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7563 | SlowPathCodeMIPS* slow_path = nullptr; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7564 | |
| 7565 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7566 | // Avoid this check if we know `obj` is not null. |
| 7567 | if (instruction->MustDoNullCheck()) { |
| 7568 | __ Move(out, ZERO); |
| 7569 | __ Beqz(obj, &done); |
| 7570 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7571 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7572 | switch (type_check_kind) { |
| 7573 | case TypeCheckKind::kExactCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7574 | ReadBarrierOption read_barrier_option = |
| 7575 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7576 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7577 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7578 | out_loc, |
| 7579 | obj_loc, |
| 7580 | class_offset, |
| 7581 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7582 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7583 | // Classes must be equal for the instanceof to succeed. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7584 | __ Xor(out, out, cls.AsRegister<Register>()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7585 | __ Sltiu(out, out, 1); |
| 7586 | break; |
| 7587 | } |
| 7588 | |
| 7589 | case TypeCheckKind::kAbstractClassCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7590 | ReadBarrierOption read_barrier_option = |
| 7591 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7592 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7593 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7594 | out_loc, |
| 7595 | obj_loc, |
| 7596 | class_offset, |
| 7597 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7598 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7599 | // If the class is abstract, we eagerly fetch the super class of the |
| 7600 | // object to avoid doing a comparison we know will fail. |
| 7601 | MipsLabel loop; |
| 7602 | __ Bind(&loop); |
| 7603 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7604 | GenerateReferenceLoadOneRegister(instruction, |
| 7605 | out_loc, |
| 7606 | super_offset, |
| 7607 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7608 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7609 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7610 | __ Beqz(out, &done); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7611 | __ Bne(out, cls.AsRegister<Register>(), &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7612 | __ LoadConst32(out, 1); |
| 7613 | break; |
| 7614 | } |
| 7615 | |
| 7616 | case TypeCheckKind::kClassHierarchyCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7617 | ReadBarrierOption read_barrier_option = |
| 7618 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7619 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7620 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7621 | out_loc, |
| 7622 | obj_loc, |
| 7623 | class_offset, |
| 7624 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7625 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7626 | // Walk over the class hierarchy to find a match. |
| 7627 | MipsLabel loop, success; |
| 7628 | __ Bind(&loop); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7629 | __ Beq(out, cls.AsRegister<Register>(), &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7630 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7631 | GenerateReferenceLoadOneRegister(instruction, |
| 7632 | out_loc, |
| 7633 | super_offset, |
| 7634 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7635 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7636 | __ Bnez(out, &loop); |
| 7637 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7638 | __ B(&done); |
| 7639 | __ Bind(&success); |
| 7640 | __ LoadConst32(out, 1); |
| 7641 | break; |
| 7642 | } |
| 7643 | |
| 7644 | case TypeCheckKind::kArrayObjectCheck: { |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7645 | ReadBarrierOption read_barrier_option = |
| 7646 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7647 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7648 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7649 | out_loc, |
| 7650 | obj_loc, |
| 7651 | class_offset, |
| 7652 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7653 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7654 | // Do an exact check. |
| 7655 | MipsLabel success; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7656 | __ Beq(out, cls.AsRegister<Register>(), &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7657 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7658 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7659 | GenerateReferenceLoadOneRegister(instruction, |
| 7660 | out_loc, |
| 7661 | component_offset, |
| 7662 | maybe_temp_loc, |
Alexey Frunze | dfc30af | 2018-01-24 16:25:10 -0800 | [diff] [blame] | 7663 | read_barrier_option); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7664 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7665 | __ Beqz(out, &done); |
| 7666 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7667 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 7668 | __ Sltiu(out, out, 1); |
| 7669 | __ B(&done); |
| 7670 | __ Bind(&success); |
| 7671 | __ LoadConst32(out, 1); |
| 7672 | break; |
| 7673 | } |
| 7674 | |
| 7675 | case TypeCheckKind::kArrayCheck: { |
| 7676 | // No read barrier since the slow path will retry upon failure. |
| 7677 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7678 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7679 | out_loc, |
| 7680 | obj_loc, |
| 7681 | class_offset, |
| 7682 | maybe_temp_loc, |
| 7683 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7684 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7685 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7686 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7687 | codegen_->AddSlowPath(slow_path); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7688 | __ Bne(out, cls.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7689 | __ LoadConst32(out, 1); |
| 7690 | break; |
| 7691 | } |
| 7692 | |
| 7693 | case TypeCheckKind::kUnresolvedCheck: |
| 7694 | case TypeCheckKind::kInterfaceCheck: { |
| 7695 | // Note that we indeed only call on slow path, but we always go |
| 7696 | // into the slow path for the unresolved and interface check |
| 7697 | // cases. |
| 7698 | // |
| 7699 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7700 | // entry point without resorting to a type checking slow path |
| 7701 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7702 | // require to assign fixed registers for the inputs of this |
| 7703 | // HInstanceOf instruction (following the runtime calling |
| 7704 | // convention), which might be cluttered by the potential first |
| 7705 | // read barrier emission at the beginning of this method. |
| 7706 | // |
| 7707 | // TODO: Introduce a new runtime entry point taking the object |
| 7708 | // to test (instead of its class) as argument, and let it deal |
| 7709 | // with the read barrier issues. This will let us refactor this |
| 7710 | // case of the `switch` code as it was previously (with a direct |
| 7711 | // call to the runtime not using a type checking slow path). |
| 7712 | // This should also be beneficial for the other cases above. |
| 7713 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7714 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7715 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7716 | codegen_->AddSlowPath(slow_path); |
| 7717 | __ B(slow_path->GetEntryLabel()); |
| 7718 | break; |
| 7719 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7720 | |
| 7721 | case TypeCheckKind::kBitstringCheck: { |
| 7722 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7723 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7724 | out_loc, |
| 7725 | obj_loc, |
| 7726 | class_offset, |
| 7727 | maybe_temp_loc, |
| 7728 | kWithoutReadBarrier); |
| 7729 | |
| 7730 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 7731 | __ Sltiu(out, out, 1); |
| 7732 | break; |
| 7733 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7734 | } |
| 7735 | |
| 7736 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7737 | |
| 7738 | if (slow_path != nullptr) { |
| 7739 | __ Bind(slow_path->GetExitLabel()); |
| 7740 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7741 | } |
| 7742 | |
| 7743 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7744 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7745 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7746 | } |
| 7747 | |
| 7748 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 7749 | // Will be generated at use site. |
| 7750 | } |
| 7751 | |
| 7752 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7753 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7754 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7755 | } |
| 7756 | |
| 7757 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 7758 | // Will be generated at use site. |
| 7759 | } |
| 7760 | |
| 7761 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { |
| 7762 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 7763 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 7764 | } |
| 7765 | |
| 7766 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7767 | HandleInvoke(invoke); |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7768 | // 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] | 7769 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7770 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T7)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7771 | } |
| 7772 | |
| 7773 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7774 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 7775 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7776 | Location receiver = invoke->GetLocations()->InAt(0); |
| 7777 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7778 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7779 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7780 | // temp = object->GetClass(); |
| 7781 | if (receiver.IsStackSlot()) { |
| 7782 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 7783 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 7784 | } else { |
| 7785 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 7786 | } |
| 7787 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7788 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7789 | // emit a read barrier for the previous class reference load. |
| 7790 | // However this is not required in practice, as this is an |
| 7791 | // intermediate/temporary reference and because the current |
| 7792 | // concurrent copying collector keeps the from-space memory |
| 7793 | // intact/accessible until the end of the marking phase (the |
| 7794 | // concurrent copying collector may not in the future). |
| 7795 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 7796 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 7797 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
| 7798 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7799 | invoke->GetImtIndex(), kMipsPointerSize)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7800 | // temp = temp->GetImtEntryAt(method_offset); |
| 7801 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7802 | // T9 = temp->GetEntryPoint(); |
| 7803 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
Lena Djokic | 3177e10 | 2018-02-28 11:32:40 +0100 | [diff] [blame] | 7804 | // Set the hidden argument. |
| 7805 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 7806 | invoke->GetDexMethodIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7807 | // T9(); |
| 7808 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7809 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7810 | DCHECK(!codegen_->IsLeafMethod()); |
| 7811 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 7812 | } |
| 7813 | |
| 7814 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7815 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7816 | if (intrinsic.TryDispatch(invoke)) { |
| 7817 | return; |
| 7818 | } |
| 7819 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7820 | HandleInvoke(invoke); |
| 7821 | } |
| 7822 | |
| 7823 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 7824 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 7825 | // art::PrepareForRegisterAllocation. |
| 7826 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7827 | |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7828 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7829 | bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
| 7830 | bool has_extra_input = invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7831 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7832 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7833 | if (intrinsic.TryDispatch(invoke)) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7834 | if (invoke->GetLocations()->CanCall() && has_extra_input) { |
| 7835 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 7836 | } |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7837 | return; |
| 7838 | } |
| 7839 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7840 | HandleInvoke(invoke); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7841 | |
| 7842 | // Add the extra input register if either the dex cache array base register |
| 7843 | // or the PC-relative base register for accessing literals is needed. |
| 7844 | if (has_extra_input) { |
| 7845 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 7846 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7847 | } |
| 7848 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 7849 | void LocationsBuilderMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7850 | HandleInvoke(invoke); |
| 7851 | } |
| 7852 | |
| 7853 | void InstructionCodeGeneratorMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7854 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 7855 | } |
| 7856 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 7857 | void LocationsBuilderMIPS::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 7858 | HandleInvoke(invoke); |
| 7859 | } |
| 7860 | |
| 7861 | void InstructionCodeGeneratorMIPS::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 7862 | codegen_->GenerateInvokeCustomCall(invoke); |
| 7863 | } |
| 7864 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7865 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7866 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7867 | IntrinsicCodeGeneratorMIPS intrinsic(codegen); |
| 7868 | intrinsic.Dispatch(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7869 | return true; |
| 7870 | } |
| 7871 | return false; |
| 7872 | } |
| 7873 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7874 | HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7875 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7876 | switch (desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7877 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7878 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7879 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7880 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7881 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame^] | 7882 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7883 | case HLoadString::LoadKind::kJitTableAddress: |
| 7884 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7885 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7886 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7887 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7888 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7889 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7890 | } |
| 7891 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7892 | HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind( |
| 7893 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7894 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7895 | case HLoadClass::LoadKind::kInvalid: |
| 7896 | LOG(FATAL) << "UNREACHABLE"; |
| 7897 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7898 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7899 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7900 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7901 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7902 | case HLoadClass::LoadKind::kBssEntry: |
| 7903 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7904 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame^] | 7905 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7906 | case HLoadClass::LoadKind::kJitTableAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7907 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7908 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7909 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7910 | break; |
| 7911 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7912 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7913 | } |
| 7914 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7915 | Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7916 | Register temp) { |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7917 | CHECK(!GetInstructionSetFeatures().IsR6()); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7918 | CHECK(!GetGraph()->HasIrreducibleLoops()); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7919 | CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7920 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7921 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7922 | return location.AsRegister<Register>(); |
| 7923 | } |
| 7924 | // For intrinsics we allow any location, so it may be on the stack. |
| 7925 | if (!location.IsRegister()) { |
| 7926 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7927 | return temp; |
| 7928 | } |
| 7929 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7930 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7931 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7932 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7933 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 7934 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 7935 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 7936 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7937 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7938 | return temp; |
| 7939 | } |
| 7940 | return location.AsRegister<Register>(); |
| 7941 | } |
| 7942 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7943 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( |
| 7944 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 7945 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7946 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7947 | } |
| 7948 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7949 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall( |
| 7950 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7951 | // 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] | 7952 | 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] | 7953 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 7954 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7955 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7956 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 7957 | Register base_reg = (invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7958 | ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>()) |
| 7959 | : ZERO; |
| 7960 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7961 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7962 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7963 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7964 | uint32_t offset = |
| 7965 | GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7966 | __ LoadFromOffset(kLoadWord, |
| 7967 | temp.AsRegister<Register>(), |
| 7968 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7969 | offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7970 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7971 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7972 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7973 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7974 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7975 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 7976 | DCHECK(GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7977 | PcRelativePatchInfo* info_high = NewBootImageMethodPatch(invoke->GetTargetMethod()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7978 | PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7979 | NewBootImageMethodPatch(invoke->GetTargetMethod(), info_high); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7980 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7981 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 7982 | __ Addiu(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7983 | break; |
| 7984 | } |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 7985 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7986 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 7987 | PcRelativePatchInfo* info_high = NewBootImageRelRoPatch(boot_image_offset); |
| 7988 | PcRelativePatchInfo* info_low = NewBootImageRelRoPatch(boot_image_offset, info_high); |
| 7989 | Register temp_reg = temp.AsRegister<Register>(); |
| 7990 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 7991 | __ Lw(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
| 7992 | break; |
| 7993 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7994 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7995 | PcRelativePatchInfo* info_high = NewMethodBssEntryPatch( |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7996 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7997 | PcRelativePatchInfo* info_low = NewMethodBssEntryPatch( |
| 7998 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7999 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 8000 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 8001 | __ Lw(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 8002 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 8003 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame^] | 8004 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 8005 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 8006 | break; |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8007 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 8008 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 8009 | return; // No code pointer retrieval; the runtime performs the call directly. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8010 | } |
| 8011 | } |
| 8012 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 8013 | switch (code_ptr_location) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8014 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 8015 | __ Bal(&frame_entry_label_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8016 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8017 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 8018 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 8019 | __ LoadFromOffset(kLoadWord, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8020 | T9, |
| 8021 | callee_method.AsRegister<Register>(), |
| 8022 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8023 | kMipsPointerSize).Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8024 | // T9() |
| 8025 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 8026 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8027 | break; |
| 8028 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8029 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 8030 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8031 | DCHECK(!IsLeafMethod()); |
| 8032 | } |
| 8033 | |
| 8034 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 8035 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 8036 | // art::PrepareForRegisterAllocation. |
| 8037 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8038 | |
| 8039 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 8040 | return; |
| 8041 | } |
| 8042 | |
| 8043 | LocationSummary* locations = invoke->GetLocations(); |
| 8044 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 8045 | locations->HasTemps() |
| 8046 | ? locations->GetTemp(0) |
| 8047 | : Location::NoLocation()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8048 | } |
| 8049 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8050 | void CodeGeneratorMIPS::GenerateVirtualCall( |
| 8051 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 8052 | // Use the calling convention instead of the location of the receiver, as |
| 8053 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 8054 | // slow path, the arguments have been moved to the right place, so here we are |
| 8055 | // guaranteed that the receiver is the first register of the calling convention. |
| 8056 | InvokeDexCallingConvention calling_convention; |
| 8057 | Register receiver = calling_convention.GetRegisterAt(0); |
| 8058 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 8059 | Register temp = temp_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8060 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 8061 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); |
| 8062 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8063 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8064 | |
| 8065 | // temp = object->GetClass(); |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 8066 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 8067 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8068 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 8069 | // emit a read barrier for the previous class reference load. |
| 8070 | // However this is not required in practice, as this is an |
| 8071 | // intermediate/temporary reference and because the current |
| 8072 | // concurrent copying collector keeps the from-space memory |
| 8073 | // intact/accessible until the end of the marking phase (the |
| 8074 | // concurrent copying collector may not in the future). |
| 8075 | __ MaybeUnpoisonHeapReference(temp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8076 | // temp = temp->GetMethodAt(method_offset); |
| 8077 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 8078 | // T9 = temp->GetEntryPoint(); |
| 8079 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 8080 | // T9(); |
| 8081 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 8082 | __ NopIfNoReordering(); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8083 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 8084 | } |
| 8085 | |
| 8086 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 8087 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 8088 | return; |
| 8089 | } |
| 8090 | |
| 8091 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8092 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8093 | } |
| 8094 | |
| 8095 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8096 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8097 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8098 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8099 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 8100 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8101 | return; |
| 8102 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8103 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8104 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8105 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8106 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 8107 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8108 | ? LocationSummary::kCallOnSlowPath |
| 8109 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8110 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8111 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 8112 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 8113 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8114 | switch (load_kind) { |
| 8115 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8116 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8117 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8118 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame^] | 8119 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8120 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8121 | break; |
| 8122 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8123 | if (has_irreducible_loops) { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame^] | 8124 | if (load_kind != HLoadClass::LoadKind::kJitBootImageAddress) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 8125 | codegen_->ClobberRA(); |
| 8126 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8127 | break; |
| 8128 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8129 | FALLTHROUGH_INTENDED; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8130 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8131 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8132 | break; |
| 8133 | default: |
| 8134 | break; |
| 8135 | } |
| 8136 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8137 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 8138 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 8139 | // 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] | 8140 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 8141 | InvokeRuntimeCallingConvention calling_convention; |
| 8142 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8143 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 8144 | } else { |
| 8145 | // For non-Baker read barriers we have a temp-clobbering call. |
| 8146 | } |
| 8147 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8148 | } |
| 8149 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 8150 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 8151 | // move. |
| 8152 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8153 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8154 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8155 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 8156 | return; |
| 8157 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8158 | DCHECK(!cls->NeedsAccessCheck()); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 8159 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8160 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8161 | Location out_loc = locations->Out(); |
| 8162 | Register out = out_loc.AsRegister<Register>(); |
| 8163 | Register base_or_current_method_reg; |
| 8164 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8165 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8166 | switch (load_kind) { |
| 8167 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8168 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8169 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8170 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame^] | 8171 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8172 | base_or_current_method_reg = |
| 8173 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8174 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8175 | case HLoadClass::LoadKind::kReferrersClass: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8176 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8177 | base_or_current_method_reg = locations->InAt(0).AsRegister<Register>(); |
| 8178 | break; |
| 8179 | default: |
| 8180 | base_or_current_method_reg = ZERO; |
| 8181 | break; |
| 8182 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 8183 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8184 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 8185 | ? kWithoutReadBarrier |
| 8186 | : kCompilerReadBarrierOption; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8187 | bool generate_null_check = false; |
| 8188 | switch (load_kind) { |
| 8189 | case HLoadClass::LoadKind::kReferrersClass: { |
| 8190 | DCHECK(!cls->CanCallRuntime()); |
| 8191 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 8192 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 8193 | GenerateGcRootFieldLoad(cls, |
| 8194 | out_loc, |
| 8195 | base_or_current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8196 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 8197 | read_barrier_option); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8198 | break; |
| 8199 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8200 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8201 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8202 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8203 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8204 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8205 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8206 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8207 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8208 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 8209 | base_or_current_method_reg); |
| 8210 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8211 | break; |
| 8212 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8213 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8214 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8215 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8216 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8217 | codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8218 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8219 | codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8220 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8221 | out, |
| 8222 | base_or_current_method_reg); |
| 8223 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8224 | break; |
| 8225 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8226 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8227 | CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high = |
| 8228 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8229 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8230 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8231 | codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8232 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8233 | base_or_current_method_reg); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8234 | GenerateGcRootFieldLoad(cls, |
| 8235 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8236 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8237 | /* placeholder */ 0x5678, |
| 8238 | read_barrier_option, |
| 8239 | &info_low->label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8240 | generate_null_check = true; |
| 8241 | break; |
| 8242 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame^] | 8243 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 8244 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 8245 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 8246 | DCHECK_NE(address, 0u); |
| 8247 | if (isR6 || !has_irreducible_loops) { |
| 8248 | __ LoadLiteral(out, |
| 8249 | base_or_current_method_reg, |
| 8250 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 8251 | } else { |
| 8252 | __ LoadConst32(out, address); |
| 8253 | } |
| 8254 | break; |
| 8255 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8256 | case HLoadClass::LoadKind::kJitTableAddress: { |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8257 | CodeGeneratorMIPS::JitPatchInfo* info = codegen_->NewJitRootClassPatch(cls->GetDexFile(), |
| 8258 | cls->GetTypeIndex(), |
| 8259 | cls->GetClass()); |
| 8260 | bool reordering = __ SetReorder(false); |
| 8261 | __ Bind(&info->high_label); |
| 8262 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8263 | __ SetReorder(reordering); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8264 | GenerateGcRootFieldLoad(cls, |
| 8265 | out_loc, |
| 8266 | out, |
| 8267 | /* placeholder */ 0x5678, |
| 8268 | read_barrier_option, |
| 8269 | &info->low_label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8270 | break; |
| 8271 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8272 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 8273 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8274 | LOG(FATAL) << "UNREACHABLE"; |
| 8275 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8276 | } |
| 8277 | |
| 8278 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 8279 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8280 | SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS( |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8281 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8282 | codegen_->AddSlowPath(slow_path); |
| 8283 | if (generate_null_check) { |
| 8284 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 8285 | } |
| 8286 | if (cls->MustGenerateClinitCheck()) { |
| 8287 | GenerateClassInitializationCheck(slow_path, out); |
| 8288 | } else { |
| 8289 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8290 | } |
| 8291 | } |
| 8292 | } |
| 8293 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 8294 | void LocationsBuilderMIPS::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 8295 | InvokeRuntimeCallingConvention calling_convention; |
| 8296 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 8297 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, loc, loc); |
| 8298 | } |
| 8299 | |
| 8300 | void InstructionCodeGeneratorMIPS::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 8301 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 8302 | } |
| 8303 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 8304 | void LocationsBuilderMIPS::VisitLoadMethodType(HLoadMethodType* load) { |
| 8305 | InvokeRuntimeCallingConvention calling_convention; |
| 8306 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 8307 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, loc, loc); |
| 8308 | } |
| 8309 | |
| 8310 | void InstructionCodeGeneratorMIPS::VisitLoadMethodType(HLoadMethodType* load) { |
| 8311 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 8312 | } |
| 8313 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8314 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8315 | return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8316 | } |
| 8317 | |
| 8318 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { |
| 8319 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8320 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8321 | locations->SetOut(Location::RequiresRegister()); |
| 8322 | } |
| 8323 | |
| 8324 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { |
| 8325 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
| 8326 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 8327 | } |
| 8328 | |
| 8329 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8330 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8331 | } |
| 8332 | |
| 8333 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 8334 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
| 8335 | } |
| 8336 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8337 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 8338 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8339 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8340 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8341 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8342 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8343 | switch (load_kind) { |
| 8344 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8345 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8346 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8347 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame^] | 8348 | case HLoadString::LoadKind::kJitBootImageAddress: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8349 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8350 | break; |
| 8351 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8352 | if (has_irreducible_loops) { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame^] | 8353 | if (load_kind != HLoadString::LoadKind::kJitBootImageAddress) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 8354 | codegen_->ClobberRA(); |
| 8355 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8356 | break; |
| 8357 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8358 | FALLTHROUGH_INTENDED; |
| 8359 | // We need an extra register for PC-relative dex cache accesses. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8360 | case HLoadString::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8361 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8362 | break; |
| 8363 | default: |
| 8364 | break; |
| 8365 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8366 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8367 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8368 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8369 | } else { |
| 8370 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8371 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 8372 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 8373 | // Rely on the pResolveString and marking to save everything we need. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8374 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 8375 | InvokeRuntimeCallingConvention calling_convention; |
| 8376 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8377 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 8378 | } else { |
| 8379 | // For non-Baker read barriers we have a temp-clobbering call. |
| 8380 | } |
| 8381 | } |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8382 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8383 | } |
| 8384 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8385 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 8386 | // move. |
| 8387 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8388 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8389 | LocationSummary* locations = load->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8390 | Location out_loc = locations->Out(); |
| 8391 | Register out = out_loc.AsRegister<Register>(); |
| 8392 | Register base_or_current_method_reg; |
| 8393 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8394 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8395 | switch (load_kind) { |
| 8396 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8397 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8398 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8399 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame^] | 8400 | case HLoadString::LoadKind::kJitBootImageAddress: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8401 | base_or_current_method_reg = |
| 8402 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8403 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8404 | default: |
| 8405 | base_or_current_method_reg = ZERO; |
| 8406 | break; |
| 8407 | } |
| 8408 | |
| 8409 | switch (load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8410 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8411 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8412 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8413 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8414 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8415 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8416 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8417 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 8418 | base_or_current_method_reg); |
| 8419 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8420 | return; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8421 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8422 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8423 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8424 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(load); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8425 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8426 | codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8427 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8428 | codegen_->NewBootImageRelRoPatch(boot_image_offset, info_high); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8429 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8430 | out, |
| 8431 | base_or_current_method_reg); |
| 8432 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
| 8433 | return; |
| 8434 | } |
| 8435 | case HLoadString::LoadKind::kBssEntry: { |
| 8436 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 8437 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
| 8438 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| 8439 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8440 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8441 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8442 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8443 | base_or_current_method_reg); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8444 | GenerateGcRootFieldLoad(load, |
| 8445 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8446 | out, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8447 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8448 | kCompilerReadBarrierOption, |
| 8449 | &info_low->label); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8450 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8451 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8452 | codegen_->AddSlowPath(slow_path); |
| 8453 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 8454 | __ Bind(slow_path->GetExitLabel()); |
| 8455 | return; |
| 8456 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame^] | 8457 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 8458 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 8459 | DCHECK_NE(address, 0u); |
| 8460 | if (isR6 || !has_irreducible_loops) { |
| 8461 | __ LoadLiteral(out, |
| 8462 | base_or_current_method_reg, |
| 8463 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 8464 | } else { |
| 8465 | __ LoadConst32(out, address); |
| 8466 | } |
| 8467 | return; |
| 8468 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8469 | case HLoadString::LoadKind::kJitTableAddress: { |
| 8470 | CodeGeneratorMIPS::JitPatchInfo* info = |
| 8471 | codegen_->NewJitRootStringPatch(load->GetDexFile(), |
| 8472 | load->GetStringIndex(), |
| 8473 | load->GetString()); |
| 8474 | bool reordering = __ SetReorder(false); |
| 8475 | __ Bind(&info->high_label); |
| 8476 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8477 | __ SetReorder(reordering); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8478 | GenerateGcRootFieldLoad(load, |
| 8479 | out_loc, |
| 8480 | out, |
| 8481 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8482 | kCompilerReadBarrierOption, |
| 8483 | &info->low_label); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8484 | return; |
| 8485 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8486 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8487 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8488 | } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 8489 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8490 | // 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] | 8491 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8492 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8493 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8494 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8495 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 8496 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8497 | } |
| 8498 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8499 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8500 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8501 | locations->SetOut(Location::ConstantLocation(constant)); |
| 8502 | } |
| 8503 | |
| 8504 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 8505 | // Will be generated at use site. |
| 8506 | } |
| 8507 | |
| 8508 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8509 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8510 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8511 | InvokeRuntimeCallingConvention calling_convention; |
| 8512 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8513 | } |
| 8514 | |
| 8515 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8516 | if (instruction->IsEnter()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8517 | codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8518 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8519 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8520 | codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8521 | } |
| 8522 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8523 | } |
| 8524 | |
| 8525 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { |
| 8526 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8527 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8528 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8529 | case DataType::Type::kInt32: |
| 8530 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8531 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8532 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8533 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8534 | break; |
| 8535 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8536 | case DataType::Type::kFloat32: |
| 8537 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8538 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8539 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 8540 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8541 | break; |
| 8542 | |
| 8543 | default: |
| 8544 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 8545 | } |
| 8546 | } |
| 8547 | |
| 8548 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8549 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8550 | LocationSummary* locations = instruction->GetLocations(); |
| 8551 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 8552 | |
| 8553 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8554 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8555 | Register dst = locations->Out().AsRegister<Register>(); |
| 8556 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 8557 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 8558 | |
| 8559 | if (isR6) { |
| 8560 | __ MulR6(dst, lhs, rhs); |
| 8561 | } else { |
| 8562 | __ MulR2(dst, lhs, rhs); |
| 8563 | } |
| 8564 | break; |
| 8565 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8566 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8567 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8568 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8569 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8570 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8571 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 8572 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 8573 | |
| 8574 | // Extra checks to protect caused by the existance of A1_A2. |
| 8575 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: |
| 8576 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). |
| 8577 | DCHECK_NE(dst_high, lhs_low); |
| 8578 | DCHECK_NE(dst_high, rhs_low); |
| 8579 | |
| 8580 | // A_B * C_D |
| 8581 | // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ] |
| 8582 | // dst_lo: [ low(B*D) ] |
| 8583 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. |
| 8584 | |
| 8585 | if (isR6) { |
| 8586 | __ MulR6(TMP, lhs_high, rhs_low); |
| 8587 | __ MulR6(dst_high, lhs_low, rhs_high); |
| 8588 | __ Addu(dst_high, dst_high, TMP); |
| 8589 | __ MuhuR6(TMP, lhs_low, rhs_low); |
| 8590 | __ Addu(dst_high, dst_high, TMP); |
| 8591 | __ MulR6(dst_low, lhs_low, rhs_low); |
| 8592 | } else { |
| 8593 | __ MulR2(TMP, lhs_high, rhs_low); |
| 8594 | __ MulR2(dst_high, lhs_low, rhs_high); |
| 8595 | __ Addu(dst_high, dst_high, TMP); |
| 8596 | __ MultuR2(lhs_low, rhs_low); |
| 8597 | __ Mfhi(TMP); |
| 8598 | __ Addu(dst_high, dst_high, TMP); |
| 8599 | __ Mflo(dst_low); |
| 8600 | } |
| 8601 | break; |
| 8602 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8603 | case DataType::Type::kFloat32: |
| 8604 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8605 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8606 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8607 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8608 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8609 | __ MulS(dst, lhs, rhs); |
| 8610 | } else { |
| 8611 | __ MulD(dst, lhs, rhs); |
| 8612 | } |
| 8613 | break; |
| 8614 | } |
| 8615 | default: |
| 8616 | LOG(FATAL) << "Unexpected mul type " << type; |
| 8617 | } |
| 8618 | } |
| 8619 | |
| 8620 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { |
| 8621 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8622 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8623 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8624 | case DataType::Type::kInt32: |
| 8625 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8626 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8627 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8628 | break; |
| 8629 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8630 | case DataType::Type::kFloat32: |
| 8631 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8632 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8633 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8634 | break; |
| 8635 | |
| 8636 | default: |
| 8637 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 8638 | } |
| 8639 | } |
| 8640 | |
| 8641 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8642 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8643 | LocationSummary* locations = instruction->GetLocations(); |
| 8644 | |
| 8645 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8646 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8647 | Register dst = locations->Out().AsRegister<Register>(); |
| 8648 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8649 | __ Subu(dst, ZERO, src); |
| 8650 | break; |
| 8651 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8652 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8653 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8654 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8655 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8656 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8657 | __ Subu(dst_low, ZERO, src_low); |
| 8658 | __ Sltu(TMP, ZERO, dst_low); |
| 8659 | __ Subu(dst_high, ZERO, src_high); |
| 8660 | __ Subu(dst_high, dst_high, TMP); |
| 8661 | break; |
| 8662 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8663 | case DataType::Type::kFloat32: |
| 8664 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8665 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8666 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8667 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8668 | __ NegS(dst, src); |
| 8669 | } else { |
| 8670 | __ NegD(dst, src); |
| 8671 | } |
| 8672 | break; |
| 8673 | } |
| 8674 | default: |
| 8675 | LOG(FATAL) << "Unexpected neg type " << type; |
| 8676 | } |
| 8677 | } |
| 8678 | |
| 8679 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8680 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8681 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8682 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8683 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8684 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8685 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8686 | } |
| 8687 | |
| 8688 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8689 | // Note: if heap poisoning is enabled, the entry point takes care |
| 8690 | // of poisoning the reference. |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8691 | QuickEntrypointEnum entrypoint = |
| 8692 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 8693 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8694 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8695 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8696 | } |
| 8697 | |
| 8698 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8699 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8700 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8701 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 8702 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8703 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8704 | } |
| 8705 | |
| 8706 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 8707 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 8708 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8709 | } |
| 8710 | |
| 8711 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8712 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8713 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8714 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8715 | } |
| 8716 | |
| 8717 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8718 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8719 | LocationSummary* locations = instruction->GetLocations(); |
| 8720 | |
| 8721 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8722 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8723 | Register dst = locations->Out().AsRegister<Register>(); |
| 8724 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8725 | __ Nor(dst, src, ZERO); |
| 8726 | break; |
| 8727 | } |
| 8728 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8729 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8730 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8731 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8732 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8733 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8734 | __ Nor(dst_high, src_high, ZERO); |
| 8735 | __ Nor(dst_low, src_low, ZERO); |
| 8736 | break; |
| 8737 | } |
| 8738 | |
| 8739 | default: |
| 8740 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 8741 | } |
| 8742 | } |
| 8743 | |
| 8744 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8745 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8746 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8747 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8748 | } |
| 8749 | |
| 8750 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 8751 | LocationSummary* locations = instruction->GetLocations(); |
| 8752 | __ Xori(locations->Out().AsRegister<Register>(), |
| 8753 | locations->InAt(0).AsRegister<Register>(), |
| 8754 | 1); |
| 8755 | } |
| 8756 | |
| 8757 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 8758 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 8759 | locations->SetInAt(0, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8760 | } |
| 8761 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8762 | void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 8763 | if (CanMoveNullCheckToUser(instruction)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8764 | return; |
| 8765 | } |
| 8766 | Location obj = instruction->GetLocations()->InAt(0); |
| 8767 | |
| 8768 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8769 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8770 | } |
| 8771 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8772 | void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8773 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) NullCheckSlowPathMIPS(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8774 | AddSlowPath(slow_path); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8775 | |
| 8776 | Location obj = instruction->GetLocations()->InAt(0); |
| 8777 | |
| 8778 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8779 | } |
| 8780 | |
| 8781 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8782 | codegen_->GenerateNullCheck(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8783 | } |
| 8784 | |
| 8785 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { |
| 8786 | HandleBinaryOp(instruction); |
| 8787 | } |
| 8788 | |
| 8789 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { |
| 8790 | HandleBinaryOp(instruction); |
| 8791 | } |
| 8792 | |
| 8793 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 8794 | LOG(FATAL) << "Unreachable"; |
| 8795 | } |
| 8796 | |
| 8797 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 8798 | if (instruction->GetNext()->IsSuspendCheck() && |
| 8799 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 8800 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 8801 | // The back edge will generate the suspend check. |
| 8802 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 8803 | } |
| 8804 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8805 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 8806 | } |
| 8807 | |
| 8808 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8809 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8810 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 8811 | if (location.IsStackSlot()) { |
| 8812 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8813 | } else if (location.IsDoubleStackSlot()) { |
| 8814 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8815 | } |
| 8816 | locations->SetOut(location); |
| 8817 | } |
| 8818 | |
| 8819 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction |
| 8820 | ATTRIBUTE_UNUSED) { |
| 8821 | // Nothing to do, the parameter is already at its location. |
| 8822 | } |
| 8823 | |
| 8824 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 8825 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8826 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8827 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 8828 | } |
| 8829 | |
| 8830 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction |
| 8831 | ATTRIBUTE_UNUSED) { |
| 8832 | // Nothing to do, the method is already at its location. |
| 8833 | } |
| 8834 | |
| 8835 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8836 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 8837 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8838 | locations->SetInAt(i, Location::Any()); |
| 8839 | } |
| 8840 | locations->SetOut(Location::Any()); |
| 8841 | } |
| 8842 | |
| 8843 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 8844 | LOG(FATAL) << "Unreachable"; |
| 8845 | } |
| 8846 | |
| 8847 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8848 | DataType::Type type = rem->GetResultType(); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8849 | bool call_rem; |
| 8850 | if ((type == DataType::Type::kInt64) && rem->InputAt(1)->IsConstant()) { |
| 8851 | int64_t imm = CodeGenerator::GetInt64ValueOf(rem->InputAt(1)->AsConstant()); |
| 8852 | call_rem = (imm != 0) && !IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm))); |
| 8853 | } else { |
| 8854 | call_rem = (type != DataType::Type::kInt32); |
| 8855 | } |
| 8856 | LocationSummary::CallKind call_kind = call_rem |
| 8857 | ? LocationSummary::kCallOnMainOnly |
| 8858 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8859 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8860 | |
| 8861 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8862 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8863 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8864 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8865 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8866 | break; |
| 8867 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8868 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8869 | if (call_rem) { |
| 8870 | InvokeRuntimeCallingConvention calling_convention; |
| 8871 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 8872 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 8873 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 8874 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 8875 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8876 | } else { |
| 8877 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8878 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 8879 | locations->SetOut(Location::RequiresRegister()); |
| 8880 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8881 | break; |
| 8882 | } |
| 8883 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8884 | case DataType::Type::kFloat32: |
| 8885 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8886 | InvokeRuntimeCallingConvention calling_convention; |
| 8887 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 8888 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 8889 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8890 | break; |
| 8891 | } |
| 8892 | |
| 8893 | default: |
| 8894 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8895 | } |
| 8896 | } |
| 8897 | |
| 8898 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8899 | DataType::Type type = instruction->GetType(); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8900 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8901 | |
| 8902 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8903 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8904 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8905 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8906 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame] | 8907 | if (locations->InAt(1).IsConstant()) { |
| 8908 | int64_t imm = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue(); |
| 8909 | if (imm == 0) { |
| 8910 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 8911 | } else if (imm == 1 || imm == -1) { |
| 8912 | DivRemOneOrMinusOne(instruction); |
| 8913 | } else { |
| 8914 | DCHECK(IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm)))); |
| 8915 | DivRemByPowerOfTwo(instruction); |
| 8916 | } |
| 8917 | } else { |
| 8918 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
| 8919 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 8920 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8921 | break; |
| 8922 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8923 | case DataType::Type::kFloat32: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8924 | codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8925 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8926 | break; |
| 8927 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8928 | case DataType::Type::kFloat64: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8929 | codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8930 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8931 | break; |
| 8932 | } |
| 8933 | default: |
| 8934 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8935 | } |
| 8936 | } |
| 8937 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 8938 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 8939 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 8940 | switch (minmax->GetResultType()) { |
| 8941 | case DataType::Type::kInt32: |
| 8942 | case DataType::Type::kInt64: |
| 8943 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8944 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8945 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8946 | break; |
| 8947 | case DataType::Type::kFloat32: |
| 8948 | case DataType::Type::kFloat64: |
| 8949 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8950 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 8951 | locations->SetOut(Location::RequiresFpuRegister(), Location::kOutputOverlap); |
| 8952 | break; |
| 8953 | default: |
| 8954 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 8955 | } |
| 8956 | } |
| 8957 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 8958 | void InstructionCodeGeneratorMIPS::GenerateMinMaxInt(LocationSummary* locations, |
| 8959 | bool is_min, |
| 8960 | bool isR6, |
| 8961 | DataType::Type type) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 8962 | if (isR6) { |
| 8963 | // Some architectures, such as ARM and MIPS (prior to r6), have a |
| 8964 | // conditional move instruction which only changes the target |
| 8965 | // (output) register if the condition is true (MIPS prior to r6 had |
| 8966 | // MOVF, MOVT, MOVN, and MOVZ). The SELEQZ and SELNEZ instructions |
| 8967 | // always change the target (output) register. If the condition is |
| 8968 | // true the output register gets the contents of the "rs" register; |
| 8969 | // otherwise, the output register is set to zero. One consequence |
| 8970 | // of this is that to implement something like "rd = c==0 ? rs : rt" |
| 8971 | // MIPS64r6 needs to use a pair of SELEQZ/SELNEZ instructions. |
| 8972 | // After executing this pair of instructions one of the output |
| 8973 | // registers from the pair will necessarily contain zero. Then the |
| 8974 | // code ORs the output registers from the SELEQZ/SELNEZ instructions |
| 8975 | // to get the final result. |
| 8976 | // |
| 8977 | // The initial test to see if the output register is same as the |
| 8978 | // first input register is needed to make sure that value in the |
| 8979 | // first input register isn't clobbered before we've finished |
| 8980 | // computing the output value. The logic in the corresponding else |
| 8981 | // clause performs the same task but makes sure the second input |
| 8982 | // register isn't clobbered in the event that it's the same register |
| 8983 | // as the output register; the else clause also handles the case |
| 8984 | // where the output register is distinct from both the first, and the |
| 8985 | // second input registers. |
| 8986 | if (type == DataType::Type::kInt64) { |
| 8987 | Register a_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8988 | Register a_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8989 | Register b_lo = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 8990 | Register b_hi = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 8991 | Register out_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 8992 | Register out_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 8993 | |
| 8994 | MipsLabel compare_done; |
| 8995 | |
| 8996 | if (a_lo == b_lo) { |
| 8997 | if (out_lo != a_lo) { |
| 8998 | __ Move(out_lo, a_lo); |
| 8999 | __ Move(out_hi, a_hi); |
| 9000 | } |
| 9001 | } else { |
| 9002 | __ Slt(TMP, b_hi, a_hi); |
| 9003 | __ Bne(b_hi, a_hi, &compare_done); |
| 9004 | |
| 9005 | __ Sltu(TMP, b_lo, a_lo); |
| 9006 | |
| 9007 | __ Bind(&compare_done); |
| 9008 | |
| 9009 | if (is_min) { |
| 9010 | __ Seleqz(AT, a_lo, TMP); |
| 9011 | __ Selnez(out_lo, b_lo, TMP); // Safe even if out_lo == a_lo/b_lo |
| 9012 | // because at this point we're |
| 9013 | // done using a_lo/b_lo. |
| 9014 | } else { |
| 9015 | __ Selnez(AT, a_lo, TMP); |
| 9016 | __ Seleqz(out_lo, b_lo, TMP); // ditto |
| 9017 | } |
| 9018 | __ Or(out_lo, out_lo, AT); |
| 9019 | if (is_min) { |
| 9020 | __ Seleqz(AT, a_hi, TMP); |
| 9021 | __ Selnez(out_hi, b_hi, TMP); // ditto but for out_hi & a_hi/b_hi |
| 9022 | } else { |
| 9023 | __ Selnez(AT, a_hi, TMP); |
| 9024 | __ Seleqz(out_hi, b_hi, TMP); // ditto but for out_hi & a_hi/b_hi |
| 9025 | } |
| 9026 | __ Or(out_hi, out_hi, AT); |
| 9027 | } |
| 9028 | } else { |
| 9029 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 9030 | Register a = locations->InAt(0).AsRegister<Register>(); |
| 9031 | Register b = locations->InAt(1).AsRegister<Register>(); |
| 9032 | Register out = locations->Out().AsRegister<Register>(); |
| 9033 | |
| 9034 | if (a == b) { |
| 9035 | if (out != a) { |
| 9036 | __ Move(out, a); |
| 9037 | } |
| 9038 | } else { |
| 9039 | __ Slt(AT, b, a); |
| 9040 | if (is_min) { |
| 9041 | __ Seleqz(TMP, a, AT); |
| 9042 | __ Selnez(AT, b, AT); |
| 9043 | } else { |
| 9044 | __ Selnez(TMP, a, AT); |
| 9045 | __ Seleqz(AT, b, AT); |
| 9046 | } |
| 9047 | __ Or(out, TMP, AT); |
| 9048 | } |
| 9049 | } |
| 9050 | } else { // !isR6 |
| 9051 | if (type == DataType::Type::kInt64) { |
| 9052 | Register a_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 9053 | Register a_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 9054 | Register b_lo = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 9055 | Register b_hi = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 9056 | Register out_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 9057 | Register out_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 9058 | |
| 9059 | MipsLabel compare_done; |
| 9060 | |
| 9061 | if (a_lo == b_lo) { |
| 9062 | if (out_lo != a_lo) { |
| 9063 | __ Move(out_lo, a_lo); |
| 9064 | __ Move(out_hi, a_hi); |
| 9065 | } |
| 9066 | } else { |
| 9067 | __ Slt(TMP, a_hi, b_hi); |
| 9068 | __ Bne(a_hi, b_hi, &compare_done); |
| 9069 | |
| 9070 | __ Sltu(TMP, a_lo, b_lo); |
| 9071 | |
| 9072 | __ Bind(&compare_done); |
| 9073 | |
| 9074 | if (is_min) { |
| 9075 | if (out_lo != a_lo) { |
| 9076 | __ Movn(out_hi, a_hi, TMP); |
| 9077 | __ Movn(out_lo, a_lo, TMP); |
| 9078 | } |
| 9079 | if (out_lo != b_lo) { |
| 9080 | __ Movz(out_hi, b_hi, TMP); |
| 9081 | __ Movz(out_lo, b_lo, TMP); |
| 9082 | } |
| 9083 | } else { |
| 9084 | if (out_lo != a_lo) { |
| 9085 | __ Movz(out_hi, a_hi, TMP); |
| 9086 | __ Movz(out_lo, a_lo, TMP); |
| 9087 | } |
| 9088 | if (out_lo != b_lo) { |
| 9089 | __ Movn(out_hi, b_hi, TMP); |
| 9090 | __ Movn(out_lo, b_lo, TMP); |
| 9091 | } |
| 9092 | } |
| 9093 | } |
| 9094 | } else { |
| 9095 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 9096 | Register a = locations->InAt(0).AsRegister<Register>(); |
| 9097 | Register b = locations->InAt(1).AsRegister<Register>(); |
| 9098 | Register out = locations->Out().AsRegister<Register>(); |
| 9099 | |
| 9100 | if (a == b) { |
| 9101 | if (out != a) { |
| 9102 | __ Move(out, a); |
| 9103 | } |
| 9104 | } else { |
| 9105 | __ Slt(AT, a, b); |
| 9106 | if (is_min) { |
| 9107 | if (out != a) { |
| 9108 | __ Movn(out, a, AT); |
| 9109 | } |
| 9110 | if (out != b) { |
| 9111 | __ Movz(out, b, AT); |
| 9112 | } |
| 9113 | } else { |
| 9114 | if (out != a) { |
| 9115 | __ Movz(out, a, AT); |
| 9116 | } |
| 9117 | if (out != b) { |
| 9118 | __ Movn(out, b, AT); |
| 9119 | } |
| 9120 | } |
| 9121 | } |
| 9122 | } |
| 9123 | } |
| 9124 | } |
| 9125 | |
| 9126 | void InstructionCodeGeneratorMIPS::GenerateMinMaxFP(LocationSummary* locations, |
| 9127 | bool is_min, |
| 9128 | bool isR6, |
| 9129 | DataType::Type type) { |
| 9130 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 9131 | FRegister a = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9132 | FRegister b = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 9133 | |
| 9134 | if (isR6) { |
| 9135 | MipsLabel noNaNs; |
| 9136 | MipsLabel done; |
| 9137 | FRegister ftmp = ((out != a) && (out != b)) ? out : FTMP; |
| 9138 | |
| 9139 | // When Java computes min/max it prefers a NaN to a number; the |
| 9140 | // behavior of MIPSR6 is to prefer numbers to NaNs, i.e., if one of |
| 9141 | // the inputs is a NaN and the other is a valid number, the MIPS |
| 9142 | // instruction will return the number; Java wants the NaN value |
| 9143 | // returned. This is why there is extra logic preceding the use of |
| 9144 | // the MIPS min.fmt/max.fmt instructions. If either a, or b holds a |
| 9145 | // NaN, return the NaN, otherwise return the min/max. |
| 9146 | if (type == DataType::Type::kFloat64) { |
| 9147 | __ CmpUnD(FTMP, a, b); |
| 9148 | __ Bc1eqz(FTMP, &noNaNs); |
| 9149 | |
| 9150 | // One of the inputs is a NaN |
| 9151 | __ CmpEqD(ftmp, a, a); |
| 9152 | // If a == a then b is the NaN, otherwise a is the NaN. |
| 9153 | __ SelD(ftmp, a, b); |
| 9154 | |
| 9155 | if (ftmp != out) { |
| 9156 | __ MovD(out, ftmp); |
| 9157 | } |
| 9158 | |
| 9159 | __ B(&done); |
| 9160 | |
| 9161 | __ Bind(&noNaNs); |
| 9162 | |
| 9163 | if (is_min) { |
| 9164 | __ MinD(out, a, b); |
| 9165 | } else { |
| 9166 | __ MaxD(out, a, b); |
| 9167 | } |
| 9168 | } else { |
| 9169 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 9170 | __ CmpUnS(FTMP, a, b); |
| 9171 | __ Bc1eqz(FTMP, &noNaNs); |
| 9172 | |
| 9173 | // One of the inputs is a NaN |
| 9174 | __ CmpEqS(ftmp, a, a); |
| 9175 | // If a == a then b is the NaN, otherwise a is the NaN. |
| 9176 | __ SelS(ftmp, a, b); |
| 9177 | |
| 9178 | if (ftmp != out) { |
| 9179 | __ MovS(out, ftmp); |
| 9180 | } |
| 9181 | |
| 9182 | __ B(&done); |
| 9183 | |
| 9184 | __ Bind(&noNaNs); |
| 9185 | |
| 9186 | if (is_min) { |
| 9187 | __ MinS(out, a, b); |
| 9188 | } else { |
| 9189 | __ MaxS(out, a, b); |
| 9190 | } |
| 9191 | } |
| 9192 | |
| 9193 | __ Bind(&done); |
| 9194 | |
| 9195 | } else { // !isR6 |
| 9196 | MipsLabel ordered; |
| 9197 | MipsLabel compare; |
| 9198 | MipsLabel select; |
| 9199 | MipsLabel done; |
| 9200 | |
| 9201 | if (type == DataType::Type::kFloat64) { |
| 9202 | __ CunD(a, b); |
| 9203 | } else { |
| 9204 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 9205 | __ CunS(a, b); |
| 9206 | } |
| 9207 | __ Bc1f(&ordered); |
| 9208 | |
| 9209 | // a or b (or both) is a NaN. Return one, which is a NaN. |
| 9210 | if (type == DataType::Type::kFloat64) { |
| 9211 | __ CeqD(b, b); |
| 9212 | } else { |
| 9213 | __ CeqS(b, b); |
| 9214 | } |
| 9215 | __ B(&select); |
| 9216 | |
| 9217 | __ Bind(&ordered); |
| 9218 | |
| 9219 | // Neither is a NaN. |
| 9220 | // a == b? (-0.0 compares equal with +0.0) |
| 9221 | // If equal, handle zeroes, else compare further. |
| 9222 | if (type == DataType::Type::kFloat64) { |
| 9223 | __ CeqD(a, b); |
| 9224 | } else { |
| 9225 | __ CeqS(a, b); |
| 9226 | } |
| 9227 | __ Bc1f(&compare); |
| 9228 | |
| 9229 | // a == b either bit for bit or one is -0.0 and the other is +0.0. |
| 9230 | if (type == DataType::Type::kFloat64) { |
| 9231 | __ MoveFromFpuHigh(TMP, a); |
| 9232 | __ MoveFromFpuHigh(AT, b); |
| 9233 | } else { |
| 9234 | __ Mfc1(TMP, a); |
| 9235 | __ Mfc1(AT, b); |
| 9236 | } |
| 9237 | |
| 9238 | if (is_min) { |
| 9239 | // -0.0 prevails over +0.0. |
| 9240 | __ Or(TMP, TMP, AT); |
| 9241 | } else { |
| 9242 | // +0.0 prevails over -0.0. |
| 9243 | __ And(TMP, TMP, AT); |
| 9244 | } |
| 9245 | |
| 9246 | if (type == DataType::Type::kFloat64) { |
| 9247 | __ Mfc1(AT, a); |
| 9248 | __ Mtc1(AT, out); |
| 9249 | __ MoveToFpuHigh(TMP, out); |
| 9250 | } else { |
| 9251 | __ Mtc1(TMP, out); |
| 9252 | } |
| 9253 | __ B(&done); |
| 9254 | |
| 9255 | __ Bind(&compare); |
| 9256 | |
| 9257 | if (type == DataType::Type::kFloat64) { |
| 9258 | if (is_min) { |
| 9259 | // return (a <= b) ? a : b; |
| 9260 | __ ColeD(a, b); |
| 9261 | } else { |
| 9262 | // return (a >= b) ? a : b; |
| 9263 | __ ColeD(b, a); // b <= a |
| 9264 | } |
| 9265 | } else { |
| 9266 | if (is_min) { |
| 9267 | // return (a <= b) ? a : b; |
| 9268 | __ ColeS(a, b); |
| 9269 | } else { |
| 9270 | // return (a >= b) ? a : b; |
| 9271 | __ ColeS(b, a); // b <= a |
| 9272 | } |
| 9273 | } |
| 9274 | |
| 9275 | __ Bind(&select); |
| 9276 | |
| 9277 | if (type == DataType::Type::kFloat64) { |
| 9278 | __ MovtD(out, a); |
| 9279 | __ MovfD(out, b); |
| 9280 | } else { |
| 9281 | __ MovtS(out, a); |
| 9282 | __ MovfS(out, b); |
| 9283 | } |
| 9284 | |
| 9285 | __ Bind(&done); |
| 9286 | } |
| 9287 | } |
| 9288 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 9289 | void InstructionCodeGeneratorMIPS::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 9290 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 9291 | DataType::Type type = minmax->GetResultType(); |
| 9292 | switch (type) { |
| 9293 | case DataType::Type::kInt32: |
| 9294 | case DataType::Type::kInt64: |
| 9295 | GenerateMinMaxInt(minmax->GetLocations(), is_min, isR6, type); |
| 9296 | break; |
| 9297 | case DataType::Type::kFloat32: |
| 9298 | case DataType::Type::kFloat64: |
| 9299 | GenerateMinMaxFP(minmax->GetLocations(), is_min, isR6, type); |
| 9300 | break; |
| 9301 | default: |
| 9302 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 9303 | } |
| 9304 | } |
| 9305 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 9306 | void LocationsBuilderMIPS::VisitMin(HMin* min) { |
| 9307 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 9308 | } |
| 9309 | |
| 9310 | void InstructionCodeGeneratorMIPS::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 9311 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 9312 | } |
| 9313 | |
| 9314 | void LocationsBuilderMIPS::VisitMax(HMax* max) { |
| 9315 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 9316 | } |
| 9317 | |
| 9318 | void InstructionCodeGeneratorMIPS::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 9319 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 9320 | } |
| 9321 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 9322 | void LocationsBuilderMIPS::VisitAbs(HAbs* abs) { |
| 9323 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 9324 | switch (abs->GetResultType()) { |
| 9325 | case DataType::Type::kInt32: |
| 9326 | case DataType::Type::kInt64: |
| 9327 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9328 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9329 | break; |
| 9330 | case DataType::Type::kFloat32: |
| 9331 | case DataType::Type::kFloat64: |
| 9332 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 9333 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 9334 | break; |
| 9335 | default: |
| 9336 | LOG(FATAL) << "Unexpected abs type " << abs->GetResultType(); |
| 9337 | } |
| 9338 | } |
| 9339 | |
| 9340 | void InstructionCodeGeneratorMIPS::GenerateAbsFP(LocationSummary* locations, |
| 9341 | DataType::Type type, |
| 9342 | bool isR2OrNewer, |
| 9343 | bool isR6) { |
| 9344 | FRegister in = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9345 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 9346 | |
| 9347 | // Note, as a "quality of implementation", rather than pure "spec compliance", we require that |
| 9348 | // Math.abs() clears the sign bit (but changes nothing else) for all numbers, including NaN |
| 9349 | // (signaling NaN may become quiet though). |
| 9350 | // |
| 9351 | // The ABS.fmt instructions (abs.s and abs.d) do exactly that when NAN2008=1 (R6). For this case, |
| 9352 | // both regular floating point numbers and NAN values are treated alike, only the sign bit is |
| 9353 | // affected by this instruction. |
| 9354 | // But when NAN2008=0 (R2 and before), the ABS.fmt instructions can't be used. For this case, any |
| 9355 | // NaN operand signals invalid operation. This means that other bits (not just sign bit) might be |
| 9356 | // changed when doing abs(NaN). Because of that, we clear sign bit in a different way. |
| 9357 | if (isR6) { |
| 9358 | if (type == DataType::Type::kFloat64) { |
| 9359 | __ AbsD(out, in); |
| 9360 | } else { |
| 9361 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 9362 | __ AbsS(out, in); |
| 9363 | } |
| 9364 | } else { |
| 9365 | if (type == DataType::Type::kFloat64) { |
| 9366 | if (in != out) { |
| 9367 | __ MovD(out, in); |
| 9368 | } |
| 9369 | __ MoveFromFpuHigh(TMP, in); |
| 9370 | // ins instruction is not available for R1. |
| 9371 | if (isR2OrNewer) { |
| 9372 | __ Ins(TMP, ZERO, 31, 1); |
| 9373 | } else { |
| 9374 | __ Sll(TMP, TMP, 1); |
| 9375 | __ Srl(TMP, TMP, 1); |
| 9376 | } |
| 9377 | __ MoveToFpuHigh(TMP, out); |
| 9378 | } else { |
| 9379 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 9380 | __ Mfc1(TMP, in); |
| 9381 | // ins instruction is not available for R1. |
| 9382 | if (isR2OrNewer) { |
| 9383 | __ Ins(TMP, ZERO, 31, 1); |
| 9384 | } else { |
| 9385 | __ Sll(TMP, TMP, 1); |
| 9386 | __ Srl(TMP, TMP, 1); |
| 9387 | } |
| 9388 | __ Mtc1(TMP, out); |
| 9389 | } |
| 9390 | } |
| 9391 | } |
| 9392 | |
| 9393 | void InstructionCodeGeneratorMIPS::VisitAbs(HAbs* abs) { |
| 9394 | LocationSummary* locations = abs->GetLocations(); |
| 9395 | bool isR2OrNewer = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
| 9396 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 9397 | switch (abs->GetResultType()) { |
| 9398 | case DataType::Type::kInt32: { |
| 9399 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 9400 | Register out = locations->Out().AsRegister<Register>(); |
| 9401 | __ Sra(AT, in, 31); |
| 9402 | __ Xor(out, in, AT); |
| 9403 | __ Subu(out, out, AT); |
| 9404 | break; |
| 9405 | } |
| 9406 | case DataType::Type::kInt64: { |
| 9407 | Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 9408 | Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 9409 | Register out_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 9410 | Register out_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 9411 | // The comments in this section show the analogous operations which would |
| 9412 | // be performed if we had 64-bit registers "in", and "out". |
| 9413 | // __ Dsra32(AT, in, 31); |
| 9414 | __ Sra(AT, in_hi, 31); |
| 9415 | // __ Xor(out, in, AT); |
| 9416 | __ Xor(TMP, in_lo, AT); |
| 9417 | __ Xor(out_hi, in_hi, AT); |
| 9418 | // __ Dsubu(out, out, AT); |
| 9419 | __ Subu(out_lo, TMP, AT); |
| 9420 | __ Sltu(TMP, out_lo, TMP); |
| 9421 | __ Addu(out_hi, out_hi, TMP); |
| 9422 | break; |
| 9423 | } |
| 9424 | case DataType::Type::kFloat32: |
| 9425 | case DataType::Type::kFloat64: |
| 9426 | GenerateAbsFP(locations, abs->GetResultType(), isR2OrNewer, isR6); |
| 9427 | break; |
| 9428 | default: |
| 9429 | LOG(FATAL) << "Unexpected abs type " << abs->GetResultType(); |
| 9430 | } |
| 9431 | } |
| 9432 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 9433 | void LocationsBuilderMIPS::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 9434 | constructor_fence->SetLocations(nullptr); |
| 9435 | } |
| 9436 | |
| 9437 | void InstructionCodeGeneratorMIPS::VisitConstructorFence( |
| 9438 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 9439 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 9440 | } |
| 9441 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9442 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 9443 | memory_barrier->SetLocations(nullptr); |
| 9444 | } |
| 9445 | |
| 9446 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 9447 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 9448 | } |
| 9449 | |
| 9450 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9451 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9452 | DataType::Type return_type = ret->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9453 | locations->SetInAt(0, MipsReturnLocation(return_type)); |
| 9454 | } |
| 9455 | |
| 9456 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 9457 | codegen_->GenerateFrameExit(); |
| 9458 | } |
| 9459 | |
| 9460 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { |
| 9461 | ret->SetLocations(nullptr); |
| 9462 | } |
| 9463 | |
| 9464 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 9465 | codegen_->GenerateFrameExit(); |
| 9466 | } |
| 9467 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 9468 | void LocationsBuilderMIPS::VisitRor(HRor* ror) { |
| 9469 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 9470 | } |
| 9471 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 9472 | void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) { |
| 9473 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 9474 | } |
| 9475 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9476 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { |
| 9477 | HandleShift(shl); |
| 9478 | } |
| 9479 | |
| 9480 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { |
| 9481 | HandleShift(shl); |
| 9482 | } |
| 9483 | |
| 9484 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { |
| 9485 | HandleShift(shr); |
| 9486 | } |
| 9487 | |
| 9488 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { |
| 9489 | HandleShift(shr); |
| 9490 | } |
| 9491 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9492 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { |
| 9493 | HandleBinaryOp(instruction); |
| 9494 | } |
| 9495 | |
| 9496 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { |
| 9497 | HandleBinaryOp(instruction); |
| 9498 | } |
| 9499 | |
| 9500 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 9501 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 9502 | } |
| 9503 | |
| 9504 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 9505 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 9506 | } |
| 9507 | |
| 9508 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 9509 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 9510 | } |
| 9511 | |
| 9512 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 9513 | HandleFieldSet(instruction, |
| 9514 | instruction->GetFieldInfo(), |
| 9515 | instruction->GetDexPc(), |
| 9516 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9517 | } |
| 9518 | |
| 9519 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( |
| 9520 | HUnresolvedInstanceFieldGet* instruction) { |
| 9521 | FieldAccessCallingConventionMIPS calling_convention; |
| 9522 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 9523 | instruction->GetFieldType(), |
| 9524 | calling_convention); |
| 9525 | } |
| 9526 | |
| 9527 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( |
| 9528 | HUnresolvedInstanceFieldGet* instruction) { |
| 9529 | FieldAccessCallingConventionMIPS calling_convention; |
| 9530 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 9531 | instruction->GetFieldType(), |
| 9532 | instruction->GetFieldIndex(), |
| 9533 | instruction->GetDexPc(), |
| 9534 | calling_convention); |
| 9535 | } |
| 9536 | |
| 9537 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( |
| 9538 | HUnresolvedInstanceFieldSet* instruction) { |
| 9539 | FieldAccessCallingConventionMIPS calling_convention; |
| 9540 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 9541 | instruction->GetFieldType(), |
| 9542 | calling_convention); |
| 9543 | } |
| 9544 | |
| 9545 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( |
| 9546 | HUnresolvedInstanceFieldSet* instruction) { |
| 9547 | FieldAccessCallingConventionMIPS calling_convention; |
| 9548 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 9549 | instruction->GetFieldType(), |
| 9550 | instruction->GetFieldIndex(), |
| 9551 | instruction->GetDexPc(), |
| 9552 | calling_convention); |
| 9553 | } |
| 9554 | |
| 9555 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( |
| 9556 | HUnresolvedStaticFieldGet* instruction) { |
| 9557 | FieldAccessCallingConventionMIPS calling_convention; |
| 9558 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 9559 | instruction->GetFieldType(), |
| 9560 | calling_convention); |
| 9561 | } |
| 9562 | |
| 9563 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( |
| 9564 | HUnresolvedStaticFieldGet* instruction) { |
| 9565 | FieldAccessCallingConventionMIPS calling_convention; |
| 9566 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 9567 | instruction->GetFieldType(), |
| 9568 | instruction->GetFieldIndex(), |
| 9569 | instruction->GetDexPc(), |
| 9570 | calling_convention); |
| 9571 | } |
| 9572 | |
| 9573 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( |
| 9574 | HUnresolvedStaticFieldSet* instruction) { |
| 9575 | FieldAccessCallingConventionMIPS calling_convention; |
| 9576 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 9577 | instruction->GetFieldType(), |
| 9578 | calling_convention); |
| 9579 | } |
| 9580 | |
| 9581 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( |
| 9582 | HUnresolvedStaticFieldSet* instruction) { |
| 9583 | FieldAccessCallingConventionMIPS calling_convention; |
| 9584 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 9585 | instruction->GetFieldType(), |
| 9586 | instruction->GetFieldIndex(), |
| 9587 | instruction->GetDexPc(), |
| 9588 | calling_convention); |
| 9589 | } |
| 9590 | |
| 9591 | void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9592 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 9593 | instruction, LocationSummary::kCallOnSlowPath); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 9594 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 9595 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 9596 | // registers in full width (since the runtime only saves/restores lower part). |
| 9597 | locations->SetCustomSlowPathCallerSaves( |
| 9598 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9599 | } |
| 9600 | |
| 9601 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 9602 | HBasicBlock* block = instruction->GetBlock(); |
| 9603 | if (block->GetLoopInformation() != nullptr) { |
| 9604 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 9605 | // The back edge will generate the suspend check. |
| 9606 | return; |
| 9607 | } |
| 9608 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 9609 | // The goto will generate the suspend check. |
| 9610 | return; |
| 9611 | } |
| 9612 | GenerateSuspendCheck(instruction, nullptr); |
| 9613 | } |
| 9614 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9615 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9616 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 9617 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9618 | InvokeRuntimeCallingConvention calling_convention; |
| 9619 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 9620 | } |
| 9621 | |
| 9622 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 9623 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9624 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 9625 | } |
| 9626 | |
| 9627 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9628 | DataType::Type input_type = conversion->GetInputType(); |
| 9629 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9630 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 9631 | << input_type << " -> " << result_type; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9632 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9633 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9634 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 9635 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9636 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 9637 | } |
| 9638 | |
| 9639 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9640 | if (!isR6 && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9641 | ((DataType::IsFloatingPointType(result_type) && input_type == DataType::Type::kInt64) || |
| 9642 | (result_type == DataType::Type::kInt64 && DataType::IsFloatingPointType(input_type)))) { |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 9643 | call_kind = LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9644 | } |
| 9645 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9646 | LocationSummary* locations = |
| 9647 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9648 | |
| 9649 | if (call_kind == LocationSummary::kNoCall) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9650 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9651 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 9652 | } else { |
| 9653 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9654 | } |
| 9655 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9656 | if (DataType::IsFloatingPointType(result_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9657 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 9658 | } else { |
| 9659 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9660 | } |
| 9661 | } else { |
| 9662 | InvokeRuntimeCallingConvention calling_convention; |
| 9663 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9664 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9665 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 9666 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9667 | DCHECK_EQ(input_type, DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9668 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 9669 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 9670 | } |
| 9671 | |
| 9672 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 9673 | } |
| 9674 | } |
| 9675 | |
| 9676 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 9677 | LocationSummary* locations = conversion->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9678 | DataType::Type result_type = conversion->GetResultType(); |
| 9679 | DataType::Type input_type = conversion->GetInputType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9680 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9681 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9682 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9683 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 9684 | << input_type << " -> " << result_type; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9685 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9686 | if (result_type == DataType::Type::kInt64 && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9687 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 9688 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 9689 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 9690 | |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 9691 | if (dst_low != src) { |
| 9692 | __ Move(dst_low, src); |
| 9693 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9694 | __ Sra(dst_high, src, 31); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9695 | } else if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9696 | Register dst = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9697 | Register src = (input_type == DataType::Type::kInt64) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9698 | ? locations->InAt(0).AsRegisterPairLow<Register>() |
| 9699 | : locations->InAt(0).AsRegister<Register>(); |
| 9700 | |
| 9701 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9702 | case DataType::Type::kUint8: |
| 9703 | __ Andi(dst, src, 0xFF); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9704 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9705 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9706 | if (has_sign_extension) { |
| 9707 | __ Seb(dst, src); |
| 9708 | } else { |
| 9709 | __ Sll(dst, src, 24); |
| 9710 | __ Sra(dst, dst, 24); |
| 9711 | } |
| 9712 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9713 | case DataType::Type::kUint16: |
| 9714 | __ Andi(dst, src, 0xFFFF); |
| 9715 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9716 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9717 | if (has_sign_extension) { |
| 9718 | __ Seh(dst, src); |
| 9719 | } else { |
| 9720 | __ Sll(dst, src, 16); |
| 9721 | __ Sra(dst, dst, 16); |
| 9722 | } |
| 9723 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9724 | case DataType::Type::kInt32: |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 9725 | if (dst != src) { |
| 9726 | __ Move(dst, src); |
| 9727 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9728 | break; |
| 9729 | |
| 9730 | default: |
| 9731 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 9732 | << " to " << result_type; |
| 9733 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9734 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
| 9735 | if (input_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9736 | if (isR6) { |
| 9737 | // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 9738 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 9739 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 9740 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 9741 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 9742 | __ Mtc1(src_low, FTMP); |
| 9743 | __ Mthc1(src_high, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9744 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9745 | __ Cvtsl(dst, FTMP); |
| 9746 | } else { |
| 9747 | __ Cvtdl(dst, FTMP); |
| 9748 | } |
| 9749 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9750 | QuickEntrypointEnum entrypoint = |
| 9751 | (result_type == DataType::Type::kFloat32) ? kQuickL2f : kQuickL2d; |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 9752 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9753 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9754 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 9755 | } else { |
| 9756 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 9757 | } |
| 9758 | } |
| 9759 | } else { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9760 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 9761 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 9762 | __ Mtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9763 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9764 | __ Cvtsw(dst, FTMP); |
| 9765 | } else { |
| 9766 | __ Cvtdw(dst, FTMP); |
| 9767 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9768 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9769 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 9770 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9771 | |
| 9772 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum |
| 9773 | // value of the output type if the input is outside of the range after the truncation or |
| 9774 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct |
| 9775 | // results. This matches the desired float/double-to-int/long conversion exactly. |
| 9776 | // |
| 9777 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive |
| 9778 | // value when the input is either a NaN or is outside of the range of the output type |
| 9779 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce |
| 9780 | // the same result. |
| 9781 | // |
| 9782 | // The code takes care of the different behaviors by first comparing the input to the |
| 9783 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). |
| 9784 | // If the input is greater than or equal to the minimum, it procedes to the truncate |
| 9785 | // instruction, which will handle such an input the same way irrespective of NAN2008. |
| 9786 | // Otherwise the input is compared to itself to determine whether it is a NaN or not |
| 9787 | // in order to return either zero or the minimum value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9788 | if (result_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9789 | if (isR6) { |
| 9790 | // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 9791 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 9792 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9793 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 9794 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9795 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9796 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9797 | __ TruncLS(FTMP, src); |
| 9798 | } else { |
| 9799 | __ TruncLD(FTMP, src); |
| 9800 | } |
| 9801 | __ Mfc1(dst_low, FTMP); |
| 9802 | __ Mfhc1(dst_high, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9803 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9804 | QuickEntrypointEnum entrypoint = |
| 9805 | (input_type == DataType::Type::kFloat32) ? kQuickF2l : kQuickD2l; |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 9806 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9807 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9808 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 9809 | } else { |
| 9810 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 9811 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9812 | } |
| 9813 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9814 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9815 | Register dst = locations->Out().AsRegister<Register>(); |
| 9816 | MipsLabel truncate; |
| 9817 | MipsLabel done; |
| 9818 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9819 | if (!isR6) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9820 | if (input_type == DataType::Type::kFloat32) { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9821 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); |
| 9822 | __ LoadConst32(TMP, min_val); |
| 9823 | __ Mtc1(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9824 | } else { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9825 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); |
| 9826 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 9827 | __ Mtc1(ZERO, FTMP); |
| 9828 | __ MoveToFpuHigh(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9829 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9830 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9831 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9832 | __ ColeS(0, FTMP, src); |
| 9833 | } else { |
| 9834 | __ ColeD(0, FTMP, src); |
| 9835 | } |
| 9836 | __ Bc1t(0, &truncate); |
| 9837 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9838 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9839 | __ CeqS(0, src, src); |
| 9840 | } else { |
| 9841 | __ CeqD(0, src, src); |
| 9842 | } |
| 9843 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 9844 | __ Movf(dst, ZERO, 0); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9845 | |
| 9846 | __ B(&done); |
| 9847 | |
| 9848 | __ Bind(&truncate); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9849 | } |
| 9850 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9851 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9852 | __ TruncWS(FTMP, src); |
| 9853 | } else { |
| 9854 | __ TruncWD(FTMP, src); |
| 9855 | } |
| 9856 | __ Mfc1(dst, FTMP); |
| 9857 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9858 | if (!isR6) { |
| 9859 | __ Bind(&done); |
| 9860 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9861 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9862 | } else if (DataType::IsFloatingPointType(result_type) && |
| 9863 | DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9864 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 9865 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9866 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9867 | __ Cvtsd(dst, src); |
| 9868 | } else { |
| 9869 | __ Cvtds(dst, src); |
| 9870 | } |
| 9871 | } else { |
| 9872 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 9873 | << " to " << result_type; |
| 9874 | } |
| 9875 | } |
| 9876 | |
| 9877 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { |
| 9878 | HandleShift(ushr); |
| 9879 | } |
| 9880 | |
| 9881 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { |
| 9882 | HandleShift(ushr); |
| 9883 | } |
| 9884 | |
| 9885 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { |
| 9886 | HandleBinaryOp(instruction); |
| 9887 | } |
| 9888 | |
| 9889 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { |
| 9890 | HandleBinaryOp(instruction); |
| 9891 | } |
| 9892 | |
| 9893 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9894 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9895 | LOG(FATAL) << "Unreachable"; |
| 9896 | } |
| 9897 | |
| 9898 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9899 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9900 | LOG(FATAL) << "Unreachable"; |
| 9901 | } |
| 9902 | |
| 9903 | void LocationsBuilderMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9904 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9905 | } |
| 9906 | |
| 9907 | void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9908 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9909 | } |
| 9910 | |
| 9911 | void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9912 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9913 | } |
| 9914 | |
| 9915 | void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9916 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9917 | } |
| 9918 | |
| 9919 | void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9920 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9921 | } |
| 9922 | |
| 9923 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9924 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9925 | } |
| 9926 | |
| 9927 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9928 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9929 | } |
| 9930 | |
| 9931 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9932 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9933 | } |
| 9934 | |
| 9935 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9936 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9937 | } |
| 9938 | |
| 9939 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9940 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9941 | } |
| 9942 | |
| 9943 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9944 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9945 | } |
| 9946 | |
| 9947 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9948 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9949 | } |
| 9950 | |
| 9951 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9952 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9953 | } |
| 9954 | |
| 9955 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9956 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9957 | } |
| 9958 | |
| 9959 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9960 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9961 | } |
| 9962 | |
| 9963 | void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9964 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9965 | } |
| 9966 | |
| 9967 | void LocationsBuilderMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9968 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9969 | } |
| 9970 | |
| 9971 | void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9972 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9973 | } |
| 9974 | |
| 9975 | void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9976 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9977 | } |
| 9978 | |
| 9979 | void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9980 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9981 | } |
| 9982 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9983 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9984 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9985 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9986 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9987 | if (!codegen_->GetInstructionSetFeatures().IsR6()) { |
| 9988 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9989 | if (num_entries > InstructionCodeGeneratorMIPS::kPackedSwitchJumpTableThreshold) { |
| 9990 | // When there's no HMipsComputeBaseMethodAddress input, R2 uses the NAL |
| 9991 | // instruction to simulate PC-relative addressing when accessing the jump table. |
| 9992 | // NAL clobbers RA. Make sure RA is preserved. |
| 9993 | codegen_->ClobberRA(); |
| 9994 | } |
| 9995 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9996 | } |
| 9997 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9998 | void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg, |
| 9999 | int32_t lower_bound, |
| 10000 | uint32_t num_entries, |
| 10001 | HBasicBlock* switch_block, |
| 10002 | HBasicBlock* default_block) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 10003 | // Create a set of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 10004 | Register temp_reg = TMP; |
| 10005 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
| 10006 | // Jump to default if index is negative |
| 10007 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 10008 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 10009 | __ Bltz(temp_reg, codegen_->GetLabelOf(default_block)); |
| 10010 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10011 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 10012 | // Jump to successors[0] if value == lower_bound. |
| 10013 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 10014 | int32_t last_index = 0; |
| 10015 | for (; num_entries - last_index > 2; last_index += 2) { |
| 10016 | __ Addiu(temp_reg, temp_reg, -2); |
| 10017 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 10018 | __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 10019 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 10020 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 10021 | } |
| 10022 | if (num_entries - last_index == 2) { |
| 10023 | // The last missing case_value. |
| 10024 | __ Addiu(temp_reg, temp_reg, -1); |
| 10025 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 10026 | } |
| 10027 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 10028 | // And the default for any other value. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10029 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 10030 | __ B(codegen_->GetLabelOf(default_block)); |
| 10031 | } |
| 10032 | } |
| 10033 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10034 | void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg, |
| 10035 | Register constant_area, |
| 10036 | int32_t lower_bound, |
| 10037 | uint32_t num_entries, |
| 10038 | HBasicBlock* switch_block, |
| 10039 | HBasicBlock* default_block) { |
| 10040 | // Create a jump table. |
| 10041 | std::vector<MipsLabel*> labels(num_entries); |
| 10042 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 10043 | for (uint32_t i = 0; i < num_entries; i++) { |
| 10044 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 10045 | } |
| 10046 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 10047 | |
| 10048 | // Is the value in range? |
| 10049 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 10050 | if (IsInt<16>(static_cast<int32_t>(num_entries))) { |
| 10051 | __ Sltiu(AT, TMP, num_entries); |
| 10052 | __ Beqz(AT, codegen_->GetLabelOf(default_block)); |
| 10053 | } else { |
| 10054 | __ LoadConst32(AT, num_entries); |
| 10055 | __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 10056 | } |
| 10057 | |
| 10058 | // We are in the range of the table. |
| 10059 | // Load the target address from the jump table, indexing by the value. |
| 10060 | __ LoadLabelAddress(AT, constant_area, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 10061 | __ ShiftAndAdd(TMP, TMP, AT, 2, TMP); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10062 | __ Lw(TMP, TMP, 0); |
| 10063 | // Compute the absolute target address by adding the table start address |
| 10064 | // (the table contains offsets to targets relative to its start). |
| 10065 | __ Addu(TMP, TMP, AT); |
| 10066 | // And jump. |
| 10067 | __ Jr(TMP); |
| 10068 | __ NopIfNoReordering(); |
| 10069 | } |
| 10070 | |
| 10071 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 10072 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 10073 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 10074 | LocationSummary* locations = switch_instr->GetLocations(); |
| 10075 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 10076 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 10077 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 10078 | |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 10079 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10080 | // R6 uses PC-relative addressing to access the jump table. |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 10081 | // |
| 10082 | // R2, OTOH, uses an HMipsComputeBaseMethodAddress input (when available) |
| 10083 | // to access the jump table and it is implemented by changing HPackedSwitch to |
| 10084 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress (see |
| 10085 | // VisitMipsPackedSwitch()). |
| 10086 | // |
| 10087 | // When there's no HMipsComputeBaseMethodAddress input (e.g. in presence of |
| 10088 | // irreducible loops), R2 uses the NAL instruction to simulate PC-relative |
| 10089 | // addressing. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10090 | GenTableBasedPackedSwitch(value_reg, |
| 10091 | ZERO, |
| 10092 | lower_bound, |
| 10093 | num_entries, |
| 10094 | switch_block, |
| 10095 | default_block); |
| 10096 | } else { |
| 10097 | GenPackedSwitchWithCompares(value_reg, |
| 10098 | lower_bound, |
| 10099 | num_entries, |
| 10100 | switch_block, |
| 10101 | default_block); |
| 10102 | } |
| 10103 | } |
| 10104 | |
| 10105 | void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 10106 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 10107 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 10108 | locations->SetInAt(0, Location::RequiresRegister()); |
| 10109 | // Constant area pointer (HMipsComputeBaseMethodAddress). |
| 10110 | locations->SetInAt(1, Location::RequiresRegister()); |
| 10111 | } |
| 10112 | |
| 10113 | void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 10114 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 10115 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 10116 | LocationSummary* locations = switch_instr->GetLocations(); |
| 10117 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 10118 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 10119 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 10120 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 10121 | |
| 10122 | // This is an R2-only path. HPackedSwitch has been changed to |
| 10123 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress |
| 10124 | // required to address the jump table relative to PC. |
| 10125 | GenTableBasedPackedSwitch(value_reg, |
| 10126 | constant_area, |
| 10127 | lower_bound, |
| 10128 | num_entries, |
| 10129 | switch_block, |
| 10130 | default_block); |
| 10131 | } |
| 10132 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 10133 | void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress( |
| 10134 | HMipsComputeBaseMethodAddress* insn) { |
| 10135 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 10136 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 10137 | locations->SetOut(Location::RequiresRegister()); |
| 10138 | } |
| 10139 | |
| 10140 | void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress( |
| 10141 | HMipsComputeBaseMethodAddress* insn) { |
| 10142 | LocationSummary* locations = insn->GetLocations(); |
| 10143 | Register reg = locations->Out().AsRegister<Register>(); |
| 10144 | |
| 10145 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 10146 | |
| 10147 | // Generate a dummy PC-relative call to obtain PC. |
| 10148 | __ Nal(); |
| 10149 | // Grab the return address off RA. |
| 10150 | __ Move(reg, RA); |
| 10151 | |
| 10152 | // Remember this offset (the obtained PC value) for later use with constant area. |
| 10153 | __ BindPcRelBaseLabel(); |
| 10154 | } |
| 10155 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 10156 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 10157 | // The trampoline uses the same calling convention as dex calling conventions, |
| 10158 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 10159 | // the method_idx. |
| 10160 | HandleInvoke(invoke); |
| 10161 | } |
| 10162 | |
| 10163 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 10164 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 10165 | } |
| 10166 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10167 | void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 10168 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 10169 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10170 | locations->SetInAt(0, Location::RequiresRegister()); |
| 10171 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 10172 | } |
| 10173 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10174 | void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 10175 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 10176 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 10177 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10178 | instruction->GetIndex(), kMipsPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 10179 | __ LoadFromOffset(kLoadWord, |
| 10180 | locations->Out().AsRegister<Register>(), |
| 10181 | locations->InAt(0).AsRegister<Register>(), |
| 10182 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10183 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 10184 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 10185 | instruction->GetIndex(), kMipsPointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 10186 | __ LoadFromOffset(kLoadWord, |
| 10187 | locations->Out().AsRegister<Register>(), |
| 10188 | locations->InAt(0).AsRegister<Register>(), |
| 10189 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 10190 | __ LoadFromOffset(kLoadWord, |
| 10191 | locations->Out().AsRegister<Register>(), |
| 10192 | locations->Out().AsRegister<Register>(), |
| 10193 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 10194 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 10195 | } |
| 10196 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 10197 | void LocationsBuilderMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 10198 | ATTRIBUTE_UNUSED) { |
| 10199 | LOG(FATAL) << "Unreachable"; |
| 10200 | } |
| 10201 | |
| 10202 | void InstructionCodeGeneratorMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 10203 | ATTRIBUTE_UNUSED) { |
| 10204 | LOG(FATAL) << "Unreachable"; |
| 10205 | } |
| 10206 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 10207 | #undef __ |
| 10208 | #undef QUICK_ENTRY_POINT |
| 10209 | |
| 10210 | } // namespace mips |
| 10211 | } // namespace art |