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 | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 1918 | __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 1919 | __ LoadConst32(AT, enum_cast<>(ClassStatus::kInitialized)); |
| 1920 | __ Bltu(TMP, AT, slow_path->GetEntryLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1921 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1922 | __ Sync(0); |
| 1923 | __ Bind(slow_path->GetExitLabel()); |
| 1924 | } |
| 1925 | |
| 1926 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1927 | __ Sync(0); // Only stype 0 is supported. |
| 1928 | } |
| 1929 | |
| 1930 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1931 | HBasicBlock* successor) { |
| 1932 | SuspendCheckSlowPathMIPS* slow_path = |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 1933 | down_cast<SuspendCheckSlowPathMIPS*>(instruction->GetSlowPath()); |
| 1934 | |
| 1935 | if (slow_path == nullptr) { |
| 1936 | slow_path = |
| 1937 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS(instruction, successor); |
| 1938 | instruction->SetSlowPath(slow_path); |
| 1939 | codegen_->AddSlowPath(slow_path); |
| 1940 | if (successor != nullptr) { |
| 1941 | DCHECK(successor->IsLoopHeader()); |
| 1942 | } |
| 1943 | } else { |
| 1944 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1945 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1946 | |
| 1947 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1948 | TMP, |
| 1949 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1950 | Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1951 | if (successor == nullptr) { |
| 1952 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 1953 | __ Bind(slow_path->GetReturnLabel()); |
| 1954 | } else { |
| 1955 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); |
| 1956 | __ B(slow_path->GetEntryLabel()); |
| 1957 | // slow_path will return to GetLabelOf(successor). |
| 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, |
| 1962 | CodeGeneratorMIPS* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1963 | : InstructionCodeGenerator(graph, codegen), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1964 | assembler_(codegen->GetAssembler()), |
| 1965 | codegen_(codegen) {} |
| 1966 | |
| 1967 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1968 | DCHECK_EQ(instruction->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1969 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1970 | DataType::Type type = instruction->GetResultType(); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1971 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1972 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1973 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1974 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1975 | HInstruction* right = instruction->InputAt(1); |
| 1976 | bool can_use_imm = false; |
| 1977 | if (right->IsConstant()) { |
| 1978 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); |
| 1979 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1980 | can_use_imm = IsUint<16>(imm); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1981 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1982 | DCHECK(instruction->IsSub() || instruction->IsAdd()); |
| 1983 | if (instruction->IsSub()) { |
| 1984 | imm = -imm; |
| 1985 | } |
| 1986 | if (isR6) { |
| 1987 | bool single_use = right->GetUses().HasExactlyOneElement(); |
| 1988 | int16_t imm_high = High16Bits(imm); |
| 1989 | int16_t imm_low = Low16Bits(imm); |
| 1990 | if (imm_low < 0) { |
| 1991 | imm_high += 1; |
| 1992 | } |
| 1993 | can_use_imm = !((imm_high != 0) && (imm_low != 0)) || single_use; |
| 1994 | } else { |
| 1995 | can_use_imm = IsInt<16>(imm); |
| 1996 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1997 | } |
| 1998 | } |
| 1999 | if (can_use_imm) |
| 2000 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 2001 | else |
| 2002 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2003 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2004 | break; |
| 2005 | } |
| 2006 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2007 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2008 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2009 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2010 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2011 | break; |
| 2012 | } |
| 2013 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2014 | case DataType::Type::kFloat32: |
| 2015 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2016 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 2017 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2018 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2019 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2020 | break; |
| 2021 | |
| 2022 | default: |
| 2023 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 2024 | } |
| 2025 | } |
| 2026 | |
| 2027 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2028 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2029 | LocationSummary* locations = instruction->GetLocations(); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2030 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2031 | |
| 2032 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2033 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2034 | Register dst = locations->Out().AsRegister<Register>(); |
| 2035 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2036 | Location rhs_location = locations->InAt(1); |
| 2037 | |
| 2038 | Register rhs_reg = ZERO; |
| 2039 | int32_t rhs_imm = 0; |
| 2040 | bool use_imm = rhs_location.IsConstant(); |
| 2041 | if (use_imm) { |
| 2042 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2043 | } else { |
| 2044 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2045 | } |
| 2046 | |
| 2047 | if (instruction->IsAnd()) { |
| 2048 | if (use_imm) |
| 2049 | __ Andi(dst, lhs, rhs_imm); |
| 2050 | else |
| 2051 | __ And(dst, lhs, rhs_reg); |
| 2052 | } else if (instruction->IsOr()) { |
| 2053 | if (use_imm) |
| 2054 | __ Ori(dst, lhs, rhs_imm); |
| 2055 | else |
| 2056 | __ Or(dst, lhs, rhs_reg); |
| 2057 | } else if (instruction->IsXor()) { |
| 2058 | if (use_imm) |
| 2059 | __ Xori(dst, lhs, rhs_imm); |
| 2060 | else |
| 2061 | __ Xor(dst, lhs, rhs_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2062 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2063 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 2064 | if (use_imm) { |
| 2065 | if (instruction->IsSub()) { |
| 2066 | rhs_imm = -rhs_imm; |
| 2067 | } |
| 2068 | if (IsInt<16>(rhs_imm)) { |
| 2069 | __ Addiu(dst, lhs, rhs_imm); |
| 2070 | } else { |
| 2071 | DCHECK(isR6); |
| 2072 | int16_t rhs_imm_high = High16Bits(rhs_imm); |
| 2073 | int16_t rhs_imm_low = Low16Bits(rhs_imm); |
| 2074 | if (rhs_imm_low < 0) { |
| 2075 | rhs_imm_high += 1; |
| 2076 | } |
| 2077 | __ Aui(dst, lhs, rhs_imm_high); |
| 2078 | if (rhs_imm_low != 0) { |
| 2079 | __ Addiu(dst, dst, rhs_imm_low); |
| 2080 | } |
| 2081 | } |
| 2082 | } else if (instruction->IsAdd()) { |
| 2083 | __ Addu(dst, lhs, rhs_reg); |
| 2084 | } else { |
| 2085 | DCHECK(instruction->IsSub()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2086 | __ Subu(dst, lhs, rhs_reg); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2087 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2088 | } |
| 2089 | break; |
| 2090 | } |
| 2091 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2092 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2093 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2094 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2095 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2096 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2097 | Location rhs_location = locations->InAt(1); |
| 2098 | bool use_imm = rhs_location.IsConstant(); |
| 2099 | if (!use_imm) { |
| 2100 | Register rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 2101 | Register rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 2102 | if (instruction->IsAnd()) { |
| 2103 | __ And(dst_low, lhs_low, rhs_low); |
| 2104 | __ And(dst_high, lhs_high, rhs_high); |
| 2105 | } else if (instruction->IsOr()) { |
| 2106 | __ Or(dst_low, lhs_low, rhs_low); |
| 2107 | __ Or(dst_high, lhs_high, rhs_high); |
| 2108 | } else if (instruction->IsXor()) { |
| 2109 | __ Xor(dst_low, lhs_low, rhs_low); |
| 2110 | __ Xor(dst_high, lhs_high, rhs_high); |
| 2111 | } else if (instruction->IsAdd()) { |
| 2112 | if (lhs_low == rhs_low) { |
| 2113 | // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs. |
| 2114 | __ Slt(TMP, lhs_low, ZERO); |
| 2115 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2116 | } else { |
| 2117 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2118 | // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged. |
| 2119 | __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low); |
| 2120 | } |
| 2121 | __ Addu(dst_high, lhs_high, rhs_high); |
| 2122 | __ Addu(dst_high, dst_high, TMP); |
| 2123 | } else { |
| 2124 | DCHECK(instruction->IsSub()); |
| 2125 | __ Sltu(TMP, lhs_low, rhs_low); |
| 2126 | __ Subu(dst_low, lhs_low, rhs_low); |
| 2127 | __ Subu(dst_high, lhs_high, rhs_high); |
| 2128 | __ Subu(dst_high, dst_high, TMP); |
| 2129 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2130 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2131 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 2132 | if (instruction->IsOr()) { |
| 2133 | uint32_t low = Low32Bits(value); |
| 2134 | uint32_t high = High32Bits(value); |
| 2135 | if (IsUint<16>(low)) { |
| 2136 | if (dst_low != lhs_low || low != 0) { |
| 2137 | __ Ori(dst_low, lhs_low, low); |
| 2138 | } |
| 2139 | } else { |
| 2140 | __ LoadConst32(TMP, low); |
| 2141 | __ Or(dst_low, lhs_low, TMP); |
| 2142 | } |
| 2143 | if (IsUint<16>(high)) { |
| 2144 | if (dst_high != lhs_high || high != 0) { |
| 2145 | __ Ori(dst_high, lhs_high, high); |
| 2146 | } |
| 2147 | } else { |
| 2148 | if (high != low) { |
| 2149 | __ LoadConst32(TMP, high); |
| 2150 | } |
| 2151 | __ Or(dst_high, lhs_high, TMP); |
| 2152 | } |
| 2153 | } else if (instruction->IsXor()) { |
| 2154 | uint32_t low = Low32Bits(value); |
| 2155 | uint32_t high = High32Bits(value); |
| 2156 | if (IsUint<16>(low)) { |
| 2157 | if (dst_low != lhs_low || low != 0) { |
| 2158 | __ Xori(dst_low, lhs_low, low); |
| 2159 | } |
| 2160 | } else { |
| 2161 | __ LoadConst32(TMP, low); |
| 2162 | __ Xor(dst_low, lhs_low, TMP); |
| 2163 | } |
| 2164 | if (IsUint<16>(high)) { |
| 2165 | if (dst_high != lhs_high || high != 0) { |
| 2166 | __ Xori(dst_high, lhs_high, high); |
| 2167 | } |
| 2168 | } else { |
| 2169 | if (high != low) { |
| 2170 | __ LoadConst32(TMP, high); |
| 2171 | } |
| 2172 | __ Xor(dst_high, lhs_high, TMP); |
| 2173 | } |
| 2174 | } else if (instruction->IsAnd()) { |
| 2175 | uint32_t low = Low32Bits(value); |
| 2176 | uint32_t high = High32Bits(value); |
| 2177 | if (IsUint<16>(low)) { |
| 2178 | __ Andi(dst_low, lhs_low, low); |
| 2179 | } else if (low != 0xFFFFFFFF) { |
| 2180 | __ LoadConst32(TMP, low); |
| 2181 | __ And(dst_low, lhs_low, TMP); |
| 2182 | } else if (dst_low != lhs_low) { |
| 2183 | __ Move(dst_low, lhs_low); |
| 2184 | } |
| 2185 | if (IsUint<16>(high)) { |
| 2186 | __ Andi(dst_high, lhs_high, high); |
| 2187 | } else if (high != 0xFFFFFFFF) { |
| 2188 | if (high != low) { |
| 2189 | __ LoadConst32(TMP, high); |
| 2190 | } |
| 2191 | __ And(dst_high, lhs_high, TMP); |
| 2192 | } else if (dst_high != lhs_high) { |
| 2193 | __ Move(dst_high, lhs_high); |
| 2194 | } |
| 2195 | } else { |
| 2196 | if (instruction->IsSub()) { |
| 2197 | value = -value; |
| 2198 | } else { |
| 2199 | DCHECK(instruction->IsAdd()); |
| 2200 | } |
| 2201 | int32_t low = Low32Bits(value); |
| 2202 | int32_t high = High32Bits(value); |
| 2203 | if (IsInt<16>(low)) { |
| 2204 | if (dst_low != lhs_low || low != 0) { |
| 2205 | __ Addiu(dst_low, lhs_low, low); |
| 2206 | } |
| 2207 | if (low != 0) { |
| 2208 | __ Sltiu(AT, dst_low, low); |
| 2209 | } |
| 2210 | } else { |
| 2211 | __ LoadConst32(TMP, low); |
| 2212 | __ Addu(dst_low, lhs_low, TMP); |
| 2213 | __ Sltu(AT, dst_low, TMP); |
| 2214 | } |
| 2215 | if (IsInt<16>(high)) { |
| 2216 | if (dst_high != lhs_high || high != 0) { |
| 2217 | __ Addiu(dst_high, lhs_high, high); |
| 2218 | } |
| 2219 | } else { |
| 2220 | if (high != low) { |
| 2221 | __ LoadConst32(TMP, high); |
| 2222 | } |
| 2223 | __ Addu(dst_high, lhs_high, TMP); |
| 2224 | } |
| 2225 | if (low != 0) { |
| 2226 | __ Addu(dst_high, dst_high, AT); |
| 2227 | } |
| 2228 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2229 | } |
| 2230 | break; |
| 2231 | } |
| 2232 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2233 | case DataType::Type::kFloat32: |
| 2234 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2235 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2236 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2237 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2238 | if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2239 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2240 | __ AddS(dst, lhs, rhs); |
| 2241 | } else { |
| 2242 | __ AddD(dst, lhs, rhs); |
| 2243 | } |
| 2244 | } else { |
| 2245 | DCHECK(instruction->IsSub()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2246 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2247 | __ SubS(dst, lhs, rhs); |
| 2248 | } else { |
| 2249 | __ SubD(dst, lhs, rhs); |
| 2250 | } |
| 2251 | } |
| 2252 | break; |
| 2253 | } |
| 2254 | |
| 2255 | default: |
| 2256 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 2257 | } |
| 2258 | } |
| 2259 | |
| 2260 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2261 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2262 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2263 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2264 | DataType::Type type = instr->GetResultType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2265 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2266 | case DataType::Type::kInt32: |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2267 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2268 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2269 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2270 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2271 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2272 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2273 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2274 | locations->SetOut(Location::RequiresRegister()); |
| 2275 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2276 | default: |
| 2277 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2278 | } |
| 2279 | } |
| 2280 | |
| 2281 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; |
| 2282 | |
| 2283 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2284 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2285 | LocationSummary* locations = instr->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2286 | DataType::Type type = instr->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2287 | |
| 2288 | Location rhs_location = locations->InAt(1); |
| 2289 | bool use_imm = rhs_location.IsConstant(); |
| 2290 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); |
| 2291 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2292 | const uint32_t shift_mask = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2293 | (type == DataType::Type::kInt32) ? kMaxIntShiftDistance : kMaxLongShiftDistance; |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2294 | const uint32_t shift_value = rhs_imm & shift_mask; |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2295 | // Are the INS (Insert Bit Field) and ROTR instructions supported? |
| 2296 | bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2297 | |
| 2298 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2299 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2300 | Register dst = locations->Out().AsRegister<Register>(); |
| 2301 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2302 | if (use_imm) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2303 | if (shift_value == 0) { |
| 2304 | if (dst != lhs) { |
| 2305 | __ Move(dst, lhs); |
| 2306 | } |
| 2307 | } else if (instr->IsShl()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2308 | __ Sll(dst, lhs, shift_value); |
| 2309 | } else if (instr->IsShr()) { |
| 2310 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2311 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2312 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2313 | } else { |
| 2314 | if (has_ins_rotr) { |
| 2315 | __ Rotr(dst, lhs, shift_value); |
| 2316 | } else { |
| 2317 | __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask); |
| 2318 | __ Srl(dst, lhs, shift_value); |
| 2319 | __ Or(dst, dst, TMP); |
| 2320 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2321 | } |
| 2322 | } else { |
| 2323 | if (instr->IsShl()) { |
| 2324 | __ Sllv(dst, lhs, rhs_reg); |
| 2325 | } else if (instr->IsShr()) { |
| 2326 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2327 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2328 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2329 | } else { |
| 2330 | if (has_ins_rotr) { |
| 2331 | __ Rotrv(dst, lhs, rhs_reg); |
| 2332 | } else { |
| 2333 | __ Subu(TMP, ZERO, rhs_reg); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2334 | // 32-bit shift instructions use the 5 least significant bits of the shift count, so |
| 2335 | // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case |
| 2336 | // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out |
| 2337 | // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`, |
| 2338 | // IOW, the OR'd values are equal. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2339 | __ Sllv(TMP, lhs, TMP); |
| 2340 | __ Srlv(dst, lhs, rhs_reg); |
| 2341 | __ Or(dst, dst, TMP); |
| 2342 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2343 | } |
| 2344 | } |
| 2345 | break; |
| 2346 | } |
| 2347 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2348 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2349 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2350 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2351 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2352 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2353 | if (use_imm) { |
| 2354 | if (shift_value == 0) { |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 2355 | codegen_->MoveLocation(locations->Out(), locations->InAt(0), type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2356 | } else if (shift_value < kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2357 | if (has_ins_rotr) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2358 | if (instr->IsShl()) { |
| 2359 | __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2360 | __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value); |
| 2361 | __ Sll(dst_low, lhs_low, shift_value); |
| 2362 | } else if (instr->IsShr()) { |
| 2363 | __ Srl(dst_low, lhs_low, shift_value); |
| 2364 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2365 | __ Sra(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2366 | } else if (instr->IsUShr()) { |
| 2367 | __ Srl(dst_low, lhs_low, shift_value); |
| 2368 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2369 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2370 | } else { |
| 2371 | __ Srl(dst_low, lhs_low, shift_value); |
| 2372 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2373 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2374 | __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2375 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2376 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2377 | if (instr->IsShl()) { |
| 2378 | __ Sll(dst_low, lhs_low, shift_value); |
| 2379 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); |
| 2380 | __ Sll(dst_high, lhs_high, shift_value); |
| 2381 | __ Or(dst_high, dst_high, TMP); |
| 2382 | } else if (instr->IsShr()) { |
| 2383 | __ Sra(dst_high, lhs_high, shift_value); |
| 2384 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2385 | __ Srl(dst_low, lhs_low, shift_value); |
| 2386 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2387 | } else if (instr->IsUShr()) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2388 | __ Srl(dst_high, lhs_high, shift_value); |
| 2389 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2390 | __ Srl(dst_low, lhs_low, shift_value); |
| 2391 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2392 | } else { |
| 2393 | __ Srl(TMP, lhs_low, shift_value); |
| 2394 | __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value); |
| 2395 | __ Or(dst_low, dst_low, TMP); |
| 2396 | __ Srl(TMP, lhs_high, shift_value); |
| 2397 | __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2398 | __ Or(dst_high, dst_high, TMP); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2399 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2400 | } |
| 2401 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2402 | const uint32_t shift_value_high = shift_value - kMipsBitsPerWord; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2403 | if (instr->IsShl()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2404 | __ Sll(dst_high, lhs_low, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2405 | __ Move(dst_low, ZERO); |
| 2406 | } else if (instr->IsShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2407 | __ Sra(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2408 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2409 | } else if (instr->IsUShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2410 | __ Srl(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2411 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2412 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2413 | if (shift_value == kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2414 | // 64-bit rotation by 32 is just a swap. |
| 2415 | __ Move(dst_low, lhs_high); |
| 2416 | __ Move(dst_high, lhs_low); |
| 2417 | } else { |
| 2418 | if (has_ins_rotr) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2419 | __ Srl(dst_low, lhs_high, shift_value_high); |
| 2420 | __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high); |
| 2421 | __ Srl(dst_high, lhs_low, shift_value_high); |
| 2422 | __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2423 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2424 | __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high); |
| 2425 | __ Srl(dst_low, lhs_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2426 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2427 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high); |
| 2428 | __ Srl(dst_high, lhs_low, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2429 | __ Or(dst_high, dst_high, TMP); |
| 2430 | } |
| 2431 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2432 | } |
| 2433 | } |
| 2434 | } else { |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2435 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2436 | MipsLabel done; |
| 2437 | if (instr->IsShl()) { |
| 2438 | __ Sllv(dst_low, lhs_low, rhs_reg); |
| 2439 | __ Nor(AT, ZERO, rhs_reg); |
| 2440 | __ Srl(TMP, lhs_low, 1); |
| 2441 | __ Srlv(TMP, TMP, AT); |
| 2442 | __ Sllv(dst_high, lhs_high, rhs_reg); |
| 2443 | __ Or(dst_high, dst_high, TMP); |
| 2444 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2445 | if (isR6) { |
| 2446 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2447 | __ Move(dst_high, dst_low); |
| 2448 | __ Move(dst_low, ZERO); |
| 2449 | } else { |
| 2450 | __ Movn(dst_high, dst_low, TMP); |
| 2451 | __ Movn(dst_low, ZERO, TMP); |
| 2452 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2453 | } else if (instr->IsShr()) { |
| 2454 | __ Srav(dst_high, lhs_high, rhs_reg); |
| 2455 | __ Nor(AT, ZERO, rhs_reg); |
| 2456 | __ Sll(TMP, lhs_high, 1); |
| 2457 | __ Sllv(TMP, TMP, AT); |
| 2458 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2459 | __ Or(dst_low, dst_low, TMP); |
| 2460 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2461 | if (isR6) { |
| 2462 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2463 | __ Move(dst_low, dst_high); |
| 2464 | __ Sra(dst_high, dst_high, 31); |
| 2465 | } else { |
| 2466 | __ Sra(AT, dst_high, 31); |
| 2467 | __ Movn(dst_low, dst_high, TMP); |
| 2468 | __ Movn(dst_high, AT, TMP); |
| 2469 | } |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2470 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2471 | __ Srlv(dst_high, lhs_high, rhs_reg); |
| 2472 | __ Nor(AT, ZERO, rhs_reg); |
| 2473 | __ Sll(TMP, lhs_high, 1); |
| 2474 | __ Sllv(TMP, TMP, AT); |
| 2475 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2476 | __ Or(dst_low, dst_low, TMP); |
| 2477 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2478 | if (isR6) { |
| 2479 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2480 | __ Move(dst_low, dst_high); |
| 2481 | __ Move(dst_high, ZERO); |
| 2482 | } else { |
| 2483 | __ Movn(dst_low, dst_high, TMP); |
| 2484 | __ Movn(dst_high, ZERO, TMP); |
| 2485 | } |
| 2486 | } else { // Rotate. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2487 | __ Nor(AT, ZERO, rhs_reg); |
| 2488 | __ Srlv(TMP, lhs_low, rhs_reg); |
| 2489 | __ Sll(dst_low, lhs_high, 1); |
| 2490 | __ Sllv(dst_low, dst_low, AT); |
| 2491 | __ Or(dst_low, dst_low, TMP); |
| 2492 | __ Srlv(TMP, lhs_high, rhs_reg); |
| 2493 | __ Sll(dst_high, lhs_low, 1); |
| 2494 | __ Sllv(dst_high, dst_high, AT); |
| 2495 | __ Or(dst_high, dst_high, TMP); |
| 2496 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2497 | if (isR6) { |
| 2498 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2499 | __ Move(TMP, dst_high); |
| 2500 | __ Move(dst_high, dst_low); |
| 2501 | __ Move(dst_low, TMP); |
| 2502 | } else { |
| 2503 | __ Movn(AT, dst_high, TMP); |
| 2504 | __ Movn(dst_high, dst_low, TMP); |
| 2505 | __ Movn(dst_low, AT, TMP); |
| 2506 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2507 | } |
| 2508 | __ Bind(&done); |
| 2509 | } |
| 2510 | break; |
| 2511 | } |
| 2512 | |
| 2513 | default: |
| 2514 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2515 | } |
| 2516 | } |
| 2517 | |
| 2518 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { |
| 2519 | HandleBinaryOp(instruction); |
| 2520 | } |
| 2521 | |
| 2522 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { |
| 2523 | HandleBinaryOp(instruction); |
| 2524 | } |
| 2525 | |
| 2526 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { |
| 2527 | HandleBinaryOp(instruction); |
| 2528 | } |
| 2529 | |
| 2530 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { |
| 2531 | HandleBinaryOp(instruction); |
| 2532 | } |
| 2533 | |
| 2534 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2535 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2536 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2537 | kEmitCompilerReadBarrier && (type == DataType::Type::kReference); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2538 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2539 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2540 | object_array_get_with_read_barrier |
| 2541 | ? LocationSummary::kCallOnSlowPath |
| 2542 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 2543 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2544 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2545 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2546 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2547 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2548 | if (DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2549 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2550 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2551 | // The output overlaps in the case of an object array get with |
| 2552 | // read barriers enabled: we do not want the move to overwrite the |
| 2553 | // array's location, as we need it to emit the read barrier. |
| 2554 | locations->SetOut(Location::RequiresRegister(), |
| 2555 | object_array_get_with_read_barrier |
| 2556 | ? Location::kOutputOverlap |
| 2557 | : Location::kNoOutputOverlap); |
| 2558 | } |
| 2559 | // We need a temporary register for the read barrier marking slow |
| 2560 | // path in CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier. |
| 2561 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2562 | bool temp_needed = instruction->GetIndex()->IsConstant() |
| 2563 | ? !kBakerReadBarrierThunksEnableForFields |
| 2564 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2565 | if (temp_needed) { |
| 2566 | locations->AddTemp(Location::RequiresRegister()); |
| 2567 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2568 | } |
| 2569 | } |
| 2570 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2571 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS* codegen) { |
| 2572 | auto null_checker = [codegen, instruction]() { |
| 2573 | codegen->MaybeRecordImplicitNullCheck(instruction); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2574 | }; |
| 2575 | return null_checker; |
| 2576 | } |
| 2577 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2578 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 2579 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2580 | Location obj_loc = locations->InAt(0); |
| 2581 | Register obj = obj_loc.AsRegister<Register>(); |
| 2582 | Location out_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2583 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2584 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2585 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2586 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2587 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2588 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2589 | instruction->IsStringCharAt(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2590 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2591 | case DataType::Type::kBool: |
| 2592 | case DataType::Type::kUint8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2593 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2594 | if (index.IsConstant()) { |
| 2595 | size_t offset = |
| 2596 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2597 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2598 | } else { |
| 2599 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2600 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2601 | } |
| 2602 | break; |
| 2603 | } |
| 2604 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2605 | case DataType::Type::kInt8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2606 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2607 | if (index.IsConstant()) { |
| 2608 | size_t offset = |
| 2609 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2610 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2611 | } else { |
| 2612 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2613 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2614 | } |
| 2615 | break; |
| 2616 | } |
| 2617 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2618 | case DataType::Type::kUint16: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2619 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2620 | if (maybe_compressed_char_at) { |
| 2621 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2622 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
| 2623 | __ Sll(TMP, TMP, 31); // Extract compression flag into the most significant bit of TMP. |
| 2624 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2625 | "Expecting 0=compressed, 1=uncompressed"); |
| 2626 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2627 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2628 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2629 | if (maybe_compressed_char_at) { |
| 2630 | MipsLabel uncompressed_load, done; |
| 2631 | __ Bnez(TMP, &uncompressed_load); |
| 2632 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2633 | out, |
| 2634 | obj, |
| 2635 | data_offset + (const_index << TIMES_1)); |
| 2636 | __ B(&done); |
| 2637 | __ Bind(&uncompressed_load); |
| 2638 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2639 | out, |
| 2640 | obj, |
| 2641 | data_offset + (const_index << TIMES_2)); |
| 2642 | __ Bind(&done); |
| 2643 | } else { |
| 2644 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2645 | out, |
| 2646 | obj, |
| 2647 | data_offset + (const_index << TIMES_2), |
| 2648 | null_checker); |
| 2649 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2650 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2651 | Register index_reg = index.AsRegister<Register>(); |
| 2652 | if (maybe_compressed_char_at) { |
| 2653 | MipsLabel uncompressed_load, done; |
| 2654 | __ Bnez(TMP, &uncompressed_load); |
| 2655 | __ Addu(TMP, obj, index_reg); |
| 2656 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2657 | __ B(&done); |
| 2658 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2659 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2660 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2661 | __ Bind(&done); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2662 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2663 | __ Addu(TMP, index_reg, obj); |
| 2664 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2665 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2666 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2667 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
| 2668 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2669 | } |
| 2670 | break; |
| 2671 | } |
| 2672 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2673 | case DataType::Type::kInt16: { |
| 2674 | Register out = out_loc.AsRegister<Register>(); |
| 2675 | if (index.IsConstant()) { |
| 2676 | size_t offset = |
| 2677 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2678 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2679 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2680 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2681 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2682 | } else { |
| 2683 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_2, TMP); |
| 2684 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
| 2685 | } |
| 2686 | break; |
| 2687 | } |
| 2688 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2689 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2690 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2691 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2692 | if (index.IsConstant()) { |
| 2693 | size_t offset = |
| 2694 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2695 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2696 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2697 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2698 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2699 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2700 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2701 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2702 | } |
| 2703 | break; |
| 2704 | } |
| 2705 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2706 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2707 | static_assert( |
| 2708 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2709 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2710 | // /* HeapReference<Object> */ out = |
| 2711 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2712 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2713 | bool temp_needed = index.IsConstant() |
| 2714 | ? !kBakerReadBarrierThunksEnableForFields |
| 2715 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2716 | Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2717 | // Note that a potential implicit null check is handled in this |
| 2718 | // CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier call. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2719 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 2720 | if (index.IsConstant()) { |
| 2721 | // Array load with a constant index can be treated as a field load. |
| 2722 | size_t offset = |
| 2723 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2724 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2725 | out_loc, |
| 2726 | obj, |
| 2727 | offset, |
| 2728 | temp, |
| 2729 | /* needs_null_check */ false); |
| 2730 | } else { |
| 2731 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2732 | out_loc, |
| 2733 | obj, |
| 2734 | data_offset, |
| 2735 | index, |
| 2736 | temp, |
| 2737 | /* needs_null_check */ false); |
| 2738 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2739 | } else { |
| 2740 | Register out = out_loc.AsRegister<Register>(); |
| 2741 | if (index.IsConstant()) { |
| 2742 | size_t offset = |
| 2743 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2744 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
| 2745 | // If read barriers are enabled, emit read barriers other than |
| 2746 | // Baker's using a slow path (and also unpoison the loaded |
| 2747 | // reference, if heap poisoning is enabled). |
| 2748 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2749 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2750 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2751 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
| 2752 | // If read barriers are enabled, emit read barriers other than |
| 2753 | // Baker's using a slow path (and also unpoison the loaded |
| 2754 | // reference, if heap poisoning is enabled). |
| 2755 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2756 | out_loc, |
| 2757 | out_loc, |
| 2758 | obj_loc, |
| 2759 | data_offset, |
| 2760 | index); |
| 2761 | } |
| 2762 | } |
| 2763 | break; |
| 2764 | } |
| 2765 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2766 | case DataType::Type::kInt64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2767 | Register out = out_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2768 | if (index.IsConstant()) { |
| 2769 | size_t offset = |
| 2770 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2771 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2772 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2773 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2774 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2775 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2776 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2777 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2778 | } |
| 2779 | break; |
| 2780 | } |
| 2781 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2782 | case DataType::Type::kFloat32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2783 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2784 | if (index.IsConstant()) { |
| 2785 | size_t offset = |
| 2786 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2787 | __ LoadSFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2788 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2789 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2790 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2791 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2792 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2793 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2794 | } |
| 2795 | break; |
| 2796 | } |
| 2797 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2798 | case DataType::Type::kFloat64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2799 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2800 | if (index.IsConstant()) { |
| 2801 | size_t offset = |
| 2802 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2803 | __ LoadDFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2804 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2805 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2806 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2807 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2808 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2809 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2810 | } |
| 2811 | break; |
| 2812 | } |
| 2813 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2814 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2815 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2816 | UNREACHABLE(); |
| 2817 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2821 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2822 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2823 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2824 | } |
| 2825 | |
| 2826 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 2827 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2828 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2829 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2830 | Register out = locations->Out().AsRegister<Register>(); |
| 2831 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2832 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2833 | // Mask out compression flag from String's array length. |
| 2834 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2835 | __ Srl(out, out, 1u); |
| 2836 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2837 | } |
| 2838 | |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2839 | Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2840 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2841 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2842 | : Location::RequiresRegister(); |
| 2843 | } |
| 2844 | |
| 2845 | Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2846 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2847 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2848 | // but we should only prefer this if the constant has a single use. |
| 2849 | if (instruction->IsConstant() && |
| 2850 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2851 | instruction->GetUses().HasExactlyOneElement())) { |
| 2852 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2853 | // Otherwise fall through and require an FPU register for the constant. |
| 2854 | } |
| 2855 | return Location::RequiresFpuRegister(); |
| 2856 | } |
| 2857 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2858 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2859 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2860 | |
| 2861 | bool needs_write_barrier = |
| 2862 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2863 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2864 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2865 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2866 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2867 | may_need_runtime_call_for_type_check ? |
| 2868 | LocationSummary::kCallOnSlowPath : |
| 2869 | LocationSummary::kNoCall); |
| 2870 | |
| 2871 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2872 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2873 | if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2874 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2875 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2876 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2877 | } |
| 2878 | if (needs_write_barrier) { |
| 2879 | // Temporary register for the write barrier. |
| 2880 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2881 | } |
| 2882 | } |
| 2883 | |
| 2884 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { |
| 2885 | LocationSummary* locations = instruction->GetLocations(); |
| 2886 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2887 | Location index = locations->InAt(1); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2888 | Location value_location = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2889 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2890 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2891 | bool needs_write_barrier = |
| 2892 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2893 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2894 | Register base_reg = index.IsConstant() ? obj : TMP; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2895 | |
| 2896 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2897 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2898 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2899 | case DataType::Type::kInt8: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2900 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2901 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2902 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2903 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2904 | __ Addu(base_reg, obj, index.AsRegister<Register>()); |
| 2905 | } |
| 2906 | if (value_location.IsConstant()) { |
| 2907 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2908 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2909 | } else { |
| 2910 | Register value = value_location.AsRegister<Register>(); |
| 2911 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2912 | } |
| 2913 | break; |
| 2914 | } |
| 2915 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2916 | case DataType::Type::kUint16: |
| 2917 | case DataType::Type::kInt16: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2918 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2919 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2920 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2921 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2922 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2923 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2924 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_2, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2925 | } |
| 2926 | if (value_location.IsConstant()) { |
| 2927 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2928 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2929 | } else { |
| 2930 | Register value = value_location.AsRegister<Register>(); |
| 2931 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2932 | } |
| 2933 | break; |
| 2934 | } |
| 2935 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2936 | case DataType::Type::kInt32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2937 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2938 | if (index.IsConstant()) { |
| 2939 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2940 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2941 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2942 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2943 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2944 | } |
| 2945 | if (value_location.IsConstant()) { |
| 2946 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2947 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2948 | } else { |
| 2949 | Register value = value_location.AsRegister<Register>(); |
| 2950 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2951 | } |
| 2952 | break; |
| 2953 | } |
| 2954 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2955 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2956 | if (value_location.IsConstant()) { |
| 2957 | // Just setting null. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2958 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2959 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2960 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2961 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2962 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2963 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2964 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2965 | DCHECK_EQ(value, 0); |
| 2966 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2967 | DCHECK(!needs_write_barrier); |
| 2968 | DCHECK(!may_need_runtime_call_for_type_check); |
| 2969 | break; |
| 2970 | } |
| 2971 | |
| 2972 | DCHECK(needs_write_barrier); |
| 2973 | Register value = value_location.AsRegister<Register>(); |
| 2974 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2975 | Register temp2 = TMP; // Doesn't need to survive slow path. |
| 2976 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2977 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2978 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2979 | MipsLabel done; |
| 2980 | SlowPathCodeMIPS* slow_path = nullptr; |
| 2981 | |
| 2982 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2983 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS(instruction); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2984 | codegen_->AddSlowPath(slow_path); |
| 2985 | if (instruction->GetValueCanBeNull()) { |
| 2986 | MipsLabel non_zero; |
| 2987 | __ Bnez(value, &non_zero); |
| 2988 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2989 | if (index.IsConstant()) { |
| 2990 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2991 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2992 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2993 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2994 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2995 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2996 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2997 | __ B(&done); |
| 2998 | __ Bind(&non_zero); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2999 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3000 | |
| 3001 | // Note that when read barriers are enabled, the type checks |
| 3002 | // are performed without read barriers. This is fine, even in |
| 3003 | // the case where a class object is in the from-space after |
| 3004 | // the flip, as a comparison involving such a type would not |
| 3005 | // produce a false positive; it may of course produce a false |
| 3006 | // negative, in which case we would take the ArraySet slow |
| 3007 | // path. |
| 3008 | |
| 3009 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 3010 | __ LoadFromOffset(kLoadWord, temp1, obj, class_offset, null_checker); |
| 3011 | __ MaybeUnpoisonHeapReference(temp1); |
| 3012 | |
| 3013 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 3014 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 3015 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3016 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 3017 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 3018 | // nor `temp2`, as we are comparing two poisoned references. |
| 3019 | |
| 3020 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3021 | MipsLabel do_put; |
| 3022 | __ Beq(temp1, temp2, &do_put); |
| 3023 | // If heap poisoning is enabled, the `temp1` reference has |
| 3024 | // not been unpoisoned yet; unpoison it now. |
| 3025 | __ MaybeUnpoisonHeapReference(temp1); |
| 3026 | |
| 3027 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 3028 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 3029 | // If heap poisoning is enabled, no need to unpoison |
| 3030 | // `temp1`, as we are comparing against null below. |
| 3031 | __ Bnez(temp1, slow_path->GetEntryLabel()); |
| 3032 | __ Bind(&do_put); |
| 3033 | } else { |
| 3034 | __ Bne(temp1, temp2, slow_path->GetEntryLabel()); |
| 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | Register source = value; |
| 3039 | if (kPoisonHeapReferences) { |
| 3040 | // Note that in the case where `value` is a null reference, |
| 3041 | // we do not enter this block, as a null reference does not |
| 3042 | // need poisoning. |
| 3043 | __ Move(temp1, value); |
| 3044 | __ PoisonHeapReference(temp1); |
| 3045 | source = temp1; |
| 3046 | } |
| 3047 | |
| 3048 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3049 | if (index.IsConstant()) { |
| 3050 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3051 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3052 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3053 | } |
| 3054 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 3055 | |
| 3056 | if (!may_need_runtime_call_for_type_check) { |
| 3057 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3058 | } |
| 3059 | |
| 3060 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 3061 | |
| 3062 | if (done.IsLinked()) { |
| 3063 | __ Bind(&done); |
| 3064 | } |
| 3065 | |
| 3066 | if (slow_path != nullptr) { |
| 3067 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3068 | } |
| 3069 | break; |
| 3070 | } |
| 3071 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3072 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3073 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3074 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3075 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3076 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3077 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3078 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3079 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3080 | } |
| 3081 | if (value_location.IsConstant()) { |
| 3082 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3083 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3084 | } else { |
| 3085 | Register value = value_location.AsRegisterPairLow<Register>(); |
| 3086 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3087 | } |
| 3088 | break; |
| 3089 | } |
| 3090 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3091 | case DataType::Type::kFloat32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3092 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3093 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3094 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3095 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3096 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3097 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3098 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3099 | } |
| 3100 | if (value_location.IsConstant()) { |
| 3101 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3102 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 3103 | } else { |
| 3104 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3105 | __ StoreSToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3106 | } |
| 3107 | break; |
| 3108 | } |
| 3109 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3110 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3111 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3112 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3113 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3114 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3115 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3116 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3117 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3118 | } |
| 3119 | if (value_location.IsConstant()) { |
| 3120 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3121 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3122 | } else { |
| 3123 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3124 | __ StoreDToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3125 | } |
| 3126 | break; |
| 3127 | } |
| 3128 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3129 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3130 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 3131 | UNREACHABLE(); |
| 3132 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3133 | } |
| 3134 | |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3135 | void LocationsBuilderMIPS::VisitIntermediateArrayAddressIndex( |
| 3136 | HIntermediateArrayAddressIndex* instruction) { |
| 3137 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3138 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3139 | |
| 3140 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 3141 | |
| 3142 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3143 | locations->SetInAt(1, Location::ConstantLocation(shift)); |
| 3144 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3145 | } |
| 3146 | |
| 3147 | void InstructionCodeGeneratorMIPS::VisitIntermediateArrayAddressIndex( |
| 3148 | HIntermediateArrayAddressIndex* instruction) { |
| 3149 | LocationSummary* locations = instruction->GetLocations(); |
| 3150 | Register index_reg = locations->InAt(0).AsRegister<Register>(); |
| 3151 | uint32_t shift = instruction->GetShift()->AsIntConstant()->GetValue(); |
| 3152 | __ Sll(locations->Out().AsRegister<Register>(), index_reg, shift); |
| 3153 | } |
| 3154 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3155 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3156 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3157 | InvokeRuntimeCallingConvention calling_convention; |
| 3158 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3159 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3160 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3161 | |
| 3162 | HInstruction* index = instruction->InputAt(0); |
| 3163 | HInstruction* length = instruction->InputAt(1); |
| 3164 | |
| 3165 | bool const_index = false; |
| 3166 | bool const_length = false; |
| 3167 | |
| 3168 | if (index->IsConstant()) { |
| 3169 | if (length->IsConstant()) { |
| 3170 | const_index = true; |
| 3171 | const_length = true; |
| 3172 | } else { |
| 3173 | int32_t index_value = index->AsIntConstant()->GetValue(); |
| 3174 | if (index_value < 0 || IsInt<16>(index_value + 1)) { |
| 3175 | const_index = true; |
| 3176 | } |
| 3177 | } |
| 3178 | } else if (length->IsConstant()) { |
| 3179 | int32_t length_value = length->AsIntConstant()->GetValue(); |
| 3180 | if (IsUint<15>(length_value)) { |
| 3181 | const_length = true; |
| 3182 | } |
| 3183 | } |
| 3184 | |
| 3185 | locations->SetInAt(0, const_index |
| 3186 | ? Location::ConstantLocation(index->AsConstant()) |
| 3187 | : Location::RequiresRegister()); |
| 3188 | locations->SetInAt(1, const_length |
| 3189 | ? Location::ConstantLocation(length->AsConstant()) |
| 3190 | : Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 3194 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3195 | Location index_loc = locations->InAt(0); |
| 3196 | Location length_loc = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3197 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3198 | if (length_loc.IsConstant()) { |
| 3199 | int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3200 | if (index_loc.IsConstant()) { |
| 3201 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3202 | if (index < 0 || index >= length) { |
| 3203 | BoundsCheckSlowPathMIPS* slow_path = |
| 3204 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3205 | codegen_->AddSlowPath(slow_path); |
| 3206 | __ B(slow_path->GetEntryLabel()); |
| 3207 | } else { |
| 3208 | // Nothing to be done. |
| 3209 | } |
| 3210 | return; |
| 3211 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3212 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3213 | BoundsCheckSlowPathMIPS* slow_path = |
| 3214 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3215 | codegen_->AddSlowPath(slow_path); |
| 3216 | Register index = index_loc.AsRegister<Register>(); |
| 3217 | if (length == 0) { |
| 3218 | __ B(slow_path->GetEntryLabel()); |
| 3219 | } else if (length == 1) { |
| 3220 | __ Bnez(index, slow_path->GetEntryLabel()); |
| 3221 | } else { |
| 3222 | DCHECK(IsUint<15>(length)) << length; |
| 3223 | __ Sltiu(TMP, index, length); |
| 3224 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3225 | } |
| 3226 | } else { |
| 3227 | Register length = length_loc.AsRegister<Register>(); |
| 3228 | BoundsCheckSlowPathMIPS* slow_path = |
| 3229 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3230 | codegen_->AddSlowPath(slow_path); |
| 3231 | if (index_loc.IsConstant()) { |
| 3232 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3233 | if (index < 0) { |
| 3234 | __ B(slow_path->GetEntryLabel()); |
| 3235 | } else if (index == 0) { |
| 3236 | __ Blez(length, slow_path->GetEntryLabel()); |
| 3237 | } else { |
| 3238 | DCHECK(IsInt<16>(index + 1)) << index; |
| 3239 | __ Sltiu(TMP, length, index + 1); |
| 3240 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 3241 | } |
| 3242 | } else { |
| 3243 | Register index = index_loc.AsRegister<Register>(); |
| 3244 | __ Bgeu(index, length, slow_path->GetEntryLabel()); |
| 3245 | } |
| 3246 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3247 | } |
| 3248 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3249 | // Temp is used for read barrier. |
| 3250 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3251 | if (kEmitCompilerReadBarrier && |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 3252 | !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) && |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3253 | (kUseBakerReadBarrier || |
| 3254 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3255 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3256 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3257 | return 1; |
| 3258 | } |
| 3259 | return 0; |
| 3260 | } |
| 3261 | |
| 3262 | // Extra temp is used for read barrier. |
| 3263 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3264 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 3265 | } |
| 3266 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3267 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3268 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3269 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 3270 | |
| 3271 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3272 | switch (type_check_kind) { |
| 3273 | case TypeCheckKind::kExactCheck: |
| 3274 | case TypeCheckKind::kAbstractClassCheck: |
| 3275 | case TypeCheckKind::kClassHierarchyCheck: |
| 3276 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3277 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3278 | ? LocationSummary::kCallOnSlowPath |
| 3279 | : LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 3280 | break; |
| 3281 | case TypeCheckKind::kArrayCheck: |
| 3282 | case TypeCheckKind::kUnresolvedCheck: |
| 3283 | case TypeCheckKind::kInterfaceCheck: |
| 3284 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3285 | break; |
| 3286 | } |
| 3287 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3288 | LocationSummary* locations = |
| 3289 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3290 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3291 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3292 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3296 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3297 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3298 | Location obj_loc = locations->InAt(0); |
| 3299 | Register obj = obj_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3300 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3301 | Location temp_loc = locations->GetTemp(0); |
| 3302 | Register temp = temp_loc.AsRegister<Register>(); |
| 3303 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 3304 | DCHECK_LE(num_temps, 2u); |
| 3305 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3306 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3307 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3308 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3309 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 3310 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 3311 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 3312 | const uint32_t object_array_data_offset = |
| 3313 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 3314 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3315 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3316 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 3317 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 3318 | // read barriers is done for performance and code size reasons. |
| 3319 | bool is_type_check_slow_path_fatal = false; |
| 3320 | if (!kEmitCompilerReadBarrier) { |
| 3321 | is_type_check_slow_path_fatal = |
| 3322 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 3323 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3324 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3325 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 3326 | !instruction->CanThrowIntoCatchBlock(); |
| 3327 | } |
| 3328 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3329 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 3330 | instruction, is_type_check_slow_path_fatal); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3331 | codegen_->AddSlowPath(slow_path); |
| 3332 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3333 | // Avoid this check if we know `obj` is not null. |
| 3334 | if (instruction->MustDoNullCheck()) { |
| 3335 | __ Beqz(obj, &done); |
| 3336 | } |
| 3337 | |
| 3338 | switch (type_check_kind) { |
| 3339 | case TypeCheckKind::kExactCheck: |
| 3340 | case TypeCheckKind::kArrayCheck: { |
| 3341 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3342 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3343 | temp_loc, |
| 3344 | obj_loc, |
| 3345 | class_offset, |
| 3346 | maybe_temp2_loc, |
| 3347 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3348 | // Jump to slow path for throwing the exception or doing a |
| 3349 | // more involved array check. |
| 3350 | __ Bne(temp, cls, slow_path->GetEntryLabel()); |
| 3351 | break; |
| 3352 | } |
| 3353 | |
| 3354 | case TypeCheckKind::kAbstractClassCheck: { |
| 3355 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3356 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3357 | temp_loc, |
| 3358 | obj_loc, |
| 3359 | class_offset, |
| 3360 | maybe_temp2_loc, |
| 3361 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3362 | // If the class is abstract, we eagerly fetch the super class of the |
| 3363 | // object to avoid doing a comparison we know will fail. |
| 3364 | MipsLabel loop; |
| 3365 | __ Bind(&loop); |
| 3366 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3367 | GenerateReferenceLoadOneRegister(instruction, |
| 3368 | temp_loc, |
| 3369 | super_offset, |
| 3370 | maybe_temp2_loc, |
| 3371 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3372 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3373 | // exception. |
| 3374 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3375 | // Otherwise, compare the classes. |
| 3376 | __ Bne(temp, cls, &loop); |
| 3377 | break; |
| 3378 | } |
| 3379 | |
| 3380 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3381 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3382 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3383 | temp_loc, |
| 3384 | obj_loc, |
| 3385 | class_offset, |
| 3386 | maybe_temp2_loc, |
| 3387 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3388 | // Walk over the class hierarchy to find a match. |
| 3389 | MipsLabel loop; |
| 3390 | __ Bind(&loop); |
| 3391 | __ Beq(temp, cls, &done); |
| 3392 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3393 | GenerateReferenceLoadOneRegister(instruction, |
| 3394 | temp_loc, |
| 3395 | super_offset, |
| 3396 | maybe_temp2_loc, |
| 3397 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3398 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3399 | // exception. Otherwise, jump to the beginning of the loop. |
| 3400 | __ Bnez(temp, &loop); |
| 3401 | __ B(slow_path->GetEntryLabel()); |
| 3402 | break; |
| 3403 | } |
| 3404 | |
| 3405 | case TypeCheckKind::kArrayObjectCheck: { |
| 3406 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3407 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3408 | temp_loc, |
| 3409 | obj_loc, |
| 3410 | class_offset, |
| 3411 | maybe_temp2_loc, |
| 3412 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3413 | // Do an exact check. |
| 3414 | __ Beq(temp, cls, &done); |
| 3415 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 3416 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3417 | GenerateReferenceLoadOneRegister(instruction, |
| 3418 | temp_loc, |
| 3419 | component_offset, |
| 3420 | maybe_temp2_loc, |
| 3421 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3422 | // If the component type is null, jump to the slow path to throw the exception. |
| 3423 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3424 | // Otherwise, the object is indeed an array, further check that this component |
| 3425 | // type is not a primitive type. |
| 3426 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 3427 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3428 | __ Bnez(temp, slow_path->GetEntryLabel()); |
| 3429 | break; |
| 3430 | } |
| 3431 | |
| 3432 | case TypeCheckKind::kUnresolvedCheck: |
| 3433 | // We always go into the type check slow path for the unresolved check case. |
| 3434 | // We cannot directly call the CheckCast runtime entry point |
| 3435 | // without resorting to a type checking slow path here (i.e. by |
| 3436 | // calling InvokeRuntime directly), as it would require to |
| 3437 | // assign fixed registers for the inputs of this HInstanceOf |
| 3438 | // instruction (following the runtime calling convention), which |
| 3439 | // might be cluttered by the potential first read barrier |
| 3440 | // emission at the beginning of this method. |
| 3441 | __ B(slow_path->GetEntryLabel()); |
| 3442 | break; |
| 3443 | |
| 3444 | case TypeCheckKind::kInterfaceCheck: { |
| 3445 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 3446 | // positives by doing this. |
| 3447 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3448 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3449 | temp_loc, |
| 3450 | obj_loc, |
| 3451 | class_offset, |
| 3452 | maybe_temp2_loc, |
| 3453 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3454 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3455 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3456 | temp_loc, |
| 3457 | temp_loc, |
| 3458 | iftable_offset, |
| 3459 | maybe_temp2_loc, |
| 3460 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3461 | // Iftable is never null. |
| 3462 | __ Lw(TMP, temp, array_length_offset); |
| 3463 | // Loop through the iftable and check if any class matches. |
| 3464 | MipsLabel loop; |
| 3465 | __ Bind(&loop); |
| 3466 | __ Addiu(temp, temp, 2 * kHeapReferenceSize); // Possibly in delay slot on R2. |
| 3467 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3468 | __ Lw(AT, temp, object_array_data_offset - 2 * kHeapReferenceSize); |
| 3469 | __ MaybeUnpoisonHeapReference(AT); |
| 3470 | // Go to next interface. |
| 3471 | __ Addiu(TMP, TMP, -2); |
| 3472 | // Compare the classes and continue the loop if they do not match. |
| 3473 | __ Bne(AT, cls, &loop); |
| 3474 | break; |
| 3475 | } |
| 3476 | } |
| 3477 | |
| 3478 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3479 | __ Bind(slow_path->GetExitLabel()); |
| 3480 | } |
| 3481 | |
| 3482 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3483 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3484 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3485 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3486 | if (check->HasUses()) { |
| 3487 | locations->SetOut(Location::SameAsFirstInput()); |
| 3488 | } |
| 3489 | } |
| 3490 | |
| 3491 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3492 | // We assume the class is not null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3493 | SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS( |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3494 | check->GetLoadClass(), |
| 3495 | check, |
| 3496 | check->GetDexPc(), |
| 3497 | true); |
| 3498 | codegen_->AddSlowPath(slow_path); |
| 3499 | GenerateClassInitializationCheck(slow_path, |
| 3500 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| 3501 | } |
| 3502 | |
| 3503 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3504 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3505 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3506 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3507 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3508 | |
| 3509 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3510 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3511 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3512 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3513 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3514 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3515 | case DataType::Type::kInt32: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3516 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3517 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3518 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3519 | break; |
| 3520 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3521 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3522 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3523 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3524 | // Output overlaps because it is written before doing the low comparison. |
| 3525 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3526 | break; |
| 3527 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3528 | case DataType::Type::kFloat32: |
| 3529 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3530 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3531 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3532 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3533 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3534 | |
| 3535 | default: |
| 3536 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3537 | } |
| 3538 | } |
| 3539 | |
| 3540 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { |
| 3541 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3542 | Register res = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3543 | DataType::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3544 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3545 | |
| 3546 | // 0 if: left == right |
| 3547 | // 1 if: left > right |
| 3548 | // -1 if: left < right |
| 3549 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3550 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3551 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3552 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3553 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3554 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3555 | case DataType::Type::kInt32: { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3556 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3557 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 3558 | __ Slt(TMP, lhs, rhs); |
| 3559 | __ Slt(res, rhs, lhs); |
| 3560 | __ Subu(res, res, TMP); |
| 3561 | break; |
| 3562 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3563 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3564 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3565 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3566 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3567 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 3568 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 3569 | // TODO: more efficient (direct) comparison with a constant. |
| 3570 | __ Slt(TMP, lhs_high, rhs_high); |
| 3571 | __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt. |
| 3572 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3573 | __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal. |
| 3574 | __ Sltu(TMP, lhs_low, rhs_low); |
| 3575 | __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt. |
| 3576 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3577 | __ Bind(&done); |
| 3578 | break; |
| 3579 | } |
| 3580 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3581 | case DataType::Type::kFloat32: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3582 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3583 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3584 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3585 | MipsLabel done; |
| 3586 | if (isR6) { |
| 3587 | __ CmpEqS(FTMP, lhs, rhs); |
| 3588 | __ LoadConst32(res, 0); |
| 3589 | __ Bc1nez(FTMP, &done); |
| 3590 | if (gt_bias) { |
| 3591 | __ CmpLtS(FTMP, lhs, rhs); |
| 3592 | __ LoadConst32(res, -1); |
| 3593 | __ Bc1nez(FTMP, &done); |
| 3594 | __ LoadConst32(res, 1); |
| 3595 | } else { |
| 3596 | __ CmpLtS(FTMP, rhs, lhs); |
| 3597 | __ LoadConst32(res, 1); |
| 3598 | __ Bc1nez(FTMP, &done); |
| 3599 | __ LoadConst32(res, -1); |
| 3600 | } |
| 3601 | } else { |
| 3602 | if (gt_bias) { |
| 3603 | __ ColtS(0, lhs, rhs); |
| 3604 | __ LoadConst32(res, -1); |
| 3605 | __ Bc1t(0, &done); |
| 3606 | __ CeqS(0, lhs, rhs); |
| 3607 | __ LoadConst32(res, 1); |
| 3608 | __ Movt(res, ZERO, 0); |
| 3609 | } else { |
| 3610 | __ ColtS(0, rhs, lhs); |
| 3611 | __ LoadConst32(res, 1); |
| 3612 | __ Bc1t(0, &done); |
| 3613 | __ CeqS(0, lhs, rhs); |
| 3614 | __ LoadConst32(res, -1); |
| 3615 | __ Movt(res, ZERO, 0); |
| 3616 | } |
| 3617 | } |
| 3618 | __ Bind(&done); |
| 3619 | break; |
| 3620 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3621 | case DataType::Type::kFloat64: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3622 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3623 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3624 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3625 | MipsLabel done; |
| 3626 | if (isR6) { |
| 3627 | __ CmpEqD(FTMP, lhs, rhs); |
| 3628 | __ LoadConst32(res, 0); |
| 3629 | __ Bc1nez(FTMP, &done); |
| 3630 | if (gt_bias) { |
| 3631 | __ CmpLtD(FTMP, lhs, rhs); |
| 3632 | __ LoadConst32(res, -1); |
| 3633 | __ Bc1nez(FTMP, &done); |
| 3634 | __ LoadConst32(res, 1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3635 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3636 | __ CmpLtD(FTMP, rhs, lhs); |
| 3637 | __ LoadConst32(res, 1); |
| 3638 | __ Bc1nez(FTMP, &done); |
| 3639 | __ LoadConst32(res, -1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3640 | } |
| 3641 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3642 | if (gt_bias) { |
| 3643 | __ ColtD(0, lhs, rhs); |
| 3644 | __ LoadConst32(res, -1); |
| 3645 | __ Bc1t(0, &done); |
| 3646 | __ CeqD(0, lhs, rhs); |
| 3647 | __ LoadConst32(res, 1); |
| 3648 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3649 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3650 | __ ColtD(0, rhs, lhs); |
| 3651 | __ LoadConst32(res, 1); |
| 3652 | __ Bc1t(0, &done); |
| 3653 | __ CeqD(0, lhs, rhs); |
| 3654 | __ LoadConst32(res, -1); |
| 3655 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3656 | } |
| 3657 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3658 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3659 | break; |
| 3660 | } |
| 3661 | |
| 3662 | default: |
| 3663 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3664 | } |
| 3665 | } |
| 3666 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3667 | void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3668 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3669 | switch (instruction->InputAt(0)->GetType()) { |
| 3670 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3671 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3672 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3673 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3674 | break; |
| 3675 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3676 | case DataType::Type::kFloat32: |
| 3677 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3678 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3679 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3680 | break; |
| 3681 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3682 | if (!instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3683 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3684 | } |
| 3685 | } |
| 3686 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3687 | void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3688 | if (instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3689 | return; |
| 3690 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3691 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3692 | DataType::Type type = instruction->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3693 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3694 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3695 | switch (type) { |
| 3696 | default: |
| 3697 | // Integer case. |
| 3698 | GenerateIntCompare(instruction->GetCondition(), locations); |
| 3699 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3700 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3701 | case DataType::Type::kInt64: |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 3702 | GenerateLongCompare(instruction->GetCondition(), locations); |
| 3703 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3704 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3705 | case DataType::Type::kFloat32: |
| 3706 | case DataType::Type::kFloat64: |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 3707 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 3708 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3709 | } |
| 3710 | } |
| 3711 | |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3712 | void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3713 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3714 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3715 | |
| 3716 | LocationSummary* locations = instruction->GetLocations(); |
| 3717 | Location second = locations->InAt(1); |
| 3718 | DCHECK(second.IsConstant()); |
| 3719 | |
| 3720 | Register out = locations->Out().AsRegister<Register>(); |
| 3721 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3722 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3723 | DCHECK(imm == 1 || imm == -1); |
| 3724 | |
| 3725 | if (instruction->IsRem()) { |
| 3726 | __ Move(out, ZERO); |
| 3727 | } else { |
| 3728 | if (imm == -1) { |
| 3729 | __ Subu(out, ZERO, dividend); |
| 3730 | } else if (out != dividend) { |
| 3731 | __ Move(out, dividend); |
| 3732 | } |
| 3733 | } |
| 3734 | } |
| 3735 | |
| 3736 | void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3737 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3738 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3739 | |
| 3740 | LocationSummary* locations = instruction->GetLocations(); |
| 3741 | Location second = locations->InAt(1); |
| 3742 | DCHECK(second.IsConstant()); |
| 3743 | |
| 3744 | Register out = locations->Out().AsRegister<Register>(); |
| 3745 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3746 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3747 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3748 | int ctz_imm = CTZ(abs_imm); |
| 3749 | |
| 3750 | if (instruction->IsDiv()) { |
| 3751 | if (ctz_imm == 1) { |
| 3752 | // Fast path for division by +/-2, which is very common. |
| 3753 | __ Srl(TMP, dividend, 31); |
| 3754 | } else { |
| 3755 | __ Sra(TMP, dividend, 31); |
| 3756 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3757 | } |
| 3758 | __ Addu(out, dividend, TMP); |
| 3759 | __ Sra(out, out, ctz_imm); |
| 3760 | if (imm < 0) { |
| 3761 | __ Subu(out, ZERO, out); |
| 3762 | } |
| 3763 | } else { |
| 3764 | if (ctz_imm == 1) { |
| 3765 | // Fast path for modulo +/-2, which is very common. |
| 3766 | __ Sra(TMP, dividend, 31); |
| 3767 | __ Subu(out, dividend, TMP); |
| 3768 | __ Andi(out, out, 1); |
| 3769 | __ Addu(out, out, TMP); |
| 3770 | } else { |
| 3771 | __ Sra(TMP, dividend, 31); |
| 3772 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3773 | __ Addu(out, dividend, TMP); |
| 3774 | if (IsUint<16>(abs_imm - 1)) { |
| 3775 | __ Andi(out, out, abs_imm - 1); |
| 3776 | } else { |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3777 | if (codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2()) { |
| 3778 | __ Ins(out, ZERO, ctz_imm, 32 - ctz_imm); |
| 3779 | } else { |
| 3780 | __ Sll(out, out, 32 - ctz_imm); |
| 3781 | __ Srl(out, out, 32 - ctz_imm); |
| 3782 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3783 | } |
| 3784 | __ Subu(out, out, TMP); |
| 3785 | } |
| 3786 | } |
| 3787 | } |
| 3788 | |
| 3789 | void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3790 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3791 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3792 | |
| 3793 | LocationSummary* locations = instruction->GetLocations(); |
| 3794 | Location second = locations->InAt(1); |
| 3795 | DCHECK(second.IsConstant()); |
| 3796 | |
| 3797 | Register out = locations->Out().AsRegister<Register>(); |
| 3798 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3799 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3800 | |
| 3801 | int64_t magic; |
| 3802 | int shift; |
| 3803 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3804 | |
| 3805 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3806 | |
| 3807 | __ LoadConst32(TMP, magic); |
| 3808 | if (isR6) { |
| 3809 | __ MuhR6(TMP, dividend, TMP); |
| 3810 | } else { |
| 3811 | __ MultR2(dividend, TMP); |
| 3812 | __ Mfhi(TMP); |
| 3813 | } |
| 3814 | if (imm > 0 && magic < 0) { |
| 3815 | __ Addu(TMP, TMP, dividend); |
| 3816 | } else if (imm < 0 && magic > 0) { |
| 3817 | __ Subu(TMP, TMP, dividend); |
| 3818 | } |
| 3819 | |
| 3820 | if (shift != 0) { |
| 3821 | __ Sra(TMP, TMP, shift); |
| 3822 | } |
| 3823 | |
| 3824 | if (instruction->IsDiv()) { |
| 3825 | __ Sra(out, TMP, 31); |
| 3826 | __ Subu(out, TMP, out); |
| 3827 | } else { |
| 3828 | __ Sra(AT, TMP, 31); |
| 3829 | __ Subu(AT, TMP, AT); |
| 3830 | __ LoadConst32(TMP, imm); |
| 3831 | if (isR6) { |
| 3832 | __ MulR6(TMP, AT, TMP); |
| 3833 | } else { |
| 3834 | __ MulR2(TMP, AT, TMP); |
| 3835 | } |
| 3836 | __ Subu(out, dividend, TMP); |
| 3837 | } |
| 3838 | } |
| 3839 | |
| 3840 | void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3841 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3842 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3843 | |
| 3844 | LocationSummary* locations = instruction->GetLocations(); |
| 3845 | Register out = locations->Out().AsRegister<Register>(); |
| 3846 | Location second = locations->InAt(1); |
| 3847 | |
| 3848 | if (second.IsConstant()) { |
| 3849 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3850 | if (imm == 0) { |
| 3851 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3852 | } else if (imm == 1 || imm == -1) { |
| 3853 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3854 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3855 | DivRemByPowerOfTwo(instruction); |
| 3856 | } else { |
| 3857 | DCHECK(imm <= -2 || imm >= 2); |
| 3858 | GenerateDivRemWithAnyConstant(instruction); |
| 3859 | } |
| 3860 | } else { |
| 3861 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3862 | Register divisor = second.AsRegister<Register>(); |
| 3863 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3864 | if (instruction->IsDiv()) { |
| 3865 | if (isR6) { |
| 3866 | __ DivR6(out, dividend, divisor); |
| 3867 | } else { |
| 3868 | __ DivR2(out, dividend, divisor); |
| 3869 | } |
| 3870 | } else { |
| 3871 | if (isR6) { |
| 3872 | __ ModR6(out, dividend, divisor); |
| 3873 | } else { |
| 3874 | __ ModR2(out, dividend, divisor); |
| 3875 | } |
| 3876 | } |
| 3877 | } |
| 3878 | } |
| 3879 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3880 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3881 | DataType::Type type = div->GetResultType(); |
| 3882 | LocationSummary::CallKind call_kind = (type == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3883 | ? LocationSummary::kCallOnMainOnly |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3884 | : LocationSummary::kNoCall; |
| 3885 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3886 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3887 | |
| 3888 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3889 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3890 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3891 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3892 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3893 | break; |
| 3894 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3895 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3896 | InvokeRuntimeCallingConvention calling_convention; |
| 3897 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3898 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3899 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3900 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3901 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 3902 | break; |
| 3903 | } |
| 3904 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3905 | case DataType::Type::kFloat32: |
| 3906 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3907 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3908 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3909 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3910 | break; |
| 3911 | |
| 3912 | default: |
| 3913 | LOG(FATAL) << "Unexpected div type " << type; |
| 3914 | } |
| 3915 | } |
| 3916 | |
| 3917 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3918 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3919 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3920 | |
| 3921 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3922 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3923 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3924 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3925 | case DataType::Type::kInt64: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 3926 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3927 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| 3928 | break; |
| 3929 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3930 | case DataType::Type::kFloat32: |
| 3931 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3932 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 3933 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3934 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3935 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3936 | __ DivS(dst, lhs, rhs); |
| 3937 | } else { |
| 3938 | __ DivD(dst, lhs, rhs); |
| 3939 | } |
| 3940 | break; |
| 3941 | } |
| 3942 | default: |
| 3943 | LOG(FATAL) << "Unexpected div type " << type; |
| 3944 | } |
| 3945 | } |
| 3946 | |
| 3947 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3948 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3949 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3950 | } |
| 3951 | |
| 3952 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3953 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3954 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3955 | codegen_->AddSlowPath(slow_path); |
| 3956 | Location value = instruction->GetLocations()->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3957 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3958 | |
| 3959 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3960 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3961 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3962 | case DataType::Type::kInt8: |
| 3963 | case DataType::Type::kUint16: |
| 3964 | case DataType::Type::kInt16: |
| 3965 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3966 | if (value.IsConstant()) { |
| 3967 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3968 | __ B(slow_path->GetEntryLabel()); |
| 3969 | } else { |
| 3970 | // A division by a non-null constant is valid. We don't need to perform |
| 3971 | // any check, so simply fall through. |
| 3972 | } |
| 3973 | } else { |
| 3974 | DCHECK(value.IsRegister()) << value; |
| 3975 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 3976 | } |
| 3977 | break; |
| 3978 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3979 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3980 | if (value.IsConstant()) { |
| 3981 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3982 | __ B(slow_path->GetEntryLabel()); |
| 3983 | } else { |
| 3984 | // A division by a non-null constant is valid. We don't need to perform |
| 3985 | // any check, so simply fall through. |
| 3986 | } |
| 3987 | } else { |
| 3988 | DCHECK(value.IsRegisterPair()) << value; |
| 3989 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); |
| 3990 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3991 | } |
| 3992 | break; |
| 3993 | } |
| 3994 | default: |
| 3995 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| 3996 | } |
| 3997 | } |
| 3998 | |
| 3999 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { |
| 4000 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4001 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4002 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4003 | } |
| 4004 | |
| 4005 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 4006 | // Will be generated at use site. |
| 4007 | } |
| 4008 | |
| 4009 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { |
| 4010 | exit->SetLocations(nullptr); |
| 4011 | } |
| 4012 | |
| 4013 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 4014 | } |
| 4015 | |
| 4016 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { |
| 4017 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4018 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4019 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4020 | } |
| 4021 | |
| 4022 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 4023 | // Will be generated at use site. |
| 4024 | } |
| 4025 | |
| 4026 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { |
| 4027 | got->SetLocations(nullptr); |
| 4028 | } |
| 4029 | |
| 4030 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| 4031 | DCHECK(!successor->IsExitBlock()); |
| 4032 | HBasicBlock* block = got->GetBlock(); |
| 4033 | HInstruction* previous = got->GetPrevious(); |
| 4034 | HLoopInformation* info = block->GetLoopInformation(); |
| 4035 | |
| 4036 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4037 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 4038 | return; |
| 4039 | } |
| 4040 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 4041 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 4042 | } |
| 4043 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 4044 | __ B(codegen_->GetLabelOf(successor)); |
| 4045 | } |
| 4046 | } |
| 4047 | |
| 4048 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { |
| 4049 | HandleGoto(got, got->GetSuccessor()); |
| 4050 | } |
| 4051 | |
| 4052 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 4053 | try_boundary->SetLocations(nullptr); |
| 4054 | } |
| 4055 | |
| 4056 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 4057 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 4058 | if (!successor->IsExitBlock()) { |
| 4059 | HandleGoto(try_boundary, successor); |
| 4060 | } |
| 4061 | } |
| 4062 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4063 | void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond, |
| 4064 | LocationSummary* locations) { |
| 4065 | Register dst = locations->Out().AsRegister<Register>(); |
| 4066 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4067 | Location rhs_location = locations->InAt(1); |
| 4068 | Register rhs_reg = ZERO; |
| 4069 | int64_t rhs_imm = 0; |
| 4070 | bool use_imm = rhs_location.IsConstant(); |
| 4071 | if (use_imm) { |
| 4072 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4073 | } else { |
| 4074 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4075 | } |
| 4076 | |
| 4077 | switch (cond) { |
| 4078 | case kCondEQ: |
| 4079 | case kCondNE: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4080 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4081 | if (rhs_imm == 0) { |
| 4082 | if (cond == kCondEQ) { |
| 4083 | __ Sltiu(dst, lhs, 1); |
| 4084 | } else { |
| 4085 | __ Sltu(dst, ZERO, lhs); |
| 4086 | } |
| 4087 | } else { |
| 4088 | __ Addiu(dst, lhs, -rhs_imm); |
| 4089 | if (cond == kCondEQ) { |
| 4090 | __ Sltiu(dst, dst, 1); |
| 4091 | } else { |
| 4092 | __ Sltu(dst, ZERO, dst); |
| 4093 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4094 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4095 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4096 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 4097 | __ Xori(dst, lhs, rhs_imm); |
| 4098 | } else { |
| 4099 | if (use_imm) { |
| 4100 | rhs_reg = TMP; |
| 4101 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4102 | } |
| 4103 | __ Xor(dst, lhs, rhs_reg); |
| 4104 | } |
| 4105 | if (cond == kCondEQ) { |
| 4106 | __ Sltiu(dst, dst, 1); |
| 4107 | } else { |
| 4108 | __ Sltu(dst, ZERO, dst); |
| 4109 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4110 | } |
| 4111 | break; |
| 4112 | |
| 4113 | case kCondLT: |
| 4114 | case kCondGE: |
| 4115 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4116 | __ Slti(dst, lhs, rhs_imm); |
| 4117 | } else { |
| 4118 | if (use_imm) { |
| 4119 | rhs_reg = TMP; |
| 4120 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4121 | } |
| 4122 | __ Slt(dst, lhs, rhs_reg); |
| 4123 | } |
| 4124 | if (cond == kCondGE) { |
| 4125 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4126 | // only the slt instruction but no sge. |
| 4127 | __ Xori(dst, dst, 1); |
| 4128 | } |
| 4129 | break; |
| 4130 | |
| 4131 | case kCondLE: |
| 4132 | case kCondGT: |
| 4133 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4134 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4135 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4136 | if (cond == kCondGT) { |
| 4137 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4138 | // only the slti instruction but no sgti. |
| 4139 | __ Xori(dst, dst, 1); |
| 4140 | } |
| 4141 | } else { |
| 4142 | if (use_imm) { |
| 4143 | rhs_reg = TMP; |
| 4144 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4145 | } |
| 4146 | __ Slt(dst, rhs_reg, lhs); |
| 4147 | if (cond == kCondLE) { |
| 4148 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4149 | // only the slt instruction but no sle. |
| 4150 | __ Xori(dst, dst, 1); |
| 4151 | } |
| 4152 | } |
| 4153 | break; |
| 4154 | |
| 4155 | case kCondB: |
| 4156 | case kCondAE: |
| 4157 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4158 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4159 | // the comparison and thus lets us compare directly with |
| 4160 | // unsigned values in the ranges [0, 0x7fff] and |
| 4161 | // [0xffff8000, 0xffffffff]. |
| 4162 | __ Sltiu(dst, lhs, rhs_imm); |
| 4163 | } else { |
| 4164 | if (use_imm) { |
| 4165 | rhs_reg = TMP; |
| 4166 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4167 | } |
| 4168 | __ Sltu(dst, lhs, rhs_reg); |
| 4169 | } |
| 4170 | if (cond == kCondAE) { |
| 4171 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4172 | // only the sltu instruction but no sgeu. |
| 4173 | __ Xori(dst, dst, 1); |
| 4174 | } |
| 4175 | break; |
| 4176 | |
| 4177 | case kCondBE: |
| 4178 | case kCondA: |
| 4179 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4180 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4181 | // Note that this only works if rhs + 1 does not overflow |
| 4182 | // to 0, hence the check above. |
| 4183 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4184 | // the comparison and thus lets us compare directly with |
| 4185 | // unsigned values in the ranges [0, 0x7fff] and |
| 4186 | // [0xffff8000, 0xffffffff]. |
| 4187 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4188 | if (cond == kCondA) { |
| 4189 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4190 | // only the sltiu instruction but no sgtiu. |
| 4191 | __ Xori(dst, dst, 1); |
| 4192 | } |
| 4193 | } else { |
| 4194 | if (use_imm) { |
| 4195 | rhs_reg = TMP; |
| 4196 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4197 | } |
| 4198 | __ Sltu(dst, rhs_reg, lhs); |
| 4199 | if (cond == kCondBE) { |
| 4200 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4201 | // only the sltu instruction but no sleu. |
| 4202 | __ Xori(dst, dst, 1); |
| 4203 | } |
| 4204 | } |
| 4205 | break; |
| 4206 | } |
| 4207 | } |
| 4208 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4209 | bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond, |
| 4210 | LocationSummary* input_locations, |
| 4211 | Register dst) { |
| 4212 | Register lhs = input_locations->InAt(0).AsRegister<Register>(); |
| 4213 | Location rhs_location = input_locations->InAt(1); |
| 4214 | Register rhs_reg = ZERO; |
| 4215 | int64_t rhs_imm = 0; |
| 4216 | bool use_imm = rhs_location.IsConstant(); |
| 4217 | if (use_imm) { |
| 4218 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4219 | } else { |
| 4220 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4221 | } |
| 4222 | |
| 4223 | switch (cond) { |
| 4224 | case kCondEQ: |
| 4225 | case kCondNE: |
| 4226 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4227 | __ Addiu(dst, lhs, -rhs_imm); |
| 4228 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 4229 | __ Xori(dst, lhs, rhs_imm); |
| 4230 | } else { |
| 4231 | if (use_imm) { |
| 4232 | rhs_reg = TMP; |
| 4233 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4234 | } |
| 4235 | __ Xor(dst, lhs, rhs_reg); |
| 4236 | } |
| 4237 | return (cond == kCondEQ); |
| 4238 | |
| 4239 | case kCondLT: |
| 4240 | case kCondGE: |
| 4241 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4242 | __ Slti(dst, lhs, rhs_imm); |
| 4243 | } else { |
| 4244 | if (use_imm) { |
| 4245 | rhs_reg = TMP; |
| 4246 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4247 | } |
| 4248 | __ Slt(dst, lhs, rhs_reg); |
| 4249 | } |
| 4250 | return (cond == kCondGE); |
| 4251 | |
| 4252 | case kCondLE: |
| 4253 | case kCondGT: |
| 4254 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4255 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4256 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4257 | return (cond == kCondGT); |
| 4258 | } else { |
| 4259 | if (use_imm) { |
| 4260 | rhs_reg = TMP; |
| 4261 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4262 | } |
| 4263 | __ Slt(dst, rhs_reg, lhs); |
| 4264 | return (cond == kCondLE); |
| 4265 | } |
| 4266 | |
| 4267 | case kCondB: |
| 4268 | case kCondAE: |
| 4269 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4270 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4271 | // the comparison and thus lets us compare directly with |
| 4272 | // unsigned values in the ranges [0, 0x7fff] and |
| 4273 | // [0xffff8000, 0xffffffff]. |
| 4274 | __ Sltiu(dst, lhs, rhs_imm); |
| 4275 | } else { |
| 4276 | if (use_imm) { |
| 4277 | rhs_reg = TMP; |
| 4278 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4279 | } |
| 4280 | __ Sltu(dst, lhs, rhs_reg); |
| 4281 | } |
| 4282 | return (cond == kCondAE); |
| 4283 | |
| 4284 | case kCondBE: |
| 4285 | case kCondA: |
| 4286 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4287 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4288 | // Note that this only works if rhs + 1 does not overflow |
| 4289 | // to 0, hence the check above. |
| 4290 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4291 | // the comparison and thus lets us compare directly with |
| 4292 | // unsigned values in the ranges [0, 0x7fff] and |
| 4293 | // [0xffff8000, 0xffffffff]. |
| 4294 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4295 | return (cond == kCondA); |
| 4296 | } else { |
| 4297 | if (use_imm) { |
| 4298 | rhs_reg = TMP; |
| 4299 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4300 | } |
| 4301 | __ Sltu(dst, rhs_reg, lhs); |
| 4302 | return (cond == kCondBE); |
| 4303 | } |
| 4304 | } |
| 4305 | } |
| 4306 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4307 | void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond, |
| 4308 | LocationSummary* locations, |
| 4309 | MipsLabel* label) { |
| 4310 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4311 | Location rhs_location = locations->InAt(1); |
| 4312 | Register rhs_reg = ZERO; |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4313 | int64_t rhs_imm = 0; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4314 | bool use_imm = rhs_location.IsConstant(); |
| 4315 | if (use_imm) { |
| 4316 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4317 | } else { |
| 4318 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4319 | } |
| 4320 | |
| 4321 | if (use_imm && rhs_imm == 0) { |
| 4322 | switch (cond) { |
| 4323 | case kCondEQ: |
| 4324 | case kCondBE: // <= 0 if zero |
| 4325 | __ Beqz(lhs, label); |
| 4326 | break; |
| 4327 | case kCondNE: |
| 4328 | case kCondA: // > 0 if non-zero |
| 4329 | __ Bnez(lhs, label); |
| 4330 | break; |
| 4331 | case kCondLT: |
| 4332 | __ Bltz(lhs, label); |
| 4333 | break; |
| 4334 | case kCondGE: |
| 4335 | __ Bgez(lhs, label); |
| 4336 | break; |
| 4337 | case kCondLE: |
| 4338 | __ Blez(lhs, label); |
| 4339 | break; |
| 4340 | case kCondGT: |
| 4341 | __ Bgtz(lhs, label); |
| 4342 | break; |
| 4343 | case kCondB: // always false |
| 4344 | break; |
| 4345 | case kCondAE: // always true |
| 4346 | __ B(label); |
| 4347 | break; |
| 4348 | } |
| 4349 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4350 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4351 | if (isR6 || !use_imm) { |
| 4352 | if (use_imm) { |
| 4353 | rhs_reg = TMP; |
| 4354 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4355 | } |
| 4356 | switch (cond) { |
| 4357 | case kCondEQ: |
| 4358 | __ Beq(lhs, rhs_reg, label); |
| 4359 | break; |
| 4360 | case kCondNE: |
| 4361 | __ Bne(lhs, rhs_reg, label); |
| 4362 | break; |
| 4363 | case kCondLT: |
| 4364 | __ Blt(lhs, rhs_reg, label); |
| 4365 | break; |
| 4366 | case kCondGE: |
| 4367 | __ Bge(lhs, rhs_reg, label); |
| 4368 | break; |
| 4369 | case kCondLE: |
| 4370 | __ Bge(rhs_reg, lhs, label); |
| 4371 | break; |
| 4372 | case kCondGT: |
| 4373 | __ Blt(rhs_reg, lhs, label); |
| 4374 | break; |
| 4375 | case kCondB: |
| 4376 | __ Bltu(lhs, rhs_reg, label); |
| 4377 | break; |
| 4378 | case kCondAE: |
| 4379 | __ Bgeu(lhs, rhs_reg, label); |
| 4380 | break; |
| 4381 | case kCondBE: |
| 4382 | __ Bgeu(rhs_reg, lhs, label); |
| 4383 | break; |
| 4384 | case kCondA: |
| 4385 | __ Bltu(rhs_reg, lhs, label); |
| 4386 | break; |
| 4387 | } |
| 4388 | } else { |
| 4389 | // Special cases for more efficient comparison with constants on R2. |
| 4390 | switch (cond) { |
| 4391 | case kCondEQ: |
| 4392 | __ LoadConst32(TMP, rhs_imm); |
| 4393 | __ Beq(lhs, TMP, label); |
| 4394 | break; |
| 4395 | case kCondNE: |
| 4396 | __ LoadConst32(TMP, rhs_imm); |
| 4397 | __ Bne(lhs, TMP, label); |
| 4398 | break; |
| 4399 | case kCondLT: |
| 4400 | if (IsInt<16>(rhs_imm)) { |
| 4401 | __ Slti(TMP, lhs, rhs_imm); |
| 4402 | __ Bnez(TMP, label); |
| 4403 | } else { |
| 4404 | __ LoadConst32(TMP, rhs_imm); |
| 4405 | __ Blt(lhs, TMP, label); |
| 4406 | } |
| 4407 | break; |
| 4408 | case kCondGE: |
| 4409 | if (IsInt<16>(rhs_imm)) { |
| 4410 | __ Slti(TMP, lhs, rhs_imm); |
| 4411 | __ Beqz(TMP, label); |
| 4412 | } else { |
| 4413 | __ LoadConst32(TMP, rhs_imm); |
| 4414 | __ Bge(lhs, TMP, label); |
| 4415 | } |
| 4416 | break; |
| 4417 | case kCondLE: |
| 4418 | if (IsInt<16>(rhs_imm + 1)) { |
| 4419 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4420 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4421 | __ Bnez(TMP, label); |
| 4422 | } else { |
| 4423 | __ LoadConst32(TMP, rhs_imm); |
| 4424 | __ Bge(TMP, lhs, label); |
| 4425 | } |
| 4426 | break; |
| 4427 | case kCondGT: |
| 4428 | if (IsInt<16>(rhs_imm + 1)) { |
| 4429 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4430 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4431 | __ Beqz(TMP, label); |
| 4432 | } else { |
| 4433 | __ LoadConst32(TMP, rhs_imm); |
| 4434 | __ Blt(TMP, lhs, label); |
| 4435 | } |
| 4436 | break; |
| 4437 | case kCondB: |
| 4438 | if (IsInt<16>(rhs_imm)) { |
| 4439 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4440 | __ Bnez(TMP, label); |
| 4441 | } else { |
| 4442 | __ LoadConst32(TMP, rhs_imm); |
| 4443 | __ Bltu(lhs, TMP, label); |
| 4444 | } |
| 4445 | break; |
| 4446 | case kCondAE: |
| 4447 | if (IsInt<16>(rhs_imm)) { |
| 4448 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4449 | __ Beqz(TMP, label); |
| 4450 | } else { |
| 4451 | __ LoadConst32(TMP, rhs_imm); |
| 4452 | __ Bgeu(lhs, TMP, label); |
| 4453 | } |
| 4454 | break; |
| 4455 | case kCondBE: |
| 4456 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4457 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4458 | // Note that this only works if rhs + 1 does not overflow |
| 4459 | // to 0, hence the check above. |
| 4460 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4461 | __ Bnez(TMP, label); |
| 4462 | } else { |
| 4463 | __ LoadConst32(TMP, rhs_imm); |
| 4464 | __ Bgeu(TMP, lhs, label); |
| 4465 | } |
| 4466 | break; |
| 4467 | case kCondA: |
| 4468 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4469 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4470 | // Note that this only works if rhs + 1 does not overflow |
| 4471 | // to 0, hence the check above. |
| 4472 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4473 | __ Beqz(TMP, label); |
| 4474 | } else { |
| 4475 | __ LoadConst32(TMP, rhs_imm); |
| 4476 | __ Bltu(TMP, lhs, label); |
| 4477 | } |
| 4478 | break; |
| 4479 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4480 | } |
| 4481 | } |
| 4482 | } |
| 4483 | |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 4484 | void InstructionCodeGeneratorMIPS::GenerateLongCompare(IfCondition cond, |
| 4485 | LocationSummary* locations) { |
| 4486 | Register dst = locations->Out().AsRegister<Register>(); |
| 4487 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4488 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4489 | Location rhs_location = locations->InAt(1); |
| 4490 | Register rhs_high = ZERO; |
| 4491 | Register rhs_low = ZERO; |
| 4492 | int64_t imm = 0; |
| 4493 | uint32_t imm_high = 0; |
| 4494 | uint32_t imm_low = 0; |
| 4495 | bool use_imm = rhs_location.IsConstant(); |
| 4496 | if (use_imm) { |
| 4497 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 4498 | imm_high = High32Bits(imm); |
| 4499 | imm_low = Low32Bits(imm); |
| 4500 | } else { |
| 4501 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 4502 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 4503 | } |
| 4504 | if (use_imm && imm == 0) { |
| 4505 | switch (cond) { |
| 4506 | case kCondEQ: |
| 4507 | case kCondBE: // <= 0 if zero |
| 4508 | __ Or(dst, lhs_high, lhs_low); |
| 4509 | __ Sltiu(dst, dst, 1); |
| 4510 | break; |
| 4511 | case kCondNE: |
| 4512 | case kCondA: // > 0 if non-zero |
| 4513 | __ Or(dst, lhs_high, lhs_low); |
| 4514 | __ Sltu(dst, ZERO, dst); |
| 4515 | break; |
| 4516 | case kCondLT: |
| 4517 | __ Slt(dst, lhs_high, ZERO); |
| 4518 | break; |
| 4519 | case kCondGE: |
| 4520 | __ Slt(dst, lhs_high, ZERO); |
| 4521 | __ Xori(dst, dst, 1); |
| 4522 | break; |
| 4523 | case kCondLE: |
| 4524 | __ Or(TMP, lhs_high, lhs_low); |
| 4525 | __ Sra(AT, lhs_high, 31); |
| 4526 | __ Sltu(dst, AT, TMP); |
| 4527 | __ Xori(dst, dst, 1); |
| 4528 | break; |
| 4529 | case kCondGT: |
| 4530 | __ Or(TMP, lhs_high, lhs_low); |
| 4531 | __ Sra(AT, lhs_high, 31); |
| 4532 | __ Sltu(dst, AT, TMP); |
| 4533 | break; |
| 4534 | case kCondB: // always false |
| 4535 | __ Andi(dst, dst, 0); |
| 4536 | break; |
| 4537 | case kCondAE: // always true |
| 4538 | __ Ori(dst, ZERO, 1); |
| 4539 | break; |
| 4540 | } |
| 4541 | } else if (use_imm) { |
| 4542 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 4543 | switch (cond) { |
| 4544 | case kCondEQ: |
| 4545 | __ LoadConst32(TMP, imm_high); |
| 4546 | __ Xor(TMP, TMP, lhs_high); |
| 4547 | __ LoadConst32(AT, imm_low); |
| 4548 | __ Xor(AT, AT, lhs_low); |
| 4549 | __ Or(dst, TMP, AT); |
| 4550 | __ Sltiu(dst, dst, 1); |
| 4551 | break; |
| 4552 | case kCondNE: |
| 4553 | __ LoadConst32(TMP, imm_high); |
| 4554 | __ Xor(TMP, TMP, lhs_high); |
| 4555 | __ LoadConst32(AT, imm_low); |
| 4556 | __ Xor(AT, AT, lhs_low); |
| 4557 | __ Or(dst, TMP, AT); |
| 4558 | __ Sltu(dst, ZERO, dst); |
| 4559 | break; |
| 4560 | case kCondLT: |
| 4561 | case kCondGE: |
| 4562 | if (dst == lhs_low) { |
| 4563 | __ LoadConst32(TMP, imm_low); |
| 4564 | __ Sltu(dst, lhs_low, TMP); |
| 4565 | } |
| 4566 | __ LoadConst32(TMP, imm_high); |
| 4567 | __ Slt(AT, lhs_high, TMP); |
| 4568 | __ Slt(TMP, TMP, lhs_high); |
| 4569 | if (dst != lhs_low) { |
| 4570 | __ LoadConst32(dst, imm_low); |
| 4571 | __ Sltu(dst, lhs_low, dst); |
| 4572 | } |
| 4573 | __ Slt(dst, TMP, dst); |
| 4574 | __ Or(dst, dst, AT); |
| 4575 | if (cond == kCondGE) { |
| 4576 | __ Xori(dst, dst, 1); |
| 4577 | } |
| 4578 | break; |
| 4579 | case kCondGT: |
| 4580 | case kCondLE: |
| 4581 | if (dst == lhs_low) { |
| 4582 | __ LoadConst32(TMP, imm_low); |
| 4583 | __ Sltu(dst, TMP, lhs_low); |
| 4584 | } |
| 4585 | __ LoadConst32(TMP, imm_high); |
| 4586 | __ Slt(AT, TMP, lhs_high); |
| 4587 | __ Slt(TMP, lhs_high, TMP); |
| 4588 | if (dst != lhs_low) { |
| 4589 | __ LoadConst32(dst, imm_low); |
| 4590 | __ Sltu(dst, dst, lhs_low); |
| 4591 | } |
| 4592 | __ Slt(dst, TMP, dst); |
| 4593 | __ Or(dst, dst, AT); |
| 4594 | if (cond == kCondLE) { |
| 4595 | __ Xori(dst, dst, 1); |
| 4596 | } |
| 4597 | break; |
| 4598 | case kCondB: |
| 4599 | case kCondAE: |
| 4600 | if (dst == lhs_low) { |
| 4601 | __ LoadConst32(TMP, imm_low); |
| 4602 | __ Sltu(dst, lhs_low, TMP); |
| 4603 | } |
| 4604 | __ LoadConst32(TMP, imm_high); |
| 4605 | __ Sltu(AT, lhs_high, TMP); |
| 4606 | __ Sltu(TMP, TMP, lhs_high); |
| 4607 | if (dst != lhs_low) { |
| 4608 | __ LoadConst32(dst, imm_low); |
| 4609 | __ Sltu(dst, lhs_low, dst); |
| 4610 | } |
| 4611 | __ Slt(dst, TMP, dst); |
| 4612 | __ Or(dst, dst, AT); |
| 4613 | if (cond == kCondAE) { |
| 4614 | __ Xori(dst, dst, 1); |
| 4615 | } |
| 4616 | break; |
| 4617 | case kCondA: |
| 4618 | case kCondBE: |
| 4619 | if (dst == lhs_low) { |
| 4620 | __ LoadConst32(TMP, imm_low); |
| 4621 | __ Sltu(dst, TMP, lhs_low); |
| 4622 | } |
| 4623 | __ LoadConst32(TMP, imm_high); |
| 4624 | __ Sltu(AT, TMP, lhs_high); |
| 4625 | __ Sltu(TMP, lhs_high, TMP); |
| 4626 | if (dst != lhs_low) { |
| 4627 | __ LoadConst32(dst, imm_low); |
| 4628 | __ Sltu(dst, dst, lhs_low); |
| 4629 | } |
| 4630 | __ Slt(dst, TMP, dst); |
| 4631 | __ Or(dst, dst, AT); |
| 4632 | if (cond == kCondBE) { |
| 4633 | __ Xori(dst, dst, 1); |
| 4634 | } |
| 4635 | break; |
| 4636 | } |
| 4637 | } else { |
| 4638 | switch (cond) { |
| 4639 | case kCondEQ: |
| 4640 | __ Xor(TMP, lhs_high, rhs_high); |
| 4641 | __ Xor(AT, lhs_low, rhs_low); |
| 4642 | __ Or(dst, TMP, AT); |
| 4643 | __ Sltiu(dst, dst, 1); |
| 4644 | break; |
| 4645 | case kCondNE: |
| 4646 | __ Xor(TMP, lhs_high, rhs_high); |
| 4647 | __ Xor(AT, lhs_low, rhs_low); |
| 4648 | __ Or(dst, TMP, AT); |
| 4649 | __ Sltu(dst, ZERO, dst); |
| 4650 | break; |
| 4651 | case kCondLT: |
| 4652 | case kCondGE: |
| 4653 | __ Slt(TMP, rhs_high, lhs_high); |
| 4654 | __ Sltu(AT, lhs_low, rhs_low); |
| 4655 | __ Slt(TMP, TMP, AT); |
| 4656 | __ Slt(AT, lhs_high, rhs_high); |
| 4657 | __ Or(dst, AT, TMP); |
| 4658 | if (cond == kCondGE) { |
| 4659 | __ Xori(dst, dst, 1); |
| 4660 | } |
| 4661 | break; |
| 4662 | case kCondGT: |
| 4663 | case kCondLE: |
| 4664 | __ Slt(TMP, lhs_high, rhs_high); |
| 4665 | __ Sltu(AT, rhs_low, lhs_low); |
| 4666 | __ Slt(TMP, TMP, AT); |
| 4667 | __ Slt(AT, rhs_high, lhs_high); |
| 4668 | __ Or(dst, AT, TMP); |
| 4669 | if (cond == kCondLE) { |
| 4670 | __ Xori(dst, dst, 1); |
| 4671 | } |
| 4672 | break; |
| 4673 | case kCondB: |
| 4674 | case kCondAE: |
| 4675 | __ Sltu(TMP, rhs_high, lhs_high); |
| 4676 | __ Sltu(AT, lhs_low, rhs_low); |
| 4677 | __ Slt(TMP, TMP, AT); |
| 4678 | __ Sltu(AT, lhs_high, rhs_high); |
| 4679 | __ Or(dst, AT, TMP); |
| 4680 | if (cond == kCondAE) { |
| 4681 | __ Xori(dst, dst, 1); |
| 4682 | } |
| 4683 | break; |
| 4684 | case kCondA: |
| 4685 | case kCondBE: |
| 4686 | __ Sltu(TMP, lhs_high, rhs_high); |
| 4687 | __ Sltu(AT, rhs_low, lhs_low); |
| 4688 | __ Slt(TMP, TMP, AT); |
| 4689 | __ Sltu(AT, rhs_high, lhs_high); |
| 4690 | __ Or(dst, AT, TMP); |
| 4691 | if (cond == kCondBE) { |
| 4692 | __ Xori(dst, dst, 1); |
| 4693 | } |
| 4694 | break; |
| 4695 | } |
| 4696 | } |
| 4697 | } |
| 4698 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4699 | void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond, |
| 4700 | LocationSummary* locations, |
| 4701 | MipsLabel* label) { |
| 4702 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4703 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4704 | Location rhs_location = locations->InAt(1); |
| 4705 | Register rhs_high = ZERO; |
| 4706 | Register rhs_low = ZERO; |
| 4707 | int64_t imm = 0; |
| 4708 | uint32_t imm_high = 0; |
| 4709 | uint32_t imm_low = 0; |
| 4710 | bool use_imm = rhs_location.IsConstant(); |
| 4711 | if (use_imm) { |
| 4712 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 4713 | imm_high = High32Bits(imm); |
| 4714 | imm_low = Low32Bits(imm); |
| 4715 | } else { |
| 4716 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 4717 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 4718 | } |
| 4719 | |
| 4720 | if (use_imm && imm == 0) { |
| 4721 | switch (cond) { |
| 4722 | case kCondEQ: |
| 4723 | case kCondBE: // <= 0 if zero |
| 4724 | __ Or(TMP, lhs_high, lhs_low); |
| 4725 | __ Beqz(TMP, label); |
| 4726 | break; |
| 4727 | case kCondNE: |
| 4728 | case kCondA: // > 0 if non-zero |
| 4729 | __ Or(TMP, lhs_high, lhs_low); |
| 4730 | __ Bnez(TMP, label); |
| 4731 | break; |
| 4732 | case kCondLT: |
| 4733 | __ Bltz(lhs_high, label); |
| 4734 | break; |
| 4735 | case kCondGE: |
| 4736 | __ Bgez(lhs_high, label); |
| 4737 | break; |
| 4738 | case kCondLE: |
| 4739 | __ Or(TMP, lhs_high, lhs_low); |
| 4740 | __ Sra(AT, lhs_high, 31); |
| 4741 | __ Bgeu(AT, TMP, label); |
| 4742 | break; |
| 4743 | case kCondGT: |
| 4744 | __ Or(TMP, lhs_high, lhs_low); |
| 4745 | __ Sra(AT, lhs_high, 31); |
| 4746 | __ Bltu(AT, TMP, label); |
| 4747 | break; |
| 4748 | case kCondB: // always false |
| 4749 | break; |
| 4750 | case kCondAE: // always true |
| 4751 | __ B(label); |
| 4752 | break; |
| 4753 | } |
| 4754 | } else if (use_imm) { |
| 4755 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 4756 | switch (cond) { |
| 4757 | case kCondEQ: |
| 4758 | __ LoadConst32(TMP, imm_high); |
| 4759 | __ Xor(TMP, TMP, lhs_high); |
| 4760 | __ LoadConst32(AT, imm_low); |
| 4761 | __ Xor(AT, AT, lhs_low); |
| 4762 | __ Or(TMP, TMP, AT); |
| 4763 | __ Beqz(TMP, label); |
| 4764 | break; |
| 4765 | case kCondNE: |
| 4766 | __ LoadConst32(TMP, imm_high); |
| 4767 | __ Xor(TMP, TMP, lhs_high); |
| 4768 | __ LoadConst32(AT, imm_low); |
| 4769 | __ Xor(AT, AT, lhs_low); |
| 4770 | __ Or(TMP, TMP, AT); |
| 4771 | __ Bnez(TMP, label); |
| 4772 | break; |
| 4773 | case kCondLT: |
| 4774 | __ LoadConst32(TMP, imm_high); |
| 4775 | __ Blt(lhs_high, TMP, label); |
| 4776 | __ Slt(TMP, TMP, lhs_high); |
| 4777 | __ LoadConst32(AT, imm_low); |
| 4778 | __ Sltu(AT, lhs_low, AT); |
| 4779 | __ Blt(TMP, AT, label); |
| 4780 | break; |
| 4781 | case kCondGE: |
| 4782 | __ LoadConst32(TMP, imm_high); |
| 4783 | __ Blt(TMP, lhs_high, label); |
| 4784 | __ Slt(TMP, lhs_high, TMP); |
| 4785 | __ LoadConst32(AT, imm_low); |
| 4786 | __ Sltu(AT, lhs_low, AT); |
| 4787 | __ Or(TMP, TMP, AT); |
| 4788 | __ Beqz(TMP, label); |
| 4789 | break; |
| 4790 | case kCondLE: |
| 4791 | __ LoadConst32(TMP, imm_high); |
| 4792 | __ Blt(lhs_high, TMP, label); |
| 4793 | __ Slt(TMP, TMP, lhs_high); |
| 4794 | __ LoadConst32(AT, imm_low); |
| 4795 | __ Sltu(AT, AT, lhs_low); |
| 4796 | __ Or(TMP, TMP, AT); |
| 4797 | __ Beqz(TMP, label); |
| 4798 | break; |
| 4799 | case kCondGT: |
| 4800 | __ LoadConst32(TMP, imm_high); |
| 4801 | __ Blt(TMP, lhs_high, label); |
| 4802 | __ Slt(TMP, lhs_high, TMP); |
| 4803 | __ LoadConst32(AT, imm_low); |
| 4804 | __ Sltu(AT, AT, lhs_low); |
| 4805 | __ Blt(TMP, AT, label); |
| 4806 | break; |
| 4807 | case kCondB: |
| 4808 | __ LoadConst32(TMP, imm_high); |
| 4809 | __ Bltu(lhs_high, TMP, label); |
| 4810 | __ Sltu(TMP, TMP, lhs_high); |
| 4811 | __ LoadConst32(AT, imm_low); |
| 4812 | __ Sltu(AT, lhs_low, AT); |
| 4813 | __ Blt(TMP, AT, label); |
| 4814 | break; |
| 4815 | case kCondAE: |
| 4816 | __ LoadConst32(TMP, imm_high); |
| 4817 | __ Bltu(TMP, lhs_high, label); |
| 4818 | __ Sltu(TMP, lhs_high, TMP); |
| 4819 | __ LoadConst32(AT, imm_low); |
| 4820 | __ Sltu(AT, lhs_low, AT); |
| 4821 | __ Or(TMP, TMP, AT); |
| 4822 | __ Beqz(TMP, label); |
| 4823 | break; |
| 4824 | case kCondBE: |
| 4825 | __ LoadConst32(TMP, imm_high); |
| 4826 | __ Bltu(lhs_high, TMP, label); |
| 4827 | __ Sltu(TMP, TMP, lhs_high); |
| 4828 | __ LoadConst32(AT, imm_low); |
| 4829 | __ Sltu(AT, AT, lhs_low); |
| 4830 | __ Or(TMP, TMP, AT); |
| 4831 | __ Beqz(TMP, label); |
| 4832 | break; |
| 4833 | case kCondA: |
| 4834 | __ LoadConst32(TMP, imm_high); |
| 4835 | __ Bltu(TMP, lhs_high, label); |
| 4836 | __ Sltu(TMP, lhs_high, TMP); |
| 4837 | __ LoadConst32(AT, imm_low); |
| 4838 | __ Sltu(AT, AT, lhs_low); |
| 4839 | __ Blt(TMP, AT, label); |
| 4840 | break; |
| 4841 | } |
| 4842 | } else { |
| 4843 | switch (cond) { |
| 4844 | case kCondEQ: |
| 4845 | __ Xor(TMP, lhs_high, rhs_high); |
| 4846 | __ Xor(AT, lhs_low, rhs_low); |
| 4847 | __ Or(TMP, TMP, AT); |
| 4848 | __ Beqz(TMP, label); |
| 4849 | break; |
| 4850 | case kCondNE: |
| 4851 | __ Xor(TMP, lhs_high, rhs_high); |
| 4852 | __ Xor(AT, lhs_low, rhs_low); |
| 4853 | __ Or(TMP, TMP, AT); |
| 4854 | __ Bnez(TMP, label); |
| 4855 | break; |
| 4856 | case kCondLT: |
| 4857 | __ Blt(lhs_high, rhs_high, label); |
| 4858 | __ Slt(TMP, rhs_high, lhs_high); |
| 4859 | __ Sltu(AT, lhs_low, rhs_low); |
| 4860 | __ Blt(TMP, AT, label); |
| 4861 | break; |
| 4862 | case kCondGE: |
| 4863 | __ Blt(rhs_high, lhs_high, label); |
| 4864 | __ Slt(TMP, lhs_high, rhs_high); |
| 4865 | __ Sltu(AT, lhs_low, rhs_low); |
| 4866 | __ Or(TMP, TMP, AT); |
| 4867 | __ Beqz(TMP, label); |
| 4868 | break; |
| 4869 | case kCondLE: |
| 4870 | __ Blt(lhs_high, rhs_high, label); |
| 4871 | __ Slt(TMP, rhs_high, lhs_high); |
| 4872 | __ Sltu(AT, rhs_low, lhs_low); |
| 4873 | __ Or(TMP, TMP, AT); |
| 4874 | __ Beqz(TMP, label); |
| 4875 | break; |
| 4876 | case kCondGT: |
| 4877 | __ Blt(rhs_high, lhs_high, label); |
| 4878 | __ Slt(TMP, lhs_high, rhs_high); |
| 4879 | __ Sltu(AT, rhs_low, lhs_low); |
| 4880 | __ Blt(TMP, AT, label); |
| 4881 | break; |
| 4882 | case kCondB: |
| 4883 | __ Bltu(lhs_high, rhs_high, label); |
| 4884 | __ Sltu(TMP, rhs_high, lhs_high); |
| 4885 | __ Sltu(AT, lhs_low, rhs_low); |
| 4886 | __ Blt(TMP, AT, label); |
| 4887 | break; |
| 4888 | case kCondAE: |
| 4889 | __ Bltu(rhs_high, lhs_high, label); |
| 4890 | __ Sltu(TMP, lhs_high, rhs_high); |
| 4891 | __ Sltu(AT, lhs_low, rhs_low); |
| 4892 | __ Or(TMP, TMP, AT); |
| 4893 | __ Beqz(TMP, label); |
| 4894 | break; |
| 4895 | case kCondBE: |
| 4896 | __ Bltu(lhs_high, rhs_high, label); |
| 4897 | __ Sltu(TMP, rhs_high, lhs_high); |
| 4898 | __ Sltu(AT, rhs_low, lhs_low); |
| 4899 | __ Or(TMP, TMP, AT); |
| 4900 | __ Beqz(TMP, label); |
| 4901 | break; |
| 4902 | case kCondA: |
| 4903 | __ Bltu(rhs_high, lhs_high, label); |
| 4904 | __ Sltu(TMP, lhs_high, rhs_high); |
| 4905 | __ Sltu(AT, rhs_low, lhs_low); |
| 4906 | __ Blt(TMP, AT, label); |
| 4907 | break; |
| 4908 | } |
| 4909 | } |
| 4910 | } |
| 4911 | |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 4912 | void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond, |
| 4913 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4914 | DataType::Type type, |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 4915 | LocationSummary* locations) { |
| 4916 | Register dst = locations->Out().AsRegister<Register>(); |
| 4917 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4918 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 4919 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4920 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 4921 | if (isR6) { |
| 4922 | switch (cond) { |
| 4923 | case kCondEQ: |
| 4924 | __ CmpEqS(FTMP, lhs, rhs); |
| 4925 | __ Mfc1(dst, FTMP); |
| 4926 | __ Andi(dst, dst, 1); |
| 4927 | break; |
| 4928 | case kCondNE: |
| 4929 | __ CmpEqS(FTMP, lhs, rhs); |
| 4930 | __ Mfc1(dst, FTMP); |
| 4931 | __ Addiu(dst, dst, 1); |
| 4932 | break; |
| 4933 | case kCondLT: |
| 4934 | if (gt_bias) { |
| 4935 | __ CmpLtS(FTMP, lhs, rhs); |
| 4936 | } else { |
| 4937 | __ CmpUltS(FTMP, lhs, rhs); |
| 4938 | } |
| 4939 | __ Mfc1(dst, FTMP); |
| 4940 | __ Andi(dst, dst, 1); |
| 4941 | break; |
| 4942 | case kCondLE: |
| 4943 | if (gt_bias) { |
| 4944 | __ CmpLeS(FTMP, lhs, rhs); |
| 4945 | } else { |
| 4946 | __ CmpUleS(FTMP, lhs, rhs); |
| 4947 | } |
| 4948 | __ Mfc1(dst, FTMP); |
| 4949 | __ Andi(dst, dst, 1); |
| 4950 | break; |
| 4951 | case kCondGT: |
| 4952 | if (gt_bias) { |
| 4953 | __ CmpUltS(FTMP, rhs, lhs); |
| 4954 | } else { |
| 4955 | __ CmpLtS(FTMP, rhs, lhs); |
| 4956 | } |
| 4957 | __ Mfc1(dst, FTMP); |
| 4958 | __ Andi(dst, dst, 1); |
| 4959 | break; |
| 4960 | case kCondGE: |
| 4961 | if (gt_bias) { |
| 4962 | __ CmpUleS(FTMP, rhs, lhs); |
| 4963 | } else { |
| 4964 | __ CmpLeS(FTMP, rhs, lhs); |
| 4965 | } |
| 4966 | __ Mfc1(dst, FTMP); |
| 4967 | __ Andi(dst, dst, 1); |
| 4968 | break; |
| 4969 | default: |
| 4970 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4971 | UNREACHABLE(); |
| 4972 | } |
| 4973 | } else { |
| 4974 | switch (cond) { |
| 4975 | case kCondEQ: |
| 4976 | __ CeqS(0, lhs, rhs); |
| 4977 | __ LoadConst32(dst, 1); |
| 4978 | __ Movf(dst, ZERO, 0); |
| 4979 | break; |
| 4980 | case kCondNE: |
| 4981 | __ CeqS(0, lhs, rhs); |
| 4982 | __ LoadConst32(dst, 1); |
| 4983 | __ Movt(dst, ZERO, 0); |
| 4984 | break; |
| 4985 | case kCondLT: |
| 4986 | if (gt_bias) { |
| 4987 | __ ColtS(0, lhs, rhs); |
| 4988 | } else { |
| 4989 | __ CultS(0, lhs, rhs); |
| 4990 | } |
| 4991 | __ LoadConst32(dst, 1); |
| 4992 | __ Movf(dst, ZERO, 0); |
| 4993 | break; |
| 4994 | case kCondLE: |
| 4995 | if (gt_bias) { |
| 4996 | __ ColeS(0, lhs, rhs); |
| 4997 | } else { |
| 4998 | __ CuleS(0, lhs, rhs); |
| 4999 | } |
| 5000 | __ LoadConst32(dst, 1); |
| 5001 | __ Movf(dst, ZERO, 0); |
| 5002 | break; |
| 5003 | case kCondGT: |
| 5004 | if (gt_bias) { |
| 5005 | __ CultS(0, rhs, lhs); |
| 5006 | } else { |
| 5007 | __ ColtS(0, rhs, lhs); |
| 5008 | } |
| 5009 | __ LoadConst32(dst, 1); |
| 5010 | __ Movf(dst, ZERO, 0); |
| 5011 | break; |
| 5012 | case kCondGE: |
| 5013 | if (gt_bias) { |
| 5014 | __ CuleS(0, rhs, lhs); |
| 5015 | } else { |
| 5016 | __ ColeS(0, rhs, lhs); |
| 5017 | } |
| 5018 | __ LoadConst32(dst, 1); |
| 5019 | __ Movf(dst, ZERO, 0); |
| 5020 | break; |
| 5021 | default: |
| 5022 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5023 | UNREACHABLE(); |
| 5024 | } |
| 5025 | } |
| 5026 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5027 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5028 | if (isR6) { |
| 5029 | switch (cond) { |
| 5030 | case kCondEQ: |
| 5031 | __ CmpEqD(FTMP, lhs, rhs); |
| 5032 | __ Mfc1(dst, FTMP); |
| 5033 | __ Andi(dst, dst, 1); |
| 5034 | break; |
| 5035 | case kCondNE: |
| 5036 | __ CmpEqD(FTMP, lhs, rhs); |
| 5037 | __ Mfc1(dst, FTMP); |
| 5038 | __ Addiu(dst, dst, 1); |
| 5039 | break; |
| 5040 | case kCondLT: |
| 5041 | if (gt_bias) { |
| 5042 | __ CmpLtD(FTMP, lhs, rhs); |
| 5043 | } else { |
| 5044 | __ CmpUltD(FTMP, lhs, rhs); |
| 5045 | } |
| 5046 | __ Mfc1(dst, FTMP); |
| 5047 | __ Andi(dst, dst, 1); |
| 5048 | break; |
| 5049 | case kCondLE: |
| 5050 | if (gt_bias) { |
| 5051 | __ CmpLeD(FTMP, lhs, rhs); |
| 5052 | } else { |
| 5053 | __ CmpUleD(FTMP, lhs, rhs); |
| 5054 | } |
| 5055 | __ Mfc1(dst, FTMP); |
| 5056 | __ Andi(dst, dst, 1); |
| 5057 | break; |
| 5058 | case kCondGT: |
| 5059 | if (gt_bias) { |
| 5060 | __ CmpUltD(FTMP, rhs, lhs); |
| 5061 | } else { |
| 5062 | __ CmpLtD(FTMP, rhs, lhs); |
| 5063 | } |
| 5064 | __ Mfc1(dst, FTMP); |
| 5065 | __ Andi(dst, dst, 1); |
| 5066 | break; |
| 5067 | case kCondGE: |
| 5068 | if (gt_bias) { |
| 5069 | __ CmpUleD(FTMP, rhs, lhs); |
| 5070 | } else { |
| 5071 | __ CmpLeD(FTMP, rhs, lhs); |
| 5072 | } |
| 5073 | __ Mfc1(dst, FTMP); |
| 5074 | __ Andi(dst, dst, 1); |
| 5075 | break; |
| 5076 | default: |
| 5077 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5078 | UNREACHABLE(); |
| 5079 | } |
| 5080 | } else { |
| 5081 | switch (cond) { |
| 5082 | case kCondEQ: |
| 5083 | __ CeqD(0, lhs, rhs); |
| 5084 | __ LoadConst32(dst, 1); |
| 5085 | __ Movf(dst, ZERO, 0); |
| 5086 | break; |
| 5087 | case kCondNE: |
| 5088 | __ CeqD(0, lhs, rhs); |
| 5089 | __ LoadConst32(dst, 1); |
| 5090 | __ Movt(dst, ZERO, 0); |
| 5091 | break; |
| 5092 | case kCondLT: |
| 5093 | if (gt_bias) { |
| 5094 | __ ColtD(0, lhs, rhs); |
| 5095 | } else { |
| 5096 | __ CultD(0, lhs, rhs); |
| 5097 | } |
| 5098 | __ LoadConst32(dst, 1); |
| 5099 | __ Movf(dst, ZERO, 0); |
| 5100 | break; |
| 5101 | case kCondLE: |
| 5102 | if (gt_bias) { |
| 5103 | __ ColeD(0, lhs, rhs); |
| 5104 | } else { |
| 5105 | __ CuleD(0, lhs, rhs); |
| 5106 | } |
| 5107 | __ LoadConst32(dst, 1); |
| 5108 | __ Movf(dst, ZERO, 0); |
| 5109 | break; |
| 5110 | case kCondGT: |
| 5111 | if (gt_bias) { |
| 5112 | __ CultD(0, rhs, lhs); |
| 5113 | } else { |
| 5114 | __ ColtD(0, rhs, lhs); |
| 5115 | } |
| 5116 | __ LoadConst32(dst, 1); |
| 5117 | __ Movf(dst, ZERO, 0); |
| 5118 | break; |
| 5119 | case kCondGE: |
| 5120 | if (gt_bias) { |
| 5121 | __ CuleD(0, rhs, lhs); |
| 5122 | } else { |
| 5123 | __ ColeD(0, rhs, lhs); |
| 5124 | } |
| 5125 | __ LoadConst32(dst, 1); |
| 5126 | __ Movf(dst, ZERO, 0); |
| 5127 | break; |
| 5128 | default: |
| 5129 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5130 | UNREACHABLE(); |
| 5131 | } |
| 5132 | } |
| 5133 | } |
| 5134 | } |
| 5135 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5136 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond, |
| 5137 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5138 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5139 | LocationSummary* input_locations, |
| 5140 | int cc) { |
| 5141 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5142 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5143 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5144 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5145 | switch (cond) { |
| 5146 | case kCondEQ: |
| 5147 | __ CeqS(cc, lhs, rhs); |
| 5148 | return false; |
| 5149 | case kCondNE: |
| 5150 | __ CeqS(cc, lhs, rhs); |
| 5151 | return true; |
| 5152 | case kCondLT: |
| 5153 | if (gt_bias) { |
| 5154 | __ ColtS(cc, lhs, rhs); |
| 5155 | } else { |
| 5156 | __ CultS(cc, lhs, rhs); |
| 5157 | } |
| 5158 | return false; |
| 5159 | case kCondLE: |
| 5160 | if (gt_bias) { |
| 5161 | __ ColeS(cc, lhs, rhs); |
| 5162 | } else { |
| 5163 | __ CuleS(cc, lhs, rhs); |
| 5164 | } |
| 5165 | return false; |
| 5166 | case kCondGT: |
| 5167 | if (gt_bias) { |
| 5168 | __ CultS(cc, rhs, lhs); |
| 5169 | } else { |
| 5170 | __ ColtS(cc, rhs, lhs); |
| 5171 | } |
| 5172 | return false; |
| 5173 | case kCondGE: |
| 5174 | if (gt_bias) { |
| 5175 | __ CuleS(cc, rhs, lhs); |
| 5176 | } else { |
| 5177 | __ ColeS(cc, rhs, lhs); |
| 5178 | } |
| 5179 | return false; |
| 5180 | default: |
| 5181 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5182 | UNREACHABLE(); |
| 5183 | } |
| 5184 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5185 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5186 | switch (cond) { |
| 5187 | case kCondEQ: |
| 5188 | __ CeqD(cc, lhs, rhs); |
| 5189 | return false; |
| 5190 | case kCondNE: |
| 5191 | __ CeqD(cc, lhs, rhs); |
| 5192 | return true; |
| 5193 | case kCondLT: |
| 5194 | if (gt_bias) { |
| 5195 | __ ColtD(cc, lhs, rhs); |
| 5196 | } else { |
| 5197 | __ CultD(cc, lhs, rhs); |
| 5198 | } |
| 5199 | return false; |
| 5200 | case kCondLE: |
| 5201 | if (gt_bias) { |
| 5202 | __ ColeD(cc, lhs, rhs); |
| 5203 | } else { |
| 5204 | __ CuleD(cc, lhs, rhs); |
| 5205 | } |
| 5206 | return false; |
| 5207 | case kCondGT: |
| 5208 | if (gt_bias) { |
| 5209 | __ CultD(cc, rhs, lhs); |
| 5210 | } else { |
| 5211 | __ ColtD(cc, rhs, lhs); |
| 5212 | } |
| 5213 | return false; |
| 5214 | case kCondGE: |
| 5215 | if (gt_bias) { |
| 5216 | __ CuleD(cc, rhs, lhs); |
| 5217 | } else { |
| 5218 | __ ColeD(cc, rhs, lhs); |
| 5219 | } |
| 5220 | return false; |
| 5221 | default: |
| 5222 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5223 | UNREACHABLE(); |
| 5224 | } |
| 5225 | } |
| 5226 | } |
| 5227 | |
| 5228 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond, |
| 5229 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5230 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5231 | LocationSummary* input_locations, |
| 5232 | FRegister dst) { |
| 5233 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5234 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5235 | CHECK(codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5236 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5237 | switch (cond) { |
| 5238 | case kCondEQ: |
| 5239 | __ CmpEqS(dst, lhs, rhs); |
| 5240 | return false; |
| 5241 | case kCondNE: |
| 5242 | __ CmpEqS(dst, lhs, rhs); |
| 5243 | return true; |
| 5244 | case kCondLT: |
| 5245 | if (gt_bias) { |
| 5246 | __ CmpLtS(dst, lhs, rhs); |
| 5247 | } else { |
| 5248 | __ CmpUltS(dst, lhs, rhs); |
| 5249 | } |
| 5250 | return false; |
| 5251 | case kCondLE: |
| 5252 | if (gt_bias) { |
| 5253 | __ CmpLeS(dst, lhs, rhs); |
| 5254 | } else { |
| 5255 | __ CmpUleS(dst, lhs, rhs); |
| 5256 | } |
| 5257 | return false; |
| 5258 | case kCondGT: |
| 5259 | if (gt_bias) { |
| 5260 | __ CmpUltS(dst, rhs, lhs); |
| 5261 | } else { |
| 5262 | __ CmpLtS(dst, rhs, lhs); |
| 5263 | } |
| 5264 | return false; |
| 5265 | case kCondGE: |
| 5266 | if (gt_bias) { |
| 5267 | __ CmpUleS(dst, rhs, lhs); |
| 5268 | } else { |
| 5269 | __ CmpLeS(dst, rhs, lhs); |
| 5270 | } |
| 5271 | return false; |
| 5272 | default: |
| 5273 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5274 | UNREACHABLE(); |
| 5275 | } |
| 5276 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5277 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5278 | switch (cond) { |
| 5279 | case kCondEQ: |
| 5280 | __ CmpEqD(dst, lhs, rhs); |
| 5281 | return false; |
| 5282 | case kCondNE: |
| 5283 | __ CmpEqD(dst, lhs, rhs); |
| 5284 | return true; |
| 5285 | case kCondLT: |
| 5286 | if (gt_bias) { |
| 5287 | __ CmpLtD(dst, lhs, rhs); |
| 5288 | } else { |
| 5289 | __ CmpUltD(dst, lhs, rhs); |
| 5290 | } |
| 5291 | return false; |
| 5292 | case kCondLE: |
| 5293 | if (gt_bias) { |
| 5294 | __ CmpLeD(dst, lhs, rhs); |
| 5295 | } else { |
| 5296 | __ CmpUleD(dst, lhs, rhs); |
| 5297 | } |
| 5298 | return false; |
| 5299 | case kCondGT: |
| 5300 | if (gt_bias) { |
| 5301 | __ CmpUltD(dst, rhs, lhs); |
| 5302 | } else { |
| 5303 | __ CmpLtD(dst, rhs, lhs); |
| 5304 | } |
| 5305 | return false; |
| 5306 | case kCondGE: |
| 5307 | if (gt_bias) { |
| 5308 | __ CmpUleD(dst, rhs, lhs); |
| 5309 | } else { |
| 5310 | __ CmpLeD(dst, rhs, lhs); |
| 5311 | } |
| 5312 | return false; |
| 5313 | default: |
| 5314 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5315 | UNREACHABLE(); |
| 5316 | } |
| 5317 | } |
| 5318 | } |
| 5319 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5320 | void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond, |
| 5321 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5322 | DataType::Type type, |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5323 | LocationSummary* locations, |
| 5324 | MipsLabel* label) { |
| 5325 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5326 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5327 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5328 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5329 | if (isR6) { |
| 5330 | switch (cond) { |
| 5331 | case kCondEQ: |
| 5332 | __ CmpEqS(FTMP, lhs, rhs); |
| 5333 | __ Bc1nez(FTMP, label); |
| 5334 | break; |
| 5335 | case kCondNE: |
| 5336 | __ CmpEqS(FTMP, lhs, rhs); |
| 5337 | __ Bc1eqz(FTMP, label); |
| 5338 | break; |
| 5339 | case kCondLT: |
| 5340 | if (gt_bias) { |
| 5341 | __ CmpLtS(FTMP, lhs, rhs); |
| 5342 | } else { |
| 5343 | __ CmpUltS(FTMP, lhs, rhs); |
| 5344 | } |
| 5345 | __ Bc1nez(FTMP, label); |
| 5346 | break; |
| 5347 | case kCondLE: |
| 5348 | if (gt_bias) { |
| 5349 | __ CmpLeS(FTMP, lhs, rhs); |
| 5350 | } else { |
| 5351 | __ CmpUleS(FTMP, lhs, rhs); |
| 5352 | } |
| 5353 | __ Bc1nez(FTMP, label); |
| 5354 | break; |
| 5355 | case kCondGT: |
| 5356 | if (gt_bias) { |
| 5357 | __ CmpUltS(FTMP, rhs, lhs); |
| 5358 | } else { |
| 5359 | __ CmpLtS(FTMP, rhs, lhs); |
| 5360 | } |
| 5361 | __ Bc1nez(FTMP, label); |
| 5362 | break; |
| 5363 | case kCondGE: |
| 5364 | if (gt_bias) { |
| 5365 | __ CmpUleS(FTMP, rhs, lhs); |
| 5366 | } else { |
| 5367 | __ CmpLeS(FTMP, rhs, lhs); |
| 5368 | } |
| 5369 | __ Bc1nez(FTMP, label); |
| 5370 | break; |
| 5371 | default: |
| 5372 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5373 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5374 | } |
| 5375 | } else { |
| 5376 | switch (cond) { |
| 5377 | case kCondEQ: |
| 5378 | __ CeqS(0, lhs, rhs); |
| 5379 | __ Bc1t(0, label); |
| 5380 | break; |
| 5381 | case kCondNE: |
| 5382 | __ CeqS(0, lhs, rhs); |
| 5383 | __ Bc1f(0, label); |
| 5384 | break; |
| 5385 | case kCondLT: |
| 5386 | if (gt_bias) { |
| 5387 | __ ColtS(0, lhs, rhs); |
| 5388 | } else { |
| 5389 | __ CultS(0, lhs, rhs); |
| 5390 | } |
| 5391 | __ Bc1t(0, label); |
| 5392 | break; |
| 5393 | case kCondLE: |
| 5394 | if (gt_bias) { |
| 5395 | __ ColeS(0, lhs, rhs); |
| 5396 | } else { |
| 5397 | __ CuleS(0, lhs, rhs); |
| 5398 | } |
| 5399 | __ Bc1t(0, label); |
| 5400 | break; |
| 5401 | case kCondGT: |
| 5402 | if (gt_bias) { |
| 5403 | __ CultS(0, rhs, lhs); |
| 5404 | } else { |
| 5405 | __ ColtS(0, rhs, lhs); |
| 5406 | } |
| 5407 | __ Bc1t(0, label); |
| 5408 | break; |
| 5409 | case kCondGE: |
| 5410 | if (gt_bias) { |
| 5411 | __ CuleS(0, rhs, lhs); |
| 5412 | } else { |
| 5413 | __ ColeS(0, rhs, lhs); |
| 5414 | } |
| 5415 | __ Bc1t(0, label); |
| 5416 | break; |
| 5417 | default: |
| 5418 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5419 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5420 | } |
| 5421 | } |
| 5422 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5423 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5424 | if (isR6) { |
| 5425 | switch (cond) { |
| 5426 | case kCondEQ: |
| 5427 | __ CmpEqD(FTMP, lhs, rhs); |
| 5428 | __ Bc1nez(FTMP, label); |
| 5429 | break; |
| 5430 | case kCondNE: |
| 5431 | __ CmpEqD(FTMP, lhs, rhs); |
| 5432 | __ Bc1eqz(FTMP, label); |
| 5433 | break; |
| 5434 | case kCondLT: |
| 5435 | if (gt_bias) { |
| 5436 | __ CmpLtD(FTMP, lhs, rhs); |
| 5437 | } else { |
| 5438 | __ CmpUltD(FTMP, lhs, rhs); |
| 5439 | } |
| 5440 | __ Bc1nez(FTMP, label); |
| 5441 | break; |
| 5442 | case kCondLE: |
| 5443 | if (gt_bias) { |
| 5444 | __ CmpLeD(FTMP, lhs, rhs); |
| 5445 | } else { |
| 5446 | __ CmpUleD(FTMP, lhs, rhs); |
| 5447 | } |
| 5448 | __ Bc1nez(FTMP, label); |
| 5449 | break; |
| 5450 | case kCondGT: |
| 5451 | if (gt_bias) { |
| 5452 | __ CmpUltD(FTMP, rhs, lhs); |
| 5453 | } else { |
| 5454 | __ CmpLtD(FTMP, rhs, lhs); |
| 5455 | } |
| 5456 | __ Bc1nez(FTMP, label); |
| 5457 | break; |
| 5458 | case kCondGE: |
| 5459 | if (gt_bias) { |
| 5460 | __ CmpUleD(FTMP, rhs, lhs); |
| 5461 | } else { |
| 5462 | __ CmpLeD(FTMP, rhs, lhs); |
| 5463 | } |
| 5464 | __ Bc1nez(FTMP, label); |
| 5465 | break; |
| 5466 | default: |
| 5467 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5468 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5469 | } |
| 5470 | } else { |
| 5471 | switch (cond) { |
| 5472 | case kCondEQ: |
| 5473 | __ CeqD(0, lhs, rhs); |
| 5474 | __ Bc1t(0, label); |
| 5475 | break; |
| 5476 | case kCondNE: |
| 5477 | __ CeqD(0, lhs, rhs); |
| 5478 | __ Bc1f(0, label); |
| 5479 | break; |
| 5480 | case kCondLT: |
| 5481 | if (gt_bias) { |
| 5482 | __ ColtD(0, lhs, rhs); |
| 5483 | } else { |
| 5484 | __ CultD(0, lhs, rhs); |
| 5485 | } |
| 5486 | __ Bc1t(0, label); |
| 5487 | break; |
| 5488 | case kCondLE: |
| 5489 | if (gt_bias) { |
| 5490 | __ ColeD(0, lhs, rhs); |
| 5491 | } else { |
| 5492 | __ CuleD(0, lhs, rhs); |
| 5493 | } |
| 5494 | __ Bc1t(0, label); |
| 5495 | break; |
| 5496 | case kCondGT: |
| 5497 | if (gt_bias) { |
| 5498 | __ CultD(0, rhs, lhs); |
| 5499 | } else { |
| 5500 | __ ColtD(0, rhs, lhs); |
| 5501 | } |
| 5502 | __ Bc1t(0, label); |
| 5503 | break; |
| 5504 | case kCondGE: |
| 5505 | if (gt_bias) { |
| 5506 | __ CuleD(0, rhs, lhs); |
| 5507 | } else { |
| 5508 | __ ColeD(0, rhs, lhs); |
| 5509 | } |
| 5510 | __ Bc1t(0, label); |
| 5511 | break; |
| 5512 | default: |
| 5513 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5514 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5515 | } |
| 5516 | } |
| 5517 | } |
| 5518 | } |
| 5519 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5520 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5521 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5522 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5523 | MipsLabel* false_target) { |
| 5524 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5525 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5526 | if (true_target == nullptr && false_target == nullptr) { |
| 5527 | // Nothing to do. The code always falls through. |
| 5528 | return; |
| 5529 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5530 | // Constant condition, statically compared against "true" (integer value 1). |
| 5531 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5532 | if (true_target != nullptr) { |
| 5533 | __ B(true_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5534 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5535 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5536 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5537 | if (false_target != nullptr) { |
| 5538 | __ B(false_target); |
| 5539 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5540 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5541 | return; |
| 5542 | } |
| 5543 | |
| 5544 | // The following code generates these patterns: |
| 5545 | // (1) true_target == nullptr && false_target != nullptr |
| 5546 | // - opposite condition true => branch to false_target |
| 5547 | // (2) true_target != nullptr && false_target == nullptr |
| 5548 | // - condition true => branch to true_target |
| 5549 | // (3) true_target != nullptr && false_target != nullptr |
| 5550 | // - condition true => branch to true_target |
| 5551 | // - branch to false_target |
| 5552 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5553 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5554 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5555 | DCHECK(cond_val.IsRegister()); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5556 | if (true_target == nullptr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5557 | __ Beqz(cond_val.AsRegister<Register>(), false_target); |
| 5558 | } else { |
| 5559 | __ Bnez(cond_val.AsRegister<Register>(), true_target); |
| 5560 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5561 | } else { |
| 5562 | // The condition instruction has not been materialized, use its inputs as |
| 5563 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5564 | HCondition* condition = cond->AsCondition(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5565 | DataType::Type type = condition->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5566 | LocationSummary* locations = cond->GetLocations(); |
| 5567 | IfCondition if_cond = condition->GetCondition(); |
| 5568 | MipsLabel* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5569 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5570 | if (true_target == nullptr) { |
| 5571 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5572 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5573 | } |
| 5574 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5575 | switch (type) { |
| 5576 | default: |
| 5577 | GenerateIntCompareAndBranch(if_cond, locations, branch_target); |
| 5578 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5579 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5580 | GenerateLongCompareAndBranch(if_cond, locations, branch_target); |
| 5581 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5582 | case DataType::Type::kFloat32: |
| 5583 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5584 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 5585 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5586 | } |
| 5587 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5588 | |
| 5589 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 5590 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 5591 | if (true_target != nullptr && false_target != nullptr) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5592 | __ B(false_target); |
| 5593 | } |
| 5594 | } |
| 5595 | |
| 5596 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5597 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5598 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5599 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5600 | } |
| 5601 | } |
| 5602 | |
| 5603 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5604 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 5605 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 5606 | MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 5607 | nullptr : codegen_->GetLabelOf(true_successor); |
| 5608 | MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 5609 | nullptr : codegen_->GetLabelOf(false_successor); |
| 5610 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5611 | } |
| 5612 | |
| 5613 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5614 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5615 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 5616 | InvokeRuntimeCallingConvention calling_convention; |
| 5617 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5618 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5619 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5620 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5621 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5622 | } |
| 5623 | } |
| 5624 | |
| 5625 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 5626 | SlowPathCodeMIPS* slow_path = |
| 5627 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5628 | GenerateTestAndBranch(deoptimize, |
| 5629 | /* condition_input_index */ 0, |
| 5630 | slow_path->GetEntryLabel(), |
| 5631 | /* false_target */ nullptr); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5632 | } |
| 5633 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5634 | // This function returns true if a conditional move can be generated for HSelect. |
| 5635 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 5636 | // branches and regular moves. |
| 5637 | // |
| 5638 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 5639 | // |
| 5640 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 5641 | // are two distinct tasks, this function does both because they share quite a bit |
| 5642 | // of common logic. |
| 5643 | static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) { |
| 5644 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 5645 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 5646 | HCondition* condition = cond->AsCondition(); |
| 5647 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5648 | DataType::Type cond_type = |
| 5649 | materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType(); |
| 5650 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5651 | |
| 5652 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 5653 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 5654 | bool is_true_value_zero_constant = |
| 5655 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 5656 | bool is_false_value_zero_constant = |
| 5657 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 5658 | |
| 5659 | bool can_move_conditionally = false; |
| 5660 | bool use_const_for_false_in = false; |
| 5661 | bool use_const_for_true_in = false; |
| 5662 | |
| 5663 | if (!cond->IsConstant()) { |
| 5664 | switch (cond_type) { |
| 5665 | default: |
| 5666 | switch (dst_type) { |
| 5667 | default: |
| 5668 | // Moving int on int condition. |
| 5669 | if (is_r6) { |
| 5670 | if (is_true_value_zero_constant) { |
| 5671 | // seleqz out_reg, false_reg, cond_reg |
| 5672 | can_move_conditionally = true; |
| 5673 | use_const_for_true_in = true; |
| 5674 | } else if (is_false_value_zero_constant) { |
| 5675 | // selnez out_reg, true_reg, cond_reg |
| 5676 | can_move_conditionally = true; |
| 5677 | use_const_for_false_in = true; |
| 5678 | } else if (materialized) { |
| 5679 | // Not materializing unmaterialized int conditions |
| 5680 | // to keep the instruction count low. |
| 5681 | // selnez AT, true_reg, cond_reg |
| 5682 | // seleqz TMP, false_reg, cond_reg |
| 5683 | // or out_reg, AT, TMP |
| 5684 | can_move_conditionally = true; |
| 5685 | } |
| 5686 | } else { |
| 5687 | // movn out_reg, true_reg/ZERO, cond_reg |
| 5688 | can_move_conditionally = true; |
| 5689 | use_const_for_true_in = is_true_value_zero_constant; |
| 5690 | } |
| 5691 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5692 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5693 | // Moving long on int condition. |
| 5694 | if (is_r6) { |
| 5695 | if (is_true_value_zero_constant) { |
| 5696 | // seleqz out_reg_lo, false_reg_lo, cond_reg |
| 5697 | // seleqz out_reg_hi, false_reg_hi, cond_reg |
| 5698 | can_move_conditionally = true; |
| 5699 | use_const_for_true_in = true; |
| 5700 | } else if (is_false_value_zero_constant) { |
| 5701 | // selnez out_reg_lo, true_reg_lo, cond_reg |
| 5702 | // selnez out_reg_hi, true_reg_hi, cond_reg |
| 5703 | can_move_conditionally = true; |
| 5704 | use_const_for_false_in = true; |
| 5705 | } |
| 5706 | // Other long conditional moves would generate 6+ instructions, |
| 5707 | // which is too many. |
| 5708 | } else { |
| 5709 | // movn out_reg_lo, true_reg_lo/ZERO, cond_reg |
| 5710 | // movn out_reg_hi, true_reg_hi/ZERO, cond_reg |
| 5711 | can_move_conditionally = true; |
| 5712 | use_const_for_true_in = is_true_value_zero_constant; |
| 5713 | } |
| 5714 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5715 | case DataType::Type::kFloat32: |
| 5716 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5717 | // Moving float/double on int condition. |
| 5718 | if (is_r6) { |
| 5719 | if (materialized) { |
| 5720 | // Not materializing unmaterialized int conditions |
| 5721 | // to keep the instruction count low. |
| 5722 | can_move_conditionally = true; |
| 5723 | if (is_true_value_zero_constant) { |
| 5724 | // sltu TMP, ZERO, cond_reg |
| 5725 | // mtc1 TMP, temp_cond_reg |
| 5726 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 5727 | use_const_for_true_in = true; |
| 5728 | } else if (is_false_value_zero_constant) { |
| 5729 | // sltu TMP, ZERO, cond_reg |
| 5730 | // mtc1 TMP, temp_cond_reg |
| 5731 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 5732 | use_const_for_false_in = true; |
| 5733 | } else { |
| 5734 | // sltu TMP, ZERO, cond_reg |
| 5735 | // mtc1 TMP, temp_cond_reg |
| 5736 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 5737 | // mov.fmt out_reg, temp_cond_reg |
| 5738 | } |
| 5739 | } |
| 5740 | } else { |
| 5741 | // movn.fmt out_reg, true_reg, cond_reg |
| 5742 | can_move_conditionally = true; |
| 5743 | } |
| 5744 | break; |
| 5745 | } |
| 5746 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5747 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5748 | // We don't materialize long comparison now |
| 5749 | // and use conditional branches instead. |
| 5750 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5751 | case DataType::Type::kFloat32: |
| 5752 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5753 | switch (dst_type) { |
| 5754 | default: |
| 5755 | // Moving int on float/double condition. |
| 5756 | if (is_r6) { |
| 5757 | if (is_true_value_zero_constant) { |
| 5758 | // mfc1 TMP, temp_cond_reg |
| 5759 | // seleqz out_reg, false_reg, TMP |
| 5760 | can_move_conditionally = true; |
| 5761 | use_const_for_true_in = true; |
| 5762 | } else if (is_false_value_zero_constant) { |
| 5763 | // mfc1 TMP, temp_cond_reg |
| 5764 | // selnez out_reg, true_reg, TMP |
| 5765 | can_move_conditionally = true; |
| 5766 | use_const_for_false_in = true; |
| 5767 | } else { |
| 5768 | // mfc1 TMP, temp_cond_reg |
| 5769 | // selnez AT, true_reg, TMP |
| 5770 | // seleqz TMP, false_reg, TMP |
| 5771 | // or out_reg, AT, TMP |
| 5772 | can_move_conditionally = true; |
| 5773 | } |
| 5774 | } else { |
| 5775 | // movt out_reg, true_reg/ZERO, cc |
| 5776 | can_move_conditionally = true; |
| 5777 | use_const_for_true_in = is_true_value_zero_constant; |
| 5778 | } |
| 5779 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5780 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5781 | // Moving long on float/double condition. |
| 5782 | if (is_r6) { |
| 5783 | if (is_true_value_zero_constant) { |
| 5784 | // mfc1 TMP, temp_cond_reg |
| 5785 | // seleqz out_reg_lo, false_reg_lo, TMP |
| 5786 | // seleqz out_reg_hi, false_reg_hi, TMP |
| 5787 | can_move_conditionally = true; |
| 5788 | use_const_for_true_in = true; |
| 5789 | } else if (is_false_value_zero_constant) { |
| 5790 | // mfc1 TMP, temp_cond_reg |
| 5791 | // selnez out_reg_lo, true_reg_lo, TMP |
| 5792 | // selnez out_reg_hi, true_reg_hi, TMP |
| 5793 | can_move_conditionally = true; |
| 5794 | use_const_for_false_in = true; |
| 5795 | } |
| 5796 | // Other long conditional moves would generate 6+ instructions, |
| 5797 | // which is too many. |
| 5798 | } else { |
| 5799 | // movt out_reg_lo, true_reg_lo/ZERO, cc |
| 5800 | // movt out_reg_hi, true_reg_hi/ZERO, cc |
| 5801 | can_move_conditionally = true; |
| 5802 | use_const_for_true_in = is_true_value_zero_constant; |
| 5803 | } |
| 5804 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5805 | case DataType::Type::kFloat32: |
| 5806 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5807 | // Moving float/double on float/double condition. |
| 5808 | if (is_r6) { |
| 5809 | can_move_conditionally = true; |
| 5810 | if (is_true_value_zero_constant) { |
| 5811 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 5812 | use_const_for_true_in = true; |
| 5813 | } else if (is_false_value_zero_constant) { |
| 5814 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 5815 | use_const_for_false_in = true; |
| 5816 | } else { |
| 5817 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 5818 | // mov.fmt out_reg, temp_cond_reg |
| 5819 | } |
| 5820 | } else { |
| 5821 | // movt.fmt out_reg, true_reg, cc |
| 5822 | can_move_conditionally = true; |
| 5823 | } |
| 5824 | break; |
| 5825 | } |
| 5826 | break; |
| 5827 | } |
| 5828 | } |
| 5829 | |
| 5830 | if (can_move_conditionally) { |
| 5831 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 5832 | } else { |
| 5833 | DCHECK(!use_const_for_false_in); |
| 5834 | DCHECK(!use_const_for_true_in); |
| 5835 | } |
| 5836 | |
| 5837 | if (locations_to_set != nullptr) { |
| 5838 | if (use_const_for_false_in) { |
| 5839 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 5840 | } else { |
| 5841 | locations_to_set->SetInAt(0, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5842 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5843 | ? Location::RequiresFpuRegister() |
| 5844 | : Location::RequiresRegister()); |
| 5845 | } |
| 5846 | if (use_const_for_true_in) { |
| 5847 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 5848 | } else { |
| 5849 | locations_to_set->SetInAt(1, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5850 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5851 | ? Location::RequiresFpuRegister() |
| 5852 | : Location::RequiresRegister()); |
| 5853 | } |
| 5854 | if (materialized) { |
| 5855 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 5856 | } |
| 5857 | // On R6 we don't require the output to be the same as the |
| 5858 | // first input for conditional moves unlike on R2. |
| 5859 | bool is_out_same_as_first_in = !can_move_conditionally || !is_r6; |
| 5860 | if (is_out_same_as_first_in) { |
| 5861 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 5862 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5863 | locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5864 | ? Location::RequiresFpuRegister() |
| 5865 | : Location::RequiresRegister()); |
| 5866 | } |
| 5867 | } |
| 5868 | |
| 5869 | return can_move_conditionally; |
| 5870 | } |
| 5871 | |
| 5872 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) { |
| 5873 | LocationSummary* locations = select->GetLocations(); |
| 5874 | Location dst = locations->Out(); |
| 5875 | Location src = locations->InAt(1); |
| 5876 | Register src_reg = ZERO; |
| 5877 | Register src_reg_high = ZERO; |
| 5878 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 5879 | Register cond_reg = TMP; |
| 5880 | int cond_cc = 0; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5881 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5882 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5883 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5884 | |
| 5885 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 5886 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 5887 | } else { |
| 5888 | HCondition* condition = cond->AsCondition(); |
| 5889 | LocationSummary* cond_locations = cond->GetLocations(); |
| 5890 | IfCondition if_cond = condition->GetCondition(); |
| 5891 | cond_type = condition->InputAt(0)->GetType(); |
| 5892 | switch (cond_type) { |
| 5893 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5894 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5895 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 5896 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5897 | case DataType::Type::kFloat32: |
| 5898 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5899 | cond_inverted = MaterializeFpCompareR2(if_cond, |
| 5900 | condition->IsGtBias(), |
| 5901 | cond_type, |
| 5902 | cond_locations, |
| 5903 | cond_cc); |
| 5904 | break; |
| 5905 | } |
| 5906 | } |
| 5907 | |
| 5908 | DCHECK(dst.Equals(locations->InAt(0))); |
| 5909 | if (src.IsRegister()) { |
| 5910 | src_reg = src.AsRegister<Register>(); |
| 5911 | } else if (src.IsRegisterPair()) { |
| 5912 | src_reg = src.AsRegisterPairLow<Register>(); |
| 5913 | src_reg_high = src.AsRegisterPairHigh<Register>(); |
| 5914 | } else if (src.IsConstant()) { |
| 5915 | DCHECK(src.GetConstant()->IsZeroBitPattern()); |
| 5916 | } |
| 5917 | |
| 5918 | switch (cond_type) { |
| 5919 | default: |
| 5920 | switch (dst_type) { |
| 5921 | default: |
| 5922 | if (cond_inverted) { |
| 5923 | __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 5924 | } else { |
| 5925 | __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 5926 | } |
| 5927 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5928 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5929 | if (cond_inverted) { |
| 5930 | __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 5931 | __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 5932 | } else { |
| 5933 | __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 5934 | __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 5935 | } |
| 5936 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5937 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5938 | if (cond_inverted) { |
| 5939 | __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5940 | } else { |
| 5941 | __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5942 | } |
| 5943 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5944 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5945 | if (cond_inverted) { |
| 5946 | __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5947 | } else { |
| 5948 | __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5949 | } |
| 5950 | break; |
| 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 | LOG(FATAL) << "Unreachable"; |
| 5955 | UNREACHABLE(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5956 | case DataType::Type::kFloat32: |
| 5957 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5958 | switch (dst_type) { |
| 5959 | default: |
| 5960 | if (cond_inverted) { |
| 5961 | __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 5962 | } else { |
| 5963 | __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 5964 | } |
| 5965 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5966 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5967 | if (cond_inverted) { |
| 5968 | __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 5969 | __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 5970 | } else { |
| 5971 | __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 5972 | __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 5973 | } |
| 5974 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5975 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5976 | if (cond_inverted) { |
| 5977 | __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5978 | } else { |
| 5979 | __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5980 | } |
| 5981 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5982 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5983 | if (cond_inverted) { |
| 5984 | __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5985 | } else { |
| 5986 | __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5987 | } |
| 5988 | break; |
| 5989 | } |
| 5990 | break; |
| 5991 | } |
| 5992 | } |
| 5993 | |
| 5994 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) { |
| 5995 | LocationSummary* locations = select->GetLocations(); |
| 5996 | Location dst = locations->Out(); |
| 5997 | Location false_src = locations->InAt(0); |
| 5998 | Location true_src = locations->InAt(1); |
| 5999 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 6000 | Register cond_reg = TMP; |
| 6001 | FRegister fcond_reg = FTMP; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6002 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6003 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6004 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6005 | |
| 6006 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 6007 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 6008 | } else { |
| 6009 | HCondition* condition = cond->AsCondition(); |
| 6010 | LocationSummary* cond_locations = cond->GetLocations(); |
| 6011 | IfCondition if_cond = condition->GetCondition(); |
| 6012 | cond_type = condition->InputAt(0)->GetType(); |
| 6013 | switch (cond_type) { |
| 6014 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6015 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6016 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 6017 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6018 | case DataType::Type::kFloat32: |
| 6019 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6020 | cond_inverted = MaterializeFpCompareR6(if_cond, |
| 6021 | condition->IsGtBias(), |
| 6022 | cond_type, |
| 6023 | cond_locations, |
| 6024 | fcond_reg); |
| 6025 | break; |
| 6026 | } |
| 6027 | } |
| 6028 | |
| 6029 | if (true_src.IsConstant()) { |
| 6030 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 6031 | } |
| 6032 | if (false_src.IsConstant()) { |
| 6033 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 6034 | } |
| 6035 | |
| 6036 | switch (dst_type) { |
| 6037 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6038 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6039 | __ Mfc1(cond_reg, fcond_reg); |
| 6040 | } |
| 6041 | if (true_src.IsConstant()) { |
| 6042 | if (cond_inverted) { |
| 6043 | __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 6044 | } else { |
| 6045 | __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 6046 | } |
| 6047 | } else if (false_src.IsConstant()) { |
| 6048 | if (cond_inverted) { |
| 6049 | __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 6050 | } else { |
| 6051 | __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 6052 | } |
| 6053 | } else { |
| 6054 | DCHECK_NE(cond_reg, AT); |
| 6055 | if (cond_inverted) { |
| 6056 | __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6057 | __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6058 | } else { |
| 6059 | __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6060 | __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6061 | } |
| 6062 | __ Or(dst.AsRegister<Register>(), AT, TMP); |
| 6063 | } |
| 6064 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6065 | case DataType::Type::kInt64: { |
| 6066 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6067 | __ Mfc1(cond_reg, fcond_reg); |
| 6068 | } |
| 6069 | Register dst_lo = dst.AsRegisterPairLow<Register>(); |
| 6070 | Register dst_hi = dst.AsRegisterPairHigh<Register>(); |
| 6071 | if (true_src.IsConstant()) { |
| 6072 | Register src_lo = false_src.AsRegisterPairLow<Register>(); |
| 6073 | Register src_hi = false_src.AsRegisterPairHigh<Register>(); |
| 6074 | if (cond_inverted) { |
| 6075 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6076 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6077 | } else { |
| 6078 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6079 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6080 | } |
| 6081 | } else { |
| 6082 | DCHECK(false_src.IsConstant()); |
| 6083 | Register src_lo = true_src.AsRegisterPairLow<Register>(); |
| 6084 | Register src_hi = true_src.AsRegisterPairHigh<Register>(); |
| 6085 | if (cond_inverted) { |
| 6086 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6087 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6088 | } else { |
| 6089 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6090 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6091 | } |
| 6092 | } |
| 6093 | break; |
| 6094 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6095 | case DataType::Type::kFloat32: { |
| 6096 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6097 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6098 | __ Sltu(TMP, ZERO, cond_reg); |
| 6099 | __ Mtc1(TMP, fcond_reg); |
| 6100 | } |
| 6101 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6102 | if (true_src.IsConstant()) { |
| 6103 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6104 | if (cond_inverted) { |
| 6105 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6106 | } else { |
| 6107 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6108 | } |
| 6109 | } else if (false_src.IsConstant()) { |
| 6110 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6111 | if (cond_inverted) { |
| 6112 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6113 | } else { |
| 6114 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6115 | } |
| 6116 | } else { |
| 6117 | if (cond_inverted) { |
| 6118 | __ SelS(fcond_reg, |
| 6119 | true_src.AsFpuRegister<FRegister>(), |
| 6120 | false_src.AsFpuRegister<FRegister>()); |
| 6121 | } else { |
| 6122 | __ SelS(fcond_reg, |
| 6123 | false_src.AsFpuRegister<FRegister>(), |
| 6124 | true_src.AsFpuRegister<FRegister>()); |
| 6125 | } |
| 6126 | __ MovS(dst_reg, fcond_reg); |
| 6127 | } |
| 6128 | break; |
| 6129 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6130 | case DataType::Type::kFloat64: { |
| 6131 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6132 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6133 | __ Sltu(TMP, ZERO, cond_reg); |
| 6134 | __ Mtc1(TMP, fcond_reg); |
| 6135 | } |
| 6136 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6137 | if (true_src.IsConstant()) { |
| 6138 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6139 | if (cond_inverted) { |
| 6140 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6141 | } else { |
| 6142 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6143 | } |
| 6144 | } else if (false_src.IsConstant()) { |
| 6145 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6146 | if (cond_inverted) { |
| 6147 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6148 | } else { |
| 6149 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6150 | } |
| 6151 | } else { |
| 6152 | if (cond_inverted) { |
| 6153 | __ SelD(fcond_reg, |
| 6154 | true_src.AsFpuRegister<FRegister>(), |
| 6155 | false_src.AsFpuRegister<FRegister>()); |
| 6156 | } else { |
| 6157 | __ SelD(fcond_reg, |
| 6158 | false_src.AsFpuRegister<FRegister>(), |
| 6159 | true_src.AsFpuRegister<FRegister>()); |
| 6160 | } |
| 6161 | __ MovD(dst_reg, fcond_reg); |
| 6162 | } |
| 6163 | break; |
| 6164 | } |
| 6165 | } |
| 6166 | } |
| 6167 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6168 | void LocationsBuilderMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6169 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6170 | LocationSummary(flag, LocationSummary::kNoCall); |
| 6171 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6172 | } |
| 6173 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6174 | void InstructionCodeGeneratorMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 6175 | __ LoadFromOffset(kLoadWord, |
| 6176 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 6177 | SP, |
| 6178 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6179 | } |
| 6180 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6181 | void LocationsBuilderMIPS::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6182 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6183 | CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6184 | } |
| 6185 | |
| 6186 | void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6187 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 6188 | if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) { |
| 6189 | if (is_r6) { |
| 6190 | GenConditionalMoveR6(select); |
| 6191 | } else { |
| 6192 | GenConditionalMoveR2(select); |
| 6193 | } |
| 6194 | } else { |
| 6195 | LocationSummary* locations = select->GetLocations(); |
| 6196 | MipsLabel false_target; |
| 6197 | GenerateTestAndBranch(select, |
| 6198 | /* condition_input_index */ 2, |
| 6199 | /* true_target */ nullptr, |
| 6200 | &false_target); |
| 6201 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 6202 | __ Bind(&false_target); |
| 6203 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6204 | } |
| 6205 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6206 | void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6207 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6208 | } |
| 6209 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 6210 | void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 6211 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 6212 | } |
| 6213 | |
| 6214 | void CodeGeneratorMIPS::GenerateNop() { |
| 6215 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6216 | } |
| 6217 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6218 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6219 | DataType::Type field_type = field_info.GetFieldType(); |
| 6220 | 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] | 6221 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6222 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6223 | kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6224 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6225 | instruction, |
| 6226 | generate_volatile |
| 6227 | ? LocationSummary::kCallOnMainOnly |
| 6228 | : (object_field_get_with_read_barrier |
| 6229 | ? LocationSummary::kCallOnSlowPath |
| 6230 | : LocationSummary::kNoCall)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6231 | |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6232 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6233 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 6234 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6235 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6236 | if (generate_volatile) { |
| 6237 | InvokeRuntimeCallingConvention calling_convention; |
| 6238 | // need A0 to hold base + offset |
| 6239 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6240 | if (field_type == DataType::Type::kInt64) { |
| 6241 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kInt64)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6242 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6243 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6244 | locations->SetOut(Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6245 | // 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] | 6246 | Location reg = calling_convention.GetReturnLocation(DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6247 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); |
| 6248 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); |
| 6249 | } |
| 6250 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6251 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6252 | locations->SetOut(Location::RequiresFpuRegister()); |
| 6253 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6254 | // The output overlaps in the case of an object field get with |
| 6255 | // read barriers enabled: we do not want the move to overwrite the |
| 6256 | // object's location, as we need it to emit the read barrier. |
| 6257 | locations->SetOut(Location::RequiresRegister(), |
| 6258 | object_field_get_with_read_barrier |
| 6259 | ? Location::kOutputOverlap |
| 6260 | : Location::kNoOutputOverlap); |
| 6261 | } |
| 6262 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6263 | // We need a temporary register for the read barrier marking slow |
| 6264 | // path in CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6265 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6266 | locations->AddTemp(Location::RequiresRegister()); |
| 6267 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6268 | } |
| 6269 | } |
| 6270 | } |
| 6271 | |
| 6272 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, |
| 6273 | const FieldInfo& field_info, |
| 6274 | uint32_t dex_pc) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6275 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 6276 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6277 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6278 | Location obj_loc = locations->InAt(0); |
| 6279 | Register obj = obj_loc.AsRegister<Register>(); |
| 6280 | Location dst_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6281 | LoadOperandType load_type = kLoadUnsignedByte; |
| 6282 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6283 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6284 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6285 | |
| 6286 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6287 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6288 | case DataType::Type::kUint8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6289 | load_type = kLoadUnsignedByte; |
| 6290 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6291 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6292 | load_type = kLoadSignedByte; |
| 6293 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6294 | case DataType::Type::kUint16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6295 | load_type = kLoadUnsignedHalfword; |
| 6296 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6297 | case DataType::Type::kInt16: |
| 6298 | load_type = kLoadSignedHalfword; |
| 6299 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6300 | case DataType::Type::kInt32: |
| 6301 | case DataType::Type::kFloat32: |
| 6302 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6303 | load_type = kLoadWord; |
| 6304 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6305 | case DataType::Type::kInt64: |
| 6306 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6307 | load_type = kLoadDoubleword; |
| 6308 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6309 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6310 | LOG(FATAL) << "Unreachable type " << type; |
| 6311 | UNREACHABLE(); |
| 6312 | } |
| 6313 | |
| 6314 | if (is_volatile && load_type == kLoadDoubleword) { |
| 6315 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6316 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6317 | // Do implicit Null check |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6318 | __ LoadFromOffset(kLoadWord, |
| 6319 | ZERO, |
| 6320 | locations->GetTemp(0).AsRegister<Register>(), |
| 6321 | 0, |
| 6322 | null_checker); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6323 | codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6324 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6325 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6326 | // FP results are returned in core registers. Need to move them. |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6327 | if (dst_loc.IsFpuRegister()) { |
| 6328 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6329 | __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6330 | dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6331 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6332 | DCHECK(dst_loc.IsDoubleStackSlot()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6333 | __ StoreToOffset(kStoreWord, |
| 6334 | locations->GetTemp(1).AsRegister<Register>(), |
| 6335 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6336 | dst_loc.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6337 | __ StoreToOffset(kStoreWord, |
| 6338 | locations->GetTemp(2).AsRegister<Register>(), |
| 6339 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6340 | dst_loc.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6341 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6342 | } |
| 6343 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6344 | if (type == DataType::Type::kReference) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6345 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 6346 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6347 | Location temp_loc = |
| 6348 | kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6349 | // Note that a potential implicit null check is handled in this |
| 6350 | // CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier call. |
| 6351 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6352 | dst_loc, |
| 6353 | obj, |
| 6354 | offset, |
| 6355 | temp_loc, |
| 6356 | /* needs_null_check */ true); |
| 6357 | if (is_volatile) { |
| 6358 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6359 | } |
| 6360 | } else { |
| 6361 | __ LoadFromOffset(kLoadWord, dst_loc.AsRegister<Register>(), obj, offset, null_checker); |
| 6362 | if (is_volatile) { |
| 6363 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6364 | } |
| 6365 | // If read barriers are enabled, emit read barriers other than |
| 6366 | // Baker's using a slow path (and also unpoison the loaded |
| 6367 | // reference, if heap poisoning is enabled). |
| 6368 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 6369 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6370 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6371 | Register dst; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6372 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6373 | DCHECK(dst_loc.IsRegisterPair()); |
| 6374 | dst = dst_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6375 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6376 | DCHECK(dst_loc.IsRegister()); |
| 6377 | dst = dst_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6378 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6379 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6380 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6381 | DCHECK(dst_loc.IsFpuRegister()); |
| 6382 | FRegister dst = dst_loc.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6383 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6384 | __ LoadSFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6385 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6386 | __ LoadDFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6387 | } |
| 6388 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6389 | } |
| 6390 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6391 | // Memory barriers, in the case of references, are handled in the |
| 6392 | // previous switch statement. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6393 | if (is_volatile && (type != DataType::Type::kReference)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6394 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6395 | } |
| 6396 | } |
| 6397 | |
| 6398 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6399 | DataType::Type field_type = field_info.GetFieldType(); |
| 6400 | 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] | 6401 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6402 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6403 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6404 | |
| 6405 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6406 | if (generate_volatile) { |
| 6407 | InvokeRuntimeCallingConvention calling_convention; |
| 6408 | // need A0 to hold base + offset |
| 6409 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6410 | if (field_type == DataType::Type::kInt64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6411 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 6412 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 6413 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6414 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6415 | locations->SetInAt(1, Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6416 | // Pass FP parameters in core registers. |
| 6417 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 6418 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 6419 | } |
| 6420 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6421 | if (DataType::IsFloatingPointType(field_type)) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6422 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6423 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6424 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6425 | } |
| 6426 | } |
| 6427 | } |
| 6428 | |
| 6429 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, |
| 6430 | const FieldInfo& field_info, |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6431 | uint32_t dex_pc, |
| 6432 | bool value_can_be_null) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6433 | DataType::Type type = field_info.GetFieldType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6434 | LocationSummary* locations = instruction->GetLocations(); |
| 6435 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6436 | Location value_location = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6437 | StoreOperandType store_type = kStoreByte; |
| 6438 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6439 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6440 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6441 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6442 | |
| 6443 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6444 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6445 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6446 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6447 | store_type = kStoreByte; |
| 6448 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6449 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6450 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6451 | store_type = kStoreHalfword; |
| 6452 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6453 | case DataType::Type::kInt32: |
| 6454 | case DataType::Type::kFloat32: |
| 6455 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6456 | store_type = kStoreWord; |
| 6457 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6458 | case DataType::Type::kInt64: |
| 6459 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6460 | store_type = kStoreDoubleword; |
| 6461 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6462 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6463 | LOG(FATAL) << "Unreachable type " << type; |
| 6464 | UNREACHABLE(); |
| 6465 | } |
| 6466 | |
| 6467 | if (is_volatile) { |
| 6468 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 6469 | } |
| 6470 | |
| 6471 | if (is_volatile && store_type == kStoreDoubleword) { |
| 6472 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6473 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6474 | // Do implicit Null check. |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6475 | __ LoadFromOffset(kLoadWord, |
| 6476 | ZERO, |
| 6477 | locations->GetTemp(0).AsRegister<Register>(), |
| 6478 | 0, |
| 6479 | null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6480 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6481 | // Pass FP parameters in core registers. |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6482 | if (value_location.IsFpuRegister()) { |
| 6483 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), |
| 6484 | value_location.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6485 | __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6486 | value_location.AsFpuRegister<FRegister>()); |
| 6487 | } else if (value_location.IsDoubleStackSlot()) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6488 | __ LoadFromOffset(kLoadWord, |
| 6489 | locations->GetTemp(1).AsRegister<Register>(), |
| 6490 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6491 | value_location.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6492 | __ LoadFromOffset(kLoadWord, |
| 6493 | locations->GetTemp(2).AsRegister<Register>(), |
| 6494 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6495 | value_location.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6496 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6497 | DCHECK(value_location.IsConstant()); |
| 6498 | DCHECK(value_location.GetConstant()->IsDoubleConstant()); |
| 6499 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6500 | __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(), |
| 6501 | locations->GetTemp(1).AsRegister<Register>(), |
| 6502 | value); |
| 6503 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6504 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6505 | codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6506 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); |
| 6507 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6508 | if (value_location.IsConstant()) { |
| 6509 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 6510 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6511 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6512 | Register src; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6513 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6514 | src = value_location.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6515 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6516 | src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6517 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6518 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 6519 | // Note that in the case where `value` is a null reference, |
| 6520 | // we do not enter this block, as a null reference does not |
| 6521 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6522 | DCHECK_EQ(type, DataType::Type::kReference); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6523 | __ PoisonHeapReference(TMP, src); |
| 6524 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 6525 | } else { |
| 6526 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 6527 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6528 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6529 | FRegister src = value_location.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6530 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6531 | __ StoreSToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6532 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6533 | __ StoreDToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6534 | } |
| 6535 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6536 | } |
| 6537 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6538 | if (needs_write_barrier) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6539 | Register src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6540 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6541 | } |
| 6542 | |
| 6543 | if (is_volatile) { |
| 6544 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 6545 | } |
| 6546 | } |
| 6547 | |
| 6548 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6549 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6550 | } |
| 6551 | |
| 6552 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6553 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 6554 | } |
| 6555 | |
| 6556 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6557 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6558 | } |
| 6559 | |
| 6560 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6561 | HandleFieldSet(instruction, |
| 6562 | instruction->GetFieldInfo(), |
| 6563 | instruction->GetDexPc(), |
| 6564 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6565 | } |
| 6566 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6567 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadOneRegister( |
| 6568 | HInstruction* instruction, |
| 6569 | Location out, |
| 6570 | uint32_t offset, |
| 6571 | Location maybe_temp, |
| 6572 | ReadBarrierOption read_barrier_option) { |
| 6573 | Register out_reg = out.AsRegister<Register>(); |
| 6574 | if (read_barrier_option == kWithReadBarrier) { |
| 6575 | CHECK(kEmitCompilerReadBarrier); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6576 | if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) { |
| 6577 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6578 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6579 | if (kUseBakerReadBarrier) { |
| 6580 | // Load with fast path based Baker's read barrier. |
| 6581 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6582 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6583 | out, |
| 6584 | out_reg, |
| 6585 | offset, |
| 6586 | maybe_temp, |
| 6587 | /* needs_null_check */ false); |
| 6588 | } else { |
| 6589 | // Load with slow path based read barrier. |
| 6590 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6591 | // in the following move operation, as we will need it for the |
| 6592 | // read barrier below. |
| 6593 | __ Move(maybe_temp.AsRegister<Register>(), out_reg); |
| 6594 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6595 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6596 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6597 | } |
| 6598 | } else { |
| 6599 | // Plain load with no read barrier. |
| 6600 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6601 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6602 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6603 | } |
| 6604 | } |
| 6605 | |
| 6606 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadTwoRegisters( |
| 6607 | HInstruction* instruction, |
| 6608 | Location out, |
| 6609 | Location obj, |
| 6610 | uint32_t offset, |
| 6611 | Location maybe_temp, |
| 6612 | ReadBarrierOption read_barrier_option) { |
| 6613 | Register out_reg = out.AsRegister<Register>(); |
| 6614 | Register obj_reg = obj.AsRegister<Register>(); |
| 6615 | if (read_barrier_option == kWithReadBarrier) { |
| 6616 | CHECK(kEmitCompilerReadBarrier); |
| 6617 | if (kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6618 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6619 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6620 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6621 | // Load with fast path based Baker's read barrier. |
| 6622 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6623 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6624 | out, |
| 6625 | obj_reg, |
| 6626 | offset, |
| 6627 | maybe_temp, |
| 6628 | /* needs_null_check */ false); |
| 6629 | } else { |
| 6630 | // Load with slow path based read barrier. |
| 6631 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6632 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6633 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6634 | } |
| 6635 | } else { |
| 6636 | // Plain load with no read barrier. |
| 6637 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6638 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6639 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6640 | } |
| 6641 | } |
| 6642 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6643 | static inline int GetBakerMarkThunkNumber(Register reg) { |
| 6644 | static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 21, "Expecting equal"); |
| 6645 | if (reg >= V0 && reg <= T7) { // 14 consequtive regs. |
| 6646 | return reg - V0; |
| 6647 | } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs. |
| 6648 | return 14 + (reg - S2); |
| 6649 | } else if (reg == FP) { // One more. |
| 6650 | return 20; |
| 6651 | } |
| 6652 | LOG(FATAL) << "Unexpected register " << reg; |
| 6653 | UNREACHABLE(); |
| 6654 | } |
| 6655 | |
| 6656 | static inline int GetBakerMarkFieldArrayThunkDisplacement(Register reg, bool short_offset) { |
| 6657 | int num = GetBakerMarkThunkNumber(reg) + |
| 6658 | (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0); |
| 6659 | return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE; |
| 6660 | } |
| 6661 | |
| 6662 | static inline int GetBakerMarkGcRootThunkDisplacement(Register reg) { |
| 6663 | return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE + |
| 6664 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET; |
| 6665 | } |
| 6666 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6667 | void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6668 | Location root, |
| 6669 | Register obj, |
| 6670 | uint32_t offset, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6671 | ReadBarrierOption read_barrier_option, |
| 6672 | MipsLabel* label_low) { |
| 6673 | bool reordering; |
| 6674 | if (label_low != nullptr) { |
| 6675 | DCHECK_EQ(offset, 0x5678u); |
| 6676 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6677 | Register root_reg = root.AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6678 | if (read_barrier_option == kWithReadBarrier) { |
| 6679 | DCHECK(kEmitCompilerReadBarrier); |
| 6680 | if (kUseBakerReadBarrier) { |
| 6681 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6682 | // Baker's read barrier are used: |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6683 | if (kBakerReadBarrierThunksEnableForGcRoots) { |
| 6684 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6685 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 6686 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 6687 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 6688 | // vice versa. |
| 6689 | // |
| 6690 | // We use thunks for the slow path. That thunk checks the reference |
| 6691 | // and jumps to the entrypoint if needed. |
| 6692 | // |
| 6693 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 6694 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 6695 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6696 | // if (temp != nullptr) { |
| 6697 | // temp = &gc_root_thunk<root_reg> |
| 6698 | // root = temp(root) |
| 6699 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6700 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6701 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 6702 | const int32_t entry_point_offset = |
| 6703 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 6704 | const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg); |
| 6705 | int16_t offset_low = Low16Bits(offset); |
| 6706 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign |
| 6707 | // extension in lw. |
| 6708 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 6709 | Register base = short_offset ? obj : TMP; |
| 6710 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6711 | // threads are suspended or running a checkpoint. |
| 6712 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 6713 | reordering = __ SetReorder(false); |
| 6714 | if (!short_offset) { |
| 6715 | DCHECK(!label_low); |
| 6716 | __ AddUpper(base, obj, offset_high); |
| 6717 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6718 | MipsLabel skip_call; |
| 6719 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6720 | if (label_low != nullptr) { |
| 6721 | DCHECK(short_offset); |
| 6722 | __ Bind(label_low); |
| 6723 | } |
| 6724 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6725 | __ LoadFromOffset(kLoadWord, root_reg, base, offset_low); // Single instruction |
| 6726 | // in delay slot. |
| 6727 | if (isR6) { |
| 6728 | __ Jialc(T9, thunk_disp); |
| 6729 | } else { |
| 6730 | __ Addiu(T9, T9, thunk_disp); |
| 6731 | __ Jalr(T9); |
| 6732 | __ Nop(); |
| 6733 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6734 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6735 | __ SetReorder(reordering); |
| 6736 | } else { |
| 6737 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6738 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 6739 | // load into `temp` (T9) the read barrier mark entry point corresponding |
| 6740 | // to register `root`. If `temp` is null, it means that `GetIsGcMarking()` |
| 6741 | // is false, and vice versa. |
| 6742 | // |
| 6743 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6744 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6745 | // if (temp != null) { |
| 6746 | // root = temp(root) |
| 6747 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6748 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6749 | if (label_low != nullptr) { |
| 6750 | reordering = __ SetReorder(false); |
| 6751 | __ Bind(label_low); |
| 6752 | } |
| 6753 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6754 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6755 | if (label_low != nullptr) { |
| 6756 | __ SetReorder(reordering); |
| 6757 | } |
| 6758 | static_assert( |
| 6759 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6760 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6761 | "have different sizes."); |
| 6762 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6763 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6764 | "have different sizes."); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6765 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6766 | // Slow path marking the GC root `root`. |
| 6767 | Location temp = Location::RegisterLocation(T9); |
| 6768 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6769 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS( |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6770 | instruction, |
| 6771 | root, |
| 6772 | /*entrypoint*/ temp); |
| 6773 | codegen_->AddSlowPath(slow_path); |
| 6774 | |
| 6775 | const int32_t entry_point_offset = |
| 6776 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(root.reg() - 1); |
| 6777 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6778 | // threads are suspended or running a checkpoint. |
| 6779 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 6780 | __ Bnez(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 6781 | __ Bind(slow_path->GetExitLabel()); |
| 6782 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6783 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6784 | if (label_low != nullptr) { |
| 6785 | reordering = __ SetReorder(false); |
| 6786 | __ Bind(label_low); |
| 6787 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6788 | // GC root loaded through a slow path for read barriers other |
| 6789 | // than Baker's. |
| 6790 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6791 | __ Addiu32(root_reg, obj, offset); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6792 | if (label_low != nullptr) { |
| 6793 | __ SetReorder(reordering); |
| 6794 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6795 | // /* mirror::Object* */ root = root->Read() |
| 6796 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6797 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6798 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6799 | if (label_low != nullptr) { |
| 6800 | reordering = __ SetReorder(false); |
| 6801 | __ Bind(label_low); |
| 6802 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6803 | // Plain GC root load with no read barrier. |
| 6804 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6805 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6806 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6807 | // do not have to unpoison `root_reg` here. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6808 | if (label_low != nullptr) { |
| 6809 | __ SetReorder(reordering); |
| 6810 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6811 | } |
| 6812 | } |
| 6813 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6814 | void CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6815 | Location ref, |
| 6816 | Register obj, |
| 6817 | uint32_t offset, |
| 6818 | Location temp, |
| 6819 | bool needs_null_check) { |
| 6820 | DCHECK(kEmitCompilerReadBarrier); |
| 6821 | DCHECK(kUseBakerReadBarrier); |
| 6822 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6823 | if (kBakerReadBarrierThunksEnableForFields) { |
| 6824 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6825 | // to decide whether to mark the loaded reference or not. Instead, we |
| 6826 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 6827 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 6828 | // vice versa. |
| 6829 | // |
| 6830 | // We use thunks for the slow path. That thunk checks the reference |
| 6831 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6832 | // it issues a load-load memory barrier and returns to the original |
| 6833 | // reference load. |
| 6834 | // |
| 6835 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 6836 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 6837 | // if (temp != nullptr) { |
| 6838 | // temp = &field_array_thunk<holder_reg> |
| 6839 | // temp() |
| 6840 | // } |
| 6841 | // not_gray_return_address: |
| 6842 | // // If the offset is too large to fit into the lw instruction, we |
| 6843 | // // use an adjusted base register (TMP) here. This register |
| 6844 | // // receives bits 16 ... 31 of the offset before the thunk invocation |
| 6845 | // // and the thunk benefits from it. |
| 6846 | // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load. |
| 6847 | // gray_return_address: |
| 6848 | |
| 6849 | DCHECK(temp.IsInvalid()); |
| 6850 | bool isR6 = GetInstructionSetFeatures().IsR6(); |
| 6851 | int16_t offset_low = Low16Bits(offset); |
| 6852 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lw. |
| 6853 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 6854 | bool reordering = __ SetReorder(false); |
| 6855 | const int32_t entry_point_offset = |
| 6856 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 6857 | // There may have or may have not been a null check if the field offset is smaller than |
| 6858 | // the page size. |
| 6859 | // There must've been a null check in case it's actually a load from an array. |
| 6860 | // We will, however, perform an explicit null check in the thunk as it's easier to |
| 6861 | // do it than not. |
| 6862 | if (instruction->IsArrayGet()) { |
| 6863 | DCHECK(!needs_null_check); |
| 6864 | } |
| 6865 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset); |
| 6866 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6867 | // threads are suspended or running a checkpoint. |
| 6868 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 6869 | Register ref_reg = ref.AsRegister<Register>(); |
| 6870 | Register base = short_offset ? obj : TMP; |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6871 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6872 | if (short_offset) { |
| 6873 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6874 | __ Beqzc(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6875 | __ Nop(); // In forbidden slot. |
| 6876 | __ Jialc(T9, thunk_disp); |
| 6877 | } else { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6878 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6879 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 6880 | __ Jalr(T9); |
| 6881 | __ Nop(); // In delay slot. |
| 6882 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6883 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6884 | } else { |
| 6885 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6886 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6887 | __ Aui(base, obj, offset_high); // In delay slot. |
| 6888 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6889 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6890 | } else { |
| 6891 | __ Lui(base, offset_high); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6892 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6893 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 6894 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6895 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6896 | __ Addu(base, base, obj); // In delay slot. |
| 6897 | } |
| 6898 | } |
| 6899 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6900 | __ LoadFromOffset(kLoadWord, ref_reg, base, offset_low); // Single instruction. |
| 6901 | if (needs_null_check) { |
| 6902 | MaybeRecordImplicitNullCheck(instruction); |
| 6903 | } |
| 6904 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6905 | __ SetReorder(reordering); |
| 6906 | return; |
| 6907 | } |
| 6908 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6909 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6910 | Location no_index = Location::NoLocation(); |
| 6911 | ScaleFactor no_scale_factor = TIMES_1; |
| 6912 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6913 | ref, |
| 6914 | obj, |
| 6915 | offset, |
| 6916 | no_index, |
| 6917 | no_scale_factor, |
| 6918 | temp, |
| 6919 | needs_null_check); |
| 6920 | } |
| 6921 | |
| 6922 | void CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6923 | Location ref, |
| 6924 | Register obj, |
| 6925 | uint32_t data_offset, |
| 6926 | Location index, |
| 6927 | Location temp, |
| 6928 | bool needs_null_check) { |
| 6929 | DCHECK(kEmitCompilerReadBarrier); |
| 6930 | DCHECK(kUseBakerReadBarrier); |
| 6931 | |
| 6932 | static_assert( |
| 6933 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6934 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6935 | ScaleFactor scale_factor = TIMES_4; |
| 6936 | |
| 6937 | if (kBakerReadBarrierThunksEnableForArrays) { |
| 6938 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6939 | // to decide whether to mark the loaded reference or not. Instead, we |
| 6940 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 6941 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 6942 | // vice versa. |
| 6943 | // |
| 6944 | // We use thunks for the slow path. That thunk checks the reference |
| 6945 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6946 | // it issues a load-load memory barrier and returns to the original |
| 6947 | // reference load. |
| 6948 | // |
| 6949 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 6950 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 6951 | // if (temp != nullptr) { |
| 6952 | // temp = &field_array_thunk<holder_reg> |
| 6953 | // temp() |
| 6954 | // } |
| 6955 | // not_gray_return_address: |
| 6956 | // // The element address is pre-calculated in the TMP register before the |
| 6957 | // // thunk invocation and the thunk benefits from it. |
| 6958 | // HeapReference<mirror::Object> reference = data[index]; // Original reference load. |
| 6959 | // gray_return_address: |
| 6960 | |
| 6961 | DCHECK(temp.IsInvalid()); |
| 6962 | DCHECK(index.IsValid()); |
| 6963 | bool reordering = __ SetReorder(false); |
| 6964 | const int32_t entry_point_offset = |
| 6965 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 6966 | // We will not do the explicit null check in the thunk as some form of a null check |
| 6967 | // must've been done earlier. |
| 6968 | DCHECK(!needs_null_check); |
| 6969 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false); |
| 6970 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6971 | // threads are suspended or running a checkpoint. |
| 6972 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 6973 | Register ref_reg = ref.AsRegister<Register>(); |
| 6974 | Register index_reg = index.IsRegisterPair() |
| 6975 | ? index.AsRegisterPairLow<Register>() |
| 6976 | : index.AsRegister<Register>(); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6977 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6978 | if (GetInstructionSetFeatures().IsR6()) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6979 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6980 | __ Lsa(TMP, index_reg, obj, scale_factor); // In delay slot. |
| 6981 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6982 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6983 | } else { |
| 6984 | __ Sll(TMP, index_reg, scale_factor); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6985 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6986 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 6987 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6988 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6989 | __ Addu(TMP, TMP, obj); // In delay slot. |
| 6990 | } |
| 6991 | // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor)) |
| 6992 | DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset; |
| 6993 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, data_offset); // Single instruction. |
| 6994 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6995 | __ SetReorder(reordering); |
| 6996 | return; |
| 6997 | } |
| 6998 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6999 | // /* HeapReference<Object> */ ref = |
| 7000 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7001 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 7002 | ref, |
| 7003 | obj, |
| 7004 | data_offset, |
| 7005 | index, |
| 7006 | scale_factor, |
| 7007 | temp, |
| 7008 | needs_null_check); |
| 7009 | } |
| 7010 | |
| 7011 | void CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7012 | Location ref, |
| 7013 | Register obj, |
| 7014 | uint32_t offset, |
| 7015 | Location index, |
| 7016 | ScaleFactor scale_factor, |
| 7017 | Location temp, |
| 7018 | bool needs_null_check, |
| 7019 | bool always_update_field) { |
| 7020 | DCHECK(kEmitCompilerReadBarrier); |
| 7021 | DCHECK(kUseBakerReadBarrier); |
| 7022 | |
| 7023 | // In slow path based read barriers, the read barrier call is |
| 7024 | // inserted after the original load. However, in fast path based |
| 7025 | // Baker's read barriers, we need to perform the load of |
| 7026 | // mirror::Object::monitor_ *before* the original reference load. |
| 7027 | // This load-load ordering is required by the read barrier. |
| 7028 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7029 | // |
| 7030 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7031 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7032 | // HeapReference<Object> ref = *src; // Original reference load. |
| 7033 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 7034 | // if (is_gray) { |
| 7035 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7036 | // } |
| 7037 | // |
| 7038 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7039 | // slightly more complex as it performs additional checks that we do |
| 7040 | // not do here for performance reasons. |
| 7041 | |
| 7042 | Register ref_reg = ref.AsRegister<Register>(); |
| 7043 | Register temp_reg = temp.AsRegister<Register>(); |
| 7044 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7045 | |
| 7046 | // /* int32_t */ monitor = obj->monitor_ |
| 7047 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 7048 | if (needs_null_check) { |
| 7049 | MaybeRecordImplicitNullCheck(instruction); |
| 7050 | } |
| 7051 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7052 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7053 | "art::LockWord and int32_t have different sizes."); |
| 7054 | |
| 7055 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 7056 | |
| 7057 | // The actual reference load. |
| 7058 | if (index.IsValid()) { |
| 7059 | // Load types involving an "index": ArrayGet, |
| 7060 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7061 | // intrinsics. |
| 7062 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 7063 | if (index.IsConstant()) { |
| 7064 | size_t computed_offset = |
| 7065 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 7066 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7067 | } else { |
| 7068 | // Handle the special case of the |
| 7069 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7070 | // intrinsics, which use a register pair as index ("long |
| 7071 | // offset"), of which only the low part contains data. |
| 7072 | Register index_reg = index.IsRegisterPair() |
| 7073 | ? index.AsRegisterPairLow<Register>() |
| 7074 | : index.AsRegister<Register>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 7075 | __ ShiftAndAdd(TMP, index_reg, obj, scale_factor, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7076 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, offset); |
| 7077 | } |
| 7078 | } else { |
| 7079 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7080 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7081 | } |
| 7082 | |
| 7083 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7084 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7085 | |
| 7086 | // Slow path marking the object `ref` when it is gray. |
| 7087 | SlowPathCodeMIPS* slow_path; |
| 7088 | if (always_update_field) { |
| 7089 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS only supports address |
| 7090 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7091 | // `field_offset` is a register pair (of which only the lower half |
| 7092 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7093 | // to be null in this code path. |
| 7094 | DCHECK_EQ(offset, 0u); |
| 7095 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7096 | slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7097 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(instruction, |
| 7098 | ref, |
| 7099 | obj, |
| 7100 | /* field_offset */ index, |
| 7101 | temp_reg); |
| 7102 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7103 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS(instruction, ref); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7104 | } |
| 7105 | AddSlowPath(slow_path); |
| 7106 | |
| 7107 | // if (rb_state == ReadBarrier::GrayState()) |
| 7108 | // ref = ReadBarrier::Mark(ref); |
| 7109 | // Given the numeric representation, it's enough to check the low bit of the |
| 7110 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 7111 | // performing a branch on less than zero. |
| 7112 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7113 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 7114 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 7115 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 7116 | __ Bltz(temp_reg, slow_path->GetEntryLabel()); |
| 7117 | __ Bind(slow_path->GetExitLabel()); |
| 7118 | } |
| 7119 | |
| 7120 | void CodeGeneratorMIPS::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7121 | Location out, |
| 7122 | Location ref, |
| 7123 | Location obj, |
| 7124 | uint32_t offset, |
| 7125 | Location index) { |
| 7126 | DCHECK(kEmitCompilerReadBarrier); |
| 7127 | |
| 7128 | // Insert a slow path based read barrier *after* the reference load. |
| 7129 | // |
| 7130 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7131 | // reference will be carried out by the runtime within the slow |
| 7132 | // path. |
| 7133 | // |
| 7134 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7135 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7136 | // not used by the artReadBarrierSlow entry point. |
| 7137 | // |
| 7138 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7139 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7140 | ReadBarrierForHeapReferenceSlowPathMIPS(instruction, out, ref, obj, offset, index); |
| 7141 | AddSlowPath(slow_path); |
| 7142 | |
| 7143 | __ B(slow_path->GetEntryLabel()); |
| 7144 | __ Bind(slow_path->GetExitLabel()); |
| 7145 | } |
| 7146 | |
| 7147 | void CodeGeneratorMIPS::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7148 | Location out, |
| 7149 | Location ref, |
| 7150 | Location obj, |
| 7151 | uint32_t offset, |
| 7152 | Location index) { |
| 7153 | if (kEmitCompilerReadBarrier) { |
| 7154 | // Baker's read barriers shall be handled by the fast path |
| 7155 | // (CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier). |
| 7156 | DCHECK(!kUseBakerReadBarrier); |
| 7157 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7158 | // by the runtime within the slow path. |
| 7159 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 7160 | } else if (kPoisonHeapReferences) { |
| 7161 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7162 | } |
| 7163 | } |
| 7164 | |
| 7165 | void CodeGeneratorMIPS::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7166 | Location out, |
| 7167 | Location root) { |
| 7168 | DCHECK(kEmitCompilerReadBarrier); |
| 7169 | |
| 7170 | // Insert a slow path based read barrier *after* the GC root load. |
| 7171 | // |
| 7172 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7173 | // not need to do anything special for this here. |
| 7174 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7175 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS(instruction, out, root); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7176 | AddSlowPath(slow_path); |
| 7177 | |
| 7178 | __ B(slow_path->GetEntryLabel()); |
| 7179 | __ Bind(slow_path->GetExitLabel()); |
| 7180 | } |
| 7181 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7182 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7183 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7184 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7185 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7186 | switch (type_check_kind) { |
| 7187 | case TypeCheckKind::kExactCheck: |
| 7188 | case TypeCheckKind::kAbstractClassCheck: |
| 7189 | case TypeCheckKind::kClassHierarchyCheck: |
| 7190 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7191 | call_kind = |
| 7192 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7193 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7194 | break; |
| 7195 | case TypeCheckKind::kArrayCheck: |
| 7196 | case TypeCheckKind::kUnresolvedCheck: |
| 7197 | case TypeCheckKind::kInterfaceCheck: |
| 7198 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7199 | break; |
| 7200 | } |
| 7201 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7202 | LocationSummary* locations = |
| 7203 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7204 | if (baker_read_barrier_slow_path) { |
| 7205 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7206 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7207 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7208 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7209 | // The output does overlap inputs. |
| 7210 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 7211 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7212 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7213 | } |
| 7214 | |
| 7215 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7216 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7217 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7218 | Location obj_loc = locations->InAt(0); |
| 7219 | Register obj = obj_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7220 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7221 | Location out_loc = locations->Out(); |
| 7222 | Register out = out_loc.AsRegister<Register>(); |
| 7223 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7224 | DCHECK_LE(num_temps, 1u); |
| 7225 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7226 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7227 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7228 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7229 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7230 | MipsLabel done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7231 | SlowPathCodeMIPS* slow_path = nullptr; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7232 | |
| 7233 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7234 | // Avoid this check if we know `obj` is not null. |
| 7235 | if (instruction->MustDoNullCheck()) { |
| 7236 | __ Move(out, ZERO); |
| 7237 | __ Beqz(obj, &done); |
| 7238 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7239 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7240 | switch (type_check_kind) { |
| 7241 | case TypeCheckKind::kExactCheck: { |
| 7242 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7243 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7244 | out_loc, |
| 7245 | obj_loc, |
| 7246 | class_offset, |
| 7247 | maybe_temp_loc, |
| 7248 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7249 | // Classes must be equal for the instanceof to succeed. |
| 7250 | __ Xor(out, out, cls); |
| 7251 | __ Sltiu(out, out, 1); |
| 7252 | break; |
| 7253 | } |
| 7254 | |
| 7255 | case TypeCheckKind::kAbstractClassCheck: { |
| 7256 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7257 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7258 | out_loc, |
| 7259 | obj_loc, |
| 7260 | class_offset, |
| 7261 | maybe_temp_loc, |
| 7262 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7263 | // If the class is abstract, we eagerly fetch the super class of the |
| 7264 | // object to avoid doing a comparison we know will fail. |
| 7265 | MipsLabel loop; |
| 7266 | __ Bind(&loop); |
| 7267 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7268 | GenerateReferenceLoadOneRegister(instruction, |
| 7269 | out_loc, |
| 7270 | super_offset, |
| 7271 | maybe_temp_loc, |
| 7272 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7273 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7274 | __ Beqz(out, &done); |
| 7275 | __ Bne(out, cls, &loop); |
| 7276 | __ LoadConst32(out, 1); |
| 7277 | break; |
| 7278 | } |
| 7279 | |
| 7280 | case TypeCheckKind::kClassHierarchyCheck: { |
| 7281 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7282 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7283 | out_loc, |
| 7284 | obj_loc, |
| 7285 | class_offset, |
| 7286 | maybe_temp_loc, |
| 7287 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7288 | // Walk over the class hierarchy to find a match. |
| 7289 | MipsLabel loop, success; |
| 7290 | __ Bind(&loop); |
| 7291 | __ Beq(out, cls, &success); |
| 7292 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7293 | GenerateReferenceLoadOneRegister(instruction, |
| 7294 | out_loc, |
| 7295 | super_offset, |
| 7296 | maybe_temp_loc, |
| 7297 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7298 | __ Bnez(out, &loop); |
| 7299 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7300 | __ B(&done); |
| 7301 | __ Bind(&success); |
| 7302 | __ LoadConst32(out, 1); |
| 7303 | break; |
| 7304 | } |
| 7305 | |
| 7306 | case TypeCheckKind::kArrayObjectCheck: { |
| 7307 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7308 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7309 | out_loc, |
| 7310 | obj_loc, |
| 7311 | class_offset, |
| 7312 | maybe_temp_loc, |
| 7313 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7314 | // Do an exact check. |
| 7315 | MipsLabel success; |
| 7316 | __ Beq(out, cls, &success); |
| 7317 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7318 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7319 | GenerateReferenceLoadOneRegister(instruction, |
| 7320 | out_loc, |
| 7321 | component_offset, |
| 7322 | maybe_temp_loc, |
| 7323 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7324 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7325 | __ Beqz(out, &done); |
| 7326 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7327 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 7328 | __ Sltiu(out, out, 1); |
| 7329 | __ B(&done); |
| 7330 | __ Bind(&success); |
| 7331 | __ LoadConst32(out, 1); |
| 7332 | break; |
| 7333 | } |
| 7334 | |
| 7335 | case TypeCheckKind::kArrayCheck: { |
| 7336 | // No read barrier since the slow path will retry upon failure. |
| 7337 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7338 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7339 | out_loc, |
| 7340 | obj_loc, |
| 7341 | class_offset, |
| 7342 | maybe_temp_loc, |
| 7343 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7344 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7345 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7346 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7347 | codegen_->AddSlowPath(slow_path); |
| 7348 | __ Bne(out, cls, slow_path->GetEntryLabel()); |
| 7349 | __ LoadConst32(out, 1); |
| 7350 | break; |
| 7351 | } |
| 7352 | |
| 7353 | case TypeCheckKind::kUnresolvedCheck: |
| 7354 | case TypeCheckKind::kInterfaceCheck: { |
| 7355 | // Note that we indeed only call on slow path, but we always go |
| 7356 | // into the slow path for the unresolved and interface check |
| 7357 | // cases. |
| 7358 | // |
| 7359 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7360 | // entry point without resorting to a type checking slow path |
| 7361 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7362 | // require to assign fixed registers for the inputs of this |
| 7363 | // HInstanceOf instruction (following the runtime calling |
| 7364 | // convention), which might be cluttered by the potential first |
| 7365 | // read barrier emission at the beginning of this method. |
| 7366 | // |
| 7367 | // TODO: Introduce a new runtime entry point taking the object |
| 7368 | // to test (instead of its class) as argument, and let it deal |
| 7369 | // with the read barrier issues. This will let us refactor this |
| 7370 | // case of the `switch` code as it was previously (with a direct |
| 7371 | // call to the runtime not using a type checking slow path). |
| 7372 | // This should also be beneficial for the other cases above. |
| 7373 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7374 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7375 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7376 | codegen_->AddSlowPath(slow_path); |
| 7377 | __ B(slow_path->GetEntryLabel()); |
| 7378 | break; |
| 7379 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7380 | } |
| 7381 | |
| 7382 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7383 | |
| 7384 | if (slow_path != nullptr) { |
| 7385 | __ Bind(slow_path->GetExitLabel()); |
| 7386 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7387 | } |
| 7388 | |
| 7389 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7390 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7391 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7392 | } |
| 7393 | |
| 7394 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 7395 | // Will be generated at use site. |
| 7396 | } |
| 7397 | |
| 7398 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7399 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7400 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7401 | } |
| 7402 | |
| 7403 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 7404 | // Will be generated at use site. |
| 7405 | } |
| 7406 | |
| 7407 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { |
| 7408 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 7409 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 7410 | } |
| 7411 | |
| 7412 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7413 | HandleInvoke(invoke); |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7414 | // 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] | 7415 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7416 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T7)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7417 | } |
| 7418 | |
| 7419 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7420 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 7421 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7422 | Location receiver = invoke->GetLocations()->InAt(0); |
| 7423 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7424 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7425 | |
| 7426 | // Set the hidden argument. |
| 7427 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 7428 | invoke->GetDexMethodIndex()); |
| 7429 | |
| 7430 | // temp = object->GetClass(); |
| 7431 | if (receiver.IsStackSlot()) { |
| 7432 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 7433 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 7434 | } else { |
| 7435 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 7436 | } |
| 7437 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7438 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7439 | // emit a read barrier for the previous class reference load. |
| 7440 | // However this is not required in practice, as this is an |
| 7441 | // intermediate/temporary reference and because the current |
| 7442 | // concurrent copying collector keeps the from-space memory |
| 7443 | // intact/accessible until the end of the marking phase (the |
| 7444 | // concurrent copying collector may not in the future). |
| 7445 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 7446 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 7447 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
| 7448 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7449 | invoke->GetImtIndex(), kMipsPointerSize)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7450 | // temp = temp->GetImtEntryAt(method_offset); |
| 7451 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7452 | // T9 = temp->GetEntryPoint(); |
| 7453 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 7454 | // T9(); |
| 7455 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7456 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7457 | DCHECK(!codegen_->IsLeafMethod()); |
| 7458 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 7459 | } |
| 7460 | |
| 7461 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7462 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7463 | if (intrinsic.TryDispatch(invoke)) { |
| 7464 | return; |
| 7465 | } |
| 7466 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7467 | HandleInvoke(invoke); |
| 7468 | } |
| 7469 | |
| 7470 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 7471 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 7472 | // art::PrepareForRegisterAllocation. |
| 7473 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7474 | |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7475 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7476 | bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
| 7477 | bool has_extra_input = invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7478 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7479 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7480 | if (intrinsic.TryDispatch(invoke)) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7481 | if (invoke->GetLocations()->CanCall() && has_extra_input) { |
| 7482 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 7483 | } |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7484 | return; |
| 7485 | } |
| 7486 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7487 | HandleInvoke(invoke); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7488 | |
| 7489 | // Add the extra input register if either the dex cache array base register |
| 7490 | // or the PC-relative base register for accessing literals is needed. |
| 7491 | if (has_extra_input) { |
| 7492 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 7493 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7494 | } |
| 7495 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 7496 | void LocationsBuilderMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7497 | HandleInvoke(invoke); |
| 7498 | } |
| 7499 | |
| 7500 | void InstructionCodeGeneratorMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7501 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 7502 | } |
| 7503 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7504 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7505 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7506 | IntrinsicCodeGeneratorMIPS intrinsic(codegen); |
| 7507 | intrinsic.Dispatch(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7508 | return true; |
| 7509 | } |
| 7510 | return false; |
| 7511 | } |
| 7512 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7513 | HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7514 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7515 | switch (desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7516 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7517 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7518 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7519 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7520 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7521 | case HLoadString::LoadKind::kJitTableAddress: |
| 7522 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7523 | break; |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7524 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7525 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7526 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7527 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7528 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7529 | } |
| 7530 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7531 | HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind( |
| 7532 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7533 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7534 | case HLoadClass::LoadKind::kInvalid: |
| 7535 | LOG(FATAL) << "UNREACHABLE"; |
| 7536 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7537 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7538 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7539 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7540 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7541 | case HLoadClass::LoadKind::kBssEntry: |
| 7542 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7543 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7544 | case HLoadClass::LoadKind::kJitTableAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7545 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7546 | break; |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7547 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7548 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7549 | break; |
| 7550 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7551 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7552 | } |
| 7553 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7554 | Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7555 | Register temp) { |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7556 | CHECK(!GetInstructionSetFeatures().IsR6()); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7557 | CHECK(!GetGraph()->HasIrreducibleLoops()); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7558 | CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7559 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7560 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7561 | return location.AsRegister<Register>(); |
| 7562 | } |
| 7563 | // For intrinsics we allow any location, so it may be on the stack. |
| 7564 | if (!location.IsRegister()) { |
| 7565 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7566 | return temp; |
| 7567 | } |
| 7568 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7569 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7570 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7571 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7572 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 7573 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 7574 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 7575 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7576 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7577 | return temp; |
| 7578 | } |
| 7579 | return location.AsRegister<Register>(); |
| 7580 | } |
| 7581 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7582 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( |
| 7583 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 7584 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7585 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7586 | } |
| 7587 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7588 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall( |
| 7589 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7590 | // 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] | 7591 | 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] | 7592 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 7593 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7594 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7595 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 7596 | Register base_reg = (invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7597 | ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>()) |
| 7598 | : ZERO; |
| 7599 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7600 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7601 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7602 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7603 | uint32_t offset = |
| 7604 | GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7605 | __ LoadFromOffset(kLoadWord, |
| 7606 | temp.AsRegister<Register>(), |
| 7607 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7608 | offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7609 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7610 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7611 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7612 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7613 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7614 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 7615 | DCHECK(GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7616 | PcRelativePatchInfo* info_high = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 7617 | PcRelativePatchInfo* info_low = |
| 7618 | NewPcRelativeMethodPatch(invoke->GetTargetMethod(), info_high); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7619 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7620 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 7621 | __ Addiu(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7622 | break; |
| 7623 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7624 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7625 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 7626 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7627 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7628 | PcRelativePatchInfo* info_high = NewMethodBssEntryPatch( |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7629 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7630 | PcRelativePatchInfo* info_low = NewMethodBssEntryPatch( |
| 7631 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7632 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7633 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 7634 | __ Lw(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7635 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7636 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7637 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 7638 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 7639 | return; // No code pointer retrieval; the runtime performs the call directly. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7640 | } |
| 7641 | } |
| 7642 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7643 | switch (code_ptr_location) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7644 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7645 | __ Bal(&frame_entry_label_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7646 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7647 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7648 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 7649 | __ LoadFromOffset(kLoadWord, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7650 | T9, |
| 7651 | callee_method.AsRegister<Register>(), |
| 7652 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7653 | kMipsPointerSize).Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7654 | // T9() |
| 7655 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7656 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7657 | break; |
| 7658 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7659 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 7660 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7661 | DCHECK(!IsLeafMethod()); |
| 7662 | } |
| 7663 | |
| 7664 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 7665 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 7666 | // art::PrepareForRegisterAllocation. |
| 7667 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7668 | |
| 7669 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 7670 | return; |
| 7671 | } |
| 7672 | |
| 7673 | LocationSummary* locations = invoke->GetLocations(); |
| 7674 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 7675 | locations->HasTemps() |
| 7676 | ? locations->GetTemp(0) |
| 7677 | : Location::NoLocation()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7678 | } |
| 7679 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7680 | void CodeGeneratorMIPS::GenerateVirtualCall( |
| 7681 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 7682 | // Use the calling convention instead of the location of the receiver, as |
| 7683 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7684 | // slow path, the arguments have been moved to the right place, so here we are |
| 7685 | // guaranteed that the receiver is the first register of the calling convention. |
| 7686 | InvokeDexCallingConvention calling_convention; |
| 7687 | Register receiver = calling_convention.GetRegisterAt(0); |
| 7688 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7689 | Register temp = temp_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7690 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7691 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); |
| 7692 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7693 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7694 | |
| 7695 | // temp = object->GetClass(); |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 7696 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7697 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7698 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7699 | // emit a read barrier for the previous class reference load. |
| 7700 | // However this is not required in practice, as this is an |
| 7701 | // intermediate/temporary reference and because the current |
| 7702 | // concurrent copying collector keeps the from-space memory |
| 7703 | // intact/accessible until the end of the marking phase (the |
| 7704 | // concurrent copying collector may not in the future). |
| 7705 | __ MaybeUnpoisonHeapReference(temp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7706 | // temp = temp->GetMethodAt(method_offset); |
| 7707 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7708 | // T9 = temp->GetEntryPoint(); |
| 7709 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 7710 | // T9(); |
| 7711 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7712 | __ NopIfNoReordering(); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7713 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7714 | } |
| 7715 | |
| 7716 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 7717 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 7718 | return; |
| 7719 | } |
| 7720 | |
| 7721 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7722 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7723 | } |
| 7724 | |
| 7725 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7726 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7727 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7728 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7729 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 7730 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7731 | return; |
| 7732 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7733 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7734 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7735 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7736 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7737 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7738 | ? LocationSummary::kCallOnSlowPath |
| 7739 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7740 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7741 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 7742 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7743 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7744 | switch (load_kind) { |
| 7745 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7746 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7747 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7748 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7749 | case HLoadClass::LoadKind::kBssEntry: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7750 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7751 | break; |
| 7752 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7753 | if (has_irreducible_loops) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 7754 | if (load_kind != HLoadClass::LoadKind::kBootImageAddress) { |
| 7755 | codegen_->ClobberRA(); |
| 7756 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7757 | break; |
| 7758 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7759 | FALLTHROUGH_INTENDED; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7760 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7761 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7762 | break; |
| 7763 | default: |
| 7764 | break; |
| 7765 | } |
| 7766 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7767 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7768 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7769 | // 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] | 7770 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7771 | InvokeRuntimeCallingConvention calling_convention; |
| 7772 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7773 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 7774 | } else { |
| 7775 | // For non-Baker read barriers we have a temp-clobbering call. |
| 7776 | } |
| 7777 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7778 | } |
| 7779 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7780 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7781 | // move. |
| 7782 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7783 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7784 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7785 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 7786 | return; |
| 7787 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7788 | DCHECK(!cls->NeedsAccessCheck()); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 7789 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7790 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7791 | Location out_loc = locations->Out(); |
| 7792 | Register out = out_loc.AsRegister<Register>(); |
| 7793 | Register base_or_current_method_reg; |
| 7794 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7795 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7796 | switch (load_kind) { |
| 7797 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7798 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7799 | case HLoadClass::LoadKind::kBootImageAddress: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7800 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7801 | case HLoadClass::LoadKind::kBssEntry: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7802 | base_or_current_method_reg = |
| 7803 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7804 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7805 | case HLoadClass::LoadKind::kReferrersClass: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7806 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7807 | base_or_current_method_reg = locations->InAt(0).AsRegister<Register>(); |
| 7808 | break; |
| 7809 | default: |
| 7810 | base_or_current_method_reg = ZERO; |
| 7811 | break; |
| 7812 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 7813 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7814 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7815 | ? kWithoutReadBarrier |
| 7816 | : kCompilerReadBarrierOption; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7817 | bool generate_null_check = false; |
| 7818 | switch (load_kind) { |
| 7819 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7820 | DCHECK(!cls->CanCallRuntime()); |
| 7821 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7822 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7823 | GenerateGcRootFieldLoad(cls, |
| 7824 | out_loc, |
| 7825 | base_or_current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7826 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 7827 | read_barrier_option); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7828 | break; |
| 7829 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7830 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7831 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7832 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7833 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7834 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7835 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 7836 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7837 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 7838 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7839 | base_or_current_method_reg); |
| 7840 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7841 | break; |
| 7842 | } |
| 7843 | case HLoadClass::LoadKind::kBootImageAddress: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7844 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7845 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7846 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 7847 | DCHECK_NE(address, 0u); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7848 | if (isR6 || !has_irreducible_loops) { |
| 7849 | __ LoadLiteral(out, |
| 7850 | base_or_current_method_reg, |
| 7851 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7852 | } else { |
| 7853 | __ LoadConst32(out, address); |
| 7854 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7855 | break; |
| 7856 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7857 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 7858 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7859 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
| 7860 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 7861 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 7862 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
| 7863 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 7864 | out, |
| 7865 | base_or_current_method_reg); |
| 7866 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
| 7867 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 7868 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 7869 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 7870 | if (masked_hash != 0) { |
| 7871 | __ Addiu(out, out, -masked_hash); |
| 7872 | } |
| 7873 | break; |
| 7874 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7875 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7876 | CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high = |
| 7877 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7878 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 7879 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7880 | codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7881 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7882 | base_or_current_method_reg); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7883 | GenerateGcRootFieldLoad(cls, |
| 7884 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7885 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7886 | /* placeholder */ 0x5678, |
| 7887 | read_barrier_option, |
| 7888 | &info_low->label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7889 | generate_null_check = true; |
| 7890 | break; |
| 7891 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7892 | case HLoadClass::LoadKind::kJitTableAddress: { |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 7893 | CodeGeneratorMIPS::JitPatchInfo* info = codegen_->NewJitRootClassPatch(cls->GetDexFile(), |
| 7894 | cls->GetTypeIndex(), |
| 7895 | cls->GetClass()); |
| 7896 | bool reordering = __ SetReorder(false); |
| 7897 | __ Bind(&info->high_label); |
| 7898 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 7899 | __ SetReorder(reordering); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7900 | GenerateGcRootFieldLoad(cls, |
| 7901 | out_loc, |
| 7902 | out, |
| 7903 | /* placeholder */ 0x5678, |
| 7904 | read_barrier_option, |
| 7905 | &info->low_label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7906 | break; |
| 7907 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7908 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7909 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7910 | LOG(FATAL) << "UNREACHABLE"; |
| 7911 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7912 | } |
| 7913 | |
| 7914 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7915 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7916 | SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS( |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7917 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7918 | codegen_->AddSlowPath(slow_path); |
| 7919 | if (generate_null_check) { |
| 7920 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 7921 | } |
| 7922 | if (cls->MustGenerateClinitCheck()) { |
| 7923 | GenerateClassInitializationCheck(slow_path, out); |
| 7924 | } else { |
| 7925 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7926 | } |
| 7927 | } |
| 7928 | } |
| 7929 | |
| 7930 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7931 | return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7932 | } |
| 7933 | |
| 7934 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { |
| 7935 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7936 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7937 | locations->SetOut(Location::RequiresRegister()); |
| 7938 | } |
| 7939 | |
| 7940 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { |
| 7941 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
| 7942 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 7943 | } |
| 7944 | |
| 7945 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7946 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7947 | } |
| 7948 | |
| 7949 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7950 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
| 7951 | } |
| 7952 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7953 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 7954 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7955 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7956 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7957 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7958 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7959 | switch (load_kind) { |
| 7960 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7961 | case HLoadString::LoadKind::kBootImageAddress: |
| 7962 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7963 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7964 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7965 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7966 | break; |
| 7967 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7968 | if (has_irreducible_loops) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 7969 | if (load_kind != HLoadString::LoadKind::kBootImageAddress) { |
| 7970 | codegen_->ClobberRA(); |
| 7971 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7972 | break; |
| 7973 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7974 | FALLTHROUGH_INTENDED; |
| 7975 | // We need an extra register for PC-relative dex cache accesses. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7976 | case HLoadString::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7977 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7978 | break; |
| 7979 | default: |
| 7980 | break; |
| 7981 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7982 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 7983 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7984 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 7985 | } else { |
| 7986 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7987 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7988 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7989 | // Rely on the pResolveString and marking to save everything we need. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7990 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7991 | InvokeRuntimeCallingConvention calling_convention; |
| 7992 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7993 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 7994 | } else { |
| 7995 | // For non-Baker read barriers we have a temp-clobbering call. |
| 7996 | } |
| 7997 | } |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 7998 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7999 | } |
| 8000 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8001 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 8002 | // move. |
| 8003 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8004 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8005 | LocationSummary* locations = load->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8006 | Location out_loc = locations->Out(); |
| 8007 | Register out = out_loc.AsRegister<Register>(); |
| 8008 | Register base_or_current_method_reg; |
| 8009 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8010 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8011 | switch (load_kind) { |
| 8012 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8013 | case HLoadString::LoadKind::kBootImageAddress: |
| 8014 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8015 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8016 | case HLoadString::LoadKind::kBssEntry: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8017 | base_or_current_method_reg = |
| 8018 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8019 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8020 | default: |
| 8021 | base_or_current_method_reg = ZERO; |
| 8022 | break; |
| 8023 | } |
| 8024 | |
| 8025 | switch (load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8026 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8027 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8028 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8029 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8030 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8031 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8032 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8033 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 8034 | base_or_current_method_reg); |
| 8035 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8036 | return; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8037 | } |
| 8038 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8039 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 8040 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 8041 | DCHECK_NE(address, 0u); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8042 | if (isR6 || !has_irreducible_loops) { |
| 8043 | __ LoadLiteral(out, |
| 8044 | base_or_current_method_reg, |
| 8045 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 8046 | } else { |
| 8047 | __ LoadConst32(out, address); |
| 8048 | } |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8049 | return; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8050 | } |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8051 | case HLoadString::LoadKind::kBootImageInternTable: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8052 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8053 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8054 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8055 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8056 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8057 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8058 | out, |
| 8059 | base_or_current_method_reg); |
| 8060 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
| 8061 | return; |
| 8062 | } |
| 8063 | case HLoadString::LoadKind::kBssEntry: { |
| 8064 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 8065 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
| 8066 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| 8067 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8068 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8069 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8070 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8071 | base_or_current_method_reg); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8072 | GenerateGcRootFieldLoad(load, |
| 8073 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8074 | out, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8075 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8076 | kCompilerReadBarrierOption, |
| 8077 | &info_low->label); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8078 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8079 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8080 | codegen_->AddSlowPath(slow_path); |
| 8081 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 8082 | __ Bind(slow_path->GetExitLabel()); |
| 8083 | return; |
| 8084 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8085 | case HLoadString::LoadKind::kJitTableAddress: { |
| 8086 | CodeGeneratorMIPS::JitPatchInfo* info = |
| 8087 | codegen_->NewJitRootStringPatch(load->GetDexFile(), |
| 8088 | load->GetStringIndex(), |
| 8089 | load->GetString()); |
| 8090 | bool reordering = __ SetReorder(false); |
| 8091 | __ Bind(&info->high_label); |
| 8092 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8093 | __ SetReorder(reordering); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8094 | GenerateGcRootFieldLoad(load, |
| 8095 | out_loc, |
| 8096 | out, |
| 8097 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8098 | kCompilerReadBarrierOption, |
| 8099 | &info->low_label); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8100 | return; |
| 8101 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8102 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8103 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8104 | } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 8105 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8106 | // 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] | 8107 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8108 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8109 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8110 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8111 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 8112 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8113 | } |
| 8114 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8115 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8116 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8117 | locations->SetOut(Location::ConstantLocation(constant)); |
| 8118 | } |
| 8119 | |
| 8120 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 8121 | // Will be generated at use site. |
| 8122 | } |
| 8123 | |
| 8124 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8125 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8126 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8127 | InvokeRuntimeCallingConvention calling_convention; |
| 8128 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8129 | } |
| 8130 | |
| 8131 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8132 | if (instruction->IsEnter()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8133 | codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8134 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8135 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8136 | codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8137 | } |
| 8138 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8139 | } |
| 8140 | |
| 8141 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { |
| 8142 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8143 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8144 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8145 | case DataType::Type::kInt32: |
| 8146 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8147 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8148 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8149 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8150 | break; |
| 8151 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8152 | case DataType::Type::kFloat32: |
| 8153 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8154 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8155 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 8156 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8157 | break; |
| 8158 | |
| 8159 | default: |
| 8160 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 8161 | } |
| 8162 | } |
| 8163 | |
| 8164 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8165 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8166 | LocationSummary* locations = instruction->GetLocations(); |
| 8167 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 8168 | |
| 8169 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8170 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8171 | Register dst = locations->Out().AsRegister<Register>(); |
| 8172 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 8173 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 8174 | |
| 8175 | if (isR6) { |
| 8176 | __ MulR6(dst, lhs, rhs); |
| 8177 | } else { |
| 8178 | __ MulR2(dst, lhs, rhs); |
| 8179 | } |
| 8180 | break; |
| 8181 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8182 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8183 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8184 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8185 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8186 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8187 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 8188 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 8189 | |
| 8190 | // Extra checks to protect caused by the existance of A1_A2. |
| 8191 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: |
| 8192 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). |
| 8193 | DCHECK_NE(dst_high, lhs_low); |
| 8194 | DCHECK_NE(dst_high, rhs_low); |
| 8195 | |
| 8196 | // A_B * C_D |
| 8197 | // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ] |
| 8198 | // dst_lo: [ low(B*D) ] |
| 8199 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. |
| 8200 | |
| 8201 | if (isR6) { |
| 8202 | __ MulR6(TMP, lhs_high, rhs_low); |
| 8203 | __ MulR6(dst_high, lhs_low, rhs_high); |
| 8204 | __ Addu(dst_high, dst_high, TMP); |
| 8205 | __ MuhuR6(TMP, lhs_low, rhs_low); |
| 8206 | __ Addu(dst_high, dst_high, TMP); |
| 8207 | __ MulR6(dst_low, lhs_low, rhs_low); |
| 8208 | } else { |
| 8209 | __ MulR2(TMP, lhs_high, rhs_low); |
| 8210 | __ MulR2(dst_high, lhs_low, rhs_high); |
| 8211 | __ Addu(dst_high, dst_high, TMP); |
| 8212 | __ MultuR2(lhs_low, rhs_low); |
| 8213 | __ Mfhi(TMP); |
| 8214 | __ Addu(dst_high, dst_high, TMP); |
| 8215 | __ Mflo(dst_low); |
| 8216 | } |
| 8217 | break; |
| 8218 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8219 | case DataType::Type::kFloat32: |
| 8220 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8221 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8222 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8223 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8224 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8225 | __ MulS(dst, lhs, rhs); |
| 8226 | } else { |
| 8227 | __ MulD(dst, lhs, rhs); |
| 8228 | } |
| 8229 | break; |
| 8230 | } |
| 8231 | default: |
| 8232 | LOG(FATAL) << "Unexpected mul type " << type; |
| 8233 | } |
| 8234 | } |
| 8235 | |
| 8236 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { |
| 8237 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8238 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8239 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8240 | case DataType::Type::kInt32: |
| 8241 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8242 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8243 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8244 | break; |
| 8245 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8246 | case DataType::Type::kFloat32: |
| 8247 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8248 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8249 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8250 | break; |
| 8251 | |
| 8252 | default: |
| 8253 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 8254 | } |
| 8255 | } |
| 8256 | |
| 8257 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8258 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8259 | LocationSummary* locations = instruction->GetLocations(); |
| 8260 | |
| 8261 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8262 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8263 | Register dst = locations->Out().AsRegister<Register>(); |
| 8264 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8265 | __ Subu(dst, ZERO, src); |
| 8266 | break; |
| 8267 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8268 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8269 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8270 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8271 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8272 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8273 | __ Subu(dst_low, ZERO, src_low); |
| 8274 | __ Sltu(TMP, ZERO, dst_low); |
| 8275 | __ Subu(dst_high, ZERO, src_high); |
| 8276 | __ Subu(dst_high, dst_high, TMP); |
| 8277 | break; |
| 8278 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8279 | case DataType::Type::kFloat32: |
| 8280 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8281 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8282 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8283 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8284 | __ NegS(dst, src); |
| 8285 | } else { |
| 8286 | __ NegD(dst, src); |
| 8287 | } |
| 8288 | break; |
| 8289 | } |
| 8290 | default: |
| 8291 | LOG(FATAL) << "Unexpected neg type " << type; |
| 8292 | } |
| 8293 | } |
| 8294 | |
| 8295 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8296 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8297 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8298 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8299 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8300 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8301 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8302 | } |
| 8303 | |
| 8304 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8305 | // Note: if heap poisoning is enabled, the entry point takes care |
| 8306 | // of poisoning the reference. |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8307 | QuickEntrypointEnum entrypoint = |
| 8308 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 8309 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8310 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8311 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8312 | } |
| 8313 | |
| 8314 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8315 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8316 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8317 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8318 | if (instruction->IsStringAlloc()) { |
| 8319 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 8320 | } else { |
| 8321 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8322 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8323 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8324 | } |
| 8325 | |
| 8326 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8327 | // Note: if heap poisoning is enabled, the entry point takes care |
| 8328 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8329 | if (instruction->IsStringAlloc()) { |
| 8330 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 8331 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8332 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8333 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 8334 | __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value()); |
| 8335 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 8336 | __ NopIfNoReordering(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8337 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 8338 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8339 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 8340 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8341 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8342 | } |
| 8343 | |
| 8344 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8345 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8346 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8347 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8348 | } |
| 8349 | |
| 8350 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8351 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8352 | LocationSummary* locations = instruction->GetLocations(); |
| 8353 | |
| 8354 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8355 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8356 | Register dst = locations->Out().AsRegister<Register>(); |
| 8357 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8358 | __ Nor(dst, src, ZERO); |
| 8359 | break; |
| 8360 | } |
| 8361 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8362 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8363 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8364 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8365 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8366 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8367 | __ Nor(dst_high, src_high, ZERO); |
| 8368 | __ Nor(dst_low, src_low, ZERO); |
| 8369 | break; |
| 8370 | } |
| 8371 | |
| 8372 | default: |
| 8373 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 8374 | } |
| 8375 | } |
| 8376 | |
| 8377 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8378 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8379 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8380 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8381 | } |
| 8382 | |
| 8383 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 8384 | LocationSummary* locations = instruction->GetLocations(); |
| 8385 | __ Xori(locations->Out().AsRegister<Register>(), |
| 8386 | locations->InAt(0).AsRegister<Register>(), |
| 8387 | 1); |
| 8388 | } |
| 8389 | |
| 8390 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 8391 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 8392 | locations->SetInAt(0, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8393 | } |
| 8394 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8395 | void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 8396 | if (CanMoveNullCheckToUser(instruction)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8397 | return; |
| 8398 | } |
| 8399 | Location obj = instruction->GetLocations()->InAt(0); |
| 8400 | |
| 8401 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8402 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8403 | } |
| 8404 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8405 | void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8406 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) NullCheckSlowPathMIPS(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8407 | AddSlowPath(slow_path); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8408 | |
| 8409 | Location obj = instruction->GetLocations()->InAt(0); |
| 8410 | |
| 8411 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8412 | } |
| 8413 | |
| 8414 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8415 | codegen_->GenerateNullCheck(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8416 | } |
| 8417 | |
| 8418 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { |
| 8419 | HandleBinaryOp(instruction); |
| 8420 | } |
| 8421 | |
| 8422 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { |
| 8423 | HandleBinaryOp(instruction); |
| 8424 | } |
| 8425 | |
| 8426 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 8427 | LOG(FATAL) << "Unreachable"; |
| 8428 | } |
| 8429 | |
| 8430 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 8431 | if (instruction->GetNext()->IsSuspendCheck() && |
| 8432 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 8433 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 8434 | // The back edge will generate the suspend check. |
| 8435 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 8436 | } |
| 8437 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8438 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 8439 | } |
| 8440 | |
| 8441 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8442 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8443 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 8444 | if (location.IsStackSlot()) { |
| 8445 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8446 | } else if (location.IsDoubleStackSlot()) { |
| 8447 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8448 | } |
| 8449 | locations->SetOut(location); |
| 8450 | } |
| 8451 | |
| 8452 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction |
| 8453 | ATTRIBUTE_UNUSED) { |
| 8454 | // Nothing to do, the parameter is already at its location. |
| 8455 | } |
| 8456 | |
| 8457 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 8458 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8459 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8460 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 8461 | } |
| 8462 | |
| 8463 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction |
| 8464 | ATTRIBUTE_UNUSED) { |
| 8465 | // Nothing to do, the method is already at its location. |
| 8466 | } |
| 8467 | |
| 8468 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8469 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 8470 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8471 | locations->SetInAt(i, Location::Any()); |
| 8472 | } |
| 8473 | locations->SetOut(Location::Any()); |
| 8474 | } |
| 8475 | |
| 8476 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 8477 | LOG(FATAL) << "Unreachable"; |
| 8478 | } |
| 8479 | |
| 8480 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8481 | DataType::Type type = rem->GetResultType(); |
| 8482 | LocationSummary::CallKind call_kind = (type == DataType::Type::kInt32) |
| 8483 | ? LocationSummary::kNoCall |
| 8484 | : LocationSummary::kCallOnMainOnly; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8485 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8486 | |
| 8487 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8488 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8489 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8490 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8491 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8492 | break; |
| 8493 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8494 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8495 | InvokeRuntimeCallingConvention calling_convention; |
| 8496 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 8497 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 8498 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 8499 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 8500 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8501 | break; |
| 8502 | } |
| 8503 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8504 | case DataType::Type::kFloat32: |
| 8505 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8506 | InvokeRuntimeCallingConvention calling_convention; |
| 8507 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 8508 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 8509 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8510 | break; |
| 8511 | } |
| 8512 | |
| 8513 | default: |
| 8514 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8515 | } |
| 8516 | } |
| 8517 | |
| 8518 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8519 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8520 | |
| 8521 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8522 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8523 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8524 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8525 | case DataType::Type::kInt64: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8526 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8527 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 8528 | break; |
| 8529 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8530 | case DataType::Type::kFloat32: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8531 | codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8532 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8533 | break; |
| 8534 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8535 | case DataType::Type::kFloat64: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8536 | codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8537 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8538 | break; |
| 8539 | } |
| 8540 | default: |
| 8541 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8542 | } |
| 8543 | } |
| 8544 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8545 | void LocationsBuilderMIPS::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 8546 | constructor_fence->SetLocations(nullptr); |
| 8547 | } |
| 8548 | |
| 8549 | void InstructionCodeGeneratorMIPS::VisitConstructorFence( |
| 8550 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 8551 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 8552 | } |
| 8553 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8554 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 8555 | memory_barrier->SetLocations(nullptr); |
| 8556 | } |
| 8557 | |
| 8558 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 8559 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 8560 | } |
| 8561 | |
| 8562 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8563 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8564 | DataType::Type return_type = ret->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8565 | locations->SetInAt(0, MipsReturnLocation(return_type)); |
| 8566 | } |
| 8567 | |
| 8568 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 8569 | codegen_->GenerateFrameExit(); |
| 8570 | } |
| 8571 | |
| 8572 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { |
| 8573 | ret->SetLocations(nullptr); |
| 8574 | } |
| 8575 | |
| 8576 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 8577 | codegen_->GenerateFrameExit(); |
| 8578 | } |
| 8579 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 8580 | void LocationsBuilderMIPS::VisitRor(HRor* ror) { |
| 8581 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 8582 | } |
| 8583 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 8584 | void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) { |
| 8585 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 8586 | } |
| 8587 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8588 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { |
| 8589 | HandleShift(shl); |
| 8590 | } |
| 8591 | |
| 8592 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { |
| 8593 | HandleShift(shl); |
| 8594 | } |
| 8595 | |
| 8596 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { |
| 8597 | HandleShift(shr); |
| 8598 | } |
| 8599 | |
| 8600 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { |
| 8601 | HandleShift(shr); |
| 8602 | } |
| 8603 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8604 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { |
| 8605 | HandleBinaryOp(instruction); |
| 8606 | } |
| 8607 | |
| 8608 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { |
| 8609 | HandleBinaryOp(instruction); |
| 8610 | } |
| 8611 | |
| 8612 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 8613 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 8614 | } |
| 8615 | |
| 8616 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 8617 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 8618 | } |
| 8619 | |
| 8620 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 8621 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 8622 | } |
| 8623 | |
| 8624 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 8625 | HandleFieldSet(instruction, |
| 8626 | instruction->GetFieldInfo(), |
| 8627 | instruction->GetDexPc(), |
| 8628 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8629 | } |
| 8630 | |
| 8631 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( |
| 8632 | HUnresolvedInstanceFieldGet* instruction) { |
| 8633 | FieldAccessCallingConventionMIPS calling_convention; |
| 8634 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8635 | instruction->GetFieldType(), |
| 8636 | calling_convention); |
| 8637 | } |
| 8638 | |
| 8639 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( |
| 8640 | HUnresolvedInstanceFieldGet* instruction) { |
| 8641 | FieldAccessCallingConventionMIPS calling_convention; |
| 8642 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8643 | instruction->GetFieldType(), |
| 8644 | instruction->GetFieldIndex(), |
| 8645 | instruction->GetDexPc(), |
| 8646 | calling_convention); |
| 8647 | } |
| 8648 | |
| 8649 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( |
| 8650 | HUnresolvedInstanceFieldSet* instruction) { |
| 8651 | FieldAccessCallingConventionMIPS calling_convention; |
| 8652 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8653 | instruction->GetFieldType(), |
| 8654 | calling_convention); |
| 8655 | } |
| 8656 | |
| 8657 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( |
| 8658 | HUnresolvedInstanceFieldSet* instruction) { |
| 8659 | FieldAccessCallingConventionMIPS calling_convention; |
| 8660 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8661 | instruction->GetFieldType(), |
| 8662 | instruction->GetFieldIndex(), |
| 8663 | instruction->GetDexPc(), |
| 8664 | calling_convention); |
| 8665 | } |
| 8666 | |
| 8667 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( |
| 8668 | HUnresolvedStaticFieldGet* instruction) { |
| 8669 | FieldAccessCallingConventionMIPS calling_convention; |
| 8670 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8671 | instruction->GetFieldType(), |
| 8672 | calling_convention); |
| 8673 | } |
| 8674 | |
| 8675 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( |
| 8676 | HUnresolvedStaticFieldGet* instruction) { |
| 8677 | FieldAccessCallingConventionMIPS calling_convention; |
| 8678 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8679 | instruction->GetFieldType(), |
| 8680 | instruction->GetFieldIndex(), |
| 8681 | instruction->GetDexPc(), |
| 8682 | calling_convention); |
| 8683 | } |
| 8684 | |
| 8685 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( |
| 8686 | HUnresolvedStaticFieldSet* instruction) { |
| 8687 | FieldAccessCallingConventionMIPS calling_convention; |
| 8688 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8689 | instruction->GetFieldType(), |
| 8690 | calling_convention); |
| 8691 | } |
| 8692 | |
| 8693 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( |
| 8694 | HUnresolvedStaticFieldSet* instruction) { |
| 8695 | FieldAccessCallingConventionMIPS calling_convention; |
| 8696 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8697 | instruction->GetFieldType(), |
| 8698 | instruction->GetFieldIndex(), |
| 8699 | instruction->GetDexPc(), |
| 8700 | calling_convention); |
| 8701 | } |
| 8702 | |
| 8703 | void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8704 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8705 | instruction, LocationSummary::kCallOnSlowPath); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 8706 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 8707 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 8708 | // registers in full width (since the runtime only saves/restores lower part). |
| 8709 | locations->SetCustomSlowPathCallerSaves( |
| 8710 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8711 | } |
| 8712 | |
| 8713 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 8714 | HBasicBlock* block = instruction->GetBlock(); |
| 8715 | if (block->GetLoopInformation() != nullptr) { |
| 8716 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 8717 | // The back edge will generate the suspend check. |
| 8718 | return; |
| 8719 | } |
| 8720 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 8721 | // The goto will generate the suspend check. |
| 8722 | return; |
| 8723 | } |
| 8724 | GenerateSuspendCheck(instruction, nullptr); |
| 8725 | } |
| 8726 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8727 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8728 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8729 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8730 | InvokeRuntimeCallingConvention calling_convention; |
| 8731 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8732 | } |
| 8733 | |
| 8734 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8735 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8736 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 8737 | } |
| 8738 | |
| 8739 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8740 | DataType::Type input_type = conversion->GetInputType(); |
| 8741 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 8742 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 8743 | << input_type << " -> " << result_type; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8744 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8745 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8746 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 8747 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8748 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 8749 | } |
| 8750 | |
| 8751 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8752 | if (!isR6 && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8753 | ((DataType::IsFloatingPointType(result_type) && input_type == DataType::Type::kInt64) || |
| 8754 | (result_type == DataType::Type::kInt64 && DataType::IsFloatingPointType(input_type)))) { |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 8755 | call_kind = LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8756 | } |
| 8757 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8758 | LocationSummary* locations = |
| 8759 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8760 | |
| 8761 | if (call_kind == LocationSummary::kNoCall) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8762 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8763 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8764 | } else { |
| 8765 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8766 | } |
| 8767 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8768 | if (DataType::IsFloatingPointType(result_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8769 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8770 | } else { |
| 8771 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8772 | } |
| 8773 | } else { |
| 8774 | InvokeRuntimeCallingConvention calling_convention; |
| 8775 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8776 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8777 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 8778 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8779 | DCHECK_EQ(input_type, DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8780 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 8781 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 8782 | } |
| 8783 | |
| 8784 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 8785 | } |
| 8786 | } |
| 8787 | |
| 8788 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 8789 | LocationSummary* locations = conversion->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8790 | DataType::Type result_type = conversion->GetResultType(); |
| 8791 | DataType::Type input_type = conversion->GetInputType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8792 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8793 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8794 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 8795 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 8796 | << input_type << " -> " << result_type; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8797 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8798 | if (result_type == DataType::Type::kInt64 && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8799 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8800 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8801 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8802 | |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 8803 | if (dst_low != src) { |
| 8804 | __ Move(dst_low, src); |
| 8805 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8806 | __ Sra(dst_high, src, 31); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8807 | } else if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8808 | Register dst = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8809 | Register src = (input_type == DataType::Type::kInt64) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8810 | ? locations->InAt(0).AsRegisterPairLow<Register>() |
| 8811 | : locations->InAt(0).AsRegister<Register>(); |
| 8812 | |
| 8813 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 8814 | case DataType::Type::kUint8: |
| 8815 | __ Andi(dst, src, 0xFF); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8816 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8817 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8818 | if (has_sign_extension) { |
| 8819 | __ Seb(dst, src); |
| 8820 | } else { |
| 8821 | __ Sll(dst, src, 24); |
| 8822 | __ Sra(dst, dst, 24); |
| 8823 | } |
| 8824 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 8825 | case DataType::Type::kUint16: |
| 8826 | __ Andi(dst, src, 0xFFFF); |
| 8827 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8828 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8829 | if (has_sign_extension) { |
| 8830 | __ Seh(dst, src); |
| 8831 | } else { |
| 8832 | __ Sll(dst, src, 16); |
| 8833 | __ Sra(dst, dst, 16); |
| 8834 | } |
| 8835 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8836 | case DataType::Type::kInt32: |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 8837 | if (dst != src) { |
| 8838 | __ Move(dst, src); |
| 8839 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8840 | break; |
| 8841 | |
| 8842 | default: |
| 8843 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 8844 | << " to " << result_type; |
| 8845 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8846 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
| 8847 | if (input_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8848 | if (isR6) { |
| 8849 | // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 8850 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 8851 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8852 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8853 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8854 | __ Mtc1(src_low, FTMP); |
| 8855 | __ Mthc1(src_high, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8856 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8857 | __ Cvtsl(dst, FTMP); |
| 8858 | } else { |
| 8859 | __ Cvtdl(dst, FTMP); |
| 8860 | } |
| 8861 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8862 | QuickEntrypointEnum entrypoint = |
| 8863 | (result_type == DataType::Type::kFloat32) ? kQuickL2f : kQuickL2d; |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8864 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8865 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8866 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 8867 | } else { |
| 8868 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 8869 | } |
| 8870 | } |
| 8871 | } else { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8872 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8873 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8874 | __ Mtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8875 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8876 | __ Cvtsw(dst, FTMP); |
| 8877 | } else { |
| 8878 | __ Cvtdw(dst, FTMP); |
| 8879 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8880 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8881 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 8882 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8883 | |
| 8884 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum |
| 8885 | // value of the output type if the input is outside of the range after the truncation or |
| 8886 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct |
| 8887 | // results. This matches the desired float/double-to-int/long conversion exactly. |
| 8888 | // |
| 8889 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive |
| 8890 | // value when the input is either a NaN or is outside of the range of the output type |
| 8891 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce |
| 8892 | // the same result. |
| 8893 | // |
| 8894 | // The code takes care of the different behaviors by first comparing the input to the |
| 8895 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). |
| 8896 | // If the input is greater than or equal to the minimum, it procedes to the truncate |
| 8897 | // instruction, which will handle such an input the same way irrespective of NAN2008. |
| 8898 | // Otherwise the input is compared to itself to determine whether it is a NaN or not |
| 8899 | // in order to return either zero or the minimum value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8900 | if (result_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8901 | if (isR6) { |
| 8902 | // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 8903 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 8904 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8905 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8906 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8907 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8908 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8909 | __ TruncLS(FTMP, src); |
| 8910 | } else { |
| 8911 | __ TruncLD(FTMP, src); |
| 8912 | } |
| 8913 | __ Mfc1(dst_low, FTMP); |
| 8914 | __ Mfhc1(dst_high, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8915 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8916 | QuickEntrypointEnum entrypoint = |
| 8917 | (input_type == DataType::Type::kFloat32) ? kQuickF2l : kQuickD2l; |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8918 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8919 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8920 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 8921 | } else { |
| 8922 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 8923 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8924 | } |
| 8925 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8926 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8927 | Register dst = locations->Out().AsRegister<Register>(); |
| 8928 | MipsLabel truncate; |
| 8929 | MipsLabel done; |
| 8930 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8931 | if (!isR6) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8932 | if (input_type == DataType::Type::kFloat32) { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8933 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); |
| 8934 | __ LoadConst32(TMP, min_val); |
| 8935 | __ Mtc1(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8936 | } else { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8937 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); |
| 8938 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 8939 | __ Mtc1(ZERO, FTMP); |
| 8940 | __ MoveToFpuHigh(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8941 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8942 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8943 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8944 | __ ColeS(0, FTMP, src); |
| 8945 | } else { |
| 8946 | __ ColeD(0, FTMP, src); |
| 8947 | } |
| 8948 | __ Bc1t(0, &truncate); |
| 8949 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8950 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8951 | __ CeqS(0, src, src); |
| 8952 | } else { |
| 8953 | __ CeqD(0, src, src); |
| 8954 | } |
| 8955 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 8956 | __ Movf(dst, ZERO, 0); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8957 | |
| 8958 | __ B(&done); |
| 8959 | |
| 8960 | __ Bind(&truncate); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8961 | } |
| 8962 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8963 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8964 | __ TruncWS(FTMP, src); |
| 8965 | } else { |
| 8966 | __ TruncWD(FTMP, src); |
| 8967 | } |
| 8968 | __ Mfc1(dst, FTMP); |
| 8969 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8970 | if (!isR6) { |
| 8971 | __ Bind(&done); |
| 8972 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8973 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8974 | } else if (DataType::IsFloatingPointType(result_type) && |
| 8975 | DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8976 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8977 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8978 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8979 | __ Cvtsd(dst, src); |
| 8980 | } else { |
| 8981 | __ Cvtds(dst, src); |
| 8982 | } |
| 8983 | } else { |
| 8984 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 8985 | << " to " << result_type; |
| 8986 | } |
| 8987 | } |
| 8988 | |
| 8989 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { |
| 8990 | HandleShift(ushr); |
| 8991 | } |
| 8992 | |
| 8993 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { |
| 8994 | HandleShift(ushr); |
| 8995 | } |
| 8996 | |
| 8997 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { |
| 8998 | HandleBinaryOp(instruction); |
| 8999 | } |
| 9000 | |
| 9001 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { |
| 9002 | HandleBinaryOp(instruction); |
| 9003 | } |
| 9004 | |
| 9005 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9006 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9007 | LOG(FATAL) << "Unreachable"; |
| 9008 | } |
| 9009 | |
| 9010 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9011 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9012 | LOG(FATAL) << "Unreachable"; |
| 9013 | } |
| 9014 | |
| 9015 | void LocationsBuilderMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9016 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9017 | } |
| 9018 | |
| 9019 | void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9020 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9021 | } |
| 9022 | |
| 9023 | void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9024 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9025 | } |
| 9026 | |
| 9027 | void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9028 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9029 | } |
| 9030 | |
| 9031 | void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9032 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9033 | } |
| 9034 | |
| 9035 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9036 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9037 | } |
| 9038 | |
| 9039 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9040 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9041 | } |
| 9042 | |
| 9043 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9044 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9045 | } |
| 9046 | |
| 9047 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9048 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9049 | } |
| 9050 | |
| 9051 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9052 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9053 | } |
| 9054 | |
| 9055 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9056 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9057 | } |
| 9058 | |
| 9059 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9060 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9061 | } |
| 9062 | |
| 9063 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9064 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9065 | } |
| 9066 | |
| 9067 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9068 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9069 | } |
| 9070 | |
| 9071 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9072 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9073 | } |
| 9074 | |
| 9075 | void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9076 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9077 | } |
| 9078 | |
| 9079 | void LocationsBuilderMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9080 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9081 | } |
| 9082 | |
| 9083 | void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9084 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9085 | } |
| 9086 | |
| 9087 | void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9088 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9089 | } |
| 9090 | |
| 9091 | void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9092 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9093 | } |
| 9094 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9095 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9096 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9097 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9098 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9099 | if (!codegen_->GetInstructionSetFeatures().IsR6()) { |
| 9100 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9101 | if (num_entries > InstructionCodeGeneratorMIPS::kPackedSwitchJumpTableThreshold) { |
| 9102 | // When there's no HMipsComputeBaseMethodAddress input, R2 uses the NAL |
| 9103 | // instruction to simulate PC-relative addressing when accessing the jump table. |
| 9104 | // NAL clobbers RA. Make sure RA is preserved. |
| 9105 | codegen_->ClobberRA(); |
| 9106 | } |
| 9107 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9108 | } |
| 9109 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9110 | void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg, |
| 9111 | int32_t lower_bound, |
| 9112 | uint32_t num_entries, |
| 9113 | HBasicBlock* switch_block, |
| 9114 | HBasicBlock* default_block) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9115 | // Create a set of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9116 | Register temp_reg = TMP; |
| 9117 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
| 9118 | // Jump to default if index is negative |
| 9119 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 9120 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 9121 | __ Bltz(temp_reg, codegen_->GetLabelOf(default_block)); |
| 9122 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9123 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9124 | // Jump to successors[0] if value == lower_bound. |
| 9125 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 9126 | int32_t last_index = 0; |
| 9127 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9128 | __ Addiu(temp_reg, temp_reg, -2); |
| 9129 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9130 | __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9131 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9132 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9133 | } |
| 9134 | if (num_entries - last_index == 2) { |
| 9135 | // The last missing case_value. |
| 9136 | __ Addiu(temp_reg, temp_reg, -1); |
| 9137 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9138 | } |
| 9139 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9140 | // And the default for any other value. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9141 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9142 | __ B(codegen_->GetLabelOf(default_block)); |
| 9143 | } |
| 9144 | } |
| 9145 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9146 | void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg, |
| 9147 | Register constant_area, |
| 9148 | int32_t lower_bound, |
| 9149 | uint32_t num_entries, |
| 9150 | HBasicBlock* switch_block, |
| 9151 | HBasicBlock* default_block) { |
| 9152 | // Create a jump table. |
| 9153 | std::vector<MipsLabel*> labels(num_entries); |
| 9154 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 9155 | for (uint32_t i = 0; i < num_entries; i++) { |
| 9156 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 9157 | } |
| 9158 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 9159 | |
| 9160 | // Is the value in range? |
| 9161 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 9162 | if (IsInt<16>(static_cast<int32_t>(num_entries))) { |
| 9163 | __ Sltiu(AT, TMP, num_entries); |
| 9164 | __ Beqz(AT, codegen_->GetLabelOf(default_block)); |
| 9165 | } else { |
| 9166 | __ LoadConst32(AT, num_entries); |
| 9167 | __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 9168 | } |
| 9169 | |
| 9170 | // We are in the range of the table. |
| 9171 | // Load the target address from the jump table, indexing by the value. |
| 9172 | __ LoadLabelAddress(AT, constant_area, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 9173 | __ ShiftAndAdd(TMP, TMP, AT, 2, TMP); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9174 | __ Lw(TMP, TMP, 0); |
| 9175 | // Compute the absolute target address by adding the table start address |
| 9176 | // (the table contains offsets to targets relative to its start). |
| 9177 | __ Addu(TMP, TMP, AT); |
| 9178 | // And jump. |
| 9179 | __ Jr(TMP); |
| 9180 | __ NopIfNoReordering(); |
| 9181 | } |
| 9182 | |
| 9183 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9184 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9185 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9186 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9187 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 9188 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 9189 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9190 | |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9191 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9192 | // R6 uses PC-relative addressing to access the jump table. |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9193 | // |
| 9194 | // R2, OTOH, uses an HMipsComputeBaseMethodAddress input (when available) |
| 9195 | // to access the jump table and it is implemented by changing HPackedSwitch to |
| 9196 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress (see |
| 9197 | // VisitMipsPackedSwitch()). |
| 9198 | // |
| 9199 | // When there's no HMipsComputeBaseMethodAddress input (e.g. in presence of |
| 9200 | // irreducible loops), R2 uses the NAL instruction to simulate PC-relative |
| 9201 | // addressing. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9202 | GenTableBasedPackedSwitch(value_reg, |
| 9203 | ZERO, |
| 9204 | lower_bound, |
| 9205 | num_entries, |
| 9206 | switch_block, |
| 9207 | default_block); |
| 9208 | } else { |
| 9209 | GenPackedSwitchWithCompares(value_reg, |
| 9210 | lower_bound, |
| 9211 | num_entries, |
| 9212 | switch_block, |
| 9213 | default_block); |
| 9214 | } |
| 9215 | } |
| 9216 | |
| 9217 | void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 9218 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9219 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9220 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9221 | // Constant area pointer (HMipsComputeBaseMethodAddress). |
| 9222 | locations->SetInAt(1, Location::RequiresRegister()); |
| 9223 | } |
| 9224 | |
| 9225 | void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 9226 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9227 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9228 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9229 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 9230 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 9231 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 9232 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9233 | |
| 9234 | // This is an R2-only path. HPackedSwitch has been changed to |
| 9235 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress |
| 9236 | // required to address the jump table relative to PC. |
| 9237 | GenTableBasedPackedSwitch(value_reg, |
| 9238 | constant_area, |
| 9239 | lower_bound, |
| 9240 | num_entries, |
| 9241 | switch_block, |
| 9242 | default_block); |
| 9243 | } |
| 9244 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 9245 | void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress( |
| 9246 | HMipsComputeBaseMethodAddress* insn) { |
| 9247 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9248 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 9249 | locations->SetOut(Location::RequiresRegister()); |
| 9250 | } |
| 9251 | |
| 9252 | void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress( |
| 9253 | HMipsComputeBaseMethodAddress* insn) { |
| 9254 | LocationSummary* locations = insn->GetLocations(); |
| 9255 | Register reg = locations->Out().AsRegister<Register>(); |
| 9256 | |
| 9257 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 9258 | |
| 9259 | // Generate a dummy PC-relative call to obtain PC. |
| 9260 | __ Nal(); |
| 9261 | // Grab the return address off RA. |
| 9262 | __ Move(reg, RA); |
| 9263 | |
| 9264 | // Remember this offset (the obtained PC value) for later use with constant area. |
| 9265 | __ BindPcRelBaseLabel(); |
| 9266 | } |
| 9267 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9268 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 9269 | // The trampoline uses the same calling convention as dex calling conventions, |
| 9270 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 9271 | // the method_idx. |
| 9272 | HandleInvoke(invoke); |
| 9273 | } |
| 9274 | |
| 9275 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 9276 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 9277 | } |
| 9278 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9279 | void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 9280 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9281 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9282 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9283 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9284 | } |
| 9285 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9286 | void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 9287 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 9288 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9289 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9290 | instruction->GetIndex(), kMipsPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9291 | __ LoadFromOffset(kLoadWord, |
| 9292 | locations->Out().AsRegister<Register>(), |
| 9293 | locations->InAt(0).AsRegister<Register>(), |
| 9294 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9295 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9296 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 9297 | instruction->GetIndex(), kMipsPointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 9298 | __ LoadFromOffset(kLoadWord, |
| 9299 | locations->Out().AsRegister<Register>(), |
| 9300 | locations->InAt(0).AsRegister<Register>(), |
| 9301 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9302 | __ LoadFromOffset(kLoadWord, |
| 9303 | locations->Out().AsRegister<Register>(), |
| 9304 | locations->Out().AsRegister<Register>(), |
| 9305 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9306 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9307 | } |
| 9308 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 9309 | void LocationsBuilderMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 9310 | ATTRIBUTE_UNUSED) { |
| 9311 | LOG(FATAL) << "Unreachable"; |
| 9312 | } |
| 9313 | |
| 9314 | void InstructionCodeGeneratorMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 9315 | ATTRIBUTE_UNUSED) { |
| 9316 | LOG(FATAL) << "Unreachable"; |
| 9317 | } |
| 9318 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9319 | #undef __ |
| 9320 | #undef QUICK_ENTRY_POINT |
| 9321 | |
| 9322 | } // namespace mips |
| 9323 | } // namespace art |