Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_mips.h" |
| 18 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 19 | #include "arch/mips/asm_support_mips.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 20 | #include "arch/mips/entrypoints_direct_mips.h" |
| 21 | #include "arch/mips/instruction_set_features_mips.h" |
| 22 | #include "art_method.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 23 | #include "class_table.h" |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 24 | #include "code_generator_utils.h" |
Vladimir Marko | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 25 | #include "compiled_method.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 26 | #include "entrypoints/quick/quick_entrypoints.h" |
| 27 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| 28 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 29 | #include "heap_poisoning.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 30 | #include "intrinsics.h" |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 31 | #include "intrinsics_mips.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 32 | #include "linker/linker_patch.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 33 | #include "mirror/array-inl.h" |
| 34 | #include "mirror/class-inl.h" |
| 35 | #include "offsets.h" |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 36 | #include "stack_map_stream.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 37 | #include "thread.h" |
| 38 | #include "utils/assembler.h" |
| 39 | #include "utils/mips/assembler_mips.h" |
| 40 | #include "utils/stack_checks.h" |
| 41 | |
| 42 | namespace art { |
| 43 | namespace mips { |
| 44 | |
| 45 | static constexpr int kCurrentMethodStackOffset = 0; |
| 46 | static constexpr Register kMethodRegisterArgument = A0; |
| 47 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 48 | // Flags controlling the use of thunks for Baker read barriers. |
| 49 | constexpr bool kBakerReadBarrierThunksEnableForFields = true; |
| 50 | constexpr bool kBakerReadBarrierThunksEnableForArrays = true; |
| 51 | constexpr bool kBakerReadBarrierThunksEnableForGcRoots = true; |
| 52 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 53 | Location MipsReturnLocation(DataType::Type return_type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 54 | switch (return_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 55 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 56 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 57 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 58 | case DataType::Type::kInt8: |
| 59 | case DataType::Type::kUint16: |
| 60 | case DataType::Type::kInt16: |
| 61 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 62 | return Location::RegisterLocation(V0); |
| 63 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 64 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 65 | return Location::RegisterPairLocation(V0, V1); |
| 66 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 67 | case DataType::Type::kFloat32: |
| 68 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 69 | return Location::FpuRegisterLocation(F0); |
| 70 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 71 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 72 | return Location(); |
| 73 | } |
| 74 | UNREACHABLE(); |
| 75 | } |
| 76 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 77 | Location InvokeDexCallingConventionVisitorMIPS::GetReturnLocation(DataType::Type type) const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 78 | return MipsReturnLocation(type); |
| 79 | } |
| 80 | |
| 81 | Location InvokeDexCallingConventionVisitorMIPS::GetMethodLocation() const { |
| 82 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 83 | } |
| 84 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 85 | Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(DataType::Type type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 86 | Location next_location; |
| 87 | |
| 88 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 89 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 90 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 91 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 92 | case DataType::Type::kInt8: |
| 93 | case DataType::Type::kUint16: |
| 94 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 95 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 96 | uint32_t gp_index = gp_index_++; |
| 97 | if (gp_index < calling_convention.GetNumberOfRegisters()) { |
| 98 | next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index)); |
| 99 | } else { |
| 100 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 101 | next_location = Location::StackSlot(stack_offset); |
| 102 | } |
| 103 | break; |
| 104 | } |
| 105 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 106 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 107 | uint32_t gp_index = gp_index_; |
| 108 | gp_index_ += 2; |
| 109 | if (gp_index + 1 < calling_convention.GetNumberOfRegisters()) { |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 110 | Register reg = calling_convention.GetRegisterAt(gp_index); |
| 111 | if (reg == A1 || reg == A3) { |
| 112 | gp_index_++; // Skip A1(A3), and use A2_A3(T0_T1) instead. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 113 | gp_index++; |
| 114 | } |
| 115 | Register low_even = calling_convention.GetRegisterAt(gp_index); |
| 116 | Register high_odd = calling_convention.GetRegisterAt(gp_index + 1); |
| 117 | DCHECK_EQ(low_even + 1, high_odd); |
| 118 | next_location = Location::RegisterPairLocation(low_even, high_odd); |
| 119 | } else { |
| 120 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 121 | next_location = Location::DoubleStackSlot(stack_offset); |
| 122 | } |
| 123 | break; |
| 124 | } |
| 125 | |
| 126 | // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double |
| 127 | // will take up the even/odd pair, while floats are stored in even regs only. |
| 128 | // On 64 bit FPU, both double and float are stored in even registers only. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 129 | case DataType::Type::kFloat32: |
| 130 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 131 | uint32_t float_index = float_index_++; |
| 132 | if (float_index < calling_convention.GetNumberOfFpuRegisters()) { |
| 133 | next_location = Location::FpuRegisterLocation( |
| 134 | calling_convention.GetFpuRegisterAt(float_index)); |
| 135 | } else { |
| 136 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 137 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 138 | : Location::StackSlot(stack_offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 139 | } |
| 140 | break; |
| 141 | } |
| 142 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 143 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 144 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 145 | break; |
| 146 | } |
| 147 | |
| 148 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 149 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 150 | |
| 151 | return next_location; |
| 152 | } |
| 153 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 154 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 155 | return MipsReturnLocation(type); |
| 156 | } |
| 157 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 158 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 159 | #define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 160 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 161 | |
| 162 | class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 163 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 164 | explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 165 | |
| 166 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 167 | LocationSummary* locations = instruction_->GetLocations(); |
| 168 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 169 | __ Bind(GetEntryLabel()); |
| 170 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 171 | // Live registers will be restored in the catch block if caught. |
| 172 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 173 | } |
| 174 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 175 | // move resolver. |
| 176 | InvokeRuntimeCallingConvention calling_convention; |
| 177 | codegen->EmitParallelMoves(locations->InAt(0), |
| 178 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 179 | DataType::Type::kInt32, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 180 | locations->InAt(1), |
| 181 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 182 | DataType::Type::kInt32); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 183 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 184 | ? kQuickThrowStringBounds |
| 185 | : kQuickThrowArrayBounds; |
| 186 | mips_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 187 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 188 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 189 | } |
| 190 | |
| 191 | bool IsFatal() const OVERRIDE { return true; } |
| 192 | |
| 193 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; } |
| 194 | |
| 195 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 196 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS); |
| 197 | }; |
| 198 | |
| 199 | class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 200 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 201 | explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 202 | |
| 203 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 204 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 205 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 206 | mips_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 207 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 208 | } |
| 209 | |
| 210 | bool IsFatal() const OVERRIDE { return true; } |
| 211 | |
| 212 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; } |
| 213 | |
| 214 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 215 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS); |
| 216 | }; |
| 217 | |
| 218 | class LoadClassSlowPathMIPS : public SlowPathCodeMIPS { |
| 219 | public: |
| 220 | LoadClassSlowPathMIPS(HLoadClass* cls, |
| 221 | HInstruction* at, |
| 222 | uint32_t dex_pc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 223 | bool do_clinit) |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 224 | : SlowPathCodeMIPS(at), |
| 225 | cls_(cls), |
| 226 | dex_pc_(dex_pc), |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 227 | do_clinit_(do_clinit) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 228 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 229 | } |
| 230 | |
| 231 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 232 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 233 | Location out = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 234 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 235 | InvokeRuntimeCallingConvention calling_convention; |
| 236 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 237 | __ Bind(GetEntryLabel()); |
| 238 | SaveLiveRegisters(codegen, locations); |
| 239 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 240 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 241 | __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 242 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 243 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 244 | mips_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 245 | if (do_clinit_) { |
| 246 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 247 | } else { |
| 248 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 249 | } |
| 250 | |
| 251 | // Move the class to the desired location. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 252 | if (out.IsValid()) { |
| 253 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 254 | DataType::Type type = instruction_->GetType(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 255 | mips_codegen->MoveLocation(out, |
| 256 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 257 | type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 258 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 259 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 260 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 261 | __ B(GetExitLabel()); |
| 262 | } |
| 263 | |
| 264 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; } |
| 265 | |
| 266 | private: |
| 267 | // The class this slow path will load. |
| 268 | HLoadClass* const cls_; |
| 269 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 270 | // The dex PC of `at_`. |
| 271 | const uint32_t dex_pc_; |
| 272 | |
| 273 | // Whether to initialize the class. |
| 274 | const bool do_clinit_; |
| 275 | |
| 276 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS); |
| 277 | }; |
| 278 | |
| 279 | class LoadStringSlowPathMIPS : public SlowPathCodeMIPS { |
| 280 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 281 | explicit LoadStringSlowPathMIPS(HLoadString* instruction) |
| 282 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 283 | |
| 284 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 285 | DCHECK(instruction_->IsLoadString()); |
| 286 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 287 | LocationSummary* locations = instruction_->GetLocations(); |
| 288 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 289 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 290 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 291 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 292 | __ Bind(GetEntryLabel()); |
| 293 | SaveLiveRegisters(codegen, locations); |
| 294 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 295 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 296 | mips_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 297 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 298 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 299 | DataType::Type type = instruction_->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 300 | mips_codegen->MoveLocation(locations->Out(), |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 301 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 302 | type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 303 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 304 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 305 | __ B(GetExitLabel()); |
| 306 | } |
| 307 | |
| 308 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; } |
| 309 | |
| 310 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 311 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS); |
| 312 | }; |
| 313 | |
| 314 | class NullCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 315 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 316 | explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 317 | |
| 318 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 319 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 320 | __ Bind(GetEntryLabel()); |
| 321 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 322 | // Live registers will be restored in the catch block if caught. |
| 323 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 324 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 325 | mips_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 326 | instruction_, |
| 327 | instruction_->GetDexPc(), |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 328 | this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 329 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 330 | } |
| 331 | |
| 332 | bool IsFatal() const OVERRIDE { return true; } |
| 333 | |
| 334 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; } |
| 335 | |
| 336 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 337 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS); |
| 338 | }; |
| 339 | |
| 340 | class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 341 | public: |
| 342 | SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 343 | : SlowPathCodeMIPS(instruction), successor_(successor) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 344 | |
| 345 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 346 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 347 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 348 | __ Bind(GetEntryLabel()); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 349 | SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD. |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 350 | mips_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 351 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 352 | RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 353 | if (successor_ == nullptr) { |
| 354 | __ B(GetReturnLabel()); |
| 355 | } else { |
| 356 | __ B(mips_codegen->GetLabelOf(successor_)); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | MipsLabel* GetReturnLabel() { |
| 361 | DCHECK(successor_ == nullptr); |
| 362 | return &return_label_; |
| 363 | } |
| 364 | |
| 365 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; } |
| 366 | |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 367 | HBasicBlock* GetSuccessor() const { |
| 368 | return successor_; |
| 369 | } |
| 370 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 371 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 372 | // If not null, the block to branch to after the suspend check. |
| 373 | HBasicBlock* const successor_; |
| 374 | |
| 375 | // If `successor_` is null, the label to branch to after the suspend check. |
| 376 | MipsLabel return_label_; |
| 377 | |
| 378 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS); |
| 379 | }; |
| 380 | |
| 381 | class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 382 | public: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 383 | explicit TypeCheckSlowPathMIPS(HInstruction* instruction, bool is_fatal) |
| 384 | : SlowPathCodeMIPS(instruction), is_fatal_(is_fatal) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 385 | |
| 386 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 387 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 388 | uint32_t dex_pc = instruction_->GetDexPc(); |
| 389 | DCHECK(instruction_->IsCheckCast() |
| 390 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 391 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 392 | |
| 393 | __ Bind(GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 394 | if (!is_fatal_) { |
| 395 | SaveLiveRegisters(codegen, locations); |
| 396 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 397 | |
| 398 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 399 | // move resolver. |
| 400 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 401 | codegen->EmitParallelMoves(locations->InAt(0), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 402 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 403 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 404 | locations->InAt(1), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 405 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 406 | DataType::Type::kReference); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 407 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 408 | mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 409 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 410 | DataType::Type ret_type = instruction_->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 411 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 412 | mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 413 | } else { |
| 414 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 415 | mips_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 416 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 419 | if (!is_fatal_) { |
| 420 | RestoreLiveRegisters(codegen, locations); |
| 421 | __ B(GetExitLabel()); |
| 422 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; } |
| 426 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 427 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 428 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 429 | private: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 430 | const bool is_fatal_; |
| 431 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 432 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS); |
| 433 | }; |
| 434 | |
| 435 | class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS { |
| 436 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 437 | explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 438 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 439 | |
| 440 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 441 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 442 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 443 | LocationSummary* locations = instruction_->GetLocations(); |
| 444 | SaveLiveRegisters(codegen, locations); |
| 445 | InvokeRuntimeCallingConvention calling_convention; |
| 446 | __ LoadConst32(calling_convention.GetRegisterAt(0), |
| 447 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 448 | mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 449 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; } |
| 453 | |
| 454 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 455 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS); |
| 456 | }; |
| 457 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 458 | class ArraySetSlowPathMIPS : public SlowPathCodeMIPS { |
| 459 | public: |
| 460 | explicit ArraySetSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {} |
| 461 | |
| 462 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 463 | LocationSummary* locations = instruction_->GetLocations(); |
| 464 | __ Bind(GetEntryLabel()); |
| 465 | SaveLiveRegisters(codegen, locations); |
| 466 | |
| 467 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 468 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 469 | parallel_move.AddMove( |
| 470 | locations->InAt(0), |
| 471 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 472 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 473 | nullptr); |
| 474 | parallel_move.AddMove( |
| 475 | locations->InAt(1), |
| 476 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 477 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 478 | nullptr); |
| 479 | parallel_move.AddMove( |
| 480 | locations->InAt(2), |
| 481 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 482 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 483 | nullptr); |
| 484 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 485 | |
| 486 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 487 | mips_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 488 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 489 | RestoreLiveRegisters(codegen, locations); |
| 490 | __ B(GetExitLabel()); |
| 491 | } |
| 492 | |
| 493 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS"; } |
| 494 | |
| 495 | private: |
| 496 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS); |
| 497 | }; |
| 498 | |
| 499 | // Slow path marking an object reference `ref` during a read |
| 500 | // barrier. The field `obj.field` in the object `obj` holding this |
| 501 | // reference does not get updated by this slow path after marking (see |
| 502 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS below for that). |
| 503 | // |
| 504 | // This means that after the execution of this slow path, `ref` will |
| 505 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 506 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 507 | // probably still be a from-space reference (unless it gets updated by |
| 508 | // another thread, or if another thread installed another object |
| 509 | // reference (different from `ref`) in `obj.field`). |
| 510 | // |
| 511 | // If `entrypoint` is a valid location it is assumed to already be |
| 512 | // holding the entrypoint. The case where the entrypoint is passed in |
| 513 | // is for the GcRoot read barrier. |
| 514 | class ReadBarrierMarkSlowPathMIPS : public SlowPathCodeMIPS { |
| 515 | public: |
| 516 | ReadBarrierMarkSlowPathMIPS(HInstruction* instruction, |
| 517 | Location ref, |
| 518 | Location entrypoint = Location::NoLocation()) |
| 519 | : SlowPathCodeMIPS(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 520 | DCHECK(kEmitCompilerReadBarrier); |
| 521 | } |
| 522 | |
| 523 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; } |
| 524 | |
| 525 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 526 | LocationSummary* locations = instruction_->GetLocations(); |
| 527 | Register ref_reg = ref_.AsRegister<Register>(); |
| 528 | DCHECK(locations->CanCall()); |
| 529 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 530 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 531 | instruction_->IsStaticFieldGet() || |
| 532 | instruction_->IsArrayGet() || |
| 533 | instruction_->IsArraySet() || |
| 534 | instruction_->IsLoadClass() || |
| 535 | instruction_->IsLoadString() || |
| 536 | instruction_->IsInstanceOf() || |
| 537 | instruction_->IsCheckCast() || |
| 538 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 539 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 540 | << "Unexpected instruction in read barrier marking slow path: " |
| 541 | << instruction_->DebugName(); |
| 542 | |
| 543 | __ Bind(GetEntryLabel()); |
| 544 | // No need to save live registers; it's taken care of by the |
| 545 | // entrypoint. Also, there is no need to update the stack mask, |
| 546 | // as this runtime call will not trigger a garbage collection. |
| 547 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 548 | DCHECK((V0 <= ref_reg && ref_reg <= T7) || |
| 549 | (S2 <= ref_reg && ref_reg <= S7) || |
| 550 | (ref_reg == FP)) << ref_reg; |
| 551 | // "Compact" slow path, saving two moves. |
| 552 | // |
| 553 | // Instead of using the standard runtime calling convention (input |
| 554 | // and output in A0 and V0 respectively): |
| 555 | // |
| 556 | // A0 <- ref |
| 557 | // V0 <- ReadBarrierMark(A0) |
| 558 | // ref <- V0 |
| 559 | // |
| 560 | // we just use rX (the register containing `ref`) as input and output |
| 561 | // of a dedicated entrypoint: |
| 562 | // |
| 563 | // rX <- ReadBarrierMarkRegX(rX) |
| 564 | // |
| 565 | if (entrypoint_.IsValid()) { |
| 566 | mips_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 567 | DCHECK_EQ(entrypoint_.AsRegister<Register>(), T9); |
| 568 | __ Jalr(entrypoint_.AsRegister<Register>()); |
| 569 | __ NopIfNoReordering(); |
| 570 | } else { |
| 571 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 572 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 573 | // This runtime call does not require a stack map. |
| 574 | mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 575 | instruction_, |
| 576 | this, |
| 577 | /* direct */ false); |
| 578 | } |
| 579 | __ B(GetExitLabel()); |
| 580 | } |
| 581 | |
| 582 | private: |
| 583 | // The location (register) of the marked object reference. |
| 584 | const Location ref_; |
| 585 | |
| 586 | // The location of the entrypoint if already loaded. |
| 587 | const Location entrypoint_; |
| 588 | |
| 589 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS); |
| 590 | }; |
| 591 | |
| 592 | // Slow path marking an object reference `ref` during a read barrier, |
| 593 | // and if needed, atomically updating the field `obj.field` in the |
| 594 | // object `obj` holding this reference after marking (contrary to |
| 595 | // ReadBarrierMarkSlowPathMIPS above, which never tries to update |
| 596 | // `obj.field`). |
| 597 | // |
| 598 | // This means that after the execution of this slow path, both `ref` |
| 599 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 600 | // hold the same to-space reference (unless another thread installed |
| 601 | // another object reference (different from `ref`) in `obj.field`). |
| 602 | class ReadBarrierMarkAndUpdateFieldSlowPathMIPS : public SlowPathCodeMIPS { |
| 603 | public: |
| 604 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(HInstruction* instruction, |
| 605 | Location ref, |
| 606 | Register obj, |
| 607 | Location field_offset, |
| 608 | Register temp1) |
| 609 | : SlowPathCodeMIPS(instruction), |
| 610 | ref_(ref), |
| 611 | obj_(obj), |
| 612 | field_offset_(field_offset), |
| 613 | temp1_(temp1) { |
| 614 | DCHECK(kEmitCompilerReadBarrier); |
| 615 | } |
| 616 | |
| 617 | const char* GetDescription() const OVERRIDE { |
| 618 | return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS"; |
| 619 | } |
| 620 | |
| 621 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 622 | LocationSummary* locations = instruction_->GetLocations(); |
| 623 | Register ref_reg = ref_.AsRegister<Register>(); |
| 624 | DCHECK(locations->CanCall()); |
| 625 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 626 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 627 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 628 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 629 | << instruction_->DebugName(); |
| 630 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 631 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 632 | DCHECK(field_offset_.IsRegisterPair()) << field_offset_; |
| 633 | |
| 634 | __ Bind(GetEntryLabel()); |
| 635 | |
| 636 | // Save the old reference. |
| 637 | // Note that we cannot use AT or TMP to save the old reference, as those |
| 638 | // are used by the code that follows, but we need the old reference after |
| 639 | // the call to the ReadBarrierMarkRegX entry point. |
| 640 | DCHECK_NE(temp1_, AT); |
| 641 | DCHECK_NE(temp1_, TMP); |
| 642 | __ Move(temp1_, ref_reg); |
| 643 | |
| 644 | // No need to save live registers; it's taken care of by the |
| 645 | // entrypoint. Also, there is no need to update the stack mask, |
| 646 | // as this runtime call will not trigger a garbage collection. |
| 647 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 648 | DCHECK((V0 <= ref_reg && ref_reg <= T7) || |
| 649 | (S2 <= ref_reg && ref_reg <= S7) || |
| 650 | (ref_reg == FP)) << ref_reg; |
| 651 | // "Compact" slow path, saving two moves. |
| 652 | // |
| 653 | // Instead of using the standard runtime calling convention (input |
| 654 | // and output in A0 and V0 respectively): |
| 655 | // |
| 656 | // A0 <- ref |
| 657 | // V0 <- ReadBarrierMark(A0) |
| 658 | // ref <- V0 |
| 659 | // |
| 660 | // we just use rX (the register containing `ref`) as input and output |
| 661 | // of a dedicated entrypoint: |
| 662 | // |
| 663 | // rX <- ReadBarrierMarkRegX(rX) |
| 664 | // |
| 665 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 666 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 667 | // This runtime call does not require a stack map. |
| 668 | mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 669 | instruction_, |
| 670 | this, |
| 671 | /* direct */ false); |
| 672 | |
| 673 | // If the new reference is different from the old reference, |
| 674 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 675 | // |
| 676 | // Note that this field could also hold a different object, if |
| 677 | // another thread had concurrently changed it. In that case, the |
| 678 | // the compare-and-set (CAS) loop below would abort, leaving the |
| 679 | // field as-is. |
| 680 | MipsLabel done; |
| 681 | __ Beq(temp1_, ref_reg, &done); |
| 682 | |
| 683 | // Update the the holder's field atomically. This may fail if |
| 684 | // mutator updates before us, but it's OK. This is achieved |
| 685 | // using a strong compare-and-set (CAS) operation with relaxed |
| 686 | // memory synchronization ordering, where the expected value is |
| 687 | // the old reference and the desired value is the new reference. |
| 688 | |
| 689 | // Convenience aliases. |
| 690 | Register base = obj_; |
| 691 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 692 | // offset ("long offset"), of which only the low part contains |
| 693 | // data. |
| 694 | Register offset = field_offset_.AsRegisterPairLow<Register>(); |
| 695 | Register expected = temp1_; |
| 696 | Register value = ref_reg; |
| 697 | Register tmp_ptr = TMP; // Pointer to actual memory. |
| 698 | Register tmp = AT; // Value in memory. |
| 699 | |
| 700 | __ Addu(tmp_ptr, base, offset); |
| 701 | |
| 702 | if (kPoisonHeapReferences) { |
| 703 | __ PoisonHeapReference(expected); |
| 704 | // Do not poison `value` if it is the same register as |
| 705 | // `expected`, which has just been poisoned. |
| 706 | if (value != expected) { |
| 707 | __ PoisonHeapReference(value); |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | // do { |
| 712 | // tmp = [r_ptr] - expected; |
| 713 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 714 | |
| 715 | bool is_r6 = mips_codegen->GetInstructionSetFeatures().IsR6(); |
| 716 | MipsLabel loop_head, exit_loop; |
| 717 | __ Bind(&loop_head); |
| 718 | if (is_r6) { |
| 719 | __ LlR6(tmp, tmp_ptr); |
| 720 | } else { |
| 721 | __ LlR2(tmp, tmp_ptr); |
| 722 | } |
| 723 | __ Bne(tmp, expected, &exit_loop); |
| 724 | __ Move(tmp, value); |
| 725 | if (is_r6) { |
| 726 | __ ScR6(tmp, tmp_ptr); |
| 727 | } else { |
| 728 | __ ScR2(tmp, tmp_ptr); |
| 729 | } |
| 730 | __ Beqz(tmp, &loop_head); |
| 731 | __ Bind(&exit_loop); |
| 732 | |
| 733 | if (kPoisonHeapReferences) { |
| 734 | __ UnpoisonHeapReference(expected); |
| 735 | // Do not unpoison `value` if it is the same register as |
| 736 | // `expected`, which has just been unpoisoned. |
| 737 | if (value != expected) { |
| 738 | __ UnpoisonHeapReference(value); |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | __ Bind(&done); |
| 743 | __ B(GetExitLabel()); |
| 744 | } |
| 745 | |
| 746 | private: |
| 747 | // The location (register) of the marked object reference. |
| 748 | const Location ref_; |
| 749 | // The register containing the object holding the marked object reference field. |
| 750 | const Register obj_; |
| 751 | // The location of the offset of the marked reference field within `obj_`. |
| 752 | Location field_offset_; |
| 753 | |
| 754 | const Register temp1_; |
| 755 | |
| 756 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS); |
| 757 | }; |
| 758 | |
| 759 | // Slow path generating a read barrier for a heap reference. |
| 760 | class ReadBarrierForHeapReferenceSlowPathMIPS : public SlowPathCodeMIPS { |
| 761 | public: |
| 762 | ReadBarrierForHeapReferenceSlowPathMIPS(HInstruction* instruction, |
| 763 | Location out, |
| 764 | Location ref, |
| 765 | Location obj, |
| 766 | uint32_t offset, |
| 767 | Location index) |
| 768 | : SlowPathCodeMIPS(instruction), |
| 769 | out_(out), |
| 770 | ref_(ref), |
| 771 | obj_(obj), |
| 772 | offset_(offset), |
| 773 | index_(index) { |
| 774 | DCHECK(kEmitCompilerReadBarrier); |
| 775 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 776 | // has been overwritten by (or after) the heap object reference load |
| 777 | // to be instrumented, e.g.: |
| 778 | // |
| 779 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 780 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 781 | // |
| 782 | // In that case, we have lost the information about the original |
| 783 | // object, and the emitted read barrier cannot work properly. |
| 784 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 785 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 786 | } |
| 787 | |
| 788 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 789 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 790 | LocationSummary* locations = instruction_->GetLocations(); |
| 791 | Register reg_out = out_.AsRegister<Register>(); |
| 792 | DCHECK(locations->CanCall()); |
| 793 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 794 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 795 | instruction_->IsStaticFieldGet() || |
| 796 | instruction_->IsArrayGet() || |
| 797 | instruction_->IsInstanceOf() || |
| 798 | instruction_->IsCheckCast() || |
| 799 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 800 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 801 | << instruction_->DebugName(); |
| 802 | |
| 803 | __ Bind(GetEntryLabel()); |
| 804 | SaveLiveRegisters(codegen, locations); |
| 805 | |
| 806 | // We may have to change the index's value, but as `index_` is a |
| 807 | // constant member (like other "inputs" of this slow path), |
| 808 | // introduce a copy of it, `index`. |
| 809 | Location index = index_; |
| 810 | if (index_.IsValid()) { |
| 811 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 812 | if (instruction_->IsArrayGet()) { |
| 813 | // Compute the actual memory offset and store it in `index`. |
| 814 | Register index_reg = index_.AsRegister<Register>(); |
| 815 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 816 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 817 | // We are about to change the value of `index_reg` (see the |
| 818 | // calls to art::mips::MipsAssembler::Sll and |
| 819 | // art::mips::MipsAssembler::Addiu32 below), but it has |
| 820 | // not been saved by the previous call to |
| 821 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 822 | // callee-save register -- |
| 823 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 824 | // callee-save registers, as it has been designed with the |
| 825 | // assumption that callee-save registers are supposed to be |
| 826 | // handled by the called function. So, as a callee-save |
| 827 | // register, `index_reg` _would_ eventually be saved onto |
| 828 | // the stack, but it would be too late: we would have |
| 829 | // changed its value earlier. Therefore, we manually save |
| 830 | // it here into another freely available register, |
| 831 | // `free_reg`, chosen of course among the caller-save |
| 832 | // registers (as a callee-save `free_reg` register would |
| 833 | // exhibit the same problem). |
| 834 | // |
| 835 | // Note we could have requested a temporary register from |
| 836 | // the register allocator instead; but we prefer not to, as |
| 837 | // this is a slow path, and we know we can find a |
| 838 | // caller-save register that is available. |
| 839 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 840 | __ Move(free_reg, index_reg); |
| 841 | index_reg = free_reg; |
| 842 | index = Location::RegisterLocation(index_reg); |
| 843 | } else { |
| 844 | // The initial register stored in `index_` has already been |
| 845 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 846 | // (as it is not a callee-save register), so we can freely |
| 847 | // use it. |
| 848 | } |
| 849 | // Shifting the index value contained in `index_reg` by the scale |
| 850 | // factor (2) cannot overflow in practice, as the runtime is |
| 851 | // unable to allocate object arrays with a size larger than |
| 852 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 853 | __ Sll(index_reg, index_reg, TIMES_4); |
| 854 | static_assert( |
| 855 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 856 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 857 | __ Addiu32(index_reg, index_reg, offset_); |
| 858 | } else { |
| 859 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 860 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 861 | // (as in the case of ArrayGet), as it is actually an offset |
| 862 | // to an object field within an object. |
| 863 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 864 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 865 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 866 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 867 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 868 | DCHECK_EQ(offset_, 0U); |
| 869 | DCHECK(index_.IsRegisterPair()); |
| 870 | // UnsafeGet's offset location is a register pair, the low |
| 871 | // part contains the correct offset. |
| 872 | index = index_.ToLow(); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | // We're moving two or three locations to locations that could |
| 877 | // overlap, so we need a parallel move resolver. |
| 878 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 879 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 880 | parallel_move.AddMove(ref_, |
| 881 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 882 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 883 | nullptr); |
| 884 | parallel_move.AddMove(obj_, |
| 885 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 886 | DataType::Type::kReference, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 887 | nullptr); |
| 888 | if (index.IsValid()) { |
| 889 | parallel_move.AddMove(index, |
| 890 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 891 | DataType::Type::kInt32, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 892 | nullptr); |
| 893 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 894 | } else { |
| 895 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 896 | __ LoadConst32(calling_convention.GetRegisterAt(2), offset_); |
| 897 | } |
| 898 | mips_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| 899 | instruction_, |
| 900 | instruction_->GetDexPc(), |
| 901 | this); |
| 902 | CheckEntrypointTypes< |
| 903 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 904 | mips_codegen->MoveLocation(out_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 905 | calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 906 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 907 | |
| 908 | RestoreLiveRegisters(codegen, locations); |
| 909 | __ B(GetExitLabel()); |
| 910 | } |
| 911 | |
| 912 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathMIPS"; } |
| 913 | |
| 914 | private: |
| 915 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 916 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 917 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 918 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 919 | if (i != ref && |
| 920 | i != obj && |
| 921 | !codegen->IsCoreCalleeSaveRegister(i) && |
| 922 | !codegen->IsBlockedCoreRegister(i)) { |
| 923 | return static_cast<Register>(i); |
| 924 | } |
| 925 | } |
| 926 | // We shall never fail to find a free caller-save register, as |
| 927 | // there are more than two core caller-save registers on MIPS |
| 928 | // (meaning it is possible to find one which is different from |
| 929 | // `ref` and `obj`). |
| 930 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 931 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 932 | UNREACHABLE(); |
| 933 | } |
| 934 | |
| 935 | const Location out_; |
| 936 | const Location ref_; |
| 937 | const Location obj_; |
| 938 | const uint32_t offset_; |
| 939 | // An additional location containing an index to an array. |
| 940 | // Only used for HArrayGet and the UnsafeGetObject & |
| 941 | // UnsafeGetObjectVolatile intrinsics. |
| 942 | const Location index_; |
| 943 | |
| 944 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS); |
| 945 | }; |
| 946 | |
| 947 | // Slow path generating a read barrier for a GC root. |
| 948 | class ReadBarrierForRootSlowPathMIPS : public SlowPathCodeMIPS { |
| 949 | public: |
| 950 | ReadBarrierForRootSlowPathMIPS(HInstruction* instruction, Location out, Location root) |
| 951 | : SlowPathCodeMIPS(instruction), out_(out), root_(root) { |
| 952 | DCHECK(kEmitCompilerReadBarrier); |
| 953 | } |
| 954 | |
| 955 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 956 | LocationSummary* locations = instruction_->GetLocations(); |
| 957 | Register reg_out = out_.AsRegister<Register>(); |
| 958 | DCHECK(locations->CanCall()); |
| 959 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 960 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 961 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 962 | << instruction_->DebugName(); |
| 963 | |
| 964 | __ Bind(GetEntryLabel()); |
| 965 | SaveLiveRegisters(codegen, locations); |
| 966 | |
| 967 | InvokeRuntimeCallingConvention calling_convention; |
| 968 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 969 | mips_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 970 | root_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 971 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 972 | mips_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 973 | instruction_, |
| 974 | instruction_->GetDexPc(), |
| 975 | this); |
| 976 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 977 | mips_codegen->MoveLocation(out_, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 978 | calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 979 | DataType::Type::kReference); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 980 | |
| 981 | RestoreLiveRegisters(codegen, locations); |
| 982 | __ B(GetExitLabel()); |
| 983 | } |
| 984 | |
| 985 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS"; } |
| 986 | |
| 987 | private: |
| 988 | const Location out_; |
| 989 | const Location root_; |
| 990 | |
| 991 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS); |
| 992 | }; |
| 993 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 994 | CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph, |
| 995 | const MipsInstructionSetFeatures& isa_features, |
| 996 | const CompilerOptions& compiler_options, |
| 997 | OptimizingCompilerStats* stats) |
| 998 | : CodeGenerator(graph, |
| 999 | kNumberOfCoreRegisters, |
| 1000 | kNumberOfFRegisters, |
| 1001 | kNumberOfRegisterPairs, |
| 1002 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1003 | arraysize(kCoreCalleeSaves)), |
| 1004 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1005 | arraysize(kFpuCalleeSaves)), |
| 1006 | compiler_options, |
| 1007 | stats), |
| 1008 | block_labels_(nullptr), |
| 1009 | location_builder_(graph, this), |
| 1010 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1011 | move_resolver_(graph->GetAllocator(), this), |
| 1012 | assembler_(graph->GetAllocator(), &isa_features), |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1013 | isa_features_(isa_features), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1014 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1015 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1016 | pc_relative_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1017 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1018 | pc_relative_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1019 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1020 | pc_relative_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1021 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1022 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1023 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1024 | clobbered_ra_(false) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1025 | // Save RA (containing the return address) to mimic Quick. |
| 1026 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 1027 | } |
| 1028 | |
| 1029 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 1030 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1031 | #define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1032 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1033 | |
| 1034 | void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) { |
| 1035 | // Ensure that we fix up branches. |
| 1036 | __ FinalizeCode(); |
| 1037 | |
| 1038 | // Adjust native pc offsets in stack maps. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1039 | StackMapStream* stack_map_stream = GetStackMapStream(); |
| 1040 | for (size_t i = 0, num = stack_map_stream->GetNumberOfStackMaps(); i != num; ++i) { |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1041 | uint32_t old_position = |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1042 | stack_map_stream->GetStackMap(i).native_pc_code_offset.Uint32Value(InstructionSet::kMips); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1043 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1044 | DCHECK_GE(new_position, old_position); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1045 | stack_map_stream->SetStackMapNativePcOffset(i, new_position); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | // Adjust pc offsets for the disassembly information. |
| 1049 | if (disasm_info_ != nullptr) { |
| 1050 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1051 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1052 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1053 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1054 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1055 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1056 | } |
| 1057 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1058 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1059 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | CodeGenerator::Finalize(allocator); |
| 1064 | } |
| 1065 | |
| 1066 | MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const { |
| 1067 | return codegen_->GetAssembler(); |
| 1068 | } |
| 1069 | |
| 1070 | void ParallelMoveResolverMIPS::EmitMove(size_t index) { |
| 1071 | DCHECK_LT(index, moves_.size()); |
| 1072 | MoveOperands* move = moves_[index]; |
| 1073 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1074 | } |
| 1075 | |
| 1076 | void ParallelMoveResolverMIPS::EmitSwap(size_t index) { |
| 1077 | DCHECK_LT(index, moves_.size()); |
| 1078 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1079 | DataType::Type type = move->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1080 | Location loc1 = move->GetDestination(); |
| 1081 | Location loc2 = move->GetSource(); |
| 1082 | |
| 1083 | DCHECK(!loc1.IsConstant()); |
| 1084 | DCHECK(!loc2.IsConstant()); |
| 1085 | |
| 1086 | if (loc1.Equals(loc2)) { |
| 1087 | return; |
| 1088 | } |
| 1089 | |
| 1090 | if (loc1.IsRegister() && loc2.IsRegister()) { |
| 1091 | // Swap 2 GPRs. |
| 1092 | Register r1 = loc1.AsRegister<Register>(); |
| 1093 | Register r2 = loc2.AsRegister<Register>(); |
| 1094 | __ Move(TMP, r2); |
| 1095 | __ Move(r2, r1); |
| 1096 | __ Move(r1, TMP); |
| 1097 | } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) { |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1098 | if (codegen_->GetGraph()->HasSIMD()) { |
| 1099 | __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(loc1)); |
| 1100 | __ MoveV(VectorRegisterFrom(loc1), VectorRegisterFrom(loc2)); |
| 1101 | __ MoveV(VectorRegisterFrom(loc2), static_cast<VectorRegister>(FTMP)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1102 | } else { |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1103 | FRegister f1 = loc1.AsFpuRegister<FRegister>(); |
| 1104 | FRegister f2 = loc2.AsFpuRegister<FRegister>(); |
| 1105 | if (type == DataType::Type::kFloat32) { |
| 1106 | __ MovS(FTMP, f2); |
| 1107 | __ MovS(f2, f1); |
| 1108 | __ MovS(f1, FTMP); |
| 1109 | } else { |
| 1110 | DCHECK_EQ(type, DataType::Type::kFloat64); |
| 1111 | __ MovD(FTMP, f2); |
| 1112 | __ MovD(f2, f1); |
| 1113 | __ MovD(f1, FTMP); |
| 1114 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1115 | } |
| 1116 | } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) || |
| 1117 | (loc1.IsFpuRegister() && loc2.IsRegister())) { |
| 1118 | // Swap FPR and GPR. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1119 | DCHECK_EQ(type, DataType::Type::kFloat32); // Can only swap a float. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1120 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1121 | : loc2.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1122 | Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1123 | __ Move(TMP, r2); |
| 1124 | __ Mfc1(r2, f1); |
| 1125 | __ Mtc1(TMP, f1); |
| 1126 | } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) { |
| 1127 | // Swap 2 GPR register pairs. |
| 1128 | Register r1 = loc1.AsRegisterPairLow<Register>(); |
| 1129 | Register r2 = loc2.AsRegisterPairLow<Register>(); |
| 1130 | __ Move(TMP, r2); |
| 1131 | __ Move(r2, r1); |
| 1132 | __ Move(r1, TMP); |
| 1133 | r1 = loc1.AsRegisterPairHigh<Register>(); |
| 1134 | r2 = loc2.AsRegisterPairHigh<Register>(); |
| 1135 | __ Move(TMP, r2); |
| 1136 | __ Move(r2, r1); |
| 1137 | __ Move(r1, TMP); |
| 1138 | } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) || |
| 1139 | (loc1.IsFpuRegister() && loc2.IsRegisterPair())) { |
| 1140 | // Swap FPR and GPR register pair. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1141 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1142 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1143 | : loc2.AsFpuRegister<FRegister>(); |
| 1144 | Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 1145 | : loc2.AsRegisterPairLow<Register>(); |
| 1146 | Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 1147 | : loc2.AsRegisterPairHigh<Register>(); |
| 1148 | // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and |
| 1149 | // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR |
| 1150 | // unpredictable and the following mfch1 will fail. |
| 1151 | __ Mfc1(TMP, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1152 | __ MoveFromFpuHigh(AT, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1153 | __ Mtc1(r2_l, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1154 | __ MoveToFpuHigh(r2_h, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1155 | __ Move(r2_l, TMP); |
| 1156 | __ Move(r2_h, AT); |
| 1157 | } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) { |
| 1158 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false); |
| 1159 | } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) { |
| 1160 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1161 | } else if (loc1.IsSIMDStackSlot() && loc2.IsSIMDStackSlot()) { |
| 1162 | ExchangeQuadSlots(loc1.GetStackIndex(), loc2.GetStackIndex()); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1163 | } else if ((loc1.IsRegister() && loc2.IsStackSlot()) || |
| 1164 | (loc1.IsStackSlot() && loc2.IsRegister())) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1165 | Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
| 1166 | intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1167 | __ Move(TMP, reg); |
| 1168 | __ LoadFromOffset(kLoadWord, reg, SP, offset); |
| 1169 | __ StoreToOffset(kStoreWord, TMP, SP, offset); |
| 1170 | } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) || |
| 1171 | (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) { |
| 1172 | Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 1173 | : loc2.AsRegisterPairLow<Register>(); |
| 1174 | Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 1175 | : loc2.AsRegisterPairHigh<Register>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1176 | intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1177 | intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize) |
| 1178 | : loc2.GetHighStackIndex(kMipsWordSize); |
| 1179 | __ Move(TMP, reg_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1180 | __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1181 | __ StoreToOffset(kStoreWord, TMP, SP, offset_l); |
David Brazdil | 04d3e87 | 2016-01-29 09:50:09 +0000 | [diff] [blame] | 1182 | __ Move(TMP, reg_h); |
| 1183 | __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h); |
| 1184 | __ StoreToOffset(kStoreWord, TMP, SP, offset_h); |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1185 | } else if ((loc1.IsFpuRegister() && loc2.IsSIMDStackSlot()) || |
| 1186 | (loc1.IsSIMDStackSlot() && loc2.IsFpuRegister())) { |
| 1187 | Location fp_loc = loc1.IsFpuRegister() ? loc1 : loc2; |
| 1188 | intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex(); |
| 1189 | __ MoveV(static_cast<VectorRegister>(FTMP), VectorRegisterFrom(fp_loc)); |
| 1190 | __ LoadQFromOffset(fp_loc.AsFpuRegister<FRegister>(), SP, offset); |
| 1191 | __ StoreQToOffset(FTMP, SP, offset); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1192 | } else if (loc1.IsFpuRegister() || loc2.IsFpuRegister()) { |
| 1193 | FRegister reg = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1194 | : loc2.AsFpuRegister<FRegister>(); |
| 1195 | intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1196 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1197 | __ MovS(FTMP, reg); |
| 1198 | __ LoadSFromOffset(reg, SP, offset); |
| 1199 | __ StoreSToOffset(FTMP, SP, offset); |
| 1200 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1201 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1202 | __ MovD(FTMP, reg); |
| 1203 | __ LoadDFromOffset(reg, SP, offset); |
| 1204 | __ StoreDToOffset(FTMP, SP, offset); |
| 1205 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1206 | } else { |
| 1207 | LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported"; |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | void ParallelMoveResolverMIPS::RestoreScratch(int reg) { |
| 1212 | __ Pop(static_cast<Register>(reg)); |
| 1213 | } |
| 1214 | |
| 1215 | void ParallelMoveResolverMIPS::SpillScratch(int reg) { |
| 1216 | __ Push(static_cast<Register>(reg)); |
| 1217 | } |
| 1218 | |
| 1219 | void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) { |
| 1220 | // Allocate a scratch register other than TMP, if available. |
| 1221 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 1222 | // automatically unspilled when the scratch scope object is destroyed). |
| 1223 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 1224 | // If V0 spills onto the stack, SP-relative offsets need to be adjusted. |
Chris Larsen | 715f43e | 2017-10-23 11:00:32 -0700 | [diff] [blame] | 1225 | int stack_offset = ensure_scratch.IsSpilled() ? kStackAlignment : 0; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1226 | for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) { |
| 1227 | __ LoadFromOffset(kLoadWord, |
| 1228 | Register(ensure_scratch.GetRegister()), |
| 1229 | SP, |
| 1230 | index1 + stack_offset); |
| 1231 | __ LoadFromOffset(kLoadWord, |
| 1232 | TMP, |
| 1233 | SP, |
| 1234 | index2 + stack_offset); |
| 1235 | __ StoreToOffset(kStoreWord, |
| 1236 | Register(ensure_scratch.GetRegister()), |
| 1237 | SP, |
| 1238 | index2 + stack_offset); |
| 1239 | __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset); |
| 1240 | } |
| 1241 | } |
| 1242 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1243 | void ParallelMoveResolverMIPS::ExchangeQuadSlots(int index1, int index2) { |
| 1244 | __ LoadQFromOffset(FTMP, SP, index1); |
| 1245 | __ LoadQFromOffset(FTMP2, SP, index2); |
| 1246 | __ StoreQToOffset(FTMP, SP, index2); |
| 1247 | __ StoreQToOffset(FTMP2, SP, index1); |
| 1248 | } |
| 1249 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1250 | void CodeGeneratorMIPS::ComputeSpillMask() { |
| 1251 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1252 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1253 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 1254 | // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved |
| 1255 | // registers, include the ZERO register to force alignment of FPU callee-saved registers |
| 1256 | // within the stack frame. |
| 1257 | if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) { |
| 1258 | core_spill_mask_ |= (1 << ZERO); |
| 1259 | } |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1263 | // If RA is clobbered by PC-relative operations on R2 and it's the only spilled register |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1264 | // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration() |
| 1265 | // into the path that creates a stack frame so that RA can be explicitly saved and restored. |
| 1266 | // RA can't otherwise be saved/restored when it's the only spilled register. |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1267 | return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_; |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1270 | static dwarf::Reg DWARFReg(Register reg) { |
| 1271 | return dwarf::Reg::MipsCore(static_cast<int>(reg)); |
| 1272 | } |
| 1273 | |
| 1274 | // TODO: mapping of floating-point registers to DWARF. |
| 1275 | |
| 1276 | void CodeGeneratorMIPS::GenerateFrameEntry() { |
| 1277 | __ Bind(&frame_entry_label_); |
| 1278 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1279 | bool do_overflow_check = |
| 1280 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips) || !IsLeafMethod(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1281 | |
| 1282 | if (do_overflow_check) { |
| 1283 | __ LoadFromOffset(kLoadWord, |
| 1284 | ZERO, |
| 1285 | SP, |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1286 | -static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kMips))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1287 | RecordPcInfo(nullptr, 0); |
| 1288 | } |
| 1289 | |
| 1290 | if (HasEmptyFrame()) { |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1291 | CHECK_EQ(fpu_spill_mask_, 0u); |
| 1292 | CHECK_EQ(core_spill_mask_, 1u << RA); |
| 1293 | CHECK(!clobbered_ra_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1294 | return; |
| 1295 | } |
| 1296 | |
| 1297 | // Make sure the frame size isn't unreasonably large. |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1298 | if (GetFrameSize() > GetStackOverflowReservedBytes(InstructionSet::kMips)) { |
| 1299 | LOG(FATAL) << "Stack frame larger than " |
| 1300 | << GetStackOverflowReservedBytes(InstructionSet::kMips) << " bytes"; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | // Spill callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1304 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1305 | uint32_t ofs = GetFrameSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1306 | __ IncreaseFrameSize(ofs); |
| 1307 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1308 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 1309 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 1310 | mask ^= 1u << reg; |
| 1311 | ofs -= kMipsWordSize; |
| 1312 | // The ZERO register is only included for alignment. |
| 1313 | if (reg != ZERO) { |
| 1314 | __ StoreToOffset(kStoreWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1315 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 1316 | } |
| 1317 | } |
| 1318 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1319 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 1320 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 1321 | mask ^= 1u << reg; |
| 1322 | ofs -= kMipsDoublewordSize; |
| 1323 | __ StoreDToOffset(reg, SP, ofs); |
| 1324 | // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1325 | } |
| 1326 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1327 | // Save the current method if we need it. Note that we do not |
| 1328 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1329 | // in the SSA graph. |
| 1330 | if (RequiresCurrentMethod()) { |
| 1331 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
| 1332 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 1333 | |
| 1334 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1335 | // Initialize should deoptimize flag to 0. |
| 1336 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1337 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | void CodeGeneratorMIPS::GenerateFrameExit() { |
| 1341 | __ cfi().RememberState(); |
| 1342 | |
| 1343 | if (!HasEmptyFrame()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1344 | // Restore callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1345 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1346 | // For better instruction scheduling restore RA before other registers. |
| 1347 | uint32_t ofs = GetFrameSize(); |
| 1348 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 1349 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 1350 | mask ^= 1u << reg; |
| 1351 | ofs -= kMipsWordSize; |
| 1352 | // The ZERO register is only included for alignment. |
| 1353 | if (reg != ZERO) { |
| 1354 | __ LoadFromOffset(kLoadWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1355 | __ cfi().Restore(DWARFReg(reg)); |
| 1356 | } |
| 1357 | } |
| 1358 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1359 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 1360 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 1361 | mask ^= 1u << reg; |
| 1362 | ofs -= kMipsDoublewordSize; |
| 1363 | __ LoadDFromOffset(reg, SP, ofs); |
| 1364 | // TODO: __ cfi().Restore(DWARFReg(reg)); |
| 1365 | } |
| 1366 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1367 | size_t frame_size = GetFrameSize(); |
| 1368 | // Adjust the stack pointer in the delay slot if doing so doesn't break CFI. |
| 1369 | bool exchange = IsInt<16>(static_cast<int32_t>(frame_size)); |
| 1370 | bool reordering = __ SetReorder(false); |
| 1371 | if (exchange) { |
| 1372 | __ Jr(RA); |
| 1373 | __ DecreaseFrameSize(frame_size); // Single instruction in delay slot. |
| 1374 | } else { |
| 1375 | __ DecreaseFrameSize(frame_size); |
| 1376 | __ Jr(RA); |
| 1377 | __ Nop(); // In delay slot. |
| 1378 | } |
| 1379 | __ SetReorder(reordering); |
| 1380 | } else { |
| 1381 | __ Jr(RA); |
| 1382 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1383 | } |
| 1384 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1385 | __ cfi().RestoreState(); |
| 1386 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 1387 | } |
| 1388 | |
| 1389 | void CodeGeneratorMIPS::Bind(HBasicBlock* block) { |
| 1390 | __ Bind(GetLabelOf(block)); |
| 1391 | } |
| 1392 | |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1393 | VectorRegister VectorRegisterFrom(Location location) { |
| 1394 | DCHECK(location.IsFpuRegister()); |
| 1395 | return static_cast<VectorRegister>(location.AsFpuRegister<FRegister>()); |
| 1396 | } |
| 1397 | |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1398 | void CodeGeneratorMIPS::MoveLocation(Location destination, |
| 1399 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1400 | DataType::Type dst_type) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1401 | if (source.Equals(destination)) { |
| 1402 | return; |
| 1403 | } |
| 1404 | |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1405 | if (source.IsConstant()) { |
| 1406 | MoveConstant(destination, source.GetConstant()); |
| 1407 | } else { |
| 1408 | if (destination.IsRegister()) { |
| 1409 | if (source.IsRegister()) { |
| 1410 | __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 1411 | } else if (source.IsFpuRegister()) { |
| 1412 | __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>()); |
| 1413 | } else { |
| 1414 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1415 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1416 | } |
| 1417 | } else if (destination.IsRegisterPair()) { |
| 1418 | if (source.IsRegisterPair()) { |
| 1419 | __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 1420 | __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 1421 | } else if (source.IsFpuRegister()) { |
| 1422 | Register dst_high = destination.AsRegisterPairHigh<Register>(); |
| 1423 | Register dst_low = destination.AsRegisterPairLow<Register>(); |
| 1424 | FRegister src = source.AsFpuRegister<FRegister>(); |
| 1425 | __ Mfc1(dst_low, src); |
| 1426 | __ MoveFromFpuHigh(dst_high, src); |
| 1427 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1428 | DCHECK(source.IsDoubleStackSlot()) |
| 1429 | << "Cannot move from " << source << " to " << destination; |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1430 | int32_t off = source.GetStackIndex(); |
| 1431 | Register r = destination.AsRegisterPairLow<Register>(); |
| 1432 | __ LoadFromOffset(kLoadDoubleword, r, SP, off); |
| 1433 | } |
| 1434 | } else if (destination.IsFpuRegister()) { |
| 1435 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1436 | DCHECK(!DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1437 | __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>()); |
| 1438 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1439 | DCHECK(DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1440 | FRegister dst = destination.AsFpuRegister<FRegister>(); |
| 1441 | Register src_high = source.AsRegisterPairHigh<Register>(); |
| 1442 | Register src_low = source.AsRegisterPairLow<Register>(); |
| 1443 | __ Mtc1(src_low, dst); |
| 1444 | __ MoveToFpuHigh(src_high, dst); |
| 1445 | } else if (source.IsFpuRegister()) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1446 | if (GetGraph()->HasSIMD()) { |
| 1447 | __ MoveV(VectorRegisterFrom(destination), |
| 1448 | VectorRegisterFrom(source)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1449 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1450 | if (DataType::Is64BitType(dst_type)) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1451 | __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 1452 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1453 | DCHECK_EQ(dst_type, DataType::Type::kFloat32); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1454 | __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 1455 | } |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1456 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1457 | } else if (source.IsSIMDStackSlot()) { |
| 1458 | __ LoadQFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1459 | } else if (source.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1460 | DCHECK(DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1461 | __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 1462 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1463 | DCHECK(!DataType::Is64BitType(dst_type)); |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1464 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1465 | __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 1466 | } |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1467 | } else if (destination.IsSIMDStackSlot()) { |
| 1468 | if (source.IsFpuRegister()) { |
| 1469 | __ StoreQToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex()); |
| 1470 | } else { |
| 1471 | DCHECK(source.IsSIMDStackSlot()); |
| 1472 | __ LoadQFromOffset(FTMP, SP, source.GetStackIndex()); |
| 1473 | __ StoreQToOffset(FTMP, SP, destination.GetStackIndex()); |
| 1474 | } |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1475 | } else if (destination.IsDoubleStackSlot()) { |
| 1476 | int32_t dst_offset = destination.GetStackIndex(); |
| 1477 | if (source.IsRegisterPair()) { |
| 1478 | __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, dst_offset); |
| 1479 | } else if (source.IsFpuRegister()) { |
| 1480 | __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset); |
| 1481 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1482 | DCHECK(source.IsDoubleStackSlot()) |
| 1483 | << "Cannot move from " << source << " to " << destination; |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1484 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1485 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset); |
| 1486 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4); |
| 1487 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset + 4); |
| 1488 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1489 | } else { |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 1490 | DCHECK(destination.IsStackSlot()) << destination; |
| 1491 | int32_t dst_offset = destination.GetStackIndex(); |
| 1492 | if (source.IsRegister()) { |
| 1493 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, dst_offset); |
| 1494 | } else if (source.IsFpuRegister()) { |
| 1495 | __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, dst_offset); |
| 1496 | } else { |
| 1497 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1498 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1499 | __ StoreToOffset(kStoreWord, TMP, SP, dst_offset); |
| 1500 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1501 | } |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) { |
| 1506 | if (c->IsIntConstant() || c->IsNullConstant()) { |
| 1507 | // Move 32 bit constant. |
| 1508 | int32_t value = GetInt32ValueOf(c); |
| 1509 | if (destination.IsRegister()) { |
| 1510 | Register dst = destination.AsRegister<Register>(); |
| 1511 | __ LoadConst32(dst, value); |
| 1512 | } else { |
| 1513 | DCHECK(destination.IsStackSlot()) |
| 1514 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1515 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1516 | } |
| 1517 | } else if (c->IsLongConstant()) { |
| 1518 | // Move 64 bit constant. |
| 1519 | int64_t value = GetInt64ValueOf(c); |
| 1520 | if (destination.IsRegisterPair()) { |
| 1521 | Register r_h = destination.AsRegisterPairHigh<Register>(); |
| 1522 | Register r_l = destination.AsRegisterPairLow<Register>(); |
| 1523 | __ LoadConst64(r_h, r_l, value); |
| 1524 | } else { |
| 1525 | DCHECK(destination.IsDoubleStackSlot()) |
| 1526 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1527 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1528 | } |
| 1529 | } else if (c->IsFloatConstant()) { |
| 1530 | // Move 32 bit float constant. |
| 1531 | int32_t value = GetInt32ValueOf(c); |
| 1532 | if (destination.IsFpuRegister()) { |
| 1533 | __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP); |
| 1534 | } else { |
| 1535 | DCHECK(destination.IsStackSlot()) |
| 1536 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1537 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1538 | } |
| 1539 | } else { |
| 1540 | // Move 64 bit double constant. |
| 1541 | DCHECK(c->IsDoubleConstant()) << c->DebugName(); |
| 1542 | int64_t value = GetInt64ValueOf(c); |
| 1543 | if (destination.IsFpuRegister()) { |
| 1544 | FRegister fd = destination.AsFpuRegister<FRegister>(); |
| 1545 | __ LoadDConst64(fd, value, TMP); |
| 1546 | } else { |
| 1547 | DCHECK(destination.IsDoubleStackSlot()) |
| 1548 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1549 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1550 | } |
| 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) { |
| 1555 | DCHECK(destination.IsRegister()); |
| 1556 | Register dst = destination.AsRegister<Register>(); |
| 1557 | __ LoadConst32(dst, value); |
| 1558 | } |
| 1559 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1560 | void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1561 | if (location.IsRegister()) { |
| 1562 | locations->AddTemp(location); |
Alexey Frunze | c9e94f3 | 2015-10-26 16:11:39 -0700 | [diff] [blame] | 1563 | } else if (location.IsRegisterPair()) { |
| 1564 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1565 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1566 | } else { |
| 1567 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1568 | } |
| 1569 | } |
| 1570 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1571 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1572 | inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches( |
| 1573 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1574 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1575 | for (const PcRelativePatchInfo& info : infos) { |
| 1576 | const DexFile& dex_file = info.target_dex_file; |
| 1577 | size_t offset_or_index = info.offset_or_index; |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1578 | DCHECK(info.label.IsBound()); |
| 1579 | uint32_t literal_offset = __ GetLabelLocation(&info.label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1580 | // On R2 we use HMipsComputeBaseMethodAddress and patch relative to |
| 1581 | // the assembler's base label used for PC-relative addressing. |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1582 | const PcRelativePatchInfo& info_high = info.patch_info_high ? *info.patch_info_high : info; |
| 1583 | uint32_t pc_rel_offset = info_high.pc_rel_label.IsBound() |
| 1584 | ? __ GetLabelLocation(&info_high.pc_rel_label) |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1585 | : __ GetPcRelBaseLabelLocation(); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1586 | linker_patches->push_back(Factory(literal_offset, &dex_file, pc_rel_offset, offset_or_index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1587 | } |
| 1588 | } |
| 1589 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1590 | void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1591 | DCHECK(linker_patches->empty()); |
| 1592 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1593 | pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1594 | method_bss_entry_patches_.size() + |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1595 | pc_relative_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1596 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1597 | pc_relative_string_patches_.size() + |
| 1598 | string_bss_entry_patches_.size(); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1599 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1600 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1601 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 1602 | pc_relative_method_patches_, linker_patches); |
| 1603 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 1604 | pc_relative_type_patches_, linker_patches); |
| 1605 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 1606 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1607 | } else { |
| 1608 | DCHECK(pc_relative_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1609 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 1610 | pc_relative_type_patches_, linker_patches); |
| 1611 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 1612 | pc_relative_string_patches_, linker_patches); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1613 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1614 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1615 | method_bss_entry_patches_, linker_patches); |
| 1616 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1617 | type_bss_entry_patches_, linker_patches); |
| 1618 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1619 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1620 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1621 | } |
| 1622 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1623 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeMethodPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1624 | MethodReference target_method, |
| 1625 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1626 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1627 | target_method.index, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1628 | info_high, |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1629 | &pc_relative_method_patches_); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1630 | } |
| 1631 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1632 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewMethodBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1633 | MethodReference target_method, |
| 1634 | const PcRelativePatchInfo* info_high) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1635 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1636 | target_method.index, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1637 | info_high, |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1638 | &method_bss_entry_patches_); |
| 1639 | } |
| 1640 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1641 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1642 | const DexFile& dex_file, |
| 1643 | dex::TypeIndex type_index, |
| 1644 | const PcRelativePatchInfo* info_high) { |
| 1645 | return NewPcRelativePatch(dex_file, type_index.index_, info_high, &pc_relative_type_patches_); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1646 | } |
| 1647 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1648 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewTypeBssEntryPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1649 | const DexFile& dex_file, |
| 1650 | dex::TypeIndex type_index, |
| 1651 | const PcRelativePatchInfo* info_high) { |
| 1652 | return NewPcRelativePatch(dex_file, type_index.index_, info_high, &type_bss_entry_patches_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1655 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1656 | const DexFile& dex_file, |
| 1657 | dex::StringIndex string_index, |
| 1658 | const PcRelativePatchInfo* info_high) { |
| 1659 | return NewPcRelativePatch(dex_file, string_index.index_, info_high, &pc_relative_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1660 | } |
| 1661 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1662 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewStringBssEntryPatch( |
| 1663 | const DexFile& dex_file, |
| 1664 | dex::StringIndex string_index, |
| 1665 | const PcRelativePatchInfo* info_high) { |
| 1666 | return NewPcRelativePatch(dex_file, string_index.index_, info_high, &string_bss_entry_patches_); |
| 1667 | } |
| 1668 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1669 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch( |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1670 | const DexFile& dex_file, |
| 1671 | uint32_t offset_or_index, |
| 1672 | const PcRelativePatchInfo* info_high, |
| 1673 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1674 | patches->emplace_back(dex_file, offset_or_index, info_high); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1675 | return &patches->back(); |
| 1676 | } |
| 1677 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1678 | Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1679 | return map->GetOrCreate( |
| 1680 | value, |
| 1681 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1682 | } |
| 1683 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1684 | Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1685 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1686 | } |
| 1687 | |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1688 | void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high, |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1689 | Register out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1690 | Register base) { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1691 | DCHECK(!info_high->patch_info_high); |
Alexey Frunze | 6079dca | 2017-05-28 19:10:28 -0700 | [diff] [blame] | 1692 | DCHECK_NE(out, base); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1693 | bool reordering = __ SetReorder(false); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1694 | if (GetInstructionSetFeatures().IsR6()) { |
| 1695 | DCHECK_EQ(base, ZERO); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1696 | __ Bind(&info_high->label); |
| 1697 | __ Bind(&info_high->pc_rel_label); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1698 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1699 | __ Auipc(out, /* placeholder */ 0x1234); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1700 | __ SetReorder(reordering); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1701 | } else { |
| 1702 | // If base is ZERO, emit NAL to obtain the actual base. |
| 1703 | if (base == ZERO) { |
| 1704 | // Generate a dummy PC-relative call to obtain PC. |
| 1705 | __ Nal(); |
| 1706 | } |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1707 | __ Bind(&info_high->label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1708 | __ Lui(out, /* placeholder */ 0x1234); |
| 1709 | // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding |
| 1710 | // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler. |
| 1711 | if (base == ZERO) { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1712 | __ Bind(&info_high->pc_rel_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1713 | } |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 1714 | __ SetReorder(reordering); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1715 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1716 | __ Addu(out, out, (base == ZERO) ? RA : base); |
| 1717 | } |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 1718 | // A following instruction will add the sign-extended low half of the 32-bit |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1719 | // offset to `out` (e.g. lw, jialc, addiu). |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1722 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootStringPatch( |
| 1723 | const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1724 | dex::StringIndex string_index, |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1725 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1726 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| 1727 | jit_string_patches_.emplace_back(dex_file, string_index.index_); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1728 | return &jit_string_patches_.back(); |
| 1729 | } |
| 1730 | |
| 1731 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootClassPatch( |
| 1732 | const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1733 | dex::TypeIndex type_index, |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1734 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1735 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| 1736 | jit_class_patches_.emplace_back(dex_file, type_index.index_); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1737 | return &jit_class_patches_.back(); |
| 1738 | } |
| 1739 | |
| 1740 | void CodeGeneratorMIPS::PatchJitRootUse(uint8_t* code, |
| 1741 | const uint8_t* roots_data, |
| 1742 | const CodeGeneratorMIPS::JitPatchInfo& info, |
| 1743 | uint64_t index_in_table) const { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1744 | uint32_t high_literal_offset = GetAssembler().GetLabelLocation(&info.high_label); |
| 1745 | uint32_t low_literal_offset = GetAssembler().GetLabelLocation(&info.low_label); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1746 | uintptr_t address = |
| 1747 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1748 | uint32_t addr32 = dchecked_integral_cast<uint32_t>(address); |
| 1749 | // lui reg, addr32_high |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1750 | DCHECK_EQ(code[high_literal_offset + 0], 0x34); |
| 1751 | DCHECK_EQ(code[high_literal_offset + 1], 0x12); |
| 1752 | DCHECK_EQ((code[high_literal_offset + 2] & 0xE0), 0x00); |
| 1753 | DCHECK_EQ(code[high_literal_offset + 3], 0x3C); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1754 | // instr reg, reg, addr32_low |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1755 | DCHECK_EQ(code[low_literal_offset + 0], 0x78); |
| 1756 | DCHECK_EQ(code[low_literal_offset + 1], 0x56); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1757 | addr32 += (addr32 & 0x8000) << 1; // Account for sign extension in "instr reg, reg, addr32_low". |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1758 | // lui reg, addr32_high |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1759 | code[high_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 16); |
| 1760 | code[high_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 24); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1761 | // instr reg, reg, addr32_low |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 1762 | code[low_literal_offset + 0] = static_cast<uint8_t>(addr32 >> 0); |
| 1763 | code[low_literal_offset + 1] = static_cast<uint8_t>(addr32 >> 8); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | void CodeGeneratorMIPS::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1767 | for (const JitPatchInfo& info : jit_string_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1768 | StringReference string_reference(&info.target_dex_file, dex::StringIndex(info.index)); |
| 1769 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1770 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1771 | } |
| 1772 | for (const JitPatchInfo& info : jit_class_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1773 | TypeReference type_reference(&info.target_dex_file, dex::TypeIndex(info.index)); |
| 1774 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1775 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1779 | void CodeGeneratorMIPS::MarkGCCard(Register object, |
| 1780 | Register value, |
| 1781 | bool value_can_be_null) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1782 | MipsLabel done; |
| 1783 | Register card = AT; |
| 1784 | Register temp = TMP; |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1785 | if (value_can_be_null) { |
| 1786 | __ Beqz(value, &done); |
| 1787 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1788 | __ LoadFromOffset(kLoadWord, |
| 1789 | card, |
| 1790 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1791 | Thread::CardTableOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1792 | __ Srl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1793 | __ Addu(temp, card, temp); |
| 1794 | __ Sb(card, temp, 0); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1795 | if (value_can_be_null) { |
| 1796 | __ Bind(&done); |
| 1797 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1798 | } |
| 1799 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1800 | void CodeGeneratorMIPS::SetupBlockedRegisters() const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1801 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1802 | blocked_core_registers_[ZERO] = true; |
| 1803 | blocked_core_registers_[K0] = true; |
| 1804 | blocked_core_registers_[K1] = true; |
| 1805 | blocked_core_registers_[GP] = true; |
| 1806 | blocked_core_registers_[SP] = true; |
| 1807 | blocked_core_registers_[RA] = true; |
| 1808 | |
| 1809 | // AT and TMP(T8) are used as temporary/scratch registers |
| 1810 | // (similar to how AT is used by MIPS assemblers). |
| 1811 | blocked_core_registers_[AT] = true; |
| 1812 | blocked_core_registers_[TMP] = true; |
| 1813 | blocked_fpu_registers_[FTMP] = true; |
| 1814 | |
Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 1815 | if (GetInstructionSetFeatures().HasMsa()) { |
| 1816 | // To be used just for MSA instructions. |
| 1817 | blocked_fpu_registers_[FTMP2] = true; |
| 1818 | } |
| 1819 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1820 | // Reserve suspend and thread registers. |
| 1821 | blocked_core_registers_[S0] = true; |
| 1822 | blocked_core_registers_[TR] = true; |
| 1823 | |
| 1824 | // Reserve T9 for function calls |
| 1825 | blocked_core_registers_[T9] = true; |
| 1826 | |
| 1827 | // Reserve odd-numbered FPU registers. |
| 1828 | for (size_t i = 1; i < kNumberOfFRegisters; i += 2) { |
| 1829 | blocked_fpu_registers_[i] = true; |
| 1830 | } |
| 1831 | |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 1832 | if (GetGraph()->IsDebuggable()) { |
| 1833 | // Stubs do not save callee-save floating point registers. If the graph |
| 1834 | // is debuggable, we need to deal with these registers differently. For |
| 1835 | // now, just block them. |
| 1836 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1837 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1838 | } |
| 1839 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1840 | } |
| 1841 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1842 | size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1843 | __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index); |
| 1844 | return kMipsWordSize; |
| 1845 | } |
| 1846 | |
| 1847 | size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1848 | __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index); |
| 1849 | return kMipsWordSize; |
| 1850 | } |
| 1851 | |
| 1852 | size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1853 | if (GetGraph()->HasSIMD()) { |
| 1854 | __ StoreQToOffset(FRegister(reg_id), SP, stack_index); |
| 1855 | } else { |
| 1856 | __ StoreDToOffset(FRegister(reg_id), SP, stack_index); |
| 1857 | } |
| 1858 | return GetFloatingPointSpillSlotSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 1862 | if (GetGraph()->HasSIMD()) { |
| 1863 | __ LoadQFromOffset(FRegister(reg_id), SP, stack_index); |
| 1864 | } else { |
| 1865 | __ LoadDFromOffset(FRegister(reg_id), SP, stack_index); |
| 1866 | } |
| 1867 | return GetFloatingPointSpillSlotSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1871 | stream << Register(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1875 | stream << FRegister(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1876 | } |
| 1877 | |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1878 | constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16; |
| 1879 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1880 | void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1881 | HInstruction* instruction, |
| 1882 | uint32_t dex_pc, |
| 1883 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1884 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1885 | GenerateInvokeRuntime(GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value(), |
| 1886 | IsDirectEntrypoint(entrypoint)); |
| 1887 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1888 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1889 | } |
| 1890 | } |
| 1891 | |
| 1892 | void CodeGeneratorMIPS::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1893 | HInstruction* instruction, |
| 1894 | SlowPathCode* slow_path, |
| 1895 | bool direct) { |
| 1896 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1897 | GenerateInvokeRuntime(entry_point_offset, direct); |
| 1898 | } |
| 1899 | |
| 1900 | void CodeGeneratorMIPS::GenerateInvokeRuntime(int32_t entry_point_offset, bool direct) { |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1901 | bool reordering = __ SetReorder(false); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1902 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1903 | __ Jalr(T9); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1904 | if (direct) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1905 | // Reserve argument space on stack (for $a0-$a3) for |
| 1906 | // entrypoints that directly reference native implementations. |
| 1907 | // Called function may use this space to store $a0-$a3 regs. |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1908 | __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1909 | __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1910 | } else { |
| 1911 | __ Nop(); // In delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1912 | } |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1913 | __ SetReorder(reordering); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, |
| 1917 | Register class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1918 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 1919 | const size_t status_byte_offset = |
| 1920 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 1921 | constexpr uint32_t shifted_initialized_value = |
| 1922 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 1923 | |
| 1924 | __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, status_byte_offset); |
| 1925 | __ LoadConst32(AT, shifted_initialized_value); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 1926 | __ Bltu(TMP, AT, slow_path->GetEntryLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1927 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1928 | __ Sync(0); |
| 1929 | __ Bind(slow_path->GetExitLabel()); |
| 1930 | } |
| 1931 | |
| 1932 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1933 | __ Sync(0); // Only stype 0 is supported. |
| 1934 | } |
| 1935 | |
| 1936 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1937 | HBasicBlock* successor) { |
| 1938 | SuspendCheckSlowPathMIPS* slow_path = |
Chris Larsen | a204591 | 2017-11-02 12:39:54 -0700 | [diff] [blame] | 1939 | down_cast<SuspendCheckSlowPathMIPS*>(instruction->GetSlowPath()); |
| 1940 | |
| 1941 | if (slow_path == nullptr) { |
| 1942 | slow_path = |
| 1943 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathMIPS(instruction, successor); |
| 1944 | instruction->SetSlowPath(slow_path); |
| 1945 | codegen_->AddSlowPath(slow_path); |
| 1946 | if (successor != nullptr) { |
| 1947 | DCHECK(successor->IsLoopHeader()); |
| 1948 | } |
| 1949 | } else { |
| 1950 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1951 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1952 | |
| 1953 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1954 | TMP, |
| 1955 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1956 | Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1957 | if (successor == nullptr) { |
| 1958 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 1959 | __ Bind(slow_path->GetReturnLabel()); |
| 1960 | } else { |
| 1961 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); |
| 1962 | __ B(slow_path->GetEntryLabel()); |
| 1963 | // slow_path will return to GetLabelOf(successor). |
| 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, |
| 1968 | CodeGeneratorMIPS* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1969 | : InstructionCodeGenerator(graph, codegen), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1970 | assembler_(codegen->GetAssembler()), |
| 1971 | codegen_(codegen) {} |
| 1972 | |
| 1973 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1974 | DCHECK_EQ(instruction->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1975 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1976 | DataType::Type type = instruction->GetResultType(); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1977 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1978 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1979 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1980 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1981 | HInstruction* right = instruction->InputAt(1); |
| 1982 | bool can_use_imm = false; |
| 1983 | if (right->IsConstant()) { |
| 1984 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); |
| 1985 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1986 | can_use_imm = IsUint<16>(imm); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1987 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 1988 | DCHECK(instruction->IsSub() || instruction->IsAdd()); |
| 1989 | if (instruction->IsSub()) { |
| 1990 | imm = -imm; |
| 1991 | } |
| 1992 | if (isR6) { |
| 1993 | bool single_use = right->GetUses().HasExactlyOneElement(); |
| 1994 | int16_t imm_high = High16Bits(imm); |
| 1995 | int16_t imm_low = Low16Bits(imm); |
| 1996 | if (imm_low < 0) { |
| 1997 | imm_high += 1; |
| 1998 | } |
| 1999 | can_use_imm = !((imm_high != 0) && (imm_low != 0)) || single_use; |
| 2000 | } else { |
| 2001 | can_use_imm = IsInt<16>(imm); |
| 2002 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2003 | } |
| 2004 | } |
| 2005 | if (can_use_imm) |
| 2006 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 2007 | else |
| 2008 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2009 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2010 | break; |
| 2011 | } |
| 2012 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2013 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2014 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2015 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2016 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2017 | break; |
| 2018 | } |
| 2019 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2020 | case DataType::Type::kFloat32: |
| 2021 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2022 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 2023 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2024 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2025 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2026 | break; |
| 2027 | |
| 2028 | default: |
| 2029 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2034 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2035 | LocationSummary* locations = instruction->GetLocations(); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2036 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2037 | |
| 2038 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2039 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2040 | Register dst = locations->Out().AsRegister<Register>(); |
| 2041 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2042 | Location rhs_location = locations->InAt(1); |
| 2043 | |
| 2044 | Register rhs_reg = ZERO; |
| 2045 | int32_t rhs_imm = 0; |
| 2046 | bool use_imm = rhs_location.IsConstant(); |
| 2047 | if (use_imm) { |
| 2048 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2049 | } else { |
| 2050 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2051 | } |
| 2052 | |
| 2053 | if (instruction->IsAnd()) { |
| 2054 | if (use_imm) |
| 2055 | __ Andi(dst, lhs, rhs_imm); |
| 2056 | else |
| 2057 | __ And(dst, lhs, rhs_reg); |
| 2058 | } else if (instruction->IsOr()) { |
| 2059 | if (use_imm) |
| 2060 | __ Ori(dst, lhs, rhs_imm); |
| 2061 | else |
| 2062 | __ Or(dst, lhs, rhs_reg); |
| 2063 | } else if (instruction->IsXor()) { |
| 2064 | if (use_imm) |
| 2065 | __ Xori(dst, lhs, rhs_imm); |
| 2066 | else |
| 2067 | __ Xor(dst, lhs, rhs_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2068 | } else { |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2069 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 2070 | if (use_imm) { |
| 2071 | if (instruction->IsSub()) { |
| 2072 | rhs_imm = -rhs_imm; |
| 2073 | } |
| 2074 | if (IsInt<16>(rhs_imm)) { |
| 2075 | __ Addiu(dst, lhs, rhs_imm); |
| 2076 | } else { |
| 2077 | DCHECK(isR6); |
| 2078 | int16_t rhs_imm_high = High16Bits(rhs_imm); |
| 2079 | int16_t rhs_imm_low = Low16Bits(rhs_imm); |
| 2080 | if (rhs_imm_low < 0) { |
| 2081 | rhs_imm_high += 1; |
| 2082 | } |
| 2083 | __ Aui(dst, lhs, rhs_imm_high); |
| 2084 | if (rhs_imm_low != 0) { |
| 2085 | __ Addiu(dst, dst, rhs_imm_low); |
| 2086 | } |
| 2087 | } |
| 2088 | } else if (instruction->IsAdd()) { |
| 2089 | __ Addu(dst, lhs, rhs_reg); |
| 2090 | } else { |
| 2091 | DCHECK(instruction->IsSub()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2092 | __ Subu(dst, lhs, rhs_reg); |
Lena Djokic | 3853017 | 2017-11-16 11:11:50 +0100 | [diff] [blame] | 2093 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2094 | } |
| 2095 | break; |
| 2096 | } |
| 2097 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2098 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2099 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2100 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2101 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2102 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2103 | Location rhs_location = locations->InAt(1); |
| 2104 | bool use_imm = rhs_location.IsConstant(); |
| 2105 | if (!use_imm) { |
| 2106 | Register rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 2107 | Register rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 2108 | if (instruction->IsAnd()) { |
| 2109 | __ And(dst_low, lhs_low, rhs_low); |
| 2110 | __ And(dst_high, lhs_high, rhs_high); |
| 2111 | } else if (instruction->IsOr()) { |
| 2112 | __ Or(dst_low, lhs_low, rhs_low); |
| 2113 | __ Or(dst_high, lhs_high, rhs_high); |
| 2114 | } else if (instruction->IsXor()) { |
| 2115 | __ Xor(dst_low, lhs_low, rhs_low); |
| 2116 | __ Xor(dst_high, lhs_high, rhs_high); |
| 2117 | } else if (instruction->IsAdd()) { |
| 2118 | if (lhs_low == rhs_low) { |
| 2119 | // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs. |
| 2120 | __ Slt(TMP, lhs_low, ZERO); |
| 2121 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2122 | } else { |
| 2123 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2124 | // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged. |
| 2125 | __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low); |
| 2126 | } |
| 2127 | __ Addu(dst_high, lhs_high, rhs_high); |
| 2128 | __ Addu(dst_high, dst_high, TMP); |
| 2129 | } else { |
| 2130 | DCHECK(instruction->IsSub()); |
| 2131 | __ Sltu(TMP, lhs_low, rhs_low); |
| 2132 | __ Subu(dst_low, lhs_low, rhs_low); |
| 2133 | __ Subu(dst_high, lhs_high, rhs_high); |
| 2134 | __ Subu(dst_high, dst_high, TMP); |
| 2135 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2136 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2137 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 2138 | if (instruction->IsOr()) { |
| 2139 | uint32_t low = Low32Bits(value); |
| 2140 | uint32_t high = High32Bits(value); |
| 2141 | if (IsUint<16>(low)) { |
| 2142 | if (dst_low != lhs_low || low != 0) { |
| 2143 | __ Ori(dst_low, lhs_low, low); |
| 2144 | } |
| 2145 | } else { |
| 2146 | __ LoadConst32(TMP, low); |
| 2147 | __ Or(dst_low, lhs_low, TMP); |
| 2148 | } |
| 2149 | if (IsUint<16>(high)) { |
| 2150 | if (dst_high != lhs_high || high != 0) { |
| 2151 | __ Ori(dst_high, lhs_high, high); |
| 2152 | } |
| 2153 | } else { |
| 2154 | if (high != low) { |
| 2155 | __ LoadConst32(TMP, high); |
| 2156 | } |
| 2157 | __ Or(dst_high, lhs_high, TMP); |
| 2158 | } |
| 2159 | } else if (instruction->IsXor()) { |
| 2160 | uint32_t low = Low32Bits(value); |
| 2161 | uint32_t high = High32Bits(value); |
| 2162 | if (IsUint<16>(low)) { |
| 2163 | if (dst_low != lhs_low || low != 0) { |
| 2164 | __ Xori(dst_low, lhs_low, low); |
| 2165 | } |
| 2166 | } else { |
| 2167 | __ LoadConst32(TMP, low); |
| 2168 | __ Xor(dst_low, lhs_low, TMP); |
| 2169 | } |
| 2170 | if (IsUint<16>(high)) { |
| 2171 | if (dst_high != lhs_high || high != 0) { |
| 2172 | __ Xori(dst_high, lhs_high, high); |
| 2173 | } |
| 2174 | } else { |
| 2175 | if (high != low) { |
| 2176 | __ LoadConst32(TMP, high); |
| 2177 | } |
| 2178 | __ Xor(dst_high, lhs_high, TMP); |
| 2179 | } |
| 2180 | } else if (instruction->IsAnd()) { |
| 2181 | uint32_t low = Low32Bits(value); |
| 2182 | uint32_t high = High32Bits(value); |
| 2183 | if (IsUint<16>(low)) { |
| 2184 | __ Andi(dst_low, lhs_low, low); |
| 2185 | } else if (low != 0xFFFFFFFF) { |
| 2186 | __ LoadConst32(TMP, low); |
| 2187 | __ And(dst_low, lhs_low, TMP); |
| 2188 | } else if (dst_low != lhs_low) { |
| 2189 | __ Move(dst_low, lhs_low); |
| 2190 | } |
| 2191 | if (IsUint<16>(high)) { |
| 2192 | __ Andi(dst_high, lhs_high, high); |
| 2193 | } else if (high != 0xFFFFFFFF) { |
| 2194 | if (high != low) { |
| 2195 | __ LoadConst32(TMP, high); |
| 2196 | } |
| 2197 | __ And(dst_high, lhs_high, TMP); |
| 2198 | } else if (dst_high != lhs_high) { |
| 2199 | __ Move(dst_high, lhs_high); |
| 2200 | } |
| 2201 | } else { |
| 2202 | if (instruction->IsSub()) { |
| 2203 | value = -value; |
| 2204 | } else { |
| 2205 | DCHECK(instruction->IsAdd()); |
| 2206 | } |
| 2207 | int32_t low = Low32Bits(value); |
| 2208 | int32_t high = High32Bits(value); |
| 2209 | if (IsInt<16>(low)) { |
| 2210 | if (dst_low != lhs_low || low != 0) { |
| 2211 | __ Addiu(dst_low, lhs_low, low); |
| 2212 | } |
| 2213 | if (low != 0) { |
| 2214 | __ Sltiu(AT, dst_low, low); |
| 2215 | } |
| 2216 | } else { |
| 2217 | __ LoadConst32(TMP, low); |
| 2218 | __ Addu(dst_low, lhs_low, TMP); |
| 2219 | __ Sltu(AT, dst_low, TMP); |
| 2220 | } |
| 2221 | if (IsInt<16>(high)) { |
| 2222 | if (dst_high != lhs_high || high != 0) { |
| 2223 | __ Addiu(dst_high, lhs_high, high); |
| 2224 | } |
| 2225 | } else { |
| 2226 | if (high != low) { |
| 2227 | __ LoadConst32(TMP, high); |
| 2228 | } |
| 2229 | __ Addu(dst_high, lhs_high, TMP); |
| 2230 | } |
| 2231 | if (low != 0) { |
| 2232 | __ Addu(dst_high, dst_high, AT); |
| 2233 | } |
| 2234 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2235 | } |
| 2236 | break; |
| 2237 | } |
| 2238 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2239 | case DataType::Type::kFloat32: |
| 2240 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2241 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2242 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2243 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2244 | if (instruction->IsAdd()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2245 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2246 | __ AddS(dst, lhs, rhs); |
| 2247 | } else { |
| 2248 | __ AddD(dst, lhs, rhs); |
| 2249 | } |
| 2250 | } else { |
| 2251 | DCHECK(instruction->IsSub()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2252 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2253 | __ SubS(dst, lhs, rhs); |
| 2254 | } else { |
| 2255 | __ SubD(dst, lhs, rhs); |
| 2256 | } |
| 2257 | } |
| 2258 | break; |
| 2259 | } |
| 2260 | |
| 2261 | default: |
| 2262 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 2263 | } |
| 2264 | } |
| 2265 | |
| 2266 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2267 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2268 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2269 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2270 | DataType::Type type = instr->GetResultType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2271 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2272 | case DataType::Type::kInt32: |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2273 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2274 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2275 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2276 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2277 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2278 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2279 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2280 | locations->SetOut(Location::RequiresRegister()); |
| 2281 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2282 | default: |
| 2283 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2284 | } |
| 2285 | } |
| 2286 | |
| 2287 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; |
| 2288 | |
| 2289 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2290 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2291 | LocationSummary* locations = instr->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2292 | DataType::Type type = instr->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2293 | |
| 2294 | Location rhs_location = locations->InAt(1); |
| 2295 | bool use_imm = rhs_location.IsConstant(); |
| 2296 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); |
| 2297 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2298 | const uint32_t shift_mask = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2299 | (type == DataType::Type::kInt32) ? kMaxIntShiftDistance : kMaxLongShiftDistance; |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2300 | const uint32_t shift_value = rhs_imm & shift_mask; |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2301 | // Are the INS (Insert Bit Field) and ROTR instructions supported? |
| 2302 | bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2303 | |
| 2304 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2305 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2306 | Register dst = locations->Out().AsRegister<Register>(); |
| 2307 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2308 | if (use_imm) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2309 | if (shift_value == 0) { |
| 2310 | if (dst != lhs) { |
| 2311 | __ Move(dst, lhs); |
| 2312 | } |
| 2313 | } else if (instr->IsShl()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2314 | __ Sll(dst, lhs, shift_value); |
| 2315 | } else if (instr->IsShr()) { |
| 2316 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2317 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2318 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2319 | } else { |
| 2320 | if (has_ins_rotr) { |
| 2321 | __ Rotr(dst, lhs, shift_value); |
| 2322 | } else { |
| 2323 | __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask); |
| 2324 | __ Srl(dst, lhs, shift_value); |
| 2325 | __ Or(dst, dst, TMP); |
| 2326 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2327 | } |
| 2328 | } else { |
| 2329 | if (instr->IsShl()) { |
| 2330 | __ Sllv(dst, lhs, rhs_reg); |
| 2331 | } else if (instr->IsShr()) { |
| 2332 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2333 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2334 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2335 | } else { |
| 2336 | if (has_ins_rotr) { |
| 2337 | __ Rotrv(dst, lhs, rhs_reg); |
| 2338 | } else { |
| 2339 | __ Subu(TMP, ZERO, rhs_reg); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2340 | // 32-bit shift instructions use the 5 least significant bits of the shift count, so |
| 2341 | // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case |
| 2342 | // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out |
| 2343 | // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`, |
| 2344 | // IOW, the OR'd values are equal. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2345 | __ Sllv(TMP, lhs, TMP); |
| 2346 | __ Srlv(dst, lhs, rhs_reg); |
| 2347 | __ Or(dst, dst, TMP); |
| 2348 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2349 | } |
| 2350 | } |
| 2351 | break; |
| 2352 | } |
| 2353 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2354 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2355 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2356 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2357 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2358 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2359 | if (use_imm) { |
| 2360 | if (shift_value == 0) { |
Lena Djokic | 8098da9 | 2017-06-28 12:07:50 +0200 | [diff] [blame] | 2361 | codegen_->MoveLocation(locations->Out(), locations->InAt(0), type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2362 | } else if (shift_value < kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2363 | if (has_ins_rotr) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2364 | if (instr->IsShl()) { |
| 2365 | __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2366 | __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value); |
| 2367 | __ Sll(dst_low, lhs_low, shift_value); |
| 2368 | } else if (instr->IsShr()) { |
| 2369 | __ Srl(dst_low, lhs_low, shift_value); |
| 2370 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2371 | __ Sra(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2372 | } else if (instr->IsUShr()) { |
| 2373 | __ Srl(dst_low, lhs_low, shift_value); |
| 2374 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2375 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2376 | } else { |
| 2377 | __ Srl(dst_low, lhs_low, shift_value); |
| 2378 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2379 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2380 | __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2381 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2382 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2383 | if (instr->IsShl()) { |
| 2384 | __ Sll(dst_low, lhs_low, shift_value); |
| 2385 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); |
| 2386 | __ Sll(dst_high, lhs_high, shift_value); |
| 2387 | __ Or(dst_high, dst_high, TMP); |
| 2388 | } else if (instr->IsShr()) { |
| 2389 | __ Sra(dst_high, lhs_high, shift_value); |
| 2390 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2391 | __ Srl(dst_low, lhs_low, shift_value); |
| 2392 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2393 | } else if (instr->IsUShr()) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2394 | __ Srl(dst_high, lhs_high, shift_value); |
| 2395 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2396 | __ Srl(dst_low, lhs_low, shift_value); |
| 2397 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2398 | } else { |
| 2399 | __ Srl(TMP, lhs_low, shift_value); |
| 2400 | __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value); |
| 2401 | __ Or(dst_low, dst_low, TMP); |
| 2402 | __ Srl(TMP, lhs_high, shift_value); |
| 2403 | __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2404 | __ Or(dst_high, dst_high, TMP); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2405 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2406 | } |
| 2407 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2408 | const uint32_t shift_value_high = shift_value - kMipsBitsPerWord; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2409 | if (instr->IsShl()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2410 | __ Sll(dst_high, lhs_low, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2411 | __ Move(dst_low, ZERO); |
| 2412 | } else if (instr->IsShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2413 | __ Sra(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2414 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2415 | } else if (instr->IsUShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2416 | __ Srl(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2417 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2418 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2419 | if (shift_value == kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2420 | // 64-bit rotation by 32 is just a swap. |
| 2421 | __ Move(dst_low, lhs_high); |
| 2422 | __ Move(dst_high, lhs_low); |
| 2423 | } else { |
| 2424 | if (has_ins_rotr) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2425 | __ Srl(dst_low, lhs_high, shift_value_high); |
| 2426 | __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high); |
| 2427 | __ Srl(dst_high, lhs_low, shift_value_high); |
| 2428 | __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2429 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2430 | __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high); |
| 2431 | __ Srl(dst_low, lhs_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2432 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2433 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high); |
| 2434 | __ Srl(dst_high, lhs_low, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2435 | __ Or(dst_high, dst_high, TMP); |
| 2436 | } |
| 2437 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2438 | } |
| 2439 | } |
| 2440 | } else { |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2441 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2442 | MipsLabel done; |
| 2443 | if (instr->IsShl()) { |
| 2444 | __ Sllv(dst_low, lhs_low, rhs_reg); |
| 2445 | __ Nor(AT, ZERO, rhs_reg); |
| 2446 | __ Srl(TMP, lhs_low, 1); |
| 2447 | __ Srlv(TMP, TMP, AT); |
| 2448 | __ Sllv(dst_high, lhs_high, rhs_reg); |
| 2449 | __ Or(dst_high, dst_high, TMP); |
| 2450 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2451 | if (isR6) { |
| 2452 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2453 | __ Move(dst_high, dst_low); |
| 2454 | __ Move(dst_low, ZERO); |
| 2455 | } else { |
| 2456 | __ Movn(dst_high, dst_low, TMP); |
| 2457 | __ Movn(dst_low, ZERO, TMP); |
| 2458 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2459 | } else if (instr->IsShr()) { |
| 2460 | __ Srav(dst_high, lhs_high, rhs_reg); |
| 2461 | __ Nor(AT, ZERO, rhs_reg); |
| 2462 | __ Sll(TMP, lhs_high, 1); |
| 2463 | __ Sllv(TMP, TMP, AT); |
| 2464 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2465 | __ Or(dst_low, dst_low, TMP); |
| 2466 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2467 | if (isR6) { |
| 2468 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2469 | __ Move(dst_low, dst_high); |
| 2470 | __ Sra(dst_high, dst_high, 31); |
| 2471 | } else { |
| 2472 | __ Sra(AT, dst_high, 31); |
| 2473 | __ Movn(dst_low, dst_high, TMP); |
| 2474 | __ Movn(dst_high, AT, TMP); |
| 2475 | } |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2476 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2477 | __ Srlv(dst_high, lhs_high, rhs_reg); |
| 2478 | __ Nor(AT, ZERO, rhs_reg); |
| 2479 | __ Sll(TMP, lhs_high, 1); |
| 2480 | __ Sllv(TMP, TMP, AT); |
| 2481 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2482 | __ Or(dst_low, dst_low, TMP); |
| 2483 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2484 | if (isR6) { |
| 2485 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2486 | __ Move(dst_low, dst_high); |
| 2487 | __ Move(dst_high, ZERO); |
| 2488 | } else { |
| 2489 | __ Movn(dst_low, dst_high, TMP); |
| 2490 | __ Movn(dst_high, ZERO, TMP); |
| 2491 | } |
| 2492 | } else { // Rotate. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2493 | __ Nor(AT, ZERO, rhs_reg); |
| 2494 | __ Srlv(TMP, lhs_low, rhs_reg); |
| 2495 | __ Sll(dst_low, lhs_high, 1); |
| 2496 | __ Sllv(dst_low, dst_low, AT); |
| 2497 | __ Or(dst_low, dst_low, TMP); |
| 2498 | __ Srlv(TMP, lhs_high, rhs_reg); |
| 2499 | __ Sll(dst_high, lhs_low, 1); |
| 2500 | __ Sllv(dst_high, dst_high, AT); |
| 2501 | __ Or(dst_high, dst_high, TMP); |
| 2502 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
Chris Larsen | 3e5fecd | 2017-11-09 14:21:28 -0800 | [diff] [blame] | 2503 | if (isR6) { |
| 2504 | __ Beqzc(TMP, &done, /* is_bare */ true); |
| 2505 | __ Move(TMP, dst_high); |
| 2506 | __ Move(dst_high, dst_low); |
| 2507 | __ Move(dst_low, TMP); |
| 2508 | } else { |
| 2509 | __ Movn(AT, dst_high, TMP); |
| 2510 | __ Movn(dst_high, dst_low, TMP); |
| 2511 | __ Movn(dst_low, AT, TMP); |
| 2512 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2513 | } |
| 2514 | __ Bind(&done); |
| 2515 | } |
| 2516 | break; |
| 2517 | } |
| 2518 | |
| 2519 | default: |
| 2520 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { |
| 2525 | HandleBinaryOp(instruction); |
| 2526 | } |
| 2527 | |
| 2528 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { |
| 2529 | HandleBinaryOp(instruction); |
| 2530 | } |
| 2531 | |
| 2532 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { |
| 2533 | HandleBinaryOp(instruction); |
| 2534 | } |
| 2535 | |
| 2536 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { |
| 2537 | HandleBinaryOp(instruction); |
| 2538 | } |
| 2539 | |
| 2540 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2541 | DataType::Type type = instruction->GetType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2542 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2543 | kEmitCompilerReadBarrier && (type == DataType::Type::kReference); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2544 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2545 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2546 | object_array_get_with_read_barrier |
| 2547 | ? LocationSummary::kCallOnSlowPath |
| 2548 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 2549 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2550 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2551 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2552 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2553 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2554 | if (DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2555 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2556 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2557 | // The output overlaps in the case of an object array get with |
| 2558 | // read barriers enabled: we do not want the move to overwrite the |
| 2559 | // array's location, as we need it to emit the read barrier. |
| 2560 | locations->SetOut(Location::RequiresRegister(), |
| 2561 | object_array_get_with_read_barrier |
| 2562 | ? Location::kOutputOverlap |
| 2563 | : Location::kNoOutputOverlap); |
| 2564 | } |
| 2565 | // We need a temporary register for the read barrier marking slow |
| 2566 | // path in CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier. |
| 2567 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2568 | bool temp_needed = instruction->GetIndex()->IsConstant() |
| 2569 | ? !kBakerReadBarrierThunksEnableForFields |
| 2570 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2571 | if (temp_needed) { |
| 2572 | locations->AddTemp(Location::RequiresRegister()); |
| 2573 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2574 | } |
| 2575 | } |
| 2576 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2577 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS* codegen) { |
| 2578 | auto null_checker = [codegen, instruction]() { |
| 2579 | codegen->MaybeRecordImplicitNullCheck(instruction); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2580 | }; |
| 2581 | return null_checker; |
| 2582 | } |
| 2583 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2584 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 2585 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2586 | Location obj_loc = locations->InAt(0); |
| 2587 | Register obj = obj_loc.AsRegister<Register>(); |
| 2588 | Location out_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2589 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2590 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2591 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2592 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2593 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2594 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2595 | instruction->IsStringCharAt(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2596 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2597 | case DataType::Type::kBool: |
| 2598 | case DataType::Type::kUint8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2599 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2600 | if (index.IsConstant()) { |
| 2601 | size_t offset = |
| 2602 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2603 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2604 | } else { |
| 2605 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2606 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2607 | } |
| 2608 | break; |
| 2609 | } |
| 2610 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2611 | case DataType::Type::kInt8: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2612 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2613 | if (index.IsConstant()) { |
| 2614 | size_t offset = |
| 2615 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2616 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2617 | } else { |
| 2618 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2619 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2620 | } |
| 2621 | break; |
| 2622 | } |
| 2623 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2624 | case DataType::Type::kUint16: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2625 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2626 | if (maybe_compressed_char_at) { |
| 2627 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2628 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
| 2629 | __ Sll(TMP, TMP, 31); // Extract compression flag into the most significant bit of TMP. |
| 2630 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2631 | "Expecting 0=compressed, 1=uncompressed"); |
| 2632 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2633 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2634 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2635 | if (maybe_compressed_char_at) { |
| 2636 | MipsLabel uncompressed_load, done; |
| 2637 | __ Bnez(TMP, &uncompressed_load); |
| 2638 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2639 | out, |
| 2640 | obj, |
| 2641 | data_offset + (const_index << TIMES_1)); |
| 2642 | __ B(&done); |
| 2643 | __ Bind(&uncompressed_load); |
| 2644 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2645 | out, |
| 2646 | obj, |
| 2647 | data_offset + (const_index << TIMES_2)); |
| 2648 | __ Bind(&done); |
| 2649 | } else { |
| 2650 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2651 | out, |
| 2652 | obj, |
| 2653 | data_offset + (const_index << TIMES_2), |
| 2654 | null_checker); |
| 2655 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2656 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2657 | Register index_reg = index.AsRegister<Register>(); |
| 2658 | if (maybe_compressed_char_at) { |
| 2659 | MipsLabel uncompressed_load, done; |
| 2660 | __ Bnez(TMP, &uncompressed_load); |
| 2661 | __ Addu(TMP, obj, index_reg); |
| 2662 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2663 | __ B(&done); |
| 2664 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2665 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2666 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2667 | __ Bind(&done); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2668 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2669 | __ Addu(TMP, index_reg, obj); |
| 2670 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2671 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2672 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2673 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
| 2674 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2675 | } |
| 2676 | break; |
| 2677 | } |
| 2678 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2679 | case DataType::Type::kInt16: { |
| 2680 | Register out = out_loc.AsRegister<Register>(); |
| 2681 | if (index.IsConstant()) { |
| 2682 | size_t offset = |
| 2683 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2684 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2685 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2686 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2687 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2688 | } else { |
| 2689 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_2, TMP); |
| 2690 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
| 2691 | } |
| 2692 | break; |
| 2693 | } |
| 2694 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2695 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2696 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2697 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2698 | if (index.IsConstant()) { |
| 2699 | size_t offset = |
| 2700 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2701 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2702 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2703 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2704 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2705 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2706 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2707 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2708 | } |
| 2709 | break; |
| 2710 | } |
| 2711 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2712 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2713 | static_assert( |
| 2714 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2715 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2716 | // /* HeapReference<Object> */ out = |
| 2717 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2718 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2719 | bool temp_needed = index.IsConstant() |
| 2720 | ? !kBakerReadBarrierThunksEnableForFields |
| 2721 | : !kBakerReadBarrierThunksEnableForArrays; |
| 2722 | Location temp = temp_needed ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2723 | // Note that a potential implicit null check is handled in this |
| 2724 | // CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier call. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 2725 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 2726 | if (index.IsConstant()) { |
| 2727 | // Array load with a constant index can be treated as a field load. |
| 2728 | size_t offset = |
| 2729 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2730 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2731 | out_loc, |
| 2732 | obj, |
| 2733 | offset, |
| 2734 | temp, |
| 2735 | /* needs_null_check */ false); |
| 2736 | } else { |
| 2737 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2738 | out_loc, |
| 2739 | obj, |
| 2740 | data_offset, |
| 2741 | index, |
| 2742 | temp, |
| 2743 | /* needs_null_check */ false); |
| 2744 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2745 | } else { |
| 2746 | Register out = out_loc.AsRegister<Register>(); |
| 2747 | if (index.IsConstant()) { |
| 2748 | size_t offset = |
| 2749 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2750 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
| 2751 | // If read barriers are enabled, emit read barriers other than |
| 2752 | // Baker's using a slow path (and also unpoison the loaded |
| 2753 | // reference, if heap poisoning is enabled). |
| 2754 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2755 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2756 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2757 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
| 2758 | // If read barriers are enabled, emit read barriers other than |
| 2759 | // Baker's using a slow path (and also unpoison the loaded |
| 2760 | // reference, if heap poisoning is enabled). |
| 2761 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2762 | out_loc, |
| 2763 | out_loc, |
| 2764 | obj_loc, |
| 2765 | data_offset, |
| 2766 | index); |
| 2767 | } |
| 2768 | } |
| 2769 | break; |
| 2770 | } |
| 2771 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2772 | case DataType::Type::kInt64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2773 | Register out = out_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2774 | if (index.IsConstant()) { |
| 2775 | size_t offset = |
| 2776 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2777 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2778 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2779 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2780 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2781 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2782 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2783 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2784 | } |
| 2785 | break; |
| 2786 | } |
| 2787 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2788 | case DataType::Type::kFloat32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2789 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2790 | if (index.IsConstant()) { |
| 2791 | size_t offset = |
| 2792 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2793 | __ LoadSFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2794 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2795 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2796 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2797 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2798 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2799 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2800 | } |
| 2801 | break; |
| 2802 | } |
| 2803 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2804 | case DataType::Type::kFloat64: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2805 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2806 | if (index.IsConstant()) { |
| 2807 | size_t offset = |
| 2808 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2809 | __ LoadDFromOffset(out, obj, offset, null_checker); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2810 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2811 | __ Addu(TMP, index.AsRegister<Register>(), obj); |
| 2812 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2813 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2814 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2815 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2816 | } |
| 2817 | break; |
| 2818 | } |
| 2819 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2820 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2821 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2822 | UNREACHABLE(); |
| 2823 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2827 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2828 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2829 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2830 | } |
| 2831 | |
| 2832 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 2833 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2834 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2835 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2836 | Register out = locations->Out().AsRegister<Register>(); |
| 2837 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2838 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2839 | // Mask out compression flag from String's array length. |
| 2840 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2841 | __ Srl(out, out, 1u); |
| 2842 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2843 | } |
| 2844 | |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2845 | Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2846 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2847 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2848 | : Location::RequiresRegister(); |
| 2849 | } |
| 2850 | |
| 2851 | Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2852 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2853 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2854 | // but we should only prefer this if the constant has a single use. |
| 2855 | if (instruction->IsConstant() && |
| 2856 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2857 | instruction->GetUses().HasExactlyOneElement())) { |
| 2858 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2859 | // Otherwise fall through and require an FPU register for the constant. |
| 2860 | } |
| 2861 | return Location::RequiresFpuRegister(); |
| 2862 | } |
| 2863 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2864 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2865 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2866 | |
| 2867 | bool needs_write_barrier = |
| 2868 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2869 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2870 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2871 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2872 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2873 | may_need_runtime_call_for_type_check ? |
| 2874 | LocationSummary::kCallOnSlowPath : |
| 2875 | LocationSummary::kNoCall); |
| 2876 | |
| 2877 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2878 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2879 | if (DataType::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2880 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2881 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2882 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2883 | } |
| 2884 | if (needs_write_barrier) { |
| 2885 | // Temporary register for the write barrier. |
| 2886 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2887 | } |
| 2888 | } |
| 2889 | |
| 2890 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { |
| 2891 | LocationSummary* locations = instruction->GetLocations(); |
| 2892 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2893 | Location index = locations->InAt(1); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2894 | Location value_location = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2895 | DataType::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2896 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2897 | bool needs_write_barrier = |
| 2898 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2899 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2900 | Register base_reg = index.IsConstant() ? obj : TMP; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2901 | |
| 2902 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2903 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2904 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2905 | case DataType::Type::kInt8: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2906 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2907 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2908 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2909 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2910 | __ Addu(base_reg, obj, index.AsRegister<Register>()); |
| 2911 | } |
| 2912 | if (value_location.IsConstant()) { |
| 2913 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2914 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2915 | } else { |
| 2916 | Register value = value_location.AsRegister<Register>(); |
| 2917 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2918 | } |
| 2919 | break; |
| 2920 | } |
| 2921 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2922 | case DataType::Type::kUint16: |
| 2923 | case DataType::Type::kInt16: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2924 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2925 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2926 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2927 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2928 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2929 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2930 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_2, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2931 | } |
| 2932 | if (value_location.IsConstant()) { |
| 2933 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2934 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2935 | } else { |
| 2936 | Register value = value_location.AsRegister<Register>(); |
| 2937 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2938 | } |
| 2939 | break; |
| 2940 | } |
| 2941 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2942 | case DataType::Type::kInt32: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2943 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2944 | if (index.IsConstant()) { |
| 2945 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2946 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2947 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2948 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2949 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2950 | } |
| 2951 | if (value_location.IsConstant()) { |
| 2952 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2953 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2954 | } else { |
| 2955 | Register value = value_location.AsRegister<Register>(); |
| 2956 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2957 | } |
| 2958 | break; |
| 2959 | } |
| 2960 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2961 | case DataType::Type::kReference: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2962 | if (value_location.IsConstant()) { |
| 2963 | // Just setting null. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2964 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2965 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2966 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2967 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2968 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2969 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2970 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2971 | DCHECK_EQ(value, 0); |
| 2972 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2973 | DCHECK(!needs_write_barrier); |
| 2974 | DCHECK(!may_need_runtime_call_for_type_check); |
| 2975 | break; |
| 2976 | } |
| 2977 | |
| 2978 | DCHECK(needs_write_barrier); |
| 2979 | Register value = value_location.AsRegister<Register>(); |
| 2980 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2981 | Register temp2 = TMP; // Doesn't need to survive slow path. |
| 2982 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2983 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2984 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2985 | MipsLabel done; |
| 2986 | SlowPathCodeMIPS* slow_path = nullptr; |
| 2987 | |
| 2988 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2989 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathMIPS(instruction); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2990 | codegen_->AddSlowPath(slow_path); |
| 2991 | if (instruction->GetValueCanBeNull()) { |
| 2992 | MipsLabel non_zero; |
| 2993 | __ Bnez(value, &non_zero); |
| 2994 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2995 | if (index.IsConstant()) { |
| 2996 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 2997 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 2998 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2999 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3000 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 3001 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3002 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 3003 | __ B(&done); |
| 3004 | __ Bind(&non_zero); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3005 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3006 | |
| 3007 | // Note that when read barriers are enabled, the type checks |
| 3008 | // are performed without read barriers. This is fine, even in |
| 3009 | // the case where a class object is in the from-space after |
| 3010 | // the flip, as a comparison involving such a type would not |
| 3011 | // produce a false positive; it may of course produce a false |
| 3012 | // negative, in which case we would take the ArraySet slow |
| 3013 | // path. |
| 3014 | |
| 3015 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 3016 | __ LoadFromOffset(kLoadWord, temp1, obj, class_offset, null_checker); |
| 3017 | __ MaybeUnpoisonHeapReference(temp1); |
| 3018 | |
| 3019 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 3020 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 3021 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3022 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 3023 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 3024 | // nor `temp2`, as we are comparing two poisoned references. |
| 3025 | |
| 3026 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3027 | MipsLabel do_put; |
| 3028 | __ Beq(temp1, temp2, &do_put); |
| 3029 | // If heap poisoning is enabled, the `temp1` reference has |
| 3030 | // not been unpoisoned yet; unpoison it now. |
| 3031 | __ MaybeUnpoisonHeapReference(temp1); |
| 3032 | |
| 3033 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 3034 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 3035 | // If heap poisoning is enabled, no need to unpoison |
| 3036 | // `temp1`, as we are comparing against null below. |
| 3037 | __ Bnez(temp1, slow_path->GetEntryLabel()); |
| 3038 | __ Bind(&do_put); |
| 3039 | } else { |
| 3040 | __ Bne(temp1, temp2, slow_path->GetEntryLabel()); |
| 3041 | } |
| 3042 | } |
| 3043 | |
| 3044 | Register source = value; |
| 3045 | if (kPoisonHeapReferences) { |
| 3046 | // Note that in the case where `value` is a null reference, |
| 3047 | // we do not enter this block, as a null reference does not |
| 3048 | // need poisoning. |
| 3049 | __ Move(temp1, value); |
| 3050 | __ PoisonHeapReference(temp1); |
| 3051 | source = temp1; |
| 3052 | } |
| 3053 | |
| 3054 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3055 | if (index.IsConstant()) { |
| 3056 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3057 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3058 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3059 | } |
| 3060 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 3061 | |
| 3062 | if (!may_need_runtime_call_for_type_check) { |
| 3063 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3064 | } |
| 3065 | |
| 3066 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 3067 | |
| 3068 | if (done.IsLinked()) { |
| 3069 | __ Bind(&done); |
| 3070 | } |
| 3071 | |
| 3072 | if (slow_path != nullptr) { |
| 3073 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3074 | } |
| 3075 | break; |
| 3076 | } |
| 3077 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3078 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3079 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3080 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3081 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3082 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3083 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3084 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3085 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3086 | } |
| 3087 | if (value_location.IsConstant()) { |
| 3088 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3089 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3090 | } else { |
| 3091 | Register value = value_location.AsRegisterPairLow<Register>(); |
| 3092 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3093 | } |
| 3094 | break; |
| 3095 | } |
| 3096 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3097 | case DataType::Type::kFloat32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3098 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3099 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3100 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3101 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3102 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3103 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3104 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3105 | } |
| 3106 | if (value_location.IsConstant()) { |
| 3107 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 3108 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 3109 | } else { |
| 3110 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3111 | __ StoreSToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3112 | } |
| 3113 | break; |
| 3114 | } |
| 3115 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3116 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3117 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3118 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3119 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3120 | } else if (instruction->InputAt(1)->IsIntermediateArrayAddressIndex()) { |
| 3121 | __ Addu(base_reg, index.AsRegister<Register>(), obj); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3122 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 3123 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 3124 | } |
| 3125 | if (value_location.IsConstant()) { |
| 3126 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 3127 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 3128 | } else { |
| 3129 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 3130 | __ StoreDToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3131 | } |
| 3132 | break; |
| 3133 | } |
| 3134 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3135 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3136 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 3137 | UNREACHABLE(); |
| 3138 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3139 | } |
| 3140 | |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3141 | void LocationsBuilderMIPS::VisitIntermediateArrayAddressIndex( |
| 3142 | HIntermediateArrayAddressIndex* instruction) { |
| 3143 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3144 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 3145 | |
| 3146 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 3147 | |
| 3148 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3149 | locations->SetInAt(1, Location::ConstantLocation(shift)); |
| 3150 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3151 | } |
| 3152 | |
| 3153 | void InstructionCodeGeneratorMIPS::VisitIntermediateArrayAddressIndex( |
| 3154 | HIntermediateArrayAddressIndex* instruction) { |
| 3155 | LocationSummary* locations = instruction->GetLocations(); |
| 3156 | Register index_reg = locations->InAt(0).AsRegister<Register>(); |
| 3157 | uint32_t shift = instruction->GetShift()->AsIntConstant()->GetValue(); |
| 3158 | __ Sll(locations->Out().AsRegister<Register>(), index_reg, shift); |
| 3159 | } |
| 3160 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3161 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3162 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3163 | InvokeRuntimeCallingConvention calling_convention; |
| 3164 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3165 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3166 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3167 | |
| 3168 | HInstruction* index = instruction->InputAt(0); |
| 3169 | HInstruction* length = instruction->InputAt(1); |
| 3170 | |
| 3171 | bool const_index = false; |
| 3172 | bool const_length = false; |
| 3173 | |
| 3174 | if (index->IsConstant()) { |
| 3175 | if (length->IsConstant()) { |
| 3176 | const_index = true; |
| 3177 | const_length = true; |
| 3178 | } else { |
| 3179 | int32_t index_value = index->AsIntConstant()->GetValue(); |
| 3180 | if (index_value < 0 || IsInt<16>(index_value + 1)) { |
| 3181 | const_index = true; |
| 3182 | } |
| 3183 | } |
| 3184 | } else if (length->IsConstant()) { |
| 3185 | int32_t length_value = length->AsIntConstant()->GetValue(); |
| 3186 | if (IsUint<15>(length_value)) { |
| 3187 | const_length = true; |
| 3188 | } |
| 3189 | } |
| 3190 | |
| 3191 | locations->SetInAt(0, const_index |
| 3192 | ? Location::ConstantLocation(index->AsConstant()) |
| 3193 | : Location::RequiresRegister()); |
| 3194 | locations->SetInAt(1, const_length |
| 3195 | ? Location::ConstantLocation(length->AsConstant()) |
| 3196 | : Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 3200 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3201 | Location index_loc = locations->InAt(0); |
| 3202 | Location length_loc = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3203 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3204 | if (length_loc.IsConstant()) { |
| 3205 | int32_t length = length_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3206 | if (index_loc.IsConstant()) { |
| 3207 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3208 | if (index < 0 || index >= length) { |
| 3209 | BoundsCheckSlowPathMIPS* slow_path = |
| 3210 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3211 | codegen_->AddSlowPath(slow_path); |
| 3212 | __ B(slow_path->GetEntryLabel()); |
| 3213 | } else { |
| 3214 | // Nothing to be done. |
| 3215 | } |
| 3216 | return; |
| 3217 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3218 | |
Goran Jakovljevic | dbd4303 | 2017-11-15 16:31:56 +0100 | [diff] [blame] | 3219 | BoundsCheckSlowPathMIPS* slow_path = |
| 3220 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3221 | codegen_->AddSlowPath(slow_path); |
| 3222 | Register index = index_loc.AsRegister<Register>(); |
| 3223 | if (length == 0) { |
| 3224 | __ B(slow_path->GetEntryLabel()); |
| 3225 | } else if (length == 1) { |
| 3226 | __ Bnez(index, slow_path->GetEntryLabel()); |
| 3227 | } else { |
| 3228 | DCHECK(IsUint<15>(length)) << length; |
| 3229 | __ Sltiu(TMP, index, length); |
| 3230 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3231 | } |
| 3232 | } else { |
| 3233 | Register length = length_loc.AsRegister<Register>(); |
| 3234 | BoundsCheckSlowPathMIPS* slow_path = |
| 3235 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathMIPS(instruction); |
| 3236 | codegen_->AddSlowPath(slow_path); |
| 3237 | if (index_loc.IsConstant()) { |
| 3238 | int32_t index = index_loc.GetConstant()->AsIntConstant()->GetValue(); |
| 3239 | if (index < 0) { |
| 3240 | __ B(slow_path->GetEntryLabel()); |
| 3241 | } else if (index == 0) { |
| 3242 | __ Blez(length, slow_path->GetEntryLabel()); |
| 3243 | } else { |
| 3244 | DCHECK(IsInt<16>(index + 1)) << index; |
| 3245 | __ Sltiu(TMP, length, index + 1); |
| 3246 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 3247 | } |
| 3248 | } else { |
| 3249 | Register index = index_loc.AsRegister<Register>(); |
| 3250 | __ Bgeu(index, length, slow_path->GetEntryLabel()); |
| 3251 | } |
| 3252 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3253 | } |
| 3254 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3255 | // Temp is used for read barrier. |
| 3256 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3257 | if (kEmitCompilerReadBarrier && |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 3258 | !(kUseBakerReadBarrier && kBakerReadBarrierThunksEnableForFields) && |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3259 | (kUseBakerReadBarrier || |
| 3260 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3261 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3262 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3263 | return 1; |
| 3264 | } |
| 3265 | return 0; |
| 3266 | } |
| 3267 | |
| 3268 | // Extra temp is used for read barrier. |
| 3269 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3270 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 3271 | } |
| 3272 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3273 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3274 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3275 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 3276 | |
| 3277 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3278 | switch (type_check_kind) { |
| 3279 | case TypeCheckKind::kExactCheck: |
| 3280 | case TypeCheckKind::kAbstractClassCheck: |
| 3281 | case TypeCheckKind::kClassHierarchyCheck: |
| 3282 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3283 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3284 | ? LocationSummary::kCallOnSlowPath |
| 3285 | : LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 3286 | break; |
| 3287 | case TypeCheckKind::kArrayCheck: |
| 3288 | case TypeCheckKind::kUnresolvedCheck: |
| 3289 | case TypeCheckKind::kInterfaceCheck: |
| 3290 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3291 | break; |
| 3292 | } |
| 3293 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3294 | LocationSummary* locations = |
| 3295 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3296 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3297 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3298 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3302 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3303 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3304 | Location obj_loc = locations->InAt(0); |
| 3305 | Register obj = obj_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3306 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3307 | Location temp_loc = locations->GetTemp(0); |
| 3308 | Register temp = temp_loc.AsRegister<Register>(); |
| 3309 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 3310 | DCHECK_LE(num_temps, 2u); |
| 3311 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3312 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3313 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3314 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3315 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 3316 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 3317 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 3318 | const uint32_t object_array_data_offset = |
| 3319 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 3320 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3321 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3322 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 3323 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 3324 | // read barriers is done for performance and code size reasons. |
| 3325 | bool is_type_check_slow_path_fatal = false; |
| 3326 | if (!kEmitCompilerReadBarrier) { |
| 3327 | is_type_check_slow_path_fatal = |
| 3328 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 3329 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3330 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3331 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 3332 | !instruction->CanThrowIntoCatchBlock(); |
| 3333 | } |
| 3334 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3335 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 3336 | instruction, is_type_check_slow_path_fatal); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3337 | codegen_->AddSlowPath(slow_path); |
| 3338 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3339 | // Avoid this check if we know `obj` is not null. |
| 3340 | if (instruction->MustDoNullCheck()) { |
| 3341 | __ Beqz(obj, &done); |
| 3342 | } |
| 3343 | |
| 3344 | switch (type_check_kind) { |
| 3345 | case TypeCheckKind::kExactCheck: |
| 3346 | case TypeCheckKind::kArrayCheck: { |
| 3347 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3348 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3349 | temp_loc, |
| 3350 | obj_loc, |
| 3351 | class_offset, |
| 3352 | maybe_temp2_loc, |
| 3353 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3354 | // Jump to slow path for throwing the exception or doing a |
| 3355 | // more involved array check. |
| 3356 | __ Bne(temp, cls, slow_path->GetEntryLabel()); |
| 3357 | break; |
| 3358 | } |
| 3359 | |
| 3360 | case TypeCheckKind::kAbstractClassCheck: { |
| 3361 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3362 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3363 | temp_loc, |
| 3364 | obj_loc, |
| 3365 | class_offset, |
| 3366 | maybe_temp2_loc, |
| 3367 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3368 | // If the class is abstract, we eagerly fetch the super class of the |
| 3369 | // object to avoid doing a comparison we know will fail. |
| 3370 | MipsLabel loop; |
| 3371 | __ Bind(&loop); |
| 3372 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3373 | GenerateReferenceLoadOneRegister(instruction, |
| 3374 | temp_loc, |
| 3375 | super_offset, |
| 3376 | maybe_temp2_loc, |
| 3377 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3378 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3379 | // exception. |
| 3380 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3381 | // Otherwise, compare the classes. |
| 3382 | __ Bne(temp, cls, &loop); |
| 3383 | break; |
| 3384 | } |
| 3385 | |
| 3386 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3387 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3388 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3389 | temp_loc, |
| 3390 | obj_loc, |
| 3391 | class_offset, |
| 3392 | maybe_temp2_loc, |
| 3393 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3394 | // Walk over the class hierarchy to find a match. |
| 3395 | MipsLabel loop; |
| 3396 | __ Bind(&loop); |
| 3397 | __ Beq(temp, cls, &done); |
| 3398 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3399 | GenerateReferenceLoadOneRegister(instruction, |
| 3400 | temp_loc, |
| 3401 | super_offset, |
| 3402 | maybe_temp2_loc, |
| 3403 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3404 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3405 | // exception. Otherwise, jump to the beginning of the loop. |
| 3406 | __ Bnez(temp, &loop); |
| 3407 | __ B(slow_path->GetEntryLabel()); |
| 3408 | break; |
| 3409 | } |
| 3410 | |
| 3411 | case TypeCheckKind::kArrayObjectCheck: { |
| 3412 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3413 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3414 | temp_loc, |
| 3415 | obj_loc, |
| 3416 | class_offset, |
| 3417 | maybe_temp2_loc, |
| 3418 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3419 | // Do an exact check. |
| 3420 | __ Beq(temp, cls, &done); |
| 3421 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 3422 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3423 | GenerateReferenceLoadOneRegister(instruction, |
| 3424 | temp_loc, |
| 3425 | component_offset, |
| 3426 | maybe_temp2_loc, |
| 3427 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3428 | // If the component type is null, jump to the slow path to throw the exception. |
| 3429 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3430 | // Otherwise, the object is indeed an array, further check that this component |
| 3431 | // type is not a primitive type. |
| 3432 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 3433 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3434 | __ Bnez(temp, slow_path->GetEntryLabel()); |
| 3435 | break; |
| 3436 | } |
| 3437 | |
| 3438 | case TypeCheckKind::kUnresolvedCheck: |
| 3439 | // We always go into the type check slow path for the unresolved check case. |
| 3440 | // We cannot directly call the CheckCast runtime entry point |
| 3441 | // without resorting to a type checking slow path here (i.e. by |
| 3442 | // calling InvokeRuntime directly), as it would require to |
| 3443 | // assign fixed registers for the inputs of this HInstanceOf |
| 3444 | // instruction (following the runtime calling convention), which |
| 3445 | // might be cluttered by the potential first read barrier |
| 3446 | // emission at the beginning of this method. |
| 3447 | __ B(slow_path->GetEntryLabel()); |
| 3448 | break; |
| 3449 | |
| 3450 | case TypeCheckKind::kInterfaceCheck: { |
| 3451 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 3452 | // positives by doing this. |
| 3453 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3454 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3455 | temp_loc, |
| 3456 | obj_loc, |
| 3457 | class_offset, |
| 3458 | maybe_temp2_loc, |
| 3459 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3460 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3461 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3462 | temp_loc, |
| 3463 | temp_loc, |
| 3464 | iftable_offset, |
| 3465 | maybe_temp2_loc, |
| 3466 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3467 | // Iftable is never null. |
| 3468 | __ Lw(TMP, temp, array_length_offset); |
| 3469 | // Loop through the iftable and check if any class matches. |
| 3470 | MipsLabel loop; |
| 3471 | __ Bind(&loop); |
| 3472 | __ Addiu(temp, temp, 2 * kHeapReferenceSize); // Possibly in delay slot on R2. |
| 3473 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3474 | __ Lw(AT, temp, object_array_data_offset - 2 * kHeapReferenceSize); |
| 3475 | __ MaybeUnpoisonHeapReference(AT); |
| 3476 | // Go to next interface. |
| 3477 | __ Addiu(TMP, TMP, -2); |
| 3478 | // Compare the classes and continue the loop if they do not match. |
| 3479 | __ Bne(AT, cls, &loop); |
| 3480 | break; |
| 3481 | } |
| 3482 | } |
| 3483 | |
| 3484 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3485 | __ Bind(slow_path->GetExitLabel()); |
| 3486 | } |
| 3487 | |
| 3488 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3489 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3490 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3491 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3492 | if (check->HasUses()) { |
| 3493 | locations->SetOut(Location::SameAsFirstInput()); |
| 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3498 | // We assume the class is not null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3499 | SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS( |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3500 | check->GetLoadClass(), |
| 3501 | check, |
| 3502 | check->GetDexPc(), |
| 3503 | true); |
| 3504 | codegen_->AddSlowPath(slow_path); |
| 3505 | GenerateClassInitializationCheck(slow_path, |
| 3506 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| 3507 | } |
| 3508 | |
| 3509 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3510 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3511 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3512 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3513 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3514 | |
| 3515 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3516 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3517 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3518 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3519 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3520 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3521 | case DataType::Type::kInt32: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3522 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3523 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3524 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3525 | break; |
| 3526 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3527 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3528 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3529 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3530 | // Output overlaps because it is written before doing the low comparison. |
| 3531 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3532 | break; |
| 3533 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3534 | case DataType::Type::kFloat32: |
| 3535 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3536 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3537 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3538 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3539 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3540 | |
| 3541 | default: |
| 3542 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3543 | } |
| 3544 | } |
| 3545 | |
| 3546 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { |
| 3547 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3548 | Register res = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3549 | DataType::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3550 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3551 | |
| 3552 | // 0 if: left == right |
| 3553 | // 1 if: left > right |
| 3554 | // -1 if: left < right |
| 3555 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3556 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3557 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3558 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3559 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3560 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3561 | case DataType::Type::kInt32: { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3562 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3563 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 3564 | __ Slt(TMP, lhs, rhs); |
| 3565 | __ Slt(res, rhs, lhs); |
| 3566 | __ Subu(res, res, TMP); |
| 3567 | break; |
| 3568 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3569 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3570 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3571 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3572 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3573 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 3574 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 3575 | // TODO: more efficient (direct) comparison with a constant. |
| 3576 | __ Slt(TMP, lhs_high, rhs_high); |
| 3577 | __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt. |
| 3578 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3579 | __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal. |
| 3580 | __ Sltu(TMP, lhs_low, rhs_low); |
| 3581 | __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt. |
| 3582 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3583 | __ Bind(&done); |
| 3584 | break; |
| 3585 | } |
| 3586 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3587 | case DataType::Type::kFloat32: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3588 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3589 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3590 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3591 | MipsLabel done; |
| 3592 | if (isR6) { |
| 3593 | __ CmpEqS(FTMP, lhs, rhs); |
| 3594 | __ LoadConst32(res, 0); |
| 3595 | __ Bc1nez(FTMP, &done); |
| 3596 | if (gt_bias) { |
| 3597 | __ CmpLtS(FTMP, lhs, rhs); |
| 3598 | __ LoadConst32(res, -1); |
| 3599 | __ Bc1nez(FTMP, &done); |
| 3600 | __ LoadConst32(res, 1); |
| 3601 | } else { |
| 3602 | __ CmpLtS(FTMP, rhs, lhs); |
| 3603 | __ LoadConst32(res, 1); |
| 3604 | __ Bc1nez(FTMP, &done); |
| 3605 | __ LoadConst32(res, -1); |
| 3606 | } |
| 3607 | } else { |
| 3608 | if (gt_bias) { |
| 3609 | __ ColtS(0, lhs, rhs); |
| 3610 | __ LoadConst32(res, -1); |
| 3611 | __ Bc1t(0, &done); |
| 3612 | __ CeqS(0, lhs, rhs); |
| 3613 | __ LoadConst32(res, 1); |
| 3614 | __ Movt(res, ZERO, 0); |
| 3615 | } else { |
| 3616 | __ ColtS(0, rhs, lhs); |
| 3617 | __ LoadConst32(res, 1); |
| 3618 | __ Bc1t(0, &done); |
| 3619 | __ CeqS(0, lhs, rhs); |
| 3620 | __ LoadConst32(res, -1); |
| 3621 | __ Movt(res, ZERO, 0); |
| 3622 | } |
| 3623 | } |
| 3624 | __ Bind(&done); |
| 3625 | break; |
| 3626 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3627 | case DataType::Type::kFloat64: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3628 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3629 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3630 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3631 | MipsLabel done; |
| 3632 | if (isR6) { |
| 3633 | __ CmpEqD(FTMP, lhs, rhs); |
| 3634 | __ LoadConst32(res, 0); |
| 3635 | __ Bc1nez(FTMP, &done); |
| 3636 | if (gt_bias) { |
| 3637 | __ CmpLtD(FTMP, lhs, rhs); |
| 3638 | __ LoadConst32(res, -1); |
| 3639 | __ Bc1nez(FTMP, &done); |
| 3640 | __ LoadConst32(res, 1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3641 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3642 | __ CmpLtD(FTMP, rhs, lhs); |
| 3643 | __ LoadConst32(res, 1); |
| 3644 | __ Bc1nez(FTMP, &done); |
| 3645 | __ LoadConst32(res, -1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3646 | } |
| 3647 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3648 | if (gt_bias) { |
| 3649 | __ ColtD(0, lhs, rhs); |
| 3650 | __ LoadConst32(res, -1); |
| 3651 | __ Bc1t(0, &done); |
| 3652 | __ CeqD(0, lhs, rhs); |
| 3653 | __ LoadConst32(res, 1); |
| 3654 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3655 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3656 | __ ColtD(0, rhs, lhs); |
| 3657 | __ LoadConst32(res, 1); |
| 3658 | __ Bc1t(0, &done); |
| 3659 | __ CeqD(0, lhs, rhs); |
| 3660 | __ LoadConst32(res, -1); |
| 3661 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3662 | } |
| 3663 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3664 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3665 | break; |
| 3666 | } |
| 3667 | |
| 3668 | default: |
| 3669 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3670 | } |
| 3671 | } |
| 3672 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3673 | void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3674 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3675 | switch (instruction->InputAt(0)->GetType()) { |
| 3676 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3677 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3678 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3679 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3680 | break; |
| 3681 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3682 | case DataType::Type::kFloat32: |
| 3683 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3684 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3685 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3686 | break; |
| 3687 | } |
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 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3690 | } |
| 3691 | } |
| 3692 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3693 | void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3694 | if (instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3695 | return; |
| 3696 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3697 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3698 | DataType::Type type = instruction->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3699 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3700 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3701 | switch (type) { |
| 3702 | default: |
| 3703 | // Integer case. |
| 3704 | GenerateIntCompare(instruction->GetCondition(), locations); |
| 3705 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3706 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3707 | case DataType::Type::kInt64: |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 3708 | GenerateLongCompare(instruction->GetCondition(), locations); |
| 3709 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3710 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3711 | case DataType::Type::kFloat32: |
| 3712 | case DataType::Type::kFloat64: |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 3713 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 3714 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3715 | } |
| 3716 | } |
| 3717 | |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3718 | void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3719 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3720 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3721 | |
| 3722 | LocationSummary* locations = instruction->GetLocations(); |
| 3723 | Location second = locations->InAt(1); |
| 3724 | DCHECK(second.IsConstant()); |
| 3725 | |
| 3726 | Register out = locations->Out().AsRegister<Register>(); |
| 3727 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3728 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3729 | DCHECK(imm == 1 || imm == -1); |
| 3730 | |
| 3731 | if (instruction->IsRem()) { |
| 3732 | __ Move(out, ZERO); |
| 3733 | } else { |
| 3734 | if (imm == -1) { |
| 3735 | __ Subu(out, ZERO, dividend); |
| 3736 | } else if (out != dividend) { |
| 3737 | __ Move(out, dividend); |
| 3738 | } |
| 3739 | } |
| 3740 | } |
| 3741 | |
| 3742 | void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3743 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3744 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3745 | |
| 3746 | LocationSummary* locations = instruction->GetLocations(); |
| 3747 | Location second = locations->InAt(1); |
| 3748 | DCHECK(second.IsConstant()); |
| 3749 | |
| 3750 | Register out = locations->Out().AsRegister<Register>(); |
| 3751 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3752 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3753 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3754 | int ctz_imm = CTZ(abs_imm); |
| 3755 | |
| 3756 | if (instruction->IsDiv()) { |
| 3757 | if (ctz_imm == 1) { |
| 3758 | // Fast path for division by +/-2, which is very common. |
| 3759 | __ Srl(TMP, dividend, 31); |
| 3760 | } else { |
| 3761 | __ Sra(TMP, dividend, 31); |
| 3762 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3763 | } |
| 3764 | __ Addu(out, dividend, TMP); |
| 3765 | __ Sra(out, out, ctz_imm); |
| 3766 | if (imm < 0) { |
| 3767 | __ Subu(out, ZERO, out); |
| 3768 | } |
| 3769 | } else { |
| 3770 | if (ctz_imm == 1) { |
| 3771 | // Fast path for modulo +/-2, which is very common. |
| 3772 | __ Sra(TMP, dividend, 31); |
| 3773 | __ Subu(out, dividend, TMP); |
| 3774 | __ Andi(out, out, 1); |
| 3775 | __ Addu(out, out, TMP); |
| 3776 | } else { |
| 3777 | __ Sra(TMP, dividend, 31); |
| 3778 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3779 | __ Addu(out, dividend, TMP); |
| 3780 | if (IsUint<16>(abs_imm - 1)) { |
| 3781 | __ Andi(out, out, abs_imm - 1); |
| 3782 | } else { |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 3783 | if (codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2()) { |
| 3784 | __ Ins(out, ZERO, ctz_imm, 32 - ctz_imm); |
| 3785 | } else { |
| 3786 | __ Sll(out, out, 32 - ctz_imm); |
| 3787 | __ Srl(out, out, 32 - ctz_imm); |
| 3788 | } |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3789 | } |
| 3790 | __ Subu(out, out, TMP); |
| 3791 | } |
| 3792 | } |
| 3793 | } |
| 3794 | |
| 3795 | void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3796 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3797 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3798 | |
| 3799 | LocationSummary* locations = instruction->GetLocations(); |
| 3800 | Location second = locations->InAt(1); |
| 3801 | DCHECK(second.IsConstant()); |
| 3802 | |
| 3803 | Register out = locations->Out().AsRegister<Register>(); |
| 3804 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3805 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3806 | |
| 3807 | int64_t magic; |
| 3808 | int shift; |
| 3809 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3810 | |
| 3811 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3812 | |
| 3813 | __ LoadConst32(TMP, magic); |
| 3814 | if (isR6) { |
| 3815 | __ MuhR6(TMP, dividend, TMP); |
| 3816 | } else { |
| 3817 | __ MultR2(dividend, TMP); |
| 3818 | __ Mfhi(TMP); |
| 3819 | } |
| 3820 | if (imm > 0 && magic < 0) { |
| 3821 | __ Addu(TMP, TMP, dividend); |
| 3822 | } else if (imm < 0 && magic > 0) { |
| 3823 | __ Subu(TMP, TMP, dividend); |
| 3824 | } |
| 3825 | |
| 3826 | if (shift != 0) { |
| 3827 | __ Sra(TMP, TMP, shift); |
| 3828 | } |
| 3829 | |
| 3830 | if (instruction->IsDiv()) { |
| 3831 | __ Sra(out, TMP, 31); |
| 3832 | __ Subu(out, TMP, out); |
| 3833 | } else { |
| 3834 | __ Sra(AT, TMP, 31); |
| 3835 | __ Subu(AT, TMP, AT); |
| 3836 | __ LoadConst32(TMP, imm); |
| 3837 | if (isR6) { |
| 3838 | __ MulR6(TMP, AT, TMP); |
| 3839 | } else { |
| 3840 | __ MulR2(TMP, AT, TMP); |
| 3841 | } |
| 3842 | __ Subu(out, dividend, TMP); |
| 3843 | } |
| 3844 | } |
| 3845 | |
| 3846 | void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3847 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3848 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt32); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3849 | |
| 3850 | LocationSummary* locations = instruction->GetLocations(); |
| 3851 | Register out = locations->Out().AsRegister<Register>(); |
| 3852 | Location second = locations->InAt(1); |
| 3853 | |
| 3854 | if (second.IsConstant()) { |
| 3855 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3856 | if (imm == 0) { |
| 3857 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3858 | } else if (imm == 1 || imm == -1) { |
| 3859 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3860 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3861 | DivRemByPowerOfTwo(instruction); |
| 3862 | } else { |
| 3863 | DCHECK(imm <= -2 || imm >= 2); |
| 3864 | GenerateDivRemWithAnyConstant(instruction); |
| 3865 | } |
| 3866 | } else { |
| 3867 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3868 | Register divisor = second.AsRegister<Register>(); |
| 3869 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3870 | if (instruction->IsDiv()) { |
| 3871 | if (isR6) { |
| 3872 | __ DivR6(out, dividend, divisor); |
| 3873 | } else { |
| 3874 | __ DivR2(out, dividend, divisor); |
| 3875 | } |
| 3876 | } else { |
| 3877 | if (isR6) { |
| 3878 | __ ModR6(out, dividend, divisor); |
| 3879 | } else { |
| 3880 | __ ModR2(out, dividend, divisor); |
| 3881 | } |
| 3882 | } |
| 3883 | } |
| 3884 | } |
| 3885 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3886 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3887 | DataType::Type type = div->GetResultType(); |
| 3888 | LocationSummary::CallKind call_kind = (type == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3889 | ? LocationSummary::kCallOnMainOnly |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3890 | : LocationSummary::kNoCall; |
| 3891 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3892 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3893 | |
| 3894 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3895 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3896 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3897 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3898 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3899 | break; |
| 3900 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3901 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3902 | InvokeRuntimeCallingConvention calling_convention; |
| 3903 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3904 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3905 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3906 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3907 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 3908 | break; |
| 3909 | } |
| 3910 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3911 | case DataType::Type::kFloat32: |
| 3912 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3913 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3914 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3915 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3916 | break; |
| 3917 | |
| 3918 | default: |
| 3919 | LOG(FATAL) << "Unexpected div type " << type; |
| 3920 | } |
| 3921 | } |
| 3922 | |
| 3923 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3924 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3925 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3926 | |
| 3927 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3928 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3929 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3930 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3931 | case DataType::Type::kInt64: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 3932 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3933 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| 3934 | break; |
| 3935 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3936 | case DataType::Type::kFloat32: |
| 3937 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3938 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 3939 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3940 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3941 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3942 | __ DivS(dst, lhs, rhs); |
| 3943 | } else { |
| 3944 | __ DivD(dst, lhs, rhs); |
| 3945 | } |
| 3946 | break; |
| 3947 | } |
| 3948 | default: |
| 3949 | LOG(FATAL) << "Unexpected div type " << type; |
| 3950 | } |
| 3951 | } |
| 3952 | |
| 3953 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3954 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3955 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3956 | } |
| 3957 | |
| 3958 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3959 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3960 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathMIPS(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3961 | codegen_->AddSlowPath(slow_path); |
| 3962 | Location value = instruction->GetLocations()->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3963 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3964 | |
| 3965 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3966 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3967 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3968 | case DataType::Type::kInt8: |
| 3969 | case DataType::Type::kUint16: |
| 3970 | case DataType::Type::kInt16: |
| 3971 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3972 | if (value.IsConstant()) { |
| 3973 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3974 | __ B(slow_path->GetEntryLabel()); |
| 3975 | } else { |
| 3976 | // A division by a non-null constant is valid. We don't need to perform |
| 3977 | // any check, so simply fall through. |
| 3978 | } |
| 3979 | } else { |
| 3980 | DCHECK(value.IsRegister()) << value; |
| 3981 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 3982 | } |
| 3983 | break; |
| 3984 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3985 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3986 | if (value.IsConstant()) { |
| 3987 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3988 | __ B(slow_path->GetEntryLabel()); |
| 3989 | } else { |
| 3990 | // A division by a non-null constant is valid. We don't need to perform |
| 3991 | // any check, so simply fall through. |
| 3992 | } |
| 3993 | } else { |
| 3994 | DCHECK(value.IsRegisterPair()) << value; |
| 3995 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); |
| 3996 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3997 | } |
| 3998 | break; |
| 3999 | } |
| 4000 | default: |
| 4001 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| 4002 | } |
| 4003 | } |
| 4004 | |
| 4005 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { |
| 4006 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4007 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4008 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4009 | } |
| 4010 | |
| 4011 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 4012 | // Will be generated at use site. |
| 4013 | } |
| 4014 | |
| 4015 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { |
| 4016 | exit->SetLocations(nullptr); |
| 4017 | } |
| 4018 | |
| 4019 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 4020 | } |
| 4021 | |
| 4022 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { |
| 4023 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4024 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4025 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4026 | } |
| 4027 | |
| 4028 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 4029 | // Will be generated at use site. |
| 4030 | } |
| 4031 | |
| 4032 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { |
| 4033 | got->SetLocations(nullptr); |
| 4034 | } |
| 4035 | |
| 4036 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4037 | if (successor->IsExitBlock()) { |
| 4038 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 4039 | return; // no code needed |
| 4040 | } |
| 4041 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4042 | HBasicBlock* block = got->GetBlock(); |
| 4043 | HInstruction* previous = got->GetPrevious(); |
| 4044 | HLoopInformation* info = block->GetLoopInformation(); |
| 4045 | |
| 4046 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4047 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 4048 | return; |
| 4049 | } |
| 4050 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 4051 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 4052 | } |
| 4053 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 4054 | __ B(codegen_->GetLabelOf(successor)); |
| 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { |
| 4059 | HandleGoto(got, got->GetSuccessor()); |
| 4060 | } |
| 4061 | |
| 4062 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 4063 | try_boundary->SetLocations(nullptr); |
| 4064 | } |
| 4065 | |
| 4066 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 4067 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 4068 | if (!successor->IsExitBlock()) { |
| 4069 | HandleGoto(try_boundary, successor); |
| 4070 | } |
| 4071 | } |
| 4072 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4073 | void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond, |
| 4074 | LocationSummary* locations) { |
| 4075 | Register dst = locations->Out().AsRegister<Register>(); |
| 4076 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4077 | Location rhs_location = locations->InAt(1); |
| 4078 | Register rhs_reg = ZERO; |
| 4079 | int64_t rhs_imm = 0; |
| 4080 | bool use_imm = rhs_location.IsConstant(); |
| 4081 | if (use_imm) { |
| 4082 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4083 | } else { |
| 4084 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4085 | } |
| 4086 | |
| 4087 | switch (cond) { |
| 4088 | case kCondEQ: |
| 4089 | case kCondNE: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4090 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4091 | if (rhs_imm == 0) { |
| 4092 | if (cond == kCondEQ) { |
| 4093 | __ Sltiu(dst, lhs, 1); |
| 4094 | } else { |
| 4095 | __ Sltu(dst, ZERO, lhs); |
| 4096 | } |
| 4097 | } else { |
| 4098 | __ Addiu(dst, lhs, -rhs_imm); |
| 4099 | if (cond == kCondEQ) { |
| 4100 | __ Sltiu(dst, dst, 1); |
| 4101 | } else { |
| 4102 | __ Sltu(dst, ZERO, dst); |
| 4103 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4104 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4105 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4106 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 4107 | __ Xori(dst, lhs, rhs_imm); |
| 4108 | } else { |
| 4109 | if (use_imm) { |
| 4110 | rhs_reg = TMP; |
| 4111 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4112 | } |
| 4113 | __ Xor(dst, lhs, rhs_reg); |
| 4114 | } |
| 4115 | if (cond == kCondEQ) { |
| 4116 | __ Sltiu(dst, dst, 1); |
| 4117 | } else { |
| 4118 | __ Sltu(dst, ZERO, dst); |
| 4119 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4120 | } |
| 4121 | break; |
| 4122 | |
| 4123 | case kCondLT: |
| 4124 | case kCondGE: |
| 4125 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4126 | __ Slti(dst, lhs, rhs_imm); |
| 4127 | } else { |
| 4128 | if (use_imm) { |
| 4129 | rhs_reg = TMP; |
| 4130 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4131 | } |
| 4132 | __ Slt(dst, lhs, rhs_reg); |
| 4133 | } |
| 4134 | if (cond == kCondGE) { |
| 4135 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4136 | // only the slt instruction but no sge. |
| 4137 | __ Xori(dst, dst, 1); |
| 4138 | } |
| 4139 | break; |
| 4140 | |
| 4141 | case kCondLE: |
| 4142 | case kCondGT: |
| 4143 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4144 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4145 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4146 | if (cond == kCondGT) { |
| 4147 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4148 | // only the slti instruction but no sgti. |
| 4149 | __ Xori(dst, dst, 1); |
| 4150 | } |
| 4151 | } else { |
| 4152 | if (use_imm) { |
| 4153 | rhs_reg = TMP; |
| 4154 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4155 | } |
| 4156 | __ Slt(dst, rhs_reg, lhs); |
| 4157 | if (cond == kCondLE) { |
| 4158 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4159 | // only the slt instruction but no sle. |
| 4160 | __ Xori(dst, dst, 1); |
| 4161 | } |
| 4162 | } |
| 4163 | break; |
| 4164 | |
| 4165 | case kCondB: |
| 4166 | case kCondAE: |
| 4167 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4168 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4169 | // the comparison and thus lets us compare directly with |
| 4170 | // unsigned values in the ranges [0, 0x7fff] and |
| 4171 | // [0xffff8000, 0xffffffff]. |
| 4172 | __ Sltiu(dst, lhs, rhs_imm); |
| 4173 | } else { |
| 4174 | if (use_imm) { |
| 4175 | rhs_reg = TMP; |
| 4176 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4177 | } |
| 4178 | __ Sltu(dst, lhs, rhs_reg); |
| 4179 | } |
| 4180 | if (cond == kCondAE) { |
| 4181 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 4182 | // only the sltu instruction but no sgeu. |
| 4183 | __ Xori(dst, dst, 1); |
| 4184 | } |
| 4185 | break; |
| 4186 | |
| 4187 | case kCondBE: |
| 4188 | case kCondA: |
| 4189 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4190 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4191 | // Note that this only works if rhs + 1 does not overflow |
| 4192 | // to 0, hence the check above. |
| 4193 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4194 | // the comparison and thus lets us compare directly with |
| 4195 | // unsigned values in the ranges [0, 0x7fff] and |
| 4196 | // [0xffff8000, 0xffffffff]. |
| 4197 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4198 | if (cond == kCondA) { |
| 4199 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 4200 | // only the sltiu instruction but no sgtiu. |
| 4201 | __ Xori(dst, dst, 1); |
| 4202 | } |
| 4203 | } else { |
| 4204 | if (use_imm) { |
| 4205 | rhs_reg = TMP; |
| 4206 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4207 | } |
| 4208 | __ Sltu(dst, rhs_reg, lhs); |
| 4209 | if (cond == kCondBE) { |
| 4210 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 4211 | // only the sltu instruction but no sleu. |
| 4212 | __ Xori(dst, dst, 1); |
| 4213 | } |
| 4214 | } |
| 4215 | break; |
| 4216 | } |
| 4217 | } |
| 4218 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4219 | bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond, |
| 4220 | LocationSummary* input_locations, |
| 4221 | Register dst) { |
| 4222 | Register lhs = input_locations->InAt(0).AsRegister<Register>(); |
| 4223 | Location rhs_location = input_locations->InAt(1); |
| 4224 | Register rhs_reg = ZERO; |
| 4225 | int64_t rhs_imm = 0; |
| 4226 | bool use_imm = rhs_location.IsConstant(); |
| 4227 | if (use_imm) { |
| 4228 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4229 | } else { |
| 4230 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4231 | } |
| 4232 | |
| 4233 | switch (cond) { |
| 4234 | case kCondEQ: |
| 4235 | case kCondNE: |
| 4236 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 4237 | __ Addiu(dst, lhs, -rhs_imm); |
| 4238 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 4239 | __ Xori(dst, lhs, rhs_imm); |
| 4240 | } else { |
| 4241 | if (use_imm) { |
| 4242 | rhs_reg = TMP; |
| 4243 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4244 | } |
| 4245 | __ Xor(dst, lhs, rhs_reg); |
| 4246 | } |
| 4247 | return (cond == kCondEQ); |
| 4248 | |
| 4249 | case kCondLT: |
| 4250 | case kCondGE: |
| 4251 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4252 | __ Slti(dst, lhs, rhs_imm); |
| 4253 | } else { |
| 4254 | if (use_imm) { |
| 4255 | rhs_reg = TMP; |
| 4256 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4257 | } |
| 4258 | __ Slt(dst, lhs, rhs_reg); |
| 4259 | } |
| 4260 | return (cond == kCondGE); |
| 4261 | |
| 4262 | case kCondLE: |
| 4263 | case kCondGT: |
| 4264 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4265 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4266 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4267 | return (cond == kCondGT); |
| 4268 | } else { |
| 4269 | if (use_imm) { |
| 4270 | rhs_reg = TMP; |
| 4271 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4272 | } |
| 4273 | __ Slt(dst, rhs_reg, lhs); |
| 4274 | return (cond == kCondLE); |
| 4275 | } |
| 4276 | |
| 4277 | case kCondB: |
| 4278 | case kCondAE: |
| 4279 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4280 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4281 | // the comparison and thus lets us compare directly with |
| 4282 | // unsigned values in the ranges [0, 0x7fff] and |
| 4283 | // [0xffff8000, 0xffffffff]. |
| 4284 | __ Sltiu(dst, lhs, rhs_imm); |
| 4285 | } else { |
| 4286 | if (use_imm) { |
| 4287 | rhs_reg = TMP; |
| 4288 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4289 | } |
| 4290 | __ Sltu(dst, lhs, rhs_reg); |
| 4291 | } |
| 4292 | return (cond == kCondAE); |
| 4293 | |
| 4294 | case kCondBE: |
| 4295 | case kCondA: |
| 4296 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4297 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4298 | // Note that this only works if rhs + 1 does not overflow |
| 4299 | // to 0, hence the check above. |
| 4300 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4301 | // the comparison and thus lets us compare directly with |
| 4302 | // unsigned values in the ranges [0, 0x7fff] and |
| 4303 | // [0xffff8000, 0xffffffff]. |
| 4304 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4305 | return (cond == kCondA); |
| 4306 | } else { |
| 4307 | if (use_imm) { |
| 4308 | rhs_reg = TMP; |
| 4309 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4310 | } |
| 4311 | __ Sltu(dst, rhs_reg, lhs); |
| 4312 | return (cond == kCondBE); |
| 4313 | } |
| 4314 | } |
| 4315 | } |
| 4316 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4317 | void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond, |
| 4318 | LocationSummary* locations, |
| 4319 | MipsLabel* label) { |
| 4320 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4321 | Location rhs_location = locations->InAt(1); |
| 4322 | Register rhs_reg = ZERO; |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4323 | int64_t rhs_imm = 0; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4324 | bool use_imm = rhs_location.IsConstant(); |
| 4325 | if (use_imm) { |
| 4326 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4327 | } else { |
| 4328 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4329 | } |
| 4330 | |
| 4331 | if (use_imm && rhs_imm == 0) { |
| 4332 | switch (cond) { |
| 4333 | case kCondEQ: |
| 4334 | case kCondBE: // <= 0 if zero |
| 4335 | __ Beqz(lhs, label); |
| 4336 | break; |
| 4337 | case kCondNE: |
| 4338 | case kCondA: // > 0 if non-zero |
| 4339 | __ Bnez(lhs, label); |
| 4340 | break; |
| 4341 | case kCondLT: |
| 4342 | __ Bltz(lhs, label); |
| 4343 | break; |
| 4344 | case kCondGE: |
| 4345 | __ Bgez(lhs, label); |
| 4346 | break; |
| 4347 | case kCondLE: |
| 4348 | __ Blez(lhs, label); |
| 4349 | break; |
| 4350 | case kCondGT: |
| 4351 | __ Bgtz(lhs, label); |
| 4352 | break; |
| 4353 | case kCondB: // always false |
| 4354 | break; |
| 4355 | case kCondAE: // always true |
| 4356 | __ B(label); |
| 4357 | break; |
| 4358 | } |
| 4359 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4360 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4361 | if (isR6 || !use_imm) { |
| 4362 | if (use_imm) { |
| 4363 | rhs_reg = TMP; |
| 4364 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4365 | } |
| 4366 | switch (cond) { |
| 4367 | case kCondEQ: |
| 4368 | __ Beq(lhs, rhs_reg, label); |
| 4369 | break; |
| 4370 | case kCondNE: |
| 4371 | __ Bne(lhs, rhs_reg, label); |
| 4372 | break; |
| 4373 | case kCondLT: |
| 4374 | __ Blt(lhs, rhs_reg, label); |
| 4375 | break; |
| 4376 | case kCondGE: |
| 4377 | __ Bge(lhs, rhs_reg, label); |
| 4378 | break; |
| 4379 | case kCondLE: |
| 4380 | __ Bge(rhs_reg, lhs, label); |
| 4381 | break; |
| 4382 | case kCondGT: |
| 4383 | __ Blt(rhs_reg, lhs, label); |
| 4384 | break; |
| 4385 | case kCondB: |
| 4386 | __ Bltu(lhs, rhs_reg, label); |
| 4387 | break; |
| 4388 | case kCondAE: |
| 4389 | __ Bgeu(lhs, rhs_reg, label); |
| 4390 | break; |
| 4391 | case kCondBE: |
| 4392 | __ Bgeu(rhs_reg, lhs, label); |
| 4393 | break; |
| 4394 | case kCondA: |
| 4395 | __ Bltu(rhs_reg, lhs, label); |
| 4396 | break; |
| 4397 | } |
| 4398 | } else { |
| 4399 | // Special cases for more efficient comparison with constants on R2. |
| 4400 | switch (cond) { |
| 4401 | case kCondEQ: |
| 4402 | __ LoadConst32(TMP, rhs_imm); |
| 4403 | __ Beq(lhs, TMP, label); |
| 4404 | break; |
| 4405 | case kCondNE: |
| 4406 | __ LoadConst32(TMP, rhs_imm); |
| 4407 | __ Bne(lhs, TMP, label); |
| 4408 | break; |
| 4409 | case kCondLT: |
| 4410 | if (IsInt<16>(rhs_imm)) { |
| 4411 | __ Slti(TMP, lhs, rhs_imm); |
| 4412 | __ Bnez(TMP, label); |
| 4413 | } else { |
| 4414 | __ LoadConst32(TMP, rhs_imm); |
| 4415 | __ Blt(lhs, TMP, label); |
| 4416 | } |
| 4417 | break; |
| 4418 | case kCondGE: |
| 4419 | if (IsInt<16>(rhs_imm)) { |
| 4420 | __ Slti(TMP, lhs, rhs_imm); |
| 4421 | __ Beqz(TMP, label); |
| 4422 | } else { |
| 4423 | __ LoadConst32(TMP, rhs_imm); |
| 4424 | __ Bge(lhs, TMP, label); |
| 4425 | } |
| 4426 | break; |
| 4427 | case kCondLE: |
| 4428 | if (IsInt<16>(rhs_imm + 1)) { |
| 4429 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4430 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4431 | __ Bnez(TMP, label); |
| 4432 | } else { |
| 4433 | __ LoadConst32(TMP, rhs_imm); |
| 4434 | __ Bge(TMP, lhs, label); |
| 4435 | } |
| 4436 | break; |
| 4437 | case kCondGT: |
| 4438 | if (IsInt<16>(rhs_imm + 1)) { |
| 4439 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4440 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4441 | __ Beqz(TMP, label); |
| 4442 | } else { |
| 4443 | __ LoadConst32(TMP, rhs_imm); |
| 4444 | __ Blt(TMP, lhs, label); |
| 4445 | } |
| 4446 | break; |
| 4447 | case kCondB: |
| 4448 | if (IsInt<16>(rhs_imm)) { |
| 4449 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4450 | __ Bnez(TMP, label); |
| 4451 | } else { |
| 4452 | __ LoadConst32(TMP, rhs_imm); |
| 4453 | __ Bltu(lhs, TMP, label); |
| 4454 | } |
| 4455 | break; |
| 4456 | case kCondAE: |
| 4457 | if (IsInt<16>(rhs_imm)) { |
| 4458 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4459 | __ Beqz(TMP, label); |
| 4460 | } else { |
| 4461 | __ LoadConst32(TMP, rhs_imm); |
| 4462 | __ Bgeu(lhs, TMP, label); |
| 4463 | } |
| 4464 | break; |
| 4465 | case kCondBE: |
| 4466 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4467 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4468 | // Note that this only works if rhs + 1 does not overflow |
| 4469 | // to 0, hence the check above. |
| 4470 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4471 | __ Bnez(TMP, label); |
| 4472 | } else { |
| 4473 | __ LoadConst32(TMP, rhs_imm); |
| 4474 | __ Bgeu(TMP, lhs, label); |
| 4475 | } |
| 4476 | break; |
| 4477 | case kCondA: |
| 4478 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4479 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4480 | // Note that this only works if rhs + 1 does not overflow |
| 4481 | // to 0, hence the check above. |
| 4482 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4483 | __ Beqz(TMP, label); |
| 4484 | } else { |
| 4485 | __ LoadConst32(TMP, rhs_imm); |
| 4486 | __ Bltu(TMP, lhs, label); |
| 4487 | } |
| 4488 | break; |
| 4489 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4490 | } |
| 4491 | } |
| 4492 | } |
| 4493 | |
Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 4494 | void InstructionCodeGeneratorMIPS::GenerateLongCompare(IfCondition cond, |
| 4495 | LocationSummary* locations) { |
| 4496 | Register dst = locations->Out().AsRegister<Register>(); |
| 4497 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4498 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4499 | Location rhs_location = locations->InAt(1); |
| 4500 | Register rhs_high = ZERO; |
| 4501 | Register rhs_low = ZERO; |
| 4502 | int64_t imm = 0; |
| 4503 | uint32_t imm_high = 0; |
| 4504 | uint32_t imm_low = 0; |
| 4505 | bool use_imm = rhs_location.IsConstant(); |
| 4506 | if (use_imm) { |
| 4507 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 4508 | imm_high = High32Bits(imm); |
| 4509 | imm_low = Low32Bits(imm); |
| 4510 | } else { |
| 4511 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 4512 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 4513 | } |
| 4514 | if (use_imm && imm == 0) { |
| 4515 | switch (cond) { |
| 4516 | case kCondEQ: |
| 4517 | case kCondBE: // <= 0 if zero |
| 4518 | __ Or(dst, lhs_high, lhs_low); |
| 4519 | __ Sltiu(dst, dst, 1); |
| 4520 | break; |
| 4521 | case kCondNE: |
| 4522 | case kCondA: // > 0 if non-zero |
| 4523 | __ Or(dst, lhs_high, lhs_low); |
| 4524 | __ Sltu(dst, ZERO, dst); |
| 4525 | break; |
| 4526 | case kCondLT: |
| 4527 | __ Slt(dst, lhs_high, ZERO); |
| 4528 | break; |
| 4529 | case kCondGE: |
| 4530 | __ Slt(dst, lhs_high, ZERO); |
| 4531 | __ Xori(dst, dst, 1); |
| 4532 | break; |
| 4533 | case kCondLE: |
| 4534 | __ Or(TMP, lhs_high, lhs_low); |
| 4535 | __ Sra(AT, lhs_high, 31); |
| 4536 | __ Sltu(dst, AT, TMP); |
| 4537 | __ Xori(dst, dst, 1); |
| 4538 | break; |
| 4539 | case kCondGT: |
| 4540 | __ Or(TMP, lhs_high, lhs_low); |
| 4541 | __ Sra(AT, lhs_high, 31); |
| 4542 | __ Sltu(dst, AT, TMP); |
| 4543 | break; |
| 4544 | case kCondB: // always false |
| 4545 | __ Andi(dst, dst, 0); |
| 4546 | break; |
| 4547 | case kCondAE: // always true |
| 4548 | __ Ori(dst, ZERO, 1); |
| 4549 | break; |
| 4550 | } |
| 4551 | } else if (use_imm) { |
| 4552 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 4553 | switch (cond) { |
| 4554 | case kCondEQ: |
| 4555 | __ LoadConst32(TMP, imm_high); |
| 4556 | __ Xor(TMP, TMP, lhs_high); |
| 4557 | __ LoadConst32(AT, imm_low); |
| 4558 | __ Xor(AT, AT, lhs_low); |
| 4559 | __ Or(dst, TMP, AT); |
| 4560 | __ Sltiu(dst, dst, 1); |
| 4561 | break; |
| 4562 | case kCondNE: |
| 4563 | __ LoadConst32(TMP, imm_high); |
| 4564 | __ Xor(TMP, TMP, lhs_high); |
| 4565 | __ LoadConst32(AT, imm_low); |
| 4566 | __ Xor(AT, AT, lhs_low); |
| 4567 | __ Or(dst, TMP, AT); |
| 4568 | __ Sltu(dst, ZERO, dst); |
| 4569 | break; |
| 4570 | case kCondLT: |
| 4571 | case kCondGE: |
| 4572 | if (dst == lhs_low) { |
| 4573 | __ LoadConst32(TMP, imm_low); |
| 4574 | __ Sltu(dst, lhs_low, TMP); |
| 4575 | } |
| 4576 | __ LoadConst32(TMP, imm_high); |
| 4577 | __ Slt(AT, lhs_high, TMP); |
| 4578 | __ Slt(TMP, TMP, lhs_high); |
| 4579 | if (dst != lhs_low) { |
| 4580 | __ LoadConst32(dst, imm_low); |
| 4581 | __ Sltu(dst, lhs_low, dst); |
| 4582 | } |
| 4583 | __ Slt(dst, TMP, dst); |
| 4584 | __ Or(dst, dst, AT); |
| 4585 | if (cond == kCondGE) { |
| 4586 | __ Xori(dst, dst, 1); |
| 4587 | } |
| 4588 | break; |
| 4589 | case kCondGT: |
| 4590 | case kCondLE: |
| 4591 | if (dst == lhs_low) { |
| 4592 | __ LoadConst32(TMP, imm_low); |
| 4593 | __ Sltu(dst, TMP, lhs_low); |
| 4594 | } |
| 4595 | __ LoadConst32(TMP, imm_high); |
| 4596 | __ Slt(AT, TMP, lhs_high); |
| 4597 | __ Slt(TMP, lhs_high, TMP); |
| 4598 | if (dst != lhs_low) { |
| 4599 | __ LoadConst32(dst, imm_low); |
| 4600 | __ Sltu(dst, dst, lhs_low); |
| 4601 | } |
| 4602 | __ Slt(dst, TMP, dst); |
| 4603 | __ Or(dst, dst, AT); |
| 4604 | if (cond == kCondLE) { |
| 4605 | __ Xori(dst, dst, 1); |
| 4606 | } |
| 4607 | break; |
| 4608 | case kCondB: |
| 4609 | case kCondAE: |
| 4610 | if (dst == lhs_low) { |
| 4611 | __ LoadConst32(TMP, imm_low); |
| 4612 | __ Sltu(dst, lhs_low, TMP); |
| 4613 | } |
| 4614 | __ LoadConst32(TMP, imm_high); |
| 4615 | __ Sltu(AT, lhs_high, TMP); |
| 4616 | __ Sltu(TMP, TMP, lhs_high); |
| 4617 | if (dst != lhs_low) { |
| 4618 | __ LoadConst32(dst, imm_low); |
| 4619 | __ Sltu(dst, lhs_low, dst); |
| 4620 | } |
| 4621 | __ Slt(dst, TMP, dst); |
| 4622 | __ Or(dst, dst, AT); |
| 4623 | if (cond == kCondAE) { |
| 4624 | __ Xori(dst, dst, 1); |
| 4625 | } |
| 4626 | break; |
| 4627 | case kCondA: |
| 4628 | case kCondBE: |
| 4629 | if (dst == lhs_low) { |
| 4630 | __ LoadConst32(TMP, imm_low); |
| 4631 | __ Sltu(dst, TMP, lhs_low); |
| 4632 | } |
| 4633 | __ LoadConst32(TMP, imm_high); |
| 4634 | __ Sltu(AT, TMP, lhs_high); |
| 4635 | __ Sltu(TMP, lhs_high, TMP); |
| 4636 | if (dst != lhs_low) { |
| 4637 | __ LoadConst32(dst, imm_low); |
| 4638 | __ Sltu(dst, dst, lhs_low); |
| 4639 | } |
| 4640 | __ Slt(dst, TMP, dst); |
| 4641 | __ Or(dst, dst, AT); |
| 4642 | if (cond == kCondBE) { |
| 4643 | __ Xori(dst, dst, 1); |
| 4644 | } |
| 4645 | break; |
| 4646 | } |
| 4647 | } else { |
| 4648 | switch (cond) { |
| 4649 | case kCondEQ: |
| 4650 | __ Xor(TMP, lhs_high, rhs_high); |
| 4651 | __ Xor(AT, lhs_low, rhs_low); |
| 4652 | __ Or(dst, TMP, AT); |
| 4653 | __ Sltiu(dst, dst, 1); |
| 4654 | break; |
| 4655 | case kCondNE: |
| 4656 | __ Xor(TMP, lhs_high, rhs_high); |
| 4657 | __ Xor(AT, lhs_low, rhs_low); |
| 4658 | __ Or(dst, TMP, AT); |
| 4659 | __ Sltu(dst, ZERO, dst); |
| 4660 | break; |
| 4661 | case kCondLT: |
| 4662 | case kCondGE: |
| 4663 | __ Slt(TMP, rhs_high, lhs_high); |
| 4664 | __ Sltu(AT, lhs_low, rhs_low); |
| 4665 | __ Slt(TMP, TMP, AT); |
| 4666 | __ Slt(AT, lhs_high, rhs_high); |
| 4667 | __ Or(dst, AT, TMP); |
| 4668 | if (cond == kCondGE) { |
| 4669 | __ Xori(dst, dst, 1); |
| 4670 | } |
| 4671 | break; |
| 4672 | case kCondGT: |
| 4673 | case kCondLE: |
| 4674 | __ Slt(TMP, lhs_high, rhs_high); |
| 4675 | __ Sltu(AT, rhs_low, lhs_low); |
| 4676 | __ Slt(TMP, TMP, AT); |
| 4677 | __ Slt(AT, rhs_high, lhs_high); |
| 4678 | __ Or(dst, AT, TMP); |
| 4679 | if (cond == kCondLE) { |
| 4680 | __ Xori(dst, dst, 1); |
| 4681 | } |
| 4682 | break; |
| 4683 | case kCondB: |
| 4684 | case kCondAE: |
| 4685 | __ Sltu(TMP, rhs_high, lhs_high); |
| 4686 | __ Sltu(AT, lhs_low, rhs_low); |
| 4687 | __ Slt(TMP, TMP, AT); |
| 4688 | __ Sltu(AT, lhs_high, rhs_high); |
| 4689 | __ Or(dst, AT, TMP); |
| 4690 | if (cond == kCondAE) { |
| 4691 | __ Xori(dst, dst, 1); |
| 4692 | } |
| 4693 | break; |
| 4694 | case kCondA: |
| 4695 | case kCondBE: |
| 4696 | __ Sltu(TMP, lhs_high, rhs_high); |
| 4697 | __ Sltu(AT, rhs_low, lhs_low); |
| 4698 | __ Slt(TMP, TMP, AT); |
| 4699 | __ Sltu(AT, rhs_high, lhs_high); |
| 4700 | __ Or(dst, AT, TMP); |
| 4701 | if (cond == kCondBE) { |
| 4702 | __ Xori(dst, dst, 1); |
| 4703 | } |
| 4704 | break; |
| 4705 | } |
| 4706 | } |
| 4707 | } |
| 4708 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4709 | void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond, |
| 4710 | LocationSummary* locations, |
| 4711 | MipsLabel* label) { |
| 4712 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4713 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4714 | Location rhs_location = locations->InAt(1); |
| 4715 | Register rhs_high = ZERO; |
| 4716 | Register rhs_low = ZERO; |
| 4717 | int64_t imm = 0; |
| 4718 | uint32_t imm_high = 0; |
| 4719 | uint32_t imm_low = 0; |
| 4720 | bool use_imm = rhs_location.IsConstant(); |
| 4721 | if (use_imm) { |
| 4722 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 4723 | imm_high = High32Bits(imm); |
| 4724 | imm_low = Low32Bits(imm); |
| 4725 | } else { |
| 4726 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 4727 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 4728 | } |
| 4729 | |
| 4730 | if (use_imm && imm == 0) { |
| 4731 | switch (cond) { |
| 4732 | case kCondEQ: |
| 4733 | case kCondBE: // <= 0 if zero |
| 4734 | __ Or(TMP, lhs_high, lhs_low); |
| 4735 | __ Beqz(TMP, label); |
| 4736 | break; |
| 4737 | case kCondNE: |
| 4738 | case kCondA: // > 0 if non-zero |
| 4739 | __ Or(TMP, lhs_high, lhs_low); |
| 4740 | __ Bnez(TMP, label); |
| 4741 | break; |
| 4742 | case kCondLT: |
| 4743 | __ Bltz(lhs_high, label); |
| 4744 | break; |
| 4745 | case kCondGE: |
| 4746 | __ Bgez(lhs_high, label); |
| 4747 | break; |
| 4748 | case kCondLE: |
| 4749 | __ Or(TMP, lhs_high, lhs_low); |
| 4750 | __ Sra(AT, lhs_high, 31); |
| 4751 | __ Bgeu(AT, TMP, label); |
| 4752 | break; |
| 4753 | case kCondGT: |
| 4754 | __ Or(TMP, lhs_high, lhs_low); |
| 4755 | __ Sra(AT, lhs_high, 31); |
| 4756 | __ Bltu(AT, TMP, label); |
| 4757 | break; |
| 4758 | case kCondB: // always false |
| 4759 | break; |
| 4760 | case kCondAE: // always true |
| 4761 | __ B(label); |
| 4762 | break; |
| 4763 | } |
| 4764 | } else if (use_imm) { |
| 4765 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 4766 | switch (cond) { |
| 4767 | case kCondEQ: |
| 4768 | __ LoadConst32(TMP, imm_high); |
| 4769 | __ Xor(TMP, TMP, lhs_high); |
| 4770 | __ LoadConst32(AT, imm_low); |
| 4771 | __ Xor(AT, AT, lhs_low); |
| 4772 | __ Or(TMP, TMP, AT); |
| 4773 | __ Beqz(TMP, label); |
| 4774 | break; |
| 4775 | case kCondNE: |
| 4776 | __ LoadConst32(TMP, imm_high); |
| 4777 | __ Xor(TMP, TMP, lhs_high); |
| 4778 | __ LoadConst32(AT, imm_low); |
| 4779 | __ Xor(AT, AT, lhs_low); |
| 4780 | __ Or(TMP, TMP, AT); |
| 4781 | __ Bnez(TMP, label); |
| 4782 | break; |
| 4783 | case kCondLT: |
| 4784 | __ LoadConst32(TMP, imm_high); |
| 4785 | __ Blt(lhs_high, TMP, label); |
| 4786 | __ Slt(TMP, TMP, lhs_high); |
| 4787 | __ LoadConst32(AT, imm_low); |
| 4788 | __ Sltu(AT, lhs_low, AT); |
| 4789 | __ Blt(TMP, AT, label); |
| 4790 | break; |
| 4791 | case kCondGE: |
| 4792 | __ LoadConst32(TMP, imm_high); |
| 4793 | __ Blt(TMP, lhs_high, label); |
| 4794 | __ Slt(TMP, lhs_high, TMP); |
| 4795 | __ LoadConst32(AT, imm_low); |
| 4796 | __ Sltu(AT, lhs_low, AT); |
| 4797 | __ Or(TMP, TMP, AT); |
| 4798 | __ Beqz(TMP, label); |
| 4799 | break; |
| 4800 | case kCondLE: |
| 4801 | __ LoadConst32(TMP, imm_high); |
| 4802 | __ Blt(lhs_high, TMP, label); |
| 4803 | __ Slt(TMP, TMP, lhs_high); |
| 4804 | __ LoadConst32(AT, imm_low); |
| 4805 | __ Sltu(AT, AT, lhs_low); |
| 4806 | __ Or(TMP, TMP, AT); |
| 4807 | __ Beqz(TMP, label); |
| 4808 | break; |
| 4809 | case kCondGT: |
| 4810 | __ LoadConst32(TMP, imm_high); |
| 4811 | __ Blt(TMP, lhs_high, label); |
| 4812 | __ Slt(TMP, lhs_high, TMP); |
| 4813 | __ LoadConst32(AT, imm_low); |
| 4814 | __ Sltu(AT, AT, lhs_low); |
| 4815 | __ Blt(TMP, AT, label); |
| 4816 | break; |
| 4817 | case kCondB: |
| 4818 | __ LoadConst32(TMP, imm_high); |
| 4819 | __ Bltu(lhs_high, TMP, label); |
| 4820 | __ Sltu(TMP, TMP, lhs_high); |
| 4821 | __ LoadConst32(AT, imm_low); |
| 4822 | __ Sltu(AT, lhs_low, AT); |
| 4823 | __ Blt(TMP, AT, label); |
| 4824 | break; |
| 4825 | case kCondAE: |
| 4826 | __ LoadConst32(TMP, imm_high); |
| 4827 | __ Bltu(TMP, lhs_high, label); |
| 4828 | __ Sltu(TMP, lhs_high, TMP); |
| 4829 | __ LoadConst32(AT, imm_low); |
| 4830 | __ Sltu(AT, lhs_low, AT); |
| 4831 | __ Or(TMP, TMP, AT); |
| 4832 | __ Beqz(TMP, label); |
| 4833 | break; |
| 4834 | case kCondBE: |
| 4835 | __ LoadConst32(TMP, imm_high); |
| 4836 | __ Bltu(lhs_high, TMP, label); |
| 4837 | __ Sltu(TMP, TMP, lhs_high); |
| 4838 | __ LoadConst32(AT, imm_low); |
| 4839 | __ Sltu(AT, AT, lhs_low); |
| 4840 | __ Or(TMP, TMP, AT); |
| 4841 | __ Beqz(TMP, label); |
| 4842 | break; |
| 4843 | case kCondA: |
| 4844 | __ LoadConst32(TMP, imm_high); |
| 4845 | __ Bltu(TMP, lhs_high, label); |
| 4846 | __ Sltu(TMP, lhs_high, TMP); |
| 4847 | __ LoadConst32(AT, imm_low); |
| 4848 | __ Sltu(AT, AT, lhs_low); |
| 4849 | __ Blt(TMP, AT, label); |
| 4850 | break; |
| 4851 | } |
| 4852 | } else { |
| 4853 | switch (cond) { |
| 4854 | case kCondEQ: |
| 4855 | __ Xor(TMP, lhs_high, rhs_high); |
| 4856 | __ Xor(AT, lhs_low, rhs_low); |
| 4857 | __ Or(TMP, TMP, AT); |
| 4858 | __ Beqz(TMP, label); |
| 4859 | break; |
| 4860 | case kCondNE: |
| 4861 | __ Xor(TMP, lhs_high, rhs_high); |
| 4862 | __ Xor(AT, lhs_low, rhs_low); |
| 4863 | __ Or(TMP, TMP, AT); |
| 4864 | __ Bnez(TMP, label); |
| 4865 | break; |
| 4866 | case kCondLT: |
| 4867 | __ Blt(lhs_high, rhs_high, label); |
| 4868 | __ Slt(TMP, rhs_high, lhs_high); |
| 4869 | __ Sltu(AT, lhs_low, rhs_low); |
| 4870 | __ Blt(TMP, AT, label); |
| 4871 | break; |
| 4872 | case kCondGE: |
| 4873 | __ Blt(rhs_high, lhs_high, label); |
| 4874 | __ Slt(TMP, lhs_high, rhs_high); |
| 4875 | __ Sltu(AT, lhs_low, rhs_low); |
| 4876 | __ Or(TMP, TMP, AT); |
| 4877 | __ Beqz(TMP, label); |
| 4878 | break; |
| 4879 | case kCondLE: |
| 4880 | __ Blt(lhs_high, rhs_high, label); |
| 4881 | __ Slt(TMP, rhs_high, lhs_high); |
| 4882 | __ Sltu(AT, rhs_low, lhs_low); |
| 4883 | __ Or(TMP, TMP, AT); |
| 4884 | __ Beqz(TMP, label); |
| 4885 | break; |
| 4886 | case kCondGT: |
| 4887 | __ Blt(rhs_high, lhs_high, label); |
| 4888 | __ Slt(TMP, lhs_high, rhs_high); |
| 4889 | __ Sltu(AT, rhs_low, lhs_low); |
| 4890 | __ Blt(TMP, AT, label); |
| 4891 | break; |
| 4892 | case kCondB: |
| 4893 | __ Bltu(lhs_high, rhs_high, label); |
| 4894 | __ Sltu(TMP, rhs_high, lhs_high); |
| 4895 | __ Sltu(AT, lhs_low, rhs_low); |
| 4896 | __ Blt(TMP, AT, label); |
| 4897 | break; |
| 4898 | case kCondAE: |
| 4899 | __ Bltu(rhs_high, lhs_high, label); |
| 4900 | __ Sltu(TMP, lhs_high, rhs_high); |
| 4901 | __ Sltu(AT, lhs_low, rhs_low); |
| 4902 | __ Or(TMP, TMP, AT); |
| 4903 | __ Beqz(TMP, label); |
| 4904 | break; |
| 4905 | case kCondBE: |
| 4906 | __ Bltu(lhs_high, rhs_high, label); |
| 4907 | __ Sltu(TMP, rhs_high, lhs_high); |
| 4908 | __ Sltu(AT, rhs_low, lhs_low); |
| 4909 | __ Or(TMP, TMP, AT); |
| 4910 | __ Beqz(TMP, label); |
| 4911 | break; |
| 4912 | case kCondA: |
| 4913 | __ Bltu(rhs_high, lhs_high, label); |
| 4914 | __ Sltu(TMP, lhs_high, rhs_high); |
| 4915 | __ Sltu(AT, rhs_low, lhs_low); |
| 4916 | __ Blt(TMP, AT, label); |
| 4917 | break; |
| 4918 | } |
| 4919 | } |
| 4920 | } |
| 4921 | |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 4922 | void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond, |
| 4923 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4924 | DataType::Type type, |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 4925 | LocationSummary* locations) { |
| 4926 | Register dst = locations->Out().AsRegister<Register>(); |
| 4927 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4928 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 4929 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4930 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 4931 | if (isR6) { |
| 4932 | switch (cond) { |
| 4933 | case kCondEQ: |
| 4934 | __ CmpEqS(FTMP, lhs, rhs); |
| 4935 | __ Mfc1(dst, FTMP); |
| 4936 | __ Andi(dst, dst, 1); |
| 4937 | break; |
| 4938 | case kCondNE: |
| 4939 | __ CmpEqS(FTMP, lhs, rhs); |
| 4940 | __ Mfc1(dst, FTMP); |
| 4941 | __ Addiu(dst, dst, 1); |
| 4942 | break; |
| 4943 | case kCondLT: |
| 4944 | if (gt_bias) { |
| 4945 | __ CmpLtS(FTMP, lhs, rhs); |
| 4946 | } else { |
| 4947 | __ CmpUltS(FTMP, lhs, rhs); |
| 4948 | } |
| 4949 | __ Mfc1(dst, FTMP); |
| 4950 | __ Andi(dst, dst, 1); |
| 4951 | break; |
| 4952 | case kCondLE: |
| 4953 | if (gt_bias) { |
| 4954 | __ CmpLeS(FTMP, lhs, rhs); |
| 4955 | } else { |
| 4956 | __ CmpUleS(FTMP, lhs, rhs); |
| 4957 | } |
| 4958 | __ Mfc1(dst, FTMP); |
| 4959 | __ Andi(dst, dst, 1); |
| 4960 | break; |
| 4961 | case kCondGT: |
| 4962 | if (gt_bias) { |
| 4963 | __ CmpUltS(FTMP, rhs, lhs); |
| 4964 | } else { |
| 4965 | __ CmpLtS(FTMP, rhs, lhs); |
| 4966 | } |
| 4967 | __ Mfc1(dst, FTMP); |
| 4968 | __ Andi(dst, dst, 1); |
| 4969 | break; |
| 4970 | case kCondGE: |
| 4971 | if (gt_bias) { |
| 4972 | __ CmpUleS(FTMP, rhs, lhs); |
| 4973 | } else { |
| 4974 | __ CmpLeS(FTMP, rhs, lhs); |
| 4975 | } |
| 4976 | __ Mfc1(dst, FTMP); |
| 4977 | __ Andi(dst, dst, 1); |
| 4978 | break; |
| 4979 | default: |
| 4980 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4981 | UNREACHABLE(); |
| 4982 | } |
| 4983 | } else { |
| 4984 | switch (cond) { |
| 4985 | case kCondEQ: |
| 4986 | __ CeqS(0, lhs, rhs); |
| 4987 | __ LoadConst32(dst, 1); |
| 4988 | __ Movf(dst, ZERO, 0); |
| 4989 | break; |
| 4990 | case kCondNE: |
| 4991 | __ CeqS(0, lhs, rhs); |
| 4992 | __ LoadConst32(dst, 1); |
| 4993 | __ Movt(dst, ZERO, 0); |
| 4994 | break; |
| 4995 | case kCondLT: |
| 4996 | if (gt_bias) { |
| 4997 | __ ColtS(0, lhs, rhs); |
| 4998 | } else { |
| 4999 | __ CultS(0, lhs, rhs); |
| 5000 | } |
| 5001 | __ LoadConst32(dst, 1); |
| 5002 | __ Movf(dst, ZERO, 0); |
| 5003 | break; |
| 5004 | case kCondLE: |
| 5005 | if (gt_bias) { |
| 5006 | __ ColeS(0, lhs, rhs); |
| 5007 | } else { |
| 5008 | __ CuleS(0, lhs, rhs); |
| 5009 | } |
| 5010 | __ LoadConst32(dst, 1); |
| 5011 | __ Movf(dst, ZERO, 0); |
| 5012 | break; |
| 5013 | case kCondGT: |
| 5014 | if (gt_bias) { |
| 5015 | __ CultS(0, rhs, lhs); |
| 5016 | } else { |
| 5017 | __ ColtS(0, rhs, lhs); |
| 5018 | } |
| 5019 | __ LoadConst32(dst, 1); |
| 5020 | __ Movf(dst, ZERO, 0); |
| 5021 | break; |
| 5022 | case kCondGE: |
| 5023 | if (gt_bias) { |
| 5024 | __ CuleS(0, rhs, lhs); |
| 5025 | } else { |
| 5026 | __ ColeS(0, rhs, lhs); |
| 5027 | } |
| 5028 | __ LoadConst32(dst, 1); |
| 5029 | __ Movf(dst, ZERO, 0); |
| 5030 | break; |
| 5031 | default: |
| 5032 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5033 | UNREACHABLE(); |
| 5034 | } |
| 5035 | } |
| 5036 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5037 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 5038 | if (isR6) { |
| 5039 | switch (cond) { |
| 5040 | case kCondEQ: |
| 5041 | __ CmpEqD(FTMP, lhs, rhs); |
| 5042 | __ Mfc1(dst, FTMP); |
| 5043 | __ Andi(dst, dst, 1); |
| 5044 | break; |
| 5045 | case kCondNE: |
| 5046 | __ CmpEqD(FTMP, lhs, rhs); |
| 5047 | __ Mfc1(dst, FTMP); |
| 5048 | __ Addiu(dst, dst, 1); |
| 5049 | break; |
| 5050 | case kCondLT: |
| 5051 | if (gt_bias) { |
| 5052 | __ CmpLtD(FTMP, lhs, rhs); |
| 5053 | } else { |
| 5054 | __ CmpUltD(FTMP, lhs, rhs); |
| 5055 | } |
| 5056 | __ Mfc1(dst, FTMP); |
| 5057 | __ Andi(dst, dst, 1); |
| 5058 | break; |
| 5059 | case kCondLE: |
| 5060 | if (gt_bias) { |
| 5061 | __ CmpLeD(FTMP, lhs, rhs); |
| 5062 | } else { |
| 5063 | __ CmpUleD(FTMP, lhs, rhs); |
| 5064 | } |
| 5065 | __ Mfc1(dst, FTMP); |
| 5066 | __ Andi(dst, dst, 1); |
| 5067 | break; |
| 5068 | case kCondGT: |
| 5069 | if (gt_bias) { |
| 5070 | __ CmpUltD(FTMP, rhs, lhs); |
| 5071 | } else { |
| 5072 | __ CmpLtD(FTMP, rhs, lhs); |
| 5073 | } |
| 5074 | __ Mfc1(dst, FTMP); |
| 5075 | __ Andi(dst, dst, 1); |
| 5076 | break; |
| 5077 | case kCondGE: |
| 5078 | if (gt_bias) { |
| 5079 | __ CmpUleD(FTMP, rhs, lhs); |
| 5080 | } else { |
| 5081 | __ CmpLeD(FTMP, rhs, lhs); |
| 5082 | } |
| 5083 | __ Mfc1(dst, FTMP); |
| 5084 | __ Andi(dst, dst, 1); |
| 5085 | break; |
| 5086 | default: |
| 5087 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5088 | UNREACHABLE(); |
| 5089 | } |
| 5090 | } else { |
| 5091 | switch (cond) { |
| 5092 | case kCondEQ: |
| 5093 | __ CeqD(0, lhs, rhs); |
| 5094 | __ LoadConst32(dst, 1); |
| 5095 | __ Movf(dst, ZERO, 0); |
| 5096 | break; |
| 5097 | case kCondNE: |
| 5098 | __ CeqD(0, lhs, rhs); |
| 5099 | __ LoadConst32(dst, 1); |
| 5100 | __ Movt(dst, ZERO, 0); |
| 5101 | break; |
| 5102 | case kCondLT: |
| 5103 | if (gt_bias) { |
| 5104 | __ ColtD(0, lhs, rhs); |
| 5105 | } else { |
| 5106 | __ CultD(0, lhs, rhs); |
| 5107 | } |
| 5108 | __ LoadConst32(dst, 1); |
| 5109 | __ Movf(dst, ZERO, 0); |
| 5110 | break; |
| 5111 | case kCondLE: |
| 5112 | if (gt_bias) { |
| 5113 | __ ColeD(0, lhs, rhs); |
| 5114 | } else { |
| 5115 | __ CuleD(0, lhs, rhs); |
| 5116 | } |
| 5117 | __ LoadConst32(dst, 1); |
| 5118 | __ Movf(dst, ZERO, 0); |
| 5119 | break; |
| 5120 | case kCondGT: |
| 5121 | if (gt_bias) { |
| 5122 | __ CultD(0, rhs, lhs); |
| 5123 | } else { |
| 5124 | __ ColtD(0, rhs, lhs); |
| 5125 | } |
| 5126 | __ LoadConst32(dst, 1); |
| 5127 | __ Movf(dst, ZERO, 0); |
| 5128 | break; |
| 5129 | case kCondGE: |
| 5130 | if (gt_bias) { |
| 5131 | __ CuleD(0, rhs, lhs); |
| 5132 | } else { |
| 5133 | __ ColeD(0, rhs, lhs); |
| 5134 | } |
| 5135 | __ LoadConst32(dst, 1); |
| 5136 | __ Movf(dst, ZERO, 0); |
| 5137 | break; |
| 5138 | default: |
| 5139 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 5140 | UNREACHABLE(); |
| 5141 | } |
| 5142 | } |
| 5143 | } |
| 5144 | } |
| 5145 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5146 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond, |
| 5147 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5148 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5149 | LocationSummary* input_locations, |
| 5150 | int cc) { |
| 5151 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5152 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5153 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5154 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5155 | switch (cond) { |
| 5156 | case kCondEQ: |
| 5157 | __ CeqS(cc, lhs, rhs); |
| 5158 | return false; |
| 5159 | case kCondNE: |
| 5160 | __ CeqS(cc, lhs, rhs); |
| 5161 | return true; |
| 5162 | case kCondLT: |
| 5163 | if (gt_bias) { |
| 5164 | __ ColtS(cc, lhs, rhs); |
| 5165 | } else { |
| 5166 | __ CultS(cc, lhs, rhs); |
| 5167 | } |
| 5168 | return false; |
| 5169 | case kCondLE: |
| 5170 | if (gt_bias) { |
| 5171 | __ ColeS(cc, lhs, rhs); |
| 5172 | } else { |
| 5173 | __ CuleS(cc, lhs, rhs); |
| 5174 | } |
| 5175 | return false; |
| 5176 | case kCondGT: |
| 5177 | if (gt_bias) { |
| 5178 | __ CultS(cc, rhs, lhs); |
| 5179 | } else { |
| 5180 | __ ColtS(cc, rhs, lhs); |
| 5181 | } |
| 5182 | return false; |
| 5183 | case kCondGE: |
| 5184 | if (gt_bias) { |
| 5185 | __ CuleS(cc, rhs, lhs); |
| 5186 | } else { |
| 5187 | __ ColeS(cc, rhs, lhs); |
| 5188 | } |
| 5189 | return false; |
| 5190 | default: |
| 5191 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5192 | UNREACHABLE(); |
| 5193 | } |
| 5194 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5195 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5196 | switch (cond) { |
| 5197 | case kCondEQ: |
| 5198 | __ CeqD(cc, lhs, rhs); |
| 5199 | return false; |
| 5200 | case kCondNE: |
| 5201 | __ CeqD(cc, lhs, rhs); |
| 5202 | return true; |
| 5203 | case kCondLT: |
| 5204 | if (gt_bias) { |
| 5205 | __ ColtD(cc, lhs, rhs); |
| 5206 | } else { |
| 5207 | __ CultD(cc, lhs, rhs); |
| 5208 | } |
| 5209 | return false; |
| 5210 | case kCondLE: |
| 5211 | if (gt_bias) { |
| 5212 | __ ColeD(cc, lhs, rhs); |
| 5213 | } else { |
| 5214 | __ CuleD(cc, lhs, rhs); |
| 5215 | } |
| 5216 | return false; |
| 5217 | case kCondGT: |
| 5218 | if (gt_bias) { |
| 5219 | __ CultD(cc, rhs, lhs); |
| 5220 | } else { |
| 5221 | __ ColtD(cc, rhs, lhs); |
| 5222 | } |
| 5223 | return false; |
| 5224 | case kCondGE: |
| 5225 | if (gt_bias) { |
| 5226 | __ CuleD(cc, rhs, lhs); |
| 5227 | } else { |
| 5228 | __ ColeD(cc, rhs, lhs); |
| 5229 | } |
| 5230 | return false; |
| 5231 | default: |
| 5232 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5233 | UNREACHABLE(); |
| 5234 | } |
| 5235 | } |
| 5236 | } |
| 5237 | |
| 5238 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond, |
| 5239 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5240 | DataType::Type type, |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5241 | LocationSummary* input_locations, |
| 5242 | FRegister dst) { |
| 5243 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5244 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5245 | CHECK(codegen_->GetInstructionSetFeatures().IsR6()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5246 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5247 | switch (cond) { |
| 5248 | case kCondEQ: |
| 5249 | __ CmpEqS(dst, lhs, rhs); |
| 5250 | return false; |
| 5251 | case kCondNE: |
| 5252 | __ CmpEqS(dst, lhs, rhs); |
| 5253 | return true; |
| 5254 | case kCondLT: |
| 5255 | if (gt_bias) { |
| 5256 | __ CmpLtS(dst, lhs, rhs); |
| 5257 | } else { |
| 5258 | __ CmpUltS(dst, lhs, rhs); |
| 5259 | } |
| 5260 | return false; |
| 5261 | case kCondLE: |
| 5262 | if (gt_bias) { |
| 5263 | __ CmpLeS(dst, lhs, rhs); |
| 5264 | } else { |
| 5265 | __ CmpUleS(dst, lhs, rhs); |
| 5266 | } |
| 5267 | return false; |
| 5268 | case kCondGT: |
| 5269 | if (gt_bias) { |
| 5270 | __ CmpUltS(dst, rhs, lhs); |
| 5271 | } else { |
| 5272 | __ CmpLtS(dst, rhs, lhs); |
| 5273 | } |
| 5274 | return false; |
| 5275 | case kCondGE: |
| 5276 | if (gt_bias) { |
| 5277 | __ CmpUleS(dst, rhs, lhs); |
| 5278 | } else { |
| 5279 | __ CmpLeS(dst, rhs, lhs); |
| 5280 | } |
| 5281 | return false; |
| 5282 | default: |
| 5283 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5284 | UNREACHABLE(); |
| 5285 | } |
| 5286 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5287 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5288 | switch (cond) { |
| 5289 | case kCondEQ: |
| 5290 | __ CmpEqD(dst, lhs, rhs); |
| 5291 | return false; |
| 5292 | case kCondNE: |
| 5293 | __ CmpEqD(dst, lhs, rhs); |
| 5294 | return true; |
| 5295 | case kCondLT: |
| 5296 | if (gt_bias) { |
| 5297 | __ CmpLtD(dst, lhs, rhs); |
| 5298 | } else { |
| 5299 | __ CmpUltD(dst, lhs, rhs); |
| 5300 | } |
| 5301 | return false; |
| 5302 | case kCondLE: |
| 5303 | if (gt_bias) { |
| 5304 | __ CmpLeD(dst, lhs, rhs); |
| 5305 | } else { |
| 5306 | __ CmpUleD(dst, lhs, rhs); |
| 5307 | } |
| 5308 | return false; |
| 5309 | case kCondGT: |
| 5310 | if (gt_bias) { |
| 5311 | __ CmpUltD(dst, rhs, lhs); |
| 5312 | } else { |
| 5313 | __ CmpLtD(dst, rhs, lhs); |
| 5314 | } |
| 5315 | return false; |
| 5316 | case kCondGE: |
| 5317 | if (gt_bias) { |
| 5318 | __ CmpUleD(dst, rhs, lhs); |
| 5319 | } else { |
| 5320 | __ CmpLeD(dst, rhs, lhs); |
| 5321 | } |
| 5322 | return false; |
| 5323 | default: |
| 5324 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 5325 | UNREACHABLE(); |
| 5326 | } |
| 5327 | } |
| 5328 | } |
| 5329 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5330 | void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond, |
| 5331 | bool gt_bias, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5332 | DataType::Type type, |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5333 | LocationSummary* locations, |
| 5334 | MipsLabel* label) { |
| 5335 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5336 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5337 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5338 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5339 | if (isR6) { |
| 5340 | switch (cond) { |
| 5341 | case kCondEQ: |
| 5342 | __ CmpEqS(FTMP, lhs, rhs); |
| 5343 | __ Bc1nez(FTMP, label); |
| 5344 | break; |
| 5345 | case kCondNE: |
| 5346 | __ CmpEqS(FTMP, lhs, rhs); |
| 5347 | __ Bc1eqz(FTMP, label); |
| 5348 | break; |
| 5349 | case kCondLT: |
| 5350 | if (gt_bias) { |
| 5351 | __ CmpLtS(FTMP, lhs, rhs); |
| 5352 | } else { |
| 5353 | __ CmpUltS(FTMP, lhs, rhs); |
| 5354 | } |
| 5355 | __ Bc1nez(FTMP, label); |
| 5356 | break; |
| 5357 | case kCondLE: |
| 5358 | if (gt_bias) { |
| 5359 | __ CmpLeS(FTMP, lhs, rhs); |
| 5360 | } else { |
| 5361 | __ CmpUleS(FTMP, lhs, rhs); |
| 5362 | } |
| 5363 | __ Bc1nez(FTMP, label); |
| 5364 | break; |
| 5365 | case kCondGT: |
| 5366 | if (gt_bias) { |
| 5367 | __ CmpUltS(FTMP, rhs, lhs); |
| 5368 | } else { |
| 5369 | __ CmpLtS(FTMP, rhs, lhs); |
| 5370 | } |
| 5371 | __ Bc1nez(FTMP, label); |
| 5372 | break; |
| 5373 | case kCondGE: |
| 5374 | if (gt_bias) { |
| 5375 | __ CmpUleS(FTMP, rhs, lhs); |
| 5376 | } else { |
| 5377 | __ CmpLeS(FTMP, rhs, lhs); |
| 5378 | } |
| 5379 | __ Bc1nez(FTMP, label); |
| 5380 | break; |
| 5381 | default: |
| 5382 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5383 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5384 | } |
| 5385 | } else { |
| 5386 | switch (cond) { |
| 5387 | case kCondEQ: |
| 5388 | __ CeqS(0, lhs, rhs); |
| 5389 | __ Bc1t(0, label); |
| 5390 | break; |
| 5391 | case kCondNE: |
| 5392 | __ CeqS(0, lhs, rhs); |
| 5393 | __ Bc1f(0, label); |
| 5394 | break; |
| 5395 | case kCondLT: |
| 5396 | if (gt_bias) { |
| 5397 | __ ColtS(0, lhs, rhs); |
| 5398 | } else { |
| 5399 | __ CultS(0, lhs, rhs); |
| 5400 | } |
| 5401 | __ Bc1t(0, label); |
| 5402 | break; |
| 5403 | case kCondLE: |
| 5404 | if (gt_bias) { |
| 5405 | __ ColeS(0, lhs, rhs); |
| 5406 | } else { |
| 5407 | __ CuleS(0, lhs, rhs); |
| 5408 | } |
| 5409 | __ Bc1t(0, label); |
| 5410 | break; |
| 5411 | case kCondGT: |
| 5412 | if (gt_bias) { |
| 5413 | __ CultS(0, rhs, lhs); |
| 5414 | } else { |
| 5415 | __ ColtS(0, rhs, lhs); |
| 5416 | } |
| 5417 | __ Bc1t(0, label); |
| 5418 | break; |
| 5419 | case kCondGE: |
| 5420 | if (gt_bias) { |
| 5421 | __ CuleS(0, rhs, lhs); |
| 5422 | } else { |
| 5423 | __ ColeS(0, rhs, lhs); |
| 5424 | } |
| 5425 | __ Bc1t(0, label); |
| 5426 | break; |
| 5427 | default: |
| 5428 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5429 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5430 | } |
| 5431 | } |
| 5432 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5433 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5434 | if (isR6) { |
| 5435 | switch (cond) { |
| 5436 | case kCondEQ: |
| 5437 | __ CmpEqD(FTMP, lhs, rhs); |
| 5438 | __ Bc1nez(FTMP, label); |
| 5439 | break; |
| 5440 | case kCondNE: |
| 5441 | __ CmpEqD(FTMP, lhs, rhs); |
| 5442 | __ Bc1eqz(FTMP, label); |
| 5443 | break; |
| 5444 | case kCondLT: |
| 5445 | if (gt_bias) { |
| 5446 | __ CmpLtD(FTMP, lhs, rhs); |
| 5447 | } else { |
| 5448 | __ CmpUltD(FTMP, lhs, rhs); |
| 5449 | } |
| 5450 | __ Bc1nez(FTMP, label); |
| 5451 | break; |
| 5452 | case kCondLE: |
| 5453 | if (gt_bias) { |
| 5454 | __ CmpLeD(FTMP, lhs, rhs); |
| 5455 | } else { |
| 5456 | __ CmpUleD(FTMP, lhs, rhs); |
| 5457 | } |
| 5458 | __ Bc1nez(FTMP, label); |
| 5459 | break; |
| 5460 | case kCondGT: |
| 5461 | if (gt_bias) { |
| 5462 | __ CmpUltD(FTMP, rhs, lhs); |
| 5463 | } else { |
| 5464 | __ CmpLtD(FTMP, rhs, lhs); |
| 5465 | } |
| 5466 | __ Bc1nez(FTMP, label); |
| 5467 | break; |
| 5468 | case kCondGE: |
| 5469 | if (gt_bias) { |
| 5470 | __ CmpUleD(FTMP, rhs, lhs); |
| 5471 | } else { |
| 5472 | __ CmpLeD(FTMP, rhs, lhs); |
| 5473 | } |
| 5474 | __ Bc1nez(FTMP, label); |
| 5475 | break; |
| 5476 | default: |
| 5477 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5478 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5479 | } |
| 5480 | } else { |
| 5481 | switch (cond) { |
| 5482 | case kCondEQ: |
| 5483 | __ CeqD(0, lhs, rhs); |
| 5484 | __ Bc1t(0, label); |
| 5485 | break; |
| 5486 | case kCondNE: |
| 5487 | __ CeqD(0, lhs, rhs); |
| 5488 | __ Bc1f(0, label); |
| 5489 | break; |
| 5490 | case kCondLT: |
| 5491 | if (gt_bias) { |
| 5492 | __ ColtD(0, lhs, rhs); |
| 5493 | } else { |
| 5494 | __ CultD(0, lhs, rhs); |
| 5495 | } |
| 5496 | __ Bc1t(0, label); |
| 5497 | break; |
| 5498 | case kCondLE: |
| 5499 | if (gt_bias) { |
| 5500 | __ ColeD(0, lhs, rhs); |
| 5501 | } else { |
| 5502 | __ CuleD(0, lhs, rhs); |
| 5503 | } |
| 5504 | __ Bc1t(0, label); |
| 5505 | break; |
| 5506 | case kCondGT: |
| 5507 | if (gt_bias) { |
| 5508 | __ CultD(0, rhs, lhs); |
| 5509 | } else { |
| 5510 | __ ColtD(0, rhs, lhs); |
| 5511 | } |
| 5512 | __ Bc1t(0, label); |
| 5513 | break; |
| 5514 | case kCondGE: |
| 5515 | if (gt_bias) { |
| 5516 | __ CuleD(0, rhs, lhs); |
| 5517 | } else { |
| 5518 | __ ColeD(0, rhs, lhs); |
| 5519 | } |
| 5520 | __ Bc1t(0, label); |
| 5521 | break; |
| 5522 | default: |
| 5523 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5524 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5525 | } |
| 5526 | } |
| 5527 | } |
| 5528 | } |
| 5529 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5530 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5531 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5532 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5533 | MipsLabel* false_target) { |
| 5534 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5535 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5536 | if (true_target == nullptr && false_target == nullptr) { |
| 5537 | // Nothing to do. The code always falls through. |
| 5538 | return; |
| 5539 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5540 | // Constant condition, statically compared against "true" (integer value 1). |
| 5541 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5542 | if (true_target != nullptr) { |
| 5543 | __ B(true_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5544 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5545 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5546 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5547 | if (false_target != nullptr) { |
| 5548 | __ B(false_target); |
| 5549 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5550 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5551 | return; |
| 5552 | } |
| 5553 | |
| 5554 | // The following code generates these patterns: |
| 5555 | // (1) true_target == nullptr && false_target != nullptr |
| 5556 | // - opposite condition true => branch to false_target |
| 5557 | // (2) true_target != nullptr && false_target == nullptr |
| 5558 | // - condition true => branch to true_target |
| 5559 | // (3) true_target != nullptr && false_target != nullptr |
| 5560 | // - condition true => branch to true_target |
| 5561 | // - branch to false_target |
| 5562 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5563 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5564 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5565 | DCHECK(cond_val.IsRegister()); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5566 | if (true_target == nullptr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5567 | __ Beqz(cond_val.AsRegister<Register>(), false_target); |
| 5568 | } else { |
| 5569 | __ Bnez(cond_val.AsRegister<Register>(), true_target); |
| 5570 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5571 | } else { |
| 5572 | // The condition instruction has not been materialized, use its inputs as |
| 5573 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5574 | HCondition* condition = cond->AsCondition(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5575 | DataType::Type type = condition->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5576 | LocationSummary* locations = cond->GetLocations(); |
| 5577 | IfCondition if_cond = condition->GetCondition(); |
| 5578 | MipsLabel* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5579 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5580 | if (true_target == nullptr) { |
| 5581 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5582 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5583 | } |
| 5584 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5585 | switch (type) { |
| 5586 | default: |
| 5587 | GenerateIntCompareAndBranch(if_cond, locations, branch_target); |
| 5588 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5589 | case DataType::Type::kInt64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5590 | GenerateLongCompareAndBranch(if_cond, locations, branch_target); |
| 5591 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5592 | case DataType::Type::kFloat32: |
| 5593 | case DataType::Type::kFloat64: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5594 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 5595 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5596 | } |
| 5597 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5598 | |
| 5599 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 5600 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 5601 | if (true_target != nullptr && false_target != nullptr) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5602 | __ B(false_target); |
| 5603 | } |
| 5604 | } |
| 5605 | |
| 5606 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5607 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5608 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5609 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5610 | } |
| 5611 | } |
| 5612 | |
| 5613 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5614 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 5615 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 5616 | MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 5617 | nullptr : codegen_->GetLabelOf(true_successor); |
| 5618 | MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 5619 | nullptr : codegen_->GetLabelOf(false_successor); |
| 5620 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5621 | } |
| 5622 | |
| 5623 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5624 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5625 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 5626 | InvokeRuntimeCallingConvention calling_convention; |
| 5627 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5628 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5629 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5630 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5631 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5632 | } |
| 5633 | } |
| 5634 | |
| 5635 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 5636 | SlowPathCodeMIPS* slow_path = |
| 5637 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5638 | GenerateTestAndBranch(deoptimize, |
| 5639 | /* condition_input_index */ 0, |
| 5640 | slow_path->GetEntryLabel(), |
| 5641 | /* false_target */ nullptr); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5642 | } |
| 5643 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5644 | // This function returns true if a conditional move can be generated for HSelect. |
| 5645 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 5646 | // branches and regular moves. |
| 5647 | // |
| 5648 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 5649 | // |
| 5650 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 5651 | // are two distinct tasks, this function does both because they share quite a bit |
| 5652 | // of common logic. |
| 5653 | static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) { |
| 5654 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 5655 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 5656 | HCondition* condition = cond->AsCondition(); |
| 5657 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5658 | DataType::Type cond_type = |
| 5659 | materialized ? DataType::Type::kInt32 : condition->InputAt(0)->GetType(); |
| 5660 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5661 | |
| 5662 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 5663 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 5664 | bool is_true_value_zero_constant = |
| 5665 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 5666 | bool is_false_value_zero_constant = |
| 5667 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 5668 | |
| 5669 | bool can_move_conditionally = false; |
| 5670 | bool use_const_for_false_in = false; |
| 5671 | bool use_const_for_true_in = false; |
| 5672 | |
| 5673 | if (!cond->IsConstant()) { |
| 5674 | switch (cond_type) { |
| 5675 | default: |
| 5676 | switch (dst_type) { |
| 5677 | default: |
| 5678 | // Moving int on int condition. |
| 5679 | if (is_r6) { |
| 5680 | if (is_true_value_zero_constant) { |
| 5681 | // seleqz out_reg, false_reg, cond_reg |
| 5682 | can_move_conditionally = true; |
| 5683 | use_const_for_true_in = true; |
| 5684 | } else if (is_false_value_zero_constant) { |
| 5685 | // selnez out_reg, true_reg, cond_reg |
| 5686 | can_move_conditionally = true; |
| 5687 | use_const_for_false_in = true; |
| 5688 | } else if (materialized) { |
| 5689 | // Not materializing unmaterialized int conditions |
| 5690 | // to keep the instruction count low. |
| 5691 | // selnez AT, true_reg, cond_reg |
| 5692 | // seleqz TMP, false_reg, cond_reg |
| 5693 | // or out_reg, AT, TMP |
| 5694 | can_move_conditionally = true; |
| 5695 | } |
| 5696 | } else { |
| 5697 | // movn out_reg, true_reg/ZERO, cond_reg |
| 5698 | can_move_conditionally = true; |
| 5699 | use_const_for_true_in = is_true_value_zero_constant; |
| 5700 | } |
| 5701 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5702 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5703 | // Moving long on int condition. |
| 5704 | if (is_r6) { |
| 5705 | if (is_true_value_zero_constant) { |
| 5706 | // seleqz out_reg_lo, false_reg_lo, cond_reg |
| 5707 | // seleqz out_reg_hi, false_reg_hi, cond_reg |
| 5708 | can_move_conditionally = true; |
| 5709 | use_const_for_true_in = true; |
| 5710 | } else if (is_false_value_zero_constant) { |
| 5711 | // selnez out_reg_lo, true_reg_lo, cond_reg |
| 5712 | // selnez out_reg_hi, true_reg_hi, cond_reg |
| 5713 | can_move_conditionally = true; |
| 5714 | use_const_for_false_in = true; |
| 5715 | } |
| 5716 | // Other long conditional moves would generate 6+ instructions, |
| 5717 | // which is too many. |
| 5718 | } else { |
| 5719 | // movn out_reg_lo, true_reg_lo/ZERO, cond_reg |
| 5720 | // movn out_reg_hi, true_reg_hi/ZERO, cond_reg |
| 5721 | can_move_conditionally = true; |
| 5722 | use_const_for_true_in = is_true_value_zero_constant; |
| 5723 | } |
| 5724 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5725 | case DataType::Type::kFloat32: |
| 5726 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5727 | // Moving float/double on int condition. |
| 5728 | if (is_r6) { |
| 5729 | if (materialized) { |
| 5730 | // Not materializing unmaterialized int conditions |
| 5731 | // to keep the instruction count low. |
| 5732 | can_move_conditionally = true; |
| 5733 | if (is_true_value_zero_constant) { |
| 5734 | // sltu TMP, ZERO, cond_reg |
| 5735 | // mtc1 TMP, temp_cond_reg |
| 5736 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 5737 | use_const_for_true_in = true; |
| 5738 | } else if (is_false_value_zero_constant) { |
| 5739 | // sltu TMP, ZERO, cond_reg |
| 5740 | // mtc1 TMP, temp_cond_reg |
| 5741 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 5742 | use_const_for_false_in = true; |
| 5743 | } else { |
| 5744 | // sltu TMP, ZERO, cond_reg |
| 5745 | // mtc1 TMP, temp_cond_reg |
| 5746 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 5747 | // mov.fmt out_reg, temp_cond_reg |
| 5748 | } |
| 5749 | } |
| 5750 | } else { |
| 5751 | // movn.fmt out_reg, true_reg, cond_reg |
| 5752 | can_move_conditionally = true; |
| 5753 | } |
| 5754 | break; |
| 5755 | } |
| 5756 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5757 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5758 | // We don't materialize long comparison now |
| 5759 | // and use conditional branches instead. |
| 5760 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5761 | case DataType::Type::kFloat32: |
| 5762 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5763 | switch (dst_type) { |
| 5764 | default: |
| 5765 | // Moving int on float/double condition. |
| 5766 | if (is_r6) { |
| 5767 | if (is_true_value_zero_constant) { |
| 5768 | // mfc1 TMP, temp_cond_reg |
| 5769 | // seleqz out_reg, false_reg, TMP |
| 5770 | can_move_conditionally = true; |
| 5771 | use_const_for_true_in = true; |
| 5772 | } else if (is_false_value_zero_constant) { |
| 5773 | // mfc1 TMP, temp_cond_reg |
| 5774 | // selnez out_reg, true_reg, TMP |
| 5775 | can_move_conditionally = true; |
| 5776 | use_const_for_false_in = true; |
| 5777 | } else { |
| 5778 | // mfc1 TMP, temp_cond_reg |
| 5779 | // selnez AT, true_reg, TMP |
| 5780 | // seleqz TMP, false_reg, TMP |
| 5781 | // or out_reg, AT, TMP |
| 5782 | can_move_conditionally = true; |
| 5783 | } |
| 5784 | } else { |
| 5785 | // movt out_reg, true_reg/ZERO, cc |
| 5786 | can_move_conditionally = true; |
| 5787 | use_const_for_true_in = is_true_value_zero_constant; |
| 5788 | } |
| 5789 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5790 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5791 | // Moving long on float/double condition. |
| 5792 | if (is_r6) { |
| 5793 | if (is_true_value_zero_constant) { |
| 5794 | // mfc1 TMP, temp_cond_reg |
| 5795 | // seleqz out_reg_lo, false_reg_lo, TMP |
| 5796 | // seleqz out_reg_hi, false_reg_hi, TMP |
| 5797 | can_move_conditionally = true; |
| 5798 | use_const_for_true_in = true; |
| 5799 | } else if (is_false_value_zero_constant) { |
| 5800 | // mfc1 TMP, temp_cond_reg |
| 5801 | // selnez out_reg_lo, true_reg_lo, TMP |
| 5802 | // selnez out_reg_hi, true_reg_hi, TMP |
| 5803 | can_move_conditionally = true; |
| 5804 | use_const_for_false_in = true; |
| 5805 | } |
| 5806 | // Other long conditional moves would generate 6+ instructions, |
| 5807 | // which is too many. |
| 5808 | } else { |
| 5809 | // movt out_reg_lo, true_reg_lo/ZERO, cc |
| 5810 | // movt out_reg_hi, true_reg_hi/ZERO, cc |
| 5811 | can_move_conditionally = true; |
| 5812 | use_const_for_true_in = is_true_value_zero_constant; |
| 5813 | } |
| 5814 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5815 | case DataType::Type::kFloat32: |
| 5816 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5817 | // Moving float/double on float/double condition. |
| 5818 | if (is_r6) { |
| 5819 | can_move_conditionally = true; |
| 5820 | if (is_true_value_zero_constant) { |
| 5821 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 5822 | use_const_for_true_in = true; |
| 5823 | } else if (is_false_value_zero_constant) { |
| 5824 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 5825 | use_const_for_false_in = true; |
| 5826 | } else { |
| 5827 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 5828 | // mov.fmt out_reg, temp_cond_reg |
| 5829 | } |
| 5830 | } else { |
| 5831 | // movt.fmt out_reg, true_reg, cc |
| 5832 | can_move_conditionally = true; |
| 5833 | } |
| 5834 | break; |
| 5835 | } |
| 5836 | break; |
| 5837 | } |
| 5838 | } |
| 5839 | |
| 5840 | if (can_move_conditionally) { |
| 5841 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 5842 | } else { |
| 5843 | DCHECK(!use_const_for_false_in); |
| 5844 | DCHECK(!use_const_for_true_in); |
| 5845 | } |
| 5846 | |
| 5847 | if (locations_to_set != nullptr) { |
| 5848 | if (use_const_for_false_in) { |
| 5849 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 5850 | } else { |
| 5851 | locations_to_set->SetInAt(0, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5852 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5853 | ? Location::RequiresFpuRegister() |
| 5854 | : Location::RequiresRegister()); |
| 5855 | } |
| 5856 | if (use_const_for_true_in) { |
| 5857 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 5858 | } else { |
| 5859 | locations_to_set->SetInAt(1, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5860 | DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5861 | ? Location::RequiresFpuRegister() |
| 5862 | : Location::RequiresRegister()); |
| 5863 | } |
| 5864 | if (materialized) { |
| 5865 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 5866 | } |
| 5867 | // On R6 we don't require the output to be the same as the |
| 5868 | // first input for conditional moves unlike on R2. |
| 5869 | bool is_out_same_as_first_in = !can_move_conditionally || !is_r6; |
| 5870 | if (is_out_same_as_first_in) { |
| 5871 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 5872 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5873 | locations_to_set->SetOut(DataType::IsFloatingPointType(dst_type) |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5874 | ? Location::RequiresFpuRegister() |
| 5875 | : Location::RequiresRegister()); |
| 5876 | } |
| 5877 | } |
| 5878 | |
| 5879 | return can_move_conditionally; |
| 5880 | } |
| 5881 | |
| 5882 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) { |
| 5883 | LocationSummary* locations = select->GetLocations(); |
| 5884 | Location dst = locations->Out(); |
| 5885 | Location src = locations->InAt(1); |
| 5886 | Register src_reg = ZERO; |
| 5887 | Register src_reg_high = ZERO; |
| 5888 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 5889 | Register cond_reg = TMP; |
| 5890 | int cond_cc = 0; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5891 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5892 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5893 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5894 | |
| 5895 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 5896 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 5897 | } else { |
| 5898 | HCondition* condition = cond->AsCondition(); |
| 5899 | LocationSummary* cond_locations = cond->GetLocations(); |
| 5900 | IfCondition if_cond = condition->GetCondition(); |
| 5901 | cond_type = condition->InputAt(0)->GetType(); |
| 5902 | switch (cond_type) { |
| 5903 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5904 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5905 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 5906 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5907 | case DataType::Type::kFloat32: |
| 5908 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5909 | cond_inverted = MaterializeFpCompareR2(if_cond, |
| 5910 | condition->IsGtBias(), |
| 5911 | cond_type, |
| 5912 | cond_locations, |
| 5913 | cond_cc); |
| 5914 | break; |
| 5915 | } |
| 5916 | } |
| 5917 | |
| 5918 | DCHECK(dst.Equals(locations->InAt(0))); |
| 5919 | if (src.IsRegister()) { |
| 5920 | src_reg = src.AsRegister<Register>(); |
| 5921 | } else if (src.IsRegisterPair()) { |
| 5922 | src_reg = src.AsRegisterPairLow<Register>(); |
| 5923 | src_reg_high = src.AsRegisterPairHigh<Register>(); |
| 5924 | } else if (src.IsConstant()) { |
| 5925 | DCHECK(src.GetConstant()->IsZeroBitPattern()); |
| 5926 | } |
| 5927 | |
| 5928 | switch (cond_type) { |
| 5929 | default: |
| 5930 | switch (dst_type) { |
| 5931 | default: |
| 5932 | if (cond_inverted) { |
| 5933 | __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 5934 | } else { |
| 5935 | __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 5936 | } |
| 5937 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5938 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5939 | if (cond_inverted) { |
| 5940 | __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 5941 | __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 5942 | } else { |
| 5943 | __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 5944 | __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 5945 | } |
| 5946 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5947 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5948 | if (cond_inverted) { |
| 5949 | __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5950 | } else { |
| 5951 | __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5952 | } |
| 5953 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5954 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5955 | if (cond_inverted) { |
| 5956 | __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5957 | } else { |
| 5958 | __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5959 | } |
| 5960 | break; |
| 5961 | } |
| 5962 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5963 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5964 | LOG(FATAL) << "Unreachable"; |
| 5965 | UNREACHABLE(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5966 | case DataType::Type::kFloat32: |
| 5967 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5968 | switch (dst_type) { |
| 5969 | default: |
| 5970 | if (cond_inverted) { |
| 5971 | __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 5972 | } else { |
| 5973 | __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 5974 | } |
| 5975 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5976 | case DataType::Type::kInt64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5977 | if (cond_inverted) { |
| 5978 | __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 5979 | __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 5980 | } else { |
| 5981 | __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 5982 | __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 5983 | } |
| 5984 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5985 | case DataType::Type::kFloat32: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5986 | if (cond_inverted) { |
| 5987 | __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5988 | } else { |
| 5989 | __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5990 | } |
| 5991 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5992 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5993 | if (cond_inverted) { |
| 5994 | __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5995 | } else { |
| 5996 | __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5997 | } |
| 5998 | break; |
| 5999 | } |
| 6000 | break; |
| 6001 | } |
| 6002 | } |
| 6003 | |
| 6004 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) { |
| 6005 | LocationSummary* locations = select->GetLocations(); |
| 6006 | Location dst = locations->Out(); |
| 6007 | Location false_src = locations->InAt(0); |
| 6008 | Location true_src = locations->InAt(1); |
| 6009 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 6010 | Register cond_reg = TMP; |
| 6011 | FRegister fcond_reg = FTMP; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6012 | DataType::Type cond_type = DataType::Type::kInt32; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6013 | bool cond_inverted = false; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6014 | DataType::Type dst_type = select->GetType(); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6015 | |
| 6016 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 6017 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 6018 | } else { |
| 6019 | HCondition* condition = cond->AsCondition(); |
| 6020 | LocationSummary* cond_locations = cond->GetLocations(); |
| 6021 | IfCondition if_cond = condition->GetCondition(); |
| 6022 | cond_type = condition->InputAt(0)->GetType(); |
| 6023 | switch (cond_type) { |
| 6024 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6025 | DCHECK_NE(cond_type, DataType::Type::kInt64); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6026 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 6027 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6028 | case DataType::Type::kFloat32: |
| 6029 | case DataType::Type::kFloat64: |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6030 | cond_inverted = MaterializeFpCompareR6(if_cond, |
| 6031 | condition->IsGtBias(), |
| 6032 | cond_type, |
| 6033 | cond_locations, |
| 6034 | fcond_reg); |
| 6035 | break; |
| 6036 | } |
| 6037 | } |
| 6038 | |
| 6039 | if (true_src.IsConstant()) { |
| 6040 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 6041 | } |
| 6042 | if (false_src.IsConstant()) { |
| 6043 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 6044 | } |
| 6045 | |
| 6046 | switch (dst_type) { |
| 6047 | default: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6048 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6049 | __ Mfc1(cond_reg, fcond_reg); |
| 6050 | } |
| 6051 | if (true_src.IsConstant()) { |
| 6052 | if (cond_inverted) { |
| 6053 | __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 6054 | } else { |
| 6055 | __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 6056 | } |
| 6057 | } else if (false_src.IsConstant()) { |
| 6058 | if (cond_inverted) { |
| 6059 | __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 6060 | } else { |
| 6061 | __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 6062 | } |
| 6063 | } else { |
| 6064 | DCHECK_NE(cond_reg, AT); |
| 6065 | if (cond_inverted) { |
| 6066 | __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6067 | __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6068 | } else { |
| 6069 | __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg); |
| 6070 | __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 6071 | } |
| 6072 | __ Or(dst.AsRegister<Register>(), AT, TMP); |
| 6073 | } |
| 6074 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6075 | case DataType::Type::kInt64: { |
| 6076 | if (DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6077 | __ Mfc1(cond_reg, fcond_reg); |
| 6078 | } |
| 6079 | Register dst_lo = dst.AsRegisterPairLow<Register>(); |
| 6080 | Register dst_hi = dst.AsRegisterPairHigh<Register>(); |
| 6081 | if (true_src.IsConstant()) { |
| 6082 | Register src_lo = false_src.AsRegisterPairLow<Register>(); |
| 6083 | Register src_hi = false_src.AsRegisterPairHigh<Register>(); |
| 6084 | if (cond_inverted) { |
| 6085 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6086 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6087 | } else { |
| 6088 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6089 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6090 | } |
| 6091 | } else { |
| 6092 | DCHECK(false_src.IsConstant()); |
| 6093 | Register src_lo = true_src.AsRegisterPairLow<Register>(); |
| 6094 | Register src_hi = true_src.AsRegisterPairHigh<Register>(); |
| 6095 | if (cond_inverted) { |
| 6096 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 6097 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 6098 | } else { |
| 6099 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 6100 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 6101 | } |
| 6102 | } |
| 6103 | break; |
| 6104 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6105 | case DataType::Type::kFloat32: { |
| 6106 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6107 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6108 | __ Sltu(TMP, ZERO, cond_reg); |
| 6109 | __ Mtc1(TMP, fcond_reg); |
| 6110 | } |
| 6111 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6112 | if (true_src.IsConstant()) { |
| 6113 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6114 | if (cond_inverted) { |
| 6115 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6116 | } else { |
| 6117 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6118 | } |
| 6119 | } else if (false_src.IsConstant()) { |
| 6120 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6121 | if (cond_inverted) { |
| 6122 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 6123 | } else { |
| 6124 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 6125 | } |
| 6126 | } else { |
| 6127 | if (cond_inverted) { |
| 6128 | __ SelS(fcond_reg, |
| 6129 | true_src.AsFpuRegister<FRegister>(), |
| 6130 | false_src.AsFpuRegister<FRegister>()); |
| 6131 | } else { |
| 6132 | __ SelS(fcond_reg, |
| 6133 | false_src.AsFpuRegister<FRegister>(), |
| 6134 | true_src.AsFpuRegister<FRegister>()); |
| 6135 | } |
| 6136 | __ MovS(dst_reg, fcond_reg); |
| 6137 | } |
| 6138 | break; |
| 6139 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6140 | case DataType::Type::kFloat64: { |
| 6141 | if (!DataType::IsFloatingPointType(cond_type)) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6142 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 6143 | __ Sltu(TMP, ZERO, cond_reg); |
| 6144 | __ Mtc1(TMP, fcond_reg); |
| 6145 | } |
| 6146 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 6147 | if (true_src.IsConstant()) { |
| 6148 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 6149 | if (cond_inverted) { |
| 6150 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6151 | } else { |
| 6152 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6153 | } |
| 6154 | } else if (false_src.IsConstant()) { |
| 6155 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 6156 | if (cond_inverted) { |
| 6157 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 6158 | } else { |
| 6159 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 6160 | } |
| 6161 | } else { |
| 6162 | if (cond_inverted) { |
| 6163 | __ SelD(fcond_reg, |
| 6164 | true_src.AsFpuRegister<FRegister>(), |
| 6165 | false_src.AsFpuRegister<FRegister>()); |
| 6166 | } else { |
| 6167 | __ SelD(fcond_reg, |
| 6168 | false_src.AsFpuRegister<FRegister>(), |
| 6169 | true_src.AsFpuRegister<FRegister>()); |
| 6170 | } |
| 6171 | __ MovD(dst_reg, fcond_reg); |
| 6172 | } |
| 6173 | break; |
| 6174 | } |
| 6175 | } |
| 6176 | } |
| 6177 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6178 | void LocationsBuilderMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6179 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6180 | LocationSummary(flag, LocationSummary::kNoCall); |
| 6181 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6182 | } |
| 6183 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 6184 | void InstructionCodeGeneratorMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 6185 | __ LoadFromOffset(kLoadWord, |
| 6186 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 6187 | SP, |
| 6188 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 6189 | } |
| 6190 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6191 | void LocationsBuilderMIPS::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6192 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6193 | CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6194 | } |
| 6195 | |
| 6196 | void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 6197 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 6198 | if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) { |
| 6199 | if (is_r6) { |
| 6200 | GenConditionalMoveR6(select); |
| 6201 | } else { |
| 6202 | GenConditionalMoveR2(select); |
| 6203 | } |
| 6204 | } else { |
| 6205 | LocationSummary* locations = select->GetLocations(); |
| 6206 | MipsLabel false_target; |
| 6207 | GenerateTestAndBranch(select, |
| 6208 | /* condition_input_index */ 2, |
| 6209 | /* true_target */ nullptr, |
| 6210 | &false_target); |
| 6211 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 6212 | __ Bind(&false_target); |
| 6213 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6214 | } |
| 6215 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6216 | void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6217 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6218 | } |
| 6219 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 6220 | void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 6221 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 6222 | } |
| 6223 | |
| 6224 | void CodeGeneratorMIPS::GenerateNop() { |
| 6225 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6226 | } |
| 6227 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6228 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6229 | DataType::Type field_type = field_info.GetFieldType(); |
| 6230 | 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] | 6231 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6232 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6233 | kEmitCompilerReadBarrier && (field_type == DataType::Type::kReference); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6234 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6235 | instruction, |
| 6236 | generate_volatile |
| 6237 | ? LocationSummary::kCallOnMainOnly |
| 6238 | : (object_field_get_with_read_barrier |
| 6239 | ? LocationSummary::kCallOnSlowPath |
| 6240 | : LocationSummary::kNoCall)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6241 | |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 6242 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6243 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 6244 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6245 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6246 | if (generate_volatile) { |
| 6247 | InvokeRuntimeCallingConvention calling_convention; |
| 6248 | // need A0 to hold base + offset |
| 6249 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6250 | if (field_type == DataType::Type::kInt64) { |
| 6251 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kInt64)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6252 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6253 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6254 | locations->SetOut(Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6255 | // 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] | 6256 | Location reg = calling_convention.GetReturnLocation(DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6257 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); |
| 6258 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); |
| 6259 | } |
| 6260 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6261 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6262 | locations->SetOut(Location::RequiresFpuRegister()); |
| 6263 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6264 | // The output overlaps in the case of an object field get with |
| 6265 | // read barriers enabled: we do not want the move to overwrite the |
| 6266 | // object's location, as we need it to emit the read barrier. |
| 6267 | locations->SetOut(Location::RequiresRegister(), |
| 6268 | object_field_get_with_read_barrier |
| 6269 | ? Location::kOutputOverlap |
| 6270 | : Location::kNoOutputOverlap); |
| 6271 | } |
| 6272 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6273 | // We need a temporary register for the read barrier marking slow |
| 6274 | // path in CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6275 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6276 | locations->AddTemp(Location::RequiresRegister()); |
| 6277 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6278 | } |
| 6279 | } |
| 6280 | } |
| 6281 | |
| 6282 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, |
| 6283 | const FieldInfo& field_info, |
| 6284 | uint32_t dex_pc) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6285 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 6286 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6287 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6288 | Location obj_loc = locations->InAt(0); |
| 6289 | Register obj = obj_loc.AsRegister<Register>(); |
| 6290 | Location dst_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6291 | LoadOperandType load_type = kLoadUnsignedByte; |
| 6292 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6293 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6294 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6295 | |
| 6296 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6297 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6298 | case DataType::Type::kUint8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6299 | load_type = kLoadUnsignedByte; |
| 6300 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6301 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6302 | load_type = kLoadSignedByte; |
| 6303 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6304 | case DataType::Type::kUint16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6305 | load_type = kLoadUnsignedHalfword; |
| 6306 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6307 | case DataType::Type::kInt16: |
| 6308 | load_type = kLoadSignedHalfword; |
| 6309 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6310 | case DataType::Type::kInt32: |
| 6311 | case DataType::Type::kFloat32: |
| 6312 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6313 | load_type = kLoadWord; |
| 6314 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6315 | case DataType::Type::kInt64: |
| 6316 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6317 | load_type = kLoadDoubleword; |
| 6318 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6319 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6320 | LOG(FATAL) << "Unreachable type " << type; |
| 6321 | UNREACHABLE(); |
| 6322 | } |
| 6323 | |
| 6324 | if (is_volatile && load_type == kLoadDoubleword) { |
| 6325 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6326 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6327 | // Do implicit Null check |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6328 | __ LoadFromOffset(kLoadWord, |
| 6329 | ZERO, |
| 6330 | locations->GetTemp(0).AsRegister<Register>(), |
| 6331 | 0, |
| 6332 | null_checker); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6333 | codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6334 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6335 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6336 | // FP results are returned in core registers. Need to move them. |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6337 | if (dst_loc.IsFpuRegister()) { |
| 6338 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6339 | __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6340 | dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6341 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6342 | DCHECK(dst_loc.IsDoubleStackSlot()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6343 | __ StoreToOffset(kStoreWord, |
| 6344 | locations->GetTemp(1).AsRegister<Register>(), |
| 6345 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6346 | dst_loc.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6347 | __ StoreToOffset(kStoreWord, |
| 6348 | locations->GetTemp(2).AsRegister<Register>(), |
| 6349 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6350 | dst_loc.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6351 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6352 | } |
| 6353 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6354 | if (type == DataType::Type::kReference) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6355 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 6356 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6357 | Location temp_loc = |
| 6358 | kBakerReadBarrierThunksEnableForFields ? Location::NoLocation() : locations->GetTemp(0); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6359 | // Note that a potential implicit null check is handled in this |
| 6360 | // CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier call. |
| 6361 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6362 | dst_loc, |
| 6363 | obj, |
| 6364 | offset, |
| 6365 | temp_loc, |
| 6366 | /* needs_null_check */ true); |
| 6367 | if (is_volatile) { |
| 6368 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6369 | } |
| 6370 | } else { |
| 6371 | __ LoadFromOffset(kLoadWord, dst_loc.AsRegister<Register>(), obj, offset, null_checker); |
| 6372 | if (is_volatile) { |
| 6373 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6374 | } |
| 6375 | // If read barriers are enabled, emit read barriers other than |
| 6376 | // Baker's using a slow path (and also unpoison the loaded |
| 6377 | // reference, if heap poisoning is enabled). |
| 6378 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 6379 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6380 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6381 | Register dst; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6382 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6383 | DCHECK(dst_loc.IsRegisterPair()); |
| 6384 | dst = dst_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6385 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6386 | DCHECK(dst_loc.IsRegister()); |
| 6387 | dst = dst_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6388 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6389 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6390 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6391 | DCHECK(dst_loc.IsFpuRegister()); |
| 6392 | FRegister dst = dst_loc.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6393 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6394 | __ LoadSFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6395 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6396 | __ LoadDFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6397 | } |
| 6398 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6399 | } |
| 6400 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6401 | // Memory barriers, in the case of references, are handled in the |
| 6402 | // previous switch statement. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6403 | if (is_volatile && (type != DataType::Type::kReference)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6404 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6405 | } |
| 6406 | } |
| 6407 | |
| 6408 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6409 | DataType::Type field_type = field_info.GetFieldType(); |
| 6410 | 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] | 6411 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6412 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6413 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6414 | |
| 6415 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6416 | if (generate_volatile) { |
| 6417 | InvokeRuntimeCallingConvention calling_convention; |
| 6418 | // need A0 to hold base + offset |
| 6419 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6420 | if (field_type == DataType::Type::kInt64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6421 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 6422 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 6423 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6424 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 6425 | locations->SetInAt(1, Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6426 | // Pass FP parameters in core registers. |
| 6427 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 6428 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 6429 | } |
| 6430 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6431 | if (DataType::IsFloatingPointType(field_type)) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6432 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6433 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6434 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6435 | } |
| 6436 | } |
| 6437 | } |
| 6438 | |
| 6439 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, |
| 6440 | const FieldInfo& field_info, |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6441 | uint32_t dex_pc, |
| 6442 | bool value_can_be_null) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6443 | DataType::Type type = field_info.GetFieldType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6444 | LocationSummary* locations = instruction->GetLocations(); |
| 6445 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6446 | Location value_location = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6447 | StoreOperandType store_type = kStoreByte; |
| 6448 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6449 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6450 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 6451 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6452 | |
| 6453 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6454 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6455 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6456 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6457 | store_type = kStoreByte; |
| 6458 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6459 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6460 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6461 | store_type = kStoreHalfword; |
| 6462 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6463 | case DataType::Type::kInt32: |
| 6464 | case DataType::Type::kFloat32: |
| 6465 | case DataType::Type::kReference: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6466 | store_type = kStoreWord; |
| 6467 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6468 | case DataType::Type::kInt64: |
| 6469 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6470 | store_type = kStoreDoubleword; |
| 6471 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6472 | case DataType::Type::kVoid: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6473 | LOG(FATAL) << "Unreachable type " << type; |
| 6474 | UNREACHABLE(); |
| 6475 | } |
| 6476 | |
| 6477 | if (is_volatile) { |
| 6478 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 6479 | } |
| 6480 | |
| 6481 | if (is_volatile && store_type == kStoreDoubleword) { |
| 6482 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 6483 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6484 | // Do implicit Null check. |
Goran Jakovljevic | 2e61a57 | 2017-10-23 08:58:15 +0200 | [diff] [blame] | 6485 | __ LoadFromOffset(kLoadWord, |
| 6486 | ZERO, |
| 6487 | locations->GetTemp(0).AsRegister<Register>(), |
| 6488 | 0, |
| 6489 | null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6490 | if (type == DataType::Type::kFloat64) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6491 | // Pass FP parameters in core registers. |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6492 | if (value_location.IsFpuRegister()) { |
| 6493 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), |
| 6494 | value_location.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6495 | __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6496 | value_location.AsFpuRegister<FRegister>()); |
| 6497 | } else if (value_location.IsDoubleStackSlot()) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6498 | __ LoadFromOffset(kLoadWord, |
| 6499 | locations->GetTemp(1).AsRegister<Register>(), |
| 6500 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6501 | value_location.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6502 | __ LoadFromOffset(kLoadWord, |
| 6503 | locations->GetTemp(2).AsRegister<Register>(), |
| 6504 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6505 | value_location.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6506 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6507 | DCHECK(value_location.IsConstant()); |
| 6508 | DCHECK(value_location.GetConstant()->IsDoubleConstant()); |
| 6509 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6510 | __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(), |
| 6511 | locations->GetTemp(1).AsRegister<Register>(), |
| 6512 | value); |
| 6513 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6514 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6515 | codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6516 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); |
| 6517 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6518 | if (value_location.IsConstant()) { |
| 6519 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 6520 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6521 | } else if (!DataType::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6522 | Register src; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6523 | if (type == DataType::Type::kInt64) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6524 | src = value_location.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6525 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6526 | src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6527 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6528 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 6529 | // Note that in the case where `value` is a null reference, |
| 6530 | // we do not enter this block, as a null reference does not |
| 6531 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6532 | DCHECK_EQ(type, DataType::Type::kReference); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6533 | __ PoisonHeapReference(TMP, src); |
| 6534 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 6535 | } else { |
| 6536 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 6537 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6538 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6539 | FRegister src = value_location.AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6540 | if (type == DataType::Type::kFloat32) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6541 | __ StoreSToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6542 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6543 | __ StoreDToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6544 | } |
| 6545 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6546 | } |
| 6547 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6548 | if (needs_write_barrier) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6549 | Register src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6550 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6551 | } |
| 6552 | |
| 6553 | if (is_volatile) { |
| 6554 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 6555 | } |
| 6556 | } |
| 6557 | |
| 6558 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6559 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6560 | } |
| 6561 | |
| 6562 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6563 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 6564 | } |
| 6565 | |
| 6566 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6567 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6568 | } |
| 6569 | |
| 6570 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6571 | HandleFieldSet(instruction, |
| 6572 | instruction->GetFieldInfo(), |
| 6573 | instruction->GetDexPc(), |
| 6574 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6575 | } |
| 6576 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6577 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadOneRegister( |
| 6578 | HInstruction* instruction, |
| 6579 | Location out, |
| 6580 | uint32_t offset, |
| 6581 | Location maybe_temp, |
| 6582 | ReadBarrierOption read_barrier_option) { |
| 6583 | Register out_reg = out.AsRegister<Register>(); |
| 6584 | if (read_barrier_option == kWithReadBarrier) { |
| 6585 | CHECK(kEmitCompilerReadBarrier); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6586 | if (!kUseBakerReadBarrier || !kBakerReadBarrierThunksEnableForFields) { |
| 6587 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6588 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6589 | if (kUseBakerReadBarrier) { |
| 6590 | // Load with fast path based Baker's read barrier. |
| 6591 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6592 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6593 | out, |
| 6594 | out_reg, |
| 6595 | offset, |
| 6596 | maybe_temp, |
| 6597 | /* needs_null_check */ false); |
| 6598 | } else { |
| 6599 | // Load with slow path based read barrier. |
| 6600 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6601 | // in the following move operation, as we will need it for the |
| 6602 | // read barrier below. |
| 6603 | __ Move(maybe_temp.AsRegister<Register>(), out_reg); |
| 6604 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6605 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6606 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6607 | } |
| 6608 | } else { |
| 6609 | // Plain load with no read barrier. |
| 6610 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6611 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6612 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6613 | } |
| 6614 | } |
| 6615 | |
| 6616 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadTwoRegisters( |
| 6617 | HInstruction* instruction, |
| 6618 | Location out, |
| 6619 | Location obj, |
| 6620 | uint32_t offset, |
| 6621 | Location maybe_temp, |
| 6622 | ReadBarrierOption read_barrier_option) { |
| 6623 | Register out_reg = out.AsRegister<Register>(); |
| 6624 | Register obj_reg = obj.AsRegister<Register>(); |
| 6625 | if (read_barrier_option == kWithReadBarrier) { |
| 6626 | CHECK(kEmitCompilerReadBarrier); |
| 6627 | if (kUseBakerReadBarrier) { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6628 | if (!kBakerReadBarrierThunksEnableForFields) { |
| 6629 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6630 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6631 | // Load with fast path based Baker's read barrier. |
| 6632 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6633 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6634 | out, |
| 6635 | obj_reg, |
| 6636 | offset, |
| 6637 | maybe_temp, |
| 6638 | /* needs_null_check */ false); |
| 6639 | } else { |
| 6640 | // Load with slow path based read barrier. |
| 6641 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6642 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6643 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6644 | } |
| 6645 | } else { |
| 6646 | // Plain load with no read barrier. |
| 6647 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6648 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6649 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6650 | } |
| 6651 | } |
| 6652 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6653 | static inline int GetBakerMarkThunkNumber(Register reg) { |
| 6654 | static_assert(BAKER_MARK_INTROSPECTION_REGISTER_COUNT == 21, "Expecting equal"); |
| 6655 | if (reg >= V0 && reg <= T7) { // 14 consequtive regs. |
| 6656 | return reg - V0; |
| 6657 | } else if (reg >= S2 && reg <= S7) { // 6 consequtive regs. |
| 6658 | return 14 + (reg - S2); |
| 6659 | } else if (reg == FP) { // One more. |
| 6660 | return 20; |
| 6661 | } |
| 6662 | LOG(FATAL) << "Unexpected register " << reg; |
| 6663 | UNREACHABLE(); |
| 6664 | } |
| 6665 | |
| 6666 | static inline int GetBakerMarkFieldArrayThunkDisplacement(Register reg, bool short_offset) { |
| 6667 | int num = GetBakerMarkThunkNumber(reg) + |
| 6668 | (short_offset ? BAKER_MARK_INTROSPECTION_REGISTER_COUNT : 0); |
| 6669 | return num * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE; |
| 6670 | } |
| 6671 | |
| 6672 | static inline int GetBakerMarkGcRootThunkDisplacement(Register reg) { |
| 6673 | return GetBakerMarkThunkNumber(reg) * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE + |
| 6674 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET; |
| 6675 | } |
| 6676 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6677 | void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6678 | Location root, |
| 6679 | Register obj, |
| 6680 | uint32_t offset, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6681 | ReadBarrierOption read_barrier_option, |
| 6682 | MipsLabel* label_low) { |
| 6683 | bool reordering; |
| 6684 | if (label_low != nullptr) { |
| 6685 | DCHECK_EQ(offset, 0x5678u); |
| 6686 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6687 | Register root_reg = root.AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6688 | if (read_barrier_option == kWithReadBarrier) { |
| 6689 | DCHECK(kEmitCompilerReadBarrier); |
| 6690 | if (kUseBakerReadBarrier) { |
| 6691 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6692 | // Baker's read barrier are used: |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6693 | if (kBakerReadBarrierThunksEnableForGcRoots) { |
| 6694 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6695 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 6696 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 6697 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 6698 | // vice versa. |
| 6699 | // |
| 6700 | // We use thunks for the slow path. That thunk checks the reference |
| 6701 | // and jumps to the entrypoint if needed. |
| 6702 | // |
| 6703 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 6704 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 6705 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6706 | // if (temp != nullptr) { |
| 6707 | // temp = &gc_root_thunk<root_reg> |
| 6708 | // root = temp(root) |
| 6709 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6710 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6711 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 6712 | const int32_t entry_point_offset = |
| 6713 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 6714 | const int thunk_disp = GetBakerMarkGcRootThunkDisplacement(root_reg); |
| 6715 | int16_t offset_low = Low16Bits(offset); |
| 6716 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign |
| 6717 | // extension in lw. |
| 6718 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 6719 | Register base = short_offset ? obj : TMP; |
| 6720 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6721 | // threads are suspended or running a checkpoint. |
| 6722 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 6723 | reordering = __ SetReorder(false); |
| 6724 | if (!short_offset) { |
| 6725 | DCHECK(!label_low); |
| 6726 | __ AddUpper(base, obj, offset_high); |
| 6727 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6728 | MipsLabel skip_call; |
| 6729 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6730 | if (label_low != nullptr) { |
| 6731 | DCHECK(short_offset); |
| 6732 | __ Bind(label_low); |
| 6733 | } |
| 6734 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6735 | __ LoadFromOffset(kLoadWord, root_reg, base, offset_low); // Single instruction |
| 6736 | // in delay slot. |
| 6737 | if (isR6) { |
| 6738 | __ Jialc(T9, thunk_disp); |
| 6739 | } else { |
| 6740 | __ Addiu(T9, T9, thunk_disp); |
| 6741 | __ Jalr(T9); |
| 6742 | __ Nop(); |
| 6743 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6744 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6745 | __ SetReorder(reordering); |
| 6746 | } else { |
| 6747 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6748 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 6749 | // load into `temp` (T9) the read barrier mark entry point corresponding |
| 6750 | // to register `root`. If `temp` is null, it means that `GetIsGcMarking()` |
| 6751 | // is false, and vice versa. |
| 6752 | // |
| 6753 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6754 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6755 | // if (temp != null) { |
| 6756 | // root = temp(root) |
| 6757 | // } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6758 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6759 | if (label_low != nullptr) { |
| 6760 | reordering = __ SetReorder(false); |
| 6761 | __ Bind(label_low); |
| 6762 | } |
| 6763 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6764 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6765 | if (label_low != nullptr) { |
| 6766 | __ SetReorder(reordering); |
| 6767 | } |
| 6768 | static_assert( |
| 6769 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6770 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6771 | "have different sizes."); |
| 6772 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6773 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6774 | "have different sizes."); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6775 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6776 | // Slow path marking the GC root `root`. |
| 6777 | Location temp = Location::RegisterLocation(T9); |
| 6778 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6779 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS( |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6780 | instruction, |
| 6781 | root, |
| 6782 | /*entrypoint*/ temp); |
| 6783 | codegen_->AddSlowPath(slow_path); |
| 6784 | |
| 6785 | const int32_t entry_point_offset = |
| 6786 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(root.reg() - 1); |
| 6787 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6788 | // threads are suspended or running a checkpoint. |
| 6789 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 6790 | __ Bnez(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 6791 | __ Bind(slow_path->GetExitLabel()); |
| 6792 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6793 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6794 | if (label_low != nullptr) { |
| 6795 | reordering = __ SetReorder(false); |
| 6796 | __ Bind(label_low); |
| 6797 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6798 | // GC root loaded through a slow path for read barriers other |
| 6799 | // than Baker's. |
| 6800 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6801 | __ Addiu32(root_reg, obj, offset); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6802 | if (label_low != nullptr) { |
| 6803 | __ SetReorder(reordering); |
| 6804 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6805 | // /* mirror::Object* */ root = root->Read() |
| 6806 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6807 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6808 | } else { |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6809 | if (label_low != nullptr) { |
| 6810 | reordering = __ SetReorder(false); |
| 6811 | __ Bind(label_low); |
| 6812 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6813 | // Plain GC root load with no read barrier. |
| 6814 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6815 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6816 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6817 | // do not have to unpoison `root_reg` here. |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6818 | if (label_low != nullptr) { |
| 6819 | __ SetReorder(reordering); |
| 6820 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6821 | } |
| 6822 | } |
| 6823 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6824 | void CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6825 | Location ref, |
| 6826 | Register obj, |
| 6827 | uint32_t offset, |
| 6828 | Location temp, |
| 6829 | bool needs_null_check) { |
| 6830 | DCHECK(kEmitCompilerReadBarrier); |
| 6831 | DCHECK(kUseBakerReadBarrier); |
| 6832 | |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6833 | if (kBakerReadBarrierThunksEnableForFields) { |
| 6834 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6835 | // to decide whether to mark the loaded reference or not. Instead, we |
| 6836 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 6837 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 6838 | // vice versa. |
| 6839 | // |
| 6840 | // We use thunks for the slow path. That thunk checks the reference |
| 6841 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6842 | // it issues a load-load memory barrier and returns to the original |
| 6843 | // reference load. |
| 6844 | // |
| 6845 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 6846 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 6847 | // if (temp != nullptr) { |
| 6848 | // temp = &field_array_thunk<holder_reg> |
| 6849 | // temp() |
| 6850 | // } |
| 6851 | // not_gray_return_address: |
| 6852 | // // If the offset is too large to fit into the lw instruction, we |
| 6853 | // // use an adjusted base register (TMP) here. This register |
| 6854 | // // receives bits 16 ... 31 of the offset before the thunk invocation |
| 6855 | // // and the thunk benefits from it. |
| 6856 | // HeapReference<mirror::Object> reference = *(obj+offset); // Original reference load. |
| 6857 | // gray_return_address: |
| 6858 | |
| 6859 | DCHECK(temp.IsInvalid()); |
| 6860 | bool isR6 = GetInstructionSetFeatures().IsR6(); |
| 6861 | int16_t offset_low = Low16Bits(offset); |
| 6862 | int16_t offset_high = High16Bits(offset - offset_low); // Accounts for sign extension in lw. |
| 6863 | bool short_offset = IsInt<16>(static_cast<int32_t>(offset)); |
| 6864 | bool reordering = __ SetReorder(false); |
| 6865 | const int32_t entry_point_offset = |
| 6866 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 6867 | // There may have or may have not been a null check if the field offset is smaller than |
| 6868 | // the page size. |
| 6869 | // There must've been a null check in case it's actually a load from an array. |
| 6870 | // We will, however, perform an explicit null check in the thunk as it's easier to |
| 6871 | // do it than not. |
| 6872 | if (instruction->IsArrayGet()) { |
| 6873 | DCHECK(!needs_null_check); |
| 6874 | } |
| 6875 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, short_offset); |
| 6876 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6877 | // threads are suspended or running a checkpoint. |
| 6878 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 6879 | Register ref_reg = ref.AsRegister<Register>(); |
| 6880 | Register base = short_offset ? obj : TMP; |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6881 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6882 | if (short_offset) { |
| 6883 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6884 | __ Beqzc(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6885 | __ Nop(); // In forbidden slot. |
| 6886 | __ Jialc(T9, thunk_disp); |
| 6887 | } else { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6888 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6889 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 6890 | __ Jalr(T9); |
| 6891 | __ Nop(); // In delay slot. |
| 6892 | } |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6893 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6894 | } else { |
| 6895 | if (isR6) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6896 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6897 | __ Aui(base, obj, offset_high); // In delay slot. |
| 6898 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6899 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6900 | } else { |
| 6901 | __ Lui(base, offset_high); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6902 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6903 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 6904 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6905 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6906 | __ Addu(base, base, obj); // In delay slot. |
| 6907 | } |
| 6908 | } |
| 6909 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6910 | __ LoadFromOffset(kLoadWord, ref_reg, base, offset_low); // Single instruction. |
| 6911 | if (needs_null_check) { |
| 6912 | MaybeRecordImplicitNullCheck(instruction); |
| 6913 | } |
| 6914 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6915 | __ SetReorder(reordering); |
| 6916 | return; |
| 6917 | } |
| 6918 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6919 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6920 | Location no_index = Location::NoLocation(); |
| 6921 | ScaleFactor no_scale_factor = TIMES_1; |
| 6922 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6923 | ref, |
| 6924 | obj, |
| 6925 | offset, |
| 6926 | no_index, |
| 6927 | no_scale_factor, |
| 6928 | temp, |
| 6929 | needs_null_check); |
| 6930 | } |
| 6931 | |
| 6932 | void CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6933 | Location ref, |
| 6934 | Register obj, |
| 6935 | uint32_t data_offset, |
| 6936 | Location index, |
| 6937 | Location temp, |
| 6938 | bool needs_null_check) { |
| 6939 | DCHECK(kEmitCompilerReadBarrier); |
| 6940 | DCHECK(kUseBakerReadBarrier); |
| 6941 | |
| 6942 | static_assert( |
| 6943 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6944 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6945 | ScaleFactor scale_factor = TIMES_4; |
| 6946 | |
| 6947 | if (kBakerReadBarrierThunksEnableForArrays) { |
| 6948 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6949 | // to decide whether to mark the loaded reference or not. Instead, we |
| 6950 | // load into `temp` (T9) the read barrier mark introspection entrypoint. |
| 6951 | // If `temp` is null, it means that `GetIsGcMarking()` is false, and |
| 6952 | // vice versa. |
| 6953 | // |
| 6954 | // We use thunks for the slow path. That thunk checks the reference |
| 6955 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6956 | // it issues a load-load memory barrier and returns to the original |
| 6957 | // reference load. |
| 6958 | // |
| 6959 | // temp = Thread::Current()->pReadBarrierMarkReg00 |
| 6960 | // // AKA &art_quick_read_barrier_mark_introspection. |
| 6961 | // if (temp != nullptr) { |
| 6962 | // temp = &field_array_thunk<holder_reg> |
| 6963 | // temp() |
| 6964 | // } |
| 6965 | // not_gray_return_address: |
| 6966 | // // The element address is pre-calculated in the TMP register before the |
| 6967 | // // thunk invocation and the thunk benefits from it. |
| 6968 | // HeapReference<mirror::Object> reference = data[index]; // Original reference load. |
| 6969 | // gray_return_address: |
| 6970 | |
| 6971 | DCHECK(temp.IsInvalid()); |
| 6972 | DCHECK(index.IsValid()); |
| 6973 | bool reordering = __ SetReorder(false); |
| 6974 | const int32_t entry_point_offset = |
| 6975 | Thread::ReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(0); |
| 6976 | // We will not do the explicit null check in the thunk as some form of a null check |
| 6977 | // must've been done earlier. |
| 6978 | DCHECK(!needs_null_check); |
| 6979 | const int thunk_disp = GetBakerMarkFieldArrayThunkDisplacement(obj, /* short_offset */ false); |
| 6980 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6981 | // threads are suspended or running a checkpoint. |
| 6982 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 6983 | Register ref_reg = ref.AsRegister<Register>(); |
| 6984 | Register index_reg = index.IsRegisterPair() |
| 6985 | ? index.AsRegisterPairLow<Register>() |
| 6986 | : index.AsRegister<Register>(); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6987 | MipsLabel skip_call; |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6988 | if (GetInstructionSetFeatures().IsR6()) { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6989 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6990 | __ Lsa(TMP, index_reg, obj, scale_factor); // In delay slot. |
| 6991 | __ Jialc(T9, thunk_disp); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6992 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6993 | } else { |
| 6994 | __ Sll(TMP, index_reg, scale_factor); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6995 | __ Beqz(T9, &skip_call, /* is_bare */ true); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6996 | __ Addiu(T9, T9, thunk_disp); // In delay slot. |
| 6997 | __ Jalr(T9); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 6998 | __ Bind(&skip_call); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 6999 | __ Addu(TMP, TMP, obj); // In delay slot. |
| 7000 | } |
| 7001 | // /* HeapReference<Object> */ ref = *(obj + data_offset + (index << scale_factor)) |
| 7002 | DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))) << data_offset; |
| 7003 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, data_offset); // Single instruction. |
| 7004 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7005 | __ SetReorder(reordering); |
| 7006 | return; |
| 7007 | } |
| 7008 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7009 | // /* HeapReference<Object> */ ref = |
| 7010 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7011 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 7012 | ref, |
| 7013 | obj, |
| 7014 | data_offset, |
| 7015 | index, |
| 7016 | scale_factor, |
| 7017 | temp, |
| 7018 | needs_null_check); |
| 7019 | } |
| 7020 | |
| 7021 | void CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7022 | Location ref, |
| 7023 | Register obj, |
| 7024 | uint32_t offset, |
| 7025 | Location index, |
| 7026 | ScaleFactor scale_factor, |
| 7027 | Location temp, |
| 7028 | bool needs_null_check, |
| 7029 | bool always_update_field) { |
| 7030 | DCHECK(kEmitCompilerReadBarrier); |
| 7031 | DCHECK(kUseBakerReadBarrier); |
| 7032 | |
| 7033 | // In slow path based read barriers, the read barrier call is |
| 7034 | // inserted after the original load. However, in fast path based |
| 7035 | // Baker's read barriers, we need to perform the load of |
| 7036 | // mirror::Object::monitor_ *before* the original reference load. |
| 7037 | // This load-load ordering is required by the read barrier. |
| 7038 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7039 | // |
| 7040 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7041 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7042 | // HeapReference<Object> ref = *src; // Original reference load. |
| 7043 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 7044 | // if (is_gray) { |
| 7045 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7046 | // } |
| 7047 | // |
| 7048 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7049 | // slightly more complex as it performs additional checks that we do |
| 7050 | // not do here for performance reasons. |
| 7051 | |
| 7052 | Register ref_reg = ref.AsRegister<Register>(); |
| 7053 | Register temp_reg = temp.AsRegister<Register>(); |
| 7054 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7055 | |
| 7056 | // /* int32_t */ monitor = obj->monitor_ |
| 7057 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 7058 | if (needs_null_check) { |
| 7059 | MaybeRecordImplicitNullCheck(instruction); |
| 7060 | } |
| 7061 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7062 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7063 | "art::LockWord and int32_t have different sizes."); |
| 7064 | |
| 7065 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 7066 | |
| 7067 | // The actual reference load. |
| 7068 | if (index.IsValid()) { |
| 7069 | // Load types involving an "index": ArrayGet, |
| 7070 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7071 | // intrinsics. |
| 7072 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 7073 | if (index.IsConstant()) { |
| 7074 | size_t computed_offset = |
| 7075 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 7076 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7077 | } else { |
| 7078 | // Handle the special case of the |
| 7079 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7080 | // intrinsics, which use a register pair as index ("long |
| 7081 | // offset"), of which only the low part contains data. |
| 7082 | Register index_reg = index.IsRegisterPair() |
| 7083 | ? index.AsRegisterPairLow<Register>() |
| 7084 | : index.AsRegister<Register>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 7085 | __ ShiftAndAdd(TMP, index_reg, obj, scale_factor, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7086 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, offset); |
| 7087 | } |
| 7088 | } else { |
| 7089 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7090 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7091 | } |
| 7092 | |
| 7093 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7094 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7095 | |
| 7096 | // Slow path marking the object `ref` when it is gray. |
| 7097 | SlowPathCodeMIPS* slow_path; |
| 7098 | if (always_update_field) { |
| 7099 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS only supports address |
| 7100 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7101 | // `field_offset` is a register pair (of which only the lower half |
| 7102 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7103 | // to be null in this code path. |
| 7104 | DCHECK_EQ(offset, 0u); |
| 7105 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7106 | slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7107 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(instruction, |
| 7108 | ref, |
| 7109 | obj, |
| 7110 | /* field_offset */ index, |
| 7111 | temp_reg); |
| 7112 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7113 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathMIPS(instruction, ref); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7114 | } |
| 7115 | AddSlowPath(slow_path); |
| 7116 | |
| 7117 | // if (rb_state == ReadBarrier::GrayState()) |
| 7118 | // ref = ReadBarrier::Mark(ref); |
| 7119 | // Given the numeric representation, it's enough to check the low bit of the |
| 7120 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 7121 | // performing a branch on less than zero. |
| 7122 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7123 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 7124 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 7125 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 7126 | __ Bltz(temp_reg, slow_path->GetEntryLabel()); |
| 7127 | __ Bind(slow_path->GetExitLabel()); |
| 7128 | } |
| 7129 | |
| 7130 | void CodeGeneratorMIPS::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7131 | Location out, |
| 7132 | Location ref, |
| 7133 | Location obj, |
| 7134 | uint32_t offset, |
| 7135 | Location index) { |
| 7136 | DCHECK(kEmitCompilerReadBarrier); |
| 7137 | |
| 7138 | // Insert a slow path based read barrier *after* the reference load. |
| 7139 | // |
| 7140 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7141 | // reference will be carried out by the runtime within the slow |
| 7142 | // path. |
| 7143 | // |
| 7144 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7145 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7146 | // not used by the artReadBarrierSlow entry point. |
| 7147 | // |
| 7148 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7149 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7150 | ReadBarrierForHeapReferenceSlowPathMIPS(instruction, out, ref, obj, offset, index); |
| 7151 | AddSlowPath(slow_path); |
| 7152 | |
| 7153 | __ B(slow_path->GetEntryLabel()); |
| 7154 | __ Bind(slow_path->GetExitLabel()); |
| 7155 | } |
| 7156 | |
| 7157 | void CodeGeneratorMIPS::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7158 | Location out, |
| 7159 | Location ref, |
| 7160 | Location obj, |
| 7161 | uint32_t offset, |
| 7162 | Location index) { |
| 7163 | if (kEmitCompilerReadBarrier) { |
| 7164 | // Baker's read barriers shall be handled by the fast path |
| 7165 | // (CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier). |
| 7166 | DCHECK(!kUseBakerReadBarrier); |
| 7167 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7168 | // by the runtime within the slow path. |
| 7169 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 7170 | } else if (kPoisonHeapReferences) { |
| 7171 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7172 | } |
| 7173 | } |
| 7174 | |
| 7175 | void CodeGeneratorMIPS::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7176 | Location out, |
| 7177 | Location root) { |
| 7178 | DCHECK(kEmitCompilerReadBarrier); |
| 7179 | |
| 7180 | // Insert a slow path based read barrier *after* the GC root load. |
| 7181 | // |
| 7182 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7183 | // not need to do anything special for this here. |
| 7184 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7185 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathMIPS(instruction, out, root); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7186 | AddSlowPath(slow_path); |
| 7187 | |
| 7188 | __ B(slow_path->GetEntryLabel()); |
| 7189 | __ Bind(slow_path->GetExitLabel()); |
| 7190 | } |
| 7191 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7192 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7193 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7194 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7195 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7196 | switch (type_check_kind) { |
| 7197 | case TypeCheckKind::kExactCheck: |
| 7198 | case TypeCheckKind::kAbstractClassCheck: |
| 7199 | case TypeCheckKind::kClassHierarchyCheck: |
| 7200 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7201 | call_kind = |
| 7202 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7203 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7204 | break; |
| 7205 | case TypeCheckKind::kArrayCheck: |
| 7206 | case TypeCheckKind::kUnresolvedCheck: |
| 7207 | case TypeCheckKind::kInterfaceCheck: |
| 7208 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7209 | break; |
| 7210 | } |
| 7211 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7212 | LocationSummary* locations = |
| 7213 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7214 | if (baker_read_barrier_slow_path) { |
| 7215 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7216 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7217 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7218 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7219 | // The output does overlap inputs. |
| 7220 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 7221 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7222 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7223 | } |
| 7224 | |
| 7225 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7226 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7227 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7228 | Location obj_loc = locations->InAt(0); |
| 7229 | Register obj = obj_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7230 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7231 | Location out_loc = locations->Out(); |
| 7232 | Register out = out_loc.AsRegister<Register>(); |
| 7233 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7234 | DCHECK_LE(num_temps, 1u); |
| 7235 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7236 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7237 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7238 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7239 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7240 | MipsLabel done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7241 | SlowPathCodeMIPS* slow_path = nullptr; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7242 | |
| 7243 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7244 | // Avoid this check if we know `obj` is not null. |
| 7245 | if (instruction->MustDoNullCheck()) { |
| 7246 | __ Move(out, ZERO); |
| 7247 | __ Beqz(obj, &done); |
| 7248 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7249 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7250 | switch (type_check_kind) { |
| 7251 | case TypeCheckKind::kExactCheck: { |
| 7252 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7253 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7254 | out_loc, |
| 7255 | obj_loc, |
| 7256 | class_offset, |
| 7257 | maybe_temp_loc, |
| 7258 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7259 | // Classes must be equal for the instanceof to succeed. |
| 7260 | __ Xor(out, out, cls); |
| 7261 | __ Sltiu(out, out, 1); |
| 7262 | break; |
| 7263 | } |
| 7264 | |
| 7265 | case TypeCheckKind::kAbstractClassCheck: { |
| 7266 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7267 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7268 | out_loc, |
| 7269 | obj_loc, |
| 7270 | class_offset, |
| 7271 | maybe_temp_loc, |
| 7272 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7273 | // If the class is abstract, we eagerly fetch the super class of the |
| 7274 | // object to avoid doing a comparison we know will fail. |
| 7275 | MipsLabel loop; |
| 7276 | __ Bind(&loop); |
| 7277 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7278 | GenerateReferenceLoadOneRegister(instruction, |
| 7279 | out_loc, |
| 7280 | super_offset, |
| 7281 | maybe_temp_loc, |
| 7282 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7283 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7284 | __ Beqz(out, &done); |
| 7285 | __ Bne(out, cls, &loop); |
| 7286 | __ LoadConst32(out, 1); |
| 7287 | break; |
| 7288 | } |
| 7289 | |
| 7290 | case TypeCheckKind::kClassHierarchyCheck: { |
| 7291 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7292 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7293 | out_loc, |
| 7294 | obj_loc, |
| 7295 | class_offset, |
| 7296 | maybe_temp_loc, |
| 7297 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7298 | // Walk over the class hierarchy to find a match. |
| 7299 | MipsLabel loop, success; |
| 7300 | __ Bind(&loop); |
| 7301 | __ Beq(out, cls, &success); |
| 7302 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7303 | GenerateReferenceLoadOneRegister(instruction, |
| 7304 | out_loc, |
| 7305 | super_offset, |
| 7306 | maybe_temp_loc, |
| 7307 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7308 | __ Bnez(out, &loop); |
| 7309 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7310 | __ B(&done); |
| 7311 | __ Bind(&success); |
| 7312 | __ LoadConst32(out, 1); |
| 7313 | break; |
| 7314 | } |
| 7315 | |
| 7316 | case TypeCheckKind::kArrayObjectCheck: { |
| 7317 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7318 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7319 | out_loc, |
| 7320 | obj_loc, |
| 7321 | class_offset, |
| 7322 | maybe_temp_loc, |
| 7323 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7324 | // Do an exact check. |
| 7325 | MipsLabel success; |
| 7326 | __ Beq(out, cls, &success); |
| 7327 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7328 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7329 | GenerateReferenceLoadOneRegister(instruction, |
| 7330 | out_loc, |
| 7331 | component_offset, |
| 7332 | maybe_temp_loc, |
| 7333 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7334 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7335 | __ Beqz(out, &done); |
| 7336 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7337 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 7338 | __ Sltiu(out, out, 1); |
| 7339 | __ B(&done); |
| 7340 | __ Bind(&success); |
| 7341 | __ LoadConst32(out, 1); |
| 7342 | break; |
| 7343 | } |
| 7344 | |
| 7345 | case TypeCheckKind::kArrayCheck: { |
| 7346 | // No read barrier since the slow path will retry upon failure. |
| 7347 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7348 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7349 | out_loc, |
| 7350 | obj_loc, |
| 7351 | class_offset, |
| 7352 | maybe_temp_loc, |
| 7353 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7354 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7355 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7356 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7357 | codegen_->AddSlowPath(slow_path); |
| 7358 | __ Bne(out, cls, slow_path->GetEntryLabel()); |
| 7359 | __ LoadConst32(out, 1); |
| 7360 | break; |
| 7361 | } |
| 7362 | |
| 7363 | case TypeCheckKind::kUnresolvedCheck: |
| 7364 | case TypeCheckKind::kInterfaceCheck: { |
| 7365 | // Note that we indeed only call on slow path, but we always go |
| 7366 | // into the slow path for the unresolved and interface check |
| 7367 | // cases. |
| 7368 | // |
| 7369 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7370 | // entry point without resorting to a type checking slow path |
| 7371 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7372 | // require to assign fixed registers for the inputs of this |
| 7373 | // HInstanceOf instruction (following the runtime calling |
| 7374 | // convention), which might be cluttered by the potential first |
| 7375 | // read barrier emission at the beginning of this method. |
| 7376 | // |
| 7377 | // TODO: Introduce a new runtime entry point taking the object |
| 7378 | // to test (instead of its class) as argument, and let it deal |
| 7379 | // with the read barrier issues. This will let us refactor this |
| 7380 | // case of the `switch` code as it was previously (with a direct |
| 7381 | // call to the runtime not using a type checking slow path). |
| 7382 | // This should also be beneficial for the other cases above. |
| 7383 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7384 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( |
| 7385 | instruction, /* is_fatal */ false); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7386 | codegen_->AddSlowPath(slow_path); |
| 7387 | __ B(slow_path->GetEntryLabel()); |
| 7388 | break; |
| 7389 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7390 | } |
| 7391 | |
| 7392 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 7393 | |
| 7394 | if (slow_path != nullptr) { |
| 7395 | __ Bind(slow_path->GetExitLabel()); |
| 7396 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7397 | } |
| 7398 | |
| 7399 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7400 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7401 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7402 | } |
| 7403 | |
| 7404 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 7405 | // Will be generated at use site. |
| 7406 | } |
| 7407 | |
| 7408 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7409 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7410 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7411 | } |
| 7412 | |
| 7413 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 7414 | // Will be generated at use site. |
| 7415 | } |
| 7416 | |
| 7417 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { |
| 7418 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 7419 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 7420 | } |
| 7421 | |
| 7422 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7423 | HandleInvoke(invoke); |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7424 | // 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] | 7425 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 7426 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T7)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7427 | } |
| 7428 | |
| 7429 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 7430 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 7431 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7432 | Location receiver = invoke->GetLocations()->InAt(0); |
| 7433 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7434 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7435 | |
| 7436 | // Set the hidden argument. |
| 7437 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 7438 | invoke->GetDexMethodIndex()); |
| 7439 | |
| 7440 | // temp = object->GetClass(); |
| 7441 | if (receiver.IsStackSlot()) { |
| 7442 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 7443 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 7444 | } else { |
| 7445 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 7446 | } |
| 7447 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7448 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7449 | // emit a read barrier for the previous class reference load. |
| 7450 | // However this is not required in practice, as this is an |
| 7451 | // intermediate/temporary reference and because the current |
| 7452 | // concurrent copying collector keeps the from-space memory |
| 7453 | // intact/accessible until the end of the marking phase (the |
| 7454 | // concurrent copying collector may not in the future). |
| 7455 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 7456 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 7457 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
| 7458 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7459 | invoke->GetImtIndex(), kMipsPointerSize)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7460 | // temp = temp->GetImtEntryAt(method_offset); |
| 7461 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7462 | // T9 = temp->GetEntryPoint(); |
| 7463 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 7464 | // T9(); |
| 7465 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7466 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7467 | DCHECK(!codegen_->IsLeafMethod()); |
| 7468 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 7469 | } |
| 7470 | |
| 7471 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7472 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7473 | if (intrinsic.TryDispatch(invoke)) { |
| 7474 | return; |
| 7475 | } |
| 7476 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7477 | HandleInvoke(invoke); |
| 7478 | } |
| 7479 | |
| 7480 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 7481 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 7482 | // art::PrepareForRegisterAllocation. |
| 7483 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7484 | |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7485 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7486 | bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
| 7487 | bool has_extra_input = invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7488 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7489 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 7490 | if (intrinsic.TryDispatch(invoke)) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7491 | if (invoke->GetLocations()->CanCall() && has_extra_input) { |
| 7492 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 7493 | } |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7494 | return; |
| 7495 | } |
| 7496 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7497 | HandleInvoke(invoke); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7498 | |
| 7499 | // Add the extra input register if either the dex cache array base register |
| 7500 | // or the PC-relative base register for accessing literals is needed. |
| 7501 | if (has_extra_input) { |
| 7502 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 7503 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7504 | } |
| 7505 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 7506 | void LocationsBuilderMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7507 | HandleInvoke(invoke); |
| 7508 | } |
| 7509 | |
| 7510 | void InstructionCodeGeneratorMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 7511 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 7512 | } |
| 7513 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7514 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7515 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 7516 | IntrinsicCodeGeneratorMIPS intrinsic(codegen); |
| 7517 | intrinsic.Dispatch(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7518 | return true; |
| 7519 | } |
| 7520 | return false; |
| 7521 | } |
| 7522 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7523 | HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7524 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7525 | switch (desired_string_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7526 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7527 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7528 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7529 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7530 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7531 | case HLoadString::LoadKind::kJitTableAddress: |
| 7532 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7533 | break; |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7534 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7535 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7536 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7537 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7538 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7539 | } |
| 7540 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7541 | HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind( |
| 7542 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7543 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7544 | case HLoadClass::LoadKind::kInvalid: |
| 7545 | LOG(FATAL) << "UNREACHABLE"; |
| 7546 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7547 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7548 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7549 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7550 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7551 | case HLoadClass::LoadKind::kBssEntry: |
| 7552 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7553 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7554 | case HLoadClass::LoadKind::kJitTableAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7555 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7556 | break; |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7557 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7558 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7559 | break; |
| 7560 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7561 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7562 | } |
| 7563 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7564 | Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7565 | Register temp) { |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7566 | CHECK(!GetInstructionSetFeatures().IsR6()); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7567 | CHECK(!GetGraph()->HasIrreducibleLoops()); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7568 | CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7569 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7570 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7571 | return location.AsRegister<Register>(); |
| 7572 | } |
| 7573 | // For intrinsics we allow any location, so it may be on the stack. |
| 7574 | if (!location.IsRegister()) { |
| 7575 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7576 | return temp; |
| 7577 | } |
| 7578 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7579 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7580 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7581 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7582 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 7583 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 7584 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 7585 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7586 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7587 | return temp; |
| 7588 | } |
| 7589 | return location.AsRegister<Register>(); |
| 7590 | } |
| 7591 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7592 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( |
| 7593 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 7594 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7595 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7596 | } |
| 7597 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7598 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall( |
| 7599 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7600 | // 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] | 7601 | 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] | 7602 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 7603 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7604 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7605 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 7606 | Register base_reg = (invoke->HasPcRelativeMethodLoadKind() && !is_r6 && !has_irreducible_loops) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7607 | ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>()) |
| 7608 | : ZERO; |
| 7609 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7610 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7611 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7612 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7613 | uint32_t offset = |
| 7614 | GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7615 | __ LoadFromOffset(kLoadWord, |
| 7616 | temp.AsRegister<Register>(), |
| 7617 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7618 | offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7619 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7620 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7621 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7622 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7623 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7624 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 7625 | DCHECK(GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7626 | PcRelativePatchInfo* info_high = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 7627 | PcRelativePatchInfo* info_low = |
| 7628 | NewPcRelativeMethodPatch(invoke->GetTargetMethod(), info_high); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7629 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7630 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 7631 | __ Addiu(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 7632 | break; |
| 7633 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7634 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7635 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 7636 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7637 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7638 | PcRelativePatchInfo* info_high = NewMethodBssEntryPatch( |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7639 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7640 | PcRelativePatchInfo* info_low = NewMethodBssEntryPatch( |
| 7641 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()), info_high); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7642 | Register temp_reg = temp.AsRegister<Register>(); |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7643 | EmitPcRelativeAddressPlaceholderHigh(info_high, TMP, base_reg); |
| 7644 | __ Lw(temp_reg, TMP, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7645 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 7646 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7647 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 7648 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 7649 | return; // No code pointer retrieval; the runtime performs the call directly. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7650 | } |
| 7651 | } |
| 7652 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7653 | switch (code_ptr_location) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7654 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7655 | __ Bal(&frame_entry_label_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7656 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7657 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7658 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 7659 | __ LoadFromOffset(kLoadWord, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7660 | T9, |
| 7661 | callee_method.AsRegister<Register>(), |
| 7662 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7663 | kMipsPointerSize).Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7664 | // T9() |
| 7665 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7666 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7667 | break; |
| 7668 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7669 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 7670 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7671 | DCHECK(!IsLeafMethod()); |
| 7672 | } |
| 7673 | |
| 7674 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 7675 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 7676 | // art::PrepareForRegisterAllocation. |
| 7677 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7678 | |
| 7679 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 7680 | return; |
| 7681 | } |
| 7682 | |
| 7683 | LocationSummary* locations = invoke->GetLocations(); |
| 7684 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 7685 | locations->HasTemps() |
| 7686 | ? locations->GetTemp(0) |
| 7687 | : Location::NoLocation()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7688 | } |
| 7689 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7690 | void CodeGeneratorMIPS::GenerateVirtualCall( |
| 7691 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 7692 | // Use the calling convention instead of the location of the receiver, as |
| 7693 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7694 | // slow path, the arguments have been moved to the right place, so here we are |
| 7695 | // guaranteed that the receiver is the first register of the calling convention. |
| 7696 | InvokeDexCallingConvention calling_convention; |
| 7697 | Register receiver = calling_convention.GetRegisterAt(0); |
| 7698 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7699 | Register temp = temp_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7700 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7701 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); |
| 7702 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7703 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7704 | |
| 7705 | // temp = object->GetClass(); |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 7706 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7707 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7708 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7709 | // emit a read barrier for the previous class reference load. |
| 7710 | // However this is not required in practice, as this is an |
| 7711 | // intermediate/temporary reference and because the current |
| 7712 | // concurrent copying collector keeps the from-space memory |
| 7713 | // intact/accessible until the end of the marking phase (the |
| 7714 | // concurrent copying collector may not in the future). |
| 7715 | __ MaybeUnpoisonHeapReference(temp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7716 | // temp = temp->GetMethodAt(method_offset); |
| 7717 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7718 | // T9 = temp->GetEntryPoint(); |
| 7719 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 7720 | // T9(); |
| 7721 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7722 | __ NopIfNoReordering(); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 7723 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7724 | } |
| 7725 | |
| 7726 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 7727 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 7728 | return; |
| 7729 | } |
| 7730 | |
| 7731 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7732 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7733 | } |
| 7734 | |
| 7735 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7736 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7737 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7738 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7739 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 7740 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7741 | return; |
| 7742 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7743 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7744 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7745 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7746 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7747 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7748 | ? LocationSummary::kCallOnSlowPath |
| 7749 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7750 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7751 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 7752 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7753 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7754 | switch (load_kind) { |
| 7755 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7756 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7757 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7758 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7759 | case HLoadClass::LoadKind::kBssEntry: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7760 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7761 | break; |
| 7762 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7763 | if (has_irreducible_loops) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 7764 | if (load_kind != HLoadClass::LoadKind::kBootImageAddress) { |
| 7765 | codegen_->ClobberRA(); |
| 7766 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7767 | break; |
| 7768 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7769 | FALLTHROUGH_INTENDED; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7770 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7771 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7772 | break; |
| 7773 | default: |
| 7774 | break; |
| 7775 | } |
| 7776 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7777 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7778 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7779 | // 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] | 7780 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7781 | InvokeRuntimeCallingConvention calling_convention; |
| 7782 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7783 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 7784 | } else { |
| 7785 | // For non-Baker read barriers we have a temp-clobbering call. |
| 7786 | } |
| 7787 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7788 | } |
| 7789 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7790 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7791 | // move. |
| 7792 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7793 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7794 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7795 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 7796 | return; |
| 7797 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7798 | DCHECK(!cls->NeedsAccessCheck()); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 7799 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7800 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7801 | Location out_loc = locations->Out(); |
| 7802 | Register out = out_loc.AsRegister<Register>(); |
| 7803 | Register base_or_current_method_reg; |
| 7804 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7805 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7806 | switch (load_kind) { |
| 7807 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7808 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7809 | case HLoadClass::LoadKind::kBootImageAddress: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7810 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7811 | case HLoadClass::LoadKind::kBssEntry: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7812 | base_or_current_method_reg = |
| 7813 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7814 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7815 | case HLoadClass::LoadKind::kReferrersClass: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7816 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7817 | base_or_current_method_reg = locations->InAt(0).AsRegister<Register>(); |
| 7818 | break; |
| 7819 | default: |
| 7820 | base_or_current_method_reg = ZERO; |
| 7821 | break; |
| 7822 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 7823 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7824 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7825 | ? kWithoutReadBarrier |
| 7826 | : kCompilerReadBarrierOption; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7827 | bool generate_null_check = false; |
| 7828 | switch (load_kind) { |
| 7829 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7830 | DCHECK(!cls->CanCallRuntime()); |
| 7831 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7832 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7833 | GenerateGcRootFieldLoad(cls, |
| 7834 | out_loc, |
| 7835 | base_or_current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7836 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 7837 | read_barrier_option); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7838 | break; |
| 7839 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7840 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7841 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7842 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7843 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7844 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7845 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 7846 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7847 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 7848 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 7849 | base_or_current_method_reg); |
| 7850 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7851 | break; |
| 7852 | } |
| 7853 | case HLoadClass::LoadKind::kBootImageAddress: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7854 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7855 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7856 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 7857 | DCHECK_NE(address, 0u); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7858 | if (isR6 || !has_irreducible_loops) { |
| 7859 | __ LoadLiteral(out, |
| 7860 | base_or_current_method_reg, |
| 7861 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7862 | } else { |
| 7863 | __ LoadConst32(out, address); |
| 7864 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7865 | break; |
| 7866 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7867 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 7868 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7869 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
| 7870 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 7871 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 7872 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex(), info_high); |
| 7873 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 7874 | out, |
| 7875 | base_or_current_method_reg); |
| 7876 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
| 7877 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 7878 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 7879 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 7880 | if (masked_hash != 0) { |
| 7881 | __ Addiu(out, out, -masked_hash); |
| 7882 | } |
| 7883 | break; |
| 7884 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7885 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7886 | CodeGeneratorMIPS::PcRelativePatchInfo* bss_info_high = |
| 7887 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7888 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 7889 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex(), bss_info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 7890 | codegen_->EmitPcRelativeAddressPlaceholderHigh(bss_info_high, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7891 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7892 | base_or_current_method_reg); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7893 | GenerateGcRootFieldLoad(cls, |
| 7894 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7895 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7896 | /* placeholder */ 0x5678, |
| 7897 | read_barrier_option, |
| 7898 | &info_low->label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7899 | generate_null_check = true; |
| 7900 | break; |
| 7901 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7902 | case HLoadClass::LoadKind::kJitTableAddress: { |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 7903 | CodeGeneratorMIPS::JitPatchInfo* info = codegen_->NewJitRootClassPatch(cls->GetDexFile(), |
| 7904 | cls->GetTypeIndex(), |
| 7905 | cls->GetClass()); |
| 7906 | bool reordering = __ SetReorder(false); |
| 7907 | __ Bind(&info->high_label); |
| 7908 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 7909 | __ SetReorder(reordering); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 7910 | GenerateGcRootFieldLoad(cls, |
| 7911 | out_loc, |
| 7912 | out, |
| 7913 | /* placeholder */ 0x5678, |
| 7914 | read_barrier_option, |
| 7915 | &info->low_label); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7916 | break; |
| 7917 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7918 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7919 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7920 | LOG(FATAL) << "UNREACHABLE"; |
| 7921 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7922 | } |
| 7923 | |
| 7924 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7925 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7926 | SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathMIPS( |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7927 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7928 | codegen_->AddSlowPath(slow_path); |
| 7929 | if (generate_null_check) { |
| 7930 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 7931 | } |
| 7932 | if (cls->MustGenerateClinitCheck()) { |
| 7933 | GenerateClassInitializationCheck(slow_path, out); |
| 7934 | } else { |
| 7935 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7936 | } |
| 7937 | } |
| 7938 | } |
| 7939 | |
| 7940 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7941 | return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7942 | } |
| 7943 | |
| 7944 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { |
| 7945 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7946 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7947 | locations->SetOut(Location::RequiresRegister()); |
| 7948 | } |
| 7949 | |
| 7950 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { |
| 7951 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
| 7952 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 7953 | } |
| 7954 | |
| 7955 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7956 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7957 | } |
| 7958 | |
| 7959 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7960 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
| 7961 | } |
| 7962 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7963 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 7964 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7965 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7966 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7967 | const bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7968 | const bool has_irreducible_loops = codegen_->GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7969 | switch (load_kind) { |
| 7970 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7971 | case HLoadString::LoadKind::kBootImageAddress: |
| 7972 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7973 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7974 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7975 | if (isR6) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7976 | break; |
| 7977 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7978 | if (has_irreducible_loops) { |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 7979 | if (load_kind != HLoadString::LoadKind::kBootImageAddress) { |
| 7980 | codegen_->ClobberRA(); |
| 7981 | } |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 7982 | break; |
| 7983 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7984 | FALLTHROUGH_INTENDED; |
| 7985 | // We need an extra register for PC-relative dex cache accesses. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7986 | case HLoadString::LoadKind::kRuntimeCall: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7987 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7988 | break; |
| 7989 | default: |
| 7990 | break; |
| 7991 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7992 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 7993 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7994 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 7995 | } else { |
| 7996 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 7997 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7998 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7999 | // Rely on the pResolveString and marking to save everything we need. |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8000 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 8001 | InvokeRuntimeCallingConvention calling_convention; |
| 8002 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8003 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 8004 | } else { |
| 8005 | // For non-Baker read barriers we have a temp-clobbering call. |
| 8006 | } |
| 8007 | } |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 8008 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8009 | } |
| 8010 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8011 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 8012 | // move. |
| 8013 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8014 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8015 | LocationSummary* locations = load->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8016 | Location out_loc = locations->Out(); |
| 8017 | Register out = out_loc.AsRegister<Register>(); |
| 8018 | Register base_or_current_method_reg; |
| 8019 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8020 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8021 | switch (load_kind) { |
| 8022 | // We need an extra register for PC-relative literals on R2. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8023 | case HLoadString::LoadKind::kBootImageAddress: |
| 8024 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8025 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8026 | case HLoadString::LoadKind::kBssEntry: |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8027 | base_or_current_method_reg = |
| 8028 | (isR6 || has_irreducible_loops) ? ZERO : locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8029 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8030 | default: |
| 8031 | base_or_current_method_reg = ZERO; |
| 8032 | break; |
| 8033 | } |
| 8034 | |
| 8035 | switch (load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8036 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8037 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8038 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8039 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8040 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8041 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8042 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8043 | out, |
Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 8044 | base_or_current_method_reg); |
| 8045 | __ Addiu(out, out, /* placeholder */ 0x5678, &info_low->label); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8046 | return; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8047 | } |
| 8048 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8049 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 8050 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 8051 | DCHECK_NE(address, 0u); |
Goran Jakovljevic | debb510 | 2017-09-21 14:24:06 +0200 | [diff] [blame] | 8052 | if (isR6 || !has_irreducible_loops) { |
| 8053 | __ LoadLiteral(out, |
| 8054 | base_or_current_method_reg, |
| 8055 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 8056 | } else { |
| 8057 | __ LoadConst32(out, address); |
| 8058 | } |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8059 | return; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8060 | } |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8061 | case HLoadString::LoadKind::kBootImageInternTable: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8062 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8063 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8064 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8065 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8066 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 8067 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
| 8068 | out, |
| 8069 | base_or_current_method_reg); |
| 8070 | __ Lw(out, out, /* placeholder */ 0x5678, &info_low->label); |
| 8071 | return; |
| 8072 | } |
| 8073 | case HLoadString::LoadKind::kBssEntry: { |
| 8074 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 8075 | CodeGeneratorMIPS::PcRelativePatchInfo* info_high = |
| 8076 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| 8077 | CodeGeneratorMIPS::PcRelativePatchInfo* info_low = |
| 8078 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex(), info_high); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8079 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info_high, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8080 | out, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8081 | base_or_current_method_reg); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8082 | GenerateGcRootFieldLoad(load, |
| 8083 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8084 | out, |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8085 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8086 | kCompilerReadBarrierOption, |
| 8087 | &info_low->label); |
Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 8088 | SlowPathCodeMIPS* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 8089 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathMIPS(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8090 | codegen_->AddSlowPath(slow_path); |
| 8091 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 8092 | __ Bind(slow_path->GetExitLabel()); |
| 8093 | return; |
| 8094 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8095 | case HLoadString::LoadKind::kJitTableAddress: { |
| 8096 | CodeGeneratorMIPS::JitPatchInfo* info = |
| 8097 | codegen_->NewJitRootStringPatch(load->GetDexFile(), |
| 8098 | load->GetStringIndex(), |
| 8099 | load->GetString()); |
| 8100 | bool reordering = __ SetReorder(false); |
| 8101 | __ Bind(&info->high_label); |
| 8102 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8103 | __ SetReorder(reordering); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 8104 | GenerateGcRootFieldLoad(load, |
| 8105 | out_loc, |
| 8106 | out, |
| 8107 | /* placeholder */ 0x5678, |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 8108 | kCompilerReadBarrierOption, |
| 8109 | &info->low_label); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 8110 | return; |
| 8111 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8112 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8113 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8114 | } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 8115 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 8116 | // 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] | 8117 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8118 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 8119 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8120 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8121 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 8122 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8123 | } |
| 8124 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8125 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8126 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8127 | locations->SetOut(Location::ConstantLocation(constant)); |
| 8128 | } |
| 8129 | |
| 8130 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 8131 | // Will be generated at use site. |
| 8132 | } |
| 8133 | |
| 8134 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8135 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8136 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8137 | InvokeRuntimeCallingConvention calling_convention; |
| 8138 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8139 | } |
| 8140 | |
| 8141 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8142 | if (instruction->IsEnter()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8143 | codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8144 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8145 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8146 | codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8147 | } |
| 8148 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8149 | } |
| 8150 | |
| 8151 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { |
| 8152 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8153 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8154 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8155 | case DataType::Type::kInt32: |
| 8156 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8157 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8158 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8159 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8160 | break; |
| 8161 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8162 | case DataType::Type::kFloat32: |
| 8163 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8164 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8165 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 8166 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8167 | break; |
| 8168 | |
| 8169 | default: |
| 8170 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 8171 | } |
| 8172 | } |
| 8173 | |
| 8174 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8175 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8176 | LocationSummary* locations = instruction->GetLocations(); |
| 8177 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 8178 | |
| 8179 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8180 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8181 | Register dst = locations->Out().AsRegister<Register>(); |
| 8182 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 8183 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 8184 | |
| 8185 | if (isR6) { |
| 8186 | __ MulR6(dst, lhs, rhs); |
| 8187 | } else { |
| 8188 | __ MulR2(dst, lhs, rhs); |
| 8189 | } |
| 8190 | break; |
| 8191 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8192 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8193 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8194 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8195 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8196 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8197 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 8198 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 8199 | |
| 8200 | // Extra checks to protect caused by the existance of A1_A2. |
| 8201 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: |
| 8202 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). |
| 8203 | DCHECK_NE(dst_high, lhs_low); |
| 8204 | DCHECK_NE(dst_high, rhs_low); |
| 8205 | |
| 8206 | // A_B * C_D |
| 8207 | // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ] |
| 8208 | // dst_lo: [ low(B*D) ] |
| 8209 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. |
| 8210 | |
| 8211 | if (isR6) { |
| 8212 | __ MulR6(TMP, lhs_high, rhs_low); |
| 8213 | __ MulR6(dst_high, lhs_low, rhs_high); |
| 8214 | __ Addu(dst_high, dst_high, TMP); |
| 8215 | __ MuhuR6(TMP, lhs_low, rhs_low); |
| 8216 | __ Addu(dst_high, dst_high, TMP); |
| 8217 | __ MulR6(dst_low, lhs_low, rhs_low); |
| 8218 | } else { |
| 8219 | __ MulR2(TMP, lhs_high, rhs_low); |
| 8220 | __ MulR2(dst_high, lhs_low, rhs_high); |
| 8221 | __ Addu(dst_high, dst_high, TMP); |
| 8222 | __ MultuR2(lhs_low, rhs_low); |
| 8223 | __ Mfhi(TMP); |
| 8224 | __ Addu(dst_high, dst_high, TMP); |
| 8225 | __ Mflo(dst_low); |
| 8226 | } |
| 8227 | break; |
| 8228 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8229 | case DataType::Type::kFloat32: |
| 8230 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8231 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8232 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8233 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8234 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8235 | __ MulS(dst, lhs, rhs); |
| 8236 | } else { |
| 8237 | __ MulD(dst, lhs, rhs); |
| 8238 | } |
| 8239 | break; |
| 8240 | } |
| 8241 | default: |
| 8242 | LOG(FATAL) << "Unexpected mul type " << type; |
| 8243 | } |
| 8244 | } |
| 8245 | |
| 8246 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { |
| 8247 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8248 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8249 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8250 | case DataType::Type::kInt32: |
| 8251 | case DataType::Type::kInt64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8252 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8253 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8254 | break; |
| 8255 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8256 | case DataType::Type::kFloat32: |
| 8257 | case DataType::Type::kFloat64: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8258 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8259 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8260 | break; |
| 8261 | |
| 8262 | default: |
| 8263 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 8264 | } |
| 8265 | } |
| 8266 | |
| 8267 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8268 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8269 | LocationSummary* locations = instruction->GetLocations(); |
| 8270 | |
| 8271 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8272 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8273 | Register dst = locations->Out().AsRegister<Register>(); |
| 8274 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8275 | __ Subu(dst, ZERO, src); |
| 8276 | break; |
| 8277 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8278 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8279 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8280 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8281 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8282 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8283 | __ Subu(dst_low, ZERO, src_low); |
| 8284 | __ Sltu(TMP, ZERO, dst_low); |
| 8285 | __ Subu(dst_high, ZERO, src_high); |
| 8286 | __ Subu(dst_high, dst_high, TMP); |
| 8287 | break; |
| 8288 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8289 | case DataType::Type::kFloat32: |
| 8290 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8291 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8292 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8293 | if (type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8294 | __ NegS(dst, src); |
| 8295 | } else { |
| 8296 | __ NegD(dst, src); |
| 8297 | } |
| 8298 | break; |
| 8299 | } |
| 8300 | default: |
| 8301 | LOG(FATAL) << "Unexpected neg type " << type; |
| 8302 | } |
| 8303 | } |
| 8304 | |
| 8305 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8306 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8307 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8308 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8309 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8310 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8311 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8312 | } |
| 8313 | |
| 8314 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8315 | // Note: if heap poisoning is enabled, the entry point takes care |
| 8316 | // of poisoning the reference. |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8317 | QuickEntrypointEnum entrypoint = |
| 8318 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 8319 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8320 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | 854df41 | 2017-06-27 14:41:39 +0200 | [diff] [blame] | 8321 | DCHECK(!codegen_->IsLeafMethod()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8322 | } |
| 8323 | |
| 8324 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8325 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8326 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8327 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8328 | if (instruction->IsStringAlloc()) { |
| 8329 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 8330 | } else { |
| 8331 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8332 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8333 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8334 | } |
| 8335 | |
| 8336 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 8337 | // Note: if heap poisoning is enabled, the entry point takes care |
| 8338 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8339 | if (instruction->IsStringAlloc()) { |
| 8340 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 8341 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8342 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8343 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 8344 | __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value()); |
| 8345 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 8346 | __ NopIfNoReordering(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8347 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 8348 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8349 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 8350 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 8351 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8352 | } |
| 8353 | |
| 8354 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8355 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8356 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8357 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8358 | } |
| 8359 | |
| 8360 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8361 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8362 | LocationSummary* locations = instruction->GetLocations(); |
| 8363 | |
| 8364 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8365 | case DataType::Type::kInt32: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8366 | Register dst = locations->Out().AsRegister<Register>(); |
| 8367 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8368 | __ Nor(dst, src, ZERO); |
| 8369 | break; |
| 8370 | } |
| 8371 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8372 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8373 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8374 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8375 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8376 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8377 | __ Nor(dst_high, src_high, ZERO); |
| 8378 | __ Nor(dst_low, src_low, ZERO); |
| 8379 | break; |
| 8380 | } |
| 8381 | |
| 8382 | default: |
| 8383 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 8384 | } |
| 8385 | } |
| 8386 | |
| 8387 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8388 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8389 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8390 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8391 | } |
| 8392 | |
| 8393 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 8394 | LocationSummary* locations = instruction->GetLocations(); |
| 8395 | __ Xori(locations->Out().AsRegister<Register>(), |
| 8396 | locations->InAt(0).AsRegister<Register>(), |
| 8397 | 1); |
| 8398 | } |
| 8399 | |
| 8400 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 8401 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 8402 | locations->SetInAt(0, Location::RequiresRegister()); |
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::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 8406 | if (CanMoveNullCheckToUser(instruction)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8407 | return; |
| 8408 | } |
| 8409 | Location obj = instruction->GetLocations()->InAt(0); |
| 8410 | |
| 8411 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8412 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8413 | } |
| 8414 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8415 | void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8416 | SlowPathCodeMIPS* slow_path = new (GetScopedAllocator()) NullCheckSlowPathMIPS(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8417 | AddSlowPath(slow_path); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8418 | |
| 8419 | Location obj = instruction->GetLocations()->InAt(0); |
| 8420 | |
| 8421 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8422 | } |
| 8423 | |
| 8424 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 8425 | codegen_->GenerateNullCheck(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8426 | } |
| 8427 | |
| 8428 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { |
| 8429 | HandleBinaryOp(instruction); |
| 8430 | } |
| 8431 | |
| 8432 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { |
| 8433 | HandleBinaryOp(instruction); |
| 8434 | } |
| 8435 | |
| 8436 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 8437 | LOG(FATAL) << "Unreachable"; |
| 8438 | } |
| 8439 | |
| 8440 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 8441 | if (instruction->GetNext()->IsSuspendCheck() && |
| 8442 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 8443 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 8444 | // The back edge will generate the suspend check. |
| 8445 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 8446 | } |
| 8447 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8448 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 8449 | } |
| 8450 | |
| 8451 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8452 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8453 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 8454 | if (location.IsStackSlot()) { |
| 8455 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8456 | } else if (location.IsDoubleStackSlot()) { |
| 8457 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 8458 | } |
| 8459 | locations->SetOut(location); |
| 8460 | } |
| 8461 | |
| 8462 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction |
| 8463 | ATTRIBUTE_UNUSED) { |
| 8464 | // Nothing to do, the parameter is already at its location. |
| 8465 | } |
| 8466 | |
| 8467 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 8468 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8469 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8470 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 8471 | } |
| 8472 | |
| 8473 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction |
| 8474 | ATTRIBUTE_UNUSED) { |
| 8475 | // Nothing to do, the method is already at its location. |
| 8476 | } |
| 8477 | |
| 8478 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8479 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 8480 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8481 | locations->SetInAt(i, Location::Any()); |
| 8482 | } |
| 8483 | locations->SetOut(Location::Any()); |
| 8484 | } |
| 8485 | |
| 8486 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 8487 | LOG(FATAL) << "Unreachable"; |
| 8488 | } |
| 8489 | |
| 8490 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8491 | DataType::Type type = rem->GetResultType(); |
| 8492 | LocationSummary::CallKind call_kind = (type == DataType::Type::kInt32) |
| 8493 | ? LocationSummary::kNoCall |
| 8494 | : LocationSummary::kCallOnMainOnly; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8495 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8496 | |
| 8497 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8498 | case DataType::Type::kInt32: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8499 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8500 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8501 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8502 | break; |
| 8503 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8504 | case DataType::Type::kInt64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8505 | InvokeRuntimeCallingConvention calling_convention; |
| 8506 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 8507 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 8508 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 8509 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 8510 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8511 | break; |
| 8512 | } |
| 8513 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8514 | case DataType::Type::kFloat32: |
| 8515 | case DataType::Type::kFloat64: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8516 | InvokeRuntimeCallingConvention calling_convention; |
| 8517 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 8518 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 8519 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 8520 | break; |
| 8521 | } |
| 8522 | |
| 8523 | default: |
| 8524 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8525 | } |
| 8526 | } |
| 8527 | |
| 8528 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8529 | DataType::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8530 | |
| 8531 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8532 | case DataType::Type::kInt32: |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 8533 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8534 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8535 | case DataType::Type::kInt64: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8536 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8537 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 8538 | break; |
| 8539 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8540 | case DataType::Type::kFloat32: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8541 | codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8542 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8543 | break; |
| 8544 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8545 | case DataType::Type::kFloat64: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8546 | codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8547 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8548 | break; |
| 8549 | } |
| 8550 | default: |
| 8551 | LOG(FATAL) << "Unexpected rem type " << type; |
| 8552 | } |
| 8553 | } |
| 8554 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8555 | void LocationsBuilderMIPS::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 8556 | constructor_fence->SetLocations(nullptr); |
| 8557 | } |
| 8558 | |
| 8559 | void InstructionCodeGeneratorMIPS::VisitConstructorFence( |
| 8560 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 8561 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 8562 | } |
| 8563 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8564 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 8565 | memory_barrier->SetLocations(nullptr); |
| 8566 | } |
| 8567 | |
| 8568 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 8569 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 8570 | } |
| 8571 | |
| 8572 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8573 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(ret); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8574 | DataType::Type return_type = ret->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8575 | locations->SetInAt(0, MipsReturnLocation(return_type)); |
| 8576 | } |
| 8577 | |
| 8578 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 8579 | codegen_->GenerateFrameExit(); |
| 8580 | } |
| 8581 | |
| 8582 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { |
| 8583 | ret->SetLocations(nullptr); |
| 8584 | } |
| 8585 | |
| 8586 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 8587 | codegen_->GenerateFrameExit(); |
| 8588 | } |
| 8589 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 8590 | void LocationsBuilderMIPS::VisitRor(HRor* ror) { |
| 8591 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 8592 | } |
| 8593 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 8594 | void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) { |
| 8595 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 8596 | } |
| 8597 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8598 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { |
| 8599 | HandleShift(shl); |
| 8600 | } |
| 8601 | |
| 8602 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { |
| 8603 | HandleShift(shl); |
| 8604 | } |
| 8605 | |
| 8606 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { |
| 8607 | HandleShift(shr); |
| 8608 | } |
| 8609 | |
| 8610 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { |
| 8611 | HandleShift(shr); |
| 8612 | } |
| 8613 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8614 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { |
| 8615 | HandleBinaryOp(instruction); |
| 8616 | } |
| 8617 | |
| 8618 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { |
| 8619 | HandleBinaryOp(instruction); |
| 8620 | } |
| 8621 | |
| 8622 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 8623 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 8624 | } |
| 8625 | |
| 8626 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 8627 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 8628 | } |
| 8629 | |
| 8630 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 8631 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 8632 | } |
| 8633 | |
| 8634 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 8635 | HandleFieldSet(instruction, |
| 8636 | instruction->GetFieldInfo(), |
| 8637 | instruction->GetDexPc(), |
| 8638 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8639 | } |
| 8640 | |
| 8641 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( |
| 8642 | HUnresolvedInstanceFieldGet* instruction) { |
| 8643 | FieldAccessCallingConventionMIPS calling_convention; |
| 8644 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8645 | instruction->GetFieldType(), |
| 8646 | calling_convention); |
| 8647 | } |
| 8648 | |
| 8649 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( |
| 8650 | HUnresolvedInstanceFieldGet* instruction) { |
| 8651 | FieldAccessCallingConventionMIPS calling_convention; |
| 8652 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8653 | instruction->GetFieldType(), |
| 8654 | instruction->GetFieldIndex(), |
| 8655 | instruction->GetDexPc(), |
| 8656 | calling_convention); |
| 8657 | } |
| 8658 | |
| 8659 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( |
| 8660 | HUnresolvedInstanceFieldSet* instruction) { |
| 8661 | FieldAccessCallingConventionMIPS calling_convention; |
| 8662 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8663 | instruction->GetFieldType(), |
| 8664 | calling_convention); |
| 8665 | } |
| 8666 | |
| 8667 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( |
| 8668 | HUnresolvedInstanceFieldSet* instruction) { |
| 8669 | FieldAccessCallingConventionMIPS calling_convention; |
| 8670 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8671 | instruction->GetFieldType(), |
| 8672 | instruction->GetFieldIndex(), |
| 8673 | instruction->GetDexPc(), |
| 8674 | calling_convention); |
| 8675 | } |
| 8676 | |
| 8677 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( |
| 8678 | HUnresolvedStaticFieldGet* instruction) { |
| 8679 | FieldAccessCallingConventionMIPS calling_convention; |
| 8680 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8681 | instruction->GetFieldType(), |
| 8682 | calling_convention); |
| 8683 | } |
| 8684 | |
| 8685 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( |
| 8686 | HUnresolvedStaticFieldGet* instruction) { |
| 8687 | FieldAccessCallingConventionMIPS calling_convention; |
| 8688 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8689 | instruction->GetFieldType(), |
| 8690 | instruction->GetFieldIndex(), |
| 8691 | instruction->GetDexPc(), |
| 8692 | calling_convention); |
| 8693 | } |
| 8694 | |
| 8695 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( |
| 8696 | HUnresolvedStaticFieldSet* instruction) { |
| 8697 | FieldAccessCallingConventionMIPS calling_convention; |
| 8698 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 8699 | instruction->GetFieldType(), |
| 8700 | calling_convention); |
| 8701 | } |
| 8702 | |
| 8703 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( |
| 8704 | HUnresolvedStaticFieldSet* instruction) { |
| 8705 | FieldAccessCallingConventionMIPS calling_convention; |
| 8706 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 8707 | instruction->GetFieldType(), |
| 8708 | instruction->GetFieldIndex(), |
| 8709 | instruction->GetDexPc(), |
| 8710 | calling_convention); |
| 8711 | } |
| 8712 | |
| 8713 | void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8714 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8715 | instruction, LocationSummary::kCallOnSlowPath); |
Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 8716 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 8717 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 8718 | // registers in full width (since the runtime only saves/restores lower part). |
| 8719 | locations->SetCustomSlowPathCallerSaves( |
| 8720 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8721 | } |
| 8722 | |
| 8723 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 8724 | HBasicBlock* block = instruction->GetBlock(); |
| 8725 | if (block->GetLoopInformation() != nullptr) { |
| 8726 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 8727 | // The back edge will generate the suspend check. |
| 8728 | return; |
| 8729 | } |
| 8730 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 8731 | // The goto will generate the suspend check. |
| 8732 | return; |
| 8733 | } |
| 8734 | GenerateSuspendCheck(instruction, nullptr); |
| 8735 | } |
| 8736 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8737 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8738 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8739 | instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8740 | InvokeRuntimeCallingConvention calling_convention; |
| 8741 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8742 | } |
| 8743 | |
| 8744 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8745 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8746 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 8747 | } |
| 8748 | |
| 8749 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8750 | DataType::Type input_type = conversion->GetInputType(); |
| 8751 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 8752 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 8753 | << input_type << " -> " << result_type; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8754 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8755 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8756 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 8757 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8758 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 8759 | } |
| 8760 | |
| 8761 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8762 | if (!isR6 && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8763 | ((DataType::IsFloatingPointType(result_type) && input_type == DataType::Type::kInt64) || |
| 8764 | (result_type == DataType::Type::kInt64 && DataType::IsFloatingPointType(input_type)))) { |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 8765 | call_kind = LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8766 | } |
| 8767 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8768 | LocationSummary* locations = |
| 8769 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8770 | |
| 8771 | if (call_kind == LocationSummary::kNoCall) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8772 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8773 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 8774 | } else { |
| 8775 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8776 | } |
| 8777 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8778 | if (DataType::IsFloatingPointType(result_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8779 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 8780 | } else { |
| 8781 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8782 | } |
| 8783 | } else { |
| 8784 | InvokeRuntimeCallingConvention calling_convention; |
| 8785 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8786 | if (DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8787 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 8788 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8789 | DCHECK_EQ(input_type, DataType::Type::kInt64); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8790 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 8791 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 8792 | } |
| 8793 | |
| 8794 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 8795 | } |
| 8796 | } |
| 8797 | |
| 8798 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 8799 | LocationSummary* locations = conversion->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8800 | DataType::Type result_type = conversion->GetResultType(); |
| 8801 | DataType::Type input_type = conversion->GetInputType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8802 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8803 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8804 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 8805 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 8806 | << input_type << " -> " << result_type; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8807 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8808 | if (result_type == DataType::Type::kInt64 && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8809 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8810 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8811 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8812 | |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 8813 | if (dst_low != src) { |
| 8814 | __ Move(dst_low, src); |
| 8815 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8816 | __ Sra(dst_high, src, 31); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8817 | } else if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8818 | Register dst = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8819 | Register src = (input_type == DataType::Type::kInt64) |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8820 | ? locations->InAt(0).AsRegisterPairLow<Register>() |
| 8821 | : locations->InAt(0).AsRegister<Register>(); |
| 8822 | |
| 8823 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 8824 | case DataType::Type::kUint8: |
| 8825 | __ Andi(dst, src, 0xFF); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8826 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8827 | case DataType::Type::kInt8: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8828 | if (has_sign_extension) { |
| 8829 | __ Seb(dst, src); |
| 8830 | } else { |
| 8831 | __ Sll(dst, src, 24); |
| 8832 | __ Sra(dst, dst, 24); |
| 8833 | } |
| 8834 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 8835 | case DataType::Type::kUint16: |
| 8836 | __ Andi(dst, src, 0xFFFF); |
| 8837 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8838 | case DataType::Type::kInt16: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8839 | if (has_sign_extension) { |
| 8840 | __ Seh(dst, src); |
| 8841 | } else { |
| 8842 | __ Sll(dst, src, 16); |
| 8843 | __ Sra(dst, dst, 16); |
| 8844 | } |
| 8845 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8846 | case DataType::Type::kInt32: |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 8847 | if (dst != src) { |
| 8848 | __ Move(dst, src); |
| 8849 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8850 | break; |
| 8851 | |
| 8852 | default: |
| 8853 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 8854 | << " to " << result_type; |
| 8855 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8856 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
| 8857 | if (input_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8858 | if (isR6) { |
| 8859 | // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 8860 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 8861 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8862 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8863 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8864 | __ Mtc1(src_low, FTMP); |
| 8865 | __ Mthc1(src_high, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8866 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8867 | __ Cvtsl(dst, FTMP); |
| 8868 | } else { |
| 8869 | __ Cvtdl(dst, FTMP); |
| 8870 | } |
| 8871 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8872 | QuickEntrypointEnum entrypoint = |
| 8873 | (result_type == DataType::Type::kFloat32) ? kQuickL2f : kQuickL2d; |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8874 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8875 | if (result_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8876 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 8877 | } else { |
| 8878 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 8879 | } |
| 8880 | } |
| 8881 | } else { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8882 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8883 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8884 | __ Mtc1(src, FTMP); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8885 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8886 | __ Cvtsw(dst, FTMP); |
| 8887 | } else { |
| 8888 | __ Cvtdw(dst, FTMP); |
| 8889 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8890 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8891 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 8892 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8893 | |
| 8894 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum |
| 8895 | // value of the output type if the input is outside of the range after the truncation or |
| 8896 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct |
| 8897 | // results. This matches the desired float/double-to-int/long conversion exactly. |
| 8898 | // |
| 8899 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive |
| 8900 | // value when the input is either a NaN or is outside of the range of the output type |
| 8901 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce |
| 8902 | // the same result. |
| 8903 | // |
| 8904 | // The code takes care of the different behaviors by first comparing the input to the |
| 8905 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). |
| 8906 | // If the input is greater than or equal to the minimum, it procedes to the truncate |
| 8907 | // instruction, which will handle such an input the same way irrespective of NAN2008. |
| 8908 | // Otherwise the input is compared to itself to determine whether it is a NaN or not |
| 8909 | // in order to return either zero or the minimum value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8910 | if (result_type == DataType::Type::kInt64) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8911 | if (isR6) { |
| 8912 | // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 8913 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 8914 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8915 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8916 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8917 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8918 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8919 | __ TruncLS(FTMP, src); |
| 8920 | } else { |
| 8921 | __ TruncLD(FTMP, src); |
| 8922 | } |
| 8923 | __ Mfc1(dst_low, FTMP); |
| 8924 | __ Mfhc1(dst_high, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8925 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8926 | QuickEntrypointEnum entrypoint = |
| 8927 | (input_type == DataType::Type::kFloat32) ? kQuickF2l : kQuickD2l; |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8928 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8929 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8930 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 8931 | } else { |
| 8932 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 8933 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8934 | } |
| 8935 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8936 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8937 | Register dst = locations->Out().AsRegister<Register>(); |
| 8938 | MipsLabel truncate; |
| 8939 | MipsLabel done; |
| 8940 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8941 | if (!isR6) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8942 | if (input_type == DataType::Type::kFloat32) { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8943 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); |
| 8944 | __ LoadConst32(TMP, min_val); |
| 8945 | __ Mtc1(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8946 | } else { |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8947 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); |
| 8948 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 8949 | __ Mtc1(ZERO, FTMP); |
| 8950 | __ MoveToFpuHigh(TMP, FTMP); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8951 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8952 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8953 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8954 | __ ColeS(0, FTMP, src); |
| 8955 | } else { |
| 8956 | __ ColeD(0, FTMP, src); |
| 8957 | } |
| 8958 | __ Bc1t(0, &truncate); |
| 8959 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8960 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8961 | __ CeqS(0, src, src); |
| 8962 | } else { |
| 8963 | __ CeqD(0, src, src); |
| 8964 | } |
| 8965 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 8966 | __ Movf(dst, ZERO, 0); |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8967 | |
| 8968 | __ B(&done); |
| 8969 | |
| 8970 | __ Bind(&truncate); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8971 | } |
| 8972 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8973 | if (input_type == DataType::Type::kFloat32) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8974 | __ TruncWS(FTMP, src); |
| 8975 | } else { |
| 8976 | __ TruncWD(FTMP, src); |
| 8977 | } |
| 8978 | __ Mfc1(dst, FTMP); |
| 8979 | |
Lena Djokic | f4e23a8 | 2017-05-09 15:43:45 +0200 | [diff] [blame] | 8980 | if (!isR6) { |
| 8981 | __ Bind(&done); |
| 8982 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8983 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8984 | } else if (DataType::IsFloatingPointType(result_type) && |
| 8985 | DataType::IsFloatingPointType(input_type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8986 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8987 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8988 | if (result_type == DataType::Type::kFloat32) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8989 | __ Cvtsd(dst, src); |
| 8990 | } else { |
| 8991 | __ Cvtds(dst, src); |
| 8992 | } |
| 8993 | } else { |
| 8994 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 8995 | << " to " << result_type; |
| 8996 | } |
| 8997 | } |
| 8998 | |
| 8999 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { |
| 9000 | HandleShift(ushr); |
| 9001 | } |
| 9002 | |
| 9003 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { |
| 9004 | HandleShift(ushr); |
| 9005 | } |
| 9006 | |
| 9007 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { |
| 9008 | HandleBinaryOp(instruction); |
| 9009 | } |
| 9010 | |
| 9011 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { |
| 9012 | HandleBinaryOp(instruction); |
| 9013 | } |
| 9014 | |
| 9015 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9016 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9017 | LOG(FATAL) << "Unreachable"; |
| 9018 | } |
| 9019 | |
| 9020 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9021 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9022 | LOG(FATAL) << "Unreachable"; |
| 9023 | } |
| 9024 | |
| 9025 | void LocationsBuilderMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9026 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9027 | } |
| 9028 | |
| 9029 | void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9030 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9031 | } |
| 9032 | |
| 9033 | void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9034 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9035 | } |
| 9036 | |
| 9037 | void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9038 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9039 | } |
| 9040 | |
| 9041 | void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9042 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9043 | } |
| 9044 | |
| 9045 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9046 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9047 | } |
| 9048 | |
| 9049 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9050 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9051 | } |
| 9052 | |
| 9053 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9054 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9055 | } |
| 9056 | |
| 9057 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9058 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9059 | } |
| 9060 | |
| 9061 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9062 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9063 | } |
| 9064 | |
| 9065 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9066 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9067 | } |
| 9068 | |
| 9069 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9070 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9071 | } |
| 9072 | |
| 9073 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9074 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9075 | } |
| 9076 | |
| 9077 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9078 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9079 | } |
| 9080 | |
| 9081 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9082 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9083 | } |
| 9084 | |
| 9085 | void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9086 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9087 | } |
| 9088 | |
| 9089 | void LocationsBuilderMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9090 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9091 | } |
| 9092 | |
| 9093 | void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9094 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9095 | } |
| 9096 | |
| 9097 | void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9098 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9099 | } |
| 9100 | |
| 9101 | void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 9102 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9103 | } |
| 9104 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9105 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9106 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9107 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9108 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9109 | if (!codegen_->GetInstructionSetFeatures().IsR6()) { |
| 9110 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9111 | if (num_entries > InstructionCodeGeneratorMIPS::kPackedSwitchJumpTableThreshold) { |
| 9112 | // When there's no HMipsComputeBaseMethodAddress input, R2 uses the NAL |
| 9113 | // instruction to simulate PC-relative addressing when accessing the jump table. |
| 9114 | // NAL clobbers RA. Make sure RA is preserved. |
| 9115 | codegen_->ClobberRA(); |
| 9116 | } |
| 9117 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9118 | } |
| 9119 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9120 | void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg, |
| 9121 | int32_t lower_bound, |
| 9122 | uint32_t num_entries, |
| 9123 | HBasicBlock* switch_block, |
| 9124 | HBasicBlock* default_block) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9125 | // Create a set of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9126 | Register temp_reg = TMP; |
| 9127 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
| 9128 | // Jump to default if index is negative |
| 9129 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 9130 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 9131 | __ Bltz(temp_reg, codegen_->GetLabelOf(default_block)); |
| 9132 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9133 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9134 | // Jump to successors[0] if value == lower_bound. |
| 9135 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 9136 | int32_t last_index = 0; |
| 9137 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9138 | __ Addiu(temp_reg, temp_reg, -2); |
| 9139 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9140 | __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9141 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9142 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9143 | } |
| 9144 | if (num_entries - last_index == 2) { |
| 9145 | // The last missing case_value. |
| 9146 | __ Addiu(temp_reg, temp_reg, -1); |
| 9147 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9148 | } |
| 9149 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9150 | // And the default for any other value. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9151 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9152 | __ B(codegen_->GetLabelOf(default_block)); |
| 9153 | } |
| 9154 | } |
| 9155 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9156 | void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg, |
| 9157 | Register constant_area, |
| 9158 | int32_t lower_bound, |
| 9159 | uint32_t num_entries, |
| 9160 | HBasicBlock* switch_block, |
| 9161 | HBasicBlock* default_block) { |
| 9162 | // Create a jump table. |
| 9163 | std::vector<MipsLabel*> labels(num_entries); |
| 9164 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 9165 | for (uint32_t i = 0; i < num_entries; i++) { |
| 9166 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 9167 | } |
| 9168 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 9169 | |
| 9170 | // Is the value in range? |
| 9171 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 9172 | if (IsInt<16>(static_cast<int32_t>(num_entries))) { |
| 9173 | __ Sltiu(AT, TMP, num_entries); |
| 9174 | __ Beqz(AT, codegen_->GetLabelOf(default_block)); |
| 9175 | } else { |
| 9176 | __ LoadConst32(AT, num_entries); |
| 9177 | __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 9178 | } |
| 9179 | |
| 9180 | // We are in the range of the table. |
| 9181 | // Load the target address from the jump table, indexing by the value. |
| 9182 | __ LoadLabelAddress(AT, constant_area, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 9183 | __ ShiftAndAdd(TMP, TMP, AT, 2, TMP); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9184 | __ Lw(TMP, TMP, 0); |
| 9185 | // Compute the absolute target address by adding the table start address |
| 9186 | // (the table contains offsets to targets relative to its start). |
| 9187 | __ Addu(TMP, TMP, AT); |
| 9188 | // And jump. |
| 9189 | __ Jr(TMP); |
| 9190 | __ NopIfNoReordering(); |
| 9191 | } |
| 9192 | |
| 9193 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9194 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9195 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9196 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9197 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 9198 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 9199 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9200 | |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9201 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9202 | // R6 uses PC-relative addressing to access the jump table. |
Alexey Frunze | 3b8c82f | 2017-10-10 23:01:34 -0700 | [diff] [blame] | 9203 | // |
| 9204 | // R2, OTOH, uses an HMipsComputeBaseMethodAddress input (when available) |
| 9205 | // to access the jump table and it is implemented by changing HPackedSwitch to |
| 9206 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress (see |
| 9207 | // VisitMipsPackedSwitch()). |
| 9208 | // |
| 9209 | // When there's no HMipsComputeBaseMethodAddress input (e.g. in presence of |
| 9210 | // irreducible loops), R2 uses the NAL instruction to simulate PC-relative |
| 9211 | // addressing. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9212 | GenTableBasedPackedSwitch(value_reg, |
| 9213 | ZERO, |
| 9214 | lower_bound, |
| 9215 | num_entries, |
| 9216 | switch_block, |
| 9217 | default_block); |
| 9218 | } else { |
| 9219 | GenPackedSwitchWithCompares(value_reg, |
| 9220 | lower_bound, |
| 9221 | num_entries, |
| 9222 | switch_block, |
| 9223 | default_block); |
| 9224 | } |
| 9225 | } |
| 9226 | |
| 9227 | void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 9228 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9229 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 9230 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9231 | // Constant area pointer (HMipsComputeBaseMethodAddress). |
| 9232 | locations->SetInAt(1, Location::RequiresRegister()); |
| 9233 | } |
| 9234 | |
| 9235 | void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 9236 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9237 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9238 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9239 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 9240 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 9241 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 9242 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9243 | |
| 9244 | // This is an R2-only path. HPackedSwitch has been changed to |
| 9245 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress |
| 9246 | // required to address the jump table relative to PC. |
| 9247 | GenTableBasedPackedSwitch(value_reg, |
| 9248 | constant_area, |
| 9249 | lower_bound, |
| 9250 | num_entries, |
| 9251 | switch_block, |
| 9252 | default_block); |
| 9253 | } |
| 9254 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 9255 | void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress( |
| 9256 | HMipsComputeBaseMethodAddress* insn) { |
| 9257 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9258 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 9259 | locations->SetOut(Location::RequiresRegister()); |
| 9260 | } |
| 9261 | |
| 9262 | void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress( |
| 9263 | HMipsComputeBaseMethodAddress* insn) { |
| 9264 | LocationSummary* locations = insn->GetLocations(); |
| 9265 | Register reg = locations->Out().AsRegister<Register>(); |
| 9266 | |
| 9267 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 9268 | |
| 9269 | // Generate a dummy PC-relative call to obtain PC. |
| 9270 | __ Nal(); |
| 9271 | // Grab the return address off RA. |
| 9272 | __ Move(reg, RA); |
| 9273 | |
| 9274 | // Remember this offset (the obtained PC value) for later use with constant area. |
| 9275 | __ BindPcRelBaseLabel(); |
| 9276 | } |
| 9277 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9278 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 9279 | // The trampoline uses the same calling convention as dex calling conventions, |
| 9280 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 9281 | // the method_idx. |
| 9282 | HandleInvoke(invoke); |
| 9283 | } |
| 9284 | |
| 9285 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 9286 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 9287 | } |
| 9288 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9289 | void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 9290 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9291 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9292 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9293 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9294 | } |
| 9295 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9296 | void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 9297 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 9298 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9299 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9300 | instruction->GetIndex(), kMipsPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9301 | __ LoadFromOffset(kLoadWord, |
| 9302 | locations->Out().AsRegister<Register>(), |
| 9303 | locations->InAt(0).AsRegister<Register>(), |
| 9304 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9305 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9306 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 9307 | instruction->GetIndex(), kMipsPointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 9308 | __ LoadFromOffset(kLoadWord, |
| 9309 | locations->Out().AsRegister<Register>(), |
| 9310 | locations->InAt(0).AsRegister<Register>(), |
| 9311 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9312 | __ LoadFromOffset(kLoadWord, |
| 9313 | locations->Out().AsRegister<Register>(), |
| 9314 | locations->Out().AsRegister<Register>(), |
| 9315 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 9316 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9317 | } |
| 9318 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 9319 | void LocationsBuilderMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 9320 | ATTRIBUTE_UNUSED) { |
| 9321 | LOG(FATAL) << "Unreachable"; |
| 9322 | } |
| 9323 | |
| 9324 | void InstructionCodeGeneratorMIPS::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 9325 | ATTRIBUTE_UNUSED) { |
| 9326 | LOG(FATAL) << "Unreachable"; |
| 9327 | } |
| 9328 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 9329 | #undef __ |
| 9330 | #undef QUICK_ENTRY_POINT |
| 9331 | |
| 9332 | } // namespace mips |
| 9333 | } // namespace art |