Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_mips.h" |
| 18 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 19 | #include "arch/mips/asm_support_mips.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 20 | #include "arch/mips/entrypoints_direct_mips.h" |
| 21 | #include "arch/mips/instruction_set_features_mips.h" |
| 22 | #include "art_method.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 23 | #include "class_table.h" |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 24 | #include "code_generator_utils.h" |
Vladimir Marko | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 25 | #include "compiled_method.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 26 | #include "entrypoints/quick/quick_entrypoints.h" |
| 27 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| 28 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 29 | #include "heap_poisoning.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 30 | #include "intrinsics.h" |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 31 | #include "intrinsics_mips.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 32 | #include "linker/linker_patch.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 33 | #include "mirror/array-inl.h" |
| 34 | #include "mirror/class-inl.h" |
| 35 | #include "offsets.h" |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 36 | #include "stack_map_stream.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 37 | #include "thread.h" |
| 38 | #include "utils/assembler.h" |
| 39 | #include "utils/mips/assembler_mips.h" |
| 40 | #include "utils/stack_checks.h" |
| 41 | |
| 42 | namespace art { |
| 43 | namespace mips { |
| 44 | |
| 45 | static constexpr int kCurrentMethodStackOffset = 0; |
| 46 | static constexpr Register kMethodRegisterArgument = A0; |
| 47 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 48 | // Flags controlling the use of thunks for Baker read barriers. |
| 49 | constexpr bool kBakerReadBarrierThunksEnableForFields = true; |
| 50 | constexpr bool kBakerReadBarrierThunksEnableForArrays = true; |
| 51 | constexpr bool kBakerReadBarrierThunksEnableForGcRoots = true; |
| 52 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 53 | Location MipsReturnLocation(DataType::Type return_type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 54 | switch (return_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 55 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 56 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 57 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 58 | case DataType::Type::kInt8: |
| 59 | case DataType::Type::kUint16: |
| 60 | case DataType::Type::kInt16: |
| 61 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 62 | return Location::RegisterLocation(V0); |
| 63 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 64 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 65 | return Location::RegisterPairLocation(V0, V1); |
| 66 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 67 | case DataType::Type::kFloat32: |
| 68 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 69 | return Location::FpuRegisterLocation(F0); |
| 70 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 71 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 72 | return Location(); |
| 73 | } |
| 74 | UNREACHABLE(); |
| 75 | } |
| 76 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 77 | Location InvokeDexCallingConventionVisitorMIPS::GetReturnLocation(DataType::Type type) const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 78 | return MipsReturnLocation(type); |
| 79 | } |
| 80 | |
| 81 | Location InvokeDexCallingConventionVisitorMIPS::GetMethodLocation() const { |
| 82 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 83 | } |
| 84 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 85 | Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(DataType::Type type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 86 | Location next_location; |
| 87 | |
| 88 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 89 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 90 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 91 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 92 | case DataType::Type::kInt8: |
| 93 | case DataType::Type::kUint16: |
| 94 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 95 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 96 | uint32_t gp_index = gp_index_++; |
| 97 | if (gp_index < calling_convention.GetNumberOfRegisters()) { |
| 98 | next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index)); |
| 99 | } else { |
| 100 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 101 | next_location = Location::StackSlot(stack_offset); |
| 102 | } |
| 103 | break; |
| 104 | } |
| 105 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 106 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 107 | uint32_t gp_index = gp_index_; |
| 108 | gp_index_ += 2; |
| 109 | if (gp_index + 1 < calling_convention.GetNumberOfRegisters()) { |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 110 | Register reg = calling_convention.GetRegisterAt(gp_index); |
| 111 | if (reg == A1 || reg == A3) { |
| 112 | gp_index_++; // Skip A1(A3), and use A2_A3(T0_T1) instead. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 113 | gp_index++; |
| 114 | } |
| 115 | Register low_even = calling_convention.GetRegisterAt(gp_index); |
| 116 | Register high_odd = calling_convention.GetRegisterAt(gp_index + 1); |
| 117 | DCHECK_EQ(low_even + 1, high_odd); |
| 118 | next_location = Location::RegisterPairLocation(low_even, high_odd); |
| 119 | } else { |
| 120 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 121 | next_location = Location::DoubleStackSlot(stack_offset); |
| 122 | } |
| 123 | break; |
| 124 | } |
| 125 | |
| 126 | // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double |
| 127 | // will take up the even/odd pair, while floats are stored in even regs only. |
| 128 | // 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] | 129 | case DataType::Type::kFloat32: |
| 130 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 131 | uint32_t float_index = float_index_++; |
| 132 | if (float_index < calling_convention.GetNumberOfFpuRegisters()) { |
| 133 | next_location = Location::FpuRegisterLocation( |
| 134 | calling_convention.GetFpuRegisterAt(float_index)); |
| 135 | } else { |
| 136 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 137 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 138 | : Location::StackSlot(stack_offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 139 | } |
| 140 | break; |
| 141 | } |
| 142 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 143 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 144 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 145 | break; |
| 146 | } |
| 147 | |
| 148 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 149 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 150 | |
| 151 | return next_location; |
| 152 | } |
| 153 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 154 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 155 | return MipsReturnLocation(type); |
| 156 | } |
| 157 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 158 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 159 | #define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 160 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 161 | |
| 162 | class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 163 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 164 | explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 165 | |
| 166 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 167 | LocationSummary* locations = instruction_->GetLocations(); |
| 168 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 169 | __ Bind(GetEntryLabel()); |
| 170 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 171 | // Live registers will be restored in the catch block if caught. |
| 172 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 173 | } |
| 174 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 175 | // move resolver. |
| 176 | InvokeRuntimeCallingConvention calling_convention; |
| 177 | codegen->EmitParallelMoves(locations->InAt(0), |
| 178 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 179 | DataType::Type::kInt32, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 180 | locations->InAt(1), |
| 181 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 182 | DataType::Type::kInt32); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 183 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 184 | ? kQuickThrowStringBounds |
| 185 | : kQuickThrowArrayBounds; |
| 186 | mips_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 187 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 188 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 189 | } |
| 190 | |
| 191 | bool IsFatal() const OVERRIDE { return true; } |
| 192 | |
| 193 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; } |
| 194 | |
| 195 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 196 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS); |
| 197 | }; |
| 198 | |
| 199 | class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 200 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 201 | explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 202 | |
| 203 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 204 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 205 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 206 | mips_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 207 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 208 | } |
| 209 | |
| 210 | bool IsFatal() const OVERRIDE { return true; } |
| 211 | |
| 212 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; } |
| 213 | |
| 214 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 215 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS); |
| 216 | }; |
| 217 | |
| 218 | class LoadClassSlowPathMIPS : public SlowPathCodeMIPS { |
| 219 | public: |
| 220 | LoadClassSlowPathMIPS(HLoadClass* cls, |
| 221 | HInstruction* at, |
| 222 | uint32_t dex_pc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 223 | bool do_clinit) |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 224 | : SlowPathCodeMIPS(at), |
| 225 | cls_(cls), |
| 226 | dex_pc_(dex_pc), |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 227 | do_clinit_(do_clinit) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 228 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 229 | } |
| 230 | |
| 231 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 232 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 233 | Location out = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 234 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 235 | InvokeRuntimeCallingConvention calling_convention; |
| 236 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 237 | __ Bind(GetEntryLabel()); |
| 238 | SaveLiveRegisters(codegen, locations); |
| 239 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 240 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 241 | __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 242 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 243 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 244 | mips_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 245 | if (do_clinit_) { |
| 246 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 247 | } else { |
| 248 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 249 | } |
| 250 | |
| 251 | // Move the class to the desired location. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 252 | if (out.IsValid()) { |
| 253 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 254 | DataType::Type type = instruction_->GetType(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 255 | mips_codegen->MoveLocation(out, |
| 256 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 257 | type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 258 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 259 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 260 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 261 | __ B(GetExitLabel()); |
| 262 | } |
| 263 | |
| 264 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; } |
| 265 | |
| 266 | private: |
| 267 | // The class this slow path will load. |
| 268 | HLoadClass* const cls_; |
| 269 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 270 | // The dex PC of `at_`. |
| 271 | const uint32_t dex_pc_; |
| 272 | |
| 273 | // Whether to initialize the class. |
| 274 | const bool do_clinit_; |
| 275 | |
| 276 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS); |
| 277 | }; |
| 278 | |
| 279 | class LoadStringSlowPathMIPS : public SlowPathCodeMIPS { |
| 280 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 281 | explicit LoadStringSlowPathMIPS(HLoadString* instruction) |
| 282 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 283 | |
| 284 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 285 | DCHECK(instruction_->IsLoadString()); |
| 286 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 287 | LocationSummary* locations = instruction_->GetLocations(); |
| 288 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 289 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 290 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 291 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 292 | __ Bind(GetEntryLabel()); |
| 293 | SaveLiveRegisters(codegen, locations); |
| 294 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 295 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 296 | mips_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 297 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 298 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 299 | DataType::Type type = instruction_->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 300 | mips_codegen->MoveLocation(locations->Out(), |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 301 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 302 | type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 303 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 304 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 305 | __ B(GetExitLabel()); |
| 306 | } |
| 307 | |
| 308 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; } |
| 309 | |
| 310 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 311 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS); |
| 312 | }; |
| 313 | |
| 314 | class NullCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 315 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 316 | explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 317 | |
| 318 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 319 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 320 | __ Bind(GetEntryLabel()); |
| 321 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 322 | // Live registers will be restored in the catch block if caught. |
| 323 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 324 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 325 | mips_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 326 | instruction_, |
| 327 | instruction_->GetDexPc(), |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 328 | this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 329 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 330 | } |
| 331 | |
| 332 | bool IsFatal() const OVERRIDE { return true; } |
| 333 | |
| 334 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; } |
| 335 | |
| 336 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 337 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS); |
| 338 | }; |
| 339 | |
| 340 | class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 341 | public: |
| 342 | SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 343 | : SlowPathCodeMIPS(instruction), successor_(successor) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 344 | |
| 345 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 346 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 347 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 348 | __ Bind(GetEntryLabel()); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 349 | SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD. |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 350 | mips_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 351 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 352 | RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 353 | if (successor_ == nullptr) { |
| 354 | __ B(GetReturnLabel()); |
| 355 | } else { |
| 356 | __ B(mips_codegen->GetLabelOf(successor_)); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | MipsLabel* GetReturnLabel() { |
| 361 | DCHECK(successor_ == nullptr); |
| 362 | return &return_label_; |
| 363 | } |
| 364 | |
| 365 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; } |
| 366 | |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 367 | HBasicBlock* GetSuccessor() const { |
| 368 | return successor_; |
| 369 | } |
| 370 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 371 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 372 | // If not null, the block to branch to after the suspend check. |
| 373 | HBasicBlock* const successor_; |
| 374 | |
| 375 | // If `successor_` is null, the label to branch to after the suspend check. |
| 376 | MipsLabel return_label_; |
| 377 | |
| 378 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS); |
| 379 | }; |
| 380 | |
| 381 | class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 382 | public: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 383 | explicit TypeCheckSlowPathMIPS(HInstruction* instruction, bool is_fatal) |
| 384 | : SlowPathCodeMIPS(instruction), is_fatal_(is_fatal) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 385 | |
| 386 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 387 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 388 | uint32_t dex_pc = instruction_->GetDexPc(); |
| 389 | DCHECK(instruction_->IsCheckCast() |
| 390 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 391 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 392 | |
| 393 | __ Bind(GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 394 | if (!is_fatal_) { |
| 395 | SaveLiveRegisters(codegen, locations); |
| 396 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 397 | |
| 398 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 399 | // move resolver. |
| 400 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 401 | codegen->EmitParallelMoves(locations->InAt(0), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 402 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 403 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 404 | locations->InAt(1), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 405 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 406 | DataType::Type::kReference); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 407 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 408 | mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 409 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 410 | DataType::Type ret_type = instruction_->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 411 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 412 | mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 413 | } else { |
| 414 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 415 | mips_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 416 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 419 | if (!is_fatal_) { |
| 420 | RestoreLiveRegisters(codegen, locations); |
| 421 | __ B(GetExitLabel()); |
| 422 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; } |
| 426 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 427 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 428 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 429 | private: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 430 | const bool is_fatal_; |
| 431 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 432 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS); |
| 433 | }; |
| 434 | |
| 435 | class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS { |
| 436 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 437 | explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 438 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 439 | |
| 440 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 441 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 442 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 443 | LocationSummary* locations = instruction_->GetLocations(); |
| 444 | SaveLiveRegisters(codegen, locations); |
| 445 | InvokeRuntimeCallingConvention calling_convention; |
| 446 | __ LoadConst32(calling_convention.GetRegisterAt(0), |
| 447 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 448 | mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 449 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; } |
| 453 | |
| 454 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 455 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS); |
| 456 | }; |
| 457 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 458 | class ArraySetSlowPathMIPS : public SlowPathCodeMIPS { |
| 459 | public: |
| 460 | explicit ArraySetSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {} |
| 461 | |
| 462 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 463 | LocationSummary* locations = instruction_->GetLocations(); |
| 464 | __ Bind(GetEntryLabel()); |
| 465 | SaveLiveRegisters(codegen, locations); |
| 466 | |
| 467 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 468 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 469 | parallel_move.AddMove( |
| 470 | locations->InAt(0), |
| 471 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 472 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 473 | nullptr); |
| 474 | parallel_move.AddMove( |
| 475 | locations->InAt(1), |
| 476 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 477 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 478 | nullptr); |
| 479 | parallel_move.AddMove( |
| 480 | locations->InAt(2), |
| 481 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 482 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 483 | nullptr); |
| 484 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 485 | |
| 486 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 487 | mips_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 488 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 489 | RestoreLiveRegisters(codegen, locations); |
| 490 | __ B(GetExitLabel()); |
| 491 | } |
| 492 | |
| 493 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS"; } |
| 494 | |
| 495 | private: |
| 496 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS); |
| 497 | }; |
| 498 | |
| 499 | // Slow path marking an object reference `ref` during a read |
| 500 | // barrier. The field `obj.field` in the object `obj` holding this |
| 501 | // reference does not get updated by this slow path after marking (see |
| 502 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS below for that). |
| 503 | // |
| 504 | // This means that after the execution of this slow path, `ref` will |
| 505 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 506 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 507 | // probably still be a from-space reference (unless it gets updated by |
| 508 | // another thread, or if another thread installed another object |
| 509 | // reference (different from `ref`) in `obj.field`). |
| 510 | // |
| 511 | // If `entrypoint` is a valid location it is assumed to already be |
| 512 | // holding the entrypoint. The case where the entrypoint is passed in |
| 513 | // is for the GcRoot read barrier. |
| 514 | class ReadBarrierMarkSlowPathMIPS : public SlowPathCodeMIPS { |
| 515 | public: |
| 516 | ReadBarrierMarkSlowPathMIPS(HInstruction* instruction, |
| 517 | Location ref, |
| 518 | Location entrypoint = Location::NoLocation()) |
| 519 | : SlowPathCodeMIPS(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 520 | DCHECK(kEmitCompilerReadBarrier); |
| 521 | } |
| 522 | |
| 523 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; } |
| 524 | |
| 525 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 526 | LocationSummary* locations = instruction_->GetLocations(); |
| 527 | Register ref_reg = ref_.AsRegister<Register>(); |
| 528 | DCHECK(locations->CanCall()); |
| 529 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 530 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 531 | instruction_->IsStaticFieldGet() || |
| 532 | instruction_->IsArrayGet() || |
| 533 | instruction_->IsArraySet() || |
| 534 | instruction_->IsLoadClass() || |
| 535 | instruction_->IsLoadString() || |
| 536 | instruction_->IsInstanceOf() || |
| 537 | instruction_->IsCheckCast() || |
| 538 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 539 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 540 | << "Unexpected instruction in read barrier marking slow path: " |
| 541 | << instruction_->DebugName(); |
| 542 | |
| 543 | __ Bind(GetEntryLabel()); |
| 544 | // No need to save live registers; it's taken care of by the |
| 545 | // entrypoint. Also, there is no need to update the stack mask, |
| 546 | // as this runtime call will not trigger a garbage collection. |
| 547 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 548 | DCHECK((V0 <= ref_reg && ref_reg <= T7) || |
| 549 | (S2 <= ref_reg && ref_reg <= S7) || |
| 550 | (ref_reg == FP)) << ref_reg; |
| 551 | // "Compact" slow path, saving two moves. |
| 552 | // |
| 553 | // Instead of using the standard runtime calling convention (input |
| 554 | // and output in A0 and V0 respectively): |
| 555 | // |
| 556 | // A0 <- ref |
| 557 | // V0 <- ReadBarrierMark(A0) |
| 558 | // ref <- V0 |
| 559 | // |
| 560 | // we just use rX (the register containing `ref`) as input and output |
| 561 | // of a dedicated entrypoint: |
| 562 | // |
| 563 | // rX <- ReadBarrierMarkRegX(rX) |
| 564 | // |
| 565 | if (entrypoint_.IsValid()) { |
| 566 | mips_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 567 | DCHECK_EQ(entrypoint_.AsRegister<Register>(), T9); |
| 568 | __ Jalr(entrypoint_.AsRegister<Register>()); |
| 569 | __ NopIfNoReordering(); |
| 570 | } else { |
| 571 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 572 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 573 | // This runtime call does not require a stack map. |
| 574 | mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 575 | instruction_, |
| 576 | this, |
| 577 | /* direct */ false); |
| 578 | } |
| 579 | __ B(GetExitLabel()); |
| 580 | } |
| 581 | |
| 582 | private: |
| 583 | // The location (register) of the marked object reference. |
| 584 | const Location ref_; |
| 585 | |
| 586 | // The location of the entrypoint if already loaded. |
| 587 | const Location entrypoint_; |
| 588 | |
| 589 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS); |
| 590 | }; |
| 591 | |
| 592 | // Slow path marking an object reference `ref` during a read barrier, |
| 593 | // and if needed, atomically updating the field `obj.field` in the |
| 594 | // object `obj` holding this reference after marking (contrary to |
| 595 | // ReadBarrierMarkSlowPathMIPS above, which never tries to update |
| 596 | // `obj.field`). |
| 597 | // |
| 598 | // This means that after the execution of this slow path, both `ref` |
| 599 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 600 | // hold the same to-space reference (unless another thread installed |
| 601 | // another object reference (different from `ref`) in `obj.field`). |
| 602 | class ReadBarrierMarkAndUpdateFieldSlowPathMIPS : public SlowPathCodeMIPS { |
| 603 | public: |
| 604 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(HInstruction* instruction, |
| 605 | Location ref, |
| 606 | Register obj, |
| 607 | Location field_offset, |
| 608 | Register temp1) |
| 609 | : SlowPathCodeMIPS(instruction), |
| 610 | ref_(ref), |
| 611 | obj_(obj), |
| 612 | field_offset_(field_offset), |
| 613 | temp1_(temp1) { |
| 614 | DCHECK(kEmitCompilerReadBarrier); |
| 615 | } |
| 616 | |
| 617 | const char* GetDescription() const OVERRIDE { |
| 618 | return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS"; |
| 619 | } |
| 620 | |
| 621 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 622 | LocationSummary* locations = instruction_->GetLocations(); |
| 623 | Register ref_reg = ref_.AsRegister<Register>(); |
| 624 | DCHECK(locations->CanCall()); |
| 625 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 626 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 627 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 628 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 629 | << instruction_->DebugName(); |
| 630 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 631 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 632 | DCHECK(field_offset_.IsRegisterPair()) << field_offset_; |
| 633 | |
| 634 | __ Bind(GetEntryLabel()); |
| 635 | |
| 636 | // Save the old reference. |
| 637 | // Note that we cannot use AT or TMP to save the old reference, as those |
| 638 | // are used by the code that follows, but we need the old reference after |
| 639 | // the call to the ReadBarrierMarkRegX entry point. |
| 640 | DCHECK_NE(temp1_, AT); |
| 641 | DCHECK_NE(temp1_, TMP); |
| 642 | __ Move(temp1_, ref_reg); |
| 643 | |
| 644 | // No need to save live registers; it's taken care of by the |
| 645 | // entrypoint. Also, there is no need to update the stack mask, |
| 646 | // as this runtime call will not trigger a garbage collection. |
| 647 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 648 | DCHECK((V0 <= ref_reg && ref_reg <= T7) || |
| 649 | (S2 <= ref_reg && ref_reg <= S7) || |
| 650 | (ref_reg == FP)) << ref_reg; |
| 651 | // "Compact" slow path, saving two moves. |
| 652 | // |
| 653 | // Instead of using the standard runtime calling convention (input |
| 654 | // and output in A0 and V0 respectively): |
| 655 | // |
| 656 | // A0 <- ref |
| 657 | // V0 <- ReadBarrierMark(A0) |
| 658 | // ref <- V0 |
| 659 | // |
| 660 | // we just use rX (the register containing `ref`) as input and output |
| 661 | // of a dedicated entrypoint: |
| 662 | // |
| 663 | // rX <- ReadBarrierMarkRegX(rX) |
| 664 | // |
| 665 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 666 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 667 | // This runtime call does not require a stack map. |
| 668 | mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 669 | instruction_, |
| 670 | this, |
| 671 | /* direct */ false); |
| 672 | |
| 673 | // If the new reference is different from the old reference, |
| 674 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 675 | // |
| 676 | // Note that this field could also hold a different object, if |
| 677 | // another thread had concurrently changed it. In that case, the |
| 678 | // the compare-and-set (CAS) loop below would abort, leaving the |
| 679 | // field as-is. |
| 680 | MipsLabel done; |
| 681 | __ Beq(temp1_, ref_reg, &done); |
| 682 | |
| 683 | // Update the the holder's field atomically. This may fail if |
| 684 | // mutator updates before us, but it's OK. This is achieved |
| 685 | // using a strong compare-and-set (CAS) operation with relaxed |
| 686 | // memory synchronization ordering, where the expected value is |
| 687 | // the old reference and the desired value is the new reference. |
| 688 | |
| 689 | // Convenience aliases. |
| 690 | Register base = obj_; |
| 691 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 692 | // offset ("long offset"), of which only the low part contains |
| 693 | // data. |
| 694 | Register offset = field_offset_.AsRegisterPairLow<Register>(); |
| 695 | Register expected = temp1_; |
| 696 | Register value = ref_reg; |
| 697 | Register tmp_ptr = TMP; // Pointer to actual memory. |
| 698 | Register tmp = AT; // Value in memory. |
| 699 | |
| 700 | __ Addu(tmp_ptr, base, offset); |
| 701 | |
| 702 | if (kPoisonHeapReferences) { |
| 703 | __ PoisonHeapReference(expected); |
| 704 | // Do not poison `value` if it is the same register as |
| 705 | // `expected`, which has just been poisoned. |
| 706 | if (value != expected) { |
| 707 | __ PoisonHeapReference(value); |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | // do { |
| 712 | // tmp = [r_ptr] - expected; |
| 713 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 714 | |
| 715 | bool is_r6 = mips_codegen->GetInstructionSetFeatures().IsR6(); |
| 716 | MipsLabel loop_head, exit_loop; |
| 717 | __ Bind(&loop_head); |
| 718 | if (is_r6) { |
| 719 | __ LlR6(tmp, tmp_ptr); |
| 720 | } else { |
| 721 | __ LlR2(tmp, tmp_ptr); |
| 722 | } |
| 723 | __ Bne(tmp, expected, &exit_loop); |
| 724 | __ Move(tmp, value); |
| 725 | if (is_r6) { |
| 726 | __ ScR6(tmp, tmp_ptr); |
| 727 | } else { |
| 728 | __ ScR2(tmp, tmp_ptr); |
| 729 | } |
| 730 | __ Beqz(tmp, &loop_head); |
| 731 | __ Bind(&exit_loop); |
| 732 | |
| 733 | if (kPoisonHeapReferences) { |
| 734 | __ UnpoisonHeapReference(expected); |
| 735 | // Do not unpoison `value` if it is the same register as |
| 736 | // `expected`, which has just been unpoisoned. |
| 737 | if (value != expected) { |
| 738 | __ UnpoisonHeapReference(value); |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | __ Bind(&done); |
| 743 | __ B(GetExitLabel()); |
| 744 | } |
| 745 | |
| 746 | private: |
| 747 | // The location (register) of the marked object reference. |
| 748 | const Location ref_; |
| 749 | // The register containing the object holding the marked object reference field. |
| 750 | const Register obj_; |
| 751 | // The location of the offset of the marked reference field within `obj_`. |
| 752 | Location field_offset_; |
| 753 | |
| 754 | const Register temp1_; |
| 755 | |
| 756 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS); |
| 757 | }; |
| 758 | |
| 759 | // Slow path generating a read barrier for a heap reference. |
| 760 | class ReadBarrierForHeapReferenceSlowPathMIPS : public SlowPathCodeMIPS { |
| 761 | public: |
| 762 | ReadBarrierForHeapReferenceSlowPathMIPS(HInstruction* instruction, |
| 763 | Location out, |
| 764 | Location ref, |
| 765 | Location obj, |
| 766 | uint32_t offset, |
| 767 | Location index) |
| 768 | : SlowPathCodeMIPS(instruction), |
| 769 | out_(out), |
| 770 | ref_(ref), |
| 771 | obj_(obj), |
| 772 | offset_(offset), |
| 773 | index_(index) { |
| 774 | DCHECK(kEmitCompilerReadBarrier); |
| 775 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 776 | // has been overwritten by (or after) the heap object reference load |
| 777 | // to be instrumented, e.g.: |
| 778 | // |
| 779 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 780 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 781 | // |
| 782 | // In that case, we have lost the information about the original |
| 783 | // object, and the emitted read barrier cannot work properly. |
| 784 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 785 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 786 | } |
| 787 | |
| 788 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 789 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 790 | LocationSummary* locations = instruction_->GetLocations(); |
| 791 | Register reg_out = out_.AsRegister<Register>(); |
| 792 | DCHECK(locations->CanCall()); |
| 793 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 794 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 795 | instruction_->IsStaticFieldGet() || |
| 796 | instruction_->IsArrayGet() || |
| 797 | instruction_->IsInstanceOf() || |
| 798 | instruction_->IsCheckCast() || |
| 799 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 800 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 801 | << instruction_->DebugName(); |
| 802 | |
| 803 | __ Bind(GetEntryLabel()); |
| 804 | SaveLiveRegisters(codegen, locations); |
| 805 | |
| 806 | // We may have to change the index's value, but as `index_` is a |
| 807 | // constant member (like other "inputs" of this slow path), |
| 808 | // introduce a copy of it, `index`. |
| 809 | Location index = index_; |
| 810 | if (index_.IsValid()) { |
| 811 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 812 | if (instruction_->IsArrayGet()) { |
| 813 | // Compute the actual memory offset and store it in `index`. |
| 814 | Register index_reg = index_.AsRegister<Register>(); |
| 815 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 816 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 817 | // We are about to change the value of `index_reg` (see the |
| 818 | // calls to art::mips::MipsAssembler::Sll and |
| 819 | // art::mips::MipsAssembler::Addiu32 below), but it has |
| 820 | // not been saved by the previous call to |
| 821 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 822 | // callee-save register -- |
| 823 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 824 | // callee-save registers, as it has been designed with the |
| 825 | // assumption that callee-save registers are supposed to be |
| 826 | // handled by the called function. So, as a callee-save |
| 827 | // register, `index_reg` _would_ eventually be saved onto |
| 828 | // the stack, but it would be too late: we would have |
| 829 | // changed its value earlier. Therefore, we manually save |
| 830 | // it here into another freely available register, |
| 831 | // `free_reg`, chosen of course among the caller-save |
| 832 | // registers (as a callee-save `free_reg` register would |
| 833 | // exhibit the same problem). |
| 834 | // |
| 835 | // Note we could have requested a temporary register from |
| 836 | // the register allocator instead; but we prefer not to, as |
| 837 | // this is a slow path, and we know we can find a |
| 838 | // caller-save register that is available. |
| 839 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 840 | __ Move(free_reg, index_reg); |
| 841 | index_reg = free_reg; |
| 842 | index = Location::RegisterLocation(index_reg); |
| 843 | } else { |
| 844 | // The initial register stored in `index_` has already been |
| 845 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 846 | // (as it is not a callee-save register), so we can freely |
| 847 | // use it. |
| 848 | } |
| 849 | // Shifting the index value contained in `index_reg` by the scale |
| 850 | // factor (2) cannot overflow in practice, as the runtime is |
| 851 | // unable to allocate object arrays with a size larger than |
| 852 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 853 | __ Sll(index_reg, index_reg, TIMES_4); |
| 854 | static_assert( |
| 855 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 856 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 857 | __ Addiu32(index_reg, index_reg, offset_); |
| 858 | } else { |
| 859 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 860 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 861 | // (as in the case of ArrayGet), as it is actually an offset |
| 862 | // to an object field within an object. |
| 863 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 864 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 865 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 866 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 867 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 868 | DCHECK_EQ(offset_, 0U); |
| 869 | DCHECK(index_.IsRegisterPair()); |
| 870 | // UnsafeGet's offset location is a register pair, the low |
| 871 | // part contains the correct offset. |
| 872 | index = index_.ToLow(); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | // We're moving two or three locations to locations that could |
| 877 | // overlap, so we need a parallel move resolver. |
| 878 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 879 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 880 | parallel_move.AddMove(ref_, |
| 881 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 882 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 883 | nullptr); |
| 884 | parallel_move.AddMove(obj_, |
| 885 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 886 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 887 | nullptr); |
| 888 | if (index.IsValid()) { |
| 889 | parallel_move.AddMove(index, |
| 890 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 891 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 892 | nullptr); |
| 893 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 894 | } else { |
| 895 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 896 | __ LoadConst32(calling_convention.GetRegisterAt(2), offset_); |
| 897 | } |
| 898 | mips_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| 899 | instruction_, |
| 900 | instruction_->GetDexPc(), |
| 901 | this); |
| 902 | CheckEntrypointTypes< |
| 903 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 904 | mips_codegen->MoveLocation(out_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 905 | calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 906 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 907 | |
| 908 | RestoreLiveRegisters(codegen, locations); |
| 909 | __ B(GetExitLabel()); |
| 910 | } |
| 911 | |
| 912 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathMIPS"; } |
| 913 | |
| 914 | private: |
| 915 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 916 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 917 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 918 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 919 | if (i != ref && |
| 920 | i != obj && |
| 921 | !codegen->IsCoreCalleeSaveRegister(i) && |
| 922 | !codegen->IsBlockedCoreRegister(i)) { |
| 923 | return static_cast<Register>(i); |
| 924 | } |
| 925 | } |
| 926 | // We shall never fail to find a free caller-save register, as |
| 927 | // there are more than two core caller-save registers on MIPS |
| 928 | // (meaning it is possible to find one which is different from |
| 929 | // `ref` and `obj`). |
| 930 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 931 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 932 | UNREACHABLE(); |
| 933 | } |
| 934 | |
| 935 | const Location out_; |
| 936 | const Location ref_; |
| 937 | const Location obj_; |
| 938 | const uint32_t offset_; |
| 939 | // An additional location containing an index to an array. |
| 940 | // Only used for HArrayGet and the UnsafeGetObject & |
| 941 | // UnsafeGetObjectVolatile intrinsics. |
| 942 | const Location index_; |
| 943 | |
| 944 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS); |
| 945 | }; |
| 946 | |
| 947 | // Slow path generating a read barrier for a GC root. |
| 948 | class ReadBarrierForRootSlowPathMIPS : public SlowPathCodeMIPS { |
| 949 | public: |
| 950 | ReadBarrierForRootSlowPathMIPS(HInstruction* instruction, Location out, Location root) |
| 951 | : SlowPathCodeMIPS(instruction), out_(out), root_(root) { |
| 952 | DCHECK(kEmitCompilerReadBarrier); |
| 953 | } |
| 954 | |
| 955 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 956 | LocationSummary* locations = instruction_->GetLocations(); |
| 957 | Register reg_out = out_.AsRegister<Register>(); |
| 958 | DCHECK(locations->CanCall()); |
| 959 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 960 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 961 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 962 | << instruction_->DebugName(); |
| 963 | |
| 964 | __ Bind(GetEntryLabel()); |
| 965 | SaveLiveRegisters(codegen, locations); |
| 966 | |
| 967 | InvokeRuntimeCallingConvention calling_convention; |
| 968 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 969 | mips_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 970 | root_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 971 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 972 | mips_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 973 | instruction_, |
| 974 | instruction_->GetDexPc(), |
| 975 | this); |
| 976 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 977 | mips_codegen->MoveLocation(out_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 978 | calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 979 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 980 | |
| 981 | RestoreLiveRegisters(codegen, locations); |
| 982 | __ B(GetExitLabel()); |
| 983 | } |
| 984 | |
| 985 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS"; } |
| 986 | |
| 987 | private: |
| 988 | const Location out_; |
| 989 | const Location root_; |
| 990 | |
| 991 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS); |
| 992 | }; |
| 993 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 994 | CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph, |
| 995 | const MipsInstructionSetFeatures& isa_features, |
| 996 | const CompilerOptions& compiler_options, |
| 997 | OptimizingCompilerStats* stats) |
| 998 | : CodeGenerator(graph, |
| 999 | kNumberOfCoreRegisters, |
| 1000 | kNumberOfFRegisters, |
| 1001 | kNumberOfRegisterPairs, |
| 1002 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1003 | arraysize(kCoreCalleeSaves)), |
| 1004 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1005 | arraysize(kFpuCalleeSaves)), |
| 1006 | compiler_options, |
| 1007 | stats), |
| 1008 | block_labels_(nullptr), |
| 1009 | location_builder_(graph, this), |
| 1010 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1011 | move_resolver_(graph->GetAllocator(), this), |
| 1012 | assembler_(graph->GetAllocator(), &isa_features), |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1013 | isa_features_(isa_features), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1014 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1015 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1016 | pc_relative_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1017 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1018 | pc_relative_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1019 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1020 | pc_relative_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1021 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1022 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1023 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1024 | clobbered_ra_(false) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1025 | // Save RA (containing the return address) to mimic Quick. |
| 1026 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 1027 | } |
| 1028 | |
| 1029 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 1030 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1031 | #define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1032 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1033 | |
| 1034 | void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) { |
| 1035 | // Ensure that we fix up branches. |
| 1036 | __ FinalizeCode(); |
| 1037 | |
| 1038 | // Adjust native pc offsets in stack maps. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1039 | StackMapStream* stack_map_stream = GetStackMapStream(); |
| 1040 | for (size_t i = 0, num = stack_map_stream->GetNumberOfStackMaps(); i != num; ++i) { |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1041 | uint32_t old_position = |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1042 | stack_map_stream->GetStackMap(i).native_pc_code_offset.Uint32Value(InstructionSet::kMips); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1043 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1044 | DCHECK_GE(new_position, old_position); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1045 | stack_map_stream->SetStackMapNativePcOffset(i, new_position); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | // Adjust pc offsets for the disassembly information. |
| 1049 | if (disasm_info_ != nullptr) { |
| 1050 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1051 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1052 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1053 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1054 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1055 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1056 | } |
| 1057 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1058 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1059 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | CodeGenerator::Finalize(allocator); |
| 1064 | } |
| 1065 | |
| 1066 | MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const { |
| 1067 | return codegen_->GetAssembler(); |
| 1068 | } |
| 1069 | |
| 1070 | void ParallelMoveResolverMIPS::EmitMove(size_t index) { |
| 1071 | DCHECK_LT(index, moves_.size()); |
| 1072 | MoveOperands* move = moves_[index]; |
| 1073 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1074 | } |
| 1075 | |
| 1076 | void ParallelMoveResolverMIPS::EmitSwap(size_t index) { |
| 1077 | DCHECK_LT(index, moves_.size()); |
| 1078 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1079 | DataType::Type type = move->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1080 | Location loc1 = move->GetDestination(); |
| 1081 | Location loc2 = move->GetSource(); |
| 1082 | |
| 1083 | DCHECK(!loc1.IsConstant()); |
| 1084 | DCHECK(!loc2.IsConstant()); |
| 1085 | |
| 1086 | if (loc1.Equals(loc2)) { |
| 1087 | return; |
| 1088 | } |
| 1089 | |
| 1090 | if (loc1.IsRegister() && loc2.IsRegister()) { |
| 1091 | // Swap 2 GPRs. |
| 1092 | Register r1 = loc1.AsRegister<Register>(); |
| 1093 | Register r2 = loc2.AsRegister<Register>(); |
| 1094 | __ Move(TMP, r2); |
| 1095 | __ Move(r2, r1); |
| 1096 | __ Move(r1, TMP); |
| 1097 | } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) { |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1098 | if (codegen_->GetGraph()->HasSIMD()) { |
| 1099 | __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(loc1)); |
| 1100 | __ MoveV(VectorRegisterFrom(loc1), VectorRegisterFrom(loc2)); |
| 1101 | __ MoveV(VectorRegisterFrom(loc2), static_cast<VectorRegister>(FTMP)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1102 | } else { |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1103 | FRegister f1 = loc1.AsFpuRegister<FRegister>(); |
| 1104 | FRegister f2 = loc2.AsFpuRegister<FRegister>(); |
| 1105 | if (type == DataType::Type::kFloat32) { |
| 1106 | __ MovS(FTMP, f2); |
| 1107 | __ MovS(f2, f1); |
| 1108 | __ MovS(f1, FTMP); |
| 1109 | } else { |
| 1110 | DCHECK_EQ(type, DataType::Type::kFloat64); |
| 1111 | __ MovD(FTMP, f2); |
| 1112 | __ MovD(f2, f1); |
| 1113 | __ MovD(f1, FTMP); |
| 1114 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1115 | } |
| 1116 | } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) || |
| 1117 | (loc1.IsFpuRegister() && loc2.IsRegister())) { |
| 1118 | // Swap FPR and GPR. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1119 | DCHECK_EQ(type, DataType::Type::kFloat32); // Can only swap a float. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1120 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1121 | : loc2.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1122 | Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1123 | __ Move(TMP, r2); |
| 1124 | __ Mfc1(r2, f1); |
| 1125 | __ Mtc1(TMP, f1); |
| 1126 | } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) { |
| 1127 | // Swap 2 GPR register pairs. |
| 1128 | Register r1 = loc1.AsRegisterPairLow<Register>(); |
| 1129 | Register r2 = loc2.AsRegisterPairLow<Register>(); |
| 1130 | __ Move(TMP, r2); |
| 1131 | __ Move(r2, r1); |
| 1132 | __ Move(r1, TMP); |
| 1133 | r1 = loc1.AsRegisterPairHigh<Register>(); |
| 1134 | r2 = loc2.AsRegisterPairHigh<Register>(); |
| 1135 | __ Move(TMP, r2); |
| 1136 | __ Move(r2, r1); |
| 1137 | __ Move(r1, TMP); |
| 1138 | } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) || |
| 1139 | (loc1.IsFpuRegister() && loc2.IsRegisterPair())) { |
| 1140 | // Swap FPR and GPR register pair. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1141 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1142 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1143 | : loc2.AsFpuRegister<FRegister>(); |
| 1144 | Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 1145 | : loc2.AsRegisterPairLow<Register>(); |
| 1146 | Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 1147 | : loc2.AsRegisterPairHigh<Register>(); |
| 1148 | // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and |
| 1149 | // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR |
| 1150 | // unpredictable and the following mfch1 will fail. |
| 1151 | __ Mfc1(TMP, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1152 | __ MoveFromFpuHigh(AT, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1153 | __ Mtc1(r2_l, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1154 | __ MoveToFpuHigh(r2_h, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1155 | __ Move(r2_l, TMP); |
| 1156 | __ Move(r2_h, AT); |
| 1157 | } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) { |
| 1158 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false); |
| 1159 | } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) { |
| 1160 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1161 | } else if (loc1.IsSIMDStackSlot() && loc2.IsSIMDStackSlot()) { |
| 1162 | ExchangeQuadSlots(loc1.GetStackIndex(), loc2.GetStackIndex()); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1163 | } else if ((loc1.IsRegister() && loc2.IsStackSlot()) || |
| 1164 | (loc1.IsStackSlot() && loc2.IsRegister())) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1165 | Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
| 1166 | intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1167 | __ Move(TMP, reg); |
| 1168 | __ LoadFromOffset(kLoadWord, reg, SP, offset); |
| 1169 | __ StoreToOffset(kStoreWord, TMP, SP, offset); |
| 1170 | } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) || |
| 1171 | (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) { |
| 1172 | Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 1173 | : loc2.AsRegisterPairLow<Register>(); |
| 1174 | Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 1175 | : loc2.AsRegisterPairHigh<Register>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1176 | intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1177 | intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize) |
| 1178 | : loc2.GetHighStackIndex(kMipsWordSize); |
| 1179 | __ Move(TMP, reg_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1180 | __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1181 | __ StoreToOffset(kStoreWord, TMP, SP, offset_l); |
David Brazdil | 04d3e87 | 2016-01-29 09:50:09 +0000 | [diff] [blame] | 1182 | __ Move(TMP, reg_h); |
| 1183 | __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h); |
| 1184 | __ StoreToOffset(kStoreWord, TMP, SP, offset_h); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1185 | } else if ((loc1.IsFpuRegister() && loc2.IsSIMDStackSlot()) || |
| 1186 | (loc1.IsSIMDStackSlot() && loc2.IsFpuRegister())) { |
| 1187 | Location fp_loc = loc1.IsFpuRegister() ? loc1 : loc2; |
| 1188 | intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex(); |
| 1189 | __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(fp_loc)); |
| 1190 | __ LoadQFromOffset(fp_loc.AsFpuRegister<FRegister>(), SP, offset); |
| 1191 | __ StoreQToOffset(FTMP, SP, offset); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1192 | } else if (loc1.IsFpuRegister() || loc2.IsFpuRegister()) { |
| 1193 | FRegister reg = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1194 | : loc2.AsFpuRegister<FRegister>(); |
| 1195 | intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1196 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1197 | __ MovS(FTMP, reg); |
| 1198 | __ LoadSFromOffset(reg, SP, offset); |
| 1199 | __ StoreSToOffset(FTMP, SP, offset); |
| 1200 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1201 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1202 | __ MovD(FTMP, reg); |
| 1203 | __ LoadDFromOffset(reg, SP, offset); |
| 1204 | __ StoreDToOffset(FTMP, SP, offset); |
| 1205 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1206 | } else { |
| 1207 | LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported"; |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | void ParallelMoveResolverMIPS::RestoreScratch(int reg) { |
| 1212 | __ Pop(static_cast<Register>(reg)); |
| 1213 | } |
| 1214 | |
| 1215 | void ParallelMoveResolverMIPS::SpillScratch(int reg) { |
| 1216 | __ Push(static_cast<Register>(reg)); |
| 1217 | } |
| 1218 | |
| 1219 | void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) { |
| 1220 | // Allocate a scratch register other than TMP, if available. |
| 1221 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 1222 | // automatically unspilled when the scratch scope object is destroyed). |
| 1223 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 1224 | // 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] | 1225 | int stack_offset = ensure_scratch.IsSpilled() ? kStackAlignment : 0; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1226 | for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) { |
| 1227 | __ LoadFromOffset(kLoadWord, |
| 1228 | Register(ensure_scratch.GetRegister()), |
| 1229 | SP, |
| 1230 | index1 + stack_offset); |
| 1231 | __ LoadFromOffset(kLoadWord, |
| 1232 | TMP, |
| 1233 | SP, |
| 1234 | index2 + stack_offset); |
| 1235 | __ StoreToOffset(kStoreWord, |
| 1236 | Register(ensure_scratch.GetRegister()), |
| 1237 | SP, |
| 1238 | index2 + stack_offset); |
| 1239 | __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset); |
| 1240 | } |
| 1241 | } |
| 1242 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1243 | void ParallelMoveResolverMIPS::ExchangeQuadSlots(int index1, int index2) { |
| 1244 | __ LoadQFromOffset(FTMP, SP, index1); |
| 1245 | __ LoadQFromOffset(FTMP2, SP, index2); |
| 1246 | __ StoreQToOffset(FTMP, SP, index2); |
| 1247 | __ StoreQToOffset(FTMP2, SP, index1); |
| 1248 | } |
| 1249 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1250 | void CodeGeneratorMIPS::ComputeSpillMask() { |
| 1251 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1252 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1253 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 1254 | // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved |
| 1255 | // registers, include the ZERO register to force alignment of FPU callee-saved registers |
| 1256 | // within the stack frame. |
| 1257 | if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) { |
| 1258 | core_spill_mask_ |= (1 << ZERO); |
| 1259 | } |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1263 | // 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] | 1264 | // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration() |
| 1265 | // into the path that creates a stack frame so that RA can be explicitly saved and restored. |
| 1266 | // 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] | 1267 | return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_; |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1270 | static dwarf::Reg DWARFReg(Register reg) { |
| 1271 | return dwarf::Reg::MipsCore(static_cast<int>(reg)); |
| 1272 | } |
| 1273 | |
| 1274 | // TODO: mapping of floating-point registers to DWARF. |
| 1275 | |
| 1276 | void CodeGeneratorMIPS::GenerateFrameEntry() { |
| 1277 | __ Bind(&frame_entry_label_); |
| 1278 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1279 | bool do_overflow_check = |
| 1280 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips) || !IsLeafMethod(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1281 | |
| 1282 | if (do_overflow_check) { |
| 1283 | __ LoadFromOffset(kLoadWord, |
| 1284 | ZERO, |
| 1285 | SP, |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1286 | -static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kMips))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1287 | RecordPcInfo(nullptr, 0); |
| 1288 | } |
| 1289 | |
| 1290 | if (HasEmptyFrame()) { |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1291 | CHECK_EQ(fpu_spill_mask_, 0u); |
| 1292 | CHECK_EQ(core_spill_mask_, 1u << RA); |
| 1293 | CHECK(!clobbered_ra_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1294 | return; |
| 1295 | } |
| 1296 | |
| 1297 | // Make sure the frame size isn't unreasonably large. |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1298 | if (GetFrameSize() > GetStackOverflowReservedBytes(InstructionSet::kMips)) { |
| 1299 | LOG(FATAL) << "Stack frame larger than " |
| 1300 | << GetStackOverflowReservedBytes(InstructionSet::kMips) << " bytes"; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | // Spill callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1304 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1305 | uint32_t ofs = GetFrameSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1306 | __ IncreaseFrameSize(ofs); |
| 1307 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1308 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 1309 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 1310 | mask ^= 1u << reg; |
| 1311 | ofs -= kMipsWordSize; |
| 1312 | // The ZERO register is only included for alignment. |
| 1313 | if (reg != ZERO) { |
| 1314 | __ StoreToOffset(kStoreWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1315 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 1316 | } |
| 1317 | } |
| 1318 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1319 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 1320 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 1321 | mask ^= 1u << reg; |
| 1322 | ofs -= kMipsDoublewordSize; |
| 1323 | __ StoreDToOffset(reg, SP, ofs); |
| 1324 | // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1325 | } |
| 1326 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1327 | // Save the current method if we need it. Note that we do not |
| 1328 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1329 | // in the SSA graph. |
| 1330 | if (RequiresCurrentMethod()) { |
| 1331 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
| 1332 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 1333 | |
| 1334 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1335 | // Initialize should deoptimize flag to 0. |
| 1336 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1337 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | void CodeGeneratorMIPS::GenerateFrameExit() { |
| 1341 | __ cfi().RememberState(); |
| 1342 | |
| 1343 | if (!HasEmptyFrame()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1344 | // Restore callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1345 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1346 | // For better instruction scheduling restore RA before other registers. |
| 1347 | uint32_t ofs = GetFrameSize(); |
| 1348 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 1349 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 1350 | mask ^= 1u << reg; |
| 1351 | ofs -= kMipsWordSize; |
| 1352 | // The ZERO register is only included for alignment. |
| 1353 | if (reg != ZERO) { |
| 1354 | __ LoadFromOffset(kLoadWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1355 | __ cfi().Restore(DWARFReg(reg)); |
| 1356 | } |
| 1357 | } |
| 1358 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1359 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 1360 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 1361 | mask ^= 1u << reg; |
| 1362 | ofs -= kMipsDoublewordSize; |
| 1363 | __ LoadDFromOffset(reg, SP, ofs); |
| 1364 | // TODO: __ cfi().Restore(DWARFReg(reg)); |
| 1365 | } |
| 1366 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1367 | size_t frame_size = GetFrameSize(); |
| 1368 | // Adjust the stack pointer in the delay slot if doing so doesn't break CFI. |
| 1369 | bool exchange = IsInt<16>(static_cast<int32_t>(frame_size)); |
| 1370 | bool reordering = __ SetReorder(false); |
| 1371 | if (exchange) { |
| 1372 | __ Jr(RA); |
| 1373 | __ DecreaseFrameSize(frame_size); // Single instruction in delay slot. |
| 1374 | } else { |
| 1375 | __ DecreaseFrameSize(frame_size); |
| 1376 | __ Jr(RA); |
| 1377 | __ Nop(); // In delay slot. |
| 1378 | } |
| 1379 | __ SetReorder(reordering); |
| 1380 | } else { |
| 1381 | __ Jr(RA); |
| 1382 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1383 | } |
| 1384 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1385 | __ cfi().RestoreState(); |
| 1386 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 1387 | } |
| 1388 | |
| 1389 | void CodeGeneratorMIPS::Bind(HBasicBlock* block) { |
| 1390 | __ Bind(GetLabelOf(block)); |
| 1391 | } |
| 1392 | |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1393 | VectorRegister VectorRegisterFrom(Location location) { |
| 1394 | DCHECK(location.IsFpuRegister()); |
| 1395 | return static_cast<VectorRegister>(location.AsFpuRegister<FRegister>()); |
| 1396 | } |
| 1397 | |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1398 | void CodeGeneratorMIPS::MoveLocation(Location destination, |
| 1399 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1400 | DataType::Type dst_type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1401 | if (source.Equals(destination)) { |
| 1402 | return; |
| 1403 | } |
| 1404 | |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1405 | if (source.IsConstant()) { |
| 1406 | MoveConstant(destination, source.GetConstant()); |
| 1407 | } else { |
| 1408 | if (destination.IsRegister()) { |
| 1409 | if (source.IsRegister()) { |
| 1410 | __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 1411 | } else if (source.IsFpuRegister()) { |
| 1412 | __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>()); |
| 1413 | } else { |
| 1414 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1415 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1416 | } |
| 1417 | } else if (destination.IsRegisterPair()) { |
| 1418 | if (source.IsRegisterPair()) { |
| 1419 | __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 1420 | __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 1421 | } else if (source.IsFpuRegister()) { |
| 1422 | Register dst_high = destination.AsRegisterPairHigh<Register>(); |
| 1423 | Register dst_low = destination.AsRegisterPairLow<Register>(); |
| 1424 | FRegister src = source.AsFpuRegister<FRegister>(); |
| 1425 | __ Mfc1(dst_low, src); |
| 1426 | __ MoveFromFpuHigh(dst_high, src); |
| 1427 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1428 | DCHECK(source.IsDoubleStackSlot()) |
| 1429 | << "Cannot move from " << source << " to " << destination; |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1430 | int32_t off = source.GetStackIndex(); |
| 1431 | Register r = destination.AsRegisterPairLow<Register>(); |
| 1432 | __ LoadFromOffset(kLoadDoubleword, r, SP, off); |
| 1433 | } |
| 1434 | } else if (destination.IsFpuRegister()) { |
| 1435 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1436 | DCHECK(!DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1437 | __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>()); |
| 1438 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1439 | DCHECK(DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1440 | FRegister dst = destination.AsFpuRegister<FRegister>(); |
| 1441 | Register src_high = source.AsRegisterPairHigh<Register>(); |
| 1442 | Register src_low = source.AsRegisterPairLow<Register>(); |
| 1443 | __ Mtc1(src_low, dst); |
| 1444 | __ MoveToFpuHigh(src_high, dst); |
| 1445 | } else if (source.IsFpuRegister()) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1446 | if (GetGraph()->HasSIMD()) { |
| 1447 | __ MoveV(VectorRegisterFrom(destination), |
| 1448 | VectorRegisterFrom(source)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1449 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1450 | if (DataType::Is64BitType(dst_type)) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1451 | __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 1452 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1453 | DCHECK_EQ(dst_type, DataType::Type::kFloat32); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1454 | __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 1455 | } |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1456 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1457 | } else if (source.IsSIMDStackSlot()) { |
| 1458 | __ LoadQFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1459 | } else if (source.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1460 | DCHECK(DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1461 | __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 1462 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1463 | DCHECK(!DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1464 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1465 | __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 1466 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1467 | } else if (destination.IsSIMDStackSlot()) { |
| 1468 | if (source.IsFpuRegister()) { |
| 1469 | __ StoreQToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex()); |
| 1470 | } else { |
| 1471 | DCHECK(source.IsSIMDStackSlot()); |
| 1472 | __ LoadQFromOffset(FTMP, SP, source.GetStackIndex()); |
| 1473 | __ StoreQToOffset(FTMP, SP, destination.GetStackIndex()); |
| 1474 | } |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1475 | } else if (destination.IsDoubleStackSlot()) { |
| 1476 | int32_t dst_offset = destination.GetStackIndex(); |
| 1477 | if (source.IsRegisterPair()) { |
| 1478 | __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, dst_offset); |
| 1479 | } else if (source.IsFpuRegister()) { |
| 1480 | __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset); |
| 1481 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1482 | DCHECK(source.IsDoubleStackSlot()) |
| 1483 | << "Cannot move from " << source << " to " << destination; |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1484 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1485 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset); |
| 1486 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4); |
| 1487 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset + 4); |
| 1488 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1489 | } else { |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1490 | DCHECK(destination.IsStackSlot()) << destination; |
| 1491 | int32_t dst_offset = destination.GetStackIndex(); |
| 1492 | if (source.IsRegister()) { |
| 1493 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, dst_offset); |
| 1494 | } else if (source.IsFpuRegister()) { |
| 1495 | __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset); |
| 1496 | } else { |
| 1497 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1498 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1499 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset); |
| 1500 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1501 | } |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) { |
| 1506 | if (c->IsIntConstant() || c->IsNullConstant()) { |
| 1507 | // Move 32 bit constant. |
| 1508 | int32_t value = GetInt32ValueOf(c); |
| 1509 | if (destination.IsRegister()) { |
| 1510 | Register dst = destination.AsRegister<Register>(); |
| 1511 | __ LoadConst32(dst, value); |
| 1512 | } else { |
| 1513 | DCHECK(destination.IsStackSlot()) |
| 1514 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1515 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1516 | } |
| 1517 | } else if (c->IsLongConstant()) { |
| 1518 | // Move 64 bit constant. |
| 1519 | int64_t value = GetInt64ValueOf(c); |
| 1520 | if (destination.IsRegisterPair()) { |
| 1521 | Register r_h = destination.AsRegisterPairHigh<Register>(); |
| 1522 | Register r_l = destination.AsRegisterPairLow<Register>(); |
| 1523 | __ LoadConst64(r_h, r_l, value); |
| 1524 | } else { |
| 1525 | DCHECK(destination.IsDoubleStackSlot()) |
| 1526 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1527 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1528 | } |
| 1529 | } else if (c->IsFloatConstant()) { |
| 1530 | // Move 32 bit float constant. |
| 1531 | int32_t value = GetInt32ValueOf(c); |
| 1532 | if (destination.IsFpuRegister()) { |
| 1533 | __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP); |
| 1534 | } else { |
| 1535 | DCHECK(destination.IsStackSlot()) |
| 1536 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1537 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1538 | } |
| 1539 | } else { |
| 1540 | // Move 64 bit double constant. |
| 1541 | DCHECK(c->IsDoubleConstant()) << c->DebugName(); |
| 1542 | int64_t value = GetInt64ValueOf(c); |
| 1543 | if (destination.IsFpuRegister()) { |
| 1544 | FRegister fd = destination.AsFpuRegister<FRegister>(); |
| 1545 | __ LoadDConst64(fd, value, TMP); |
| 1546 | } else { |
| 1547 | DCHECK(destination.IsDoubleStackSlot()) |
| 1548 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1549 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1550 | } |
| 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) { |
| 1555 | DCHECK(destination.IsRegister()); |
| 1556 | Register dst = destination.AsRegister<Register>(); |
| 1557 | __ LoadConst32(dst, value); |
| 1558 | } |
| 1559 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1560 | void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1561 | if (location.IsRegister()) { |
| 1562 | locations->AddTemp(location); |
Alexey Frunze | c9e94f3 | 2015-10-26 16:11:39 -0700 | [diff] [blame] | 1563 | } else if (location.IsRegisterPair()) { |
| 1564 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1565 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1566 | } else { |
| 1567 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1568 | } |
| 1569 | } |
| 1570 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1571 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1572 | inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches( |
| 1573 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1574 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1575 | for (const PcRelativePatchInfo& info : infos) { |
| 1576 | const DexFile& dex_file = info.target_dex_file; |
| 1577 | size_t offset_or_index = info.offset_or_index; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1578 | DCHECK(info.label.IsBound()); |
| 1579 | uint32_t literal_offset = __ GetLabelLocation(&info.label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1580 | // On R2 we use HMipsComputeBaseMethodAddress and patch relative to |
| 1581 | // the assembler's base label used for PC-relative addressing. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1582 | const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info; |
| 1583 | uint32_t pc_rel_offset = info_high.pc_rel_label.IsBound() |
| 1584 | ? __ GetLabelLocation(&info_high.pc_rel_label) |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1585 | : __ GetPcRelBaseLabelLocation(); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1586 | 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] | 1587 | } |
| 1588 | } |
| 1589 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1590 | void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1591 | DCHECK(linker_patches->empty()); |
| 1592 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1593 | pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1594 | method_bss_entry_patches_.size() + |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1595 | pc_relative_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1596 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1597 | pc_relative_string_patches_.size() + |
| 1598 | string_bss_entry_patches_.size(); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1599 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1600 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1601 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 1602 | pc_relative_method_patches_, linker_patches); |
| 1603 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 1604 | pc_relative_type_patches_, linker_patches); |
| 1605 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 1606 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1607 | } else { |
| 1608 | DCHECK(pc_relative_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1609 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 1610 | pc_relative_type_patches_, linker_patches); |
| 1611 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 1612 | pc_relative_string_patches_, linker_patches); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1613 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1614 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1615 | method_bss_entry_patches_, linker_patches); |
| 1616 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1617 | type_bss_entry_patches_, linker_patches); |
| 1618 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1619 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1620 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1621 | } |
| 1622 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1623 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeMethodPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1624 | MethodReference target_method, |
| 1625 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1626 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1627 | target_method.index, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1628 | info_high, |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1629 | &pc_relative_method_patches_); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1630 | } |
| 1631 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1632 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewMethodBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1633 | MethodReference target_method, |
| 1634 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1635 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1636 | target_method.index, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1637 | info_high, |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1638 | &method_bss_entry_patches_); |
| 1639 | } |
| 1640 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1641 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1642 | const DexFile& dex_file, |
| 1643 | dex::TypeIndex type_index, |
| 1644 | const PcRelativePatchInfo* info_high) { |
| 1645 | return NewPcRelativePatch(dex_file, type_index.index_, info_high, &pc_relative_type_patches_); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1646 | } |
| 1647 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1648 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewTypeBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1649 | const DexFile& dex_file, |
| 1650 | dex::TypeIndex type_index, |
| 1651 | const PcRelativePatchInfo* info_high) { |
| 1652 | 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] | 1653 | } |
| 1654 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1655 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1656 | const DexFile& dex_file, |
| 1657 | dex::StringIndex string_index, |
| 1658 | const PcRelativePatchInfo* info_high) { |
| 1659 | return NewPcRelativePatch(dex_file, string_index.index_, info_high, &pc_relative_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1660 | } |
| 1661 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1662 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewStringBssEntryPatch( |
| 1663 | const DexFile& dex_file, |
| 1664 | dex::StringIndex string_index, |
| 1665 | const PcRelativePatchInfo* info_high) { |
| 1666 | return NewPcRelativePatch(dex_file, string_index.index_, info_high, &string_bss_entry_patches_); |
| 1667 | } |
| 1668 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1669 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1670 | const DexFile& dex_file, |
| 1671 | uint32_t offset_or_index, |
| 1672 | const PcRelativePatchInfo* info_high, |
| 1673 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1674 | patches->emplace_back(dex_file, offset_or_index, info_high); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1675 | return &patches->back(); |
| 1676 | } |
| 1677 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1678 | Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1679 | return map->GetOrCreate( |
| 1680 | value, |
| 1681 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1682 | } |
| 1683 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1684 | Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1685 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1686 | } |
| 1687 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1688 | void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high, |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1689 | Register out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1690 | Register base) { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1691 | DCHECK(!info_high->patch_info_high); |
Alexey Frunze | 6079dca | 2017-05-28 19:10:28 -0700 | [diff] [blame] | 1692 | DCHECK_NE(out, base); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1693 | bool reordering = __ SetReorder(false); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1694 | if (GetInstructionSetFeatures().IsR6()) { |
| 1695 | DCHECK_EQ(base, ZERO); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1696 | __ Bind(&info_high->label); |
| 1697 | __ Bind(&info_high->pc_rel_label); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1698 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1699 | __ Auipc(out, /* placeholder */ 0x1234); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1700 | __ SetReorder(reordering); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1701 | } else { |
| 1702 | // If base is ZERO, emit NAL to obtain the actual base. |
| 1703 | if (base == ZERO) { |
| 1704 | // Generate a dummy PC-relative call to obtain PC. |
| 1705 | __ Nal(); |
| 1706 | } |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1707 | __ Bind(&info_high->label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1708 | __ Lui(out, /* placeholder */ 0x1234); |
| 1709 | // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding |
| 1710 | // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler. |
| 1711 | if (base == ZERO) { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1712 | __ Bind(&info_high->pc_rel_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1713 | } |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1714 | __ SetReorder(reordering); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1715 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1716 | __ Addu(out, out, (base == ZERO) ? RA : base); |
| 1717 | } |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1718 | // 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] | 1719 | // offset to `out` (e.g. lw, jialc, addiu). |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1722 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootStringPatch( |
| 1723 | const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1724 | dex::StringIndex string_index, |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1725 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1726 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| 1727 | jit_string_patches_.emplace_back(dex_file, string_index.index_); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1728 | return &jit_string_patches_.back(); |
| 1729 | } |
| 1730 | |
| 1731 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootClassPatch( |
| 1732 | const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1733 | dex::TypeIndex type_index, |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1734 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1735 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| 1736 | jit_class_patches_.emplace_back(dex_file, type_index.index_); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1737 | return &jit_class_patches_.back(); |
| 1738 | } |
| 1739 | |
| 1740 | void CodeGeneratorMIPS::PatchJitRootUse(uint8_t* code, |
| 1741 | const uint8_t* roots_data, |
| 1742 | const CodeGeneratorMIPS::JitPatchInfo& info, |
| 1743 | uint64_t index_in_table) const { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1744 | uint32_t high_literal_offset = GetAssembler().GetLabelLocation(&info.high_label); |
| 1745 | uint32_t low_literal_offset = GetAssembler().GetLabelLocation(&info.low_label); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1746 | uintptr_t address = |
| 1747 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1748 | uint32_t addr32 = dchecked_integral_cast<uint32_t>(address); |
| 1749 | // lui reg, addr32_high |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1750 | DCHECK_EQ(code[high_literal_offset + 0], 0x34); |
| 1751 | DCHECK_EQ(code[high_literal_offset + 1], 0x12); |
| 1752 | DCHECK_EQ((code[high_literal_offset + 2] & 0xE0), 0x00); |
| 1753 | DCHECK_EQ(code[high_literal_offset + 3], 0x3C); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1754 | // instr reg, reg, addr32_low |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1755 | DCHECK_EQ(code[low_literal_offset + 0], 0x78); |
| 1756 | DCHECK_EQ(code[low_literal_offset + 1], 0x56); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1757 | 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] | 1758 | // lui reg, addr32_high |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1759 | code[high_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 16); |
| 1760 | code[high_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 24); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1761 | // instr reg, reg, addr32_low |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1762 | code[low_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 0); |
| 1763 | code[low_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 8); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | void CodeGeneratorMIPS::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1767 | for (const JitPatchInfo& info : jit_string_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1768 | StringReference string_reference(&info.target_dex_file, dex::StringIndex(info.index)); |
| 1769 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1770 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1771 | } |
| 1772 | for (const JitPatchInfo& info : jit_class_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1773 | TypeReference type_reference(&info.target_dex_file, dex::TypeIndex(info.index)); |
| 1774 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1775 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1779 | void CodeGeneratorMIPS::MarkGCCard(Register object, |
| 1780 | Register value, |
| 1781 | bool value_can_be_null) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1782 | MipsLabel done; |
| 1783 | Register card = AT; |
| 1784 | Register temp = TMP; |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1785 | if (value_can_be_null) { |
| 1786 | __ Beqz(value, &done); |
| 1787 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1788 | __ LoadFromOffset(kLoadWord, |
| 1789 | card, |
| 1790 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1791 | Thread::CardTableOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1792 | __ Srl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1793 | __ Addu(temp, card, temp); |
| 1794 | __ Sb(card, temp, 0); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1795 | if (value_can_be_null) { |
| 1796 | __ Bind(&done); |
| 1797 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1798 | } |
| 1799 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1800 | void CodeGeneratorMIPS::SetupBlockedRegisters() const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1801 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1802 | blocked_core_registers_[ZERO] = true; |
| 1803 | blocked_core_registers_[K0] = true; |
| 1804 | blocked_core_registers_[K1] = true; |
| 1805 | blocked_core_registers_[GP] = true; |
| 1806 | blocked_core_registers_[SP] = true; |
| 1807 | blocked_core_registers_[RA] = true; |
| 1808 | |
| 1809 | // AT and TMP(T8) are used as temporary/scratch registers |
| 1810 | // (similar to how AT is used by MIPS assemblers). |
| 1811 | blocked_core_registers_[AT] = true; |
| 1812 | blocked_core_registers_[TMP] = true; |
| 1813 | blocked_fpu_registers_[FTMP] = true; |
| 1814 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1815 | if (GetInstructionSetFeatures().HasMsa()) { |
| 1816 | // To be used just for MSA instructions. |
| 1817 | blocked_fpu_registers_[FTMP2] = true; |
| 1818 | } |
| 1819 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1820 | // Reserve suspend and thread registers. |
| 1821 | blocked_core_registers_[S0] = true; |
| 1822 | blocked_core_registers_[TR] = true; |
| 1823 | |
| 1824 | // Reserve T9 for function calls |
| 1825 | blocked_core_registers_[T9] = true; |
| 1826 | |
| 1827 | // Reserve odd-numbered FPU registers. |
| 1828 | for (size_t i = 1; i < kNumberOfFRegisters; i += 2) { |
| 1829 | blocked_fpu_registers_[i] = true; |
| 1830 | } |
| 1831 | |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 1832 | if (GetGraph()->IsDebuggable()) { |
| 1833 | // Stubs do not save callee-save floating point registers. If the graph |
| 1834 | // is debuggable, we need to deal with these registers differently. For |
| 1835 | // now, just block them. |
| 1836 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1837 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1838 | } |
| 1839 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1840 | } |
| 1841 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1842 | size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1843 | __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index); |
| 1844 | return kMipsWordSize; |
| 1845 | } |
| 1846 | |
| 1847 | size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1848 | __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index); |
| 1849 | return kMipsWordSize; |
| 1850 | } |
| 1851 | |
| 1852 | size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1853 | if (GetGraph()->HasSIMD()) { |
| 1854 | __ StoreQToOffset(FRegister(reg_id), SP, stack_index); |
| 1855 | } else { |
| 1856 | __ StoreDToOffset(FRegister(reg_id), SP, stack_index); |
| 1857 | } |
| 1858 | return GetFloatingPointSpillSlotSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1862 | if (GetGraph()->HasSIMD()) { |
| 1863 | __ LoadQFromOffset(FRegister(reg_id), SP, stack_index); |
| 1864 | } else { |
| 1865 | __ LoadDFromOffset(FRegister(reg_id), SP, stack_index); |
| 1866 | } |
| 1867 | return GetFloatingPointSpillSlotSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1871 | stream << Register(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1875 | stream << FRegister(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1876 | } |
| 1877 | |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1878 | constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16; |
| 1879 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1880 | void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1881 | HInstruction* instruction, |
| 1882 | uint32_t dex_pc, |
| 1883 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1884 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1885 | GenerateInvokeRuntime(GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value(), |
| 1886 | IsDirectEntrypoint(entrypoint)); |
| 1887 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1888 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1889 | } |
| 1890 | } |
| 1891 | |
| 1892 | void CodeGeneratorMIPS::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1893 | HInstruction* instruction, |
| 1894 | SlowPathCode* slow_path, |
| 1895 | bool direct) { |
| 1896 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1897 | GenerateInvokeRuntime(entry_point_offset, direct); |
| 1898 | } |
| 1899 | |
| 1900 | void CodeGeneratorMIPS::GenerateInvokeRuntime(int32_t entry_point_offset, bool direct) { |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1901 | bool reordering = __ SetReorder(false); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1902 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1903 | __ Jalr(T9); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1904 | if (direct) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1905 | // Reserve argument space on stack (for $a0-$a3) for |
| 1906 | // entrypoints that directly reference native implementations. |
| 1907 | // Called function may use this space to store $a0-$a3 regs. |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1908 | __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1909 | __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1910 | } else { |
| 1911 | __ Nop(); // In delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1912 | } |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1913 | __ SetReorder(reordering); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, |
| 1917 | Register class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1918 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 1919 | const size_t status_byte_offset = |
| 1920 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 1921 | constexpr uint32_t shifted_initialized_value = |
| 1922 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 1923 | |
| 1924 | __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, status_byte_offset); |
| 1925 | __ LoadConst32(AT, shifted_initialized_value); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 1926 | __ Bltu(TMP, AT, slow_path->GetEntryLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1927 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1928 | __ Sync(0); |
| 1929 | __ Bind(slow_path->GetExitLabel()); |
| 1930 | } |
| 1931 | |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 1932 | void InstructionCodeGeneratorMIPS::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 1933 | Register temp) { |
| 1934 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 1935 | uint32_t mask = check->GetBitstringMask(); |
| 1936 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 1937 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 1938 | |
| 1939 | if (mask_bits == 16u) { |
| 1940 | // Load only the bitstring part of the status word. |
| 1941 | __ LoadFromOffset( |
| 1942 | kLoadUnsignedHalfword, temp, temp, mirror::Class::StatusOffset().Int32Value()); |
| 1943 | // Compare the bitstring bits using XOR. |
| 1944 | __ Xori(temp, temp, dchecked_integral_cast<uint16_t>(path_to_root)); |
| 1945 | } else { |
| 1946 | // /* uint32_t */ temp = temp->status_ |
| 1947 | __ LoadFromOffset(kLoadWord, temp, temp, mirror::Class::StatusOffset().Int32Value()); |
| 1948 | // Compare the bitstring bits using XOR. |
| 1949 | if (IsUint<16>(path_to_root)) { |
| 1950 | __ Xori(temp, temp, dchecked_integral_cast<uint16_t>(path_to_root)); |
| 1951 | } else { |
| 1952 | __ LoadConst32(TMP, path_to_root); |
| 1953 | __ Xor(temp, temp, TMP); |
| 1954 | } |
| 1955 | // Shift out bits that do not contribute to the comparison. |
| 1956 | __ Sll(temp, temp, 32 - mask_bits); |
| 1957 | } |
| 1958 | } |
| 1959 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1960 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1961 | __ Sync(0); // Only stype 0 is supported. |
| 1962 | } |
| 1963 | |
| 1964 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1965 | HBasicBlock* successor) { |
| 1966 | SuspendCheckSlowPathMIPS* slow_path = |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 1967 | down_cast<SuspendCheckSlowPathMIPS*>(instruction->GetSlowPath()); |
| 1968 | |
| 1969 | if (slow_path == nullptr) { |
| 1970 | slow_path = |
| 1971 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS(instruction, successor); |
| 1972 | instruction->SetSlowPath(slow_path); |
| 1973 | codegen_->AddSlowPath(slow_path); |
| 1974 | if (successor != nullptr) { |
| 1975 | DCHECK(successor->IsLoopHeader()); |
| 1976 | } |
| 1977 | } else { |
| 1978 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1979 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1980 | |
| 1981 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1982 | TMP, |
| 1983 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1984 | Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1985 | if (successor == nullptr) { |
| 1986 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 1987 | __ Bind(slow_path->GetReturnLabel()); |
| 1988 | } else { |
| 1989 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); |
| 1990 | __ B(slow_path->GetEntryLabel()); |
| 1991 | // slow_path will return to GetLabelOf(successor). |
| 1992 | } |
| 1993 | } |
| 1994 | |
| 1995 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, |
| 1996 | CodeGeneratorMIPS* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1997 | : InstructionCodeGenerator(graph, codegen), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1998 | assembler_(codegen->GetAssembler()), |
| 1999 | codegen_(codegen) {} |
| 2000 | |
| 2001 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 2002 | DCHECK_EQ(instruction->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2003 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2004 | DataType::Type type = instruction->GetResultType(); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2005 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2006 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2007 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2008 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2009 | HInstruction* right = instruction->InputAt(1); |
| 2010 | bool can_use_imm = false; |
| 2011 | if (right->IsConstant()) { |
| 2012 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); |
| 2013 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 2014 | can_use_imm = IsUint<16>(imm); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2015 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2016 | DCHECK(instruction->IsSub() || instruction->IsAdd()); |
| 2017 | if (instruction->IsSub()) { |
| 2018 | imm = -imm; |
| 2019 | } |
| 2020 | if (isR6) { |
| 2021 | bool single_use = right->GetUses().HasExactlyOneElement(); |
| 2022 | int16_t imm_high = High16Bits(imm); |
| 2023 | int16_t imm_low = Low16Bits(imm); |
| 2024 | if (imm_low < 0) { |
| 2025 | imm_high += 1; |
| 2026 | } |
| 2027 | can_use_imm = !((imm_high != 0) && (imm_low != 0)) || single_use; |
| 2028 | } else { |
| 2029 | can_use_imm = IsInt<16>(imm); |
| 2030 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2031 | } |
| 2032 | } |
| 2033 | if (can_use_imm) |
| 2034 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 2035 | else |
| 2036 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2037 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2038 | break; |
| 2039 | } |
| 2040 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2041 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2042 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2043 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2044 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2045 | break; |
| 2046 | } |
| 2047 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2048 | case DataType::Type::kFloat32: |
| 2049 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2050 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 2051 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2052 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2053 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2054 | break; |
| 2055 | |
| 2056 | default: |
| 2057 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2062 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2063 | LocationSummary* locations = instruction->GetLocations(); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2064 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2065 | |
| 2066 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2067 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2068 | Register dst = locations->Out().AsRegister<Register>(); |
| 2069 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2070 | Location rhs_location = locations->InAt(1); |
| 2071 | |
| 2072 | Register rhs_reg = ZERO; |
| 2073 | int32_t rhs_imm = 0; |
| 2074 | bool use_imm = rhs_location.IsConstant(); |
| 2075 | if (use_imm) { |
| 2076 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2077 | } else { |
| 2078 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2079 | } |
| 2080 | |
| 2081 | if (instruction->IsAnd()) { |
| 2082 | if (use_imm) |
| 2083 | __ Andi(dst, lhs, rhs_imm); |
| 2084 | else |
| 2085 | __ And(dst, lhs, rhs_reg); |
| 2086 | } else if (instruction->IsOr()) { |
| 2087 | if (use_imm) |
| 2088 | __ Ori(dst, lhs, rhs_imm); |
| 2089 | else |
| 2090 | __ Or(dst, lhs, rhs_reg); |
| 2091 | } else if (instruction->IsXor()) { |
| 2092 | if (use_imm) |
| 2093 | __ Xori(dst, lhs, rhs_imm); |
| 2094 | else |
| 2095 | __ Xor(dst, lhs, rhs_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2096 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2097 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 2098 | if (use_imm) { |
| 2099 | if (instruction->IsSub()) { |
| 2100 | rhs_imm = -rhs_imm; |
| 2101 | } |
| 2102 | if (IsInt<16>(rhs_imm)) { |
| 2103 | __ Addiu(dst, lhs, rhs_imm); |
| 2104 | } else { |
| 2105 | DCHECK(isR6); |
| 2106 | int16_t rhs_imm_high = High16Bits(rhs_imm); |
| 2107 | int16_t rhs_imm_low = Low16Bits(rhs_imm); |
| 2108 | if (rhs_imm_low < 0) { |
| 2109 | rhs_imm_high += 1; |
| 2110 | } |
| 2111 | __ Aui(dst, lhs, rhs_imm_high); |
| 2112 | if (rhs_imm_low != 0) { |
| 2113 | __ Addiu(dst, dst, rhs_imm_low); |
| 2114 | } |
| 2115 | } |
| 2116 | } else if (instruction->IsAdd()) { |
| 2117 | __ Addu(dst, lhs, rhs_reg); |
| 2118 | } else { |
| 2119 | DCHECK(instruction->IsSub()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2120 | __ Subu(dst, lhs, rhs_reg); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2121 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2122 | } |
| 2123 | break; |
| 2124 | } |
| 2125 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2126 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2127 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2128 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2129 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2130 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2131 | Location rhs_location = locations->InAt(1); |
| 2132 | bool use_imm = rhs_location.IsConstant(); |
| 2133 | if (!use_imm) { |
| 2134 | Register rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 2135 | Register rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 2136 | if (instruction->IsAnd()) { |
| 2137 | __ And(dst_low, lhs_low, rhs_low); |
| 2138 | __ And(dst_high, lhs_high, rhs_high); |
| 2139 | } else if (instruction->IsOr()) { |
| 2140 | __ Or(dst_low, lhs_low, rhs_low); |
| 2141 | __ Or(dst_high, lhs_high, rhs_high); |
| 2142 | } else if (instruction->IsXor()) { |
| 2143 | __ Xor(dst_low, lhs_low, rhs_low); |
| 2144 | __ Xor(dst_high, lhs_high, rhs_high); |
| 2145 | } else if (instruction->IsAdd()) { |
| 2146 | if (lhs_low == rhs_low) { |
| 2147 | // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs. |
| 2148 | __ Slt(TMP, lhs_low, ZERO); |
| 2149 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2150 | } else { |
| 2151 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2152 | // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged. |
| 2153 | __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low); |
| 2154 | } |
| 2155 | __ Addu(dst_high, lhs_high, rhs_high); |
| 2156 | __ Addu(dst_high, dst_high, TMP); |
| 2157 | } else { |
| 2158 | DCHECK(instruction->IsSub()); |
| 2159 | __ Sltu(TMP, lhs_low, rhs_low); |
| 2160 | __ Subu(dst_low, lhs_low, rhs_low); |
| 2161 | __ Subu(dst_high, lhs_high, rhs_high); |
| 2162 | __ Subu(dst_high, dst_high, TMP); |
| 2163 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2164 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2165 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 2166 | if (instruction->IsOr()) { |
| 2167 | uint32_t low = Low32Bits(value); |
| 2168 | uint32_t high = High32Bits(value); |
| 2169 | if (IsUint<16>(low)) { |
| 2170 | if (dst_low != lhs_low || low != 0) { |
| 2171 | __ Ori(dst_low, lhs_low, low); |
| 2172 | } |
| 2173 | } else { |
| 2174 | __ LoadConst32(TMP, low); |
| 2175 | __ Or(dst_low, lhs_low, TMP); |
| 2176 | } |
| 2177 | if (IsUint<16>(high)) { |
| 2178 | if (dst_high != lhs_high || high != 0) { |
| 2179 | __ Ori(dst_high, lhs_high, high); |
| 2180 | } |
| 2181 | } else { |
| 2182 | if (high != low) { |
| 2183 | __ LoadConst32(TMP, high); |
| 2184 | } |
| 2185 | __ Or(dst_high, lhs_high, TMP); |
| 2186 | } |
| 2187 | } else if (instruction->IsXor()) { |
| 2188 | uint32_t low = Low32Bits(value); |
| 2189 | uint32_t high = High32Bits(value); |
| 2190 | if (IsUint<16>(low)) { |
| 2191 | if (dst_low != lhs_low || low != 0) { |
| 2192 | __ Xori(dst_low, lhs_low, low); |
| 2193 | } |
| 2194 | } else { |
| 2195 | __ LoadConst32(TMP, low); |
| 2196 | __ Xor(dst_low, lhs_low, TMP); |
| 2197 | } |
| 2198 | if (IsUint<16>(high)) { |
| 2199 | if (dst_high != lhs_high || high != 0) { |
| 2200 | __ Xori(dst_high, lhs_high, high); |
| 2201 | } |
| 2202 | } else { |
| 2203 | if (high != low) { |
| 2204 | __ LoadConst32(TMP, high); |
| 2205 | } |
| 2206 | __ Xor(dst_high, lhs_high, TMP); |
| 2207 | } |
| 2208 | } else if (instruction->IsAnd()) { |
| 2209 | uint32_t low = Low32Bits(value); |
| 2210 | uint32_t high = High32Bits(value); |
| 2211 | if (IsUint<16>(low)) { |
| 2212 | __ Andi(dst_low, lhs_low, low); |
| 2213 | } else if (low != 0xFFFFFFFF) { |
| 2214 | __ LoadConst32(TMP, low); |
| 2215 | __ And(dst_low, lhs_low, TMP); |
| 2216 | } else if (dst_low != lhs_low) { |
| 2217 | __ Move(dst_low, lhs_low); |
| 2218 | } |
| 2219 | if (IsUint<16>(high)) { |
| 2220 | __ Andi(dst_high, lhs_high, high); |
| 2221 | } else if (high != 0xFFFFFFFF) { |
| 2222 | if (high != low) { |
| 2223 | __ LoadConst32(TMP, high); |
| 2224 | } |
| 2225 | __ And(dst_high, lhs_high, TMP); |
| 2226 | } else if (dst_high != lhs_high) { |
| 2227 | __ Move(dst_high, lhs_high); |
| 2228 | } |
| 2229 | } else { |
| 2230 | if (instruction->IsSub()) { |
| 2231 | value = -value; |
| 2232 | } else { |
| 2233 | DCHECK(instruction->IsAdd()); |
| 2234 | } |
| 2235 | int32_t low = Low32Bits(value); |
| 2236 | int32_t high = High32Bits(value); |
| 2237 | if (IsInt<16>(low)) { |
| 2238 | if (dst_low != lhs_low || low != 0) { |
| 2239 | __ Addiu(dst_low, lhs_low, low); |
| 2240 | } |
| 2241 | if (low != 0) { |
| 2242 | __ Sltiu(AT, dst_low, low); |
| 2243 | } |
| 2244 | } else { |
| 2245 | __ LoadConst32(TMP, low); |
| 2246 | __ Addu(dst_low, lhs_low, TMP); |
| 2247 | __ Sltu(AT, dst_low, TMP); |
| 2248 | } |
| 2249 | if (IsInt<16>(high)) { |
| 2250 | if (dst_high != lhs_high || high != 0) { |
| 2251 | __ Addiu(dst_high, lhs_high, high); |
| 2252 | } |
| 2253 | } else { |
| 2254 | if (high != low) { |
| 2255 | __ LoadConst32(TMP, high); |
| 2256 | } |
| 2257 | __ Addu(dst_high, lhs_high, TMP); |
| 2258 | } |
| 2259 | if (low != 0) { |
| 2260 | __ Addu(dst_high, dst_high, AT); |
| 2261 | } |
| 2262 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2263 | } |
| 2264 | break; |
| 2265 | } |
| 2266 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2267 | case DataType::Type::kFloat32: |
| 2268 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2269 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2270 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2271 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2272 | if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2273 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2274 | __ AddS(dst, lhs, rhs); |
| 2275 | } else { |
| 2276 | __ AddD(dst, lhs, rhs); |
| 2277 | } |
| 2278 | } else { |
| 2279 | DCHECK(instruction->IsSub()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2280 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2281 | __ SubS(dst, lhs, rhs); |
| 2282 | } else { |
| 2283 | __ SubD(dst, lhs, rhs); |
| 2284 | } |
| 2285 | } |
| 2286 | break; |
| 2287 | } |
| 2288 | |
| 2289 | default: |
| 2290 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2295 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2296 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2297 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2298 | DataType::Type type = instr->GetResultType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2299 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2300 | case DataType::Type::kInt32: |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2301 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2302 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2303 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2304 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2305 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2306 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2307 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2308 | locations->SetOut(Location::RequiresRegister()); |
| 2309 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2310 | default: |
| 2311 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2312 | } |
| 2313 | } |
| 2314 | |
| 2315 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; |
| 2316 | |
| 2317 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2318 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2319 | LocationSummary* locations = instr->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2320 | DataType::Type type = instr->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2321 | |
| 2322 | Location rhs_location = locations->InAt(1); |
| 2323 | bool use_imm = rhs_location.IsConstant(); |
| 2324 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); |
| 2325 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2326 | const uint32_t shift_mask = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2327 | (type == DataType::Type::kInt32) ? kMaxIntShiftDistance : kMaxLongShiftDistance; |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2328 | const uint32_t shift_value = rhs_imm & shift_mask; |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2329 | // Are the INS (Insert Bit Field) and ROTR instructions supported? |
| 2330 | bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2331 | |
| 2332 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2333 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2334 | Register dst = locations->Out().AsRegister<Register>(); |
| 2335 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2336 | if (use_imm) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2337 | if (shift_value == 0) { |
| 2338 | if (dst != lhs) { |
| 2339 | __ Move(dst, lhs); |
| 2340 | } |
| 2341 | } else if (instr->IsShl()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2342 | __ Sll(dst, lhs, shift_value); |
| 2343 | } else if (instr->IsShr()) { |
| 2344 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2345 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2346 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2347 | } else { |
| 2348 | if (has_ins_rotr) { |
| 2349 | __ Rotr(dst, lhs, shift_value); |
| 2350 | } else { |
| 2351 | __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask); |
| 2352 | __ Srl(dst, lhs, shift_value); |
| 2353 | __ Or(dst, dst, TMP); |
| 2354 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2355 | } |
| 2356 | } else { |
| 2357 | if (instr->IsShl()) { |
| 2358 | __ Sllv(dst, lhs, rhs_reg); |
| 2359 | } else if (instr->IsShr()) { |
| 2360 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2361 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2362 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2363 | } else { |
| 2364 | if (has_ins_rotr) { |
| 2365 | __ Rotrv(dst, lhs, rhs_reg); |
| 2366 | } else { |
| 2367 | __ Subu(TMP, ZERO, rhs_reg); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2368 | // 32-bit shift instructions use the 5 least significant bits of the shift count, so |
| 2369 | // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case |
| 2370 | // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out |
| 2371 | // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`, |
| 2372 | // IOW, the OR'd values are equal. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2373 | __ Sllv(TMP, lhs, TMP); |
| 2374 | __ Srlv(dst, lhs, rhs_reg); |
| 2375 | __ Or(dst, dst, TMP); |
| 2376 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2377 | } |
| 2378 | } |
| 2379 | break; |
| 2380 | } |
| 2381 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2382 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2383 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2384 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2385 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2386 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2387 | if (use_imm) { |
| 2388 | if (shift_value == 0) { |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 2389 | codegen_->MoveLocation(locations->Out(), locations->InAt(0), type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2390 | } else if (shift_value < kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2391 | if (has_ins_rotr) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2392 | if (instr->IsShl()) { |
| 2393 | __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2394 | __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value); |
| 2395 | __ Sll(dst_low, lhs_low, shift_value); |
| 2396 | } else if (instr->IsShr()) { |
| 2397 | __ Srl(dst_low, lhs_low, shift_value); |
| 2398 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2399 | __ Sra(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2400 | } else if (instr->IsUShr()) { |
| 2401 | __ Srl(dst_low, lhs_low, shift_value); |
| 2402 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2403 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2404 | } else { |
| 2405 | __ Srl(dst_low, lhs_low, shift_value); |
| 2406 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2407 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2408 | __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2409 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2410 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2411 | if (instr->IsShl()) { |
| 2412 | __ Sll(dst_low, lhs_low, shift_value); |
| 2413 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); |
| 2414 | __ Sll(dst_high, lhs_high, shift_value); |
| 2415 | __ Or(dst_high, dst_high, TMP); |
| 2416 | } else if (instr->IsShr()) { |
| 2417 | __ Sra(dst_high, lhs_high, shift_value); |
| 2418 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2419 | __ Srl(dst_low, lhs_low, shift_value); |
| 2420 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2421 | } else if (instr->IsUShr()) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2422 | __ Srl(dst_high, lhs_high, shift_value); |
| 2423 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2424 | __ Srl(dst_low, lhs_low, shift_value); |
| 2425 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2426 | } else { |
| 2427 | __ Srl(TMP, lhs_low, shift_value); |
| 2428 | __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value); |
| 2429 | __ Or(dst_low, dst_low, TMP); |
| 2430 | __ Srl(TMP, lhs_high, shift_value); |
| 2431 | __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2432 | __ Or(dst_high, dst_high, TMP); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2433 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2434 | } |
| 2435 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2436 | const uint32_t shift_value_high = shift_value - kMipsBitsPerWord; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2437 | if (instr->IsShl()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2438 | __ Sll(dst_high, lhs_low, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2439 | __ Move(dst_low, ZERO); |
| 2440 | } else if (instr->IsShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2441 | __ Sra(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2442 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2443 | } else if (instr->IsUShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2444 | __ Srl(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2445 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2446 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2447 | if (shift_value == kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2448 | // 64-bit rotation by 32 is just a swap. |
| 2449 | __ Move(dst_low, lhs_high); |
| 2450 | __ Move(dst_high, lhs_low); |
| 2451 | } else { |
| 2452 | if (has_ins_rotr) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2453 | __ Srl(dst_low, lhs_high, shift_value_high); |
| 2454 | __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high); |
| 2455 | __ Srl(dst_high, lhs_low, shift_value_high); |
| 2456 | __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2457 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2458 | __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high); |
| 2459 | __ Srl(dst_low, lhs_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2460 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2461 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high); |
| 2462 | __ Srl(dst_high, lhs_low, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2463 | __ Or(dst_high, dst_high, TMP); |
| 2464 | } |
| 2465 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2466 | } |
| 2467 | } |
| 2468 | } else { |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2469 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2470 | MipsLabel done; |
| 2471 | if (instr->IsShl()) { |
| 2472 | __ Sllv(dst_low, lhs_low, rhs_reg); |
| 2473 | __ Nor(AT, ZERO, rhs_reg); |
| 2474 | __ Srl(TMP, lhs_low, 1); |
| 2475 | __ Srlv(TMP, TMP, AT); |
| 2476 | __ Sllv(dst_high, lhs_high, rhs_reg); |
| 2477 | __ Or(dst_high, dst_high, TMP); |
| 2478 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2479 | if (isR6) { |
| 2480 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2481 | __ Move(dst_high, dst_low); |
| 2482 | __ Move(dst_low, ZERO); |
| 2483 | } else { |
| 2484 | __ Movn(dst_high, dst_low, TMP); |
| 2485 | __ Movn(dst_low, ZERO, TMP); |
| 2486 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2487 | } else if (instr->IsShr()) { |
| 2488 | __ Srav(dst_high, lhs_high, rhs_reg); |
| 2489 | __ Nor(AT, ZERO, rhs_reg); |
| 2490 | __ Sll(TMP, lhs_high, 1); |
| 2491 | __ Sllv(TMP, TMP, AT); |
| 2492 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2493 | __ Or(dst_low, dst_low, TMP); |
| 2494 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2495 | if (isR6) { |
| 2496 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2497 | __ Move(dst_low, dst_high); |
| 2498 | __ Sra(dst_high, dst_high, 31); |
| 2499 | } else { |
| 2500 | __ Sra(AT, dst_high, 31); |
| 2501 | __ Movn(dst_low, dst_high, TMP); |
| 2502 | __ Movn(dst_high, AT, TMP); |
| 2503 | } |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2504 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2505 | __ Srlv(dst_high, lhs_high, rhs_reg); |
| 2506 | __ Nor(AT, ZERO, rhs_reg); |
| 2507 | __ Sll(TMP, lhs_high, 1); |
| 2508 | __ Sllv(TMP, TMP, AT); |
| 2509 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2510 | __ Or(dst_low, dst_low, TMP); |
| 2511 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2512 | if (isR6) { |
| 2513 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2514 | __ Move(dst_low, dst_high); |
| 2515 | __ Move(dst_high, ZERO); |
| 2516 | } else { |
| 2517 | __ Movn(dst_low, dst_high, TMP); |
| 2518 | __ Movn(dst_high, ZERO, TMP); |
| 2519 | } |
| 2520 | } else { // Rotate. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2521 | __ Nor(AT, ZERO, rhs_reg); |
| 2522 | __ Srlv(TMP, lhs_low, rhs_reg); |
| 2523 | __ Sll(dst_low, lhs_high, 1); |
| 2524 | __ Sllv(dst_low, dst_low, AT); |
| 2525 | __ Or(dst_low, dst_low, TMP); |
| 2526 | __ Srlv(TMP, lhs_high, rhs_reg); |
| 2527 | __ Sll(dst_high, lhs_low, 1); |
| 2528 | __ Sllv(dst_high, dst_high, AT); |
| 2529 | __ Or(dst_high, dst_high, TMP); |
| 2530 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2531 | if (isR6) { |
| 2532 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2533 | __ Move(TMP, dst_high); |
| 2534 | __ Move(dst_high, dst_low); |
| 2535 | __ Move(dst_low, TMP); |
| 2536 | } else { |
| 2537 | __ Movn(AT, dst_high, TMP); |
| 2538 | __ Movn(dst_high, dst_low, TMP); |
| 2539 | __ Movn(dst_low, AT, TMP); |
| 2540 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2541 | } |
| 2542 | __ Bind(&done); |
| 2543 | } |
| 2544 | break; |
| 2545 | } |
| 2546 | |
| 2547 | default: |
| 2548 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2549 | } |
| 2550 | } |
| 2551 | |
| 2552 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { |
| 2553 | HandleBinaryOp(instruction); |
| 2554 | } |
| 2555 | |
| 2556 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { |
| 2557 | HandleBinaryOp(instruction); |
| 2558 | } |
| 2559 | |
| 2560 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { |
| 2561 | HandleBinaryOp(instruction); |
| 2562 | } |
| 2563 | |
| 2564 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { |
| 2565 | HandleBinaryOp(instruction); |
| 2566 | } |
| 2567 | |
| 2568 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2569 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2570 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2571 | kEmitCompilerReadBarrier && (type == DataType::Type::kReference); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2572 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2573 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2574 | object_array_get_with_read_barrier |
| 2575 | ? LocationSummary::kCallOnSlowPath |
| 2576 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 2577 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2578 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2579 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2580 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2581 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2582 | if (DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2583 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2584 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2585 | // The output overlaps in the case of an object array get with |
| 2586 | // read barriers enabled: we do not want the move to overwrite the |
| 2587 | // array's location, as we need it to emit the read barrier. |
| 2588 | locations->SetOut(Location::RequiresRegister(), |
| 2589 | object_array_get_with_read_barrier |
| 2590 | ? Location::kOutputOverlap |
| 2591 | : Location::kNoOutputOverlap); |
| 2592 | } |
| 2593 | // We need a temporary register for the read barrier marking slow |
| 2594 | // path in CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier. |
| 2595 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2596 | bool temp_needed = instruction->GetIndex()->IsConstant() |
| 2597 | ? !kBakerReadBarrierThunksEnableForFields |
| 2598 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2599 | if (temp_needed) { |
| 2600 | locations->AddTemp(Location::RequiresRegister()); |
| 2601 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2602 | } |
| 2603 | } |
| 2604 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2605 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS* codegen) { |
| 2606 | auto null_checker = [codegen, instruction]() { |
| 2607 | codegen->MaybeRecordImplicitNullCheck(instruction); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2608 | }; |
| 2609 | return null_checker; |
| 2610 | } |
| 2611 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2612 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 2613 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2614 | Location obj_loc = locations->InAt(0); |
| 2615 | Register obj = obj_loc.AsRegister<Register>(); |
| 2616 | Location out_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2617 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2618 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2619 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2620 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2621 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2622 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2623 | instruction->IsStringCharAt(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2624 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2625 | case DataType::Type::kBool: |
| 2626 | case DataType::Type::kUint8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2627 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2628 | if (index.IsConstant()) { |
| 2629 | size_t offset = |
| 2630 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2631 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2632 | } else { |
| 2633 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2634 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2635 | } |
| 2636 | break; |
| 2637 | } |
| 2638 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2639 | case DataType::Type::kInt8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2640 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2641 | if (index.IsConstant()) { |
| 2642 | size_t offset = |
| 2643 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2644 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2645 | } else { |
| 2646 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2647 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2648 | } |
| 2649 | break; |
| 2650 | } |
| 2651 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2652 | case DataType::Type::kUint16: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2653 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2654 | if (maybe_compressed_char_at) { |
| 2655 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2656 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
| 2657 | __ Sll(TMP, TMP, 31); // Extract compression flag into the most significant bit of TMP. |
| 2658 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2659 | "Expecting 0=compressed, 1=uncompressed"); |
| 2660 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2661 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2662 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2663 | if (maybe_compressed_char_at) { |
| 2664 | MipsLabel uncompressed_load, done; |
| 2665 | __ Bnez(TMP, &uncompressed_load); |
| 2666 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2667 | out, |
| 2668 | obj, |
| 2669 | data_offset + (const_index << TIMES_1)); |
| 2670 | __ B(&done); |
| 2671 | __ Bind(&uncompressed_load); |
| 2672 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2673 | out, |
| 2674 | obj, |
| 2675 | data_offset + (const_index << TIMES_2)); |
| 2676 | __ Bind(&done); |
| 2677 | } else { |
| 2678 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2679 | out, |
| 2680 | obj, |
| 2681 | data_offset + (const_index << TIMES_2), |
| 2682 | null_checker); |
| 2683 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2684 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2685 | Register index_reg = index.AsRegister<Register>(); |
| 2686 | if (maybe_compressed_char_at) { |
| 2687 | MipsLabel uncompressed_load, done; |
| 2688 | __ Bnez(TMP, &uncompressed_load); |
| 2689 | __ Addu(TMP, obj, index_reg); |
| 2690 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2691 | __ B(&done); |
| 2692 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2693 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2694 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2695 | __ Bind(&done); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2696 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2697 | __ Addu(TMP, index_reg, obj); |
| 2698 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2699 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2700 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2701 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
| 2702 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2703 | } |
| 2704 | break; |
| 2705 | } |
| 2706 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2707 | case DataType::Type::kInt16: { |
| 2708 | Register out = out_loc.AsRegister<Register>(); |
| 2709 | if (index.IsConstant()) { |
| 2710 | size_t offset = |
| 2711 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2712 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2713 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2714 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2715 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2716 | } else { |
| 2717 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_2, TMP); |
| 2718 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
| 2719 | } |
| 2720 | break; |
| 2721 | } |
| 2722 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2723 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2724 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2725 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2726 | if (index.IsConstant()) { |
| 2727 | size_t offset = |
| 2728 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2729 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2730 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2731 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2732 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2733 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2734 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2735 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2736 | } |
| 2737 | break; |
| 2738 | } |
| 2739 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2740 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2741 | static_assert( |
| 2742 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2743 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2744 | // /* HeapReference<Object> */ out = |
| 2745 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2746 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2747 | bool temp_needed = index.IsConstant() |
| 2748 | ? !kBakerReadBarrierThunksEnableForFields |
| 2749 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2750 | Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2751 | // Note that a potential implicit null check is handled in this |
| 2752 | // CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier call. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2753 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 2754 | if (index.IsConstant()) { |
| 2755 | // Array load with a constant index can be treated as a field load. |
| 2756 | size_t offset = |
| 2757 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2758 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2759 | out_loc, |
| 2760 | obj, |
| 2761 | offset, |
| 2762 | temp, |
| 2763 | /* needs_null_check */ false); |
| 2764 | } else { |
| 2765 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2766 | out_loc, |
| 2767 | obj, |
| 2768 | data_offset, |
| 2769 | index, |
| 2770 | temp, |
| 2771 | /* needs_null_check */ false); |
| 2772 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2773 | } else { |
| 2774 | Register out = out_loc.AsRegister<Register>(); |
| 2775 | if (index.IsConstant()) { |
| 2776 | size_t offset = |
| 2777 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2778 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
| 2779 | // If read barriers are enabled, emit read barriers other than |
| 2780 | // Baker's using a slow path (and also unpoison the loaded |
| 2781 | // reference, if heap poisoning is enabled). |
| 2782 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2783 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2784 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2785 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
| 2786 | // If read barriers are enabled, emit read barriers other than |
| 2787 | // Baker's using a slow path (and also unpoison the loaded |
| 2788 | // reference, if heap poisoning is enabled). |
| 2789 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2790 | out_loc, |
| 2791 | out_loc, |
| 2792 | obj_loc, |
| 2793 | data_offset, |
| 2794 | index); |
| 2795 | } |
| 2796 | } |
| 2797 | break; |
| 2798 | } |
| 2799 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2800 | case DataType::Type::kInt64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2801 | Register out = out_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2802 | if (index.IsConstant()) { |
| 2803 | size_t offset = |
| 2804 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2805 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2806 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2807 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2808 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2809 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2810 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2811 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2812 | } |
| 2813 | break; |
| 2814 | } |
| 2815 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2816 | case DataType::Type::kFloat32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2817 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2818 | if (index.IsConstant()) { |
| 2819 | size_t offset = |
| 2820 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2821 | __ LoadSFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2822 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2823 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2824 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2825 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2826 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2827 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2828 | } |
| 2829 | break; |
| 2830 | } |
| 2831 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2832 | case DataType::Type::kFloat64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2833 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2834 | if (index.IsConstant()) { |
| 2835 | size_t offset = |
| 2836 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2837 | __ LoadDFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2838 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2839 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2840 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2841 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2842 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2843 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2844 | } |
| 2845 | break; |
| 2846 | } |
| 2847 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2848 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2849 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2850 | UNREACHABLE(); |
| 2851 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2855 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2856 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2857 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2858 | } |
| 2859 | |
| 2860 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 2861 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2862 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2863 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2864 | Register out = locations->Out().AsRegister<Register>(); |
| 2865 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2866 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2867 | // Mask out compression flag from String's array length. |
| 2868 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2869 | __ Srl(out, out, 1u); |
| 2870 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2871 | } |
| 2872 | |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2873 | Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2874 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2875 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2876 | : Location::RequiresRegister(); |
| 2877 | } |
| 2878 | |
| 2879 | Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2880 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2881 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2882 | // but we should only prefer this if the constant has a single use. |
| 2883 | if (instruction->IsConstant() && |
| 2884 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2885 | instruction->GetUses().HasExactlyOneElement())) { |
| 2886 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2887 | // Otherwise fall through and require an FPU register for the constant. |
| 2888 | } |
| 2889 | return Location::RequiresFpuRegister(); |
| 2890 | } |
| 2891 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2892 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2893 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2894 | |
| 2895 | bool needs_write_barrier = |
| 2896 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2897 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2898 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2899 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2900 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2901 | may_need_runtime_call_for_type_check ? |
| 2902 | LocationSummary::kCallOnSlowPath : |
| 2903 | LocationSummary::kNoCall); |
| 2904 | |
| 2905 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2906 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2907 | if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2908 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2909 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2910 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2911 | } |
| 2912 | if (needs_write_barrier) { |
| 2913 | // Temporary register for the write barrier. |
| 2914 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2915 | } |
| 2916 | } |
| 2917 | |
| 2918 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { |
| 2919 | LocationSummary* locations = instruction->GetLocations(); |
| 2920 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2921 | Location index = locations->InAt(1); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2922 | Location value_location = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2923 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2924 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2925 | bool needs_write_barrier = |
| 2926 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2927 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2928 | Register base_reg = index.IsConstant() ? obj : TMP; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2929 | |
| 2930 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2931 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2932 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2933 | case DataType::Type::kInt8: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2934 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2935 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2936 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2937 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2938 | __ Addu(base_reg, obj, index.AsRegister<Register>()); |
| 2939 | } |
| 2940 | if (value_location.IsConstant()) { |
| 2941 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2942 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2943 | } else { |
| 2944 | Register value = value_location.AsRegister<Register>(); |
| 2945 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2946 | } |
| 2947 | break; |
| 2948 | } |
| 2949 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2950 | case DataType::Type::kUint16: |
| 2951 | case DataType::Type::kInt16: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2952 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2953 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2954 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2955 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2956 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2957 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2958 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_2, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2959 | } |
| 2960 | if (value_location.IsConstant()) { |
| 2961 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2962 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2963 | } else { |
| 2964 | Register value = value_location.AsRegister<Register>(); |
| 2965 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2966 | } |
| 2967 | break; |
| 2968 | } |
| 2969 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2970 | case DataType::Type::kInt32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2971 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2972 | if (index.IsConstant()) { |
| 2973 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2974 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2975 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2976 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2977 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2978 | } |
| 2979 | if (value_location.IsConstant()) { |
| 2980 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2981 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2982 | } else { |
| 2983 | Register value = value_location.AsRegister<Register>(); |
| 2984 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2985 | } |
| 2986 | break; |
| 2987 | } |
| 2988 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2989 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2990 | if (value_location.IsConstant()) { |
| 2991 | // Just setting null. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2992 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2993 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2994 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2995 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2996 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2997 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2998 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2999 | DCHECK_EQ(value, 0); |
| 3000 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 3001 | DCHECK(!needs_write_barrier); |
| 3002 | DCHECK(!may_need_runtime_call_for_type_check); |
| 3003 | break; |
| 3004 | } |
| 3005 | |
| 3006 | DCHECK(needs_write_barrier); |
| 3007 | Register value = value_location.AsRegister<Register>(); |
| 3008 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 3009 | Register temp2 = TMP; // Doesn't need to survive slow path. |
| 3010 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3011 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3012 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3013 | MipsLabel done; |
| 3014 | SlowPathCodeMIPS* slow_path = nullptr; |
| 3015 | |
| 3016 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3017 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS(instruction); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3018 | codegen_->AddSlowPath(slow_path); |
| 3019 | if (instruction->GetValueCanBeNull()) { |
| 3020 | MipsLabel non_zero; |
| 3021 | __ Bnez(value, &non_zero); |
| 3022 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3023 | if (index.IsConstant()) { |
| 3024 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3025 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3026 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 3027 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3028 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 3029 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3030 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 3031 | __ B(&done); |
| 3032 | __ Bind(&non_zero); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3033 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3034 | |
| 3035 | // Note that when read barriers are enabled, the type checks |
| 3036 | // are performed without read barriers. This is fine, even in |
| 3037 | // the case where a class object is in the from-space after |
| 3038 | // the flip, as a comparison involving such a type would not |
| 3039 | // produce a false positive; it may of course produce a false |
| 3040 | // negative, in which case we would take the ArraySet slow |
| 3041 | // path. |
| 3042 | |
| 3043 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 3044 | __ LoadFromOffset(kLoadWord, temp1, obj, class_offset, null_checker); |
| 3045 | __ MaybeUnpoisonHeapReference(temp1); |
| 3046 | |
| 3047 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 3048 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 3049 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3050 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 3051 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 3052 | // nor `temp2`, as we are comparing two poisoned references. |
| 3053 | |
| 3054 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3055 | MipsLabel do_put; |
| 3056 | __ Beq(temp1, temp2, &do_put); |
| 3057 | // If heap poisoning is enabled, the `temp1` reference has |
| 3058 | // not been unpoisoned yet; unpoison it now. |
| 3059 | __ MaybeUnpoisonHeapReference(temp1); |
| 3060 | |
| 3061 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 3062 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 3063 | // If heap poisoning is enabled, no need to unpoison |
| 3064 | // `temp1`, as we are comparing against null below. |
| 3065 | __ Bnez(temp1, slow_path->GetEntryLabel()); |
| 3066 | __ Bind(&do_put); |
| 3067 | } else { |
| 3068 | __ Bne(temp1, temp2, slow_path->GetEntryLabel()); |
| 3069 | } |
| 3070 | } |
| 3071 | |
| 3072 | Register source = value; |
| 3073 | if (kPoisonHeapReferences) { |
| 3074 | // Note that in the case where `value` is a null reference, |
| 3075 | // we do not enter this block, as a null reference does not |
| 3076 | // need poisoning. |
| 3077 | __ Move(temp1, value); |
| 3078 | __ PoisonHeapReference(temp1); |
| 3079 | source = temp1; |
| 3080 | } |
| 3081 | |
| 3082 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3083 | if (index.IsConstant()) { |
| 3084 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3085 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3086 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3087 | } |
| 3088 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 3089 | |
| 3090 | if (!may_need_runtime_call_for_type_check) { |
| 3091 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3092 | } |
| 3093 | |
| 3094 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 3095 | |
| 3096 | if (done.IsLinked()) { |
| 3097 | __ Bind(&done); |
| 3098 | } |
| 3099 | |
| 3100 | if (slow_path != nullptr) { |
| 3101 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3102 | } |
| 3103 | break; |
| 3104 | } |
| 3105 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3106 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3107 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3108 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3109 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3110 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3111 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3112 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3113 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3114 | } |
| 3115 | if (value_location.IsConstant()) { |
| 3116 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3117 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3118 | } else { |
| 3119 | Register value = value_location.AsRegisterPairLow<Register>(); |
| 3120 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3121 | } |
| 3122 | break; |
| 3123 | } |
| 3124 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3125 | case DataType::Type::kFloat32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3126 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3127 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3128 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3129 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3130 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3131 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3132 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3133 | } |
| 3134 | if (value_location.IsConstant()) { |
| 3135 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3136 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 3137 | } else { |
| 3138 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3139 | __ StoreSToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3140 | } |
| 3141 | break; |
| 3142 | } |
| 3143 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3144 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3145 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3146 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3147 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3148 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3149 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3150 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3151 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3152 | } |
| 3153 | if (value_location.IsConstant()) { |
| 3154 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3155 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3156 | } else { |
| 3157 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3158 | __ StoreDToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3159 | } |
| 3160 | break; |
| 3161 | } |
| 3162 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3163 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3164 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 3165 | UNREACHABLE(); |
| 3166 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3167 | } |
| 3168 | |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3169 | void LocationsBuilderMIPS::VisitIntermediateArrayAddressIndex( |
| 3170 | HIntermediateArrayAddressIndex* instruction) { |
| 3171 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3172 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3173 | |
| 3174 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 3175 | |
| 3176 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3177 | locations->SetInAt(1, Location::ConstantLocation(shift)); |
| 3178 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3179 | } |
| 3180 | |
| 3181 | void InstructionCodeGeneratorMIPS::VisitIntermediateArrayAddressIndex( |
| 3182 | HIntermediateArrayAddressIndex* instruction) { |
| 3183 | LocationSummary* locations = instruction->GetLocations(); |
| 3184 | Register index_reg = locations->InAt(0).AsRegister<Register>(); |
| 3185 | uint32_t shift = instruction->GetShift()->AsIntConstant()->GetValue(); |
| 3186 | __ Sll(locations->Out().AsRegister<Register>(), index_reg, shift); |
| 3187 | } |
| 3188 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3189 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3190 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3191 | InvokeRuntimeCallingConvention calling_convention; |
| 3192 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3193 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3194 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3195 | |
| 3196 | HInstruction* index = instruction->InputAt(0); |
| 3197 | HInstruction* length = instruction->InputAt(1); |
| 3198 | |
| 3199 | bool const_index = false; |
| 3200 | bool const_length = false; |
| 3201 | |
| 3202 | if (index->IsConstant()) { |
| 3203 | if (length->IsConstant()) { |
| 3204 | const_index = true; |
| 3205 | const_length = true; |
| 3206 | } else { |
| 3207 | int32_t index_value = index->AsIntConstant()->GetValue(); |
| 3208 | if (index_value < 0 || IsInt<16>(index_value + 1)) { |
| 3209 | const_index = true; |
| 3210 | } |
| 3211 | } |
| 3212 | } else if (length->IsConstant()) { |
| 3213 | int32_t length_value = length->AsIntConstant()->GetValue(); |
| 3214 | if (IsUint<15>(length_value)) { |
| 3215 | const_length = true; |
| 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | locations->SetInAt(0, const_index |
| 3220 | ? Location::ConstantLocation(index->AsConstant()) |
| 3221 | : Location::RequiresRegister()); |
| 3222 | locations->SetInAt(1, const_length |
| 3223 | ? Location::ConstantLocation(length->AsConstant()) |
| 3224 | : Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3225 | } |
| 3226 | |
| 3227 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 3228 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3229 | Location index_loc = locations->InAt(0); |
| 3230 | Location length_loc = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3231 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3232 | if (length_loc.IsConstant()) { |
| 3233 | int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3234 | if (index_loc.IsConstant()) { |
| 3235 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3236 | if (index < 0 || index >= length) { |
| 3237 | BoundsCheckSlowPathMIPS* slow_path = |
| 3238 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3239 | codegen_->AddSlowPath(slow_path); |
| 3240 | __ B(slow_path->GetEntryLabel()); |
| 3241 | } else { |
| 3242 | // Nothing to be done. |
| 3243 | } |
| 3244 | return; |
| 3245 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3246 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3247 | BoundsCheckSlowPathMIPS* slow_path = |
| 3248 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3249 | codegen_->AddSlowPath(slow_path); |
| 3250 | Register index = index_loc.AsRegister<Register>(); |
| 3251 | if (length == 0) { |
| 3252 | __ B(slow_path->GetEntryLabel()); |
| 3253 | } else if (length == 1) { |
| 3254 | __ Bnez(index, slow_path->GetEntryLabel()); |
| 3255 | } else { |
| 3256 | DCHECK(IsUint<15>(length)) << length; |
| 3257 | __ Sltiu(TMP, index, length); |
| 3258 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3259 | } |
| 3260 | } else { |
| 3261 | Register length = length_loc.AsRegister<Register>(); |
| 3262 | BoundsCheckSlowPathMIPS* slow_path = |
| 3263 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3264 | codegen_->AddSlowPath(slow_path); |
| 3265 | if (index_loc.IsConstant()) { |
| 3266 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3267 | if (index < 0) { |
| 3268 | __ B(slow_path->GetEntryLabel()); |
| 3269 | } else if (index == 0) { |
| 3270 | __ Blez(length, slow_path->GetEntryLabel()); |
| 3271 | } else { |
| 3272 | DCHECK(IsInt<16>(index + 1)) << index; |
| 3273 | __ Sltiu(TMP, length, index + 1); |
| 3274 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 3275 | } |
| 3276 | } else { |
| 3277 | Register index = index_loc.AsRegister<Register>(); |
| 3278 | __ Bgeu(index, length, slow_path->GetEntryLabel()); |
| 3279 | } |
| 3280 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3281 | } |
| 3282 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3283 | // Temp is used for read barrier. |
| 3284 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3285 | if (kEmitCompilerReadBarrier && |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 3286 | !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) && |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3287 | (kUseBakerReadBarrier || |
| 3288 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3289 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3290 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3291 | return 1; |
| 3292 | } |
| 3293 | return 0; |
| 3294 | } |
| 3295 | |
| 3296 | // Extra temp is used for read barrier. |
| 3297 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3298 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 3299 | } |
| 3300 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3301 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3302 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3303 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 3304 | |
| 3305 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3306 | switch (type_check_kind) { |
| 3307 | case TypeCheckKind::kExactCheck: |
| 3308 | case TypeCheckKind::kAbstractClassCheck: |
| 3309 | case TypeCheckKind::kClassHierarchyCheck: |
| 3310 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3311 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3312 | ? LocationSummary::kCallOnSlowPath |
| 3313 | : LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 3314 | break; |
| 3315 | case TypeCheckKind::kArrayCheck: |
| 3316 | case TypeCheckKind::kUnresolvedCheck: |
| 3317 | case TypeCheckKind::kInterfaceCheck: |
| 3318 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3319 | break; |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 3320 | case TypeCheckKind::kBitstringCheck: |
| 3321 | break; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3322 | } |
| 3323 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3324 | LocationSummary* locations = |
| 3325 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3326 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 3327 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3328 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3329 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3330 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3331 | } else { |
| 3332 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3333 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3334 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3335 | } |
| 3336 | |
| 3337 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3338 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3339 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3340 | Location obj_loc = locations->InAt(0); |
| 3341 | Register obj = obj_loc.AsRegister<Register>(); |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 3342 | Location cls = locations->InAt(1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3343 | Location temp_loc = locations->GetTemp(0); |
| 3344 | Register temp = temp_loc.AsRegister<Register>(); |
| 3345 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 3346 | DCHECK_LE(num_temps, 2u); |
| 3347 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3348 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3349 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3350 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3351 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 3352 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 3353 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 3354 | const uint32_t object_array_data_offset = |
| 3355 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 3356 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3357 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3358 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 3359 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 3360 | // read barriers is done for performance and code size reasons. |
| 3361 | bool is_type_check_slow_path_fatal = false; |
| 3362 | if (!kEmitCompilerReadBarrier) { |
| 3363 | is_type_check_slow_path_fatal = |
| 3364 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 3365 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3366 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3367 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 3368 | !instruction->CanThrowIntoCatchBlock(); |
| 3369 | } |
| 3370 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3371 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 3372 | instruction, is_type_check_slow_path_fatal); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3373 | codegen_->AddSlowPath(slow_path); |
| 3374 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3375 | // Avoid this check if we know `obj` is not null. |
| 3376 | if (instruction->MustDoNullCheck()) { |
| 3377 | __ Beqz(obj, &done); |
| 3378 | } |
| 3379 | |
| 3380 | switch (type_check_kind) { |
| 3381 | case TypeCheckKind::kExactCheck: |
| 3382 | case TypeCheckKind::kArrayCheck: { |
| 3383 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3384 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3385 | temp_loc, |
| 3386 | obj_loc, |
| 3387 | class_offset, |
| 3388 | maybe_temp2_loc, |
| 3389 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3390 | // Jump to slow path for throwing the exception or doing a |
| 3391 | // more involved array check. |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 3392 | __ Bne(temp, cls.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3393 | break; |
| 3394 | } |
| 3395 | |
| 3396 | case TypeCheckKind::kAbstractClassCheck: { |
| 3397 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3398 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3399 | temp_loc, |
| 3400 | obj_loc, |
| 3401 | class_offset, |
| 3402 | maybe_temp2_loc, |
| 3403 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3404 | // If the class is abstract, we eagerly fetch the super class of the |
| 3405 | // object to avoid doing a comparison we know will fail. |
| 3406 | MipsLabel loop; |
| 3407 | __ Bind(&loop); |
| 3408 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3409 | GenerateReferenceLoadOneRegister(instruction, |
| 3410 | temp_loc, |
| 3411 | super_offset, |
| 3412 | maybe_temp2_loc, |
| 3413 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3414 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3415 | // exception. |
| 3416 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3417 | // Otherwise, compare the classes. |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 3418 | __ Bne(temp, cls.AsRegister<Register>(), &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3419 | break; |
| 3420 | } |
| 3421 | |
| 3422 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3423 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3424 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3425 | temp_loc, |
| 3426 | obj_loc, |
| 3427 | class_offset, |
| 3428 | maybe_temp2_loc, |
| 3429 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3430 | // Walk over the class hierarchy to find a match. |
| 3431 | MipsLabel loop; |
| 3432 | __ Bind(&loop); |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 3433 | __ Beq(temp, cls.AsRegister<Register>(), &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3434 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3435 | GenerateReferenceLoadOneRegister(instruction, |
| 3436 | temp_loc, |
| 3437 | super_offset, |
| 3438 | maybe_temp2_loc, |
| 3439 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3440 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3441 | // exception. Otherwise, jump to the beginning of the loop. |
| 3442 | __ Bnez(temp, &loop); |
| 3443 | __ B(slow_path->GetEntryLabel()); |
| 3444 | break; |
| 3445 | } |
| 3446 | |
| 3447 | case TypeCheckKind::kArrayObjectCheck: { |
| 3448 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3449 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3450 | temp_loc, |
| 3451 | obj_loc, |
| 3452 | class_offset, |
| 3453 | maybe_temp2_loc, |
| 3454 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3455 | // Do an exact check. |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 3456 | __ Beq(temp, cls.AsRegister<Register>(), &done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3457 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 3458 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3459 | GenerateReferenceLoadOneRegister(instruction, |
| 3460 | temp_loc, |
| 3461 | component_offset, |
| 3462 | maybe_temp2_loc, |
| 3463 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3464 | // If the component type is null, jump to the slow path to throw the exception. |
| 3465 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3466 | // Otherwise, the object is indeed an array, further check that this component |
| 3467 | // type is not a primitive type. |
| 3468 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 3469 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3470 | __ Bnez(temp, slow_path->GetEntryLabel()); |
| 3471 | break; |
| 3472 | } |
| 3473 | |
| 3474 | case TypeCheckKind::kUnresolvedCheck: |
| 3475 | // We always go into the type check slow path for the unresolved check case. |
| 3476 | // We cannot directly call the CheckCast runtime entry point |
| 3477 | // without resorting to a type checking slow path here (i.e. by |
| 3478 | // calling InvokeRuntime directly), as it would require to |
| 3479 | // assign fixed registers for the inputs of this HInstanceOf |
| 3480 | // instruction (following the runtime calling convention), which |
| 3481 | // might be cluttered by the potential first read barrier |
| 3482 | // emission at the beginning of this method. |
| 3483 | __ B(slow_path->GetEntryLabel()); |
| 3484 | break; |
| 3485 | |
| 3486 | case TypeCheckKind::kInterfaceCheck: { |
| 3487 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 3488 | // positives by doing this. |
| 3489 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3490 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3491 | temp_loc, |
| 3492 | obj_loc, |
| 3493 | class_offset, |
| 3494 | maybe_temp2_loc, |
| 3495 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3496 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3497 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3498 | temp_loc, |
| 3499 | temp_loc, |
| 3500 | iftable_offset, |
| 3501 | maybe_temp2_loc, |
| 3502 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3503 | // Iftable is never null. |
| 3504 | __ Lw(TMP, temp, array_length_offset); |
| 3505 | // Loop through the iftable and check if any class matches. |
| 3506 | MipsLabel loop; |
| 3507 | __ Bind(&loop); |
| 3508 | __ Addiu(temp, temp, 2 * kHeapReferenceSize); // Possibly in delay slot on R2. |
| 3509 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3510 | __ Lw(AT, temp, object_array_data_offset - 2 * kHeapReferenceSize); |
| 3511 | __ MaybeUnpoisonHeapReference(AT); |
| 3512 | // Go to next interface. |
| 3513 | __ Addiu(TMP, TMP, -2); |
| 3514 | // Compare the classes and continue the loop if they do not match. |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 3515 | __ Bne(AT, cls.AsRegister<Register>(), &loop); |
| 3516 | break; |
| 3517 | } |
| 3518 | |
| 3519 | case TypeCheckKind::kBitstringCheck: { |
| 3520 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3521 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3522 | temp_loc, |
| 3523 | obj_loc, |
| 3524 | class_offset, |
| 3525 | maybe_temp2_loc, |
| 3526 | kWithoutReadBarrier); |
| 3527 | |
| 3528 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 3529 | __ Bnez(temp, slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3530 | break; |
| 3531 | } |
| 3532 | } |
| 3533 | |
| 3534 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3535 | __ Bind(slow_path->GetExitLabel()); |
| 3536 | } |
| 3537 | |
| 3538 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3539 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3540 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3541 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3542 | if (check->HasUses()) { |
| 3543 | locations->SetOut(Location::SameAsFirstInput()); |
| 3544 | } |
| 3545 | } |
| 3546 | |
| 3547 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3548 | // We assume the class is not null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3549 | SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS( |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3550 | check->GetLoadClass(), |
| 3551 | check, |
| 3552 | check->GetDexPc(), |
| 3553 | true); |
| 3554 | codegen_->AddSlowPath(slow_path); |
| 3555 | GenerateClassInitializationCheck(slow_path, |
| 3556 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| 3557 | } |
| 3558 | |
| 3559 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3560 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3561 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3562 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3563 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3564 | |
| 3565 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3566 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3567 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3568 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3569 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3570 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3571 | case DataType::Type::kInt32: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3572 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3573 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3574 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3575 | break; |
| 3576 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3577 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3578 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3579 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3580 | // Output overlaps because it is written before doing the low comparison. |
| 3581 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3582 | break; |
| 3583 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3584 | case DataType::Type::kFloat32: |
| 3585 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3586 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3587 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3588 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3589 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3590 | |
| 3591 | default: |
| 3592 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3593 | } |
| 3594 | } |
| 3595 | |
| 3596 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { |
| 3597 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3598 | Register res = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3599 | DataType::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3600 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3601 | |
| 3602 | // 0 if: left == right |
| 3603 | // 1 if: left > right |
| 3604 | // -1 if: left < right |
| 3605 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3606 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3607 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3608 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3609 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3610 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3611 | case DataType::Type::kInt32: { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3612 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3613 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 3614 | __ Slt(TMP, lhs, rhs); |
| 3615 | __ Slt(res, rhs, lhs); |
| 3616 | __ Subu(res, res, TMP); |
| 3617 | break; |
| 3618 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3619 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3620 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3621 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3622 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3623 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 3624 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 3625 | // TODO: more efficient (direct) comparison with a constant. |
| 3626 | __ Slt(TMP, lhs_high, rhs_high); |
| 3627 | __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt. |
| 3628 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3629 | __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal. |
| 3630 | __ Sltu(TMP, lhs_low, rhs_low); |
| 3631 | __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt. |
| 3632 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3633 | __ Bind(&done); |
| 3634 | break; |
| 3635 | } |
| 3636 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3637 | case DataType::Type::kFloat32: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3638 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3639 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3640 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3641 | MipsLabel done; |
| 3642 | if (isR6) { |
| 3643 | __ CmpEqS(FTMP, lhs, rhs); |
| 3644 | __ LoadConst32(res, 0); |
| 3645 | __ Bc1nez(FTMP, &done); |
| 3646 | if (gt_bias) { |
| 3647 | __ CmpLtS(FTMP, lhs, rhs); |
| 3648 | __ LoadConst32(res, -1); |
| 3649 | __ Bc1nez(FTMP, &done); |
| 3650 | __ LoadConst32(res, 1); |
| 3651 | } else { |
| 3652 | __ CmpLtS(FTMP, rhs, lhs); |
| 3653 | __ LoadConst32(res, 1); |
| 3654 | __ Bc1nez(FTMP, &done); |
| 3655 | __ LoadConst32(res, -1); |
| 3656 | } |
| 3657 | } else { |
| 3658 | if (gt_bias) { |
| 3659 | __ ColtS(0, lhs, rhs); |
| 3660 | __ LoadConst32(res, -1); |
| 3661 | __ Bc1t(0, &done); |
| 3662 | __ CeqS(0, lhs, rhs); |
| 3663 | __ LoadConst32(res, 1); |
| 3664 | __ Movt(res, ZERO, 0); |
| 3665 | } else { |
| 3666 | __ ColtS(0, rhs, lhs); |
| 3667 | __ LoadConst32(res, 1); |
| 3668 | __ Bc1t(0, &done); |
| 3669 | __ CeqS(0, lhs, rhs); |
| 3670 | __ LoadConst32(res, -1); |
| 3671 | __ Movt(res, ZERO, 0); |
| 3672 | } |
| 3673 | } |
| 3674 | __ Bind(&done); |
| 3675 | break; |
| 3676 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3677 | case DataType::Type::kFloat64: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3678 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3679 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3680 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3681 | MipsLabel done; |
| 3682 | if (isR6) { |
| 3683 | __ CmpEqD(FTMP, lhs, rhs); |
| 3684 | __ LoadConst32(res, 0); |
| 3685 | __ Bc1nez(FTMP, &done); |
| 3686 | if (gt_bias) { |
| 3687 | __ CmpLtD(FTMP, lhs, rhs); |
| 3688 | __ LoadConst32(res, -1); |
| 3689 | __ Bc1nez(FTMP, &done); |
| 3690 | __ LoadConst32(res, 1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3691 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3692 | __ CmpLtD(FTMP, rhs, lhs); |
| 3693 | __ LoadConst32(res, 1); |
| 3694 | __ Bc1nez(FTMP, &done); |
| 3695 | __ LoadConst32(res, -1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3696 | } |
| 3697 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3698 | if (gt_bias) { |
| 3699 | __ ColtD(0, lhs, rhs); |
| 3700 | __ LoadConst32(res, -1); |
| 3701 | __ Bc1t(0, &done); |
| 3702 | __ CeqD(0, lhs, rhs); |
| 3703 | __ LoadConst32(res, 1); |
| 3704 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3705 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3706 | __ ColtD(0, rhs, lhs); |
| 3707 | __ LoadConst32(res, 1); |
| 3708 | __ Bc1t(0, &done); |
| 3709 | __ CeqD(0, lhs, rhs); |
| 3710 | __ LoadConst32(res, -1); |
| 3711 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3712 | } |
| 3713 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3714 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3715 | break; |
| 3716 | } |
| 3717 | |
| 3718 | default: |
| 3719 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3720 | } |
| 3721 | } |
| 3722 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3723 | void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3724 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3725 | switch (instruction->InputAt(0)->GetType()) { |
| 3726 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3727 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3728 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3729 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3730 | break; |
| 3731 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3732 | case DataType::Type::kFloat32: |
| 3733 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3734 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3735 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3736 | break; |
| 3737 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3738 | if (!instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3739 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3740 | } |
| 3741 | } |
| 3742 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3743 | void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3744 | if (instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3745 | return; |
| 3746 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3747 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3748 | DataType::Type type = instruction->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3749 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3750 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3751 | switch (type) { |
| 3752 | default: |
| 3753 | // Integer case. |
| 3754 | GenerateIntCompare(instruction->GetCondition(), locations); |
| 3755 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3756 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3757 | case DataType::Type::kInt64: |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 3758 | GenerateLongCompare(instruction->GetCondition(), locations); |
| 3759 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3760 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3761 | case DataType::Type::kFloat32: |
| 3762 | case DataType::Type::kFloat64: |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 3763 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 3764 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3765 | } |
| 3766 | } |
| 3767 | |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3768 | void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3769 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3770 | |
| 3771 | LocationSummary* locations = instruction->GetLocations(); |
| 3772 | Location second = locations->InAt(1); |
| 3773 | DCHECK(second.IsConstant()); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 3774 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3775 | DCHECK(imm == 1 || imm == -1); |
| 3776 | |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 3777 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 3778 | Register out = locations->Out().AsRegister<Register>(); |
| 3779 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3780 | |
| 3781 | if (instruction->IsRem()) { |
| 3782 | __ Move(out, ZERO); |
| 3783 | } else { |
| 3784 | if (imm == -1) { |
| 3785 | __ Subu(out, ZERO, dividend); |
| 3786 | } else if (out != dividend) { |
| 3787 | __ Move(out, dividend); |
| 3788 | } |
| 3789 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3790 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 3791 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 3792 | Register out_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 3793 | Register out_low = locations->Out().AsRegisterPairLow<Register>(); |
| 3794 | Register in_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3795 | Register in_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3796 | |
| 3797 | if (instruction->IsRem()) { |
| 3798 | __ Move(out_high, ZERO); |
| 3799 | __ Move(out_low, ZERO); |
| 3800 | } else { |
| 3801 | if (imm == -1) { |
| 3802 | __ Subu(out_low, ZERO, in_low); |
| 3803 | __ Sltu(AT, ZERO, out_low); |
| 3804 | __ Subu(out_high, ZERO, in_high); |
| 3805 | __ Subu(out_high, out_high, AT); |
| 3806 | } else { |
| 3807 | __ Move(out_low, in_low); |
| 3808 | __ Move(out_high, in_high); |
| 3809 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3810 | } |
| 3811 | } |
| 3812 | } |
| 3813 | |
| 3814 | void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3815 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3816 | |
| 3817 | LocationSummary* locations = instruction->GetLocations(); |
| 3818 | Location second = locations->InAt(1); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 3819 | const bool is_r2_or_newer = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
| 3820 | const bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3821 | DCHECK(second.IsConstant()); |
| 3822 | |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 3823 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 3824 | Register out = locations->Out().AsRegister<Register>(); |
| 3825 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3826 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3827 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 3828 | int ctz_imm = CTZ(abs_imm); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3829 | |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 3830 | if (instruction->IsDiv()) { |
| 3831 | if (ctz_imm == 1) { |
| 3832 | // Fast path for division by +/-2, which is very common. |
| 3833 | __ Srl(TMP, dividend, 31); |
| 3834 | } else { |
| 3835 | __ Sra(TMP, dividend, 31); |
| 3836 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3837 | } |
| 3838 | __ Addu(out, dividend, TMP); |
| 3839 | __ Sra(out, out, ctz_imm); |
| 3840 | if (imm < 0) { |
| 3841 | __ Subu(out, ZERO, out); |
| 3842 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3843 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 3844 | if (ctz_imm == 1) { |
| 3845 | // Fast path for modulo +/-2, which is very common. |
| 3846 | __ Sra(TMP, dividend, 31); |
| 3847 | __ Subu(out, dividend, TMP); |
| 3848 | __ Andi(out, out, 1); |
| 3849 | __ Addu(out, out, TMP); |
| 3850 | } else { |
| 3851 | __ Sra(TMP, dividend, 31); |
| 3852 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3853 | __ Addu(out, dividend, TMP); |
| 3854 | if (IsUint<16>(abs_imm - 1)) { |
| 3855 | __ Andi(out, out, abs_imm - 1); |
| 3856 | } else { |
| 3857 | if (is_r2_or_newer) { |
| 3858 | __ Ins(out, ZERO, ctz_imm, 32 - ctz_imm); |
| 3859 | } else { |
| 3860 | __ Sll(out, out, 32 - ctz_imm); |
| 3861 | __ Srl(out, out, 32 - ctz_imm); |
| 3862 | } |
| 3863 | } |
| 3864 | __ Subu(out, out, TMP); |
| 3865 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3866 | } |
| 3867 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 3868 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 3869 | Register out_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 3870 | Register out_low = locations->Out().AsRegisterPairLow<Register>(); |
| 3871 | Register in_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3872 | Register in_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3873 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3874 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 3875 | int ctz_imm = CTZ(abs_imm); |
| 3876 | |
| 3877 | if (instruction->IsDiv()) { |
| 3878 | if (ctz_imm < 32) { |
| 3879 | if (ctz_imm == 1) { |
| 3880 | __ Srl(AT, in_high, 31); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3881 | } else { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 3882 | __ Sra(AT, in_high, 31); |
| 3883 | __ Srl(AT, AT, 32 - ctz_imm); |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3884 | } |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 3885 | __ Addu(AT, AT, in_low); |
| 3886 | __ Sltu(TMP, AT, in_low); |
| 3887 | __ Addu(out_high, in_high, TMP); |
| 3888 | __ Srl(out_low, AT, ctz_imm); |
| 3889 | if (is_r2_or_newer) { |
| 3890 | __ Ins(out_low, out_high, 32 - ctz_imm, ctz_imm); |
| 3891 | __ Sra(out_high, out_high, ctz_imm); |
| 3892 | } else { |
| 3893 | __ Sll(AT, out_high, 32 - ctz_imm); |
| 3894 | __ Sra(out_high, out_high, ctz_imm); |
| 3895 | __ Or(out_low, out_low, AT); |
| 3896 | } |
| 3897 | if (imm < 0) { |
| 3898 | __ Subu(out_low, ZERO, out_low); |
| 3899 | __ Sltu(AT, ZERO, out_low); |
| 3900 | __ Subu(out_high, ZERO, out_high); |
| 3901 | __ Subu(out_high, out_high, AT); |
| 3902 | } |
| 3903 | } else if (ctz_imm == 32) { |
| 3904 | __ Sra(AT, in_high, 31); |
| 3905 | __ Addu(AT, AT, in_low); |
| 3906 | __ Sltu(AT, AT, in_low); |
| 3907 | __ Addu(out_low, in_high, AT); |
| 3908 | if (imm < 0) { |
| 3909 | __ Srl(TMP, out_low, 31); |
| 3910 | __ Subu(out_low, ZERO, out_low); |
| 3911 | __ Sltu(AT, ZERO, out_low); |
| 3912 | __ Subu(out_high, TMP, AT); |
| 3913 | } else { |
| 3914 | __ Sra(out_high, out_low, 31); |
| 3915 | } |
| 3916 | } else if (ctz_imm < 63) { |
| 3917 | __ Sra(AT, in_high, 31); |
| 3918 | __ Srl(TMP, AT, 64 - ctz_imm); |
| 3919 | __ Addu(AT, AT, in_low); |
| 3920 | __ Sltu(AT, AT, in_low); |
| 3921 | __ Addu(out_low, in_high, AT); |
| 3922 | __ Addu(out_low, out_low, TMP); |
| 3923 | __ Sra(out_low, out_low, ctz_imm - 32); |
| 3924 | if (imm < 0) { |
| 3925 | __ Subu(out_low, ZERO, out_low); |
| 3926 | } |
| 3927 | __ Sra(out_high, out_low, 31); |
| 3928 | } else { |
| 3929 | DCHECK_LT(imm, 0); |
| 3930 | if (is_r6) { |
| 3931 | __ Aui(AT, in_high, 0x8000); |
| 3932 | } else { |
| 3933 | __ Lui(AT, 0x8000); |
| 3934 | __ Xor(AT, AT, in_high); |
| 3935 | } |
| 3936 | __ Or(AT, AT, in_low); |
| 3937 | __ Sltiu(out_low, AT, 1); |
| 3938 | __ Move(out_high, ZERO); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3939 | } |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 3940 | } else { |
| 3941 | if ((ctz_imm == 1) && !is_r6) { |
| 3942 | __ Andi(AT, in_low, 1); |
| 3943 | __ Sll(TMP, in_low, 31); |
| 3944 | __ And(TMP, in_high, TMP); |
| 3945 | __ Sra(out_high, TMP, 31); |
| 3946 | __ Or(out_low, out_high, AT); |
| 3947 | } else if (ctz_imm < 32) { |
| 3948 | __ Sra(AT, in_high, 31); |
| 3949 | if (ctz_imm <= 16) { |
| 3950 | __ Andi(out_low, in_low, abs_imm - 1); |
| 3951 | } else if (is_r2_or_newer) { |
| 3952 | __ Ext(out_low, in_low, 0, ctz_imm); |
| 3953 | } else { |
| 3954 | __ Sll(out_low, in_low, 32 - ctz_imm); |
| 3955 | __ Srl(out_low, out_low, 32 - ctz_imm); |
| 3956 | } |
| 3957 | if (is_r6) { |
| 3958 | __ Selnez(out_high, AT, out_low); |
| 3959 | } else { |
| 3960 | __ Movz(AT, ZERO, out_low); |
| 3961 | __ Move(out_high, AT); |
| 3962 | } |
| 3963 | if (is_r2_or_newer) { |
| 3964 | __ Ins(out_low, out_high, ctz_imm, 32 - ctz_imm); |
| 3965 | } else { |
| 3966 | __ Sll(AT, out_high, ctz_imm); |
| 3967 | __ Or(out_low, out_low, AT); |
| 3968 | } |
| 3969 | } else if (ctz_imm == 32) { |
| 3970 | __ Sra(AT, in_high, 31); |
| 3971 | __ Move(out_low, in_low); |
| 3972 | if (is_r6) { |
| 3973 | __ Selnez(out_high, AT, out_low); |
| 3974 | } else { |
| 3975 | __ Movz(AT, ZERO, out_low); |
| 3976 | __ Move(out_high, AT); |
| 3977 | } |
| 3978 | } else if (ctz_imm < 63) { |
| 3979 | __ Sra(AT, in_high, 31); |
| 3980 | __ Move(TMP, in_low); |
| 3981 | if (ctz_imm - 32 <= 16) { |
| 3982 | __ Andi(out_high, in_high, (1 << (ctz_imm - 32)) - 1); |
| 3983 | } else if (is_r2_or_newer) { |
| 3984 | __ Ext(out_high, in_high, 0, ctz_imm - 32); |
| 3985 | } else { |
| 3986 | __ Sll(out_high, in_high, 64 - ctz_imm); |
| 3987 | __ Srl(out_high, out_high, 64 - ctz_imm); |
| 3988 | } |
| 3989 | __ Move(out_low, TMP); |
| 3990 | __ Or(TMP, TMP, out_high); |
| 3991 | if (is_r6) { |
| 3992 | __ Selnez(AT, AT, TMP); |
| 3993 | } else { |
| 3994 | __ Movz(AT, ZERO, TMP); |
| 3995 | } |
| 3996 | if (is_r2_or_newer) { |
| 3997 | __ Ins(out_high, AT, ctz_imm - 32, 64 - ctz_imm); |
| 3998 | } else { |
| 3999 | __ Sll(AT, AT, ctz_imm - 32); |
| 4000 | __ Or(out_high, out_high, AT); |
| 4001 | } |
| 4002 | } else { |
| 4003 | if (is_r6) { |
| 4004 | __ Aui(AT, in_high, 0x8000); |
| 4005 | } else { |
| 4006 | __ Lui(AT, 0x8000); |
| 4007 | __ Xor(AT, AT, in_high); |
| 4008 | } |
| 4009 | __ Or(AT, AT, in_low); |
| 4010 | __ Sltiu(AT, AT, 1); |
| 4011 | __ Sll(AT, AT, 31); |
| 4012 | __ Move(out_low, in_low); |
| 4013 | __ Xor(out_high, in_high, AT); |
| 4014 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4015 | } |
| 4016 | } |
| 4017 | } |
| 4018 | |
| 4019 | void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4020 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4021 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4022 | |
| 4023 | LocationSummary* locations = instruction->GetLocations(); |
| 4024 | Location second = locations->InAt(1); |
| 4025 | DCHECK(second.IsConstant()); |
| 4026 | |
| 4027 | Register out = locations->Out().AsRegister<Register>(); |
| 4028 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4029 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4030 | |
| 4031 | int64_t magic; |
| 4032 | int shift; |
| 4033 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4034 | |
| 4035 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4036 | |
| 4037 | __ LoadConst32(TMP, magic); |
| 4038 | if (isR6) { |
| 4039 | __ MuhR6(TMP, dividend, TMP); |
| 4040 | } else { |
| 4041 | __ MultR2(dividend, TMP); |
| 4042 | __ Mfhi(TMP); |
| 4043 | } |
| 4044 | if (imm > 0 && magic < 0) { |
| 4045 | __ Addu(TMP, TMP, dividend); |
| 4046 | } else if (imm < 0 && magic > 0) { |
| 4047 | __ Subu(TMP, TMP, dividend); |
| 4048 | } |
| 4049 | |
| 4050 | if (shift != 0) { |
| 4051 | __ Sra(TMP, TMP, shift); |
| 4052 | } |
| 4053 | |
| 4054 | if (instruction->IsDiv()) { |
| 4055 | __ Sra(out, TMP, 31); |
| 4056 | __ Subu(out, TMP, out); |
| 4057 | } else { |
| 4058 | __ Sra(AT, TMP, 31); |
| 4059 | __ Subu(AT, TMP, AT); |
| 4060 | __ LoadConst32(TMP, imm); |
| 4061 | if (isR6) { |
| 4062 | __ MulR6(TMP, AT, TMP); |
| 4063 | } else { |
| 4064 | __ MulR2(TMP, AT, TMP); |
| 4065 | } |
| 4066 | __ Subu(out, dividend, TMP); |
| 4067 | } |
| 4068 | } |
| 4069 | |
| 4070 | void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 4071 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4072 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4073 | |
| 4074 | LocationSummary* locations = instruction->GetLocations(); |
| 4075 | Register out = locations->Out().AsRegister<Register>(); |
| 4076 | Location second = locations->InAt(1); |
| 4077 | |
| 4078 | if (second.IsConstant()) { |
| 4079 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4080 | if (imm == 0) { |
| 4081 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4082 | } else if (imm == 1 || imm == -1) { |
| 4083 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4084 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4085 | DivRemByPowerOfTwo(instruction); |
| 4086 | } else { |
| 4087 | DCHECK(imm <= -2 || imm >= 2); |
| 4088 | GenerateDivRemWithAnyConstant(instruction); |
| 4089 | } |
| 4090 | } else { |
| 4091 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4092 | Register divisor = second.AsRegister<Register>(); |
| 4093 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4094 | if (instruction->IsDiv()) { |
| 4095 | if (isR6) { |
| 4096 | __ DivR6(out, dividend, divisor); |
| 4097 | } else { |
| 4098 | __ DivR2(out, dividend, divisor); |
| 4099 | } |
| 4100 | } else { |
| 4101 | if (isR6) { |
| 4102 | __ ModR6(out, dividend, divisor); |
| 4103 | } else { |
| 4104 | __ ModR2(out, dividend, divisor); |
| 4105 | } |
| 4106 | } |
| 4107 | } |
| 4108 | } |
| 4109 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4110 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4111 | DataType::Type type = div->GetResultType(); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 4112 | bool call_long_div = false; |
| 4113 | if (type == DataType::Type::kInt64) { |
| 4114 | if (div->InputAt(1)->IsConstant()) { |
| 4115 | int64_t imm = CodeGenerator::GetInt64ValueOf(div->InputAt(1)->AsConstant()); |
| 4116 | call_long_div = (imm != 0) && !IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm))); |
| 4117 | } else { |
| 4118 | call_long_div = true; |
| 4119 | } |
| 4120 | } |
| 4121 | LocationSummary::CallKind call_kind = call_long_div |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4122 | ? LocationSummary::kCallOnMainOnly |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4123 | : LocationSummary::kNoCall; |
| 4124 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4125 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4126 | |
| 4127 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4128 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4129 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4130 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4131 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4132 | break; |
| 4133 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4134 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 4135 | if (call_long_div) { |
| 4136 | InvokeRuntimeCallingConvention calling_convention; |
| 4137 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4138 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4139 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4140 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4141 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4142 | } else { |
| 4143 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4144 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 4145 | locations->SetOut(Location::RequiresRegister()); |
| 4146 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4147 | break; |
| 4148 | } |
| 4149 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4150 | case DataType::Type::kFloat32: |
| 4151 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4152 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4153 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4154 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4155 | break; |
| 4156 | |
| 4157 | default: |
| 4158 | LOG(FATAL) << "Unexpected div type " << type; |
| 4159 | } |
| 4160 | } |
| 4161 | |
| 4162 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4163 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4164 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4165 | |
| 4166 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4167 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4168 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4169 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4170 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 4171 | if (locations->InAt(1).IsConstant()) { |
| 4172 | int64_t imm = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue(); |
| 4173 | if (imm == 0) { |
| 4174 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4175 | } else if (imm == 1 || imm == -1) { |
| 4176 | DivRemOneOrMinusOne(instruction); |
| 4177 | } else { |
| 4178 | DCHECK(IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm)))); |
| 4179 | DivRemByPowerOfTwo(instruction); |
| 4180 | } |
| 4181 | } else { |
| 4182 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
| 4183 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| 4184 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4185 | break; |
| 4186 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4187 | case DataType::Type::kFloat32: |
| 4188 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4189 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 4190 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4191 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4192 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4193 | __ DivS(dst, lhs, rhs); |
| 4194 | } else { |
| 4195 | __ DivD(dst, lhs, rhs); |
| 4196 | } |
| 4197 | break; |
| 4198 | } |
| 4199 | default: |
| 4200 | LOG(FATAL) << "Unexpected div type " << type; |
| 4201 | } |
| 4202 | } |
| 4203 | |
| 4204 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4205 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4206 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4207 | } |
| 4208 | |
| 4209 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4210 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4211 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4212 | codegen_->AddSlowPath(slow_path); |
| 4213 | Location value = instruction->GetLocations()->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4214 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4215 | |
| 4216 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4217 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4218 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4219 | case DataType::Type::kInt8: |
| 4220 | case DataType::Type::kUint16: |
| 4221 | case DataType::Type::kInt16: |
| 4222 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4223 | if (value.IsConstant()) { |
| 4224 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 4225 | __ B(slow_path->GetEntryLabel()); |
| 4226 | } else { |
| 4227 | // A division by a non-null constant is valid. We don't need to perform |
| 4228 | // any check, so simply fall through. |
| 4229 | } |
| 4230 | } else { |
| 4231 | DCHECK(value.IsRegister()) << value; |
| 4232 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 4233 | } |
| 4234 | break; |
| 4235 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4236 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4237 | if (value.IsConstant()) { |
| 4238 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4239 | __ B(slow_path->GetEntryLabel()); |
| 4240 | } else { |
| 4241 | // A division by a non-null constant is valid. We don't need to perform |
| 4242 | // any check, so simply fall through. |
| 4243 | } |
| 4244 | } else { |
| 4245 | DCHECK(value.IsRegisterPair()) << value; |
| 4246 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); |
| 4247 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 4248 | } |
| 4249 | break; |
| 4250 | } |
| 4251 | default: |
| 4252 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| 4253 | } |
| 4254 | } |
| 4255 | |
| 4256 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { |
| 4257 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4258 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4259 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4260 | } |
| 4261 | |
| 4262 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 4263 | // Will be generated at use site. |
| 4264 | } |
| 4265 | |
| 4266 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { |
| 4267 | exit->SetLocations(nullptr); |
| 4268 | } |
| 4269 | |
| 4270 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 4271 | } |
| 4272 | |
| 4273 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { |
| 4274 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4275 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4276 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4277 | } |
| 4278 | |
| 4279 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 4280 | // Will be generated at use site. |
| 4281 | } |
| 4282 | |
| 4283 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { |
| 4284 | got->SetLocations(nullptr); |
| 4285 | } |
| 4286 | |
| 4287 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4288 | if (successor->IsExitBlock()) { |
| 4289 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 4290 | return; // no code needed |
| 4291 | } |
| 4292 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4293 | HBasicBlock* block = got->GetBlock(); |
| 4294 | HInstruction* previous = got->GetPrevious(); |
| 4295 | HLoopInformation* info = block->GetLoopInformation(); |
| 4296 | |
| 4297 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4298 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 4299 | return; |
| 4300 | } |
| 4301 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 4302 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 4303 | } |
| 4304 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 4305 | __ B(codegen_->GetLabelOf(successor)); |
| 4306 | } |
| 4307 | } |
| 4308 | |
| 4309 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { |
| 4310 | HandleGoto(got, got->GetSuccessor()); |
| 4311 | } |
| 4312 | |
| 4313 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 4314 | try_boundary->SetLocations(nullptr); |
| 4315 | } |
| 4316 | |
| 4317 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 4318 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 4319 | if (!successor->IsExitBlock()) { |
| 4320 | HandleGoto(try_boundary, successor); |
| 4321 | } |
| 4322 | } |
| 4323 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4324 | void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond, |
| 4325 | LocationSummary* locations) { |
| 4326 | Register dst = locations->Out().AsRegister<Register>(); |
| 4327 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4328 | Location rhs_location = locations->InAt(1); |
| 4329 | Register rhs_reg = ZERO; |
| 4330 | int64_t rhs_imm = 0; |
| 4331 | bool use_imm = rhs_location.IsConstant(); |
| 4332 | if (use_imm) { |
| 4333 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4334 | } else { |
| 4335 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4336 | } |
| 4337 | |
| 4338 | switch (cond) { |
| 4339 | case kCondEQ: |
| 4340 | case kCondNE: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4341 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4342 | if (rhs_imm == 0) { |
| 4343 | if (cond == kCondEQ) { |
| 4344 | __ Sltiu(dst, lhs, 1); |
| 4345 | } else { |
| 4346 | __ Sltu(dst, ZERO, lhs); |
| 4347 | } |
| 4348 | } else { |
| 4349 | __ Addiu(dst, lhs, -rhs_imm); |
| 4350 | if (cond == kCondEQ) { |
| 4351 | __ Sltiu(dst, dst, 1); |
| 4352 | } else { |
| 4353 | __ Sltu(dst, ZERO, dst); |
| 4354 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4355 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4356 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4357 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 4358 | __ Xori(dst, lhs, rhs_imm); |
| 4359 | } else { |
| 4360 | if (use_imm) { |
| 4361 | rhs_reg = TMP; |
| 4362 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4363 | } |
| 4364 | __ Xor(dst, lhs, rhs_reg); |
| 4365 | } |
| 4366 | if (cond == kCondEQ) { |
| 4367 | __ Sltiu(dst, dst, 1); |
| 4368 | } else { |
| 4369 | __ Sltu(dst, ZERO, dst); |
| 4370 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4371 | } |
| 4372 | break; |
| 4373 | |
| 4374 | case kCondLT: |
| 4375 | case kCondGE: |
| 4376 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4377 | __ Slti(dst, lhs, rhs_imm); |
| 4378 | } else { |
| 4379 | if (use_imm) { |
| 4380 | rhs_reg = TMP; |
| 4381 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4382 | } |
| 4383 | __ Slt(dst, lhs, rhs_reg); |
| 4384 | } |
| 4385 | if (cond == kCondGE) { |
| 4386 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4387 | // only the slt instruction but no sge. |
| 4388 | __ Xori(dst, dst, 1); |
| 4389 | } |
| 4390 | break; |
| 4391 | |
| 4392 | case kCondLE: |
| 4393 | case kCondGT: |
| 4394 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4395 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4396 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4397 | if (cond == kCondGT) { |
| 4398 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4399 | // only the slti instruction but no sgti. |
| 4400 | __ Xori(dst, dst, 1); |
| 4401 | } |
| 4402 | } else { |
| 4403 | if (use_imm) { |
| 4404 | rhs_reg = TMP; |
| 4405 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4406 | } |
| 4407 | __ Slt(dst, rhs_reg, lhs); |
| 4408 | if (cond == kCondLE) { |
| 4409 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4410 | // only the slt instruction but no sle. |
| 4411 | __ Xori(dst, dst, 1); |
| 4412 | } |
| 4413 | } |
| 4414 | break; |
| 4415 | |
| 4416 | case kCondB: |
| 4417 | case kCondAE: |
| 4418 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4419 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4420 | // the comparison and thus lets us compare directly with |
| 4421 | // unsigned values in the ranges [0, 0x7fff] and |
| 4422 | // [0xffff8000, 0xffffffff]. |
| 4423 | __ Sltiu(dst, lhs, rhs_imm); |
| 4424 | } else { |
| 4425 | if (use_imm) { |
| 4426 | rhs_reg = TMP; |
| 4427 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4428 | } |
| 4429 | __ Sltu(dst, lhs, rhs_reg); |
| 4430 | } |
| 4431 | if (cond == kCondAE) { |
| 4432 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4433 | // only the sltu instruction but no sgeu. |
| 4434 | __ Xori(dst, dst, 1); |
| 4435 | } |
| 4436 | break; |
| 4437 | |
| 4438 | case kCondBE: |
| 4439 | case kCondA: |
| 4440 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4441 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4442 | // Note that this only works if rhs + 1 does not overflow |
| 4443 | // to 0, hence the check above. |
| 4444 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4445 | // the comparison and thus lets us compare directly with |
| 4446 | // unsigned values in the ranges [0, 0x7fff] and |
| 4447 | // [0xffff8000, 0xffffffff]. |
| 4448 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4449 | if (cond == kCondA) { |
| 4450 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4451 | // only the sltiu instruction but no sgtiu. |
| 4452 | __ Xori(dst, dst, 1); |
| 4453 | } |
| 4454 | } else { |
| 4455 | if (use_imm) { |
| 4456 | rhs_reg = TMP; |
| 4457 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4458 | } |
| 4459 | __ Sltu(dst, rhs_reg, lhs); |
| 4460 | if (cond == kCondBE) { |
| 4461 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4462 | // only the sltu instruction but no sleu. |
| 4463 | __ Xori(dst, dst, 1); |
| 4464 | } |
| 4465 | } |
| 4466 | break; |
| 4467 | } |
| 4468 | } |
| 4469 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4470 | bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond, |
| 4471 | LocationSummary* input_locations, |
| 4472 | Register dst) { |
| 4473 | Register lhs = input_locations->InAt(0).AsRegister<Register>(); |
| 4474 | Location rhs_location = input_locations->InAt(1); |
| 4475 | Register rhs_reg = ZERO; |
| 4476 | int64_t rhs_imm = 0; |
| 4477 | bool use_imm = rhs_location.IsConstant(); |
| 4478 | if (use_imm) { |
| 4479 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4480 | } else { |
| 4481 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4482 | } |
| 4483 | |
| 4484 | switch (cond) { |
| 4485 | case kCondEQ: |
| 4486 | case kCondNE: |
| 4487 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4488 | __ Addiu(dst, lhs, -rhs_imm); |
| 4489 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 4490 | __ Xori(dst, lhs, rhs_imm); |
| 4491 | } else { |
| 4492 | if (use_imm) { |
| 4493 | rhs_reg = TMP; |
| 4494 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4495 | } |
| 4496 | __ Xor(dst, lhs, rhs_reg); |
| 4497 | } |
| 4498 | return (cond == kCondEQ); |
| 4499 | |
| 4500 | case kCondLT: |
| 4501 | case kCondGE: |
| 4502 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4503 | __ Slti(dst, lhs, rhs_imm); |
| 4504 | } else { |
| 4505 | if (use_imm) { |
| 4506 | rhs_reg = TMP; |
| 4507 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4508 | } |
| 4509 | __ Slt(dst, lhs, rhs_reg); |
| 4510 | } |
| 4511 | return (cond == kCondGE); |
| 4512 | |
| 4513 | case kCondLE: |
| 4514 | case kCondGT: |
| 4515 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4516 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4517 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4518 | return (cond == kCondGT); |
| 4519 | } else { |
| 4520 | if (use_imm) { |
| 4521 | rhs_reg = TMP; |
| 4522 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4523 | } |
| 4524 | __ Slt(dst, rhs_reg, lhs); |
| 4525 | return (cond == kCondLE); |
| 4526 | } |
| 4527 | |
| 4528 | case kCondB: |
| 4529 | case kCondAE: |
| 4530 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4531 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4532 | // the comparison and thus lets us compare directly with |
| 4533 | // unsigned values in the ranges [0, 0x7fff] and |
| 4534 | // [0xffff8000, 0xffffffff]. |
| 4535 | __ Sltiu(dst, lhs, rhs_imm); |
| 4536 | } else { |
| 4537 | if (use_imm) { |
| 4538 | rhs_reg = TMP; |
| 4539 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4540 | } |
| 4541 | __ Sltu(dst, lhs, rhs_reg); |
| 4542 | } |
| 4543 | return (cond == kCondAE); |
| 4544 | |
| 4545 | case kCondBE: |
| 4546 | case kCondA: |
| 4547 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4548 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4549 | // Note that this only works if rhs + 1 does not overflow |
| 4550 | // to 0, hence the check above. |
| 4551 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4552 | // the comparison and thus lets us compare directly with |
| 4553 | // unsigned values in the ranges [0, 0x7fff] and |
| 4554 | // [0xffff8000, 0xffffffff]. |
| 4555 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4556 | return (cond == kCondA); |
| 4557 | } else { |
| 4558 | if (use_imm) { |
| 4559 | rhs_reg = TMP; |
| 4560 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4561 | } |
| 4562 | __ Sltu(dst, rhs_reg, lhs); |
| 4563 | return (cond == kCondBE); |
| 4564 | } |
| 4565 | } |
| 4566 | } |
| 4567 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4568 | void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond, |
| 4569 | LocationSummary* locations, |
| 4570 | MipsLabel* label) { |
| 4571 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4572 | Location rhs_location = locations->InAt(1); |
| 4573 | Register rhs_reg = ZERO; |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4574 | int64_t rhs_imm = 0; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4575 | bool use_imm = rhs_location.IsConstant(); |
| 4576 | if (use_imm) { |
| 4577 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4578 | } else { |
| 4579 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4580 | } |
| 4581 | |
| 4582 | if (use_imm && rhs_imm == 0) { |
| 4583 | switch (cond) { |
| 4584 | case kCondEQ: |
| 4585 | case kCondBE: // <= 0 if zero |
| 4586 | __ Beqz(lhs, label); |
| 4587 | break; |
| 4588 | case kCondNE: |
| 4589 | case kCondA: // > 0 if non-zero |
| 4590 | __ Bnez(lhs, label); |
| 4591 | break; |
| 4592 | case kCondLT: |
| 4593 | __ Bltz(lhs, label); |
| 4594 | break; |
| 4595 | case kCondGE: |
| 4596 | __ Bgez(lhs, label); |
| 4597 | break; |
| 4598 | case kCondLE: |
| 4599 | __ Blez(lhs, label); |
| 4600 | break; |
| 4601 | case kCondGT: |
| 4602 | __ Bgtz(lhs, label); |
| 4603 | break; |
| 4604 | case kCondB: // always false |
| 4605 | break; |
| 4606 | case kCondAE: // always true |
| 4607 | __ B(label); |
| 4608 | break; |
| 4609 | } |
| 4610 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4611 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4612 | if (isR6 || !use_imm) { |
| 4613 | if (use_imm) { |
| 4614 | rhs_reg = TMP; |
| 4615 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4616 | } |
| 4617 | switch (cond) { |
| 4618 | case kCondEQ: |
| 4619 | __ Beq(lhs, rhs_reg, label); |
| 4620 | break; |
| 4621 | case kCondNE: |
| 4622 | __ Bne(lhs, rhs_reg, label); |
| 4623 | break; |
| 4624 | case kCondLT: |
| 4625 | __ Blt(lhs, rhs_reg, label); |
| 4626 | break; |
| 4627 | case kCondGE: |
| 4628 | __ Bge(lhs, rhs_reg, label); |
| 4629 | break; |
| 4630 | case kCondLE: |
| 4631 | __ Bge(rhs_reg, lhs, label); |
| 4632 | break; |
| 4633 | case kCondGT: |
| 4634 | __ Blt(rhs_reg, lhs, label); |
| 4635 | break; |
| 4636 | case kCondB: |
| 4637 | __ Bltu(lhs, rhs_reg, label); |
| 4638 | break; |
| 4639 | case kCondAE: |
| 4640 | __ Bgeu(lhs, rhs_reg, label); |
| 4641 | break; |
| 4642 | case kCondBE: |
| 4643 | __ Bgeu(rhs_reg, lhs, label); |
| 4644 | break; |
| 4645 | case kCondA: |
| 4646 | __ Bltu(rhs_reg, lhs, label); |
| 4647 | break; |
| 4648 | } |
| 4649 | } else { |
| 4650 | // Special cases for more efficient comparison with constants on R2. |
| 4651 | switch (cond) { |
| 4652 | case kCondEQ: |
| 4653 | __ LoadConst32(TMP, rhs_imm); |
| 4654 | __ Beq(lhs, TMP, label); |
| 4655 | break; |
| 4656 | case kCondNE: |
| 4657 | __ LoadConst32(TMP, rhs_imm); |
| 4658 | __ Bne(lhs, TMP, label); |
| 4659 | break; |
| 4660 | case kCondLT: |
| 4661 | if (IsInt<16>(rhs_imm)) { |
| 4662 | __ Slti(TMP, lhs, rhs_imm); |
| 4663 | __ Bnez(TMP, label); |
| 4664 | } else { |
| 4665 | __ LoadConst32(TMP, rhs_imm); |
| 4666 | __ Blt(lhs, TMP, label); |
| 4667 | } |
| 4668 | break; |
| 4669 | case kCondGE: |
| 4670 | if (IsInt<16>(rhs_imm)) { |
| 4671 | __ Slti(TMP, lhs, rhs_imm); |
| 4672 | __ Beqz(TMP, label); |
| 4673 | } else { |
| 4674 | __ LoadConst32(TMP, rhs_imm); |
| 4675 | __ Bge(lhs, TMP, label); |
| 4676 | } |
| 4677 | break; |
| 4678 | case kCondLE: |
| 4679 | if (IsInt<16>(rhs_imm + 1)) { |
| 4680 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4681 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4682 | __ Bnez(TMP, label); |
| 4683 | } else { |
| 4684 | __ LoadConst32(TMP, rhs_imm); |
| 4685 | __ Bge(TMP, lhs, label); |
| 4686 | } |
| 4687 | break; |
| 4688 | case kCondGT: |
| 4689 | if (IsInt<16>(rhs_imm + 1)) { |
| 4690 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4691 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4692 | __ Beqz(TMP, label); |
| 4693 | } else { |
| 4694 | __ LoadConst32(TMP, rhs_imm); |
| 4695 | __ Blt(TMP, lhs, label); |
| 4696 | } |
| 4697 | break; |
| 4698 | case kCondB: |
| 4699 | if (IsInt<16>(rhs_imm)) { |
| 4700 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4701 | __ Bnez(TMP, label); |
| 4702 | } else { |
| 4703 | __ LoadConst32(TMP, rhs_imm); |
| 4704 | __ Bltu(lhs, TMP, label); |
| 4705 | } |
| 4706 | break; |
| 4707 | case kCondAE: |
| 4708 | if (IsInt<16>(rhs_imm)) { |
| 4709 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4710 | __ Beqz(TMP, label); |
| 4711 | } else { |
| 4712 | __ LoadConst32(TMP, rhs_imm); |
| 4713 | __ Bgeu(lhs, TMP, label); |
| 4714 | } |
| 4715 | break; |
| 4716 | case kCondBE: |
| 4717 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4718 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4719 | // Note that this only works if rhs + 1 does not overflow |
| 4720 | // to 0, hence the check above. |
| 4721 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4722 | __ Bnez(TMP, label); |
| 4723 | } else { |
| 4724 | __ LoadConst32(TMP, rhs_imm); |
| 4725 | __ Bgeu(TMP, lhs, label); |
| 4726 | } |
| 4727 | break; |
| 4728 | case kCondA: |
| 4729 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4730 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4731 | // Note that this only works if rhs + 1 does not overflow |
| 4732 | // to 0, hence the check above. |
| 4733 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4734 | __ Beqz(TMP, label); |
| 4735 | } else { |
| 4736 | __ LoadConst32(TMP, rhs_imm); |
| 4737 | __ Bltu(TMP, lhs, label); |
| 4738 | } |
| 4739 | break; |
| 4740 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4741 | } |
| 4742 | } |
| 4743 | } |
| 4744 | |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 4745 | void InstructionCodeGeneratorMIPS::GenerateLongCompare(IfCondition cond, |
| 4746 | LocationSummary* locations) { |
| 4747 | Register dst = locations->Out().AsRegister<Register>(); |
| 4748 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4749 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4750 | Location rhs_location = locations->InAt(1); |
| 4751 | Register rhs_high = ZERO; |
| 4752 | Register rhs_low = ZERO; |
| 4753 | int64_t imm = 0; |
| 4754 | uint32_t imm_high = 0; |
| 4755 | uint32_t imm_low = 0; |
| 4756 | bool use_imm = rhs_location.IsConstant(); |
| 4757 | if (use_imm) { |
| 4758 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 4759 | imm_high = High32Bits(imm); |
| 4760 | imm_low = Low32Bits(imm); |
| 4761 | } else { |
| 4762 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 4763 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 4764 | } |
| 4765 | if (use_imm && imm == 0) { |
| 4766 | switch (cond) { |
| 4767 | case kCondEQ: |
| 4768 | case kCondBE: // <= 0 if zero |
| 4769 | __ Or(dst, lhs_high, lhs_low); |
| 4770 | __ Sltiu(dst, dst, 1); |
| 4771 | break; |
| 4772 | case kCondNE: |
| 4773 | case kCondA: // > 0 if non-zero |
| 4774 | __ Or(dst, lhs_high, lhs_low); |
| 4775 | __ Sltu(dst, ZERO, dst); |
| 4776 | break; |
| 4777 | case kCondLT: |
| 4778 | __ Slt(dst, lhs_high, ZERO); |
| 4779 | break; |
| 4780 | case kCondGE: |
| 4781 | __ Slt(dst, lhs_high, ZERO); |
| 4782 | __ Xori(dst, dst, 1); |
| 4783 | break; |
| 4784 | case kCondLE: |
| 4785 | __ Or(TMP, lhs_high, lhs_low); |
| 4786 | __ Sra(AT, lhs_high, 31); |
| 4787 | __ Sltu(dst, AT, TMP); |
| 4788 | __ Xori(dst, dst, 1); |
| 4789 | break; |
| 4790 | case kCondGT: |
| 4791 | __ Or(TMP, lhs_high, lhs_low); |
| 4792 | __ Sra(AT, lhs_high, 31); |
| 4793 | __ Sltu(dst, AT, TMP); |
| 4794 | break; |
| 4795 | case kCondB: // always false |
| 4796 | __ Andi(dst, dst, 0); |
| 4797 | break; |
| 4798 | case kCondAE: // always true |
| 4799 | __ Ori(dst, ZERO, 1); |
| 4800 | break; |
| 4801 | } |
| 4802 | } else if (use_imm) { |
| 4803 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 4804 | switch (cond) { |
| 4805 | case kCondEQ: |
| 4806 | __ LoadConst32(TMP, imm_high); |
| 4807 | __ Xor(TMP, TMP, lhs_high); |
| 4808 | __ LoadConst32(AT, imm_low); |
| 4809 | __ Xor(AT, AT, lhs_low); |
| 4810 | __ Or(dst, TMP, AT); |
| 4811 | __ Sltiu(dst, dst, 1); |
| 4812 | break; |
| 4813 | case kCondNE: |
| 4814 | __ LoadConst32(TMP, imm_high); |
| 4815 | __ Xor(TMP, TMP, lhs_high); |
| 4816 | __ LoadConst32(AT, imm_low); |
| 4817 | __ Xor(AT, AT, lhs_low); |
| 4818 | __ Or(dst, TMP, AT); |
| 4819 | __ Sltu(dst, ZERO, dst); |
| 4820 | break; |
| 4821 | case kCondLT: |
| 4822 | case kCondGE: |
| 4823 | if (dst == lhs_low) { |
| 4824 | __ LoadConst32(TMP, imm_low); |
| 4825 | __ Sltu(dst, lhs_low, TMP); |
| 4826 | } |
| 4827 | __ LoadConst32(TMP, imm_high); |
| 4828 | __ Slt(AT, lhs_high, TMP); |
| 4829 | __ Slt(TMP, TMP, lhs_high); |
| 4830 | if (dst != lhs_low) { |
| 4831 | __ LoadConst32(dst, imm_low); |
| 4832 | __ Sltu(dst, lhs_low, dst); |
| 4833 | } |
| 4834 | __ Slt(dst, TMP, dst); |
| 4835 | __ Or(dst, dst, AT); |
| 4836 | if (cond == kCondGE) { |
| 4837 | __ Xori(dst, dst, 1); |
| 4838 | } |
| 4839 | break; |
| 4840 | case kCondGT: |
| 4841 | case kCondLE: |
| 4842 | if (dst == lhs_low) { |
| 4843 | __ LoadConst32(TMP, imm_low); |
| 4844 | __ Sltu(dst, TMP, lhs_low); |
| 4845 | } |
| 4846 | __ LoadConst32(TMP, imm_high); |
| 4847 | __ Slt(AT, TMP, lhs_high); |
| 4848 | __ Slt(TMP, lhs_high, TMP); |
| 4849 | if (dst != lhs_low) { |
| 4850 | __ LoadConst32(dst, imm_low); |
| 4851 | __ Sltu(dst, dst, lhs_low); |
| 4852 | } |
| 4853 | __ Slt(dst, TMP, dst); |
| 4854 | __ Or(dst, dst, AT); |
| 4855 | if (cond == kCondLE) { |
| 4856 | __ Xori(dst, dst, 1); |
| 4857 | } |
| 4858 | break; |
| 4859 | case kCondB: |
| 4860 | case kCondAE: |
| 4861 | if (dst == lhs_low) { |
| 4862 | __ LoadConst32(TMP, imm_low); |
| 4863 | __ Sltu(dst, lhs_low, TMP); |
| 4864 | } |
| 4865 | __ LoadConst32(TMP, imm_high); |
| 4866 | __ Sltu(AT, lhs_high, TMP); |
| 4867 | __ Sltu(TMP, TMP, lhs_high); |
| 4868 | if (dst != lhs_low) { |
| 4869 | __ LoadConst32(dst, imm_low); |
| 4870 | __ Sltu(dst, lhs_low, dst); |
| 4871 | } |
| 4872 | __ Slt(dst, TMP, dst); |
| 4873 | __ Or(dst, dst, AT); |
| 4874 | if (cond == kCondAE) { |
| 4875 | __ Xori(dst, dst, 1); |
| 4876 | } |
| 4877 | break; |
| 4878 | case kCondA: |
| 4879 | case kCondBE: |
| 4880 | if (dst == lhs_low) { |
| 4881 | __ LoadConst32(TMP, imm_low); |
| 4882 | __ Sltu(dst, TMP, lhs_low); |
| 4883 | } |
| 4884 | __ LoadConst32(TMP, imm_high); |
| 4885 | __ Sltu(AT, TMP, lhs_high); |
| 4886 | __ Sltu(TMP, lhs_high, TMP); |
| 4887 | if (dst != lhs_low) { |
| 4888 | __ LoadConst32(dst, imm_low); |
| 4889 | __ Sltu(dst, dst, lhs_low); |
| 4890 | } |
| 4891 | __ Slt(dst, TMP, dst); |
| 4892 | __ Or(dst, dst, AT); |
| 4893 | if (cond == kCondBE) { |
| 4894 | __ Xori(dst, dst, 1); |
| 4895 | } |
| 4896 | break; |
| 4897 | } |
| 4898 | } else { |
| 4899 | switch (cond) { |
| 4900 | case kCondEQ: |
| 4901 | __ Xor(TMP, lhs_high, rhs_high); |
| 4902 | __ Xor(AT, lhs_low, rhs_low); |
| 4903 | __ Or(dst, TMP, AT); |
| 4904 | __ Sltiu(dst, dst, 1); |
| 4905 | break; |
| 4906 | case kCondNE: |
| 4907 | __ Xor(TMP, lhs_high, rhs_high); |
| 4908 | __ Xor(AT, lhs_low, rhs_low); |
| 4909 | __ Or(dst, TMP, AT); |
| 4910 | __ Sltu(dst, ZERO, dst); |
| 4911 | break; |
| 4912 | case kCondLT: |
| 4913 | case kCondGE: |
| 4914 | __ Slt(TMP, rhs_high, lhs_high); |
| 4915 | __ Sltu(AT, lhs_low, rhs_low); |
| 4916 | __ Slt(TMP, TMP, AT); |
| 4917 | __ Slt(AT, lhs_high, rhs_high); |
| 4918 | __ Or(dst, AT, TMP); |
| 4919 | if (cond == kCondGE) { |
| 4920 | __ Xori(dst, dst, 1); |
| 4921 | } |
| 4922 | break; |
| 4923 | case kCondGT: |
| 4924 | case kCondLE: |
| 4925 | __ Slt(TMP, lhs_high, rhs_high); |
| 4926 | __ Sltu(AT, rhs_low, lhs_low); |
| 4927 | __ Slt(TMP, TMP, AT); |
| 4928 | __ Slt(AT, rhs_high, lhs_high); |
| 4929 | __ Or(dst, AT, TMP); |
| 4930 | if (cond == kCondLE) { |
| 4931 | __ Xori(dst, dst, 1); |
| 4932 | } |
| 4933 | break; |
| 4934 | case kCondB: |
| 4935 | case kCondAE: |
| 4936 | __ Sltu(TMP, rhs_high, lhs_high); |
| 4937 | __ Sltu(AT, lhs_low, rhs_low); |
| 4938 | __ Slt(TMP, TMP, AT); |
| 4939 | __ Sltu(AT, lhs_high, rhs_high); |
| 4940 | __ Or(dst, AT, TMP); |
| 4941 | if (cond == kCondAE) { |
| 4942 | __ Xori(dst, dst, 1); |
| 4943 | } |
| 4944 | break; |
| 4945 | case kCondA: |
| 4946 | case kCondBE: |
| 4947 | __ Sltu(TMP, lhs_high, rhs_high); |
| 4948 | __ Sltu(AT, rhs_low, lhs_low); |
| 4949 | __ Slt(TMP, TMP, AT); |
| 4950 | __ Sltu(AT, rhs_high, lhs_high); |
| 4951 | __ Or(dst, AT, TMP); |
| 4952 | if (cond == kCondBE) { |
| 4953 | __ Xori(dst, dst, 1); |
| 4954 | } |
| 4955 | break; |
| 4956 | } |
| 4957 | } |
| 4958 | } |
| 4959 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4960 | void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond, |
| 4961 | LocationSummary* locations, |
| 4962 | MipsLabel* label) { |
| 4963 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4964 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4965 | Location rhs_location = locations->InAt(1); |
| 4966 | Register rhs_high = ZERO; |
| 4967 | Register rhs_low = ZERO; |
| 4968 | int64_t imm = 0; |
| 4969 | uint32_t imm_high = 0; |
| 4970 | uint32_t imm_low = 0; |
| 4971 | bool use_imm = rhs_location.IsConstant(); |
| 4972 | if (use_imm) { |
| 4973 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 4974 | imm_high = High32Bits(imm); |
| 4975 | imm_low = Low32Bits(imm); |
| 4976 | } else { |
| 4977 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 4978 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 4979 | } |
| 4980 | |
| 4981 | if (use_imm && imm == 0) { |
| 4982 | switch (cond) { |
| 4983 | case kCondEQ: |
| 4984 | case kCondBE: // <= 0 if zero |
| 4985 | __ Or(TMP, lhs_high, lhs_low); |
| 4986 | __ Beqz(TMP, label); |
| 4987 | break; |
| 4988 | case kCondNE: |
| 4989 | case kCondA: // > 0 if non-zero |
| 4990 | __ Or(TMP, lhs_high, lhs_low); |
| 4991 | __ Bnez(TMP, label); |
| 4992 | break; |
| 4993 | case kCondLT: |
| 4994 | __ Bltz(lhs_high, label); |
| 4995 | break; |
| 4996 | case kCondGE: |
| 4997 | __ Bgez(lhs_high, label); |
| 4998 | break; |
| 4999 | case kCondLE: |
| 5000 | __ Or(TMP, lhs_high, lhs_low); |
| 5001 | __ Sra(AT, lhs_high, 31); |
| 5002 | __ Bgeu(AT, TMP, label); |
| 5003 | break; |
| 5004 | case kCondGT: |
| 5005 | __ Or(TMP, lhs_high, lhs_low); |
| 5006 | __ Sra(AT, lhs_high, 31); |
| 5007 | __ Bltu(AT, TMP, label); |
| 5008 | break; |
| 5009 | case kCondB: // always false |
| 5010 | break; |
| 5011 | case kCondAE: // always true |
| 5012 | __ B(label); |
| 5013 | break; |
| 5014 | } |
| 5015 | } else if (use_imm) { |
| 5016 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 5017 | switch (cond) { |
| 5018 | case kCondEQ: |
| 5019 | __ LoadConst32(TMP, imm_high); |
| 5020 | __ Xor(TMP, TMP, lhs_high); |
| 5021 | __ LoadConst32(AT, imm_low); |
| 5022 | __ Xor(AT, AT, lhs_low); |
| 5023 | __ Or(TMP, TMP, AT); |
| 5024 | __ Beqz(TMP, label); |
| 5025 | break; |
| 5026 | case kCondNE: |
| 5027 | __ LoadConst32(TMP, imm_high); |
| 5028 | __ Xor(TMP, TMP, lhs_high); |
| 5029 | __ LoadConst32(AT, imm_low); |
| 5030 | __ Xor(AT, AT, lhs_low); |
| 5031 | __ Or(TMP, TMP, AT); |
| 5032 | __ Bnez(TMP, label); |
| 5033 | break; |
| 5034 | case kCondLT: |
| 5035 | __ LoadConst32(TMP, imm_high); |
| 5036 | __ Blt(lhs_high, TMP, label); |
| 5037 | __ Slt(TMP, TMP, lhs_high); |
| 5038 | __ LoadConst32(AT, imm_low); |
| 5039 | __ Sltu(AT, lhs_low, AT); |
| 5040 | __ Blt(TMP, AT, label); |
| 5041 | break; |
| 5042 | case kCondGE: |
| 5043 | __ LoadConst32(TMP, imm_high); |
| 5044 | __ Blt(TMP, lhs_high, label); |
| 5045 | __ Slt(TMP, lhs_high, TMP); |
| 5046 | __ LoadConst32(AT, imm_low); |
| 5047 | __ Sltu(AT, lhs_low, AT); |
| 5048 | __ Or(TMP, TMP, AT); |
| 5049 | __ Beqz(TMP, label); |
| 5050 | break; |
| 5051 | case kCondLE: |
| 5052 | __ LoadConst32(TMP, imm_high); |
| 5053 | __ Blt(lhs_high, TMP, label); |
| 5054 | __ Slt(TMP, TMP, lhs_high); |
| 5055 | __ LoadConst32(AT, imm_low); |
| 5056 | __ Sltu(AT, AT, lhs_low); |
| 5057 | __ Or(TMP, TMP, AT); |
| 5058 | __ Beqz(TMP, label); |
| 5059 | break; |
| 5060 | case kCondGT: |
| 5061 | __ LoadConst32(TMP, imm_high); |
| 5062 | __ Blt(TMP, lhs_high, label); |
| 5063 | __ Slt(TMP, lhs_high, TMP); |
| 5064 | __ LoadConst32(AT, imm_low); |
| 5065 | __ Sltu(AT, AT, lhs_low); |
| 5066 | __ Blt(TMP, AT, label); |
| 5067 | break; |
| 5068 | case kCondB: |
| 5069 | __ LoadConst32(TMP, imm_high); |
| 5070 | __ Bltu(lhs_high, TMP, label); |
| 5071 | __ Sltu(TMP, TMP, lhs_high); |
| 5072 | __ LoadConst32(AT, imm_low); |
| 5073 | __ Sltu(AT, lhs_low, AT); |
| 5074 | __ Blt(TMP, AT, label); |
| 5075 | break; |
| 5076 | case kCondAE: |
| 5077 | __ LoadConst32(TMP, imm_high); |
| 5078 | __ Bltu(TMP, lhs_high, label); |
| 5079 | __ Sltu(TMP, lhs_high, TMP); |
| 5080 | __ LoadConst32(AT, imm_low); |
| 5081 | __ Sltu(AT, lhs_low, AT); |
| 5082 | __ Or(TMP, TMP, AT); |
| 5083 | __ Beqz(TMP, label); |
| 5084 | break; |
| 5085 | case kCondBE: |
| 5086 | __ LoadConst32(TMP, imm_high); |
| 5087 | __ Bltu(lhs_high, TMP, label); |
| 5088 | __ Sltu(TMP, TMP, lhs_high); |
| 5089 | __ LoadConst32(AT, imm_low); |
| 5090 | __ Sltu(AT, AT, lhs_low); |
| 5091 | __ Or(TMP, TMP, AT); |
| 5092 | __ Beqz(TMP, label); |
| 5093 | break; |
| 5094 | case kCondA: |
| 5095 | __ LoadConst32(TMP, imm_high); |
| 5096 | __ Bltu(TMP, lhs_high, label); |
| 5097 | __ Sltu(TMP, lhs_high, TMP); |
| 5098 | __ LoadConst32(AT, imm_low); |
| 5099 | __ Sltu(AT, AT, lhs_low); |
| 5100 | __ Blt(TMP, AT, label); |
| 5101 | break; |
| 5102 | } |
| 5103 | } else { |
| 5104 | switch (cond) { |
| 5105 | case kCondEQ: |
| 5106 | __ Xor(TMP, lhs_high, rhs_high); |
| 5107 | __ Xor(AT, lhs_low, rhs_low); |
| 5108 | __ Or(TMP, TMP, AT); |
| 5109 | __ Beqz(TMP, label); |
| 5110 | break; |
| 5111 | case kCondNE: |
| 5112 | __ Xor(TMP, lhs_high, rhs_high); |
| 5113 | __ Xor(AT, lhs_low, rhs_low); |
| 5114 | __ Or(TMP, TMP, AT); |
| 5115 | __ Bnez(TMP, label); |
| 5116 | break; |
| 5117 | case kCondLT: |
| 5118 | __ Blt(lhs_high, rhs_high, label); |
| 5119 | __ Slt(TMP, rhs_high, lhs_high); |
| 5120 | __ Sltu(AT, lhs_low, rhs_low); |
| 5121 | __ Blt(TMP, AT, label); |
| 5122 | break; |
| 5123 | case kCondGE: |
| 5124 | __ Blt(rhs_high, lhs_high, label); |
| 5125 | __ Slt(TMP, lhs_high, rhs_high); |
| 5126 | __ Sltu(AT, lhs_low, rhs_low); |
| 5127 | __ Or(TMP, TMP, AT); |
| 5128 | __ Beqz(TMP, label); |
| 5129 | break; |
| 5130 | case kCondLE: |
| 5131 | __ Blt(lhs_high, rhs_high, label); |
| 5132 | __ Slt(TMP, rhs_high, lhs_high); |
| 5133 | __ Sltu(AT, rhs_low, lhs_low); |
| 5134 | __ Or(TMP, TMP, AT); |
| 5135 | __ Beqz(TMP, label); |
| 5136 | break; |
| 5137 | case kCondGT: |
| 5138 | __ Blt(rhs_high, lhs_high, label); |
| 5139 | __ Slt(TMP, lhs_high, rhs_high); |
| 5140 | __ Sltu(AT, rhs_low, lhs_low); |
| 5141 | __ Blt(TMP, AT, label); |
| 5142 | break; |
| 5143 | case kCondB: |
| 5144 | __ Bltu(lhs_high, rhs_high, label); |
| 5145 | __ Sltu(TMP, rhs_high, lhs_high); |
| 5146 | __ Sltu(AT, lhs_low, rhs_low); |
| 5147 | __ Blt(TMP, AT, label); |
| 5148 | break; |
| 5149 | case kCondAE: |
| 5150 | __ Bltu(rhs_high, lhs_high, label); |
| 5151 | __ Sltu(TMP, lhs_high, rhs_high); |
| 5152 | __ Sltu(AT, lhs_low, rhs_low); |
| 5153 | __ Or(TMP, TMP, AT); |
| 5154 | __ Beqz(TMP, label); |
| 5155 | break; |
| 5156 | case kCondBE: |
| 5157 | __ Bltu(lhs_high, rhs_high, label); |
| 5158 | __ Sltu(TMP, rhs_high, lhs_high); |
| 5159 | __ Sltu(AT, rhs_low, lhs_low); |
| 5160 | __ Or(TMP, TMP, AT); |
| 5161 | __ Beqz(TMP, label); |
| 5162 | break; |
| 5163 | case kCondA: |
| 5164 | __ Bltu(rhs_high, lhs_high, label); |
| 5165 | __ Sltu(TMP, lhs_high, rhs_high); |
| 5166 | __ Sltu(AT, rhs_low, lhs_low); |
| 5167 | __ Blt(TMP, AT, label); |
| 5168 | break; |
| 5169 | } |
| 5170 | } |
| 5171 | } |
| 5172 | |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5173 | void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond, |
| 5174 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5175 | DataType::Type type, |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5176 | LocationSummary* locations) { |
| 5177 | Register dst = locations->Out().AsRegister<Register>(); |
| 5178 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5179 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5180 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5181 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5182 | if (isR6) { |
| 5183 | switch (cond) { |
| 5184 | case kCondEQ: |
| 5185 | __ CmpEqS(FTMP, lhs, rhs); |
| 5186 | __ Mfc1(dst, FTMP); |
| 5187 | __ Andi(dst, dst, 1); |
| 5188 | break; |
| 5189 | case kCondNE: |
| 5190 | __ CmpEqS(FTMP, lhs, rhs); |
| 5191 | __ Mfc1(dst, FTMP); |
| 5192 | __ Addiu(dst, dst, 1); |
| 5193 | break; |
| 5194 | case kCondLT: |
| 5195 | if (gt_bias) { |
| 5196 | __ CmpLtS(FTMP, lhs, rhs); |
| 5197 | } else { |
| 5198 | __ CmpUltS(FTMP, lhs, rhs); |
| 5199 | } |
| 5200 | __ Mfc1(dst, FTMP); |
| 5201 | __ Andi(dst, dst, 1); |
| 5202 | break; |
| 5203 | case kCondLE: |
| 5204 | if (gt_bias) { |
| 5205 | __ CmpLeS(FTMP, lhs, rhs); |
| 5206 | } else { |
| 5207 | __ CmpUleS(FTMP, lhs, rhs); |
| 5208 | } |
| 5209 | __ Mfc1(dst, FTMP); |
| 5210 | __ Andi(dst, dst, 1); |
| 5211 | break; |
| 5212 | case kCondGT: |
| 5213 | if (gt_bias) { |
| 5214 | __ CmpUltS(FTMP, rhs, lhs); |
| 5215 | } else { |
| 5216 | __ CmpLtS(FTMP, rhs, lhs); |
| 5217 | } |
| 5218 | __ Mfc1(dst, FTMP); |
| 5219 | __ Andi(dst, dst, 1); |
| 5220 | break; |
| 5221 | case kCondGE: |
| 5222 | if (gt_bias) { |
| 5223 | __ CmpUleS(FTMP, rhs, lhs); |
| 5224 | } else { |
| 5225 | __ CmpLeS(FTMP, rhs, lhs); |
| 5226 | } |
| 5227 | __ Mfc1(dst, FTMP); |
| 5228 | __ Andi(dst, dst, 1); |
| 5229 | break; |
| 5230 | default: |
| 5231 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5232 | UNREACHABLE(); |
| 5233 | } |
| 5234 | } else { |
| 5235 | switch (cond) { |
| 5236 | case kCondEQ: |
| 5237 | __ CeqS(0, lhs, rhs); |
| 5238 | __ LoadConst32(dst, 1); |
| 5239 | __ Movf(dst, ZERO, 0); |
| 5240 | break; |
| 5241 | case kCondNE: |
| 5242 | __ CeqS(0, lhs, rhs); |
| 5243 | __ LoadConst32(dst, 1); |
| 5244 | __ Movt(dst, ZERO, 0); |
| 5245 | break; |
| 5246 | case kCondLT: |
| 5247 | if (gt_bias) { |
| 5248 | __ ColtS(0, lhs, rhs); |
| 5249 | } else { |
| 5250 | __ CultS(0, lhs, rhs); |
| 5251 | } |
| 5252 | __ LoadConst32(dst, 1); |
| 5253 | __ Movf(dst, ZERO, 0); |
| 5254 | break; |
| 5255 | case kCondLE: |
| 5256 | if (gt_bias) { |
| 5257 | __ ColeS(0, lhs, rhs); |
| 5258 | } else { |
| 5259 | __ CuleS(0, lhs, rhs); |
| 5260 | } |
| 5261 | __ LoadConst32(dst, 1); |
| 5262 | __ Movf(dst, ZERO, 0); |
| 5263 | break; |
| 5264 | case kCondGT: |
| 5265 | if (gt_bias) { |
| 5266 | __ CultS(0, rhs, lhs); |
| 5267 | } else { |
| 5268 | __ ColtS(0, rhs, lhs); |
| 5269 | } |
| 5270 | __ LoadConst32(dst, 1); |
| 5271 | __ Movf(dst, ZERO, 0); |
| 5272 | break; |
| 5273 | case kCondGE: |
| 5274 | if (gt_bias) { |
| 5275 | __ CuleS(0, rhs, lhs); |
| 5276 | } else { |
| 5277 | __ ColeS(0, rhs, lhs); |
| 5278 | } |
| 5279 | __ LoadConst32(dst, 1); |
| 5280 | __ Movf(dst, ZERO, 0); |
| 5281 | break; |
| 5282 | default: |
| 5283 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5284 | UNREACHABLE(); |
| 5285 | } |
| 5286 | } |
| 5287 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5288 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5289 | if (isR6) { |
| 5290 | switch (cond) { |
| 5291 | case kCondEQ: |
| 5292 | __ CmpEqD(FTMP, lhs, rhs); |
| 5293 | __ Mfc1(dst, FTMP); |
| 5294 | __ Andi(dst, dst, 1); |
| 5295 | break; |
| 5296 | case kCondNE: |
| 5297 | __ CmpEqD(FTMP, lhs, rhs); |
| 5298 | __ Mfc1(dst, FTMP); |
| 5299 | __ Addiu(dst, dst, 1); |
| 5300 | break; |
| 5301 | case kCondLT: |
| 5302 | if (gt_bias) { |
| 5303 | __ CmpLtD(FTMP, lhs, rhs); |
| 5304 | } else { |
| 5305 | __ CmpUltD(FTMP, lhs, rhs); |
| 5306 | } |
| 5307 | __ Mfc1(dst, FTMP); |
| 5308 | __ Andi(dst, dst, 1); |
| 5309 | break; |
| 5310 | case kCondLE: |
| 5311 | if (gt_bias) { |
| 5312 | __ CmpLeD(FTMP, lhs, rhs); |
| 5313 | } else { |
| 5314 | __ CmpUleD(FTMP, lhs, rhs); |
| 5315 | } |
| 5316 | __ Mfc1(dst, FTMP); |
| 5317 | __ Andi(dst, dst, 1); |
| 5318 | break; |
| 5319 | case kCondGT: |
| 5320 | if (gt_bias) { |
| 5321 | __ CmpUltD(FTMP, rhs, lhs); |
| 5322 | } else { |
| 5323 | __ CmpLtD(FTMP, rhs, lhs); |
| 5324 | } |
| 5325 | __ Mfc1(dst, FTMP); |
| 5326 | __ Andi(dst, dst, 1); |
| 5327 | break; |
| 5328 | case kCondGE: |
| 5329 | if (gt_bias) { |
| 5330 | __ CmpUleD(FTMP, rhs, lhs); |
| 5331 | } else { |
| 5332 | __ CmpLeD(FTMP, rhs, lhs); |
| 5333 | } |
| 5334 | __ Mfc1(dst, FTMP); |
| 5335 | __ Andi(dst, dst, 1); |
| 5336 | break; |
| 5337 | default: |
| 5338 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5339 | UNREACHABLE(); |
| 5340 | } |
| 5341 | } else { |
| 5342 | switch (cond) { |
| 5343 | case kCondEQ: |
| 5344 | __ CeqD(0, lhs, rhs); |
| 5345 | __ LoadConst32(dst, 1); |
| 5346 | __ Movf(dst, ZERO, 0); |
| 5347 | break; |
| 5348 | case kCondNE: |
| 5349 | __ CeqD(0, lhs, rhs); |
| 5350 | __ LoadConst32(dst, 1); |
| 5351 | __ Movt(dst, ZERO, 0); |
| 5352 | break; |
| 5353 | case kCondLT: |
| 5354 | if (gt_bias) { |
| 5355 | __ ColtD(0, lhs, rhs); |
| 5356 | } else { |
| 5357 | __ CultD(0, lhs, rhs); |
| 5358 | } |
| 5359 | __ LoadConst32(dst, 1); |
| 5360 | __ Movf(dst, ZERO, 0); |
| 5361 | break; |
| 5362 | case kCondLE: |
| 5363 | if (gt_bias) { |
| 5364 | __ ColeD(0, lhs, rhs); |
| 5365 | } else { |
| 5366 | __ CuleD(0, lhs, rhs); |
| 5367 | } |
| 5368 | __ LoadConst32(dst, 1); |
| 5369 | __ Movf(dst, ZERO, 0); |
| 5370 | break; |
| 5371 | case kCondGT: |
| 5372 | if (gt_bias) { |
| 5373 | __ CultD(0, rhs, lhs); |
| 5374 | } else { |
| 5375 | __ ColtD(0, rhs, lhs); |
| 5376 | } |
| 5377 | __ LoadConst32(dst, 1); |
| 5378 | __ Movf(dst, ZERO, 0); |
| 5379 | break; |
| 5380 | case kCondGE: |
| 5381 | if (gt_bias) { |
| 5382 | __ CuleD(0, rhs, lhs); |
| 5383 | } else { |
| 5384 | __ ColeD(0, rhs, lhs); |
| 5385 | } |
| 5386 | __ LoadConst32(dst, 1); |
| 5387 | __ Movf(dst, ZERO, 0); |
| 5388 | break; |
| 5389 | default: |
| 5390 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5391 | UNREACHABLE(); |
| 5392 | } |
| 5393 | } |
| 5394 | } |
| 5395 | } |
| 5396 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5397 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond, |
| 5398 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5399 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5400 | LocationSummary* input_locations, |
| 5401 | int cc) { |
| 5402 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5403 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5404 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5405 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5406 | switch (cond) { |
| 5407 | case kCondEQ: |
| 5408 | __ CeqS(cc, lhs, rhs); |
| 5409 | return false; |
| 5410 | case kCondNE: |
| 5411 | __ CeqS(cc, lhs, rhs); |
| 5412 | return true; |
| 5413 | case kCondLT: |
| 5414 | if (gt_bias) { |
| 5415 | __ ColtS(cc, lhs, rhs); |
| 5416 | } else { |
| 5417 | __ CultS(cc, lhs, rhs); |
| 5418 | } |
| 5419 | return false; |
| 5420 | case kCondLE: |
| 5421 | if (gt_bias) { |
| 5422 | __ ColeS(cc, lhs, rhs); |
| 5423 | } else { |
| 5424 | __ CuleS(cc, lhs, rhs); |
| 5425 | } |
| 5426 | return false; |
| 5427 | case kCondGT: |
| 5428 | if (gt_bias) { |
| 5429 | __ CultS(cc, rhs, lhs); |
| 5430 | } else { |
| 5431 | __ ColtS(cc, rhs, lhs); |
| 5432 | } |
| 5433 | return false; |
| 5434 | case kCondGE: |
| 5435 | if (gt_bias) { |
| 5436 | __ CuleS(cc, rhs, lhs); |
| 5437 | } else { |
| 5438 | __ ColeS(cc, rhs, lhs); |
| 5439 | } |
| 5440 | return false; |
| 5441 | default: |
| 5442 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5443 | UNREACHABLE(); |
| 5444 | } |
| 5445 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5446 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5447 | switch (cond) { |
| 5448 | case kCondEQ: |
| 5449 | __ CeqD(cc, lhs, rhs); |
| 5450 | return false; |
| 5451 | case kCondNE: |
| 5452 | __ CeqD(cc, lhs, rhs); |
| 5453 | return true; |
| 5454 | case kCondLT: |
| 5455 | if (gt_bias) { |
| 5456 | __ ColtD(cc, lhs, rhs); |
| 5457 | } else { |
| 5458 | __ CultD(cc, lhs, rhs); |
| 5459 | } |
| 5460 | return false; |
| 5461 | case kCondLE: |
| 5462 | if (gt_bias) { |
| 5463 | __ ColeD(cc, lhs, rhs); |
| 5464 | } else { |
| 5465 | __ CuleD(cc, lhs, rhs); |
| 5466 | } |
| 5467 | return false; |
| 5468 | case kCondGT: |
| 5469 | if (gt_bias) { |
| 5470 | __ CultD(cc, rhs, lhs); |
| 5471 | } else { |
| 5472 | __ ColtD(cc, rhs, lhs); |
| 5473 | } |
| 5474 | return false; |
| 5475 | case kCondGE: |
| 5476 | if (gt_bias) { |
| 5477 | __ CuleD(cc, rhs, lhs); |
| 5478 | } else { |
| 5479 | __ ColeD(cc, rhs, lhs); |
| 5480 | } |
| 5481 | return false; |
| 5482 | default: |
| 5483 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5484 | UNREACHABLE(); |
| 5485 | } |
| 5486 | } |
| 5487 | } |
| 5488 | |
| 5489 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond, |
| 5490 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5491 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5492 | LocationSummary* input_locations, |
| 5493 | FRegister dst) { |
| 5494 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5495 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5496 | CHECK(codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5497 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5498 | switch (cond) { |
| 5499 | case kCondEQ: |
| 5500 | __ CmpEqS(dst, lhs, rhs); |
| 5501 | return false; |
| 5502 | case kCondNE: |
| 5503 | __ CmpEqS(dst, lhs, rhs); |
| 5504 | return true; |
| 5505 | case kCondLT: |
| 5506 | if (gt_bias) { |
| 5507 | __ CmpLtS(dst, lhs, rhs); |
| 5508 | } else { |
| 5509 | __ CmpUltS(dst, lhs, rhs); |
| 5510 | } |
| 5511 | return false; |
| 5512 | case kCondLE: |
| 5513 | if (gt_bias) { |
| 5514 | __ CmpLeS(dst, lhs, rhs); |
| 5515 | } else { |
| 5516 | __ CmpUleS(dst, lhs, rhs); |
| 5517 | } |
| 5518 | return false; |
| 5519 | case kCondGT: |
| 5520 | if (gt_bias) { |
| 5521 | __ CmpUltS(dst, rhs, lhs); |
| 5522 | } else { |
| 5523 | __ CmpLtS(dst, rhs, lhs); |
| 5524 | } |
| 5525 | return false; |
| 5526 | case kCondGE: |
| 5527 | if (gt_bias) { |
| 5528 | __ CmpUleS(dst, rhs, lhs); |
| 5529 | } else { |
| 5530 | __ CmpLeS(dst, rhs, lhs); |
| 5531 | } |
| 5532 | return false; |
| 5533 | default: |
| 5534 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5535 | UNREACHABLE(); |
| 5536 | } |
| 5537 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5538 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5539 | switch (cond) { |
| 5540 | case kCondEQ: |
| 5541 | __ CmpEqD(dst, lhs, rhs); |
| 5542 | return false; |
| 5543 | case kCondNE: |
| 5544 | __ CmpEqD(dst, lhs, rhs); |
| 5545 | return true; |
| 5546 | case kCondLT: |
| 5547 | if (gt_bias) { |
| 5548 | __ CmpLtD(dst, lhs, rhs); |
| 5549 | } else { |
| 5550 | __ CmpUltD(dst, lhs, rhs); |
| 5551 | } |
| 5552 | return false; |
| 5553 | case kCondLE: |
| 5554 | if (gt_bias) { |
| 5555 | __ CmpLeD(dst, lhs, rhs); |
| 5556 | } else { |
| 5557 | __ CmpUleD(dst, lhs, rhs); |
| 5558 | } |
| 5559 | return false; |
| 5560 | case kCondGT: |
| 5561 | if (gt_bias) { |
| 5562 | __ CmpUltD(dst, rhs, lhs); |
| 5563 | } else { |
| 5564 | __ CmpLtD(dst, rhs, lhs); |
| 5565 | } |
| 5566 | return false; |
| 5567 | case kCondGE: |
| 5568 | if (gt_bias) { |
| 5569 | __ CmpUleD(dst, rhs, lhs); |
| 5570 | } else { |
| 5571 | __ CmpLeD(dst, rhs, lhs); |
| 5572 | } |
| 5573 | return false; |
| 5574 | default: |
| 5575 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5576 | UNREACHABLE(); |
| 5577 | } |
| 5578 | } |
| 5579 | } |
| 5580 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5581 | void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond, |
| 5582 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5583 | DataType::Type type, |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5584 | LocationSummary* locations, |
| 5585 | MipsLabel* label) { |
| 5586 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5587 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5588 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5589 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5590 | if (isR6) { |
| 5591 | switch (cond) { |
| 5592 | case kCondEQ: |
| 5593 | __ CmpEqS(FTMP, lhs, rhs); |
| 5594 | __ Bc1nez(FTMP, label); |
| 5595 | break; |
| 5596 | case kCondNE: |
| 5597 | __ CmpEqS(FTMP, lhs, rhs); |
| 5598 | __ Bc1eqz(FTMP, label); |
| 5599 | break; |
| 5600 | case kCondLT: |
| 5601 | if (gt_bias) { |
| 5602 | __ CmpLtS(FTMP, lhs, rhs); |
| 5603 | } else { |
| 5604 | __ CmpUltS(FTMP, lhs, rhs); |
| 5605 | } |
| 5606 | __ Bc1nez(FTMP, label); |
| 5607 | break; |
| 5608 | case kCondLE: |
| 5609 | if (gt_bias) { |
| 5610 | __ CmpLeS(FTMP, lhs, rhs); |
| 5611 | } else { |
| 5612 | __ CmpUleS(FTMP, lhs, rhs); |
| 5613 | } |
| 5614 | __ Bc1nez(FTMP, label); |
| 5615 | break; |
| 5616 | case kCondGT: |
| 5617 | if (gt_bias) { |
| 5618 | __ CmpUltS(FTMP, rhs, lhs); |
| 5619 | } else { |
| 5620 | __ CmpLtS(FTMP, rhs, lhs); |
| 5621 | } |
| 5622 | __ Bc1nez(FTMP, label); |
| 5623 | break; |
| 5624 | case kCondGE: |
| 5625 | if (gt_bias) { |
| 5626 | __ CmpUleS(FTMP, rhs, lhs); |
| 5627 | } else { |
| 5628 | __ CmpLeS(FTMP, rhs, lhs); |
| 5629 | } |
| 5630 | __ Bc1nez(FTMP, label); |
| 5631 | break; |
| 5632 | default: |
| 5633 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5634 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5635 | } |
| 5636 | } else { |
| 5637 | switch (cond) { |
| 5638 | case kCondEQ: |
| 5639 | __ CeqS(0, lhs, rhs); |
| 5640 | __ Bc1t(0, label); |
| 5641 | break; |
| 5642 | case kCondNE: |
| 5643 | __ CeqS(0, lhs, rhs); |
| 5644 | __ Bc1f(0, label); |
| 5645 | break; |
| 5646 | case kCondLT: |
| 5647 | if (gt_bias) { |
| 5648 | __ ColtS(0, lhs, rhs); |
| 5649 | } else { |
| 5650 | __ CultS(0, lhs, rhs); |
| 5651 | } |
| 5652 | __ Bc1t(0, label); |
| 5653 | break; |
| 5654 | case kCondLE: |
| 5655 | if (gt_bias) { |
| 5656 | __ ColeS(0, lhs, rhs); |
| 5657 | } else { |
| 5658 | __ CuleS(0, lhs, rhs); |
| 5659 | } |
| 5660 | __ Bc1t(0, label); |
| 5661 | break; |
| 5662 | case kCondGT: |
| 5663 | if (gt_bias) { |
| 5664 | __ CultS(0, rhs, lhs); |
| 5665 | } else { |
| 5666 | __ ColtS(0, rhs, lhs); |
| 5667 | } |
| 5668 | __ Bc1t(0, label); |
| 5669 | break; |
| 5670 | case kCondGE: |
| 5671 | if (gt_bias) { |
| 5672 | __ CuleS(0, rhs, lhs); |
| 5673 | } else { |
| 5674 | __ ColeS(0, rhs, lhs); |
| 5675 | } |
| 5676 | __ Bc1t(0, label); |
| 5677 | break; |
| 5678 | default: |
| 5679 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5680 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5681 | } |
| 5682 | } |
| 5683 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5684 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5685 | if (isR6) { |
| 5686 | switch (cond) { |
| 5687 | case kCondEQ: |
| 5688 | __ CmpEqD(FTMP, lhs, rhs); |
| 5689 | __ Bc1nez(FTMP, label); |
| 5690 | break; |
| 5691 | case kCondNE: |
| 5692 | __ CmpEqD(FTMP, lhs, rhs); |
| 5693 | __ Bc1eqz(FTMP, label); |
| 5694 | break; |
| 5695 | case kCondLT: |
| 5696 | if (gt_bias) { |
| 5697 | __ CmpLtD(FTMP, lhs, rhs); |
| 5698 | } else { |
| 5699 | __ CmpUltD(FTMP, lhs, rhs); |
| 5700 | } |
| 5701 | __ Bc1nez(FTMP, label); |
| 5702 | break; |
| 5703 | case kCondLE: |
| 5704 | if (gt_bias) { |
| 5705 | __ CmpLeD(FTMP, lhs, rhs); |
| 5706 | } else { |
| 5707 | __ CmpUleD(FTMP, lhs, rhs); |
| 5708 | } |
| 5709 | __ Bc1nez(FTMP, label); |
| 5710 | break; |
| 5711 | case kCondGT: |
| 5712 | if (gt_bias) { |
| 5713 | __ CmpUltD(FTMP, rhs, lhs); |
| 5714 | } else { |
| 5715 | __ CmpLtD(FTMP, rhs, lhs); |
| 5716 | } |
| 5717 | __ Bc1nez(FTMP, label); |
| 5718 | break; |
| 5719 | case kCondGE: |
| 5720 | if (gt_bias) { |
| 5721 | __ CmpUleD(FTMP, rhs, lhs); |
| 5722 | } else { |
| 5723 | __ CmpLeD(FTMP, rhs, lhs); |
| 5724 | } |
| 5725 | __ Bc1nez(FTMP, label); |
| 5726 | break; |
| 5727 | default: |
| 5728 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5729 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5730 | } |
| 5731 | } else { |
| 5732 | switch (cond) { |
| 5733 | case kCondEQ: |
| 5734 | __ CeqD(0, lhs, rhs); |
| 5735 | __ Bc1t(0, label); |
| 5736 | break; |
| 5737 | case kCondNE: |
| 5738 | __ CeqD(0, lhs, rhs); |
| 5739 | __ Bc1f(0, label); |
| 5740 | break; |
| 5741 | case kCondLT: |
| 5742 | if (gt_bias) { |
| 5743 | __ ColtD(0, lhs, rhs); |
| 5744 | } else { |
| 5745 | __ CultD(0, lhs, rhs); |
| 5746 | } |
| 5747 | __ Bc1t(0, label); |
| 5748 | break; |
| 5749 | case kCondLE: |
| 5750 | if (gt_bias) { |
| 5751 | __ ColeD(0, lhs, rhs); |
| 5752 | } else { |
| 5753 | __ CuleD(0, lhs, rhs); |
| 5754 | } |
| 5755 | __ Bc1t(0, label); |
| 5756 | break; |
| 5757 | case kCondGT: |
| 5758 | if (gt_bias) { |
| 5759 | __ CultD(0, rhs, lhs); |
| 5760 | } else { |
| 5761 | __ ColtD(0, rhs, lhs); |
| 5762 | } |
| 5763 | __ Bc1t(0, label); |
| 5764 | break; |
| 5765 | case kCondGE: |
| 5766 | if (gt_bias) { |
| 5767 | __ CuleD(0, rhs, lhs); |
| 5768 | } else { |
| 5769 | __ ColeD(0, rhs, lhs); |
| 5770 | } |
| 5771 | __ Bc1t(0, label); |
| 5772 | break; |
| 5773 | default: |
| 5774 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5775 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5776 | } |
| 5777 | } |
| 5778 | } |
| 5779 | } |
| 5780 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5781 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5782 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5783 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5784 | MipsLabel* false_target) { |
| 5785 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5786 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5787 | if (true_target == nullptr && false_target == nullptr) { |
| 5788 | // Nothing to do. The code always falls through. |
| 5789 | return; |
| 5790 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5791 | // Constant condition, statically compared against "true" (integer value 1). |
| 5792 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5793 | if (true_target != nullptr) { |
| 5794 | __ B(true_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5795 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5796 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5797 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5798 | if (false_target != nullptr) { |
| 5799 | __ B(false_target); |
| 5800 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5801 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5802 | return; |
| 5803 | } |
| 5804 | |
| 5805 | // The following code generates these patterns: |
| 5806 | // (1) true_target == nullptr && false_target != nullptr |
| 5807 | // - opposite condition true => branch to false_target |
| 5808 | // (2) true_target != nullptr && false_target == nullptr |
| 5809 | // - condition true => branch to true_target |
| 5810 | // (3) true_target != nullptr && false_target != nullptr |
| 5811 | // - condition true => branch to true_target |
| 5812 | // - branch to false_target |
| 5813 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5814 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5815 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5816 | DCHECK(cond_val.IsRegister()); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5817 | if (true_target == nullptr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5818 | __ Beqz(cond_val.AsRegister<Register>(), false_target); |
| 5819 | } else { |
| 5820 | __ Bnez(cond_val.AsRegister<Register>(), true_target); |
| 5821 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5822 | } else { |
| 5823 | // The condition instruction has not been materialized, use its inputs as |
| 5824 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5825 | HCondition* condition = cond->AsCondition(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5826 | DataType::Type type = condition->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5827 | LocationSummary* locations = cond->GetLocations(); |
| 5828 | IfCondition if_cond = condition->GetCondition(); |
| 5829 | MipsLabel* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5830 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5831 | if (true_target == nullptr) { |
| 5832 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5833 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5834 | } |
| 5835 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5836 | switch (type) { |
| 5837 | default: |
| 5838 | GenerateIntCompareAndBranch(if_cond, locations, branch_target); |
| 5839 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5840 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5841 | GenerateLongCompareAndBranch(if_cond, locations, branch_target); |
| 5842 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5843 | case DataType::Type::kFloat32: |
| 5844 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5845 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 5846 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5847 | } |
| 5848 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5849 | |
| 5850 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 5851 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 5852 | if (true_target != nullptr && false_target != nullptr) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5853 | __ B(false_target); |
| 5854 | } |
| 5855 | } |
| 5856 | |
| 5857 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5858 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5859 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5860 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5861 | } |
| 5862 | } |
| 5863 | |
| 5864 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5865 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 5866 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 5867 | MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 5868 | nullptr : codegen_->GetLabelOf(true_successor); |
| 5869 | MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 5870 | nullptr : codegen_->GetLabelOf(false_successor); |
| 5871 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5875 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5876 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 5877 | InvokeRuntimeCallingConvention calling_convention; |
| 5878 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5879 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5880 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5881 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5882 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5883 | } |
| 5884 | } |
| 5885 | |
| 5886 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 5887 | SlowPathCodeMIPS* slow_path = |
| 5888 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5889 | GenerateTestAndBranch(deoptimize, |
| 5890 | /* condition_input_index */ 0, |
| 5891 | slow_path->GetEntryLabel(), |
| 5892 | /* false_target */ nullptr); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5893 | } |
| 5894 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5895 | // This function returns true if a conditional move can be generated for HSelect. |
| 5896 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 5897 | // branches and regular moves. |
| 5898 | // |
| 5899 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 5900 | // |
| 5901 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 5902 | // are two distinct tasks, this function does both because they share quite a bit |
| 5903 | // of common logic. |
| 5904 | static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) { |
| 5905 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 5906 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 5907 | HCondition* condition = cond->AsCondition(); |
| 5908 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5909 | DataType::Type cond_type = |
| 5910 | materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType(); |
| 5911 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5912 | |
| 5913 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 5914 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 5915 | bool is_true_value_zero_constant = |
| 5916 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 5917 | bool is_false_value_zero_constant = |
| 5918 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 5919 | |
| 5920 | bool can_move_conditionally = false; |
| 5921 | bool use_const_for_false_in = false; |
| 5922 | bool use_const_for_true_in = false; |
| 5923 | |
| 5924 | if (!cond->IsConstant()) { |
| 5925 | switch (cond_type) { |
| 5926 | default: |
| 5927 | switch (dst_type) { |
| 5928 | default: |
| 5929 | // Moving int on int condition. |
| 5930 | if (is_r6) { |
| 5931 | if (is_true_value_zero_constant) { |
| 5932 | // seleqz out_reg, false_reg, cond_reg |
| 5933 | can_move_conditionally = true; |
| 5934 | use_const_for_true_in = true; |
| 5935 | } else if (is_false_value_zero_constant) { |
| 5936 | // selnez out_reg, true_reg, cond_reg |
| 5937 | can_move_conditionally = true; |
| 5938 | use_const_for_false_in = true; |
| 5939 | } else if (materialized) { |
| 5940 | // Not materializing unmaterialized int conditions |
| 5941 | // to keep the instruction count low. |
| 5942 | // selnez AT, true_reg, cond_reg |
| 5943 | // seleqz TMP, false_reg, cond_reg |
| 5944 | // or out_reg, AT, TMP |
| 5945 | can_move_conditionally = true; |
| 5946 | } |
| 5947 | } else { |
| 5948 | // movn out_reg, true_reg/ZERO, cond_reg |
| 5949 | can_move_conditionally = true; |
| 5950 | use_const_for_true_in = is_true_value_zero_constant; |
| 5951 | } |
| 5952 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5953 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5954 | // Moving long on int condition. |
| 5955 | if (is_r6) { |
| 5956 | if (is_true_value_zero_constant) { |
| 5957 | // seleqz out_reg_lo, false_reg_lo, cond_reg |
| 5958 | // seleqz out_reg_hi, false_reg_hi, cond_reg |
| 5959 | can_move_conditionally = true; |
| 5960 | use_const_for_true_in = true; |
| 5961 | } else if (is_false_value_zero_constant) { |
| 5962 | // selnez out_reg_lo, true_reg_lo, cond_reg |
| 5963 | // selnez out_reg_hi, true_reg_hi, cond_reg |
| 5964 | can_move_conditionally = true; |
| 5965 | use_const_for_false_in = true; |
| 5966 | } |
| 5967 | // Other long conditional moves would generate 6+ instructions, |
| 5968 | // which is too many. |
| 5969 | } else { |
| 5970 | // movn out_reg_lo, true_reg_lo/ZERO, cond_reg |
| 5971 | // movn out_reg_hi, true_reg_hi/ZERO, cond_reg |
| 5972 | can_move_conditionally = true; |
| 5973 | use_const_for_true_in = is_true_value_zero_constant; |
| 5974 | } |
| 5975 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5976 | case DataType::Type::kFloat32: |
| 5977 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5978 | // Moving float/double on int condition. |
| 5979 | if (is_r6) { |
| 5980 | if (materialized) { |
| 5981 | // Not materializing unmaterialized int conditions |
| 5982 | // to keep the instruction count low. |
| 5983 | can_move_conditionally = true; |
| 5984 | if (is_true_value_zero_constant) { |
| 5985 | // sltu TMP, ZERO, cond_reg |
| 5986 | // mtc1 TMP, temp_cond_reg |
| 5987 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 5988 | use_const_for_true_in = true; |
| 5989 | } else if (is_false_value_zero_constant) { |
| 5990 | // sltu TMP, ZERO, cond_reg |
| 5991 | // mtc1 TMP, temp_cond_reg |
| 5992 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 5993 | use_const_for_false_in = true; |
| 5994 | } else { |
| 5995 | // sltu TMP, ZERO, cond_reg |
| 5996 | // mtc1 TMP, temp_cond_reg |
| 5997 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 5998 | // mov.fmt out_reg, temp_cond_reg |
| 5999 | } |
| 6000 | } |
| 6001 | } else { |
| 6002 | // movn.fmt out_reg, true_reg, cond_reg |
| 6003 | can_move_conditionally = true; |
| 6004 | } |
| 6005 | break; |
| 6006 | } |
| 6007 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6008 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6009 | // We don't materialize long comparison now |
| 6010 | // and use conditional branches instead. |
| 6011 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6012 | case DataType::Type::kFloat32: |
| 6013 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6014 | switch (dst_type) { |
| 6015 | default: |
| 6016 | // Moving int on float/double condition. |
| 6017 | if (is_r6) { |
| 6018 | if (is_true_value_zero_constant) { |
| 6019 | // mfc1 TMP, temp_cond_reg |
| 6020 | // seleqz out_reg, false_reg, TMP |
| 6021 | can_move_conditionally = true; |
| 6022 | use_const_for_true_in = true; |
| 6023 | } else if (is_false_value_zero_constant) { |
| 6024 | // mfc1 TMP, temp_cond_reg |
| 6025 | // selnez out_reg, true_reg, TMP |
| 6026 | can_move_conditionally = true; |
| 6027 | use_const_for_false_in = true; |
| 6028 | } else { |
| 6029 | // mfc1 TMP, temp_cond_reg |
| 6030 | // selnez AT, true_reg, TMP |
| 6031 | // seleqz TMP, false_reg, TMP |
| 6032 | // or out_reg, AT, TMP |
| 6033 | can_move_conditionally = true; |
| 6034 | } |
| 6035 | } else { |
| 6036 | // movt out_reg, true_reg/ZERO, cc |
| 6037 | can_move_conditionally = true; |
| 6038 | use_const_for_true_in = is_true_value_zero_constant; |
| 6039 | } |
| 6040 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6041 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6042 | // Moving long on float/double condition. |
| 6043 | if (is_r6) { |
| 6044 | if (is_true_value_zero_constant) { |
| 6045 | // mfc1 TMP, temp_cond_reg |
| 6046 | // seleqz out_reg_lo, false_reg_lo, TMP |
| 6047 | // seleqz out_reg_hi, false_reg_hi, TMP |
| 6048 | can_move_conditionally = true; |
| 6049 | use_const_for_true_in = true; |
| 6050 | } else if (is_false_value_zero_constant) { |
| 6051 | // mfc1 TMP, temp_cond_reg |
| 6052 | // selnez out_reg_lo, true_reg_lo, TMP |
| 6053 | // selnez out_reg_hi, true_reg_hi, TMP |
| 6054 | can_move_conditionally = true; |
| 6055 | use_const_for_false_in = true; |
| 6056 | } |
| 6057 | // Other long conditional moves would generate 6+ instructions, |
| 6058 | // which is too many. |
| 6059 | } else { |
| 6060 | // movt out_reg_lo, true_reg_lo/ZERO, cc |
| 6061 | // movt out_reg_hi, true_reg_hi/ZERO, cc |
| 6062 | can_move_conditionally = true; |
| 6063 | use_const_for_true_in = is_true_value_zero_constant; |
| 6064 | } |
| 6065 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6066 | case DataType::Type::kFloat32: |
| 6067 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6068 | // Moving float/double on float/double condition. |
| 6069 | if (is_r6) { |
| 6070 | can_move_conditionally = true; |
| 6071 | if (is_true_value_zero_constant) { |
| 6072 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 6073 | use_const_for_true_in = true; |
| 6074 | } else if (is_false_value_zero_constant) { |
| 6075 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 6076 | use_const_for_false_in = true; |
| 6077 | } else { |
| 6078 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 6079 | // mov.fmt out_reg, temp_cond_reg |
| 6080 | } |
| 6081 | } else { |
| 6082 | // movt.fmt out_reg, true_reg, cc |
| 6083 | can_move_conditionally = true; |
| 6084 | } |
| 6085 | break; |
| 6086 | } |
| 6087 | break; |
| 6088 | } |
| 6089 | } |
| 6090 | |
| 6091 | if (can_move_conditionally) { |
| 6092 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 6093 | } else { |
| 6094 | DCHECK(!use_const_for_false_in); |
| 6095 | DCHECK(!use_const_for_true_in); |
| 6096 | } |
| 6097 | |
| 6098 | if (locations_to_set != nullptr) { |
| 6099 | if (use_const_for_false_in) { |
| 6100 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 6101 | } else { |
| 6102 | locations_to_set->SetInAt(0, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6103 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6104 | ? Location::RequiresFpuRegister() |
| 6105 | : Location::RequiresRegister()); |
| 6106 | } |
| 6107 | if (use_const_for_true_in) { |
| 6108 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 6109 | } else { |
| 6110 | locations_to_set->SetInAt(1, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6111 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6112 | ? Location::RequiresFpuRegister() |
| 6113 | : Location::RequiresRegister()); |
| 6114 | } |
| 6115 | if (materialized) { |
| 6116 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 6117 | } |
| 6118 | // On R6 we don't require the output to be the same as the |
| 6119 | // first input for conditional moves unlike on R2. |
| 6120 | bool is_out_same_as_first_in = !can_move_conditionally || !is_r6; |
| 6121 | if (is_out_same_as_first_in) { |
| 6122 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 6123 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6124 | locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6125 | ? Location::RequiresFpuRegister() |
| 6126 | : Location::RequiresRegister()); |
| 6127 | } |
| 6128 | } |
| 6129 | |
| 6130 | return can_move_conditionally; |
| 6131 | } |
| 6132 | |
| 6133 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) { |
| 6134 | LocationSummary* locations = select->GetLocations(); |
| 6135 | Location dst = locations->Out(); |
| 6136 | Location src = locations->InAt(1); |
| 6137 | Register src_reg = ZERO; |
| 6138 | Register src_reg_high = ZERO; |
| 6139 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 6140 | Register cond_reg = TMP; |
| 6141 | int cond_cc = 0; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6142 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6143 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6144 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6145 | |
| 6146 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 6147 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 6148 | } else { |
| 6149 | HCondition* condition = cond->AsCondition(); |
| 6150 | LocationSummary* cond_locations = cond->GetLocations(); |
| 6151 | IfCondition if_cond = condition->GetCondition(); |
| 6152 | cond_type = condition->InputAt(0)->GetType(); |
| 6153 | switch (cond_type) { |
| 6154 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6155 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6156 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 6157 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6158 | case DataType::Type::kFloat32: |
| 6159 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6160 | cond_inverted = MaterializeFpCompareR2(if_cond, |
| 6161 | condition->IsGtBias(), |
| 6162 | cond_type, |
| 6163 | cond_locations, |
| 6164 | cond_cc); |
| 6165 | break; |
| 6166 | } |
| 6167 | } |
| 6168 | |
| 6169 | DCHECK(dst.Equals(locations->InAt(0))); |
| 6170 | if (src.IsRegister()) { |
| 6171 | src_reg = src.AsRegister<Register>(); |
| 6172 | } else if (src.IsRegisterPair()) { |
| 6173 | src_reg = src.AsRegisterPairLow<Register>(); |
| 6174 | src_reg_high = src.AsRegisterPairHigh<Register>(); |
| 6175 | } else if (src.IsConstant()) { |
| 6176 | DCHECK(src.GetConstant()->IsZeroBitPattern()); |
| 6177 | } |
| 6178 | |
| 6179 | switch (cond_type) { |
| 6180 | default: |
| 6181 | switch (dst_type) { |
| 6182 | default: |
| 6183 | if (cond_inverted) { |
| 6184 | __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 6185 | } else { |
| 6186 | __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 6187 | } |
| 6188 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6189 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6190 | if (cond_inverted) { |
| 6191 | __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 6192 | __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 6193 | } else { |
| 6194 | __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 6195 | __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 6196 | } |
| 6197 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6198 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6199 | if (cond_inverted) { |
| 6200 | __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6201 | } else { |
| 6202 | __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6203 | } |
| 6204 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6205 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6206 | if (cond_inverted) { |
| 6207 | __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6208 | } else { |
| 6209 | __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 6210 | } |
| 6211 | break; |
| 6212 | } |
| 6213 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6214 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6215 | LOG(FATAL) << "Unreachable"; |
| 6216 | UNREACHABLE(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6217 | case DataType::Type::kFloat32: |
| 6218 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6219 | switch (dst_type) { |
| 6220 | default: |
| 6221 | if (cond_inverted) { |
| 6222 | __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 6223 | } else { |
| 6224 | __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 6225 | } |
| 6226 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6227 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6228 | if (cond_inverted) { |
| 6229 | __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 6230 | __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 6231 | } else { |
| 6232 | __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 6233 | __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 6234 | } |
| 6235 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6236 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6237 | if (cond_inverted) { |
| 6238 | __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6239 | } else { |
| 6240 | __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6241 | } |
| 6242 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6243 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6244 | if (cond_inverted) { |
| 6245 | __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6246 | } else { |
| 6247 | __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 6248 | } |
| 6249 | break; |
| 6250 | } |
| 6251 | break; |
| 6252 | } |
| 6253 | } |
| 6254 | |
| 6255 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) { |
| 6256 | LocationSummary* locations = select->GetLocations(); |
| 6257 | Location dst = locations->Out(); |
| 6258 | Location false_src = locations->InAt(0); |
| 6259 | Location true_src = locations->InAt(1); |
| 6260 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 6261 | Register cond_reg = TMP; |
| 6262 | FRegister fcond_reg = FTMP; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6263 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6264 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6265 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6266 | |
| 6267 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 6268 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 6269 | } else { |
| 6270 | HCondition* condition = cond->AsCondition(); |
| 6271 | LocationSummary* cond_locations = cond->GetLocations(); |
| 6272 | IfCondition if_cond = condition->GetCondition(); |
| 6273 | cond_type = condition->InputAt(0)->GetType(); |
| 6274 | switch (cond_type) { |
| 6275 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6276 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6277 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 6278 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6279 | case DataType::Type::kFloat32: |
| 6280 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6281 | cond_inverted = MaterializeFpCompareR6(if_cond, |
| 6282 | condition->IsGtBias(), |
| 6283 | cond_type, |
| 6284 | cond_locations, |
| 6285 | fcond_reg); |
| 6286 | break; |
| 6287 | } |
| 6288 | } |
| 6289 | |
| 6290 | if (true_src.IsConstant()) { |
| 6291 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 6292 | } |
| 6293 | if (false_src.IsConstant()) { |
| 6294 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 6295 | } |
| 6296 | |
| 6297 | switch (dst_type) { |
| 6298 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6299 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6300 | __ Mfc1(cond_reg, fcond_reg); |
| 6301 | } |
| 6302 | if (true_src.IsConstant()) { |
| 6303 | if (cond_inverted) { |
| 6304 | __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 6305 | } else { |
| 6306 | __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 6307 | } |
| 6308 | } else if (false_src.IsConstant()) { |
| 6309 | if (cond_inverted) { |
| 6310 | __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 6311 | } else { |
| 6312 | __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 6313 | } |
| 6314 | } else { |
| 6315 | DCHECK_NE(cond_reg, AT); |
| 6316 | if (cond_inverted) { |
| 6317 | __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6318 | __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6319 | } else { |
| 6320 | __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6321 | __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6322 | } |
| 6323 | __ Or(dst.AsRegister<Register>(), AT, TMP); |
| 6324 | } |
| 6325 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6326 | case DataType::Type::kInt64: { |
| 6327 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6328 | __ Mfc1(cond_reg, fcond_reg); |
| 6329 | } |
| 6330 | Register dst_lo = dst.AsRegisterPairLow<Register>(); |
| 6331 | Register dst_hi = dst.AsRegisterPairHigh<Register>(); |
| 6332 | if (true_src.IsConstant()) { |
| 6333 | Register src_lo = false_src.AsRegisterPairLow<Register>(); |
| 6334 | Register src_hi = false_src.AsRegisterPairHigh<Register>(); |
| 6335 | if (cond_inverted) { |
| 6336 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6337 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6338 | } else { |
| 6339 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6340 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6341 | } |
| 6342 | } else { |
| 6343 | DCHECK(false_src.IsConstant()); |
| 6344 | Register src_lo = true_src.AsRegisterPairLow<Register>(); |
| 6345 | Register src_hi = true_src.AsRegisterPairHigh<Register>(); |
| 6346 | if (cond_inverted) { |
| 6347 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6348 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6349 | } else { |
| 6350 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6351 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6352 | } |
| 6353 | } |
| 6354 | break; |
| 6355 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6356 | case DataType::Type::kFloat32: { |
| 6357 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6358 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6359 | __ Sltu(TMP, ZERO, cond_reg); |
| 6360 | __ Mtc1(TMP, fcond_reg); |
| 6361 | } |
| 6362 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6363 | if (true_src.IsConstant()) { |
| 6364 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6365 | if (cond_inverted) { |
| 6366 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6367 | } else { |
| 6368 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6369 | } |
| 6370 | } else if (false_src.IsConstant()) { |
| 6371 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6372 | if (cond_inverted) { |
| 6373 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6374 | } else { |
| 6375 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6376 | } |
| 6377 | } else { |
| 6378 | if (cond_inverted) { |
| 6379 | __ SelS(fcond_reg, |
| 6380 | true_src.AsFpuRegister<FRegister>(), |
| 6381 | false_src.AsFpuRegister<FRegister>()); |
| 6382 | } else { |
| 6383 | __ SelS(fcond_reg, |
| 6384 | false_src.AsFpuRegister<FRegister>(), |
| 6385 | true_src.AsFpuRegister<FRegister>()); |
| 6386 | } |
| 6387 | __ MovS(dst_reg, fcond_reg); |
| 6388 | } |
| 6389 | break; |
| 6390 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6391 | case DataType::Type::kFloat64: { |
| 6392 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6393 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6394 | __ Sltu(TMP, ZERO, cond_reg); |
| 6395 | __ Mtc1(TMP, fcond_reg); |
| 6396 | } |
| 6397 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6398 | if (true_src.IsConstant()) { |
| 6399 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6400 | if (cond_inverted) { |
| 6401 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6402 | } else { |
| 6403 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6404 | } |
| 6405 | } else if (false_src.IsConstant()) { |
| 6406 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6407 | if (cond_inverted) { |
| 6408 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6409 | } else { |
| 6410 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6411 | } |
| 6412 | } else { |
| 6413 | if (cond_inverted) { |
| 6414 | __ SelD(fcond_reg, |
| 6415 | true_src.AsFpuRegister<FRegister>(), |
| 6416 | false_src.AsFpuRegister<FRegister>()); |
| 6417 | } else { |
| 6418 | __ SelD(fcond_reg, |
| 6419 | false_src.AsFpuRegister<FRegister>(), |
| 6420 | true_src.AsFpuRegister<FRegister>()); |
| 6421 | } |
| 6422 | __ MovD(dst_reg, fcond_reg); |
| 6423 | } |
| 6424 | break; |
| 6425 | } |
| 6426 | } |
| 6427 | } |
| 6428 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6429 | void LocationsBuilderMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6430 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6431 | LocationSummary(flag, LocationSummary::kNoCall); |
| 6432 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6433 | } |
| 6434 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6435 | void InstructionCodeGeneratorMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 6436 | __ LoadFromOffset(kLoadWord, |
| 6437 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 6438 | SP, |
| 6439 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6440 | } |
| 6441 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6442 | void LocationsBuilderMIPS::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6443 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6444 | CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6445 | } |
| 6446 | |
| 6447 | void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6448 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 6449 | if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) { |
| 6450 | if (is_r6) { |
| 6451 | GenConditionalMoveR6(select); |
| 6452 | } else { |
| 6453 | GenConditionalMoveR2(select); |
| 6454 | } |
| 6455 | } else { |
| 6456 | LocationSummary* locations = select->GetLocations(); |
| 6457 | MipsLabel false_target; |
| 6458 | GenerateTestAndBranch(select, |
| 6459 | /* condition_input_index */ 2, |
| 6460 | /* true_target */ nullptr, |
| 6461 | &false_target); |
| 6462 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 6463 | __ Bind(&false_target); |
| 6464 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6465 | } |
| 6466 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6467 | void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6468 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6469 | } |
| 6470 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 6471 | void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 6472 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 6473 | } |
| 6474 | |
| 6475 | void CodeGeneratorMIPS::GenerateNop() { |
| 6476 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6477 | } |
| 6478 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6479 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6480 | DataType::Type field_type = field_info.GetFieldType(); |
| 6481 | 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] | 6482 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6483 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6484 | kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6485 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6486 | instruction, |
| 6487 | generate_volatile |
| 6488 | ? LocationSummary::kCallOnMainOnly |
| 6489 | : (object_field_get_with_read_barrier |
| 6490 | ? LocationSummary::kCallOnSlowPath |
| 6491 | : LocationSummary::kNoCall)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6492 | |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6493 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6494 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 6495 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6496 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6497 | if (generate_volatile) { |
| 6498 | InvokeRuntimeCallingConvention calling_convention; |
| 6499 | // need A0 to hold base + offset |
| 6500 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6501 | if (field_type == DataType::Type::kInt64) { |
| 6502 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kInt64)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6503 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6504 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6505 | locations->SetOut(Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6506 | // 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] | 6507 | Location reg = calling_convention.GetReturnLocation(DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6508 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); |
| 6509 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); |
| 6510 | } |
| 6511 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6512 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6513 | locations->SetOut(Location::RequiresFpuRegister()); |
| 6514 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6515 | // The output overlaps in the case of an object field get with |
| 6516 | // read barriers enabled: we do not want the move to overwrite the |
| 6517 | // object's location, as we need it to emit the read barrier. |
| 6518 | locations->SetOut(Location::RequiresRegister(), |
| 6519 | object_field_get_with_read_barrier |
| 6520 | ? Location::kOutputOverlap |
| 6521 | : Location::kNoOutputOverlap); |
| 6522 | } |
| 6523 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6524 | // We need a temporary register for the read barrier marking slow |
| 6525 | // path in CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6526 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6527 | locations->AddTemp(Location::RequiresRegister()); |
| 6528 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6529 | } |
| 6530 | } |
| 6531 | } |
| 6532 | |
| 6533 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, |
| 6534 | const FieldInfo& field_info, |
| 6535 | uint32_t dex_pc) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6536 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 6537 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6538 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6539 | Location obj_loc = locations->InAt(0); |
| 6540 | Register obj = obj_loc.AsRegister<Register>(); |
| 6541 | Location dst_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6542 | LoadOperandType load_type = kLoadUnsignedByte; |
| 6543 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6544 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6545 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6546 | |
| 6547 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6548 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6549 | case DataType::Type::kUint8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6550 | load_type = kLoadUnsignedByte; |
| 6551 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6552 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6553 | load_type = kLoadSignedByte; |
| 6554 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6555 | case DataType::Type::kUint16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6556 | load_type = kLoadUnsignedHalfword; |
| 6557 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6558 | case DataType::Type::kInt16: |
| 6559 | load_type = kLoadSignedHalfword; |
| 6560 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6561 | case DataType::Type::kInt32: |
| 6562 | case DataType::Type::kFloat32: |
| 6563 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6564 | load_type = kLoadWord; |
| 6565 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6566 | case DataType::Type::kInt64: |
| 6567 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6568 | load_type = kLoadDoubleword; |
| 6569 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6570 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6571 | LOG(FATAL) << "Unreachable type " << type; |
| 6572 | UNREACHABLE(); |
| 6573 | } |
| 6574 | |
| 6575 | if (is_volatile && load_type == kLoadDoubleword) { |
| 6576 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6577 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6578 | // Do implicit Null check |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6579 | __ LoadFromOffset(kLoadWord, |
| 6580 | ZERO, |
| 6581 | locations->GetTemp(0).AsRegister<Register>(), |
| 6582 | 0, |
| 6583 | null_checker); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6584 | codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6585 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6586 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6587 | // FP results are returned in core registers. Need to move them. |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6588 | if (dst_loc.IsFpuRegister()) { |
| 6589 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6590 | __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6591 | dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6592 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6593 | DCHECK(dst_loc.IsDoubleStackSlot()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6594 | __ StoreToOffset(kStoreWord, |
| 6595 | locations->GetTemp(1).AsRegister<Register>(), |
| 6596 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6597 | dst_loc.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6598 | __ StoreToOffset(kStoreWord, |
| 6599 | locations->GetTemp(2).AsRegister<Register>(), |
| 6600 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6601 | dst_loc.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6602 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6603 | } |
| 6604 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6605 | if (type == DataType::Type::kReference) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6606 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 6607 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6608 | Location temp_loc = |
| 6609 | kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6610 | // Note that a potential implicit null check is handled in this |
| 6611 | // CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier call. |
| 6612 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6613 | dst_loc, |
| 6614 | obj, |
| 6615 | offset, |
| 6616 | temp_loc, |
| 6617 | /* needs_null_check */ true); |
| 6618 | if (is_volatile) { |
| 6619 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6620 | } |
| 6621 | } else { |
| 6622 | __ LoadFromOffset(kLoadWord, dst_loc.AsRegister<Register>(), obj, offset, null_checker); |
| 6623 | if (is_volatile) { |
| 6624 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6625 | } |
| 6626 | // If read barriers are enabled, emit read barriers other than |
| 6627 | // Baker's using a slow path (and also unpoison the loaded |
| 6628 | // reference, if heap poisoning is enabled). |
| 6629 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 6630 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6631 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6632 | Register dst; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6633 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6634 | DCHECK(dst_loc.IsRegisterPair()); |
| 6635 | dst = dst_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6636 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6637 | DCHECK(dst_loc.IsRegister()); |
| 6638 | dst = dst_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6639 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6640 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6641 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6642 | DCHECK(dst_loc.IsFpuRegister()); |
| 6643 | FRegister dst = dst_loc.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6644 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6645 | __ LoadSFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6646 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6647 | __ LoadDFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6648 | } |
| 6649 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6650 | } |
| 6651 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6652 | // Memory barriers, in the case of references, are handled in the |
| 6653 | // previous switch statement. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6654 | if (is_volatile && (type != DataType::Type::kReference)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6655 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6656 | } |
| 6657 | } |
| 6658 | |
| 6659 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6660 | DataType::Type field_type = field_info.GetFieldType(); |
| 6661 | 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] | 6662 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6663 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6664 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6665 | |
| 6666 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6667 | if (generate_volatile) { |
| 6668 | InvokeRuntimeCallingConvention calling_convention; |
| 6669 | // need A0 to hold base + offset |
| 6670 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6671 | if (field_type == DataType::Type::kInt64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6672 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 6673 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 6674 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6675 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6676 | locations->SetInAt(1, Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6677 | // Pass FP parameters in core registers. |
| 6678 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 6679 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 6680 | } |
| 6681 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6682 | if (DataType::IsFloatingPointType(field_type)) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6683 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6684 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6685 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6686 | } |
| 6687 | } |
| 6688 | } |
| 6689 | |
| 6690 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, |
| 6691 | const FieldInfo& field_info, |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6692 | uint32_t dex_pc, |
| 6693 | bool value_can_be_null) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6694 | DataType::Type type = field_info.GetFieldType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6695 | LocationSummary* locations = instruction->GetLocations(); |
| 6696 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6697 | Location value_location = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6698 | StoreOperandType store_type = kStoreByte; |
| 6699 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6700 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6701 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6702 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6703 | |
| 6704 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6705 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6706 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6707 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6708 | store_type = kStoreByte; |
| 6709 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6710 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6711 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6712 | store_type = kStoreHalfword; |
| 6713 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6714 | case DataType::Type::kInt32: |
| 6715 | case DataType::Type::kFloat32: |
| 6716 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6717 | store_type = kStoreWord; |
| 6718 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6719 | case DataType::Type::kInt64: |
| 6720 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6721 | store_type = kStoreDoubleword; |
| 6722 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6723 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6724 | LOG(FATAL) << "Unreachable type " << type; |
| 6725 | UNREACHABLE(); |
| 6726 | } |
| 6727 | |
| 6728 | if (is_volatile) { |
| 6729 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 6730 | } |
| 6731 | |
| 6732 | if (is_volatile && store_type == kStoreDoubleword) { |
| 6733 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6734 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6735 | // Do implicit Null check. |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6736 | __ LoadFromOffset(kLoadWord, |
| 6737 | ZERO, |
| 6738 | locations->GetTemp(0).AsRegister<Register>(), |
| 6739 | 0, |
| 6740 | null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6741 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6742 | // Pass FP parameters in core registers. |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6743 | if (value_location.IsFpuRegister()) { |
| 6744 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), |
| 6745 | value_location.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6746 | __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6747 | value_location.AsFpuRegister<FRegister>()); |
| 6748 | } else if (value_location.IsDoubleStackSlot()) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6749 | __ LoadFromOffset(kLoadWord, |
| 6750 | locations->GetTemp(1).AsRegister<Register>(), |
| 6751 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6752 | value_location.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6753 | __ LoadFromOffset(kLoadWord, |
| 6754 | locations->GetTemp(2).AsRegister<Register>(), |
| 6755 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6756 | value_location.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6757 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6758 | DCHECK(value_location.IsConstant()); |
| 6759 | DCHECK(value_location.GetConstant()->IsDoubleConstant()); |
| 6760 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6761 | __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(), |
| 6762 | locations->GetTemp(1).AsRegister<Register>(), |
| 6763 | value); |
| 6764 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6765 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6766 | codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6767 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); |
| 6768 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6769 | if (value_location.IsConstant()) { |
| 6770 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 6771 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6772 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6773 | Register src; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6774 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6775 | src = value_location.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6776 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6777 | src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6778 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6779 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 6780 | // Note that in the case where `value` is a null reference, |
| 6781 | // we do not enter this block, as a null reference does not |
| 6782 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6783 | DCHECK_EQ(type, DataType::Type::kReference); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6784 | __ PoisonHeapReference(TMP, src); |
| 6785 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 6786 | } else { |
| 6787 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 6788 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6789 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6790 | FRegister src = value_location.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6791 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6792 | __ StoreSToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6793 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6794 | __ StoreDToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6795 | } |
| 6796 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6797 | } |
| 6798 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6799 | if (needs_write_barrier) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6800 | Register src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6801 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6802 | } |
| 6803 | |
| 6804 | if (is_volatile) { |
| 6805 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 6806 | } |
| 6807 | } |
| 6808 | |
| 6809 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6810 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6811 | } |
| 6812 | |
| 6813 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6814 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 6815 | } |
| 6816 | |
| 6817 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6818 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6819 | } |
| 6820 | |
| 6821 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6822 | HandleFieldSet(instruction, |
| 6823 | instruction->GetFieldInfo(), |
| 6824 | instruction->GetDexPc(), |
| 6825 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6826 | } |
| 6827 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6828 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadOneRegister( |
| 6829 | HInstruction* instruction, |
| 6830 | Location out, |
| 6831 | uint32_t offset, |
| 6832 | Location maybe_temp, |
| 6833 | ReadBarrierOption read_barrier_option) { |
| 6834 | Register out_reg = out.AsRegister<Register>(); |
| 6835 | if (read_barrier_option == kWithReadBarrier) { |
| 6836 | CHECK(kEmitCompilerReadBarrier); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6837 | if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) { |
| 6838 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6839 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6840 | if (kUseBakerReadBarrier) { |
| 6841 | // Load with fast path based Baker's read barrier. |
| 6842 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6843 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6844 | out, |
| 6845 | out_reg, |
| 6846 | offset, |
| 6847 | maybe_temp, |
| 6848 | /* needs_null_check */ false); |
| 6849 | } else { |
| 6850 | // Load with slow path based read barrier. |
| 6851 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6852 | // in the following move operation, as we will need it for the |
| 6853 | // read barrier below. |
| 6854 | __ Move(maybe_temp.AsRegister<Register>(), out_reg); |
| 6855 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6856 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6857 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6858 | } |
| 6859 | } else { |
| 6860 | // Plain load with no read barrier. |
| 6861 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6862 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6863 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6864 | } |
| 6865 | } |
| 6866 | |
| 6867 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadTwoRegisters( |
| 6868 | HInstruction* instruction, |
| 6869 | Location out, |
| 6870 | Location obj, |
| 6871 | uint32_t offset, |
| 6872 | Location maybe_temp, |
| 6873 | ReadBarrierOption read_barrier_option) { |
| 6874 | Register out_reg = out.AsRegister<Register>(); |
| 6875 | Register obj_reg = obj.AsRegister<Register>(); |
| 6876 | if (read_barrier_option == kWithReadBarrier) { |
| 6877 | CHECK(kEmitCompilerReadBarrier); |
| 6878 | if (kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6879 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6880 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6881 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6882 | // Load with fast path based Baker's read barrier. |
| 6883 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6884 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6885 | out, |
| 6886 | obj_reg, |
| 6887 | offset, |
| 6888 | maybe_temp, |
| 6889 | /* needs_null_check */ false); |
| 6890 | } else { |
| 6891 | // Load with slow path based read barrier. |
| 6892 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6893 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6894 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6895 | } |
| 6896 | } else { |
| 6897 | // Plain load with no read barrier. |
| 6898 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6899 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6900 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6901 | } |
| 6902 | } |
| 6903 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6904 | static inline int GetBakerMarkThunkNumber(Register reg) { |
| 6905 | static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 21, "Expecting equal"); |
| 6906 | if (reg >= V0 && reg <= T7) { // 14 consequtive regs. |
| 6907 | return reg - V0; |
| 6908 | } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs. |
| 6909 | return 14 + (reg - S2); |
| 6910 | } else if (reg == FP) { // One more. |
| 6911 | return 20; |
| 6912 | } |
| 6913 | LOG(FATAL) << "Unexpected register " << reg; |
| 6914 | UNREACHABLE(); |
| 6915 | } |
| 6916 | |
| 6917 | static inline int GetBakerMarkFieldArrayThunkDisplacement(Register reg, bool short_offset) { |
| 6918 | int num = GetBakerMarkThunkNumber(reg) + |
| 6919 | (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0); |
| 6920 | return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE; |
| 6921 | } |
| 6922 | |
| 6923 | static inline int GetBakerMarkGcRootThunkDisplacement(Register reg) { |
| 6924 | return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE + |
| 6925 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET; |
| 6926 | } |
| 6927 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6928 | void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6929 | Location root, |
| 6930 | Register obj, |
| 6931 | uint32_t offset, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6932 | ReadBarrierOption read_barrier_option, |
| 6933 | MipsLabel* label_low) { |
| 6934 | bool reordering; |
| 6935 | if (label_low != nullptr) { |
| 6936 | DCHECK_EQ(offset, 0x5678u); |
| 6937 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6938 | Register root_reg = root.AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6939 | if (read_barrier_option == kWithReadBarrier) { |
| 6940 | DCHECK(kEmitCompilerReadBarrier); |
| 6941 | if (kUseBakerReadBarrier) { |
| 6942 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6943 | // Baker's read barrier are used: |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6944 | if (kBakerReadBarrierThunksEnableForGcRoots) { |
| 6945 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6946 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 6947 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 6948 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 6949 | // vice versa. |
| 6950 | // |
| 6951 | // We use thunks for the slow path. That thunk checks the reference |
| 6952 | // and jumps to the entrypoint if needed. |
| 6953 | // |
| 6954 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 6955 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 6956 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6957 | // if (temp != nullptr) { |
| 6958 | // temp = &gc_root_thunk<root_reg> |
| 6959 | // root = temp(root) |
| 6960 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6961 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6962 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 6963 | const int32_t entry_point_offset = |
| 6964 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 6965 | const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg); |
| 6966 | int16_t offset_low = Low16Bits(offset); |
| 6967 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign |
| 6968 | // extension in lw. |
| 6969 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 6970 | Register base = short_offset ? obj : TMP; |
| 6971 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6972 | // threads are suspended or running a checkpoint. |
| 6973 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 6974 | reordering = __ SetReorder(false); |
| 6975 | if (!short_offset) { |
| 6976 | DCHECK(!label_low); |
| 6977 | __ AddUpper(base, obj, offset_high); |
| 6978 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6979 | MipsLabel skip_call; |
| 6980 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6981 | if (label_low != nullptr) { |
| 6982 | DCHECK(short_offset); |
| 6983 | __ Bind(label_low); |
| 6984 | } |
| 6985 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6986 | __ LoadFromOffset(kLoadWord, root_reg, base, offset_low); // Single instruction |
| 6987 | // in delay slot. |
| 6988 | if (isR6) { |
| 6989 | __ Jialc(T9, thunk_disp); |
| 6990 | } else { |
| 6991 | __ Addiu(T9, T9, thunk_disp); |
| 6992 | __ Jalr(T9); |
| 6993 | __ Nop(); |
| 6994 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6995 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6996 | __ SetReorder(reordering); |
| 6997 | } else { |
| 6998 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6999 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 7000 | // load into `temp` (T9) the read barrier mark entry point corresponding |
| 7001 | // to register `root`. If `temp` is null, it means that `GetIsGcMarking()` |
| 7002 | // is false, and vice versa. |
| 7003 | // |
| 7004 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 7005 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7006 | // if (temp != null) { |
| 7007 | // root = temp(root) |
| 7008 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7009 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7010 | if (label_low != nullptr) { |
| 7011 | reordering = __ SetReorder(false); |
| 7012 | __ Bind(label_low); |
| 7013 | } |
| 7014 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7015 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7016 | if (label_low != nullptr) { |
| 7017 | __ SetReorder(reordering); |
| 7018 | } |
| 7019 | static_assert( |
| 7020 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7021 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7022 | "have different sizes."); |
| 7023 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7024 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7025 | "have different sizes."); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7026 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7027 | // Slow path marking the GC root `root`. |
| 7028 | Location temp = Location::RegisterLocation(T9); |
| 7029 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7030 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS( |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7031 | instruction, |
| 7032 | root, |
| 7033 | /*entrypoint*/ temp); |
| 7034 | codegen_->AddSlowPath(slow_path); |
| 7035 | |
| 7036 | const int32_t entry_point_offset = |
| 7037 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(root.reg() - 1); |
| 7038 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7039 | // threads are suspended or running a checkpoint. |
| 7040 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 7041 | __ Bnez(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 7042 | __ Bind(slow_path->GetExitLabel()); |
| 7043 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7044 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7045 | if (label_low != nullptr) { |
| 7046 | reordering = __ SetReorder(false); |
| 7047 | __ Bind(label_low); |
| 7048 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7049 | // GC root loaded through a slow path for read barriers other |
| 7050 | // than Baker's. |
| 7051 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 7052 | __ Addiu32(root_reg, obj, offset); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7053 | if (label_low != nullptr) { |
| 7054 | __ SetReorder(reordering); |
| 7055 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7056 | // /* mirror::Object* */ root = root->Read() |
| 7057 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7058 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7059 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7060 | if (label_low != nullptr) { |
| 7061 | reordering = __ SetReorder(false); |
| 7062 | __ Bind(label_low); |
| 7063 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7064 | // Plain GC root load with no read barrier. |
| 7065 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7066 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7067 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7068 | // do not have to unpoison `root_reg` here. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7069 | if (label_low != nullptr) { |
| 7070 | __ SetReorder(reordering); |
| 7071 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7072 | } |
| 7073 | } |
| 7074 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7075 | void CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7076 | Location ref, |
| 7077 | Register obj, |
| 7078 | uint32_t offset, |
| 7079 | Location temp, |
| 7080 | bool needs_null_check) { |
| 7081 | DCHECK(kEmitCompilerReadBarrier); |
| 7082 | DCHECK(kUseBakerReadBarrier); |
| 7083 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7084 | if (kBakerReadBarrierThunksEnableForFields) { |
| 7085 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 7086 | // to decide whether to mark the loaded reference or not. Instead, we |
| 7087 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 7088 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 7089 | // vice versa. |
| 7090 | // |
| 7091 | // We use thunks for the slow path. That thunk checks the reference |
| 7092 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 7093 | // it issues a load-load memory barrier and returns to the original |
| 7094 | // reference load. |
| 7095 | // |
| 7096 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 7097 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 7098 | // if (temp != nullptr) { |
| 7099 | // temp = &field_array_thunk<holder_reg> |
| 7100 | // temp() |
| 7101 | // } |
| 7102 | // not_gray_return_address: |
| 7103 | // // If the offset is too large to fit into the lw instruction, we |
| 7104 | // // use an adjusted base register (TMP) here. This register |
| 7105 | // // receives bits 16 ... 31 of the offset before the thunk invocation |
| 7106 | // // and the thunk benefits from it. |
| 7107 | // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load. |
| 7108 | // gray_return_address: |
| 7109 | |
| 7110 | DCHECK(temp.IsInvalid()); |
| 7111 | bool isR6 = GetInstructionSetFeatures().IsR6(); |
| 7112 | int16_t offset_low = Low16Bits(offset); |
| 7113 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lw. |
| 7114 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 7115 | bool reordering = __ SetReorder(false); |
| 7116 | const int32_t entry_point_offset = |
| 7117 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 7118 | // There may have or may have not been a null check if the field offset is smaller than |
| 7119 | // the page size. |
| 7120 | // There must've been a null check in case it's actually a load from an array. |
| 7121 | // We will, however, perform an explicit null check in the thunk as it's easier to |
| 7122 | // do it than not. |
| 7123 | if (instruction->IsArrayGet()) { |
| 7124 | DCHECK(!needs_null_check); |
| 7125 | } |
| 7126 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset); |
| 7127 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7128 | // threads are suspended or running a checkpoint. |
| 7129 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 7130 | Register ref_reg = ref.AsRegister<Register>(); |
| 7131 | Register base = short_offset ? obj : TMP; |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7132 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7133 | if (short_offset) { |
| 7134 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7135 | __ Beqzc(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7136 | __ Nop(); // In forbidden slot. |
| 7137 | __ Jialc(T9, thunk_disp); |
| 7138 | } else { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7139 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7140 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 7141 | __ Jalr(T9); |
| 7142 | __ Nop(); // In delay slot. |
| 7143 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7144 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7145 | } else { |
| 7146 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7147 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7148 | __ Aui(base, obj, offset_high); // In delay slot. |
| 7149 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7150 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7151 | } else { |
| 7152 | __ Lui(base, offset_high); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7153 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7154 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 7155 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7156 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7157 | __ Addu(base, base, obj); // In delay slot. |
| 7158 | } |
| 7159 | } |
| 7160 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7161 | __ LoadFromOffset(kLoadWord, ref_reg, base, offset_low); // Single instruction. |
| 7162 | if (needs_null_check) { |
| 7163 | MaybeRecordImplicitNullCheck(instruction); |
| 7164 | } |
| 7165 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7166 | __ SetReorder(reordering); |
| 7167 | return; |
| 7168 | } |
| 7169 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7170 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7171 | Location no_index = Location::NoLocation(); |
| 7172 | ScaleFactor no_scale_factor = TIMES_1; |
| 7173 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 7174 | ref, |
| 7175 | obj, |
| 7176 | offset, |
| 7177 | no_index, |
| 7178 | no_scale_factor, |
| 7179 | temp, |
| 7180 | needs_null_check); |
| 7181 | } |
| 7182 | |
| 7183 | void CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7184 | Location ref, |
| 7185 | Register obj, |
| 7186 | uint32_t data_offset, |
| 7187 | Location index, |
| 7188 | Location temp, |
| 7189 | bool needs_null_check) { |
| 7190 | DCHECK(kEmitCompilerReadBarrier); |
| 7191 | DCHECK(kUseBakerReadBarrier); |
| 7192 | |
| 7193 | static_assert( |
| 7194 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7195 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7196 | ScaleFactor scale_factor = TIMES_4; |
| 7197 | |
| 7198 | if (kBakerReadBarrierThunksEnableForArrays) { |
| 7199 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 7200 | // to decide whether to mark the loaded reference or not. Instead, we |
| 7201 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 7202 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 7203 | // vice versa. |
| 7204 | // |
| 7205 | // We use thunks for the slow path. That thunk checks the reference |
| 7206 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 7207 | // it issues a load-load memory barrier and returns to the original |
| 7208 | // reference load. |
| 7209 | // |
| 7210 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 7211 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 7212 | // if (temp != nullptr) { |
| 7213 | // temp = &field_array_thunk<holder_reg> |
| 7214 | // temp() |
| 7215 | // } |
| 7216 | // not_gray_return_address: |
| 7217 | // // The element address is pre-calculated in the TMP register before the |
| 7218 | // // thunk invocation and the thunk benefits from it. |
| 7219 | // HeapReference<mirror::Object> reference = data[index]; // Original reference load. |
| 7220 | // gray_return_address: |
| 7221 | |
| 7222 | DCHECK(temp.IsInvalid()); |
| 7223 | DCHECK(index.IsValid()); |
| 7224 | bool reordering = __ SetReorder(false); |
| 7225 | const int32_t entry_point_offset = |
| 7226 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 7227 | // We will not do the explicit null check in the thunk as some form of a null check |
| 7228 | // must've been done earlier. |
| 7229 | DCHECK(!needs_null_check); |
| 7230 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false); |
| 7231 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7232 | // threads are suspended or running a checkpoint. |
| 7233 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 7234 | Register ref_reg = ref.AsRegister<Register>(); |
| 7235 | Register index_reg = index.IsRegisterPair() |
| 7236 | ? index.AsRegisterPairLow<Register>() |
| 7237 | : index.AsRegister<Register>(); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7238 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7239 | if (GetInstructionSetFeatures().IsR6()) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7240 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7241 | __ Lsa(TMP, index_reg, obj, scale_factor); // In delay slot. |
| 7242 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7243 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7244 | } else { |
| 7245 | __ Sll(TMP, index_reg, scale_factor); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7246 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7247 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 7248 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 7249 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7250 | __ Addu(TMP, TMP, obj); // In delay slot. |
| 7251 | } |
| 7252 | // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor)) |
| 7253 | DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset; |
| 7254 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, data_offset); // Single instruction. |
| 7255 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7256 | __ SetReorder(reordering); |
| 7257 | return; |
| 7258 | } |
| 7259 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7260 | // /* HeapReference<Object> */ ref = |
| 7261 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7262 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 7263 | ref, |
| 7264 | obj, |
| 7265 | data_offset, |
| 7266 | index, |
| 7267 | scale_factor, |
| 7268 | temp, |
| 7269 | needs_null_check); |
| 7270 | } |
| 7271 | |
| 7272 | void CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7273 | Location ref, |
| 7274 | Register obj, |
| 7275 | uint32_t offset, |
| 7276 | Location index, |
| 7277 | ScaleFactor scale_factor, |
| 7278 | Location temp, |
| 7279 | bool needs_null_check, |
| 7280 | bool always_update_field) { |
| 7281 | DCHECK(kEmitCompilerReadBarrier); |
| 7282 | DCHECK(kUseBakerReadBarrier); |
| 7283 | |
| 7284 | // In slow path based read barriers, the read barrier call is |
| 7285 | // inserted after the original load. However, in fast path based |
| 7286 | // Baker's read barriers, we need to perform the load of |
| 7287 | // mirror::Object::monitor_ *before* the original reference load. |
| 7288 | // This load-load ordering is required by the read barrier. |
| 7289 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7290 | // |
| 7291 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7292 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7293 | // HeapReference<Object> ref = *src; // Original reference load. |
| 7294 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 7295 | // if (is_gray) { |
| 7296 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7297 | // } |
| 7298 | // |
| 7299 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7300 | // slightly more complex as it performs additional checks that we do |
| 7301 | // not do here for performance reasons. |
| 7302 | |
| 7303 | Register ref_reg = ref.AsRegister<Register>(); |
| 7304 | Register temp_reg = temp.AsRegister<Register>(); |
| 7305 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7306 | |
| 7307 | // /* int32_t */ monitor = obj->monitor_ |
| 7308 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 7309 | if (needs_null_check) { |
| 7310 | MaybeRecordImplicitNullCheck(instruction); |
| 7311 | } |
| 7312 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7313 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7314 | "art::LockWord and int32_t have different sizes."); |
| 7315 | |
| 7316 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 7317 | |
| 7318 | // The actual reference load. |
| 7319 | if (index.IsValid()) { |
| 7320 | // Load types involving an "index": ArrayGet, |
| 7321 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7322 | // intrinsics. |
| 7323 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 7324 | if (index.IsConstant()) { |
| 7325 | size_t computed_offset = |
| 7326 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 7327 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7328 | } else { |
| 7329 | // Handle the special case of the |
| 7330 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7331 | // intrinsics, which use a register pair as index ("long |
| 7332 | // offset"), of which only the low part contains data. |
| 7333 | Register index_reg = index.IsRegisterPair() |
| 7334 | ? index.AsRegisterPairLow<Register>() |
| 7335 | : index.AsRegister<Register>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 7336 | __ ShiftAndAdd(TMP, index_reg, obj, scale_factor, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7337 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, offset); |
| 7338 | } |
| 7339 | } else { |
| 7340 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7341 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7342 | } |
| 7343 | |
| 7344 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7345 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7346 | |
| 7347 | // Slow path marking the object `ref` when it is gray. |
| 7348 | SlowPathCodeMIPS* slow_path; |
| 7349 | if (always_update_field) { |
| 7350 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS only supports address |
| 7351 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7352 | // `field_offset` is a register pair (of which only the lower half |
| 7353 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7354 | // to be null in this code path. |
| 7355 | DCHECK_EQ(offset, 0u); |
| 7356 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7357 | slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7358 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(instruction, |
| 7359 | ref, |
| 7360 | obj, |
| 7361 | /* field_offset */ index, |
| 7362 | temp_reg); |
| 7363 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7364 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS(instruction, ref); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7365 | } |
| 7366 | AddSlowPath(slow_path); |
| 7367 | |
| 7368 | // if (rb_state == ReadBarrier::GrayState()) |
| 7369 | // ref = ReadBarrier::Mark(ref); |
| 7370 | // Given the numeric representation, it's enough to check the low bit of the |
| 7371 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 7372 | // performing a branch on less than zero. |
| 7373 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7374 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 7375 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 7376 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 7377 | __ Bltz(temp_reg, slow_path->GetEntryLabel()); |
| 7378 | __ Bind(slow_path->GetExitLabel()); |
| 7379 | } |
| 7380 | |
| 7381 | void CodeGeneratorMIPS::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7382 | Location out, |
| 7383 | Location ref, |
| 7384 | Location obj, |
| 7385 | uint32_t offset, |
| 7386 | Location index) { |
| 7387 | DCHECK(kEmitCompilerReadBarrier); |
| 7388 | |
| 7389 | // Insert a slow path based read barrier *after* the reference load. |
| 7390 | // |
| 7391 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7392 | // reference will be carried out by the runtime within the slow |
| 7393 | // path. |
| 7394 | // |
| 7395 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7396 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7397 | // not used by the artReadBarrierSlow entry point. |
| 7398 | // |
| 7399 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7400 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7401 | ReadBarrierForHeapReferenceSlowPathMIPS(instruction, out, ref, obj, offset, index); |
| 7402 | AddSlowPath(slow_path); |
| 7403 | |
| 7404 | __ B(slow_path->GetEntryLabel()); |
| 7405 | __ Bind(slow_path->GetExitLabel()); |
| 7406 | } |
| 7407 | |
| 7408 | void CodeGeneratorMIPS::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7409 | Location out, |
| 7410 | Location ref, |
| 7411 | Location obj, |
| 7412 | uint32_t offset, |
| 7413 | Location index) { |
| 7414 | if (kEmitCompilerReadBarrier) { |
| 7415 | // Baker's read barriers shall be handled by the fast path |
| 7416 | // (CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier). |
| 7417 | DCHECK(!kUseBakerReadBarrier); |
| 7418 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7419 | // by the runtime within the slow path. |
| 7420 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 7421 | } else if (kPoisonHeapReferences) { |
| 7422 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7423 | } |
| 7424 | } |
| 7425 | |
| 7426 | void CodeGeneratorMIPS::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7427 | Location out, |
| 7428 | Location root) { |
| 7429 | DCHECK(kEmitCompilerReadBarrier); |
| 7430 | |
| 7431 | // Insert a slow path based read barrier *after* the GC root load. |
| 7432 | // |
| 7433 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7434 | // not need to do anything special for this here. |
| 7435 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7436 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS(instruction, out, root); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7437 | AddSlowPath(slow_path); |
| 7438 | |
| 7439 | __ B(slow_path->GetEntryLabel()); |
| 7440 | __ Bind(slow_path->GetExitLabel()); |
| 7441 | } |
| 7442 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7443 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7444 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7445 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7446 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7447 | switch (type_check_kind) { |
| 7448 | case TypeCheckKind::kExactCheck: |
| 7449 | case TypeCheckKind::kAbstractClassCheck: |
| 7450 | case TypeCheckKind::kClassHierarchyCheck: |
| 7451 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7452 | call_kind = |
| 7453 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7454 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7455 | break; |
| 7456 | case TypeCheckKind::kArrayCheck: |
| 7457 | case TypeCheckKind::kUnresolvedCheck: |
| 7458 | case TypeCheckKind::kInterfaceCheck: |
| 7459 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7460 | break; |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7461 | case TypeCheckKind::kBitstringCheck: |
| 7462 | break; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7463 | } |
| 7464 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7465 | LocationSummary* locations = |
| 7466 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7467 | if (baker_read_barrier_slow_path) { |
| 7468 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7469 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7470 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7471 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7472 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7473 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7474 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7475 | } else { |
| 7476 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7477 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7478 | // The output does overlap inputs. |
| 7479 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 7480 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7481 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7482 | } |
| 7483 | |
| 7484 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7485 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7486 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7487 | Location obj_loc = locations->InAt(0); |
| 7488 | Register obj = obj_loc.AsRegister<Register>(); |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7489 | Location cls = locations->InAt(1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7490 | Location out_loc = locations->Out(); |
| 7491 | Register out = out_loc.AsRegister<Register>(); |
| 7492 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7493 | DCHECK_LE(num_temps, 1u); |
| 7494 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7495 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7496 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7497 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7498 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7499 | MipsLabel done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7500 | SlowPathCodeMIPS* slow_path = nullptr; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7501 | |
| 7502 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7503 | // Avoid this check if we know `obj` is not null. |
| 7504 | if (instruction->MustDoNullCheck()) { |
| 7505 | __ Move(out, ZERO); |
| 7506 | __ Beqz(obj, &done); |
| 7507 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7508 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7509 | switch (type_check_kind) { |
| 7510 | case TypeCheckKind::kExactCheck: { |
| 7511 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7512 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7513 | out_loc, |
| 7514 | obj_loc, |
| 7515 | class_offset, |
| 7516 | maybe_temp_loc, |
| 7517 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7518 | // Classes must be equal for the instanceof to succeed. |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7519 | __ Xor(out, out, cls.AsRegister<Register>()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7520 | __ Sltiu(out, out, 1); |
| 7521 | break; |
| 7522 | } |
| 7523 | |
| 7524 | case TypeCheckKind::kAbstractClassCheck: { |
| 7525 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7526 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7527 | out_loc, |
| 7528 | obj_loc, |
| 7529 | class_offset, |
| 7530 | maybe_temp_loc, |
| 7531 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7532 | // If the class is abstract, we eagerly fetch the super class of the |
| 7533 | // object to avoid doing a comparison we know will fail. |
| 7534 | MipsLabel loop; |
| 7535 | __ Bind(&loop); |
| 7536 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7537 | GenerateReferenceLoadOneRegister(instruction, |
| 7538 | out_loc, |
| 7539 | super_offset, |
| 7540 | maybe_temp_loc, |
| 7541 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7542 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7543 | __ Beqz(out, &done); |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7544 | __ Bne(out, cls.AsRegister<Register>(), &loop); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7545 | __ LoadConst32(out, 1); |
| 7546 | break; |
| 7547 | } |
| 7548 | |
| 7549 | case TypeCheckKind::kClassHierarchyCheck: { |
| 7550 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7551 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7552 | out_loc, |
| 7553 | obj_loc, |
| 7554 | class_offset, |
| 7555 | maybe_temp_loc, |
| 7556 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7557 | // Walk over the class hierarchy to find a match. |
| 7558 | MipsLabel loop, success; |
| 7559 | __ Bind(&loop); |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7560 | __ Beq(out, cls.AsRegister<Register>(), &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7561 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7562 | GenerateReferenceLoadOneRegister(instruction, |
| 7563 | out_loc, |
| 7564 | super_offset, |
| 7565 | maybe_temp_loc, |
| 7566 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7567 | __ Bnez(out, &loop); |
| 7568 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7569 | __ B(&done); |
| 7570 | __ Bind(&success); |
| 7571 | __ LoadConst32(out, 1); |
| 7572 | break; |
| 7573 | } |
| 7574 | |
| 7575 | case TypeCheckKind::kArrayObjectCheck: { |
| 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, |
| 7582 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7583 | // Do an exact check. |
| 7584 | MipsLabel success; |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7585 | __ Beq(out, cls.AsRegister<Register>(), &success); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7586 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7587 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7588 | GenerateReferenceLoadOneRegister(instruction, |
| 7589 | out_loc, |
| 7590 | component_offset, |
| 7591 | maybe_temp_loc, |
| 7592 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7593 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7594 | __ Beqz(out, &done); |
| 7595 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7596 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 7597 | __ Sltiu(out, out, 1); |
| 7598 | __ B(&done); |
| 7599 | __ Bind(&success); |
| 7600 | __ LoadConst32(out, 1); |
| 7601 | break; |
| 7602 | } |
| 7603 | |
| 7604 | case TypeCheckKind::kArrayCheck: { |
| 7605 | // No read barrier since the slow path will retry upon failure. |
| 7606 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7607 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7608 | out_loc, |
| 7609 | obj_loc, |
| 7610 | class_offset, |
| 7611 | maybe_temp_loc, |
| 7612 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7613 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7614 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7615 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7616 | codegen_->AddSlowPath(slow_path); |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7617 | __ Bne(out, cls.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7618 | __ LoadConst32(out, 1); |
| 7619 | break; |
| 7620 | } |
| 7621 | |
| 7622 | case TypeCheckKind::kUnresolvedCheck: |
| 7623 | case TypeCheckKind::kInterfaceCheck: { |
| 7624 | // Note that we indeed only call on slow path, but we always go |
| 7625 | // into the slow path for the unresolved and interface check |
| 7626 | // cases. |
| 7627 | // |
| 7628 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7629 | // entry point without resorting to a type checking slow path |
| 7630 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7631 | // require to assign fixed registers for the inputs of this |
| 7632 | // HInstanceOf instruction (following the runtime calling |
| 7633 | // convention), which might be cluttered by the potential first |
| 7634 | // read barrier emission at the beginning of this method. |
| 7635 | // |
| 7636 | // TODO: Introduce a new runtime entry point taking the object |
| 7637 | // to test (instead of its class) as argument, and let it deal |
| 7638 | // with the read barrier issues. This will let us refactor this |
| 7639 | // case of the `switch` code as it was previously (with a direct |
| 7640 | // call to the runtime not using a type checking slow path). |
| 7641 | // This should also be beneficial for the other cases above. |
| 7642 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7643 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7644 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7645 | codegen_->AddSlowPath(slow_path); |
| 7646 | __ B(slow_path->GetEntryLabel()); |
| 7647 | break; |
| 7648 | } |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 7649 | |
| 7650 | case TypeCheckKind::kBitstringCheck: { |
| 7651 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7652 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7653 | out_loc, |
| 7654 | obj_loc, |
| 7655 | class_offset, |
| 7656 | maybe_temp_loc, |
| 7657 | kWithoutReadBarrier); |
| 7658 | |
| 7659 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 7660 | __ Sltiu(out, out, 1); |
| 7661 | break; |
| 7662 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7663 | } |
| 7664 | |
| 7665 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7666 | |
| 7667 | if (slow_path != nullptr) { |
| 7668 | __ Bind(slow_path->GetExitLabel()); |
| 7669 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7670 | } |
| 7671 | |
| 7672 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7673 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7674 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7675 | } |
| 7676 | |
| 7677 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 7678 | // Will be generated at use site. |
| 7679 | } |
| 7680 | |
| 7681 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7682 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7683 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7684 | } |
| 7685 | |
| 7686 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 7687 | // Will be generated at use site. |
| 7688 | } |
| 7689 | |
| 7690 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { |
| 7691 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 7692 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 7693 | } |
| 7694 | |
| 7695 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7696 | HandleInvoke(invoke); |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7697 | // 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] | 7698 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7699 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T7)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7700 | } |
| 7701 | |
| 7702 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7703 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 7704 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7705 | Location receiver = invoke->GetLocations()->InAt(0); |
| 7706 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7707 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7708 | |
| 7709 | // Set the hidden argument. |
| 7710 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 7711 | invoke->GetDexMethodIndex()); |
| 7712 | |
| 7713 | // temp = object->GetClass(); |
| 7714 | if (receiver.IsStackSlot()) { |
| 7715 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 7716 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 7717 | } else { |
| 7718 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 7719 | } |
| 7720 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7721 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7722 | // emit a read barrier for the previous class reference load. |
| 7723 | // However this is not required in practice, as this is an |
| 7724 | // intermediate/temporary reference and because the current |
| 7725 | // concurrent copying collector keeps the from-space memory |
| 7726 | // intact/accessible until the end of the marking phase (the |
| 7727 | // concurrent copying collector may not in the future). |
| 7728 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 7729 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 7730 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
| 7731 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7732 | invoke->GetImtIndex(), kMipsPointerSize)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7733 | // temp = temp->GetImtEntryAt(method_offset); |
| 7734 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7735 | // T9 = temp->GetEntryPoint(); |
| 7736 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 7737 | // T9(); |
| 7738 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7739 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7740 | DCHECK(!codegen_->IsLeafMethod()); |
| 7741 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 7742 | } |
| 7743 | |
| 7744 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7745 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7746 | if (intrinsic.TryDispatch(invoke)) { |
| 7747 | return; |
| 7748 | } |
| 7749 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7750 | HandleInvoke(invoke); |
| 7751 | } |
| 7752 | |
| 7753 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 7754 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 7755 | // art::PrepareForRegisterAllocation. |
| 7756 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7757 | |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7758 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7759 | bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
| 7760 | bool has_extra_input = invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7761 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7762 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7763 | if (intrinsic.TryDispatch(invoke)) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7764 | if (invoke->GetLocations()->CanCall() && has_extra_input) { |
| 7765 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 7766 | } |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7767 | return; |
| 7768 | } |
| 7769 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7770 | HandleInvoke(invoke); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7771 | |
| 7772 | // Add the extra input register if either the dex cache array base register |
| 7773 | // or the PC-relative base register for accessing literals is needed. |
| 7774 | if (has_extra_input) { |
| 7775 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 7776 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7777 | } |
| 7778 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 7779 | void LocationsBuilderMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7780 | HandleInvoke(invoke); |
| 7781 | } |
| 7782 | |
| 7783 | void InstructionCodeGeneratorMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7784 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 7785 | } |
| 7786 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7787 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7788 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7789 | IntrinsicCodeGeneratorMIPS intrinsic(codegen); |
| 7790 | intrinsic.Dispatch(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7791 | return true; |
| 7792 | } |
| 7793 | return false; |
| 7794 | } |
| 7795 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7796 | HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7797 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7798 | switch (desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7799 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7800 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7801 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7802 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7803 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7804 | case HLoadString::LoadKind::kJitTableAddress: |
| 7805 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7806 | break; |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7807 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7808 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7809 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7810 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7811 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7812 | } |
| 7813 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7814 | HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind( |
| 7815 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7816 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7817 | case HLoadClass::LoadKind::kInvalid: |
| 7818 | LOG(FATAL) << "UNREACHABLE"; |
| 7819 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7820 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7821 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7822 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7823 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7824 | case HLoadClass::LoadKind::kBssEntry: |
| 7825 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7826 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7827 | case HLoadClass::LoadKind::kJitTableAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7828 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7829 | break; |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7830 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7831 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7832 | break; |
| 7833 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7834 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7835 | } |
| 7836 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7837 | Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7838 | Register temp) { |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7839 | CHECK(!GetInstructionSetFeatures().IsR6()); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7840 | CHECK(!GetGraph()->HasIrreducibleLoops()); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7841 | CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7842 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7843 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7844 | return location.AsRegister<Register>(); |
| 7845 | } |
| 7846 | // For intrinsics we allow any location, so it may be on the stack. |
| 7847 | if (!location.IsRegister()) { |
| 7848 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7849 | return temp; |
| 7850 | } |
| 7851 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7852 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7853 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7854 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7855 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 7856 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 7857 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 7858 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7859 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7860 | return temp; |
| 7861 | } |
| 7862 | return location.AsRegister<Register>(); |
| 7863 | } |
| 7864 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7865 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( |
| 7866 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 7867 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7868 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7869 | } |
| 7870 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7871 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall( |
| 7872 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7873 | // 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] | 7874 | 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] | 7875 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 7876 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7877 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7878 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 7879 | Register base_reg = (invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7880 | ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>()) |
| 7881 | : ZERO; |
| 7882 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7883 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7884 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7885 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7886 | uint32_t offset = |
| 7887 | GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7888 | __ LoadFromOffset(kLoadWord, |
| 7889 | temp.AsRegister<Register>(), |
| 7890 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7891 | offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7892 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7893 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7894 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7895 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7896 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7897 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 7898 | DCHECK(GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7899 | PcRelativePatchInfo* info_high = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 7900 | PcRelativePatchInfo* info_low = |
| 7901 | NewPcRelativeMethodPatch(invoke->GetTargetMethod(), info_high); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7902 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7903 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 7904 | __ Addiu(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7905 | break; |
| 7906 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7907 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7908 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 7909 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7910 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7911 | PcRelativePatchInfo* info_high = NewMethodBssEntryPatch( |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7912 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7913 | PcRelativePatchInfo* info_low = NewMethodBssEntryPatch( |
| 7914 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7915 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7916 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 7917 | __ Lw(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7918 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7919 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7920 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 7921 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 7922 | return; // No code pointer retrieval; the runtime performs the call directly. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7923 | } |
| 7924 | } |
| 7925 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7926 | switch (code_ptr_location) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7927 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7928 | __ Bal(&frame_entry_label_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7929 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7930 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7931 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 7932 | __ LoadFromOffset(kLoadWord, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7933 | T9, |
| 7934 | callee_method.AsRegister<Register>(), |
| 7935 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7936 | kMipsPointerSize).Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7937 | // T9() |
| 7938 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7939 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7940 | break; |
| 7941 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7942 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 7943 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7944 | DCHECK(!IsLeafMethod()); |
| 7945 | } |
| 7946 | |
| 7947 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 7948 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 7949 | // art::PrepareForRegisterAllocation. |
| 7950 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7951 | |
| 7952 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 7953 | return; |
| 7954 | } |
| 7955 | |
| 7956 | LocationSummary* locations = invoke->GetLocations(); |
| 7957 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 7958 | locations->HasTemps() |
| 7959 | ? locations->GetTemp(0) |
| 7960 | : Location::NoLocation()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7961 | } |
| 7962 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7963 | void CodeGeneratorMIPS::GenerateVirtualCall( |
| 7964 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 7965 | // Use the calling convention instead of the location of the receiver, as |
| 7966 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7967 | // slow path, the arguments have been moved to the right place, so here we are |
| 7968 | // guaranteed that the receiver is the first register of the calling convention. |
| 7969 | InvokeDexCallingConvention calling_convention; |
| 7970 | Register receiver = calling_convention.GetRegisterAt(0); |
| 7971 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7972 | Register temp = temp_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7973 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7974 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); |
| 7975 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7976 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7977 | |
| 7978 | // temp = object->GetClass(); |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 7979 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7980 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7981 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7982 | // emit a read barrier for the previous class reference load. |
| 7983 | // However this is not required in practice, as this is an |
| 7984 | // intermediate/temporary reference and because the current |
| 7985 | // concurrent copying collector keeps the from-space memory |
| 7986 | // intact/accessible until the end of the marking phase (the |
| 7987 | // concurrent copying collector may not in the future). |
| 7988 | __ MaybeUnpoisonHeapReference(temp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7989 | // temp = temp->GetMethodAt(method_offset); |
| 7990 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7991 | // T9 = temp->GetEntryPoint(); |
| 7992 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 7993 | // T9(); |
| 7994 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7995 | __ NopIfNoReordering(); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7996 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7997 | } |
| 7998 | |
| 7999 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 8000 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 8001 | return; |
| 8002 | } |
| 8003 | |
| 8004 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8005 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8006 | } |
| 8007 | |
| 8008 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8009 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8010 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8011 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8012 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 8013 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8014 | return; |
| 8015 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8016 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8017 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8018 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8019 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 8020 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8021 | ? LocationSummary::kCallOnSlowPath |
| 8022 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8023 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8024 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 8025 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 8026 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8027 | switch (load_kind) { |
| 8028 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8029 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8030 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8031 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8032 | case HLoadClass::LoadKind::kBssEntry: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8033 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8034 | break; |
| 8035 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8036 | if (has_irreducible_loops) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 8037 | if (load_kind != HLoadClass::LoadKind::kBootImageAddress) { |
| 8038 | codegen_->ClobberRA(); |
| 8039 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8040 | break; |
| 8041 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8042 | FALLTHROUGH_INTENDED; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8043 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8044 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8045 | break; |
| 8046 | default: |
| 8047 | break; |
| 8048 | } |
| 8049 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8050 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 8051 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 8052 | // 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] | 8053 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 8054 | InvokeRuntimeCallingConvention calling_convention; |
| 8055 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8056 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 8057 | } else { |
| 8058 | // For non-Baker read barriers we have a temp-clobbering call. |
| 8059 | } |
| 8060 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8061 | } |
| 8062 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 8063 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 8064 | // move. |
| 8065 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8066 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8067 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8068 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 8069 | return; |
| 8070 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8071 | DCHECK(!cls->NeedsAccessCheck()); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 8072 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8073 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8074 | Location out_loc = locations->Out(); |
| 8075 | Register out = out_loc.AsRegister<Register>(); |
| 8076 | Register base_or_current_method_reg; |
| 8077 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8078 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8079 | switch (load_kind) { |
| 8080 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8081 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8082 | case HLoadClass::LoadKind::kBootImageAddress: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8083 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8084 | case HLoadClass::LoadKind::kBssEntry: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8085 | base_or_current_method_reg = |
| 8086 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8087 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8088 | case HLoadClass::LoadKind::kReferrersClass: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8089 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8090 | base_or_current_method_reg = locations->InAt(0).AsRegister<Register>(); |
| 8091 | break; |
| 8092 | default: |
| 8093 | base_or_current_method_reg = ZERO; |
| 8094 | break; |
| 8095 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 8096 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8097 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 8098 | ? kWithoutReadBarrier |
| 8099 | : kCompilerReadBarrierOption; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8100 | bool generate_null_check = false; |
| 8101 | switch (load_kind) { |
| 8102 | case HLoadClass::LoadKind::kReferrersClass: { |
| 8103 | DCHECK(!cls->CanCallRuntime()); |
| 8104 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 8105 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 8106 | GenerateGcRootFieldLoad(cls, |
| 8107 | out_loc, |
| 8108 | base_or_current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8109 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 8110 | read_barrier_option); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8111 | break; |
| 8112 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8113 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8114 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8115 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8116 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8117 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8118 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8119 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8120 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8121 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 8122 | base_or_current_method_reg); |
| 8123 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8124 | break; |
| 8125 | } |
| 8126 | case HLoadClass::LoadKind::kBootImageAddress: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8127 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 8128 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 8129 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 8130 | DCHECK_NE(address, 0u); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8131 | if (isR6 || !has_irreducible_loops) { |
| 8132 | __ LoadLiteral(out, |
| 8133 | base_or_current_method_reg, |
| 8134 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 8135 | } else { |
| 8136 | __ LoadConst32(out, address); |
| 8137 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8138 | break; |
| 8139 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 8140 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 8141 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 8142 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
| 8143 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 8144 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8145 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
| 8146 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8147 | out, |
| 8148 | base_or_current_method_reg); |
| 8149 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
| 8150 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 8151 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 8152 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 8153 | if (masked_hash != 0) { |
| 8154 | __ Addiu(out, out, -masked_hash); |
| 8155 | } |
| 8156 | break; |
| 8157 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8158 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8159 | CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high = |
| 8160 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8161 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8162 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8163 | codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8164 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8165 | base_or_current_method_reg); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8166 | GenerateGcRootFieldLoad(cls, |
| 8167 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8168 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8169 | /* placeholder */ 0x5678, |
| 8170 | read_barrier_option, |
| 8171 | &info_low->label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8172 | generate_null_check = true; |
| 8173 | break; |
| 8174 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8175 | case HLoadClass::LoadKind::kJitTableAddress: { |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8176 | CodeGeneratorMIPS::JitPatchInfo* info = codegen_->NewJitRootClassPatch(cls->GetDexFile(), |
| 8177 | cls->GetTypeIndex(), |
| 8178 | cls->GetClass()); |
| 8179 | bool reordering = __ SetReorder(false); |
| 8180 | __ Bind(&info->high_label); |
| 8181 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8182 | __ SetReorder(reordering); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8183 | GenerateGcRootFieldLoad(cls, |
| 8184 | out_loc, |
| 8185 | out, |
| 8186 | /* placeholder */ 0x5678, |
| 8187 | read_barrier_option, |
| 8188 | &info->low_label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8189 | break; |
| 8190 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8191 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 8192 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 8193 | LOG(FATAL) << "UNREACHABLE"; |
| 8194 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8195 | } |
| 8196 | |
| 8197 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 8198 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8199 | SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS( |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8200 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8201 | codegen_->AddSlowPath(slow_path); |
| 8202 | if (generate_null_check) { |
| 8203 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 8204 | } |
| 8205 | if (cls->MustGenerateClinitCheck()) { |
| 8206 | GenerateClassInitializationCheck(slow_path, out); |
| 8207 | } else { |
| 8208 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8209 | } |
| 8210 | } |
| 8211 | } |
| 8212 | |
| 8213 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8214 | return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8215 | } |
| 8216 | |
| 8217 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { |
| 8218 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8219 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8220 | locations->SetOut(Location::RequiresRegister()); |
| 8221 | } |
| 8222 | |
| 8223 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { |
| 8224 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
| 8225 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 8226 | } |
| 8227 | |
| 8228 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8229 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8230 | } |
| 8231 | |
| 8232 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 8233 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
| 8234 | } |
| 8235 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8236 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 8237 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8238 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8239 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8240 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8241 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8242 | switch (load_kind) { |
| 8243 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8244 | case HLoadString::LoadKind::kBootImageAddress: |
| 8245 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8246 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8247 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8248 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8249 | break; |
| 8250 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8251 | if (has_irreducible_loops) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 8252 | if (load_kind != HLoadString::LoadKind::kBootImageAddress) { |
| 8253 | codegen_->ClobberRA(); |
| 8254 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8255 | break; |
| 8256 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8257 | FALLTHROUGH_INTENDED; |
| 8258 | // We need an extra register for PC-relative dex cache accesses. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8259 | case HLoadString::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8260 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8261 | break; |
| 8262 | default: |
| 8263 | break; |
| 8264 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 8265 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8266 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8267 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8268 | } else { |
| 8269 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8270 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 8271 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 8272 | // Rely on the pResolveString and marking to save everything we need. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8273 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 8274 | InvokeRuntimeCallingConvention calling_convention; |
| 8275 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8276 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 8277 | } else { |
| 8278 | // For non-Baker read barriers we have a temp-clobbering call. |
| 8279 | } |
| 8280 | } |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8281 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8282 | } |
| 8283 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8284 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 8285 | // move. |
| 8286 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8287 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8288 | LocationSummary* locations = load->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8289 | Location out_loc = locations->Out(); |
| 8290 | Register out = out_loc.AsRegister<Register>(); |
| 8291 | Register base_or_current_method_reg; |
| 8292 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8293 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8294 | switch (load_kind) { |
| 8295 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8296 | case HLoadString::LoadKind::kBootImageAddress: |
| 8297 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8298 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8299 | case HLoadString::LoadKind::kBssEntry: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8300 | base_or_current_method_reg = |
| 8301 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8302 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8303 | default: |
| 8304 | base_or_current_method_reg = ZERO; |
| 8305 | break; |
| 8306 | } |
| 8307 | |
| 8308 | switch (load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8309 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8310 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8311 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8312 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8313 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8314 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8315 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8316 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 8317 | base_or_current_method_reg); |
| 8318 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8319 | return; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8320 | } |
| 8321 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8322 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 8323 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 8324 | DCHECK_NE(address, 0u); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8325 | if (isR6 || !has_irreducible_loops) { |
| 8326 | __ LoadLiteral(out, |
| 8327 | base_or_current_method_reg, |
| 8328 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 8329 | } else { |
| 8330 | __ LoadConst32(out, address); |
| 8331 | } |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8332 | return; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8333 | } |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8334 | case HLoadString::LoadKind::kBootImageInternTable: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8335 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8336 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8337 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8338 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8339 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8340 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8341 | out, |
| 8342 | base_or_current_method_reg); |
| 8343 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
| 8344 | return; |
| 8345 | } |
| 8346 | case HLoadString::LoadKind::kBssEntry: { |
| 8347 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 8348 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
| 8349 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| 8350 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8351 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8352 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8353 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8354 | base_or_current_method_reg); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8355 | GenerateGcRootFieldLoad(load, |
| 8356 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8357 | out, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8358 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8359 | kCompilerReadBarrierOption, |
| 8360 | &info_low->label); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8361 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8362 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8363 | codegen_->AddSlowPath(slow_path); |
| 8364 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 8365 | __ Bind(slow_path->GetExitLabel()); |
| 8366 | return; |
| 8367 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8368 | case HLoadString::LoadKind::kJitTableAddress: { |
| 8369 | CodeGeneratorMIPS::JitPatchInfo* info = |
| 8370 | codegen_->NewJitRootStringPatch(load->GetDexFile(), |
| 8371 | load->GetStringIndex(), |
| 8372 | load->GetString()); |
| 8373 | bool reordering = __ SetReorder(false); |
| 8374 | __ Bind(&info->high_label); |
| 8375 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8376 | __ SetReorder(reordering); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8377 | GenerateGcRootFieldLoad(load, |
| 8378 | out_loc, |
| 8379 | out, |
| 8380 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8381 | kCompilerReadBarrierOption, |
| 8382 | &info->low_label); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8383 | return; |
| 8384 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8385 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8386 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8387 | } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 8388 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8389 | // 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] | 8390 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8391 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8392 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8393 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8394 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 8395 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8396 | } |
| 8397 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8398 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8399 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8400 | locations->SetOut(Location::ConstantLocation(constant)); |
| 8401 | } |
| 8402 | |
| 8403 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 8404 | // Will be generated at use site. |
| 8405 | } |
| 8406 | |
| 8407 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8408 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8409 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8410 | InvokeRuntimeCallingConvention calling_convention; |
| 8411 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8412 | } |
| 8413 | |
| 8414 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8415 | if (instruction->IsEnter()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8416 | codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8417 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8418 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8419 | codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8420 | } |
| 8421 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8422 | } |
| 8423 | |
| 8424 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { |
| 8425 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8426 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8427 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8428 | case DataType::Type::kInt32: |
| 8429 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8430 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8431 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8432 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8433 | break; |
| 8434 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8435 | case DataType::Type::kFloat32: |
| 8436 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8437 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8438 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 8439 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8440 | break; |
| 8441 | |
| 8442 | default: |
| 8443 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 8444 | } |
| 8445 | } |
| 8446 | |
| 8447 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8448 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8449 | LocationSummary* locations = instruction->GetLocations(); |
| 8450 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 8451 | |
| 8452 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8453 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8454 | Register dst = locations->Out().AsRegister<Register>(); |
| 8455 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 8456 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 8457 | |
| 8458 | if (isR6) { |
| 8459 | __ MulR6(dst, lhs, rhs); |
| 8460 | } else { |
| 8461 | __ MulR2(dst, lhs, rhs); |
| 8462 | } |
| 8463 | break; |
| 8464 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8465 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8466 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8467 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8468 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8469 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8470 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 8471 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 8472 | |
| 8473 | // Extra checks to protect caused by the existance of A1_A2. |
| 8474 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: |
| 8475 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). |
| 8476 | DCHECK_NE(dst_high, lhs_low); |
| 8477 | DCHECK_NE(dst_high, rhs_low); |
| 8478 | |
| 8479 | // A_B * C_D |
| 8480 | // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ] |
| 8481 | // dst_lo: [ low(B*D) ] |
| 8482 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. |
| 8483 | |
| 8484 | if (isR6) { |
| 8485 | __ MulR6(TMP, lhs_high, rhs_low); |
| 8486 | __ MulR6(dst_high, lhs_low, rhs_high); |
| 8487 | __ Addu(dst_high, dst_high, TMP); |
| 8488 | __ MuhuR6(TMP, lhs_low, rhs_low); |
| 8489 | __ Addu(dst_high, dst_high, TMP); |
| 8490 | __ MulR6(dst_low, lhs_low, rhs_low); |
| 8491 | } else { |
| 8492 | __ MulR2(TMP, lhs_high, rhs_low); |
| 8493 | __ MulR2(dst_high, lhs_low, rhs_high); |
| 8494 | __ Addu(dst_high, dst_high, TMP); |
| 8495 | __ MultuR2(lhs_low, rhs_low); |
| 8496 | __ Mfhi(TMP); |
| 8497 | __ Addu(dst_high, dst_high, TMP); |
| 8498 | __ Mflo(dst_low); |
| 8499 | } |
| 8500 | break; |
| 8501 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8502 | case DataType::Type::kFloat32: |
| 8503 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8504 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8505 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8506 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8507 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8508 | __ MulS(dst, lhs, rhs); |
| 8509 | } else { |
| 8510 | __ MulD(dst, lhs, rhs); |
| 8511 | } |
| 8512 | break; |
| 8513 | } |
| 8514 | default: |
| 8515 | LOG(FATAL) << "Unexpected mul type " << type; |
| 8516 | } |
| 8517 | } |
| 8518 | |
| 8519 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { |
| 8520 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8521 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8522 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8523 | case DataType::Type::kInt32: |
| 8524 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8525 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8526 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8527 | break; |
| 8528 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8529 | case DataType::Type::kFloat32: |
| 8530 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8531 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8532 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8533 | break; |
| 8534 | |
| 8535 | default: |
| 8536 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 8537 | } |
| 8538 | } |
| 8539 | |
| 8540 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8541 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8542 | LocationSummary* locations = instruction->GetLocations(); |
| 8543 | |
| 8544 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8545 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8546 | Register dst = locations->Out().AsRegister<Register>(); |
| 8547 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8548 | __ Subu(dst, ZERO, src); |
| 8549 | break; |
| 8550 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8551 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8552 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8553 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8554 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8555 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8556 | __ Subu(dst_low, ZERO, src_low); |
| 8557 | __ Sltu(TMP, ZERO, dst_low); |
| 8558 | __ Subu(dst_high, ZERO, src_high); |
| 8559 | __ Subu(dst_high, dst_high, TMP); |
| 8560 | break; |
| 8561 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8562 | case DataType::Type::kFloat32: |
| 8563 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8564 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8565 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8566 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8567 | __ NegS(dst, src); |
| 8568 | } else { |
| 8569 | __ NegD(dst, src); |
| 8570 | } |
| 8571 | break; |
| 8572 | } |
| 8573 | default: |
| 8574 | LOG(FATAL) << "Unexpected neg type " << type; |
| 8575 | } |
| 8576 | } |
| 8577 | |
| 8578 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8579 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8580 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8581 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8582 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8583 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8584 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8585 | } |
| 8586 | |
| 8587 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8588 | // Note: if heap poisoning is enabled, the entry point takes care |
| 8589 | // of poisoning the reference. |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8590 | QuickEntrypointEnum entrypoint = |
| 8591 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 8592 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8593 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8594 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8595 | } |
| 8596 | |
| 8597 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8598 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8599 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8600 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8601 | if (instruction->IsStringAlloc()) { |
| 8602 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 8603 | } else { |
| 8604 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8605 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8606 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8607 | } |
| 8608 | |
| 8609 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8610 | // Note: if heap poisoning is enabled, the entry point takes care |
| 8611 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8612 | if (instruction->IsStringAlloc()) { |
| 8613 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 8614 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8615 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8616 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 8617 | __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value()); |
| 8618 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 8619 | __ NopIfNoReordering(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8620 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 8621 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8622 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 8623 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8624 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8625 | } |
| 8626 | |
| 8627 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8628 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8629 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8630 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8631 | } |
| 8632 | |
| 8633 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8634 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8635 | LocationSummary* locations = instruction->GetLocations(); |
| 8636 | |
| 8637 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8638 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8639 | Register dst = locations->Out().AsRegister<Register>(); |
| 8640 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8641 | __ Nor(dst, src, ZERO); |
| 8642 | break; |
| 8643 | } |
| 8644 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8645 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8646 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8647 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8648 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8649 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8650 | __ Nor(dst_high, src_high, ZERO); |
| 8651 | __ Nor(dst_low, src_low, ZERO); |
| 8652 | break; |
| 8653 | } |
| 8654 | |
| 8655 | default: |
| 8656 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 8657 | } |
| 8658 | } |
| 8659 | |
| 8660 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8661 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8662 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8663 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8664 | } |
| 8665 | |
| 8666 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 8667 | LocationSummary* locations = instruction->GetLocations(); |
| 8668 | __ Xori(locations->Out().AsRegister<Register>(), |
| 8669 | locations->InAt(0).AsRegister<Register>(), |
| 8670 | 1); |
| 8671 | } |
| 8672 | |
| 8673 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 8674 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 8675 | locations->SetInAt(0, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8676 | } |
| 8677 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8678 | void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 8679 | if (CanMoveNullCheckToUser(instruction)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8680 | return; |
| 8681 | } |
| 8682 | Location obj = instruction->GetLocations()->InAt(0); |
| 8683 | |
| 8684 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8685 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8686 | } |
| 8687 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8688 | void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8689 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) NullCheckSlowPathMIPS(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8690 | AddSlowPath(slow_path); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8691 | |
| 8692 | Location obj = instruction->GetLocations()->InAt(0); |
| 8693 | |
| 8694 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8695 | } |
| 8696 | |
| 8697 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8698 | codegen_->GenerateNullCheck(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8699 | } |
| 8700 | |
| 8701 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { |
| 8702 | HandleBinaryOp(instruction); |
| 8703 | } |
| 8704 | |
| 8705 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { |
| 8706 | HandleBinaryOp(instruction); |
| 8707 | } |
| 8708 | |
| 8709 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 8710 | LOG(FATAL) << "Unreachable"; |
| 8711 | } |
| 8712 | |
| 8713 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 8714 | if (instruction->GetNext()->IsSuspendCheck() && |
| 8715 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 8716 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 8717 | // The back edge will generate the suspend check. |
| 8718 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 8719 | } |
| 8720 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8721 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 8722 | } |
| 8723 | |
| 8724 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8725 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8726 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 8727 | if (location.IsStackSlot()) { |
| 8728 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8729 | } else if (location.IsDoubleStackSlot()) { |
| 8730 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8731 | } |
| 8732 | locations->SetOut(location); |
| 8733 | } |
| 8734 | |
| 8735 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction |
| 8736 | ATTRIBUTE_UNUSED) { |
| 8737 | // Nothing to do, the parameter is already at its location. |
| 8738 | } |
| 8739 | |
| 8740 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 8741 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8742 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8743 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 8744 | } |
| 8745 | |
| 8746 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction |
| 8747 | ATTRIBUTE_UNUSED) { |
| 8748 | // Nothing to do, the method is already at its location. |
| 8749 | } |
| 8750 | |
| 8751 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8752 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 8753 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8754 | locations->SetInAt(i, Location::Any()); |
| 8755 | } |
| 8756 | locations->SetOut(Location::Any()); |
| 8757 | } |
| 8758 | |
| 8759 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 8760 | LOG(FATAL) << "Unreachable"; |
| 8761 | } |
| 8762 | |
| 8763 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8764 | DataType::Type type = rem->GetResultType(); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 8765 | bool call_rem; |
| 8766 | if ((type == DataType::Type::kInt64) && rem->InputAt(1)->IsConstant()) { |
| 8767 | int64_t imm = CodeGenerator::GetInt64ValueOf(rem->InputAt(1)->AsConstant()); |
| 8768 | call_rem = (imm != 0) && !IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm))); |
| 8769 | } else { |
| 8770 | call_rem = (type != DataType::Type::kInt32); |
| 8771 | } |
| 8772 | LocationSummary::CallKind call_kind = call_rem |
| 8773 | ? LocationSummary::kCallOnMainOnly |
| 8774 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8775 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8776 | |
| 8777 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8778 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8779 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8780 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8781 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8782 | break; |
| 8783 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8784 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 8785 | if (call_rem) { |
| 8786 | InvokeRuntimeCallingConvention calling_convention; |
| 8787 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 8788 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 8789 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 8790 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 8791 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8792 | } else { |
| 8793 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8794 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 8795 | locations->SetOut(Location::RequiresRegister()); |
| 8796 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8797 | break; |
| 8798 | } |
| 8799 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8800 | case DataType::Type::kFloat32: |
| 8801 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8802 | InvokeRuntimeCallingConvention calling_convention; |
| 8803 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 8804 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 8805 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8806 | break; |
| 8807 | } |
| 8808 | |
| 8809 | default: |
| 8810 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8811 | } |
| 8812 | } |
| 8813 | |
| 8814 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8815 | DataType::Type type = instruction->GetType(); |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 8816 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8817 | |
| 8818 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8819 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8820 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8821 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8822 | case DataType::Type::kInt64: { |
Lena Djokic | 4b8025c | 2017-12-21 16:15:50 +0100 | [diff] [blame^] | 8823 | if (locations->InAt(1).IsConstant()) { |
| 8824 | int64_t imm = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue(); |
| 8825 | if (imm == 0) { |
| 8826 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 8827 | } else if (imm == 1 || imm == -1) { |
| 8828 | DivRemOneOrMinusOne(instruction); |
| 8829 | } else { |
| 8830 | DCHECK(IsPowerOfTwo(static_cast<uint64_t>(AbsOrMin(imm)))); |
| 8831 | DivRemByPowerOfTwo(instruction); |
| 8832 | } |
| 8833 | } else { |
| 8834 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
| 8835 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 8836 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8837 | break; |
| 8838 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8839 | case DataType::Type::kFloat32: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8840 | codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8841 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8842 | break; |
| 8843 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8844 | case DataType::Type::kFloat64: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8845 | codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8846 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8847 | break; |
| 8848 | } |
| 8849 | default: |
| 8850 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8851 | } |
| 8852 | } |
| 8853 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8854 | void LocationsBuilderMIPS::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 8855 | constructor_fence->SetLocations(nullptr); |
| 8856 | } |
| 8857 | |
| 8858 | void InstructionCodeGeneratorMIPS::VisitConstructorFence( |
| 8859 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 8860 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 8861 | } |
| 8862 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8863 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 8864 | memory_barrier->SetLocations(nullptr); |
| 8865 | } |
| 8866 | |
| 8867 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 8868 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 8869 | } |
| 8870 | |
| 8871 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8872 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8873 | DataType::Type return_type = ret->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8874 | locations->SetInAt(0, MipsReturnLocation(return_type)); |
| 8875 | } |
| 8876 | |
| 8877 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 8878 | codegen_->GenerateFrameExit(); |
| 8879 | } |
| 8880 | |
| 8881 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { |
| 8882 | ret->SetLocations(nullptr); |
| 8883 | } |
| 8884 | |
| 8885 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 8886 | codegen_->GenerateFrameExit(); |
| 8887 | } |
| 8888 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 8889 | void LocationsBuilderMIPS::VisitRor(HRor* ror) { |
| 8890 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 8891 | } |
| 8892 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 8893 | void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) { |
| 8894 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 8895 | } |
| 8896 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8897 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { |
| 8898 | HandleShift(shl); |
| 8899 | } |
| 8900 | |
| 8901 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { |
| 8902 | HandleShift(shl); |
| 8903 | } |
| 8904 | |
| 8905 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { |
| 8906 | HandleShift(shr); |
| 8907 | } |
| 8908 | |
| 8909 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { |
| 8910 | HandleShift(shr); |
| 8911 | } |
| 8912 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8913 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { |
| 8914 | HandleBinaryOp(instruction); |
| 8915 | } |
| 8916 | |
| 8917 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { |
| 8918 | HandleBinaryOp(instruction); |
| 8919 | } |
| 8920 | |
| 8921 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 8922 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 8923 | } |
| 8924 | |
| 8925 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 8926 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 8927 | } |
| 8928 | |
| 8929 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 8930 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 8931 | } |
| 8932 | |
| 8933 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 8934 | HandleFieldSet(instruction, |
| 8935 | instruction->GetFieldInfo(), |
| 8936 | instruction->GetDexPc(), |
| 8937 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8938 | } |
| 8939 | |
| 8940 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( |
| 8941 | HUnresolvedInstanceFieldGet* instruction) { |
| 8942 | FieldAccessCallingConventionMIPS calling_convention; |
| 8943 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8944 | instruction->GetFieldType(), |
| 8945 | calling_convention); |
| 8946 | } |
| 8947 | |
| 8948 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( |
| 8949 | HUnresolvedInstanceFieldGet* instruction) { |
| 8950 | FieldAccessCallingConventionMIPS calling_convention; |
| 8951 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8952 | instruction->GetFieldType(), |
| 8953 | instruction->GetFieldIndex(), |
| 8954 | instruction->GetDexPc(), |
| 8955 | calling_convention); |
| 8956 | } |
| 8957 | |
| 8958 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( |
| 8959 | HUnresolvedInstanceFieldSet* instruction) { |
| 8960 | FieldAccessCallingConventionMIPS calling_convention; |
| 8961 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8962 | instruction->GetFieldType(), |
| 8963 | calling_convention); |
| 8964 | } |
| 8965 | |
| 8966 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( |
| 8967 | HUnresolvedInstanceFieldSet* instruction) { |
| 8968 | FieldAccessCallingConventionMIPS calling_convention; |
| 8969 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8970 | instruction->GetFieldType(), |
| 8971 | instruction->GetFieldIndex(), |
| 8972 | instruction->GetDexPc(), |
| 8973 | calling_convention); |
| 8974 | } |
| 8975 | |
| 8976 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( |
| 8977 | HUnresolvedStaticFieldGet* instruction) { |
| 8978 | FieldAccessCallingConventionMIPS calling_convention; |
| 8979 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8980 | instruction->GetFieldType(), |
| 8981 | calling_convention); |
| 8982 | } |
| 8983 | |
| 8984 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( |
| 8985 | HUnresolvedStaticFieldGet* instruction) { |
| 8986 | FieldAccessCallingConventionMIPS calling_convention; |
| 8987 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8988 | instruction->GetFieldType(), |
| 8989 | instruction->GetFieldIndex(), |
| 8990 | instruction->GetDexPc(), |
| 8991 | calling_convention); |
| 8992 | } |
| 8993 | |
| 8994 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( |
| 8995 | HUnresolvedStaticFieldSet* instruction) { |
| 8996 | FieldAccessCallingConventionMIPS calling_convention; |
| 8997 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8998 | instruction->GetFieldType(), |
| 8999 | calling_convention); |
| 9000 | } |
| 9001 | |
| 9002 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( |
| 9003 | HUnresolvedStaticFieldSet* instruction) { |
| 9004 | FieldAccessCallingConventionMIPS calling_convention; |
| 9005 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 9006 | instruction->GetFieldType(), |
| 9007 | instruction->GetFieldIndex(), |
| 9008 | instruction->GetDexPc(), |
| 9009 | calling_convention); |
| 9010 | } |
| 9011 | |
| 9012 | void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9013 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 9014 | instruction, LocationSummary::kCallOnSlowPath); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 9015 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 9016 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 9017 | // registers in full width (since the runtime only saves/restores lower part). |
| 9018 | locations->SetCustomSlowPathCallerSaves( |
| 9019 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9020 | } |
| 9021 | |
| 9022 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 9023 | HBasicBlock* block = instruction->GetBlock(); |
| 9024 | if (block->GetLoopInformation() != nullptr) { |
| 9025 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 9026 | // The back edge will generate the suspend check. |
| 9027 | return; |
| 9028 | } |
| 9029 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 9030 | // The goto will generate the suspend check. |
| 9031 | return; |
| 9032 | } |
| 9033 | GenerateSuspendCheck(instruction, nullptr); |
| 9034 | } |
| 9035 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9036 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9037 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 9038 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9039 | InvokeRuntimeCallingConvention calling_convention; |
| 9040 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 9041 | } |
| 9042 | |
| 9043 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 9044 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9045 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 9046 | } |
| 9047 | |
| 9048 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9049 | DataType::Type input_type = conversion->GetInputType(); |
| 9050 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9051 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 9052 | << input_type << " -> " << result_type; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9053 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9054 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9055 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 9056 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9057 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 9058 | } |
| 9059 | |
| 9060 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9061 | if (!isR6 && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9062 | ((DataType::IsFloatingPointType(result_type) && input_type == DataType::Type::kInt64) || |
| 9063 | (result_type == DataType::Type::kInt64 && DataType::IsFloatingPointType(input_type)))) { |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 9064 | call_kind = LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9065 | } |
| 9066 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9067 | LocationSummary* locations = |
| 9068 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9069 | |
| 9070 | if (call_kind == LocationSummary::kNoCall) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9071 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9072 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 9073 | } else { |
| 9074 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9075 | } |
| 9076 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9077 | if (DataType::IsFloatingPointType(result_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9078 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 9079 | } else { |
| 9080 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9081 | } |
| 9082 | } else { |
| 9083 | InvokeRuntimeCallingConvention calling_convention; |
| 9084 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9085 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9086 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 9087 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9088 | DCHECK_EQ(input_type, DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9089 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 9090 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 9091 | } |
| 9092 | |
| 9093 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 9094 | } |
| 9095 | } |
| 9096 | |
| 9097 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 9098 | LocationSummary* locations = conversion->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9099 | DataType::Type result_type = conversion->GetResultType(); |
| 9100 | DataType::Type input_type = conversion->GetInputType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9101 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9102 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9103 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9104 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 9105 | << input_type << " -> " << result_type; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9106 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9107 | if (result_type == DataType::Type::kInt64 && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9108 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 9109 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 9110 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 9111 | |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 9112 | if (dst_low != src) { |
| 9113 | __ Move(dst_low, src); |
| 9114 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9115 | __ Sra(dst_high, src, 31); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9116 | } else if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9117 | Register dst = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9118 | Register src = (input_type == DataType::Type::kInt64) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9119 | ? locations->InAt(0).AsRegisterPairLow<Register>() |
| 9120 | : locations->InAt(0).AsRegister<Register>(); |
| 9121 | |
| 9122 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9123 | case DataType::Type::kUint8: |
| 9124 | __ Andi(dst, src, 0xFF); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9125 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9126 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9127 | if (has_sign_extension) { |
| 9128 | __ Seb(dst, src); |
| 9129 | } else { |
| 9130 | __ Sll(dst, src, 24); |
| 9131 | __ Sra(dst, dst, 24); |
| 9132 | } |
| 9133 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 9134 | case DataType::Type::kUint16: |
| 9135 | __ Andi(dst, src, 0xFFFF); |
| 9136 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9137 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9138 | if (has_sign_extension) { |
| 9139 | __ Seh(dst, src); |
| 9140 | } else { |
| 9141 | __ Sll(dst, src, 16); |
| 9142 | __ Sra(dst, dst, 16); |
| 9143 | } |
| 9144 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9145 | case DataType::Type::kInt32: |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 9146 | if (dst != src) { |
| 9147 | __ Move(dst, src); |
| 9148 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9149 | break; |
| 9150 | |
| 9151 | default: |
| 9152 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 9153 | << " to " << result_type; |
| 9154 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9155 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
| 9156 | if (input_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9157 | if (isR6) { |
| 9158 | // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 9159 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 9160 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 9161 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 9162 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 9163 | __ Mtc1(src_low, FTMP); |
| 9164 | __ Mthc1(src_high, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9165 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9166 | __ Cvtsl(dst, FTMP); |
| 9167 | } else { |
| 9168 | __ Cvtdl(dst, FTMP); |
| 9169 | } |
| 9170 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9171 | QuickEntrypointEnum entrypoint = |
| 9172 | (result_type == DataType::Type::kFloat32) ? kQuickL2f : kQuickL2d; |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 9173 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9174 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9175 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 9176 | } else { |
| 9177 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 9178 | } |
| 9179 | } |
| 9180 | } else { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9181 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 9182 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 9183 | __ Mtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9184 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9185 | __ Cvtsw(dst, FTMP); |
| 9186 | } else { |
| 9187 | __ Cvtdw(dst, FTMP); |
| 9188 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9189 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9190 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 9191 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9192 | |
| 9193 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum |
| 9194 | // value of the output type if the input is outside of the range after the truncation or |
| 9195 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct |
| 9196 | // results. This matches the desired float/double-to-int/long conversion exactly. |
| 9197 | // |
| 9198 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive |
| 9199 | // value when the input is either a NaN or is outside of the range of the output type |
| 9200 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce |
| 9201 | // the same result. |
| 9202 | // |
| 9203 | // The code takes care of the different behaviors by first comparing the input to the |
| 9204 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). |
| 9205 | // If the input is greater than or equal to the minimum, it procedes to the truncate |
| 9206 | // instruction, which will handle such an input the same way irrespective of NAN2008. |
| 9207 | // Otherwise the input is compared to itself to determine whether it is a NaN or not |
| 9208 | // in order to return either zero or the minimum value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9209 | if (result_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9210 | if (isR6) { |
| 9211 | // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 9212 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 9213 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9214 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 9215 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9216 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9217 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9218 | __ TruncLS(FTMP, src); |
| 9219 | } else { |
| 9220 | __ TruncLD(FTMP, src); |
| 9221 | } |
| 9222 | __ Mfc1(dst_low, FTMP); |
| 9223 | __ Mfhc1(dst_high, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9224 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9225 | QuickEntrypointEnum entrypoint = |
| 9226 | (input_type == DataType::Type::kFloat32) ? kQuickF2l : kQuickD2l; |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 9227 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9228 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9229 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 9230 | } else { |
| 9231 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 9232 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9233 | } |
| 9234 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9235 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 9236 | Register dst = locations->Out().AsRegister<Register>(); |
| 9237 | MipsLabel truncate; |
| 9238 | MipsLabel done; |
| 9239 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9240 | if (!isR6) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9241 | if (input_type == DataType::Type::kFloat32) { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9242 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); |
| 9243 | __ LoadConst32(TMP, min_val); |
| 9244 | __ Mtc1(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9245 | } else { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9246 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); |
| 9247 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 9248 | __ Mtc1(ZERO, FTMP); |
| 9249 | __ MoveToFpuHigh(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9250 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9251 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9252 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9253 | __ ColeS(0, FTMP, src); |
| 9254 | } else { |
| 9255 | __ ColeD(0, FTMP, src); |
| 9256 | } |
| 9257 | __ Bc1t(0, &truncate); |
| 9258 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9259 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9260 | __ CeqS(0, src, src); |
| 9261 | } else { |
| 9262 | __ CeqD(0, src, src); |
| 9263 | } |
| 9264 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 9265 | __ Movf(dst, ZERO, 0); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9266 | |
| 9267 | __ B(&done); |
| 9268 | |
| 9269 | __ Bind(&truncate); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9270 | } |
| 9271 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9272 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 9273 | __ TruncWS(FTMP, src); |
| 9274 | } else { |
| 9275 | __ TruncWD(FTMP, src); |
| 9276 | } |
| 9277 | __ Mfc1(dst, FTMP); |
| 9278 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 9279 | if (!isR6) { |
| 9280 | __ Bind(&done); |
| 9281 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9282 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9283 | } else if (DataType::IsFloatingPointType(result_type) && |
| 9284 | DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9285 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 9286 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9287 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9288 | __ Cvtsd(dst, src); |
| 9289 | } else { |
| 9290 | __ Cvtds(dst, src); |
| 9291 | } |
| 9292 | } else { |
| 9293 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 9294 | << " to " << result_type; |
| 9295 | } |
| 9296 | } |
| 9297 | |
| 9298 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { |
| 9299 | HandleShift(ushr); |
| 9300 | } |
| 9301 | |
| 9302 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { |
| 9303 | HandleShift(ushr); |
| 9304 | } |
| 9305 | |
| 9306 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { |
| 9307 | HandleBinaryOp(instruction); |
| 9308 | } |
| 9309 | |
| 9310 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { |
| 9311 | HandleBinaryOp(instruction); |
| 9312 | } |
| 9313 | |
| 9314 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9315 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9316 | LOG(FATAL) << "Unreachable"; |
| 9317 | } |
| 9318 | |
| 9319 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9320 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9321 | LOG(FATAL) << "Unreachable"; |
| 9322 | } |
| 9323 | |
| 9324 | void LocationsBuilderMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9325 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9326 | } |
| 9327 | |
| 9328 | void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9329 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9330 | } |
| 9331 | |
| 9332 | void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9333 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9334 | } |
| 9335 | |
| 9336 | void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9337 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9338 | } |
| 9339 | |
| 9340 | void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9341 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9342 | } |
| 9343 | |
| 9344 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9345 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9346 | } |
| 9347 | |
| 9348 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9349 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9350 | } |
| 9351 | |
| 9352 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9353 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9354 | } |
| 9355 | |
| 9356 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9357 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9358 | } |
| 9359 | |
| 9360 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9361 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9362 | } |
| 9363 | |
| 9364 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9365 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9366 | } |
| 9367 | |
| 9368 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9369 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9370 | } |
| 9371 | |
| 9372 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9373 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9374 | } |
| 9375 | |
| 9376 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9377 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9378 | } |
| 9379 | |
| 9380 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9381 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9382 | } |
| 9383 | |
| 9384 | void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9385 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9386 | } |
| 9387 | |
| 9388 | void LocationsBuilderMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9389 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9390 | } |
| 9391 | |
| 9392 | void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9393 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9394 | } |
| 9395 | |
| 9396 | void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9397 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9398 | } |
| 9399 | |
| 9400 | void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9401 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9402 | } |
| 9403 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9404 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9405 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9406 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9407 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9408 | if (!codegen_->GetInstructionSetFeatures().IsR6()) { |
| 9409 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9410 | if (num_entries > InstructionCodeGeneratorMIPS::kPackedSwitchJumpTableThreshold) { |
| 9411 | // When there's no HMipsComputeBaseMethodAddress input, R2 uses the NAL |
| 9412 | // instruction to simulate PC-relative addressing when accessing the jump table. |
| 9413 | // NAL clobbers RA. Make sure RA is preserved. |
| 9414 | codegen_->ClobberRA(); |
| 9415 | } |
| 9416 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9417 | } |
| 9418 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9419 | void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg, |
| 9420 | int32_t lower_bound, |
| 9421 | uint32_t num_entries, |
| 9422 | HBasicBlock* switch_block, |
| 9423 | HBasicBlock* default_block) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9424 | // Create a set of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9425 | Register temp_reg = TMP; |
| 9426 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
| 9427 | // Jump to default if index is negative |
| 9428 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 9429 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 9430 | __ Bltz(temp_reg, codegen_->GetLabelOf(default_block)); |
| 9431 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9432 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9433 | // Jump to successors[0] if value == lower_bound. |
| 9434 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 9435 | int32_t last_index = 0; |
| 9436 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9437 | __ Addiu(temp_reg, temp_reg, -2); |
| 9438 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9439 | __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9440 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9441 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9442 | } |
| 9443 | if (num_entries - last_index == 2) { |
| 9444 | // The last missing case_value. |
| 9445 | __ Addiu(temp_reg, temp_reg, -1); |
| 9446 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9447 | } |
| 9448 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9449 | // And the default for any other value. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9450 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9451 | __ B(codegen_->GetLabelOf(default_block)); |
| 9452 | } |
| 9453 | } |
| 9454 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9455 | void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg, |
| 9456 | Register constant_area, |
| 9457 | int32_t lower_bound, |
| 9458 | uint32_t num_entries, |
| 9459 | HBasicBlock* switch_block, |
| 9460 | HBasicBlock* default_block) { |
| 9461 | // Create a jump table. |
| 9462 | std::vector<MipsLabel*> labels(num_entries); |
| 9463 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 9464 | for (uint32_t i = 0; i < num_entries; i++) { |
| 9465 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 9466 | } |
| 9467 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 9468 | |
| 9469 | // Is the value in range? |
| 9470 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 9471 | if (IsInt<16>(static_cast<int32_t>(num_entries))) { |
| 9472 | __ Sltiu(AT, TMP, num_entries); |
| 9473 | __ Beqz(AT, codegen_->GetLabelOf(default_block)); |
| 9474 | } else { |
| 9475 | __ LoadConst32(AT, num_entries); |
| 9476 | __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 9477 | } |
| 9478 | |
| 9479 | // We are in the range of the table. |
| 9480 | // Load the target address from the jump table, indexing by the value. |
| 9481 | __ LoadLabelAddress(AT, constant_area, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 9482 | __ ShiftAndAdd(TMP, TMP, AT, 2, TMP); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9483 | __ Lw(TMP, TMP, 0); |
| 9484 | // Compute the absolute target address by adding the table start address |
| 9485 | // (the table contains offsets to targets relative to its start). |
| 9486 | __ Addu(TMP, TMP, AT); |
| 9487 | // And jump. |
| 9488 | __ Jr(TMP); |
| 9489 | __ NopIfNoReordering(); |
| 9490 | } |
| 9491 | |
| 9492 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9493 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9494 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9495 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9496 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 9497 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 9498 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9499 | |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9500 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9501 | // R6 uses PC-relative addressing to access the jump table. |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9502 | // |
| 9503 | // R2, OTOH, uses an HMipsComputeBaseMethodAddress input (when available) |
| 9504 | // to access the jump table and it is implemented by changing HPackedSwitch to |
| 9505 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress (see |
| 9506 | // VisitMipsPackedSwitch()). |
| 9507 | // |
| 9508 | // When there's no HMipsComputeBaseMethodAddress input (e.g. in presence of |
| 9509 | // irreducible loops), R2 uses the NAL instruction to simulate PC-relative |
| 9510 | // addressing. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9511 | GenTableBasedPackedSwitch(value_reg, |
| 9512 | ZERO, |
| 9513 | lower_bound, |
| 9514 | num_entries, |
| 9515 | switch_block, |
| 9516 | default_block); |
| 9517 | } else { |
| 9518 | GenPackedSwitchWithCompares(value_reg, |
| 9519 | lower_bound, |
| 9520 | num_entries, |
| 9521 | switch_block, |
| 9522 | default_block); |
| 9523 | } |
| 9524 | } |
| 9525 | |
| 9526 | void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 9527 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9528 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9529 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9530 | // Constant area pointer (HMipsComputeBaseMethodAddress). |
| 9531 | locations->SetInAt(1, Location::RequiresRegister()); |
| 9532 | } |
| 9533 | |
| 9534 | void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 9535 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9536 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9537 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9538 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 9539 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 9540 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 9541 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9542 | |
| 9543 | // This is an R2-only path. HPackedSwitch has been changed to |
| 9544 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress |
| 9545 | // required to address the jump table relative to PC. |
| 9546 | GenTableBasedPackedSwitch(value_reg, |
| 9547 | constant_area, |
| 9548 | lower_bound, |
| 9549 | num_entries, |
| 9550 | switch_block, |
| 9551 | default_block); |
| 9552 | } |
| 9553 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 9554 | void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress( |
| 9555 | HMipsComputeBaseMethodAddress* insn) { |
| 9556 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9557 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 9558 | locations->SetOut(Location::RequiresRegister()); |
| 9559 | } |
| 9560 | |
| 9561 | void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress( |
| 9562 | HMipsComputeBaseMethodAddress* insn) { |
| 9563 | LocationSummary* locations = insn->GetLocations(); |
| 9564 | Register reg = locations->Out().AsRegister<Register>(); |
| 9565 | |
| 9566 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 9567 | |
| 9568 | // Generate a dummy PC-relative call to obtain PC. |
| 9569 | __ Nal(); |
| 9570 | // Grab the return address off RA. |
| 9571 | __ Move(reg, RA); |
| 9572 | |
| 9573 | // Remember this offset (the obtained PC value) for later use with constant area. |
| 9574 | __ BindPcRelBaseLabel(); |
| 9575 | } |
| 9576 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9577 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 9578 | // The trampoline uses the same calling convention as dex calling conventions, |
| 9579 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 9580 | // the method_idx. |
| 9581 | HandleInvoke(invoke); |
| 9582 | } |
| 9583 | |
| 9584 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 9585 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 9586 | } |
| 9587 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9588 | void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 9589 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9590 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9591 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9592 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9593 | } |
| 9594 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9595 | void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 9596 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 9597 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9598 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9599 | instruction->GetIndex(), kMipsPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9600 | __ LoadFromOffset(kLoadWord, |
| 9601 | locations->Out().AsRegister<Register>(), |
| 9602 | locations->InAt(0).AsRegister<Register>(), |
| 9603 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9604 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9605 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 9606 | instruction->GetIndex(), kMipsPointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 9607 | __ LoadFromOffset(kLoadWord, |
| 9608 | locations->Out().AsRegister<Register>(), |
| 9609 | locations->InAt(0).AsRegister<Register>(), |
| 9610 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9611 | __ LoadFromOffset(kLoadWord, |
| 9612 | locations->Out().AsRegister<Register>(), |
| 9613 | locations->Out().AsRegister<Register>(), |
| 9614 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9615 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9616 | } |
| 9617 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 9618 | void LocationsBuilderMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 9619 | ATTRIBUTE_UNUSED) { |
| 9620 | LOG(FATAL) << "Unreachable"; |
| 9621 | } |
| 9622 | |
| 9623 | void InstructionCodeGeneratorMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 9624 | ATTRIBUTE_UNUSED) { |
| 9625 | LOG(FATAL) << "Unreachable"; |
| 9626 | } |
| 9627 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9628 | #undef __ |
| 9629 | #undef QUICK_ENTRY_POINT |
| 9630 | |
| 9631 | } // namespace mips |
| 9632 | } // namespace art |